Skip to main content

Transitions

Transitions change the state. init sets up the initial states, and tran is the step the model takes again and again. A named transition runs only when another transition calls it with an inline call.

Declaring a Transition​

Declare a transition with tran, a name, parameters, and a body of operations:

class Counter {
var value: int := 0

tran increase(amount: int) {
value := value + amount
}
}

Parameters work as for properties, but a transition cannot write them. To change a parameter, copy it into a local variable.

The Implicit main and init​

A tran without a name is called main, and init is called init. Every class inherits an empty main and init from Anything, so declare your own with redefine:

class Counter {
var value: int := 0

redefine init {
value := 1
}

redefine tran {
value := value + 1
}
}

A verification case runs its own init and main, inherited or redefined, but not those of its parts. To run those of a part, call them, as inlining then expands:

class Holder {
contains counter: Counter

redefine init {
inline counter.init()
}

redefine tran {
inline counter.main()
}
}

Initial States​

The initial states are the states init reaches from the initial values of the variables. Use havoc in init to start from any value:

class Counter {
var value: int := 0

redefine init {
havoc(value) // value starts at any integer
}
}

If init blocks, the model has no states, so every AG property holds and no EF property does.

Branches with or​

Separate branches with or. Each run of the transition takes one of the branches that do not block:

class Counter {
var value: int := 0

tran step() {
value := value + 1
} or {
value := value - 1
}
}

This works like a choice around the whole body. init can have branches too, and each branch gives initial states.

Abstract Transitions​

An abstract transition has no body. Declare one with abstract in an abstract class:

abstract class Switch {
abstract tran toggle()
}