Generic Expressions
Generic Expressions¶
This section details the HS\({}^3\) generic expression language. Expressions can be use to specify generic functions and generic distributions. The implementations that support generic expression must support:
- Literal integer (format
1234
), boolean (formatTRUE
andFALSE
) and floating point (format123.4
,1.234e2
and1.234E2
) values. - Literal values for \(\pi\) (
PI
) and Euler's number (EULER
). - The arithmetic operators addition (
x + y
), subtraction (x - y
), multiplication (x * y
), division (x / y
) and exponentiation (x^y
). - The comparison operators approximately-equal (
x == y
), exactly-equal (x === y
), not-approximately-equal (x != y
), not-exactly-equal (x !== y
), less-than (x < y
), less-or-equal (x <= y
), greater-than (x >= y
) and greater-or-equal (x >= y
). - The logical operators logical-inverse (
!a
), logical-and (a && b
), logical-or (a || b
), less-or-equal (a <= b
), greater-than (a >= b
) and greater-or-equal (a >= b
). - Round brackets to specify the order of operations.
- The ternary operator
condition ? result_if_true : result_if_false
- The functions
exp(x)
: Euler's number raised to the power ofx
log(x)
: Natural logarithm ofx
sqrt(x)
: The square root ofx
abs(x)
: The absolute value ofx
pow(x, y)
:x
raised to the power ofy
pow(x, y)
:x
raised to the power ofy
min(x, y)
: minimum ofx
andy
max(x, y)
: maximum ofx
andy
sin(x)
: The sine ofx
cos(x)
: The cosine ofx
tan(x)
: The tangent ofx
asin(x)
: The inverse sin ofx
acos(x)
: The inverse cosine ofx
atan(x)
: The inverse tangent ofx
Symbols not defined here refer to variables in the HS\({}^3\) model.
The operator precedence and associativity is acorrding to the common conventions.
Spaces between operators and operands are optional. There must be no space between a function name and the function arguments, spaces between function arguments are optional (f(a, b)
and f(a,b)
are correct but f (a, b)
is not allowed).
Division must be treated as floating-point division (i.e. 2/3
should be equivalent to 2.0/3.0
).
The approximately-equal (a == b
) and the not-approximately-equal operator (a != b
), should compare floating-point numbers to within a small multiple of the unit of least precision.
The behavior of any functions and operators not listed above is not defined, they are reserved for future versions of this standard. Implementations may support additional functions and operators as experimental features, but their use is considered non-standard and results in non-portable and potentially non-forward-compatible HS\({}^3\) documents.