=========================================================================== CSC 236 Lecture Summary for Week 1 Fall 2007 =========================================================================== Course information sheet. ------------ Introduction ------------ Induction = Recursion Topics: - Induction (simple, complete, well-ordering, structural). Chapters 1, 4 [3 weeks] - Algorithm complexity and recurrence relations. Chapter 3 [2 weeks] - Algorithm correctness. Chapter 2 [2 weeks] - Regular languages, finite-state automata, and regular expressions. Chapter 7 [3 weeks] - Context-free languages, context-free grammars, and pushwon automata. Chapter 8 [3 weeks] Consider: a = 1/5 while true: print a a = (1 + a) / 2 - What does this print? - Trace: 1/5, 3/5, 4/5, 9/10, 19/20, ... (assume perfect arithmetic) - Conjectures? 1. every value < 1 2. values increasing 3. limit = 1 (outside scope of this course!) - Proofs? First, try to convince ourselves. 1. (a) 1/5 < 1 (b) if a < 1, then (1 + a) / 2 is average of 1 and a so < 1 (arithmetic: (1 + a) / 2 < (1 + 1) /2) (c) so it must be the case that a < 1 always -> This is a proof by induction! - Conjecture 2: Is it always the case that a < (1 + a) / 2? Yes: a < 1 -> (a + a) / 2 < (1 + a) / 2 More formally. - In math, variable = unknown but fixed quantity. In CS, variable = name of a memory location, whose content can change. - How to express mathematically (i.e., precisely) changing values of an algorithm's variable? - Convention: Let a_n represent value of a at the end of n complete iterations of the loop (i.e., just before loop test is evaluated for (n+1)st time); in particular, a_0 = value before loop starts. - Algorithm's computation simply evaluates the sequence: a_0 = 1/5 a_{n+1} = (1 + a_n) / 2 for all n in N - Conjectures can be written: [notation: \-/ = 'for all'] 1. \-/ n in N, a_n < 1 2. \-/ n in N, a_n < a_{n+1} - Notice: . sequence defined inductively/recursively; . conjecture 1 is about individual elements, and was proved using induction; . conjecture 2 is about consecutive elements, and was proved directly (making use of conjecture 1). - Symbolic proofs: Proof of Conjecture 1: . a_0 = 1/5 < 1. . Let n in N and suppose a_n < 1. Then, a_{n+1} = (1 + a_n) / 2 < (1 + 1) / 2 = 1. . So, because a_0 < 1 and \-/ n in N, a_n < 1 -> a_{n+1} < 1, we conclude \-/ n in N, a_n < 1 Principle of Simple Induction: For a predicate P(n), ( P(0) /\ \-/ n in N, P(n) -> P(n+1) ) -> \-/ n in N, P(n). Claim: This principle is "self-evident". We will never attempt to "prove" it; rather we will only make use of it. Making use of an implication A -> B? Prove A, then conclude B. In other words, in order to prove \-/ n in N, P(n) using induction, we prove instead P(0) /\ \-/ n in N, P(n) -> P(n+1). When making use of induction, we never directly prove \-/ n in N, P(n). ---------------------------------------------- Standard format for proofs by simple induction ---------------------------------------------- 0. Define precisely P(n), the statement for which we want to prove \-/ n in N, P(n). CAREFUL: We are not proving P(n), but \-/ n in N, P(n), so the statement P(n) should NOT contain any quantifier on variable n. 1. Base Case: Prove P(0). 2. Inductive Hypothesis (IH): Let n in N, and suppose P(n). 3. Inductive Step: Prove P(n+1). 4. Conclusion: By induction, \-/ n in N, P(n). Example 1: Prove that 12^n - 1 is divisible by 11 for all n in N. 0. P(n) = -] k in N, 12^n - 1 = 11 k [notation: -] = 'there exists'] 1. Base Case: P(0) = -] k in N, 12^0 - 1 = 11 k. But 12^0 - 1 = 1 - 1 = 0 = 11 * 0, so P(0) holds by picking k = 0. Formally, in the style of CSC 165: Let k = 0. Then k in N and 12^0 - 1 = 0 = 11 k. Hence, -] k in N, 12^0 - 1 = 11 k. (In this course, we use the first "shorthand" style rather than the detailed style from CSC 165.) 2. IH: Let n in N and suppose P(N), i.e., -] k in N, 12^n - 1 = 11 k. 3. Inductive Step: Need to prove -] k' in N, 12^{n+1} - 1 = 11 k'. However, 12^{n+1} - 1 = 12 * 12^n - 1 = 11 * 12^n + 12^n - 1 = 11 * 12^n + 11 k = 11 * (12^n + k) so P(n+1) holds by picking k' = 12^n + k. [NOTE: In class, we obtained a different expression for k' through different algebra; however, both expressions have the same value.] 4. Hence, by induction, \-/ n in N, P(n), i.e., 12^n - 1 is a multiple of 11 for all n in N. Example 2: Given an unlimited supply of 4c and 7c stamps, what amounts of postage can be made exactly? - Explore: Try amounts until pattern emerges. Impossible: 1c, 2c, 3c, 5c, 6c, 9c, 10c, 13c, 17c Possible: 4c, 7c, 8c, 11c, 12c, 14c, 15c, 16c, 18c, 19c, 20c, 21c, ... - Conjecture: Every amount of 18c or more can be made exactly. >> Think about how to define P(n) for this problem.