CS 399: Constructive Logic Final Exam (Sample Solution) Name Instructions
Transcription
CS 399: Constructive Logic Final Exam (Sample Solution) Name Instructions
CS 399: Constructive Logic Final Exam (Sample Solution) May 6, 2004 Name Name: Andrew ID: Instructions • This is an open-book, open-notes examination. You have 3 hours to complete this examination. • There are 20 pages in this examination, including two worksheets. • This examination consists of 6 questions worth a total of 100 points • Write your answers legibly in the space provided on the examination sheet. If you use the back of a sheet, indicate clearly that you have done so on the front. • Write your name and Andrew id on this page and on the top of each successive page in the space provided. Grading Ques. 1 2 3 4 5 6 EC Total 20 16 16 16 16 16 10 110 Score Max 1 Short answers [20 pts] 1. Proof Terms: Give a proof term corresponding to the following proposition (A ∧ B ⊃ C) ⊃ ((D ⊃ B) ⊃ (A ∧ D ⊃ C)). Solution: λu : (A∧B ⊃ C). λv : (D ⊃ B). λx : (A∧D). u hfst(x), v snd(x)i 2. Derivability: Show that Perice’s law, ((P ⊃⊥) ⊃ P ) ⊃ P , is not derivable in Constructive Logic. Your proof must be in the form of a failed derivation tree. Solution: Suppose there was a normal proof of ((P ⊃⊥) ⊃ P ) ⊃ P in C.L. Then the last inference rule must be ⊃ I. So starting from the hypothesis ((P ⊃⊥) ⊃ P ) ↓ we need to derive a normal proof for P . The only way we can derive P ↑ is via P ↓. Further, the only way we can make use of the hypothesis is to use it in an ⊃ E rule. But then we need P ⊃⊥↑ under the hypothesis((P ⊃⊥) ⊃ P ) ↓. Clearly that is not possible in general because for P = >, the hypothesis is true but ¬P cannot be true. Hence we cannot derive P ↑ from (P ⊃⊥) ⊃ P ↓ 2 3. Reduction: Simplify the following proof term. Assume that r is of type C, q is of type B and y is of type A. (λu : A ∨ B ⊃ C. λv : D ⊃ B. λz : A ∨ D. case z of inl x1 =⇒ u inl x1 | inr x2 =⇒ u inr v x2 ) (λx : A ∨ B. r) (λx : D. q) (inl y) Solution: r 4. Classical Proof Terms: Give a proof term for the following De Morgan’s law ¬(A ∧ B) ⊃ ¬A ∨ ¬B The solution has to be of the form λx : ¬(A ∧ B). letcc u in . . . The missing part will involve two uses of throw. Solution: λx : ¬(A∧B). letcc u in throw inl(λy : A. throw ( inr(λz : B. xhy, zi)) to u) to u 3 5. Linear Logic: style) proof. Prove the following judgement. Give a linear (tutch (A&B), (A ⊕ B) ( C ° C. Solution: 1. (A&B) ° (A&B) 2.(A ⊕ B) ( C ° (A ⊕ B) ( C 3.A&B ° A 4.A&B ° A ⊕ B &E 1 ⊕I 5.(A&B), (A ⊕ B) ( C ° C. ( E2 4 4 Axiomatizing XOR [16 pts] (A) Suppose we want to add a connective, ¯, which roughly corresponds to an “exclusive or.” A¯B is provable exactly when either A or B is provable and the other is refutable. We could give a definition of ¯ in terms of other connectives as A ¯ B ≡ (A ∧ ¬B) ∨ (¬A ∧ B). But, we will give a direct definition for A ¯ B using intro and elim rules that capture the informal meaning described above. Given below is the elim rule for ¯. Fill in the intro rules without using the ∧ and ∨ connectives (you may use ¬). Intro (2 rules): Γ`A¯B ¯I1 Γ`A¯B ¯I2 Elim (1 rule): Γ ` A ¯ B Γ, A, ¬B ` C Γ`C Γ, ¬A, B ` C ¯E Solution : Γ ` A Γ ` ¬B ¯I1 Γ`A¯B Γ ` ¬A Γ ` B ¯I2 Γ`A¯B 5 (B) Using the rules for constructive logic given in the notes, plus the rules you defined in question 1, prove the following (you can complete this question and the next even if you answered question 1 incorrectly). ((A ¯ B) ∧ A) ⊃ ¬B Solution : Let Γ = (A ¯ B) ∧ A. .. .. .. .. Γ, B, A, ¬B ` ⊥ Γ, B, ¬A, B ` ⊥ ¯E Γ, B ` ⊥ ⊃I Γ ` ¬B ⊃I · ` (A ¯ B) ∧ A ⊃ ¬B Hyp Γ, B ` Γ ∧EL Γ, B ` A ¯ B Hyp Hyp Γ, B, A, ¬B ` B Γ, B, A, ¬B ` ¬B ¬E Γ, B, A, ¬B ` ⊥ Hyp Γ, B, ¬A, B ` (A ¯ B) ∧ A ∧ER Γ, B, ¬A, B ` ¬A Γ, B, ¬A, B ` A ¬E Γ, B, ¬A, B ` ⊥ Hyp (C) Prove A ¯ A ⊃ ⊥ Solution: Let Γ = (A ¯ A). 6 Γ`A¯A Hyp A ¬A Hyp Hyp Γ, A, ¬A ` Γ, A, ¬A ` ¬E Γ, A, ¬A ` ⊥ Γ`⊥ ⊃I ·`A¯A⊃⊥ 7 A ¬A Hyp Hyp Γ, ¬A, A ` Γ, ¬A, A ` Γ, ¬A, A ` ⊥ ¯E Disequality and Unequality[16 pts] We want to define a new predicate 6= over nat. This new predicate must model the usual disequality relation over natural numbers. The formation rule for the predicate is: Γ ` n ∈ nat Γ ` m ∈ nat 6= F Γ ` n 6= m The predicate is defined by the following rules (given with annotation): Γ ` n ∈ nat 6= I0s Γ ` neI0s : 0 6= s(n) Γ ` n ∈ nat 6= Is0 Γ ` neIs0 : s(n) 6= 0 Γ ` M : n 6= m 6= Is Γ ` neIs (M ) : s(n) 6= s(m) Γ ` M : 0 6= 0 6= E0 Γ ` neE0 (M ) : C Γ ` M : s(n) 6= s(m) 6= Es Γ ` neEs (M ) : n 6= m (A) We will now prove that the predicate determined by the five rules is a symmetric. Show by induction on x and y that ∀x ∈ nat.∀y ∈ nat. x 6= y ⊃ y 6= x. Give your proof using proof terms. λx ∈ nat. rec x of f (0) ⇒ λy ∈ nat. | f (s(x0 )) ⇒ λy ∈ nat. 8 Solution: The proof term is as follows: λx ∈ nat . rec x of f (0) ⇒ λy ∈ nat . rec y of g(0) ⇒ λu : ( 0 6= 0 ). neE0 (u) | g(s(y 0 )) ⇒ λu : ( 0 6= s(y 0 )). neIs0 0 | f (s(x )) ⇒ λy ∈ nat . rec y of g(0) ⇒ λu : (s(x0 ) 6= 0 ). neI0s | g(s(y 0 )) ⇒ λu : (s(x0 ) 6= s(y 0 )). neIs (f (neEs (u))) 9 Unequality: We will say x and y are unequal if ¬(x =N y). In the next two problems you will show that x 6= y if and only if x and y are unequal. The proof terms for =N are given on page 57 of the Pfenning notes. (B) Prove that ∀x ∈ nat. ∀y ∈ nat.¬(x =N y) ⊃ x 6= y. Give your proof using proof terms. Solution: The proof term is as follows: λx ∈ nat . rec x of f (0) ⇒ λy ∈ nat . rec y of g(0) ⇒ λu : ¬( 0 =N 0) . abort(u eq0 ) | g(s(y 0 )) ⇒ λu : ¬(0 =N s(y 0 )) . neI0s 0 | f (s(x ) ⇒ λy ∈ nat . rec y of g(0) ⇒ λu : ¬(s(x0 ) =N 0) . neIs0 | g(s(y 0 )) ⇒ λu : ¬(s(x0 ) =N s(y 0 )) . neI s (f (λv : (x0 = y 0 ). u( eqs v))) (C) Prove that ∀x ∈ nat. ∀y ∈ nat. x 6= y ⊃ ¬(x =N y) . Give your proof using proof terms. Solution: The proof term is as follows: λx ∈ nat . rec x of f (0) ⇒ λy ∈ nat . rec y of g(0) ⇒ λu : ( 0 6= 0). neI0 (u) | g(s(y 0 )) ⇒ λu : 0 = s(y 0 ). abort(u) 0 | f (s(x ) ⇒ λy ∈ nat . rec y of g(0) ⇒ λu : s(y 0 ) = 0 . abort(u) | g(s(y 0 )) ⇒ λu : s(x0 ) = s(y 0 ). f ( neI s (u))eqEs (x) 10 List Recursion and Erasure [16 pts] We want to write a function, index, that takes a τ list and a nat i and returns the nth element in the list. The head of the list is considered the element number 0. To get the implementation right we must have the condition that i is less than the length of the τ list. We can include this information by passing to the function the length of the τ list and a proof that i is less than the length. This suggests the following type for index : Π n ∈ nat . τ list(n) → Π i ∈ nat . (i <N n) → τ (1) The function index can be defined by induction on the list argument alone and the length argument n is immaterial to the computation. (A) We will bracket out the length information and the proof that i is within the limits. The bracketed type is then: Π [n ∈ nat ]. τ list([n]) → Π i ∈ nat . [(i <N n)] → τ (2). Complete the well bracketed implementation of the function index below. The bracketing must be consistent with the bracketing shown in (2). index = λ[n]. λ l ∈ τ list ([n]). rec l of f ([0], nil) ⇒ | f ([s(n0 )], h :: t) ⇒ Solution: λ[n]. 11 λ l ∈ τ list [(n)]. rec l of f ([0], nil) ⇒ λi ∈ nat. λ[u] : [(i <N 0)]. abort([ltE0 u]) | f ([s(n0 )], h :: t) ⇒ λi ∈ nat . rec i of g( 0 ⇒ λ[u] : [(i <N 0)]. h g(s(i0 )) ⇒ λ[u] : [(s(i0 ) <N s(n0 ))]. f (t)(i0 )([less(u)]) (B) The optimized function will be of the type τ list → nat → τ (3) Optimize the bracketed implementation of function index that you defined above. Solution: λ l ∈ τ list . rec l of f (nil) ⇒ λi ∈ nat. abortτ | f (h :: t) ⇒ λi ∈ nat . rec i of g( 0 ⇒ h g(s(i0 )) ⇒ f (t)(i0 ) 12 Substructural Logics [16 pts] We arrived at linear logic by requiring that each hypothesis be used exactly once. If we relax this restriction and say that each hypothesis must be used at most once, we obtain what is called affine logic. The hypothesis rules become: Γ; ∆, A ` A Lin Hyp Γ, A; ∆ ` A Hyp In linear logic, we had two notions of truth: >, which could be proven from any assumptions and 1, which had to be proven in the empty context. In affine logic, since we do not have to use all our assumptions, we only have one notion of truth. The rule for this is: Γ; ∆ ` > T −I All the other rules are the same as in linear logic (in particular, there are still two types of conjunction). Now, suppose we want to give an encoding of affine logic into linear logic. We will write A◦ for the translation of the affine proposition A into a linear logic proposition. The statement of adequacy for this encoding will be Γ; ∆ ` A if and only if Γ; ∆∗ ° A◦ & 1 where if ∆ = u1 : A1 , u2 : A2 , . . . , un : An then ∆∗ = u1 : A◦1 & 1, u2 : A◦2 & 1, . . . , un : A◦n & 1. The encoding we will use is: (A ⊕ B)◦ (A ⊗ B)◦ = = (A◦ & 1) ⊕ (B ◦ & 1) (A◦ & 1) ⊗ (B ◦ & 1) (A & B)◦ (A ( B)◦ = = (A◦ & 1) & (B ◦ & 1) (A◦ & 1) ( (B ◦ & 1) P◦ >◦ = P &1 = > (where P is an atomic proposition) We now ask you to show three cases of the proof of adequacy in the forward direction. That is, we will show three cases of the proof that if Γ; ∆ ` A then Γ; ∆∗ ° A◦ & 1. You may assume the truth of the following lemma: Γ; ∆∗ ° 1 That is, we can always use up the resources in ∆∗ . Question 1. Case ⊗I. Γ; ∆1 ` A Γ; ∆2 ` B ⊗IA Γ; ∆1 , ∆2 ` A ⊗ B 13 (1) Given the following inductive hypotheses Γ; ∆∗1 ° A◦ & 1 Γ; ∆∗2 ° B ◦ & 1 Show Γ; ∆∗1 , ∆∗2 ° (A ⊗ B)◦ & 1 Solution: I.H. I.H. Γ; ∆∗1 ° A◦ & 1 Γ; ∆∗2 ° B ◦ & 1 ⊗O Γ; ∆∗1 , ∆∗2 ° 1 Γ; ∆∗1 , ∆∗2 ° (A◦ & 1) ⊗ (B ◦ & 1) &I Γ; ∆∗1 , ∆∗2 ° ((A◦ & 1) ⊗ (B ◦ & 1)) & 1 ◦ def of A Γ; ∆∗1 , ∆∗2 ° (A ⊗ B)◦ & 1 Lemma Question 2. Case ( E Γ; ∆1 ` A ( B Γ; ∆2 ` A (E Γ; ∆1 , ∆2 ` B 2(a). What are the inductive hypotheses in this case? 14 Solution: Γ; ∆∗1 ° (A ( B)◦ & 1 and Γ; ∆∗2 ° A◦ & 1 15 2(b). Show that Γ; ∆∗1 , ∆∗2 ° B ◦ & 1 follows from the I.H. Solution: I.H. Γ; ∆∗1 ° (A ( B)◦ & 1 def of A◦ Γ; ∆∗1 ° ((A◦ & 1) ( (B ◦ & 1)) & 1 & EL Γ; ∆∗1 ° (A◦ & 1) ( (B ◦ & 1) Γ; ∆∗1 , ∆∗2 ° B & 1 Question 3. Case linear hypothesis. Γ; ∆, A ` A LinHyp Show that Γ; ∆∗ , A∗ ° A◦ & 1. Solution: LinHyp Γ; A∗ ° A∗ def. of A∗ Γ; ∆∗ ° 1 Γ; A∗ ° A◦ & 1 1−E Γ; ∆∗ , A∗ ° A◦ & 1 Lemma(1) 16 Γ; ∆∗2 ° A◦ & 1 I.H. (E Question 4. We now consider the proof of the lemma we used in the previous question: Γ; ∆∗ ° 1 We will prove this by induction on the structure of ∆. Since ∆ is a list, we must show two cases. The base case is · ° 1, which is easy. We ask you to show the inductive case. Case: ∆ = ∆1 , A Given Γ; ∆∗1 ° 1 show that Γ; ∆∗1 , A∗ ° 1 Solution: Hyp Γ; A & 1 ° A & 1 & ER Γ; A & 1 ° 1 I.H. def of A∗ Γ; A∗ ° 1 Γ; ∆∗1 ° 1 1−E Γ; ∆∗1 , A∗ ° 1 Extra Credit. One might wonder if there is an encoding which is more efficient in the sense that the translated propositions are shorter. Consider the following encoding, which only adds “& 1” to the atomic propositions. (A ⊕ B)◦ ◦ = A◦ ⊕ B ◦ (A ⊗ B) (A & B)◦ = A◦ ⊗ B ◦ = A◦ & B ◦ (A ( B)◦ P◦ = A◦ ( B ◦ = P & 1 (where P is an atomic proposition) >◦ = > 17 The statement of adequacy will be the same Γ; ∆ ` A if and only if Γ; ∆∗ ° P ◦ & 1 The proof fails at the ( I step. Given ∆∗ , A∗ ° B ◦ & 1, we must show ∆∗ ° (A ( B)◦ & 1. Show this fails by showing that the normal proof below cannot be completed. I.H. Γ; ∆∗ , A∗ ° B ◦ & 1 ↓ .. Lemma (1) Γ; ∆∗ ° 1 ↓ .. ↓↑ Γ; ∆∗ ° 1 ↑ Γ; ∆∗ ° A◦ ( B ◦ ↑ &I Γ; ∆∗ ° (A◦ ( B ◦ ) & 1 ↑ ◦ def of A Γ; ∆∗ ° (A ( B)◦ & 1 ↑ Γ; ∆∗ , A∗ ↓ ° B ◦ & 1 ↓ Γ; ∆∗ ° A◦ ( B ◦ ↑ Solution: 18 I.H. I.H. Γ; ∆∗ , A∗ ↓ ° B ◦ & 1 ↓ def of A∗ Γ; ∆∗ , A◦ & 1 ↓ ° B ◦ & 1 & EL Γ; ∆∗ , A◦ & 1 ↓ ° B ◦ ↓ .. .. Γ; ∆∗ , A◦ ↓ ° B ◦ ↑ (I Γ; ∆∗ ° A◦ ( B ◦ ↑ From A◦ & 1 ↓, all we can conclude is Γ; ∆∗ , A◦ & 1 ↓ ° A◦ ↓ or Γ; ∆∗ , A◦ & 1 ↓ ° 1 ↓ neither of which gets us closer to proving Γ; ∆∗ , A◦ ↓ ° B ◦ ↑. 19 CPS Transform[16 pts] In the class notes, the correctness of the double negation translation is shown by the following theorem If Γ; ∆ ` M : P, then Γ◦ , ¬∆◦ ` M ∗ : ¬¬P ◦ for some term M ∗ This theorem was proved by induction on the structure of the proof term M . Some representative cases were worked out in the class notes. The next few problems ask you to give M ∗ for conjunction. Recall that (P1 ∧ P2 )◦ = P1◦ ∧ P2◦ . This translation corresponds to an eager interpretation of pairing in which the components of a pair are evaluated before the pair is formed. (A) Consider the case M = hL, N i in the above theorem. Since M is a pair, we know that P must have been derived via ∧ Introduction. So we know P = P1 ∧ P2 for some P1 and P2 . Further, by the induction hypothesis we have Γ◦ , ¬∆◦ ` L∗ : ¬¬P1◦ and Γ◦ , ¬∆◦ ` N ∗ : ¬¬P2◦ Given this information derive M ∗ . Keep in mind that M ∗ is a proof term for ¬¬P ◦ . Solution: M ∗ is λu : ¬(P1◦ ∧ P2◦ ).L∗ (λu1 : P ◦ . N ∗ (λu2 : P2◦ . uhu1 , u2 i)) 20 (B) Consider the case M = fst(N ), for some N . We know that N must be a pair and further there must a proposition Q such that N : P ∧ Q. By induction hypothesis, we have Γ◦ , ¬∆◦ ` N ∗ : ¬¬(P ∧ Q)◦ . That is, Γ◦ , ¬∆◦ ` N ∗ : ¬¬(P ◦ ∧ Q◦ ) With this information derive M ∗ such that it is of the type ¬¬P ◦ Solution: M ∗ = λu : ¬P ◦ . N ∗ .λv : (P ◦ ∧ Q◦ ). u fst(v) An alternative way of translating ∧ is (P1 ∧ P2 )◦ = ¬¬P1◦ ∧ ¬¬P2◦ . This translation corresponds to an lazy interpretation of pairing. That is, the components are not evaluated while forming the pair. The flip side is that the components have to be evaluated when taking projections. 21 (C) Consider problem (A) again under this new translation. If M is a pair hL, N i, what is M ∗ ? M ∗ must be of the type ¬¬(¬¬P1◦ ∧ ¬¬P2◦ ). You have the same inductive hypotheses as in problem (A). Solution: M ∗ = λu : ¬(¬¬P1◦ ∧ ¬¬P2◦ ). u hL∗ , N ∗ i (D) Under the new translation for ∧, if M = fst(N ) for some N : P ∧ Q, what is M ∗ ? By inductive hypothesis we have Γ◦ , ¬∆◦ ` N ∗ : ¬¬(P ∧ Q)◦ . That is, Γ◦ , ¬∆◦ ` N ∗ : ¬¬(¬¬P ◦ ∧ ¬¬Q◦ ) Keep in mind that M ∗ must be of the type ¬¬P ◦ . Solution: M ∗ = λu : ¬P ◦ . N ∗ .λv : (¬¬P ◦ ∧ ¬¬Q◦ ). fst(v) u 22