A Tour of Temporal Typing Specifications & State · 6/6
Specifications & State · Page 6 of 6

Exercise: Traffic Light

Time to write your first specification fix!

On the right is a TrafficLight whose state is a finite Literal["red", "green", "yellow"]. Two ActionInvariant clauses constrain every legal transition using implies(p, q) (p => q):

  • no_red_to_yellow: a red light must never jump directly to yellow.
  • no_green_to_red: a green light must never jump directly to red.
Exercise: Click Check first to see the failing transition. Then fix advance() so the light cycles properly: "red" → "green" → "yellow" → "red". Click Check until you get PASS (3 states).

Stuck? Use Hint or Solution in the toolbar above the output pane.

Click Check (or press Shift+Enter) to run the front-end and check this specification. Switch to TLA⁺ to view its TLA⁺ meaning.
---- MODULE TrafficLight ----
VARIABLE color

Init == color = "red"
Advance ==
    color' = IF color = "red" THEN "green"
             ELSE IF color = "green" THEN "yellow"
             ELSE "red"
Next == Advance
Spec == Init /\ [][Next]_color

NoRedToYellow == [][color = "red" => color' # "yellow"]_color
NoGreenToRed  == [][color = "green" => color' # "red"]_color
====