Research Atlas

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.

Formula
DNF · 2ⁿ⁻¹ terms Circuit · 4(n − 1) gates
Each additional bit doubles the term count

Term or gate count

Each additional bit doubles the term count. Term or gate count / Input bits n.

Input bits n

  • Minimum DNF terms
  • Gates in the XOR chain
Chart values
Input bits nMinimum DNF termsGates in the XOR chain
224
348
4812
51616
63220
76424
812828
Each new input adds four gates to the circuit. A term specifies an input assignment, while a gate performs a logical operation.

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.

Working and verification

Download code and materials · ZIP

References

The P versus NP problem