Yablonskii's formulas for parity #
Write n = 2 ^ k + r with r ≤ 2 ^ k. Splitting the bits into blocks of 2 ^ (k - 1) + ⌊r / 2⌋
and 2 ^ (k - 1) + ⌈r / 2⌉ bits and combining formulas for their parities by
x ⊕ y = (x ∧ ¬y) ∨ (¬x ∧ y) gives a De Morgan formula (see
Complexity/Computability/Circuit/Boolean/Formula.lean) for
the parity of n bits of leaf size at most 2 ^ k (2 ^ k + 3 r) [Yab54], [Juk12]
(exists_formula_parity_two_pow_add). The bound is exactly additive along the recursion:
2 m (2 m + 3 r) = 2 · m (m + 3 s) + 2 · m (m + 3 t) for m = 2 ^ (k - 1), s = ⌊r / 2⌋ and
t = ⌈r / 2⌉, and an exclusive or doubles the leaves of both arguments.
As 9 (2 ^ k + r) ^ 2 - 8 · 2 ^ k (2 ^ k + 3 r) = (2 ^ k - 3 r) ^ 2, the parity of any number
n of bits has a formula of leaf size at most 9 n ^ 2 / 8
(exists_formula_parity_eight_mul_leafSize_le), within a factor 9 / 8 of Khrapchenko's lower
bound n ^ 2 (sq_le_leafSize_of_computes_parity). For r = 0 the construction is the balanced
formula parityFormula, whose leaf size n ^ 2 is optimal.
The formulas are balanced: they have at most 2 ⌈log₂ n⌉ AND and OR gates on every path
(depthWith_binaryCost_yablonskiiFormula), so the formula depth of parity, with negations free,
is at most 2 ⌈log₂ n⌉ (formulaDepth_parity_le_two_mul_clog).
Main definitions #
Cslib.Circuits.Boolean.yablonskiiFormula: Yablonskii's formula for the parity of2 ^ k + rconsecutive bits.
Main results #
Cslib.Circuits.Boolean.exists_formula_parity_two_pow_add: the parity of2 ^ k + rbits,r ≤ 2 ^ k, has a De Morgan formula of leaf size at most2 ^ k (2 ^ k + 3 r).Cslib.Circuits.Boolean.exists_formula_parity_eight_mul_leafSize_le: the parity ofnbits has a De Morgan formula of leaf size at most9 n ^ 2 / 8.Cslib.Circuits.Boolean.formulaDepth_parity_le_two_mul_clog: the formula depth of the parity ofnbits is at most2 ⌈log₂ n⌉.
References #
Yablonskii's formula for the parity of the 2 ^ k + r bits from o on, where r ≤ 2 ^ k:
the exclusive or of such formulas for the first 2 ^ (k - 1) + ⌊r / 2⌋ and the remaining
2 ^ (k - 1) + ⌈r / 2⌉ bits. For r = 0 it is parityFormula k o (yablonskiiFormula_zero).
Instances For
Yablonskii's formula on all 2 ^ k + r bits computes their parity.
The constant formula false computes the parity of no bits.
Yablonskii's bound. The parity of 2 ^ k + r bits, r ≤ 2 ^ k, has a De Morgan formula of
leaf size at most 2 ^ k (2 ^ k + 3 r).
The formula depth of the parity of n bits, with negations free, is at most 2 ⌈log₂ n⌉.