32.2.4. Mathematical Functions

CLIPS provides a number of functions for mathematical computation. They are split into two packages: a set of standard functions, and a set of extended functions.

32.2.4.1. Standard Mathematical Functions

The following are the standard mathematical functions. These functions should be used only on numerical arguments. You will see an error message if a string argument is passed to a math function.

  • Addition

    The + function returns the sum of its arguments (possibly more than two). Each of its arguments should be a numeric expression.

    The syntax for this function is

    (+ numeric_expression numeric_expression … numeric_expression )

    Example:

    CLIPS> (+ 2. 3.)
    5.
    CLIPS> (+ 2. 3. 4.)
    9.
  • Subtraction

    The - function returns the value of the first argument minus the sum of the all subsequent arguments. Each of its arguments should be a numeric expression.

    The syntax for this function is

    (- numeric_expression numeric_expression … numeric_expression )

    Example:

    CLIPS> (- 2. 3.)
    -1.
    CLIPS> (- 12. 3. 4.)
    5.
  • Multiplication

    The * function returns the product of its arguments. Each of its arguments should be a numeric expression.

    The syntax for this function is

    (* numeric_expression numeric_expression … numeric_expression )

    Example:

    CLIPS> (* 2. 3.)
    6.
    CLIPS> (* 2. 3. 4.)
    24.
  • Division

    The / function returns the value of the first argument divided by the product of the subsequent arguments. Each of its arguments should be a numeric expression.

    The syntax for this function is

    (/ numeric_expression numeric_expression … numeric_expression )

    Example:

    CLIPS> (/ 6. 3.)
    2.
    CLIPS> (/ 12. 3. 4.)
    1.
  • Maximum numeric value

    The max function returns the value of its largest numeric argument. Each of its arguments should be a numeric expression.

    The syntax for this function is

    (max numeric_expression numeric_expression … numeric_expression )

    Example:

    CLIPS> (max 1. 3. 2. 1.9)
    3. 
    
  • Minimum numeric value

    The min function returns the value of its smallest numeric argument.

    The syntax for this function is

    (min numeric_expression numeric_expression … numeric_expression )

    Example:

    CLIPS> (min 2.2 3.5 4.8 2.01)
    2.01 
    
  • Absolute value

    The abs function returns the absolute value of its only argument. The argument should be a numeric expression.

    The syntax for this function is

    (abs numeric_expression )

    Example:

    CLIPS> (abs 2.3)
    2.3 
    CLIPS> (abs -4.5)
    4.5 
    
  • Convert to float

    The float function converts its only argument to type float and returns this value. The argument should be a numeric expression.

    The syntax for this function is

    (float numeric_expression )

    Example:

    CLIPS> (float 4)
    4.0 
    CLIPS> (float -2.)
    -2.0 
    

32.2.4.2. Extended Mathematical Functions

In addition to standard mathematical functions, CLIPS also provides a large number of scientific and trigonometric functions for more extensive computations.

  • Convert from degrees to gradians

    The deg-grad function converts its only argument from units of degrees to units of gradians. That is, it multiplies the argument by a factor of . The return value of this function is a float. The argument should be a numeric expression.

    The syntax for this function is

    (deg-grad numeric_expression )

    Example:

    CLIPS> (deg-grad 90)
    100.0 
    
  • Trigonometric functions

    The following functions take a single numeric argument and return a floating-point number. The argument is expected in radians.

    FunctionReturns
    acos arccosine
    acosh hyperbolic arccosine
    acot arccotangent
    acoth hyperbolic arccotangent
    acsc arccosecant
    acsch hyperbolic arccosecant
    asec arcsecant
    asech hyperbolic arcsecant
    asin arcsine
    asinh hyperbolic arcsine
    atan arctangent
    atanh hyperbolic arctangent
    cos cosine
    cosh hyperbolic cosine
    cot cotangent
    coth hyperbolic cotangent
    csc cosecant
    csch hyperbolic cosecant
    sec secant
    sech hyperbolic secant
    sin sine
    sinh hyperbolic sine
    tan tangent
    tanh hyperbolic tangent

    Example:

    CLIPS> (cos 0)
    1.0 
    CLIPS> (acos 1.)
    0.0 
    
  • Convert from degrees to radians

    The deg-rad function converts its only argument from units of degrees to units of radians. That is, it multiplies the argument by a factor of . The return value of this function is a float. The argument should be a numeric expression.

    The syntax for this function is

    (deg-rad numeric_expression )

    Example:

    CLIPS> (deg-rad 180)
    3.141592653589793 
    
  • Convert from gradians to degrees

    The grad-deg function converts its only argument from units of gradians to units of degrees. That is, it multiplies the argument by a factor of . The return value of this function is a float. The argument should be a numeric expression.

    The syntax for this function is

    (grad-deg numeric_expression )

    Example:

    CLIPS> (grad-deg 100)
    90.0 
    
  • Convert from radians to degrees

    The rad-deg function converts its only argument from units of radians to units of degrees. That is, it multiplies the argument by a factor of . The return value of this function is a float. The argument should be a numeric expression.

    The syntax for this function is

    (rad-deg numeric_expression )

    Example:

    CLIPS> (rad-deg 3.141592653589793)
    180.0 
    
  • Return the value of

    The pi function returns the value of as a float.

    The syntax for this function is

    (pi)

    Example:

    CLIPS> (pi)
    3.141592653589793 
    
  • Square root

    The sqrt function returns the square root of its only argument as a float. The argument should be a numeric expression.

    The syntax for this function is

    (sqrt numeric_expression )

    Example:

    CLIPS> (sqrt 9)
    3.0 
    
  • Power

    The power function (**) returns the value of its first argument raised to the power of its second argument. The arguments should be numeric expressions. The return value is a float.

    The syntax for this function is

    (** numeric_expression numeric_expression )

    Example:

    CLIPS> (** 2 3)
    8.0 
    
  • Exponential function

    The exp function evaluates the exponential function (where is the base of the natural logarithm, ) at the value of the function’s only argument, and returns the result as a float. The argument should be a numeric expression.

    The syntax for this function is

    (exp numeric_expression )

    Example:

    CLIPS> (exp 2.)
    7.3890560989306502 
    
  • Natural logarithm

    The log function evaluates the natural logarithm at the value of the function’s only argument and returns the result as a float. The argument should be a numeric expression.

    The syntax for this function is

    (log numeric_expression )

    Example:

    CLIPS> (log 2.718281828459045)
    0.9999999999999999 
    
  • Base 10 logarithm

    The log10 function evaluates the base 10 logarithm at the value of the function’s only argument and returns the result as a float. The argument should be a numeric expression.

    The syntax for this function is

    (log10 numeric_expression )

    Example:

    CLIPS> (log10 100)
    2.0