Documentation

_lazy_or

"lazy or" of Boolean expressions

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

_lazy_or(b1, b2, …)

Description

_lazy_or(b1, b2, ...) evaluates the Boolean expression b1 or b2 or ... by "lazy evaluation".

_lazy_or(b1, b2, ...) produces the same result as bool(b1 or b2 or ...), provided the latter call does not produce an error. The difference between these calls is as follows:

bool(b1 or b2 or ...) evaluates all Boolean expressions before combining them logically via 'or'.

Note that the result is TRUE if one of b1, b2 etc. evaluates to TRUE. "Lazy evaluation" is based on this fact: _lazy_or(b1, b2, ...) evaluates the arguments from left to right. The evaluation is stopped immediately if one argument evaluates to TRUE. In this case, _lazy_or returns TRUEwithout evaluating the remaining Boolean expressions. If none of the expressions b1, b2 etc. evaluates to TRUE, then all arguments are evaluated and the corresponding result FALSE or UNKNOWN is returned.

_lazy_or is also called "conditional or".

If any of the considered Boolean expressions b1, b2 etc. cannot be evaluated to TRUE, FALSE, or UNKNOWN, then _lazy_or produces errors.

_lazy_or is used internally by the if, repeat, and while statements.

_lazy_or() returns FALSE.

Examples

Example 1

This example demonstrates the difference between lazy evaluation and complete evaluation of Boolean conditions. For x = 0, the evaluation of leads to an error:

x := 0: bool(x <> 0 and sin(1/x) = 0)
Error: Division by zero. [_invert]

With "lazy evaluation", the expression is not evaluated. This avoids the previous error:

_lazy_and(x <> 0, sin(1/x) = 0)

bool(x = 0 or sin(1/x) = 0)
Error: Division by zero. [_invert]
_lazy_or(x = 0, sin(1/x) = 0)

delete x:

Example 2

The following statements do no produce an error, because if uses lazy evaluation internally:

for x in [0, PI, 1/PI] do
  if x = 0 or sin(1/x) = 0 then
     print(x)
  end_if;
end_for:

delete x:

Example 3

Both functions can be called without parameters:

_lazy_and(), _lazy_or()

Parameters

b1, b2, …

Boolean expressions

Return Values

TRUE, FALSE, or UNKNOWN.

Overloaded By

b1, b2

See Also

MuPAD Functions

Was this topic helpful?