Expressions
Expressions appear in guards, effects, invariants, properties, pattern constraints and behavior guards.
Operators (lowest to highest binding)#
| Level | Operators | Description |
|---|---|---|
| 1 | <=> | Biconditional |
| 2 | => | Implication (left-associative) |
| 3 | ||, or | Disjunction |
| 4 | &&, and | Conjunction |
| 5 | !, not | Negation (prefix) |
| 6 | == != < <= > >= in subset and the bit-vector comparisons <u <=u >u >=u <s <=s >s >=s | Comparison (non-associative) |
| 7 | + - | Addition, subtraction |
| 8 | * / % *u /u %u *s /s %s | Multiplication, division, remainder |
| 9 | & | ^ | Bitwise and, or, xor |
| 10 | << >> >>> | Shifts |
| 11 | - ~ | Unary minus, bitwise complement (prefix) |
! binds looser than the comparisons: !a == b is !(a == b). And the bitwise operators bind tighter than * and +: a * b & c is a * (b & c). Parenthesise when in doubt.
See Operator Precedence for associativity and the behavior operators.
Quantifiers and sums#
forall (x : Int) in [0..n) . body
exists (x : Int) in [0..n) . body
sum (k : Int) in [0..n) . weight[k]The range [lo..hi) is half-open ([0..n) is 0, 1, …, n-1) and optional. The . separates the binding from the body. sum is a quantifier keyword, not a function.
Conditional expression#
if x > 0 then x else -xLambda#
lambda(x : Int) => x * 2Field, indexed and call access#
node.state
balances[from]
f(x, y)
Memory<8>(addr) // multi-byte read, see Bit-vector Operationsgrid[i][j] parses, but to an internal call that nothing evaluates, so its value is unconstrained. Use a one-dimensional index such as grid[i * n + j].
A qualified name such as libc.last_alloc_ptr is a field access as well; the AArch64 front end uses these names for the library state of a trace model.
a.b.c is read as field c of b, and Cache(i).state as field state of Cache — the arguments (i) are dropped. On the left of :=, Cache(i).state keeps its arguments. Prefer an indexed attribute (state[i]) when an expression must select an instance.
Literals#
Integers (42, 0xFF, 0b1010), reals (3.14, 1.0e3), Booleans, strings ("text") and typed bit-vector literals (0xff:BV<8>). See Types for the limits.
Example#
schema Ledger {
attributes {
n : Int = 4 ;
balance : Array(Int, 4) ;
total : Int = 0 ;
}
invariants {
forall (i : Int) in [0..n) . balance[i] >= 0 ;
total == sum (k : Int) in [0..n) . balance[k] ;
!(total < 0) ;
}
}The invariants of this schema are parsed but not checked today (see Schemas); state them as system properties to have them checked.