The PRISM Language /

Expressions

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, true, false, etc.), identifiers (corresponding to variables, constants, etc.) and operators from the following list:

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. + and -) 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).

Built-in Functions

Expressions can make use of several built-in functions:

Examples of their usage are:

min(x+1, x_max)
max(a,b,c)
floor(13.5)
ceil(13.5)
round(13.5)
pow(2, 8)
pow(9.0, 0.5)
mod(1977, 100)
log(123, 2.71828183)

For compatibility with older versions of PRISM, all functions can also be expressed via the func keyword, e.g. func(floor, 13.5).

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:

[] (x>=1 & x<=10) -> x/10 : (x'=max(1,x-1)) + 1-x/10 : (x'=min(10,x+1))