Ds 2 Predicate
Ds 2 Predicate
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Chapter 2
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
Logics (cont.)
Discrete Structures for Computing on January 4, 2023
Contents
Predicate Logic
Exercise
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
2 Exercise
2.2
Course outcomes Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
L.O.2 Represent and model practical problems with discrete structures Contents
L.O.2.1 Logically describe some problems arising in Computing Predicate Logic
L.O.2.2 Use proving methods: direct, contrapositive, induction Exercise
L.O.2.3 Explain problem modeling using discrete structures
2.3
Limits of Propositional Logic Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
Contents
• x>3
Predicate Logic
• All square numbers are not prime numbers. 100 is a square Exercise
number. Therefore 100 is not a prime number.
2.4
Predicates Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
Definition
A predicate (và tø ) is a statement containing one or more
variables. If values are assigned to all the variables in a predicate,
the resulting statement is a proposition (m»nh · ). Contents
Predicate Logic
• x > 3 → P (x) Exercise
• 5 > 3 → P (5)
• A predicate with n variables P (x1 , x2 , ..., xn )
Example:
• x > 3 (predicate)
• 5 > 3 (proposition)
• 2>3 (proposition)
2.5
Truth value Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
2.6
Quantifiers Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
2.7
Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
Example
Let P (x) be the statement x < 2. What is the truth value of the
quantification ∀xP (x), where the domain consists of all real
number?
Contents
• P (3) = 3 < 2 is false
Predicate Logic
• ⇒ ∀xP (x) is false Exercise
Example
What is the truth value of the quantification ∃xP (x), where the
domain consists of all real number?
2.8
Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
Example
Express the statement "Some student in this class comes from
Central Vietnam."
Solution 1
Contents
• M (x) = x comes from Central Vietnam Predicate Logic
• ∃xM (x)
Solution 2
• Domain for x is all people
• ...
2.9
Negation of Quantifiers Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
• ∀x : C(x) → S(x)
• ∃x : ¬(C(x) → S(x)) ≡ ∃x : C(x) ∧ ¬S(x)
• There is a CSE student who does not study Discrete Math 1.
2.10
Another Example Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
Example
Translate these:
Solution
Let P (x), Q(x) and R(x) be the statements x is a lion, x is
fierce and x drinks coffee, respectively.
2.11
The Order of Quantifiers Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
Example Contents
Predicate Logic
∀x ∀y (x + y = y + x) Exercise
T for all x, y ∈ R
Example
∀x ∃y (x + y = 0) is T,
while
∃y ∀x (x + y = 0) is F
2.12
Translating Nested Quantifiers Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
Example
∀x (C(x) ∨ ∃y (C(y) ∧ F (x, y)) )
Provided that:
Contents
• C(x): x has a computer, Predicate Logic
• F (x, y): x and y are friends, Exercise
Answer
For every student x in your school, x has a computer or there is a
student y such that y has a computer and x and y are friends.
2.13
Translating Nested Quantifiers Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
Example
∃x∀y∀z (((F (x, y) ∧ F (x, z) ∧ (y 6= z)) → ¬F (y, z)))
Provided that:
Contents
• F (x, y): x, y are friends Predicate Logic
Answer
There is a student x, so that for every student y , every student z
not the same as y, if x and y are friends, and x and z are friends,
then y and z are not friends.
2.14
Translating into Logical Expressions Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
Example
1 There is a student in the class has visited Hanoi.
Assume:
C(x) : x has visited Hanoi
D(x) : x has visited Nha Trang
E(x) : x has visited Vung Tau
We have:
1 ∃xC(x)
2 ∀x(D(x) ∨ E(x))
2.15
Translating into Logical Expressions Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Solution
Contents
We define:
Predicate Logic
• W (x) : x is woman Exercise
• P (x) : x is a parent
• M (x, y): x is mother of y
We have: ∀x((W (x) ∧ P (x)) → ∃yM (x, y))
Example
"Every people has only one best friend."
Assume:
2.16
Translating into Logical Expressions Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
Example
"Every people has only one best friend." Contents
Assume: Predicate Logic
• B(x, y) : y Exercise
is the best friend of x
Solution
∀x∃y∀z(B(x, y) ∧ ((y 6= z) → ¬B(x, z)))
2.17
Inference Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
Example
• If I have a girlfriend, I will take her to go shopping.
• Today is March 8.
2.18
Propositional Rules of Inferences Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
∴ ¬p Modus tollens
p→q
q→r
Hypothetical syllogism
∴p→r
(Tam o¤n luªn gi£ ành)
p∨q
¬p
Disjunctive syllogism
∴q
(Tam o¤n luªn tuyºn)
2.19
Propositional Rules of Inferences Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
2.20
Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Example Toan, Tran Hong Tai
2.21
Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
Example
1. ¬p ∧ q Hypothesis
• It is not sunny this afternoon
(¬p) and it is colder than 2. ¬p Simplification using (1)
yesterday (q )
• We will go swimming (r) only if 3. r → p Hypothesis Contents
it is sunny Predicate Logic
4. ¬r Modus tollens using (2) andExercise
(3)
• If we do not go swimming, then
we will take a canoe trip (s) 5. ¬r → s Hypothesis
• If we take a canoe trip, then we
will be home by sunset (t) 6. s Modus ponens using (4) and (5)
• We will be home by sunset (t)
7. s → t Hypothesis
2.22
Fallacies Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
Definition
Fallacies (ngöy bi»n) resemble rules of inference but are based on
contingencies rather than tautologies. Contents
Predicate Logic
Example Exercise
Is [(p → q) ∧ q] → p a tautology?
2.23
Rules of Inference for Quantified Statements Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
2.24
Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
Example
• A student in this class has not gone to class
• Someone who passed the first exam has not gone to class Contents
Predicate Logic
Exercise
Hint
• C(x): x is in this class
• Premises???
2.25
Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
2.26
Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
a) p(0) Contents
b) p(1) Predicate Logic
Exercise
c) p(2)
d) ∃x, p(x)
e) ∀x, p(x)
2.27
Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
a) p(2, 3)
b) p(2, 6)
Contents
c) ∀y, p(1, y) Predicate Logic
d) ∀x, p(x, x) Exercise
e) ∀x∃y, p(x, y)
f) ∃y∀x, p(x, y)
g) ∀x∀y, (p(x, y) ∧ p(y, x)) → (x = y)
h) ∀x∀y∀z(p(x, y) ∧ p(y, z)) → (p(x, z))
2.28
Logics (cont.)
• M (x, y) : x is mother of y ,
• S(x, y) : x is sister of y ,
• B(x, y) : x is brother of y ,
• H(x, y) : x is spouse (wife/husband) of y,
Contents
• O(x, y) : x is elder than y .
Predicate Logic
Exercise
Express each of these statements using predicates:
a) `He (a person) has an elder sister and younger brother'.
2.29
Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Solutions: Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
2.30
Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
2.31
Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Given a predicate N (x) "x has been to Da Lat" with the domain Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
is the all students in Mathematics class. Translate the following
predicates into English
a) ∃xN (x)
b) ∀xN (x)
c) ¬∃xN (x) Contents
d) ∃x¬N (x) Predicate Logic
Exercise
e) ¬∀xN (x)
f) ∀x¬N (x)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
Given the predicate N (x) "x studies more than 5 hours in class
every weekday" with the domain is the all students in
Mathematics class. Express the following predicates:
Contents
a) ∃xN (x) Predicate Logic
Exercise
b) ∀xN (x)
c) ∃x¬N (x)
d) ∀x¬N (x)
2.33
Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
}
return true;
• There are no mushrooms that are poisonous and purple.
2.34
Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
2.35
Logics (cont.)
Contents
// Now look for a second match Predicate Logic
for (y=0; (y<numKids)&&(y!=x); y++) Exercise
if isParent(Peter, kids[y])
match2Found = true;
2.36
Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
Let P(x) be "x can speak Russian" and Q(x) be "x can use Java".
Formalize the following:
Giving the space is ll students in your university.
a) There is a student in your university that can speak Russian and can use
Java.
b) There is a student in your university that can speak Russian but can't Contents
use Java. Predicate Logic
c) Every student in your university can speak Russian or can use Java. Exercise
d) None of the student in your university can speak Russian or can use Java.
2.37
Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
Let L(x,y) be "x love y", where the space of x and y is the set of
all people in the world. Use logical quantifier to express the
following:
a) Everybody loves Jerry.
b) Everybody loves someone.
Contents
c) There is a person who everybody loves. Predicate Logic
d) Nobody loves everybody. Exercise
e) There is someone Lydica doesn't love.
f) There is someone nobody loves.
g) There is exact one person everybody loves.
h) There are exact two person Lynn loves.
i) Everybody loves themselves.
j) There is a person who love nobody but himself.
2.38
Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Giving the following: Toan, Tran Hong Tai
b) ∃x(S(x) ∧ ¬P (x))
There are many ways to translate a formula to natural language
and the following is one of them
x is not easy.
2.39
Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
2.40
Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
2.41
Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
2.42
Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Toan, Tran Hong Tai
Let:
- P (x, y): x is parent of y.
- M (x): x is male .
Given:
Contents
F (v, w) = M (v) ∧ ∃x∃y(P (x, y) ∧ P (x, v) ∧ (y 6= v) ∧ P (y, w)),
Predicate Logic
then F (v, w) means:
Exercise
A) v is brother of w
B) v is cousin of w
C) v is uncle of w
D) v is grand father of w
2.43
Logics (cont.)
Nguyen An Khuong,
Tran Tuan Anh, Nguyen
Tien Thinh, Mai Xuan
Formalize the following sentences using predicate logic: Toan, Tran Hong Tai
a) When a hard drive has less than 30GB free space, a warning
2.44