Exact circuit complexity of counting modulo 4
Given n Boolean inputs x₁, ..., xₙ ∈ {0, 1} with sum s = x₁ + ... + xₙ, we ask for the minimum number of two-input Boolean gates needed to decide whether s ≡ r (mod 4). Over the full binary basis of all sixteen two-input operations, Stockmeyer (1977) proved that this minimum lies between 5n/2 − 6 and 5n/2, while the exact gate count remained open. In this paper, we settle this problem for every n ≥ 1 and every residue r ∈ {0, 1, 2, 3}. For all n ≥ 5, we prove that the minimum number of gates is ⌊5n/2⌋ − 3 − [n ≡ 2r (mod 4)], where the bracket equals 1 if the condition inside holds and 0 otherwise. More generally, we determine the exact minimum gate count for every Boolean function that depends only on s mod 4. Beyond constants and parity, an exact formula was previously known only for [s mod 4 ∈ {1, 2}] when n ≡ 3 (mod 8) and n ≥ 11. For the upper bounds, we add a two-gate step on the last input at the end of Stockmeyer's pair-based circuit. For the lower bounds, we apply Stockmeyer's gate-elimination step to one function of s mod 4 at a time instead of a whole class of functions, and induct on n. Among the base cases n ≤ 4, only x₁ + x₂ + x₃ + x₄ = 3 uses a computer check. Finally, we formalize all results and proofs of this paper and its supplementary material in Lean 4. This record includes both the main manuscript (counting_mod4_dam.pdf) and the self-contained supplementary material proving Theorem 2.5(b) (counting_mod4_dam_supplement.pdf). The companion Lean 4 formalization, SAT CNF/DRAT certificate, and verification scripts are archived at https://doi.org/10.5281/zenodo.24358625.
Authors
- Shuheng Ma
Publication Details
- Journal
- Zenodo (CERN European Organization for Nuclear Research)
- Published
- 2026-11-24
- DOI
- https://doi.org/10.5281/zenodo.24514178
- Primary Topic
- Complexity and Algorithms in Graphs
- Type
- preprint