SlideShare a Scribd company logo
1 of 43
1
Mathematical Induction
CS/APMA 202
Rosen section 3.3
Aaron Bloomfield
2
What is induction?
A method of proof
It does not generate answers:
it only can prove them
Three parts:
 Base case(s): show it is true
for one element
 Inductive hypothesis: assume
it is true for any given element
Must be clearly labeled!!!
 Show that if it true for the next
highest element
3
Show that the sum of the first n odd
integers is n2
 Example: If n = 5, 1+3+5+7+9 = 25 = 52
 Formally, Show
Base case: Show that P(1) is true
Induction example




n
i
n
i
1
2
1
2
1
1
1
1
)
(
2
1
1
2





i
i

 )
P(
where
)
P( n
n
n

)
1
P(

4
Inductive hypothesis: assume true for k
 Thus, we assume that P(k) is true, or that
 Note: we don’t yet know if this is true or not!
Inductive step: show true for k+1
 We want to show that:




k
i
k
i
1
2
1
2






1
1
2
)
1
(
1
2
k
i
k
i
Induction example, continued
5
1
2
1
2
1
)
1
(
2 2
1






 

k
k
i
k
k
i
1
2
1
)
1
(
2 2
2





 k
k
k
k
Induction example, continued
Recall the inductive hypothesis:
Proof of inductive step:




k
i
k
i
1
2
1
2
1
2
1
2 2
2




 k
k
k
k
2
1
1
)
1
(
1
2 





k
i
k
i
6
What did we show
Base case: P(1)
If P(k) was true, then P(k+1) is true
 i.e., P(k) → P(k+1)
We know it’s true for P(1)
Because of P(k) → P(k+1), if it’s true for P(1), then it’s true for P(2)
Because of P(k) → P(k+1), if it’s true for P(2), then it’s true for P(3)
Because of P(k) → P(k+1), if it’s true for P(3), then it’s true for P(4)
Because of P(k) → P(k+1), if it’s true for P(4), then it’s true for P(5)
And onwards to infinity
Thus, it is true for all possible values of n
In other words, we showed that:
 
  )
P(
)
1
P(
)
P(
)
1
P( n
n
k
k
k 





7
The idea behind inductive proofs
Show the base case
Show the inductive hypothesis
Manipulate the inductive step so that you
can substitute in part of the inductive
hypothesis
Show the inductive step
8
Quick survey
 I felt I understood the first example of
induction…
a) Very well
b) With some review, I’ll be good
c) Not really
d) Not at all
9
Quick survey
 I felt I could do my own inductive proof…
a) Very well
b) With some review, I’ll be good
c) Not really
d) Not at all
10
Why speling is not so important…
I cdnuolt blveieetaht I cluod aulaclty uesdnatnrd
waht I was rdanieg. The phaonmneal pweor of
thehmuan mind. Aoccdrnig to a rscheearch at
Cmabrigde Uinervtisy, it deosn't mttaer in waht
oredr the ltteers in a wrod are, the olny iprmoatnt
tihng is taht thefrist and lsat ltteer be in the rghit
pclae. The rset can be a taotl mses andyou can
sitll raed it wouthit a porbelm. Tihs is bcuseae
the huamn mnid deosnot raed ervey lteter by
istlef, but the wrod as a wlohe. Amzanig huh?
yaeh and I awlyas thought slpeling was ipmorantt.
11
Second induction example
Rosen, section 3.3, question 2:
 Show the sum of the first n positive even
integers is n2 + n
 Rephrased:
The three parts:
 Base case
 Inductive hypothesis
 Inductive step






n
i
n
n
i
n
n
n
1
2
2
)
P(
where
)
P(
12
Second induction example,
continued
Base case: Show P(1):
Inductive hypothesis: Assume
Inductive step: Show
2
2
1
1
)
(
2
)
1
P(
1
1
2




 

i
i





k
i
k
k
i
k
1
2
2
)
P(
)
1
(
)
1
(
2
)
1
P( 2
1
1





 


k
k
i
k
k
i
13
2
3
2
3 2
2




 k
k
k
k
1
)
1
(
)
1
(
2 2
2






 k
k
k
k
k
1
)
1
(
2
)
1
(
2 2
1





 

k
k
i
k
k
i
1
)
1
(
2 2
1
1







k
k
i
k
i
Second induction example,
continued
Recall our inductive
hypothesis: 




k
i
k
k
i
k
1
2
2
)
P(
14
Notes on proofs by induction
We manipulate the k+1 case to make part
of it look like the k case
We then replace that part with the other
side of the k case





k
i
k
k
i
k
1
2
2
)
P(
2
3
2
3 2
2




 k
k
k
k
1
)
1
(
)
1
(
2 2
2






 k
k
k
k
k
1
)
1
(
2
)
1
(
2 2
1





 

k
k
i
k
k
i
1
)
1
(
2 2
1
1







k
k
i
k
i
15
Third induction example
Rosen, question 7: Show
Base case: n = 1
Inductive hypothesis: assume
6
)
1
2
)(
1
(
1
2 




n
n
n
i
n
i
1
1
6
6
1
6
)
1
2
)(
1
1
(
1
2
1
1
2







i
i
6
)
1
2
)(
1
(
1
2 




k
k
k
i
k
i
16
Third induction example
Inductive step: show
6
)
1
)
1
(
2
)(
1
)
1
)((
1
(
1
1
2 








k
k
k
i
k
i
6
)
3
2
)(
2
)(
1
(
)
1
(
1
2
2 




 

k
k
k
i
k
k
i
6
13
9
2
6
13
9
2 2
3
2
3






 k
k
k
k
k
k
)
3
2
)(
2
)(
1
(
)
1
2
)(
1
(
)
1
(
6 2







 k
k
k
k
k
k
k
6
)
3
2
)(
2
)(
1
(
6
)
1
2
)(
1
(
)
1
( 2 







k
k
k
k
k
k
k
6
)
1
)
1
(
2
)(
1
)
1
)((
1
(
1
1
2 








k
k
k
i
k
i
6
)
1
2
)(
1
(
1
2 




k
k
k
i
k
i
17
Third induction again: what if your
inductive hypothesis was wrong?
Show:
Base case: n = 1:
But let’s continue anyway…
Inductive hypothesis: assume
6
)
2
2
)(
1
(
1
2 




n
n
n
i
n
i
6
7
1
6
7
1
6
)
2
2
)(
1
1
(
1
2
1
1
2







i
i
6
)
2
2
)(
1
(
1
2 




k
k
k
i
k
i
18
Third induction again: what if your
inductive hypothesis was wrong?
Inductive step: show
6
)
2
)
1
(
2
)(
1
)
1
)((
1
(
1
1
2 








k
k
k
i
k
i
6
)
4
2
)(
2
)(
1
(
)
1
(
1
2
2 




 

k
k
k
i
k
k
i
8
16
10
2
6
14
10
2 2
3
2
3






 k
k
k
k
k
k
)
4
2
)(
2
)(
1
(
)
2
2
)(
1
(
)
1
(
6 2







 k
k
k
k
k
k
k
6
)
4
2
)(
2
)(
1
(
6
)
2
2
)(
1
(
)
1
( 2 







k
k
k
k
k
k
k
6
)
2
)
1
(
2
)(
1
)
1
)((
1
(
1
1
2 








k
k
k
i
k
i
6
)
2
2
)(
1
(
1
2 




k
k
k
i
k
i
19
Fourth induction example
Rosen, question 14: show that n! < nn for
all n > 1
Base case: n = 2
2! < 22
2 < 4
Inductive hypothesis: assume k! < kk
Inductive step: show that (k+1)! < (k+1)k+1
)!
1
( 
k !
)
1
( k
k 

k
k
k )
1
( 
 k
k
k )
1
)(
1
( 

 1
)
1
( 

 k
k
20
Quick survey
 I felt I understand induction…
a) Very well
b) With some review, I’ll be good
c) Not really
d) Not at all
21
Strong induction
Weak mathematical induction assumes
P(k) is true, and uses that (and only that!)
to show P(k+1) is true
Strong mathematical induction assumes
P(1), P(2), …, P(k) are all true, and uses
that to show that P(k+1) is true.
  )
1
P(
)
P(
...
)
3
P(
)
2
P(
)
1
P( 




 k
k
22
Strong induction example 1
Show that any number > 1 can be written
as the product of primes
Base case: P(2)
 2 is the product of 2 (remember that 1 is not
prime!)
Inductive hypothesis: P(1), P(2), P(3), …,
P(k) are all true
Inductive step: Show that P(k+1) is true
23
Strong induction example 1
Inductive step: Show that P(k+1) is true
There are two cases:
 k+1 is prime
It can then be written as the product of k+1
 k+1 is composite
It can be written as the product of two composites,
a and b, where 2 ≤ a ≤ b < k+1
By the inductive hypothesis, both P(a) and P(b) are
true
24
Strong induction vs. non-strong
induction
Rosen, question 31: Determine which
amounts of postage can be written with 5
and 6 cent stamps
 Prove using both versions of induction
 Similar to example 15 (page 250)
Answer: any postage ≥ 20
25
Answer via mathematical induction
Show base case: P(20):
 20 = 5 + 5 + 5 + 5
Inductive hypothesis: Assume P(k) is true
Inductive step: Show that P(k+1) is true
 If P(k) uses a 5 cent stamp, replace that stamp with a
6 cent stamp
 If P(k) does not use a 5 cent stamp, it must use only 6
cent stamps
Since k > 18, there must be four 6 cent stamps
Replace these with five 5 cent stamps to obtain k+1
26
Answer via strong induction
Show base cases: P(20), P(21), P(22), P(23), and P(24)
 20 = 5 + 5 + 5 + 5
 21 = 5 + 5 + 5 + 6
 22 = 5 + 5 + 6 + 6
 23 = 5 + 6 + 6 + 6
 24 = 6 + 6 + 6 + 6
Inductive hypothesis: Assume P(20), P(21), …, P(k) are
all true
Inductive step: Show that P(k+1) is true
 We will obtain P(k+1) by adding a 5 cent stamp to P(k+1-5)
 Since we know P(k+1-5) = P(k-4) is true, our proof is complete
27
Strong induction vs. non-strong
induction, take 2
Rosen, section 3.4, example 15: Show
that every postage amount 12 cents or
more can be formed using only 4 and 5
cent stamps
Similar to the previous example
28
Answer via mathematical induction
Show base case: P(12):
 12 = 4 + 4 + 4
Inductive hypothesis: Assume P(k) is true
Inductive step: Show that P(k+1) is true
 If P(k) uses a 4 cent stamp, replace that stamp with a
5 cent stamp to obtain P(k+1)
 If P(k) does not use a 4 cent stamp, it must use only 5
cent stamps
Since k > 10, there must be at least three 5 cent stamps
Replace these with four 4 cent stamps to obtain k+1
Note that only P(k) was assumed to be true
29
Answer via strong induction
Show base cases: P(12), P(13), P(14), and P(15)
 12 = 4 + 4 + 4
 13 = 4 + 4 + 5
 14 = 4 + 5 + 5
 15 = 5 + 5 + 5
Inductive hypothesis: Assume P(12), P(13), …, P(k) are all true
 For k ≥ 15
Inductive step: Show that P(k+1) is true
 We will obtain P(k+1) by adding a 4 cent stamp to P(k+1-4)
 Since we know P(k+1-4) = P(k-3) is true, our proof is complete
Note that P(12), P(13), …, P(k) were all assumed to be true
30
Quick survey
 I felt I understand strong vs. weak induction…
a) Very well
b) With some review, I’ll be good
c) Not really
d) Not at all
31
An aside: IOCCC
 The International Obfuscated C Code
Contest
– Online at http://www.ioccc.org
 C has very terse syntax
– So the contest tries to make it terser!
 One common method is by modifying the
whitespace
32
X X
X X X X
X X X X
X X X X
X X X X
X X X X
X X X X
X X X X X X
X XX X X XX X
X XXX X XXXXXXXXX X XXX X
X XXX X XXXX XXXX X XXX X
X XXXX X XX ainma(){ archa XX X XXXX X
X XXXX X oink[9],*igpa, X XXXX X
X XXXXXX atinla=etcharga(),iocccwa XXXXXX X
X XXXX ,apca='A',owla='a',umna=26 XXXX X
X XXX ; orfa(; (atinla+1)&&(!((( XXX X
X XX atinla-apca)*(apca+umna-atinla) XX X
X X >=0)+((atinla-owla)*(owla+umna- X X
X atinla)>=0))); utcharpa(atinla), X
X X atinla=etcharga()); orfa(; atinla+1; X X
X X ){ orfa( igpa=oink ,iocccwa=( X X
X X (atinla- XXX apca)*( XXX apca+umna- X X
X atinla)>=0) XXX XXX ; (((( X
X atinla-apca XXXXX XXXXXXX XXXXX )*(apca+ X
X umna-atinla XXXXXX )>=0) XXXXXX +((atinla- X
X owla)*(owla+ XXXX umna- XXXX atinla)>=0)) X
X &&"-Pig-" XX "Lat-in" XX "COb-fus" X
X "ca-tion!!"[ X (((atinla- X apca)*(apca+ X
X umna-atinla) X >=0)?atinla- X apca+owla: X
X atinla)-owla X ]-'-')||((igpa== X oink)&&!(*( X
X igpa++)='w') X )||! X (*( X igpa X ++)=owla); * X
X (igpa++)=(( X ( XXX XXX X atinla-apca X
X )*(apca+ X umna XXX - XXX X atinla)>=0) X
X ?atinla- X apca XXX + XXX owla X :atinla), X
X atinla= X X X X etcharga()) X
X ; orfa( X atinla=iocccwa?(( X (atinla- X
X owla)*(owla+ X umna-atinla)>=0 X )?atinla- X
X owla+apca: X atinla): X atinla; ((( X
X atinla-apca)* X (apca+umna- X atinla)>=0)+( X
X (atinla-owla)* X (owla+ X umna-atinla)>= X
X 0)); utcharpa( XX XX atinla),atinla X
X =etcharga()); XXXXXXX orfa(*igpa=0, X
X igpa=oink; * igpa; utcharpa( X
X *(igpa++))); orfa(; (atinla+1)&&(!((( X
X atinla-apca )*(apca+ X
X umna- XXXXX XXXXX atinla)>=0 X
X )+(( XXXXX atinla- X
XX owla)*( owla+umna- XX
XX atinla)>=0))); utcharpa XX
XX (atinla),atinla= XX
XX etcharga()); } XX
XXXX } XXXX
XXXXXXXXX
#define X
#define XX
#define XXX
#define XXXX
#define XXXXX
#define XXXXXX
#define XXXXXXX
#define orfa for
#define XXXXXXXXX
#define archa char
#define ainma main
#define etcharga getchar
#define utcharpa putchar
#include <stdio.h>
#define Q r=R[*p++-'0'];while(
#define B ;break;case
char*s="Qjou!s311^-g311^-n311^-c::^-q-ma%mO1JBHm%BQ-aP1J[O1HB%[Q<nbj
o)*|gps)<<*txjudi)m*|aQdbtf!::::;sfuvso<aQefgbvmu;aQ<m,,a%CQ<csfbla%bQ<aN2!Q
ndbtf!aP2Q;m>aP2Q<a%!D12J!JGJHJOJQJFJSJJJMHS%HD12D12N3!N4nJUJT%UQm>aP4HC%T
Qsq,,^>m,2<m>aP4HC%SD12N1nJNQm>s..q^aHC%NHb%GN1!D32P3%RN1UP1D12JPQUaP1H
R%PN4nQ<g(aP3Q(^>aP2Q,2<n(aP3Q(^>aP4Hb%OD12D12N2!N3nJVP3Q,,<jg)aP3Q=>n
(aP3Q(^*m>g(aP3Q(^<fmtf!m,,aHC%QN1!N1nJ#Qqsjoug)#&e]o#-aP1Q*aHb%#Qqvut)
aP1Q*aHb%FN1nQm>::::aHC%VP3Q>bupj)hfut)c**aHb%JD12JON1!Qjg)a%LN1UP1D12JIQUa
P1HL%IQ*m>aN2!N2nP2Q<fmtf!m,,aHC%MN1!N2>P2Q>aN2nP2Hbdd!b/d";k;char R[4][99]
;main(c,v)char**v;{char*p,*r,*q;for(q=s;*q;q++)*q>' '&&(*q)--;{FILE*i=fopen(v
[1],"r"),*o=fopen(q-3,"w");for(p=s;;p++)switch(*p++){B'M':Q(k=fgetc(i))!=EOF
&&k!=*p)*r++=k;if(k==EOF){fputs("}}n",o);fclose(o);return system(q-6);}*r=0
B'P':while(*p!='`')fputc(*p++,o)B'O':Q*r)fputc(*r++,o);p--B'C':k=0;Q k<*p-'0'
)(*r++=fgetc(i),k++);*r=0 B'I':k= *p;if(**R==k)goto G B'G':k= *p;G:p=s;while(
*p!='$'||p[1]!= k)p++;p++B'N':R[*p-'0'][0]++;}}}
a(X){/*/X=- a(X){/*/X=-
-1;F;X=- -1;F;X=-
-1;F;}/*/ -1;F;}/*/
char*z[]={"char*z[]={","a(X){/*/X=-","-1;F;X=-","-1;F;}/*/","9999999999 :-| ",
"int q,i,j,k,X,O=0,H;S(x)int*x;{X+=X;O+=O;*x+1?*x+2||X++:O++;*x=1;}L(n){for(*",
"z[i=1]=n+97;i<4;i++)M(256),s(i),M(128),s(i),M(64),N;X*=8;O*=8;}s(R){char*r=z",
"[R];for(q&&Q;*r;)P(*r++);q&&(Q,P(44));}M(m){P(9);i-2||P(X&m?88:O&m?48:32);P(",
"9);}y(A){for(j=8;j;)~A&w[--j]||(q=0);}e(W,Z){for(i-=i*q;i<9&&q;)y(W|(1<<i++&",
"~Z));}R(){for(k=J[*J-48]-40;k;)e(w[k--],X|O);}main(u,v)char**v;{a(q=1);b(1);",
"c(1);*J=--u?O?*J:*v[1]:53;X|=u<<57-*v[u];y(X);K=40+q;q?e(O,X),q&&(K='|'),e(X",
",O),R(),O|=1<<--i:J[*J-48+(X=O=0)]--;L(q=0);for(s(i=0);q=i<12;)s(i++),i>4&&N",
";s(q=12);P(48);P('}');P(59);N;q=0;L(1);for(i=5;i<13;)s(i++),N;L(2);}",0};
b(X){/*/X=- b(X){/*/X=-
-1;F;X=- -1;F;X=-
-1;F;}/*/ -1;F;}/*/
int q,i,j,k,X,O=0,H;S(x)int*x;{X+=X;O+=O;*x+1?*x+2||X++:O++;*x=1;}L(n){for(*
z[i=1]=n+97;i<4;i++)M(256),s(i),M(128),s(i),M(64),N;X*=8;O*=8;}s(R){char*r=z
[R];for(q&&Q;*r;)P(*r++);q&&(Q,P(44));}M(m){P(9);i-2||P(X&m?88:O&m?48:32);P(
9);}y(A){for(j=8;j;)~A&w[--j]||(q=0);}e(W,Z){for(i-=i*q;i<9&&q;)y(W|(1<<i++&
~Z));}R(){for(k=J[*J-48]-40;k;)e(w[k--],X|O);}main(u,v)char**v;{a(q=1);b(1);
c(1);*J=--u?O?*J:*v[1]:53;X|=u<<57-*v[u];y(X);K=40+q;q?e(O,X),q&&(K='|'),e(X
,O),R(),O|=1<<--i:J[*J-48+(X=O=0)]--;L(q=0);for(s(i=0);q=i<12;)s(i++),i>4&&N
;s(q=12);P(48);P('}');P(59);N;q=0;L(1);for(i=5;i<13;)s(i++),N;L(2);}
c(X){/*/X=- c(X){/*/X=-
-1;F;X=- -1;F;X=-
-1;F;}/*/ -1;F;}/*/
An aside: IOCCC
#define _ -F<00||--F-OO--;
int F=00,OO=00;main(){F_OO();printf("%1.3fn",4.*-F/OO/OO);}F_OO()
{
_-_-_-_
_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_-_-_-_-_
_-_-_-_-_-_-_-_
_-_-_-_
}
33
Chess and induction
7
6
5
4
3
2
1
0
0 1 2 3 4 5 6 7
Can the knight reach any
square in a finite number
of moves?
Show that the knight can
reach any square (i, j) for
which i+j=k where k > 1.
Base case: k = 2
Inductive hypothesis:
assume the knight can
reach any square (i, j) for
which i+j=k where k > 1.
Inductive step: show the
knight can reach any
square (i, j) for which
i+j=k+1 where k > 1.
34
Chess and induction
Inductive step: show the knight can reach any
square (i, j) for which i+j=k+1 where k > 1.
 Note that k+1 ≥ 3, and one of i or j is ≥ 2
 If i ≥ 2, the knight could have moved from (i-2, j+1)
Since i+j = k+1, i-2 + j+1 = k, which is assumed true
 If j ≥ 2, the knight could have moved from (i+1, j-2)
Since i+j = k+1, i+1 + j-2 = k, which is assumed true
35
We are skipping…
The well-ordering property
Why mathematical induction is valid
These are the last two sub-sections of
section 3.3
36
Question 40
Take a pile of n stones
 Split the pile into two smaller piles of size r
and s
 Repeat until you have n piles of 1 stone each
Take the product of all the splits
 So all the r’s and s’s from each split
Sum up each of these products
Prove that this product equals
2
)
1
( 
n
n
37
10
3
1
4
7
1 1
2 2 2 1
2
3
1 1 1 1 1 1
21
12 2
4 2 1
1 1 1
Question 40
2
)
1
( 
n
n
10
2
9
*
10
45
1
1
1
1
2
4
2
12
21 









38
Question 40
We will show it is true for a pile of k
stones, and show it is true for k+1 stones
 So P(k) means that it is true for k stones
Base case: n = 1
 No splits necessary, so the sum of the
products = 0
 1*(1-1)/2 = 0
 Base case proven
39
Question 40
Inductive hypothesis: assume that P(1), P(2), …,
P(k) are all true
 This is strong induction!
Inductive step: Show that P(k+1) is true
 We assume that we split the k+1 pile into a pile of i
stones and a pile of k+1-i stones
 Thus, we want to show that
(i)*(k+1-i) + P(i) + P(k+1-i) = P(k+1)
 Since 0 < i < k+1, both i and k+1-i are between 1 and
k, inclusive
40
Question 40
k
k
k
k 

 2
2
k
k
i
i
ki
k
k
i
i
i
i
ki 









 2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2 k
k
i
i
ki
k
k
i
i
i
i
ki











)
1
P(
)
1
P(
)
P(
)
1
(
*
)
( 






 k
i
k
i
i
k
i
2
2
)
1
1
)(
1
(
)
1
P(
2
k
k
k
k
k







2
2
2
)
1
1
)(
1
(
)
1
P(
2
2
i
i
ki
k
k
i
k
i
k
i
k













2
)
P(
2
i
i
i


Thus, we want to show that
(i)*(k+1-i) + P(i) + P(k+1-i) = P(k+1)
41
Quick survey
 I felt I understood the material in this slide set…
a) Very well
b) With some review, I’ll be good
c) Not really
d) Not at all
42
Quick survey
 The pace of the lecture for this slide set was…
a) Fast
b) About right
c) A little slow
d) Too slow
43
Quick survey
 How interesting was the material in this slide
set? Be honest!
a) Wow! That was SOOOOOO cool!
b) Somewhat interesting
c) Rather borting
d) Zzzzzzzzzzz

More Related Content

Similar to 17-mathematical-induction.ppt

Similar to 17-mathematical-induction.ppt (20)

11-Induction CIIT.pptx
11-Induction CIIT.pptx11-Induction CIIT.pptx
11-Induction CIIT.pptx
 
6e-ch4.ppt
6e-ch4.ppt6e-ch4.ppt
6e-ch4.ppt
 
Mcs 013 solve assignment
Mcs 013 solve assignmentMcs 013 solve assignment
Mcs 013 solve assignment
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
Chapter5.pptx
Chapter5.pptxChapter5.pptx
Chapter5.pptx
 
Induction.pptx
Induction.pptxInduction.pptx
Induction.pptx
 
mathematical induction and stuff Induction.pptx
mathematical induction and stuff Induction.pptxmathematical induction and stuff Induction.pptx
mathematical induction and stuff Induction.pptx
 
DMA_Induction (2).pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
DMA_Induction (2).pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnDMA_Induction (2).pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
DMA_Induction (2).pptx nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
 
Principle of mathematical induction
Principle of mathematical inductionPrinciple of mathematical induction
Principle of mathematical induction
 
Aa - Module 1 Fundamentals_2.pdf
Aa  - Module 1  Fundamentals_2.pdfAa  - Module 1  Fundamentals_2.pdf
Aa - Module 1 Fundamentals_2.pdf
 
5.1 Induction
5.1 Induction5.1 Induction
5.1 Induction
 
1112 ch 11 day 12
1112 ch 11 day 121112 ch 11 day 12
1112 ch 11 day 12
 
Discrete Math Lecture 03: Methods of Proof
Discrete Math Lecture 03: Methods of ProofDiscrete Math Lecture 03: Methods of Proof
Discrete Math Lecture 03: Methods of Proof
 
Mathematical Induction DM
Mathematical Induction DMMathematical Induction DM
Mathematical Induction DM
 
CMSC 56 | Lecture 11: Mathematical Induction
CMSC 56 | Lecture 11: Mathematical InductionCMSC 56 | Lecture 11: Mathematical Induction
CMSC 56 | Lecture 11: Mathematical Induction
 
G03201034038
G03201034038G03201034038
G03201034038
 
Lemh1a1
Lemh1a1Lemh1a1
Lemh1a1
 
Lemh1a1
Lemh1a1Lemh1a1
Lemh1a1
 
Stochastic Processes Homework Help
Stochastic Processes Homework HelpStochastic Processes Homework Help
Stochastic Processes Homework Help
 
DM(1).pptx
DM(1).pptxDM(1).pptx
DM(1).pptx
 

Recently uploaded

Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 

Recently uploaded (20)

Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 

17-mathematical-induction.ppt

  • 1. 1 Mathematical Induction CS/APMA 202 Rosen section 3.3 Aaron Bloomfield
  • 2. 2 What is induction? A method of proof It does not generate answers: it only can prove them Three parts:  Base case(s): show it is true for one element  Inductive hypothesis: assume it is true for any given element Must be clearly labeled!!!  Show that if it true for the next highest element
  • 3. 3 Show that the sum of the first n odd integers is n2  Example: If n = 5, 1+3+5+7+9 = 25 = 52  Formally, Show Base case: Show that P(1) is true Induction example     n i n i 1 2 1 2 1 1 1 1 ) ( 2 1 1 2      i i   ) P( where ) P( n n n  ) 1 P( 
  • 4. 4 Inductive hypothesis: assume true for k  Thus, we assume that P(k) is true, or that  Note: we don’t yet know if this is true or not! Inductive step: show true for k+1  We want to show that:     k i k i 1 2 1 2       1 1 2 ) 1 ( 1 2 k i k i Induction example, continued
  • 5. 5 1 2 1 2 1 ) 1 ( 2 2 1          k k i k k i 1 2 1 ) 1 ( 2 2 2       k k k k Induction example, continued Recall the inductive hypothesis: Proof of inductive step:     k i k i 1 2 1 2 1 2 1 2 2 2      k k k k 2 1 1 ) 1 ( 1 2       k i k i
  • 6. 6 What did we show Base case: P(1) If P(k) was true, then P(k+1) is true  i.e., P(k) → P(k+1) We know it’s true for P(1) Because of P(k) → P(k+1), if it’s true for P(1), then it’s true for P(2) Because of P(k) → P(k+1), if it’s true for P(2), then it’s true for P(3) Because of P(k) → P(k+1), if it’s true for P(3), then it’s true for P(4) Because of P(k) → P(k+1), if it’s true for P(4), then it’s true for P(5) And onwards to infinity Thus, it is true for all possible values of n In other words, we showed that:     ) P( ) 1 P( ) P( ) 1 P( n n k k k      
  • 7. 7 The idea behind inductive proofs Show the base case Show the inductive hypothesis Manipulate the inductive step so that you can substitute in part of the inductive hypothesis Show the inductive step
  • 8. 8 Quick survey  I felt I understood the first example of induction… a) Very well b) With some review, I’ll be good c) Not really d) Not at all
  • 9. 9 Quick survey  I felt I could do my own inductive proof… a) Very well b) With some review, I’ll be good c) Not really d) Not at all
  • 10. 10 Why speling is not so important… I cdnuolt blveieetaht I cluod aulaclty uesdnatnrd waht I was rdanieg. The phaonmneal pweor of thehmuan mind. Aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it deosn't mttaer in waht oredr the ltteers in a wrod are, the olny iprmoatnt tihng is taht thefrist and lsat ltteer be in the rghit pclae. The rset can be a taotl mses andyou can sitll raed it wouthit a porbelm. Tihs is bcuseae the huamn mnid deosnot raed ervey lteter by istlef, but the wrod as a wlohe. Amzanig huh? yaeh and I awlyas thought slpeling was ipmorantt.
  • 11. 11 Second induction example Rosen, section 3.3, question 2:  Show the sum of the first n positive even integers is n2 + n  Rephrased: The three parts:  Base case  Inductive hypothesis  Inductive step       n i n n i n n n 1 2 2 ) P( where ) P(
  • 12. 12 Second induction example, continued Base case: Show P(1): Inductive hypothesis: Assume Inductive step: Show 2 2 1 1 ) ( 2 ) 1 P( 1 1 2        i i      k i k k i k 1 2 2 ) P( ) 1 ( ) 1 ( 2 ) 1 P( 2 1 1          k k i k k i
  • 13. 13 2 3 2 3 2 2      k k k k 1 ) 1 ( ) 1 ( 2 2 2        k k k k k 1 ) 1 ( 2 ) 1 ( 2 2 1         k k i k k i 1 ) 1 ( 2 2 1 1        k k i k i Second induction example, continued Recall our inductive hypothesis:      k i k k i k 1 2 2 ) P(
  • 14. 14 Notes on proofs by induction We manipulate the k+1 case to make part of it look like the k case We then replace that part with the other side of the k case      k i k k i k 1 2 2 ) P( 2 3 2 3 2 2      k k k k 1 ) 1 ( ) 1 ( 2 2 2        k k k k k 1 ) 1 ( 2 ) 1 ( 2 2 1         k k i k k i 1 ) 1 ( 2 2 1 1        k k i k i
  • 15. 15 Third induction example Rosen, question 7: Show Base case: n = 1 Inductive hypothesis: assume 6 ) 1 2 )( 1 ( 1 2      n n n i n i 1 1 6 6 1 6 ) 1 2 )( 1 1 ( 1 2 1 1 2        i i 6 ) 1 2 )( 1 ( 1 2      k k k i k i
  • 16. 16 Third induction example Inductive step: show 6 ) 1 ) 1 ( 2 )( 1 ) 1 )(( 1 ( 1 1 2          k k k i k i 6 ) 3 2 )( 2 )( 1 ( ) 1 ( 1 2 2         k k k i k k i 6 13 9 2 6 13 9 2 2 3 2 3        k k k k k k ) 3 2 )( 2 )( 1 ( ) 1 2 )( 1 ( ) 1 ( 6 2         k k k k k k k 6 ) 3 2 )( 2 )( 1 ( 6 ) 1 2 )( 1 ( ) 1 ( 2         k k k k k k k 6 ) 1 ) 1 ( 2 )( 1 ) 1 )(( 1 ( 1 1 2          k k k i k i 6 ) 1 2 )( 1 ( 1 2      k k k i k i
  • 17. 17 Third induction again: what if your inductive hypothesis was wrong? Show: Base case: n = 1: But let’s continue anyway… Inductive hypothesis: assume 6 ) 2 2 )( 1 ( 1 2      n n n i n i 6 7 1 6 7 1 6 ) 2 2 )( 1 1 ( 1 2 1 1 2        i i 6 ) 2 2 )( 1 ( 1 2      k k k i k i
  • 18. 18 Third induction again: what if your inductive hypothesis was wrong? Inductive step: show 6 ) 2 ) 1 ( 2 )( 1 ) 1 )(( 1 ( 1 1 2          k k k i k i 6 ) 4 2 )( 2 )( 1 ( ) 1 ( 1 2 2         k k k i k k i 8 16 10 2 6 14 10 2 2 3 2 3        k k k k k k ) 4 2 )( 2 )( 1 ( ) 2 2 )( 1 ( ) 1 ( 6 2         k k k k k k k 6 ) 4 2 )( 2 )( 1 ( 6 ) 2 2 )( 1 ( ) 1 ( 2         k k k k k k k 6 ) 2 ) 1 ( 2 )( 1 ) 1 )(( 1 ( 1 1 2          k k k i k i 6 ) 2 2 )( 1 ( 1 2      k k k i k i
  • 19. 19 Fourth induction example Rosen, question 14: show that n! < nn for all n > 1 Base case: n = 2 2! < 22 2 < 4 Inductive hypothesis: assume k! < kk Inductive step: show that (k+1)! < (k+1)k+1 )! 1 (  k ! ) 1 ( k k   k k k ) 1 (   k k k ) 1 )( 1 (    1 ) 1 (    k k
  • 20. 20 Quick survey  I felt I understand induction… a) Very well b) With some review, I’ll be good c) Not really d) Not at all
  • 21. 21 Strong induction Weak mathematical induction assumes P(k) is true, and uses that (and only that!) to show P(k+1) is true Strong mathematical induction assumes P(1), P(2), …, P(k) are all true, and uses that to show that P(k+1) is true.   ) 1 P( ) P( ... ) 3 P( ) 2 P( ) 1 P(       k k
  • 22. 22 Strong induction example 1 Show that any number > 1 can be written as the product of primes Base case: P(2)  2 is the product of 2 (remember that 1 is not prime!) Inductive hypothesis: P(1), P(2), P(3), …, P(k) are all true Inductive step: Show that P(k+1) is true
  • 23. 23 Strong induction example 1 Inductive step: Show that P(k+1) is true There are two cases:  k+1 is prime It can then be written as the product of k+1  k+1 is composite It can be written as the product of two composites, a and b, where 2 ≤ a ≤ b < k+1 By the inductive hypothesis, both P(a) and P(b) are true
  • 24. 24 Strong induction vs. non-strong induction Rosen, question 31: Determine which amounts of postage can be written with 5 and 6 cent stamps  Prove using both versions of induction  Similar to example 15 (page 250) Answer: any postage ≥ 20
  • 25. 25 Answer via mathematical induction Show base case: P(20):  20 = 5 + 5 + 5 + 5 Inductive hypothesis: Assume P(k) is true Inductive step: Show that P(k+1) is true  If P(k) uses a 5 cent stamp, replace that stamp with a 6 cent stamp  If P(k) does not use a 5 cent stamp, it must use only 6 cent stamps Since k > 18, there must be four 6 cent stamps Replace these with five 5 cent stamps to obtain k+1
  • 26. 26 Answer via strong induction Show base cases: P(20), P(21), P(22), P(23), and P(24)  20 = 5 + 5 + 5 + 5  21 = 5 + 5 + 5 + 6  22 = 5 + 5 + 6 + 6  23 = 5 + 6 + 6 + 6  24 = 6 + 6 + 6 + 6 Inductive hypothesis: Assume P(20), P(21), …, P(k) are all true Inductive step: Show that P(k+1) is true  We will obtain P(k+1) by adding a 5 cent stamp to P(k+1-5)  Since we know P(k+1-5) = P(k-4) is true, our proof is complete
  • 27. 27 Strong induction vs. non-strong induction, take 2 Rosen, section 3.4, example 15: Show that every postage amount 12 cents or more can be formed using only 4 and 5 cent stamps Similar to the previous example
  • 28. 28 Answer via mathematical induction Show base case: P(12):  12 = 4 + 4 + 4 Inductive hypothesis: Assume P(k) is true Inductive step: Show that P(k+1) is true  If P(k) uses a 4 cent stamp, replace that stamp with a 5 cent stamp to obtain P(k+1)  If P(k) does not use a 4 cent stamp, it must use only 5 cent stamps Since k > 10, there must be at least three 5 cent stamps Replace these with four 4 cent stamps to obtain k+1 Note that only P(k) was assumed to be true
  • 29. 29 Answer via strong induction Show base cases: P(12), P(13), P(14), and P(15)  12 = 4 + 4 + 4  13 = 4 + 4 + 5  14 = 4 + 5 + 5  15 = 5 + 5 + 5 Inductive hypothesis: Assume P(12), P(13), …, P(k) are all true  For k ≥ 15 Inductive step: Show that P(k+1) is true  We will obtain P(k+1) by adding a 4 cent stamp to P(k+1-4)  Since we know P(k+1-4) = P(k-3) is true, our proof is complete Note that P(12), P(13), …, P(k) were all assumed to be true
  • 30. 30 Quick survey  I felt I understand strong vs. weak induction… a) Very well b) With some review, I’ll be good c) Not really d) Not at all
  • 31. 31 An aside: IOCCC  The International Obfuscated C Code Contest – Online at http://www.ioccc.org  C has very terse syntax – So the contest tries to make it terser!  One common method is by modifying the whitespace
  • 32. 32 X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X XX X X XX X X XXX X XXXXXXXXX X XXX X X XXX X XXXX XXXX X XXX X X XXXX X XX ainma(){ archa XX X XXXX X X XXXX X oink[9],*igpa, X XXXX X X XXXXXX atinla=etcharga(),iocccwa XXXXXX X X XXXX ,apca='A',owla='a',umna=26 XXXX X X XXX ; orfa(; (atinla+1)&&(!((( XXX X X XX atinla-apca)*(apca+umna-atinla) XX X X X >=0)+((atinla-owla)*(owla+umna- X X X atinla)>=0))); utcharpa(atinla), X X X atinla=etcharga()); orfa(; atinla+1; X X X X ){ orfa( igpa=oink ,iocccwa=( X X X X (atinla- XXX apca)*( XXX apca+umna- X X X atinla)>=0) XXX XXX ; (((( X X atinla-apca XXXXX XXXXXXX XXXXX )*(apca+ X X umna-atinla XXXXXX )>=0) XXXXXX +((atinla- X X owla)*(owla+ XXXX umna- XXXX atinla)>=0)) X X &&"-Pig-" XX "Lat-in" XX "COb-fus" X X "ca-tion!!"[ X (((atinla- X apca)*(apca+ X X umna-atinla) X >=0)?atinla- X apca+owla: X X atinla)-owla X ]-'-')||((igpa== X oink)&&!(*( X X igpa++)='w') X )||! X (*( X igpa X ++)=owla); * X X (igpa++)=(( X ( XXX XXX X atinla-apca X X )*(apca+ X umna XXX - XXX X atinla)>=0) X X ?atinla- X apca XXX + XXX owla X :atinla), X X atinla= X X X X etcharga()) X X ; orfa( X atinla=iocccwa?(( X (atinla- X X owla)*(owla+ X umna-atinla)>=0 X )?atinla- X X owla+apca: X atinla): X atinla; ((( X X atinla-apca)* X (apca+umna- X atinla)>=0)+( X X (atinla-owla)* X (owla+ X umna-atinla)>= X X 0)); utcharpa( XX XX atinla),atinla X X =etcharga()); XXXXXXX orfa(*igpa=0, X X igpa=oink; * igpa; utcharpa( X X *(igpa++))); orfa(; (atinla+1)&&(!((( X X atinla-apca )*(apca+ X X umna- XXXXX XXXXX atinla)>=0 X X )+(( XXXXX atinla- X XX owla)*( owla+umna- XX XX atinla)>=0))); utcharpa XX XX (atinla),atinla= XX XX etcharga()); } XX XXXX } XXXX XXXXXXXXX #define X #define XX #define XXX #define XXXX #define XXXXX #define XXXXXX #define XXXXXXX #define orfa for #define XXXXXXXXX #define archa char #define ainma main #define etcharga getchar #define utcharpa putchar #include <stdio.h> #define Q r=R[*p++-'0'];while( #define B ;break;case char*s="Qjou!s311^-g311^-n311^-c::^-q-ma%mO1JBHm%BQ-aP1J[O1HB%[Q<nbj o)*|gps)<<*txjudi)m*|aQdbtf!::::;sfuvso<aQefgbvmu;aQ<m,,a%CQ<csfbla%bQ<aN2!Q ndbtf!aP2Q;m>aP2Q<a%!D12J!JGJHJOJQJFJSJJJMHS%HD12D12N3!N4nJUJT%UQm>aP4HC%T Qsq,,^>m,2<m>aP4HC%SD12N1nJNQm>s..q^aHC%NHb%GN1!D32P3%RN1UP1D12JPQUaP1H R%PN4nQ<g(aP3Q(^>aP2Q,2<n(aP3Q(^>aP4Hb%OD12D12N2!N3nJVP3Q,,<jg)aP3Q=>n (aP3Q(^*m>g(aP3Q(^<fmtf!m,,aHC%QN1!N1nJ#Qqsjoug)#&e]o#-aP1Q*aHb%#Qqvut) aP1Q*aHb%FN1nQm>::::aHC%VP3Q>bupj)hfut)c**aHb%JD12JON1!Qjg)a%LN1UP1D12JIQUa P1HL%IQ*m>aN2!N2nP2Q<fmtf!m,,aHC%MN1!N2>P2Q>aN2nP2Hbdd!b/d";k;char R[4][99] ;main(c,v)char**v;{char*p,*r,*q;for(q=s;*q;q++)*q>' '&&(*q)--;{FILE*i=fopen(v [1],"r"),*o=fopen(q-3,"w");for(p=s;;p++)switch(*p++){B'M':Q(k=fgetc(i))!=EOF &&k!=*p)*r++=k;if(k==EOF){fputs("}}n",o);fclose(o);return system(q-6);}*r=0 B'P':while(*p!='`')fputc(*p++,o)B'O':Q*r)fputc(*r++,o);p--B'C':k=0;Q k<*p-'0' )(*r++=fgetc(i),k++);*r=0 B'I':k= *p;if(**R==k)goto G B'G':k= *p;G:p=s;while( *p!='$'||p[1]!= k)p++;p++B'N':R[*p-'0'][0]++;}}} a(X){/*/X=- a(X){/*/X=- -1;F;X=- -1;F;X=- -1;F;}/*/ -1;F;}/*/ char*z[]={"char*z[]={","a(X){/*/X=-","-1;F;X=-","-1;F;}/*/","9999999999 :-| ", "int q,i,j,k,X,O=0,H;S(x)int*x;{X+=X;O+=O;*x+1?*x+2||X++:O++;*x=1;}L(n){for(*", "z[i=1]=n+97;i<4;i++)M(256),s(i),M(128),s(i),M(64),N;X*=8;O*=8;}s(R){char*r=z", "[R];for(q&&Q;*r;)P(*r++);q&&(Q,P(44));}M(m){P(9);i-2||P(X&m?88:O&m?48:32);P(", "9);}y(A){for(j=8;j;)~A&w[--j]||(q=0);}e(W,Z){for(i-=i*q;i<9&&q;)y(W|(1<<i++&", "~Z));}R(){for(k=J[*J-48]-40;k;)e(w[k--],X|O);}main(u,v)char**v;{a(q=1);b(1);", "c(1);*J=--u?O?*J:*v[1]:53;X|=u<<57-*v[u];y(X);K=40+q;q?e(O,X),q&&(K='|'),e(X", ",O),R(),O|=1<<--i:J[*J-48+(X=O=0)]--;L(q=0);for(s(i=0);q=i<12;)s(i++),i>4&&N", ";s(q=12);P(48);P('}');P(59);N;q=0;L(1);for(i=5;i<13;)s(i++),N;L(2);}",0}; b(X){/*/X=- b(X){/*/X=- -1;F;X=- -1;F;X=- -1;F;}/*/ -1;F;}/*/ int q,i,j,k,X,O=0,H;S(x)int*x;{X+=X;O+=O;*x+1?*x+2||X++:O++;*x=1;}L(n){for(* z[i=1]=n+97;i<4;i++)M(256),s(i),M(128),s(i),M(64),N;X*=8;O*=8;}s(R){char*r=z [R];for(q&&Q;*r;)P(*r++);q&&(Q,P(44));}M(m){P(9);i-2||P(X&m?88:O&m?48:32);P( 9);}y(A){for(j=8;j;)~A&w[--j]||(q=0);}e(W,Z){for(i-=i*q;i<9&&q;)y(W|(1<<i++& ~Z));}R(){for(k=J[*J-48]-40;k;)e(w[k--],X|O);}main(u,v)char**v;{a(q=1);b(1); c(1);*J=--u?O?*J:*v[1]:53;X|=u<<57-*v[u];y(X);K=40+q;q?e(O,X),q&&(K='|'),e(X ,O),R(),O|=1<<--i:J[*J-48+(X=O=0)]--;L(q=0);for(s(i=0);q=i<12;)s(i++),i>4&&N ;s(q=12);P(48);P('}');P(59);N;q=0;L(1);for(i=5;i<13;)s(i++),N;L(2);} c(X){/*/X=- c(X){/*/X=- -1;F;X=- -1;F;X=- -1;F;}/*/ -1;F;}/*/ An aside: IOCCC #define _ -F<00||--F-OO--; int F=00,OO=00;main(){F_OO();printf("%1.3fn",4.*-F/OO/OO);}F_OO() { _-_-_-_ _-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_-_-_-_-_ _-_-_-_-_-_-_-_ _-_-_-_ }
  • 33. 33 Chess and induction 7 6 5 4 3 2 1 0 0 1 2 3 4 5 6 7 Can the knight reach any square in a finite number of moves? Show that the knight can reach any square (i, j) for which i+j=k where k > 1. Base case: k = 2 Inductive hypothesis: assume the knight can reach any square (i, j) for which i+j=k where k > 1. Inductive step: show the knight can reach any square (i, j) for which i+j=k+1 where k > 1.
  • 34. 34 Chess and induction Inductive step: show the knight can reach any square (i, j) for which i+j=k+1 where k > 1.  Note that k+1 ≥ 3, and one of i or j is ≥ 2  If i ≥ 2, the knight could have moved from (i-2, j+1) Since i+j = k+1, i-2 + j+1 = k, which is assumed true  If j ≥ 2, the knight could have moved from (i+1, j-2) Since i+j = k+1, i+1 + j-2 = k, which is assumed true
  • 35. 35 We are skipping… The well-ordering property Why mathematical induction is valid These are the last two sub-sections of section 3.3
  • 36. 36 Question 40 Take a pile of n stones  Split the pile into two smaller piles of size r and s  Repeat until you have n piles of 1 stone each Take the product of all the splits  So all the r’s and s’s from each split Sum up each of these products Prove that this product equals 2 ) 1 (  n n
  • 37. 37 10 3 1 4 7 1 1 2 2 2 1 2 3 1 1 1 1 1 1 21 12 2 4 2 1 1 1 1 Question 40 2 ) 1 (  n n 10 2 9 * 10 45 1 1 1 1 2 4 2 12 21          
  • 38. 38 Question 40 We will show it is true for a pile of k stones, and show it is true for k+1 stones  So P(k) means that it is true for k stones Base case: n = 1  No splits necessary, so the sum of the products = 0  1*(1-1)/2 = 0  Base case proven
  • 39. 39 Question 40 Inductive hypothesis: assume that P(1), P(2), …, P(k) are all true  This is strong induction! Inductive step: Show that P(k+1) is true  We assume that we split the k+1 pile into a pile of i stones and a pile of k+1-i stones  Thus, we want to show that (i)*(k+1-i) + P(i) + P(k+1-i) = P(k+1)  Since 0 < i < k+1, both i and k+1-i are between 1 and k, inclusive
  • 40. 40 Question 40 k k k k    2 2 k k i i ki k k i i i i ki            2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 k k i i ki k k i i i i ki            ) 1 P( ) 1 P( ) P( ) 1 ( * ) (         k i k i i k i 2 2 ) 1 1 )( 1 ( ) 1 P( 2 k k k k k        2 2 2 ) 1 1 )( 1 ( ) 1 P( 2 2 i i ki k k i k i k i k              2 ) P( 2 i i i   Thus, we want to show that (i)*(k+1-i) + P(i) + P(k+1-i) = P(k+1)
  • 41. 41 Quick survey  I felt I understood the material in this slide set… a) Very well b) With some review, I’ll be good c) Not really d) Not at all
  • 42. 42 Quick survey  The pace of the lecture for this slide set was… a) Fast b) About right c) A little slow d) Too slow
  • 43. 43 Quick survey  How interesting was the material in this slide set? Be honest! a) Wow! That was SOOOOOO cool! b) Somewhat interesting c) Rather borting d) Zzzzzzzzzzz