CS 173 Lecture 2: Propositional Logic

Similar documents
Lecture 2. Logic Compound Statements Conditional Statements Valid & Invalid Arguments Digital Logic Circuits. Reading (Epp s textbook)

Boolean algebra. Examples of these individual laws of Boolean, rules and theorems for Boolean algebra are given in the following table.

COS 140: Foundations of Computer Science

Part I: Propositional Calculus

CSC Discrete Math I, Spring Propositional Logic

Truth-Functional Logic

Computer Organization: Boolean Logic

Compound Propositions

CITS2211 Discrete Structures. Propositional Logic

Topic 1: Propositional logic

2.2: Logical Equivalence: The Laws of Logic

Propositional and Predicate Logic

CSE 311: Foundations of Computing. Lecture 3: Digital Circuits & Equivalence

Propositional Logic: Equivalence

Formal Verification Methods 1: Propositional Logic

Propositional and Predicate Logic

Propositional Equivalence

CISC-102 Winter 2016 Lecture 17

Discrete Structures & Algorithms. Propositional Logic EECE 320 // UBC

Propositional Logic. Spring Propositional Logic Spring / 32

HW1 graded review form? HW2 released CSE 20 DISCRETE MATH. Fall

Announcements. CS311H: Discrete Mathematics. Propositional Logic II. Inverse of an Implication. Converse of a Implication

Review. Propositional Logic. Propositions atomic and compound. Operators: negation, and, or, xor, implies, biconditional.

Tools for reasoning: Logic. Ch. 1: Introduction to Propositional Logic Truth values, truth tables Boolean logic: Implications:

Conjunction: p q is true if both p, q are true, and false if at least one of p, q is false. The truth table for conjunction is as follows.

Unit 8A Computer Organization. Boolean Logic and Gates

THE LOGIC OF COMPOUND STATEMENTS

Unit 1. Propositional Logic Reading do all quick-checks Propositional Logic: Ch. 2.intro, 2.2, 2.3, 2.4. Review 2.9

CSE 311: Foundations of Computing. Lecture 2: More Logic, Equivalence & Digital Circuits

A Primer on Boole s Algebra of Logic for Classes

Logic Propositional logic; First order/predicate logic

COSC 243. Introduction to Logic And Combinatorial Logic. Lecture 4 - Introduction to Logic and Combinatorial Logic. COSC 243 (Computer Architecture)

Digital Logic (2) Boolean Algebra

Discrete Mathematics and Applications COT3100

Propositional logic ( ): Review from Mat 1348

Example. Logic. Logical Statements. Outline of logic topics. Logical Connectives. Logical Connectives

Propositional Logic Basics Propositional Equivalences Normal forms Boolean functions and digital circuits. Propositional Logic.

UC Berkeley College of Engineering, EECS Department CS61C: Representations of Combinational Logic Circuits

XOR - XNOR Gates. The graphic symbol and truth table of XOR gate is shown in the figure.

Propositional Logic. Fall () Propositional Logic Fall / 30

BOOLEAN ALGEBRA INTRODUCTION SUBSETS

EECS 1028 M: Discrete Mathematics for Engineers

ICS141: Discrete Mathematics for Computer Science I

UC Berkeley CS 170: Efficient Algorithms and Intractable Problems Handout 22 Lecturer: David Wagner April 24, Notes 22 for CS 170

EECS 1028 M: Discrete Mathematics for Engineers

CSE 20 Discrete Math. Algebraic Rules for Propositional Formulas. Summer, July 11 (Day 2) Number Systems/Computer Arithmetic Predicate Logic

1 Propositional Logic

Announcements. CS243: Discrete Structures. Propositional Logic II. Review. Operator Precedence. Operator Precedence, cont. Operator Precedence Example

1.3 Propositional Equivalences

CHAPTER 10. Gentzen Style Proof Systems for Classical Logic

Chapter 2: Switching Algebra and Logic Circuits

Unit 4: Computer as a logic machine

Logic As Algebra COMP1600 / COMP6260. Dirk Pattinson Australian National University. Semester 2, 2017

Solutions to Homework I (1.1)

CSCI3390-Lecture 18: Why is the P =?NP Problem Such a Big Deal?

Propositional Logic: Methods of Proof (Part II)

2. The Logic of Compound Statements Summary. Aaron Tan August 2017

Propositional Calculus: Formula Simplification, Essential Laws, Normal Forms

Building a Computer Adder

Logic, Sets, and Proofs

Boolean algebra. Values

Packet #1: Logic & Proofs. Applied Discrete Mathematics

Implementation of Boolean Logic by Digital Circuits

COMP 182 Algorithmic Thinking. Proofs. Luay Nakhleh Computer Science Rice University

MODULE- 07 : FLUIDICS AND FLUID LOGIC

Department of Computer Science & Software Engineering Comp232 Mathematics for Computer Science

Chapter 1, Part I: Propositional Logic. With Question/Answer Animations

Propositional Logic: Part II - Syntax & Proofs 0-0

Section 1.2 Propositional Equivalences. A tautology is a proposition which is always true. A contradiction is a proposition which is always false.

CS61c: Representations of Combinational Logic Circuits

CS1021. Why logic? Logic about inference or argument. Start from assumptions or axioms. Make deductions according to rules of reasoning.

1 Propositional Logic

Adequate set of connectives, logic gates and circuits

Discrete Mathematics and Its Applications

Sample Problems for all sections of CMSC250, Midterm 1 Fall 2014

Introduction to Sets and Logic (MATH 1190)

CprE 281: Digital Logic

CS70 is a course about on Discrete Mathematics for Computer Scientists. The purpose of the course is to teach you about:

Switches: basic element of physical implementations

Propositional Logic: Semantics

Definition 2. Conjunction of p and q

Mathematical Logic Part One

Set Theory Basics of Set Theory. mjarrar Watch this lecture and download the slides

CS 226: Digital Logic Design

CISC-102 Fall 2018 Week 11

Proposition/Statement. Boolean Logic. Boolean variables. Logical operators: And. Logical operators: Not 9/3/13. Introduction to Logical Operators

Logic and Proofs. (A brief summary)

Chapter 4, Logic using Propositional Calculus Handout

More Propositional Logic Algebra: Expressive Completeness and Completeness of Equivalences. Computability and Logic

Chapter 2. Reductions and NP. 2.1 Reductions Continued The Satisfiability Problem (SAT) SAT 3SAT. CS 573: Algorithms, Fall 2013 August 29, 2013

Why Learning Logic? Logic. Propositional Logic. Compound Propositions

Tecniche di Verifica. Introduction to Propositional Logic

Mathematical Logic Part Three

CHAPTER 1. MATHEMATICAL LOGIC 1.1 Fundamentals of Mathematical Logic

Logic: Propositional Logic (Part I)

For all For every For each For any There exists at least one There exists There is Some

1.1 Statements and Compound Statements

EECS150 - Digital Design Lecture 4 - Boolean Algebra I (Representations of Combinational Logic Circuits)

Description Logics. Foundations of Propositional Logic. franconi. Enrico Franconi

Discrete Mathematics and Probability Theory Fall 2012 Vazirani Note 1

Transcription:

CS 173 Lecture 2: Propositional Logic José Meseguer University of Illinois at Urbana-Champaign 1 Propositional Formulas A proposition is a statement that is either true, T or false, F. A proposition usually combines simpler propositions by means of connectives such as AND (^), OR (_), exclusive-or, XOR ( ), NOT ( ), and IMPLIES (ñ). Aristotle (384 322 BC) invented Formal Logic thanks to his insight that the truth value of any proposition only depends on the truth value of its most basic ones and on the form in which they are combined by various connectives, i.e., on its logical form, which is obtained by replacing the basic propositions by propositional variables. For example, the logical form of: is: (pigs fly AND smoke) IMPLIES (fire OR smoke) pp ^ Sq ñ pf _ Sq A proposition so abstracted is called a propositional formula, denoted ϕ, φ, ψ, ϕ 1..., ϕ n,..., which can be precisely defined as follows: Propositional variables, P, Q, X, Y, X 1,..., X n,... are (the most basic) propositional formulas. If ϕ, ϕ 1 are propositional formulas, then: ϕ, ϕ ^ ϕ 1, ϕ _ ϕ 1, ϕ ϕ 1, and ϕ ñ ϕ 1 are propositional formulas. Nothing else is a propositional formula. Using digital electronics we can implement ϕpx 1,..., X n q as a circuit viewing the X 1,..., X n as its input wires and producing then the output ϕpx 1,..., X n q in its output wire. The shape of the circuit ϕpx 1,..., X n q is exactly the logical form of ϕpx 1,..., X n q pictured as a tree, with each connective, ^, _,, and ñ implemented as a gate (or as a small circuit using other gates). This is the way microprocessors having millions of gates are built in hardware to implement a general-purpose computer as, e.g., an Intel chip. 2 Truth Tables and Evaluation of Propositional Formulas Given a propositional formula ϕpx 1,..., X n q and truth values b 1,..., b n, i.e., b i P tt, Fu for i 1,..., n, for its variables X 1,..., X n, then ϕpx 1,..., X n q will evaluate to exactly one truth value. This is Aristotle s insight about logical form.

2 J. Meseguer The truth value of ϕpx 1,..., X n q for any b 1,..., b n can be determined as follows: Variables. For variables X 1,..., X n and truth values b 1,..., b n, then X i evaluates to b i for i 1,..., n, Connectives are evaluated according to the following truth tables (similar to addition and multiplication tables for numbers): AND : X 1 X 2 X 1 ^ X 2 T F F F T F OR : X 1 X 2 X 1 _ X 2 T F T XOR : X 1 X 2 X 1 X 2 T T F T F T NOT : X X T F F T IMPLIES : X 1 X 2 X 1 ñ X 2 T F F F F T Complex Propositions. Evaluate as follows. If for truth values b 1,..., b n for the variables X 1,..., X n, ϕpx 1,..., X n q evaluates to b and ϕ 1 px 1,..., X n q evaluates to b 1, then: ϕ evaluates to b ϕ ^ ϕ 1 evaluates to b ^ b 1 ϕ _ ϕ 1 evaluates to b _ b 1 ϕ ϕ 1 evaluates to b b 1 ϕ ñ ϕ 1 evaluates to b ñ b 1

Propositional Logic 3 according to the above truth tables, where not all variables X 1,..., X n need to appear in both ϕ and ϕ 1. Truth Tables for Complex Propositions. We can build a truth table for any complex proposition by applying above s idea to incrementally build truth tables for its subexpressions. For example, we can define a new connective for if and only if IFF (ô), where, by definition, X 1 ô X 2 is the complex proposition X 1 ô X 2 def px 1 ñ X 2 q ^ px 2 ñ X 1 q as follows: X 1 X 2 X 1 ñ X 2 X 2 ñ X 1 X 1 ô X 2 T T T F F T F F F F T Note that the truth table for X 1 ô X 2 is exactly the identity predicate on truth values, that is, b ô b 1 T if b b 1, and b ô b 1 F if b b 1. Therefore, if for truth values b 1,..., b n, ϕpx 1,..., X n q evaluates to b and ϕpx 1,..., X n q evaluates to b 1, then ϕ ô ϕ 1 evaluates to b b 1. Viewed as an electronic circuit, X 1 ô X 2 is a circuit that can be used to check whether the circuits for ϕ and ϕ 1 produce the same output value for all inputs. This will happen exactly when ϕ ô ϕ 1 produces the value T for all inputs. We then say that ϕ and ϕ 1 are equivalent as formulas, and therefore as circuits, so that we can replace one by the other as equivalent components in a hardware design. This is further explained in what follows. 3 Tautologies, Falsities, and Equivalences Tautologies and Falsities. A formula ϕ is called a tautology if it is true for all inputs, that is, if for all truth values b 1,..., b n, ϕpx 1,..., X n q evaluates to T. Equivalently, ϕpx 1,..., X n q is a tautology if its truth table is true for all inputs. Tautologies are exactly the formulas that are logically true in all circumstances. A formula ϕ is called a falsity if it is false for all inputs, that is, if for all truth values b 1,..., b n, ϕpx 1,..., X n q evaluates to F. Equivalently, ϕpx 1,..., X n q is a falsity if its truth table is false for all inputs. Falsities are exactly the formulas that are logically false in all circumstances. Note the important facts that: ϕ is a tautology iff ϕ is a falsity, and ϕ is a falsity iff ϕ is a tautology. Equivalences. An equivalence is a tautology of the form ϕ ô ψ. But recall that the truth table of ô is the identity function. Therefore, ϕ ô ψ is a tautology if and only if for truth values b 1,..., b n of their input variables 1 X 1,..., X n ϕpx 1,..., X n q and ϕ 1 px 1,..., X n q evaluate to the same truth value b P tt, Fu. If ϕ ô ψ is a tautology then we write: ϕ ψ and call it an equivalence. 1 Some of those variables may not appear in either ϕ or ψ. The X 1,..., X n are the variables appearing in either ϕ or ψ (or both).

4 J. Meseguer If we view ϕ and ψ as digital circuits, then ϕ ψ exactly means that we can replace the circuit ϕ by the circuit ψ, or viceversa (perhaps inside any bigger circuit) without changing the behavior of the circuit. Also, if we view ô as a circuit, we can use it to check that ϕ and ψ are equivalent circuits by connecting the output wires of ϕ, and ψ into the inputs of ô and then checking that the output of the combined circuit ϕ ô ψ is T for all inputs. Tautologies and Falsities as Equivalences. We have three related notions: tautology, falsity, and equivalence as a special kind of tautology. Can we reduce these three notions to just one? Yes! Just to the notion of equivalence, as follows: ϕ is a tautology if and only if ϕ T ϕ is a falsity if and only if ϕ F The Algebra of Equivalences. Recall that the meaning of ô is just equality. Therefore, we should think of an equivalence ϕ ô ψ an algebraic law ϕ ψ that holds for Propositional Algebra (also called Boolean Algebra after its inventor George Boole in the 19 th Century), the same way the arithmetic laws hold for ordinary algebra. In fact, if we think of _ as `, ^ as, T as 1, and F as 0, we see that many laws (though not all) are the same. For example distributivity: X py ` Xq px Y q ` px Zq versus X ^ py _ Xq px ^ Y q _ px ^ Zq. Boolean Algebra Laws. The following are very useful equivalences in Boolean Algebra, which can be proved by checking that they are tautologies building their truth table (do it for a couple of them to convince yourself): 1. Commutativity of _ and ^: X _ Y Y _ X and X ^ Y Y ^ X. 2. Associativity of _ and ^: px _ Y q _ Z X _ py _ Zq and X ^ py ^ Zq X ^ py ^ Zq. 3. Identity Laws for _ and ^: X _ F X and X ^ T X. 4. Collapse Laws for _ and ^: X _ T T and X ^ F F. 5. Idempotency Laws for _ and ^: X _ X X and X ^ X X. 6. Distributivity of ^ over _: X ^ py _ Zq px ^ Y q _ px ^ Zq. 7. Distributivity of _ over ^: X _ py ^ Zq px _ Y q ^ px _ Zq. 8. Absorption Laws for _ and ^: X _ px ^ Y q X and X ^ px _ Y q X. 9. Double Negation: X X. 10. Principle of Contradiction: X ^ X F. 11. Law of Excluded Middle: X _ X T.

Propositional Logic 5 12. De Morgan s Laws for _ and ^: px _ Y q p Xq ^ p Y q and px ^ Y q p Xq _ p Y q. Expressing All Connectives in Terms of _ and ^. We can express all other connectives in terms of _ and ^ by means of the following very useful equivalences, which can be checked by building the associated truth tables: X Y px _ Y q ^ px ^ Y q X ñ Y p Xq _ Y X ô Y pp Xq _ Y q ^ p py q _ Xq. Proving Equivalences vs. Building Truth Tables. How can we convince ourselves that a formula ϕ ô ψ is in fact an equivalence ϕ ψ? We have two ways: (1) We can settle the matter by checking that ϕ and ψ have the same truth table. But this is tedious for humans, although easy to write a program to check it, so that we can automatically decide whether any equivalence holds or not. 2 (2) Alternatively, an often easier way is to use the above equivalences (1) (12) as algebraic laws as we do in ordinary algebra by replacing equals for equals. In this way, it is often much easier to obtain new equivalences. In fact, the above laws (1) (12) are enough to prove all equivalences algebraically. Of course, as in ordinary algebra, we can also use equivalences that we have already proved as lemmas when proving other equivalences. Here is a simple example on deriving the so-called Law of Contrapositive, X ñ Y p Y q ñ p Xq, which we will use in writing proofs by contrapositive: X ñ Y p Xq _ Y p Xq _ p Y q p Y q _ p Xq p Y q ñ p Xq. where we have used Double Negation for the second step, and Commutativity of _ for the third, together with the equivalence X ñ Y p Xq _ Y (twice) as a lemma. 2 A naive program will be very inefficient, because the problem of checking equivalence is a so-called NP-Complete problem that has an exponential blowup on the size of the formula. This means that for formulas with many propositional variables the program will easily get bogged down and take forever. Even though NP-completeness is an intrinsic difficulty of the problem, much more efficient programs called SATsolvers that can often efficiently handle formulas with thousands of variables are now routinely used for this purpose in many applications (e.g., hardware design).