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.
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.
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.
Every TLA+ specification has the same shape. It's the "standard form":
Spec ≡ Init ∧ □[Next]_vars ∧ Fairness
| Component | Meaning |
|---|---|
Init | A state predicate: where the system may start. |
□[Next]_vars | Every step is either a Next step or a stuttering step. This is the safety part. |
Fairness | Conditions like WF_vars(A) (weak fairness) forcing progress. This is the liveness part. |
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 | Liveness | |
|---|---|---|
| Question | What may happen? | What must eventually happen? |
| Form | □P — always P (invariants) | ◇Q, P ⇗ Q — eventually Q, leads-to |
| Checked by | State invariants | Temporal formulas + fairness |
| Violation | Finite bad state (a counterexample) | Infinite stuttering trace (a livelock) |
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.
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) =============================================================================
Init starts the clock anywhere in 1..12 — a set of 12 possible initial states.Next either increments or wraps from 12 to 1.TypeOK is an invariant: every reachable state must keep hr in range.Live is a liveness property: from hour 12 the clock must eventually reach 1 — which only holds because of weak fairness 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.