Main Menu        
    UserFormula (UFO)   UFO: Syntax UFO: Predefined


UFO: Further Examples

Conditional operators return 1 if the condition is satisfied, and zero if the condition is false. Therefore the characteristic function of an interval may be expressed using two comparisons. Write (x>0)*(x<=1) to obtain 1 if x is in the inverval (0, 1].

Multiplicative expressions are evaluated from left to right. However, as soon as a factor is calculated to zero the factors right of it are ignored. Thus it is possible to use a characteristic function to stop the interpreter from evaluating undefined functions. For example, write (x>0)*log(x) for a safe calculation of logarithms.

The conditional evaluation (cond ? expr1 : expr2) works as in the C programming language. If the condition is satisfied, the first expression is evaluated, otherwise the second expression. Thus the sign function could have been defined as

sign(x) = x<=0 ? (x<0 ? -1 : 0) : 1 .

Recursive definitions may be used if you make sure that the recursive expansion terminates. The faculty can be defined as

fac(x) = x<=0 ? 1 : x*fac(x-1) .

Note that because of rounding errors the above definition checks if the argument is less that or equal to zero.

© 2005
Xtremes Group · updated Jun 21, 2005