ifelse - Help

ifelse

the conditional function

 Calling Sequence Conditional Function ifelse(conditional expression, true expression, false expression) if(conditional expression, true expression, false expression)

Description

 • The ifelse(c,a,b) function requires three arguments and returns the evaluation of the second or third, depending on the truth value of the first.
 • The first argument a must be a conditional expression; if it evaluates to true, b is evaluated and returned.  If a evaluates to false or FAIL, then c is evaluated and returned.
 The name if is an alias for ifelse. When using this name, if must be enclosed in back quotes (left single quotes) because if is a Maple reserved word.

Conditional Expressions

 • A conditional expression is any Boolean expression formed using the relational operators ( <, <=, >, >=, =, <> ), the logical operators (and, or, not), and the logical names (true, false, FAIL).
 • When a conditional expression is evaluated in this context, it must evaluate to true, false, or FAIL; otherwise, an error occurs.

 • The ifelse function is thread-safe as of Maple 15.

Examples

Simple Case

 > $a≔3;$$b≔5$
 ${a}{≔}{3}$
 ${b}{≔}{5}$ (1)
 The conditional operator can be used inside an equation. Since b (5) is not less than a (3), the result of the inner ifelse command will be the false expression, b, which is used as part of the calculation.
 > $5\left(\mathrm{Pi}+\mathrm{ifelse}\left(b
 ${5}{}{\mathrm{\pi }}{+}{25}$ (2)

Using ifelse with NULL

 Since a is less than b, x is assigned NULL. Unlike every other function call, which removes NULLs from the calling sequence, NULL can be used with the ifelse operator.
 > $x≔\mathrm{ifelse}\left(a