03-03
Break it on purpose
00Recall
One card from 03-02 (why a trace stops at the bad state), one from chapter 02 (reading /\ and \/ as filters), and one from 00-04 (the one question to ask of any evidence). The last one is this lesson in a sentence.
03-02-a from Your first counterexample
Why does a TLC trace for an invariant violation stop at the bad state instead of showing a whole infinite behavior?
Show answer
Once a state breaks an invariant, nothing later can repair it, so the path to that state is all the evidence needed.
02-04-a from Just enough logic
Read /\ and \/ as filters on candidate states or steps. What does each do?
Show answer
P /\ Q lets a candidate through only if both pass it, so adding a conjunct can only narrow the set. P \/ Q lets it through if either passes it, so adding a disjunct can only widen it. P => Q lets through every candidate that P rejects.
00-04-a from How this course works
What is the one question this course asks of any piece of evidence?
Show answer
Could this check have failed? A check that cannot fail on the bug you care about tells you nothing about it.
Skip recall Recall is never required.
01Commit
Two teammates changed KitchenMeasures on two branches. One wanted the puzzle to start with the big jug full, and added big = Big to Init. The other kept both jugs empty. The merge conflicted on Init, and whoever resolved the conflict kept both sides, so specs/MergedKitchen.tla starts like this:
Init is defined as
and small = 0
and big = 0
and big = BigIts cfg checks three invariants: TypeOK, EmptyOrFull, and NeverFive. You know from 03-02 that NeverFive is false in the puzzle.
Commit a
TLC checks MergedKitchen.cfg, which includes NeverFive. What does TLC report?
- A violation of NeverFive, as in 03-02.
- No violation.
- An error: Init contradicts itself, and TLC says so.
Answer No violation.
- If you picked A
- NeverFive can only fail in a state TLC reaches. Ask how TLC finds the first states, and how many there are when Init asks for big = 0 and big = 7 at once.
- If you picked C
- TLC refuses an Init that mentions no variables, such as FALSE: you will meet that message in the Stretch exercise. It does not solve equations to notice that big = 0 and big = Big cannot both hold. It looks for initial states, finds none, and has nothing left to check.
Commit b
You ask TLC to check the invariant ~FiveCups (read "not FiveCups") on KitchenMeasures, and it reports a violation. What has it shown?
- That the spec is broken: it reaches a state it should not.
- That every behavior of the spec reaches 5 cups sooner or later.
- That a state with 5 cups is reachable, and how to reach it.
Answer That a state with 5 cups is reachable, and how to reach it.
- If you picked A
- A violation means only that the claim is false somewhere. Whether that is a bug depends on whether you wanted the claim to be true. Here you wrote the claim so that it would fail.
- If you picked B
- One path to the state is enough to refute "never". It says nothing about the other behaviors: a behavior that only fills and empties the small jug never gets near 5 cups. Reachable is not the same as inevitable.
02Lab
./tla check chapters/03-meet-tlc/specs/MergedKitchen.cfgRead every line of the output before you open the reveal. Which lines would look exactly the same for a model that works? Which would not?
03-meet-tlc/specs/MergedKitchen03-meet-tlc/specs/MergedKitchen MergedKitchen.cfg (Small=3, Big=7)
parse ok
model check: no violation found in 0 distinct states (0 generated, depth 0)
expected outcome met: coverage-gap FillSmallReveal for commit a
No violation, after exploring 0 distinct states. There is no initial state, so there is nothing to check, and every claim "holds", including one you know is false. Two things give it away: the zero in the counts, and the line expected outcome met: coverage-gap FillSmall. The cfg's author predicted that FillSmall, the first action of Next, would never fire. With no state to start from, none of the six does.
Reveal for commit b
A violation of ~FiveCups is a reachable state where FiveCups is true, with the path to it. That is not a bug report. It is evidence you asked for: a worked example showing that 5 cups can be measured. In 03-02 you got the same evidence by checking NeverFive, an equivalent formula under another name.
03Reason
If you expected NeverFive to fail again, you assumed the check still had a model to look at. It did not. And TLC said "no error" with a straight face.
That is the uncomfortable fact this lesson is built on. A green result has two possible meanings: the claim is true in every state the system can reach, or the system reaches nothing worth mentioning. TLC gives the same verdict, "no error", for both. Only the numbers, and ./tla's coverage and witness checks, tell them apart.
Write something before openingNeverFive is false in the puzzle. Why does TLC report no violation of it here?
"NeverFive holds in every reachable state" is a statement about all the reachable states. When there are none, there is no state where it fails, so the statement is true. The same goes for every other invariant. Nothing was checked, and everything passed.
So how do you tell a true claim from an empty model? Turn the trick from 03-02 around. There, you wrote NeverFive hoping TLC would show you wrong, and the counterexample was a recipe. That generalises:
To show that a state can happen, claim that it never does, and let TLC refute you.
A state you expect to be reachable, written as a state predicate, is a witness. KitchenMeasures.tla defines one:
FiveCups is defined as big = 5Checking the invariant ~FiveCups is breaking your own spec on purpose. If TLC reports a violation, FiveCups is reachable and the trace shows how. If it reports no violation, either 5 cups is truly impossible, or your model is stuck. Either way you have learnt something you did not know.
The witness rule. Every passing model in this course names at least one witness, and the check is not done until each witness is reached. You never write ~FiveCups by hand. The cfg header says @witness: FiveCups, and ./tla builds a small wrapper module with NotW == ~FiveCups, runs TLC on it, and expects a violation. That is the line you saw in 03-01: "witness FiveCups reached".
Write something before openingMergedKitchen fails a second check too. Which one, and what does it look for?
Coverage. A header line @coverage: all asks ./tla to confirm that TLC computed at least one successor state from every action named in Next; this cfg says @expect: coverage-gap FillSmall instead, because its author knew the answer. With no initial state, no action ever fires. Had the header named the witness FiveCups, that check would fail too, since no state has five cups.
Coverage and witnesses look for different kinds of emptiness. Coverage asks "was every action ever enabled?" It does not ask whether the step changed anything: an action that leaves every variable unchanged still counts as fired. A witness asks "did the system ever get somewhere interesting?" Neither replaces the other. In the Warm-up exercise, an action never fires while five cups stays within reach, and of the cfg's checks only coverage notices. In the Core exercise, every action fires and a weak witness is reached; only a check that needs the real work notices.
Choosing a witness. Not every reachable state makes a good witness. A witness reached in the initial state tells you only that the model starts; a witness that is a small variation of TRUE tells you nothing at all. Pick a state that the system can only reach by doing its real work. FiveCups is a good one: it needs fills, empties and pours, in the right order. For a thermostat, "the heater is on and the room is at the top of the band" needs the heater to switch on and the room to warm up. For a vending machine, "an item was sold" needs coins, credit and a sale. If one witness cannot exercise everything, name two.
Write something before openinga teammate's witness for the jugs is BigEmpty == big = 0. It is reached. What has it shown?
Almost nothing. big = 0 holds in the initial state, so ./tla reaches it with a trace of one state and no steps. The same witness would be reached by MergedKitchen with its Init restored to both jugs empty and every action deleted. A witness earns its keep only when reaching it requires the behavior you are worried about.
None of this costs much. A witness is one line in the module and one in the cfg header. The habit is the expensive part: before you trust a green result, make it go red once on purpose.
04In your editor
The vacuous model is chapters/03-meet-tlc/specs/MergedKitchen.tla. Check this lesson's exercises with:
./tla check 03-03The passing spec with its witness:
03-meet-tlc/specs/KitchenMeasures03-meet-tlc/specs/KitchenMeasures KitchenMeasures.cfg (Small=3, Big=7)
parse ok
model check: no violation found in 20 distinct states (75 generated, depth 10)
expected outcome met: pass
coverage: all 6 actions fired
witness FiveCups reached (trace of 9 states)The witness line is the result of a second TLC run that ./tla set up for you. Its raw log sits next to the main one in .tla-out/, with witness_FiveCups in the name, and its working files are under .tla-out/work/: a module MCWitness_FiveCups that extends KitchenMeasures and defines NotW == ~FiveCups, and a cfg that checks NotW as its only invariant, with CHECK_DEADLOCK FALSE so that a dead end before the witness cannot stop the run first. Open them once. There is no magic in the course's tooling, only checks you could write yourself. On a project without ./tla, you would write the same three lines by hand: a NotW operator in a wrapper module, INVARIANT NotW, and CHECK_DEADLOCK FALSE, and expect the run to fail.
05Practice
Warm-up. All the invariants pass, and one line of the output says an action never fires. Find out why, and whether five cups is still within reach.
Core. Every action fires, but your break-it-on-purpose check refuses to break. Find what stops the spec from reaching five cups.
Between them, the two exercises show why the course asks for both kinds of evidence. Before you fix anything, write down which check caught each bug and which check missed it.
03-03-ex1Warm-up5 min
03-03-ex1 · The fill that never fires
Tier: warm-up. Time: about 5 minutes.
Every invariant in KitchenMeasures.cfg passes. A reviewer would wave it through. One line of ./tla's output disagrees.
- Run
./tla check 03-03-ex1and read every line of the first block, forKitchenMeasures.cfg. The linestarter state: expected outcome met (coverage-gap FillBig)says the cfg's author knew this action never fires. ReadFillBig's guard aloud: when is it true? - Can the jugs still reach 5 cups without that action? Work out a route by hand, using only the other five moves.
- Fill gap g1 so that the action does what its comment says, and run the check again. This time
./tlachecks coverage and the witnessFiveCupsitself.
Coverage asks only that FillBig fires somewhere, so a guard that is too narrow, such as big = 0, satisfies it. The check therefore also runs the course's own test: in every reachable state it compares FillBig with FillSmall read with the jugs swapped. MCKitchenMeasures.cfg runs it with jugs of 3 and 7 cups, and MCKitchenMeasures.other.cfg with 4 and 9, so a guard that writes a size as a number instead of Big fails. Both stop on the starter too, in the initial state; read them after the first block. Leave the MC files as they are.
This is the case for coverage: the invariants were all true, and a state you care about may still be reachable, while a whole action of the spec never did anything.
Hints: HINTS.md, under "03-03-ex1 hint 1" to "hint 3". The solution is in solutions/chapters/03-meet-tlc/exercises/03-ex1-fill-never-fires/; open it after you have a passing answer of your own.
Every cfg must meet its goal, "goal met: pass". If TLC finds no violation but an action never fires or a witness is not reached, ./tla prints "goal not met" and exits with code 1.
Done when: ./tla check 03-03-ex1 prints "goal met: pass".
./tla check 03-03-ex1
Repo chapters/03-meet-tlc/exercises/03-ex1-fill-never-fires/
Hints
Hint 1
The starter line names one action. Read its guard aloud: when is it true?
Hint 2
A fill makes sense whenever the jug is not already full. Compare the guard with the guard of FillSmall.
Hint 3 (nearly the answer)
The comparison points the wrong way. The big jug can never hold more than Big, so big > Big is never true. Compare with FillSmall's guard.
03-03-ex2Core8 min
03-03-ex2 · All or nothing
Tier: core. Time: about 8 minutes.
In this copy, both pours go through one helper, Poured, written by a teammate. Every invariant passes, EmptyOrFull included, and so does the break-it-on-purpose check NeverFive. The cfg also names a witness, BothFull.
That last pass is the bug report. Your check was supposed to break, and it did not.
- Run
./tla check 03-03-ex2. Note the distinct count and compare it with the run of the same jugs in lesson 03-01. - Would the witness
BothFullbe reached with these broken pours? Apply "Choosing a witness" from lesson 03-03: which moves does a state with both jugs full need? Does it need a single pour? - Read
Poured. What happens when the water does not all fit? - Fill gap g1 so that a pour moves as much as fits. Run the check:
NeverFiveshould now break, with a recipe, andEmptyOrFullshould hold in every state TLC reached before it stopped.
BothFull is a weak witness: two fills reach it, broken pours or not, so it says nothing about pouring. FiveCups would be a strong one, because no route to five cups avoids the pours, and here the break-it-on-purpose check NeverFive plays that part. Every action, broken pours included, is enabled somewhere, so a coverage check would not object; only a check that needs the real work shows that the work is wrong.
Hints: HINTS.md, under "03-03-ex2 hint 1" to "hint 3". The solution is in solutions/chapters/03-meet-tlc/exercises/03-ex2-all-or-nothing/; open it after you have a passing answer of your own.
Done when: ./tla check 03-03-ex2 prints "goal met: violation NeverFive".
./tla check 03-03-ex2
Repo chapters/03-meet-tlc/exercises/03-ex2-all-or-nothing/
Hints
Hint 1
Compare the distinct count with the run of the same jugs in 03-01. The model is missing most of its states. Which moves would create them?
Hint 2
Evaluate Poured(3, 1) by hand: the small jug holds 3 cups and the big one has room for 1. A real pour moves 1 cup. What does the teammate's helper return?
Hint 3 (nearly the answer)
When the amount does not fit, a pour moves exactly as much as fits. One of Poured's two parameters already says how much that is. Change only the ELSE branch.
06Explain it
Open NOTES.md and answer the three prompts under 03-03, about the Core exercise.
What I built, and why it is correct:
Which assumption, if false, breaks it:
What TLC did not check here:Compare your answers with "03-03 check your explanation" in HINTS.md.
After you writeCheck your explanation
A good answer: "The helper returned 0 when the water did not all fit, so most pours moved nothing and the spec could never reach 5 cups; my fix returns the room left. Every action still fired in the broken version, and the witness BothFull needs only two fills, so neither coverage nor that weak witness could see it; only the failed break-it-on-purpose check (NeverFive passing) showed it. TLC checked one model with a 3-cup and a 7-cup jug, and a reached witness says one state is reachable, not that the pours are right in every state."
A weak answer: "The pour was broken and now it works." It names no evidence, does not say which check revealed the bug, and does not say what the fix assumes.
Done?