Lecture 15 Notes I explained that the Midterm 2 would be very much like Homework 8, except with fewer proofs. I presented the induction principle. See the notes for details, but the basic idea is: Induction: To prove psi, chose a variable z and some car/cdr substitutions sigma1, sigma2, ..., sigmak. Then prove the following two cases: Base Case: !(consp z) --> psi Induction Step: ((consp z) & psi/sigma1 & psi/sigma2 & ... psi/sigmak) --> psi If you prove both of those then you know psi holds for all possible values of the variables. Next I argued this was adequate for proving psi. Why does psi hold for (1 2 3 4)? According to the Induction Step, since (1 2 3 4) is a consp, psi holds for (1 2 3 4) if it holds for (2 3 4). According to the Induction Step, since (2 3 4) is a consp, psi holds for (2 3 4) if it holds for (3 4). According to the Induction Step, since (3 4) is a consp, psi holds for (3 4) if it holds for (4). According to the Induction Step, since (4) is a consp, psi holds for (4) if it holds for NIL. But according to the Base Case, psi holds for nil. Thus, psi holds for (4), and thus for (3 4), and thus for (2 3 4) and thuse for (1 2 3 4). Q.E.D. I just showed a way for using the Induction Step and the Base Case to prove that psi holds for any concrete list you pick. Next, I gave some advice on how to use induction: (1) Recognize that you need to use induction, by determining that you're dealing with a recursive function and you don't know how many times you have to expand it's definition to eliminate it. (2) Choose a variable and some sigmas. The variable is generally the one tested in the recursive functions in the conjecture. The sigmas are car/cdr substitutions on that variable and they replace the variable by whatever car/cdr nests the function recurses on. (3) THE STEP EVERYBODY FORGETS: Write down the Base Case and the Induction Step! (4) Just prove them, forgetting all about why you're proving them. Just use the techniques we've already studied to prove the Base Case and the Induction Step. Then I proved many examples, culminating with: (defun app (x y) (if (endp x) y (cons (car x) (app (cdr x) y)))) (defun tp (x) ; A short name for "true-listp". (if (endp x) (equal x nil) (tp (cdr x)))) Theorem: (tp x) --> (app x nil) = x. [Hmmm. I need induction. There's only one var, so I'll induct on x. sigma = {x <-- (cdr x)}. Below I have written down the Base Case and the Induction Step. I wrote them both down before I developed the proofs of the two formulas. That way, I wouldn't forget what I'm doing. After writing down the two subgoals, I developed the proofs of each. You see the proofs below.] Base Case: !(consp x) --> ((tp x) --> (app x nil) = x) <--> {promotion} (!(consp x) & (tp x)) --> (app x nil) = x <--> {def tp, and hyp 1} (!(consp x) & x=nil) --> (app x nil) = x <--> {hyp 2} (!(consp x) & x=nil) --> (app nil nil) = nil <--> {comp, equal reflexive, short circuit} t Ind. Step: [Because the formula is so big, I'm going to put a line of hyphens between each step.] ----------------------------------------------------------------- (consp x) & ((tp (cdr x)) --> (app (cdr x) nil) = (cdr x)) --> ((tp x) --> (app x nil) = x) ----------------------------------------------------------------- <--> {promotion} ----------------------------------------------------------------- (consp x) & ((tp (cdr x)) --> (app (cdr x) nil) = (cdr x)) & (tp x)) --> (app x nil) = x ----------------------------------------------------------------- <--> {def tp} ----------------------------------------------------------------- (consp x) & ((tp (cdr x)) --> (app (cdr x) nil) = (cdr x)) & (tp (cdr x)) --> (app x nil) = x ----------------------------------------------------------------- <--> {forward chain} ----------------------------------------------------------------- (consp x) & (app (cdr x) nil) = (cdr x) & (tp (cdr x)) --> (app x nil) = x) ----------------------------------------------------------------- <--> {def app, hyp 1} ----------------------------------------------------------------- (consp x) & (app (cdr x) nil) = (cdr x) & (tp (cdr x)) --> (cons (car x) (app (cdr x) nil)) = x ----------------------------------------------------------------- <--> {hyp 2} ----------------------------------------------------------------- (consp x) & (app (cdr x) nil) = (cdr x) & (tp (cdr x))) --> (cons (car x) (cdr x)) = x ----------------------------------------------------------------- <--> {cons-car-cdr} ----------------------------------------------------------------- (consp x) & (app (cdr x) nil) = (cdr x) & (tp (cdr x))) --> x = x ----------------------------------------------------------------- <--> {equal reflexive, short-circuit} ----------------------------------------------------------------- t ----------------------------------------------------------------- Q.E.D.