TRUE, FALSE,
UNKNOWN
-- Boolean constantsMuPAD uses a three state logic with the Boolean constants
TRUE
, FALSE
, and UNKNOWN
.
_lazy_and
,
_lazy_or
, and
, bool
, DOM_BOOL
, if
, is
, not
, or
, repeat
, while
TRUE
, FALSE
,
UNKNOWN
are of domain type DOM_BOOL
.and
, or
,
not
for the logical rules of MuPAD's three
state logic.bool
and is
. These functions evaluate Boolean
expressions such as equations and inequalities.The Boolean constants may be combined via and
, or
, and not
:
>> (TRUE and (not FALSE)) or UNKNOWN
TRUE
The function bool
serves for reducing Boolean
expressions such as equations or inequalities to one of the Boolean
constants:
>> bool(x = x and 2 < 3 and 3 <> 4 or UNKNOWN)
TRUE
The function is
evaluates symbolic Boolean expressions
with properties:
>> assume(x > 2): is(x^2 > 4), is(x^3 < 0), is(x^4 > 17)
TRUE, FALSE, UNKNOWN
>> unassume(x):
Boolean constants occur in the conditional part of
program control structures such as if
, repeat
, or while
statements. The following loop
searches for the smallest Mersenne prime larger than 500
(see numlib::mersenne
for details). The function isprime
returns TRUE
if
its argument is a prime, and FALSE
otherwise. Once a
Mersenne prime is found, the while
-loop is interrupted by the
break
statement:
>> p := 500: while TRUE do p := nextprime(p + 1): if isprime(2^p - 1) then print(p); break; end_if; end_while:
521
Note that the conditional part of if
, repeat
, and while
statements must evaluate to
TRUE
or FALSE
. Any other value leads to an
error:
>> if UNKNOWN then "true" else "false" end_if
Error: Can't evaluate to boolean [if]
>> delete p: