Lecture 11 · Arithmetic I: Linear Real Arithmetic and the Simplex Method

Introduction to Automated Reasoning · Lecture 11。个人学习讲义与配套实验,按主题整理并持续修订。

课程源码 ZIP ↓

个人整理的学习笔记,非官方讲义;课程来源与整理说明见课程介绍。配套示例未逐一运行验证。

本篇目录

Maps to: Stanford CS 257 Introduction to Automated Reasoning (Winter 2026), Lecture 11 · Tue 02/10/2026 · First-order theories: arithmetic I (Hanna Lachnitt). Reading: Kroening & Strichman (DP) §5.1–5.2. Basis: The Stanford slides are on Canvas and not public. This lecture follows the public Iowa deck Theory Solvers II (CS:4980, Cesare Tinelli, Spring 2024). That deck says it is adapted from slides by Clark Barrett, Caroline Trippel and Andrew (Haoze) Wu (Stanford), with slides contributed by Guy Katz, and it covers:

  • QF_LRA and linear programming;
  • the simplex method in dictionary form: slack variables, pivoting, Dantzig’s rule, initialization by an auxiliary problem, degeneracy, cycling and Bland’s rule;
  • the reduction of satisfiability to LP;
  • a neural-network verification example.

The deck’s last slide lists “general LPs with bounds” and “infeasible subsets (theory explanations)” as improvements. §5 develops exactly those, following Dutertre and de Moura (2006), the version of simplex inside SMT solvers. “The slides” below means the Iowa deck.

These notes add:

  • a module, simplex.py: the textbook simplex with a trace, the general simplex with bounds, Farkas certificates and δ-rationals, Fourier–Motzkin elimination, and an LRA theory solver for Lecture 10’s CDCL(T);
  • the slides’ dictionaries reproduced pivot by pivot;
  • Chvátal’s cycling example and the Klee–Minty cube;
  • job-shop scheduling, and the slides’ network verified (its property fails);
  • every answer certified.

The experiments and their code were designed for these notes and do not reflect what was said in class. Code: code/lecture11/ (3 scripts + 1 module; Python standard library only; 1 to 3 seconds each) Reading time: 3 hours including running the code


0. How to read this lecture

0.1 Learning goals

After this lecture you should be able to:

  1. Define QF_LRA, a linear program, feasible / optimal / unbounded, and picture the feasible set as a convex polyhedron.
  2. Run the simplex method on a dictionary: choose the entering and leaving variables, pivot, and recognize optimality.
  3. Initialize simplex with the auxiliary problem, and explain degeneracy, cycling and Bland’s rule.
  4. Reduce satisfiability of linear literals to an LP, as the slides do, and say why SMT solvers do something else.
  5. Run the general simplex with bounds, explain a conflict, and check its Farkas certificate.
  6. Handle strict inequalities with δ-rationals and turn a δ-solution into a real one.
  7. Explain why the general simplex is incremental and backtrackable, and plug it into CDCL(T) with bound propagation.

0.2 Prerequisites and scope

AssumedIntroduced hereDeveloped later
CDCL(T), the theory-solver interface (Lecture 10)the LRA theory solverintegers: branch and bound, cuts (Lecture 12)
linear equations, Gaussian eliminationsimplex, Bland’s rule, Farkas’ lemmaFourier–Motzkin in depth, difference logic (Lecture 12)
first-order theories (Lecture 8)TRAT_{RA}, QF_LRAcombining LRA with EUF (Lecture 18)

Scope: linear real arithmetic, where multiplication is only by numerals. Nonlinear real arithmetic (decidable, Tarski; cylindrical algebraic decomposition) is outside this course.

0.3 Map

§1  QF_LRA and linear programs                                  ← code 01
§2  the simplex method: dictionaries and pivots                 ← code 01
§3  initialization, degeneracy, cycling, Bland, the worst case   ← code 01
§4  satisfiability as linear programming (the slides)            ← code 02
§5  the general simplex of SMT solvers                           ← code 02
§6  pivoting rules, and Fourier–Motzkin                          ← code 02
§7  LRA inside CDCL(T)                                           ← code 03
§8 summary   §9 common pitfalls   §10 exercises   §11 further reading   §12 next lecture

0.4 Notation

SymbolMeaning
A,b,cA, b, cconstraint matrix, right-hand sides, objective: maximize cTxc^T x subject to Ax≤bAx \le b
basic / non-basicleft-hand / right-hand variables of a dictionary (non-basic ones are at their bounds)
ℓi,ui\ell_i, u_ilower and upper bound of variable xix_i in the general simplex
β(x)\beta(x)the current assignment
a+bδa + b\deltaa δ-rational: δ\delta is a positive infinitesimal
λk\lambda_kFarkas multipliers

0.5 The code of this lecture

One module, simplex.py:

  • numbers: exact Fractions everywhere, and DeltaRational for a+bδa + b\delta;
  • linear terms: linearize, Constraint (with canonical, which sets the first coefficient to 1 so equivalent forms share a slack), atom_constraint;
  • textbook simplex: Dictionary (pivot, Dantzig / Bland rules, cycle detection, traces) and two_phase;
  • general simplex: GeneralSimplex (tableau, bounds with tags, check() with Bland or greedy pivoting, Farkas explanations, undo, traces), plus concrete_delta and farkas_check;
  • fourier_motzkin, an independent decision procedure;
  • the theory solver LRA, with bound propagation, plus preprocess (arithmetic equalities into two ≤), solve_lra, check_model_lra and fm_unsat;
  • the benchmarks: the slides’ LPs, Chvátal’s example, klee_minty, random systems, job_shop, the ReLU network.

1. QF_LRA and linear programs

1.1 The theory

The theory of real arithmetic TRAT_{RA} has signature {+,−,∗,≤}\{+, -, *, \le\} plus numerals, and interprets them over R\mathbb{R}. QF_LRA is its quantifier-free, linear fragment: every ∗* has a numeral as one argument. A literal is then a linear constraint a1x1+⋯+anxn⋈ba_1x_1 + \dots + a_nx_n \bowtie b with ⋈∈{≤,<,=}\bowtie \in \{\le, <, =\}, possibly negated.

The slides note that many SMT solvers, cvc5 and Z3 among them, use a version of the simplex method as their QF_LRA theory solver.

1.2 Linear programs

A linear program (LP) asks:

maximize cTxc^T x subject to Ax≤bAx \le b.

The slides’ terminology, on maximize 2x2−x12x_2 - x_1 subject to x1+x2≤3x_1 + x_2 \le 3, 2x1−x2≤−52x_1 - x_2 \le -5 (script 01, Part 1):

pointfeasible?objective
(0, 0)no–
(−2, 1)yes4
(−10, 13)yes36

This LP is unbounded. Along x1=−tx_1 = -t, x2=3+tx_2 = 3 + t the point stays feasible for t≥2/3t \ge 2/3, and the objective 6+3t6 + 3t grows without limit.

Geometry (the slides):

  • the feasible set {x∣Ax≤b}\{x \mid Ax \le b\} is a convex polyhedron, an intersection of half-spaces;
  • the LP is infeasible iff the polyhedron is empty, and unbounded iff it is open in the direction of cc;
  • a bounded LP attains its optimum at a vertex.

LP geometry


2. The simplex method

2.1 Dictionaries

Dantzig’s simplex method (late 1940s; the slides date it 1949) walks from vertex to vertex. Take the standard form: maximize ∑jcjxj\sum_j c_j x_j subject to ∑jaijxj≤bi\sum_j a_{ij} x_j \le b_i and x≥0x \ge 0 (every LP can be brought into it).

Add a slack variable per constraint, xn+i=bi−∑jaijxj≥0x_{n+i} = b_i - \sum_j a_{ij}x_j \ge 0. The resulting dictionary writes the slacks and zz in terms of the original variables. The slides’ running example (script 01, Part 2):

x4 = 5 - 2x1 - 3x2 - x3
x5 = 11 - 4x1 - x2 - 2x3
x6 = 8 - 3x1 - 4x2 - 2x3
z  = 5x1 + 4x2 + 3x3

Basic variables are on the left; non-basic ones are on the right, all 0. When every constant is ≥0\ge 0 the dictionary is feasible: the solution x1=x2=x3=0x_1 = x_2 = x_3 = 0, x4=5x_4 = 5, x5=11x_5 = 11, x6=8x_6 = 8.

2.2 Pivoting

Each step of the method makes three choices:

  1. Entering variable. A non-basic variable with a positive coefficient in zz: increasing it increases zz. Dantzig’s rule takes the largest coefficient, here x1x_1.
  2. Leaving variable. The basic variable that first hits 0 as the entering one grows: the ratio test. Here x1≤5/2,11/4,8/3x_1 \le 5/2, 11/4, 8/3, so x4x_4 leaves.
  3. Pivot. Solve x4x_4‘s equation for x1x_1 and substitute it everywhere.

Script 01 prints the slides’ dictionaries exactly:

pivot: x1 enters, x4 leaves; z: 0 -> 25/2
    x1 = 5/2 - 3/2x2 - 1/2x3 - 1/2x4
    x5 = 1 + 5x2 + 2x4
    x6 = 1/2 + 1/2x2 - 1/2x3 + 3/2x4
    z  = 25/2 - 7/2x2 + 1/2x3 - 5/2x4

pivot: x3 enters, x6 leaves; z: 25/2 -> 13
    x1 = 2 - 2x2 - 2x4 + x6
    x3 = 1 + x2 + 3x4 - 2x6
    x5 = 1 + 5x2 + 2x4
    z  = 13 - 3x2 - x4 - x6

Optimality. Every coefficient of zz is now negative, and x2,x4,x6≥0x_2, x_4, x_6 \ge 0. So z≤13z \le 13 for every feasible point, and (2,0,1)(2, 0, 1) is optimal.

The slides’ invariants:

  • the number of equations never changes;
  • every variable is either basic or non-basic;
  • the non-basic variables sit at their bounds;
  • the basic values follow from the equations.

Why exact arithmetic. The fractions 5/2 and 1/2 appear after one pivot. A floating-point simplex accumulates rounding error and can declare feasible what is not, or the reverse. For a decision procedure that is unacceptable, so every number in simplex.py is a Fraction. That is the slides’ first suggested improvement.


3. Initialization, degeneracy and termination

3.1 The auxiliary problem

If some bi<0b_i < 0, the origin is infeasible and there is no starting dictionary. The slides’ fix is to solve the auxiliary problem

maximize −x0-x_0 subject to Ax−x0≤bAx - x_0 \le b, x≥0x \ge 0, x0≥0x_0 \ge 0.

A large enough x0x_0 satisfies every constraint. Script 01, Part 3 reproduces the slides’ example:

x3 = -2 - 2x1 + 3x2 + x0           one pivot (x0 enters, x4 leaves):   x3 = 2 + 2x1 + 2x2 + x4
x4 = -4 - 4x1 + x2 + x0                                                 x0 = 4 + 4x1 - x2 + x4
z  = -x0                                                                z  = -4 - 4x1 + x2 - x4

The original problem is feasible iff the auxiliary optimum has x0=0x_0 = 0 (2 pivots here). Phase 2 then continues from that basis with the original objective. For the slides’ objective (maximize x1+2x2x_1 + 2x_2) it finds the LP unbounded: x2x_2 can grow forever. Minimizing instead gives 8 at (0,4)(0, 4).

Phase 1 is a satisfiability check. It decides whether Ax≤bAx \le b has a solution, with no objective. That is all an SMT solver needs (§5).

3.2 Cycling and Bland’s rule

The slides’ Theorem 1: simplex fails to terminate iff it cycles, generating the same dictionary infinitely often. The reasoning:

  • there are finitely many bases;
  • each determines its dictionary;
  • zz never decreases.

Cycling therefore needs degenerate pivots, where the entering variable cannot actually grow and zz is unchanged.

Chvátal’s example (script 01, Part 4) shows it really happens:

pivotentersleavesz after
1x1x50
2x2x60
3x3x10
4x4x20
5x5x30
6x6x40

After 6 degenerate pivots under Dantzig’s rule, the basis is {x5, x6, x7} again: the method loops forever.

Bland’s rule (1977) prevents this:

  • the entering variable is the one with the smallest index among those that improve zz;
  • the leaving variable is the one with the smallest index among the tied candidates.

Theorem (Bland). With these choices simplex never cycles. On Chvátal’s example it reaches the optimum z=1z = 1 at x=(1,0,1,0)x = (1, 0, 1, 0) after 7 pivots.

3.3 The worst case

On the Klee–Minty cube (1972), a squashed nn-dimensional cube, Dantzig’s rule visits every vertex:

nverticespivots, Dantzigpivots, Bland
416159
825625567
112,0482,047287

Bland’s rule is no cure for the worst case: its counts grow by about 1.6 per dimension here, also exponentially. No pivoting rule is known to be polynomial.

The slides list the alternatives: the ellipsoid method (Khachiyan 1979) and interior-point methods (Karmarkar 1984) are polynomial. Simplex is the oldest and theoretically worst, and still the most popular, because it is fast in practice and, for SMT, because it is incremental (§5).

Run it: python3 01_linear_programming.py (about 1 s), with figures/01_lp_geometry.png.


4. Satisfiability as linear programming

The slides reduce the satisfiability of a set of linear literals to one LP in three steps:

  1. Equalities. aTx=ba^Tx = b becomes aTx≤ba^Tx \le b and −aTx≤−b-a^Tx \le -b.
  2. Negated inequalities. ¬(aTx≤b)\neg(a^Tx \le b) becomes −aTx+y≤−b-a^Tx + y \le -b with one fresh y>0y > 0 shared by all of them. If there are none, add y≤1y \le 1.
  3. Maximize yy subject to the result. The literals are satisfiable iff the optimum is positive.

Script 02, Part 1 implements this, splitting each free xx into x+−x−x^+ - x^- so the textbook simplex applies:

literalsmax yLP reductiongeneral simplex
Ax1+x2≤3∧¬(2x1−x2≤3)x_1 + x_2 \le 3 \wedge \neg(2x_1 - x_2 \le 3)1SATSAT
BA ∧ x1≤1∧−x2≤0\wedge\ x_1 \le 1 \wedge -x_2 \le 0–UNSATUNSAT
Cx1+x2=2∧¬(x1−x2≤0)∧x1≤1x_1 + x_2 = 2 \wedge \neg(x_1 - x_2 \le 0) \wedge x_1 \le 10UNSATUNSAT

In B even y=0y = 0 is infeasible (x2≤2x1−3≤−1x_2 \le 2x_1 - 3 \le -1 contradicts x2≥0x_2 \ge 0), so the LP itself is infeasible. In C the LP is feasible only with y=0y = 0.

The reduction is correct but clumsy for SMT:

  • it solves an optimization problem to answer yes or no;
  • it encodes strictness in an extra variable;
  • most importantly, it gives no explanation of an UNSAT answer.

5. The general simplex of SMT solvers

5.1 Equations fixed, bounds changing

Dutertre and de Moura (2006) separate what is fixed from what changes:

  • every distinct linear form LL of the input gets one slack variable ss with the equation s=Ls = L. The equations never change;
  • every constraint becomes a bound on a single variable: 2x−y≥02x - y \ge 0 is s2≥0s_2 \ge 0, where s2=x−12ys_2 = x - \tfrac12 y after canonicalization;
  • asserting a constraint tightens a bound; retracting it restores the old bound.

The state:

  • a tableau, with basic variables written as linear combinations of non-basic ones;
  • bounds ℓi≤xi≤ui\ell_i \le x_i \le u_i, each tagged with the constraint that set it;
  • an assignment β\beta.

Invariant: every non-basic variable is within its bounds. Basic variables may be out of bounds; check() repairs them.

5.2 check()

repeat:
    x_i := the basic variable of smallest index violating a bound;  none -> SAT
    if β(x_i) < ℓ_i:
        x_j := the non-basic variable of smallest index that can move x_i up without leaving its own bounds
               (a_ij > 0 and β(x_j) < u_j,  or  a_ij < 0 and β(x_j) > ℓ_j)
        none -> UNSAT: explain
        pivot x_i and x_j, and set x_i := ℓ_i
    symmetric if β(x_i) > u_i

Choosing the smallest index in both places is Bland’s rule again, and it guarantees termination.

Script 02, Part 2 traces it on c1:x+y≥2c_1: x + y \ge 2, c2:2x−y≥0c_2: 2x - y \ge 0, c3:−x+2y≥1c_3: -x + 2y \ge 1, c4:x≤0c_4: x \le 0:

$s1 = x + y      $s2 = x - 1/2y      $s3 = x - 2y              (slacks of the three linear forms)

assert c1: bound $s1 ≥ 2;  $s1 violates it: pivot with x, set $s1 := 2     -> x = 2, y = 0
assert c2: bound $s2 ≥ 0;  consistent                                       -> $s2 = 2
assert c3: bound $s3 ≤ -1; $s3 violates it: pivot with y, set $s3 := -1     -> x = 1, y = 1
assert c4: bound x ≤ 0;    x violates it: pivot with $s3, set x := 0
           CONFLICT on row $s2 = -1/2$s1 + 3/2x: no non-basic variable can move it
           explanation: c2, c1, c4

5.3 Explanations and Farkas’ lemma

At the conflict, row s2=−12s1+32xs_2 = -\tfrac12 s_1 + \tfrac32 x needs s2≥0s_2 \ge 0. But s1≥2s_1 \ge 2 and x≤0x \le 0 hold it at most at −1-1. Only those three bounds matter, so the explanation {c1,c2,c4}\{c_1, c_2, c_4\} omits c3c_3. Smaller explanations give stronger learned clauses in CDCL(T).

Farkas’ lemma. A system Lk≤ckL_k \le c_k has no real solution iff there are λk≥0\lambda_k \ge 0 with:

  • ∑λkLk=0\sum \lambda_k L_k = 0 (the zero linear form);
  • ∑λkck<0\sum \lambda_k c_k < 0, or =0= 0 when some strict inequality has λk>0\lambda_k > 0.

The conflict row supplies the multipliers. Script 02 prints and checks them:

1⋅(x−12y≥0)+12⋅(x+y≥2)+32⋅(x≤0)⇝0≤−1.1\cdot(x - \tfrac12 y \ge 0) + \tfrac12\cdot(x + y \ge 2) + \tfrac32\cdot(x \le 0) \quad\leadsto\quad 0 \le -1.

farkas_check verifies the certificate with additions alone. Like DRUP in Lecture 5, the checker needs no trust in the solver. The self-test checks this on the conflicts of 150 random systems.

5.4 Strict inequalities: δ-rationals

x<cx < c is not a bound. Dutertre and de Moura write it as x≤c−δx \le c - \delta for a symbolic positive infinitesimal δ. Values are pairs a+bδa + b\delta, compared lexicographically:

  • first by aa;
  • then by bb.

Simplex runs unchanged on such pairs. Script 02, Part 3:

constraintsresultδ-solutionconcrete δreal solution
x<y, y<z, z<x+1x < y,\ y < z,\ z < x + 1SATx=−2δ, y=−δ, z=0x = -2\delta,\ y = -\delta,\ z = 01/3x=−2/3, y=−1/3, z=0x = -2/3,\ y = -1/3,\ z = 0
x<y, y<xx < y,\ y < xUNSAT–––
x≤y, y≤xx \le y,\ y \le xSATx=y=0x = y = 01x=y=0x = y = 0

A δ-solution becomes a real one by choosing δ small enough. For each bound a+bδ≤c+dδa + b\delta \le c + d\delta with a<ca < c and b>db > d, any δ≤(c−a)/(b−d)\delta \le (c - a)/(b - d) works; take the minimum over all bounds. Here three strict steps share a gap of 1, so δ=1/3\delta = 1/3.

5.5 Incremental and backtrackable

The two properties CDCL(T) needs (Lecture 10, §5.6) come for free:

random feasible systemspivots, a check after each constraintpivots, one check at the endpivots after retracting the last constraint
4 variables, 8 constraints4.84.20.0
10 variables, 20 constraints16.716.70.0

Incremental. Each check starts from the previous solution and only repairs it. Checking after every constraint costs about as many pivots in total as one check at the end.

Backtrackable. Retracting a constraint only loosens a bound, so the current assignment remains a solution: no pivots at all. The tableau stays; only the bound stack is popped.

Run it: python3 02_general_simplex.py (about 2 s), with figures/02_simplex_vs_fm.png.


6. Pivoting rules, and Fourier–Motzkin

Rules. Script 02, Part 5, one check on each of 30 random systems per size:

variablesconstraintspivots, Blandpivots, greedygreedy over budget
4896760
8164372740
12248944260

Bland’s rule is safe but slow. The greedy rule (largest violation, largest coefficient) needs about half the pivots at 12 variables and never cycled here. Real solvers use such heuristics and switch to Bland’s rule when they detect cycling, as the slides say.

Fourier–Motzkin elimination (Fourier 1826, Motzkin 1936) is the classic alternative.

  • To eliminate xx, write every constraint mentioning it as a lower bound L≤xL \le x or an upper bound x≤Ux \le U.
  • Replace them by all pairs L≤UL \le U: that is exactly ∃x\exists x of the conjunction.
  • Eliminating all variables leaves constant comparisons.

The procedure is simple and obviously correct, but each step can square the number of constraints:

variablesconstraintssimplex pivotsFM peak constraints
5156219
6188122,911

So FM is a poor decision procedure and a good checker. fm_unsat re-checks every LRA theory lemma, which is a conjunction of a few literals, with code that shares nothing with the simplex. Lecture 12 returns to FM, its Omega-test refinement and integers.

simplex vs FM


7. LRA inside CDCL(T)

7.1 The theory solver

The class LRA implements Lecture 10’s interface:

  • Atoms. Every arithmetic atom t1⋈t2t_1 \bowtie t_2 is linearized, moved to L⋈cL \bowtie c and canonicalized (first coefficient 1). All atoms over the same form LL share one simplex variable.
  • Equalities are rewritten before abstraction (preprocess): t1=t2t_1 = t_2 becomes t1≤t2∧t2≤t1t_1 \le t_2 \wedge t_2 \le t_1. Its negation is then the disjunction t1<t2∨t1>t2t_1 < t_2 \vee t_1 > t_2, a case split that belongs to the SAT solver, not a bound.
  • assert_lit. An atom set true asserts its bound. An atom set false asserts the bound of its negation: ¬(L≤c)\neg(L \le c) is L≥c+δL \ge c + \delta.
  • check runs GeneralSimplex.check(). backtrack_to pops bounds.
  • Bound propagation. For atoms over the same form, an asserted L≤3L \le 3 entails L≤5L \le 5 and refutes L>4L > 4, with the one-literal explanation {L≤3}\{L \le 3\}.
  • model returns rational values, with a concrete δ. check_model_lra re-evaluates the input, and fm_unsat re-checks lemmas.

7.2 A traced run

Script 03, Part 1, on (x≤0∨x≥2)∧(y≤0∨y≥2)∧x+y=1∧x≥0∧y≥0(x \le 0 \vee x \ge 2) \wedge (y \le 0 \vee y \ge 2) \wedge x + y = 1 \wedge x \ge 0 \wedge y \ge 0:

PROPAGATE  5, 6, 7, 8          (x + y ≤ 1, 1 ≤ x + y, 0 ≤ x, 0 ≤ y: unit clauses)
DECIDE     •¬1                 (x ≤ 0 false)
PROPAGATE  2                   (so x ≥ 2)
T-CONFLICT {¬2, ¬8, ¬5}        x ≥ 2, y ≥ 0, x + y ≤ 1 are inconsistent
LEARN+BACKJUMP {¬2}, level 0;  PROPAGATE 1
DECIDE     •¬3;  PROPAGATE 4;  T-CONFLICT {¬4, ¬7, ¬5};  LEARN {¬4};  PROPAGATE 3
T-CONFLICT {¬3, ¬1, ¬6}        x ≤ 0, y ≤ 0, x + y ≥ 1 -> FAIL: UNSAT

Each lemma has three bounds, not all eight atoms. Replacing x≥0∧y≥0x \ge 0 \wedge y \ge 0 by x≥−1x \ge -1 makes the formula satisfiable with model x=2x = 2, y=−1y = -1, which is checked against the input.

7.3 Scheduling

Job-shop scheduling. Each job is a sequence of tasks on machines, and a machine runs one task at a time. Each pair of tasks on one machine is a disjunction: one finishes before the other starts. CDCL(T) chooses the orders, and the simplex checks that they fit the horizon.

Binary search on the horizon turns the decision procedure into an optimizer. Script 03, Part 2 (5 jobs × 4 machines):

horizonresultdecisionsconflictscertificate
49SAT866model ok
28SAT21323model ok
24UNSAT22236refutation ok
26SAT32163model ok
25UNSAT24452refutation ok

The shortest makespan is 26, found with 6 SMT calls in 0.34 s. The interesting answer is the UNSAT at 25, “no shorter schedule exists”. Its certificate consists of lemmas re-checked by Fourier–Motzkin plus a DRUP proof.

schedule

7.4 Verifying the slides’ neural network

The slides’ network has two inputs, two ReLU units and two outputs:

  • r1=x1+x2r_1 = x_1 + x_2 and r2=2x1−x2r_2 = 2x_1 - x_2;
  • y1=ReLU(r2)−ReLU(r1)y_1 = \mathrm{ReLU}(r_2) - \mathrm{ReLU}(r_1) and y2=−y1y_2 = -y_1;
  • inputs x1∈[−2,1]x_1 \in [-2, 1], x2∈[−2,2]x_2 \in [-2, 2].

Each ReLU is a disjunction (r≤0∧f=0)∨(r≥0∧f=r)(r \le 0 \wedge f = 0) \vee (r \ge 0 \wedge f = r). A property holds iff network ∧ ¬property is UNSAT (script 03, Part 3):

propertyresultmeaning
y1<y2y_1 < y_2 (the slides)SATfails: x1=2/3x_1 = 2/3, x2=1/3x_2 = 1/3 gives y1=y2=0y_1 = y_2 = 0
y1≤4y_1 \le 4UNSATholds for every input (certified)
y1+y2=0y_1 + y_2 = 0UNSATholds
y1≤3y_1 \le 3SATfails at x1=1x_1 = 1, x2=−2x_2 = -2 (y1=4y_1 = 4)

The slides use this network to illustrate the encoding. As stated, its property is false: both ReLUs can output the same value.

Real network verifiers handle the case splits that ReLUs force by extending the simplex with ReLU-aware pivoting: Reluplex and Marabou (Katz et al.; Guy Katz contributed some of the slides).

7.5 Ablation

Script 03, Part 4, 80 random QF_LRA formulas (47 SAT, 33 UNSAT, all 80 certified):

configurationdecisionsconflictsT-propagations
Bland, bound propagation3,4941,2451,504
Bland, no propagation7,2812,0110
greedy pivoting, propagation3,2901,2541,398

Bound propagation is a comparison of constants on one linear form, and it halves the decisions.

Run it: python3 03_lra_in_cdclt.py (about 3 s), with figures/03_schedule.png.


8. Summary

  1. QF_LRA literals are linear constraints over the reals. Their conjunctions are decidable in polynomial time, and in practice by simplex.

  2. The textbook simplex pivots between dictionaries:

    • entering variable: a positive coefficient in zz;
    • leaving variable: the ratio test;
    • optimal when no coefficient of zz is positive.

    The code reproduces the slides’ dictionaries exactly.

  3. Initialization is an auxiliary LP. Its optimum decides feasibility, so phase 1 is satisfiability.

  4. Cycling needs degenerate pivots (Chvátal’s example: 6 pivots back to the start). Bland’s rule prevents it. The worst case is exponential for both rules (Klee–Minty).

  5. The general simplex of SMT solvers keeps a fixed tableau and changes bounds. It is incremental, and backtracking needs no pivots. Its conflicts come with explanations and Farkas certificates that anyone can check.

  6. Strict inequalities use δ-rationals; a concrete δ turns a δ-solution into a real solution.

  7. Fourier–Motzkin is simple but explosive: 122,911 constraints at 6 variables. It serves as an independent lemma checker.

  8. Inside CDCL(T), LRA handles scheduling (makespan 26, with “no 25” certified) and ReLU networks (the slides’ property fails). Bound propagation halves the decisions.

9. Common pitfalls

  • Floating point. A simplex in floats is a heuristic, not a decision procedure. Use exact rationals. (The code once let a float in through an int / int division, and the tableau filled up with 2251799813685249/4503599627370496.)
  • Forgetting x≥0x \ge 0. The textbook method assumes non-negative variables. A free variable must be split, x=x+−x−x = x^+ - x^-, or handled with bounds as in the general simplex.
  • Treating ≠\neq or a negated equality as a constraint. ¬(aTx=b)\neg(a^T x = b) is a disjunction of two strict inequalities, so it belongs in the Boolean structure.
  • Dropping strictness. x<1∧x>1−ϵx < 1 \wedge x > 1 - \epsilon is satisfiable for every ϵ>0\epsilon > 0, but x<y∧y<xx < y \wedge y < x is not. Without δ, strict inequalities are either lost or approximated unsoundly.
  • Assuming Bland’s rule is fast. It guarantees termination, not speed.
  • Explanations that are not minimal. A conflict explained by all asserted bounds is sound but weak. The row of the conflict gives a small, certifiable explanation.
  • Backtracking the tableau. Unnecessary: pivots are equivalence transformations. Only the bounds must be restored.

10. Exercises

1. (pivoting) Starting from the slides’ first dictionary, pivot with Bland’s rule instead of Dantzig’s. Which variables enter and leave, and do you reach the same optimum?

Answer

First pivot. Bland picks the smallest index with a positive coefficient, which is x1x_1, as Dantzig did. So the first pivot is the same: x1x_1 enters and x4x_4 leaves.

Second pivot. Only x3x_3 has a positive coefficient (+1/2+1/2), so x3x_3 enters and x6x_6 leaves.

Both rules reach z=13z = 13 at (2,0,1)(2, 0, 1) in 2 pivots, which two_phase(..., rule="bland") confirms.

2. (ratio test) Why must the leaving variable be the one with the smallest ratio? What goes wrong if x5x_5 leaves in the first pivot of the slides’ example?

Answer

Why the smallest. The entering variable can grow only until the first basic variable reaches 0. Beyond that point that variable turns negative and the solution is infeasible.

If x5x_5 leaves. Then x1=11/4x_1 = 11/4, and x4=5−2⋅11/4=−1/2<0x_4 = 5 - 2 \cdot 11/4 = -1/2 < 0: the dictionary is no longer feasible.

3. (degeneracy) Show that every pivot of Chvátal’s cycle is degenerate. Explain why cycling is impossible when no pivot is degenerate.

Answer

Every pivot is degenerate. All right-hand sides of the cycling rows are 0, so every ratio is 0. The entering variable stays at 0 and zz does not change (the table shows z = 0 throughout).

Why non-degenerate pivots cannot cycle. If every pivot strictly increased zz, no basis could repeat, because each basis has a fixed zz. There are finitely many bases, so the method would terminate.

4. (general simplex) Run check() by hand on x+y≤4x + y \le 4, x−y≥2x - y \ge 2, y≥1y \ge 1, x≤2x \le 2. Is it feasible? If not, give the explanation and a Farkas certificate.

Answer

Infeasible. From x−y≥2x - y \ge 2 and y≥1y \ge 1 we get x≥3x \ge 3, contradicting x≤2x \le 2.

The certificate. Sum 1⋅(−(x−y)≤−2)+1⋅(−y≤−1)+1⋅(x≤2)1\cdot(-(x - y) \le -2) + 1\cdot(-y \le -1) + 1\cdot(x \le 2), which gives 0≤−10 \le -1.

The explanation. It omits x+y≤4x + y \le 4. The simplex finds it from the row of x−yx - y with xx at its upper bound and yy at its lower bound.

5. (δ) Find the concrete δ for x>0x > 0, x<1x < 1, y>xy > x, y<1y < 1, and a real solution.

Answer

A δ-solution. x=δx = \delta, y=2δy = 2\delta (or similar).

The bounds on δ. y<1y < 1 requires 2δ≤1−δ2\delta \le 1 - \delta, i.e. δ≤1/3\delta \le 1/3.

A real solution. With δ=1/3\delta = 1/3: x=1/3x = 1/3, y=2/3y = 2/3.

6. (Farkas) Prove the easy direction of Farkas’ lemma: if multipliers λ≥0\lambda \ge 0 with ∑λkLk=0\sum \lambda_k L_k = 0 and ∑λkck<0\sum \lambda_k c_k < 0 exist, the system Lk≤ckL_k \le c_k has no solution.

Answer

Combine the constraints. Suppose xx satisfies every Lk(x)≤ckL_k(x) \le c_k. Multiplying by λk≥0\lambda_k \ge 0 and adding gives ∑λkLk(x)≤∑λkck\sum \lambda_k L_k(x) \le \sum \lambda_k c_k.

The contradiction. The left side is the zero form, so 0≤∑λkck<00 \le \sum \lambda_k c_k < 0. With strict inequalities and ∑λkck=0\sum \lambda_k c_k = 0, the sum is strict (0<00 < 0), also a contradiction.

The other direction. The hard direction (infeasible ⇒ multipliers exist) is what simplex constructs.

7. (FM) Eliminate xx from x≥1x \ge 1, x≥yx \ge y, x≤3x \le 3, x≤2yx \le 2y, y≤1y \le 1 by hand. Is the system satisfiable?

Answer

The bounds on xx. Lower bounds {1,y}\{1, y\}; upper bounds {3,2y}\{3, 2y\}.

The pairs. 1≤31 \le 3, 1≤2y1 \le 2y, y≤3y \le 3, y≤2yy \le 2y. With y≤1y \le 1, these say 1/2≤y≤11/2 \le y \le 1: satisfiable.

A solution. E.g. y=1y = 1, x∈[1,2]x \in [1, 2].

8. (CDCL(T)) Why does preprocess rewrite t1=t2t_1 = t_2 as two inequalities instead of letting the theory handle equality atoms directly? What would go wrong with an equality atom assigned false?

Answer

The negation is not a bound. A false equality atom means t1≠t2t_1 \ne t_2, which is t1<t2∨t1>t2t_1 < t_2 \vee t_1 > t_2. The general simplex handles conjunctions of bounds only, and a disjunction is not one.

What the rewrite buys. As two ≤ atoms, the negation becomes ¬(t1≤t2)∨¬(t2≤t1)\neg(t_1 \le t_2) \vee \neg(t_2 \le t_1) in the Boolean structure. CDCL splits on it as on any clause.

The alternative. Some solvers keep disequalities and split lazily (“splitting on demand”).

9. (programming) Add theory propagation through rows: after check(), compute for each basic variable the interval implied by its row and the bounds of the non-basic variables. Propagate the atoms over that variable that the interval decides. Measure the effect on script 03’s Part 4.

Answer sketch

The implied interval. For row xi=∑aijxjx_i = \sum a_{ij} x_j, the lower bound is ∑a>0a ℓj+∑a<0a uj\sum_{a>0} a\,\ell_j + \sum_{a<0} a\,u_j (when all are finite), and symmetrically for the upper bound.

What to propagate. An atom xi≤cx_i \le c with c≥c \ge the implied upper bound is entailed. Its explanation is the bounds used, which is also a Farkas certificate.

The trade-off. Expect fewer conflicts at some cost per check. This is what production solvers do (Dutertre and de Moura, §4).

10. (programming) Implement the dual view of conflicts: from a conflict row, construct the Farkas multipliers over the original atoms (not the slack bounds), and verify them with farkas_check inside check_unsat instead of Fourier–Motzkin.

Answer sketch

Mapping back to the atoms. Each bound carries its tag (SAT literal), which maps to an atom and its truth value. The canonical constraint of that literal, multiplied by the row coefficient, is the term of the sum.

What to store. Record the certificate in LRA.assert_lit / check, keyed by the lemma clause, and check it in check_unsat.

The payoff. No search in the checker at all.


11. Further reading

  • G. B. Dantzig, Linear Programming and Extensions, Princeton 1963; V. Chvátal, Linear Programming, Freeman 1983 (dictionaries, cycling example, Bland’s rule).
  • R. G. Bland, “New Finite Pivoting Rules for the Simplex Method”, Mathematics of Operations Research 1977.
  • V. Klee, G. J. Minty, “How Good Is the Simplex Algorithm?”, 1972.
  • B. Dutertre, L. de Moura, “A Fast Linear-Arithmetic Solver for DPLL(T)”, CAV 2006: the general simplex of this lecture.
  • D. Kroening, O. Strichman, Decision Procedures, Chapter 5 (linear arithmetic, simplex, Fourier–Motzkin).
  • G. Katz, C. Barrett, D. Dill, K. Julian, M. Kochenderfer, “Reluplex: An Efficient SMT Solver for Verifying Deep Neural Networks”, CAV 2017; and “The Marabou Framework”, CAV 2019.
  • L. Khachiyan, “A Polynomial Algorithm in Linear Programming”, 1979; N. Karmarkar, “A New Polynomial-Time Algorithm for Linear Programming”, 1984.

12. Next lecture

Lecture 12: arithmetic II, integers. Over the integers, 2x=12x = 1 has no solution even though LRA finds x=1/2x = 1/2.

  • Branch and bound splits on fractional values: x≤0∨x≥1x \le 0 \vee x \ge 1.
  • Gomory cuts add constraints that remove fractional vertices.
  • Fourier–Motzkin and the Omega test eliminate variables.
  • Difference logic reduces to negative cycles in a graph.

We will see that branch and bound need not terminate on unbounded problems, and how solvers guarantee termination.

← 返回课程目录