The definition of the
area constant, in the example above, uses an expression.
We now define more precisely what types of expression are supported by PRISM.
Expressions can contain literal values (12, 3.141592,
identifiers (corresponding to variables, constants, etc.) and operators from the following list:
condition ? a : bmeans "if
conditionis true then
All of these operators except
? are left associative
(i.e. they are evaluated from left to right).
The precedence of the operators is as found in the list above,
most strongly binding operators first.
Operators on the same line (e.g.
-) are of equal precedence.
Much of the notation for expressions is hence essentially equivalent to that of C/C++ or Java.
One notable exception to this is that the division operator
/ always performs floating point, not integer, division,
i.e. the result of
22/7 is 3.142857... not 3.
All expressions must evaluate correctly in terms of type (integer, double or Boolean).
Expressions can make use of several built-in functions:
max(...), which select the minimum and maximum value, respectively, of two or more numbers;
ceil(x), which round
xdown and up, respectively, to the nearest integer;
xto the power of
mod(i,n)for integer modulo operations;
log(x,b), which computes the logarithm of
Examples of their usage are:
For compatibility with older versions of PRISM, all functions can also be expressed via the
func keyword, e.g.
Use of Expressions
Expressions can be used in a wide range of places in a PRISM language description, e.g.:
This allows, for example, the probability in a command to be dependent on the current state: