per4 induction

30
March 3, 2003 Applied Discrete Mathematics Week 6: Counting 1 Induction Induction The The principle of mathematical principle of mathematical induction induction is a useful tool for is a useful tool for proving that a certain predicate is proving that a certain predicate is true for true for all natural numbers all natural numbers . . It cannot be used to discover It cannot be used to discover theorems, but only to prove them. theorems, but only to prove them.

Upload: evert-sandye-taasiringan

Post on 16-Apr-2017

79 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

1

InductionInduction

The The principle of mathematical inductionprinciple of mathematical induction is a is a useful tool for proving that a certain predicate is useful tool for proving that a certain predicate is true for true for all natural numbersall natural numbers..

It cannot be used to discover theorems, but only to It cannot be used to discover theorems, but only to prove them.prove them.

Page 2: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

2

InductionInductionIf we have a propositional function P(n), and we If we have a propositional function P(n), and we want to prove that P(n) is true for any natural want to prove that P(n) is true for any natural number n, we do the following:number n, we do the following:

• Show that P(0) is true.Show that P(0) is true. (basis step)(basis step)• Show that if P(n) then P(n + 1) for any nShow that if P(n) then P(n + 1) for any nN.N. (inductive step)(inductive step)• Then P(n) must be true for any nThen P(n) must be true for any nN. N. (conclusion)(conclusion)

Page 3: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

3

InductionInduction

Example:Example:

Show that n < 2Show that n < 2nn for all positive integers n. for all positive integers n.

Let P(n) be the proposition “n < 2Let P(n) be the proposition “n < 2nn.”.”

1. Show that P(1) is true.1. Show that P(1) is true.(basis step)(basis step)

P(1) is true, because 1 < 2P(1) is true, because 1 < 211 = 2. = 2.

Page 4: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

4

InductionInduction

2. Show that if P(n) is true, then P(n + 1) is true.2. Show that if P(n) is true, then P(n + 1) is true.(inductive step)(inductive step)

Assume that n < 2Assume that n < 2nn is true. is true.We need to show that P(n + 1) is true, i.e.We need to show that P(n + 1) is true, i.e.n + 1 < 2n + 1 < 2n+1n+1

We start from n < 2We start from n < 2nn::n + 1 < 2n + 1 < 2nn + 1 + 1 2 2nn + 2 + 2nn = 2 = 2n+1n+1

Therefore, if n < 2Therefore, if n < 2nn then n + 1 < 2 then n + 1 < 2n+1n+1

Page 5: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

5

InductionInduction

3.3. Then P(n) must be true for any positive Then P(n) must be true for any positive integer.integer.(conclusion)(conclusion)

n < 2n < 2nn is true for any positive integer. is true for any positive integer.

End of proof.End of proof.

Page 6: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

6

InductionInduction

Another Example (“Gauss”):Another Example (“Gauss”):

1 + 2 + … + n = n (n + 1)/21 + 2 + … + n = n (n + 1)/2

1.1. Show that P(0) is true.Show that P(0) is true.(basis step)(basis step)

For n = 0 we get 0 = 0. For n = 0 we get 0 = 0. True.True.

Page 7: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

7

InductionInduction

2.2. Show that if P(n) then P(n + 1) for any nShow that if P(n) then P(n + 1) for any nNN. . (inductive step)(inductive step)

1 + 2 + … + n = n (n + 1)/21 + 2 + … + n = n (n + 1)/21 + 2 + … + n 1 + 2 + … + n + (n + 1)+ (n + 1) = n (n + 1)/2 = n (n + 1)/2 + (n + 1)+ (n + 1)

= (2n + 2 + n (n + 1))/2= (2n + 2 + n (n + 1))/2= (2n + 2 + n= (2n + 2 + n22 + n)/2 + n)/2= (2 + 3n + n= (2 + 3n + n2 2 )/2)/2= (n + 1) (n + 2)/2= (n + 1) (n + 2)/2= = (n + 1)(n + 1) ( ((n + 1)(n + 1) + 1)/2 + 1)/2

Page 8: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

8

InductionInduction

3.3. Then P(n) must be true for any nThen P(n) must be true for any nN. N. (conclusion)(conclusion)

1 + 2 + … + n = n (n + 1)/2 is true for all n1 + 2 + … + n = n (n + 1)/2 is true for all nN.N.

End of proof.End of proof.

Page 9: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

9

InductionInduction

There is another proof technique that is very similar There is another proof technique that is very similar to the principle of mathematical induction.to the principle of mathematical induction.

It is called It is called the second principle of mathematical the second principle of mathematical inductioninduction..

It can be used to prove that a propositional function It can be used to prove that a propositional function P(n) is true for any natural number n.P(n) is true for any natural number n.

Page 10: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

10

InductionInduction

The second principle of mathematical induction:The second principle of mathematical induction:

• Show that P(0) is true.Show that P(0) is true.(basis step)(basis step)

• Show that if P(0) and P(1) and … and P(n),Show that if P(0) and P(1) and … and P(n),then P(n + 1) for any nthen P(n + 1) for any nN.N.(inductive step)(inductive step)

• Then P(n) must be true for any nThen P(n) must be true for any nN. N. (conclusion)(conclusion)

Page 11: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

11

InductionInduction

Example:Example: Show that every integer greater than 1 can be Show that every integer greater than 1 can be written as the product of primes.written as the product of primes.

• Show that P(2) is true.Show that P(2) is true. (basis step)(basis step)

2 is the product of one prime: itself.2 is the product of one prime: itself.

Page 12: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

12

InductionInduction• Show that if P(2) and P(3) and … and P(n),Show that if P(2) and P(3) and … and P(n),

then P(n + 1) for any nthen P(n + 1) for any nN. N. (inductive step)(inductive step)

Two possible cases:Two possible cases:• If (n + 1) is If (n + 1) is primeprime, then obviously P(n + 1) is true., then obviously P(n + 1) is true.• If (n + 1) is If (n + 1) is compositecomposite, it can be written as the , it can be written as the

product of two integers a and b such thatproduct of two integers a and b such that2 2 a a b < n + 1. b < n + 1.

By the By the induction hypothesisinduction hypothesis, both a and b can be , both a and b can be written as the product of primes.written as the product of primes.

Therefore, n + 1 = aTherefore, n + 1 = ab can be written as the b can be written as the product of primes.product of primes.

Page 13: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

13

InductionInduction

• Then P(n) must be true for any nThen P(n) must be true for any nN. N. (conclusion)(conclusion)

End of proof.End of proof.

We have shown that We have shown that every integer greater than 1every integer greater than 1 can be written as the product of primes.can be written as the product of primes.

Page 14: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

14

Recursive DefinitionsRecursive Definitions

RecursionRecursion is a principle closely related to is a principle closely related to mathematical induction.mathematical induction.

In a In a recursive definitionrecursive definition, an object is defined in , an object is defined in terms of itself.terms of itself.

We can recursively define We can recursively define sequencessequences, , functionsfunctions and and setssets..

Page 15: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

15

Recursively Defined SequencesRecursively Defined SequencesExample:Example:

The sequence {aThe sequence {ann} of powers of 2 is given by} of powers of 2 is given byaann = 2 = 2nn for n = 0, 1, 2, … . for n = 0, 1, 2, … .

The same sequence can also be defined The same sequence can also be defined recursivelyrecursively::

aa00 = 1 = 1aan+1n+1 = 2a = 2an n for n = 0, 1, 2, …for n = 0, 1, 2, …

Obviously, induction and recursion are similar Obviously, induction and recursion are similar principles.principles.

Page 16: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

16

Recursively Defined FunctionsRecursively Defined Functions

We can use the following method to define a We can use the following method to define a function with the function with the natural numbersnatural numbers as its domain: as its domain:

1.1. Specify the value of the function at zero.Specify the value of the function at zero.2.2. Give a rule for finding its value at any integer Give a rule for finding its value at any integer from its values at smaller integers. from its values at smaller integers.

Such a definition is called Such a definition is called recursiverecursive or or inductive inductive definitiondefinition. .

Page 17: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

17

Recursively Defined FunctionsRecursively Defined Functions

Example:Example:

f(0) = 3f(0) = 3f(n + 1) = 2f(n) + 3f(n + 1) = 2f(n) + 3

f(0) = 3f(0) = 3f(1) = 2f(0) + 3 = 2f(1) = 2f(0) + 3 = 23 + 3 = 93 + 3 = 9f(2) = 2f(1) + 3 = 2f(2) = 2f(1) + 3 = 29 + 3 = 219 + 3 = 21f(3) = 2f(2) + 3 = 2f(3) = 2f(2) + 3 = 221 + 3 = 4521 + 3 = 45f(4) = 2f(3) + 3 = 2f(4) = 2f(3) + 3 = 245 + 3 = 9345 + 3 = 93

Page 18: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

18

Recursively Defined FunctionsRecursively Defined Functions

How can we recursively define the factorial How can we recursively define the factorial function f(n) = n! ? function f(n) = n! ?

f(0) = 1f(0) = 1f(n + 1) = (n + 1)f(n) f(n + 1) = (n + 1)f(n)

f(0) = 1f(0) = 1f(1) = 1f(0) = 1f(1) = 1f(0) = 11 = 11 = 1f(2) = 2f(1) = 2f(2) = 2f(1) = 21 = 21 = 2f(3) = 3f(2) = 3f(3) = 3f(2) = 32 = 62 = 6f(4) = 4f(3) = 4f(4) = 4f(3) = 46 = 246 = 24

Page 19: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

19

Recursively Defined FunctionsRecursively Defined Functions

A famous example: The Fibonacci numbers A famous example: The Fibonacci numbers f(0) = 0, f(1) = 1f(0) = 0, f(1) = 1f(n) = f(n – 1) + f(n - 2) f(n) = f(n – 1) + f(n - 2)

f(0) = 0f(0) = 0f(1) = 1f(1) = 1f(2) = f(1) + f(0) = 1 + 0 = 1f(2) = f(1) + f(0) = 1 + 0 = 1f(3) = f(2) + f(1) = 1 + 1 = 2f(3) = f(2) + f(1) = 1 + 1 = 2f(4) = f(3) + f(2) = 2 + 1 = 3f(4) = f(3) + f(2) = 2 + 1 = 3f(5) = f(4) + f(3) = 3 + 2 = 5f(5) = f(4) + f(3) = 3 + 2 = 5f(6) = f(5) + f(4) = 5 + 3 = 8f(6) = f(5) + f(4) = 5 + 3 = 8

Page 20: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

20

Recursively Defined SetsRecursively Defined Sets

If we want to recursively define a set, we need to If we want to recursively define a set, we need to provide two things:provide two things:

• an an initial setinitial set of elements, of elements,• rulesrules for the construction of for the construction of additionaladditional elements from elements in the set. elements from elements in the set.

Example:Example: Let S be recursively defined by: Let S be recursively defined by:3 3 S S(x + y) (x + y) S if (x S if (x S) and (y S) and (y S) S)

S is the set of positive integers divisible by 3.S is the set of positive integers divisible by 3.

Page 21: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

21

Recursively Defined SetsRecursively Defined Sets

Proof:Proof:

Let A be the set of all positive integers divisible by 3.Let A be the set of all positive integers divisible by 3.

To show that A = S, we must show that To show that A = S, we must show that A A S and S S and S A. A.

Part I:Part I: To prove that A To prove that A S, we must show that S, we must show that every positive integer divisible by 3 is in S.every positive integer divisible by 3 is in S.

We will use mathematical induction to show this. We will use mathematical induction to show this.

Page 22: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

22

Recursively Defined SetsRecursively Defined Sets

Let P(n) be the statement “3n belongs to S”.Let P(n) be the statement “3n belongs to S”.

Basis step:Basis step: P(1) is true, because 3 is in S. P(1) is true, because 3 is in S.

Inductive step:Inductive step: To show: To show:If P(n) is true, then P(n + 1) is true.If P(n) is true, then P(n + 1) is true.

Assume 3n is in S. Since 3n is in S and 3 is in S, it Assume 3n is in S. Since 3n is in S and 3 is in S, it follows from the recursive definition of S thatfollows from the recursive definition of S that3n + 3 = 3(n + 1) is also in S.3n + 3 = 3(n + 1) is also in S.

Conclusion of Part I:Conclusion of Part I: A A S. S.

Page 23: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

23

Recursively Defined SetsRecursively Defined SetsPart II:Part II: To show: S To show: S A. A.

Basis step:Basis step: To show: To show: All initial elements of S are in A. 3 is in A. True.All initial elements of S are in A. 3 is in A. True.

Inductive step:Inductive step: To show: To show:(x + y) is in A whenever x and y are in S.(x + y) is in A whenever x and y are in S.

If x and y are both in A, it follows that 3 | x and 3 | y. If x and y are both in A, it follows that 3 | x and 3 | y. As we already know, it follows that 3 | (x + y).As we already know, it follows that 3 | (x + y).

Conclusion of Part II:Conclusion of Part II: S S A. A.Overall conclusion:Overall conclusion: A = S. A = S.

Page 24: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

24

Recursively Defined SetsRecursively Defined Sets

Another example:Another example:

The well-formed formulas of variables, numerals The well-formed formulas of variables, numerals and operators from {+, -, *, /, ^} are defined by:and operators from {+, -, *, /, ^} are defined by:

x is a well-formed formula if x is a numeral or x is a well-formed formula if x is a numeral or variable.variable.

(f + g), (f – g), (f * g), (f / g), (f ^ g) are well-formed (f + g), (f – g), (f * g), (f / g), (f ^ g) are well-formed formulas if f and g are.formulas if f and g are.

Page 25: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

25

Recursively Defined SetsRecursively Defined Sets

With this definition, we can construct formulas such With this definition, we can construct formulas such as:as:

(x – y)(x – y)((z / 3) – y)((z / 3) – y)((z / 3) – (6 + 5))((z / 3) – (6 + 5))((z / (2 * 4)) – (6 + 5))((z / (2 * 4)) – (6 + 5))

Page 26: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

26

Recursive AlgorithmsRecursive Algorithms

An algorithm is called An algorithm is called recursiverecursive if it solves a problem if it solves a problem by reducing it to an instance of the same problem with by reducing it to an instance of the same problem with smaller input.smaller input.

Example I:Example I: Recursive Euclidean Algorithm Recursive Euclidean Algorithm

procedureprocedure gcd(a, b: nonnegative integers with a < b) gcd(a, b: nonnegative integers with a < b)ifif a = 0 a = 0 then then gcd(a, b) := bgcd(a, b) := belseelse gcd(a, b) := gcd(b gcd(a, b) := gcd(b modmod a, a) a, a)

Page 27: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

27

Recursive AlgorithmsRecursive Algorithms

Example II:Example II: Recursive Fibonacci Algorithm Recursive Fibonacci Algorithm

procedureprocedure fibo(n: nonnegative integer) fibo(n: nonnegative integer)ifif n = 0 n = 0 then then fibo(0) := 0fibo(0) := 0else ifelse if n = 1 n = 1 then then fibo(1) := 1fibo(1) := 1elseelse fibo(n) := fibo(n – 1) + fibo(n – 2) fibo(n) := fibo(n – 1) + fibo(n – 2)

Page 28: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

28

Recursive AlgorithmsRecursive Algorithms

Recursive Fibonacci Evaluation:Recursive Fibonacci Evaluation:

f(4)f(4)

f(3)f(3)

f(2)f(2)

f(1)f(1) f(0)f(0)

f(1)f(1)

f(2)f(2)

f(1)f(1) f(0)f(0)

Page 29: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

29

Recursive AlgorithmsRecursive Algorithms

procedureprocedure iterative_fibo(n: nonnegative integer) iterative_fibo(n: nonnegative integer)ifif n = 0 n = 0 then then y := 0y := 0elseelsebeginbegin

x := 0x := 0y := 1y := 1for for i := 1 i := 1 toto n-1 n-1beginbegin

z := x + yz := x + yx : = yx : = yy := zy := z

endendendend {y is the n-th Fibonacci number}{y is the n-th Fibonacci number}

Page 30: Per4 induction

March 3, 2003 Applied Discrete MathematicsWeek 6: Counting

30

Recursive AlgorithmsRecursive Algorithms

For every recursive algorithm, there is an For every recursive algorithm, there is an equivalentequivalent iterative algorithm.iterative algorithm.

Recursive algorithms are often Recursive algorithms are often shortershorter, , more more elegantelegant, and , and easier to understandeasier to understand than their than their iterative counterparts.iterative counterparts.

However, iterative algorithms are usually However, iterative algorithms are usually more more efficientefficient in their use of space and time. in their use of space and time.