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.
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
maxfunction returns the value of its largest numeric argument. Each of its arguments should be a numeric expression.The syntax for this function is
(maxnumeric_expression numeric_expression … numeric_expression)Example:
CLIPS> (max 1. 3. 2. 1.9) 3.
Minimum numeric value
The
minfunction returns the value of its smallest numeric argument.The syntax for this function is
(minnumeric_expression numeric_expression … numeric_expression)Example:
CLIPS> (min 2.2 3.5 4.8 2.01) 2.01
Absolute value
The
absfunction returns the absolute value of its only argument. The argument should be a numeric expression.The syntax for this function is
(absnumeric_expression)Example:
CLIPS> (abs 2.3) 2.3 CLIPS> (abs -4.5) 4.5
Convert to float
The
floatfunction converts its only argument to type float and returns this value. The argument should be a numeric expression.The syntax for this function is
(floatnumeric_expression)Example:
CLIPS> (float 4) 4.0 CLIPS> (float -2.) -2.0
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-gradfunction 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-gradnumeric_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.
Function Returns acosarccosineacoshhyperbolic arccosineacotarccotangentacothhyperbolic arccotangentacscarccosecantacschhyperbolic arccosecantasecarcsecantasechhyperbolic arcsecantasinarcsineasinhhyperbolic arcsineatanarctangentatanhhyperbolic arctangentcoscosinecoshhyperbolic cosinecotcotangentcothhyperbolic cotangentcsccosecantcschhyperbolic cosecantsecsecantsechhyperbolic secantsinsinesinhhyperbolic sinetantangenttanhhyperbolic tangentExample:
CLIPS> (cos 0) 1.0 CLIPS> (acos 1.) 0.0
Convert from degrees to radians
The
deg-radfunction 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-radnumeric_expression)Example:
CLIPS> (deg-rad 180) 3.141592653589793
Convert from gradians to degrees
The
grad-degfunction 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-degnumeric_expression)Example:
CLIPS> (grad-deg 100) 90.0
Convert from radians to degrees
The
rad-degfunction 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-degnumeric_expression)Example:
CLIPS> (rad-deg 3.141592653589793) 180.0
Return the value of
The
pifunction returns the value ofas a float.
The syntax for this function is
(pi)Example:
CLIPS> (pi) 3.141592653589793
Square root
The
sqrtfunction returns the square root of its only argument as a float. The argument should be a numeric expression.The syntax for this function is
(sqrtnumeric_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
expfunction 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
(expnumeric_expression)Example:
CLIPS> (exp 2.) 7.3890560989306502
Natural logarithm
The
logfunction 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
(lognumeric_expression)Example:
CLIPS> (log 2.718281828459045) 0.9999999999999999
Base 10 logarithm
The
log10function 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
(log10numeric_expression)Example:
CLIPS> (log10 100) 2.0