Z3: an efficient SAT/SMT solver
SAT Problem SAT problem is translate in propositional formula that is composed by boolean variables ● connected by boolean operators: Not, And, Or, ->, <->. If the formula is satisfiable , there is an assignment that make the results true , otherwise the ● formula in unsat. The solution of the formula are based on the Truth table. The solution on Truth table is exponential ● in the number of variables. SAT is NP-Complete Problem. SAT solvers are successful for a big formula and a lot of practical problems. ●
SMT Theories SMT is Satisfiability Modulo Theories is about SAT extended with other theories ● SMT can add other abstract layers to handle more complicate expressions. ● SMT include the theory of integers, the theory of reals, the theory of arrays, the theory of data ● types, the theory of bit vectors and the theory of the pointers . SMT can be view a language of first order logic. ●
Z3 SAT/SMT Solver (Microsoft Research)
Z3 SMT/SAT Syntax set-logic and/or set-options (often redundant) ● declarations: declare-constant, declare-func ● ( assert…. ) containing the actual formula. ● ( check-sat ) to do the actual sat solving. ● ( get model ) to show the satisfying assignment. ●
Z3 SMT/SAT Variable Example (declare-const a Int) (declare-const b Int) (declare-const c Int) (declare-const d Int) (assert (and (> (* 2 a) (+ b c)) (> (* 2 b) (+ c d)) (> (* 2 c) (* 3 d)) (> (* 3 d) (+ a c)))) (check-sat) (get-model)
Z3 SMT/SAT Functions Example (declare-fun f (Int) Int) (assert (and (> (* 2 (f 1)) (+ (f 2) (f 3))) (> (* 2 (f 2)) (+ (f 3) (f 4))) (> (* 2 (f 3)) (* 3 (f 4))) (> (* 3 (f 4)) (+ (f 1) (f 3))))) (check-sat) (get-model)
Z3 SMT/SAT Big Number Example (declare-const A Int) (declare-const B Int) (declare-const C Int) (assert (and (= A 98798798987987987987987923423) (= B 763429999988888888887364578645) (= (+ (* 87 A) (* 93 B)) (+ C C)))) (check-sat) (get-model)
Z3 SMT/SAT If Statement Example (ite ( < a b ) 13 ( * 3 a )) If a < b return 13 Else return 3 * a
Recommend
More recommend