Logics Logics Huynh Tuong Nguyen, Tran Vinh Tan Contents Propositional Logic 1 1 Chapter 1 Logics Discrete Structures for Computing on 13 March 2012 Huynh Tuong Nguyen, Tran Vinh Tan Faculty of Comput[.]
Logics Huynh Tuong Nguyen, Tran Vinh Tan Chapter Logics Discrete Structures for Computing on 13 March 2012 Contents Propositional Logic Huynh Tuong Nguyen, Tran Vinh Tan Faculty of Computer Science and Engineering University of Technology - VNUHCM 1.1 Logics Contents Huynh Tuong Nguyen, Tran Vinh Tan Contents Propositional Logic Propositional Logic 1.2 Logics Logic Huynh Tuong Nguyen, Tran Vinh Tan Definition (Averroes) The tool for distinguishing between the true and the false Contents 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 Logics Applications in Computer Science Huynh Tuong Nguyen, Tran Vinh Tan • Design of computer circuits Contents • Construction of computer programs Propositional Logic • Verification of the correctness of programs • Constructing proofs automatically • Artificial intelligence • Many more 1.4 Logics Propositional Logic Huynh Tuong Nguyen, Tran Vinh Tan Definition A proposition is a declarative sentence that is either true or false, but not both Contents Propositional Logic Examples • Hanoi is the capital of Viet Nam • New York City is the capital of USA • 1+1=2 • 2+2=3 1.5 Logics Examples Huynh Tuong Nguyen, Tran Vinh Tan Examples (Which of these are propositions?) • How easy is logic! Contents • Read this carefully Propositional Logic • 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 Logics Notations Huynh Tuong Nguyen, Tran Vinh Tan 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 Huynh Tuong Nguyen, Tran Vinh Tan Negation - ”Phủ định”: ¬p Contents Propositional Logic Bảng: Truth Table for Negation p ¬p T F F T 1.8 Logics Operators Huynh Tuong Nguyen, Tran Vinh Tan Conjunction - ”Hội”: p ∧ q “p and q” Disjunction - ”Tuyển”: p ∨ q “p or q” Contents Propositional Logic 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 We need students who have experience in Java or C++ Tomorrow, I will eat Pho or Bun bo 1.9 Logics Operators Huynh Tuong Nguyen, Tran Vinh Tan 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” Contents Propositional Logic p q p→q T T F F T F T F T F T T If it rains, the pavement will be wet 1.10 Logics More Expressions for Implication p → q Huynh Tuong Nguyen, Tran Vinh Tan • if p, then q • p implies q Contents • p is sufficient for q Propositional Logic • 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 + = 1.11 Logics Conditional Statements From p → q Huynh Tuong Nguyen, Tran Vinh Tan Contents • q → p (converse - o) Propositional Logic ã ơq ơp (contrapositive - phn đảo) • Prove that only contrapositive have the same truth table with p→q 1.12 Logics Huynh Tuong Nguyen, Tran Vinh Tan Exercise What are the converse and contrapositive of the following conditional statement “If he plays online games too much, his girlfriend leaves him.” Contents 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 Huynh Tuong Nguyen, Tran Vinh Tan p↔q “p if and only if q” Contents p q p→q T T F F T F T F T F F T Propositional Logic • “p is necessary and sufficient for q” • “if p then q, and conversely” • “p iff q” 1.14 Logics Translating Natural Sentences Huynh Tuong Nguyen, Tran Vinh Tan Exercise I will buy a new phone only if I have enough money to buy iPhone or my phone is not working Contents Propositional Logic • p: I will buy a new phone • q: I have enough money to buy iPhone • r: My phone is working ã p (q ơr) 1.15 Logics Translating Natural Sentences Huynh Tuong Nguyen, Tran Vinh Tan 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 Huynh Tuong Nguyen, Tran Vinh Tan Exercise Construct the truth table of the compound proposition (p ∨ ¬q) → (p ∧ q) Contents 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 Logics Applications Huynh Tuong Nguyen, Tran Vinh Tan • System specifications • “When a user clicked on Help button, a pop-up will be shown up” Contents Propositional Logic • Boolean search • type “dai hoc bach khoa” in Google • means “dai AND hoc AND bach AND khoa” 1.18 Logics Applications (cont.) Huynh Tuong Nguyen, Tran Vinh Tan • 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”? Contents Propositional Logic • Bit operations • 101010011 is a bit string of length nine 1.19 Logics Tautology and Contradiction Huynh Tuong Nguyen, Tran Vinh Tan Definition A compound proposition that is always true (false) is called a tautology (contradiction) • Tautology: Contents Propositional Logic • Contradiction: mâu thuẫn Example • p ∨ ¬p (tautology) • p ∧ ¬p (contradiction) 1.20