I=IntSort()
f =Function('f', I, I)
x, y, z =Ints('x y z')
A=Array('A',I,I)
fml =Implies(x + 2 == y, f(Select(Store(A, x, 3), y - 2)) == f(y - x + 1))
s =Solver()
s.add(Not(fml))
print s.check()
SAT/SMT
Logical Queries - SAT+
sat unsat
model (clausal) proof
correction set core
local min correction set local min core
min correction set min core
Logical Queries
Theories
Equality and Uninterpreted functions
EUF
(declare-sortA)
(declare-fun f (A) A)
(declare-const x A)
(assert (= (f (f x)) x))
(assert (= (f (f (f x))) x))
(check-sat)
(assert (not (= (f x) x)))
(check-sat)
Deciding Equality
Disequalities
Variants of union-find are effective to decide equality.
Free functions
Congruence rule
Naming sub-terms
Applying Congruence (1)
Applying Congruence (2)
EUF Models
A satisfiable version:
EUF Models (II)
Associate a distinct value with each equivalence class.
A=Array(Index, Elem) # array sort
a[i] # index array 'a' at index 'i'# Select(a, i)Store(a, i, v) # update array 'a' with value 'v' at index 'i'# = lambda j: If(i == j, v, a[j])Const(v, A) # constant array# = lambda j: vMap(f, a) # map function 'f' on values of 'a'# = lambda j: f(a[j])Ext(a, b) # Extensionality# Implies(a[Ext(a, b)] == b[Ext(a, b)], a == b)
Array Decision Procedure
Example Store(a, i, v)
Each occurrence of Store(a, i, v) and b[j],
Assert Store(a, i, v)[j] == If(i == j, v, a[j])
Assert Store(a, i, v)[i] == v
Each shared occurrences of :
Assert .
Array Decision Procedure (2)
Example Store(a, i, v)
Each occurrence of Store(a, i, v) and b[j],
Assert Store(a, i, v)[j] == If(i == j, v, a[j])
Assert Store(a, i, v)[i] == v
Each shared occurrences of :
Assert .
Suppose we are given a model satisfying all asserted equalities.
assigns values to terms.
Extend:
Claim: satisfies Store axioms.
Efficient Array Decision Procedures
Use current partial interpretation to guide axiom instantiation.
Rough sketch:
If (congruent) in current state
Assert .
If in current state
Assert
Also important to limit set of pairs.
Z3 uses relevancy propagation to prune don't care literals
Boolector uses dual propagation to extract small implicant
Bit-Vectors
(define-fun is-power-of-two ((x (_ BitVec4))) Bool
(= #x0 (bvand x (bvsub x #x1))))
(declare-const a (_ BitVec4))
(assert
(not (= (is-power-of-two a)
(or (= a #x0)
(= a #x1)
(= a #x2)
(= a #x4)
(= a #x8)))))
(check-sat)
(declare-const a String)
(declare-const b String)
(declare-const c String)
(assert (str.prefixof b a))
(assert (str.suffixof c a))
(assert (= (str.len a) (+ (str.len b) (str.len c))))
(assert (not (= a (str.++ b c))))
(check-sat)
Theorem 1. For every , exactly one of the two conditions hold:
for some where .
for some where and some resolution proof .
Corollary 1.
CDCL realizes the dichotomy by interleaving model and consequence finding:
Corollary 2. If , then for every
where : .
Corollary 3. If , i.e., for some , then
for every consequence from using forced literals in it is the case
that and there is no
such that .
Realizing the dichotomy
Main invariants preserved by CDCL:
Conflict state: For the state it is the case that
and .
Propagation:
For the state and ,
whenever , then
and .
Illustrating the invariants
if
Finds First Unique Implication Point (FUIP)
minimizes number of decision literals in .
maximizes propagated literals in
Next frontiers:
Lecture 3: Optimization and MaxSAT
Objectives
Optimization as SMT with preferred models
An introduction to cores and correction sets
Show examples of algorithms on top of SMT/Z3
An invitation to optimization
Type error localization using MaxSMT
Optimization
Three main SMT extensions
(maximize (+ x (* 2 y)))
(minimize (bvadd u v))
(assert-soft (> x y) :weight4)
Maximize objective
linear arithmetic
Minimize objective
bit-vector
Add a soft constraint
optional weight
Soft constraints as 0-1 optimization
Equilvalent formulations
(assert-soft :weight3)
(assert-soft :weight4)
(minimize (+ (if 03) (if 04)))
Optimizing Assertions
x, y =Ints('x y')
opt =Optimize()
opt.set(priority='pareto')
opt.add(x + y == 10, x >= 0, y >= 0)
mx = opt.maximize(x)
my = opt.maximize(y)
while opt.check() == sat:print mx.value(), my.value()
Optimization Extensions
MaxSAT solver
Primal simplex optimization
Applied on feasible tableau
Multiple Objectives
Box
Lex
Pareto
Optimization as an extension of core SMT solving
MaxSMT
Typical definition: Minimize the number of violated soft assertions.
Is built-in, based on MaxSAT algorithms.
MaxSAT example
(declare-const a Bool)
(declare-const b Bool)
(declare-const c Bool)
(assert-soft a :weight1)
(assert-soft b :weight2)
(assert-soft c :weight3)
(assert (= a c))
(assert (not (and a b)))
(check-sat)
(get-model)
MaxSAT flattened
(declare-const a Bool)
(declare-const b Bool)
(declare-const c Bool)
(assert-soft a :weight1)
(assert-soft b :weight1) (assert-soft b :weight1)
(assert-soft c :weight1) (assert-soft c :weight1) (assert-soft c :weight1)
(assert (= a c))
(assert (not (and a b)))
(check-sat)
(get-model)
NB. Implementations of MaxSAT typically flatten weights on demand.
def add_def(s, fml):
name =Bool("%s" % fml)
s.add(name == fml)
return name
def relax_core(s, core, Fs):
prefix =BoolVal(True)
Fs -= { f for f in core }
for i in range(len(core)-1):
prefix = add_def(s, And(core[i], prefix))
Fs |= { add_def(s, Or(prefix, core[i+1])) }
def maxsat(s, Fs):
cost =0Fs0=Fs.copy()
while unsat == s.check(Fs):
cost += 1
relax_core(s, s.unsat_core(), Fs)
return cost, { f for f inFs0if tt(s, f) }
MaxSAT with MCS (python)
def relax_mcs(s, mcs, Fs):
prefix =BoolVal(False)
Fs -= { f for f in mcs }
s.add(Or(mcs))
for i in range(len(mcs)-1):
prefix = add_def(s, Or(mcs[i], prefix))
Fs |= { add_def(s, And(prefix, mcs[i+1])) }
def maxsat(s, Fs0):Fs=Fs0.copy()
cost = len(Fs)
while s.check() == sat:
mss = { f for f inFsif tt(s, f) }
model1 = get_mss(s, mss, Fs)
mcs =Fs - mss
if cost > len(mcs):
cost = len(mcs)
model = model1
relax_mcs(s, [ f for f in mcs ], Fs)
return cost, [ f for f inFs0if is_true(model.eval(f)) ]
MCS alone is inefficient. In [11] we combine MUS and MCS steps.
Cores, Correction Sets, Satisfying Assignments
(M)US (Minimal) unsatisfiable subset
(minimal) subset of assertions that are unsatisfiable.
Also known as a core
(M)SS (Maximal) satisfiable subset
(maximal) subset of assertions that are satisfiable.
a, b, c, d =Bools('a b c d')
s =Solver()
s.add(Implies(a, b), Implies(c, d)) # background formulaprint s.consequences([a, c], # assumptions
[b, c, d]) # what is implied?
Claim: the two compute the same solutions if the projection operators are independent of the value of .
Initialization
def level(j,a):return max level of bound variable in atom a of parity j
Property Directed QSAT Algorithm
def strategy(M,j):returndef tailv(j):return
j =1M= null
whileTrue:if strategy(M, j) is unsat:if j == 1:returnFis unsat
if j == 2:returnFis sat
C=Core(, strategy(M, j))
J=Mbp(tailv(j), C)
j = index of max variable inJ of same parity as j
=JM= null
else:M= current model
j = j + 1
Finding strategies
Other main ingredient of QSAT is option for players to narrow options of opponents by revealing a strategy
at round :
value of is already fixed,
fixes value of ,
can make a function of .
Developing practical strategies is work in progress
Instead of tracking progress using marking use under approximations.
Maintain of under approximations.
Recall that are over approximations.
Satisfying
.
Search with Under-approximations
Decide and Conflict pushing a goal over
If , then goal cannot be reached.
If , then goal can be reached.
Otherwise case split on .
Search with Under-approximations
Reachable If is satisfiable, then return Reachable. Decide For for , add to if:
- .
- .
-
- is disjoint from for every . Decide For for , add to if:
- .
- .
-
- is disjoint from for every . Close For for , if is satisfiable, but is unsatsifiable,
then update , where .
Recursion-free Horn Clauses
Interpolation in standard form is a special case of Horn Clause solving.
(1)
IC3 (sans Inductive Generalization) produces as side-effect solutions that are interpolants.
Interpolants are quaint, almost beautiful[1, 3, 16].
def sign(s, x):if tt(s, x):return x
returnNot(x)
def cute(A,B,xs):
sA =Solver()
sB =Solver()
sA.add(A)
sB.add(B)
I= []
while sat == sB.check():if unsat == sA.check([ sign(sB, x) for x in xs ]):I1=Not(And(sA.unsat_core()))
sB.add(I1)
I += [I1]
else:returnNonereturnAnd(I)
Can also be viewed as an iteration of IC3 steps.
Generalization to EPR [6].
[1]Aws Albarghouthi, and Kenneth L. McMillan. “Beautiful Interpolants.” In CAV, 313–329. 2013. 🔎
[2]Fahiem Bacchus, and George Katsirelos. “Using Minimal Correction Sets to More Efficiently Compute Minimal
Unsatisfiable Sets.” In Computer Aided Verification - 27th International Conference, CAV
2015, San Francisco, CA, USA, July 18-24, 2015, Proceedings, Part
II, 70–86. 2015. doi:10.1007/978-3-319-21668-3_5. 🔎
[3]Sam Bayless, Celina Val, Thomas Ball, Holger Hoos, and Alan Hu. “Efficient Modular SAT Solving for IC3.” In FMCAD. 2013. 🔎
[4]Nikolaj Bjørner. “Linear Quantifier-Elimination as an Abstract Decision Procedure.” In IJCAR. 2010. 🔎
[5]Nikolaj Bjørner. “Satisfiability Modulo Theories.” Edited by Javier Esparza, Orna Grumberg, and Salomon Sickert, in Esparza et al. [22]. 2016. 🔎
[6]Nikolaj Bjørner, Arie Gurfinkel, Konstantin Korovin, and Ori Lahav. “Instantiations, Zippers and EPR Interpolation.” In LPAR 2013, 19th International Conference on Logic for Programming,
Artificial Intelligence and Reasoning, December 12-17, 2013, Stellenbosch,
South Africa, Short Papers Proceedings, 35–41. 2013. http://www.easychair.org/publications/?page=275044893. 🔎
[7]Nikolaj Bjørner, Arie Gurfinkel, Kenneth L. McMillan, and Andrey Rybalchenko. “Horn Clause Solvers for Program Verification.” In Fields of Logic and Computation II - Essays Dedicated to Yuri Gurevich
on the Occasion of His 75th Birthday, 24–51. 2015. doi:10.1007/978-3-319-23534-9_2. 🔎
[8]Nikolaj Bjørner, and Mikolás Janota. “Playing with Alternating Quantifier Satisfaction.” In LPAR Short Presentation Papers. 2015. 🔎
[9]Nikolaj Bjørner, Mikolás Janota, and William Klieber. “On Conflicts and Strategies in QBF.” In 20th International Conferences on Logic for Programming, Artificial
Intelligence and Reasoning - Short Presentations, LPAR 2015, Suva,
Fiji, November 24-28, 2015., 28–41. 2015. http://www.easychair.org/publications/paper/On_Conflicts_and_Strategies_in_QBF. 🔎
[10]Nikolaj Bjørner, Kenneth L. McMillan, and Andrey Rybalchenko. “On Solving Universally Quantified Horn Clauses.” In SAS, 105–125. 2013. 🔎
[11]Nikolaj Bjørner, and Nina Narodytska. “Maximum Satisfiability Using Cores and Correction Sets.” In Proceedings of the Twenty-Fourth International Joint Conference on
Artificial Intelligence, IJCAI 2015, Buenos Aires, Argentina, July
25-31, 2015, 246–252. 2015. http://ijcai.org/Abstract/15/041. 🔎
[12]Maria Paola Bonacina, Christopher Lynch, and Leonardo Mendonça de Moura. “On Deciding Satisfiability by Theorem Proving with Speculative
Inferences.” J. Autom. Reasoning 47 (2): 161–189. 2011. 🔎
[13]Aaron R. Bradley. “SAT-Based Model Checking without Unrolling.” In VMCAI, 70–87. 2011. 🔎
[14]Aaron R. Bradley, and Zohar Manna. “Checking Safety by Inductive Generalization of Counterexamples to
Induction.” In Formal Methods in Computer-Aided Design, 7th International Conference,
FMCAD 2007, Austin, Texas, USA, November 11-14, 2007, Proceedings, 173–180. 2007. doi:10.1109/FAMCAD.2007.15. 🔎
[15]Hana Chockler, Alexander Ivrii, and Arie Matsliah. “Computing Interpolants without Proofs.” In Hardware and Software: Verification and Testing - 8th International
Haifa Verification Conference, HVC 2012, Haifa, Israel, November
6-8, 2012. Revised Selected Papers, 72–85. 2012. doi:10.1007/978-3-642-39611-3_12. 🔎
[16]Hana Chockler, Alexander Ivrii, and Arie Matsliah. “Computing Interpolants without Proofs.” In Hardware and Software: Verification and Testing, edited by Armin Biere, Amir Nahir, and Tanja Vos, 7857:72–85. Lecture Notes in Computer Science. Springer Berlin Heidelberg. 2013. 🔎
[17]Alessandro Cimatti, and Alberto Griggio. “Software Model Checking via IC3.” In CAV, 277–293. 2012. 🔎
[18]Alessandro Cimatti, Alberto Griggio, Sergio Mover, and Stefano Tonetta. “IC3 Modulo Theories via Implicit Predicate Abstraction.” In TACAS, 46–61. 2014. 🔎
[19]M. Davis, G. Logemann, and D. Loveland. “A Machine Program for Theorem Proving.” Communications of the ACM. 1962. 🔎
[20]B. Dutertre, and L. de Moura. “A Fast Linear-Arithmetic Solver for DPLL(T).” In CAV. 2006. 🔎
[21]Niklas Eén, Alan Mishchenko, and Robert K. Brayton. “Efficient Implementation of Property Directed Reachability.” In FMCAD, 125–134. 2011. 🔎
[22]Javier Esparza, Orna Grumberg, and Salomon Sickert, editors. Dependable Software Systems Engineering. Volume 45. NATO Science for Peace and Security Series - D: Information and
Communication Security. IOS Press. 2016. 🔎
[23]Yeting Ge, and Leonardo Mendonça de Moura. “Complete Instantiation for Quantified Formulas in Satisfiabiliby
Modulo Theories.” In CAV, 306–320. 2009. 🔎
[24]Sergey Grebenshchikov, Nuno P. Lopes, Corneliu Popeea, and Andrey Rybalchenko. “Synthesizing Software Verifiers from Proof Rules.” In ACM SIGPLAN Conference on Programming Language Design and Implementation,
PLDI ’12, Beijing, China - June 11 - 16, 2012, 405–416. 2012. doi:10.1145/2254064.2254112. 🔎
[25]Krystof Hoder, and Nikolaj Bjørner. “Generalized Property Directed Reachability.” In Theory and Applications of Satisfiability Testing - SAT 2012 - 15th
International Conference, Trento, Italy, June 17-20, 2012. Proceedings, 157–171. 2012. doi:10.1007/978-3-642-31612-8_13. 🔎
[26]Krystof Hoder, Nikolaj Bjørner, and Leonardo Mendonça de Moura. “μZ- An Efficient Engine for Fixed Points with Constraints.” In Computer Aided Verification - 23rd International Conference, CAV
2011, Snowbird, UT, USA, July 14-20, 2011. Proceedings, 457–462. 2011. doi:10.1007/978-3-642-22110-1_36. 🔎
[27]Shachar Itzhaky, Nikolaj Bjørner, Thomas W. Reps, Mooly Sagiv, and Aditya V. Thakur. “Property-Directed Shape Analysis.” In CAV, 35–51. 2014. 🔎
[28]Mikolás Janota, Inês Lynce, and Joao Marques-Silva. “Algorithms for Computing Backbones of Propositional Formulae.” AI Commun. 28 (2): 161–177. 2015. doi:10.3233/AIC-140640. 🔎
[29]Dejan Jovanovic, and Leonardo Mendonça de Moura. “Solving Non-Linear Arithmetic.” In Automated Reasoning - 6th International Joint Conference, IJCAR
2012, Manchester, UK, June 26-29, 2012. Proceedings, 339–354. 2012. doi:10.1007/978-3-642-31365-3_27. 🔎
[30]Ulrich Junker. “QUICKXPLAIN: Preferred Explanations and Relaxations for Over-Constrained
Problems.” In Proceedings of the Nineteenth National Conference on Artificial Intelligence,
Sixteenth Conference on Innovative Applications of Artificial Intelligence,
July 25-29, 2004, San Jose, California, USA, 167–172. 2004. http://www.aaai.org/Library/AAAI/2004/aaai04-027.php. 🔎
[31]Roland Kindermann, Tommi A. Junttila, and Ilkka Niemelä “SMT-Based Induction Methods for Timed Systems.” In FORMATS, 171–187. 2012. 🔎
[32]Anvesh Komuravelli, Arie Gurfinkel, and Sagar Chaki. “SMT-Based Model Checking for Recursive Programs.” In CAV, 17–34. 2014. 🔎
[34]João Marques-Silva, Mikolás Janota, and Anton Belov. “Minimal Sets over Monotone Predicates in Boolean Formulae.” In Computer Aided Verification - 25th International Conference, CAV
2013, Saint Petersburg, Russia, July 13-19, 2013. Proceedings, 592–607. 2013. doi:10.1007/978-3-642-39799-8_39. 🔎
[35]Kenneth L. McMillan. “Lazy Annotation Revisited.” In Computer Aided Verification - 26th International Conference, CAV
2014, Held as Part of the Vienna Summer of Logic, VSL 2014, Vienna,
Austria, July 18-22, 2014. Proceedings, 243–259. 2014. doi:10.1007/978-3-319-08867-9_16. 🔎
[36]Carlos Mencía, Alessandro Previti, and João Marques-Silva. “Literal-Based MCS Extraction.” In Proceedings of the Twenty-Fourth International Joint Conference on
Artificial Intelligence, IJCAI 2015, Buenos Aires, Argentina, July
25-31, 2015, 1973–1979. 2015. http://ijcai.org/Abstract/15/280. 🔎
[37]Leonardo Mendonça de Moura, and Nikolaj Bjørner. “Efficient E-Matching for SMT Solvers.” In CADE, 183–198. 2007. 🔎
[38]Leonardo Mendonça de Moura, and Nikolaj Bjørner. “Engineering DPLL(T) + Saturation.” In IJCAR, 475–490. 2008. 🔎
[39]Leonardo Mendonça de Moura, and Nikolaj Bjørner. “Generalized, Efficient Array Decision Procedures.” In Proceedings of 9th International Conference on Formal Methods in Computer-Aided
Design, FMCAD 2009, 15-18 November 2009, Austin, Texas, USA, 45–52. 2009. doi:10.1109/FMCAD.2009.5351142. 🔎
[40]Leonardo Mendonça de Moura, and Nikolaj Bjørner. “Bugs, Moles and Skeletons: Symbolic Reasoning for Software
Development.” In IJCAR, 400–411. 2010. 🔎
[41]Nina Narodytska, and Fahiem Bacchus. “Maximum Satisfiability Using Core-Guided MaxSAT Resolution.” In AAAI 2014, 2717–2723. 2014. 🔎
[42]R. Nieuwenhuis, A. Oliveras, and C. Tinelli. “Solving SAT and SAT Modulo Theories: From an Abstract Davis–Putnam–Logemann–Loveland Procedure to DPLL(T).” J. ACM 53 (6). 2006. 🔎
[43]Anh-Dung Phan, Nikolaj Bjørner, and David Monniaux. “Anatomy of Alternating Quantifier Satisfiability (Work in
Progress).” In SMT-IJCAR, 120–130. 2012. 🔎
[44]Ruzica Piskac, Leonardo Mendonça de Moura, and Nikolaj Bjørner. “Deciding Effectively Propositional Logic Using DPLL and
Substitution Sets.” J. Autom. Reasoning 44 (4): 401–424. 2010. 🔎
[45]Raymond Reiter. “A Theory of Diagnosis from First Principles.” Artif. Intell. 32 (1): 57–95. 1987. doi:10.1016/0004-3702(87)90062-2. 🔎
[46]João P. Marques Silva, and Karem A. Sakallah. “GRASP: A Search Algorithm for Propositional Satisfiability.” IEEE Trans. Computers 48 (5): 506–521. 1999. 🔎
[47]Christoph M. Wintersteiger, Youssef Hamadi, and Leonardo Mendonça de Moura. “Efficiently Solving Quantified Bit-Vector Formulas.” Formal Methods in System Design 42 (1): 3–23. 2013. 🔎