Documentation

Complexitylib.Algebraic.LowerBound.KarchmerWigderson.Khrapchenko

Khrapchenko's bound #

For sets A of inputs where a formula is 1 and B of inputs where it is 0, let edges A B be the pairs in A × B at Hamming distance one. Khrapchenko's theorem says that every De Morgan formula separating A from B has at least |edges A B|² / (|A| · |B|) leaves (Formula.sq_card_edges_le, stated without division). A literal leaf can only separate along its own coordinate, so its edges form a partial matching, and a gate splits one side of the rectangle, where the Cauchy–Schwarz inequality makes the measure subadditive.

If every input of a nonempty A has at least s₁ neighbours in a nonempty B and every input of B has at least s₀ neighbours in A, every formula separating them has at least s₀ · s₁ leaves (Formula.mul_le_leaves_of_neighbours); taking the one-inputs and zero-inputs of f gives the bound for sensitive functions (leaves_ge_of_sensitive). Parity is sensitive to every coordinate everywhere, so every De Morgan formula for parity on n ≥ 1 bits has at least n² leaves (parity_sq_le_leaves). The inputs of weight k and k - 1 show that the threshold function "at least k ones" needs k · (n + 1 - k) leaves for 1 ≤ k ≤ n (threshold_mul_le_leaves), so strict majority needs ((n + 1) / 2)² leaves for odd n (majority_mul_le_leaves).

These corollaries use only the rectangle bound |edges A B|² ≤ M · |A| · |B| for sets A of one-inputs and B of zero-inputs of f (KhrapchenkoBound f M). They are proved for every such M (KhrapchenkoBound.mul_le_of_sensitive, KhrapchenkoBound.parity_sq_le, KhrapchenkoBound.threshold_mul_le, KhrapchenkoBound.majority_mul_le) and specialized to formulas, where M is the number of leaves (Formula.khrapchenkoBound), so other models that satisfy the rectangle bound inherit them.

Splitting the inputs in half gives formulas with exactly 4 ^ k leaves for parity on 2 ^ k bits, so formulaSize parity = n² when n is a power of two (formulaSize_parity_two_pow).

The Khrapchenko measure #

def Algebraic.KW.diff {n : ℕ} (x y : Fin n → Bool) :

The coordinates where two inputs differ.

Equations
Instances For
    noncomputable def Algebraic.KW.edges {n : ℕ} (A B : Finset (Fin n → Bool)) :
    Finset ((Fin n → Bool) × (Fin n → Bool))

    Pairs from A × B at Hamming distance one.

    Equations
    Instances For
      def Algebraic.KW.flip {n : ℕ} (x : Fin n → Bool) (i : Fin n) :
      Fin n → Bool

      The input x with coordinate i flipped.

      Equations
      Instances For
        theorem Algebraic.KW.diff_flip {n : ℕ} (x : Fin n → Bool) (i : Fin n) :
        diff x (flip x i) = {i}
        theorem Algebraic.KW.eq_flip_of_diff {n : ℕ} {x y : Fin n → Bool} {i : Fin n} (hcard : (diff x y).card = 1) (hi : x i ≠ y i) :
        y = flip x i

        An input at distance one from x whose difference contains i is x flipped at i.

        def Algebraic.KW.Formula.Separates {n : ℕ} (F : Formula n) (A B : Finset (Fin n → Bool)) :

        A formula separates A from B when it is 1 on A and 0 on B.

        Equations
        Instances For
          theorem Algebraic.KW.sq_add_le_of_sq_le {r₁ r₂ L₁ L₂ a b₁ b₂ : ℕ} (h₁ : r₁ ^ 2 ≤ L₁ * a * b₁) (h₂ : r₂ ^ 2 ≤ L₂ * a * b₂) :
          (r₁ + r₂) ^ 2 ≤ (L₁ + L₂) * a * (b₁ + b₂)

          The arithmetic heart of Khrapchenko's bound: the measure r² / (a · b) is subadditive when one side of the rectangle is split.

          theorem Algebraic.KW.card_edges_split_right {n : ℕ} (A B : Finset (Fin n → Bool)) (p : (Fin n → Bool) → Prop) [DecidablePred p] :
          (edges A B).card = (edges A (Finset.filter p B)).card + (edges A ({y ∈ B | ¬p y})).card

          Splitting the zero side of a rectangle splits its edges.

          theorem Algebraic.KW.card_edges_split_left {n : ℕ} (A B : Finset (Fin n → Bool)) (p : (Fin n → Bool) → Prop) [DecidablePred p] :
          (edges A B).card = (edges (Finset.filter p A) B).card + (edges ({x ∈ A | ¬p x}) B).card

          Splitting the one side of a rectangle splits its edges.

          theorem Algebraic.KW.card_edges_le_left_of_lit {n : ℕ} {i : Fin n} {b : Bool} {A B : Finset (Fin n → Bool)} (h : (Formula.lit i b).Separates A B) :
          (edges A B).card ≤ A.card

          A literal separating A from B has at most |A| edges: each one-input has only one candidate partner, obtained by flipping the literal's coordinate.

          theorem Algebraic.KW.card_edges_le_right_of_lit {n : ℕ} {i : Fin n} {b : Bool} {A B : Finset (Fin n → Bool)} (h : (Formula.lit i b).Separates A B) :
          (edges A B).card ≤ B.card

          A literal separating A from B has at most |B| edges.

          theorem Algebraic.KW.Formula.sq_card_edges_le {n : ℕ} (F : Formula n) (A B : Finset (Fin n → Bool)) :
          F.Separates A B → (edges A B).card ^ 2 ≤ F.leaves * A.card * B.card

          Khrapchenko's theorem. If a De Morgan formula F is 1 on A and 0 on B, then |edges A B|² ≤ leaves F · |A| · |B|.

          theorem Algebraic.KW.Formula.sq_card_edges_le_of_computes {n : ℕ} {F : Formula n} {f : Cslib.BooleanFunction n} (hF : F.Computes f) :
          (edges {x : Fin n → Bool | f x = true} {y : Fin n → Bool | f y = false}).card ^ 2 ≤ F.leaves * {x : Cslib.BitString n | f x = true}.card * {y : Cslib.BitString n | f y = false}.card

          Khrapchenko's theorem for a formula computing f, on the full rectangle of one-inputs and zero-inputs.

          M bounds the Khrapchenko measure of f: for every set A of one-inputs and every set B of zero-inputs of f, |edges A B|² ≤ M · |A| · |B|. A formula computing f gives this bound with M its number of leaves (Formula.khrapchenkoBound); the corollaries below depend only on this bound, not on the model of computation.

          Equations
          Instances For

            Khrapchenko's theorem as a bound on the measure of the computed function.

            Neighbour counts #

            def Algebraic.KW.neighbours {n : ℕ} (S : Finset (Fin n → Bool)) (x : Fin n → Bool) :

            The coordinates at which flipping x lands in S.

            Equations
            Instances For
              theorem Algebraic.KW.sum_card_neighbours_le_card_edges {n : ℕ} (A B : Finset (Fin n → Bool)) :
              ∑ x ∈ A, (neighbours B x).card ≤ (edges A B).card

              Each input of A contributes its neighbours in B as edges.

              theorem Algebraic.KW.diff_comm {n : ℕ} (x y : Fin n → Bool) :
              diff x y = diff y x
              theorem Algebraic.KW.card_edges_comm {n : ℕ} (A B : Finset (Fin n → Bool)) :
              (edges B A).card = (edges A B).card

              The edge count is symmetric in the two sides.

              theorem Algebraic.KW.mul_le_of_neighbours {n : ℕ} {A B : Finset (Fin n → Bool)} {s₀ s₁ M : ℕ} (hE : (edges A B).card ^ 2 ≤ M * A.card * B.card) (hA : A.Nonempty) (hB : B.Nonempty) (h₁ : ∀ x ∈ A, s₁ ≤ (neighbours B x).card) (h₀ : ∀ y ∈ B, s₀ ≤ (neighbours A y).card) :
              s₀ * s₁ ≤ M

              Neighbour counts against a measure bound. If |edges A B|² ≤ M · |A| · |B| for nonempty A and B, every input of A has at least s₁ neighbours in B, and every input of B has at least s₀ neighbours in A, then s₀ · s₁ ≤ M.

              theorem Algebraic.KW.Formula.mul_le_leaves_of_neighbours {n : ℕ} {F : Formula n} {A B : Finset (Fin n → Bool)} {s₀ s₁ : ℕ} (hF : F.Separates A B) (hA : A.Nonempty) (hB : B.Nonempty) (h₁ : ∀ x ∈ A, s₁ ≤ (neighbours B x).card) (h₀ : ∀ y ∈ B, s₀ ≤ (neighbours A y).card) :
              s₀ * s₁ ≤ F.leaves

              Khrapchenko's bound from neighbour counts. If a formula separates nonempty A from nonempty B, every input of A has at least s₁ neighbours in B, and every input of B has at least s₀ neighbours in A, the formula has at least s₀ · s₁ leaves.

              Sensitive functions #

              The coordinates of x at which flipping changes f.

              Equations
              Instances For
                theorem Algebraic.KW.KhrapchenkoBound.mul_le_of_sensitive {n : ℕ} {f : Cslib.BooleanFunction n} {s₀ s₁ M : ℕ} (hM : KhrapchenkoBound f M) (hone : ∃ (x : Cslib.BitString n), f x = true) (hzero : ∃ (y : Cslib.BitString n), f y = false) (h₁ : ∀ (x : Cslib.BitString n), f x = true → s₁ ≤ (sensitiveCoordinates f x).card) (h₀ : ∀ (y : Cslib.BitString n), f y = false → s₀ ≤ (sensitiveCoordinates f y).card) :
                s₀ * s₁ ≤ M

                Sensitivity against a measure bound. If every one-input of f is sensitive on at least s₁ coordinates, every zero-input on at least s₀, and f takes both values, then every bound M on the Khrapchenko measure of f satisfies s₀ · s₁ ≤ M.

                theorem Algebraic.KW.leaves_ge_of_sensitive {n : ℕ} {f : Cslib.BooleanFunction n} {s₀ s₁ : ℕ} (hone : ∃ (x : Cslib.BitString n), f x = true) (hzero : ∃ (y : Cslib.BitString n), f y = false) (h₁ : ∀ (x : Cslib.BitString n), f x = true → s₁ ≤ (sensitiveCoordinates f x).card) (h₀ : ∀ (y : Cslib.BitString n), f y = false → s₀ ≤ (sensitiveCoordinates f y).card) {F : Formula n} (hF : F.Computes f) :
                s₀ * s₁ ≤ F.leaves

                Khrapchenko's bound for sensitive functions. If every one-input of f is sensitive on at least s₁ coordinates, every zero-input on at least s₀, and f takes both values, every De Morgan formula for f has at least s₀ · s₁ leaves.

                Parity #

                Parity against a measure bound. Every bound on the Khrapchenko measure of the parity of n ≥ 1 bits is at least n².

                Khrapchenko's bound for parity. Every De Morgan formula computing the parity of n ≥ 1 bits has at least n² leaves.

                Threshold functions #

                def Algebraic.KW.weight {n : ℕ} (x : Fin n → Bool) :

                The number of ones in an input.

                Equations
                Instances For

                  The threshold function: at least k of the inputs are one.

                  Equations
                  Instances For

                    Strict majority: more than half of the inputs are one (ties are false).

                    Equations
                    Instances For
                      theorem Algebraic.KW.weight_flip_of_true {n : ℕ} {x : Fin n → Bool} {i : Fin n} (hi : x i = true) :
                      weight (flip x i) + 1 = weight x
                      theorem Algebraic.KW.weight_flip_of_false {n : ℕ} {x : Fin n → Bool} {i : Fin n} (hi : x i = false) :
                      weight (flip x i) = weight x + 1
                      def Algebraic.KW.prefixOnes {n : ℕ} (k : ℕ) :
                      Fin n → Bool

                      An input whose first k coordinates are one and the rest zero.

                      Equations
                      Instances For
                        theorem Algebraic.KW.KhrapchenkoBound.threshold_mul_le {n k M : ℕ} (hk : 1 ≤ k) (hkn : k ≤ n) (hM : KhrapchenkoBound (threshold k) M) :
                        (n + 1 - k) * k ≤ M

                        Threshold functions against a measure bound. For 1 ≤ k ≤ n, every bound on the Khrapchenko measure of "at least k of n inputs are one" is at least k · (n + 1 - k): the inputs of weight k and k - 1 form the rectangle.

                        theorem Algebraic.KW.threshold_mul_le_leaves {n k : ℕ} (hk : 1 ≤ k) (hkn : k ≤ n) {F : Formula n} (hF : F.Computes (threshold k)) :
                        (n + 1 - k) * k ≤ F.leaves

                        Khrapchenko's bound for threshold functions. For 1 ≤ k ≤ n, every De Morgan formula computing "at least k of n inputs are one" has at least k · (n + 1 - k) leaves: the inputs of weight k and k - 1 form the rectangle.

                        theorem Algebraic.KW.KhrapchenkoBound.majority_mul_le {n M : ℕ} (hn : 1 ≤ n) (hM : KhrapchenkoBound majority M) :
                        (n - n / 2) * (n / 2 + 1) ≤ M

                        Majority against a measure bound. For n ≥ 1, every bound on the Khrapchenko measure of strict majority of n inputs is at least (n - ⌊n/2⌋) · (⌊n/2⌋ + 1).

                        theorem Algebraic.KW.majority_mul_le_leaves {n : ℕ} (hn : 1 ≤ n) {F : Formula n} (hF : F.Computes majority) :
                        (n - n / 2) * (n / 2 + 1) ≤ F.leaves

                        Khrapchenko's bound for majority. Every De Morgan formula computing strict majority of n ≥ 1 inputs has at least (n - ⌊n/2⌋) · (⌊n/2⌋ + 1) leaves, which is ((n + 1)/2)² for odd n.

                        A matching upper bound at powers of two #

                        The formula (L ∧ ¬R) ∨ (¬L ∧ R) for the exclusive or of two formulas.

                        Equations
                        Instances For
                          @[simp]
                          theorem Algebraic.KW.Formula.eval_xor {n : ℕ} (L R : Formula n) (x : Fin n → Bool) :
                          (L.xor R).eval x = (L.eval x ^^ R.eval x)
                          @[simp]
                          theorem Algebraic.KW.Formula.leaves_xor {n : ℕ} (L R : Formula n) :
                          (L.xor R).leaves = 2 * (L.leaves + R.leaves)

                          Parity on 2 ^ k bits as a balanced formula with 4 ^ k leaves.

                          Equations
                          Instances For

                            Formula size of parity. At n = 2 ^ k bits the minimum number of leaves of a De Morgan formula computing parity is exactly n².