# [Maxima] code for unevaluated Boolean and conditional expressions

Robert Dodier robert.dodier at gmail.com
Fri May 5 01:19:56 CDT 2006

```Stavros,

Here is the spec for the code, such as it is.
The code at present deviates slightly from this: at present
MEVAL applied to a Boolean expression calls MEVALP to
evaluate the arguments only if the operator is MAND, MOR,
or MNOT. It is a subtle point but I'll try to fix it.

Hope this helps,
Robert

Simplification of boolean expressions:

and: if any argument simplifies to false, return false
otherwise omit arguments which simplify to true and simplify others
if only one argument remains, return it
if none remain, return true

or: if any argument simplifies to true, return true
otherwise omit arguments which simplify to false and simplify others
if only one argument remains, return it
if none remain, return false

not: if argument simplifies to true / false, return false / true
otherwise reverse sense of comparisons (if argument is a comparison)
otherwise return not <simplified argument>

Evaluation (MEVAL) of boolean expressions:
same as simplification except evaluating (MEVALP) arguments instead
of simplifying
When prederror = true, complain if expression evaluates to something
other than T / NIL
(otherwise return unevaluated boolean expression)

Evaluation (MEVALP) of boolean expressions:
same as simplification except evaluating (MEVALP) arguments instead
of simplifying
When prederror = true, complain if expression evaluates to something
other than T / NIL
(otherwise return unevaluated boolean expression)

Simplification of "is" expressions:
if argument simplifies to true/false, return true/false
otherwise return is (<simplified argument>)

Evaluation of "is" expressions:
if argument evaluates to true/false, return true/false
otherwise return unknown if prederror = false, else trigger an error

Simplification of "maybe" expressions:
if argument simplifies to true/false, return true/false
otherwise return maybe (<simplified expression>)

Evaluation of "maybe" expressions:
if argument evaluates to true/false, return true/false
otherwise return unknown

Simplification of "if" expressions:

Let the expression be if P[1] then E[1] elseif P[2] then E[2] ...
elseif P[n] then E[n]
("if P[1] then E[1] else E[2]" parses to the above with P[2] = true,
and "if P[1] then E[1]" parses to the above with P[2] = true and E[2] = false.)

(1) If any P[k] simplifies to false, do not simplify E[k],
and omit P[k] and E[k] from the result.
(2) If any P[k] simplifies to true, simplify E[k],
but do not simplify any P[k + 1], E[k + 1], ..., and omit them
from the result.
(3) Otherwise, simplify E[k].

If there are no P and E remaining, return false.
Let P*[1], E*[1], ... be any P and E remaining after applying (1),
(2), and (3).
If P*[1] = true, return E*[1].
Otherwise return "if P*[1] then E*[1] elseif P*[2] then E*[2] ..."
with "if" being a noun iff the original "if" was a noun.

Evaluation of "if" expressions:

(1) If any P[k] evaluates to false, do not evaluate E[k],
and omit P[k] and E[k] from the result.
(2) If any P[k] evaluates to true, evaluate E[k],
but do not evaluate any P[k + 1], E[k + 1], ..., and omit them
from the result.
(3) Otherwise, evaluate atoms (not function calls) in E[k].

If there are no P and E remaining, return false.
Let P*[1], E*[1], ... be any P and E remaining after applying (1),
(2), and (3).
If P*[1] = true, return E*[1].
Otherwise return "if P*[1] then E*[1] elseif P*[2] then E*[2] ..."
with "if" being a noun iff the original "if" was a noun.

```