ESOP and Reed–Muller Synthesis

In ordinary logic design you learned to write any Boolean function as a sum of products — ANDs joined by ORs, minimised on a Karnaugh map. The reversible world speaks a different dialect: ANDs joined by XOR. The reason is hiding in plain sight in the gates themselves — a Toffoli computes t \oplus ab: an AND, XORed onto a target. XOR is what Toffoli-family gates do natively. So if you can write your function as an exclusive sum of products (an ESOP), the circuit practically draws itself: one Toffoli per product term. This page is about that translation — and the classical theory behind it, the Reed–Muller expansion.

Every function is an XOR of ANDs

The translation toolkit between the OR world of Boolean algebra and the XOR world is tiny:

IdentityUse it to…
x \lor y = x \oplus y \oplus xyturn each OR into XORs (the xy term cancels the double-count)
\bar x = x \oplus 1trade a negation for a constant term
x \oplus x = 0cancel duplicated terms — pairs annihilate
x \lor y = x \oplus y when xy = 0replace OR by XOR outright for disjoint terms

Worked example: the majority function

Take the 3-input majority \mathrm{maj}(a,b,c) — output 1 when at least two inputs are 1 (the carry bit of a full adder). Its familiar SOP is ab \lor bc \lor ca. Convert: the three products overlap only in the all-ones case abc. Apply x \lor y = x \oplus y \oplus xy twice and collect — every correction term is a copy of abc, and they cancel in pairs (abc \oplus abc = 0). The result:

\mathrm{maj}(a,b,c) \;=\; ab \,\oplus\, bc \,\oplus\, ca.

Check it the fast way, case by case: no 1s or one 1 — every product is 0. Two 1s (say a=b=1, c=0) — exactly one product fires: 1 \oplus 0 \oplus 0 = 1. Three 1s — all three fire: 1 \oplus 1 \oplus 1 = 1. Correct on all eight rows, and already in positive-polarity Reed–Muller form: three AND terms, no negations, no constant.

Term by term, gate by gate

Now the payoff. Add one fresh target ancilla wire t, prepared as 0. For each product term of the ESOP, place one (multi-controlled) Toffoli: controls on the term's variables, target on t. Each gate XORs its term onto t, so after k gates the target holds 0 \oplus (\text{term}_1) \oplus \cdots \oplus (\text{term}_k) = f — while the inputs pass through completely untouched. An ESOP with k terms becomes a k-Toffoli cascade. For the majority:

Housekeeping for the other term shapes: a single-variable term (x_i) becomes a CNOT; the constant term 1 becomes a NOT on t; and a mixed-polarity term like \bar a b is a Toffoli whose a-control is conjugated by NOTs (or, expanding \bar a b = b \oplus ab, a CNOT plus a Toffoli — your choice, and a genuine cost trade-off). Since every gate targets t and the controls never change, the gates commute freely — order the cascade however suits the optimiser.

ESOP versus MMD

Notice what changed since transformation-based synthesis: MMD synthesises a whole reversible permutation in place; ESOP synthesis computes an ordinary, quite possibly irreversible, Boolean function onto a fresh output wire — reversibility is restored by the ancilla, exactly the embedding move you know from Bennett-style computing. That makes ESOP the tool of choice when your spec is "compute f(x)" rather than "permute the states": arithmetic predicates, comparators, round functions of ciphers. Real toolchains factor the work: an ESOP minimiser (the classic tool is EXORCISM) squeezes the term count k, then the term-per-Toffoli translation runs mechanically.

The expansion is older than reversible computing by decades. David Muller described the algebraic form in 1954; Irving Reed, the same year, gave a majority-logic decoder for it — and their names stuck to the resulting family of error-correcting codes. The connection is direct: the codewords of a Reed–Muller code are exactly the truth tables of low-degree XOR-of-ANDs polynomials. The very same expansion that here turns functions into Toffoli cascades also protected the imagery beamed back by the Mariner probes from Mars in the 1970s. One algebraic identity, two entirely different superpowers — and in both cases the magic ingredient is that XOR makes Boolean functions into honest algebra (a vector space over GF(2)) where cancellation and uniqueness hold.

The single most dangerous reflex from SOP-land: reading \oplus as "or". They agree on three of four input pairs and differ exactly where it hurts: 1 \oplus 1 = 0 while 1 \lor 1 = 1. So you may not take a Karnaugh-map cover and staple its product terms together with XORs — wherever two terms overlap, the overlap counts twice and cancels. (Try it on the majority: stapling gives ab \oplus bc \oplus ca, which happens to be right only because the double-counted abc region is covered three times — an odd number. Cover it twice and it would vanish!) The safe road is always through the identities: x \lor y = x \oplus y \oplus xy, or use disjoint products. XOR keeps honest books: every term is counted mod 2.