1 Section 3.4 Recursive Definitions. 2 Recursion Recursion is the process of defining an object in terms of itself Technique can be used to define sequences,

Slides:



Advertisements
Similar presentations
Fall 2002CMSC Discrete Structures1 If I told you once, it must be... Recursion.
Advertisements

Mathematical Induction
22C:19 Discrete Structures Induction and Recursion Fall 2014 Sukumar Ghosh.
Discrete Mathematics Math 6A Homework 9 Solution.
Recursive Definitions and Structural Induction
Induction and Recursion. Odd Powers Are Odd Fact: If m is odd and n is odd, then nm is odd. Proposition: for an odd number m, m k is odd for all non-negative.
10.1 CompSci 102© Michael Frank Today’s topics RecursionRecursion –Recursively defined functions –Recursively defined sets –Structural Induction Reading:
UCI ICS/Math 6A, Summer Recursion -1 after Strong Induction “Normal” Induction “Normal” Induction: If we prove.
Induction and recursion
CSE115/ENGR160 Discrete Mathematics 04/03/12 Ming-Hsuan Yang UC Merced 1.
Recursive Definitions Rosen, 3.4. Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.
CSE115/ENGR160 Discrete Mathematics 03/31/11
Recursive Definitions Rosen, 3.4 Recursive (or inductive) Definitions Sometimes easier to define an object in terms of itself. This process is called.
Discrete Structures Chapter 5: Sequences, Mathematical Induction, and Recursion 5.2 Mathematical Induction I [Mathematical induction is] the standard proof.
1 Section 3.3 Mathematical Induction. 2 Technique used extensively to prove results about large variety of discrete objects Can only be used to prove.
1 Strong Mathematical Induction. Principle of Strong Mathematical Induction Let P(n) be a predicate defined for integers n; a and b be fixed integers.
1 Mathematical Induction. 2 Mathematical Induction: Example  Show that any postage of ≥ 8¢ can be obtained using 3¢ and 5¢ stamps.  First check for.
Induction and Recursion by: Mohsin tahir (GL) Numan-ul-haq Waqas akram Rao arslan Ali asghar.
Induction and recursion
Induction and recursion
Discrete Mathematics Chapter 4 Induction and Recursion 大葉大學 資訊工程系 黃鈴玲 (Lingling Huang)
Recursive Definitions and Structural Induction
Discrete Mathematics CS 2610 March 26, 2009 Skip: structural induction generalized induction Skip section 4.5.
Lecture 9. Arithmetic and geometric series and mathematical induction
Induction and recursion
Chapter 6 Mathematical Induction
Mathematical Induction. F(1) = 1; F(n+1) = F(n) + (2n+1) for n≥ F(n) n F(n) =n 2 for all n ≥ 1 Prove it!
Chapter 4: Induction and Recursion
Section 5.3. Section Summary Recursively Defined Functions Recursively Defined Sets and Structures Structural Induction.
INDUCTION AND RECURSION. PRINCIPLE OF MATHEMATICAL INDUCTION To prove that P(n) is true for all positive integers n, where P(n) is a propositional function,
Two examples English-Words English-Sentences alphabet S ={a,b,c,d,…}
Induction and recursion
Sequences and Summations
Chapter 5 With Question/Answer Animations. Section 5.1.
4.3 Recursive Definitions and Structural Induction Sometimes it is difficult to define an object explicitly. However, it may be easy to define this object.
ICS 253: Discrete Structures I Induction and Recursion King Fahd University of Petroleum & Minerals Information & Computer Science Department.
CS 103 Discrete Structures Lecture 13 Induction and Recursion (1)
Foundations of Discrete Mathematics Chapters 5 By Dr. Dalia M. Gil, Ph.D.
1 Recursive Definitions and Structural Induction CS 202 Epp section ??? Aaron Bloomfield.
Inductive Proofs and Inductive Definitions Jim Skon.
Mathematical Induction Section 5.1. Climbing an Infinite Ladder Suppose we have an infinite ladder: 1.We can reach the first rung of the ladder. 2.If.
Mathematical Induction
CompSci 102 Discrete Math for Computer Science March 13, 2012 Prof. Rodger Slides modified from Rosen.
Chapter 5. Section 5.1 Climbing an Infinite Ladder Suppose we have an infinite ladder: 1.We can reach the first rung of the ladder. 2.If we can reach.
Chapter 5 Kenneth Rosen, Discrete Mathematics and its Applications, 7th edition, McGraw Hill Instructor: Longin Jan Latecki, Copyright.
1 Discrete Mathematical Mathematical Induction ( الاستقراء الرياضي )
6/12/2016 Prepared by Dr.Saad Alabbad1 CS100 : Discrete Structures Proof Techniques(2) Mathematical Induction & Recursion Dr.Saad Alabbad Department of.
Chapter 5 With Question/Answer Animations 1. Chapter Summary Mathematical Induction - Sec 5.1 Strong Induction and Well-Ordering - Sec 5.2 Lecture 18.
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
1 Recursive Definitions and Structural Induction CS/APMA 202 Rosen section 3.4 Aaron Bloomfield.
Section Recursion  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
CSE 311 Foundations of Computing I Lecture 15 Strong Induction and Recursive Definitions Spring
Mathematical Induction And Recursion Discrete Math Team KS MATEMATIKA DISKRIT (DISCRETE MATHEMATICS ) 1.
Fall 2002CMSC Discrete Structures1 Chapter 3 Sequences Mathematical Induction Recursion Recursion.
3.3 Mathematical Induction 1 Follow me for a walk through...
(Proof By) Induction Recursion
Chapter 4: Induction and Recursion
Induction and Recursion Chapter 5
CS2210:0001Discrete Structures Induction and Recursion
Induction and recursion
Induction and Recursion
Mathematical Induction Recursion
Discrete Structures for Computer Science
Chapter 5 Induction and Recursion
Induction and recursion
Applied Discrete Mathematics Week 9: Integer Properties
Mathematical Induction
Mathematical Induction
Induction and recursion
Recursion.
Presentation transcript:

1 Section 3.4 Recursive Definitions

2 Recursion Recursion is the process of defining an object in terms of itself Technique can be used to define sequences, functions and sets To recursively define a sequence: –give first term –give rule for defining subsequent terms from previous terms

3 Recursively Defined Functions Specify f(0) Give a rule for finding f from f’s value at smaller integers

4 Example 1 Define f recursively by: f(0) = 3 f(n+1) = 2(f(n)) + 3 Find f(1), f(2), f(3) and f(4) f(1) = 2(f(0)) + 3 = 9 f(2) = 2(f(1)) + 3 = 21 f(3) = 2(f(2)) + 3 = 45 f(4) = 2(f(3)) + 3 = 93

5 Example 2: give a recursive definition of the factorial function Define f(0): f(0) = 1 Define rule for f(n+1) from f(n): –Since (n+1)! = n!(n+1) –then f(n+1) = (n+1)(f(n)) For example, to find f(5) = 5! Do: f(5) = 5(f(4)) = 5(4(f(3))) = 5(4(3(f(2)))) = 5(4(3(2(f(1))))) = 5(4(3(2(1(f(0))))))) = 5*4*3*2*1*1 = 120

6 Example 3 Give recursive definition for the sum of the first n positive integers Define f(0) = 0 Then f(n+1) = n+1+f(n) Thus f(4), for example, is: 4+f(3) = 4+3+f(2) = f(1) = f(0) = = 10

7 Example 4 Give recursive definition of a n where a is a non-zero real number and n is a non- negative integer Define a 0 = 1 Then define a n+1 = a(a n ) So x 5 = x(x 4 ) = x(x(x 3 )) = x(x(x(x 2 ))) = x(x(x(x(x 1 )))) = x(x(x(x(x(x 0 ) = x*x*x*x*x*1

8 Example 5: summation Give a recursive definition of: n  ak ak k=0 Basis: n  a k = a 0 k=0 Inductive: n+1 n  a k = a n+1 +  a k k=0

9 Example 6 Give recursive definition of P m (n), product of integer m and non-negative integer n Basis: P m (0) = 0 Inductive: P m (n+1) = P m (n) + m So, for example, 4*3 = P 4 (3) = P 4 (2)+4 = P 4 (1)+4+4 = P 4 (0) = = 12

10 Fibonacci numbers Fibonacci numbers are defined by: f 0 = 0, f 1 = 1, f n = f n-1 + f n-2 where n=2,3,4 … Sof 2 = f 1 + f 0 = 1 f 3 = f 2 + f 1 = 2 f 4 = f 3 + f 2 = 3 f 5 = f 4 + f 3 = 5 f 6 = f 5 + f 4 = 8etc.

11 Example 7: Fibonacci numbers The recursive definition of Fibonacci numbers can be used to prove many properties of these numbers. For example: f n >  n-2 where  = (1 +  5) / 2 whenever n  3 Let P(n) = f n >  n-2 ; we wish to show that P(n) is true for n  3

12 Example 7 Note that:   3-2 )  2 = ((1+  5)/2)((1+  5)/2) = (1+2  5+5)/4 = (2(  5+3))/(2*2) = (3 +  5) / 2 (3 +  5) / 2  4-2 ) So P(n) is true for n=3 and n=4

13 Example 7 Assume P(k) is true, so f k >  k-2 for all integers k with 3 <= k <= n, with n  4 Show P(n+1) is true: f n+1 >  n-1 By the quadratic formula: x=(-b  b 2 -4ac)/2a  is a solution for x 2 -x-1=0 so  2 =  + 1

14 Example 7 Thus,  n-1 =  2 (  n-3 ) = (  +1)  n-3 =  (  n-3 ) +1(  n-3 ) = (  n-2 +  n-3 ) By the inductive hypothesis, if n  5, it follows that f n-1 >  n-3, f n >  n-2 So we have: f n+1 = (f n + f n-1 ) > (  n-2 +  n-3 ) =  n-1, completing the proof

15 Example 8 Prove that f 1 +f 3 + … +f 2n-1 = f 2n whenever n is a positive integer Basis: f 1 = f 2*1 true, since f 1 = f 2 = 1 We want to prove: f 1 +f 3 + … f 2n-1 +f 2n+1 =f 2(n+1)

16 Example 8 Assume P(n) is true; then: f 1 +f 3 + … f 2n-1 +f 2n+1 = f 2n + f 2(n+1) f 2n + f 2(n+1) = f 2n+2 Recall the definition of Fibonacci numbers: f n = f n-1 + f n-2 So the theorem is true

17 Recursively defined sets Sets may be recursively defined as follows: –an initial collection of elements is given –rules used to construct elements of the set from other elements are given Such sets are well-defined, and theorems about them can be proved using their recursive definitions

18 Example 9 S is recursively defined by: 3  S (x+y)  S if x  S and y  S Show that S is the set of all positive integers divisible by 3

19 Example 9: Proof Let A = {x | x is divisible by 3} (or, x=3n) To prove A=S, show that A  S and S  A Proving A  S by mathematical induction: –P(n): 3n belongs to S –Basis: 3*1  S - true by definition of S –Inductive: Since we already know 3  S (by definition), and (3n+3)  S (also by definition) and 3n+3 = 3(n+1), A  S is proven

20 Example 9: Proof To prove S  A, use recursive definition of S: –Basis: 3  S (by definition) –Since 3 = 3*1, all elements specified by the definition’s basis step are divisible by 3 To complete proof, must show all integers generated by using second part of definition of S are in A

21 Example 9: Proof To do this, show that x+y is in A when x  S and y  S and x  A and y  A If x  A and y  A, 3|x and 3|y - so 3|(x+y) This completes the proof

22 Well-formed Formulae Common application of the recursive definition of sets Example: well-formed formulae of variables, numerals and operators from {+,-,*,/,  } are defined by: –x is a well-formed formula is x is a numeral or variable; –(f+g), (f-g), (f*g), (f/g) and (f  g) are well-formed formulae if f and g are well-formed formulae

23 Application of well-formed formulae Using this definition, we can define any infix expression For example, x and 5 are well-formed formulae So (x+5), (x*5), etc. are well-formed formulae And (x+5) / (x*5) is a well-formed formula

24 Example 10 Well-formed formulae for compound propositions involving T, F, variables and operators { , , , ,  } are defined by: –T, F and p (where p is a propositional variable) are well-formed formulae; –(  p), (p  q), (p  q), (p  q), (p  q) are well- formed formulae is p and q are well-formed –Thus, we could build any compound propositional expression in the same way as with infix arithmetic expressions

25 Recursive definition of strings The set  * of strings over the alphabet  can be recursively defined by: –   * where is the empty string and –wx   * whenever w   * and x   Translation: –empty strings belong to the set of strings –can produce new strings by concatenating strings from the set of strings with symbols from the alphabet

26 Recursive definition of strings Can also recursively define the length of strings; if l(w) is the length of string w, then: –l( ) = 0 –l(wx) = l(w)+1 if w   * and x   Can use these definitions in proofs

27 Example 11 Prove that l(xy) = l(x) + l(y) where x   * and y   * Basis: P( ) –show l(x ) = l(x)+l( ) for x  * –since l( ) = 0, l(x)+l( ) = l(x), so l(x ) is true

28 Example 11 Inductive step: –Assume P(y) is true; show that this implies P(ya) is true where a   –Need to show l(xya) = l(x) + l(ya) –By recursive definition of l(w), we have l(xya)=l(xy+1) and l(ya) = l(y)+1 –By inductive hypothesis, l(xy)=l(x)+l(y) –So we conclude l(xya)=l(x)+l(y)+1 = l(x)+l(ya)

29 Section 3.3 Recursive Definitions - ends -