Docsity

Understanding Propositional Logic and its Applications in SAT Solvers - Prof. Hantao Zhang, Study notes of Computer Science

Toggle sidebar
bg1
SAT: Propositional SatisfiabilitySAT: Propositional Satisfiability
22c:145 Artificial Intelligence
Russell & Norvig, Ch. 7.6
Validity vs. SatisfiabilityValidity vs. Satisfiability
zValidity:
– A sentence is valid if it is true in every interpretation (every
interpretation is a model).
– A sentence sis a valid consequence of a set Sof sentences
if
(
S => s
)
is valid.
()
– Proof methods: True Table and Inference Rules
zSatisfiability:
– A set of sentences is satisfiable if there exists an
interpretation in which every sentence is true (it has at least
one model).
– Proof Methods: The Davis-Putnam-Logeman-Loveland
procedure (DPLL).
SAT: Propositional SatisfiabilitySAT: Propositional Satisfiability
zAn instance of SAT is defined as (X, S)
–X: A set of 0-1 (propositional) variables
–S: A set of sentences (formulas) on X
zGoal: Find an assignment f: X -> {0, 1} so that
every sentence becomes true.
zSAT is the first NP-complete problem.
– Good News: Thousands of problems can be
transformed into SAT
– Bad News: There are no efficient algorithms for SAT
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13

Partial preview of the text

Download Understanding Propositional Logic and its Applications in SAT Solvers - Prof. Hantao Zhang and more Study notes Computer Science in PDF only on Docsity!

SAT: Propositional SatisfiabilitySAT: Propositional Satisfiability

22c:145 Artificial Intelligence Russell & Norvig, Ch. 7.

Validity vs. SatisfiabilityValidity vs. Satisfiability

z Validity:

  • A sentence is valid if it is true in every interpretation (every interpretation is a model).
  • A sentence s is a valid consequence of a set S of sentences if (S => s) is valid.( )
  • Proof methods: True Table and Inference Rules z Satisfiability:
  • A set of sentences is satisfiable if there exists an interpretation in which every sentence is true (it has at least one model).
  • Proof Methods: The Davis-Putnam-Logeman-Loveland procedure (DPLL).

SAT: Propositional SatisfiabilitySAT: Propositional Satisfiability

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

  • X: A set of 0-1 (propositional) variables
  • S: A set of sentences (formulas) on X

z Goal: Find an assignment f: X -> {0, 1} so that

every sentence becomes true.

z SAT is the first NP-complete problem.

  • Good News: Thousands of problems can be transformed into SAT
  • Bad News: There are no efficient algorithms for SAT

Conjunctive Normal Form (CNF)Conjunctive Normal Form (CNF)

ϕ = ( a V c ) & ( b V c ) & (¬ a V ¬ b V ¬ c )

Clause

Positive Literal

Negative Literal

Propositional ClausesPropositional Clauses

z Every propositional constraint can be converted into a set of equivalent clauses.

  • S = { C 1 , C 2 , …, Cm } = C 1 & C 2 & … & Cm z A clause is a disjunction of literals.
  • C = (L( 11 V L 22 V … V L (^) kk ) ) z A literal is either a variable or the negation of a variable.
  • L = x or L = ¬ x z A set of clauses is also said to be in Conjunctive Normal Form (CNF).

Gate CNFGate CNF

a b d^

ϕd = [d ≡ ¬(a & b )] = [d → ¬(a & b)] & [¬(a & b) → d] = (¬d V ¬a V ¬b)[¬d → (a & b)]

ϕd = [ d ≡ ¬( a & b )] = ¬[ d ⊕ ¬( a & b )] = ¬[(¬( a & b ) & ¬ d ) V ( a & b & d )] = ¬[¬ a ¬ d V ¬ b ¬ d V a b d ] = ( a V d )( b V d )(¬ a V ¬ b V ¬ d )

( d a b)[ d → (a & b)] = (a V d)(b V d)(¬a V ¬b V ¬d)

z An unresolved clause is unit if it has exactly

one unassigned literal

ϕ = ( a V c )( b V c )(¬a V ¬b V ¬ c )

Unit Clause RuleUnit Clause Rule -- ImplicationsImplications

z A unit clause has exactly one option for being

satisfied

a b → ¬ c

i.e. c must be set to 0.

Pure Literal RulePure Literal Rule

z A variable is pure if its literals are either all positive or all negative z Satisfiability of a formula is unaffected by assigning pure variables the values that satisfy all the clauses containing themcontaining them

ϕ = ( a V c )( b V c )( b V ¬ d )(¬a V ¬b V d )

z Set c to 1; if ϕ becomes unsatisfiable, then it is also unsatisfiable when c is set to 0.

z General technique for deriving new clauses Example: ω 1 = (¬ a V b V c ), ω 2 = ( a V b V d ) Resolution:

Resolution/ConsensusResolution/Consensus

res(ω 1 , ω 2 , a ) = ( b V c V d )

z Complete procedure for satisfiability [Davis, JACM’60] z Impractical for real-world problem instances z Application of restricted forms has been successful!

  • E.g., always apply restricted resolution
    • res((¬ a V α), ( a V α), a ) = (α) α is a disjunction of literals

A Taxonomy of SAT AlgorithmsA Taxonomy of SAT Algorithms

SAT Algorithms

Complete Incomplete

Backtrack search (DP) Resolution (original DP) Recursive learning (RL)

BDDs (Binary Decision Diagram)

...

Local search (hill climbing) Continuous formulations Genetic algorithms Simulated annealing

...

Tabu search

Can prove unsatisfiability Cannot prove unsatisfiability

X1 V X X1 V X -X1 V -X -X1 V -X -X2 V -X3 1 V X 1 V X 0 V -X 0 V -X -X2 V -X

0 V X 0 V X 1 V -X 1 V -X -X2 V -X

X1=

X X

X1=

1 (^1) X2=

SAT:

A search

problem

1 1 -X2 V -X 1 X 1 1 0 V -X

1 1 1 1 0

X2=

1 -X -X -X2 V -X3 (^11) 1 -X 1 V -X3 (^1) 1 1 1 1

X2=

X3=

1 0 1 1 1

(^0) X3=0 X3= X 1 1 1 V –X

X2=

X1 V X X1 V X -X1 V -X -X1 V -X -X2 V -X3 1 1 -X -X -X2 V -X

X X 1 1 -X2 V -X

X1=0 X1=

Simplification Rules: 1 V C = 1, 0 V C = C

-X2 V -X3^ X2 V^ X

1 1 1 1 0

X2=1, X3=

1 1 1 1 1

X2=0, X3=

Unit

Propagation:

Make all unit clauses true; No splitting on them.

Implementing The DPLL AlgorithmImplementing The DPLL Algorithm

z A destructive data structure is needed for

clauses: Instead of copying clauses, modify

them and then undo modification when

backtracking.

z Efficient algorithms for unit-propagation.

z There are many choices for selecting a literal to

split (heuristics are needed).

Satbox’s Results on nSatbox’s Results on n--queen prob.queen prob.

n solutions 1 soln. all soln.

  • Times are in seconds.
  • There are 1646800 clauses for n=

Resolution (original DP)Resolution (original DP)

z Iteratively apply resolution (consensus) to eliminate one variable each time

  • i.e., resolution between all pairs of clauses containing x and ¬ x
  • formula satisfiability is preserved zz Stop applying resolution whenStop applying resolution when,
  • Either empty clause is derived ⇒ instance is unsatisfiable
  • Or only clauses satisfied or with pure literals are obtained ⇒ instance is satisfiable

ϕ = ( a V c )( b V c )( d V c )(¬ a V ¬ b V ¬ c ) Eliminate variable c

ϕ 1 = ( a V ¬ a V ¬ b )( b V ¬ a V ¬ b )( d V ¬ a V ¬ b ) = ( d V ¬ a V ¬ b ) (^) Instance is SAT!

Recursive Learning (RL)Recursive Learning (RL) in CNFin CNF

z Recursive evaluation of clause satisfiability requirements for identifying common assignments

ϕϕϕϕ = (= (= (= ( aaaa VVVV bbbb )(¬)(¬)(¬)(¬ aaaa VVVV dddd ) (¬) (¬) (¬) (¬ bbbb VVVV dddd ))))

Recursion can be of arbitrary depth

Try a = 1: ( a = 1) ⇒ ( d = 1)

Try b = 1: ( b = 1) ⇒ ( d = 1)

C( a = 1) = { a = 1, d = 1}

C( b = 1) = { b = 1, d = 1}

C( a = 1) ∩ C( b = 1) = { d = 1} Every way of satisfying^ ( a^ V^ b )^ implies^ d^ = 1. Hence, d = 1 is a necessary assignment!

An Alternative Explanation for RLAn Alternative Explanation for RL

ϕ = ( a V b )(¬ a V d ) (¬ b V d )

( b V d )

resolution ( )

( d )

resolution

Sequence of resolution operations for finding necessary assignments

Comment: RL provides yet another mechanism for identifying suitable resolution operations

ComparisonComparison

z Local search is incomplete

  • If instances are known to be SAT, local search can be competitive

z Resolution is in general impractical

z Recursive Learning (RL) are in general slow, though robust

  • RL can derive too much unnecessary information

NonNon--Chronological BacktrackingChronological Backtracking

z During backtrack search, in the presence of conflicts, backtrack to one of the causes of the conflict

ϕ = ( a V b )(¬ b V c V d ) (¬ b V e )(¬ d V ¬ e V f ) ( a V c V f )(¬ a V g )(¬ g V b )(¬ h V j )(¬ i V k )…

ϕ = ( a V b )(¬ b V c V d ) (¬ b V e )(¬ d V ¬ e V f ) ( a V c V f )(¬ a V g )(¬ g V b )(¬ h V j )(¬ i V k )…

ϕ = ( a V b )(¬ b V c V d ) (¬ b V e )(¬ d V ¬ e V f ) ( a V c V f )(¬ a V g )(¬ g V b )(¬ h V j )(¬ i V k )…

ϕ = ( a V b )(¬ b V c V d ) (¬ b V e )(¬ d V ¬ e V f ) ( a V c V f )(¬ a V g )(¬ g V b )(¬ h V j )(¬ i V k )…

( a = 1) ∧ ( c = 0) ∧ ( f = 0) ⇒ (ϕ = 0)

Assume (decisions) c = 0, f = 0, h = 0 and i = 0

Assignment a = 0 caused conflict ⇒ clause ( a V c V f ) created ( a V c V f ) implies a = 1

A conflict is again reached: (¬ d V ¬ e V f ) is unsat

(ϕ = 1) ⇒ ( a = 0) ∨ ( c = 1) ∨ ( f = 1) ∴create new clause: (¬ a V c V f )

NonNon--Chronological BacktrackingChronological Backtracking

Created clauses: ( a V c V f ) and (¬ a V c V f ) Apply resolution: new unsat clause ( c V f )

0

0

c

f

∴ backtrack to most recent decision: f = 0

∴created clauses/implicates: ( a V c V f ), (¬ a V c V f ), and ( c V f )

i

h

0

0

a 0 1 ( c V f )

Ideas from other ApproachesIdeas from other Approaches

z Resolution and recursive learning can be incorporated into backtrack search (DP)

  • create additional clauses/implicates
  • anticipate and prevent conflicting conditions
  • identify necessary assignmentsidentify necessary assignments
  • allow for non-chronological backtracking

( b V c V d )

resolution ( b^ V^ c^ V^ d ) Unit clause^!

( a V b V c ) (¬ a V b V d )

Resolution within DP:

Clause provides explanation for necessary assignment b = 1

Implications:

ϕ = ( a V b V c )(¬ a V d V e ) (¬ b V d V c )

( a = 1) ∧ ( e = 0) ⇒ ( d = 1)

ϕϕ = (= ( aa VV b V cb V c )(¬)(¬ aa VV d V ed V e ) (¬) (¬ bb VV d V cd V c ))

Recursive LearningRecursive Learning within DPwithin DP

resolution

ϕ = ( a V b V c )(¬ a V d V e ) (¬ b V d V c )

( a 1) ∧ ( e 0) ⇒ ( d 1)

( b = 1) ∧ ( c = 0) ⇒ ( d = 1)

Clause provides explanation for necessary assignment d = 1

( c V e V d )

resolution

( b V c V e V d )

( c = 0) ∧ (( e = 0) ∧ ( c = 0)) ⇒ ( d = 1)

Clausal form:

( c V e V d ) Unit clause!

Formula SimplificationFormula Simplification

z Eliminate clauses and variables

  • If ( x V ¬ y ) and (¬ x V y ) exist, then x and y are equivalent, ( x ↔ y )
    • eliminate y , and replace by x
    • remove satisfied clauses
  • Utilize 2CNF sub-formula for identifying equivalent variablesUtilize 2CNF sub formula for identifying equivalent variables

Implication graph:

a

d

b c

a , b , c and d are pairwise equivalent

(¬ a V b )(¬ b V c )(¬ c V d )(¬ d V b )(¬ d V a )

≡ (a→b)(b→c)(c→d)(d→b)(d→a)

∴replace all variables by a

2 2--Variable EquivalenceVariable Equivalence

( a V ¬ x )( b V ¬ x )(¬ a V ¬ b V x ) ( a V ¬ y )( b V ¬ y )(¬ a V ¬ b V y

resolution

x ↔ y

(¬ x V ¬ b V y ) (¬ y V ¬ b V x )

(¬ x V y ) (¬ y V x )

resolution

Randomization & RestartsRandomization & Restarts

z Can make the search strategy complete

  • Increase backtrack cutoff value after each restart z Can utilize learning
  • Useful for proving unsatisfiability z CC an utilize portfolios of algorithms and/or algorithmili f li f l i h d/ l i h configurations
  • Either, run K algorithms (or algorithm configurations)
  • concurrently, in different processors, or
  • sequentially, in a single processor
  • Or, after each restart, pick an algorithm from a portfolio
  • Also useful for proving unsatisfiability

Circuit SatisfiabilityCircuit Satisfiability

a b

c

d

e

f

c h? e (^) g

ϕ = [ d ≡ ¬( ab )] [ e ≡ ¬( b V c )] [ f ≡ ¬ d ] [ g ≡ d V e ] [ h ≡ fg ] h

Circuit SatisfiabilityCircuit Satisfiability

a b

c

d

e

f

h?

a b

c

d

e

f

h?

a b

c

d

e

f

h?

a b

c

d

e

f

h?

= h ( a V d )( b V d )(¬ a V ¬ b V ¬ d ) (¬ b V ¬ e )(¬ c V ¬ e )( b V c V e ) (¬ d V ¬ f )( d V f ) (¬ d V g )(¬ e V g )( d V e V ¬ g ) ( f V ¬ h )( g V ¬ h )(¬ f V ¬ g V h )

= h ( a V d )( b V d )(¬ a V ¬ b V ¬ d ) (¬ b V ¬ e )(¬ c V ¬ e )( b V c V e ) (¬ d V ¬ f )( d V f ) (¬ d V g )(¬ e V g )( d V e V ¬ g ) ( f V ¬ h )( g V ¬ h )(¬ f V ¬ g V h )

= h ( a V d )( b V d )(¬ a V ¬ b V ¬ d ) (¬ b V ¬ e )(¬ c V ¬ e )( b V c V e ) (¬ d V ¬ f )( d V f ) (¬ d V g )(¬ e V g )( d V e V ¬ g ) ( f V ¬ h )( g V ¬ h )(¬ f V ¬ g V h )

= h ( a V d )( b V d )(¬ a V ¬ b V ¬ d ) (¬ b V ¬ e )(¬ c V ¬ e )( b V c V e ) (¬ d V ¬ f )( d V f ) (¬ d V g )(¬ e V g )( d V e V ¬ g ) ( f V ¬ h )( g V ¬ h )(¬ f V ¬ g V h )

= h ( a V d )( b V d )(¬ a V ¬ b V ¬ d ) (¬ b V ¬ e )(¬ c V ¬ e )( b V c V e ) (¬ d V ¬ f )( d V f ) (¬ d V g )(¬ e V g )( d V e V ¬ g ) ( f V ¬ h )( g V ¬ h )(¬ f V ¬ g V h )

c (^) e (^) g

ϕ = h [ d ≡ ¬( ab )] [ e ≡ ¬( b V c )] [ f ≡ ¬ d ] [ g ≡ d V e ] [ h ≡ fg ]

c c c (^) eee (^) ggg

ATPGATPG (Automatic Test Pattern Generation)(Automatic Test Pattern Generation)

xx (^11)

xx (^22)

xx (^55)

xx 66 xx^77 xx (^99)

= 0= 0

xx 11 CG

xx (^22)

xx (^55)

xx (^66) xx (^77) xx (^99) s-a-

xx (^44)

xx (^11)

xx (^22)

xx (^33)

xx (^55)

xx 66 xx (^77)

xx (^88)

xx (^99)

xx (^44)

xx 33 xx^88

= 1= 1

CF

xx (^44)

xx (^11)

xx (^33)

xx (^55)

xx 66 xx (^77)

xx (^88)

xx (^99)

xx (^33) xx (^44)

xx (^88) zz = 1?

Trivially mapped into CNF

Equivalence CheckingEquivalence Checking

CA

z Combinational Circuits:

If z = 1 is unsatisfiable, the two circuits are equivalent!

CB

z = 1?

Bounded Model CheckingBounded Model Checking

z Sequential Circuits:

z Problem formulation,

  • System property P does not hold in one of the first k states f llfollowing initial state i i iti l t t II 0
  • Transition function ρ

I 0 ∧ ρ(0,1) ∧ ρ(1,2) ∧ … ∧ ρ ( k -1, k ) ∧ (¬ P 0 ∨ ¬ P 1 … ∨ ¬ P k)

  • Represent formula as an instance of SAT in CNF format

Empirical Evidence (in EDA)Empirical Evidence (in EDA)

Can solve large problem instances

ddomain i iinstance t variables clauses CPU timei bl l CPU ti FPGA routing bigkeyv1w6 25896 91400 11.

Empirical Evidence (in EDA)Empirical Evidence (in EDA)

Non-chronological backtracking (NCB) and clause recording (CR) can be observed often and can be crucial

domain instance B T B NCB LJ T B NCB LJ T testing ssa2670-130 > 11250000 > 10000 7142 3538 20 60.3 100 42 15 0.

w/o NCB and CR w/ NCB and w/o CR w/ NCB and CR

Empirical Evidence (in EDA)Empirical Evidence (in EDA)

Formula simplification can be significant

domain instance variables clauses variables clauses BMC barrel7 3523 13765 805 3467

before after

Empirical Evidence (in EDA)Empirical Evidence (in EDA)

Randomization & Restarts can be effective

domain instance B NCB LJ T B NCB LJ T R

w/o restarts w/ restarts

Restart search every 100 backtracks Keep recorded clauses of size ≤ 10

verification 2dlx_cc_bug54 42645 15156 35 2299.3 222 147 36 53.5 3

Empirical Evidence (in EDA)Empirical Evidence (in EDA)

Portfolio of algorithm configurations can be essential

domain instance B NCB LJ T B NCB LJ T verification dlx2 cc 2273327 688891 39 > 100000 100498 32066 70 2032

w/o portfolio w/ portfolio

verification dlx2_cc 2273327 688891 39 > 100000 100498 32066 70 2032

Configurations: Clauses recorded: sizes 15 to 30 Clauses kept: sizes 10 to 20 Each configuration w/ equal probability 4 different configurations used Initial cutoff = 250; increments = 50

ConclusionsConclusions

z Many recent SAT algorithms and (EDA) applications z Hard Applications

  • Bounded Model Checking
  • Combinational Equivalence Checking
  • Superscalar processor verificationS l ifi ti
  • FPGA routing z “Easy” Applications
  • Test Pattern Generation: Stuck-at, Delay faults, etc.
  • Redundancy Removal
  • Circuit Delay Computation z Other Applications
  • Noise analysis, etc.

A Few References (Cont’d)A Few References (Cont’d)

z Backtrack Search (Cont’d)

  • Randomization and restarts
    • Gomes&Selman, AAAI’98; Baptista&Marques-Silva, CP’
  • Formula simplification
    • Li AAAI’2000; Marques Silva CP’2000• Li, AAAI 2000; Marques-Silva, CP 2000 z Stalmarck’s Method
  • Stalmarck, Patent’89; Groote&Warners, CWI TechRep’ z Recursive Learning
  • Kunz&Pradhan, ITC’92; Marques-Silva&Glass, DATE’ z Local Search
  • Selman&Kautz, IJCAI’