39
1 Sequences and Sequences and Summations Summations CS/APMA 202 CS/APMA 202 Rosen section 3.2 Rosen section 3.2 Aaron Bloomfield Aaron Bloomfield

1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

Embed Size (px)

Citation preview

Page 1: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

11

Sequences and Sequences and SummationsSummations

CS/APMA 202CS/APMA 202

Rosen section 3.2Rosen section 3.2

Aaron BloomfieldAaron Bloomfield

Page 2: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

22

DefinitionsDefinitions

Sequence: an ordered list of elementsSequence: an ordered list of elements Like a set, but:Like a set, but:

Elements can be duplicatedElements can be duplicated

Elements are orderedElements are ordered

Page 3: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

33

SequencesSequences

A sequence is a function from a subset of A sequence is a function from a subset of ZZ to a set S to a set S Usually from the positive or non-negative intsUsually from the positive or non-negative ints aann is the image of is the image of nn

aann is a term in the sequence is a term in the sequence

{{aann} means the entire sequence} means the entire sequence The same notation as sets!The same notation as sets!

Page 4: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

44

Sequence examplesSequence examples

aann = 3 = 3nn The terms in the sequence are The terms in the sequence are aa11, , aa22, , aa33, …, …

The sequence {The sequence {aann} is { 3, 6, 9, 12, … }} is { 3, 6, 9, 12, … }

bbnn = 2 = 2nn

The terms in the sequence are The terms in the sequence are bb11, , bb22, , bb33, …, …

The sequence {The sequence {bbnn} is { 2, 4, 8, 16, 32, … }} is { 2, 4, 8, 16, 32, … }

Note that sequences are indexed from 1Note that sequences are indexed from 1 Not in all other textbooks, though!Not in all other textbooks, though!

Page 5: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

55

Geometric vs. arithmetic Geometric vs. arithmetic sequencessequences

The difference is in how they growThe difference is in how they grow

Arithmetic sequences increase by a constant Arithmetic sequences increase by a constant amountamount aann = 3 = 3nn The sequence {The sequence {aann} is { 3, 6, 9, 12, … }} is { 3, 6, 9, 12, … } Each number is 3 more than the lastEach number is 3 more than the last Of the form: Of the form: ff((xx) = ) = dxdx + + aa

Geometric sequences increase by a constant Geometric sequences increase by a constant factorfactor bbnn = 2 = 2nn

The sequence {The sequence {bbnn} is { 2, 4, 8, 16, 32, … }} is { 2, 4, 8, 16, 32, … } Each number is twice the previousEach number is twice the previous Of the form: Of the form: ff((xx) = ) = ararxx

Page 6: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

66

Fibonacci sequenceFibonacci sequence

Sequences can be neither geometric or Sequences can be neither geometric or arithmeticarithmetic FFnn = F = Fn-1n-1 + F + Fn-2n-2, where the first two terms are 1, where the first two terms are 1

Alternative, Alternative, FF((nn) = ) = FF((nn-1) + -1) + FF((nn-2)-2) Each term is the sum of the previous two termsEach term is the sum of the previous two terms Sequence: { 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, … }Sequence: { 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, … } This is the Fibonacci sequenceThis is the Fibonacci sequence

Full formula:Full formula:

n

nn

nF25

5151)(

Page 7: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

77

Fibonacci sequence in natureFibonacci sequence in nature

1385321

Page 8: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

88

Reproducing rabbitsReproducing rabbits

You have one pair of rabbits on an islandYou have one pair of rabbits on an island The rabbits repeat the following:The rabbits repeat the following:

Get pregnant one monthGet pregnant one month

Give birth (to another pair) the next monthGive birth (to another pair) the next month This process repeats indefinitely (no deaths)This process repeats indefinitely (no deaths) Rabbits get pregnant the month they are bornRabbits get pregnant the month they are born

How many rabbits are there after 10 How many rabbits are there after 10 months?months?

Page 9: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

99

Reproducing rabbitsReproducing rabbits

First month: 1 pairFirst month: 1 pair The original pairThe original pair

Second month: 1 pairSecond month: 1 pair The original (and now pregnant) pairThe original (and now pregnant) pair

Third month: 2 pairsThird month: 2 pairs The child pair (which is pregnant) and the parent pair The child pair (which is pregnant) and the parent pair

(recovering)(recovering)

Fourth month: 3 pairsFourth month: 3 pairs ““Grandchildren”: Children from the baby pair (now pregnant)Grandchildren”: Children from the baby pair (now pregnant) Child pair (recovering)Child pair (recovering) Parent pair (pregnant)Parent pair (pregnant)

Fifth month: 5 pairsFifth month: 5 pairs Both the grandchildren and the parents reproducedBoth the grandchildren and the parents reproduced 3 pairs are pregnant (child and the two new born rabbits)3 pairs are pregnant (child and the two new born rabbits)

Page 10: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

1010

Reproducing rabbitsReproducing rabbits

Sixth month: 8 pairsSixth month: 8 pairs All 3 new rabbit pairs are pregnant, as well as those not All 3 new rabbit pairs are pregnant, as well as those not

pregnant in the last month (2)pregnant in the last month (2)

Seventh month: 13 pairsSeventh month: 13 pairs All 5 new rabbit pairs are pregnant, as well as those not All 5 new rabbit pairs are pregnant, as well as those not

pregnant in the last month (3)pregnant in the last month (3)

Eighth month: 21 pairsEighth month: 21 pairs All 8 new rabbit pairs are pregnant, as well as those not All 8 new rabbit pairs are pregnant, as well as those not

pregnant in the last month (5)pregnant in the last month (5)

Ninth month: 34 pairsNinth month: 34 pairs All 13 new rabbit pairs are pregnant, as well as those not All 13 new rabbit pairs are pregnant, as well as those not

pregnant in the last month (8)pregnant in the last month (8)

Tenth month: 55 pairsTenth month: 55 pairs All 21 new rabbit pairs are pregnant, as well as those not All 21 new rabbit pairs are pregnant, as well as those not

pregnant in the last month (13)pregnant in the last month (13)

Page 11: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

1111

Reproducing rabbitsReproducing rabbits

Note the sequence:Note the sequence:

{ 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, … }{ 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, … }

The Fibonacci sequence againThe Fibonacci sequence again

Page 12: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

1212

Fibonacci sequenceFibonacci sequence

Another application:Another application:

Fibonacci references from Fibonacci references from http://en.wikipedia.org/wiki/Fibonacci_sequencehttp://en.wikipedia.org/wiki/Fibonacci_sequence

Page 13: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

1313

Fibonacci sequenceFibonacci sequence

As the terms increase, the ratio between As the terms increase, the ratio between successive terms approaches 1.618successive terms approaches 1.618

This is called the “golden ratio”This is called the “golden ratio” Ratio of human leg length to arm lengthRatio of human leg length to arm length Ratio of successive layers in a conch shellRatio of successive layers in a conch shell

Reference: http://en.wikipedia.org/wiki/Golden_ratioReference: http://en.wikipedia.org/wiki/Golden_ratio

618933989.12

15

)(

)1(lim

nF

nFn

Page 14: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

1414

The Golden The Golden RatioRatio

Page 15: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

1515

Page 16: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

1616

Determining the sequence formulaDetermining the sequence formula

Given values in a sequence, how do you Given values in a sequence, how do you determine the formula?determine the formula?

Steps to consider:Steps to consider: Is it an arithmetic progression (each term a constant Is it an arithmetic progression (each term a constant

amount from the last)?amount from the last)? Is it a geometric progression (each term a factor of Is it a geometric progression (each term a factor of

the previous term)?the previous term)? Does the sequence it repeat (or cycle)?Does the sequence it repeat (or cycle)? Does the sequence combine previous terms?Does the sequence combine previous terms? Are there runs of the same value?Are there runs of the same value?

Page 17: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

1717

Determining the sequence formulaDetermining the sequence formula

Rosen, question 9 (page 236)Rosen, question 9 (page 236)

a)a) 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, …1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, …The sequence alternates 1’s and 0’s, increasing the number of The sequence alternates 1’s and 0’s, increasing the number of 1’s and 0’s each time1’s and 0’s each time

b)b) 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, …1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, …This sequence increases by one, but repeats all even This sequence increases by one, but repeats all even numbers oncenumbers once

c)c) 1, 0, 2, 0, 4, 0, 8, 0, 16, 0, …1, 0, 2, 0, 4, 0, 8, 0, 16, 0, …The non-0 numbers are a geometric sequence (2The non-0 numbers are a geometric sequence (2nn) ) interspersed with zerosinterspersed with zeros

d)d) 3, 6, 12, 24, 48, 96, 192, …3, 6, 12, 24, 48, 96, 192, …Each term is twice the previous: geometric progressionEach term is twice the previous: geometric progression

aann = 3*2 = 3*2n-1n-1

Page 18: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

1818

Determining the sequence formulaDetermining the sequence formula

e)e) 15, 8, 1, -6, -13, -20, -27, …15, 8, 1, -6, -13, -20, -27, …Each term is 7 less than the previous termEach term is 7 less than the previous termaann = 22 - 7 = 22 - 7nn

f)f) 3, 5, 8, 12, 17, 23, 30, 38, 47, …3, 5, 8, 12, 17, 23, 30, 38, 47, …The difference between successive terms increases by one The difference between successive terms increases by one each timeeach timeaa11 = 3, = 3, aann = = aann-1-1 + + nnaann = = nn((nn+1)/2 + 2+1)/2 + 2

g)g) 2, 16, 54, 128, 250, 432, 686, …2, 16, 54, 128, 250, 432, 686, …Each term is twice the cube of Each term is twice the cube of nnaann = 2* = 2*nn33

h)h) 2, 3, 7, 25, 121, 721, 5041, 403212, 3, 7, 25, 121, 721, 5041, 40321Each successive term is about Each successive term is about nn times the previous times the previousaann = = nn! + 1! + 1My solution: My solution: aann = a = an-1n-1 * n - n + 1 * n - n + 1

Page 19: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

1919

OEIS: Online Encyclopedia of OEIS: Online Encyclopedia of Integer SequencesInteger Sequences

Online at Online at http://www.research.att.com/~njas/sequences/http://www.research.att.com/~njas/sequences/

Page 20: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

2020

Useful sequencesUseful sequences

nn22 = 1, 4, 9, 16, 25, 36, … = 1, 4, 9, 16, 25, 36, …

nn33 = 1, 8, 27, 64, 125, 216, … = 1, 8, 27, 64, 125, 216, …

nn44 = 1, 16, 81, 256, 625, 1296, … = 1, 16, 81, 256, 625, 1296, …

22nn = 2, 4, 8, 16, 32, 64, … = 2, 4, 8, 16, 32, 64, …

33nn = 3, 9, 27, 81, 243, 729, … = 3, 9, 27, 81, 243, 729, …

nn! = 1, 2, 6, 24, 120, 720, …! = 1, 2, 6, 24, 120, 720, …

Listed in Table 1, page 228 of RosenListed in Table 1, page 228 of Rosen

Page 21: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

21

Quick surveyQuick survey

I felt I understood sequences…I felt I understood sequences…

a)a) Very wellVery well

b)b) With some review, I’ll be goodWith some review, I’ll be good

c)c) Not reallyNot really

d)d) Not at allNot at all

Page 22: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

2222

Geeky TattoosGeeky Tattoos

Page 23: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

2323

SummationsSummations

A summation:A summation:

oror

is like a for loop:is like a for loop:

int sum = 0;int sum = 0;

for ( int j = m; j <= n; j++ )for ( int j = m; j <= n; j++ )

sum += a(j);sum += a(j);

n

mjja j

nmj a

index ofsummation

upper limit

lower limit

Page 24: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

2424

Evaluating sequencesEvaluating sequences

Rosen, question 13, page 3.2Rosen, question 13, page 3.2

5

1

)1(k

k

4

0

)2(j

j

10

1

3i

8

0

1 22j

jj

2 + 3 + 4 + 5 + 6 = 202 + 3 + 4 + 5 + 6 = 20

(-2)(-2)00 + (-2) + (-2)11 + (-2) + (-2)22 + (-2) + (-2)33 + (-2) + (-2)44 = 11 = 11

3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 = 303 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 + 3 = 30

(2(211-2-200) + (2) + (222-2-211) + (2) + (233-2-222) + … (2) + … (21010-2-299) = 511) = 511 Note that each term (except the first Note that each term (except the first

and last) is cancelled by another termand last) is cancelled by another term

Page 25: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

2525

Evaluating sequencesEvaluating sequences

Rosen, question 14, page 3.2Rosen, question 14, page 3.2 S = { 1, 3, 5, 7 }S = { 1, 3, 5, 7 }

What is What is jjS S jj 1 + 3 + 5 + 7 = 161 + 3 + 5 + 7 = 16

What is What is jjS S jj22 1122 + 3 + 322 + 5 + 522 + 7 + 722 = 84 = 84

What is What is jjS S (1/(1/jj)) 1/1 + 1/3 + 1/5 + 1/7 = 176/1051/1 + 1/3 + 1/5 + 1/7 = 176/105

What is What is jjS S 11 1 + 1 + 1 + 1 = 41 + 1 + 1 + 1 = 4

Page 26: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

2626

Sum of a geometricSum of a geometricseries:series:

Example:Example:

20471

12048

12

122

11010

0

j

n

Summation of a geometric seriesSummation of a geometric series

1 if)1(

1 if1

1

0 ran

rr

aarar

nn

j

j

Page 27: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

2727

1

)1(1

1

1

1

1

0

1

1

0

1

0

0

r

aarS

aarrS

aarSrS

aarSrS

aarar

ar

ar

arrrS

arS

n

n

n

n

nn

k

k

n

k

k

n

j

j

n

j

j

n

j

j

Proof of last slideProof of last slide

If If rr = 1, then the sum is: = 1, then the sum is:

anaSn

j

)1(0

Page 28: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

2828

Double summationsDouble summations

Like a nested for loopLike a nested for loop

Is equivalent to:Is equivalent to:int sum = 0;int sum = 0;

for ( int i = 1; i <= 4; i++ )for ( int i = 1; i <= 4; i++ )

for ( int j = 1; j <= 3; j++ )for ( int j = 1; j <= 3; j++ )

sum += i*j;sum += i*j;

4

1

3

1i j

ij

Page 29: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

2929

Useful summation formulaeUseful summation formulae

Well, only 1 really important one:Well, only 1 really important one:

2

)1(

1

nnk

n

k

Page 30: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

3030

All your base are belong to All your base are belong to usus

Flash animationFlash animation Reference: http://en.wikipedia.org/wiki/All_your_base_are_belong_to_usReference: http://en.wikipedia.org/wiki/All_your_base_are_belong_to_us

Page 31: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

3232

CardinalityCardinality

For finite (only) sets, cardinality is the For finite (only) sets, cardinality is the number of elements in the setnumber of elements in the set

For finite and infinite sets, two sets For finite and infinite sets, two sets AA and and BB have the same cardinality if there is a have the same cardinality if there is a one-to-one correspondence from one-to-one correspondence from AA to to BB

Page 32: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

3333

CardinalityCardinality

Example on finite sets:Example on finite sets: Let Let SS = { 1, 2, 3, 4, 5 } = { 1, 2, 3, 4, 5 } Let Let TT = { a, b, c, d, e } = { a, b, c, d, e } There is a one-to-one correspondence between the There is a one-to-one correspondence between the

setssets

Example on infinite sets:Example on infinite sets: Let S = Let S = ZZ++ Let T = { Let T = { xx | | xx = 2 = 2kk and and kk ZZ+ }+ } One-to-one correspondence:One-to-one correspondence:

1 ↔ 21 ↔ 2 2 ↔ 4 2 ↔ 4 3 ↔ 6 3 ↔ 6 4 ↔ 2 4 ↔ 25 ↔ 105 ↔ 10 6 ↔ 12 6 ↔ 12 7 ↔ 14 7 ↔ 14 8 ↔ 16 8 ↔ 16Etc.Etc.

Note that here the ‘↔’ symbol means that there is a Note that here the ‘↔’ symbol means that there is a correspondence between them, not the biconditionalcorrespondence between them, not the biconditional

Page 33: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

3434

More definitionsMore definitions

Countably infinite: elements can be listedCountably infinite: elements can be listed Anything that has the same cardinality as the Anything that has the same cardinality as the

integersintegers Example: rational numbers, ordered pairs of Example: rational numbers, ordered pairs of

integersintegers

Uncountably infinite: elements cannot be Uncountably infinite: elements cannot be listedlisted Example: real numbersExample: real numbers

Page 34: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

3535

Showing a set is countably infiniteShowing a set is countably infinite

Done by showing there is a one-to-one Done by showing there is a one-to-one correspondence between the set and the correspondence between the set and the integersintegers

ExamplesExamples Even numbersEven numbers

Shown two slides agoShown two slides ago Rational numbersRational numbers

Shown in Rosen, page 234-235Shown in Rosen, page 234-235 Ordered pairs of integersOrdered pairs of integers

Shown next slideShown next slide

Page 35: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

3636

Showing ordered pairs of integers Showing ordered pairs of integers are countably infiniteare countably infinite

A one-to-one correspondence

Page 36: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

37

Quick surveyQuick survey

I felt I understood the material in this I felt I understood the material in this slide set…slide set…

a)a) Very wellVery well

b)b) With some review, I’ll be goodWith some review, I’ll be good

c)c) Not reallyNot really

d)d) Not at allNot at all

Page 37: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

38

Quick surveyQuick survey

The pace of the lecture for this The pace of the lecture for this slide set was…slide set was…

a)a) FastFast

b)b) About rightAbout right

c)c) A little slowA little slow

d)d) Too slowToo slow

Page 38: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

39

Quick surveyQuick survey

How interesting was the material in How interesting was the material in this slide set? Be honest!this slide set? Be honest!

a)a) Wow! That was SOOOOOO cool!Wow! That was SOOOOOO cool!

b)b) Somewhat interestingSomewhat interesting

c)c) Rather bortingRather borting

d)d) ZzzzzzzzzzzZzzzzzzzzzz

Page 39: 1 Sequences and Summations CS/APMA 202 Rosen section 3.2 Aaron Bloomfield

4040

Today’s demotivatorsToday’s demotivators