ifelse - Maple Help

convert/ifelse

convert to ifelse expression

 Calling Sequence convert(expr, ifelse) convert(expr, ifelse, recurse)

Parameters

 expr - expression to convert

Options

 • recurse : true or false
 This option specifies whether the transformation should be applied to subexpressions of the original expression expr. The default is false.

Description

 • The convert(expr, ifelse) command accepts a Maple piecewise expression and return a result written in terms of nested calls to the ifelse function.

Examples

Convert a piecewise with three branches to nested ifelse calls.

 > $p≔\mathrm{piecewise}\left(2
 ${p}{≔}\left\{\begin{array}{cc}{1}& {2}{<}{x}\\ {2}& {1}{<}{x}\\ {3}& {\mathrm{otherwise}}\end{array}\right\$ (1)
 > $\mathrm{convert}\left(p,\mathrm{ifelse}\right)$
 ${\mathrm{ifelse}}{}\left({2}{<}{x}{,}{1}{,}{\mathrm{ifelse}}{}\left({1}{<}{x}{,}{2}{,}{3}\right)\right)$ (2)

Convert a nested piecewise to ifelse with and without the recurse option.

 > $p≔\mathrm{piecewise}\left(2
 ${p}{≔}\left\{\begin{array}{cc}{1}& {2}{<}{x}\\ \left\{\begin{array}{cc}{{x}}^{{2}}& {{x}}^{{2}}{<}{y}\\ {x}& {0}{<}{y}\\ {0}& {\mathrm{otherwise}}\end{array}\right\& {\mathrm{otherwise}}\end{array}\right\$ (3)
 > $\mathrm{convert}\left(p,\mathrm{ifelse}\right)$
 ${\mathrm{ifelse}}{}\left({2}{<}{x}{,}{1}{,}\left\{\begin{array}{cc}{{x}}^{{2}}& {{x}}^{{2}}{<}{y}\\ {x}& {0}{<}{y}\\ {0}& {\mathrm{otherwise}}\end{array}\right\\right)$ (4)
 > $\mathrm{convert}\left(p,\mathrm{ifelse},\mathrm{recurse}\right)$
 ${\mathrm{ifelse}}{}\left({2}{<}{x}{,}{1}{,}{\mathrm{ifelse}}{}\left({{x}}^{{2}}{<}{y}{,}{{x}}^{{2}}{,}{\mathrm{ifelse}}{}\left({0}{<}{y}{,}{x}{,}{0}\right)\right)\right)$ (5)

Compatibility

 • The convert/ifelse command was introduced in Maple 2021.