Download as pdf or txt
Download as pdf or txt
You are on page 1of 41

Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen

Chapter 1
An Khuong, Le Hong
Trang

Logics
Discrete Structures for Computing on August 27, 2021

Contents
Propositional Logic
Logical Equivalences
Exercise

Huynh Tuong Nguyen, Tran Tuan Anh, Nguyen An Khuong, Le


Hong Trang
Faculty of Computer Science and Engineering
University of Technology - VNUHCM
trtanh@hcmut.edu.vn - htnguyen@hcmut.edu.vn
1.1
Contents
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

1 Propositional Logic
Contents
Propositional Logic
Logical Equivalences
2 Logical Equivalences Exercise

3 Exercise

1.2
Course outcomes
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Course learning outcomes


L.O.1 Understanding of logic and discrete structures
L.O.1.1  Describe definition of propositional and predicate logic
L.O.1.2  Define basic discrete structures: set, mapping, graphs

L.O.2 Represent and model practical problems with discrete structures Contents
L.O.2.1  Logically describe some problems arising in Computing Propositional Logic
L.O.2.2  Use proving methods: direct, contrapositive, induction Logical Equivalences
L.O.2.3  Explain problem modeling using discrete structures Exercise

L.O.3 Understanding of basic probability and random variables


L.O.3.1  Define basic probability theory
L.O.3.2  Explain discrete random variables

L.O.4 Compute quantities of discrete structures and probabilities


L.O.4.1  Operate (compute/ optimize) on discrete structures
L.O.4.2  Compute probabilities of various events, conditional
ones, Bayes theorem

1.3
Logic
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Definition (Averroes)

The tool for distinguishing between the true and the false.

Contents
Definition (Penguin Encyclopedia) Propositional Logic
Logical Equivalences
The formal systematic study of the principles of valid inference Exercise
and correct reasoning.

Definition (Discrete Mathematics - Rosen)

Rules of logic are used to distinguish between valid and invalid


mathematical arguments.

1.4
Applications in Computer Science
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

• Design of computer circuits

• Construction of computer programs Contents


Propositional Logic
• Verification of the correctness of programs
Logical Equivalences
• Constructing proofs automatically Exercise

• Artificial intelligence

• Many more...

1.5
Propositional Logic
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Definition

A proposition is a declarative sentence that is either true or false,


but not both. Contents
Propositional Logic
Examples Logical Equivalences
Exercise
• Hanoi is the capital of Vietnam.

• New York City is the capital of USA.

• 1+1=2
• 2+2=3

1.6
Examples
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Examples (Which of these are propositions?)

• How easy is logic!

• Read this carefully. Contents


Propositional Logic
• H1 building is in Ho Chi Minh City.
Logical Equivalences
• 4>2 Exercise

• 2n ≥ 100
• The Sun circles the Earth.
• Today is Thursday.
• Proposition only when the time is specified

1.7
Notations
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents
• Propositions are denoted by p, q, . . . Propositional Logic
Logical Equivalences
• The truth value (ch¥n trà) is true (T) or false (F)
Exercise

1.8
Operators
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Negation - Phõ ành: ¬p


Contents
Propositional Logic
B£ng: Truth Table for Negation
Logical Equivalences
Exercise
p ¬p
T F
F T

1.9
Operators
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Conjunction - Hëi: p∧q Disjunction - Tuyºn: p∨q


 p and q  p or q
Contents
p q p∧q p q p∨q Propositional Logic
Logical Equivalences
T T T T T T
Exercise
T F F T F T
F T F F T T
F F F F F F

I'm teaching DM1 and it is We need students who have


raining today. experience in Java or C++.
Tomorrow, I will eat Pho or Bun
bo.

1.10
Operators
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Exclusive OR - Tuyºn lo¤i : p⊕q Implication - K²o theo : p→q


 p or q (but not both) if p, then q
Contents
Propositional Logic
p q p⊕q p q p→q Logical Equivalences
Exercise
T T F T T T
T F T T F F
F T T F T T
F F F F F T

If it rains, the pavement will be


wet.

1.11
More Expressions for Implication p → q
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

• if p, then q
• p implies q
Contents
• p is sufficient for q
Propositional Logic
• q if p Logical Equivalences
• p only if q Exercise

• q unless ¬p
• If you get 100% on the final, you will get 10 grade.

• If you feel asleep this afternoon, then 2 + 3 = 5.

1.12
Conditional Statements From p → q
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

• q → p (converse - £o ) Contents


Propositional Logic
• ¬q → ¬p (contrapositive - ph£n £o )
Logical Equivalences
• Prove that only contrapositive have the same truth table with Exercise
p→q

1.13
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Exercise

What are the converse and contrapositive of the following


conditional statement
Contents
If he plays online games too much, his girlfriend leaves him.
Propositional Logic
Logical Equivalences
• Converse: If his girlfriend leaves him, then he plays online Exercise
games too much.

• Contrapositive: If his girlfriend does not leave him, then he


does not play online games too much.

1.14
Biconditionals
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

p↔q
 p if and only if q

p q p↔q Contents
Propositional Logic
T T T
Logical Equivalences
T F F
Exercise
F T F
F F T

•  p is necessary and sufficient for q .


• if p then q , and conversely.
• p iff q .

1.15
The order of operators
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

• 1. in the bracket()
Contents
• 2. negation ¬ Propositional Logic
• 3. ∨, ∧, ⊕ Logical Equivalences
Exercise
• 4. →
• 5. ↔

1.16
Translating Natural Sentences
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Exercise

I will buy a new phone only if I have enough money to buy iPhone
Contents
4 or my phone is not working.
Propositional Logic
Logical Equivalences
• p: I will buy a new phone
Exercise
• q: I have enough money to buy iPhone 4

• r: My phone is working

• p → (q ∨ ¬r)

1.17
Translating Natural Sentences
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Contents
Exercise
Propositional Logic
He will not run the red light if he sees the police unless he is too Logical Equivalences
risky. Exercise

1.18
Construct Truth Table
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Exercise

Construct the truth table of the compound proposition


(p ∨ ¬q) → (p ∧ q).
Contents
Propositional Logic
Logical Equivalences
p q ¬q p ∨ ¬q p∧q (p ∨ ¬q) → (p ∧ q) Exercise

T T F T T T
T F T T F F
F T F F F T
F F T T F F

1.19
Exercise - Truth table
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

¬p → (¬q ∨ r)

p q r ¬p ¬q ¬q ∨ r ¬p → (¬q ∨ r)
T T T F F T T
T T F F F F T
T F T F T T T
T F F F T T T
Contents
F T T T F T T
F T F T F F F Propositional Logic
F F T T T T T Logical Equivalences
F F F T T T T
Exercise

a) (p ∧ q) → ¬q
b) (p ∨ r) → (r ∨ ¬p)
c) (p → q) ∨ (q → p)
d) (p ∨ ¬q) ∧ (¬p ∨ q)
e) (p → ¬q) ∨ (q → ¬p)
f) ¬(¬p ∧ ¬q)
g) (p ∨ q) → (p ⊕ q)
h) (p ∧ q) ∨ (r ⊕ q)

1.20
Applications
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

• System specifications
Contents
• When a user clicked on Help button, a pop-up will be shown Propositional Logic
up
Logical Equivalences
• Boolean search Exercise
• type dai hoc bach khoa in Google
• means dai AND hoc AND bach AND khoa

1.21
Applications (cont.)
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

• Logic puzzles
• There are two kinds of inhabitants on an island, knights, who Contents
always tell the truth, and their opposites, knaves, who may Propositional Logic
lie. You encounter two people A and B . What are A and B if Logical Equivalences
A says  B is a knight and B says The two of us are Exercise
opposite types ?
• Bit operations
• 101010011 is a bit string of length nine.

1.22
Tautology and Contradiction
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Definition

A compound proposition that is always true (false) is called a


tautology - h¬ng óng (contradiction - h¬ng sai).
Contents
• Tautology: h¬ng óng
Propositional Logic
• Contradiction: m¥u thu¨n Logical Equivalences
Exercise

Example

• p ∨ ¬p (tautology)

• p ∧ ¬p (contradiction)

1.23
Question
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Which of the following is a tautology


Hint: Apply truth table.

a) (p ∨ q) → (p ∧ q) Contents
Propositional Logic
b) (p ∧ q) → (p ∨ q) Logical Equivalences
c) p → (¬q → p) Exercise

d) p → (p → q)
e) p → (p → p)
f) (p → q) → [(p → r) → (q → r)]

1.24
Proposition? Truth value?
Logics

Huynh Tuong Nguyen,

a) Fansipan is the highest mountain in Vietnam. Tran Tuan Anh, Nguyen


An Khuong, Le Hong
b) Two coprime numbers have the only common divisor of 1. Trang

c) The product of 3 continuous integers is divisible by 3.

d) Stand up!

e) x+1=0

f) Hexagons have 8 vertices.

g) 0 is a positive number.

h) The equation: x2 + 5x + 6 = 0 has no root. Contents


i) is 2 a prime number? Propositional Logic
j) The equation mx2 + 2x − 1 = 0 has a single root if and only if m=-1. Logical Equivalences
k) There is a prime that is even. Exercise
2
l) x + 1 > 0.
m) When will our class go camping?

n) Mercury is not a metal.


20
o)  3 > 230 .
p) Airplanes are the fastest transport.

q) 2002 is a leap year.

r) There are infinite prime numbers.


10
s) 2 −1 is divisible by 11.

t) No smoking in public place.

u) All even positive integer is a summation of 2 prime numbers.

v)  x is a prime number if it doesn't have any divisor other than 1 and x.
1.25
Logical Equivalences
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Definition
Contents
The compound compositions p andq are called logically equivalent
Propositional Logic
if p↔q is a tautology, denoted p ≡ q. Logical Equivalences
Exercise
Example

Show that ¬(p ∨ q) and ¬p ∧ ¬q are logically equivalent.

1.26
Logical Equivalences
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

p∧T ≡ p Identity laws


p∨F ≡ p Luªt çng nh§t
Contents
p∨T ≡ T Domination laws
Propositional Logic
p∧F ≡ F Luªt nuèt Logical Equivalences
Exercise
p∨p ≡ p Idempotent laws
p∧p ≡ p Luªt lôy ¯ng

¬(¬p) ≡ p Double negation law


Lu¥t phõ ành k²p

1.27
Logical Equivalences
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

p∨q ≡ q∨p Commutative laws


p∧q ≡ q∧p Luªt giao ho¡n

(p ∨ q) ∨ r ≡ p ∨ (q ∨ r) Associative laws
Contents
(p ∧ q) ∧ r ≡ p ∧ (q ∧ r) Luªt k¸t hñp Propositional Logic
Logical Equivalences
p ∨ (q ∧ r) ≡ (p ∨ q) ∧ (p ∨ r) Distributive laws
Exercise
p ∧ (q ∨ r) ≡ (p ∧ q) ∨ (p ∧ r) Luªt ph¥n phèi

¬(p ∧ q) ≡ ¬p ∨ ¬q De Morgan's law


¬(p ∨ q) ≡ ¬p ∧ ¬q Luªt De Morgan

p ∨ (p ∧ q) ≡ p Absorption laws
p ∧ (p ∨ q) ≡ p Luªt hót thu

1.28
Logical Equivalences
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Equivalence

p ∨ ¬p ≡ T
p ∧ ¬p ≡ F Contents

p→q ≡ ¬p ∨ q Propositional Logic


Logical Equivalences
(p → q) ∧ (p → r) ≡ p → (q ∧ r)
Exercise
(p → r) ∧ (q → r) ≡ (p ∨ q) → r
(p → q) ∨ (p → r) ≡ p → (q ∨ r)
(p → r) ∨ (q → r) ≡ (p ∧ q) → r
p↔q ≡ (p → q) ∧ (q → p)
p↔q ≡ (¬p ∨ q) ∧ (p ∨ ¬q)

1.29
Constructing New Logical Equivalences
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Example

Show that ¬(p ∨ (¬p ∧ q)) and ¬p ∧ ¬q are logically equivalent by


developing a series of logical equivalences.

Solution
Contents
Propositional Logic
¬(p ∨ (¬p ∧ q)) ≡ ¬p ∧ ¬(¬p ∧ q) by the second De Morgan law
Logical Equivalences
≡ ¬p ∧ [¬(¬p) ∨ ¬q] by the first De Morgan law Exercise

≡ ¬p ∧ (p ∨ ¬q) by the double negation law

≡ (¬p ∧ p) ∨ (¬p ∧ ¬q) by the second distributive law

≡ F ∨ (¬p ∧ ¬q) because ¬p ∧ p ≡ F

≡ ¬p ∧ ¬q by the identity law for F

Consequently, ¬(p ∨ (¬p ∧ q)) and ¬p ∧ ¬q are logically equivalent.

1.30
Exercise
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Negate the following proposition and try to simplify it.

Example

p → (¬q ∧ r)
By using the truth table, we can prove that p→q and ¬p ∨ q are
Contents
logical equivalence.
Propositional Logic
Negate: ¬(p → (¬q ∧ r)) Logical Equivalences
≡ ¬(¬p ∨ (¬q ∧ r)) Exercise
≡ p ∧ ¬(¬q ∧ r)
≡ p ∧ (q ∨ ¬r)

a) p ∧ (q ∨ r) ∧ (¬p ∨ ¬q ∨ r)
b) (p ∧ q) → r
c) p ∨ q ∨ (¬p ∧ ¬q ∧ r)
d) [[[(p ∧ q) ∧ r] ∨ [(p ∧ r) ∧ ¬r]] ∨ ¬q] → s

1.31
Exercise
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Prove the following proposition are logical equivalence.


Hint: Apply truth table or the series of logical equivalences.

a) ¬(p ↔ q) v  ¬p ↔ q Contents
Propositional Logic
b) (p → q) ∧ (p → r) v  p → (q ∧ r) Logical Equivalences
c) (p → r) ∧ (q → r) v  (p ∨ q) → r Exercise

d) (p → q) ∨ (p → r) v  p → (q ∨ r)
e) ¬p → (q → r) v  q → (p ∨ r)
f) p↔q v  (p → q) ∧ (q → p)

1.33
Exercise
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

The following proposition are logical equivalence? Prove it or give


an example?

a) p ∧ (p → q) v  p∧q Contents
b) p→q v  ¬p ∨ (p ∧ q) Propositional Logic
Logical Equivalences
c) p→q v  ¬p ∨ ¬q
Exercise
d) ¬p v  ¬(p ∨ q) ∨ (¬p ∧ q)
e) [(p ↔ q) ∧ (q ↔ r) ∧ (r ↔ p)] v 
[(p → q) ∧ (q → r) ∧ (r → p)]
f) [(p ∧ q) ∨ (q ∧ r) ∨ (r ∧ p)] v  [(p ∨ q) ∧ (q ∨ r) ∧ (r ∨ p)]

1.34
Exercise
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Determine the truth value and find the contrapositions as well as


the contradictions of the following propositions.
a) If ABCD is a rectangle, AB and CD are perpendicular.

b) If 14 is an odd number, 15 is divisible by 4.


Contents
c) Two equal triangles have the same area.
2 Propositional Logic
d) If the quadratic equation ax + bx + c = 0 has a.c < 0, it has root.
Logical Equivalences
e) If two numbers x and y are both divisible by n, (x + y) is also divisible by n.
Exercise
f) If 45 ended with 5, 45 is divisible by 5.
√ √ √
g) If 2 is an irrational number then 2. 2 is an irrational number.

h) If Pythagoras is French, Vietnam belongs to Asia.

i) If 3n + 2 is an odd integer, n is an odd integer.

j) If 8 < 9, 5 is a prime number.

k) A quadrilateral is a rhombus when it has 2 perpendicular diagonals.

l) If 5 < 3, 7 is a prime number.

1.36
Exercise
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang
Let p and q be:

• p: "Brandon likes reading"

• q: "Brandon is a good student"

The statement that formalize "If Brandon likes reading, Brandon


is a good student, vice versa, If Brandon is a good student,
Contents
Brandon like reading" is: Propositional Logic
Logical Equivalences
Exercise

A) (p ∧ q) → r
B) p→q
C) p∨q
D) p∧q
E) p↔q
F) ¬p → ¬q
G) ¬p ∨ (p ∧ q)
H) None of the others.
1.38
Exercise
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
Let P , Q, R be: An Khuong, Le Hong
Trang

• P: Potter is studying Math.

• Q: Potter is studying Computer science.

• R: Potter is studying English.

Formalize the following statement using the propositional


connectives. Contents
Propositional Logic
Example
Logical Equivalences
Potter is studying Math and English but not Computer science: Exercise
P ∧ R ∧ ¬Q

a) Potter is studying Math and Computer science but not


Computer science and English at the same time.

b) It is not true that Potter is studying English and not Math.

c) It is not true that Potter is studying English or Computer


science and not Math.

d) Potter is not studying both Computer science and English but


is studying Math.
1.39
Exercise
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Determine the wrong statement among the following.

a) x ∈ {x}
b) {x} ⊆ {x}
c) {x} ∈ {x} Contents
d) {x} ∈ {{x}} Propositional Logic
Logical Equivalences
e) ∅ ⊆ {x} Exercise

A) a
B) b
C) c
D) d
E) none of the others.

1.40
Exercise
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

Which of the following proposition is a truth.


Contents
A) (p ∨ ¬q) → q Propositional Logic

B) p → (p ∧ q) Logical Equivalences
Exercise
C) ¬p → (p → q)
D) ¬(p → q) → q
E) none of the others.

1.41
Exercise
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen

Let's consider a propositional language where: An Khuong, Le Hong


Trang

• p:  ABC is an isosceles triangle .

• q :  ABC is an equilateral triangle .

• r:  ABC has a 60o angle .

Contents
Propositional Logic
Which of the following compounds formalize the theorem: if Logical Equivalences
ABC is an isosceles triangle and has a 60o angle then it is an Exercise
equilateral triangle ?

A) (p ∧ q) → r
B) (p ∧ r) → q
C) (p ∧ r) ∨ q
D) q → (p ∨ r)
E) none of the others.

1.42
Exercise
Logics

Huynh Tuong Nguyen,


Tran Tuan Anh, Nguyen
An Khuong, Le Hong
Trang

There are 6 soccer teams A, B, C, D, E, F contested in a


tournament. The following are statements on which two teams are
in the grand final:
Contents
a. A and C
Propositional Logic
b. B and E Logical Equivalences
Exercise
c. B and F

d. A and F

e. A and D

Knowing that there are 4 half true statements and 1 totally false
statement. What teams are in the grand final?

1.43
Exercise Logics

Find the truth values of the following statements (with brief Huynh Tuong Nguyen,
Tran Tuan Anh, Nguyen
explanations): An Khuong, Le Hong
Trang

a)  ∀x ∈ N, x2 + 5x + 6 is not a prime number.

b)  ∃x ∈ R, x2 + x + 1 ≤ 0
c)  ∃n ∈ N, (n3 − n) is not a multiple of 3.

d)  ∀n ∈ N ∗, n2 − 1 is a multiple of 3.

e)  ∀x, ∀y ∈ R, x2 + y 2 > 2xy 


f)  ∃r ∈ Q, 3 < r < π 
Contents
g)  ∃n ∈ N, n2 + 1 divisible by 8
Propositional Logic
h)  ∀x ∈ R, |x| < 3 ⇔ x2 < 9 Logical Equivalences
i)  ∃a, b ∈ R, (a + b)2 > 2(a2 + b2 ) Exercise
j) All real numbers are positive.

k) There is a liquid metal.

l) All equilateral triangles are equal.

m) All gases are non-conductive.

n) There exist quadrilaterals which don't have circumcircles.

o) There is a natural number n that, for all real numbers x, we have


f (x) = x2 − 2x + n is not negative.
p) For all positive integers x and y we have x ≤ y .
q) For all positive integers x, there is a positive integer y so that x ≤ y .
r) There is a positive integer x that, for all positive integers y, we have x ≤ y .
s) There exist positive integers x and y so that x ≤ y .
1.45

You might also like