Chapter

05

Just enough set theory

Part II · Safety and the language

  • 5 lessons
  • 3 h 45 min of core lessons
  • Skills: abstraction, intent

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:

shell
./tla check 05-01
./tla check 05-review
./tla check --gate 05

Skills

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 ./tla fills 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 FiniteSets and Sequences, 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 05

    Hints

    Hint 1

    Start with TypeOK and Init: cal is a function from pairs of room and slot, and held a function from people to sets of pairs. Then write Book with 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 EXCEPT and @. A person's slot is busy if some pair in their held has that slot as its second part.

    Hint 3 (nearly the answer; opening it marks a pass as "passed with help")

    Safety is a conjunction of three state predicates over cal and held: 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 --twin

    Hints

    Hint 1

    Start with TypeOK and Init: shelf is a function from pairs of copy and title, and loans a function from members to sets of pairs. Then write Borrow with 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 EXCEPT and @. 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")

    Safety is a conjunction of three state predicates over shelf and loans: 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.