Logics Nguyen An Khuong, Huynh Tuong Nguyen Chapter 1 Logics Contents Propositional Logic Discrete Structures for Computer Science (CO1007) on Ngày 13 tháng 1 năm 2017 Nguyen An Khuong, Huynh Tuong Nguyen Faculty of Computer Science and Engineering University of Technology, VNU-HCM 1.1 Contents Logics Nguyen An Khuong, Huynh Tuong Nguyen Contents Propositional Logic 1 Propositional Logic 1.2 Logic Logics Nguyen An Khuong, Huynh Tuong Nguyen Definition (Averroes) Contents The tool for distinguishing between the true and the false. Propositional Logic Definition (Penguin Encyclopedia) The formal systematic study of the principles of valid inference and correct reasoning. Definition (Discrete Mathematics - Rosen) Rules of logic are used to distinguish between valid and invalid mathematical arguments. 1.3 Applications in Computer Science Logics Nguyen An Khuong, Huynh Tuong Nguyen Contents Propositional Logic • Design of computer circuits • Construction of computer programs • Verification of the correctness of programs • Constructing proofs automatically • Artificial intelligence • Many more... 1.4 Propositional Logic Logics Nguyen An Khuong, Huynh Tuong Nguyen Definition Contents Propositional Logic A proposition is a declarative sentence that is either true or false, but not both. Examples • Hanoi is the capital of Viet Nam. • New York City is the capital of USA. • 1+1=2 • 2+2=3 1.5 Examples Logics Nguyen An Khuong, Huynh Tuong Nguyen Examples (Which of these are propositions?) Contents Propositional Logic • How easy is logic! • Read this carefully. • H1 building is in Ho Chi Minh City. • 4>2 • 2n ≥ 100 • The sun circles the earth. • Today is Thursday. • Proposition only when the time is specified 1.6 Notations Logics Nguyen An Khuong, Huynh Tuong Nguyen Contents Propositional Logic • Propositions are denoted by p, q, . . . • The truth value (”chân trị”) is true (T) or false (F) 1.7 Logics Operators Nguyen An Khuong, Huynh Tuong Nguyen Contents Negation - ”Phủ định”: ¬p Propositional Logic Bảng: Truth Table for Negation p ¬p T F F T 1.8 Logics Operators Nguyen An Khuong, Huynh Tuong Nguyen Conjunction - ”Hội”: p ∧ q “p and q” Disjunction - ”Tuyển”: p ∨ q “p or q” p q p∧q p q p∨q T T F F T F T F T F F F T T F F T F T F T T T F I’m teaching DM1 and it is raining today. Contents Propositional Logic We need students who have experience in Java or C++. Tomorrow, I will eat Pho or Bun bo. 1.9 Logics Operators Nguyen An Khuong, Huynh Tuong Nguyen Contents Exclusive OR - Tuyển loại tru: p⊕q “p or q (but not both)” p q p⊕q T T F F T F T F F T T F Implication - Kéo theo: p → q “if p, then q” p q p→q T T F F T F T F T F T T Propositional Logic If it rains, the pavement will be wet. 1.10 More Expressions for Implication p → q Logics Nguyen An Khuong, Huynh Tuong Nguyen Contents • if p, then q Propositional Logic • p implies q • p is sufficient for q • q if p • p only if q • 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.11 Conditional Statements From p → q Logics Nguyen An Khuong, Huynh Tuong Nguyen Contents Propositional Logic • q → p (converse - đảo) • ¬q → ¬p (contrapositive - phản đảo) • Prove that only contrapositive have the same truth table with p→q 1.12 Logics Nguyen An Khuong, Huynh Tuong Nguyen Exercise Contents What are the converse and contrapositive of the following conditional statement “If he plays online games too much, his girlfriend leaves him.” Propositional Logic • Converse: If his girlfriend leaves him, then he plays online games too much. • Contrapositive: If his girlfriend does not leave him, then he does not play online games too much. 1.13 Logics Biconditionals Nguyen An Khuong, Huynh Tuong Nguyen p↔q “p if and only if q” Contents Propositional Logic p q p↔q T T F F T F T F T F F T • “p is necessary and sufficient for q”. • “if p then q, and conversely”. • “p iff q”. 1.14 Translating Natural Sentences Logics Nguyen An Khuong, Huynh Tuong Nguyen Contents Exercise Propositional Logic I will buy a new phone only if I have enough money to buy iPhone 4 or my phone is not working. • p: I will buy a new phone • q: I have enough money to buy iPhone 4 • r: My phone is working • p → (q ∨ ¬r) 1.15 Translating Natural Sentences Logics Nguyen An Khuong, Huynh Tuong Nguyen Contents Propositional Logic Exercise He will not run the red light if he sees the police unless he is too risky. 1.16 Logics Construct Truth Table Nguyen An Khuong, Huynh Tuong Nguyen Exercise Contents Construct the truth table of the compound proposition (p ∨ ¬q) → (p ∧ q). Propositional Logic p q ¬q p ∨ ¬q p∧q (p ∨ ¬q) → (p ∧ q) T T F F T F T F F T F T T T F T T F F F T F T F 1.17 Applications Logics Nguyen An Khuong, Huynh Tuong Nguyen Contents Propositional Logic • System specifications • “When a user clicked on Help button, a pop-up will be shown up” • Boolean search • type “dai hoc bach khoa” in Google • means “dai AND hoc AND bach AND khoa” 1.18 Applications (cont.) Logics Nguyen An Khuong, Huynh Tuong Nguyen Contents Propositional Logic • Logic puzzles • There are two kinds of inhabitants on an island, knights, who always tell the truth, and their opposites, knaves, who always lie. You encounter two people A and B. What are A and B if A says “B is a knight” and B says ”The two of us are opposite types”? • Bit operations • 101010011 is a bit string of length nine. 1.19 Tautology and Contradiction Logics Nguyen An Khuong, Huynh Tuong Nguyen Definition A compound proposition that is always true (false) is called a tautology (contradiction). Contents Propositional Logic • Tautology: hằng đúng • Contradiction: mâu thuẫn Example • p ∨ ¬p (tautology) • p ∧ ¬p (contradiction) 1.20 Logical Equivalences Logics Nguyen An Khuong, Huynh Tuong Nguyen Contents Propositional Logic Definition The compound compositions φ and ψ are called logically equivalent if φ ↔ ψ is a tautology, denoted φ ≡ ψ. Example Show that ¬(p ∨ q) and ¬p ∧ ¬q are logically equivalent. 1.21 Logics Logical Equivalences Nguyen An Khuong, Huynh Tuong Nguyen Contents p∧T p∨F ≡ ≡ p p Identity laws Luật đồng nhất p∨T p∧F ≡ ≡ T F Domination laws Luật nuốt p∨p p∧p ≡ ≡ p p Idempotent laws Luật lũy đẳng ¬(¬p) ≡ p Double negation law Luât phủ định kép Propositional Logic 1.22 Logics Logical Equivalences Nguyen An Khuong, Huynh Tuong Nguyen p∨q p∧q ≡ ≡ q∨p q∧p (p ∨ q) ∨ r (p ∧ q) ∧ r ≡ ≡ p ∨ (q ∨ r) p ∧ (q ∧ r) Associative laws Luật kết hợp p ∨ (q ∧ r) p ∧ (q ∨ r) ≡ ≡ (p ∨ q) ∧ (p ∨ r) (p ∧ q) ∨ (p ∧ r) Distributive laws Luật phân phối ¬(p ∧ q) ¬(p ∨ q) ≡ ≡ ¬p ∨ ¬q ¬p ∧ ¬q De Morgan’s law Luật De Morgan p ∨ (p ∧ q) p ∧ (p ∨ q) ≡ ≡ p p Commutative laws Luật giao hoán Contents Propositional Logic Absorption laws Luật hút thu 1.23 Logics Logical Equivalences Nguyen An Khuong, Huynh Tuong Nguyen Contents Propositional Logic Equivalence p ∨ ¬p p ∧ ¬p (p → q) ∧ (p → r) (p → r) ∧ (q → r) (p → q) ∨ (p → r) (p → r) ∨ (q → r) p↔q ≡ ≡ ≡ ≡ ≡ ≡ ≡ T F p → (q ∧ r) (p ∨ q) → r p → (q ∨ r) (p ∧ q) → r (p → q) ∧ (q → p) 1.24 Logics Constructing New Logical Equivalences Nguyen An Khuong, Huynh Tuong Nguyen Example Show that ¬(p ∨ (¬p ∧ q)) and ¬p ∧ ¬q are logically equivalent by developing a series of logical equivalences. Contents Propositional Logic Solution ¬(p ∨ (¬p ∧ q)) ≡ ¬p ∧ ¬(¬p ∧ q) by the second De Morgan law ≡ ¬p ∧ [¬(¬p) ∨ ¬q] by the first De Morgan law ≡ ¬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.25