SAT Solvers Ranjit Jhala, UC San Diego April 9, 2013 Decision - - PowerPoint PPT Presentation

sat solvers
SMART_READER_LITE
LIVE PREVIEW

SAT Solvers Ranjit Jhala, UC San Diego April 9, 2013 Decision - - PowerPoint PPT Presentation

SAT Solvers Ranjit Jhala, UC San Diego April 9, 2013 Decision Procedures We will look very closely at the following 1. Propositional Logic 2. Theory of Equality 3. Theory of Uninterpreted Functions 4. Theory of Difference-Bounded Arithmetic


slide-1
SLIDE 1

SAT Solvers

Ranjit Jhala, UC San Diego April 9, 2013

slide-2
SLIDE 2

Decision Procedures

We will look very closely at the following

  • 1. Propositional Logic
  • 2. Theory of Equality
  • 3. Theory of Uninterpreted Functions
  • 4. Theory of Difference-Bounded Arithmetic

Decision Problem: Satisfaction

◮ Does eval s p return True for some assignment s ? ◮ “Can we assign the variables to make the formula true” ?

slide-3
SLIDE 3

Decision Procedures

We will look very closely at the following

  • 1. Propositional Logic
  • 2. Theory of Equality
  • 3. Theory of Uninterpreted Functions
  • 4. Theory of Difference-Bounded Arithmetic

Why?

◮ Representative ◮ Have “efficient” algorithms

slide-4
SLIDE 4

Decision Procedures

We will look very closely at the following

  • 1. Propositional Logic
  • 2. Theory of Equality
  • 3. Theory of Uninterpreted Functions
  • 4. Theory of Difference-Bounded Arithmetic

Plan

◮ First in isolation ◮ Then in combination ◮ Very slick SW-Eng, based on logic

slide-5
SLIDE 5

Decision Procedures: Propositional Logic

Popularly called SAT Solvers

slide-6
SLIDE 6

Decision Procedures: Propositional Logic

Basics

◮ Propositional Logic 101 ◮ Conjunctive Normal Form ◮ Resolution

Algorithms

◮ Resolution ◮ Backtracking Search ◮ Boolean Constraint Propagation ◮ Conflict Driven Learning & Backjumping

slide-7
SLIDE 7

Decision Procedures: Propositional Logic

Basics

◮ Propositional Logic 101 ◮ Conjunctive Normal Form ◮ Resolution

Algorithms

◮ Resolution ◮ Backtracking Search ◮ Boolean Constraint Propagation ◮ Conflict Driven Learning & Backjumping

slide-8
SLIDE 8

Propositional Logic 101

Propositional Variables

data PVar

Propositional Formulas

data Formula = Prop PVar | Not Formula | Formula ‘And‘ Formula | Formula ‘Or‘ Formula

slide-9
SLIDE 9

Decision Procedures: Propositional Logic

Basics

◮ Propositional Logic 101 ◮ Conjunctive Normal Form ◮ Resolution

Algorithms

◮ Resolution ◮ Backtracking Search ◮ Boolean Constraint Propagation ◮ Conflict Driven Learning & Backjumping

slide-10
SLIDE 10

Conjunctive Normal Form

Restricted representation of Formula

Literals: Variables or Negated Variables

data Literal = Pos PVar | Neg PVar

Clauses: Disjunctions (Or) of Literals

data Clauses = [Literal]

CNF Formulas: Conjunctions (And) of Clauses

data CnfFormula = [Clauses]

slide-11
SLIDE 11

Conjunctive Normal Form: Example

Consider a Formula

(x1 ∨ x2) ∧ (¬x1 ∨ x3) ∧ ¬x3

Represented as a Formula

(Prop 1 ‘Or‘ Prop 2) ‘And‘ (Not (Prop 1) ‘Or‘ Prop 3) ‘And‘ (Not (Prop 3) )

Represented as a CnfFormula

[ [Pos 1 , Pos 2] , [Neg 1 , Pos 3] , [Neg 3 ] ]

slide-12
SLIDE 12

Conjunctive Normal Form Conversion

Theorem There is a poly-time function toCNF :: Formula -> CnfFormula toCNF = error "Exercise For The Reader" Such that any f is satisfiable iff (toCNF f) is satisfiable.

◮ toCNF adds new variables for sub-formulas ◮ otherwise, an exponential blowup in CnfFormula size

slide-13
SLIDE 13

Conjunctive Normal Form Conversion

Theorem There is a poly-time function toCNF :: Formula -> CnfFormula toCNF = error "Exercise For The Reader" Such that any f is satisfiable iff (toCNF f) is satisfiable. Henceforth Only consider formulas in Conjunctive Normal Form Formulas

slide-14
SLIDE 14

Decision Procedures: Propositional Logic

Basics

◮ Propositional Logic 101 ◮ Conjunctive Normal Form

Algorithms

◮ Resolution ◮ Backtracking Search ◮ Boolean Constraint Propagation ◮ Conflict Driven Learning & Backjumping

slide-15
SLIDE 15

Properties of CNF

Pure Variable

◮ One which appears only +ve or −ve in a CnfFormula

Empty Clause

◮ If a CnfFormula has some Clause without Literals ◮ Then the CnfFormula is UNSAT

Trivial Formula

◮ If a CnfFormula has no Clause ◮ Or every variable is pure ◮ Then the CnfFormula is SAT

slide-16
SLIDE 16

Goal

Determine satisfaction by reducing CnfFormula to one of

◮ Empty Clause (ie UNSAT), or ◮ Trivial Formula (ie SAT).

slide-17
SLIDE 17

Reducing Formulas By Resolution

(“Reduce” is, perhaps, not the best word. . . ) Resolution: For any A, B and variable x, the formula (A ∨ x) ∧ (B ∨ ¬x) is equivalent to the formula (A ∨ B)

◮ The variable x is called a pivot variable

slide-18
SLIDE 18

General Resolution

Resolution: For any Ai, Bj and variable x, the formula

  • i

(Ai ∨ x) ∧

  • j

(Bj ∨ ¬x) is equivalent to the formula

  • i,j

(Ai ∨ Bj)

◮ Pivot variable x is eliminated by resolution

slide-19
SLIDE 19

Davis-Putnam Algorithm: Example 1

Input Formula

◮ (x1 ∨ x2 ∨ x3) ∧ (x2 ∨ ¬x3 ∨ x5) ∧ (¬x2 ∨ x4))

Pivot on x2

◮ (x1 ∨ x3 ∨ x4) ∧ (¬x3 ∨ x5 ∨ x4)

Pivot on x3

◮ (x1 ∨ x4 ∨ x5)

All variables are pure . . . hence, SAT

slide-20
SLIDE 20

Davis-Putnam Algorithm: Example 2

Input Formula

◮ (x1 ∨ x2) ∧ (x1 ∨ ¬x2) ∧ (¬x1 ∨ x3) ∧ (¬x1 ∨ ¬x3)

Pivot on x2

◮ (x1) ∧ (¬x1 ∨ x3) ∧ (¬x1 ∨ ¬x3)

Pivot on x3

◮ (x1) ∧ (¬x1)

Pivot on x1

◮ ()

Empty clause . . . hence, UNSAT

slide-21
SLIDE 21

Davis-Putnam Algorithm

Algorithm

  • 1. Select pivot and perform resolution
  • 2. Repeat until SAT or UNSAT

Issues?

◮ Space blowup (formula size blows up on resolution)

slide-22
SLIDE 22

Decision Procedures: Propositional Logic

Basics

◮ Propositional Logic 101 ◮ Conjunctive Normal Form

Algorithms

◮ Resolution ◮ Backtracking Search ◮ Boolean Constraint Propagation ◮ Conflict Driven Learning & Backjumping

slide-23
SLIDE 23

Decision Tree: Describes Space of All Assignments

Figure: SAT Decision Tree (Courtesy: Lintao Zhang)

slide-24
SLIDE 24

Decision Tree: SAT via Depth First Search

Figure: DFS On Decision Tree (Courtesy: Lintao Zhang)

slide-25
SLIDE 25

Backtracking Search

Don’t build whole tree, but lazily search solutions

◮ Choose a variable x, set to True ◮ Remove constraints where x appears ◮ Recurse on remaining constraints ◮ Backtrack if a contradiction is found

slide-26
SLIDE 26

Backtracking Search (1/21)

Figure: Basic DLL (Courtesy: Lintao Zhang)

slide-27
SLIDE 27

Backtracking Search (2/21)

Figure: Basic DLL (Courtesy: Lintao Zhang)

slide-28
SLIDE 28

Backtracking Search (3/21)

Figure: Basic DLL (Courtesy: Lintao Zhang)

slide-29
SLIDE 29

Backtracking Search (4/21)

Figure: Basic DLL (Courtesy: Lintao Zhang)

slide-30
SLIDE 30

Backtracking Search (5/21)

Figure: Basic DLL (Courtesy: Lintao Zhang)

slide-31
SLIDE 31

Backtracking Search (6/21)

Figure: Basic DLL (Courtesy: Lintao Zhang)

slide-32
SLIDE 32

Backtracking Search (7/21)

Figure: Basic DLL (Courtesy: Lintao Zhang)

slide-33
SLIDE 33

Backtracking Search (8/21)

Figure: Basic DLL (Courtesy: Lintao Zhang)

slide-34
SLIDE 34

Backtracking Search (9/21)

Figure: Basic DLL (Courtesy: Lintao Zhang)

slide-35
SLIDE 35

Backtracking Search (10/21)

Figure: Basic DLL (Courtesy: Lintao Zhang)

slide-36
SLIDE 36

Backtracking Search (11/21)

Figure: Basic DLL (Courtesy: Lintao Zhang)

slide-37
SLIDE 37

Backtracking Search (12/21)

Figure: Basic DLL (Courtesy: Lintao Zhang)

slide-38
SLIDE 38

Backtracking Search (13/21)

Figure: Basic DLL (Courtesy: Lintao Zhang)

slide-39
SLIDE 39

Backtracking Search (14/21)

Figure: Basic DLL (Courtesy: Lintao Zhang)

slide-40
SLIDE 40

Backtracking Search (15/21)

Figure: Basic DLL (Courtesy: Lintao Zhang)

slide-41
SLIDE 41

Backtracking Search (16/21)

Figure: Basic DLL (Courtesy: Lintao Zhang)

slide-42
SLIDE 42

Backtracking Search (17/21)

Figure: Basic DLL (Courtesy: Lintao Zhang)

slide-43
SLIDE 43

Backtracking Search (18/21)

Figure: Basic DLL (Courtesy: Lintao Zhang)

slide-44
SLIDE 44

Backtracking Search (19/21)

Figure: Basic DLL (Courtesy: Lintao Zhang)

slide-45
SLIDE 45

Backtracking Search (20/21)

Figure: Basic DLL (Courtesy: Lintao Zhang)

slide-46
SLIDE 46

Backtracking Search (21/21)

Figure: Basic DLL (Courtesy: Lintao Zhang)

slide-47
SLIDE 47

Backtracking Search

Don’t build whole tree, but lazily search solutions

◮ Choose a variable x, set to True ◮ Remove constraints where x appears ◮ Recurse on remaining constraints ◮ Backtrack if a contradiction is found

(whew!)

◮ DFS avoids space blowup (only need to save stack) . . . ◮ . . . but not time (natch)

slide-48
SLIDE 48

Decision Procedures: Propositional Logic

Basics

◮ Propositional Logic 101 ◮ Conjunctive Normal Form

Algorithms

◮ Resolution ◮ Backtracking Search ◮ Boolean Constraint Propagation ◮ Conflict Driven Learning & Backjumping

slide-49
SLIDE 49

Boolean Constraint Propagation

Often, we don’t really have a choice. . .

slide-50
SLIDE 50

Boolean Constraint Propagation

Unit Clause Rule

◮ If an (unsatisfied) Clause has one unassigned Literal ◮ Then that Literal must be True in any SAT assignment

Example

◮ Formula (x1 ∨ ¬x2 ∨ x3) ∧ (x2 ∨ ¬x3) ∧ (¬x1 ∨ ¬x3) ◮ Assignment x1 = T, x2 = T ◮ The last clause is a unit clause ◮ Any SAT assigment must set ¬x3 = T (i.e. x3 = F)

slide-51
SLIDE 51

Boolean Constraint Propagation

Unit Clause Rule

◮ If an (unsatisfied) Clause has one unassigned Literal ◮ Then that Literal must be True in any SAT assignment

BCP or Unit Propagation

◮ Repeat applying unit clause rule ◮ Until no unit clause remains.

slide-52
SLIDE 52

Boolean Constraint Propagation: Example

Revisit Example With BCP

Figure: Boolean Constraint Propagation (Courtesy: Lintao Zhang)

slide-53
SLIDE 53

Boolean Constraint Propagation

DPLL = Backtracking Search + BCP

◮ Backtracking: Avoids space blowup ◮ BCP: Avoid doing obvious work ◮ Still repeatedly explore all choices (e.g. whole left subtree)

Wanted

◮ Means to learn to repeat dead ends ◮ Key to scaling to practical problems

slide-54
SLIDE 54

Decision Procedures: Propositional Logic

Basics

◮ Propositional Logic 101 ◮ Conjunctive Normal Form

Algorithms

◮ Resolution ◮ Backtracking Search ◮ Boolean Constraint Propagation ◮ Conflict Driven Learning & Backjumping

slide-55
SLIDE 55

Conflict Driven Learning

Key Insight

◮ On finding conflict, don’t (just) backtrack ◮ Learn new clause to prevent same conflict in future

Major breakthrough

◮ J. P. Marques-Silva and K. A. Sakallah, “GRASP – A New

Search Algorithm for Satisfiability,” Proc. ICCAD 1996.

◮ R. J. Bayardo Jr. and R. C. Schrag “Using CSP look-back

techniques to solve real world SAT instances.” Proc. AAAI, 1997

slide-56
SLIDE 56

Conflict Driven Learning

◮ Resolve on conflict variable to learn new conflict clause ◮ Add clause to set of clauses ◮ Backjump using conflict clause

slide-57
SLIDE 57

Conflict Driven Learning

Revisit Example With CDL

◮ Learn, Add, Backjump ◮ Vastly faster search

Figure: Boolean Constraint Propagation (Courtesy: Lintao Zhang)

slide-58
SLIDE 58

Backtracking Only (01/26)

slide-59
SLIDE 59

Backtracking Only (02/26)

slide-60
SLIDE 60

Backtracking Only (03/26)

slide-61
SLIDE 61

Backtracking Only (04/26)

slide-62
SLIDE 62

Backtracking Only (05/26)

slide-63
SLIDE 63

Backtracking Only (06/26)

slide-64
SLIDE 64

Backtracking Only (07/26)

slide-65
SLIDE 65

Backtracking Only (08/26)

slide-66
SLIDE 66

Backtracking Only (09/26)

slide-67
SLIDE 67

Backtracking Only (10/26)

slide-68
SLIDE 68

Backtracking Only (11/26)

slide-69
SLIDE 69

Backtracking Only (12/26)

slide-70
SLIDE 70

Backtracking Only (13/26)

slide-71
SLIDE 71

Backtracking Only (14/26)

slide-72
SLIDE 72

Backtracking Only (15/26)

slide-73
SLIDE 73

Backtracking Only (16/26)

slide-74
SLIDE 74

Backtracking Only (17/26)

slide-75
SLIDE 75

Backtracking Only (18/26)

slide-76
SLIDE 76

Backtracking Only (19/26)

slide-77
SLIDE 77

Backtracking Only (20/26)

slide-78
SLIDE 78

Backtracking Only (21/26)

slide-79
SLIDE 79

Backtracking Only (22/26)

slide-80
SLIDE 80

Backtracking Only (23/26)

slide-81
SLIDE 81

Backtracking Only (24/26)

slide-82
SLIDE 82

Backtracking Only (25/26)

slide-83
SLIDE 83

Backtracking Only (26/26)

slide-84
SLIDE 84

Boolean Constraint Propagation (01/23)

slide-85
SLIDE 85

Boolean Constraint Propagation (02/23)

slide-86
SLIDE 86

Boolean Constraint Propagation (03/23)

slide-87
SLIDE 87

Boolean Constraint Propagation (04/23)

slide-88
SLIDE 88

Boolean Constraint Propagation (05/23)

slide-89
SLIDE 89

Boolean Constraint Propagation (06/23)

slide-90
SLIDE 90

Boolean Constraint Propagation (07/23)

slide-91
SLIDE 91

Boolean Constraint Propagation (08/23)

slide-92
SLIDE 92

Boolean Constraint Propagation (09/23)

slide-93
SLIDE 93

Boolean Constraint Propagation (10/23)

slide-94
SLIDE 94

Boolean Constraint Propagation (11/23)

slide-95
SLIDE 95

Boolean Constraint Propagation (12/23)

slide-96
SLIDE 96

Boolean Constraint Propagation (13/23)

slide-97
SLIDE 97

Boolean Constraint Propagation (14/23)

slide-98
SLIDE 98

Boolean Constraint Propagation (15/23)

slide-99
SLIDE 99

Boolean Constraint Propagation (16/23)

slide-100
SLIDE 100

Boolean Constraint Propagation (17/23)

slide-101
SLIDE 101

Boolean Constraint Propagation (18/23)

slide-102
SLIDE 102

Boolean Constraint Propagation (19/23)

slide-103
SLIDE 103

Boolean Constraint Propagation (20/23)

slide-104
SLIDE 104

Boolean Constraint Propagation (21/23)

slide-105
SLIDE 105

Boolean Constraint Propagation (22/23)

slide-106
SLIDE 106

Boolean Constraint Propagation (23/23)

slide-107
SLIDE 107

Conflict Driven Learning (01/21)

slide-108
SLIDE 108

Conflict Driven Learning (02/21)

slide-109
SLIDE 109

Conflict Driven Learning (03/21)

slide-110
SLIDE 110

Conflict Driven Learning (04/21)

slide-111
SLIDE 111

Conflict Driven Learning (05/21)

slide-112
SLIDE 112

Conflict Driven Learning (06/21)

slide-113
SLIDE 113

Conflict Driven Learning (07/21)

slide-114
SLIDE 114

Conflict Driven Learning (08/21)

slide-115
SLIDE 115

Conflict Driven Learning (09/21)

slide-116
SLIDE 116

Conflict Driven Learning (10/21)

slide-117
SLIDE 117

Conflict Driven Learning (11/21)

slide-118
SLIDE 118

Conflict Driven Learning (12/21)

slide-119
SLIDE 119

Conflict Driven Learning (13/21)

slide-120
SLIDE 120

Conflict Driven Learning (14/21)

slide-121
SLIDE 121

Conflict Driven Learning (15/21)

slide-122
SLIDE 122

Conflict Driven Learning (16/21)

slide-123
SLIDE 123

Conflict Driven Learning (17/21)

slide-124
SLIDE 124

Conflict Driven Learning (18/21)

slide-125
SLIDE 125

Conflict Driven Learning (19/21)

slide-126
SLIDE 126

Conflict Driven Learning (20/21)

slide-127
SLIDE 127

Conflict Driven Learning (21/21)

slide-128
SLIDE 128

More Details about SAT Solvers

Lectures By Lintao Zhang (ZChaff)

◮ 1 ◮ 2

slide-129
SLIDE 129

Next Time: SMT = SAT + Theories

  • 1. Propositional Logic
  • 2. Combining Theories

◮ Equality + Uninterpreted Functions ◮ Difference-Bounded Arithmetic

  • 3. Combining SAT + Theories