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 gives , and an XOR gate gives . Each input gets the vanishing polynomial , which is zero exactly when . For an -bit multiplier the specification is the polynomial . Backward rewriting replaces, in , each gate output by its polynomial, from the outputs back to the inputs, and replaces by . 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 times , and the output of an XOR gate is .
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 by , because and . 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 is combinational, with inputs and gates in topological order. Each gate computes a Boolean function of earlier signals, and the outputs are some of the signals. The polynomial ring is , over the field of rationals, with one variable per signal.
- Each gate has a polynomial that equals on . For the usual gates: , , , . The gate polynomial is .
- The gate ideal is . The polynomials are the vanishing polynomials of .
- The specification is a polynomial in the signals. The circuit is correct if for every input , where are the values of the gates. For an unsigned multiplier with outputs , .
- The term order is lexicographic, with every gate variable larger than every variable in its fanin cone, for example . Then the leading term of is , since uses only smaller variables, and the leading term of is .
The template
ALGEBRAIC-CHECK(C, S)- 1
order the variables so that each gate is larger than every variable in its fanin cone - 2
G ← {−g + P_g for each gate g} ∪ {x² − x for each input x} - 3
r ← S - 4
for each gate g, from the outputs back to the inputs, do - 5
r ← r with every occurrence of g replaced by P_g ▷ backward rewriting - 6
in r, replace every power x^k with k ≥ 2 of an input by x - 7
if r = 0 then return correct - 8
m ← a monomial of r of least degree - 9
return the counterexample: the inputs of m set to 1, all other inputs 0
Lines L4 to L6 are the multivariate division of by , with the reductions done in a fixed order. Replacing by subtracts a multiple of , and replacing by subtracts a multiple of . When the loop ends, no term of contains a gate variable, and no input has an exponent above 1.
is a Gröbner basis. The leading terms 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 is a Gröbner basis of with no computation. So the remainder of is unique, whatever order of reductions is used, and exactly when it is 0. This is the ideal membership test of the method.
Theorem. With , , the order and as above, the following are equivalent: (1) the circuit is correct; (2) ; (3) . If , the input of line L9 makes .
Proof. The points of the circuit are the vectors with . Every polynomial of vanishes at each of them: for , and because equals the gate function on 0-1 values and is that value. So every polynomial of vanishes at every point of the circuit.
(3) implies (2): lines L4 to L6 subtract multiples of polynomials of , so , and gives . (2) implies (1): is in , so it vanishes at every point of the circuit.
(1) implies (3): has no gate variable and no input with an exponent above 1, so is a multilinear polynomial in . Since , for every , and by (1) is zero on all of . A multilinear polynomial that is zero on is the zero polynomial. By induction on : write with multilinear in . Setting shows that is zero on , and setting shows that is, hence too. By induction both are 0, so .
For the counterexample, let and let have least degree among the monomials of . At the point , a monomial is 1 exactly when . Every monomial of other than has degree at least and differs from , so it is not a subset of . So is the coefficient of , which is not 0, and .
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 of every gate polynomial never divides, so a specification with integer coefficients keeps integer coefficients throughout.
Example. A 2-bit multiplier has inputs and , partial products , , , , and two half adders: , , , . The specification is . Write for the product.
| step | rewrite | |
|---|---|---|
| start | ||
| 1 | ||
| 2 | ||
| 3 | ||
| 4 | ||
| 5 | the four partial products |
In steps 2 and 4 the products and cancel: the carry of a half adder takes over the part of the sum that the XOR loses. If the bug replaces the AND, step 3 gives , and the remainder is . Its least monomial is , so line L9 sets and . Then , but the circuit gives , , , so the output is , and is the difference.
Cost. Lines L1 and L2 are linear in the circuit. A rewrite at line L5 multiplies the terms that contain by , so the number of terms of can grow. Deciding correctness is coNP-hard in general: with the specification for one output , correctness says that 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 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 , with a word variable per operand and the vanishing polynomials for the words and 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 reduces to 0 in one pass, full adder by full adder.
Variations
- Over the integers. All leading coefficients are , so the reduction stays in 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 on 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 , the remainder of a correct circuit can be a nonzero polynomial that is zero only on 0-1 points, such as , and the check reports a false bug.
- Truncated outputs. A multiplier with only outputs computes modulo . The specification then holds only modulo . Over the number is a unit, so the check must work over the integers with added to the ideal, which is outside the theorem of this page, or keep all outputs.
- Signed numbers. A two's complement word has the polynomial . 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
- Write the gate polynomials of a full adder with sum and carry , and reduce to 0.
- Show that is in if and only if the output is 0 on every input, and conclude that the problem is coNP-hard.
- Reduce the specification of the 2-bit multiplier of the example with and find the counterexample of line L9.
References
- 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
- 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
- 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
- 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.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W3 standard |
|
Tag TA6P1V Edit this page History Report an error Markdown