Chapter

04

Stuttering and the shape of a spec

Part I · Behaviors before syntax

  • 4 lessons
  • 2 h 53 min of core lessons
  • Skills: intent, abstraction

Lessons

About

A clock with only an hour hand moves on one hour at a time. Now add a minute hand. Between one hour and the next, the minute hand moves on its own fifty-nine times, and the hour hand moves only with the sixtieth. Is the new clock still a valid hour clock?

Your intuition says yes. A careless formula says no. This chapter is about the piece of syntax that makes your intuition right: the subscript in [][Next]_vars. You take the shape of every spec apart, meet the steps that change nothing, find out what "nothing" means, and check one spec's behaviors as the shadow of another's, an idea chapter 11 calls refinement.

Before you start

  • Chapter 03: SANY, the cfg, invariants, witnesses and coverage.
  • Chapter 02: primes, UNCHANGED, and what an action says about a variable it does not mention.
  • Time: the chapter page shows the estimate, generated from the lessons.

What else is here

  • specs/: HourClock, HourMinuteClock, and one small module per way a clock can surprise you.
  • review/ (04-review): a teammate's scoreboard, and a rule that was written down but never checked.
  • ai/1-stops-the-clock/ (04-ai1): an AI's argument that its wall clock's hours display behaves like an hour clock.
  • gate/ (04-gate): a stopwatch with laps; gate/twin/ (04-gate-twin): an odometer with a trip meter.

Run it

From the repository root:

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

Skills

intent (stating intent as properties), abstraction (choosing what a spec is about, and what it leaves alone).

Elsewhere

  • Web version: https://indicogni.com/learn/tla-plus/04-stuttering/
  • Recaps: CONCEPTS.md. Hints and explanation checks: HINTS.md. Predictions without answers: PREDICT.md.
  • Solutions: solutions/chapters/04-stuttering/, including the gate references and their mutants.
  • Further reading and credit: the hour clock, with its spec HourClock and its variable hr, is the first example in Leslie Lamport's Specifying Systems. The argument that an hour-minute clock should still count as an hour clock, and the picture of a faster camera adding frames that change nothing, are also Lamport's, from his page "Stuttering Steps". The other clocks, their failure modes and the exercises are the course's own.

Beyond the lessons

  • 04-review Review a teammate’s spec · chapters/04-stuttering/review/ · ./tla check 04-review
  • 04-ai1 AI item · chapters/04-stuttering/ai/1-stops-the-clock/ · ./tla check 04-ai1
  • 04-gate Gate · ./tla check --gate 04

    Hints

    Hint 1

    Write PressStartStop and Tick first, then Next and Spec in the shape of every spec in this chapter, and run your cfg. Add PressLap last: it has two cases, running and stopped.

    Hint 2

    PressLap can be written with IF running THEN … ELSE … for each variable it changes. Write every new value from old, unprimed values. LapRecorded needs the watch to start, tick at least once, and record a lap while running.

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

    A tick or a Start/Stop press must pass your Safety, whatever it does to elapsed or running. A lap display that changes in any step that is not a Lap/Reset press must fail it, including a press of some other button. If you write the rule with your own PressLap, a bug inside PressLap passes it; the hidden checks look at PressLap itself.

  • 04-gate-twin Gate twin, another domain · ./tla check --gate 04 --twin

    Hints

    Hint 1

    Write TurnKey and Drive first, then Next and Spec in the shape of every spec in this chapter, and run your cfg. Add PressTrip last: it has two cases, engine on and engine off.

    Hint 2

    Drive changes two counters and leaves the ignition alone. PressTrip can be written with IF ignition THEN … ELSE …. Write every new value from old, unprimed values. TripBehind needs the car to drive and the trip meter to be reset afterwards.

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

    A key turn or a trip reset must pass your Safety, whatever it does to ignition or trip. An odometer that changes in any step that is not a Drive step must fail it, even with the engine on. If you write the rule with your own Drive, a bug inside Drive passes it; the hidden checks look at Drive itself.

  • CP1 Checkpoint CP1 follows this chapter: mixed items from every chapter so far, with no hints.