Professional Documents
Culture Documents
Chapter 2 Ngoc Le
Logics (cont.)
Discrete Structures for Computing
Contents
Predicate Logic
Exercise
Contents
1 Predicate Logic Predicate Logic
Exercise
2 Exercise
2.2
Logics (cont.)
Course outcomes
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
2.3
Logics (cont.)
Limits of Propositional Logic
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
Exercise
• All square numbers are not prime numbers. 100 is a square
number. Therefore 100 is not a prime number.
2.4
Logics (cont.)
Predicates
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
A predicate (vị từ) is a statement containing one or more Contents
variables. If values are assigned to all the variables in a predicate, Predicate Logic
Example:
• x > 3 (predicate)
• 5 > 3 (proposition)
• 2 > 3 (proposition)
2.5
Logics (cont.)
Predicates
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
2.6
Logics (cont.)
Truth value
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Contents
• x > 3 is true or false?
Predicate Logic
• 5>3 Exercise
2.7
Logics (cont.)
Quantifiers
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Exercise
• ∃: Existential – Tồn tại
• ∃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.)
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
Example
What is the truth value of the quantification ∃xP (x), where the
domain consists of all real number?
2.9
Logics (cont.)
Example
Express the statement “Some student in this class comes from
Central Vietnam.”
Solution 1 Contents
Predicate Logic
• M (x) = x comes from Central Vietnam
Exercise
• Domain for x is the students in the class
• ∃xM (x)
Solution 2
• Domain for x is all people
• ...
2.10
Logics (cont.)
Negation of Quantifiers
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Predicate Logic
Exercise
Example
2.11
Logics (cont.)
Another Example
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Translate these:
• All lions are fierce.
• Some lions do not drink coffee. Contents
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,
Tran Tuan Anh, Nguyen
Ngoc Le
∀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,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
∀x (C(x) ∨ ∃y (C(y) ∧ F (x, y)) )
Provided that: Contents
Exercise
• F (x, y): x and y are friends,
• x, y ∈ all students in your school.
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,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
∃x∀y∀z (((F (x, y) ∧ F (x, z) ∧ (y 6= z)) → ¬F (y, z)))
Provided that: Contents
Predicate Logic
• F (x, y): x, y are friends
Exercise
• x, y, z ∈ all students in your school.
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,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Predicate Logic
Exercise
Answer
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,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Every people has only one best friend. Contents
Predicate Logic
Exercise
Solution
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,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
If a person is a woman and a parent, then this person is mother of
some one. Contents
Predicate Logic
Solution Exercise
We define:
• 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,
Tran Tuan Anh, Nguyen
Ngoc Le
Example
Predicate Logic
special day, I will surely buy her some expensive gift.
Exercise
• If I buy my girlfriend expensive gifts, I will eat noodles for a
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,
Tran Tuan Anh, Nguyen
Ngoc Le
Predicate Logic
¬q Exercise
p→q
∴ ¬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,
Tran Tuan Anh, Nguyen
Ngoc Le
Predicate Logic
p∧q
Simplification Exercise
∴p
(Rút gọn)
p
q
Conjunction
∴p∧q
(Kết hợp)
p∨q
¬p ∨ r
Resolution
∴q∨r
(Phân giải)
2.21
Logics (cont.)
Predicate Logic
Solution Exercise
• p: It is raining today
• q: We will not have a barbecue today
• r: We will have barbecue tomorrow
p→q
q→r
∴p→r
Hypothetical syllogism
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)
Contents
• We will go swimming (r) only if 3. r → p Hypothesis Predicate Logic
it is sunny Exercise
4. ¬r Modus tollens using (2) and (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.23
Logics (cont.)
Fallacies
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Definition
Fallacies (ngụy biện) resemble rules of inference but are based on
contingencies rather than tautologies. Contents
Predicate Logic
Exercise
Example
If you do correctly every questions in mid-term exam, you will get
10 grade. You got 10 grade.
Therefore, you did correctly every questions in mid-term exam.
Is [(p → q) ∧ q] → p a tautology?
2.24
Logics (cont.)
Rules of Inference for Quantified Statements
Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
Ngoc Le
Exercise
P (c)for an arbitrary c
Universal generalization
∴ ∀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.)
Example
Exercise
Hint
• C(x): x is in this class
• B(x): x has gone to class
• P (x): x passed the first exam
• Premises???
2.26
Logics (cont.)
2.27
Logics (cont.)
Xét vị từ p(x) :00 x2 − 3x + 2 = 000 . Cho biết chân trị các mệnh đề
sau:
a) p(0)
b) p(1)
c) p(2) Contents
Predicate Logic
d) ∃x, p(x) Exercise
e) ∀x, p(x)
a) F
b) T
c) T
d) T
e) F
2.28
Xét vị từ theo 2 biến nguyên dương: p(x, y): “x là ước của y” Logics (cont.)
Hãy xác định chân trị các mệnh đề sau: Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
a) p(2, 3) Ngoc Le
b) p(2, 6)
c) ∀y, p(1, y)
d) ∀x, p(x, x)
Exercise
g) ∀x∀y, (p(x, y) ∧ p(y, x)) → (x = y)
a) F
b) T
c) T
d) T
e) T
f) F
g) T
h) T 2.29
Logics (cont.)
Predicate Logic
Xác định các biểu thức luận lý vị từ để diễn đạt các câu sau Exercise
2.30
Logics (cont.)
Lời giải - Xác định các biểu thức luận lý vị từ để diễn đạt các câu
sau
a) ∃x∃y(S(x, m) ∧ O(x, m) ∧ B(y, m) ∧ ¬O(y, m)).
Contents
b) ∀x(B(x, m) → ¬O(x, m)).
Predicate Logic
c) ∃x∀y H(x, Thuyen) ∧ H(y, Thuyen) → (x = y) Exercise
2.31
Logics (cont.)
Exercise
2.32
Logics (cont.)
bộ sinh viên trong lớp Toán. Hãy phát biểu các vị từ sau:
a) ∃xN (x)
b) ∀xN (x)
c) ¬∃xN (x)
Contents
d) ∃x¬N (x) Predicate Logic
f) ∀x¬N (x)
2.33
Logics (cont.)
Cho vị từ N (x) “x học ở lớp hơn 5 giờ mỗi ngày trong tuần” với
tập vũ trụ là toàn bộ sinh viên trong lớp Toán. Hãy phát biểu các
vị từ sau:
a) ∃xN (x)
Contents
b) ∀xN (x) Predicate Logic
d) ∀x¬N (x)
a) Có một sinh viên học ở lớp hơn 5 giờ mỗi ngày trong tuần.
b) Mọi sinh viên đều học ở lớp hơn 5 giờ mỗi ngày trong tuần.
c) Có một sinh viên không học ở lớp hơn 5 giờ mỗi ngày trong tuần.
d) Không có sinh viên nào học ở lớp hơn 5 giờ mỗi ngày trong tuần.
2.34
Logics (cont.)
Hãy cho biết công thức vị từ của đoạn mã giả (pseudo code) sau:
return false;
}
return true;
2.35
Logics (cont.)
Hãy cho biết công thức vị từ của đoạn mã giả (pseudo code) sau:
Exercise
return true;
}
return false;
2.36
Logics (cont.)
Predicate Logic
//— Now look for a second match Exercise
for (y=0; (y<numKids)&&(y!=x); y++)
if isParent(Peter, kids[y])
match2Found = true;
2.37
Logics (cont.)
2.38
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,
Tran Tuan Anh, Nguyen
các câu sau Ngoc Le
a) Mọi người đều yêu Jerry.
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. Contents
Diễn giải những công thức vị từ sau dưới dạng ngôn ngữ tự nhiên Exercise
2.40
Logics (cont.)
2.41
Logics (cont.)
Chuyển các câu sau sang vị từ, lượng từ và toán tử logic: Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
a) Không có ai là hoàn hảo. Ngoc Le
Exercise
C(x): x là hoàn hảo.
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.42
Logics (cont.)
Predicate Logic
Mệnh đề vị từ nào sau biểu diễn câu : "Mọi chương trình đào tạo
Exercise
nếu có mục tiêu giống một chương trình khác đã đáp ứng chuẩn
ABET và kết quả đầu ra có thể kiểm chứng được thì cũng tuân
theo chuẩn ABET"
A) ∀x(P (x) ∧ ¬Q(x)) → ∃x(R(x))
B) ∀x(∃y(Q(x, y) ∧ P (y) ∧ R(x)) → P (x))
C) ∀x(∃y(Q(x, y) ∧ P (y) ∧ R(x)) → P (x) ∨ R(x))
D) ∀x(∀y(Q(x, y) ∧ P (y) ∨ R(x)) → P (x))
2.43
Logics (cont.)
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.44
Logics (cont.)
a) Khi ổ cứng còn ít hơn 30 GB, một thông điệp cảnh báo sẽ
được gửi tới mọi người dùng.
b) Không được sao lưu hệ thống tập tin nếu có một người nào
đó đang đăng nhập vào hệ thống.
c) Đoạn phim Youtube sẽ được buffer khi còn ít nhất 8 MB bộ Contents
Exercise
d) Chỉ vài sinh viên máy tính lập trình tốt.
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.45