Nikolaj Bjørner
Microsoft Research
nbjorner@microsoft.com |
Lev Nachmanson
Microsoft Research
levnach@microsoft.com |
linear and non-linear arithmetic
Cardinality, Pseudo-Boolean, finite range LIA theories
Modular arithmetic, finite fields
Bi-linear real arithmetic
Non-unit two-variable per inequality
At most one (unit) positive variable per inequality (Horn) .
What is the non-unit complexity?
max-atom: . In NP co-NP, local strategy/policy iteration (Costan et al., 2005; Gawlitza and Seidl, 2007; Bezem et al., 2008; Karpenkov et al., 2016; Karpenkov, 2017)
Knapsack theories: all variables with positive coefficients,
except for one inequality where all variables have negative coefficients.
What: Variables range over reals (rationals). Addition, multiplication by constant
How: Dual Simplex
Why: A basis for everything more
SMT solving based on Dual Simplex maintain a tableau of the form:
where are basic and are non-basic variables.
x, y = Reals('x y')
solve([x >= 0, Or(x + y <= 2, x + 2*y >= 6),
Or(x + y >= 2, x + 2*y > 4)])
Introduce slacks to define terms
Formula using slacks:
Equalities are global definitions
Bounds (e.g., ) are added/deleted during search.
- are basic (dependent)
- are non-basic
- are basic (dependent)
- are non-basic
Initial values:
Bounds :
, make non-basic.
- are basic (dependent)
- are non-basic
A tableau is infeasible if there is a row such that
conflict explanation: literals that are used for tight bounds.
Convexity: , then for or .
Z3 uses bignum (infinite precision arithmetic), always.
Z3 also contains difference logic solvers. They are used sparingly for SMTLIB categories IDL/RDL.
Integration of policy/strategy iteration?
Goal is to find minimal such that:
Policy Initially replaces by (arbitrary choice).
Solve the resulting unit-Horn system with solution .
Evaluate each subterm wrt. to check if it preserves .
Repeat For each , if ,
but , then update .
What: Extract Boolean propagation axioms from arithmetic.
How: Index bounds atoms that are created and infer bounds from tableau.
Why: It is much more efficient to have the SAT solver propagate (binary) clauses than theory reasoning.
If is asserted, then directly propagate to false.
For atoms add axioms .
Infer new bounds of variables: .
What: Extract equalities between variables and propagate equalities to other theories.
How: By cheap tests on the tableau.
Why: Useful to propagate congruences for arithmetic variables used under non arithmetical function symbols.
Solved tableau:
assignment . Necessary condition for . Sufficient (incomplete) condition:
are linear combinations of fixed variables. We never have to calculate !
Will this method find all implied equalities?
If are shared variables and , but the equality between has not been propagated. Then we can assume the equality atom. It is satisfied in the theory of arithmetic, and the equality atom will propagate to other theories that have to reconcile on .
If then assume : conflicts with .
Arithmetic solver:
Add atom to search space and assign it to true.
EUF solver
Conflict:
Lemma
Arithmetic solver: .
New lemma
Z3 exposes solve_for API function to extract all equalities through Gaussian elimination.
Integrate stronger inequality propagation eagerly?
(set-logic QF_IDL) ; optional in Z3
(declare-fun t11 () Int)
(declare-fun t12 () Int)
(declare-fun t21 () Int)
(declare-fun t22 () Int)
(declare-fun t31 () Int)
(declare-fun t32 () Int)
(assert (and (>= t11 0) ...))
(assert (and (>= t21 0) ...))
(assert (and (>= t31 0) (>= t32 (+ t31 2)) (<= (+ t32 3) 8)))
(assert (or ... (>= t21 (+ t11 2))))
(assert (or (>= t21 (+ t31 2)) ...))
(check-sat)
(get-model) ; display the model
Solve difference logic using graph Bellman-Ford network flow algorithm. Negative cycle unsat.
IDL poly time but is not convex. : two out of three have to be equal.
UF is poly time.
Quiz [Vaughan Pratt]: The combination IDL+UF is NP hard.
Add bit-vector operators together with on-demand expansion.
Native arithmetic operators and decision procedures for bit-wise and, shift left, shift right logical and shift right arithmetical.
Quiz: express bitwise negation.
Eager axioms:
On-demand axioms - the rest
An instance from a plant capacity problem:
Direct MIP-style encoding: - Task is at station attended by operator .
Instead use EUF , .
Scales encoding, but loses propagation efficiency.
Claim: Ackerman reduction simulate indicator variables.
What: Variables range over Integers. Addition, multiplication by constant.
How: Conservative: If unsat in LRA then unsat in LIA. Cuts, Branch and Bound.
Why: A practical basis for program verification (few verification systems use bit-vectors) and many applications.
When can a solution to LRA be used for LIA?
Patching and Cubes: If assignment from LRA is already integral or can be fixed.
GCD Test and bounds tightening: Detect when there are no integer solutions.
Cuts and branches: Block current LRA solution.
Proposition: If has a solution over the reals, then
has an integer solution obtained by rounding.
Example: Given
Solve instead
Real solution . Then is an integer solution.
Observation: One can often avoid strengthening inequalities.
bounds on variables .
differences between variables need not be strengthened to .
octagon inequalities can be strengthened to , or solutions can be patched.
unit horn inequalities
Basic GCD: is infeasible, if
Extended GCD: is infeasible if
Example:
Constraints: .
Assume is square and a tight non-integral solution .
Find Hermite , unimodular , s.t. .
Then
Then is not integral either.
Branch on some non-integral : .
Bring tableau into integer solved form with integer (also used by Pugh's Omega test):
Example 1.
LRA solver assigns , for integer .
Create branch atom .
When is assigned, upper bound is added to tableau.
When is assigned, then lower bound is added to tableau.
Opportunities for micro-tuning are endless.
Smart scheduling for LIA (and NRA/NIA) end-game solvers?
LIA solver for small integers.
IntSAT/CutSAT not part of Z3.
What: Variables range over Reals. Addition, unrestricted multiplication.
How: Incremental linearization, CAD.
Why: A basis for solving also NIA and interesting self-contained uses pop up, such as Economy.
Subset of variables are monomials :
Z3 tracks some equalities: If and is known, then is also used for lemmas.
Suppose is in tableau, but .
Patching uses LP patch lookahead.
Monomial propagation:
Recall: A term is a slack variable introduced as short-hand for arithmetic expression.
Interval arithmetic isn't distributive:
Let
Then
But
So z3 explores different variants of distributing multiplication over terms.
Design goals:
Integration of linearization with NLSAT (Promies et al., 2025)
-satisfiability to leverage numeric methods.
Postitiv Stellensatz (ground and quantifiers)
What: Variables range over Integers. Addition, unrestricted multiplication.
How: Methods for NRA + LIA +
Why: The tougher spot in verification tools, such as F* and Certora.
QF_NIA is undecidable (Davis et al., 1961; Matiyasevich, 1970): there is no complete proof system for UNSAT.
QF_NIA used by ZK/Smart Contract auditors for bounded integers .
Partial solution by
(Jovanović, 2017): add branch and bound to NLSAT. Also current method in Z3's NLSAT.
(Cimatti et al., 2018b): incremental linearization.
Idea: Augment NLSAT (complete for NRA) post-check for integers.
If solution to is not integer, but in interval , then
Add axiom .
Run NLSAT again.
Suppose . Then setting , ensures that .
Consistency checks on equations produced by Gröbner saturation.
Create lemma if current assignment to violates or . To not introduce divergence, z3 skips lemmas of the form .
Identifying practical inference algorithms where .
Local search
Still very fragile, some can be mitigated by parallelism
Grow under-approximation: :
Initially
Maintain, under-approximates and set .
Suppose
Compute interpolant :
Initially
Add conjunctions from I to that are inductive, that is:
You can set the initial value of variables.
(declare-const x Int)
(set-initial-value x 10)
(push)
(assert (> x 0))
(check-sat)
(eval x)
; 10
It is not always possible to enforce: If a benchmark is translated to SAT, initialization is partial.