Title: Mathematical Reasoning,Induction,and Recursion
1Chapter 3
- Mathematical Reasoning,Induction,and Recursion
23.1 PROOF STRATEGY
- FORWARD AND BACKWARD REASONING
- Example 3.1.1 Backward Reasoning
- Let a,b?R, with a?b. Then
- Proof Conclusion is true if
- which is true if (ab)2gt4ab,
- which is true if a22abb2gt4ab,
- which is true if a2-2abb2gt0,
- which is true if (a-b)2gt0,which is true.
3- Example 3.1.2Foreward Reasoning
- Let n ? N, such that n is not divisible by 2 or
3. - Then n2 - 1 is divisible by 24.
- Proof Since n is not divisible by 2 or 3,
- it follows that n 6k 1 or 6k 5.
- Case 1. (6k 1)2 - 1 ? 36k2 12k mod 24
- ? 12k2 12k ? 0 mod 24, since 2 divides k2 k.
- Case 2. (6k 5)2 - 1 ? 36k2 60k 24 mod 24
- ? 12k2 12k ? 0 mod 24, as above.
4TWO FAMOUS PROBLEMS
- Fermats Last ThmFor n gt 2, the equation
- anbncn
- has no solutions for non-zero integers a, b, c.
- Status Proved by Andrew Wiles.
- Goldbach Conjecture Every even number
- larger than 2 is the sum of two odd primes.
- Status Open.
53.2 SEQUENCES AND SUMMATIONS
- DEF A sequence in a set A is a function f
- from a subset of the integers (usually 0, 1, 2,
. . . or 1, 2, 3, . . .) to A. The values of a
sequence - are also called terms or entries.
- NOTATION The value f(n) is usually denoted an.
- A sequence is often written a0, a1, a2, . . ..
6- Example 3.2.1 Two sequences.
- Example 3.2.2 Five ubiquitous sequences.
7STRINGS
- DEF A set of characters is called an alphabet.
- Example 3.2.3 Some common alphabets
- 0, 1 the binary alphabet
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 the decimal digits
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,A,B, C,D,E, F
- the hexadecimal digits
- A,B,C,D, . . . , X,Y,Z English uppercase
- ASCII
8- DEF A string is a sequence in an alphabet.
- notation Usually a string is written without
- commas, so that consecutive characters are
juxtaposed. - Example 3.2.4 If f(0) M,f(1) A,
- f(2) T, and f(3) H, then write MATH.
9SPECIFYING a RULE
- Problem Given some initial terms a0, a1, ..., ak
- of a sequence, try to construct a rule that is
- consistent with those initial terms.
- Approaches There are two standard kinds of
- rule for calculating a generic term an.
- DEF A recursion for an is a function whose
- arguments are earlier terms in the sequence.
- DEF A closed form for an is a formula whose
- argument is the subscript n.
10- Example 3.2.5 1, 3, 5, 7, 9, 11, . . .
- recursion a0 1 an an-1 2 for n ? 1
- closed form an 2n 1
- The differences between consecutive terms
- often suggest a recursion. Finding a recursion is
- usually easier than finding a closed formula.
11- Example 3.2.6 1, 3, 7, 13, 21, 31, 43, . . .
- recursion b0 1 bn bn-1 2n for n ? 1
- closed form bn n2 n 1
- Sometimes, it is significantly harder to
construct - a closed formula.
12- Example 3.2.7 1, 1, 2, 3, 5, 8, 13, 21, 34, . .
. - recursion c0 1, c1 1
- cn cn-1 cn-2 for n ? 1
- closed form
- where and
13INFERRING a RULE
- The ESSENCE of science is inferring rules from
- partial data.
- Example 3.2.8 Sit under apple tree.
- Infer gravity.
- Example 3.2.9 Watch starlight move 0.15
- arc-seconds in total eclipse. Infer relativity.
- Example 3.2.10 Observe biological species.
- Infer DNA.
14- Important life skill Given a di?cult general
- problem, start with special cases you can solve.
- Example 3.2.11 Find a recursion and a
- closed form for the arithmetic progression
- c, c d, c 2d, c 3d, . . .
- recursion a0 c an an-1 d
- closed form an c nd.
- Q How would you decide that a given sequence
- is an arithmetic progression?
- A Calculate di?erences betw consec terms.
15- DEF The di?erence sequence for a sequence
- an is the sequence an an - an-1 for n 1.
- Example 3.2.5 redux
- Analysis Since an is constant, the sequence is
- speci?ed by this recursion
- a0 1 an an-1 2 for n 1.
- Moreover, it has this closed form
- an a0 a1 a2 an
- a0 22 2 1 2n
16- If you dont get a constant sequence on the ?rst
- di?erence, then try reiterating.
- Revisit Example 1.7.6 1, 3, 7, 13, 21, 31, 43, .
. . - bn 1 3 7 13 21 31 43
- bn 2 4 6 8 10 12
- bn 2 2 2 2 2
- Analysis Since bn is constant, we have
- bn 2 2n
- Therefore,
-
17- Consolation Prize Without knowing about
- ?nite sums, you can still extend the sequence
- bn 1 3 7 13 21 31 43 57
- bn 2 4 6 8 10 12 14
- bn 2 2 2 2 2 2
18SUMMATIONS
- DEF Let an be a sequence. Then the big-sigma
- notation
- means the sum
- am am1 am2 an-1 an
- TERMINOLOGY j is the index of summation
- TERMINOLOGY m is the lower limit
- TERMINOLOGY n is the upper limit
- TERMINOLOGY aj is the summand
19- Theorem 3.2.1. These formulas for summing
- falling powers are provable by induction (see
- 3.3)
20- Example 3.2.12 True Love and Thm 3.2.1
- On the jth day ... True Love gave me
21- Corollary 3.2.2. High-powered look-ahead to
- formulas for summing jk j 0, 1, ..., n.
22POTLATCH RULES for CARDINALITY
- DEF nondominating cardinality Let A and
- B be sets. Then A ? B means that ? one-to-
- one function f A ? B.
- DEF Set A and B have equal cardinality
- (write A B) if ? bijection f A ? B,
which - obviously implies that A ? B and B ? A.
- DEF strictly dominating cardinality Let
- A and B be sets. Then A lt B means that
- A ? B and A ? B.
23- DEF The cardinality of a set A is n if
- A 1, 2, . . . , n and 0 if A ?. Such
cardi- - nalitiesare called finite. NOTATION A n.
- DEF The cardinality of N is ? (omega), or
- alternatively, N0(aleph null).
- def A set is countable if it is finite or ?.
- Remark N0 is the smallest in.nite cardinality.
- The real numbers have cardinality N1 (aleph
- one), which is larger than N0, for reasons to be
- given.
24INFINITE CARDINALITIES
- Proposition 3.2.3. There are as many even
- nonnegative numbers as non-negative numbers.
- Proof f(2n) n is a bijection.
- Theorem 3.2.4. There are as many positive
- integers as rational fractions.
- Proof
- Example 3.2.13
25- Theorem 3.2.5. (G. Cantor) There are more
- positive real numbers than positive integers.
- Semi-proof A putative bijection f Z ? R
- would generate a sequence in which each real
- number appears somewhere as an infinite decimal
- fraction, like this
- Let f(n)k be the kth digit of f(n), and let ? be
- the permutation 0 ? 9, 1 ? 0, . . . 9 ? 8. Then
- the infinite decimal fraction whose kth digit is
- ? (f(n)k) is not in the sequence. Therefore, the
- function f is not onto, and accordingly, not a
- bijection.
263.3 MATHEMATICAL INDUCTION
- From modus ponens
- p basis assertion
- p ? q conditional assertion
- q conclusion
- we can easily derive double modus ponens
- p0 basis assertion
- p0 ? p1 conditional assertion
- p1 ? p2 conditional assertion
- p2 conclusion
- We might also derive triple modus ponens,
- quadruple modus ponens, and so on. Thus, we
- have no trouble proving assertions about arbi-
- trarily large integers. For instance,
- The initial domino falls.
- If any of the first 999 dominoes falls,
- then so does its successor.
- Therefore, the first 1000 dominoes all fall
down.
27- The induction axiom for the integers may be
- characterized as
- THE GREAT LEAP TO INFINITY
- Given a countably infinite row of dominoes,
- suppose that
- (1) The initial domino falls.
- (2) If domino n, then so domino n 1.
- Conclusion All the dominoes all fall down.
28- Example 3.3.1 a proof by induction
- Calculate the sum of the first k odd numbers
- 1 3 5 (2k - 1)
- Practical Method for General Problem Solving.
- Special Case Deriving a Formula
- Step 1. Calculate the result for some small
cases. - Step 2. Guess a formula to match all those cases.
- Step 3. Verify your guess in the general case.
29- Step 1. examine small cases
- (empty sum) 0
- 1 1
- 1 3 4
- 1 3 5 9
- 1 3 5 7 16
- Step 2. It sure looks like 13...(2k-1) k2.
- Step 3. Try to prove this assertion by induction.
- (see next page for proof)
30- Basis Step. when k 0
- Ind Hyp. when k n
- Ind Step. Consider the case k n 1.
31- Why is induction important to CS majors?
- It is the method used to prove that a loop or a
- recursively defined function correctly calculates
- the intended result. (just for a start)
32- Example 3.3.2 another proof by induction
- Calculate the sum of the first k numbers
- 1 2 3 k
- Step 1. examine small cases
- (empty sum) 0 0 1/2
- 1 1 1 2/2
- 1 2 3 2 3/2
- 1 2 3 6 3 4/2
- 1 2 3 4 10 4 5/2
- Step 2. Infer pattern
- Step 3. Use induction proof to verify pattern.
- See next page.
33- Proposition 3.3.1.
- Basis Step. when k 0.
- Ind Hyp. when k n.
- Ind. Step.
34NONALGEBRAIC APPLICATIONS of INDUCTION
- Consider tiling a 2k-by-2k chessboard.
- (k 3 in the figure below)
- with L-shaped tiles, so that one corner-square is
- left uncovered.
- Basis Step. You can do this when k 0.
- Ind Hyp. Assume you can do this for k n.
- Ind. Step. Prove you can do it for k n1.
35ALTERNATIVE FORMS of INDUCTION
- In a proof by induction, verifying the inductive
- premise means you show that the antecedent of
- the quantified statement implies the conclusion.
- DEF In a proof by mathematical induction, the
- inductive hypothesis is the antecedent of the
- inductive premise.
36- Standard 0-based inductive rule of inference
- 0 ? S basis premise
- (?n)n ? 0 ? n ? S ? n 1 ? S ind prem____
- (?n)n ? 0 ? n ? S conclusion
- Alternative Form 1. Using an integer other than
- zero as a basis.
- b ? S basis premise
- (?n)n ? b ? n ? S ? n 1 ? S ind prem____
- (?n)n ? b ? n ? S conclusion
37- Example 3.3.3 using 5 as the basis
- n2 gt 2n 1 for all n ? 5
- Basis Step. 52 gt 2 5 1
- Ind Hyp. Assume k2 gt 2k 1 for k ? 5.
- Ind. Step.
- (k 1)2 k2 2k 1 by arithmetic
- gt (2k 1) 2k 1 by ind hyp
- 4k 2 by
arithmetic - 2(k 1) 2k by
arithmetic - ? 2(k 1) 10 since k ?
5 - ? 2(k 1) 1 since 10
? 1
38- Example 3.3.4 2n gt n2 for all n ? 5.
- Basis Step. 25 gt 52
- Ind Hyp. Assume 2k gt k2 for k ? 5
- Ind. Step.
- 2k1 2 2k arithmetic
- 2k 2k arithmetic
- gt k2 k2 ind. hyp.
- gt k2 (2k 1) by Example 3.3.3
- (k 1)2 arithmetic
39- Example 3.3.5 Prove that any postage of
- 8 cents or more can be created from nothing but
- 3-cent and 5-cent stamps.
- Basis Step. 8 1 3 1 5
- Ind Hyp. Assume n possible from 3s and 5s.
- Ind. Step. Try to make (n 1) postage.
- Suppose that n r 3 s
- Case 1 s ? 1. Then n 1 . . .
- Case 2 s 0. Then n 1 . . .
40- Alternative Form 2. Inductive hyposthesis is that
- the first n dominoes all fall down.
- b ? S basis premise
- (?n)n ? b ? (? k ? n)k ? S ? n 1 ? S ind p
- (?n)n ? b ? n ? S conclusion
41- Example 3.3.6 Prove that every integer n gt 0
- is the product of finitely many primes.
- Basis Step. 1 is the empty product.
- Ind Hyp. Assume that 1, . . . , n are each a
prod- - uct of finitely many primes.
- Ind Step.
- (1) Either n 1 is prime, or ?b, c ? Z such that
- n 1 bc. (law of excl middle, def of prime)
- (2) But b and c are the products of finitely many
- primes. (by Ind Hyp)
- (3) Thus, so is bc.
42Mind-Benders re Induction
- 1. 2/3 ancestry
- 2. All solid billiard balls are the same color.
- 3. Everyone is essentially bald.
433.4 RECURSIVE DEFINITIONS
- Functions can be defined recursively. The
- simplest form of recursive definition of a
- function f on the natural numbers speci.es a
- basis rule
- (B) the value f(0)
- and a recursion rule
- (R) how to obtain f(n) from f(n - 1), ?n ? 1
44- Example 3.4.1 n-factorial n!
- (B) 0! 1
- (R) (n 1)! (n 1) n!
- However, recursive de.nitions often take some-
- What more general forms.
45- Example 3.4.2 mergesort (A1 . . . 2n real)
- if n 0
- return(A)
- otherwise
- return(merge (msort(1st half), msort(2nd
half)))
46- Since a sequence is defined to be a special kind
- of a function, some sequences can be specified
- recursively.
- Example 3.4.3 Hanoi sequence
- 0, 1, 3, 7, 15, 31, . . .
- h0 0
- hn 2hn-1 1 for n ? 1
- Example 3.4.4 Fibonacci seq
- 1, 1, 2, 3, 5, 8, 13, . . .
- f0 1
- f1 1
- fn fn-1 fn-2 for n ? 2
47- Example 3.4.5 partial sums of sequences
- Example 3.4.6 Catalan sequence
- 1, 1, 2, 5, 14, 42, . . .
- c0 1
- cn c0cn-1 c1cn-2 cn-1c0 for n ? 1
48RECURSIVE DEFINITION of SETS
- DEF A recursive definition of a set S com-
- prises the following
- (B) a basis clause that specifies a set of
- primitive elements
- (R) a recursive clause that specifies how ele-
- ments of the set may be constructed from ele-
- ments already known to be in set S there may
- be several recursive subclauses
- (E) an implicit exclusion clause that anything
- not in the set as a result of the basis clause or
- the recursive clause is not in set S.
49- Backus Normal Form (BNF) is an example of
- a context-free grammar that is useful for giving
- resursive definitions of sets. In W3261, you will
- learn that context-free languages are
recognizable - by pushdown automata.
50- Example 3.4.7 a rec. def. set of integers
- (B) 7, 10 ? S
- (R) if r ? S then r 7, r 10 ? S
- This reminds us of the postage stamp problem.
- Claim (?n ? 54)n ? S
- Basis 54 2 7 4 10
- Ind Hyp Assume n r 7 s 10 with n ? 54.
- Ind Step Two cases.
- Case 1 r ? 7. Then n1 (r-7)7(s5)10.
- Case 2 r lt 7 ? r 7 ? 42 ? s ? 2.
- Then n 1 (r 3) 7 (s . 2) 10.
- In computer science, we often use recursive
- definitions of sets of strings.
51RECURSIVE DEFINITION of STRINGS
- NOTATION The set of all strings in the alphabet
- ? is generally denoted ?
- Example 3.4.8 0, 1 denotes the set of all
- binary strings.
52- DEF string in an alphabet ?
- (B) (empty string) ? is a string
- (R) If s is a string and b ? ?, then sb is a
string. - Railroad Normal Form for strings
- Example 3.4.9 BNF for strings
- ltstringgt ? ltstringgtltcharactergt
53RECURSIVE DEFINITION of IDENTIFIERS
- DEF An identifier is (for some programming
- languages) either
- (B) a letter, or
- (R) an identifier followed by a digit or a
letter.
54- Example 3.4.10 BNF for identifiers
- ltlowercase_lettergt a b z
- ltuppercase_lettergt A B Z
- ltlettergtltlowercase_lettergtltuppercase_lettergt
- ltdigitgt 0 1 9
- ltidentifiergt ltlettergt ltidentifiergtltlettergt
- ltidentifiergtltdigitgt
55ARITHMETIC EXPRESSIONS
- DEF arithmetic expressions
- (B) A numeral is an arithmetic expression.
- (R) If e1 and e2 are arithmetic expressions, then
- all of the following are arithmetic expressions
- e1 e2, e1 - e2, e1 e2, e1/e2, e1 e2, (e1)
56- Example 3.4.11 Backus Normal Form
- ltexpressiongt ltnumeralgt
- ltexpressiongt ltexpressiongt
- ltexpressiongt - ltexpressiongt
- ltexpressiongt ltexpressiongt
- ltexpressiongt / ltexpressiongt
- ltexpressiongt ltexpressiongt
- (ltexpressiongt)
57SUBCLASSES of STRINGS
- Example 3.4.12 binary strings of even length
- (B) ? ? S
- (R) If b ? S, then b00, b01, b10, b11 ? S.
- Example 3.4.13 binary strings of even length
- that start with 1
- (B) 10, 11 ? S
- (R) If b ? S, then b00, b01, b10, b11 ? S.
58- DEF A strict palindrome is a character string
- that is identical to its reverse. (In natural
lan- - guage,blanks and other punctuation are ignored,
- as is the distinction between upper and lower
- case letters.)
- Able was I ere I saw Elba.
- Madam, Im Adam.
- Eve.
- Example 3.4.14 set of binary palindromes
- (B) ?, 0, 1 ? S
- (R) If x ? S then 0x0, 1x1 ? S.
59LOGICAL PROPOSITIONS
- DEF propositional forms
- (B) p, q, r, s, t, u, v,w are propositional forms
- (R) If x and y are propositional forms, then so
- are ?x, x ? y, x ? y, x ? y, x ? y and (x).
- Propositional forms under basis clause (B) are
- called atomic.
- Remark Recursive definition of a set
- facilitates proofs by induction about properties
- of its elements.
60- Proposition 3.4.1. Every proposition has an
- even number of parentheses.
- Proof by induction on the length of the
- derivation of a proposition.
- Basis Step. All the atomic propositions have
- evenly many parentheses.
- Ind Step. Assume that propositions x and y have
- evenly many parentheses. Then so do proposi-
- tions ?x, x ? y, x ? y, x ? y, x ? y and (x).
61CIRCULAR DEFINITIONS
- DEF A would-be recursive definition is
- circular if the sequence of iterated
- applications it generates fails to terminate in
- applications to elements of the basis set.
- Example 3.4.15 a circular de.nition from
- Index and Glossary of Knuth, Vol 1.
- Circular Definition, 260
- see Definition, circular
- Definition, circular,
- see Circular definition
623.5 RECURSIVE ALGORITHMS
- REVIEW An algorithm is a computational
- representation of a function.
- Remark Although it is often easier to write a
- correct recursive algorithm for a function,
- iterative implementations typically run faster,
- because they avoid calling the stack.
63RECURSIVELY DEFINED ARITHMETIC
- Example 3.5.1 recursive addition of natural
- numbers succ successor, pred predecessor.
64- Example 3.5.2 iterative addition of natural
- numbers
65- Example 3.5.3 proper subtraction of natural
- numbers succ successor, pred predecessor.
66- Example 3.5.4 natural multiplication
67- Example 3.5.5 factorial function
NOTATION Hereafter, we mostly use the
infix notations , -, , and ! to mean the
functions sum, diff, prod, and factorial,
respectively.
68RECURSIVELY DEFINED RELATIONS
- DEF The (Iverson) truth function true
- assigns to an assertion the boolean value TRUE
- if true and FALSE otherwise.
69- Example 3.5.6 order relation
- Time-Complexity ?(min(m, n)).
70OTHER RECURSIVELY DEFINED FUNCTIONS
- REVIEW Euclidean algorithm
Time-Complexity O(ln n). Example 3.5.7
Iterative calc of gcd (289, 255) m1 289 n1
255 r1 34 m2 255 n2 34 r2
17 m3 34 n3 17 r3 0
71- DEF The execution of a function exhibits
- exponential recursive descent if a call at one
- level can generate multiple calls at the next
level. - Example 3.5.8 Fibonacci function
- f0 1, f1 1, fn fn-1 fn-2 for n ? 2
- 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, . . .
- Time-Complexity ?(((1?5)/2)n)
72 73RECURSIVE STRING OPERATIONS
- ? set, c ? ? (object), s ? ? (string)
- ? 0 ? ? strings of length 0
- ? n ? n-1 ? ? strings of length n
- ? ? 1 ? ? 2 ? all finite non-empty
strings - ? ? 0 ? ? 1 ? ? 2 ? all finite strings
- These three primitive string functions are all
- defined and implemented nonrecursively for arbi-
- trary sequences, not just strings of characters.
74- DEF appending a character to a string
- append ? ? ? ? ? . non-recursive
- (a1a2 an, c) ? a1a2 an c
- DEF first character of a non-empty string
- first ? ? ? non-recursive
- a1a2 an ? a1
- DEF trailer of a non-empty string
- trailer ? n ? ? n-1
- a1a2 an ? a2 an
75- These four secondary string functions are all
- defined and implemented recursively.
- DEF length of a string
- length ? ? N
- length(s) 0 if s ?
- 1 length(trailer(s)) if s ? ?
- DEF concatenation of two strings
- concat ? ? ? ? ?
- (s ? t) s if t ?
- append(s,first(t)) ? trailer(t) if s
? ? - NOTATION It is customary to overload the
- concatenation operator ? so that it also
appends.
76- DEF reversing a string
- reverse ? ? ?
- s-1 s if s ?
- trailer(s) -1 ? first(s) if s ? ?
- DEF last character of a non-empty string
- last ? ? ?
- last(s) first(s-1)
77RECURSIVE ARRAY OPERATIONS
78 Time-Complexity ?(log n).
79Time-Complexity ?(n).
80(No Transcript)
81(No Transcript)