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.