learning_tla/lamport_video/docs/lecture04.md
2025-02-08 18:44:33 +01:00

1.3 KiB

04 Die Hard 3

  • Getting started on a spec
    • Write a single correct behavior, informally
    • The next-state formula describes ALL permitted steps. It's usually written as F1 \/ F2 \/ ... \/ Fn where each Fi allows a different kind of step.
  • Die Hard jugs problem:
    • you have a 3 gallon and a 5 gallon jug, and a faucet, and you need to obtain exactly 4 gallons of water
      • Start: [small: 0, big: 0]
      • Fill small: [small: 3, big: 0]
      • Pour small to big: [small: 0, big: 3]
      • Fill small: [small: 3, big: 3]
      • Pour small to big without overflowing: [small: 1, big: 5]
      • Empty big: [small: 1, big: 0]
      • Pour small to big: [small: 0, big: 1]
      • Fill small: [small: 3, big: 1]
      • Pour small to big: [small: 0, big: 4] : solved
    • By doing this, we learned
      • what the variables are
      • what constitutes a step: in this example, the partially filled temporary situations while filling or emptying are not being recorded as states, so there are no steps to them
    • The Die Hard behavior has 3 kinds of steps:
      • Fill a jug
      • Empty a jug
      • Pour one jug into the other
  • Adding an invariant for big /= 4
    • Passes all cases where the desired state big = 4 is NOT reached.
    • Meaning a failing case happens for any behavior where big = 4, so it is a solution to the problem.