This is a refrence page for the Mathmatical and Logical expressions that can be used in SimLab Training Builder.
Content:
- Section 01 - Capabilities
- Section 02 - Example Expressions
- Section 03 - Built-In Operations & Functions
Section 1 - CAPABILITIES:
The ExprTk expression evaluator supports the following fundamental arithmetic operations, functions and processes:
- Basic operators:
+, -, *, /, %, ^ - Equalities & Inequalities:
=, ==, <>, !=, <, <=, >, >= - Logic operators:
and, mand, mor, nand, nor, not, or, shl, shr, xnor, xor, true, false - Functions:
abs, avg, ceil, clamp, equal, erf, erfc, exp, expm1, floor, frac, log, log10, log1p, log2, logn, max, min, mul, ncdf, not_equal, root, round, roundn, sgn, sqrt, sum, swap, trunc - Trigonometry:
acos, acosh, asin, asinh, atan, atanh, atan2, cos, cosh, cot, csc, sec, sin, sinc, sinh, tan, tanh, hypot, rad2deg, deg2grad, deg2rad, grad2deg - String processing:
in, like, ilike, concatenation
Section 2 - EXAMPLE EXPRESSIONS:
The following is a short listing of infix format based mathematical expressions that can be parsed and evaluated using the ExprTk library.
-
sqrt(1 - (3 / x^2)) -
clamp(-1, sin(2 * pi * x) + cos(y / 2 * pi), +1) -
sin(2.34e-3 * x) -
inrange(-2,m,+2) == if(({-2 <= m} and [m <= +2]),1,0) -
({1/1}*[1/2]+(1/3))-{1/4}^[1/5]+(1/6)-({1/7}+[1/8]*(1/9)) -
a * exp(2.2 / 3.3 * t) + c -
2x + 3y + 4z + 5w == 2 * x + 3 * y + 4 * z + 5 * w -
3(x + y) / 2.9 + 1.234e+12 == 3 * (x + y) / 2.9 + 1.234e+12 -
(x + y)3.3 + 1 / 4.5 == [x + y] * 3.3 + 1 / 4.5 -
(x + y[i])z + 1.1 / 2.7 == (x + y[i]) * z + 1.1 / 2.7 -
(sin(x / pi) cos(2y) + 1) == (sin(x / pi) * cos(2 * y) + 1) -
75x^17 + 25.1x^5 - 35x^4 - 15.2x^3 + 40x^2 - 15.3x + 1 -
(avg(x,y) <= x + y ? x - y : x * y) + 2.345 * pi / x -
x <= 'abc123' and (y in 'AString') or ('1x2y3z' != z) -
((x + 'abc') like '*123*') or ('a123b' ilike y) -
sgn(+1.2^3.4z / -5.6y) <= {-7.8^9 / -10.11x }
Section 3 - BUILT-IN OPERATIONS FUNCTIONS:
- Arithmetic Operators
OPERATOR DEFINITION EXAMPLE + Addition between x and y. x + y- Subtraction between x and y. x - y* Multiplication between x and y. x * y/ Division between x and y. x / y% Modulus of x with respect to y. x % y^ x to the power of y. x ^ y - Equalities & Inequalities
OPERATOR DEFINITION EXAMPLE == or = True only if x is strictly equal to y. x == y<> or != True only if x does not equal y. x <> y or x != y< True only if x is less than y. x < y<= True only if x is less than or equal to y. x <= y> True only if x is greater than y. x > y>= True only if x greater than or equal to y. x >= y - Boolean Operations
OPERATOR DEFINITION EXAMPLE true True state or any value other than zero (typically 1). false False state, value of exactly zero. and Logical AND, True only if x and y are both true. x and ymand Multi-input logical AND, True only if all inputs are true. Left to right short-circuiting of expressions. mand(x > y, z < w, u or v, w and x)mor Multi-input logical OR, True if at least one of the inputs are true. Left to right short-circuiting of expressions. mor(x > y, z < w, u or v, w and x)nand Logical NAND, True only if either x or y is false. x nand ynor Logical NOR, True only if the result of x or y is false x nor ynot Logical NOT, Negate the logical sense of the input. not(x and y) == x nand yor Logical OR, True if either x or y is true. x or yxor Logical XOR, True only if the logical states of x and y differ. x xor yxnor Logical XNOR, True iff the biconditional of x and y is satisfied. x xnor y& Similar to AND but with left to right expression short circuiting optimisation. (x & y) == (y and x)| Similar to OR but with left to right expression short circuiting optimisation. (x | y) == (y or x) - General Purpose Functions
FUNCTION DEFINITION EXAMPLE random Generate a random number between 0 and 1. random()abs Absolute value of x. abs(x)avg Average of all the inputs. avg(x,y,z,w,u,v) == (x + y + z + w + u + v) / 6ceil Smallest integer that is greater than or equal to x. clamp Clamp x in range between r0 and r1, where r0 < r1. clamp(r0,x,r1)equal Equality test between x and y using normalised epsilon erf Error function of x. erf(x)erfc Complimentary error function of x. erfc(x)exp e to the power of x. exp(x)expm1 e to the power of x minus 1, where x is very small. expm1(x)floor Largest integer that is less than or equal to x. floor(x)frac Fractional portion of x. frac(x)hypot Hypotenuse of x and y hypot(x,y) = sqrt(x*x + y*y)iclamp Inverse-clamp x outside of the range r0 and r1. Where r0 < r1. If x is within the range it will snap to the closest bound. iclamp(r0,x,r1)inrange In-range returns 'true' when x is within the range r0 and r1. Where r0 < r1. inrange(r0,x,r1)log Natural logarithm of x. log(x)log10 Base 10 logarithm of x. log10(x)log1p Natural logarithm of 1 + x, where x is very small. log1p(x)log2 Base 2 logarithm of x. log2(x)logn Base N logarithm of x. where n is a positive integer. logn(x,8)max Largest value of all the inputs. max(x,y,z,w,u,v)min Smallest value of all the inputs. min(x,y,z,w,u)mul Product of all the inputs. mul(x,y,z,w,u,v,t) == (x * y * z * w * u * v * t)ncdf Normal cumulative distribution function. ncdf(x)not_equal Not-equal test between x and y using normalised epsilon pow x to the power of y. pow(x,y) == x ^ yroot Nth-Root of x. where n is a positive integer. root(x,3) == x^(1/3)round Round x to the nearest integer. (eg: round(x)) roundn Round x to n decimal places (eg: roundn(x,3)) where n > 0 and is an integer. roundn(1.2345678,4) == 1.2346sgn Sign of x, -1 where x < 0, +1 where x > 0, else zero. sgn(x)sqrt Square root of x, where x >= 0. sqrt(x)sum Sum of all the inputs. sum(x,y,z,w,u,v,t) == (x + y + z + w + u + v + t)swap <=> Swap the values of the variables x and y and return the current value of y. swap(x,y) or x <=> ytrunc Integer portion of x. trunc(x) - Trigonometry Functions
FUNCTION DEFINITION EXAMPLE acos Arc cosine of x expressed in radians. Interval [-1,+1] acos(x)acosh Inverse hyperbolic cosine of x expressed in radians. acosh(x)asin Arc sine of x expressed in radians. Interval [-1,+1] asin(x)asinh Inverse hyperbolic sine of x expressed in radians. asinh(x)atan Arc tangent of x expressed in radians. Interval [-1,+1] atan(x)atan2 Arc tangent of (x / y) expressed in radians. [-pi,+pi] atan2(x,y)atanh Inverse hyperbolic tangent of x expressed in radians. atanh(x)cos Cosine of x. cos(x)cosh Hyperbolic cosine of x. cosh(x)cot Cotangent of x. cot(x)csc Cosecant of x. csc(x)sec Secant of x. sec(x)sin Sine of x. sin(x)sinc Sine cardinal of x. sinc(x)sinh Hyperbolic sine of x. sinh(x)tan Tangent of x. tan(x)tanh Hyperbolic tangent of x. tanh(x)deg2rad Convert x from degrees to radians. deg2rad(x)deg2grad Convert x from degrees to gradians. deg2grad(x)rad2deg Convert x from radians to degrees. rad2deg(x)grad2deg Convert x from gradians to degrees. grad2deg(x) - String Processing
FUNCTION DEFINITION EXAMPLE = , ==
!=, <>
<=, >=
< , >All common equality/inequality operators are applicableto strings and are applied in a case sensitive manner.
In the following example x, y and z are of type string.not((x <= 'AbC') and ('1x2y3z' <> y)) or (z == x)in True only if x is a substring of y. x in y or 'abc' in 'abcdefgh'like True only if the string x matches the pattern y.
Available wildcard characters are '*' and '?' denoting zero or more and zero or one matches respectively.x like y or 'abcdefgh' like 'a?d*h'ilike True only if the string x matches the pattern y in a case insensitive manner. Available wildcard characters are '*' and '?' denoting zero or more and zero or one matches respectively. x ilike y or 'a1B2c3D4e5F6g7H' ilike 'a?d*h'[r0:r1] The closed interval [r0,r1] of the specified string. Given a string x with a value of 'abcdefgh' then:
x[1:4] == 'bcde'x[ :5] == x[:10 / 2] == 'abcdef'x[2 + 1: ] == x[3:] =='defgh'x[ : ] == x[:] == 'abcdefgh'x[4/2:3+2] == x[2:5] == 'cdef'
Note: Both r0 and r1 are assumed to be integers, where r0 <= r1. They may also be the result of an expression, in the event they have fractional components truncation will be performed. (eg: 1.67 --> 1)
+ Concatenation of x and y. Where x and y are strings or string ranges. x + yx + 'abc'x + y[:i + j]x[i:j] + y[2:3] + '0123456789'[2:7]'abc' + x + y'abc' + '1234567'(x + 'a1B2c3D4' + y)[i:2j]
<=> Swap the values of x and y. Where x and y are mutable strings. (eg: x <=> y) [] The string size operator returns the size of the string being actioned. 'abc'[] == 3var max_str_length := max(s0[],s1[],s2[],s3[])('abc' + 'xyz')[] == 6(('abc' + 'xyz')[1:4])[] == 4
- Control Structures
STRUCTURE DEFINITION Example if If x is true then return y else return z. if (x, y, z)if ((x + 1) > 2y, z + 1, w / v)if (x > y) z;if (x <= 2*y) { z + w };
switch The first true case condition that is encountered will determine the result of the switch.
If none of the case conditions hold true, the default action is assumed as the final return value.
This is sometimes also known as a multi-way branch mechanism.switch
{
case x > (y + z) : 2 * x / abs(y - z);
case x < 3 : sin(x + y);
default : 1 + x;
}?: Ternary conditional statement, similar to that of the above denoted if-statement. x ? y : zx + 1 > 2y ? z + 1 : (w / v)min(x,y) > z ? (x < y + 1) ? x : y : (w * v)
Note: In the tables above, the symbols x, y, z, w, u and v where appropriate may represent any of one the following:
- Literal numeric/string value
- Number variable
- string variable