Great Theoretical Ideas in Computer Science

Slides:



Advertisements
Similar presentations
Factoring Trinomials 9-4 ax2 + bx +c
Advertisements

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
Generating Function October 21, 2014 Generating Functions Given an infinite sequence, its ordinary generating function is the power series: ‏G(x) = g.
The Golden Ratio, Fibonacci Numbers, And Other Recurrences Great Theoretical Ideas In Computer Science John LaffertyCS Fall 2006 Lecture 13October.
Fibonacci Numbers, Polynomial Coefficients, and Vector Programs.
Copyright © 2014, 2010 Pearson Education, Inc. Chapter 9 Further Topics in Algebra Copyright © 2014, 2010 Pearson Education, Inc.
§ 4.5 Multiplication of Polynomials. Angel, Elementary Algebra, 7ed 2 Multiplying Polynomials To multiply a monomial by a monomial, multiply their coefficients.
The Binomial Theorem.
1 Section 5.5 Solving Recurrences Any recursively defined function ƒ with domain N that computes numbers is called a recurrence or recurrence relation.
1 Chapter 7 Generating functions. 2 Summary Generating functions Recurrences and generating functions A geometry example Exponential generating functions.
Great Theoretical Ideas in Computer Science.
Counting III: Pascal’s Triangle, Polynomials, and Vector Programs Great Theoretical Ideas In Computer Science Steven RudichCS Spring 2003 Lecture.
Copyright © 2007 Pearson Education, Inc. Slide 8-1.
How do I use Special Product Patterns to Multiply Polynomials?
Generating Functions and Counting Trees. Today’s Plan 1.Generating functions for basic sequences 2.Operations on generating functions 3.Counting 4.Solve.
Analyzing Patterns when Multiplying Polynomials Carol A. Marinas, Ph.D.
COMPSCI 102 Discrete Mathematics for Computer Science.
Polynomial Functions Addition, Subtraction, and Multiplication.
Lesson 76 – Introduction to Complex Numbers HL2 MATH - SANTOWSKI.
Sequences and Series!! !. Finding the Degree of a Sequence Begin by finding the difference between adjacent numbers.
Math I, Sections 2.1 – 2.4 Standard: MM1A2c Add, subtract, multiply and divide polynomials. Today’s Question: What are polynomials, and how do we add,
Geometric Sequences A geometric sequence is a sequence where each # in the seq. is multiplied by a constant (which is called the common ratio (r)) To find.
9.3 Geometric Sequences and Series. 9.3 Geometric Sequences A sequence is geometric if the ratios of consecutive terms are the same. This common ratio.
Patterns in Sequences. Number patterns Sequences of numbers can have interesting patterns. Here we list the most common patterns and how they are made.
Algebra 2 CC 1.3 Apply the Binomial Expansion Theorem Recall: A binomial takes the form; (a+b) Complete the table by expanding each power of a binomial.
By: Michelle Green. Construction of Pascal’s Triangle ROW 0 ROW 1 ROW 2 ROW 3 ROW 4 ROW ROW 6 ALWAYS.
6 – 3 Adding, Subtracting and Multiplying Polynomials Day 1 Objective: Add, subtract, and multiply polynomials.
5.3 Notes – Add, Subtract, & Multiply Polynomials.
Induction in Pascal’s Triangle
Copyright © Cengage Learning. All rights reserved.
Induction in Pascal’s Triangle
Solving Quadratic Equations by Factoring
Developing Your Counting Muscles
Patterns and Sequences
Arithmetic Sequences and Series
The Binomial Expansion Chapter 7
A quick and efficient way to expand binomials
What you need to know To recognise GP’s and use nth term and sum of n terms formulae to solve problems To know about the sum of an infinite GP where How.
Counting III: Pascal’s Triangle, Polynomials, and Vector Programs
9.5 The Binomial Theorem Let’s look at the expansion of (x + y)n
The Fibonacci Numbers And An Unexpected Calculation
a*(variable)2 + b*(variable) + c
Generating Functions II
Ch 4.2: Adding, Subtracting, and Multiplying Polynomials
The Golden Ratio, Fibonacci Numbers, And Other Recurrences
Factoring Polynomials SUM AND PRODUCT
Polynomials and the FFT(UNIT-3)
4-2 The Binomial Theorem Use Pascal’s Triangle to expand powers of binomials Use the Binomial Theorem to expand powers of binomials.
a*(variable)2 + b*(variable) + c
Sequences and Series in the Complex Plane
Number Patterns.
Basic Counting.
a*(variable)2 + b*(variable) + c
Copyright © Cengage Learning. All rights reserved.
5.1 Power Series Method Section 5.1 p1.
Great Theoretical Ideas in Computer Science
Counting III: Pascal’s Triangle, Polynomials, and Vector Programs
Great Theoretical Ideas in Computer Science
Discrete Mathematics for Computer Science
©2001 by R. Villar All Rights Reserved
Introduction to Discrete Mathematics
Section 4.2 Adding, Subtracting and Multiplying Polynomials
Counting II: Recurring Problems And Correspondences
Algebraic Identities.
DETERMINANT MATH 80 - Linear Algebra.
Packet #29 Arithmetic and Geometric Sequences
Matho083 Bianco Warm Up Multiply: 1) (x2) (x3) 2) (3x2) (4x3)
The sum of an Infinite Series
Presentation transcript:

Great Theoretical Ideas in Computer Science 15-251 Great Theoretical Ideas in Computer Science

X1 X2 X3 + Counting III: Generating Functions Lecture 8 (February 5, 2009) X1 X2 + X3

Recall the Geometric Series X - 1 Xn – 1 1 + X1 + X2 + X3 + … + Xn-2 + Xn-1 = 1 - X 1 - Xn = Recall the Geometric Series

the Infinite Geometric Series 1 - X 1 1 + X1 + X2 + X3 + … + Xn + … = the Infinite Geometric Series Holds when |X| < 1 Also makes sense if we view the infinite sum on the left as a formal power series

Formal Power Series  i = 0  aiXi P(X) =

P(X) = 1 + X1 + X2 + X3 + … + Xn + … -X * P(X) = - X1 - X2 - X3 - … - Xn - Xn+1 - … (1- X) P(X) = 1 1 - X 1  P(X) =

 Formal Power Series P(X) = aiXi  i = 0 There are no worries about convergence issues. This is a purely syntactic object.

 Formal Power Series P(X) = aiXi  i = 0 If you want, think of as the infinite vector V = < a0, a1, a2, ..., an, … > But, as you will see, thinking of as a “polynomial” is very natural.

Operations A(X) = a0 + a1 X + a2 X2 + … B(X) = b0 + b1 X + b2 X2 + … adding them together (A+B)(X) = (a0+b0) + (a1+b1) X + (a2+b2) X2 + … like adding the vectors position-wise <4,2,3,…> + <5,1,1,….> = <9,3,4,…>

Operations A(X) = a0 X0 + a1 X1 + a2 X2 + … multiplying by X X * A(X) = 0 X0 + a0 X1 + a1 X2 + a2 X3 + … like shifting the vector entries SHIFT<4,2,3,…> = <0,4,2,3,…>

V = nth row of Pascal’s triangle Example Example: Store: V := <1,0,0,…>; Loop n times V := V + SHIFT(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

V = nth row of Pascal’s triangle Example Example: V := <1,0,0,…>; Loop n times V := V + SHIFT(V); PV := 1; PV := PV(1+X); V = nth row of Pascal’s triangle

V = nth row of Pascal’s triangle Example Example: V := <1,0,0,…>; Loop n times V := V + SHIFT(V); PV = (1+ X)n V = nth row of Pascal’s triangle As expected, the coefficients of PV give the nth row of Pascal’s triangle

 To summarize… P(X) = aiXi Given a sequence V = < a0, a1, a2, ..., an, … > associate a formal power series with it  i = 0  aiXi P(X) = This is the “generating function” for V

Fibonaccis F0 = 0, F1 = 1, Fn = Fn-1 + Fn-2 i.e., the sequence <0,1,1,2,3,5,8,13…> is represented by the power series 0 + 1X1 + 1X2 + 2 X3 + 3 X4 + 5 X5 + 8 X6 +…

Can we write A(X) more succinctly? Two Representations F0 = 0, F1 = 1, Fn = Fn-1 + Fn-2 A(X) = 0 + 1X1 + 1X2 + 2 X3 + 3 X4 + 5 X5 + 8 X6 +… Can we write A(X) more succinctly?

A(X) = F0 + F1 X1 + F2 X2 + F3 X3 + … + Fn Xn +… X A(X) = 0 + F0 X1 + F1 X2 + F2 X3 + … + Fn-1 Xn +… X2 A(X) = 0 + 0 X1 + F0 X2 + F1 X3 + … + Fn-2 Xn +… (1 – X – X2) A(X) = (F_0 – 0 – 0) + (F1 – F0 – 0)X1 + 0 = X X A(X) = (1 – X – X2)

Fibonaccis F0 = 0, F1 = 1, Fn = Fn-1 + Fn-2 has the generating function X A(X) = (1 – X – X2) i.e., the coefficient of Xn in A(X) is Fn

-(X – X2 – X3) X -(X2 – X3 – X4) + X2 -(2X3 – 2X4 – 2X5) + 2X3 + 3X4 -(3X4 – 3X5 – 3X6) + 5X5 -(5X5 – 5X6 – 5X7) + 8X6 -(8X6 – 8X7 – 8X8) 1 – X – X2 X X2 + X3 2X3 + X4 3X4 + 2X5 5X5 + 3X6 8X6 + 5X7

Two representations of the same thing… X F0 = 0, F1 = 1, Fn = Fn-1 + Fn-2 X A(X) = (1 – X – X2)

(1 – X – X2) = (1 - φX)(1 – (-1/φ)X) Closed form? X F0 = 0, F1 = 1, Fn = Fn-1 + Fn-2 A(X) = (1 – X – X2) let’s factor (1 – X – X2) (1 – X – X2) = (1 - φX)(1 – (-1/φ)X) where φ = 1 + √5 2

Simplify, simplify… X F0 = 0, F1 = 1, Fn = Fn-1 + Fn-2 A(X) = (1 - φX)(1 – (-1/φ)X) some elementary algebra omitted…* √5 1 1 √5 -1 1 A(X) = + (1 - φX) (1 – (-1/φ)X) *you are not allowed to say this in your answers…

the Infinite Geometric Series √5 1 1 √5 -1 1 A(X) = + (1 - φX) (1 – (-1/φ)X) 1 = 1 + φ X + φ2 X2 + … + φn Xn + … (1 - φX) 1 - Y 1 = 1 + Y1 + Y2 + Y3 + … + Yn + … the Infinite Geometric Series

1 + (-1/φ) X + … + (-1/φ)n Xn + … (1 – (-1/φ)X) √5 1 1 √5 -1 1 A(X) = + (1 - φX) (1 – (-1/φ)X) 1 = 1 + φ X + φ2 X2 + … + φn Xn + … (1 - φX) 1 = 1 + (-1/φ) X + … + (-1/φ)n Xn + … (1 – (-1/φ)X)  the coefficient of Xn in A(X) is… √5 1 √5 -1 φn (-1/φ)n +

Closed form for Fibonaccis √5 1 √5 -1 Fn = φn + (-1/φ)n where φ = 1 + √5 2 “golden ratio” Abraham de Moivre (1730) Leonhard Euler (1765) J.P.M. Binet (1843)

Closed form for Fibonaccis √5 1 √5 -1 Fn = φn + (-1/φ)n √5 1 Fn = φn closest integer to

To recap… Given a sequence V = < a0, a1, a2, ..., an, … > associate a formal power series with it  i = 0  aiXi P(X) = This is the “generating function” for V We just used this for the Fibonaccis… 28

Multiplication A(X) = a0 + a1 X + a2 X2 + … B(X) = b0 + b1 X + b2 X2 + … multiply them together (A*B)(X) = (a0*b0) + (a0b1 + a1b0) X + (a0b2 + a1b1 + a2b0) X2 + (a0b3 + a1b2 + a2b1 + a3b0 ) X2 + … seems a bit less natural in the vector representation (it’s called a “convolution” there)

Mult.: special case A(X) = a0 + a1 X + a2 X2 + … 1 1-X = Special case: B(X) = 1 + X + X2 + … multiply them together (A*B)(X) = a0 + (a0 + a1) X + (a0 + a1 + a2) X2 + (a0 + a1 + a2 + a3) X2 + … it gives us partial sums!

For example… 1 1-X = Suppose A(X) = 1 + X + X2 + … and B(X) = 1 + X + X2 + … 1 1-X = then (A*B)(X) = 1 + 2X + 3X2 + 4X3 + … 1 1-X = 1 (1-X)2 = 1 1-X * Generating function for the sequence <0,1,2,3,4…>

What happens if we again take prefix sums? 1 (1-X)2 = Take 1 + 2X + 3X2 + 4X3 + … multiplying through by 1/(1-X) 1 (1-X)3 = ¢1 + ¢2X1 + ¢3X2 + ¢4X3 +… Generating function for the triangular numbers!

What’s the pattern? 1 <1,1,1,1,…> = 1-X 1 <1,2,3,4,…> = <¢1,¢2,¢3,¢4,…> 1 (1-X)n = ???

What’s the pattern? 1 , , , , … = 1-X 1 <1,2,3,4,…> = (1-X)2 1 = 1 2 3 1 1-X = , , , , … 1 (1-X)2 = <1,2,3,4,…> 1 (1-X)3 = <¢1,¢2,¢3,¢4,…> 1 (1-X)n = ???

What’s the pattern? 1 , , , , … = 1-X 1 = , , , , … (1-X)2 1 = 1 2 3 1 1-X = , , , , … 1 (1-X)2 = 1 2 1 3 1 4 1 , , , , … 1 (1-X)3 = <¢1,¢2,¢3,¢4,…> 1 (1-X)n = ???

What’s the pattern? 1 , , , , … = 1-X 1 = , , , , … (1-X)2 1 = 1 2 3 1 1-X = , , , , … 1 (1-X)2 = 1 2 1 3 1 4 1 , , , , … 1 (1-X)3 = 2 3 2 4 2 5 2 , , , , … 1 (1-X)n = ???

What’s the pattern? 1 , , , , … = 1-X 1 = , , , , … (1-X)2 1 = 1 2 3 1 1-X = , , , , … 1 (1-X)2 = 1 2 1 3 1 4 1 , , , , … 1 (1-X)3 = 2 3 2 4 2 5 2 , , , , … 1 (1-X)n =

 What’s the pattern? Xk 1 , , , , … = 1-X 1 = , , , , … (1-X)2 1 = 1 2 3 1 1-X = , , , , … 1 (1-X)2 = 1 2 1 3 1 4 1 , , , , … 1 (1-X)3 = 2 3 2 4 2 5 2 , , , , …  k = 0  Xk k+n-1 n-1 1 (1-X)n =

 From Lecture #7 1 1 1 i k+1 = 1 2 1 n n+1 1 3 3 1 1 4 6 4 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1  i = 0 k i n k+1 n+1 = Can be used to derive the coefficient of Xk

What’s the pattern?  k = 0  Xk k+n-1 n-1 1 (1-X)n =

What is the coefficient of Xk in the expansion of: ( 1 + X + X2 + X3 + X4 + . . . . )n ? Another way to see it… Each path in the choice tree for the cross terms has n choices of exponent e1, e2, . . . , en ¸ 0. Each exponent can be any natural number. Coefficient of Xk is the number of non-negative solutions to: e1 + e2 + . . . + en = k

What is the coefficient of Xk in the expansion of: ( 1 + X + X2 + X3 + X4 + . . . . )n ? Another way to see it… n + k - 1 n - 1

Recap: getting partial sums A(X) = a0 + a1 X + a2 X2 + … A(X) 1-X = a0 + (a0 + a1) X + (a0 + a1 + a2) X2 + (a0 + a1 + a2 + a3) X2 + … dividing by (1-X) gives us partial sums!

Here’s an interesting use…  k = 0  Xk (k+2)(k+1) 2 1 (1-X)3 = k+2 2 3/2 (1-X)2 1 1-X ½ subtract off and add  k = 0  Xk k2 2 X(1+X) 2(1-X)3 =

  k2 Xk Xk sum of first k squares From the previous page… k = 0  X(1+X) (1-X)3 = hence if we take partial sums…  k = 0  Xk sum of first k squares X(1+X) (1-X)3 = 1 1-X *

Coefficient of Xk in (X2+X)/(1-X)4 is the sum of the first k squares:

So finally…

a different counting problem… Finally, a different counting problem…

Let cn = number of ways to pick exactly n fruits. E.g., c5 = 6 What is a closed form for cn?

Recall Multiplication A(X) = a0 + a1 X + a2 X2 + … B(X) = b0 + b1 X + b2 X2 + … multiply them together (A*B)(X) = (a0*b0) + (a0b1 + a1b0) X + (a0b2 + a1b1 + a2b0) X2 + (a0b3 + a1b2 + a2b1 + a3b0 ) X2 + …

So if A(x), B(x), O(x) and P(x) are the generating functions for the number of ways to fill baskets using only one kind of fruit the generating function for number of ways to fill basket using any of these fruit is given by C(x) = A(x)B(x)O(x)P(x)

Suppose we only pick bananas bn = number of ways to pick n fruits, only bananas. <1,0,1,0,1,0,…> 1 1-X2 = B(x) = 1 + x2 + x4 + x6 + …

Suppose we only pick apples an = number of ways to pick n fruits, only apples. <1,0,0,0,0,1,…> 1 1-X5 = A(x) = 1 + x5 + x10 + x15 + …

Suppose we only pick oranges on = number of ways to pick n fruits, only oranges. <1,1,1,1,1,0,0,0,…> 1-X5 1-X = O(x) = 1 + x + x2 + x3 + x4

Suppose we only pick pears pn = number of ways to pick n fruits, only pears. <1,1,0,0,0,0,0,…> 1-X2 1-X = P(x) = 1 + x

Let cn = number of ways to pick exactly n fruits of any type  cn xn = A(x) B(x) O(x) P(x) 1 1-X2 1 (1-X)2 1 1-X5 1-X5 1-X 1-X2 1-X = =

cn = n+1. Let cn = number of ways to pick exactly n fruits of any type cn is coefficient of Xn in cn = n+1. <1,2,3,4,…>

More operations: Differentiation A(X) = a0 + a1 X + a2 X2 + … differentiate it… A’(X) = a1 + 2a2 X + 3a3 X2 …  i = 0  (i+1)ai+1 Xi A’(X) =  i = 0  iai Xi X A’(X) =

Here’s What You Need to Know… Formal Power Series Basic operations on Formal Power Series Writing the generating function for a recurrence binomial and multinomial coefficients Solving G.F. to get closed form G.F.s for common sequences Prefix sums using G.F.s Using G.F.s to solve counting problems Here’s What You Need to Know…