Chapter
05
Just enough set theory
Part II · Safety and the language
Lessons
About
A box office double-books a seat. The teammate who modelled it stored the sales as a set of <<seat, guest>> pairs, and wrote a guard that looked right. TLC finds the double booking in a trace you can read at a glance. What should the seats have been?
This chapter teaches the data side of TLA+, one failure at a time: sets and quantifiers as queries, functions as total maps, records, sequences and SUBSET, CHOOSE and recursion, and the constants and model values a cfg supplies. Each piece arrives because a model went wrong without it, and a TLC run shows the difference.
Before you start
- Chapter 03 (TLC, invariants, witnesses, coverage,
TypeOK) and chapter 04 (the shape of a spec). - High-school algebra. Set notation is taught from zero, with every operator's spoken reading.
- Time: the chapter page shows the estimate, generated from the lessons.
What else is here
specs/:SeatBooking,SeatChart,Permissions,InventoryLedger, and the small variants each lesson runs.review/(05-review): a teammate's quorum commit that passes on their cfg.ai/1-in-vs-subseteq/(05-ai1): a feature-flag service and a message that says its refusal works, curated in the style of assistant output.gate/(05-gate): meeting-room booking;gate/twin/(05-gate-twin): library loans. The skeletons supply the interface, and you write everything else.
Run it
From the repository root:
./tla check 05-01
./tla check 05-review
./tla check --gate 05Skills
abstraction (choosing the abstraction), intent (stating intent as properties).
Elsewhere
- Web version: https://indicogni.com/learn/tla-plus/05-just-enough-set-theory/
- Read the lessons rendered, on the web page. In the repository their numbers and output blocks are placeholders that
./tlafills in. - Recaps:
CONCEPTS.md. Hints and explanation checks:HINTS.md. Predictions without answers:PREDICT.md. - Solutions:
solutions/chapters/05-just-enough-set-theory/, including the gate references and their mutants. - Further reading: the set theory TLA+ uses, and the standard modules
FiniteSetsandSequences, are defined in Specifying Systems, free from Lamport's TLA+ site.
Beyond the lessons
- 05-review Review a teammate’s spec ·
chapters/05-just-enough-set-theory/review/·./tla check 05-review - 05-ai1 AI item ·
chapters/05-just-enough-set-theory/ai/1-in-vs-subseteq/·./tla check 05-ai1 - 05-gate Gate ·
./tla check --gate 05Hints
Hint 1
Start with
TypeOKandInit:calis a function from pairs of room and slot, andhelda function from people to sets of pairs. Then writeBookwith every rule in the README as its own guard, one conjunct each.Hint 2
Every action changes both calendars, or neither. Write each new value from unprimed values, with
EXCEPTand@. A person's slot is busy if some pair in theirheldhas that slot as its second part.Hint 3 (nearly the answer; opening it marks a pass as "passed with help")
Safetyis a conjunction of three state predicates overcalandheld: one ties the room calendars to the personal calendars, one is about a person and a slot, and one is about a person's number of bookings. - 05-gate-twin Gate twin, another domain ·
./tla check --gate 05 --twinHints
Hint 1
Start with
TypeOKandInit:shelfis a function from pairs of copy and title, andloansa function from members to sets of pairs. Then writeBorrowwith every rule in the README as its own guard, one conjunct each.Hint 2
Every action changes both records, or neither. Write each new value from unprimed values, with
EXCEPTand@. A member already has a title if some pair on their card has that title as its second part.Hint 3 (nearly the answer; opening it marks a pass as "passed with help")
Safetyis a conjunction of three state predicates overshelfandloans: one ties the shelf to the cards, one is about a member and a title, and one is about a member's number of loans.