Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computational Processes II

Similar presentations


Presentation on theme: "Computational Processes II"— Presentation transcript:

1 Computational Processes II
Mathematics for Computer Science MIT 6.042J/18.062J Computational Processes II Copyright © Albert Meyer, 2002. Prof. Albert Meyer & Dr. Radhika Nagpal

2 Computational Processes
Last lecture: Invariants & Partial Correctness.

3 Computational Processes
Today: Termination, Derived Variables, Getting Married.

4 A derived variable, v, is a function giving a value to each state.
Derived variables A derived variable, v, is a function giving a value to each state. Robot example: Sum of coordinates, v ::= x + y. Parity of x + y, w ::= v mod 2.

5 Derived variables For GCD, already have variables x, y.

6 Proof of GCD termination: variable y is strictly decreasing and
Derived variables Proof of GCD termination: variable y is strictly decreasing and natural number valued.

7 Termination follows by least number principle:
Derived variables Termination follows by least number principle: y must take a least value, and thus the algorithm is stuck.

8 Strictly Decreasing Variable
16 12 8 4 Goes down at every step State

9 Weakly Decreasing Variable
16 12 8 4 Down or constant after each step State

10 Weakly Decreasing Variable
(We used to call weakly decreasing variables “nonincreasing” variables.)

11 Weakly Decreasing Variable
OK terminology but remember: nonincreasing is NOT SAME as “not increasing.”

12 In-class Problem Problem 1

13 Stable Marriage A Marriage Problem Boys Girls A B C D E

14 Preferences: Boys Girls 1: CBEAD A : 35214 2 : ABECD B : 52143
Stable Marriage Preferences: Boys Girls 1: CBEAD A : 35214 2 : ABECD B : 52143 3 : DCBAE C : 43512 4 : ACDBE D : 12345 5 : ABDEC E :

15 Try “greedy” strategy for boys Preferences 1: CBEAD 2 : ABECD
Stable Marriage 1: CBEAD 2 : ABECD 3 : DCBAE 4 : ACDBE 5 : ABDEC Preferences Try “greedy” strategy for boys

16 Marry Boy 1 with Girl C Preferences (his 1st choice) 1: CBEAD
Stable Marriage Marry Boy 1 with Girl C (his 1st choice) Preferences 1: CBEAD 2 : ABECD 3 : DCBAE 4 : ACDBE 5 : ABDEC 1 C

17 Marry Boy 1 with Girl C Preferences (his 1st choice) 2 : ABE D
Stable Marriage Marry Boy 1 with Girl C (his 1st choice) Preferences 2 : ABE D 3 : D BAE 4 : A DBE 5 : ABDE 1 C

18 Marry Boy 1 with Girl C Preferences (his 1st choice) 2 : ABED 3 : DBAE
Stable Marriage Marry Boy 1 with Girl C (his 1st choice) Preferences 2 : ABED 3 : DBAE 4 : ADBE 5 : ABDE 1 C

19 (best remaining choice) Preferences
Stable Marriage Next: Marry Boy 2 with Girl A: (best remaining choice) Preferences 2 : ABED 3 : DBAE 4 : ADBE 5 : ABDE 1 C 2 A

20 Final “boy greedy” marriages
Stable Marriage Final “boy greedy” marriages 1 C 3 D 2 A 4 B 5 E

21 Stable Marriage Trouble! 1 C 4 B

22 Boy 4 likes Girl C better than his wife.
Stable Marriage Boy 4 likes Girl C better than his wife. 1 C 4 B

23 Stable Marriage and vice-versa 1 C 4 B

24 Stable Marriage Rogue Couple 1 C 4 B

25 Stable Marriage Problem: Marry everyone without any rogue couples!

26 Stable Marriage Do it! PROBLEM 2

27 Matching Hospitals & Residents. Matching Dance Partners.
Stable Marriage More than a puzzle: College Admissions (original Gale & Shapley paper, 1962) Matching Hospitals & Residents. Matching Dance Partners.

28 Stable Marriage

29 Stable Marriage The Mating Algorithm

30 Stable Marriage The Mating Algorithm: day by day

31 Morning: boy serenades favorite girl
Stable Marriage Morning: boy serenades favorite girl Ted Alice Bob

32 Morning: boy serenades favorite girl
Stable Marriage Morning: boy serenades favorite girl Afternoon: girl rejects all but favorite Ted Alice Bob

33 … … Morning: boy serenades favorite girl
Stable Marriage Morning: boy serenades favorite girl Afternoon: girl rejects all but favorite Evening: rejected boy writes off girl Alice Ted

34 Stop when no rejects. favorite suitor. Girl marries her
Stable Marriage Stop when no rejects. Girl marries her favorite suitor.

35 In-class Problem Problem 3

36 Partial Correctness: Termination: Everyone is married.
Stable Marriage Partial Correctness: Everyone is married. Marriages are stable. Termination: there exists a Wedding Day.

37 State q: Each boy’s set of eligible girls
Stable Marriage Model as State Machine State q: Each boy’s set of eligible girls q(Bob)={Carole, Alice, …}

38 Derived Variable: serenading
Stable Marriage Derived Variable: serenading Bob’s favorite eligible girl.

39 Derived Variable: suitors
Stable Marriage Derived Variable: suitors all boys serenading Alice.

40 Derived Variable: favorite
Stable Marriage Derived Variable: favorite Carole’s preferred suitor.

41 Different girls have different favorites,
Stable Marriage Different girls have different favorites, because boys serenade one girl at a time.

42 Lemma: A girl’s favorite tomorrow
Stable Marriage Lemma: A girl’s favorite tomorrow will be at least as desirable as today’s. favorite(G) is weakly increasing for each G.

43 Lemma: A boy’s love tomorrow will be no more desirable than today’s.
Stable Marriage Lemma: A boy’s love tomorrow will be no more desirable than today’s. serenading(B) is weakly decreasing for each B.

44 So  Wedding Day. Derived Variable: total-girls-names
Stable Marriage Derived Variable: total-girls-names ::= total number of names not crossed off boy’s lists Strictly decreasing & N-valued. So  Wedding Day.

45 Mating Invariant If G has rejected B, then she has
Stable Marriage Mating Invariant If G has rejected B, then she has a better current favorite.

46 Mating Invariant If G has rejected B, then she has
Stable Marriage Mating Invariant If G has rejected B, then she has a better current favorite. Proof: favorite(G) is weakly increasing.

47 Everyone is Married on the Wedding Day
Stable Marriage Everyone is Married on the Wedding Day Proof by contradiction: If B is not married, can’t be serenading, so list is empty. By Invariant all girls have favorites better than B. So all girls are married. So all boys are married.

48 Stable Marriage Stability: Similar easy argument using the Invariant.

49 In-class Problem Problem 4

50 Who does better, boys or girls?
Stable Marriage Who does better, boys or girls? Girls’ suitors get better, and boy’s sweethearts get worse, so girls do better? No!

51 Mating Algorithm is Optimal for all Boys at once. Pessimal for all
Stable Marriage Mating Algorithm is Optimal for all Boys at once. Pessimal for all Girls.

52 More questions, rich theory:
Stable Marriage More questions, rich theory: Other stable marriages possible? Can be many. Can a boy do better by lying? – No! Can a girl do better by lying – Yes!


Download ppt "Computational Processes II"

Similar presentations


Ads by Google