Constants, labels and formulas
Constants
PRISM models often contain constants, which can be used to parameterise some values within the model,
such as the range of a variable or the probability associated with an update.
These constants can then appear in expressions anywhere in the model.
For example, we can rewrite the earlier walk-var.prism with constants,
making it much easier to change the size of the random walk or its probabilities:
// Variant of a random walk
dtmc
// Max value of random walk
const int N = 3;
// Probability of increment
const double p = 0.5;
// Probability of changing y when incrementing
const double q = 0.2;
module M
x : [0..N] init 0;
y : [0..1] init 0;
[] y=0 & x<N -> 1-p:(x'=max(x-1,0)) + p*(1-q):(x'=x+1) + p*q:(x'=x+1)&(y'=1);
[] y=0 & x=N -> true;
[] y=1 -> (y'=0);
endmodule
Constants can be defined anywhere in a model file (but outside its modules) and can be of type integer, double or Boolean. The value of a constant can be specified as any constant expression of an appropriate type, and can also refer to the values of other constants. Examples of constant definitions are:
const int size = 10;
const double prob_fail = 1/size;
const bool enabled = true;
It is also possible to leave the values of one or more constants undefined, which allows them to be specified at the time of model checking, or to facilitate experiments over ranges of values:
const int size;
const double prob_fail = 1/size;
Labels
Models can be annotated with labels, which are used to identify sets of states that are of particular interest. Primarily, these are used when specifying properties and are in this sense synonymous with the notion of atomic propositions in temporal logic.
A label is defined by a Boolean expression, and its name is written using quotation marks ("..."), as illustrated in the following examples:
label "top" = x=N;
label "safe" = temp<=100 | alarm=true;
label "fail" = temp>100 & alarm=false;
Unlike constants, though, labels cannot be used to define other labels, and cannot appear in other parts of the model, such as guards or updates.
Formulas
The PRISM language supports formulas, which are used to avoid duplication of commonly repeated expressions within a model definition. A formula definition gives its name (a valid identifier) and an expression that defines it. The latter can be any valid expression, of arbitrary type, and including constants, variables or other formulas. The formula name can then be used as shorthand for the expression anywhere that an expression might usually be accepted. A formula is defined as follows:
formula num_tokens = q1+q2+q3+q4+q5;
It can then be used anywhere within that file, as for example in this command:
[] p1=2 & num_tokens=5 -> (p1'=4);
The effect is exactly as if the following had been typed:
[] p1=2 & (q1+q2+q3+q4+q5)=5 -> (p1'=4);
Formulas defined in a model can also be used when specifying its properties. Unlike labels, formulas can be of any type, not just Boolean, and their names are written without quotation marks.