Presentation is loading. Please wait.

Presentation is loading. Please wait.

SAT and SMT solvers Ayrat Khalimov (based on Georg Hofferek‘s slides) AKDV 2014.

Similar presentations


Presentation on theme: "SAT and SMT solvers Ayrat Khalimov (based on Georg Hofferek‘s slides) AKDV 2014."— Presentation transcript:

1 SAT and SMT solvers Ayrat Khalimov (based on Georg Hofferek‘s slides) AKDV 2014

2 Motivation Institute for Applied Information Processing and Communications 2 SAT solvers: ­ They rocketed the model checking First-Order Theories ­ Very expressive ­ Efficient SMT Solvers But: What are they? How do solvers work?

3 Outline Institute for Applied Information Processing and Communications 3 Propositional SAT solver ­ DPLL algorithm Predicate Logic (aka. First-Order Logic) ­ Syntax ­ Semantics First Order Logic First-Order Theories SMT solver ­ Eager Encoding ­ Lazy Encoding ­ DPLL(T)

4 Scope of Solvers propositional logic SAT solvers first order logic theory of equality difference logic Theorem provers SMT solvers linear integer arithmetic … theory of arrays

5 Notation propositional variables ­ e.g., a, b, c, d, … literal is a variable or its negation ­ e.g.,  a, b, … partial assignment A is a conjunction of literals ­ e.g., A =  a  d clause is a disjunction of literals ­ e.g., c = a   b  is a CNF formula (i.e. conjunction of clauses): ­ e.g.,  = (a  b   d)  c  [A] is  with all variables set according to A ­ e.g.,  [A] = (FALSE  b   TRUE)  c = b  c

6 SAT Solver Formula in CNF Satisfiable (+ model) Unsatisfiable (+ refutation proof)

7 DPLL Algorithm Due to Davis, Putnam, Loveland, Logemann ­ two papers: 1960, 1962 Basis for all modern SAT solvers

8 CNF as a Set of Clauses

9 Idea of DPLL-based SAT Solvers Recursively search an A: ­  [A] is TRUE Proves  satisfiable “A” is a satisfying model No such A exists ­  is unsatisfiable

10 Setting Literals

11 Truth Value of a CNF At least one clause is empty: ­ FALSE Clause set empty: ­ TRUE Otherwise: ­ Unassigned Literals left

12 DPLL Algorithm // sat( , A)=TRUE iff  [A] is satisfiable // sat( , true)=TRUE iff  is satisfiable sat( , A){ if(  [A] = true) return TRUE; if(  [A] = false) return FALSE; // Some unassigned variables left l = pick unassigned variable; AT = A  l; if(sat( , AT)) return TRUE; AF = A   l; if(sat( , AF)) return TRUE; return FALSE; }

13 DPLL Example Formula to check: (  a  b)  (  b  c)  (  c   a) 1.sat((  a  b)  (  b  c)  (  c   a), true) 2.sat( (  a  b)  (  b  c)  (  c   a), a) 3.sat( (  a  b)  (  b  c)  (  c   a), a  b) 4.sat( (  a  b)  (  b  c)  (  c   a), a  b  c) unsat 5.sat( (  a  b)  (  b  c)  (  c   a), a  b  c) unsat 6.sat( (  a  b)  (  b  c)  (  c   a), a  b) unsat 7.sat( (  a  b)  (  b  c)  (  c   a),  a) 8.sat((  a  b)  (  b  c)  (  c   a),  a  b) 9.sat((  a  b)  (  b  c)  (  c   a),  a  b  c) sat

14 Boolean Constraint Propagation (BCP) Unit clause: ­ a clause with a single unassigned literal ­ Examples: (a) (  b) Unit Clause exists  set its literal ­ Very simple but very important heuristic!

15 DPLL with BCP sat( , A){ while(unit clause occurs){ // l is only unassigned literal in // unit clause; A = A  l; } if(  [A] = true) return TRUE; if(  [A] = false) return FALSE; l = pick unassigned variable; AT = A  l; if(sat( , AT)) return TRUE; AF = A   l; if(sat( , AF)) return TRUE; return FALSE; }

16 Example Formula to check: (  a  b)  (  b  c)  (  c   a) 1.sat((  a  b)  (  b  c)  (  c   a), true) 2.sat( (  a  b)  (  b  c)  (  c   a), a) 3.[BCP]: sat( (  a  b)  (  b  c)  (  c   a), a  b) 4.[BCP]: sat( (  a  b)  (  b  c)  (  c   a), a  b  c) unsat 5.sat( (  a  b)  (  b  c)  (  c   a),  a) 6.sat( (  a  b)  (  b  c)  (  c   a),  a  b) 7.sat((  a  b)  (  b  c)  (  c   a),  a  b  c) sat

17 Can we do better? sat( , A){ while(unit clause occurs){ // l is only unassigned literal in // unit clause; A = A  l; } if(  [A] = true) return TRUE; if(  [A] = false) return FALSE; l = pick unassigned variable; AT = A  l; if(sat( , AT)) return TRUE; AF = A   l; if(sat( , AF)) return TRUE; return FALSE; }

18 Pure Literals Pure literal: ­ Literal for unassigned variable ­ The variable appears in one phase only Pure literals  true them

19 DPLL with BCP and Pure Literals sat( , A){ while(unit clause occurs){ // BCP let l be only unassigned literal in c; A = A  l; } while(pure literal l exists){ // Pure literals A = A  l; } if(  [A] = true) return TRUE; if(  [A] = false) return FALSE; l = pick a literal that does not occur in A; AT = A  l; if(sat( , AT)) return TRUE; AL = A   l; if(sat( , AL)) return TRUE; return FALSE; }

20 Example Formula to check: (  a  b)  (  b  c)  (  c   a) 1.sat((  a  b)  (  b  c)  (  c   a), true) [  a pure] 2.sat( (  a  b)  (  b  c)  (  c   a),  a) [  b pure] 3.sat( (  a  b)  (  b  c)  (  c   a),  a  b) sat

21 Can we do better? Institute for Applied Information Processing and Communications 21 sat( , A){ while(unit clause l occurs) A = A  l; while(pure literal l exists) A = A  l; if(  [A] = true) return TRUE; if(  [A] = false) return FALSE; l = pick a literal that does not occur in A; AT = A  l; if(sat( , AT)) return TRUE; AL = A   l; if(sat( , AL)) return TRUE; return FALSE; }

22 Whenever we get the conflict ­ analyze it add clauses to avoid in future 2013-03-08 Institute for Applied Information Processing and Communications 22 Learning: informal

23 Learning 1.(a   c) 2.(b   c) 3.(  a   b  c) 4.(  a   b) 5.(  a  b) 6.(a   b) 7.(a  b) cc aa UNSAT

24 Learning 1.(a   c) 2.(b   c) 3.(  a   b  c) 4.(  a   b) 5.(  a  b) 6.(a   b) 7.(a  b) cc aa UNSAT a The problem is with a: no need to set c=true! aa UNSAT a Without learning

25 Learning 1.(a   c) 2.(b   c) 3.(  a   b  c) 4.(  a   b) 5.(  a  b) 6.(a   b) 7.(a  b) cc aa UNSAT aa false 7 We learn: a bb 6

26 Learning & Backtracking 1.(a   c) 2.(b   c) 3.(  a   b  c) 4.(  a   b) 5.(  a  b) 6.(a   b) 7.(a  b) 8.a cc aa UNSAT Jump back to level 0 is smart LEVEL 0 LEVEL 1 LEVEL 2 aa false 7 We learn: a bb 6

27 Learning & Backtracking 1.(a   c) 2.(b   c) 3.(  a   b  c) 4.(  a   b) 5.(  a  b) 6.(a   b) 7.(a  b) 8.a cc aa UNSAT a Jump back to level 0 is smart LEVEL 0 LEVEL 1 LEVEL 2

28 Learning & Backtracking 1.(a   c) 2.(b   c) 3.(  a   b  c) 4.(  a   b) 5.(  a  b) 6.(a   b) 7.(a  b) 8.a cc aa UNSAT a bb 4 false 5 LEVEL 0 LEVEL 1 LEVEL 2

29 Learning & Backtracking 1.(a   c) 2.(b   c) 3.(  a   b  c) 4.(  a   b) 5.(  a  b) 6.(a   b) 7.(a  b) 8.a cc aa UNSAT a bb 4 false 5 UNSAT We learn: UNSAT, because no decision was necessary LEVEL 0 LEVEL 1 LEVEL 2

30 Backtrack Level Three important possibilities 1.Backtrack as usual 2.Restart for every learned clause 3.Go to the earliest level in which the conflict clause is a unit clause Option 3 often performs better

31 Can we do better? (learning is not shown) 31 sat( , A){ while(unit clause l occurs) A = A  l; while(pure literal l exists) A = A  l; if(  [A] = true) return TRUE; if(  [A] = false) return FALSE; l = pick a literal that does not occur in A; AT = A  l; if(sat( , AT)) return TRUE; AF = A   l; if(sat( , AF)) return TRUE; return FALSE; } how to pick literals?

32 Institute for Applied Information Processing and Communications 32 Source: Armin Biere’s slides: http://fmv.jku.at/rerise14/rerise14-sat-slides.pdf Effect of picking heuristics on SAT solver performance

33 Can we do better? -- Special cases 2013-03-08 Institute for Applied Information Processing and Communications 33 Horn clauses can be solved in polynomial time Cut width algorithm

34 source: http://gauss.ececs.uc.edu/SAT/

35

36 Syntax of Predicate Logic Two sorts: ­ Objects Numbers Strings Elements of sets … ­ Truth values IsEven(42) “Terms” “Formulas”

37 From Terms to Formulas Term Formula Predicate

38 FOL formulae: informal definition quantifiers over variables unary predicates: binary, etc. functions can FO formulae quantify over functions/predicates? can FO formulae have free (non-quantified) variables? * can FO formulae have ‘uninterpreted’ functions? * can FO formula has infinite number of atoms?

39 Syntax of Predicate Logic Variables ­ x, y, z, … Functions ­ f, g, h, … (arity > 0) ­ constants (arity = 0) Predicates ℙ ­ P, Q, R, … (with arity > 0) Terms and Formulae defined next

40 Terms

41 Formulae

42 True and False FO formulae

43

44 Semantics of Predicate Logic  Inductive Definition

45 Semantics of Predicate Logic

46 2013-03-08 Institute for Applied Information Processing and Communications 46 Examples

47 Satisfiable FO formulae

48 Valid FO formulae

49 Some facts about our world Gödel proved that ­ every valid FO formula has a finite proof. Church-Turing proved that ­ no algorithm exists that can decide if FO formula is invalid proof deduction algorithm FO formula may never terminate if valid if invalid

50 Notion of “Theory” Application Domain Structures & Objects Predicates & Functions Arithmetic Numbers (Integers, Rationals, Reals) Computer Programs Arrays,Bitvectors Array-Read, Array-Write, …

51 Definition of a Theory

52

53 Model View We check satisfiability and validity only wrt models that satisfy axioms ­  “Satisfiability modulo (=‘with respect to’) theories” All possible Models Models satisfying all axioms

54 Green: Models Satisfying all Axioms Violet: Models Satisfying Formula in Question

55 Green: Models Satisfying all Axioms Violet: Models Satisfying Formula in Question

56 Theory Formulas vs. FO Formulas equivalid equisatisfiable

57 Fragment of a Theory

58 Scope of Solvers propositional logic SAT solvers first order logic theory of equality difference logic Theorem provers SMT solvers linear integer arithmetic … theory of arrays

59 Deciding Satisfiability (quantifier free theory): main methods 1. Eager Encoding ­ Equisatisfiable propositional formula ­ one fat SAT call 2. Lazy Encoding  Theory Solver  Conjunctive Fragment  Blocking Clauses  numerous SAT calls 3. DPLL (T)

60 Axiom Schema: Template for (infinite number of) axioms

61 Two-Stage Eager Encoding equisatisfiable propositional formula equisatisfiable propositional formula Ackermann’s Reduction Graph-based Reduction SAT Solver

62

63 63

64 Non-Polar Equality Graph ­ Node per variable ­ Edge per (dis)equality Make it chordal ­ No chord-free cycles (size > 3) a b c d e f g

65  SAT Solver

66 66

67 Summary: Eager Encoding equisatisfiable propositional formula equisatisfiable propositional formula Ackermann’s Reduction Graph-based Reduction SAT Solver

68 Lazy Encoding SAT Solver Theory Solver Assignment of Literals Blocking Clause SAT UNSAT

69

70 Congruence-Closure Algorithm

71 71

72 Lazy Encoding SAT Solver Theory Solver Assignment of Literals Blocking Clause SAT UNSAT

73 DPLL(T) Decide Start full assignment SAT BCP/PL partial assignment Analyze Conflict conflict UNSAT Learn & Backtrack Theory Solver Add Clauses partial assignment theory propagation / conflict partial assignment

74 Scope of Solvers propositional logic SAT solvers first order logic theory of equality difference logic Theorem provers SMT solvers linear integer arithmetic … theory of arrays

75 Summary 75

76 Self-check: learning targets Institute for Applied Information Processing and Communications 76 Explain Satisfiability Modulo Theories Describe Theory of Uninterpreted Functions and Equality Explain and use ­ Ackermann’s Reduction ­ Graph-based Reduction ­ Congruence Closure ­ DPLL ­ DPLL(T)

77 History of satisfiability: http://gauss.ececs.uc.edu/SAT/articles/FAIA185- 0003.pdfhttp://gauss.ececs.uc.edu/SAT/articles/FAIA185- 0003.pdf SAT basics: http://gauss.ececs.uc.edu/SAT/articles/sat.pdfhttp://gauss.ececs.uc.edu/SAT/articles/sat.pdf Conflict Driven Clause Learning: http://gauss.ececs.uc.edu/SAT/articles/FAIA185-0131.pdf http://gauss.ececs.uc.edu/SAT/articles/FAIA185-0131.pdf Armin Biere’s slides: http://fmv.jku.at/rerise14/rerise14-sat-slides.pdfhttp://fmv.jku.at/rerise14/rerise14-sat-slides.pdf SAT game http://www.cril.univ- artois.fr/~roussel/satgame/satgame.php?level=1&lang=enghttp://www.cril.univ- artois.fr/~roussel/satgame/satgame.php?level=1&lang=eng Logic and Computability classes by Georg http://www.iaik.tugraz.at/content/teaching/bachelor_courses/logik_und_ber echenbarkeit/ http://www.iaik.tugraz.at/content/teaching/bachelor_courses/logik_und_ber echenbarkeit/ Institute for Applied Information Processing and Communications 77 some reading


Download ppt "SAT and SMT solvers Ayrat Khalimov (based on Georg Hofferek‘s slides) AKDV 2014."

Similar presentations


Ads by Google