Chapter 3 Recursion and Recurrence Relations

Total Page:16

File Type:pdf, Size:1020Kb

Chapter 3 Recursion and Recurrence Relations Chapter 3 Recursion and Recurrence Relations CS 130 – Discrete Structures Recursive Examples CS 130 – Discrete Structures 2 Recursion • Recursive definitions: define an entity in terms of itself. • There are two parts: – Basic case (basis): the most primitive case(s) of the entity are defined without reference to the entity. – Recursive (inductive) case: new cases of the entity are defined in terms of simpler cases of the entity. • Recursive sequences – A sequence is an ordered list of objects, which is potentially infinite. s(k) denotes the kth object in the sequence. – A sequence is defined recursively by explicitly naming the first value (or the first few values) in the sequence and then define later values in the sequence in terms of earlier values. CS 130 – Discrete Structures 3 Examples of Recursive Sequence • A recursively defined sequence: – S(1) = 2 …… basis case – S(n) = 2 * S(n-1), for n >= 2 …… recursive case – what does the sequence look like? – T(1) =1 …… basis case – T(n) = T(n-1) + 3, for n >= 2 …… recursive case – what does the sequence look like? CS 130 – Discrete Structures 4 Fibonacci Sequence • The Fibonacci Sequence is defined by: • F(1) = 1, F(2) = 1 …… basis case • F(n) = F(n-2) + F(n-1), for n > 2 …… recursive case • the sequence? • http://www.mcs.surrey.ac.uk/Personal/R.Knott/Fibonacci/fibnat.html#Rabbits CS 130 – Discrete Structures 5 Proofs Related To Recursively Defined Sequence • Proofs of properties about recursively defined entities are typically inductive proofs. • Prove directly from the definition • For example: – prove that in the Fibonacci sequence: – F(n+4) = 3F(n+2) – F(n), for n >= 1 – F(n+1) + F(n-2) = 2F(n), for n >= 3 CS 130 – Discrete Structures 6 Recursively Defined Operations • Certain operations performed on objects can be defined recursively • Examples: – A recursive definition of multiplication: • m * 1 = m • m * n = m * (n-1) + m, for n >= 2 – A recursive definition of exponentiation: • a0 = 1 • an = (an-1)*a, for n > 0 – A recursive definition of factorial operation: • F(0) = 1 • F(n) = n * F(n-1) for n >= 1 CS 130 – Discrete Structures 7 Examples • Give a recursive definition of the following sets of objects: – 1, 3, 9, 27, 81, … – 2, 1, ½, ¼, 1/8, … – 1, 2, 4, 7, 11, 16, 22, … CS 130 – Discrete Structures 8 Recursively Defined Algorithms • If a recurrence relation exists for an operation, then the algorithm for such a relation can be written either iteratively or recursively • Example: factorial, multiplication, etc. • Factorial: S(1) = 2, S(n) = 2S(n-1) for n >= 2 Calculate S(n): if n = 1 then output 2 and return Calculate S(n): j = 2 if n = 1 then S = 2 return 2 while j <= n else S = S*2 return 2*S(n-1) j = j + 1 endif end while output S CS 130 – Discrete Structures 9 Solving Recurrence Relations • Closed-form solution – S(1) = 2 – S(n) = 2*S(n-1) for n >= 2 – Since S(1) = 2 = 21, S(2) = 4 = 22, S(3) = 8 = 23, … – We can see S(n) = 2n, and it is called a closed-form solution to the recurrence relation – Finding a closed-form solution is called solving recurrence relation • General method: expand, guess and verify • Another method: solution formula (will not be covered here) CS 130 – Discrete Structures 10 Example of Expand, Guess, and Verify • The factorial example: – S(1) = 2 – S(n) = 2S(n-1) for n >= 2 • Expand: S(n) = 2S(n-1) = 2[2S(n-2)] = 22S(n-2) = 22[2S(n-3)] = 23S(n-3) • Guess: after k such expansions, the equation has the form: S(n) = 2kS(n-k) – it stops when n-k = 1, that is when k = n-1, replace k with (n-1) – S(n) = 2n-1S(n-(n-1)) = 2n-1S(1) = 2n • Verify: proof by induction CS 130 – Discrete Structures 11 Exercise • Solve the recurrence relation: – F(1) = 1 – F(n) = n*F(n-1) for n >= 2 • Given the Fib. definition, prove that – F(n) = 5*F(n-4) + 3*F(n-5) for n >= 6 CS 130 – Discrete Structures 12.
Recommended publications
  • CS311H: Discrete Mathematics Recursive Definitions Recursive
    Recursive Definitions CS311H: Discrete Mathematics I Should be familiar with recursive functions from programming: Recursive Definitions public int fact(int n) { if(n <= 1) return 1; return n * fact(n - 1); Instructor: I¸sıl Dillig } I Recursive definitions are also used in math for defining sets, functions, sequences etc. Instructor: I¸sıl Dillig, CS311H: Discrete Mathematics Recursive Definitions 1/18 Instructor: I¸sıl Dillig, CS311H: Discrete Mathematics Recursive Definitions 2/18 Recursive Definitions in Math Recursively Defined Functions I Consider the following sequence: I Just like sequences, functions can also be defined recursively 1, 3, 9, 27, 81,... I Example: I This sequence can be defined recursively as follows: f (0) = 3 f (n + 1) = 2f (n) + 3 (n 1) a0 = 1 ≥ an = 3 an 1 · − I What is f (1)? I First part called base case; second part called recursive step I What is f (2)? I Very similar to induction; in fact, recursive definitions I What is f (3)? sometimes also called inductive definitions Instructor: I¸sıl Dillig, CS311H: Discrete Mathematics Recursive Definitions 3/18 Instructor: I¸sıl Dillig, CS311H: Discrete Mathematics Recursive Definitions 4/18 Recursive Definition Examples Recursive Definitions of Important Functions I Some important functions/sequences defined recursively I Consider f (n) = 2n + 1 where n is non-negative integer I Factorial function: I What’s a recursive definition for f ? f (1) = 1 f (n) = n f (n 1) (n 2) · − ≥ I Consider the sequence 1, 4, 9, 16,... I Fibonacci numbers: 1, 1, 2, 3, 5, 8, 13, 21,... I What is a recursive
    [Show full text]
  • Chapter 3 Induction and Recursion
    Chapter 3 Induction and Recursion 3.1 Induction: An informal introduction This section is intended as a somewhat informal introduction to The Principle of Mathematical Induction (PMI): a theorem that establishes the validity of the proof method which goes by the same name. There is a particular format for writing the proofs which makes it clear that PMI is being used. We will not explicitly use this format when introducing the method, but will do so for the large number of different examples given later. Suppose you are given a large supply of L-shaped tiles as shown on the left of the figure below. The question you are asked to answer is whether these tiles can be used to exactly cover the squares of an 2n × 2n punctured grid { a 2n × 2n grid that has had one square cut out { say the 8 × 8 example shown in the right of the figure. 1 2 CHAPTER 3. INDUCTION AND RECURSION In order for this to be possible at all, the number of squares in the punctured grid has to be a multiple of three. It is. The number of squares is 2n2n − 1 = 22n − 1 = 4n − 1 ≡ 1n − 1 ≡ 0 (mod 3): But that does not mean we can tile the punctured grid. In order to get some traction on what to do, let's try some small examples. The tiling is easy to find if n = 1 because 2 × 2 punctured grid is exactly covered by one tile. Let's try n = 2, so that our punctured grid is 4 × 4.
    [Show full text]
  • Recursive Definitions and Structural Induction 1 Recursive Definitions
    Massachusetts Institute of Technology Course Notes 6 6.042J/18.062J, Fall ’02: Mathematics for Computer Science Professor Albert Meyer and Dr. Radhika Nagpal Recursive Definitions and Structural Induction 1 Recursive Definitions Recursive definitions say how to build something from a simpler version of the same thing. They have two parts: • Base case(s) that don’t depend on anything else. • Combination case(s) that depend on simpler cases. Here are some examples of recursive definitions: Example 1.1. Define a set, E, recursively as follows: 1. 0 E, 2 2. if n E, then n + 2 E, 2 2 3. if n E, then n E. 2 − 2 Using this definition, we can see that since 0 E by 1., it follows from 2. that 0 + 2 = 2 E, and 2 2 so 2 + 2 = 4 E, 4 + 2 = 6 E, : : : , and in fact any nonegative even number is in E. Also, by 3., 2 2 2; 4; 6; E. − − − · · · 2 Is anything else in E? The definition doesn’t say so explicitly, but an implicit condition on a recursive definition is that the only way things get into E is as a consequence of 1., 2., and 3. So clearly E is exactly the set of even integers. Example 1.2. Define a set, S, of strings of a’s and b’s recursively as follows: 1. λ S, where λ is the empty string, 2 2. if x S, then axb S, 2 2 3. if x S, then bxa S, 2 2 4. if x; y S, then xy S.
    [Show full text]
  • Triangular Numbers /, 3,6, 10, 15, ", Tn,'" »*"
    TRIANGULAR NUMBERS V.E. HOGGATT, JR., and IVIARJORIE BICKWELL San Jose State University, San Jose, California 9111112 1. INTRODUCTION To Fibonacci is attributed the arithmetic triangle of odd numbers, in which the nth row has n entries, the cen- ter element is n* for even /?, and the row sum is n3. (See Stanley Bezuszka [11].) FIBONACCI'S TRIANGLE SUMS / 1 =:1 3 3 5 8 = 2s 7 9 11 27 = 33 13 15 17 19 64 = 4$ 21 23 25 27 29 125 = 5s We wish to derive some results here concerning the triangular numbers /, 3,6, 10, 15, ", Tn,'" »*". If one o b - serves how they are defined geometrically, 1 3 6 10 • - one easily sees that (1.1) Tn - 1+2+3 + .- +n = n(n±M and (1.2) • Tn+1 = Tn+(n+1) . By noticing that two adjacent arrays form a square, such as 3 + 6 = 9 '.'.?. we are led to 2 (1.3) n = Tn + Tn„7 , which can be verified using (1.1). This also provides an identity for triangular numbers in terms of subscripts which are also triangular numbers, T =T + T (1-4) n Tn Tn-1 • Since every odd number is the difference of two consecutive squares, it is informative to rewrite Fibonacci's tri- angle of odd numbers: 221 222 TRIANGULAR NUMBERS [OCT. FIBONACCI'S TRIANGLE SUMS f^-O2) Tf-T* (2* -I2) (32-22) Ti-Tf (42-32) (52-42) (62-52) Ti-Tl•2 (72-62) (82-72) (9*-82) (Kp-92) Tl-Tl Upon comparing with the first array, it would appear that the difference of the squares of two consecutive tri- angular numbers is a perfect cube.
    [Show full text]
  • Physics 403, Spring 2011 Problem Set 2 Due Thursday, February 17
    Physics 403, Spring 2011 Problem Set 2 due Thursday, February 17 1. A Differential Equation for the Legendre Polynomials (15 pts): In this prob- lem, we will derive a second order linear differential equation satisfied by the Legendre polynomials (−1)n dn P (x) = [(1 − x2)n] : n 2nn! dxn (a) Show that Z 1 2 0 0 Pm(x)[(1 − x )Pn(x)] dx = 0 for m 6= n : (1) −1 Conclude that 2 0 0 [(1 − x )Pn(x)] = λnPn(x) 0 for λn a constant. [ Prime here and in the following questions denotes d=dx.] (b) Perform the integral (1) for m = n to find a relation for λn in terms of the leading n coefficient of the Legendre polynomial Pn(x) = knx + :::. What is kn? 2. A Generating Function for the Legendre Polynomials (20 pts): In this problem, we will derive a generating function for the Legendre polynomials. (a) Verify that the Legendre polynomials satisfy the recurrence relation 0 0 0 Pn − 2xPn−1 + Pn−2 − Pn−1 = 0 : (b) Consider the generating function 1 X n g(x; t) = t Pn(x) : n=0 Use the recurrence relation above to show that the generating function satisfies the first order differential equation d (1 − 2xt + t2) g(x; t) = tg(x; t) : dx Determine the constant of integration by using the fact that Pn(1) = 1. (c) Use the generating function to express the potential for a point particle q jr − r0j in terms of Legendre polynomials. 1 3. The Dirac delta function (15 pts): Dirac delta functions are useful mathematical tools in quantum mechanics.
    [Show full text]
  • Polynomial Sequences Generated by Linear Recurrences
    Innocent Ndikubwayo Polynomial Sequences Generated by Linear Recurrences: Location and Reality of Zeros Polynomial Sequences Generated by Linear Recurrences: Location and Reality of Zeros Linear Recurrences: Location by Sequences Generated Polynomial Innocent Ndikubwayo ISBN 978-91-7911-462-6 Department of Mathematics Doctoral Thesis in Mathematics at Stockholm University, Sweden 2021 Polynomial Sequences Generated by Linear Recurrences: Location and Reality of Zeros Innocent Ndikubwayo Academic dissertation for the Degree of Doctor of Philosophy in Mathematics at Stockholm University to be publicly defended on Friday 14 May 2021 at 15.00 in sal 14 (Gradängsalen), hus 5, Kräftriket, Roslagsvägen 101 and online via Zoom, public link is available at the department website. Abstract In this thesis, we study the problem of location of the zeros of individual polynomials in sequences of polynomials generated by linear recurrence relations. In paper I, we establish the necessary and sufficient conditions that guarantee hyperbolicity of all the polynomials generated by a three-term recurrence of length 2, whose coefficients are arbitrary real polynomials. These zeros are dense on the real intervals of an explicitly defined real semialgebraic curve. Paper II extends Paper I to three-term recurrences of length greater than 2. We prove that there always exist non- hyperbolic polynomial(s) in the generated sequence. We further show that with at most finitely many known exceptions, all the zeros of all the polynomials generated by the recurrence lie and are dense on an explicitly defined real semialgebraic curve which consists of real intervals and non-real segments. The boundary points of this curve form a subset of zero locus of the discriminant of the characteristic polynomial of the recurrence.
    [Show full text]
  • Linear Recurrence Relations: the Theory Behind Them
    Linear Recurrence Relations: The Theory Behind Them David Soukup October 29, 2019 Linear Recurrence Relations Contents 1 Foreword ii 2 The matrix diagonalization method 1 3 Generating functions 3 4 Analogies to ODEs 6 5 Exercises 8 6 References 10 i Linear Recurrence Relations 1 Foreword This guide is intended mostly for students in Math 61 who are looking for a more theoretical background to the solving of linear recurrence relations. A typical problem encountered is the following: suppose we have a sequence defined by an = 2an−1 + 3an−2 where a0 = 0; a1 = 8: Certainly this recurrence defines the sequence fang unambiguously (at least for positive integers n), and we can compute the first several terms without much problem: a0 = 0 a1 = 8 a2 = 2 · a1 + 3 · a0 = 2 · 8 + 3 · 0 = 16 a3 = 2 · a2 + 3 · a1 = 2 · 16 + 3 · 8 = 56 a4 = 2 · a3 + 3 · a2 = 2 · 56 + 3 · 16 = 160 . While this does allow us to compute the value of an for small n, this is unsatisfying for several reasons. For one, computing the value of a100 by this method would be time-consuming. If we solely use the recurrence, we would have to find the previous 99 values of the sequence first. Moreover, until we compute it we have no good idea of how large a100 will be. We can observe from the table above that an grows quite rapidly as n increases, but we do not know how to extrapolate this rate of growth to all n. Most importantly, we would like to know the order of growth of this function.
    [Show full text]
  • Analysis of Non-Linear Recurrence Relations for the Recurrence Coefficients of Generalized Charlier Polynomials
    Journal of Nonlinear Mathematical Physics Volume 10, Supplement 2 (2003), 231–237 SIDE V Analysis of Non-Linear Recurrence Relations for the Recurrence Coefficients of Generalized Charlier Polynomials Walter VAN ASSCHE † and Mama FOUPOUAGNIGNI ‡ † Katholieke Universiteit Leuven, Department of Mathematics, Celestijnenlaan 200 B, B-3001 Leuven, Belgium E-mail: [email protected] ‡ University of Yaounde, Advanced School of Education, Department of Mathematics, P.O. Box 47, Yaounde, Cameroon E-mail: [email protected] This paper is part of the Proceedings of SIDE V; Giens, June 21-26, 2002 Abstract The recurrence coefficients of generalized Charlier polynomials satisfy a system of non- linear recurrence relations. We simplify the recurrence relations, show that they are related to certain discrete Painlev´e equations, and analyze the asymptotic behaviour. 1 Introduction Orthogonal polynomials on the real line always satisfy a three-term recurrence relation. For monic polynomials Pn this is of the form Pn+1(x)=(x − βn)Pn(x) − γnPn−1(x), (1.1) with initial values P0 = 1 and P−1 = 0. For the orthonormal polynomials pn the recurrence relation is xpn(x)=an+1pn+1(x)+bnpn(x)+anpn−1(x), (1.2) 2 where an = γn and bn = βn. The recurrence coefficients are given by the integrals 2 an = xpn(x)pn−1(x) dµ(x),bn = xpn(x) dµ(x) and can also be expressed in terms of determinants containing the moments of the orthog- onality measure µ [11]. For classical orthogonal polynomials one knows these recurrence coefficients explicitly, but when one uses non-classical weights, then often one does not Copyright c 2003 by W Van Assche and M Foupouagnigni 232 W Van Assche and M Foupouagnigni know the recurrence coefficients explicitly.
    [Show full text]
  • Series Solutions of Ordinary Differential Equations
    Series Solutions of Homogeneous, Linear, 2nd Order ODE “Standard form” of a homogeneous, linear, 2nd order ODE: y′′ + p( z) y′ + q( z) y = 0 The first step is always to put the given equation into this “standard form.” Then the technique for obtaining two independent solutions depends on the existence and nature of any singularities of the ODE at the point z = z0 about which the series is to be expanded. By a change of variable, the ODE can always be written so that z0 = 0 and this is assumed below. Case I: z = 0 is an ordinary point: (1) Assume a power series solution about z = 0: ∞ n y() z= ∑ an z . Eq. (1) n=0 (2) Substitute Eq. (1) and its derivatives into the ODE and require that the coefficients of each power of z sum to zero to get a recurrence relation. The recurrence relation expresses a coefficient an in terms of the coefficients ar where r ≤ n − 1. (3) Sometimes the recurrence relation will have two solutions which can be used to construct series for two independent solutions to the ODE, y1(z) and y2(z). Other times, independent solutions can be obtained by choosing differing starting points for the series, e.g. a0 = 1, a1 =0 or a0 = 0, a1 = 1. A systematic approach is to assume Frobenius power series solutions ∞ σ n y() z= z∑ an z Eq. (2) n=0 with σ = 0 and σ = 1 instead of using only Eq. (1). (4) Try to relate the power series to the closed form of an elementary function (not always possible).
    [Show full text]
  • Arxiv:1410.2193V1 [Math.CO] 8 Oct 2014 There Are No Coincidences
    There are no Coincidences Tanya Khovanova October 21, 2018 Abstract This paper is inspired by a seqfan post by Jeremy Gardiner. The post listed nine sequences with similar parities. In this paper I prove that the similarities are not a coincidence but a mathematical fact. 1 Introduction Do you use your Inbox as your implicit to-do list? I do. I delete spam and cute cats. I reply, if I can. I deal with emails related to my job. But sometimes I get a message that requires some thought or some serious time to process. It sits in my Inbox. There are 200 messages there now. This method creates a lot of stress. But this paper is not about stress management. Let me get back on track. I was trying to shrink this list and discovered an email I had completely forgotten about. The email was sent in December 2008 to the seqfan list by Jeremy Gardiner [1]. The email starts: arXiv:1410.2193v1 [math.CO] 8 Oct 2014 It strikes me as an interesting coincidence that the following se- quences appear to have the same underlying parity. Then he lists six sequences with the same parity: • A128975 The number of unordered three-heap P-positions in Nim. • A102393, A wicked evil sequence. • A029886, Convolution of the Thue-Morse sequence with itself. 1 • A092524, Binary representation of n interpreted in base p, where p is the smallest prime factor of n. • A104258, Replace 2i with ni in the binary representation of n. n • A061297, a(n)= Pr=0 lcm(n, n−1, n−2,...,n−r+1)/ lcm(1, 2, 3,...,r).
    [Show full text]
  • The Fractional Derivative of the Dirac Delta Function and New Results on the Inverse Laplace Transform of Irrational Functions
    The fractional derivative of the Dirac delta function and new results on the inverse Laplace transform of irrational functions Nicos Makris1 Abstract Motivated from studies on anomalous diffusion, we show that the memory function M(t) of q + complex materials, that their creep compliance follows a power law, J(t) ∼ t with q 2 R , dqδ(t−0) + is the fractional derivative of the Dirac delta function, dtq with q 2 R . This leads q + to the finding that the inverse Laplace transform of s for any q 2 R is the fractional dqδ(t−0) derivative of the Dirac delta function, dtq . This result, in association with the con- sq volution theorem, makes possible the calculation of the inverse Laplace transform of sα∓λ + where α < q 2 R which is the fractional derivative of order q of the Rabotnov function α−1 α + "α−1(±λ, t) = t Eα, α(±λt ). The fractional derivative of order q 2 R of the Rabotnov function, "α−1(±λ, t) produces singularities which are extracted with a finite number of frac- tional derivatives of the Dirac delta function depending on the strength of q in association with the recurrence formula of the two-parameter Mittag–Leffler function. arXiv:2006.04966v1 [math-ph] 8 Jun 2020 Keywords: Generalized functions, Laplace transform, anomalous diffusion, fractional calculus, Mittag–Leffler function 1Department of Civil and Environmental Engineering, Southern Methodist University, Dallas, Texas, 75276 [email protected] Office of Theoretical and Applied Mechanics, Academy of Athens, 10679, Greece 1 1 Introduction 1 The classical result for the inverse Laplace transform of the function F(s) = sq is (Erdélyi 1954) 1 1 L−1 = tq−1 with q > 0 (1) sq Γ(q) 1 In Eq.
    [Show full text]
  • Math 280 Incompleteness 1. Definability, Representability and Recursion
    Math 280 Incompleteness 1. Definability, Representability and Recursion We will work with the language of arithmetic: 0_; S;_ +_ ; ·_; <_ . We will be sloppy and won't write dots. When we say \formula,"\satisfaction,"\proof,"everything will refer to this language. We will use the standard model of arithmetic N = (!; 0; S; +; ·; <). 1.1 Definition: (i) A bounded existential quantification is a quantification of the form (9z)(z < x ^ φ) which we will abbreviate by (9z < x)φ. (ii) A bounded universal quantification has the form (8z)(z < x ! φ) which we will abbreviate by (8z < x)φ. 1.2 Fact: The formulae (8z < x)φ $ :(9z < x):φ (9z < x)φ $ :(8z < x):φ are provable in predicate calculus. Proof: Exercise. 1.3 Definition: (i) A formula is bounded iff all definitions of this formula are bounded. We also say “Σ0"or “∆0"for bounded. (ii) A formula is Σn iff it has the form (9x1; :::; x1 )(8x2; :::; x2 )(9x3; :::; x3 ) ··· (Q(xn; :::; xn )) 1 l1 1 l2 1 l3 1 ln where is bounded. (iii) Πn formulae are defined dually. Here we start with a block of universal quantifiers. (iv) So Σn and Πn can be defined inductively: φ is Σn+1 iff φ has the form (9x1) ··· (9xl) where is Πn. Dually for Πn+1. 1.4 Definition: n A relation R(x1; :::; xn) ⊆ ( N) is Σl−definable iff R has a Σl−definition over N i.e. iff there is a Σl n formula φ(x1; :::; xl) such that for all a1; :::; an 2 ( N), R(a1; :::; an) iff N φ[a1; :::; an]: Similarly: R is Πl iff it has a Πl definition over N.
    [Show full text]