You are on page 1of 30

COMP2121

Discrete Mathematics

Logic
Hubert Chan

[O1 Abstract Concepts]


[O2 Proof Techniques]

1
Logic (Chapter 1)
(chapters 1.1, 1.2)

• Propositional Logic
 Basic Definitions
 Logical operators

• Predicate Logic
 Predicates
 Quantified expressions

2
A Puzzle
• In the middle of the journey to a village, you need to
select whether to go East or West at a branch.
• One is the path to hell and the other is to heaven, but you
cannot tell which is which.
• Each villager always tells the truth or always lies and will
only give a “Yes” or a “No” response to a question.
• You are only allowed to ask a villager one question to
determine the way to heaven. What to ask?

• If you can ask two questions, the problem is trivial.


• Question 1: 4 > 5?
• Question 2: Is East the way to heaven?

• Yet you are allowed to ask only one question!


3
Propositions – Definition [O1]
• Def: A proposition is a statement that is either true (T) or
false (F), but not both.

• Which of the followings are propositions?


 1 + 1 = 7.
 Do you feel hungry?
 Hong Kong is the largest city of China.
 1 + 3.
 x + 2.
 Come here quickly!

4
Compound Proposition
• A proposition (compound proposition) can be formed by
combining several propositions using logical operators.
• Logical operators:  (negation),  (and),  (or), 
(exclusive or),  (implication),  (biconditional)
• Example: Mr. Wong is stupid and his wife is lazy.
p: Mr. Wong is stupid
q: his wife is lazy.
p  q: where  stands for connective “and”
• A compound proposition also has a truth value (T or F)
depending on the truth values of its constituting
propositions and the operator(s).

5
Logical operators
• And (Conjunction) - Let p and q be two propositions, (p 
q) is defined to be true if both p and q are true, and false
otherwise.
• Example:
(Today is Friday)  (2 is a factor of 15) ---- False
• Or (Disjunction) - Let p and q be two propositions, (p  q)
is defined to be true if either p or q or both are true, and
false otherwise.
• Exclusive-or - Let p and q be two propositions, then (p 
q) is defined to be true if either p or q, but not both, is
true, and false otherwise.
• Not (Negation) - Let p be a proposition, p is defined to
be true if p is false. Otherwise p is false.
6
Truth Table
• Truth table can be used to display the truth values of
propositions and is useful in determining the truth values
of complicated proposition.

Truth Tables for  (negation),  (and),  (or),  (exclusive-or)


p q pq pq pq
T T T T F p p
All
possible T F F T T T F
cases.
How F T F T T F T
many?
F F F F F
p and q are two propositions

7
Logical operators:  (negation),  (and),  (or), 
(exclusive or),  (implication),  (biconditional)
The implication pq is the proposition that is false
when p is true and q is false, and true otherwise.
pq is often read as “p implies q”
p q pq
or “if p, then q”
T T T
Intuitively, the statement has no problem if
T F F the hypothesis p is not true.

F T T Example:
Let p denote “You get grade A”,
F F T q denote “You will receive an iPad”.
r denote pq
What’s the truth value of r if
(a) You do not get grade A, and you receive an iPad T
(b) You do not get grade A, an you do not receive an iPad T
(c) You get grade A, and you do not receive an iPad F
8
Remarks:
1 The mathematical concept of an implication vs
daily usage of English

“If today is Sunday, then 2+3 = 5” daily usage

Assumes a relationship between the hypothesis & conclusion

But the implication is true according to the definition.

Also, the meaning of the if-then statement is different when


2 used in a program

if (x > 3) then y = x;
If the value of x is greater than 3, then execute the
statement “y = x”

9
The bicondition pq is the proposition that is true both
p and q have the same truth values and is false
otherwise.

p q pq pq is often read as “p if and only if


q” or “p is necessary and sufficient
T T T for q”
T F F
F T F Remark:
pq is true when both pq and
F F T qp are true.

Example:
(X is an even number)  (X+1 is an odd number)

10
Exercise:
Let p and q be the propositions.
p: It is below freezing
q: It is snowing
Write the following propositions using p and q and logical
connectives (operators).

(a) It is below freezing but not snowing. p  q

(b) It is either below freezing or it is


snowing, but it is not snowing if it is (p  q)  (p  q)
below freezing.

(c) It is either below freezing or


snowing, but not both. pq

11
Logically equivalence

We say that the two propositions p and q are logically equivalent if


pq is always true. We denote this relationship by pq (or p ≡ q).

That is, either both are


true or both are false.

Claim: (p  q)  (p  q)


Again, we can prove it using truth table!

12
Some important equivalences
Obvious Rules
pTp pTT ppp (p)  p
pFp pFF ppp

Commutative
pqqp Q: Is addition commutative? (p + q = q + p ?)
pqqp Q: Is subtraction commutative? (p – q = q – p?)

Associative
(p  q)  r  p  (q  r) Q: Is multiplication associative?
(p  q)  r  p  (q  r) Q: Is division associative?

Q: (p  q)  r  p  (q  r) ??
To show that it is not correct: Let p = F, q = F, r = T
13
More….

(Distributive Law) (De Morgan’s Law)


p  (q  r)  (p  q)  (p  r) (p  q)  p  q
p  (q  r)  (p  q)  (p  r) (p  q)  p  q

(Negation Law)
(Implication Law)
p  p  T p  p  F (p  q)  (p  q)

14
Implication Law
• Let p, q be the propositions:
 p: You do not finish your homework.
 q: You get punished.

• The meaning of pq:


 If you do not finish your homework, you get punished.

• The meaning of :pÇq:


 You finish your homework or you will get punished.

15
“Unless”
• Another way of saying ‘You finish your homework or you
get punished.’:
You get punished, unless you finish your homework.

• What do we mean by saying ‘p unless q’:


It means p or q.

16
• Question to be asked: If I were to ask you whether East
is the way to heaven, would you answer “yes”? [O2]

• If the correct answer is East:


 The honest answer is “Yes”.
 For the dishonest villager,
 Ifhe is asked “whether East is the way to heaven?” (Q1)
 What would be his answer?
 “No”
 So, if we ask him “If I were to ask you whether East is the
way to heaven, would you answer “yes”?
 Since his own answer to Q1 is “No”, so he lies, and would
answer “Yes” to this question.
• Similarly for the incorrect answer, both will answer “No”.

17
Case Study
• Default: in a divorce, the wife gets alimony.
• In the prenuptial agreement, here is a statement:
 “If (p: the wife is unfaithful), then (q: she gets no
alimony), unless (r: she gives birth to an offspring of
the husband).
 Is this statement ambiguous? Which interpretation
favors the wife more?

A: (if p, then q), unless r


B: if p, then (q, unless r)

18
COMP2121
Discrete Mathematics

Predicates and Quantifiers


(chapters 1.3, 1.4)

[O1 Abstract Concepts]

19
Predicates [O1]
Is “x > 3” a proposition?

No, unless the value of x is fixed.

Let P(x) denote the statement “x > 3” where P(x) is called a


propositional function.

P(x) has a truth value once the value of x is fixed.


E.g. P(5) is true; P(1) is false.

P actually refers to the property “is greater than 3” and is called the
predicate. Note that x is a variable (the subject).

A propositional function can have more than one variable (multi-


value predicates).
E.g. Let Q(x, y) denote “x + y > 10”.
Then, Q(4, 5) is false; Q(5, 6) is true.

20
Universe of Discourse
• The collection of values that a variable x may take is
called the universe of discourse or domain.

• Example:
 “x is rich”, x can refer to people in HK, the world,
movies stars, IT people, …
 For the statement “x is prime”, the universe of
discourse of x is the set of all positive integers.

21
Quantification (Quantifiers)
Two ways to convert a propositional function, say P(x), into a
proposition.
• Assign value(s) to variable(s).
• Quantify variable(s):
 Universal: P(x) is true for all possible values of x
 Existential: At least one value of x such that P(x) is true

Example:
Let P(x) denote the statement “x has a million dollars”.
P(x) has no truth value and is not a proposition.
P(John) is a proposition.
x P(x) is a proposition.
“for all possible values of x (universe of discourse), P(x) is true”
e.g. “x P(x)” is false where domain is people in Hong Kong.
22
Universal and Existential Quantification
• Suppose the universe of discourse (domain) of P(x) is
 {x1, x2, x3 …}

• The universal quantification


 x P(x)  P(x1)  P(x2)  P(x3)  …
 P(x) is true for all possible values of x

• The existential quantification


 x P(x)  P(x1)  P(x2)  P(x3)  …
 P(x) is true for at least one value of x

23
Example:
Let P(x) denote the statement “x is married”.
P(x) has no truth value and is not a proposition.
P(Peter) is a proposition.
x P(x) is a proposition.
“there exist an x from the possible values, P(x) is true”
e.g. “x P(x)” is true where u.o.d. is the postgrad students in our dept.

Examples (the universe of discourse is the set of integers):


What is the truth value of the following?
x (x2 = x)
x (x2 = x)
x [y (x+y = x-y)]
x [y (x+y = x-y)]

24
Example
• To express:
 “Every student in this class is smart.”
 “All students in this class are smart.” etc.

• Let’s make the universe of discourse be the set of all


students (including those not in this class).
• Let P(x) be the statement “x is smart.”
• Let Q(x) be the statement “x is in the class.”

• Can you write down the expression?


• x (Q(x) ∧ P(x))
• which means all students are in this class and smart
• Answer: x (Q(x) P(x))
25
Example
• To express: “Some students in the this class are smart.”
• “At least one student in this class is smart.”
• “Not all students in this class are stupid”

• Let P(x) be the statement “x is smart.”


• Let Q(x) be the statement “x is in the FCS class.”

• Let’s make the universe of discourse be the set of all students.


• Can you write down the expression?
•  x (Q(x)  P(x))
which cannot guarantee at least one student in this class is
smart (e.g. there can be no students in this class and there is
one student, say Peter, who is not in this class, the statement is
still true!).
Answer:  x (Q(x) ∧ P(x))

26
Quantifier Equivalences
• Suppose the universe of discourse is {x1, x2, x3,…}.

• x P(x)  P(x1)  P(x2)  P(x3)  …


• x P(x)  P(x1)  P(x2)  P(x3)  …

• By the De Morgan’s Law,


• (p  q)  p  q
• (p  q)  p  q

• we can prove that


• x P(x)  x P(x)
• x P(x)  x P(x)
27
Compared the previous example with this one.

Let P(x) denote “x is at least 165 cm tall”


A(x) denote “x is less than 165 cm tall”

Are “x (P(x)  A(x))” and “(x P(x))  (x A(x))” equivalent?

No, here is the counterexample.


Let the universe of discourse has only “Peter” and “May”.
Peter is 170 cm tall, and May is 160 cm tall.
P(Peter) is true, but A(Peter) is false;
P(May) is false, but A(May) is true;
So, “x (P(x)  A(x))” is true but “(x P(x))  (x A(x))” is false

28
Ordering of quantifiers
If x y M(x, y) is true, can we say that y x M(x, y) is also true?

If y x M(x, y) is true, can we say that x y M(x, y) is also true?

Hint: Suppose x is a key and y is a lock.


Let M(x, y) denote the statement “x can open y”
Note: Transposing different kinds of quantifiers
may have different meanings

However, two quantifiers of the same kind can be


transposed without changing the meaning of the
expression.

x y Q(x, y)  y x Q(x, y)


x y Q(x, y)  y x Q(x, y)

29
Some Conventions
• The universe of discourse may be restricted within the
quantification.
• x > 0 P(x)
 x (x > 0  P(x))
[ For all x that are greater than zero, P(x) holds ]
• x > 0 P(x)
 x (x > 0  P(x))
[ There is an x greater than zero such that P(x)
holds. ]
• The universe of discourse is restricted from
“a set of integers” to “a set of positive integers”
Try some exercises on Sec. 1.3, 1.4
30

You might also like