The Temporal Logic of Actions

TLA+ is not a programming language. It's a mathematical formalism for describing what a system is — and reasoning about it with the same rigor as a proof.

Behaviors and states

The universe of TLA+ is the behavior: an infinite sequence of states. A state is an assignment of values to the system's variables. A behavior is one possible history of the system.

s0
x = 0
→
s1
x = 1
→
s2
x = 2
→
s3 (stutter)
x = 2
→
s4
x = 3
→ …
A behavior: states advance one step at a time. Note the stuttering step, where nothing changes — TLA+ permits these, and they're essential for refinement.

Actions

A step is a pair of consecutive states. An action is a formula over two states, written with primed variables: the unprimed x is the value now, the primed x′ is the value next.

Inc ≡ x′ = x + 1     \* the action: "add 1 to x"

A system where nothing may ever happen would satisfy Inc trivially — which is why TLA+ builds stuttering into every spec's safety part.

A spec is a single formula

Every TLA+ specification has the same shape. It's the "standard form":

Spec ≡ Init ∧ □[Next]_vars ∧ Fairness
ComponentMeaning
InitA state predicate: where the system may start.
□[Next]_varsEvery step is either a Next step or a stuttering step. This is the safety part.
FairnessConditions like WF_vars(A) (weak fairness) forcing progress. This is the liveness part.
Why stuttering matters

Without allowing stuttering, a fine-grained spec could never be compared to a coarser one. Stuttering is what makes refinement — proving one spec implements another — expressible as simple implication.

Safety vs. liveness

SafetyLiveness
QuestionWhat may happen?What must eventually happen?
Form□P — always P (invariants)◇Q, P ⇗ Q — eventually Q, leads-to
Checked byState invariantsTemporal formulas + fairness
ViolationFinite bad state (a counterexample)Infinite stuttering trace (a livelock)

PlusCal: an algorithm language

Writing actions directly is powerful but terse. PlusCal is a pseudocode-style language — with processes, labels, while, and await — that compiles to TLA+. You write the algorithm; the translator generates the actions and the spec.

---algorithm Clock
variable hr = 1;
begin
  Tick:
    while TRUE do
      hr := IF hr # 12 THEN hr + 1 ELSE 1;
    end while;
end algorithm

The TLA+ translator turns this into the Init/Next actions plus a Spec — and you model-check the result exactly as if you'd written the logic by hand.

A complete TLA+ module

The classic HourClock from Lamport's Specifying Systems — minimal, but it demonstrates every idea above.

----------------------------- MODULE HourClock -----------------------------
EXTENDS Naturals, TLC

VARIABLE hr

Init     ==  hr \in 1..12
Next     ==  hr′ = IF hr # 12 THEN hr + 1 ELSE 1
TypeOK   ==  hr \in 1..12
Live     ==  hr = 12 ~> hr = 1

Spec     ==  Init /\ [][Next]_hr /\ WF_hr(Next)
=============================================================================

Without the fairness clause, TLC would find a valid behavior that stutters at hr = 12 forever — a livelock. See this explored on the worked example page.

Made with Aii CloudReport