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.

5 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.

6 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.

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

8 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.

9 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.

10 Strictly Decreasing Variable
16 12 8 4 State

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

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

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

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

15 In-class Problem Problem 1

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

17 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 :

18 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

19 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

20 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

21 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

22 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

23 (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

24 (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

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

26 Stable Marriage Trouble! 1 C 4 B

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

28 Stable Marriage and vice-versa 1 C 4 B

29 Stable Marriage Rogue Couple 1 C 4 B

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

31 Stable Marriage Do it! PROBLEM 2

32 Stable Marriage More than a puzzle:

33 More than a puzzle: College Admissions Stable Marriage
(original Gale & Shapley paper, 1962)

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

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

36 Stable Marriage

37 Stable Marriage The Mating Algorithm

38 Stable Marriage The Mating Algorithm: day by day

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

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

41 … … 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

42 … … 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

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

44 In-class Problem Problem 3

45 Stable Marriage Partial Correctness:

46 Stable Marriage Partial Correctness: Everyone is married.

47 Partial Correctness: Everyone is married. Marriages are stable.
Stable Marriage Partial Correctness: Everyone is married. Marriages are stable.

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

49 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, …}

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

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

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

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

54 Lemma: A girl’s favorite tomorrow
Stable Marriage Lemma: A girl’s favorite tomorrow will be at least as desirable as today’s.

55 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.

56 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.

57 Derived Variable: total-girls-names
Stable Marriage Derived Variable: total-girls-names ::= total number of names not crossed off boy’s lists

58 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.

59 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.

60 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.

61 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.

62 Everyone is Married on the Wedding Day
Stable Marriage Everyone is Married on the Wedding Day Proof by contradiction:

63 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.

64 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.

65 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.

66 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.

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

68 In-class Problem Problem 4

69 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?

70 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!

71 Mating Algorithm is Optimal for all Boys at once.
Stable Marriage Mating Algorithm is Optimal for all Boys at once.

72 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.

73 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