Appendix 1: Formula Input

Appendix 1: Formula Input#

When formula input is specified, enter functions as formulas. The final function definition in an input must define the function used by that input. The input format resembles C/C++. The rules are described below.

  1. Comment Lines

    A comment line begins with *.

  2. Formula Separators

    Use ; (a semicolon) to separate formulas. Multiple formulas may appear on one line, and a formula may span multiple lines.

  3. End of Formula Input

    End formula input with ;; (two semicolons).

  4. Constants

    Constants are signed or unsigned integer constants and floating-point constants. Do not include spaces within a constant.

    Examples: 123, -123, 123., 0.123, 1.23e4, -1.23e-4, 1.23E04, -1.23E+004

    Not supported: 1.23+5, 1.23d5, 1.23D-5, 1.23 e-4

  5. Variables

    A variable is a contiguous string beginning with an alphabetic character (uppercase or lowercase). Variable names are case-sensitive and may contain digits. No special characters other than _ (underscore) are allowed. Use no more than 19 characters. PI is reserved for the circular constant.

    Examples: ABC, abc, Abc, A123, a123, a_123

    Not supported: 1abc, a-123, abc#123

  6. Expressions

    The following standard expressions are available. Operator precedence follows the usual rules. Operands are constants, variables, and functions.

    • +: addition

    • -: subtraction

    • *: multiplication

    • /: division (performed using real-number values)

    • **: exponentiation

    • (): grouping with parentheses

    Examples: a+b-c*d/e, -a*(b + c)**d, 2**-5

    Not supported: (-2.)**5.

  7. Library Functions

    The following library functions are available. Their definitions and domains are the same as in the C/C++ language standard. When using these functions, ensure that their arguments are within the applicable domains.

    Available functions: sin, cos, tan, asin, acos, atan, atan2, sinh, cosh, tanh, asinh, acosh, atanh, sqrt, exp, log, log10

  8. Assignment Statements

    The left-hand side is a variable, and the right-hand side is a constant or an expression. Except for variables designated as input variables, all variables must have been assigned a value before this assignment statement.

    Examples#
    a=1.23;
    b=sin(a*PI/180);
    
  9. Function Definitions

    You can define a function whose inputs are variables designated as input variables.

    Examples#
    a=1.23; b=a+5;
    f(x)=a*x+sin(b*x**2);
    g(x,t) = f(x)**2+t;
    
    Not supported#
    a=sin(x); f(x)=a**3;;
    

    The preceding example is valid when written as a(x)=sin(x); f(x)=a(x)**3;;.

  10. Function Definition Domain

    You can define the variable range of a function as follows. Use < (less than) and <= (less than or equal to) in range definitions. > and >= are not supported. The value is zero outside the defined range. You can add together piecewise-defined functions.

    Example 1#
     [x<-10] f1(x)=5*x;
     [-10<=x<=10] f2(x)=10*x**2;
     [10<x] f3(x)=x**3;
     f(x)=f1(x)+f2(x)+f3(x);;
    
    Example 2#
     a=5; b=10;
     [a<=x][b<y] f(x,y)=x*y;;