## Documentation |

Logical equivalence

This functionality does not run in MATLAB.

b_equiv(_{1}<=> b_{2}b,_{1}b)_{2}

`b1 <=> b2` represents the logical equivalence
of the Boolean expressions `b1`, `b2`.

MuPAD^{®} uses a three state logic with the Boolean constants `TRUE`, `FALSE`,
and `UNKNOWN`.
These are processed as follows:

The operator `<=>` is defined as follows: `a
<=> b` is equivalent to `(a => b) and (b
=> a)`.

Boolean expressions may be composed of these constants as well
as of arbitrary arithmetical expressions. Typically, equations such
as `x = y` and inequalities such as `x <>
y`, `x < y`, `x <= y` etc.
are used to construct Boolean expressions.

`_equiv(a, b)` is equivalent to `a
<=> b`.

Combinations of the constants `TRUE`, `FALSE`, `UNKNOWN` inside a Boolean
expression are simplified automatically. However, symbolic Boolean
subexpressions, equalities, and inequalities are not evaluated and
simplified by logical operators. Use `bool` to evaluate such expressions to
one of the Boolean constants. Note, however, that `bool` can evaluate inequalities `x
< y`, `x <= y` etc. only if they are
composed of numbers of type `Type::Real`.
Cf. Example 2.

Use `simplify` with
the option `logic` to simplify expressions involving
symbolic Boolean subexpressions. Cf. Example 3.

The precedences of the logical operators are as follows: The
operator `not` is stronger binding than `and`,
i.e, `not b1 and b2` = `(not b1) and b2`.
The operator `and` is stronger binding than `xor`,
i.e., `b1 and b2 or b3` = `(b1 and b2) xor
b3`. The operator `xor` is stronger binding
than `or`, i.e., `b1 xor b2 or b3` = `(b1
xor b2) or b3`. The operator `or` is stronger
binding than `==>`, i.e., `b1 or b2 ==>
b3` = `(b1 or b2) ==> b3`. The operator `==>` is
stronger binding than `<=>`, i.e., `b1
==> b2 <=> b3` = `(b1 ==> b2) <=>
b3`.

If in doubt, use brackets to make sure that the expression is parsed as desired.

In the conditional context of `if`, `repeat`, and `while` statements, Boolean expressions
are evaluated via "lazy evaluation" (see `_lazy_and`, `_lazy_or`). In any other
context, all operands are evaluated.

Combinations of the Boolean constants `TRUE`, `FALSE`,
and `UNKNOWN` are simplified automatically to one
of these constants:

TRUE and not (FALSE or TRUE)

FALSE and UNKNOWN, TRUE and UNKNOWN

FALSE or UNKNOWN, TRUE or UNKNOWN

not UNKNOWN

Logical operators simplify subexpressions that evaluate to the
constants `TRUE`, `FALSE`, `UNKNOWN`.

b1 or b2 and TRUE

FALSE or ((not b1) and TRUE)

b1 and (b2 or FALSE) and UNKNOWN

FALSE or (b1 and UNKNOWN) or x < 1

TRUE and ((b1 and FALSE) or (b1 and TRUE))

However, equalities and inequalities are not evaluated:

(x = x) and (1 < 2) and (2 < 3) and (3 < 4)

Boolean evaluation is enforced via `bool`:

bool(%)

Expressions involving symbolic Boolean subexpressions are not
simplified by `and`, `or`, `not`. Simplification has to be requested
explicitly via the function `simplify`:

(b1 and b2) or (b1 and (not b2)) and (1 < 2)

simplify(%, logic)

The Boolean functions `_and` and `_or` accept
arbitrary sequences of Boolean expressions. The following call uses `isprime` to check whether *all* elements
of the given set are prime:

set := {1987, 1993, 1997, 1999, 2001}: _and(isprime(i) $ i in set)

The following call checks whether *at least one* of
the numbers is prime:

_or(isprime(i) $ i in set)

delete set:

Was this topic helpful?