01 Logic
01 Logic
01 Logic
Discrete Mathematics
Logic
Hubert Chan
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?
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.
7
Logical operators: (negation), (and), (or),
(exclusive or), (implication), (biconditional)
The implication pq is the proposition that is false
when p is true and q is false, and true otherwise.
pq is often read as “p implies q”
p q pq
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 pq
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 (x > 3) then y = x;
If the value of x is greater than 3, then execute the
statement “y = x”
9
The bicondition pq is the proposition that is true both
p and q have the same truth values and is false
otherwise.
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).
11
Logically equivalence
12
Some important equivalences
Obvious Rules
pTp pTT ppp (p) p
pFp pFF ppp
Commutative
pqqp Q: Is addition commutative? (p + q = q + p ?)
pqqp 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….
(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.
15
“Unless”
• Another way of saying ‘You finish your homework or you
get punished.’:
You get punished, unless you finish your homework.
16
• Question to be asked: If I were to ask you whether East
is the way to heaven, would you answer “yes”? [O2]
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?
18
COMP2121
Discrete Mathematics
19
Predicates [O1]
Is “x > 3” a proposition?
P actually refers to the property “is greater than 3” and is called the
predicate. Note that x is a variable (the subject).
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 …}
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.
24
Example
• To express:
“Every student in this class is smart.”
“All students in this class are smart.” etc.
26
Quantifier Equivalences
• Suppose the universe of discourse is {x1, x2, x3,…}.
Are “x (P(x) A(x))” and “(x P(x)) (x A(x))” equivalent?
28
Ordering of quantifiers
If x y M(x, y) is true, can we say that y x M(x, y) is also true?
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