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 (formatTRUEandFALSE) and floating point (format123.4,1.234e2and1.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) and logical-or (a || b). - Round brackets to specify the order of operations.
- The conditional expression
ifelse(condition, result_if_true, result_if_false). - The functions
exp(x): Euler's number raised to the power ofxlog(x): Natural logarithm ofxsqrt(x): The square root ofxabs(x): The absolute value ofxfloor(x): The greatest integer less than or equal toxceil(x): The smallest integer greater than or equal toxpow(x, y):xraised to the power ofymin(x, y): minimum ofxandymax(x, y): maximum ofxandysin(x): The sine ofxcos(x): The cosine ofxtan(x): The tangent ofxasin(x): The inverse sin ofxacos(x): The inverse cosine ofxatan(x): The inverse tangent ofxerf(x): The standard error function ofx
Symbols not defined here refer to variables in the HS\({}^3\) model.
The operator precedence and associativity is according 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.
Conditional expression may be evaluated in a lazy fashion (evaluating either result_if_true or result_if_false depending on the result of condition) or in an eager fashion (evaluating all of condition, result_if_true and result_if_false in arbitrary order). Evaluation strategy is left to the engine. This implies that on some engines, large trees of conditional expressions may have a high evaluation cost.
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.