A matching upper bound for parity with shared gates #
Cut the n inputs into k + 1 blocks of m = ⌈n / (k + 1)⌉ consecutive bits
(SharedProgram.blockLength). Share the parity of the first block and then, for each of the
next k - 1 blocks, the exclusive or of the last shared value with the block's parity, and
output the exclusive or of the last shared value with the parity of the last block
(SharedProgram.parityProgram, built from SharedProgram.xorChain). This program has k
shared gates and computes parity (SharedProgram.parityProgram_computes).
A balanced formula for the parity of m consecutive bits (Formula.parityRange) has at most
2 m² gates (Formula.gates_parityRange_le), and each step z ⊕ φ = (z ∧ ¬φ) ∨ (¬z ∧ φ)
reads φ and its De Morgan dual, so (k + 1) · gates ≤ 4 (n + k)² + 3 k (k + 1)
(SharedProgram.mul_gates_parityProgram_le), which is at most 19 n² when k < n
(SharedProgram.exists_parity_mul_gates_le_of_lt). Together with the lower bound
n² ≤ (k + 1) · (gates + k + 1) of SharedProgram.parity_sq_le_gates, the minimum number of
gates of a program with k shared gates computing parity is Θ(n² / (k + 1)) whenever
2 (k + 1)² ≤ n².
A balanced formula for the parity of the inputs with index in [a, a + m): split the range
in half and combine the halves with Formula.xor. Indices outside Fin n are skipped.
Equations
- Algebraic.KW.Formula.parityRange x✝ 0 = Algebraic.KW.Formula.const false
- Algebraic.KW.Formula.parityRange x✝ 1 = if h : x✝ < n then Algebraic.KW.Formula.lit ⟨x✝, h⟩ true else Algebraic.KW.Formula.const false
- Algebraic.KW.Formula.parityRange x✝ m.succ.succ = (Algebraic.KW.Formula.parityRange x✝ ((m + 2) / 2)).xor (Algebraic.KW.Formula.parityRange (x✝ + (m + 2) / 2) (m + 2 - (m + 2) / 2))
Instances For
The balanced parity formula on m bits has at most 2 m² gates.