105
Counting III: Pascal’s Triangle, Polynomials, and Vector Programs Great Theoretical Ideas In Computer Science Steven Rudich CS 15-251 Spring 2003 Lecture 11 Feb 14, 2004 Carnegie Mellon University X 1 X 2 + + X 3

Counting III: Pascal’s Triangle, Polynomials, and Vector Programs

Embed Size (px)

DESCRIPTION

X 1. X 2. +. +. X 3. Counting III: Pascal’s Triangle, Polynomials, and Vector Programs. X n+1 - 1. 1 + X 1 + X 2 + X 3 + … + X n-1 + X n =. X - 1. The Geometric Series. 1. 1 + X 1 + X 2 + X 3 + … + X n + ….. =. 1 - X. The Infinite Geometric Series. 1. - PowerPoint PPT Presentation

Citation preview

Page 1: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Counting III: Pascal’s Triangle, Polynomials, and Vector

Programs

Great Theoretical Ideas In Computer Science

Steven Rudich

CS 15-251 Spring 2003

Lecture 11 Feb 14, 2004 Carnegie Mellon University

X1 X2 + + X3

Page 2: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

1 + X1 + X11 + X + X22 + X + X 33 + … + X + … + Xn-1n-1 + X + Xnn ==

XXn+1 n+1 - 1- 1

XX - 1- 1

The Geometric Series

Page 3: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

1 + X1 + X11 + X + X22 + X + X 33 + … + X + … + Xnn + ….. + ….. ==

11

1 - X1 - X

The Infinite Geometric Series

Page 4: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

(X-1) ( 1 + X1 + X2 + X 3 + … + Xn + … )= X1 + X2 + X 3 + … + Xn + Xn+1

+ …. - 1 - X1 - X2 - X 3 - … - Xn-1 – Xn - Xn+1 - …

= 1

1 + X1 + X11 + X + X22 + X + X 33 + … + X + … + Xnn + ….. + ….. ==

11

1 - X1 - X

Page 5: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

1 + x + ….. ____________________1-x | 1 -[1 – x] _____ x -[x – x2 ]

______ x2

-....

1 + X1 + X11 + X + X22 + X + X 33 + … + X + … + Xnn + ….. + ….. ==

11

1 - X1 - X

Page 6: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

1 + aX1 + aX11 + a + a22XX22 + a + a33X X 33 + … + a + … + annXXnn + ….. =+ ….. =

11

1 - aX1 - aX

Geometric Series (Linear Form)

Page 7: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

(1 + aX1 + a2X2 + … + anXn + …..) (1 + bX1 + b2X2 + … + bnXn

+ …..) =

11

(1 – aX)(1-bX)(1 – aX)(1-bX)

Geometric Series (Quadratic Form)

Page 8: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

(1 + aX1 + a2X2 + … + anXn + …..) (1 + bX1 + b2X2 + … + bnXn

+ …..) =

1 + c1X1 + .. + ck Xk + …

Suppose we multiply this out to get a single, infinite

polynomial.

What is an expression for Cn?

Page 9: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

(1 + aX1 + a2X2 + … + anXn + …..) (1 + bX1 + b2X2 + … + bnXn

+ …..) =

1 + c1X1 + .. + ck Xk + …

cn =

aa00bbnn + a + a11bbn-1n-1 +… a +… aiibbn-in-i… + a… + an-1n-1bb11 + +

aannbb00

Page 10: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

(1 + aX1 + a2X2 + … + anXn + …..) (1 + bX1 + b2X2 + … + bnXn

+ …..) =

1 + c1X1 + .. + ck Xk + …

If a = b then

cn = (n+1)(an)

aa00bbnn + a + a11bbn-1n-1 +… a +… aiibbn-in-i… + a… + an-1n-1bb11 + +

aannbb00

Page 11: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

(a-b) (aa00bbnn + a + a11bbn-1n-1 +… a +… aiibbn-in-i… + a… + an-1n-1bb11 + a + annbb00)

= aa11bbnn +… a +… ai+1i+1bbn-in-i… + a… + annbb11 + a + an+1n+1bb00

- aa00bbn+1 n+1 – a – a11bbnn… a… ai+1i+1bbn-in-i… - a… - an-1n-1bb22 - a - annbb11

= - bn+1 + an+1

= an+1 – bn+1

aa00bbnn + a + a11bbn-1n-1 +… a +… aiibbn-in-i… + a… + an-1n-1bb11 + a + annbb00 = = aan+1 n+1 – – bbn+1n+1

aa - b- b

Page 12: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

(1 + aX1 + a2X2 + … + anXn + …..) (1 + bX1 + b2X2 + … + bnXn

+ …..) =

1 + c1X1 + .. + ck Xk + …

if a b then

cn =

aa00bbnn + a + a11bbn-1n-1 +… a +… aiibbn-in-i… + a… + an-1n-1bb11 + +

aannbb00

aan+1 n+1 – – bbn+1n+1

aa - b- b

Page 13: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

(1 + aX1 + a2X2 + … + anXn + …..) (1 + bX1 + b2X2 + … + bnXn

+ …..) =

11

(1 – aX)(1-bX)(1 – aX)(1-bX)

Geometric Series (Quadratic Form)

aan+1 n+1 – – bbn+1n+1

aa - b- b

n=0..1Xn

=

=

n=0..1 Xnor (n+1)a(n+1)ann

when a=b

Page 14: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Previously, we saw that

Polynomials Count!

Page 15: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

What is the coefficient of BA3N2 in the expansion of

(B + A + N)6?

The number of ways to

rearrange the letters in the

word BANANA.

Page 16: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

1 X 1 X1 X 1 X

1 X 1 X

1 X

Choice tree for terms of (1+X)3

1 X X X2 X X2 X2 X3

Combine like terms to get 1 + 3X + 3X2 + X3

Page 17: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

The Binomial Formula

(1 X) FHGIKJ

FHGIKJ

FHGIKJ

FHGIKJ

FHGIKJ

n k nn n

Xn

Xn

kX

n

nX

0 1 22 ... ...

binomial expression

Binomial Coefficients

Page 18: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

0

(1 )n

n k

k

nx x

k

The Binomial Formula

Page 19: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

0

(1 )n

n k

k

nx x

k

One polynomial, two representations

“Product form” or“Generating form” “Additive form” or

“Expanded form”

Page 20: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

0

0

(1 )n

n k

k

k

k

nx x

k

nx

k

“Closed form” or“Generating form”

“Power series” (“Taylor series”) expansion

Since 0 if n

k nk

Power Series Representation

Page 21: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

By playing these two representations againsteach other we obtain a new representation ofa previous insight:

0

0

(1 )

2

nn k

k

nn

k

nx x

k

n

k

Let x=1.

The number ofThe number ofsubsets of an subsets of an nn-element set-element set

Page 22: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

0

0

1

even odd

(1 )

0 ( 1)

2

nn k

k

nk

k

n nn

k k

nx x

k

n

k

n n

k k

Let x= -1.

Equivalently,

By varying x, we can discover new identities

Page 23: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

0

0

1

even odd

(1 )

0 ( 1)

2

nn k

k

nk

k

n nn

k k

nx x

k

n

k

n n

k k

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.

Page 24: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

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.

0

(1 )n

n k

k

nx x

k

Page 25: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Proofs that work by manipulating algebraic forms

are called “algebraic” arguments. Proofs that build a 1-1 onto correspondence are

called “combinatorial” arguments.

0

(1 )n

n k

k

nx x

k

Page 26: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Let Let OOnn be the set of binary strings of be the set of binary strings of length length nn with an with an oddodd number of ones. number of ones.

Let Let EEnn be the set of binary strings of be the set of binary strings of length length nn with an with an even even number of ones.number of ones.

We gave an We gave an algebraicalgebraic proof that proof that

OOn n = = E Enn

1

even odd

2n n

n

k k

n n

k k

Page 27: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

A Combinatorial Proof

Let Let OOnn be the set of binary strings of length be the set of binary strings of length nn with an with an oddodd number of ones. number of ones.

Let Let EEnn be the set of binary strings of length be the set of binary strings of length nn with an with an even even number of ones.number of ones.

A A combinatorialcombinatorial proof must construct a proof must construct a one-one-to-one correspondence to-one correspondence betweenbetween OOn n and and EEn n

Page 28: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

An attempt at a correspondenceLet fn be the function that takes an

n-bit string and flips all its bits.

...but do even n work? In f6 we have

110011 001100

101010 010101

Uh oh. Complementing maps evens to evens!

fn is clearly a one-to-one and onto function

for odd n. E.g. in f7 we have

0010011 1101100

1001101 0110010

Page 29: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

A correspondence that works for all n

Let Let ffnn be the function that takes an be the function that takes an n-bit string and flips only n-bit string and flips only the first bitthe first bit..

For example,For example,

0010011 0010011 1010011 10100111001101 1001101 0001101 0001101

110011 110011 010011 010011101010 101010 001010 001010

Page 30: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

The binomial coefficients have so many representations that

many fundamental mathematical identities

emerge…

0

(1 )n

n k

k

nx x

k

Page 31: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

The Binomial Formula

(1+X)1 =

(1+X)0 =

(1+X)2 =

(1+X)3 =

1

1 + 1X

1 + 2X + 1X2

1 + 3X + 3X2 + 1X3

(1+X)4 = 1 + 4X + 6X2 + 4X3 + 1X4

Page 32: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Pascal’s Triangle:kth row are the coefficients of (1+X)k

(1+X)1 =

(1+X)0 =

(1+X)2 =

(1+X)3 =

1

1 + 1X

1 + 2X + 1X2

1 + 3X + 3X2 + 1X3

(1+X)4 = 1 + 4X + 6X2 + 4X3 + 1X4

Page 33: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

kth Row Of Pascal’s Triangle:

(1+X)1 =

(1+X)0 =

(1+X)2 =

(1+X)3 =

1

1 + 1X

1 + 2X + 1X2

1 + 3X + 3X2 + 1X3

(1+X)4 = 1 + 4X + 6X2 + 4X3 + 1X4

, , ,..., ,...0 1 2

n n n n n

k n

Page 34: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

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 =

1

1 + 1X

1 + 2X + 1X2

1 + 3X + 3X2 + 1X3

(1+X)4 = 1 + 4X + 6X2 + 4X3 + 1X4

Page 35: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

0

0

1 1

0 1

2 2 2

1

1 1

1 2 1

1 3 3

0 1 2

3 3 3

0 31

3

1 2

“Pascal’s Triangle”

Al-Karaji, Baghdad 953-1029

Chu Shin-Chieh 1303The Precious Mirror of the Four Elements. . . Known in Europe by 1529 Blaise Pascal 1654

Page 36: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Pascal’s Triangle

11

1 11 1

1 2 11 2 1

1 3 3 11 3 3 1

1 4 6 4 11 4 6 4 1

1 5 10 10 5 11 5 10 10 5 1

1 6 15 20 15 6 11 6 15 20 15 6 1

“It is extraordinaryhow fertile in

properties thetriangle is.

Everyone cantry hishand.”

Page 37: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Summing The RowsSumming The Rows

11

1 1 ++ 1 1

1 1 ++ 2 2 ++ 1 1

1 1 ++ 3 3 ++ 3 3 ++ 1 1

1 1 ++ 4 4 ++ 6 6 ++ 4 4 ++ 1 1

1 1 ++ 5 5 ++ 10 10 ++ 10 10 ++ 5 5 ++ 1 1

1 1 ++ 6 6 ++ 15 15 ++ 20 20 ++ 15 15 ++ 6 6 ++ 1 1

=1=1

=2=2

=4=4

=8=8

=16=16

=32=32

=64=64

0

2n

n

k

n

k

Page 38: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

11

1 11 1

1 2 11 2 1

1 3 3 11 3 3 1

1 4 6 4 11 4 6 4 1

1 5 10 10 5 11 5 10 10 5 1

1 6 15 20 15 6 11 6 15 20 15 6 1

6+20+6 1+15+15+1=

Page 39: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Summing on 1Summing on 1stst Avenue Avenue

11

1 11 1

1 2 11 2 1

1 3 3 11 3 3 1

1 4 6 4 11 4 6 4 1

1 5 10 10 5 11 5 10 10 5 1

1 6 15 20 15 6 11 6 15 20 15 6 1

1 ( 1)

1 2 2

n n

i k i k

i n n ni

Page 40: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

11

1 11 1

1 2 11 2 1

1 3 3 11 3 3 1

1 4 6 4 11 4 6 4 1

1 5 10 10 5 11 5 10 10 5 1

1 6 15 20 15 6 11 6 15 20 15 6 1

Summing on kSumming on kthth Avenue Avenue

1

1

n

i k

i n

k k

Page 41: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

11

1 11 1

1 2 11 2 1

1 3 3 11 3 3 1

1 4 6 4 11 4 6 4 1

1 5 10 10 5 11 5 10 10 5 1

1 6 15 20 15 6 11 6 15 20 15 6 1

=2

=5

=13

=3

=8

Page 42: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

11

1 11 1

1 2 11 2 1

1 3 3 11 3 3 1

1 4 6 4 11 4 6 4 1

1 5 10 10 5 11 5 10 10 5 1

1 6 15 20 15 6 11 6 15 20 15 6 1

222

2222

Page 43: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Al-Karaji SquaresAl-Karaji Squares

11

1 1 1 1

1 1 2 2 ++ 2*2*11

1 1 3 3 ++ 2*2*3 3 1 1

1 1 4 4 ++ 2*2*6 4 6 4 1 1

1 1 5 5 ++ 2*2*10 10 10 10 5 5 1 1

1 1 6 6 ++ 2*2*15 15 20 20 15 15 6 6 1 1

=0=0

=1=1

=4=4

=9=9

=16=16

=25=25

=36=36

Page 44: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

All these properties can be proved inductively and algebraically. We will give combinatorial proofs using

the Manhattan block walking representation of

binomial coefficients.

Page 45: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

How many shortest routes from A to B?

B

A

10

5

Page 46: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Manhattan

k’th Avenue01

23

4

j’th Street 01

23

4

Page 47: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Manhattan

k’th Avenue01

23

4

Level n0

1

34

2

………

…………………… …………………………

…………………………………

………….

Page 48: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Manhattan

k’th Avenue01

23

4

Level n0

1

34

2

………

…………………… …………………………

…………………………………

………….

Page 49: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

. . . . .. . . . .

. . . . .. . . . .

. . . . .

level nk’th Avenue1

11

11

1

1

11

11

32

34 46

156 65 510 10

1520

Page 50: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

. . . . .. . . . .

. . . . .. . . . .

. . . . .

level nk’th Avenue1

1

1

1

1

1

1

1

1

11

3

2

3

4 46

156 6

5 510 10

1520

1 1

1

n n n

k k k

Page 51: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

. . . . .. . . . .

. . . . .. . . . .

. . . . .

level nk’th Avenue1

1

1

1

1

1

1

1

1

11

3

2

3

4 46

156 6

5 510 10

1520

1

even

2n

k

n

k

Page 52: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

. . . . .. . . . .

. . . . .. . . . .

. . . . .

level nk’th Avenue1

1

1

1

1

1

1

1

1

11

3

2

3

4 46

156 6

5 510 10

1520

2

0

2n

k

n n

k n

Page 53: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

0! 1

1 if 0

0 if 0 or

nk

k

nk k n

k

By convention:

(empty product = 1)

Page 54: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

1

1

1

n

i

i n

k k

1

Corollary ( 1)

1 ( 1)

2 2

n

i

k

n n ni

. . . . .. . . . .

. . . . .. . . . .

. . . . .

level nk’th Avenue1

1

1

1

1

1

1

1

1

11

3

2

3

4 46

156 6

5 510 10

1520

Page 55: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Application (Al-Karaji):

2 2 2 2 2

0

1

1 2 3

(1 0 1) (2 1 2) (3 2 3) ( ( 1) )

1 0 2 1 3 2 ( 1)

2 3 4 5 12

2 2 2 2 2 2

1 1 (2 1)( 1)2

3 2 6

n

i

n

i

i n

n n n

n n i

n n

n n n n n

Page 56: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

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:

< * , * , * , * , *, *, . . . . . . . . . >

0 1 2 3 4 5 . . . . . . . . .

Page 57: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

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

Page 58: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

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,. …>

Page 59: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Vector Programs

Example:

V! := <6>;V! := RIGHT(V!) + <42>;V! := RIGHT(V!) + <2>;V! := RIGHT(V!) + <13>;

VV!! = < 13, 2, 42, 6, 0, 0, 0, . . . > = < 13, 2, 42, 6, 0, 0, 0, . . . >

Stare

V! = <6,0,0,0,..>V! = <42,6,0,0,..>V! = <2,42,6,0,..> V!

= <13,2,42,6,.>

Page 60: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Vector Programs

Example:

V! := <1>;

Loop n times: V! := V! + RIGHT(V!);

VV!! = n = nthth row of Pascal’s triangle. row of Pascal’s triangle.

Stare

V! = <1,0,0,0,..>

V! = <1,1,0,0,..>V! = <1,2,1,0,..> V! = <1,3,3,1,.>

Page 61: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

X1 X2 + + X3

Vector programs can be

implemented by polynomials!

Page 62: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Programs -----> Polynomials

The vector V! = < a0, a1, a2, . . . > will be represented by the polynomial:

Page 63: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Formal Power Series

The vector V! = < a0, a1, a2, . . . > will be represented by the formal power series:

Page 64: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

V! = < a0, a1, a2, . . . >

<0> is represented by 0<k> is represented by k

RIGHT(V! ) is represented by (PV X)

V! + T! is represented by (PV + PT)

Page 65: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Vector Programs

Example:

V! := <1>;

Loop n times: V! := V! + RIGHT(V!);

VV!! = n = nthth row of Pascal’s triangle. row of Pascal’s triangle.

PV := 1;

PV := PV + PV X;

Page 66: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Vector Programs

Example:

V! := <1>;

Loop n times: V! := V! + RIGHT(V!);

VV!! = n = nthth row of Pascal’s triangle. row of Pascal’s triangle.

PV := 1;

PV := PV (1+ X);

Page 67: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Vector Programs

Example:

V! := <1>;

Loop n times: V! := V! + RIGHT(V!);

VV!! = n = nthth row of Pascal’s triangle. row of Pascal’s triangle.

PV = (1+ X)n

Page 68: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

What is the coefficient of Xk in the expansion of:

( 1 + X + X2 + X3 + X4

+ . . . . )n ?

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

Page 69: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

What is the coefficient of Xk in the expansion of:

( 1 + X + X2 + X3 + X4

+ . . . . )n ?

n

n -1

1k

Page 70: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

( 1 + X + X2 + X3 + X4

+ . . . . )n =

k

k 0

nX

n -1

11

1n

k

X

Page 71: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

What is the coefficient of Xk in the expansion of:

(a0 + a1X + a2X2 + a3X3 + …) ( 1 + X + X2 + X3

+ . . . )

= (a0 + a1X + a2X2 + a3X3 + …) / (1 – X) ?

a0 + a1 + a2 + .. + ak

Page 72: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

(a0 + a1X + a2X2 + a3X3 + …) / (1

– X)

= k

k 0 i 0

a X

i k

i

=

PREFIXSUM(a0 + a1X + a2X2 + a3X3 + …)

Page 73: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Let’s add an instruction called PREFIXSUM to our

VECTOR language.

W! := PREFIXSUM(V!)

means that the ith position of W contains the sum of all the numbers in V from

positions 0 to i.

Page 74: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

What does this program output?

V! := 1! ;Loop k times: V! := PREFIXSUM(V!) ;

k’th Avenue01

23

4

Page 75: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Can you see how PREFIXSUM can be represented by a

familiar polynomial expression?

Page 76: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

W! := PREFIXSUM(V!)

is represented by

PW = PV / (1-X)

= PV (1+X+X2+X3+

….. )

Page 77: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Al-Karaji Program

Zero_Ave := PREFIXSUM(<1>);First_Ave := PREFIXSUM(Zero_Ave);Second_Ave :=PREFIXSUM(First_Ave);

Output:= First_Ave + 2*RIGHT(Second_Ave)

OUTPUTOUTPUT!! = = <1, 4, 9, 25, 36, 49, …. ><1, 4, 9, 25, 36, 49, …. >

Page 78: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

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)(1-X)/(1-X)3 3 + 2X/(1-X)+ 2X/(1-X)3 3

= (1+X)/(1-X)= (1+X)/(1-X)33

Page 79: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

(1+X)/(1-X)(1+X)/(1-X)33

Zero_Ave := PREFIXSUM(<1>);First_Ave := PREFIXSUM(Zero_Ave);Second_Ave :=PREFIXSUM(First_Ave);

Output:= RIGHT(Second_Ave) + Second_Ave

Second_Ave = <1, 3, 6, 10, 15,. Second_Ave = <1, 3, 6, 10, 15,.

RIGHT(Second_Ave) = <0, 1, 3, 6, 10,.RIGHT(Second_Ave) = <0, 1, 3, 6, 10,.Output = <1, 4, 9, 16, 25

Page 80: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

(1+X)/(1-X)(1+X)/(1-X)3 3 outputs <1, 4, 9, ..>outputs <1, 4, 9, ..>

X(1+X)/(1-X)X(1+X)/(1-X)3 3 outputs <0, 1, 4, 9, ..>outputs <0, 1, 4, 9, ..>

The kThe kthth entry is k entry is k22

Page 81: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

X(1+X)/(1-X)X(1+X)/(1-X)3 3 = = k k22XXkk

What does X(1+X)/(1-X)What does X(1+X)/(1-X)44 do?do?

Page 82: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

X(1+X)/(1-X)X(1+X)/(1-X)44 expands to : expands to :

SSkk X Xkk

where Swhere Skk is the sum of the is the sum of the first k squaresfirst k squares

Page 83: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Aha! Thus, if there is an Aha! Thus, if there is an alternative interpretation of alternative interpretation of

the kthe kthth coefficient of coefficient of X(1+X)/(1-X)X(1+X)/(1-X)44

we would have a new way we would have a new way to get a formula for the sum to get a formula for the sum

of the first k squares.of the first k squares.

Page 84: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Using pirates and gold we found that:

k

k 0

nX

n -1

11

1n

k

X

k

k 0

X3

4

31

1

k

X

THUS:

Page 85: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Coefficient of Xk in PV = (X2+X)(1-X)-4

is the sum of the first k squares:

k

k 0

X3

4

31

1

k

X

Page 86: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Vector programs -> Polynomials-> Closed form expression

Page 87: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Expressions of the formExpressions of the form

Finite Polynomial / Finite Finite Polynomial / Finite PolynomialPolynomial

are called are called Rational Polynomial Rational Polynomial ExpressionsExpressions. .

Clearly, these expressions have Clearly, these expressions have some deeper interpretation as a some deeper interpretation as a

programming language.programming language.

Page 88: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

What about this one?

X/(1-X-X2)

Page 89: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

0 1 2 30 1 2 32

01i

ii

xF x F x F x F x F x

x x

The action of dividing one polynomial by another can

simulate a program to recursively compute Fibonacci

numbers.

Page 90: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

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!

Page 91: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

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! ).

Page 92: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Fibonacci Numbers

0 1

1 2 1

0, 1,

,n n n n

F F

F F F

Recurrence Relation Definition:

Vector Recurrence Relation Definition:

FF!! = RIGHT( F = RIGHT( F! ! + <1> ) + RIGHT( RIGHT( F+ <1> ) + RIGHT( RIGHT( F!! ) ) ) )

Page 93: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

FF!! = RIGHT( F = RIGHT( F! ! + <+ <1>1> ) + RIGHT( RIGHT( F ) + RIGHT( RIGHT( F!! ) ) ) )

RIGHTRIGHT(F(F! ! +<+<1>1>) ) = = 00, a, a0 0 + + 11, a, a11, a, a22, a, a33,,

FF!! = = aa00, a, a1 1 , a, a22, a, a33, a, a44, . . ., . . .

RIGHTRIGHT( ( RIGHTRIGHT( F( F!! ) ) ) )

= = 00, , 00 , a , a00, a, a11, a, a22, a, a33, ., .

Page 94: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

FF!! = RIGHT( F = RIGHT( F! ! + + 11 ) + RIGHT( RIGHT( F ) + RIGHT( RIGHT( F!! ) ) ) )

RIGHTRIGHT(F(F + + 11)) = = ((FF++11)) XX

FF = = aa00 + a + a1 1 X + aX + a2 2 XX22 + a + a3 3 XX33 + +

RIGHTRIGHT( ( RIGHTRIGHT( F ) )( F ) )

= F= F XX22

Page 95: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

F = (F + 1) X + F XF = (F + 1) X + F X22

RIGHTRIGHT(F(F + 1) + 1) = ( = (F+1F+1)) XX

FF = = aa00 + a + a1 1 X + aX + a2 2 XX22 + a + a3 3 XX33 + . . . + . . .

RIGHTRIGHT( ( RIGHTRIGHT( F ) )( F ) )

= = F F XX22

Page 96: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

F = F X + X + F XF = F X + X + F X22

Solve for F. F - FX - FX2 = XF(1-X-X2) = X

F = X/(1-X-X2)

Page 97: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

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

x2) ?

Page 98: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

Since the bottom is quadratic we can factor

it.

X / (1-X-X2) =

X/(1- X)(1 – (-)-1X)

where =

“The Golden Ratio”

Page 99: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

XX

(1 – (1 – X)(1- (-X)(1- (--1-1X)X)

Linear factors on the bottom

n=0..∞= Xn?

Page 100: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

(1 + aX1 + a2X2 + … + anXn + …..) (1 + bX1 + b2X2 + … + bnXn

+ …..) =

11

(1 – aX)(1-bX)(1 – aX)(1-bX)

Geometric Series (Quadratic Form)

aan+1 n+1 – – bbn+1n+1

aa - b- b

n=0..1Xn

=

=

Page 101: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

11

(1 – (1 – X)(1- (-X)(1- (--1-1X)X)

Geometric Series (Quadratic Form)

n+1 n+1 – (-– (---1)1)n+1n+1

5 5 n=0.. ∞

= Xn

Page 102: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

XX

(1 – (1 – X)(1- (-X)(1- (--1-1X)X)

Power Series Expansion of F

n+1 n+1 – (-– (---1)1)n+1n+1

55 n=0.. ∞

= Xn+1

Page 103: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

0 1 2 30 1 2 32

01i

ii

xF x F x F x F x F x

x x

20

1 1

1 5

i

i i

i

xx

x x

Page 104: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

0 1 2 30 1 2 32

01i

ii

xF x F x F x F x F x

x x

The ith Fibonacci number is:

0

1 1

5

i

i

i

Page 105: Counting III: Pascal’s Triangle, Polynomials,  and Vector Programs

References

Applied Combinatorics, by Alan Tucker

Generatingfunctionology, Herbert Wilf