Proof
define: m|a => exist a Integer number k, make m equals to k * a
Invariant: P(n) = “if (x, y) is the state after n transitions, then m|x, m|y”
problem
we have two jugs, the one only can fill with 3 gals water, another one can only fill with 5 gals water. We need a jug fill with 4 gals water.
State machine
(a=3,b=3)
define state pairs(x,y)
x=#a, y=#b
start states: (0,0)
Transitions
emyting:
(x,y) to (0,y)
(x,y) to (x,0)
filling:
(x,y) to (a,y)
(x,y) to (x,b)
pouring:
(x,y) to (0, x+y) when x+y<=b
(x,y) to (x - (b-y), b) when x+y>=b
(x,y) to (x+y,0) when x+y<=a
(x,y) to (a,y-(a-y)) when x+y>=a
How to proof
Base case: (0,0), m|0 => p(0) is true
Inductive step: assume P(n) is true, to proof P(n+1) is true.
if P(n+1) is true : m|y-(a-x),m|x-(b-y),m|(x+y),m|x,m|y,m|a,m|b,m|0 need be true
Because p(n)=> m|a, m|b,m|x, m|y,m|0 so P(n+1) is true,
Proof ends.