Home / Journal / The cost of writing parity
Computational complexity
The cost of writing parity
Abstract
How many terms does it take to describe every bit string with an odd number of ones? A disjunctive normal form needs a separate term for each accepted string. A circuit can retain the parity of the bits it has already read. With six inputs, the exact minimum is 32 terms, while an explicit circuit uses 20 gates.
Term or gate count
Input bits n
- Minimum DNF terms
- Gates in the XOR chain
Chart values
| Input bits n | Minimum DNF terms | Gates in the XOR chain |
|---|---|---|
| 2 | 2 | 4 |
| 3 | 4 | 8 |
| 4 | 8 | 12 |
| 5 | 16 | 16 |
| 6 | 32 | 20 |
| 7 | 64 | 24 |
| 8 | 128 | 28 |
Derivation #
Try leaving one bit free #
A term specifies individual bits. For example, “the first bit is 1 and the second is 0” accepts both 100 and 101 on three inputs. The first string has one 1 and the second has two. Including that term in a disjunction would accept both strings.
Count the terms that survive #
Flipping any free bit gives the same contradiction. Every satisfiable term in a correct DNF fixes all n bits and accepts exactly one string. Flipping the first bit pairs strings of opposite parity, so exactly half of the 2ⁿ strings are accepted. Listing them gives precisely 2ⁿ⁻¹ terms and attains the lower bound.
Keep a running parity bit #
Start with the first bit. If a is the running parity and b is the next input, their new parity is a XOR b. The expression (a OR b) AND NOT(a AND b) takes four gates. After n − 1 updates the output is correct on every input.
Check the six-bit case #
For n = 6 the check enumerates 3⁶ = 729 terms in which each bit is zero, one or free. Exactly 32 guarantee output 1. The program then feeds all 64 strings through the 20-gate circuit and compares each answer with the sum of the bits modulo two.
Conclusion #
On six bits, 20 gates suffice even though every DNF needs 32 terms. The minimum DNF term count therefore cannot serve as a universal lower bound on circuit gate count.
Scope
This teaching example reproduces a known representation-specific bound. P versus NP remains open.