
Khoros(Expressions)          Khoros           Khoros(Expressions)

     STANDARD FUNCTIONS

     Standard functions recognized by the Khoros expression
     parser include:

     "sin"         sin(x)          sine of x
     "cos"         cos(x)          cosine of x
     "tan"         tan(x)          tangent of x

     "sinh"        sinh(x)         hyperbolic sine of x
     "cosh"        cosh(x)         hyperbolic cosine of x
     "tanh"        tanh(x)         hyperbolic tangent of x

     "asin"        asin(x)         arc sine of x (range -J/2 to J/2)
     "acos"        acos(x)         arc cosine of x (range 0 to J)
     "atan"        atan(x)         arc tangent of x (range -J/2 to J/2)
     "atan2"       atan(y,x)       arc tangent of y/x (range -pi to pi)

     "sqrt"        sqrt(x)         square root of x
     "hypot"       hypot(x,y)      Euclidean distance (returns  sqrt(x*x + y*y))
     "exp"         exp(x)          exponential function of x
     "expm1"       expm1(x)        (exp(x) - 1) even for small x
     "ln"          ln(x)           natural log of x
     "log10"       log10(x)        log base 10 of x
     "log1p"       log1p(x)        log(1+x) even for small x
     "gamma"       gamma(x)        log gamma function of x

     "abs"         abs(x)          absolute value of |x|
     "floor"       floor(x)        largest integer not greater than x
     "ceil"        ceil(x)         smallest integer not less than x
     "rint"        rint(x)

     "pow"         pow(x,y)        x raised to the power of y
     "fact"        fact(x)         integer factorial of x
     "gnoise"      gnoise(x)       gaussian noise function
     "unoise"      unoise(x)       uniform noise function
     "impulse"     impulse(x)      impulse function
     "step"        step(x)         unit step function
     "sign"        sign(x)         sign function

     "j0"          j0(x)           bessel functions
     "j1"          j1(x)           bessel functions
     "y0"          y0(x)           bessel functions
     "y1"          y1(x)           bessel functions

     "erfc"        erfc(x)         error function for 1.0 - erf(x)
     "erf"         erf(x)          error function of x
          where erf(x) = 2/sqrt(pi)*integral from 0 to x of exp(-t*t) dt.

     INSTRUCTION or STATEMENTS

     Currently there is only one type of instruction, an
     "IF/ELSE" instruction.  An if/else expression can be entered
     two ways.  The following example sets "i" performs a modulo
     increment of the variable i, (i = (i+1)%11).

     1)   The first is the standard C style if statement.
                i = if (i > 10) 0 else i + 1

     2)   The second is an internal C style if statement.
          i = (i > 10) ? 0 : i + 1

     USER DEFINED FUNCTIONS  (cantata only)

     Users may also define there own function similar to defining
     variables.  In some instances this proves to be easier than
     trying to keep track of many dependent expressions or
     evaluating complex expressions.  For instance:

          f(x,y)= cos(sqrt(x**2+y**2))*exp(0.0-sqrt(x**2+y**2)/4)

     To examine the above expression at x = 0 & y = 0 you simple
     enter f(0,0) which should result in the value of "1.0".  You
     may also enter expressions as well as variables in evaluat-
     ing the function "f".  Meaning that it is valid to enter
     f(-pi*2,2+x) to be evaluated.  Also, since x & y are defined
     by the function then any local definition of these variable
     will be ignored.  Which also implies that if you enter an
     expression that is dependent on a variable not defined
     within the function then the current variable list will be
     searched.

          f(x) = x + z

     The variable z is not defined by the function "f" so the
     current variable list will be searched (if the variable is
     not defined then an error will be displayed).

     Recursive definitions are allowed but be careful to under-
     stand that there are no checks on the stack size, therefore
     it is very easy to core dump the current application.  In
     any recursive function you need to make sure that the recur-
     sive expression has a base case, thus preventing a stack
     overflow from occurring.  The proper way to do a Fibonacci
     sequence is to enter the following expression:

          fib(n) = (n == 0 || n == 1) ? n : fib(n-1) + fib(n-2)

     Therefore the Fibonacci sequence of 10 "fib(10)" should
     return 55.  The base case occurs when n equals 0 or 1.  But
     if the user enters fib(-2) this will cause an stack over-
     flow.  Therefore,

          fib(n) = (n > 1) ? fib(n-1) + fib(n-2) : n

     should prevent the application from crashing, although this
     is not the strict definition of a Fibonacci definition.

     Copyright 1991, University of New Mexico. All rights
     reserved.

Khoros                    Release: 1.0                          1

