Algorithm Search⌘K

Techniqueresearch

Algebraic verification of arithmetic circuits

Also called backward rewriting of multipliers, Groebner basis circuit verification.

Models each gate as a polynomial and rewrites the specification of a multiplier or adder backward through the gates, a Groebner basis reduction that ends in zero if correct.

Algebraic verification proves that a gate-level arithmetic circuit, such as a multiplier, computes its word-level specification. Each gate becomes a polynomial equation over the rationals. An AND gate g=a∧bg = a \wedge b gives −g+ab-g + ab, and an XOR gate g=a⊕bg = a \oplus b gives −g+a+b−2ab-g + a + b - 2ab. Each input xx gets the vanishing polynomial x2−xx^2 - x, which is zero exactly when x∈{0,1}x \in \{0, 1\}. For an nn-bit multiplier the specification is the polynomial S=∑i2isi−(∑i2iai)(∑j2jbj)S = \sum_i 2^i s_i - \bigl(\sum_i 2^i a_i\bigr)\bigl(\sum_j 2^j b_j\bigr). Backward rewriting replaces, in SS, each gate output by its polynomial, from the outputs back to the inputs, and replaces x2x^2 by xx. This is division by the gate polynomials, which form a Gröbner basis for a term order that puts every gate above its inputs. The remainder is zero exactly when the circuit is correct, and a nonzero remainder gives an input that shows the bug. The check does not depend on how many input values there are, so it works for multipliers of hundreds of bits where BDDs of the outputs are exponential. Its cost is the size of the intermediate polynomials, which depends strongly on the architecture.

In plain words

Write each wire of the circuit as a number that is 0 or 1. Each gate is then a small formula. The output of an AND gate is aa times bb, and the output of an XOR gate is a+b−2aba + b - 2ab.

The specification is also a formula: the outputs, read as a binary number, minus the product of the two inputs. It must be 0 for every input.

Start with this formula and replace the output wires by their gate formulas. Then replace the wires that those use, back to the inputs. Wherever an input appears squared, replace x2x^2 by xx, because 02=00^2 = 0 and 12=11^2 = 1. If everything cancels and you get 0, the circuit is correct for all inputs. If something is left, it is a formula in the inputs, and any input where it is not 0 is a bug.

When it applies

  • The circuit CC is combinational, with inputs x1,…,xnx_1, \ldots, x_n and gates g1,…,gmg_1, \ldots, g_m in topological order. Each gate computes a Boolean function of earlier signals, and the outputs are some of the signals. The polynomial ring is Q[x1,…,xn,g1,…,gm]\mathbb{Q}[x_1, \ldots, x_n, g_1, \ldots, g_m], over the field Q\mathbb{Q} of rationals, with one variable per signal.
  • Each gate g=op(u1,…,uk)g = \mathrm{op}(u_1, \ldots, u_k) has a polynomial Pg(u1,…,uk)P_g(u_1, \ldots, u_k) that equals op\mathrm{op} on {0,1}k\{0, 1\}^k. For the usual gates: ¬a↦1−a\neg a \mapsto 1 - a, a∧b↦aba \wedge b \mapsto ab, a∨b↦a+b−aba \vee b \mapsto a + b - ab, a⊕b↦a+b−2aba \oplus b \mapsto a + b - 2ab. The gate polynomial is −g+Pg-g + P_g.
  • The gate ideal is J=⟨−gj+Pgj (1≤j≤m), xi2−xi (1≤i≤n)⟩J = \langle -g_j + P_{g_j} \ (1 \le j \le m),\ x_i^2 - x_i \ (1 \le i \le n) \rangle. The polynomials xi2−xix_i^2 - x_i are the vanishing polynomials of {0,1}\{0, 1\}.
  • The specification is a polynomial SS in the signals. The circuit is correct if S(a,C(a))=0S(a, C(a)) = 0 for every input a∈{0,1}na \in \{0, 1\}^n, where C(a)C(a) are the values of the gates. For an unsigned n×nn \times n multiplier with outputs s0,…,s2n−1s_0, \ldots, s_{2n-1}, S=∑i<2n2isi−(∑i<n2iai)(∑j<n2jbj)S = \sum_{i < 2n} 2^i s_i - \bigl(\sum_{i < n} 2^i a_i\bigr)\bigl(\sum_{j < n} 2^j b_j\bigr).
  • The term order is lexicographic, with every gate variable larger than every variable in its fanin cone, for example gm>⋯>g1>xn>⋯>x1g_m > \cdots > g_1 > x_n > \cdots > x_1. Then the leading term of −gj+Pgj-g_j + P_{g_j} is gjg_j, since PgjP_{g_j} uses only smaller variables, and the leading term of xi2−xix_i^2 - x_i is xi2x_i^2.

The template

  1. ALGEBRAIC-CHECK(C, S)
  2. 1order the variables so that each gate is larger than every variable in its fanin cone
  3. 2G ← {−g + P_g for each gate g} ∪ {x² − x for each input x}
  4. 3r ← S
  5. 4for each gate g, from the outputs back to the inputs, do
  6. 5r ← r with every occurrence of g replaced by P_g ▷ backward rewriting
  7. 6in r, replace every power x^k with k ≥ 2 of an input by x
  8. 7if r = 0 then return correct
  9. 8m ← a monomial of r of least degree
  10. 9return the counterexample: the inputs of m set to 1, all other inputs 0

Lines L4 to L6 are the multivariate division of SS by GG, with the reductions done in a fixed order. Replacing gg by PgP_g subtracts a multiple of −g+Pg-g + P_g, and replacing x2x^2 by xx subtracts a multiple of x2−xx^2 - x. When the loop ends, no term of rr contains a gate variable, and no input has an exponent above 1.

GG is a Gröbner basis. The leading terms g1,…,gm,x12,…,xn2g_1, \ldots, g_m, x_1^2, \ldots, x_n^2 are pairwise coprime. By Buchberger's product criterion (Buchberger's criteria), the S-polynomial of two polynomials with coprime leading terms reduces to 0, so GG is a Gröbner basis of JJ with no computation. So the remainder of SS is unique, whatever order of reductions is used, and S∈JS \in J exactly when it is 0. This is the ideal membership test of the method.

Theorem. With Q\mathbb{Q}, JJ, the order and rr as above, the following are equivalent: (1) the circuit is correct; (2) S∈JS \in J; (3) r=0r = 0. If r≠0r \ne 0, the input of line L9 makes S(a,C(a))≠0S(a, C(a)) \ne 0.

Proof. The points of the circuit are the vectors (a,C(a))(a, C(a)) with a∈{0,1}na \in \{0, 1\}^n. Every polynomial of GG vanishes at each of them: ai2−ai=0a_i^2 - a_i = 0 for ai∈{0,1}a_i \in \{0, 1\}, and −g+Pg=0-g + P_g = 0 because PgP_g equals the gate function on 0-1 values and gg is that value. So every polynomial of JJ vanishes at every point of the circuit.

(3) implies (2): lines L4 to L6 subtract multiples of polynomials of GG, so S−r∈JS - r \in J, and r=0r = 0 gives S∈JS \in J. (2) implies (1): SS is in JJ, so it vanishes at every point of the circuit.

(1) implies (3): rr has no gate variable and no input with an exponent above 1, so rr is a multilinear polynomial in x1,…,xnx_1, \ldots, x_n. Since S−r∈JS - r \in J, r(a)=S(a,C(a))r(a) = S(a, C(a)) for every a∈{0,1}na \in \{0, 1\}^n, and by (1) rr is zero on all of {0,1}n\{0, 1\}^n. A multilinear polynomial that is zero on {0,1}n\{0, 1\}^n is the zero polynomial. By induction on nn: write r=r0+xnr1r = r_0 + x_n r_1 with r0,r1r_0, r_1 multilinear in x1,…,xn−1x_1, \ldots, x_{n-1}. Setting xn=0x_n = 0 shows that r0r_0 is zero on {0,1}n−1\{0, 1\}^{n-1}, and setting xn=1x_n = 1 shows that r0+r1r_0 + r_1 is, hence r1r_1 too. By induction both are 0, so r=0r = 0.

For the counterexample, let r≠0r \ne 0 and let m=∏i∈Txim = \prod_{i \in T} x_i have least degree among the monomials of rr. At the point a=1Ta = \mathbf{1}_T, a monomial ∏i∈Uxi\prod_{i \in U} x_i is 1 exactly when U⊆TU \subseteq T. Every monomial of rr other than mm has degree at least ∣T∣|T| and differs from mm, so it is not a subset of TT. So r(a)r(a) is the coefficient of mm, which is not 0, and S(a,C(a))=r(a)≠0S(a, C(a)) = r(a) \ne 0. □\square

The proof does not need the Gröbner basis property; it uses only that the remainder is multilinear in the inputs. The property says more: the remainder does not depend on the order in which the reductions are done. Rewriting with the leading coefficient −1-1 of every gate polynomial never divides, so a specification with integer coefficients keeps integer coefficients throughout.

Example. A 2-bit multiplier has inputs a1a0a_1 a_0 and b1b0b_1 b_0, partial products s0=a0b0s_0 = a_0 b_0, p01=a0b1p_{01} = a_0 b_1, p10=a1b0p_{10} = a_1 b_0, p11=a1b1p_{11} = a_1 b_1, and two half adders: s1=p01⊕p10s_1 = p_{01} \oplus p_{10}, c1=p01∧p10c_1 = p_{01} \wedge p_{10}, s2=p11⊕c1s_2 = p_{11} \oplus c_1, s3=p11∧c1s_3 = p_{11} \wedge c_1. The specification is S=8s3+4s2+2s1+s0−(2a1+a0)(2b1+b0)S = 8 s_3 + 4 s_2 + 2 s_1 + s_0 - (2 a_1 + a_0)(2 b_1 + b_0). Write Q=4a1b1+2a1b0+2a0b1+a0b0Q = 4 a_1 b_1 + 2 a_1 b_0 + 2 a_0 b_1 + a_0 b_0 for the product.

step rewrite rr
start 8s3+4s2+2s1+s0−Q8 s_3 + 4 s_2 + 2 s_1 + s_0 - Q
1 s3→p11c1s_3 \to p_{11} c_1 8p11c1+4s2+2s1+s0−Q8 p_{11} c_1 + 4 s_2 + 2 s_1 + s_0 - Q
2 s2→p11+c1−2p11c1s_2 \to p_{11} + c_1 - 2 p_{11} c_1 4p11+4c1+2s1+s0−Q4 p_{11} + 4 c_1 + 2 s_1 + s_0 - Q
3 c1→p01p10c_1 \to p_{01} p_{10} 4p11+4p01p10+2s1+s0−Q4 p_{11} + 4 p_{01} p_{10} + 2 s_1 + s_0 - Q
4 s1→p01+p10−2p01p10s_1 \to p_{01} + p_{10} - 2 p_{01} p_{10} 4p11+2p01+2p10+s0−Q4 p_{11} + 2 p_{01} + 2 p_{10} + s_0 - Q
5 the four partial products Q−Q=0Q - Q = 0

In steps 2 and 4 the products p11c1p_{11} c_1 and p01p10p_{01} p_{10} cancel: the carry of a half adder takes over the part of the sum that the XOR loses. If the bug c1=p01∨p10c_1 = p_{01} \vee p_{10} replaces the AND, step 3 gives 4p01+4p10−4p01p104 p_{01} + 4 p_{10} - 4 p_{01} p_{10}, and the remainder is r=4a0b1+4a1b0−8a0a1b0b1r = 4 a_0 b_1 + 4 a_1 b_0 - 8 a_0 a_1 b_0 b_1. Its least monomial is a0b1a_0 b_1, so line L9 sets a0=b1=1a_0 = b_1 = 1 and a1=b0=0a_1 = b_0 = 0. Then 1⋅2=21 \cdot 2 = 2, but the circuit gives s1=1s_1 = 1, c1=1c_1 = 1, s2=1s_2 = 1, so the output is 66, and r=4r = 4 is the difference.

Cost. Lines L1 and L2 are linear in the circuit. A rewrite at line L5 multiplies the terms that contain gg by PgP_g, so the number of terms of rr can grow. Deciding correctness is coNP-hard in general: with the specification S=sS = s for one output ss, correctness says that ss is 0 on every input, which is the unsatisfiability of a circuit, a coNP-complete problem. So no order of rewriting is polynomial for all circuits unless P = NP. The size of rr in practice is measured, not proved. For array and simple tree multipliers, the papers in the references report remainders that stay small with a good order, and for optimized multipliers with complex final adders they report a large growth that their methods avoid.

Classic examples

  • Simple multipliers. Array multipliers and Wallace tree or Dadda multipliers built from half and full adders. Ritirc, Biere and Kauers (2017) split the specification by output columns and rewrite one column at a time, which keeps the polynomials small.
  • Galois field multipliers. Lv, Kalla and Enescu (2013) work over the finite field F2k\mathbb{F}_{2^k}, with a word variable per operand and the vanishing polynomials x2k−xx^{2^k} - x for the words and x2−xx^2 - x for the bits. The same term order makes the gate polynomials a Gröbner basis.
  • Optimized multipliers. Booth encoding and parallel prefix final adders make the intermediate polynomials blow up. Kaufmann, Biere and Kauers (2019) check a complex final adder against a ripple-carry adder with SAT and use algebra for the rest. Mahzoon, Grosse and Drechsler (2019) first find the half and full adders and other blocks, then rewrite.
  • Adders and sums. A ripple-carry adder with the specification ∑i2isi−∑i2iai−∑i2ibi\sum_i 2^i s_i - \sum_i 2^i a_i - \sum_i 2^i b_i reduces to 0 in one pass, full adder by full adder.

Variations

  • Over the integers. All leading coefficients are −1-1, so the reduction stays in Z[X]\mathbb{Z}[X] and needs no fractions.
  • Forward or mixed rewriting. Rewriting from the inputs builds the polynomial of each output, as in function extraction. Rewriting backward keeps only one polynomial but depends on the order.
  • Rewriting rules for XOR chains and adders. Preprocessing that merges gates into half and full adders, or eliminates internal variables first, changes the gate polynomials but not the ideal of the circuit points.
  • Word-level specifications. The specification can be any polynomial of the input words that has integer values. A Taylor expansion diagram represents such word-level polynomials canonically, and BMDs represent the bit-level ones.
  • Counterexamples. A nonzero remainder is a polynomial in the inputs. Line L9 gives one failing input, and any zero of rr on {0,1}n\{0, 1\}^n is a passing one.

Pitfalls

  • The term order. Rewriting a gate before every gate that uses it would leave it in the polynomial. Use a reverse topological order of the whole circuit, not of each output cone.
  • Missing vanishing polynomials. Without x2−xx^2 - x, the remainder of a correct circuit can be a nonzero polynomial that is zero only on 0-1 points, such as a2−aa^2 - a, and the check reports a false bug.
  • Truncated outputs. A multiplier with only nn outputs computes a⋅ba \cdot b modulo 2n2^n. The specification then holds only modulo 2n2^n. Over Q\mathbb{Q} the number 2n2^n is a unit, so the check must work over the integers with 2n2^n added to the ideal, which is outside the theorem of this page, or keep all 2n2n outputs.
  • Signed numbers. A two's complement word has the polynomial −2n−1an−1+∑i<n−12iai-2^{n-1} a_{n-1} + \sum_{i < n-1} 2^i a_i. A specification with the unsigned form fails on a correct signed multiplier.
  • Blowup without a bug. A large remainder during rewriting is not a sign of a bug. Optimized designs need the methods above before the rewrite.

Exercises

  1. Write the gate polynomials of a full adder with sum a⊕b⊕ca \oplus b \oplus c and carry ab∨ac∨bcab \vee ac \vee bc, and reduce 2cout+s−a−b−c2 c_{\mathrm{out}} + s - a - b - c to 0.
  2. Show that S=sS = s is in JJ if and only if the output ss is 0 on every input, and conclude that the problem is coNP-hard.
  3. Reduce the specification of the 2-bit multiplier of the example with s2=p11∨c1s_2 = p_{11} \vee c_1 and find the counterexample of line L9.

References

  1. D. Ritirc, A. Biere and M. Kauers, Column-wise verification of multipliers using computer algebra, Formal Methods in Computer-Aided Design (FMCAD 2017), 23 to 30, 2017, the gate polynomials and field polynomials of a circuit, the term order that makes them a Groebner basis, the reduction of the multiplier specification, and its split by output columns
  2. J. Lv, P. Kalla and F. Enescu, Efficient Groebner basis reductions for formal verification of Galois field arithmetic circuits, IEEE Transactions on Computer-Aided Design of Integrated Circuits and Systems 32(9), 1409 to 1420, 2013, the reverse topological term order under which the gate polynomials form a Groebner basis, and the reduction over finite fields of characteristic 2 with the vanishing polynomials x^q - x
  3. D. Kaufmann, A. Biere and M. Kauers, Verifying large multipliers by combining SAT and computer algebra, Formal Methods in Computer-Aided Design (FMCAD 2019), 28 to 36, 2019, the combination in which SAT checks a complex final-stage adder against a simple one and computer algebra checks the rest of the multiplier
  4. A. Mahzoon, D. Grosse and R. Drechsler, RevSCA, using reverse engineering to bring light into backward rewriting for big and dirty multipliers, Design Automation Conference (DAC 2019), 2019, the growth of the intermediate polynomials in backward rewriting of optimized multipliers, and the identification of adder blocks that avoids it

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW3 standard
  • five exercises