Counting III: Pascal’s Triangle, Polynomials, and Vector Programs Great Theoretical Ideas In...

67
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

Transcript of Counting III: Pascal’s Triangle, Polynomials, and Vector Programs Great Theoretical Ideas In...

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

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

(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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

(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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

(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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

(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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

(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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

(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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

(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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

(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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

Previously, we saw that

Polynomials Count!

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

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

0

(1 )n

n k

k

nx x

k

The Binomial Formula

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

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

How many shortest routes from A to B?

B

A

10

5

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

Manhattan

k’th Avenue01

23

4

j’th Street 01

23

4

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

Manhattan

k’th Avenue01

23

4

Level n0

1

34

2

………

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

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

………….

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

Manhattan

k’th Avenue01

23

4

Level n0

1

34

2

………

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

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

………….

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

. . . . .. . . . .

. . . . .. . . . .

. . . . .

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

. . . . .. . . . .

. . . . .. . . . .

. . . . .

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

. . . . .. . . . .

. . . . .. . . . .

. . . . .

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

. . . . .. . . . .

. . . . .. . . . .

. . . . .

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

X1 X2 + + X3

Vector programs can be

implemented by polynomials!

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

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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 Great Theoretical Ideas In Computer Science Steven RudichCS 15-251 Spring 2003 Lecture.

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