10.07.2015 Views

Exam 2: Logic, Deduction, and Lambda Calculus: Answer Key

Exam 2: Logic, Deduction, and Lambda Calculus: Answer Key

Exam 2: Logic, Deduction, and Lambda Calculus: Answer Key

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Exam</strong> 2: <strong>Logic</strong>, <strong>Deduction</strong>, <strong>and</strong> <strong>Lambda</strong> <strong>Calculus</strong>:<strong>Answer</strong> <strong>Key</strong>COGS Q250, Fall 201111 November 2011Instructions:On the following pages you will find questions related to the topics we covered in class. Pleaseanswer each question completely, <strong>and</strong> show all of your work. Partial credit will be awarded as Ideem appropriate, <strong>and</strong> the more work you show the easier it will be for me to decide whether ornot to give you any partial credit.Please read the directions carefully. If you have any questions, you may raise your h<strong>and</strong> <strong>and</strong> Iwill come talk to you. I may not be able to answer all questions, depending on the problem. I willnot tell you if your work is correct — that is for you to check.Unless otherwise specified, each problem is worth 5 points. And unless otherwise specifiedthe proofs should be given as natural deduction or Fitch-style proofs. For either proof style, besure to do it properly. That is, give the reasons for each step, <strong>and</strong> for Fitch-style proofs be sure todraw the spine, give each line a number, <strong>and</strong> give the line numbers for each premise required forthe rule used.After you are done please h<strong>and</strong> in all pages of the exam. With the exception of the h<strong>and</strong>outcontaining a synopsis of the basic rules, this is closed book, closed notes test. No calculators, cellphones, PDAs or laptops allowed during the test. Cheating will not be tolerated. Anyone caughtcheating will receive an automatic F on the exam.Good Luck!Student name:Signature:11 November 2011 1 of 9


<strong>Exam</strong> 2: <strong>Logic</strong>, <strong>Deduction</strong>, <strong>and</strong> <strong>Lambda</strong> <strong>Calculus</strong> COGS Q250, Fall 20111Fill in the following truth tables <strong>and</strong> state whether the final column is a tautology, contingency, orcontradiction.1.1Contingencyp q ¬(p∧ p) ¬(q∧q) ¬(p∧ p)∧¬(q∧q) ¬(¬(p∧ p)∧¬(q∧q))⊤ ⊤ ⊥ ⊥ ⊥ ⊤⊤ ⊥ ⊥ ⊤ ⊥ ⊤⊥ ⊤ ⊤ ⊥ ⊥ ⊤⊥ ⊥ ⊤ ⊤ ⊤ ⊥1.2Tautologyp q ¬p∨q p⇒q (¬p∨q)⇒(p⇒q) (p⇒q)⇒(¬p∨q) (p⇒q)⇔(¬p∨q)⊤ ⊤ ⊤ ⊤ ⊤ ⊤ ⊤⊤ ⊥ ⊥ ⊥ ⊤ ⊤ ⊤⊥ ⊤ ⊤ ⊤ ⊤ ⊤ ⊤⊥ ⊥ ⊤ ⊤ ⊤ ⊤ ⊤1.3Tautologyp q p⊻q ¬(p⊻q) p⇔q ¬(p⇔q) ¬(p⇔q)⊻¬(p⊻q)⊤ ⊤ ⊥ ⊤ ⊤ ⊥ ⊤⊤ ⊥ ⊤ ⊥ ⊥ ⊤ ⊤⊥ ⊤ ⊤ ⊥ ⊥ ⊤ ⊤⊥ ⊥ ⊥ ⊤ ⊤ ⊥ ⊤2Prove that we only need one of the classical axioms to derive the other two, <strong>and</strong> that it doesn’tmatter which. We will do this in six parts. For each of the parts, you can only use the classical rulespecified.11 November 2011 2 of 9


<strong>Exam</strong> 2: <strong>Logic</strong>, <strong>Deduction</strong>, <strong>and</strong> <strong>Lambda</strong> <strong>Calculus</strong> COGS Q250, Fall 20112.1 Assuming ⊥ C , prove ¬¬ CThis one is easy. Given our premise¬¬A true, we just assume by way of contradiction that¬A true<strong>and</strong> then derive the contradiction.u ¬¬A true¬A true¬E⊥ trueA true⊥ u C2.2 Assuming ⊥ C , prove LEMFor this one we must prove⊢ A∨¬A, with no premises. So, in order to get anywhere, it’s clear thatwe’ll have to use the rules which allow local assumptions (⇒I, ¬I, etc.). Since we have access to⊥ C , we’ll have to assume the negation of our goal <strong>and</strong> try to derive a contradiction. De Morgan’slaws help to simplify this proof considerably.¬(A∨¬A) true u¬A∧¬¬A true DM¬A true¬(A∨¬A) true u¬A∧¬¬A true DM∧E L¬¬A true⊥ trueA∨¬A true∧E R¬E⊥ u C2.3 Assuming ¬¬ C , prove⊥ CIn order to give a derivation for ⊥ C we must take as a premise the derivation D of¬A⊢⊥.¬A true uD⊥ true¬¬A true ¬IuA true¬¬ C11 November 2011 3 of 9


<strong>Exam</strong> 2: <strong>Logic</strong>, <strong>Deduction</strong>, <strong>and</strong> <strong>Lambda</strong> <strong>Calculus</strong> COGS Q250, Fall 20112.4 Assuming ¬¬ C , prove LEMThe proof here is much like the other proof of LEM.¬(A∨¬A) true u¬A∧¬¬A true DM¬A true¬(A∨¬A) true u¬A∧¬¬A true DM¬¬A true∧E LA true⊥ true¬¬(A∨¬A) trueA∨¬A true∧E R¬¬ C¬E¬I u¬¬ C2.5 Assuming LEM, prove ⊥ CHere, the disjunctive syllogism helps shorten things considerably.¬A true uD⊥ true¬¬A true ¬IuA∨¬A true LEMA trueDS2.6 Assuming LEM, prove ¬¬ C¬¬A trueA∨¬A true LEMA trueDS3Prove the following theorems. Theorems marked with(†) require classical axioms.3.1 ¬A∨B⊢A⇒BA true u ¬A true v¬E⊥ true¬I¬¬A truev ¬A∨B trueDSB trueA⇒Btrue⇒I u11 November 2011 4 of 9


<strong>Exam</strong> 2: <strong>Logic</strong>, <strong>Deduction</strong>, <strong>and</strong> <strong>Lambda</strong> <strong>Calculus</strong> COGS Q250, Fall 20113.2 A⇒B⊢¬A∨B (†)A∨¬A true LEMA⇒BtrueA true u⇒EB true¬A∨B trueA⇒¬A∨B true¬A∨B true∨I R⇒I u¬A true v¬A∨B true ∨I L¬A⇒¬A∨B true ⇒Iv∨E3.3 ¬A⇒¬B⊢B⇒A (†)B true u ¬B true v¬E⊥ true¬I¬¬B truev ¬A⇒¬B trueMT¬¬A trueA trueB⇒Atrue¬¬ C⇒I u3.4 A⇒¬B⊢B⇒¬AB true u ¬B true v¬E⊥ true¬I¬¬B truev A⇒¬B trueMT¬A trueB⇒¬A true⇒I u3.5 ¬A⇒B⊢¬B⇒A (†)¬B true u ¬A⇒BtrueMT¬¬A trueA true¬B⇒Atrue¬¬ C⇒I u11 November 2011 5 of 9


<strong>Exam</strong> 2: <strong>Logic</strong>, <strong>Deduction</strong>, <strong>and</strong> <strong>Lambda</strong> <strong>Calculus</strong> COGS Q250, Fall 20114This one was quite a bit trickier than I recalled. The solutions are isomorphic for both subproblems,so you should be able to use one to help derive the other.4.1 Give a natural deduction proof of⊢¬¬(((A⇒B)⇒A)⇒A)First, we’ll give an inscrutably small ND-style proof.¬(((A⇒B)⇒A)⇒A) true x A true z((A⇒B)⇒A)⇒Atrue ⇒Iw¬E⊥ true⊥E(A⇒B)⇒Atrue y B true⇒I zA⇒Btrue⇒E¬(((A⇒B)⇒A)⇒A) true x A true⇒I y((A⇒B)⇒A)⇒Atrue¬E⊥ true¬I x¬¬(((A⇒B)⇒A)⇒A) trueOr, in Fitch-style we can use regular font size <strong>and</strong> still fit it on the page.12 ¬(((A⇒B)⇒A)⇒A) true Assumption3 (A⇒B)⇒Atrue Assumption4 A true Assumption5 (A⇒B)⇒Atrue Assumption6 A true 47 ((A⇒B)⇒A)⇒Atrue 5–6, ⇒I8 ⊥ true 2, 7, ¬E9 B true 8,⊥E10 A⇒Btrue 4–9, ⇒I11 A true 3, 10, ⇒E12 ((A⇒B)⇒A)⇒Atrue 3–11, ⇒I13 ⊥ true 2, 12, ¬E14 ¬¬(((A⇒B)⇒A)⇒A) true 2–13, ¬I11 November 2011 6 of 9


<strong>Exam</strong> 2: <strong>Logic</strong>, <strong>Deduction</strong>, <strong>and</strong> <strong>Lambda</strong> <strong>Calculus</strong> COGS Q250, Fall 20114.2 Give a λ-term of type((((A→B)→A)→A)→⊥)→⊥The λ-calculus version is far shorter than either of the above.λx. x(λy. y(λz. abort(x(λw. z))))To keep track of what’s going on, note that we have the following types:λx. x(λy. y(λz. abort(x(λw. z)))) : ((((A→B)→A)→A)→⊥)→⊥x : (((A→B)→A)→A)→⊥x(λy. y(λz. abort(x(λw. z)))) : ⊥λy. y(λz. abort(x(λw. z))) : ((A→B)→A)→Ay : (A→B)→Ay(λz. abort(x(λw. z))) : Aλz. abort(x(λw. z)) : A→Bz : Aabort(x(λw. z)) : Bx(λw. z) : ⊥λw. z : ((A→B)→A)→Aw : (A→B)→A5Consider the following data type <strong>and</strong> function definition.data Peano wherezero : Peanosucc : Peano→Peanoplus : Peano→Peano→Peanoplus zero y=yplus(succ x) y=succ(plus x y)Prove the following theorems for 10 points each. For these problems you should use caseanalysis <strong>and</strong> equational reasoning, as in homeworks 4 <strong>and</strong> 8.11 November 2011 7 of 9


<strong>Exam</strong> 2: <strong>Logic</strong>, <strong>Deduction</strong>, <strong>and</strong> <strong>Lambda</strong> <strong>Calculus</strong> COGS Q250, Fall 20115.1 Prove∀p:Peano.∀q:Peano. plus p q≡plus q pThis one is a lot longer than I remembered it being. First we’ll prove a couple lemmas. Since weonly use them each once, we could do these proofs inline, but it’s clearer if we break them out.Lemma 5.1.1. ∀p:Peano. plus p zero≡ pProof. Case p=zero:Case p=succ q:plus p zero=plus zero zerop=zero= zero definition of plus= p p=zeroplus p zero=plus(succ q) zerop=succ q= succ(plus q zero) definition of plus= succ q inductive hypothesis= p p=succ qLemma 5.1.2. ∀p:Peano. q:Peano. succ(plus p q)≡plus p(succ q)Proof. Case p=zero:Case p=succ r:succ(plus p q)=succ(plus zero q)p=zero= succ q definition of plus= plus zero(succ q) definition of plus= plus p(succ q) p=zerosucc(plus p q)=succ(plus(succ r) q)And now the main proof.p=succ r= succ(succ(plus r q)) definition of plus= succ(plus r(succ q)) inductive hypothesis= plus(succ r)(succ q) definition of plus= plus p(succ q) p=succ r11 November 2011 8 of 9


<strong>Exam</strong> 2: <strong>Logic</strong>, <strong>Deduction</strong>, <strong>and</strong> <strong>Lambda</strong> <strong>Calculus</strong> COGS Q250, Fall 2011Case p=zero:plus p q=plus zero qp=zero= q definition of plus= plus q zero lemma 5.1.1= plus q p p=zeroCase p=succ r:plus p q=plus(succ r) qp=succ r= succ(plus r q) definition of plus= succ(plus q r) inductive hypothesis= plus q(succ r) lemma 5.1.2= plus q p p=succ r5.2 Prove∀p:Peano.∀q:Peano.∀r:Peano. plus(plus p q) r≡ plus p(plus q r)Case p=zero:plus(plus p q) r=plus(plus zero q) rp=zero= plus q r definition of plus= plus zero(plus q r) definition of plus= plus p(plus q r) p=zeroCase p=succ t:plus(plus p q) r=plus(plus(succ t) q) rp=succ t= plus(succ(plus t q)) r definition of plus= succ(plus(plus t q) r) definition of plus= succ(plus t (plus q r)) inductive hypothesis= plus(succ t)(plus q r) definition of plus= plus p(plus q r) p=succ t11 November 2011 9 of 9

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!