Documentation

Complexitylib.Algebraic.LowerBound.KarchmerWigderson.Sharing.UpperBound

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².

@[simp]
theorem Algebraic.KW.Formula.gates_xor {n : ℕ} (L R : Formula n) :
(L.xor R).gates = 2 * (L.gates + R.gates) + 3
theorem Algebraic.KW.Formula.xor_eq_add (a b : Bool) :
(a ^^ b) = a + b

On Bool, exclusive or is the addition used by parity.

@[irreducible]

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
Instances For
    theorem Algebraic.KW.Formula.eval_parityRange {n : ℕ} (x : Fin n → Bool) (a m : ℕ) :
    (parityRange a m).eval x = ∑ i : Fin n, if a ≤ ↑i ∧ ↑i < a + m then x i else 0

    The balanced parity formula on m bits has at most 2 m² gates.

    The program that shares acc, then shares in turn the exclusive or z ⊕ ψ i of the last shared value z with each ψ i but the last, and outputs z ⊕ ψ (r - 1). It has r shared gates and computes acc ⊕ ψ 0 ⊕ ⋯ ⊕ ψ (r - 1).

    Equations
    Instances For
      theorem Algebraic.KW.SharedProgram.eval_xorChain {N r : ℕ} (acc : Formula N) (ψ : Fin r → Formula N) (x : Fin N → Bool) :
      (xorChain acc ψ).eval x = acc.eval x + ∑ i : Fin r, (ψ i).eval x
      theorem Algebraic.KW.SharedProgram.gates_xorChain {N r : ℕ} (acc : Formula N) (ψ : Fin r → Formula N) :
      (xorChain acc ψ).gates = acc.gates + ∑ i : Fin r, (2 * (ψ i).gates + 3)

      The block length ⌈n / (k + 1)⌉: k + 1 blocks of this length cover n inputs.

      Equations
      Instances For

        Parity with k shared gates: cut the inputs into k + 1 blocks of blockLength n k consecutive bits and chain the block parities with xorChain.

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          theorem Algebraic.KW.SharedProgram.mul_gates_parityProgram_le (n k : ℕ) :
          (k + 1) * (parityProgram n k).gates ≤ 4 * (n + k) ^ 2 + 3 * k * (k + 1)

          A matching upper bound. For all n and k some program with k shared gates computes the parity of n bits with (k + 1) · gates ≤ 4 (n + k)² + 3 k (k + 1).

          A matching upper bound, for k < n. Some program with k shared gates computes the parity of n bits with at most 19 n² / (k + 1) gates.