Derived Variables A derived variable v is simply a function that associate value with state. Die Hard Example: total amount of water in the two jugs v ::= b + l
For GCD, already have variables Derived Variables For GCD, already have variables x, y.
Derived Variables Proof of GCD termination: Show that variable y is strictly decreasing and natural number valued.
Derived Variables Termination follows by least number principle: y must take a least value, and thus the algorithm is stuck.
Strictly Decreasing Variable 16 12 8 4 State
Weakly Decreasing Variable 16 12 8 4 State
Weakly Decreasing Variable We used to call weakly decreasing variables “nonincreasing” variables. OK terminology but remember: nondecreasing is NOT EQUAL to “not decreasing.”
There are 5 girls and 5 boys Stable Marriage There are 5 girls and 5 boys 1 A 2 B 3 C 4 D 5 E
Stable Marriage Preferences: Boys Girls 1: CBEAD A: 35214 2 : ABECD B : 52143 3 : DCBAE C : 43512 4 : ACDBE D : 12345 5 : ABDEC E : 23415
Stable Marriage Preferences: Marry 1 with C: Boys 1: CBEAD 2 : ABECD 3 : DCBAE 4 : ACDBE 5 : ABDEC Marry 1 with C: 1 C
Stable Marriage Only 4 boys and 4 girls left. Boys 2 : ABED 3 : DBAE 4 : ADBE 5 : ABDE 2 3 4 5 A B D E
Stable Marriage A problem: Rogue couples 1 C 4 B Girl C likes like boy 4 better Boy 4 like girl C better
Stable marriage The mating algorithm – day by day Morning: boys serenade favorite girls Afternoon: girl rejects all but best Serenader Evening: rejected boys cross off girls
Stable marriage Termination condition: stop when no rejection is possible. The algorithm terminates. Everybody ends up married. The resulting marriages are stable.
Infinitely Wide Trees … …
Infinitely Wide Trees … …
Infinitely Wide Trees
Infinitely Wide Trees
Tutorial Problem 1