Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate...

26
Inductive Proofs Inductive Proofs

Transcript of Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate...

Page 1: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

Inductive ProofsInductive Proofs

Page 2: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

Mathematical InductionMathematical 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)n0 (P(n)P(n+1))n0 P(n)

“The First Principleof Mathematical

Induction”

Page 3: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

Outline of an Inductive ProofOutline 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 nN, assume P(n). (inductive hypothesis)– Under this assumption, prove P(n+1).

• Inductive inference rule then gives n P(n).

Page 4: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

Generalizing InductionGeneralizing Induction• Can also be used to prove nc P(n) for a

given constant cZ, where maybe c0.– In this circumstance, the base case is to prove

P(c) rather than P(0), and the inductive step is to prove nc (P(n)P(n+1)).

Page 5: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

Second Principle of InductionSecond Principle of Induction

• Characterized by another inference rule:P(0)n0: (0kn P(k)) P(n+1)n0: 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.

P is true in all previous cases

Page 6: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

Induction Example (1st princ.)Induction Example (1st princ.)

• Prove that the sum of the first n odd positive integers is n2. That is, prove:

• Proof by induction.– Base case: Let n=1. The sum of the first 1 odd

positive integer is 1 which equals 12.(Cont…)

2

1

)12(:1 ninn

i

P(n)

Page 7: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

Example cont.Example cont.

• Inductive step: Prove n1: P(n)P(n+1).– Let n1, assume P(n), and prove P(n+1).

2

2

1

1

1

)1(

12

)1)1(2()12()12(

n

nn

niin

i

n

i

By inductivehypothesis P(n)

Page 8: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

Another Induction ExampleAnother Induction Example

• Prove that n>0, n<2n. Let P(n)=(n<2n)– Base case: P(1)=(1<21)=(1<2)=T.– Inductive step: For n>0, prove P(n)P(n+1).• Assuming n<2n, prove n+1 < 2n+1.• Note n + 1 < 2n + 1 (by inductive hypothesis)

< 2n + 2n (because 1<2=2222n-

1= 2n) = 2n+1

• So n + 1 < 2n+1, and we’re done.

Page 9: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

Example of Second PrincipleExample of Second Principle

• Show that every n>1 can be written as a product p1p2…ps of some series of s prime numbers. Let P(n)=“n has that property”

• Base case: n=2, let s=1, p1=2.• Inductive step: Let n2. Assume 2kn: P(k).

Consider n+1. If prime, let s=1, p1=n+1.Else n+1=ab, where 1an and 1bn.Then a=p1p2…pt and b=q1q2…qu. Then n+1= p1p2…pt

q1q2…qu, a product of s=t+u primes.

Page 10: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

Another 2nd Principle ExampleAnother 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=34), 13=24)+1(5), 14=1(4)+2(5), 15=3(5), so 12n15, P(n).

• Inductive step: Let n15, assume 12kn P(k). Note 12n3n, so P(n3), so add a 4-cent stamp to get postage for n+1.

Page 11: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

RecursionRecursion

Page 12: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

Recursive DefinitionsRecursive 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.

Page 13: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

RecursionRecursion

• 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.

Page 14: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

Recursively Defined FunctionsRecursively Defined Functions

• Simplest case: One way to define a function f:NS (for any set S) or series an=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 an :≡ 2n recursively:– Let a0 :≡ 1.

– For n>0, let an :≡ 2an-1.

Page 15: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

Another ExampleAnother Example

• Suppose we define f(n) for all nN recursively by:– Let f(0)=3– For all nN, let f(n+1)=2f(n)+3

• What are the values of the following?– f(1)= f(2)= f(3)= f(4)=9 21 45 93

Page 16: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

Recursive definition of FactorialRecursive definition of Factorial

• Give an inductive definition of the factorial function F(n) :≡ n! :≡ 23…n.– Base case: F(0) :≡ 1– Recursive part: F(n) :≡ n F(n-1).• F(1)=1• F(2)=2• F(3)=6

Page 17: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

The Fibonacci SeriesThe Fibonacci Series

• The Fibonacci series fn≥0 is a famous series defined by:

f0 :≡ 0, f1 :≡ 1, fn≥2 :≡ fn−1 + fn−2

Leonardo Fibonacci1170-1250

01 1

2 35 8

13

Page 18: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

Recursive AlgorithmsRecursive Algorithms

• Recursive definitions can be used to describe algorithms as well as functions and sets.

• Example: A procedure to compute an.procedure power(a≠0: real, nN)

if n = 0 then return 1else return a · power(a, n−1)

Page 19: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

Recursive Factorial AlgorithmRecursive Factorial Algorithm

Procedure factorial(n: nonnegative integer)if n = 0 then factorial(n) = 1else factorial(n) = n · factorial(n - 1)

• 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.

Page 20: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

Recursive Euclid’s AlgorithmRecursive Euclid’s Algorithm

procedure gcd(a,bN)if a = 0 then gcd(a, b) = belse gcd(a, b) = gcd(b mod a, a)

Page 21: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

Recursive Fibonacci AlgorithmRecursive Fibonacci Algorithm

Procedure fibonacci(n: nonnegative integer)if n = 0 then fibonacci(0) = 0else if n = 1 then = fibonacci(1) = 1

else fibonacci(n) = fibonacci(n - 1) + fibonacci(n -

1)

Page 22: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

Tow of HanoiTow of Hanoi

• 3 개의 기둥 중 제일 왼쪽 기둥에 크기가 큰 것이 제일 아래에 있게 원판들이 쌓여있을 때 제일 오른쪽 기둥으로 원판을 옮기는 데 소요되는 최소 이동 회수를 구하는 문제

– 추가조건• 원판은 한 번에 하나씩만 옮길 수 있다 .

• 원판은 기둥과 기둥으로만 옮길 수 있다 .

( 즉 , 바닥에 내려놓을 수 없다 .)

• 크기가 큰 원판은 작은 원판 위에 올 수 없다 .

Page 23: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

Tow of Hanoi cont.Tow of Hanoi cont.• 원판이 3 개인 하노이 탑의 풀이 원리

Page 24: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

Tow of Hanoi cont.Tow of Hanoi cont.• [ 예제 ] 하노이 탑 문제의 재귀 알고리즘을 구하시오 .

[ 풀이 ]

endif

),,1(move

begin

then1if

Begin

),,,(

tofrom

n

nbytofromhanoiprocedure

End

endelse

),1,,,(hanoi

),,(move

)1,,,(hanoi

begin

else

nfromtoby

tofromn

ntobyfrom

Page 25: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

The Merge SortThe Merge Sort

Procedure mergesort(L = a1,…, an)if n > 1 then

m := n/2 {this is rough ½-way point}L1 := a1,…, am

L2 := am+1,…, an

L := merge(mergesort(L1), mergesort(L2)){ L is now sorted into elements in nondreasing

order }

Page 26: Inductive Proofs. Mathematical Induction A powerful, rigorous technique for proving that a predicate P(n) is true for every natural number n, no matter.

Merge RoutineMerge Routine

procedure merge(L1, L2 : sorted lists)L = empty listwhile L1 and L2 are both nonemptyBegin

remove smaller of first element of L1 and L2 from the list it is in and put it at the right end of LIf removal of this element makes one list empty then remove all elements from the other list and append them to L

End (L is the merged sorted list in increasing order)