Comp487/587 - Boolean Formulas

Similar documents
Tecniche di Verifica. Introduction to Propositional Logic

A brief introduction to Logic. (slides from

Propositional Logic: Models and Proofs

Part 1: Propositional Logic

CS156: The Calculus of Computation

Lecture 9: The Splitting Method for SAT

Conjunctive Normal Form and SAT

The Calculus of Computation: Decision Procedures with Applications to Verification. Part I: FOUNDATIONS. by Aaron Bradley Zohar Manna

Conjunctive Normal Form and SAT

Propositional Calculus: Formula Simplification, Essential Laws, Normal Forms

ECE473 Lecture 15: Propositional Logic

Conjunctive Normal Form and SAT

Knowledge base (KB) = set of sentences in a formal language Declarative approach to building an agent (or other system):

Automated Program Verification and Testing 15414/15614 Fall 2016 Lecture 2: Propositional Logic

Solvers for the Problem of Boolean Satisfiability (SAT) Will Klieber Aug 31, 2011

Propositional and Predicate Logic - II

CS156: The Calculus of Computation Zohar Manna Autumn 2008

Warm-Up Problem. Is the following true or false? 1/35

A Collection of Problems in Propositional Logic

PROPOSITIONAL LOGIC. VL Logik: WS 2018/19

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

Propositional Logic and Semantics

CS 512, Spring 2017, Handout 10 Propositional Logic: Conjunctive Normal Forms, Disjunctive Normal Forms, Horn Formulas, and other special forms

Propositional and First Order Reasoning

Lecture #14: NP-Completeness (Chapter 34 Old Edition Chapter 36) Discussion here is from the old edition.

Lecture 2 Propositional Logic & SAT

Equivalences. Proposition 2.8: The following equivalences are valid for all formulas φ, ψ, χ: (φ φ) φ. Idempotency Idempotency Commutativity

Supplementary exercises in propositional logic

LOGIC PROPOSITIONAL REASONING

Logic. Introduction to Artificial Intelligence CS/ECE 348 Lecture 11 September 27, 2001

CSE 555 HW 5 SAMPLE SOLUTION. Question 1.

Propositional Logic Part 1

Propositional Logic. Testing, Quality Assurance, and Maintenance Winter Prof. Arie Gurfinkel

Introduction to Artificial Intelligence Propositional Logic & SAT Solving. UIUC CS 440 / ECE 448 Professor: Eyal Amir Spring Semester 2010

NP and Computational Intractability

Solutions to Homework I (1.1)

Exercises 1 - Solutions

Foundations of Artificial Intelligence

Lecture 3: Semantics of Propositional Logic

Propositional Logic: Evaluating the Formulas

Propositional Logic. Methods & Tools for Software Engineering (MTSE) Fall Prof. Arie Gurfinkel

COMP219: Artificial Intelligence. Lecture 20: Propositional Reasoning

Logic: Propositional Logic (Part I)

7. Propositional Logic. Wolfram Burgard and Bernhard Nebel

3 Propositional Logic

Propositional Logic Language

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

COMP9414: Artificial Intelligence Propositional Logic: Automated Reasoning

Maximum 3-SAT as QUBO

Classes of Boolean Functions

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

Reasoning with Quantified Boolean Formulas

Non-Deterministic Time

Substitution Theorem. Equivalences. Proposition 2.8 The following equivalences are valid for all formulas φ, ψ, χ: (φ φ) φ Idempotency

CSE507. Introduction. Computer-Aided Reasoning for Software. Emina Torlak courses.cs.washington.edu/courses/cse507/17wi/

Decision Procedures for Satisfiability and Validity in Propositional Logic

Learning Goals of CS245 Logic and Computation

Foundations of Artificial Intelligence

Foundations of Artificial Intelligence

02 Propositional Logic

Complexity Theory VU , SS The Polynomial Hierarchy. Reinhard Pichler

Outline. Complexity Theory EXACT TSP. The Class DP. Definition. Problem EXACT TSP. Complexity of EXACT TSP. Proposition VU 181.

NP-Complete Problems. Complexity Class P. .. Cal Poly CSC 349: Design and Analyis of Algorithms Alexander Dekhtyar..

Branching. Teppo Niinimäki. Helsinki October 14, 2011 Seminar: Exact Exponential Algorithms UNIVERSITY OF HELSINKI Department of Computer Science

Propositional Resolution Part 1. Short Review Professor Anita Wasilewska CSE 352 Artificial Intelligence

Logic as a Tool Chapter 1: Understanding Propositional Logic 1.1 Propositions and logical connectives. Truth tables and tautologies

Formal Verification Methods 1: Propositional Logic

CSCE 222 Discrete Structures for Computing. Propositional Logic. Dr. Hyunyoung Lee. !!!!!! Based on slides by Andreas Klappenecker

Logic and Inferences

INF3170 Logikk Spring Homework #8 For Friday, March 18

Part 1: Propositional Logic

1 Propositional Logic

Propositional logic. First order logic. Alexander Clark. Autumn 2014

Advanced Topics in LP and FP

NP-Complete problems

Advanced Topics in Theoretical Computer Science

Deductive Systems. Lecture - 3

Lecture 4: Proposition, Connectives and Truth Tables

Inference in Propositional Logic

2.5.2 Basic CNF/DNF Transformation

Limitations of Algorithm Power

Title: Logical Agents AIMA: Chapter 7 (Sections 7.4 and 7.5)

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.

Introduction to Theoretical Computer Science

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

Language of Propositional Logic

Introduction to Artificial Intelligence. Logical Agents

Critical Reading of Optimization Methods for Logical Inference [1]

Reduced Ordered Binary Decision Diagrams

Solutions to Sample Problems for Midterm

Intro to Theory of Computation

Foundations of Artificial Intelligence

SAT Solvers: Theory and Practice

A Lower Bound of 2 n Conditional Jumps for Boolean Satisfiability on A Random Access Machine

Truth-Functional Logic

Introduction to Solving Combinatorial Problems with SAT

Propositional logic. Programming and Modal Logic

Classical Propositional Logic

NP Complete Problems. COMP 215 Lecture 20

Transcription:

Comp487/587 - Boolean Formulas 1 Logic and SAT 1.1 What is a Boolean Formula Logic is a way through which we can analyze and reason about simple or complicated events. In particular, we are interested in Boolean logic in which we simplify the events to be either 0 or 1, true or false. This strong simplification allows us to actually reason about the events, things that we cannot do with more complicated logics. One of the formal way to do this is to take atomic events, or propositions, that can each be true or false. From these we can construct a more complicated formula through operations like and or or. 1.2 Syntax of Boolean Formulas Symbolically, a Boolean formula is a finite string which is constructed from: Variables: From a set Vars of variable symbols, e.g. x 1, x 2 Boolean operators: (negation), (disjunction, or), (conjunction, and), (implication), (equivalence) Parenthesis: (, ). The definition of Boolean formulas is given recursively, as follows: Definition 1. The set of Boolean formulas Form is the smallest set satisfying the following two properties: Every variable is a Boolean formula. That is, Vars Form. If ψ 1, ψ 2 are in Form, then so are ( ψ 1 ), (ψ 1 ψ 2 ), (ψ 1 ψ 2 ), (ψ 1 ψ 2 ), and (ψ 1 ψ 2 ). Boolean formulas of the second type are called compound formulas, and the ψ 1 and ψ 2 are called the immediate subformulas. Example 1. ϕ = ((x 1 ( x 2 )) (( ) x 2 )) is a Boolean formula. Sometimes we denote ϕ as ϕ(x 1, x 2, ) to notate the (free/unquantified) variables in it. We will talk later on quantified variables. 1.3 Semantics of Boolean Formulas A truth assignment is an assignment of either 1 (true) or 0 (false) to each variable. We will often use T to denote 1 and F to denote 0. Formally, a truth assignment is a function τ : Vars {0, 1}. Notice that there are 2 n possible truth assignments over n variables. We can use a particular truth assignment τ to evaluate a Boolean formula to be either true or false. In this way, a Boolean formula represents a function from the set of all possible truth assignments {τ : Vars {0, 1}} to the set {0, 1}. We give the computation of this function recursively, along the lines of the definition above: If ϕ is a variable, to determine the value of ϕ we can look directly at the truth assignment. That is, to determine ϕ(τ) we consider ϕ as a variable and use it to lookup into τ. Thus ϕ(τ) = τ(ϕ). If ϕ is a compound formula (with immediate subformulas ψ 1 and ψ 2 ), then: If ϕ = ( ψ 1 ) then ϕ(τ) = 1 iff ψ 1 (τ) = 0. If ϕ = (ψ 1 ψ 2 ) then ϕ(τ) = 1 iff ψ 1 (τ) = 1 or ψ 2 (τ) = 1. If ϕ = (ψ 1 ψ 2 ) then ϕ(τ) = 1 iff ψ 1 (τ) = 1 and ψ 2 (τ) = 1. If ϕ = (ψ 1 ψ 2 ) then ϕ(τ) = 1 iff ψ 1 (τ) = 0 or ψ 2 (τ) = 1. If ϕ = (ψ 1 ψ 2 ) then ϕ(τ) = 1 iff either (ψ 1 (τ) = 1 and ψ 2 (τ) = 1) or (ψ 1 (τ) = 0 and ψ 2 (τ) = 0).

Example 2. Let ϕ = ((x 1 ( x 2 )) (( ) x 2 )). Let τ = {x 1 1, x 2 0, 1} i.e. the truth assignment which sets x 1 and to true and x 2 to false. Then ϕ(τ) = 0. In many cases is it easy to ditch the parenthesis (unless we really need them). If we do, we give precedence to over other the Boolean operators. Obviously ((x 1 x 2 ) ) is the same as (x 1 (x 2 )) (and similarly for ) so we just write (x 1 x 2 ). You can think of a Boolean formula as a way to compactly represent a set of truth assignments, namely the set of truth assignments τ that make the formula true. We will often find two formulas that are composed of different symbols but represent the same set of truth assignments; this motivates the following definition: Definition 2. Two Boolean formulas are called equivalent if they have the same value under every possible truth assignment. That is, we say ϕ and ψ are equivalent (denoted ϕ ψ) if for all τ : Vars {0, 1} we have that ϕ(τ) = ψ(τ). Example 3. ϕ 1 = ((x 1 x 2 ) x 1 ) is equivalent to ϕ 2 = (x 1 x 2 ). 1.4 Truth tables Another way to see the evaluation of the Boolean formula is by truth tables. A truth table is a table in which we see the evaluation of a formula under all possible truth assignments. Example 4. The truth table for ϕ = ((x 1 ( x 2 )) (( ) x 2 )) is: x 1 x 2 ϕ 0 0 0 1 0 0 0 1 0 1 0 1 1 0 0 0 1 0 1 0 0 1 Notice that the size of the truth table is exponential in the number of variables. When we want to reason about larger Boolean formulas a truth table will quickly become cumbersome. 1.5 Binary Decision Tree Another way to describe a Boolean formula is by a Binary Decision Tree. This is a binary tree in which every layer represents a fresh variable and every node has two children: Left (to set the variable to 0) and Right (to set the variable to 1). Then each path in the tree represents a possible assignment for the variables; the corresponding evaluation of the formula is the leaf at the end of the path. Example 5. The truth table given above for ϕ = ((x 1 ( x 2 )) (( ) x 2 )) becomes: x 1 0 1 x 2 0 1 0 1 x 2 0 1 0 1 0 1 0 1 0 0 Note that this description of a Boolean formula is also exponential in the number of variables. 2

1.6 Satisfiability, Unsatisfiability, and Validity Definition 3. Let ϕ be a Boolean formula. ϕ is called satisfiable if it is true under at least one truth assignment of the variables, i.e., if ϕ(τ) = 1 for some truth assignment τ. We say that the assignment τ satisfies the formula. ϕ is called unsatisfiable if ϕ is false under every truth assignment, i.e., if ϕ(τ) = 0 for all truth assignments τ. ϕ is called valid if it is true under every truth assignment, i.e., if ϕ(τ) = 1 for all truth assignments τ. Example 6. Let ϕ = (x 1 x 2 ). Then {x 1 1, x 2 0} satisfies ϕ but {x 1 0, x 2 0} does not satisfy ϕ. Thus ϕ is satisfiable but not valid. Example 7. ϕ = (x x) is valid. 1.7 CNF, k-cnf We will shortly be interested in determining the complexity of checking satisfiability of a Boolean formula. It turns out that we do not always have to consider every possible Boolean formula. Instead, it is sufficient to consider only a certain subset of Boolean formulas. A common subset is known as CNF. Definition 4. A literal is either a variable (x) or the negation of a variable ( x). A [CNF -]clause is the disjunction (or) of literals. A Boolean formula is in Conjunctive Normal Form (CNF ) if it is the conjunction of disjunctions of literals. That is, ϕ is in CNF if ϕ = ( l i ) = (l 1 l 2 l a1 ) (l a1+1 l a1+2 l a2 ) (l ab 1 +1 l ab 1 +2 l ab ) where each l i is a literal (either a variable or the negation of a variable). For a truth assignment to satisfy a CNF formula it must satisfy at least one literal from every clause. Note that the concatenation of two CNF formulas is still a CNF formula. Example 8. (x 1 x 2 ) ( x 1 x 2 x 5 x 4 ) (x 4 x 2 ) is in CNF. It is often interesting to consider only CNF formulas with the same number of literals, k, in each clause. This defines a subset of CNF formulas known as k-cnf formulas: Definition 5. Let k 2 be an integer. A formula φ is in k-cnf if it is in CNF and there are exactly k literals in each clause. Example 9. (x 1 x 2 ) ( x 5 x 4 ) (x 4 x 2 x 1 ) is in 3-CNF. 1.8 SAT, k-sat Checking the satisfiability of Boolean formulas is a famous important problem. It turns out that checking the satisfiability of general Boolean formulas is equivalent to checking the satisfiability of Boolean formulas in CNF, because of the following theorem: Theorem 1. There is a polynomial time algorithm that, given a Boolean formula ϕ, will construct a CNF formula which is satisfiable iff ϕ is satisfiable. Proof. The proof of this theorem will be given as a Homework Exercise 3

The formula constructed in the theorem above may introduce a linear fraction of new variables. It is also possible to construct a CNF formula equivalent (not just equi-satisfiable) to a given Boolean formula without introducing new variables, but the new formula may be exponentially larger in the worst-case. We can define two decision problems, SAT and k-sat, that check the satisfiability of a formula in either CNF or k-cnf: SAT: Input: a Boolean formula ϕ in CNF Output: Yes if ϕ is satisfiable, No otherwise. k-sat: Input: a Boolean formula ϕ in k-cnf Output: Yes if ϕ is satisfiable, No otherwise. We will see later that these two decision problems are closely related. In fact, both SAT and k-sat (for k 3) are NP-complete. 2 Exercises 2.1 Problem 1 Which of the following is a Boolean formula? 1. (x 1 x 2 ) ( (x 2 ) 2. (x 2 ) 3. (x 1 x 2 ) ((x 2 ( ))) 2.2 Problem 2 Prove the De-Morgan laws. That is, for every pair of Boolean formulas ψ 1, ψ 2 we have: 1. ( (ψ 1 ψ 2 )) ( ψ 1 ψ2) 2. ( (ψ 1 ψ 2 )) ( ψ 1 ψ2) 3. ( ψ 1 ) ψ 1 2.3 Problem 3 Prove the distributive and associative properties. That is, for every pair of Boolean formulas ψ 1, ψ 2, ψ 3 we have: 1. (ψ 1 ψ 2 ) ψ 3 = ψ 1 (ψ 2 ψ 3 ) 2. (ψ 1 ψ 2 ) ψ 3 = ψ 1 (ψ 2 ψ 3 ) 3. (ψ 1 ψ 2 ) ψ 3 = (ψ 1 ψ 3 ) (ψ 2 ψ 3 ) 4. (ψ 1 ψ 2 ) ψ 3 = (ψ 1 ψ 3 ) (ψ 2 ψ 3 ) 5. Is it also true that (ψ 1 ψ 2 ) ψ 3 = ψ 1 (ψ 2 ψ 3 )? 2.4 Problem 4 Prove all of the following. Let ϕ be a Boolean formula: 1. ϕ is valid iff (ϕ) is not satisfiable. 2. ϕ is no valid iff (ϕ) is satisfiable. 3. ϕ is satisfiable iff (ϕ) is not valid. 4

2.5 Problem 5 Let ϕ = (x 1 x 2 ) ((x 2 ) (x 1 x 2 )). 1. Draw the truth table and Binary Decision Tree of ϕ. 2. Is ϕ satisfiable/valid/not-satisfiable? If satisfiable, which assignments satisfy ϕ? 3. Let ψ (x 1 x 2 ) Prove or refute that ϕ and ψ are equivalent. 2.6 Problem 6 We learned about formulas in CNF. A formula is in Disjunctive Normal Form (DNF ) if if it is the disjunction of conjunctions of literals. For example, (x 1 x 2 ) ( x 1 x 2 x 5 x 4 ) (x 4 x 2 ) is a formula in DNF. Prove the following: 1. ϕ is a DNF formula iff ϕ is a CNF formula. 2. L = {ϕ ϕ is a DNF formula} is in P T IME. 5