CSE 312 Foundations of Computing II Lecture 4: Inclusion-exclusion principle Stefano Tessaro tessaro@cs.washington.edu 1
Announcements • Homework online tonight by 11:59pm. • Go to sections tomorrow. 2
Inclusion-Exclusion Sometimes, we want ! , and ! = # ∪ % % # Fact. # ∪ % = # + % − |# ∩ %| 3
Inclusion-Exclusion – Three Sets % # # ∪ % ∪ * ? * 4
Inclusion-Exclusion – Three Sets % # # + % + |C| 1 2 1 − # ∩ % − # ∩ * − |% ∩ *| 3 2 2 1 * 5
Inclusion-Exclusion – Three Sets % # # + % + |C| 1 1 1 − # ∩ % − # ∩ * − |% ∩ *| 0 1 + # ∩ % ∩ * 1 1 * 6
Inclusion-Exclusion – Three Sets # ∪ % ∪ * = % # # + % + |C| 1 1 1 − # ∩ % − # ∩ * − |% ∩ *| 1 1 + # ∩ % ∩ * 1 1 * 7
Example – Number of Derangements How many one-to-one maps -: 3 → 3 are there such that - 1 ≠ 1 for all 1 ? 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 8
Example – Number of Derangements How many one-to-one maps -: 3 → 3 are there such that - 1 ≠ 1 for all 1 ? Alternatively: In how many ways can we arrange 3 people such that none of them stays in place? In how many ways can we have students grade each other’s homework without anyone grading their own homework? 9
Example – Number of Derangements How many one-to-one maps -: 3 → 3 are there such that - 1 ≠ 1 for all 1 ? ! 5 = all one-to-one -: 3 → 3 # = all - ∈ ! 5 s.t. - 1 = 1 % = all - ∈ ! 5 s.t. - 2 = 2 * = all - ∈ ! 5 s.t. - 3 = 3 Wanted: ! 5 ∖ # ∪ % ∪ * = ! 5 − |# ∪ % ∪ *| = 3! =? 10
Example – Number of Derangements How many one-to-one maps -: 3 → 3 are there such that - 1 ≠ 1 for all 1 ? ! 5 = all -: 3 → 3 # = all - ∈ ! 5 s.t. - 1 = 1 % = all - ∈ ! 5 s.t. - 2 = 2 * = all - ∈ ! 5 s.t. - 3 = 3 # ∪ % ∪ * = # + % + |C|− # ∩ % − # ∩ * − |% ∩ *| + # ∩ % ∩ * = 0! = 1 = 2! = 2 = 1! = 1 11
Example – Number of Derangements How many one-to-one maps -: 3 → 3 are there such that - 1 ≠ 1 for all 1 ? ! 5 = all -: 3 → 3 # = all - ∈ ! 5 s.t. - 1 = 1 % = all - ∈ ! 5 s.t. - 2 = 2 * = all - ∈ ! 5 s.t. - 3 = 3 # ∪ % ∪ * = 3×2 − 3×1 + 1 = 4 ! 5 ∖ # ∪ % ∪ * = ! 5 − # ∪ % ∪ * = 3! − 4 = 2 12
General Case – Number of Derangements How many one-to-one maps -: < → < are there such that - 1 ≠ 1 for all 1 ∈ [<] ? We have seen that 1/3 permutations over [3] are derangements Any guesses for the general case? Vanishing fraction? Constant fraction? 13
Inclusion-exclusion – General formula Theorem. For any < v(finite) sets # ? , … , # B , B I K? L # D = F −1 # D C DE? ∅HI⊆[B] D∈I sum over all subsets of [<] , except the empty set + sign for odd-sized sets, - sign for even-sized sets 14
B I K? L Inclusion-exclusion – Proof (sketch) C # D = F −1 # D DE? ∅HI⊆[B] D∈I B Need to verify every element M ∈ ⋃ DE? # D is counted exactly once. Assume M is contained in 1 ≤ P ≤ < sets – call these # D Q , … , # D R In formula, M is counted P P P − P 2 + P 3 − P 4 + ⋯ = F − F = 1 1 1 D TUU D VWVB,DXY Why? Binomial theorem ⟹ 0 = 1 − 1 [ = ∑ DEY −1 D [ [ D 15
Example – Number of Derangements How many one-to-one maps -: < → < are there such that - 1 ≠ 1 for all 1 ∈ [<] ? ! B = all one-to-one -: 3 → 3 Fact. ⋂ D∈I # D = < − _ ! # D = all - ∈ ! B s.t. - 1 = 1 Wanted: ! B ∖ # ? ∪ # ] ∪ ⋯ ∪ # B = ! B − |# ? ∪ # ] ∪ ⋯ ∪ # B | = <! =? 16
Fact. ⋂ D∈I # D = < − _ ! B I K? L C # D = F −1 # D ∅HI⊆[B] DE? D∈I < <! I K? < − _ ! = = F −1 P P! < − P ! ∅HI⊆[B] B B B −1 [ −1 [K? −1 [K? < = F < − P ! = −<! F = <! F P P! P! [E? [E? [E? b M [ ` a = F P! [EY → <! B B B B −1 [ −1 [ ! B ∖ C # D = <! − C # D = <! + <! F = <! F ` P! P! DE? DE? [E? [EY [Indeed: result is integer closest to B! V ] 17
Back to Euler’s Totient Function Definition . The Euler totient function is defined as c d = e ∈ [d] gcd e, d = 1} Goal: Give a formula for c d . 18
V p … j V R where j V Q j Assume d = j ? , … , j [ are distinct primes (by the ? ] [ fundamental theorem of arithmetic, this factorization is unique). # D = multiples of j D in [d] k Fact. ⋂ D∈I # D = ∏ m∈n o m |# D | = d/j D We know (see last time): [ [ c d = [d] ∖ C # D = d − C # D DE? DE? 19
k Fact. ⋂ D∈I # D = [ ∏ m∈n o m I K? L c d = d − C # D = d − F −1 # D V p … j V Q j V R d = j ∅HI⊆[B] DE? D∈I ? ] [ d I = d + F −1 ∏ D∈I j D ∅HI⊆[B] 1 1 I r I = d F −1 = d F −1 ∏ D∈I j D j D I⊆[B] I⊆[B] D∈I − 1 = d F r e.g. 1 − ? 1 − ? o p = 1 − ? o Q − ? ? j D o p + o Q o Q o p I⊆[B] D∈I [ [ 1 − 1 V m s? (j D − 1) = d r = r j D j D DE? DE? 20
Recommend
More recommend