Counting III: Pascal’s Triangle, Polynomials, and Vector Programs Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

Slides:



Advertisements
Similar presentations
CompSci 102 Discrete Math for Computer Science March 27, 2012 Prof. Rodger Lecture adapted from Bruce Maggs/Lecture developed at Carnegie Mellon, primarily.
Advertisements

Counting Chapter 6 With Question/Answer Animations.
Counting III: Pascal’s Triangle, Polynomials, and Vector Programs Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2003 Lecture.
Sequences, Series, and the Binomial Theorem
Discrete Structures & Algorithms More Counting. + + ( ) + ( ) = ? Counting II: Recurring Problems and Correspondences.
CSE115/ENGR160 Discrete Mathematics 04/17/12
Counting II: Recurring Problems And Correspondences Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2004 Lecture 10Feb 12, 2004Carnegie.
Counting I: One To One Correspondence and Choice Trees Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2004 Lecture 9Feb 10,
CSE115/ENGR160 Discrete Mathematics 02/21/12
Counting II: Pascal, Binomials, and Other Tricks Great Theoretical Ideas In Computer Science A. Gupta D. Sleator CS Fall 2010 Lecture 8Sept. 16,
CompSci 102 Discrete Math for Computer Science March 22, 2012 Prof. Rodger Lecture adapted from Bruce Maggs/Lecture developed at Carnegie Mellon, primarily.
The Golden Ratio, Fibonacci Numbers, And Other Recurrences Great Theoretical Ideas In Computer Science John LaffertyCS Fall 2006 Lecture 13October.
1 1.0 Students solve equations and inequalities involving absolute value. Algebra 2 Standards.
Advanced Counting Techniques
Fibonacci Numbers, Polynomial Coefficients, and Vector Programs.
1 © 2010 Pearson Education, Inc. All rights reserved 10.1 DEFINITION OF A SEQUENCE An infinite sequence is a function whose domain is the set of positive.
Rev.S08 MAC 1140 Module 12 Introduction to Sequences, Counting, The Binomial Theorem, and Mathematical Induction.
Lecture 11 Feb 17, 1998 Doug Beeferman Carnegie Mellon University Count your blessings... … faster !
Polynomials and Polynomial Functions
Discrete Mathematics, 1st Edition Kevin Ferland
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
Basic Counting. This Lecture We will study some basic rules for counting. Sum rule, product rule, generalized product rule Permutations, combinations.
2.4 Sequences and Summations
Section 2.4. Section Summary Sequences. Examples: Geometric Progression, Arithmetic Progression Recurrence Relations Example: Fibonacci Sequence Summations.
MATH – High School Common Core Vs Tested Kansas Standards Please note: For informational purposes, all Common Core standards are listed, and the tested.
Chapter 6 With Question/Answer Animations 1. Chapter Summary The Basics of Counting The Pigeonhole Principle Permutations and Combinations Binomial Coefficients.
Slide 7- 1 Copyright © 2006 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
1 Section 5.5 Solving Recurrences Any recursively defined function ƒ with domain N that computes numbers is called a recurrence or recurrence relation.
Great Theoretical Ideas in Computer Science.
Great Theoretical Ideas in Computer Science.
Sequences and Summations
1 Binomial Coefficients CS 202 Epp, section ??? Aaron Bloomfield.
Copyright © Cengage Learning. All rights reserved. CHAPTER 9 COUNTING AND PROBABILITY.
Section 2.4. Section Summary Sequences. Examples: Geometric Progression, Arithmetic Progression Recurrence Relations Example: Fibonacci Sequence Summations.
COMPSCI 102 Discrete Mathematics for Computer Science.
Discrete Mathematics for Computer Science. + + ( ) + ( ) = ? Counting II: Recurring Problems and Correspondences Chapter 9 slides 1-54.
Great Theoretical Ideas in Computer Science.
Sequences and Summations Section 2.4. Section Summary Sequences. – Examples: Geometric Progression, Arithmetic Progression Recurrence Relations – Example:
Functions Section 2.3. Section Summary Definition of a Function. – Domain, Cdomain – Image, Preimage Injection, Surjection, Bijection Inverse Function.
Fibonacci Numbers, Vector Programs and a new kind of science.
COMPSCI 102 Discrete Mathematics for Computer Science.
In this section we develop general methods for finding power series representations. Suppose that f (x) is represented by a power series centered at.
Counting II: Recurring Problems And Correspondences Great Theoretical Ideas In Computer Science John LaffertyCS Fall 2005 Lecture 7Sept 20, 2005Carnegie.
Counting I: One To One Correspondence and Choice Trees Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2004 Lecture 9Feb 10,
Choose Your Representation! Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2005 Lecture 14 Feb 24, 2005 Carnegie Mellon University.
Counting II: Recurring Problems And Correspondences Great Theoretical Ideas In Computer Science V. AdamchikCS Spring 2006 Lecture 6Feb 2, 2005Carnegie.
Counting I: One To One Correspondence and Choice Trees Great Theoretical Ideas In Computer Science John LaffertyCS Fall 2005 Lecture 6Sept 15,
Section 6.4. Powers of Binomial Expressions Definition: A binomial expression is the sum of two terms, such as x + y. (More generally, these terms can.
Binomial Coefficients and Identities
Polynomials Count! CS Lecture 9 X1 X1 X2 X2 + + X3 X3.
Counting III: Pigeonhole principal, Pascal’s Triangle and more Great Theoretical Ideas In Computer Science S. Rudich V. Adamchik CS Spring 2006.
Chapter 2 1. Chapter Summary Sets The Language of Sets - Sec 2.1 – Lecture 8 Set Operations and Set Identities - Sec 2.2 – Lecture 9 Functions and sequences.
Copyright © 2004 Pearson Education, Inc.. Chapter 7 Further Topics in Algebra.
Developing Your Counting Muscles
Induction: One Step At A Time
Counting III: Pascal’s Triangle, Polynomials, and Vector Programs
The Fibonacci Numbers And An Unexpected Calculation
Generating Functions II
The Golden Ratio, Fibonacci Numbers, And Other Recurrences
Great Theoretical Ideas in Computer Science
Basic Counting.
Great Theoretical Ideas in Computer Science
Michael Duquette & Whitney Sherman
Counting III: Pascal’s Triangle, Polynomials, and Vector Programs
Counting II: Recurring Problems And Correspondences
Great Theoretical Ideas in Computer Science
Discrete Mathematics for Computer Science
Introduction to Discrete Mathematics
Counting II: Recurring Problems And Correspondences
Presentation transcript:

Counting III: Pascal’s Triangle, Polynomials, and Vector Programs Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2003 Lecture 11Feb 14, 2004Carnegie Mellon University X1 X1 X2 X2 + + X3 X3

1 + X 1 + X 2 + X 3 + … + X n-1 + X n = 1 + X 1 + X 2 + X 3 + … + X n-1 + X n = X n X - 1 The Geometric Series

1 + X 1 + X 2 + X 3 + … + X n + ….. = 1 + X 1 + X 2 + X 3 + … + X n + ….. = X The Infinite Geometric Series

(X-1) ( 1 + X 1 + X 2 + X 3 + … + X n + … ) = X 1 + X 2 + X 3 + … + X n + X n+1 + … X 1 - X 2 - X 3 - … - X n-1 – X n - X n+1 - … = X 1 + X 2 + X 3 + … + X n + ….. = 1 + X 1 + X 2 + X 3 + … + X n + ….. = X

1 + x + ….. ____________________ 1-x | 1 -[1 – x] _____ x -[x – x 2 ] ______ x X 1 + X 2 + X 3 + … + X n + ….. = 1 + X 1 + X 2 + X 3 + … + X n + ….. = X

1 + aX 1 + a 2 X 2 + a 3 X 3 + … + a n X n + ….. = 1 + aX 1 + a 2 X 2 + a 3 X 3 + … + a n X n + ….. = aX Geometric Series (Linear Form)

( 1 + aX 1 + a 2 X 2 + … + a n X n + ….. ) ( 1 + bX 1 + b 2 X 2 + … + b n X n + ….. ) = 1 (1 – aX)(1-bX) Geometric Series (Quadratic Form)

( 1 + aX 1 + a 2 X 2 + … + a n X n + ….. ) ( 1 + bX 1 + b 2 X 2 + … + b n X n + ….. ) = 1 + c 1 X c k X k + … Suppose we multiply this out to get a single, infinite polynomial. What is an expression for C n ?

( 1 + aX 1 + a 2 X 2 + … + a n X n + ….. ) ( 1 + bX 1 + b 2 X 2 + … + b n X n + ….. ) = 1 + c 1 X c k X k + … a 0 b n + a 1 b n-1 +… a i b n-i … + a n-1 b 1 + a n b 0 c n = a 0 b n + a 1 b n-1 +… a i b n-i … + a n-1 b 1 + a n b 0

( 1 + aX 1 + a 2 X 2 + … + a n X n + ….. ) ( 1 + bX 1 + b 2 X 2 + … + b n X n + ….. ) = 1 + c 1 X c k X k + … a 0 b n + a 1 b n-1 +… a i b n-i … + a n-1 b 1 + a n b 0 If a = b then c n = (n+1)(a n ) a 0 b n + a 1 b n-1 +… a i b n-i … + a n-1 b 1 + a n b 0

a 0 b n + a 1 b n-1 +… a i b n-i … + a n-1 b 1 + a n b 0 (a-b) ( a 0 b n + a 1 b n-1 +… a i b n-i … + a n-1 b 1 + a n b 0 ) a 1 b n +… a i+1 b n-i … + a n b 1 + a n+1 b 0 = a 1 b n +… a i+1 b n-i … + a n b 1 + a n+1 b 0 a 0 b n+1 – a 1 b n … a i+1 b n-i … - a n-1 b 2 - a n b 1 - a 0 b n+1 – a 1 b n … a i+1 b n-i … - a n-1 b 2 - a n b 1 = - b n+1 + a n+1 = a n+1 – b n+1 a 0 b n + a 1 b n-1 +… a i b n-i … + a n-1 b 1 + a n b 0 = a n+1 – b n+1 a - b

( 1 + aX 1 + a 2 X 2 + … + a n X n + ….. ) ( 1 + bX 1 + b 2 X 2 + … + b n X n + ….. ) = 1 + c 1 X c k X k + … a 0 b n + a 1 b n-1 +… a i b n-i … + a n-1 b 1 + a n b 0 if a  b then c n = a 0 b n + a 1 b n-1 +… a i b n-i … + a n-1 b 1 + a n b 0 a n+1 – b n+1 a - b

( 1 + aX 1 + a 2 X 2 + … + a n X n + ….. ) ( 1 + bX 1 + b 2 X 2 + … + b n X n + ….. ) = 1 (1 – aX)(1-bX) Geometric Series (Quadratic Form) a n+1 – b n+1 a - b  n=0.. 1 XnXn = = XnXn or (n+1)a n when a=b

Previously, we saw that Polynomials Count!

What is the coefficient of BA 3 N 2 in the expansion of (B + A + N) 6 ? The number of ways to rearrange the letters in the word BANANA.

1X1X1X1X 1X 1X 1X Choice tree for terms of (1+X) 3 1 X X X2X2 X X2X2 X2X2 X3X3 Combine like terms to get 1 + 3X + 3X 2 + X 3

The Binomial Formula binomial expression Binomial Coefficients

The Binomial Formula

One polynomial, two representations “Product form” or “Generating form” “Additive form” or “Expanded form”

“Closed form” or “Generating form” “Power series” (“Taylor series”) expansion Power Series Representation

By playing these two representations against each other we obtain a new representation of a previous insight: Let x=1. The number of subsets of an n-element set

Let x= -1. Equivalently, By varying x, we can discover new identities

Let x= -1. Equivalently, The number of even-sized subsets of an n element set is the same as the number of odd-sized subsets.

We could discover new identities by substituting in different numbers for X. One cool idea is to try complex roots of unity, however, the lecture is going in another direction.

Proofs that work by manipulating algebraic forms are called “algebraic” arguments. Proofs that build a 1-1 onto correspondence are called “combinatorial” arguments.

Let O n be the set of binary strings of length n with an odd number of ones. Let E n be the set of binary strings of length n with an even number of ones. We gave an algebraic proof that  O n  =  E n   O n  =  E n 

A Combinatorial Proof Let O n be the set of binary strings of length n with an odd number of ones. Let E n be the set of binary strings of length n with an even number of ones. A combinatorial proof must construct a one-to- one correspondence between O n and E n

An attempt at a correspondence Let f n be the function that takes an n-bit string and flips all its bits....but do even n work? In f 6 we have   Uh oh. Complementing maps evens to evens! f n is clearly a one-to-one and onto function for odd n. E.g. in f 7 we have  

A correspondence that works for all n Let f n be the function that takes an n-bit string and flips only the first bit. For example,    

The binomial coefficients have so many representations that many fundamental mathematical identities emerge…

The Binomial Formula (1+X) 1 = (1+X) 0 = (1+X) 2 = (1+X) 3 = X 1 + 2X + 1X X + 3X 2 + 1X 3 (1+X) 4 = 1 + 4X + 6X 2 + 4X 3 + 1X 4

Pascal’s Triangle: k th row are the coefficients of (1+X) k (1+X) 1 = (1+X) 0 = (1+X) 2 = (1+X) 3 = X 1 + 2X + 1X X + 3X 2 + 1X 3 (1+X) 4 = 1 + 4X + 6X 2 + 4X 3 + 1X 4

k th Row Of Pascal’s Triangle: (1+X) 1 = (1+X) 0 = (1+X) 2 = (1+X) 3 = X 1 + 2X + 1X X + 3X 2 + 1X 3 (1+X) 4 = 1 + 4X + 6X 2 + 4X 3 + 1X 4

Inductive definition of kth entry of nth row: Pascal(n,0) = Pacal (n,n) = 1; Pascal(n,k) = Pascal(n-1,k-1) + Pascal(n,k) (1+X) 1 = (1+X) 0 = (1+X) 2 = (1+X) 3 = X 1 + 2X + 1X X + 3X 2 + 1X 3 (1+X) 4 = 1 + 4X + 6X 2 + 4X 3 + 1X 4

“Pascal’s Triangle” Al-Karaji, Baghdad Chu Shin-Chieh 1303 The Precious Mirror of the Four Elements... Known in Europe by 1529 Blaise Pascal 1654

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

Summing The Rows =1=2=4=8=16=32=64

=

Summing on 1 st Avenue

Summing on k th Avenue

=2 =5 =13 =3 =8

Al-Karaji Squares * * * * * =0=1=4=9=16=25=36

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

How many shortest routes from A to B? B A

Manhattan k’th Avenue j’th Street

Manhattan k’th Avenue Level n ……… …………………… ………………………… ………………………………… ………….

Manhattan k’th Avenue Level n ……… …………………… ………………………… ………………………………… ………….

..... level n k’th Avenue

..... level n k’th Avenue

..... level n k’th Avenue

..... level n k’th Avenue

By convention: (empty product = 1)

..... level n k’th Avenue

Application (Al-Karaji):

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:

Vector Programs Let k stand for a scalar constant will stand for the vector = V ! + T ! means to add the vectors position-wise. + =

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( ) =

Vector Programs Example: V ! := ; V ! := RIGHT(V ! ) + ; V ! = V ! = Stare V ! = V ! = V ! =

Vector Programs Example: V ! := ; Loop n times: V ! := V ! + RIGHT(V ! ); V ! = n th row of Pascal’s triangle. Stare V ! = V ! = V ! =

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

Programs -----> Polynomials The vector V ! = will be represented by the polynomial:

Formal Power Series The vector V ! = will be represented by the formal power series:

V ! = is represented by 0 is represented by k RIGHT(V ! ) is represented by (P V X) V ! + T ! is represented by (P V + P T )

Vector Programs Example: V ! := ; Loop n times: V ! := V ! + RIGHT(V ! ); V ! = n th row of Pascal’s triangle. P V := 1; P V := P V + P V X;

Vector Programs Example: V ! := ; Loop n times: V ! := V ! + RIGHT(V ! ); V ! = n th row of Pascal’s triangle. P V := 1; P V := P V (1+ X);

Vector Programs Example: V ! := ; Loop n times: V ! := V ! + RIGHT(V ! ); V ! = n th row of Pascal’s triangle. P V = (1+ X) n

What is the coefficient of X k in the expansion of: ( 1 + X + X 2 + X 3 + X ) n ? Each path in the choice tree for the cross terms has n choices of exponent e 1, e 2,..., e n ¸ 0. Each exponent can be any natural number. Coefficient of X k is the number of non-negative solutions to: e 1 + e e n = k

What is the coefficient of X k in the expansion of: ( 1 + X + X 2 + X 3 + X ) n ?

( 1 + X + X 2 + X 3 + X ) n =

What is the coefficient of X k in the expansion of: (a 0 + a 1 X + a 2 X 2 + a 3 X 3 + …) ( 1 + X + X 2 + X ) = (a 0 + a 1 X + a 2 X 2 + a 3 X 3 + …) / (1 – X) ? a 0 + a 1 + a a k

(a 0 + a 1 X + a 2 X 2 + a 3 X 3 + …) / (1 – X) = PREFIXSUM(a 0 + a 1 X + a 2 X 2 + a 3 X 3 + …)

Let’s add an instruction called PREFIXSUM to our VECTOR language. W ! := PREFIXSUM(V ! ) means that the i th position of W contains the sum of all the numbers in V from positions 0 to i.

What does this program output? V ! := 1 ! ; Loop k times: V ! := PREFIXSUM(V ! ) ; k’th Avenue

Can you see how PREFIXSUM can be represented by a familiar polynomial expression?

W ! := PREFIXSUM(V ! ) is represented by P W = P V / (1-X) = P V ( 1+X+X 2 +X 3 + ….. )

Al-Karaji Program Zero_Ave := PREFIXSUM( ); First_Ave := PREFIXSUM(Zero_Ave); Second_Ave :=PREFIXSUM(First_Ave); Output:= First_Ave + 2*RIGHT(Second_Ave) OUTPUT ! = OUTPUT ! =

Al-Karaji Program Zero_Ave = 1/(1-X); First_Ave = 1/(1-X) 2 ; Second_Ave = 1/(1-X) 3 ; Output = 1/(1-X) 2 + 2X/(1-X) 3 (1-X)/(1-X) 3 + 2X/(1-X) 3 = (1+X)/(1-X) 3

(1+X)/(1-X) 3 Zero_Ave := PREFIXSUM( ); First_Ave := PREFIXSUM(Zero_Ave); Second_Ave :=PREFIXSUM(First_Ave); Output:= RIGHT(Second_Ave) + Second_Ave Second_Ave = <1, 3, 6, 10, 15,. RIGHT(Second_Ave) = <0, 1, 3, 6, 10,. Output = <1, 4, 9, 16, 25

(1+X)/(1-X) 3 outputs outputs X(1+X)/(1-X) 3 outputs outputs The k th entry is k 2 The k th entry is k 2

X(1+X)/(1-X) 3 =  k 2 X k What does X(1+X)/(1-X) 4 do?

X(1+X)/(1-X) 4 expands to :  S k X k where S k is the sum of the first k squares

Aha! Thus, if there is an alternative interpretation of the k th coefficient of X(1+X)/(1-X) 4 we would have a new way to get a formula for the sum of the first k squares.

Using pirates and gold we found that: THUS:

Coefficient of X k in P V = (X 2 +X)(1-X) -4 is the sum of the first k squares:

Vector programs -> Polynomials -> Closed form expression

Expressions of the form Finite Polynomial / Finite Polynomial Finite Polynomial / Finite Polynomial are called Rational Polynomial Expressions. Clearly, these expressions have some deeper interpretation as a programming language.

What about this one? X/(1-X-X 2 )

The action of dividing one polynomial by another can simulate a program to recursively compute Fibonacci numbers.

Vector Program I/O Example: INPUT I ! ; /* not allowed to alter I ! */ V ! := I ! + 1; Loop n times: V ! := V ! + RIGHT(V ! ) + I ! ; OUTPUT V !

Vector Recurrence Relations Let P be a vector program that takes input. A vector relation is any statement of the form: V ! = P( V ! ) If there is a unique V ! satisfying the relation, then V ! is said to be defined by the relation V ! = P( V ! ).

Fibonacci Numbers Recurrence Relation Definition: Vector Recurrence Relation Definition: F ! = RIGHT( F ! + ) + RIGHT( RIGHT( F ! ) )

RIGHT(F ! + ) = 0, a 0 + 1, a 1, a 2, a 3, F ! = a 0, a 1, a 2, a 3, a 4,... RIGHT( RIGHT( F ! ) ) = 0, 0, a 0, a 1, a 2, a 3,. = 0, 0, a 0, a 1, a 2, a 3,.

F ! = RIGHT( F ! + 1 ) + RIGHT( RIGHT( F ! ) ) RIGHT(F + 1) = (F+1) X F = a 0 + a 1 X + a 2 X 2 + a 3 X 3 + RIGHT( RIGHT( F ) ) = F X 2 = F X 2

F = (F + 1) X + F X 2 RIGHT(F + 1) = (F+1) X F = a 0 + a 1 X + a 2 X 2 + a 3 X RIGHT( RIGHT( F ) ) = F X 2 = F X 2

F = F X + X + F X 2 Solve for F. F - FX - FX 2 = X F(1-X-X 2 ) = X F = X/(1-X-X 2 )

What is the Power Series Expansion of x / (1-x-x 2 ) ?

Since the bottom is quadratic we can factor it. X / (1-X-X 2 ) = X/(1-  X)(1 – (-  ) -1 X) where  = “The Golden Ratio”

X (1 –  X)(1- (-  -1 X) Linear factors on the bottom  n=0.. ∞ = XnXn ?

( 1 + aX 1 + a 2 X 2 + … + a n X n + ….. ) ( 1 + bX 1 + b 2 X 2 + … + b n X n + ….. ) = 1 (1 – aX)(1-bX) Geometric Series (Quadratic Form) a n+1 – b n+1 a - b  n=0.. 1 XnXn = =

1 (1 –  X)(1- (-  -1 X) Geometric Series (Quadratic Form)  n+1 – (-  - 1) n+1 5555  n=0.. ∞ = XnXn

X (1 –  X)(1- (-  -1 X) Power Series Expansion of F  n+1 – (-  - 1) n+1 5555  n=0.. ∞ = X n+1

The i th Fibonacci number is:

References Applied Combinatorics, by Alan Tucker Generatingfunctionology, Herbert Wilf