A 12-hour clock is trivially simple — which makes it a perfect lens for the whole workflow: spec, invariant, liveness, and a deliberately introduced bug.
----------------------------- 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) =============================================================================
hr is always between 1 and 12 in every reachable state.
From hour 12, the clock eventually reaches 1 — it never stops ticking.
Weak fairness forbids stuttering forever while Next remains enabled.
The clock ticks around its 12 reachable states. Press Break Next to remove the wrap-around and watch TLC's invariant check catch the bug.
| Scenario | Properties checked | TLC output |
|---|---|---|
| Correct spec | TypeOK (safety) | No error — 12 distinct states, 12 reachable states found. |
| Correct spec | Live (liveness) | No error — fairness ensures the clock keeps advancing. |
Broken Next | TypeOK | Error — counterexample of length 13 ending at hr = 13. |
| No fairness clause | Live | Error — a stuttering behavior that stays at hr = 12 forever. |
Three ideas, one tiny module: safety (TypeOK), liveness (Live), and fairness (WF) — and each failure mode maps to a different, precise TLC diagnostic. This is the exact reasoning you scale up to distributed protocols like consensus or replication.