Presentation is loading. Please wait.

Presentation is loading. Please wait.

Discrete Mathematics for Computer Science

Similar presentations


Presentation on theme: "Discrete Mathematics for Computer Science"— Presentation transcript:

1 Discrete Mathematics for Computer Science
COMPSCI 230 Discrete Mathematics for Computer Science

2 Counting III Lecture 8 X1 X2 + X3

3 How many ways to rearrange the letters in the word “CARNEGIEMELLON”?
14 2 positions of the Ns 12 3 positions of the Es 9 2 positions of the Ls 7! ways to order the rest

4 Arrange n symbols: r1 of type 1, r2 of type 2, …, rk of type k
n-r1 r2 n - r1 - r2 - … - rk-1 rk n! (n-r1)!r1! = (n-r1)! (n-r1-r2)!r2! = n! r1!r2! … rk!

5 CARNEGIEMELLON 14! = 3,632,428,800 2!3!2!

6 5 distinct pirates want to divide 20 identical, indivisible bars of gold. How many different ways can they divide up the loot?

7 Sequences with 20 G’s and 4 /’s
GG/G//GGGGGGGGGGGGGGGGG/ represents the following division among the pirates: 2, 1, 0, 17, 0 In general, the ith pirate gets the number of G’s after the (i-1)st / and before the ith / This gives a correspondence (bijection) between divisions of the gold and sequences with 20 G’s and 4 /’s

8 24 4 How many different ways to divide up the loot?
Sequences with 20 G’s and 4 /’s 24 4

9 How many different ways can n distinct pirates divide k identical, indivisible bars of gold?
n + k - 1 n - 1 n + k - 1 k =

10 67 12 7 Identical/Distinct Dice Suppose that we roll seven dice
How many different outcomes are there, if order matters? 67 12 7 What if order doesn’t matter? (E.g., Yahtzee) (Corresponds to 6 pirates and 7 bars of gold)

11 Unary visualization: {Y, Y, Y, Z, Z}
Multisets A multiset is a set of elements, each of which has a multiplicity The size of the multiset is the sum of the multiplicities of all the elements Example: {X, Y, Z} with m(X)=0 m(Y)=3, m(Z)=2 Unary visualization: {Y, Y, Y, Z, Z}

12 size k from n types of elements is:
Counting Multisets There number of ways to choose a multiset of size k from n types of elements is: n + k - 1 n - 1 n + k - 1 k =

13 Taking k items from a set of n
(n-k)! Order matters, no repetition: Order matters, repetition allowed: nk n k Order doesn’t matter, no repetition: Order doesn’t matter, repetition allowed: n + k - 1 k

14 ( ) ( ) = + + + + + + + + Polynomials Express Choices and Outcomes
Products of Sum = Sums of Products ( ) ( ) = + + + + + + + +

15 b1 b3 b2 t1 t2 t1 t2 t1 t2 b1t1 b1t2 b2t1 b2t2 b3t1 b3t2 (b1+b2+b3)(t1+t2) = b1t1 + b1t2 + b2t1 + b2t2 + b3t1 + b3t2

16 What is a Closed Form Expression For ck?
(1+X)n = c0 + c1X + c2X2 + … + cnXn (1+X)(1+X)(1+X)(1+X)…(1+X) After multiplying things out, but before combining like terms, we get 2n cross terms, each corresponding to a path in the choice tree ck, the coefficient of Xk, is the number of paths with exactly k X’s n k ck =

17 Binomial Coefficients
The Binomial Formula n n 1 n (1+X)n = X0 + X1 +…+ Xn Binomial Coefficients binomial expression

18 The Binomial Formula (1+X)0 = 1 (1+X)1 = 1 + 1X (1+X)2 = 1 + 2X + 1X2 (1+X)3 = 1 + 3X + 3X2 + 1X3 (1+X)4 = 1 + 4X + 6X2 + 4X3 + 1X4

19 What is the coefficient of EMSTY in the expansion of
5!

20 What is the coefficient of EMS3TY in the expansion of
The number of ways to rearrange the letters in the word SYSTEMS

21 What is the coefficient of (X1r1X2r2…Xkrk)
in the expansion of (X1+X2+X3+…+Xk)n? n! r1!r2!...rk!

22   Power Series Representation n k (1+X)n = Xk n k Xk = n k = 0 
For k>n, “Product form” or “Generating form” n k = 0 “Power Series” or “Taylor Series” Expansion

23 The number of subsets of an n-element set
By playing these two representations against each other we obtain a new representation of a previous insight: n n k (1+X)n = Xk k = 0 n k k = 0 2n = Let x = 1, The number of subsets of an n-element set

24    By varying x, we can discover new identities: n k (1+X)n = Xk n
0 = (-1)k Let x = -1, n k k even k odd = Equivalently,

25 The number of subsets with even size is the same as the number of subsets with odd size

26 n n k (1+X)n = Xk k = 0 Proofs that work by manipulating algebraic forms are called “algebraic” arguments. Proofs that build a bijection are called “combinatorial” arguments

27 We gave an algebraic proof that
k k even k odd = Let On be the set of binary strings of length n with an odd number of ones. Let En be the set of binary strings of length n with an even number of ones. We gave an algebraic proof that On  =  En 

28 A combinatorial proof must construct a bijection between On and En
Let On be the set of binary strings of length n with an odd number of ones Let En be the set of binary strings of length n with an even number of ones A combinatorial proof must construct a bijection between On and En

29 An Attempt at a Bijection
Let fn be the function that takes an n-bit string and flips all its bits fn is clearly a one-to-one and onto function for odd n. E.g. in f7 we have: ...but do even n work? In f6 we have Uh oh. Complementing maps evens to evens!

30 A Correspondence That Works for all n
Let fn be the function that takes an n-bit string and flips only the first bit. For example,

31 n n k (1+X)n = Xk k = 0 The binomial coefficients have so many representations that many fundamental mathematical identities emerge…

32 Pascal’s Triangle: kth row are coefficients of (1+X)k
The Binomial Formula (1+X)0 = 1 (1+X)1 = 1 + 1X (1+X)2 = 1 + 2X + 1X2 (1+X)3 = 1 + 3X + 3X2 + 1X3 (1+X)4 = 1 + 4X + 6X2 + 4X3 + 1X4 Pascal’s Triangle: kth row are coefficients of (1+X)k Inductive definition of kth entry of nth row: Pascal(n,0) = Pascal (n,n) = 1; Pascal(n,k) = Pascal(n-1,k-1) + Pascal(n-1,k)

33 “Pascal’s Triangle” = 1 1 = 1 1 = 1 2 = 1 2 1 = 2 2 = 1 3 = 1 3 1 = 3
= 1 1 = 1 1 = 1 2 = 1 2 1 = 2 2 = 1 3 = 1 3 1 = 3 3 2 = 3 3 = 1 Al-Karaji, Baghdad Chu Shin-Chieh 1303 Blaise Pascal 1654

34 Pascal’s Triangle “It is extraordinary how fertile in 1 properties the
triangle is. Everyone can try his hand” 1 1 1 1 2 1

35  Summing the Rows n 2n = k k = 0 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
1 1 1 2 1 = 1 + + + + + + = 2 = 4 = 8 = 16 = 32 = 64

36 Odds and Evens 1 1 1 1 2 1 =

37   Summing on 1st Avenue i i 1 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1
1 1 1 2 1 n+1 2 = =

38  Summing on kth Avenue 1 1 1 n+1 i = 1 2 1 k+1 k 1 3 3 1 1 4 6 4 1
1 1 1 2 1 i = k n i k n+1 k+1 =

39 Fibonacci Numbers 1 1 1 1 2 1 = 2 = 3 = 5 = 8 = 13

40 Sums of Squares 1 1 1 1 2 1 2 2 2 2 2 2 2

41 Al-Karaji Squares 1 1 1 1 2 1 = 1 +2 = 4 +2 = 9 +2 = 16 +2 = 25 +2 = 36

42 Pascal Mod 2

43 All these properties can be proved inductively and algebraically
All these properties can be proved inductively and algebraically. We will give combinatorial proofs using the Manhattan block walking representation of binomial coefficients

44 How many shortest routes from A to B?
10 5 B

45 shortest routes from (0,0) to (j,k)
Manhattan 1 1 jth street kth avenue 2 2 3 3 4 4 j+k k There are shortest routes from (0,0) to (j,k)

46 shortest routes from (0,0) to (n-k,k)
Manhattan 1 Level n kth avenue 1 2 2 3 3 4 4 n k There are shortest routes from (0,0) to (n-k,k)

47 Manhattan 1 Level n kth avenue 1 2 2 3 3 4 4 n k There are
1 Level n kth avenue 1 2 2 3 3 4 4 n k There are shortest routes from (0,0) to level n and kth avenue

48 1 Level n kth avenue 1 1 2 2 1 1 3 1 2 1 3 4 1 3 3 1 4 1 4 6 4 1 1 5 1 10 10 5 6 15 20 15 6

49 n k n-1 k-1 n-1 k = + Level n kth avenue 1 1 2 1 1 1 2 1 3 1 3 3 1 4 1
Level n kth avenue 1 1 2 1 1 1 2 1 3 1 3 3 1 4 1 4 6 4 1 1 5 10 + 10 5 1 6 20 15 6 15 n k n-1 k-1 n-1 k = +

50 1 Level n kth avenue 1 2 2 3 3 4 4 n k k = 0 2 2n n =

51 1 Level n kth avenue 1 2 2 3 3 4 4 n+1 k+1 i k i = k n =

52 Vector Programs < * , * , * , * , *, *, … >
Let’s define a (parallel) programming language called VECTOR that operates on possibly infinite vectors of numbers. Each variable V! can be thought of as: < * , * , * , * , *, *, … >

53 Vector Programs Let k stand for a scalar constant
<k> will stand for the vector <k,0,0,0,…> <0> = <0,0,0,0,…> <1> = <1,0,0,0,…> V! + T! means to add the vectors position-wise <4,2,3,…> + <5,1,1,….> = <9,3,4,…>

54 RIGHT( <1,2,3, …> ) = <0,1,2,3,…>
Vector Programs RIGHT(V!) means to shift every number in V! one position to the right and to place a 0 in position 0 RIGHT( <1,2,3, …> ) = <0,1,2,3,…>

55 Vector Programs Example: Store: V! := <6>;
V! := RIGHT(V!) + <42>; V! := RIGHT(V!) + <2>; V! := RIGHT(V!) + <13>; V! = <6,0,0,0,…> V! = <42,6,0,0,…> V! = <2,42,6,0,…> V!= <13,2,42,6,…> V! = < 13, 2, 42, 6, 0, 0, 0, … >

56 V! = nth row of Pascal’s triangle
Vector Programs Example: Store: V! := <1>; Loop n times V! := V! + RIGHT(V!); V! = <1,0,0,0,…> V! = <1,1,0,0,…> V! = <1,2,1,0,…> V!= <1,3,3,1,…> V! = nth row of Pascal’s triangle

57 Vector programs can be implemented by polynomials!
X1 + X2 + X3 Vector programs can be implemented by polynomials!

58 Programs  Polynomials
The vector V! = < a0, a1, a2, > will be represented by the polynomial: i = 0 aiXi PV =

59  Formal Power Series aiXi PV =
The vector V! = < a0, a1, a2, > will be represented by the formal power series: i = 0 aiXi PV =

60  V! = < a0, a1, a2, . . . > aiXi PV = i = 0 
<0> is represented by <k> is represented by k V! + T! is represented by (PV + PT) RIGHT(V!) is represented by (PV X)

61 V! = nth row of Pascal’s triangle
Vector Programs Example: V! := <1>; Loop n times V! := V! + RIGHT(V!); PV := 1; PV := PV + PV X; V! = nth row of Pascal’s triangle

62 V! = nth row of Pascal’s triangle
Vector Programs Example: V! := <1>; Loop n times V! := V! + RIGHT(V!); PV := 1; PV := PV(1+X); V! = nth row of Pascal’s triangle

63 V! = nth row of Pascal’s triangle
Vector Programs Example: V! := <1>; Loop n times V! := V! + RIGHT(V!); PV = (1+ X)n V! = nth row of Pascal’s triangle

64 Here’s What You Need to Know…
Polynomials count Binomial formula Combinatorial proofs of binomial identities Vector programs Here’s What You Need to Know…


Download ppt "Discrete Mathematics for Computer Science"

Similar presentations


Ads by Google