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

Similar documents
COMP219: Artificial Intelligence. Lecture 20: Propositional Reasoning

Formal Verification Methods 1: Propositional Logic

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

Propositional and First Order Reasoning

Heuristics for Efficient SAT Solving. As implemented in GRASP, Chaff and GSAT.

LOGIC PROPOSITIONAL REASONING

Lecture 2 Propositional Logic & SAT

Tutorial 1: Modern SMT Solvers and Verification

Classical Propositional Logic

Comp487/587 - Boolean Formulas

CS156: The Calculus of Computation

Propositional Logic: Evaluating the Formulas

Lecture Notes on SAT Solvers & DPLL

Automated Program Verification and Testing 15414/15614 Fall 2016 Lecture 3: Practical SAT Solving

Foundations of Artificial Intelligence

A brief introduction to Logic. (slides from

From SAT To SMT: Part 1. Vijay Ganesh MIT

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

VLSI CAD: Lecture 4.1. Logic to Layout. Computational Boolean Algebra Representations: Satisfiability (SAT), Part 1

Clause/Term Resolution and Learning in the Evaluation of Quantified Boolean Formulas

An Introduction to SAT Solving

Part 1: Propositional Logic

Lecture 9: The Splitting Method for SAT

CS156: The Calculus of Computation Zohar Manna Autumn 2008

Conjunctive Normal Form and SAT

Computational Logic. Davide Martinenghi. Spring Free University of Bozen-Bolzano. Computational Logic Davide Martinenghi (1/30)

Conjunctive Normal Form and SAT

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

Foundations of Artificial Intelligence

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

Decision Procedures for Satisfiability and Validity in Propositional Logic

Propositional logic. Programming and Modal Logic

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

Propositional Reasoning

Conjunctive Normal Form and SAT

A New 3-CNF Transformation by Parallel-Serial Graphs 1

Chapter 7 R&N ICS 271 Fall 2017 Kalev Kask

Logic and Inferences

Satisfiability and SAT Solvers. CS 270 Math Foundations of CS Jeremy Johnson

SAT Solvers: Theory and Practice

Logic in AI Chapter 7. Mausam (Based on slides of Dan Weld, Stuart Russell, Subbarao Kambhampati, Dieter Fox, Henry Kautz )

Propositional Logic: Models and Proofs

An instance of SAT is defined as (X, S)

WHAT IS AN SMT SOLVER? Jaeheon Yi - April 17, 2008

Satisfiability Modulo Theories

Intelligent Agents. Pınar Yolum Utrecht University

Introduction to Artificial Intelligence. Logical Agents

EE562 ARTIFICIAL INTELLIGENCE FOR ENGINEERS

Proof Methods for Propositional Logic

Topics in Model-Based Reasoning

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

SAT-Solving: From Davis- Putnam to Zchaff and Beyond Day 3: Recent Developments. Lintao Zhang

Logical Agents. Chapter 7

Satisfiability Modulo Theories (SMT)

Part 1: Propositional Logic

Logical agents. Chapter 7. Chapter 7 1

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

Kecerdasan Buatan M. Ali Fauzi

Pythagorean Triples and SAT Solving

SAT, CSP, and proofs. Ofer Strichman Technion, Haifa. Tutorial HVC 13

Price: $25 (incl. T-Shirt, morning tea and lunch) Visit:

Solving SAT Modulo Theories

CS:4420 Artificial Intelligence

Reasoning with Quantified Boolean Formulas

1 Efficient Transformation to CNF Formulas

3 Propositional Logic

CS 380: ARTIFICIAL INTELLIGENCE PREDICATE LOGICS. Santiago Ontañón

Practical SAT Solving

Satisfiability Checking of Non-clausal Formulas using General Matings

Verification using Satisfiability Checking, Predicate Abstraction, and Craig Interpolation. Himanshu Jain THESIS ORAL TALK

CS250: Discrete Math for Computer Science. L6: CNF and Natural Deduction for PropCalc

Mathematical Logic Part Three

Logic in AI Chapter 7. Mausam (Based on slides of Dan Weld, Stuart Russell, Dieter Fox, Henry Kautz )

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

A Collection of Problems in Propositional Logic

Logic: Propositional Logic (Part I)

Propositional and Predicate Logic. jean/gbooks/logic.html

CS 380: ARTIFICIAL INTELLIGENCE

Artificial Intelligence

Extending DPLL-Based QBF Solvers to Handle Free Variables

PROPOSITIONAL LOGIC. VL Logik: WS 2018/19

Critical Reading of Optimization Methods for Logical Inference [1]

Towards Understanding and Harnessing the Potential of Clause Learning

Propositional Logic: Methods of Proof (Part II)

Artificial Intelligence

Logical agents. Chapter 7. Chapter 7 1

Artificial Intelligence

Propositional Logic: Methods of Proof (Part II)

Propositional and Predicate Logic - II

Planning as Satisfiability

Solving QBF with Free Variables

Introduction to Solving Combinatorial Problems with SAT

TDT4136 Logic and Reasoning Systems

Chapter 7 Propositional Satisfiability Techniques

Quantified Boolean Formulas: Complexity and Expressiveness

COMP9414: Artificial Intelligence Propositional Logic: Automated Reasoning

Propositional Calculus

Abstract Answer Set Solvers with Backjumping and Learning

The Wumpus Game. Stench Gold. Start. Cao Hoang Tru CSE Faculty - HCMUT

Language of Propositional Logic

Transcription:

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

Why study SAT solvers? Many problems reduce to SAT. Formal verification CAD, VLSI Optimization AI, planning, automated deduction Modern SAT solvers are often fast. Other solvers (QBF, SMT, etc.) borrow techniques from SAT solvers. SAT solvers and related solvers are still active areas of research. 2

Negation-Normal Form (NNF) A formula is in negation-normal form iff: all negations are directly in front of variables, and the only logical connectives are:,,. A literal is a variable or its negation. Convert to NNF by pushing negations inward: (P Q) ( P Q) (P Q) ( P Q) (De Morgan s Laws) 3

Disjunctive Normal Form (DNF) Recall: A literal is a variable or its negation. A formula is in DNF iff: it is a disjunction of conjunctions of literals. (l 11 l 12 l 13 ) }{{} conjunction 1 (l 21 l 22 l 23 ) }{{} conjunction 2 Every formula in DNF is also in NNF. A simple (but inefficient) way convert to DNF: Make a truth table for the formula φ. (l 31 l 32 l 33 ) }{{} conjunction 3 Each row where φ is true corresponds to a conjunct. 4

Conjunctive Normal Form (CNF) A formula is in CNF iff: it is a conjunction of disjunctions of literals. (l 11 l 12 l 13 ) }{{} clause 1 (l 21 l 22 l 23 ) }{{} clause 2 Modern SAT solvers use CNF. Any formula can be converted to CNF. Equivalent CNF can be exponentially larger. Equi-satisfiable CNF (Tseitin encoding): Only linearly larger than original formula. (l 31 l 32 l 33 ) }{{} clause 3 5

Tseitin transformation to CNF Introduce new variables to represent subformulas. E.g, to convert (A (B C)): Replace (B C) with a new variable g 1. Add clauses to equate g 1 with (B C). Original: x. φ( x) Transformed: x. g. ψ( x, g) (A g 1 ) (B g 1 ) }{{} ( B g 1 ) (C g 1 ) }{{} ( C g 1 ) ( B C g 1 ) }{{} ((B C) g 1 ) Gives value of g 1 for all 4 possible assignments to {B, C}. 6

Tseitin transformation to CNF Convert (A (B C)) to CNF by introducing new variable g 1 for (B C). (A g 1 ) ( g 1 B) }{{} (g 1 B) ( g 1 C) }{{} (g 1 C) ( B C g 1 ) }{{} ((B C) g 1 ) (g 1 (B C)) ((B C) g 1 ) (g 1 (B C)) 7

SAT Solvers -- Representation A CNF formula is represented by a set of clauses. Empty set represents a true formula. A clause is represented by a set of literals Empty set represents a false clause. A variable is represented by a positive integer. The logical negation of a variable is represented by the arithmetic negation of its number. E.g., ((x1 x2) ( x1 x2)) is represented by {{1, 2}, {-1, -2}} 8

Naïve Approach SAT problem: Given a boolean formula φ, does there exist an assignment that satisfies φ? Naïve approach: Search all assignments! n variables 2^n possible assignments Explosion! SAT is NP-complete: Worst case is likely O(2^n ), unless P=NP. But for many cases that arise in practice, we can do much better. 9

Unit Propagation Davis-Putnam-Logemann-Loveland (DPLL) Unit Clause: Clause with exactly one literal. Algorithm: If a clause has exactly one literal, then assign it true. Repeat until there are no more unit clauses. Example: ((x1 x2) ( x1 x2) (x1)) (( T x2) ( F x2) (T)) (( T ) ( x2 )) T 10

Helper function from copy import copy, deepcopy def AssignLit(ClauseList, lit): ClauseList = deepcopy(clauselist) for clause in copy(clauselist): if lit in clause: ClauseList.remove(clause) if -lit in clause: clause.remove(-lit) return ClauseList >>> AssignLit([[1, 2, -3], [-1, -2, 4], [3, 4]], 1) [[-2, 4], [3, 4]] >>> AssignLit([[1, 2, -3], [-1, -2, 4], [3, 4]], -1) [[2, -3], [3, 4]] Assumption: No clause contains both a variable and its negation. 11

Naïve Solver def AssignLit(ClauseList, lit): ClauseList = deepcopy(clauselist) for clause in copy(clauselist): if lit in clause: ClauseList.remove(clause) if -lit in clause: clause.remove(-lit) return ClauseList def IsSatisfiable(ClauseList): # Test if no unsatisfied clauses remain if len(clauselist) == 0: return True # Test for presense of empty clause if [] in ClauseList: return False # Split on an arbitrarily decided literal DecLit = ClauseList[0][0] return (IsSatisfiable(AssignLit(ClauseList, DecLit)) or IsSatisfiable(AssignLit(ClauseList, -DecLit))) 12

DPLL Solver def IsSatisfiable(ClauseList): # Unit propagation repeat until fixed point: for each unit clause UC in ClauseList: ForcedLit = UC[0] ClauseList = AssignLit(ClauseList, ForcedLit) unchanged # Test if no unsatisfied clauses remain if len(clauselist) == 0: return True # Test for presense of empty clause if [] in ClauseList: return False # Split on an arbitrarily decided literal DecLit = (choose a variable occuring in ClauseList) return (IsSatisfiable(AssignLit(ClauseList, DecLit)) or IsSatisfiable(AssignLit(ClauseList, -DecLit))) 13

GRASP: an efficient SAT solver Original Slides by Pankaj Chauhan Modified by Will Klieber Please interrupt me if anything is not clear!

Terminology CNF formula ϕ x 1,, x n : n variables ω 1,, ω m : m clauses Assignment A Set of (variable, value) pairs. φ = ω 1 1 ω 2 2 ω 33 ω 11 = (x (x 22 x 33 )) ω 22 = ( x 11 x x 44 )) ω 3 = 3 ( x 2 2 x 4 ) 4 ) A = {x {x 11 =0, x 22 =1, x 33 =0, x 44 =1} Notation: {(x 1,1), (x 2,0)}, {x 1 :1, x 2 :0}, {x 1 =1, x 2 =0}, {x 1, x 2 } A < n partial assignment {x 1 =0, x 2 =1, x 4 =1} A = n complete assignment {x 1 =0, x 2 =1, x 3 =0, x 4 =1} ϕ A = 0 falsifying assignment {x 1 =1, x 4 =1} ϕ A = 1 satisfying assignment {x 1 =0, x 2 =1, x 4 =1} ϕ A = X unresolved asgnment {x 1 =0, x 2 =0, x 4 =1} 15

Terminology An assignment partitions the clause database into three classes: Satisfied, falsified, unresolved Free literal: an unassigned literal Unit clause: has exactly one free literal 16

Basic Backtracking Search Organize the search in the form of a decision tree. Each node is a decision variable. Outgoing edges: assignment to the decision variable. Depth of node in decision tree is decision level δ(x). x=v @ d means variable x is assigned value v at decision level d. x 1 = 1@1 x 1 x 1 = 0@1 x 2 = 1@2 x 2 x 2 x 2 = 0@2 17

Basic Backtracking Search 1. Make new decision assignments. 2. Infer implied assignments by a deduction process (unit propagation). May lead to falsifying clauses, conflict! The assignment is called conflicting assignment. 3. Conflicting assignments leads to backtrack. 18

Backtracking Search in Action Example 1 x 1 = 0@1 x 1 ω 11 = (x (x 22 x 33 )) ω 22 = ( x 11 x x 44 )) ω 33 = ( x 22 x 44 )) x 2 = 0@2 x 3 = 1@2 x 2 {(x 1,0), (x 2,0), (x 3,1)} No backtrack in this example! 19

Backtracking Search in Action Example 2 x 1 ω 11 = (x (x 22 x 33 )) ω 22 = ( x 11 x x 44 )) ω 33 = ( x 22 x 44 )) x 1 = 1@1 x 4 = 0@1 x 2 = 0@1 x 3 = 1@1 {(x 1,1), (x 2,0), (x 3,1), (x 4,0)} No backtrack in this example! 20

Backtracking Search in Action Example 3 x 1 = 1@1 x 4 = 0@1 x 2 = 0@1 x 3 = 1@1 conflict x 1 x 1 = 0@1 x 2 x 2 = 0@2 x 3 = 1@2 {(x 1,0), (x 2,0), (x 3,1)} ω 11 = (x (x 22 x 33 )) ω 22 = ( x 11 x x 44 )) ω 33 = ( x 22 x 44 )) ω 44 = ( x 11 x 22 x x 33 )) 21

GRASP GRASP is Generalized search Algorithm for the Satisfiability Problem (Silva, Sakallah, 96). Features: Implication graphs for Unit Propagation and conflict analysis. Learning of new clauses. Non-chronological backtracking! 22

Learning GRASP can learn new clauses that are logically implied by the original formula. Goal is to allow Unit Prop to deduce more forced literals, pruning the search space. Example: φ contains clauses (x y z) and (x y z). Resolving on z yields a new clause (x y). If y is false, then x must be true for φ to be true. But not discoverable by simple Unit Prop w/o resolvent clause. Clause (x y) allows Unit Prop to force x=1 when y=0. New clauses learned from conflicting assignments. 23

Resolution From (x 1 x n r) ( r y 1 y m ) deduce (x 1 x n y 1 y m ) 24

Top-level of GRASP-like solver 1. CurAsgn = {}; 2. while (true) { 3. while (value of φ under CurAsgn is unknown) { 4. DecideLit(); // Add decision literal to CurAsgn. 5. Propagate(); // Add forced literals to CurAsgn. 6. } 7. if (CurAsgn satisifies φ) {return true;} 8. Analyze conflict and learn a new clause; 9. if (the learned clause is empty) {return false;} 10. Backtrack(); 11. Propagate(); // Learned clause will force a literal 12. } 25

GRASP Decision Heuristics Procedure DecideLit() Choose the variable that satisfies the most clauses Other possibilities exist 26

GRASP Deduction Unit Propagation is a type of Boolean Constraint Propagation (BCP). Grasp does Unit Prop using implication graphs: E.g., for the clause ω = (x y), if y=1, then x=1 is forced; the antecedent of x is {y=1}. If a variable x is forced by a clause during BCP, then assignment of 0 to all other literals in the clause is called the antecedent assignment A(x). E.g., for ω = (x y z), A(x) = {y:0, z:1}, A(y) = {x:0, z:1}, A(z) = {x:0, y:0} Variables directly responsible for forcing the value of x. Antecedent assignment of a decision variable is empty. 27

Implication Graphs Depicts the antecedents of assigned variables. A node is an assignment to a variable. (decision or implied) Predecessors of x correspond to antecedent A(x). No predecessors for decision assignments! For special conflict vertex κ, antecedent A(κ) is assignment to vars in the falsified clause. x 2 =1@6 x 10 =0@3 x 5 =1@6 x 1 =1@6 x 4 =1@6 κ x 3 =1@6 x 6 =1@6 conflict x 9 =0@1 x 11 =0@3 28

Example Implication Graph Current truth assignment: {x 9 =0@1, x 12 =1@2, x 13 =1@2, x 10 =0@3, x 11 =0@3} Current decision assignment: {x 1 =1@6} ω 1 ω = 1 ( x ( x 1 1 x x 2 ) 2 ) ω 2 ω = 2 ( x ( x 1 1 x x 3 3 x x 9 ) 9 ) ω 3 ω = 3 ( x ( x 2 2 x x 3 3 x x 4 ) 4 ) ω 4 ω = 4 ( x ( x 4 4 x x 5 5 x x 10 ) x 10 ) 1 =1@6 ω 5 ω = 5 ( x ( x 4 4 x x 6 6 x x 11 ) 11 ) ω 6 ω = 6 ( x ( x 5 5 xx 6 ) 6 ) ω 7 ω = 7 (x (x 1 1 x x 7 7 x x 12 ) 12 ) x 9 =0@1 ω 8 ω = 8 (x (x 1 1 x x 8 ) 8 ) ω 9 ω = 9 ( x ( x 7 7 x x 8 8 xx 13 ) 13 ) ω 1 ω 2 ω 2 x 2 =1@6 x 3 =1@6 ω 3 ω 3 x 10 =0@3 ω 4 ω 4 x 11 =0@3 x 4 =1@6 ω 5 ω 5 x 5 =1@6 ω 6 ω 6 x6 =1@6 κ conflict 29

GRASP Conflict Analysis After a conflict arises, analyze the implication graph. Add new clause that would prevent the occurrence of the same conflict in the future. Learning Determine decision level to backtrack to; this might not be the immediate one. Non-chronological backtrack 30

Learning Algorithm 1. Let CA be the assignment of False to all literals in the falsified clause. ( CA is short for conflict assignment.) Example: CA= {x 5 =1@6, x 6 = 1@6} 2. A literal l CA is a unique implication point (UIP) iff every other literal in CA has an earlier decision level than l. 3. loop: Remove the most recently assigned literal from CA and replace it by its antecedent. if (CA is empty or has a UIP): break; 4. Let {L 1,..., L n } = CA; learn clause ( L 1... L n ). 5. Backtrack to the earliest decision level at which the learned clause will force the UIP to be false. Why is this guaranteed to be possible? 31

Example Implication Graph Current truth assignment: {x 9 =0@1, x 12 =1@2, x 13 =1@2, x 10 =0@3, x 11 =0@3} Current decision assignment: {x 1 =1@6} ω 1 ω = 1 ( x ( x 1 1 x x 2 ) 2 ) ω 2 ω = 2 ( x ( x 1 1 x x 3 3 x x 9 ) 9 ) ω 3 ω = 3 ( x ( x 2 2 x x 3 3 x x 4 ) 4 ) ω 4 ω = 4 ( x ( x 4 4 x x 5 5 x x 10 ) x 10 ) 1 =1@6 ω 5 ω = 5 ( x ( x 4 4 x x 6 6 x x 11 ) 11 ) ω 6 ω = 6 ( x ( x 5 5 xx 6 ) 6 ) ω 7 ω = 7 (x (x 1 1 x x 7 7 x x 12 ) 12 ) x 9 =0@1 ω 8 ω = 8 (x (x 1 1 x x 8 ) 8 ) ω 9 ω = 9 ( x ( x 7 7 x x 8 8 xx 13 ) 13 ) ω 1 ω 2 ω 2 x 2 =1@6 x 3 =1@6 ω 3 ω 3 x 10 =0@3 x 11 =0@3 ω 4 ω 4 x 4 =1@6 ω 5 ω 5 x 5 =1@6 ω 6 ω 6 x6 =1@6 κ conflict 32

Example ω 11 = ( x 11 x 88 x 99 )) ω 22 = ( x 11 x 88 x x 99 )) ω 33 = ( x 11 x x 88 x 99 )) ω 44 = ( x 11 x x 88 x x 99 )) ω 55 = (x (x 11 x 33 )) ω 66 = (x (x 11 x x 33 )) 33

Is that all? Huge overhead for boolean constraint propagation (BCP) Better decision heuristics Better learning, problem specific Better engineering! Chaff 34