Expressions

Expressions appear in guards, effects, invariants, properties, pattern constraints and behavior guards.

Operators (lowest to highest binding)#

LevelOperatorsDescription
1<=>Biconditional
2=>Implication (left-associative)
3||, orDisjunction
4&&, andConjunction
5!, notNegation (prefix)
6== != < <= > >= in subset and the bit-vector comparisons <u <=u >u >=u <s <=s >s >=sComparison (non-associative)
7+ -Addition, subtraction
8* / % *u /u %u *s /s %sMultiplication, division, remainder
9& | ^Bitwise and, or, xor
10<< >> >>>Shifts
11- ~Unary minus, bitwise complement (prefix)
Two surprises
! 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#

SPL
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#

SPL
if x > 0 then x else -x

Lambda#

SPL
lambda(x : Int) => x * 2

Field, indexed and call access#

SPL
node.state
balances[from]
f(x, y)
Memory<8>(addr)     // multi-byte read, see Bit-vector Operations
Known limitation
Chained indexing grid[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.

Known limitation
In an expression, a field chain keeps only its last base: 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#

SPL
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.

↑ ↓ to moveEnter to openEsc to close