Ds 2 Predicate
Ds 2 Predicate
Logics (cont.)
Discrete Structures for Computing on August 5, 2020
Contents
Predicate Logic
Exercise
Predicate Logic
Exercise
2 Exercise
2.2
Logics (cont.)
Course outcomes
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang, Nguyen
Tien Thinh
Course learning outcomes
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
Logics (cont.)
Limits of Propositional Logic
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang, Nguyen
Tien Thinh
• x>3 Contents
Predicate Logic
• All square numbers are not prime numbers. 100 is a square
Exercise
number. Therefore 100 is not a prime number.
2.4
Logics (cont.)
Predicates
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang, Nguyen
Tien Thinh
Definition
A predicate (vị từ) is a statement containing one or more
variables. If values are assigned to all the variables in a predicate, Contents
Exercise
Example:
• x > 3 (predicate)
• 5 > 3 (proposition)
• 2 > 3 (proposition)
2.5
Logics (cont.)
Predicates
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang, Nguyen
Tien Thinh
Exercise
• A predicate with n variables P (x1 , x2 , ..., xn )
2.6
Logics (cont.)
Truth value
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang, Nguyen
Tien Thinh
2.7
Logics (cont.)
Quantifiers
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang, Nguyen
Tien Thinh
Predicate Logic
• ∃: Existential – Tồn tại Exercise
• ∃xP (x) = There exists an element x such that P (x) is T
• We need a domain of discourse for variable
2.8
Logics (cont.)
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?
Exercise
Example
What is the truth value of the quantification ∃xP (x), where the
domain consists of all real number?
2.9
Logics (cont.)
Solution 1
Predicate Logic
• Domain for x is the students in the class Exercise
• ∃xM (x)
Solution 2
2.10
Logics (cont.)
Negation of Quantifiers
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang, Nguyen
Tien Thinh
Predicate Logic
Example
Exercise
2.11
Logics (cont.)
Another Example
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang, Nguyen
Tien Thinh
Example
Translate these:
• All lions are fierce.
• Some lions do not drink coffee.
• Some fierce creatures do not drink coffee. Contents
Predicate Logic
Exercise
Solution
Let P (x), Q(x) and R(x) be the statements “x is a lion”, “x is
fierce” and “x drinks coffee”, respectively.
• ∀x(P (x) → Q(x)).
• ∃x(P (x) ∧ ¬R(x)).
• ∃x(Q(x) ∧ ¬R(x)).
2.12
Logics (cont.)
The Order of Quantifiers
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang, Nguyen
Tien Thinh
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.13
Logics (cont.)
Translating Nested Quantifiers
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang, Nguyen
Tien Thinh
Example
∀x (C(x) ∨ ∃y (C(y) ∧ F (x, y)) )
Provided that:
• C(x): x has a computer, Contents
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.14
Logics (cont.)
Translating Nested Quantifiers
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang, Nguyen
Tien Thinh
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
• x, y, z ∈ all students in your school. Exercise
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.15
Logics (cont.)
Translating into Logical Expressions
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang, Nguyen
Tien Thinh
Example
Predicate Logic
Answer Exercise
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.16
Logics (cont.)
Translating into Logical Expressions
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang, Nguyen
Tien Thinh
Example
Every people has only one best friend.
Contents
Predicate Logic
Solution
Exercise
Assume:
• B(x, y) : y is the best friend of x
We have:
∀x∃y∀z(B(x, y) ∧ ((y 6= z) → ¬B(x, z)))
2.17
Logics (cont.)
Translating into Logical Expressions
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang, Nguyen
Tien Thinh
Example
If a person is a woman and a parent, then this person is mother of
some one.
Contents
Solution Predicate Logic
We define: Exercise
• W (x) : x is woman
• P (x) : x is a parent
• M (x, y): x is mother of y
We have:
∀x((W (x) ∧ P (x)) → ∃yM (x, y))
2.18
Logics (cont.)
Inference
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang, Nguyen
Tien Thinh
Example
week.
• Today is March 8.
• March 8 is such a special day.
• Therefore, if I have a girlfriend,...
• I will eat noodles for a week.
2.19
Logics (cont.)
Propositional Rules of Inferences
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang, Nguyen
Tien Thinh
Rule of Inference Name
p
p→q
∴q Modus ponens
Contents
¬q Predicate Logic
p→q Exercise
∴ ¬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.20
Logics (cont.)
Propositional Rules of Inferences
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang, Nguyen
Tien Thinh
2.21
Logics (cont.)
2.22
Logics (cont.)
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) and (3)
• If we do not go swimming, then Exercise
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.23
Logics (cont.)
Fallacies
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang, Nguyen
Tien Thinh
Definition
Fallacies (ngụy biện) resemble rules of inference but are based on
contingencies rather than tautologies.
Contents
Predicate Logic
Example Exercise
2.24
Logics (cont.)
Rules of Inference for Quantified Statements
Huynh Tuong Nguyen,
Nguyen An Khuong,
Tran Tuan Anh, Le
Hong Trang, Nguyen
Tien Thinh
Predicate Logic
P (c)for an arbitrary c
Universal generalization Exercise
∴ ∀xP (x)
(Tổng quát hóa phổ quát)
∃xP (x)
Existential instantiation
∴ P (c)for some element c
(Cụ thể hóa tồn tại)
P (c)for some element c
Existential generalization
∴ ∃xP (x)
(Tổng quát hóa tồn tại)
2.25
Logics (cont.)
Predicate Logic
Hint Exercise
2.26
Logics (cont.)
2.27
Logics (cont.)
c) p(2) Exercise
d) ∃x, p(x)
e) ∀x, p(x)
2.28
Logics (cont.)
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.29
Logics (cont.)
Provided that: Huynh Tuong Nguyen,
Nguyen An Khuong,
• F (x, y) : x is father of y, Tran Tuan Anh, Le
Hong Trang, Nguyen
• M (x, y) : x is mother of y, Tien Thinh
• 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,
• O(x, y) : x is elder than y. Contents
Predicate Logic
Express each of these statements using predicates: Exercise
2.30
Logics (cont.)
2.31
Logics (cont.)
Predicate Logic
c) ∀x∀y(S(x, m) ∧ B(c, y) → x = y). Exercise
2.32
Logics (cont.)
Predicate Logic
c) ∀x∀y(S(x, m) ∧ B(c, y) → x = y).
Exercise
Whoever is the sister of m, then c is also a brother of that
person.
d) ∃x((S(x, m) ∨ H(c, x)) ∨ ∃x(H(x, m) ∧ O(x, m))).
There is a sister of m or c is her husband, or there is a
husband of m and elder than m.
e) ∀x∀y(S(x, m) ∧ S(y, m) → O(x, y) ∨ O(y, x))
All of the sisters of m are older or younger together.
2.33
Logics (cont.)
Predicate Logic
e) ¬∀xN (x) Exercise
f) ∀x¬N (x)
2.34
Logics (cont.)
a) There is a student who studies in the class over 5 hours in class every
weekday.
b) All of the students in Math class study over 5 hours every weekday.
c) There is a student who does not study in the class over 5 hours every
weekday.
d) There are no student studies in the class over 5 hours every weekday.
2.35
Logics (cont.)
}
return true;
2.36
Logics (cont.)
Hãy cho biết công thức vị từ của đoạn mã giả (pseudo code) sau:
} Exercise
return false;
2.37
Logics (cont.)
if isParent(Peter, kids[y])
match2Found = true;
2.38
Logics (cont.)
2.39
Cho L(x,y) là câu "x yêu y", với không gian của cả x và y là tập Logics (cont.)
hợp mọi người trên thế giới. Hãy dùng các lượng từ để diễn đạt Huynh Tuong Nguyen,
Nguyen An Khuong,
các câu sau Tran Tuan Anh, Le
Hong Trang, Nguyen
a) Mọi người đều yêu Jerry. Tien Thinh
b) Mọi người đều yêu một ai đó.
c) Có một người mà tất cả mọi người đều yêu.
d) Không có ai yêu tất cả mọi người.
e) Có một người mà Lydia không yêu.
f) Có một người mà không ai yêu.
g) Có đúng một người mà tất cả mọi người đều yêu.
h) Có đúng hai người mà Lynn yêu. Contents
i) Mọi người đều yêu chính mình. Predicate Logic
j) Có một người nào đó không yêu ai ngoài chính mình. Exercise
a) ∀xL(x, Jerry)
b) ∀x∃yL(x, y)
c) ∃y∀xL(x, y)
d) ¬(∃x(∀yL(x, y)), ¬(∃x(∧y L(x, y)) hoặc ∀x¬(∧y L(x, y))
e) ∃x¬L(Lydia, x)
f) ∃x∀y¬L(x, y)
g) ∃x(∀yL(x, y) ∧ ∀z((∀wL(w, z)) → z = x))
h) ∃x∃y(x 6= y ∧ L(Lynn, x) ∧ L(Lynn, y) ∧ ∀z(L(Lynn, z) →
(z = x ∨ z = y)))
i) ∀xL(x, x)
j) ∃x∀y(L(x, y) → x = y) 2.40
Logics (cont.)
. -Q(x): "x khó" (theo một tiêu chuẩn được định nghĩa tốt
nào đó).
. -R(x): "x dễ" (theo một tiêu chuẩn được định nghĩa tốt nào
đó - giống như trên).
. -S(x): "x không thể giải được". Contents
Diễn giải những công thức vị từ sau dưới dạng ngôn ngữ tự nhiên Predicate Logic
Exercise
a) ∀x(P (x) → (Q(x) ⇐⇒ ¬R(x)))
b) ∃x(S(x) ∧ ¬P (x))
Vì có nhiều cách diễn đạt một công thức vị từ dưới dạng ngôn
ngữ tự nhiên và sau đây là một cách
a) Nếu x là một vấn đề toán học thì x là bài toán khó tương
đương với x không dễ.
b) Có vấn đề không toán học không thể giải được
2.41
Logics (cont.)
Exercise
d) (∀pB(p) ∧ ∀jQ(j)) → ∃jL(j)
a) Nếu có một máy in nào đó bị hỏng trong khi đang bận in tài liệu thì
chắc chắn sẽ có tài liệu bị mất.
b) Nếu tất cả máy in đều đang bận in tài liệu thì sẽ có tài liệu đang đợi
được in.
c) Nếu một tài liệu đang được đợi in nhưng lại bị mất, chứng tỏ có máy in
nào đó đã bị hỏng.
d) Khi tất cả các máy in đều đang bận in tài liệu khác, mà tất cả các công
việc in vẫn phải chờ, thì sẽ có một việc in nào đó bị mất.
2.42
Logics (cont.)
Chuyển các câu sau sang vị từ, lượng từ và toán tử logic: Huynh Tuong Nguyen,
Nguyen An Khuong,
a) Không có ai là hoàn hảo. Tran Tuan Anh, Le
Hong Trang, Nguyen
Tien Thinh
b) Không phải mọi người đều hoàn hảo.
c) Tất cả bạn bè của bạn đều hoàn hảo.
Predicate Logic
C(x): x là hoàn hảo.
Exercise
D(x): x là bạn của bạn.
E(x): x là bất kỳ người nào khác.
a) ¬∃xC(x)
b) ∃x¬C(x)
c) ∀xD(x) → C(x)
d) ∃x∀y(D(x) ∧ D(y) ∧ (x 6= y)) → C(x) =⇒ ∃y(D(y) → C(y))
e) ∀x(D(x) ∧ C(x))
f) ∀x∃y(D(y) ∧ (y 6= x) ∨ ¬C(y)) =⇒ ¬∀xD(x) ∨ ∃yC(y)
2.43
Logics (cont.)
2.44
Logics (cont.)
Exercise
A) v là anh của w
B) v là cháu trai của w
C) v là chú của w
D) v là ông của w
2.45
Logics (cont.)
Predicate Logic
d) Chỉ vài sinh viên máy tính lập trình tốt. Exercise
e) Không một sinh viên máy tính nào không cần cù.
f) Không phải tất cả các sinh viên máy tính đều thông minh.
g) Tất cả người Pompei hoặc trung thành với Caesar hoặc ghét
ông ta.
h) Mỗi người đều trung thành với một người nào đó.
i) Người ta chỉ muốn ám sát những nhà cầm quyền mà người ta
không trung thành.
2.46