Documentation

Complexitylib.Algebraic.LowerBound.KarchmerWigderson.Basic

Karchmer–Wigderson games #

A De Morgan formula has literal and constant leaves and binary AND and OR gates. The Karchmer–Wigderson game of f gives Alice an input x with f x = 1 and Bob an input y with f y = 0; they must agree on a coordinate where x and y differ. A deterministic protocol is a binary tree whose internal nodes are owned by one player and branch on that player's input, and whose leaves name a coordinate.

The Karchmer–Wigderson theorem says that formulas and protocols are the same trees: an OR gate is a node where Alice says which side of the disjunction her input satisfies, an AND gate is a node where Bob says which side his input violates, and a literal leaf names its coordinate (Formula.toProtocol). Conversely a protocol induces, at every node, a rectangle of inputs still consistent with the transcript, and the formula built with OR at Alice's nodes and AND at Bob's nodes is 1 on Alice's side and 0 on Bob's side of every rectangle (Protocol.toFormula). Depth and leaf count are preserved in both directions, so for n ≥ 1 the minimum formula depth of f equals the minimum protocol depth of its game (formulaDepth_eq_protocolDepth), and likewise for leaf size (formulaSize_eq_protocolSize). Both need [NeZero n]: with no coordinates there is no protocol at all (a leaf must name a coordinate), so the protocol measures are ⊤, while a constant formula has depth 0.

De Morgan formulas #

inductive Algebraic.KW.Formula (n : ℕ) :

A De Morgan formula: literal leaves, constants, binary AND and OR.

Instances For
    def Algebraic.KW.Formula.eval {n : ℕ} :
    Formula n → (Fin n → Bool) → Bool

    Evaluate a formula.

    Equations
    Instances For
      @[simp]
      theorem Algebraic.KW.Formula.eval_lit {n : ℕ} (i : Fin n) (b : Bool) (x : Fin n → Bool) :
      (lit i b).eval x = (x i == b)
      @[simp]
      theorem Algebraic.KW.Formula.eval_const {n : ℕ} (b : Bool) (x : Fin n → Bool) :
      (const b).eval x = b
      @[simp]
      theorem Algebraic.KW.Formula.eval_and {n : ℕ} (l r : Formula n) (x : Fin n → Bool) :
      (l.and r).eval x = (l.eval x && r.eval x)
      @[simp]
      theorem Algebraic.KW.Formula.eval_or {n : ℕ} (l r : Formula n) (x : Fin n → Bool) :
      (l.or r).eval x = (l.eval x || r.eval x)

      The depth: the longest root-to-leaf path.

      Equations
      Instances For

        The number of leaves, counting literals and constants, so every formula has at least one leaf. This differs from Algebraic.Binary.Formula.leaves, which counts only variable leaves and gives constants leaf size 0; formulaSize and the KRW statements use this convention.

        Equations
        Instances For

          The De Morgan dual, computing the negation with the same shape.

          Equations
          Instances For
            @[simp]
            theorem Algebraic.KW.Formula.eval_neg {n : ℕ} (F : Formula n) (x : Fin n → Bool) :
            F.neg.eval x = !F.eval x
            @[simp]

            A formula computes f when it agrees with f everywhere.

            Equations
            Instances For

              Protocols #

              inductive Algebraic.KW.Protocol (n : ℕ) :

              A deterministic two-party protocol whose leaves name a coordinate. Each internal node is owned by Alice or Bob and branches on the owner's input.

              Instances For
                def Algebraic.KW.Protocol.run {n : ℕ} :
                Protocol n → (Fin n → Bool) → (Fin n → Bool) → Fin n

                The coordinate output on inputs x for Alice and y for Bob.

                Equations
                Instances For

                  The depth: the longest root-to-leaf path.

                  Equations
                  Instances For

                    The number of leaves.

                    Equations
                    Instances For
                      def Algebraic.KW.Protocol.Solves {n : ℕ} (P : Protocol n) (A B : (Fin n → Bool) → Prop) :

                      The protocol solves the game on the rectangle A × B: on inputs from A for Alice and B for Bob, the output coordinate distinguishes them.

                      Equations
                      Instances For

                        The protocol solves the Karchmer–Wigderson game of f.

                        Equations
                        Instances For

                          From formulas to protocols #

                          The protocol of a formula: Bob resolves conjunctions, Alice resolves disjunctions, literals name their coordinate. A constant leaf, which can only be reached on an empty rectangle, answers the default coordinate i₀.

                          Equations
                          Instances For
                            @[simp]
                            theorem Algebraic.KW.Formula.depth_toProtocol {n : ℕ} (i₀ : Fin n) (F : Formula n) :
                            (toProtocol i₀ F).depth = F.depth
                            @[simp]
                            theorem Algebraic.KW.Formula.leaves_toProtocol {n : ℕ} (i₀ : Fin n) (F : Formula n) :

                            From protocols to formulas #

                            noncomputable def Algebraic.KW.Protocol.toFormula {n : ℕ} :
                            Protocol n → ((Fin n → Bool) → Prop) → ((Fin n → Bool) → Prop) → Formula n

                            The formula of a protocol, relative to the rectangle A × B of inputs reaching the current node: OR at Alice's nodes, AND at Bob's nodes, and at a leaf naming i the literal that is 1 on A and 0 on B.

                            Equations
                            Instances For
                              theorem Algebraic.KW.Protocol.toFormula_spec {n : ℕ} (P : Protocol n) (A B : (Fin n → Bool) → Prop) :
                              P.Solves A B → (∀ (x : Fin n → Bool), A x → (P.toFormula A B).eval x = true) ∧ ∀ (y : Fin n → Bool), B y → (P.toFormula A B).eval y = false

                              The formula of a protocol solving the game on A × B is 1 on A and 0 on B.

                              @[simp]
                              theorem Algebraic.KW.Protocol.depth_toFormula {n : ℕ} (P : Protocol n) (A B : (Fin n → Bool) → Prop) :
                              @[simp]
                              theorem Algebraic.KW.Protocol.leaves_toFormula {n : ℕ} (P : Protocol n) (A B : (Fin n → Bool) → Prop) :

                              A protocol for the game of f yields a formula for f of the same shape.

                              The Karchmer–Wigderson theorem #

                              theorem Algebraic.KW.Formula.exists_protocol_of_computes {n : ℕ} (i₀ : Fin n) {F : Formula n} {f : Cslib.BooleanFunction n} (h : F.Computes f) :
                              ∃ (P : Protocol n), P.SolvesKW f ∧ P.depth = F.depth ∧ P.leaves = F.leaves

                              A formula for f yields a protocol for its game of the same shape.

                              The minimum depth of a formula computing f.

                              Equations
                              Instances For
                                noncomputable def Algebraic.KW.formulaSize {n : ℕ} (f : Cslib.BooleanFunction n) :

                                The minimum number of leaves of a formula computing f.

                                Equations
                                Instances For

                                  The minimum depth of a protocol for the game of f.

                                  Equations
                                  Instances For

                                    The minimum number of leaves of a protocol for the game of f.

                                    Equations
                                    Instances For

                                      Karchmer–Wigderson, depth. For n ≥ 1, the minimum formula depth of f is the minimum depth of a protocol for its game.

                                      Karchmer–Wigderson, size. For n ≥ 1, the minimum leaf size of a formula for f is the minimum number of leaves of a protocol for its game.