Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c)2001-2004, Michael P. Frank. Modified By Mingwu Chen Induction.

Slides:



Advertisements
Similar presentations
Copyright © Cengage Learning. All rights reserved. CHAPTER 5 SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION SEQUENCES, MATHEMATICAL INDUCTION, AND RECURSION.
Advertisements

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:
Based on Rosen, Discrete Mathematics & Its Applications, 5e Prepared by (c) Michael P. Frank Modified by (c) Haluk Bingöl 1/18 Module.
Induction and recursion
Recursion Rosen 5 th ed., § Recursion Sometimes, defining an object explicitly might be difficult.Sometimes, defining an object explicitly might.
1 Inductive Proofs Rosen 6 th ed., § Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every.
CSE115/ENGR160 Discrete Mathematics 03/22/12 Ming-Hsuan Yang UC Merced 1.
Recursion. Recursive Definitions In recursive definitions, we define a function, a predicate, a set, or a more complex structure over an infinite domain.
CSE115/ENGR160 Discrete Mathematics 03/31/11
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.
Mathematical Induction
Induction and recursion
Induction and recursion
Discrete Mathematics Chapter 4 Induction and Recursion 大葉大學 資訊工程系 黃鈴玲 (Lingling Huang)
Mathematical Maxims and Minims, 1988
Induction and recursion
Chapter 6 Mathematical Induction
Discrete Mathematics and Its Applications Sixth Edition By Kenneth Rosen Chapter 4 Induction and Recursion 歐亞書局.
1 Introduction to Abstract Mathematics Chapter 4: Sequences and Mathematical Induction Instructor: Hayk Melikya 4.1- Sequences. 4.2,
Induction and Recursion §4.1 Mathematical Induction §4.2 Strong Induction and Well-Ordering §4.3 Recursive Definitions and Structural Inductions §4.4 Recursive.
강원대학교 컴퓨터과학전공 문양세 이산수학 (Discrete Mathematics) 재귀 호출 (Recursion)
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,
Module #14: Recursion Rosen 5 th ed., §§ In this class, we will study recursion, one of the most important topics in computer science. In the last.
Induction and recursion
이산수학 (Discrete Mathematics) 3.5 재귀 알고리즘 (Recursive Algorithms) 2006 년 봄학기 문양세 강원대학교 컴퓨터과학과.
Module #13: Inductive Proofs Rosen 5 th ed., § inference of a generalized conclusion from particular instances 2. mathematical demonstration of the.
Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.
Chapter 5 With Question/Answer Animations. Section 5.1.
Chap 3 –A theorem is a statement that can be shown to be true –A proof is a sequence of statements to show that a theorem is true –Axioms: statements which.
Section 3.3: Mathematical Induction Mathematical induction is a proof technique that can be used to prove theorems of the form:  n  Z +,P(n) We have.
1 Inductive Proofs Rosen 6 th ed., § Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every.
ICS 253: Discrete Structures I Induction and Recursion King Fahd University of Petroleum & Minerals Information & Computer Science Department.
Module #15 – Inductive Proofs 12/6/2015(c) , Michael P. Frank1 Inductive Proofs: a brief introduction Rosen 5 th ed., §3.3 ~35 slides, ~1.5 lecture.
Based on Rosen, Discrete Mathematics & Its Applications, 5e Prepared by (c) Michael P. Frank Modified by (c) Haluk Bingöl 1/18 Module.
CompSci 102 Discrete Math for Computer Science March 1, 2012 Prof. Rodger Slides modified from Rosen.
CS 103 Discrete Structures Lecture 13 Induction and Recursion (1)
Foundations of Discrete Mathematics Chapters 5 By Dr. Dalia M. Gil, Ph.D.
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.
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.
2012 년 봄학기 강원대학교 컴퓨터과학전공 문양세 이산수학 (Discrete Mathematics) 수학적 귀납법 (Mathematical Induction)
Chapter 5 Kenneth Rosen, Discrete Mathematics and its Applications, 7th edition, McGraw Hill Instructor: Longin Jan Latecki, Copyright.
Mathematical Induction
Induction and Recursion CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Section Recursion  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
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...
Chapter 5 1. Chapter Summary  Mathematical Induction  Strong Induction  Recursive Definitions  Structural Induction  Recursive Algorithms.
Induction and recursion
CS2210:0001Discrete Structures Induction and Recursion
Induction and recursion
Mathematical Induction Recursion
Chapter 5 Induction and Recursion
Discrete Mathematics and its Applications
Induction and recursion
Rosen 5th ed., §§ ~18 slides, ~1 lecture
Applied Discrete Mathematics Week 9: Integer Properties
Module #13: Inductive Proofs
Rosen 5th ed., §§ ~18 slides, ~1 lecture
Induction Chapter
Advanced Analysis of Algorithms
Discrete Mathematics and its Applications
Discrete Mathematics and its Applications
Induction and recursion
Discrete Mathematics and its Applications
Recursion.
Presentation transcript:

Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen Induction and Recursion

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 2 Topics Mathematical induction Well ordered property Second principle of induction Recursive definition Recursive algorithms

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 3 Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter how large. Essentially a “domino effect” principle. Based on a predicate-logic inference rule: P(0)  n  0 (P(n)  P(n+1))  n  0 P(n)

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 4 Validity of Induction Proof that  k  0 P(k) is a valid consequent: Given any k  0,  n  0 (P(n)  P(n+1)) (antecedent 2) trivially implies  n  0 (n<k)  (P(n)  P(n+1)), or (P(0)  P(1))  (P(1)  P(2))  …  (P(k  1)  P(k)). Repeatedly applying the hypothetical syllogism rule to adjacent implications k-1 times then gives P(0)  P(k); which with P(0) (antecedent #1) and modus ponens gives P(k). Thus  k  0 P(k).

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 5 The Well-Ordering Property The validity of the inductive inference rule can also be proved using the well-ordering property, which says: Every non-empty set of non-negative integers has a minimum (smallest) element.   S  N :  m  S :  n  S : m  n Assume that there exists at least one positive integer n: {n|  P(n)}. This non-empty set has a minimum element m. So m-1 is not in this set and thus P(m-1) is true, but then P(m-1)  P((m-1)+1) contradicted with  P(m).

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 6 Outline of an Inductive Proof Want to prove  n P(n)… Base case (or basis step): Prove P(0). Inductive step: Prove  n P(n)  P(n+1). E.g. use a direct proof: Let n  N, assume P(n). (inductive hypothesis) Under this assumption, prove P(n+1). Inductive inference rule then gives  n P(n).

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 7 Generalizing Induction Can also be used to prove  n  c P(n) for a given constant c  Z, where maybe c  0. In this circumstance, the base case is to prove P(c) rather than P(0), and the inductive step is to prove  n  c (P(n)  P(n+1)).

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 8 Second Principle of Induction Characterized by another inference rule: P(0)  n  0: (  0  k  n P(k))  P(n+1)  n  0: P(n) Difference with 1st principle is that the inductive step uses the fact that P(k) is true for all smaller k<n+1, not just for k=n.

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 9 Induction Example (1st princ.) Prove that the sum of the first n odd positive integers is n 2. That is, prove: Proof by induction. Base case: Let n=1. The sum of the first 1 odd positive integer is 1 which equals 1 2. Inductive step: Prove  n  1: P(n)  P(n+1). Let n  1, assume P(n), and prove P(n+1).

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 10 Another Induction Example Prove that  n>0, n<2 n. Let P(n)=(n<2 n ) Base case: P(1)=(1<2 1 )=(1<2)=T. Inductive step: For n>0, prove P(n)  P(n+1). Assuming n<2 n, prove n+1 < 2 n+1. Note n + 1 < 2 n + 1 (by inductive hypothesis) < 2 n + 2 n = 2 n+1 So n + 1 < 2 n+1, and we’re done.

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 11 Example of Second Principle Show that every n>1 can be written as a product p 1 p 2 …p s of some series of s prime numbers. Let P(n)=“n has that property” Base case: n=2, let s=1, p 1 =2. Inductive step: Let n  2. Assume  2  k  n: P(k). Consider n+1. If prime, let s=1, p 1 =n+1. Else n+1=ab, where 2  a  n and 2  b  n. Since a=p 1 p 2 …p t and b=q 1 q 2 …q u, then n+1= p 1 p 2 …p t q 1 q 2 …q u, a product of s=t+u primes.

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 12 Another 2nd Principle Example Prove that every amount of postage of 12 cents or more can be formed using just 4- cent and 5-cent stamps. Base case: 12=3  4), 13=2  4)+1(5), 14=1(4)+2(5), 15=3(5), so  12  n  15, P(n). Inductive step: Let n  15, assume  12  k  n P(k). Note 12  n  3  n, so P(n  3), so add a 4-cent stamp to get postage for n+1.

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 13 Recursive Definitions In induction, we prove all members of an infinite set have some property P by proving the truth for larger members in terms of that of smaller members. In recursive definitions, we similarly define a function, a predicate or a set over an infinite number of elements by defining the function or predicate value or set-membership of larger elements in terms of that of smaller ones.

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 14 Recursion Recursion is a general term for the practice of defining an object in terms of itself (or of part of itself). An inductive proof establishes the truth of P(n+1) recursively in terms of P(n). There are also recursive algorithms, definitions, functions, sequences, and sets.

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 15 Recursively Defined Functions Simplest case: One way to define a function f:N  S (for any set S) or series a n =f(n) is to: Define f(0). For n>0, define f(n) in terms of f(0),…,f(n−1). E.g.: Define the series a n :  2 n recursively: Let a 0 :  1. For n>0, let a n :  2a n-1.

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 16 Another Example Suppose we define f(n) for all n  N recursively by: Let f(0)=3 For all n  N, let f(n+1)=2f(n)+3 What are the values of the following? f(1)= f(2)= f(3)= f(4)=

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 17 Recursive definition of Factorial Give a recursive definition of the factorial function F(n) :  n! :  2  3  …  n. Base case: F(0) :  1 Recursive part: F(n) :  n  F(n-1). F(1)=1 F(2)=2 F(3)=6

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 18 The Fibonacci Series The Fibonacci series f n  0 is a famous series defined by: f 0 :  0, f 1 :  1, f n  2 :  f n−1 + f n−

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 19 Inductive Proof about Fib. series Theorem: f n < 2 n. Proof: By induction. Base cases:f 0 = 0 < 2 0 = 1 f 1 = 1 < 2 1 = 2 Inductive step: Use 2 nd principle of induction (strong induction). Assume  k<n, f k < 2 k. Then f n = f n−1 + f n−2 is < 2 n−1 + 2 n−2 < 2 n−1 + 2 n−1 = 2 n.

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 20 Recursively Defined Sets An infinite set S may be defined recursively, by giving: A small finite set of base elements of S. A rule for constructing new elements of S from previously-established elements. Implicitly, S has no other elements but these. Example: Let 3  S, and let x+y  S if x,y  S. What is S?

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 21 The Set of All Strings Given an alphabet , the set  * of all strings over  can be recursively defined as:   * ( :  “”, the empty string) w   *  x    wx   *

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 22 Recursive Algorithms Recursive definitions can be used to describe algorithms as well as functions and sets. Example: A procedure to compute a n. procedure power(a  0: real, n  N) if n = 0 then return 1 else return a · power(a, n−1)

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 23 Efficiency of Recursive Algorithms The time complexity of a recursive algorithm may depend critically on the number of recursive calls it makes. Example: Modular exponentiation to a power n can take log(n) time if done right, but linear time if done differently. Task: Compute b n mod m, where m  2, n  0, and 1  b<m.

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 24 Modular Exponentiation Alg. #1 Uses the fact that b n = b·b n−1 and that x·y mod m = x·(y mod m) mod m. procedure mpower(b  1,n  0,m>b  N) {Returns b n mod m.} if n=0 then return 1 else return (b·mpower(b,n−1,m)) mod m Note this algorithm takes  (n) steps!

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 25 Modular Exponentiation Alg. #2 Uses the fact that b 2k = b k·2 = (b k ) 2. procedure mpower(b,n,m) {same signature} if n=0 then return 1 else if 2|n then return mpower(b,n/2,m) 2 mod m else return (mpower(b,n−1,m)·b) mod m What is its time complexity?

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 26 Recursive Euclid’s Algorithm procedure gcd(a,b  N) if a = 0 then return b else return gcd(b mod a, a) Note recursive algorithms are often simpler to code than iterative ones… However, they can consume more stack space, if your compiler is not smart enough.

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 27 Merge Sort procedure sort(L = 1,…, n ) if n>1 then m :=  n/2  {this is rough ½-way point} L := merge(sort( 1,…, m ), sort( m+1,…, n )) return L The merge takes  (n) steps, and merge- sort takes  (n log n).

Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank. Modified By Mingwu Chen 28 Merge Routine procedure merge(A, B: sorted lists) L = empty list i:=0, j:=0, k:=0 while i<|A|  j<|B| {|A| is length of A} if i=|A| then L k := B j ; j := j + 1 else if j=|B| then L k := A i ; i := i + 1 else if A i < B j then L k := A i ; i := i + 1 else L k := B j ; j := j + 1 k := k+1 return L Takes  (|A|+|B|) time