Docsity

Logic, Proofs, Set Theory, Algorithm - Midterm 2007 | ECS 020, Exams of Computer Science

Toggle sidebar
bg1
Midterm - on 11/08/2007
Part I: Logic
Exercise 1
We study : A= [¬(p∨q)∧ ¬(q∨p)↔(p∧q)]
p q p ∨q¬(p∨q)p∧q A
T T T F T F
T F T F F T
F T T F F T
F F F T F F
From column 6, we get that Ais not a tautology nor a contradiction.
Exercise 2
A and B are inhabitants of Smullyan islands, and A says ”If I am a knight, then B is a knave”,
while B says ”If I am a knave, then A is a knight”.
The answer is: The two propositions are contradictory: there is no answer.
We proceed as follows:
•We show first that A is a knight.
We use a proof by contradiction. We suppose that A is a knave. In this case, the proposition
”If I am a knight, then B is a knave” is false. Since this proposition is a conditional of the
form p→q, it is false when pis true and qis false. pis true means A is a knight. But this
contradicts A is a knave. So our hypothesis is false, and therefore A is a knight.
•We show that B is a knight.
Again we use a proof by contradiction. We suppose that B is a knave. In this case, the
proposition ”If I am a knave, then A is a knight” is false, i.e. B is a knave and A is a knave.
But we have shown that A is a knight, and therefore we have reached a contradiction, and B
is a knight.
•We show that B is a knave.
A is a knight, and therefore the proposition ”A is a knight and B is a knave is true”. Since
this is a proposition of the form p→qthat is true, with ptrue, then qis true, i.e. B is a
knave
We have therefore reached a contradiction, and the problem has no answer.
Exercise 3
We want to prove that : (((p∨q)→r)∧(r→s)) →(¬s→ ¬p) is a tautology:
1
pf3
pf4
pf5

Partial preview of the text

Download Logic, Proofs, Set Theory, Algorithm - Midterm 2007 | ECS 020 and more Exams Computer Science in PDF only on Docsity!

Midterm - on 11/08/

Part I: Logic

Exercise 1

We study : A = [¬(p ∨ q) ∧ ¬(q ∨ p) ↔ (p ∧ q)]

p q p ∨ q ¬(p ∨ q) p ∧ q A T T T F T F T F T F F T F T T F F T F F F T F F

From column 6, we get that A is not a tautology nor a contradiction.

Exercise 2

A and B are inhabitants of Smullyan islands, and A says ”If I am a knight, then B is a knave”, while B says ”If I am a knave, then A is a knight”. The answer is: The two propositions are contradictory: there is no answer. We proceed as follows:

  • We show first that A is a knight. We use a proof by contradiction. We suppose that A is a knave. In this case, the proposition ”If I am a knight, then B is a knave” is false. Since this proposition is a conditional of the form p → q, it is false when p is true and q is false. p is true means A is a knight. But this contradicts A is a knave. So our hypothesis is false, and therefore A is a knight.
  • We show that B is a knight. Again we use a proof by contradiction. We suppose that B is a knave. In this case, the proposition ”If I am a knave, then A is a knight” is false, i.e. B is a knave and A is a knave. But we have shown that A is a knight, and therefore we have reached a contradiction, and B is a knight.
  • We show that B is a knave. A is a knight, and therefore the proposition ”A is a knight and B is a knave is true”. Since this is a proposition of the form p → q that is true, with p true, then q is true, i.e. B is a knave

We have therefore reached a contradiction, and the problem has no answer.

Exercise 3

We want to prove that : (((p ∨ q) → r) ∧ (r → s)) → (¬s → ¬p) is a tautology:

p q r s p ∨ q a = (p ∨ q) → r r → s b = a ∧ (r → s) c = ¬s → ¬p b → c T T T T T T T T T T T T T F T T F F F T T T F T T F T F T T T T F F T F T F T T T F T T T T T T T T T F T F T T F F F T T F F T T F T F T T T F F F T F T F T T F T T T T T T T T T F T T F T T F F F T F T F T T F T F T T F T F F T F T F T T F F T T F T T T T T F F T F F T F F F T F F F T F T T T T T F F F F F T T T T T

From column 6, we get that the proposition is indeed a tautology.

Part II: Proofs

Exercise 1

n and m are integers. We want to show that if nm is even, then one of n or m is even. We use a proof by contradiction. let p be the proposition nm is even, and let q be the proposition ”n or m is even”. The proposition p → q is false when p is true and q is false, i.e. nm is even and ”n is odd and m is odd”. If n is odd, there exists an integer k such that n = 2k + 1. Similarly, if m is odd, there exists an integer l such that m = 2l + 1. Then, nm = (2k + 1)(2l + 1) = 4kl + 2k + 2l + 1 = 2(kl + k + l) + 1 i.e. nm is odd. But this is in contradiction with nm is even, and therefore the proposition ”if nm is even, then one of n or m is even” is true.

Exercise 2

Let n = 4^25650925 − 1. Notice that 4 = 2^2 and 9 = 3^2. We can rewrite n as: n = 2^50650350 − 1 = 36^50 − 1 = (36^25 )^2 − 1 = (36^25 − 1)(36^25 + 1). Since both 36^25 − 1 and 36^25 + 1 are not equal to 1, we can conclude that n is composite.

Exercise 3

Let A = {p | p is a prime number }, let B = {(k^2 − 1) | k ∈ Z}, and let C = { 3 }. We want to show that A ∩ B = C. We show this by proving that A ∩ B ⊂ C and C ⊂ A ∩ B.

  • We show that A ∩ B ⊂ C. Let p be an integer in A ∩ B. Since p is in A, p is a prime number. Since p is in B, there exists k such that p = k^2 − 1. Notice that p = k^2 − 1 = (k − 1)(k + 1), i.e. p can only be prime if k + 1 = 1 or k − 1 = 1, or k + 1 = −1, or k − 1 = −1.

Let us suppose that A ∩ B = A. Based on De Morgan’s law, B ∩ A¯ = B¯∪ A¯. We also know that A¯ = A. Therefore, B∩B ∩ A¯ = B ∩ ( B¯ ∪ A). Using distributivity, we get: B ∩ B ∩ A¯ = (B ∩ B¯) ∪ (B ∩ A). We know that B ∩ B¯ = ∅; then B ∩B ∩ A¯ = B ∩A = A, based on the premise. The proposition is therefore true.

Exercise 2

We want to prove or disprove that for four sets A, B, C and D, (A − B) − (C − D) = (A − C) − (B − D). The proposition is probably false. We have two ways to show this:

a) Find a counter example. Notice that if an element x is in A, C and D, but not in B, then: x ∈ A − B but x /∈ C − D, and therefore x ∈ (A − B) − (C − D) x /∈ A − C, therefore x /∈ (A − C) − (B − D). We have therefore a counterexample! For instance: A = { 1 , 2 , 3 , 4 , 5 }, B = { 2 , 3 }, C = { 1 , 3 , 4 } and D = { 1 , 4 , 5 }. Then: A − B = { 1 , 4 , 5 }, C − D = { 3 } and (A − B) − (C − D) = { 1 , 4 , 5 }. A − C = { 2 , 5 }, B − D = { 2 , 3 } and (A − C) − (B − D) = { 5 }. b) We can use a membership table:

A B C D A − B C − D (A − B) − (C − D) A − C (B − D) (A − C) − (B − D) 1 1 1 1 0 0 0 0 0 0 1 1 1 0 0 1 0 0 1 0 1 1 0 1 0 0 0 1 0 1 1 1 0 0 0 0 0 1 1 0 1 0 1 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 0 0 1 0 0 1 1 0 1 1 0 1 1 0 0 0 1 0 1 1 0 1 0 1 1 1 0 0 0 0 0 0 0 1 1 0 0 1 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Since column 7 and 10 are not equal, (A − B) − (C − D) 6 = (A − C) − (B − D)

Part IV: Algorithm

We want to design an algorithm that replaces a number in a sequence by the sum of the numbers that precede follow that number in the sequence. We first notice that if the sequence is defined as ai, for i ∈ [1, n], and if we define S as the sum of the numbers in the sequences, then the operation we need to perform is simply:

For all i, replace ai with S − ai !! This is easily done as follows:

Procedure Replace Input: a 1 , a 2 ,... , an Output: b 1 , b 2 ,... , bn Real a 1 , a 2 ,... , an Real b 1 , b 2 ,... , bn Real S Integer i

S ← 0 for { i = 1; i=n; STEP=1} { S ← S + ai } for { i = 1; i=n; STEP=1} { bi ← S − ai }

return We need n additions to compute S, and then n substitutions to find the sequence b. The procedure is of order n.