Chapter
03
Meet TLC
Part I · Behaviors before syntax
Lessons
About
Kitchen Measures. You have a 3-cup jug, a 7-cup jug, a tap and a sink, and no markings on either jug. A recipe needs exactly 5 cups. Can you measure it, and how many moves does the shortest recipe take?
Here you write the puzzle in TLA+, let the model checker TLC search every state it can reach, and learn to read what TLC tells you and what it does not. A green result can mean "no state in this model breaks your claim" or "your model never got anywhere"; lesson 03-03 shows how to tell them apart.
The goals: run SANY and TLC with one command, write a .cfg, get counterexamples from invariants, read TLC's numbers, follow the witness rule, write TypeOK, and catch the checks you forgot to configure.
Before you start
- Chapters 01 and 02: states, steps, behaviors, and actions as formulas.
- A working
./tla doctor(seeSTART.md). - Time: the chapter page shows the estimate, generated from the lessons.
What else is here
specs/:KitchenMeasures,Thermostat, and the variants the lessons run.review/(03-review): a teammate's ice maker, and a cfg change that hides a bug.ai/1-type-only-safety/(03-ai1): an AI-written lift spec whose only invariant isTypeOK, and a message claiming safety.ai/2-correct-thermostat/(03-ai2): an AI-written heat pump. Decide, with evidence, whether its claim holds.gate/(03-gate): a vending machine's coin box;gate/twin/(03-gate-twin): a parking meter. The skeletons supply the variables,TypeOKand the action names.
Run it
From the repository root:
./tla check 03-01
./tla check 03-review
./tla check --gate 03Skills
intent (stating intent as properties), counterexamples (reading them), evidence (knowing what a check covers).
Elsewhere
- Web version: https://indicogni.com/learn/tla-plus/03-meet-tlc/
- Recaps:
CONCEPTS.md. Hints and explanation checks:HINTS.md. Predictions without answers:PREDICT.md. - Solutions:
solutions/chapters/03-meet-tlc/, including the gate references and their mutants. - Further reading: measuring with unmarked vessels is among the puzzles in Claude-Gaspard Bachet's Problèmes plaisants et délectables qui se font par les nombres, a collection first published in the seventeenth century and reprinted many times. The MacTutor essay on Bachet (https://mathshistory.st-andrews.ac.uk/Strick/bachet.pdf) lists it as "Transferring liquids". This version, its names and its constants are the course's own. The best-known TLA+ version of the puzzle is the "Die Hard" lecture of Lamport's TLA+ Video Course, with other jug sizes and another goal; watch it after this chapter, because it walks through the same search.
Beyond the lessons
- 03-review Review a teammate’s spec ·
chapters/03-meet-tlc/review/·./tla check 03-review - 03-ai1 AI item ·
chapters/03-meet-tlc/ai/1-type-only-safety/·./tla check 03-ai1 - 03-ai2 AI item ·
chapters/03-meet-tlc/ai/2-correct-thermostat/·./tla check 03-ai2 - 03-gate Gate ·
./tla check --gate 03Hints
Hint 1
Write
InsertCoinandRefundfirst. Each changes onlycredit; the other three variables areUNCHANGED. Run your cfg after each.Hint 2
Dispensechanges all four variables. Write its guard from the requirement's "when" sentence and its effect from the "drops one item and moves the credit" sentence. Write every new value in terms of the old, unprimed values: an action is an equation about two states, not a sequence of assignments.Hint 3 (nearly the answer; opening it marks a pass as "passed with help")
Safetyrelates two variables: the coins in the box and the number of items sold. Ask how many coins the box must hold after one sale, and after two. - 03-gate-twin Gate twin, another domain ·
./tla check --gate 03 --twinHints
Hint 1
Write
FeedCoinandCancelfirst. Each changes onlypaid; the other three variables areUNCHANGED. Run your cfg after each.Hint 2
PrintTicketchanges all four variables. Write its guard from the requirement's "when" sentence and its effect from the "prints one ticket and moves the payment" sentence. Write every new value in terms of the old, unprimed values: an action is an equation about two states, not a sequence of assignments.Hint 3 (nearly the answer; opening it marks a pass as "passed with help")
Safetyrelates two variables: the coins in the cash box and the number of tickets printed. Ask how many coins the cash box must hold after one ticket, and after two.