Lecture 12 · Arithmetic II: Integers

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

课程源码 ZIP ↓

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

本篇目录

Maps to: Stanford CS 257 Introduction to Automated Reasoning (Winter 2026), Lecture 12 · Thu 02/12/2026 · First-order theories: arithmetic II (Hanna Lachnitt). The take-home midterm window opens. Reading: none listed on the course page. Basis: The Stanford slides are on Canvas, and the public Iowa decks have no lecture on integer arithmetic; their Satisfiability Modulo Theories deck only states the facts about TIAT_{IA} quoted in §1. This lecture is therefore written from:

  • Kroening and Strichman, Decision Procedures, Chapter 5: branch and bound, cutting planes, Fourier–Motzkin, the Omega test;
  • Dutertre and de Moura (2006), the integer extension of the general simplex;
  • Pugh (1991), the Omega test;
  • Cotton and Maler (2006), incremental difference logic;
  • Papadimitriou (1981), bounds on integer solutions.

These notes add a module, lia.py, built on Lecture 11’s simplex, with:

  • integer normalization and the gcd test;
  • branch and bound with explanations;
  • branch and bound with LP bounds, and Gomory cuts, for integer programs;
  • real and dark shadows;
  • an incremental difference-logic solver;
  • an LIA theory solver for CDCL(T).

The experiments are the coin problem, a branch and bound that never ends, knapsack and job-shop scheduling, and every answer is certified. They and their code were designed for these notes and do not reflect what was said in class. Code: code/lecture12/ (4 scripts + 1 module; Python standard library only; 1 to 25 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. Explain why integer arithmetic is harder than real arithmetic, and place LIA, Presburger arithmetic and nonlinear integer arithmetic on the decidability map.
  2. Normalize an integer constraint (gcd, tightening, strictness) and apply the gcd test.
  3. Run branch and bound on a conjunction, read off the explanation of an integer refutation, and explain when branch and bound fails to terminate and how solvers fix it.
  4. Solve a small integer program by branch and bound with LP bounds and by Gomory cuts.
  5. Explain why Fourier–Motzkin is unsound over the integers, and what the Omega test’s real and dark shadows are.
  6. Decide difference logic with negative-cycle detection, incrementally.
  7. Describe how an LIA theory solver sits inside CDCL(T).

0.2 Prerequisites and scope

AssumedIntroduced hereDeveloped later
the general simplex, Farkas, δ (Lecture 11)branch and bound, cuts, normalization—
CDCL(T) (Lecture 10)LIA and DL theory solverstheory combination (Lecture 18)
Fourier–Motzkin (Lecture 11, as a checker)FM over integers, the Omega test—
shortest paths (Bellman–Ford)difference logic—
—nonlinear arithmetic (overview)bit-vectors (Lecture 16)

0.3 Map

§1  integers vs reals; the decidability map                 ← code 01
§2  normalization and the gcd test                           ← code 01
§3  branch and bound (decision), and its non-termination      ← code 02
§4  integer programs: bounds and Gomory cuts                 ← code 02
§5  Fourier–Motzkin over the integers: the Omega test        ← code 01
§6  difference logic                                          ← code 03
§7  LIA inside CDCL(T)                                        ← code 04
§8  nonlinear arithmetic (overview)                           ← code 04
§9 summary   §10 common pitfalls   §11 exercises   §12 further reading   §13 next lecture

0.4 Notation

SymbolMeaning
⌊v⌋\lfloor v \rfloor, ⌈v⌉\lceil v \rceilfloor and ceiling
LP relaxationthe same constraints over the reals
a≤αxa \le \alpha x, βx≤b\beta x \le blower and upper bounds on xx with positive integer coefficients
x−y≤cx - y \le ca difference constraint, the edge y→xy \to x with weight cc
π\pia potential (a model of a difference system)

0.5 The code of this lecture

One module, lia.py:

  • int_normalize and is_integral;
  • branch_and_bound (conjunctions; returns status, model, explanation, nodes, an optional trace);
  • ilp_branch_and_bound, gomory_cut and ilp_cutting_planes (integer programs, on Lecture 11’s two_phase);
  • shadows;
  • difference_form, DifferenceGraph (Bellman–Ford with negative cycles) and the incremental theory solver DL;
  • the theory solver LIA (LRA plus branch and bound at final checks), solve_lia, check_model_lia and lia_unsat;
  • the benchmarks frobenius, knapsack, job_shop_dl and CLASSIC_ILP.

1. Integers vs reals

1.1 Integer gaps

Script 01, Part 1 decides the same formulas over R\mathbb{R} (Lecture 11) and over Z\mathbb{Z}:

formulaLRAa real modelLIA
2x=12x = 1SATx=1/2x = 1/2UNSAT
1≤3x∧3x≤21 \le 3x \wedge 3x \le 2SATx=1/3x = 1/3UNSAT
x+y=1∧x−y=0x + y = 1 \wedge x - y = 0SATx=y=1/2x = y = 1/2UNSAT
2x+4y=72x + 4y = 7SATx=7/2x = 7/2UNSAT
x>0∧x<1x > 0 \wedge x < 1SATx=1/2x = 1/2UNSAT
2x+3y=12x + 3y = 1SATx=1/2x = 1/2SAT: x=−1,y=1x = -1, y = 1

The coin problem. Pay nn with coins of 6, 9 and 20, that is, 6a+9b+20c=n6a + 9b + 20c = n with a,b,c≥0a, b, c \ge 0. Over the reals it is always SAT. Over the integers, n=43n = 43 is UNSAT and every nn from 38 to 47 except 43 is SAT; 43 is the “McNugget” Frobenius number. The real relaxation forgets exactly what makes the question interesting.

1.2 The decidability map

fragmentcomplexity / decidabilitysource
conjunctions of linear real constraintspolynomialLecture 11
conjunctions of linear integer constraintsNP-complete (contains subset sum and 0/1 knapsack)Karp 1972; Borosh–Treybig 1976 for membership in NP
quantifier-free LIANP-complete—
full linear integer arithmetic (Presburger arithmetic, with quantifiers)decidable, worst case triply exponential (the slides)Presburger 1929; Oppen 1978
integer arithmetic with ∗*not even semi-decidable (the slides); quantifier-free undecidableMatiyasevich 1970 (Hilbert’s tenth problem)

Why NP membership is non-trivial: a satisfiable integer system could, a priori, have only huge solutions. Papadimitriou (1981) showed that if one exists, one exists with polynomially many bits. That bound also rescues branch and bound (§3.3).


2. Normalization and the gcd test

Over the integers, ∑ajxj\sum a_j x_j with integer aja_j is an integer. int_normalize therefore does four things:

  1. Scale to integer coefficients.
  2. Divide by g=gcd⁡(a1,…,an)g = \gcd(a_1, \dots, a_n).
  3. Round the constant: L≤⌊c⌋L \le \lfloor c \rfloor, L≥⌈c⌉L \ge \lceil c \rceil.
  4. Remove strictness: L<cL < c becomes L≤⌈c⌉−1L \le \lceil c \rceil - 1.

The gcd test: an equality L=cL = c whose constant is not an integer after dividing by the gcd has no integer solution.

Script 01, Part 2:

constraintinteger-normalized
2x=12x = 1x=1/2x = 1/2: no integer solution (gcd test)
3x−3y≥13x - 3y \ge 1x−y≥1x - y \ge 1
3x−3y≤23x - 3y \le 2x−y≤0x - y \le 0
2x+4y<72x + 4y < 7x+2y≤3x + 2y \le 3
6x+9y+15z≤206x + 9y + 15z \le 202x+3y+5z≤62x + 3y + 5z \le 6
12x+13y>1\tfrac12 x + \tfrac13 y > 13x+2y≥73x + 2y \ge 7
4x−6y=104x - 6y = 102x−3y=52x - 3y = 5

Normalization loses no integer solution and cuts off fractional ones, and it is the cheapest integer reasoning there is. Two consequences:

  • 3x−3y≥1∧3x−3y≤23x - 3y \ge 1 \wedge 3x - 3y \le 2 becomes x−y≥1∧x−y≤0x - y \ge 1 \wedge x - y \le 0, which the real simplex refutes at once;
  • over the integers no δ is needed.

3. Branch and bound

3.1 The idea

Solve the LP relaxation first.

  • If it is infeasible, so is the integer problem.
  • If its solution is integral, we are done.
  • Otherwise some integer variable has a fractional value vv. Every integer solution satisfies x≤⌊v⌋x \le \lfloor v \rfloor or x≥⌈v⌉x \ge \lceil v \rceil, so solve both branches.

branch_and_bound runs on the general simplex. A branch is just a bound asserted after a mark, undone by backtrack: Lecture 11’s incrementality pays off.

Script 02, Part 1, on a thin sliver (x,y∈[0,10]x, y \in [0, 10], c4:6x−7y≤−11c_4: 6x - 7y \le -11, c5:6x−5y≥7c_5: 6x - 5y \ge 7) that has real points but no integer ones:

LP solution has x = 26/3: branch x ≤ 8
   infeasible, explained by [c4, c5]
LP solution has x = 26/3: branch x ≥ 9
   LP solution has y = 47/5: branch y ≤ 9
      infeasible, explained by [c4]
   LP solution has y = 47/5: branch y ≥ 10
      LP solution has x = 19/2: branch x ≤ 9
         infeasible, explained by [c5]
      LP solution has x = 19/2: branch x ≥ 10
         infeasible, explained by [c4, c3]
UNSAT after 3 branchings; explanation: [c3, c4, c5]

3.2 Explanations

The branching bounds are asserted without a tag. The union of the leaves’ explanations therefore mentions only input constraints: here {c3,c4,c5}\{c_3, c_4, c_5\}.

It is a valid theory lemma for the integers, ¬c3∨¬c4∨¬c5\neg c_3 \vee \neg c_4 \vee \neg c_5. It is not valid over the reals, where these three constraints are satisfiable. Exactly this kind of lemma reaches the SAT solver in §7.

3.3 A branch and bound that never ends

Branch and bound is complete only when the variables are bounded. Script 02, Part 2 runs it on 1≤3x−3y≤21 \le 3x - 3y \le 2 without normalization:

LP: x = 1/3; try x ≤ 0
   LP: y = -1/3; try y ≤ -1
      LP: x = -1/3; try x ≤ -1
         LP: y = -4/3; try y ≤ -2
            ...
node budgetresultbranchingsdepth
10UNKNOWN1010
150UNKNOWN150150

Every LP solution lies on 3x−3y=13x - 3y = 1 with fractional coordinates, and each branch slides the solution one unit further along the strip, forever.

Solvers use three fixes:

  1. Normalization. Here it refutes the problem with 0 branchings.
  2. A priori bounds. By Papadimitriou’s bound, if an integer solution exists, one exists within a box computable from the coefficients, so the search can be made finite. The bound is astronomically large and is used only to guarantee termination.
  3. Cuts and “cuts from proofs”. New constraints are derived from the infeasibility of the relaxation (Dillig, Dillig and Aiken 2009; Jovanović and de Moura 2011, “Cutting to the Chase”).

Run it: python3 02_branch_and_bound_and_cuts.py (about 1 s), with figures/02_cuts.png.


4. Integer programs: bounds and cuts

For optimization, maximize 5x1+8x25x_1 + 8x_2 subject to x1+x2≤6x_1 + x_2 \le 6, 5x1+9x2≤455x_1 + 9x_2 \le 45, x∈Z≥0x \in \mathbb{Z}_{\ge 0} (script 02, Part 3). The LP relaxation gives 165/4165/4 at (9/4,15/4)(9/4, 15/4).

Branch and bound with bounds. The LP optimum of a node bounds every integer point below it. A node whose bound is no better than the best integer solution found so far (the incumbent) is pruned:

depthboundsLP valuedecision
0root165/4branch on x1=9/4x_1 = 9/4
1x1≤2x_1 \le 2370/9branch on x2=35/9x_2 = 35/9
2x1≤2,x2≤3x_1 \le 2, x_2 \le 334integral: incumbent
2x1≤2,x2≥4x_1 \le 2, x_2 \ge 441branch on x1=9/5x_1 = 9/5
3… x1≤1x_1 \le 1365/9branch on x2=40/9x_2 = 40/9
4… x2≤4x_2 \le 437integral: incumbent
4… x2≥5x_2 \ge 540integral: incumbent
3… x1≥2x_1 \ge 2infeasibleprune
1x1≥3x_1 \ge 339prune: bound 39 ≤ incumbent 40

The optimum is 40 at (0,5)(0, 5), after 9 nodes.

Note that rounding the LP vertex gives (2,4)(2, 4), which is not even feasible: 5⋅2+9⋅4=46>455\cdot 2 + 9\cdot 4 = 46 > 45.

Gomory cuts (1958). Take a row xi=bˉ+∑jdjxjx_i = \bar b + \sum_j d_j x_j of the optimal dictionary with bˉ\bar b fractional. Split off the fractional parts, fj={−dj}f_j = \{-d_j\} and f0={bˉ}f_0 = \{\bar b\}. For integer points, xi+∑j⌊−dj⌋xj−⌊bˉ⌋=f0−∑jfjxjx_i + \sum_j \lfloor -d_j \rfloor x_j - \lfloor \bar b \rfloor = f_0 - \sum_j f_j x_j. The left side is an integer, and the right side is <1< 1, so both are ≤0\le 0: ∑jfjxj≥f0(the cut).\sum_j f_j x_j \ge f_0 \qquad\text{(the cut)}. Every integer point satisfies the cut, and the current vertex (all xj=0x_j = 0) violates it.

gomory_cut rewrites the cut in the original variables, scales it to integer coefficients and rounds the constant down, which is again valid by integrality:

cutLP vertex cut offLP valuecut
1(9/4, 15/4)165/44x1+7x2≤354x_1 + 7x_2 \le 35
2(7/3, 11/3)413x1+5x2≤253x_1 + 5x_2 \le 25
3(5/2, 7/2)81/22x1+3x2≤152x_1 + 3x_2 \le 15

After three cuts the LP optimum is integral: 40 at (0,5)(0, 5).

Gomory cuts

On 30 random integer programs (script 02, Part 4) both methods agree on all 30 optima, with 212 branch-and-bound nodes and 68 cuts in total. Neither dominates. Modern MIP solvers combine them (branch and cut). SMT solvers use branch and bound as the workhorse, because it needs no special tableau form, and add cuts to strengthen it.


5. Fourier–Motzkin over the integers: the Omega test

Lecture 11 used Fourier–Motzkin as a checker. To eliminate xx from lower bounds a≤αxa \le \alpha x and upper bounds βx≤b\beta x \le b, it combines every pair into the real shadow βa≤αb\beta a \le \alpha b. Over the integers this is unsound: 1≤3x≤21 \le 3x \le 2 has real shadow 3≤63 \le 6, true, yet no integer xx fits.

Pugh’s Omega test (1991) adds the dark shadow αb−βa≥(α−1)(β−1)\alpha b - \beta a \ge (\alpha - 1)(\beta - 1). It demands a gap wide enough to contain a multiple, so it implies that an integer exists. Script 01, Part 3:

constraintsreal shadowdark shadowinteger xx exists
1≤3x≤21 \le 3x \le 2yesnono
1≤3x≤51 \le 3x \le 5yesyesyes
3≤3x≤43 \le 3x \le 4yesnoyes (x=1x = 1)
1≤x≤21 \le x \le 2yesyesyes
  • If the dark shadow holds, a solution exists.
  • If the real shadow fails, none exists.
  • In between (as for 3≤3x≤43 \le 3x \le 4), the Omega test enumerates splinters: the few values close to the bounds.

With a coefficient 1 (α=1\alpha = 1 or β=1\beta = 1) the shadows coincide and elimination is exact. That is the common case for the array-index constraints compilers ask about, which is why the Omega test worked well in dependence analysis.


6. Difference logic

6.1 Graphs and negative cycles

A difference constraint x−y≤cx - y \le c says ”xx is at most cc above yy”. It becomes an edge y→xy \to x of weight cc, and a bound x≤cx \le c becomes x−zero≤cx - \mathit{zero} \le c.

Theorem. A set of difference constraints is satisfiable iff its graph has no negative cycle.

  • If there is no negative cycle, the shortest distances dd from a virtual source satisfy d(x)≤d(y)+cd(x) \le d(y) + c on every edge, so x:=d(x)x := d(x) is a model: shortest paths are solutions.
  • If there is a negative cycle, adding its constraints cancels every variable and leaves 0≤0 \le (a negative number).

Script 03, Part 1, with the constraints c1..c4c_1..c_4 and then c5:x−w≤−2c_5: x - w \le -2:

Bellman–Ford distances: w = 0, x = 0, y = -2, z = 0     (a model of c1..c4)
add c5: negative cycle z -> w -> x -> z (total weight -1)
explanation: c4: w - z ≤ 0, c5: x - w ≤ -2, c3: z - x ≤ 1        (c1 is not needed)

Difference logic expresses precedence and timing: scheduling, timed automata, pipelines. Conjunctions are decidable in polynomial time, over R\mathbb{R} and over Z\mathbb{Z} (where strict x−y<cx - y < c is x−y≤c−1x - y \le c - 1).

6.2 Incremental negative-cycle detection

Rerunning Bellman–Ford, O(VE)O(VE), at every check is wasteful. The DL solver instead keeps a potential π\pi that satisfies every asserted constraint (after Cotton and Maler 2006):

  • a new edge y→xy \to x that π\pi already satisfies costs nothing;
  • otherwise π(x)\pi(x) is lowered to π(y)+c\pi(y) + c, and the decrease is propagated Dijkstra-style. If it reaches yy, the new edge closes a negative cycle.

Script 03, Part 2:

assertedrepairnodes visitedresult
c1:x−y≤3c_1: x - y \le 300π\pi unchanged
c2:y−z≤−2c_2: y - z \le -211y=−2y = -2
c3,c4c_3, c_400unchanged
c5:x−w≤−2c_5: x - w \le -214CONFLICT [c5, c3, c4]

Retracting edges never breaks π\pi, so backtracking is free: the same property that made the general simplex fit CDCL(T).

6.3 Scheduling with three theories

Job-shop scheduling (Lecture 11) is pure difference logic. Script 03, Part 3 finds the optimal makespan by binary search with three theory solvers:

instancetheory solvermakespanconflictscertifiedtime
6 × 5DL (potentials)345246/60.64 s
6 × 5LRA (simplex)344356/61.53 s
7 × 5DL (potentials)391,6076/61.78 s
7 × 5LRA (simplex)391,8156/67.84 s
7 × 5LIA (simplex + B&B)391,8156/68.69 s

The specialised DL solver is several times faster. It needs no tableau, and its arithmetic involves only the constants.

Over the integers, LIA’s branch and bound made 0 branchings in all 18 calls. The LP relaxation of a difference system with integer constants has integral vertices: its constraint matrix (an incidence matrix) is totally unimodular.

Run it: python3 03_difference_logic.py (about 25 s).


7. LIA inside CDCL(T)

7.1 The theory solver

LIA extends Lecture 11’s LRA in three ways:

  1. Atoms are integer-normalized, for both polarities: ¬(x≤5)\neg(x \le 5) is x≥6x \ge 6.
  2. check(final = False), at every propagation fixpoint, is the cheap LRA check. If the relaxation is infeasible, so are the integers.
  3. check(final = True), at a complete Boolean assignment, runs branch and bound on the current bounds. An integer refutation becomes a theory lemma, the union of the leaf explanations. A budget overrun makes the answer UNKNOWN.

Script 04, Part 1, on (x≤3∨y≥9)(x \le 3 \vee y \ge 9) ∧ the sliver of §3.1, which is LRA-SAT:

PROPAGATE  3, 4, 5, 6, 7, 8     (the unit clauses)
DECIDE     •¬1;  PROPAGATE 2    (y ≥ 9)
T-CONFLICT {¬3, ¬4, ¬8}         branch and bound at the final check: 3 nodes
CONFLICT at level 0 -> FAIL: UNSAT
lemma: ¬(6x - 7y ≤ -11) ∨ ¬(7 ≤ 6x - 5y) ∨ ¬(y ≤ 10)

The lemma is valid over the integers and false over the reals. It omits five of the eight atoms, so the learned clause is strong. Its certificate comes from lia_unsat, which enumerates the bounded box, together with DRUP.

7.2 Knapsack

0/1 knapsack (12 items, capacity 45), with binary search on the target value (script 04, Part 2):

targetresultB&B nodescertificate
58SAT21model ok
87UNSAT0refutation ok
79UNSAT9refutation ok
78SAT1model ok

The best value is 78, found with 7 calls in 0.03 s, and brute force over all 2122^{12} subsets agrees. The UNSAT at 79 is the optimality proof. Knapsack is NP-hard, and only LP bounds and good branching make typical instances fast.

7.3 When the relaxation lies

On 60 random QF_LIA formulas (script 04, Part 3):

LRA / LIAformulas
SAT / SAT21
SAT / UNSAT10
UNSAT / UNSAT29

Branch and bound ran 31 final checks with 40 nodes in all, and 60/60 answers are certified. UNSAT over the reals always means UNSAT over the integers, which is why the LRA check runs first and eagerly. The ten SAT/UNSAT formulas are the ones only integer reasoning can refute.


8. Nonlinear arithmetic (overview)

linearize rejects x⋅yx \cdot y and x⋅(y+1)x \cdot (y + 1) (script 04, Part 4). Beyond the linear fragment:

  • Integers with multiplication: undecidable. Every Diophantine equation is a formula, and Hilbert’s tenth problem has no algorithm (Matiyasevich 1970).
  • Reals with multiplication: decidable (Tarski), by quantifier elimination or cylindrical algebraic decomposition. It is doubly exponential, but modern solvers implement it in a conflict-driven way (NLSAT, Jovanović and de Moura 2012).
  • In practice solvers combine incomplete strategies: incremental linearization, interval reasoning, and bit-blasting of bounded integers into SAT, the subject of Lecture 16.

9. Summary

  1. Over the integers, linear constraints can have real but no integer solutions (2x=12x = 1, the coin problem’s 43). Conjunctions become NP-complete, and multiplication makes the theory undecidable.
  2. Normalization (gcd, rounding, no strictness) and the gcd test are cheap integer reasoning. They refute 1≤3x−3y≤21 \le 3x - 3y \le 2 with no search.
  3. Branch and bound solves the relaxation and splits on fractional values. Its refutations yield integer-only lemmas. It is complete only for bounded variables, and solvers ensure termination with normalization, a priori bounds or cuts.
  4. For integer programs, LP bounds prune the tree and Gomory cuts shave the polytope: 3 cuts suffice for the classic example.
  5. Fourier–Motzkin is unsound over the integers. The Omega test’s dark shadow restores soundness, and splinters handle the gap. Elimination is exact when a coefficient is 1.
  6. Difference logic is negative-cycle detection, decided incrementally with potentials. It beats the simplex several times on scheduling, and its LP relaxations are integral (total unimodularity).
  7. LIA in CDCL(T) runs LRA eagerly and branch and bound at final checks; the integer lemmas reach the SAT solver like any other.

10. Common pitfalls

  • Trusting the relaxation. A fractional LRA model says nothing about integers; only LRA’s UNSAT carries over.
  • Rounding LP solutions. The rounded vertex may be infeasible (here (2,4)(2, 4)) or far from optimal.
  • Unbounded branch and bound. Without normalization, bounds or cuts, it may never stop.
  • Fourier–Motzkin over integers. The real shadow is necessary, not sufficient.
  • Forgetting to normalize negated atoms. ¬(x≤5)\neg(x \le 5) is x≥6x \ge 6 over the integers, not x>5x > 5 with a δ.
  • Including branching bounds in explanations. A lemma must mention only input literals; branch bounds are internal.
  • Assuming integrality is always hard. Difference constraints and other totally unimodular systems have integral relaxations.

11. Exercises

1. (gcd test) Which of these have integer solutions: 6x+10y=76x + 10y = 7; 6x+10y=86x + 10y = 8; 6x+10y+15z=16x + 10y + 15z = 1? Find one where it exists.

Answer
  • 6x+10y=76x + 10y = 7: none. gcd(6, 10) = 2 does not divide 7.
  • 6x+10y=86x + 10y = 8: yes. For example x=−2x = -2, y=2y = 2 (−12+20=8-12 + 20 = 8).
  • 6x+10y+15z=16x + 10y + 15z = 1: yes. gcd(6, 10, 15) = 1 divides 1. For example x=1x = 1, y=1y = 1, z=−1z = -1 (6+10−15=16 + 10 - 15 = 1).

2. (normalization) Normalize 4x−6y<94x - 6y < 9 and −3x+9y≥7-3x + 9y \ge 7 for integer variables.

Answer

First constraint. 4x−6y<94x - 6y < 9: divide by gcd 2 to get 2x−3y<4.52x - 3y < 4.5, so 2x−3y≤42x - 3y \le 4.

Second constraint. −3x+9y≥7-3x + 9y \ge 7: divide by 3 to get −x+3y≥7/3-x + 3y \ge 7/3, so −x+3y≥3-x + 3y \ge 3.

3. (branch and bound) Run branch and bound by hand on 2x+2y≥32x + 2y \ge 3, 2x+2y≤52x + 2y \le 5, 0≤x,y≤30 \le x, y \le 3, without normalization. Then normalize: what changes?

Answer

Without normalization. The relaxation contains points with x+y∈[1.5,2.5]x + y \in [1.5, 2.5]. If the LP solution is fractional (e.g. x=1.5x = 1.5, y=0y = 0), branch: x≤1x \le 1 or x≥2x \ge 2. Both branches contain integer points such as (1,1)(1, 1) and (2,0)(2, 0), so the answer is SAT after one branching.

With normalization. The constraints become x+y≥2x + y \ge 2 and x+y≤2x + y \le 2, i.e. x+y=2x + y = 2. The LP vertex is integral, so there are no branchings.

4. (non-termination) Explain why branch and bound on 1≤3x−3y≤21 \le 3x - 3y \le 2 never terminates. What bound on ∣x∣|x| would make it terminate, and what would it prove?

Answer

Why it never ends. Every LP solution has x−y=1/3+kx - y = 1/3 + k with k∈{0,1/3}k \in \{0, 1/3\}, so it is always fractional, and each branch shifts the solution along the strip.

A bound. Any box, e.g. ∣x∣,∣y∣≤10|x|, |y| \le 10, makes the tree finite: all leaves become infeasible, and the answer is UNSAT.

What it proves. Papadimitriou’s theorem says that if an integer solution exists, one exists within a computable bound. Searching that box exhaustively therefore proves UNSAT for the unbounded problem too.

5. (Gomory) Derive the first Gomory cut of script 02 by hand from the row x1=9/4−9/4 x3+1/4 x4x_1 = 9/4 - 9/4\,x_3 + 1/4\,x_4 (slack x3=6−x1−x2x_3 = 6 - x_1 - x_2, x4=45−5x1−9x2x_4 = 45 - 5x_1 - 9x_2). Express it in x1,x2x_1, x_2.

Answer

The fractional parts. −d3=9/4-d_3 = 9/4 gives f3=1/4f_3 = 1/4; −d4=−1/4-d_4 = -1/4 gives f4=3/4f_4 = 3/4; f0=1/4f_0 = 1/4.

The cut in slack variables. 14x3+34x4≥14\tfrac14 x_3 + \tfrac34 x_4 \ge \tfrac14.

In the original variables. Multiply by 4 and substitute the slacks: (6−x1−x2)+3(45−5x1−9x2)≥1(6 - x_1 - x_2) + 3(45 - 5x_1 - 9x_2) \ge 1, i.e. 16x1+28x2≤14016x_1 + 28x_2 \le 140, or 4x1+7x2≤354x_1 + 7x_2 \le 35. That is the table’s first cut; script 02 derives it from the same row (x1x_1).

6. (shadows) For 5≤4x≤75 \le 4x \le 7, compute the real and the dark shadow. Is there an integer xx?

Answer

The shadows. α=β=4\alpha = \beta = 4, a=5a = 5, b=7b = 7.

  • Real shadow: 4⋅5≤4⋅74 \cdot 5 \le 4 \cdot 7, true.
  • Dark shadow: 28−20=8≥928 - 20 = 8 \ge 9, false.

An integer xx. 4x∈{5,6,7}4x \in \{5, 6, 7\} has no multiple of 4, so there is none. The splinter check confirms it.

7. (difference logic) Model “task B starts at least 3 after task A ends (A takes 2), and C starts at most 4 after A starts, and C starts after B ends (B takes 1)” as difference constraints. Is it satisfiable? Draw the graph.

Answer

The constraints.

  • sB−sA≥5s_B - s_A \ge 5, i.e. sA−sB≤−5s_A - s_B \le -5;
  • sC−sA≤4s_C - s_A \le 4;
  • sC−sB≥1s_C - s_B \ge 1, i.e. sB−sC≤−1s_B - s_C \le -1.

The negative cycle. A→CA \to C (4), C→BC \to B (−1), B→AB \to A (−5), with total weight −2<0-2 < 0. So the constraints are unsatisfiable: C must start ≥ 6 after A but ≤ 4 after A.

8. (total unimodularity) Why does the LP relaxation of a difference system with integer constants have integral vertices? (Hint: a vertex solves a square subsystem Bx=bBx = b; what is det⁡B\det B?)

Answer

The determinant. Rows have one +1+1 and one −1-1 (or a single ±1\pm1). Such incidence matrices are totally unimodular: every square submatrix has determinant 0 or ±1.

Integrality. By Cramer’s rule, x=B−1bx = B^{-1}b has integer entries when bb is integral.

9. (programming) Add a priori bounds to branch_and_bound: compute a box from the coefficients (for instance ∣xj∣≤n(m amax⁡)2m+1|x_j| \le n (m\,a_{\max})^{2m+1}) and assert it before searching. Confirm that 1≤3x−3y≤21 \le 3x - 3y \le 2 then terminates without normalization, and count the nodes.

Answer sketch

The box. Assert −M≤xj≤M-M \le x_j \le M for every variable with Papadimitriou’s MM. Here MM is huge, e.g. 2⋅(2⋅3)5=15,5522 \cdot (2 \cdot 3)^5 = 15{,}552.

What to expect. The search becomes finite but long. Each branch shifts by one unit, so the depth is about 2M2M. Run it with a large max_depth, or a smaller box for illustration.

The lesson. Bounds guarantee termination, not efficiency; that is why normalization and cuts matter.

10. (programming) Implement cuts in the general simplex (Dutertre and de Moura): when all non-basic variables of a row are at their bounds, derive a Gomory mixed-integer cut from the row, and add it as a new constraint in LIA.check(final=True) before branching. Compare branch-and-bound nodes on script 04’s random formulas.

Answer sketch

The cut. Translate each non-basic variable to its bound: xj=ℓj+yjx_j = \ell_j + y_j or uj−yju_j - y_j, with yj≥0y_j \ge 0. Then apply the Gomory formula to the row in the yy‘s.

Two cautions.

  • The cut mentions slack variables, which must be expanded into the original variables.
  • Its explanation (for lemmas) is the bounds used.

What to expect. Fewer nodes, at the cost of larger rows.


12. Further reading

  • D. Kroening, O. Strichman, Decision Procedures, Chapter 5 (2nd ed.): branch and bound, cutting planes, Fourier–Motzkin, the Omega test.
  • R. E. Gomory, “Outline of an Algorithm for Integer Solutions to Linear Programs”, 1958.
  • C. H. Papadimitriou, “On the Complexity of Integer Programming”, JACM 1981.
  • W. Pugh, “The Omega Test: a Fast and Practical Integer Programming Algorithm for Dependence Analysis”, Supercomputing 1991.
  • B. Dutertre, L. de Moura, “Integrating Simplex with DPLL(T)”, SRI technical report 2006.
  • I. Dillig, T. Dillig, A. Aiken, “Cuts from Proofs: A Complete and Practical Technique for Solving Linear Inequalities over Integers”, CAV 2009; D. Jovanović, L. de Moura, “Cutting to the Chase: Solving Linear Integer Arithmetic”, CADE 2011.
  • S. Cotton, O. Maler, “Fast and Flexible Difference Constraint Propagation for DPLL(T)”, SAT 2006.
  • D. Jovanović, L. de Moura, “Solving Non-linear Arithmetic”, IJCAR 2012 (NLSAT).
  • Y. Matiyasevich, Hilbert’s Tenth Problem, MIT Press 1993.

13. Next lecture

Lecture 13: arrays, strings and sequences (guest lecture by Clark Barrett).

  • Arrays model memory: read-over-write axioms, extensionality, and lazy axiom instantiation on top of CDCL(T).
  • Strings add concatenation, length and regular expressions. The calculus is the one in the public Iowa deck Theory Solvers III, with its rules L-INTRO, C-SPLIT and friends.

We will build arrays.py and strings.py on top of smt.py.

← 返回课程目录