smt and z3
play

SMT and Z3 Nikolaj Bjrner Microsoft Research ReRISE Winter School, - PowerPoint PPT Presentation

SMT and Z3 Nikolaj Bjrner Microsoft Research ReRISE Winter School, Linz, Austria February 5, 2014 Plan Mon An invitation to SMT with Z3 Tue Equalities and Theory Combination Wed Theories: Arithmetic, Arrays, Data types Thu Quantifiers and


  1. SMT and Z3 Nikolaj BjΓΈrner Microsoft Research ReRISE Winter School, Linz, Austria February 5, 2014

  2. Plan Mon An invitation to SMT with Z3 Tue Equalities and Theory Combination Wed Theories: Arithmetic, Arrays, Data types Thu Quantifiers and Theories Fri Programming Z3: Interfacing and Solving

  3. Quiz Show: A difference logic graph without negative cycles has a model. Give a procedure for extracting a model. True or false: A formula over difference logic has a model over reals iff it has a model over integers? Give an efficient algorithm to extract models for UTVPI over integers. Encode lambda Calculus into π‘›π‘π‘ž, 𝐿, 𝑠𝑓𝑏𝑒 (without 𝐽 ).

  4. Plan β€’ Arithmetic β€’ Arrays and friends β€’ Data types [Introduction]

  5. What Theories? Overall aim: Rich Theories (and logics) with Efficient Decision Procedures ASP Auth MSOL Sequences XDucers Queues DL homomor Optimiz BAPA Orders Objects HOL MultiSets phisms ation Floats f* * Strings Reg. Exprs. NRA NIA SAT Arrays Bit-Vectors Alg. DT EUF LRA LIA

  6. Be afraid!

  7. Linear Real Arithmetic β€’ Many approaches – Graph-based for difference logic: a – b ο‚£ 3 – Fourier-Motzkin elimination: – Standard Simplex – General Form Simplex – GDPLL [McMillan], Unate Resolution [Coton], Conflict Resolution [Korovin et.al.]

  8. Difference Logic: a – b ο‚£ 5 Very useful in practice! Most arithmetical constraints in software verification/analysis are in this fragment. x := x + 1 x 1 = x 0 + 1 x 1 - x 0 ο‚£ 1, x 0 - x 1 ο‚£ - 1

  9. Job shop scheduling

  10. Difference Logic Chasing negative cycles! Algorithms based on Bellman-Ford (O(mn)).

  11. Unit Two Variables Per Inequality 𝑦 + 𝑧 ≀ 5 ∧ βˆ’π‘¦ + 𝑧 ≀ βˆ’4 ∧ 𝑧 + 𝑧 β‰₯ 1

  12. Unit Two Variables Per Inequality 𝑦 + 𝑧 ≀ 5 ∧ βˆ’π‘¦ + 𝑧 ≀ βˆ’4 ∧ 2𝑧 β‰₯ 1 2𝑧 ≀ 1 ∧ 2𝑧 β‰₯ 1

  13. Unit Two Variables Per Inequality 𝑦 + 𝑧 ≀ 5 ∧ βˆ’π‘¦ + 𝑧 ≀ βˆ’4 ∧ 2𝑧 β‰₯ 1 2𝑧 ≀ 1 ∧ 2𝑧 β‰₯ 1 𝑧 ≀ 0 ∧ 𝑧 β‰₯ 1

  14. Unit Two Variables Per Inequality: UTVPI Reduce to Difference Logic: β€’ For every variable 𝑦 introduce fresh variables 𝑦 + , 𝑦 βˆ’ β€’ Meaning: 2𝑦 ≔ 𝑦 + βˆ’ 𝑦 βˆ’ β€’ Rewrite constraints as follows: β‡’ 𝑦 + βˆ’ 𝑧 + ≀ 𝑙 β€’ 𝑦 βˆ’ 𝑧 ≀ 𝑙 𝑧 βˆ’ βˆ’ 𝑦 βˆ’ ≀ 𝑙 β€’

  15. UTVPI β‡’ 𝑦 + βˆ’ 𝑧 + ≀ 𝑙 β€’ 𝑦 βˆ’ 𝑧 ≀ 𝑙 𝑧 βˆ’ βˆ’ 𝑦 βˆ’ ≀ 𝑙 β‡’ 𝑦 + βˆ’ 𝑦 βˆ’ ≀ 2𝑙 β€’ 𝑦 ≀ 𝑙 β‡’ 𝑦 + βˆ’ 𝑧 βˆ’ ≀ 𝑙 β€’ 𝑦 + 𝑧 ≀ 𝑙 𝑧 + βˆ’ 𝑦 βˆ’ ≀ 𝑙 β€’ 𝑦 + 𝑧 ≀ 𝑙 β‡’ chalkboard

  16. UTVPI 𝑦 + 𝑧 ≀ 5 ∧ βˆ’π‘¦ + 𝑧 ≀ βˆ’4 ∧ 2𝑧 β‰₯ 1 𝑦 + βˆ’ 𝑧 βˆ’ ≀ 5 ∧ 𝑧 + βˆ’ 𝑦 βˆ’ ≀ 5 ∧ βˆ’π‘¦ + + 𝑧 + ≀ βˆ’4 ∧ 𝑦 βˆ’ βˆ’ 𝑧 βˆ’ ≀ βˆ’4 ∧ 𝑧 βˆ’ βˆ’ 𝑧 + ≀ 1

  17. UTVPI β€’ Solve for 𝑦 + and 𝑦 βˆ’ β€’ 𝑁(𝑦) ≔ (𝑁(𝑦 + ) βˆ’ 𝑁(𝑦 βˆ’ ))/2 β€’ Nothing can go wrong… 2𝑧 ≀ 1 ∧ 2𝑧 β‰₯ 1

  18. UTVPI β€’ 𝑁(𝑦) ≔ (𝑁(𝑦 + ) βˆ’ 𝑁(𝑦 βˆ’ ))/2 β€’ Nothing can go wrong… as if β€’ What if: – 𝑦 is an integer – 𝑁(𝑦 + ) is odd and – 𝑁(𝑦 βˆ’ ) is even β€’ Thm : Parity can be fixed iff there is no tight loop forcing the wrong parity

  19. UTVPI 𝑦 βˆ’ βˆ’ 𝑧 + ≀ 5 𝑧 + βˆ’ 𝑨 βˆ’ ≀ βˆ’6 𝑦 βˆ’ βˆ’ 𝑦 + ≀ βˆ’3 𝑨 βˆ’ βˆ’ 𝑦 + β‡’ ≀ βˆ’2 𝑦 + βˆ’ 𝑦 βˆ’ ≀ 3 𝑦 + βˆ’ 𝑀 + ≀ 3 𝑀 + βˆ’ 𝑦 βˆ’ ≀ 0

  20. General Form

  21. From Definitions to a Tableau s 1 ο‚Ί x + y, s 2 ο‚Ί x + 2y

  22. From Definitions to a Tableau s 1 ο‚Ί x + y, s 2 ο‚Ί x + 2y s 1 = x + y, s 2 = x + 2y

  23. From Definitions to a Tableau s 1 ο‚Ί x + y, s 2 ο‚Ί x + 2y s 1 = x + y, s 2 = x + 2y s 1 - x - y = 0 s 2 - x - 2y = 0

  24. From Definitions to a Tableau s 1 ο‚Ί x + y, s 2 ο‚Ί x + 2y s 1 = x + y, s 2 = x + 2y s 1 , s 2 are basic (dependent) s 1 - x - y = 0 x,y are non-basic s 2 - x - 2y = 0

  25. Pivoting A way to swap a basic with a non-basic variable! It is just equational reasoning. Key invariant: a basic variable occurs in only one equation. Example: swap s 1 and y s 1 - x - y = 0 s 2 - x - 2y = 0

  26. Pivoting A way to swap a basic with a non-basic variable! It is just equational reasoning. Key invariant: a basic variable occurs in only one equation. Example: swap s 1 and y s 1 - x - y = 0 s 2 - x - 2y = 0 -s 1 + x + y = 0 s 2 - x - 2y = 0

  27. Pivoting A way to swap a basic with a non-basic variable! It is just equational reasoning. Key invariant: a basic variable occurs in only one equation. Example: swap s 1 and y s 1 - x - y = 0 s 2 - x - 2y = 0 -s 1 + x + y = 0 s 2 - x - 2y = 0 -s 1 + x + y = 0 s 2 - 2s 1 + x = 0

  28. Pivoting A way to swap a basic with a non-basic variable! It is just equational reasoning. Key invariant: a basic variable occurs in only one equation. Example: swap s 1 and y s 1 - x - y = 0 It is just substituting s 2 - x - 2y = 0 equals by equals. -s 1 + x + y = 0 s 2 - x - 2y = 0 -s 1 + x + y = 0 s 2 - 2s 1 + x = 0

  29. Definition: Pivoting An assignment (model) is a mapping from variables to values A way to swap a basic with a non-basic variable! It is just equational reasoning. Key invariant: a basic variable occurs in only one equation. Example: swap s 1 and y s 1 - x - y = 0 It is just substituting s 2 - x - 2y = 0 equals by equals. -s 1 + x + y = 0 Key Property: s 2 - x - 2y = 0 If an assignment satisfies the equations before a pivoting -s 1 + x + y = 0 step, then it will also satisfy s 2 - 2s 1 + x = 0 them after!

  30. Definition: Pivoting An assignment (model) is a mapping from variables to values A way to swap a basic with a non-basic variable! It is just equational reasoning. Key invariant: a basic variable occurs in only one equation. Example: swap s 2 and y s 1 - x - y = 0 It is just substituting s 2 - x - 2y = 0 equals by equals. Example: -s 1 + x + y = 0 M(x) = 1 Key Property: s 2 - x - 2y = 0 M(y) = 1 If an assignment satisfies the M(s 1 ) = 2 equations before a pivoting M(s 2 ) = 3 -s 1 + x + y = 0 step, then it will also satisfy s 2 - 2s 1 + x = 0 them after!

  31. Equations + Bounds + Assignment

  32. β€œRepairing Models” If the assignment of a non-basic variable does not satisfy a bound, then fix it and propagate the change to all dependent variables. a = c – d a = c – d b = c + d b = c + d M(a) = 0 M(a) = 1 M(b) = 0 M(b) = 1 M(c) = 0 M(c) = 1 M(d) = 0 M(d) = 0 1 ο‚£ c 1 ο‚£ c

  33. β€œRepairing Models” If the assignment of a non-basic variable does not satisfy a bound, then fix it and propagate the change to all dependent variables. Of course, we may introduce new β€œproblems”. a = c – d a = c – d b = c + d b = c + d M(a) = 0 M(a) = 1 M(b) = 0 M(b) = 1 M(c) = 0 M(c) = 1 M(d) = 0 M(d) = 0 1 ο‚£ c 1 ο‚£ c a ο‚£ 0 a ο‚£ 0

  34. β€œRepairing Models” If the assignment of a basic variable does not satisfy a bound, then pivot it, fix it, and propagate the change to its new dependent variables. a = c – d c = a + d c = a + d b = c + d b = a + 2d b = a + 2d M(a) = 0 M(a) = 0 M(a) = 1 M(b) = 0 M(b) = 0 M(b) = 1 M(c) = 0 M(c) = 0 M(c) = 1 M(d) = 0 M(d) = 0 M(d) = 0 1 ο‚£ a 1 ο‚£ a 1 ο‚£ a

  35. β€œRepairing Models” Sometimes, a model cannot be repaired. It is pointless to pivot. The value of M(a) is too big. We can reduce it by: a = b – c - reducing M(b) a ο‚£ 0, 1 ο‚£ b, c ο‚£ 0 not possible b is at lower bound - increasing M(c) M(a) = 1 not possible c is at upper bound M(b) = 1 M(c) = 0

  36. β€œRepairing Models” Extracting proof from failed repair attempts is easy. s 1 ο‚Ί a + d, s 2 ο‚Ί c + d a = s 1 – s 2 + c a ο‚£ 0, 1 ο‚£ s 1 , s 2 ο‚£ 0, 0 ο‚£ c M(a) = 1 M(s 1 ) = 1 M(s 2 ) = 0 M(c) = 0

  37. β€œRepairing Models” Extracting proof from failed repair attempts is easy. s 1 ο‚Ί a + d, s 2 ο‚Ί c + d a = s 1 – s 2 + c a ο‚£ 0, 1 ο‚£ s 1 , s 2 ο‚£ 0, 0 ο‚£ c M(a) = 1 M(s 1 ) = 1 M(s 2 ) = 0 M(c) = 0 { a ο‚£ 0, 1 ο‚£ s 1 , s 2 ο‚£ 0, 0 ο‚£ c } is inconsistent

  38. β€œRepairing Models” Extracting proof from failed repair attempts is easy. s 1 ο‚Ί a + d, s 2 ο‚Ί c + d a = s 1 – s 2 + c a ο‚£ 0, 1 ο‚£ s 1 , s 2 ο‚£ 0, 0 ο‚£ c M(a) = 1 M(s 1 ) = 1 M(s 2 ) = 0 M(c) = 0 { a ο‚£ 0, 1 ο‚£ s 1 , s 2 ο‚£ 0, 0 ο‚£ c } is inconsistent { a ο‚£ 0, 1 ο‚£ a + d, c + d ο‚£ 0, 0 ο‚£ c } is inconsistent

  39. What are arrays? β€’ Applicative stores: ο€½ ( , , )[ ] write a i v i v ο‚Ή οƒž ο€½ ( , , )[ ] [ ] i j write a i v j a j β€’ Or, special combinator: ο€½  ο€½ ( , , ) . ( , , [ ]) write a i v j ite i j v a j

  40. What are arrays? β€’ Special combinator: ο€½  ο€½ ( , , ) . ( , , [ ]) write a i v j ite i j v a j β€’ Existential fragment is decidable by reduction to congruence closure using finite set of instances. β€’ Models for arrays are finite maps with default values.

  41. What else are arrays? β€’ Special combinators: ο€½  ο€½ ( , , ) . ( , , [ ]) write a i v j ite i j v a j ο€½  ( ) . K v j v ο€½  ( , ) . ( [ ], [ ]) map a b j f a j b j f β€’ Result : Existential fragment is decidable and in NP by reduction to congruence closure using finite set of instances.

Recommend


More recommend