Solving Recurrence Equations
Total Page:16
File Type:pdf, Size:1020Kb
Great Theoretical Ideas In Computer Science V. Adamchik CS 15-251 Spring 2010 D. Sleator Solve in integers Lecture 8 Feb 04, 2010 Carnegie Mellon University Recurrences and Continued Fractions x1 + x2 +…+ x5 = 40 xkrk; yk=xk – k y1 + y2 +…+ y5 = 25 y ≥ 0; k 29 4 Partitions Solve in integers Find the number of ways to partition the integer n x + y + z = 11 3 = 1+1+1=1+2 xr0; yb3; zr0 4=1+1+1+1=1+1+2=1+3=2+2 2 3 x1 2x2 3x3 ... nxn n [X11] 1 x x x (1 -x) 2 1 (1 -x)(1 -x2)(1 -x3)...(1 -xn) Leonardo Fibonacci The rabbit reproduction model •A rabbit lives forever In 1202, Fibonacci has become •The population starts as a single newborn interested in rabbits and what they do pair •Every month, each productive pair begets a new pair which will become productive after 2 months old Fn= # of rabbit pairs at the beginning of the nth month month 1 2 3 4 5 6 7 rabbits 1 1 2 3 5 8 13 1 F =0, F =1, 0 1 WARNING!!!! Fn=Fn-1+Fn-2 for n≥2 This lecture has What is a closed form explicit mathematical formula for Fn? content that can be shocking to some students. n n-1 n-2 Characteristic Equation - - = 0 n-2 2 Characteristic Fn=Fn-1+Fn-2 iff ( - - 1) = 0 equation Consider solutions of the form: iff 2 - - 1 = 0 n 1 5 Fn= for some (unknown) constant ≠ 0 2 = , or = -1/ must satisfy: (“phi”) is the golden ratio n - n-1 - n-2 = 0 a,b a n + b (-1/ )n = , or = -(1/ ) satisfies the inductive condition So for all these values of the Adjust a and b to fit the base inductive condition is satisfied: conditions. n=0: a + b = 0 2 - - 1= 0 n=1: a 1 + b (-1/ )1 = 1 Do any of them happen to satisfy the base condition as well? a= 1/ 5 b= -1/ 5 F0=0, F1=1 2 Fibonacci Power Series Leonhard Euler (1765) n ( 1 )n Fn k 5 Fk x ?? k 0 x 1 x x2 Fibonacci Bamboozlement Cassini’s Identity 2 n Fn+1Fn-1 - Fn = (-1) We dissect FnxFn square and rearrange pieces into Fn+1xFn-1 square From the previous lecture Characteristic Equation dn dn 1 2dn 2 dn dn 1 2dn 2 d0 0, d1 1 d0 0, d1 1 2 2 0 1 1, 2 2 n n dn a ( 1) b 2 3 n n Characteristic Equation dn a ( 1) b 2 x 2x x 0 0 n n 1 n 2 d0 0 a ( 1) b 2 a b x0 1, x1 2 1 1 d1 1 a ( 1) b 2 a 2 b 1 1 b ,a 3 3 Characteristic Equation Characteristic Equation Theorem. Let be a root of multiplicity p xn 2xn 1 xn 2 of the characteristic equation. Then 2 2 1 0 λn ,n λn ,n2λn ,...,np-1λn are all solutions. 1 2 1 From the previous lecture: xn 2xn 1 xn 2 Rogue Recurrence The theorem says that xn=n is a solution. an 5an 1 8an 2 4an 3 a0 0, a1 1, a2 4 This can be easily verified: n = 2 n - n Characteristic equation: 3 5 2 8 4 0 1 1, 2 3 2 4 a 5a 8a 4a n n 1 n 2 n 3 The Golden Ratio a0 0, a1 1, a2 4 “Some other majors have their General solution: n n an a b 2 c n 2 mystery numbers, like and e. In Computer Science the mystery a0 0 a b a b 0, number is , the Golden Ratio.” – 1 S.Rudich a1 1 a 2b 2c c 2 a2 4 a 4b 8c n-1 an n 2 Golden Ratio -Divine Proportion Golden Ratio - the divine Ratio obtained when you divide a line segment proportion into two unequal parts such that the ratio of 2 1 5 the whole to the larger part is the same as 1 0 the ratio of the larger to the smaller. 2 AC AB A B C = 1.6180339887498948482045… AB BC “Phi” is named after the Greek sculptor 2 AC AB AC 2 AB BC BC 1 0 Phidias AC AB AC AB 2 1 BC BC BC Which is the most attractive Aesthetics rectangle? plays a central role in renaissance art and architecture. After measuring the dimensions of pictures, cards, books, snuff boxes, writing paper, windows, and such, psychologist Gustav Fechner claimed that the preferred rectangle had sides in the golden ratio (1871). 5 Which is the most attractive The Golden Ratio rectangle? 1 Golden Rectangle Divina Proportione Table of contents Luca Pacioli (1509) •The first considerable effect Pacioli devoted an entire book to the •The second essential effect marvelous properties of . The book •The third singular effect was illustrated by a friend of his •The fourth ineffable effect named: •The fifth admirable effect •The sixth inexpressible effect Leonardo Da Vinci •The seventh inestimable effect •The ninth most excellent effect •The twelfth incomparable effect •The thirteenth most distinguished effect Divina Proportione Table of contents Luca Pacioli (1509) “For the sake of salvation, the list "Ninth Most Excellent Effect" must end here” – Luca Pacioli two diagonals of a regular pentagon divide each other in the Divine Proportion. AC AB C A B AB BC 6 Expanding Recursively Expanding Recursively 2 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 A (Simple) Continued Fraction Is A Continued Fraction can have a Any Expression Of The Form: finite or infinite number of terms. 1 1 a a 1 1 b b 1 1 c c 1 1 d d 1 1 e e 1 1 f f 1 1 g g 1 1 h h 1 1 i i j .... j .... where a, b, c, … are whole numbers. We also denote this fraction by [a,b,c,d,e,f,…] Continued Fraction Representation Recursively Defined Form For CF 81 1 1 5 1 CF whole number 1 1 1 1 whole number 1 CF 1 = [1,1,1,1,1,0,0,0,…] 7 Euclid’s GCD = Continued Fraction Proposition: Any finite continued fraction Euclid(A,B) = Euclid(B, A mod B) evaluates to a rational. Stop when B=0 a b q1 r1 Converse: Any rational has b r1 q2 r2 a finite continued fraction r1 r2 q3 r3 representation. .... rk 1 rk qk 1 0 Euclid’s GCD = Continued Fraction Euclid’s GCD = Continued Fraction a 1 a r1 1 a b q1 r1 a b q1 r1 q q q1 1 1 b b b b b b r q r r1 b r q r r1 1 2 2 1 2 2 b r 1 1 2 r1 r2 q3 r3 q2 q2 q1 r1 r2 q3 r3 r1 1 r1 r1 q r1 r2 .... 2 .... r2 r1 r3 1 rk 1 rk qk 1 0 1 r r q 0 q q q1 k 1 k k 1 3 3 r2 1 r2 r2 r q2 q 1 3 3 r2 r3 A Pattern for Divine Proportion 1 Let r1 = [1,0,0,0,…] = 1 1 n n 1 r2 = [1,1,0,0,0,…] = 2/1 1 1 n r3 = [1,1,1,0,0,0…] = 3/2 Fn r = [1,1,1,1,0,0,0…] = 5/3 lim lim n 1 lim n 1 4 n F n n and so on. n 1 n 1 1 Theorem: = Fn/Fn-1 when n -> 8 Heads-on Magic conversion 50 km = 34 + 13 + 3 How to convert kilometers into miles? 50 = F9 + F7 + F4 F8 + F6 + F3 = 31 miles Quadratic Equations A Periodic CF 2 3 13 1 X – 3x – 1 = 0 3 13 3 X 1 2 3 2 1 X2 = 3X + 1 3 1 3 1 3 X = 3 + 1/X 1 3 1 3 1 3 1 X = 3 + 1/X = 3 + 1/[3 + 1/X] = … 3 3 .... A period-2 CF Proposition: Any quadratic 1 2 1 solution has a periodic 1 continued fraction. 3 1 1 4 Converse: Any periodic 1 continued fraction is the 8 1 solution of a quadratic 4 equation 1 8 4 ... 9 Euclid’s GCD = Continued Fraction a b q r What about those 1 1 π 3 1 0.1415 non-periodic b r q r 1 7 0.1415 0.00885 continued fractions? 1 2 2 0.1415 15 0.00885 0.00882 r1 r2 q3 r3 0.00885 1 0.00882 0.000078 What is the .... continued fraction rk 1 rk qk 1 0 expansion for ? ?? What is the pattern? What is the pattern? 1 1 3 e 11 1 1 7 1 1 1 15 2 1 1 1 1 1 1 292 1 1 1 1 4 1 1 1 1 1 1 1 1 1 1 2 6 1 .... 1 .... Every irrational number greater than 1 is the limit of a unique infinite continued fraction. Every irrational number Suppose that y>1 is irrational and y = [b0;b1,b2, . .]. greater than 1 is the 1 1 limit of a y b0 b0 b ... y unique infinite 1 1 continued fraction. where y1 > 1. Thus, 1 b0 y y y1 Similarly, for all bk. 10 To calculate the continued fraction for a real number What a cool y, set y0 =y and then representation! bk yk Finite CF: Rationals 1 Periodic CF: Quadratic y k 1 roots yk bk And some numbers reveal hidden regularity.