Lecture 16 · Bit-Vectors

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

课程源码 ZIP ↓

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

本篇目录

Maps to: Stanford CS 257 Introduction to Automated Reasoning (Winter 2026), Lecture 16 · Thu 02/26/2026 · Bit-vectors (guest lecture by Mathias Preiner). Reading: Kroening and Strichman, Decision Procedures, Chapter 6 (bit-vectors). Basis: The Stanford slides are on Canvas, and the public Iowa decks have no bit-vector lecture. This lecture is written from:

  • Kroening and Strichman, Chapter 6: bit-flattening, incremental and abstraction-based approaches;
  • the SMT-LIB QF_BV semantics;
  • Brummayer and Biere’s Boolector papers;
  • Niemetz, Preiner and Biere (2017), propagation-based local search;
  • Niemetz and Preiner (CAV 2023), Bitwuzla, the solver the guest lecturer co-develops;
  • Bryant et al. (TACAS 2007), abstraction for bit-vector arithmetic;
  • Warren, Hacker’s Delight;
  • de Moura’s Lecture 15 slides, for bv_decide.

These notes add one module, bitvec.py, with:

  • terms with exact semantics;
  • a bit-blaster to CNF for Lecture 5’s CDCL;
  • word-level rewriting with polynomial normalization;
  • lazy multiplication;
  • certificates for every answer.

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


0. How to read this lecture

0.1 Learning goals

After this lecture you should be able to:

  1. State the semantics of fixed-width bit-vectors: arithmetic modulo 2w2^w, unsigned vs signed readings, and the SMT-LIB conventions for division by zero and large shifts.
  2. Find the integer facts that fail on bit-vectors, and recognize classic overflow bugs.
  3. Bit-blast each operator into a circuit and its CNF, and estimate the circuit sizes: linear, wlog⁡ww \log w and quadratic.
  4. Explain why multiplication is the bottleneck of bit-blasting, and why a faster SAT solver does not fix it.
  5. Use word-level rewriting, including polynomial normalization modulo 2w2^w, and explain why it is sound but incomplete.
  6. Describe abstraction refinement (lazy multiplication) and local search as alternatives to eager bit-blasting.
  7. Connect bit-blasting with certificates: DRUP here, and LRAT with a verified checker in Lean’s bv_decide.

0.2 Prerequisites and scope

AssumedIntroduced hereDeveloped later
CDCL, DRUP (Lecture 5); Tseitin (Lecture 2)bit-blasting, AIGs, structural hashing—
integer arithmetic (Lecture 12)arithmetic modulo 2w2^wtheory combination with BV (Lecture 18)
lazy lemmas (Lectures 10, 13)abstraction refinement for multiplication—
proof kernels, bv_decide (Lecture 15)the bit-blasting pipeline in detail—

0.3 Map

§1  why bit-vectors: programs compute modulo 2^w
§2  semantics, and the facts that break                       ← code 01
§3  bit-blasting: gates, circuits, CNF                         ← code 02
§4  why multiplication is hard                                 ← code 02
§5  word-level rewriting and polynomials modulo 2^w            ← code 03
§6  lazy multiplication and other alternatives                 ← code 03
§7  certificates: from DRUP to verified bit-blasting
§8  summary   §9 common pitfalls   §10 exercises   §11 further reading   §12 next lecture

0.4 Notation

SymbolMeaning
wwbit width; values are 0…2w−10 \ldots 2^w - 1
+,−,⋅+, -, \cdotarithmetic modulo 2w2^w
<u<_u, <s<_sunsigned and signed (two’s complement) comparison
≫\gg, ≫s\gg_slogical and arithmetic right shift
x[i]x[i], x[h:l]x[h{:}l]bit ii; the slice from bit hh down to bit ll
AIGand-inverter graph: a circuit of AND gates and negations

0.5 The code of this lecture

One module, bitvec.py:

  • terms and semantics: bv, const, ite, Python operators on BV and Bool, evaluate, to_signed;
  • bit-blasting: the Blaster gates and circuits, and simulate;
  • solving: solve and prove, with checked models and DRUP proofs;
  • rewriting: Rewriter and poly;
  • abstraction refinement: solve_lazy_mul;
  • benchmarks: popcount_hd, popcount_loop, midpoint_naive, midpoint_safe, abs_branchy, is_power_of_two.

1. Why bit-vectors

Lecture 12’s integers are unbounded; a machine’s are not. A 32-bit int holds 2322^{32} values, and + wraps around. Most software and all hardware compute on fixed-width words. The bugs that matter are exactly where words and integers disagree:

  • overflow;
  • signed vs unsigned confusion;
  • shifts by too much.

The theory QF_BV (quantifier-free bit-vectors, SMT-LIB) is the theory of these words. Its consumers:

  • symbolic execution of binaries (Lecture 14’s topic: KLEE and friends speak QF_BV);
  • hardware verification (Lecture 9’s circuits are bit-vector transition systems);
  • compiler verification (Alive checks LLVM peephole optimizations);
  • cryptography and smart contracts.

Complexity. QF_BV with widths written in unary is NP-complete: bit-blasting is a polynomial reduction to SAT. SMT-LIB writes widths in binary, though, so a formula can mention 2642^{64}-bit vectors in a few characters. Kovásznai, Fröhlich and Biere showed that with binary widths the problem is NEXPTIME-complete.


2. Semantics, and the facts that break

2.1 Two readings of every word

A word is a string of ww bits. Operations, not words, have signs:

  • the unsigned reading of bw−1…b0b_{w-1} \ldots b_0 is ∑bi2i\sum b_i 2^i;
  • the signed (two’s complement) reading subtracts 2w2^w when the top bit is 1.

Script 01, Part 1, on 8 bits:

expressionunsignedsignedbits
200 + 100444400101100
127 + 1128−12810000000
0 − 1255−111111111
16 · 160000000000
200 ≫ 1 (logical)10010001100100
200 ≫ₛ 1 (arithmetic)228−2811100100
7 / 0 (udiv)255−111111111
7 % 0 (urem)7700000111
1 ≪ 90000000000

What the table shows.

  • Comparisons depend on the reading. 255<u1255 <_u 1 is false, but 255<s1255 <_s 1 is true.
  • SMT-LIB makes division total. x/0x / 0 is all ones and x%0=xx \% 0 = x, so a formula never has an “undefined” value.
  • Large shifts give 0. Shifting by ≥w\ge w gives 0 (the arithmetic shift fills with the sign).

2.2 Integer facts that fail

Each claim below is valid over Z\mathbb{Z} (Lecture 12). On words prove returns a counterexample, checked by evaluating the claim on it (script 01, Part 2):

claim8 bits32 bits
x+1>uxx + 1 >_u xx=255x = 255x=4294967295x = 4294967295
x+1>sxx + 1 >_s xx=127x = 127x=2147483647x = 2147483647
x⋅y=0⇒x=0∨y=0x \cdot y = 0 \Rightarrow x = 0 \vee y = 0x=y=128x = y = 128x=y=231x = y = 2^{31}
−x=x⇒x=0-x = x \Rightarrow x = 0x=128x = 128x=231x = 2^{31}
x≥s0⇒2x≥sxx \ge_s 0 \Rightarrow 2x \ge_s xx=64x = 64x=230x = 2^{30}

The counterexamples are the boundaries:

  • the unsigned and signed maxima;
  • 2w−12^{w-1}, the most negative number, which is its own negation;
  • zero divisors: 2w−1⋅2w−1=02^{w-1} \cdot 2^{w-1} = 0, because Z/2w\mathbb{Z}/2^w is not a field.

2.3 Classic bugs, and tricks that work

Script 01, Part 3, at 8, 16 and 32 bits:

claimresult (32 bits)conflicts
midpoint (lo+hi)≫1=lo+((hi−lo)≫1)(lo + hi) \gg 1 = lo + ((hi - lo) \gg 1), given lo≤uhilo \le_u hicounterexample lo=hi=231lo = hi = 2^{31}2
lo≤lo+((hi−lo)≫1)≤hilo \le lo + ((hi - lo) \gg 1) \le hivalid1,993
abs(x)≥s0\mathrm{abs}(x) \ge_s 0counterexample x=231x = 2^{31}0
x&(x−1)=0⇒xx \mathbin{\&} (x - 1) = 0 \Rightarrow x is a power of twocounterexample x=0x = 00
the xor swap exchanges aa and bbvalid286
(a&b)+((a⊕b)≫1)=⌊(a+b)/2⌋(a \mathbin{\&} b) + ((a \oplus b) \gg 1) = \lfloor (a + b)/2 \rfloorvalid943

The bugs.

  • The midpoint. The naive midpoint overflows when lo+hi≥2wlo + hi \ge 2^w. That is the binary-search bug that sat in the Java library for about nine years (Bloch 2006; there with signed ints). The fix is proved to stay in range for all 2642^{64} pairs of 32-bit inputs.
  • abs. It fails on the most negative number.
  • The power-of-two test. The textbook trick also accepts 0.

The tricks. The two bit tricks from Hacker’s Delight are proved outright.

Run it: python3 01_machine_arithmetic.py (about 2 s).


3. Bit-blasting

3.1 The idea

Bit-blasting is also called bit-flattening (Kroening and Strichman). It builds the circuit that a processor would build and hands it to a SAT solver:

  1. every bit of every term becomes a propositional literal;
  2. every operator becomes a circuit of gates;
  3. every gate becomes its Tseitin clauses (Lecture 2): g⇔a∧bg \Leftrightarrow a \wedge b is {¬g∨a, ¬g∨b, g∨¬a∨¬b}\{\neg g \vee a,\ \neg g \vee b,\ g \vee \neg a \vee \neg b\}.

Blaster builds an and-inverter graph (AIG) with XOR and MUX conveniences, using two tricks:

  • constant propagation: a∧⊥=⊥a \wedge \bot = \bot and a⊕⊤=¬aa \oplus \top = \neg a, with no clauses at all;
  • structural hashing: building a∧ba \wedge b twice returns the same literal, so equal subcircuits are shared.

3.2 The circuits

operatorcircuitsize
++, −- (and negation)ripple-carry adder: one full adder per bit; a−b=a+¬b+1a - b = a + \neg b + 1linear
<u<_uthe borrow of a−ba - blinear
<s<_sflip both sign bits, then <u<_ulinear
==conjunction of XNORslinear
≪\ll, ≫\gg, ≫s\gg_sbarrel shifter: ⌈log⁡2w⌉\lceil\log_2 w\rceil layers of multiplexers, plus “amount ≥w\ge w”wlog⁡ww \log w
⋅\cdotshift-and-add: ww partial products of ww bits, ww additionsquadratic
/u/_u, %u\%_ufresh quotient qq and remainder rr with b≠0⇒a=q⋅b+rb \neq 0 \Rightarrow a = q \cdot b + r (in 2w2w bits) ∧ r<ub\wedge\ r <_u b, and the SMT-LIB values for b=0b = 0quadratic, double width

Script 02, Part 1, counts clauses:

operatorw=4w = 4w=8w = 8w=16w = 16w=32w = 32
x+yx + y59127263535
x<uyx <_u y62130266538
x≪yx \ll y772396451,611
x⋅yx \cdot y1035152,2999,707
x/uyx /_u y4461,5545,69021,642

3.3 Who checks the bit-blaster?

A bit-blaster is a compiler from words to gates, and compilers have bugs. Script 02, Part 2 compares every circuit with evaluate, the exact semantics:

  • 18 operators;
  • widths 1–4 (division 1–3);
  • every pair of inputs.

That is 5,608 cases, all agreeing.

  • How each case is checked. Gate-level simulation for most circuits; a SAT call per input for division, which introduces quotient and remainder bits that no gate defines.
  • What it does not prove. Exhaustive checking at small widths is evidence, not a proof for 32 bits. Lean’s bv_decide closes that gap by proving its bit-blaster correct for every width (§7).

Answers are checked too.

  • SAT. The model is evaluated on the original formula with the semantics.
  • UNSAT. The CDCL run’s DRUP proof is checked by Lecture 5’s checker. That certifies the CNF, and the circuit checks connect the CNF to the formula.

4. Why multiplication is hard

Script 02, Part 3 proves three identities at growing widths:

wwx+y=y+xx+y = y+xx⋅y=y⋅xx \cdot y = y \cdot x(x+y)2=x2+2xy+y2(x+y)^2 = x^2 + 2xy + y^2
301331
4091144
50403432
601,8281,733
708,636—

(The figures are CDCL conflicts; see figures/02_multiplier_hardness.png. At 8 bits commutativity of multiplication took about 36,000 conflicts during development.)

Addition is free. Structural hashing builds the same gates for x+yx + y and y+xy + x, because AND and XOR are hashed with sorted inputs. The miter, which asserts that the two outputs differ, collapses to ⊥ before the search starts.

Multiplication is not. The two multipliers add their partial products in different orders, so their internal signals differ, and CDCL has no notion of “the same number”. The conflicts grow by a factor of about 4–5 per bit. Multiplier equivalence is a classic hard family for SAT solvers and for BDDs: Bryant showed that BDDs for multiplication are exponential in any variable order.

That is the bottleneck of bit-blasting. It is the standard answer and works astonishingly well for most bit-level reasoning, but nonlinear arithmetic on wide words defeats it. The cure is not a faster SAT solver but reasoning at the word level (§5).

A success story for comparison. Script 02, Part 4 proves the slides’ bv_decide example: Hacker’s Delight’s branch-free popcount equals the loop.

wwvariablesclausesconflicts
8131421174
164191,3892,505
321,4194,80515,227

All are certified by DRUP. The 32-bit proof takes tens of seconds with our Python CDCL; bv_decide hands the same kind of CNF to CaDiCaL, an industrial SAT solver.

Run it: python3 02_bit_blasting.py (about 30 s), with figures/02_multiplier_hardness.png.


5. Word-level rewriting

5.1 Rules

Before any bit exists, Rewriter simplifies terms bottom-up:

  • constant folding: every operator applied to constants is evaluated;
  • identities:
    • x+0x + 0, x⋅1x \cdot 1, x&∼0x \mathbin{\&} \sim 0, x∣0x \mid 0 and x⊕0x \oplus 0 become xx;
    • x⋅0x \cdot 0, x&0x \mathbin{\&} 0, x⊕xx \oplus x and x−xx - x become 00;
    • ∼∼x\sim\sim x and −−x--x become xx;
    • shifts by ≥w\ge w give 0;
    • s=ss = s becomes ⊤;
  • canonical order: the arguments of +,⋅,&,∣,⊕+, \cdot, \&, \mid, \oplus are sorted, so y⋅xy \cdot x becomes x⋅yx \cdot y;
  • polynomial normalization of equalities: both sides of s=ts = t are read as polynomials in their atoms, with coefficients modulo 2w2^w.
    • The atoms are variables and non-arithmetic subterms.
    • Equal polynomials give ⊤.
    • A difference that is a non-zero constant gives ⊥.

5.2 What it buys

Script 03, Part 1:

claim8 bits16 bits32 bits
x⋅y=y⋅xx \cdot y = y \cdot xvalid, by rewritingvalid, by rewritingvalid, by rewriting
(x+y)2=x2+2xy+y2(x+y)^2 = x^2 + 2xy + y^2valid, by rewritingvalid, by rewritingvalid, by rewriting
(x−16)(x+16)=x2(x - 16)(x + 16) = x^2valid, by rewritingfalse, by rewritingfalse, by rewriting
(x+y)−y=x(x + y) - y = xvalid, by rewritingvalid, by rewritingvalid, by rewriting
(x⊕y)⊕y=x(x \oplus y) \oplus y = xvalid, by SAT (40 conflicts)valid, by SAT (80)valid, by SAT (160)

All with 0 conflicts where rewriting decides.

Reading the table.

  • Commutativity. It needed 8,636 conflicts at 7 bits in §4, and here costs nothing at 32 bits.
  • The middle claim is Lean’s grind slide: “BitVec 8 is a CommRing of characteristic 256 — no bitvector-specific theory needed”. On 8 bits, (x−16)(x+16)=x2−256=x2(x-16)(x+16) = x^2 - 256 = x^2, since 256≡0256 \equiv 0. On 16 and 32 bits the difference is the non-zero constant −256-256, so the claim is false, and the model x=0x = 0 confirms it.
  • The xor claim is not polynomial, so the solver bit-blasts it.

5.3 What it cannot do

Rewriting is sound (every rule is an identity modulo 2w2^w) but incomplete (script 03, Part 2):

  • x⋅x=xx \cdot x = x on 1 bit. It is valid: 0⋅0=00 \cdot 0 = 0 and 1⋅1=11 \cdot 1 = 1. Yet x2x^2 and xx are different polynomials, and a difference in normal forms proves nothing, so the bit-blaster decides it.
  • Bit tricks. The power-of-two test and popcount are not polynomial identities: they need the bits.

On 300 random 6-bit formulas (282 SAT, 18 UNSAT; script 03, Part 3):

  • rewriting never changes an answer (300/300);
  • it decides 12 formulas alone;
  • it cuts the total conflicts from 1,293 to 197.

Every SAT answer is still checked on the original formula, so a wrong rewrite rule would be caught.

Real solvers rewrite much more. Boolector and Bitwuzla apply hundreds of rewrite rules, normalize sums and products, and eliminate variables from linear equations. Rewriting is where most of a modern bit-vector solver’s engineering goes.


6. Alternatives to eager bit-blasting

6.1 Lazy multiplication by abstraction refinement

The idea is CEGAR again (Lectures 9, 10 and 13; Bryant et al. 2007):

  1. Abstract every non-constant multiplication: its result bits are fresh and unconstrained, an over-approximation of the formula.
  2. If the abstraction is UNSAT, so is the formula.
  3. If it is SAT, evaluate every multiplication on the model’s operands. If the model’s result bits are the true product everywhere, it is a real model. Otherwise make the violated multiplications precise and solve again.

Script 03, Part 4:

formulaeager clauseseager conflictslazy clausesroundsprecise
s+s=2ss + s = 2s, ss a sum of 8 products (16 bits)20,22001,83610/8
x⋅y=323x \cdot y = 323, 1<x≤y1 < x \le y (20 bits)2,073472,07321/1
x⋅y=y⋅xx \cdot y = y \cdot x (6 bits)4931,82849332/2
grind slide: x2y=1∧xy2=y⇒yx=1x^2 y = 1 \wedge x y^2 = y \Rightarrow y x = 1 (16 bits)10,8021510,80255/5

When it pays.

  • It pays when the multiplications do not matter. s+s=2ss + s = 2s holds whatever the products are: the first call is UNSAT with a tenth of the clauses.
  • It costs rounds when they do. Factoring (the answer 17·19) and commutativity need the multipliers, so the loop ends with the full circuit plus extra rounds.
  • Our measurements. CDCL also dispatches irrelevant multipliers by propagation (0 conflicts eager), so the saving is in size, not search.

What real solvers add.

  • They under-approximate too (fix some bits, or bound the operands), to find models faster.
  • They refine lemma by lemma, not by blasting whole multipliers: Boolector and Bitwuzla do this for arrays and other operators.

Bitwuzla, co-developed by this lecture’s guest, also has a propagation-based local search engine (Niemetz, Preiner and Biere 2017). It works directly on the words, with no CNF:

  1. start from an assignment of the inputs;
  2. if the root is false, walk down the term to a “responsible” input, choosing at each operator a value that would make its output right (an inverse value, computed by word-level operations);
  3. change that input, and repeat.

It is incomplete (it never proves UNSAT), but very effective on satisfiable instances with wide arithmetic, exactly where bit-blasting struggles. Exercise 10 asks you to build a tiny version.

6.3 Other word-level techniques (overview)

  • Width reduction. Some formulas are equisatisfiable at smaller widths, which gives smaller circuits.
  • Algebraic methods. Gröbner bases over Z/2w\mathbb{Z}/2^w, the ring solver of grind (Lecture 15), prove polynomial identities without bits. Recent multiplier verification combines algebra with SAT.
  • Int-blasting. Translate to integer arithmetic with explicit modulo constraints. This sometimes beats bit-blasting on wide words, and Lean’s grind uses it through its ToInt embedding.

Run it: python3 03_word_level.py (about 4 s).


7. Certificates: from DRUP to verified bit-blasting

Lecture 15 showed Lean’s bv_decide pipeline:

Simplify → Reflect → Bit-blast → AIG → CNF → SAT solver (CaDiCaL) → LRAT proof → verified checker

This lecture built the same pipeline in Python:

stageherein bv_decide
simplifyRewritersimp with bit-vector lemmas
bit-blast to an AIGBlaster (hashing, constant propagation)a bit-blaster written and proved correct in Lean
CNFTseitin clausesthe same
SATLecture 5’s CDCLCaDiCaL
proofDRUPLRAT (DRUP with hints)
checkerLecture 5’s check_drup (unverified)an LRAT checker proved correct in Lean

Where trust sits. Our pipeline trusts the bit-blaster and the DRUP checker. We test the blaster exhaustively at small widths and keep the checker independent of the solver. bv_decide trusts neither: the reflection theorem says “if the verified checker accepts this certificate for the verified bit-blasting of φ, then φ holds”, and the Lean kernel checks that theorem once. A buggy CaDiCaL can at worst fail to produce a certificate.


8. Summary

  1. Bit-vectors are words modulo 2w2^w with two readings. SMT-LIB makes every operation total (division by zero, large shifts). Integer facts fail at the boundaries and on zero divisors.
  2. Bit-blasting turns each operator into a circuit and each gate into Tseitin clauses, with constant propagation and structural hashing (an AIG). Adders and comparators are linear, shifters wlog⁡ww \log w, and multipliers and dividers quadratic.
  3. The blaster itself must be checked: here it agrees with the semantics on 5,608 exhaustive cases. Every answer is checked, by evaluating the model or by DRUP.
  4. Multiplication is the bottleneck. Commutativity needs 0 conflicts for ++ and 8,636 for ⋅\cdot at 7 bits, growing about 4–5× per bit.
  5. Word-level rewriting, with polynomial normalization modulo 2w2^w, proves such identities instantly at any width. It is sound but incomplete (x2=xx^2 = x on 1 bit), so solvers rewrite first and blast the rest.
  6. Abstraction refinement blasts only the multipliers a model violates; it saves size when they are irrelevant and costs rounds when they matter. Local search works on words directly for satisfiable instances.
  7. bv_decide is this pipeline with a verified bit-blaster and LRAT checker: trust moves from tools to proofs.

9. Common pitfalls

  • Reasoning about words with integer intuitions. x+1>xx + 1 > x, xy=0⇒x=0∨y=0xy = 0 \Rightarrow x = 0 \vee y = 0 and ∣x∣≥0|x| \ge 0 all fail.
  • Forgetting which reading an operator uses. <u<_u vs <s<_s, logical vs arithmetic shift, zero vs sign extension.
  • Undefined division. In SMT-LIB, x/0x / 0 is all ones, not an error; programs may differ, so model their semantics explicitly.
  • Trusting the bit-blaster. It is a compiler; test it, or verify it.
  • Expecting SAT to handle multiplication. Multiplier identities blow up; use word-level reasoning.
  • Reading a rewriting failure as a counterexample. Different normal forms prove nothing; only the bit-level answer counts.

10. Exercises

1. (semantics) On 8 bits, compute −128-128 as an unsigned value, (−128)⋅(−1)(-128) \cdot (-1), 200≫s2200 \gg_s 2 and sext(200)\text{sext}(200) to 16 bits.

Answer
  • −128-128 is 128128 unsigned.
  • (−128)⋅(−1)=128⋅255=32640≡128(-128)\cdot(-1) = 128 \cdot 255 = 32640 \equiv 128, i.e. −128-128 again.
  • 200≫s2200 \gg_s 2: the bits 11001000 become 11110010, which is 242 (signed −14-14).
  • sext(200)\text{sext}(200) to 16 bits is 0xFFC8=654800xFFC8 = 65480 (signed −56-56).

2. (counterexamples) Find, by hand, an 8-bit counterexample to x<sy⇒x+1≤sy+1x <_s y \Rightarrow x + 1 \le_s y + 1.

Answer

A counterexample. y=127y = 127 and any x<127x < 127, say x=0x = 0: then y+1=−128y + 1 = -128, and x+1=1̸≤s−128x + 1 = 1 \not\le_s -128.

3. (circuits) How many full adders does the shift-add multiplier of Blaster.mul build for w=4w = 4, before constant propagation? Why does constant propagation remove some?

Answer

The count. There are w=4w = 4 additions of ww-bit rows, so 16 full adders before simplification.

What constant propagation removes.

  • The first row is added to an all-zero accumulator, so its adders collapse.
  • Row ii has ii low constant-0 bits, so those positions only copy.
  • The carry into bit 0 is the constant 0.

4. (comparators) Explain why flipping the sign bits turns <s<_s into <u<_u.

Answer

The offset. Flipping the top bit adds 2w−12^{w-1} modulo 2w2^w, mapping signed values −2w−1..2w−1−1-2^{w-1}..2^{w-1}-1 monotonically onto unsigned 0..2w−10..2^w - 1.

Why the order survives. A monotone, order-preserving bijection keeps the comparison.

5. (division) Why does the division circuit compute q⋅b+rq \cdot b + r in 2w2w bits? Give an 8-bit example that would go wrong in ww bits.

Answer

What goes wrong in ww bits. The constraint a=q⋅b+ra = q \cdot b + r could be satisfied with a wrapped-around product.

An example. a=0a = 0, b=16b = 16, r=0r = 0 and q=16q = 16: on 8 bits, 16⋅16+0=256≡0=a16 \cdot 16 + 0 = 256 \equiv 0 = a. So q=16q = 16 would be accepted, although 0/16=00 / 16 = 0. In 16 bits, 256≠0256 \neq 0, which forces the true quotient.

6. (hardness) Why does structural hashing make x+y=y+xx + y = y + x trivial but not x⋅y=y⋅xx \cdot y = y \cdot x?

Answer

Addition. Each bit of x+yx + y is a function of xix_i, yiy_i and a carry, built from AND and XOR. These are hashed with sorted inputs, so both orders build identical gates.

Multiplication. x⋅yx \cdot y adds the partial products x⋅yix \cdot y_i row by row, and y⋅xy \cdot x adds y⋅xiy \cdot x_i. The intermediate sums are different functions, and only the final sums agree, so there is nothing to share.

7. (polynomials) Show by polynomial normalization that (x+1)2−(x−1)2=4x(x + 1)^2 - (x - 1)^2 = 4x holds at every width, and that (x+128)2=x2(x + 128)^2 = x^2 holds at 8 bits but not at 16.

Answer

The first identity. The difference is (x2+2x+1)−(x2−2x+1)=4x(x^2 + 2x + 1) - (x^2 - 2x + 1) = 4x, which holds in every ring.

The second. (x+128)2=x2+256x+16384(x + 128)^2 = x^2 + 256x + 16384. At 8 bits, 256≡0256 \equiv 0 and 16384=64⋅256≡016384 = 64 \cdot 256 \equiv 0. At 16 bits the difference is 256x+16384256x + 16384, which is not the zero polynomial; as a function it is non-zero at x=0x = 0 (16384), so the claim is false.

8. (abstraction) For x⋅y=6∧x=2∧y=3x \cdot y = 6 \wedge x = 2 \wedge y = 3, trace solve_lazy_mul. How many rounds?

Answer

One round. The product bits are fresh, but the formula forces them to 6. The check computes 2⋅3=62 \cdot 3 = 6 from the model’s operands, the abstraction was right, and the answer is SAT after one round.

A variant. With x⋅y=7x \cdot y = 7 instead, round 1 sets the product bits to 7 and the check fails (2⋅3=62 \cdot 3 = 6). The multiplier is made precise, and round 2 is UNSAT. solve_lazy_mul reports exactly these round counts.

9. (programming) Add a Karatsuba-style multiplier to Blaster (split operands in halves) and compare clause counts and the commutativity conflicts with the shift-add multiplier.

Answer sketch

The construction. Split x=xh2w/2+xlx = x_h 2^{w/2} + x_l, and compute xhyhx_h y_h, xlylx_l y_l and (xh+xl)(yh+yl)(x_h + x_l)(y_h + y_l) recursively, with sums in w/2+1w/2 + 1 bits.

What to expect. Fewer partial-product gates for large ww, but more adders, and no gain for SAT: commutativity of two different multiplier architectures is typically even harder for CDCL.

10. (programming) Implement a tiny propagation-based local search for formulas t=ct = c (tt built from ++, ⋅\cdot, ⊕\oplus over two variables). At each step, pick the operand to change and compute an inverse value:

  • for x+s=cx + s = c, take x:=c−sx := c - s;
  • for x⊕s=cx \oplus s = c, take x:=c⊕sx := c \oplus s;
  • for x⋅s=cx \cdot s = c, if ss is odd take x:=c⋅s−1x := c \cdot s^{-1} modulo 2w2^w, otherwise try random values.

Measure its success rate on random satisfiable targets.

Answer sketch

The search. Evaluate the term; if wrong, descend from the root, choosing at each node the child whose value can be inverted. Odd numbers are invertible modulo 2w2^w; compute the inverse by Newton iteration.

What to expect. Fast success on most SAT instances with odd multipliers; even multipliers need random moves. The procedure never proves UNSAT.


11. Further reading

  • D. Kroening, O. Strichman, Decision Procedures, Chapter 6 (2nd ed.): bit-vector arithmetic, bit-flattening, incremental and abstraction-based approaches.
  • C. Barrett, P. Fontaine, C. Tinelli, The SMT-LIB Standard (the FixedSizeBitVectors theory and QF_BV logic).
  • R. Brummayer, A. Biere, “Boolector: An Efficient SMT Solver for Bit-Vectors and Arrays”, TACAS 2009.
  • A. Niemetz, M. Preiner, “Bitwuzla”, CAV 2023.
  • A. Niemetz, M. Preiner, A. Biere, “Propagation based local search for bit-precise reasoning”, FMSD 2017.
  • R. E. Bryant, D. Kroening, J. Ouaknine, S. A. Seshia, O. Strichman, B. Brady, “Deciding Bit-Vector Arithmetic with Abstraction”, TACAS 2007.
  • G. Kovásznai, A. Fröhlich, A. Biere, “Complexity of Fixed-Size Bit-Vector Logics”, Theory of Computing Systems, 2016.
  • R. E. Bryant, “On the Complexity of VLSI Implementations and Graph Representations of Boolean Functions with Application to Integer Multiplication”, IEEE TC 1991.
  • H. S. Warren, Hacker’s Delight, 2nd ed., 2012.
  • J. Bloch, “Extra, Extra — Read All About It: Nearly All Binary Searches and Mergesorts are Broken”, Google Research blog, 2006.

12. Next lecture

Lecture 17: Herbrand’s theorem and quantifier instantiation.

  • Beyond quantifier-free formulas. Herbrand’s theorem reduces first-order unsatisfiability to the unsatisfiability of finitely many ground instances. SMT solvers find those instances by E-matching (grind’s annotations in Lecture 15), model-based instantiation and enumeration.

See Lecture 17.

← 返回课程目录