0% found this document useful (0 votes)
13 views11 pages

Tutorial 1: Propositional Logics

This tutorial covers propositional logic, focusing on logical equivalence and transformations of propositions. It includes examples of code from different versions of Mergesort to illustrate logical conditions, as well as a series of questions and solutions regarding the equivalence of various logical statements. The document emphasizes the use of truth tables and logical reasoning to determine equivalence.

Uploaded by

王少甫
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views11 pages

Tutorial 1: Propositional Logics

This tutorial covers propositional logic, focusing on logical equivalence and transformations of propositions. It includes examples of code from different versions of Mergesort to illustrate logical conditions, as well as a series of questions and solutions regarding the equivalence of various logical statements. The document emphasizes the use of truth tables and logical reasoning to determine equivalence.

Uploaded by

王少甫
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Tutorial 1: Propositional Logics

Department of Computer Science and Engineering


Hong Kong University of Science and Technology

Tutorial 1: Propositional Logics 1 / 11


Logic in Programs

(1) if ((i+j ≤ p+q) && (i ≤ p) && (1) if (((i+j ≤ p+q) && (i ≤ p) &&
((j > q) || (List1[i] ≤ List2[j]))) (j > q)) || ((i+j ≤ p+q) && (i ≤
(2) List3[k] = List1[i] p) && (List1[i] ≤ List2[j])))

(3) i = i+1 (2) List3[k] = List1[i]

(4) else (3) i = i+1

(5) List3[k] = List2[j] (4) else

(6) j = j+1 (5) List3[k] = List2[j]

(7) k = k+1 (6) j = j+1


(7) k = k+1

Consider the above two pieces of code. They are taken from two
different versions of Mergesort. Do they do the same thing? (Note
that && = “and”, || = “or”.)
Observation: The two pieces of code are the same except for line 1.

Tutorial 1: Propositional Logics 2 / 11


Logic in Programs

(1) ((i+j ≤ p+q) && (i ≤ p) && ((j > q) || (List1[i] ≤ List2[j])))


(1’) (((i+j ≤ p+q) && (i ≤ p) && (j > q)) || ((i+j ≤ p+q) &&
(i ≤ p) && (List1[i] ≤ List2[j])))
Are they equivalent?

Let’s rewrite using


s ∼ (i+j ≤ p+q) t ∼ (i ≤ p) u ∼ (j > q) v ∼ (List[i] ≤
List2[j])
(1) s and t and (u or v )
(1’) (s and t and u) or (s and t and v )

Now set w ∼ (s and t)


equal?
(1) w and (u or v ) ←−−→ (1’) (w and u) or (w and v )

Tutorial 1: Propositional Logics 3 / 11


Logic in Programs

We just transformed our code into compound propositions and


next want to develop a theory of how to determine whether two
such propositions are equal (equivalent).

Tutorial 1: Propositional Logics 4 / 11


Question 1

Are s ⊕ t and (s ∧ ¬t) ∨ (¬s ∧ t) logically equivalent? If yes, prove


it by truth table. Otherwise, give a counterexample to show that
they are not logically equivalent.

Solution:
s t s ⊕t s ∧ ¬t ¬s ∧ t (s ∧ ¬t) ∨ (¬s ∧ t)
T T F F F F
T F T T F T
F T T F T T
F F F F F F

Tutorial 1: Propositional Logics 5 / 11


Question 2

Are w ∧ (s ⊕ t) and (w ∨ s) ⊕ (w ∨ t) logically equivalent? If yes,


prove it by truth table. Otherwise, give a counterexample to show
that they are not logically equivalent.

Solution:
No, they are not logically equivalent. Set w = F , s = F and
t = T . w ∧ (s ⊕ t) = F but (w ∨ s) ⊕ (w ∨ t) = T .

Tutorial 1: Propositional Logics 6 / 11


Question 3

For each of the following pairs of propositions, either prove they


are logically equivalent, or give a counterexample.
(a) p → q and q → p
(b) p → q and ¬q → ¬p
(c) (p → q) → q and p → q
(d) (p → p) → q and q
(e) q → (p ∧ ¬p) and ¬q
(f) q → (p ∧ ¬p) and ¬p

Tutorial 1: Propositional Logics 7 / 11


Question 3

Solution:
(a) Not equivalent. Set p = T , q = F , then p → q = F but
q → p = T.
(b) Equivalent. p → q ≡ ¬p ∨ q ≡ (¬¬q) ∨ (¬p) ≡ ¬q → ¬p.
Or truth table.
p q p → q ¬q ¬p ¬q → ¬p
T T T F F T
T F F T F F
F T T F T T
F F T T T T
(c) Not equivalent. Set p = F , q = F , then (p → q) → q = F
but p → q = T

Tutorial 1: Propositional Logics 8 / 11


Question 3

(d) Equivalent. (p → p) → q ≡ T → q ≡ q. Or truth table.


p q p → p (p → p) → q q
T T T T T
T F T F F
F T T T T
F F T F F
(e) Equivalent. q → (p ∧ ¬p) ≡ q → F ≡ ¬q. Or truth table.
p q p ∧ ¬p q → (p ∧ ¬p) ¬q
T T F F F
T F F T T
F T F F F
F F F T T
(f) Not equivalent. Set p = T , q = F , then q → (p ∧ ¬p) = T
but ¬p = F

Tutorial 1: Propositional Logics 9 / 11


Question 4

For each of the following pair of propositions, either prove that the
two propositions are logically equivalent without using truth table,
or give a counterexample to show that the propositions are not
logically equivalent.
(a) (i) p → (q → r )
(ii) (p ∧ q) → r
(b) (i) (¬(p → ¬q)) → (¬(p ∧ r ) ∨ s)
(ii) (¬r → p) → ((p ∧ q) → s)

Tutorial 1: Propositional Logics 10 / 11


Question 4
Solution:
(a) Consider
p → (q → r ) = ¬p ∨ (q → r )
= ¬p ∨ (¬q ∨ r )
= ¬p ∨ ¬q ∨ r
Consider
(p ∧ q) → r = ¬(p ∧ q) ∨ r
= (¬p ∨ ¬q) ∨ r
= ¬p ∨ ¬q ∨ r
Thus, p → (q → r ) is equivalent to (p ∧ q) → r .
(b) Set p = T , q = T , r = F , s = F ,
(¬(p → ¬q)) → (¬(p ∧ r ) ∨ s) becomes true and
(¬r → p) → ((p ∧ q) → s) becomes false. Thus they are not
equivalent.
Tutorial 1: Propositional Logics 11 / 11

You might also like