Documentation

Complexitylib.BooleanAnalysis.FourierExpansion.Defs

Chapter 1: Boolean functions and the Fourier expansion — Definitions #

This file contains the core definitions for Fourier analysis of Boolean functions following Chapter 1 of "Analysis of Boolean Functions" by Ryan O'Donnell.

We work with the Hamming cube modeled as Fin n → ZMod 2, with the encoding χ : ZMod 2 → ℝ sending 0 ↦ 1 and 1 ↦ -1. This corresponds to the book's convention of representing the cube as {-1, 1}^n via the map b ↦ (-1)^b.

The space BooleanFunction n of real-valued functions on the Boolean cube carries the uniform-measure L² inner product ⟪f, g⟫ = 𝔼[f·g] = (1/2ⁿ) · ∑_x f(x)·g(x) (Definition 1.3), realized as a Mathlib InnerProductSpace. The def (rather than abbrev) for BooleanFunction blocks typeclass resolution from seeing through to Cube n → ℝ, avoiding a norm diamond with Mathlib's Pi-type sup norm.

Notation #

Within the BooleanAnalysis namespace, we provide notation that mirrors the book's conventions:

Basic types #

@[reducible, inline]

The Hamming cube 𝔽₂ⁿ is Fin n → ZMod 2.

Equations
Instances For

    BooleanFunction n is the space of real-valued functions on the Boolean cube 𝔽₂ⁿ, equipped with the uniform-measure L² inner product ⟪f, g⟫ = 𝔼[f·g] (Definition 1.3 in O'Donnell).

    The def (rather than abbrev) blocks typeclass resolution from seeing through to Cube n → ℝ, preventing a norm diamond with Mathlib's Pi-type sup norm while still allowing the kernel to see through for type checking.

    Equations
    Instances For
      @[implicit_reducible]
      Equations
      • One or more equations did not get rendered due to their size.
      @[implicit_reducible]
      Equations
      • One or more equations did not get rendered due to their size.
      @[implicit_reducible]
      Equations
      • One or more equations did not get rendered due to their size.
      theorem Complexity.BooleanAnalysis.BooleanFunction.ext {n : } {f g : BooleanFunction n} (h : ∀ (x : Cube n), f x = g x) :
      f = g
      theorem Complexity.BooleanAnalysis.BooleanFunction.ext_iff {n : } {f g : BooleanFunction n} :
      f = g ∀ (x : Cube n), f x = g x
      @[simp]
      theorem Complexity.BooleanAnalysis.BooleanFunction.add_apply {n : } (f g : BooleanFunction n) (x : Cube n) :
      (f + g) x = f x + g x
      @[simp]
      theorem Complexity.BooleanAnalysis.BooleanFunction.sub_apply {n : } (f g : BooleanFunction n) (x : Cube n) :
      (f - g) x = f x - g x
      @[simp]
      theorem Complexity.BooleanAnalysis.BooleanFunction.smul_apply {n : } (r : ) (f : BooleanFunction n) (x : Cube n) :
      (r f) x = r * f x
      @[simp]
      theorem Complexity.BooleanAnalysis.BooleanFunction.mul_apply {n : } (f g : BooleanFunction n) (x : Cube n) :
      (f * g) x = f x * g x
      @[simp]
      theorem Complexity.BooleanAnalysis.BooleanFunction.sum_apply {n : } {ι : Type u_1} (s : Finset ι) (g : ιBooleanFunction n) (x : Cube n) :
      (∑ is, g i) x = is, g i x

      Evaluate a Finset sum of BooleanFunctions pointwise.

      Extract the underlying function from a BooleanFunction.

      Equations
      Instances For

        Inner product space structure #

        The inner product on BooleanFunction n is the uniform-measure inner product ⟪f, g⟫ = (1/2ⁿ) · ∑_x f(x)·g(x), matching O'Donnell's Definition 1.3. This is the expectation 𝔼[f·g] under the uniform distribution on 𝔽₂ⁿ.

        @[implicit_reducible]

        The uniform-measure inner product: ⟪f, g⟫ = (1/2ⁿ) · ∑_x f(x)·g(x).

        Equations
        • One or more equations did not get rendered due to their size.
        theorem Complexity.BooleanAnalysis.BooleanFunction.inner_def {n : } (f g : BooleanFunction n) :
        inner f g = 1 / 2 ^ n * x : Cube n, f x * g x
        @[implicit_reducible]
        Equations
        • One or more equations did not get rendered due to their size.

        Notation #

        The book uses ⟪f, g⟫ for the inner product (Definition 1.3) and ‖f‖₂ for the L² norm (§1.3, page 24). These map to Mathlib's inner and norm on BooleanFunction n.

        ⟪f, g⟫ — the inner product 𝔼[f·g] on BooleanFunction n (Definition 1.3).

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For

          ‖f‖₂ — the L² norm √⟪f, f⟫ on BooleanFunction n (§1.3, page 24).

          This equals Mathlib's ‖f‖ since the InnerProductSpace instance makes norm the L² norm. We use the subscript to match the book's convention and to distinguish from other norms that may appear in later chapters.

          Equations
          • One or more equations did not get rendered due to their size.
          Instances For
            theorem Complexity.BooleanAnalysis.inner_def {n : } (f g : BooleanFunction n) :
            inner f g = 1 / 2 ^ n * x : Cube n, f x * g x

            ⟪f, g⟫ = (1/2ⁿ) · ∑_x f(x)·g(x) — unfold the inner product to the explicit sum form.

            §1.2 The encoding and parity functions #

            A function f : 𝔽₂ⁿ → ℝ is Boolean-valued if its range is {-1, 1}. In the ±1 encoding, this means f(x) = ±1 for all x.

            Equations
            Instances For

              The encoding χ : ZMod 2 → ℝ defined by χ(b) = (-1)^b. Concretely, χ(0) = 1 and χ(1) = -1. (Book §1.2)

              Equations
              Instances For

                The parity function χ S : 𝔽₂ⁿ → ℝ for S ⊆ [n], defined by (χ S)(x) = ∏_{i ∈ S} χ(xᵢ) = (-1)^(∑_{i ∈ S} xᵢ). (Definition 1.2)

                Equations
                Instances For

                  χ S — the parity function on the coordinate set S.

                  Equations
                  • One or more equations did not get rendered due to their size.
                  Instances For

                    §1.3–1.4 Expectation, Fourier coefficients #

                    noncomputable def Complexity.BooleanAnalysis.expect {n : } (f : BooleanFunction n) :

                    The uniform expectation 𝔼[f] = 2⁻ⁿ · ∑_x f(x).

                    Equations
                    Instances For

                      𝔼[f] — the uniform expectation of f over the Hamming cube.

                      Equations
                      • One or more equations did not get rendered due to their size.
                      Instances For
                        noncomputable def Complexity.BooleanAnalysis.fourierCoeff {n : } (f : BooleanFunction n) (S : Finset (Fin n)) :

                        The Fourier coefficient 𝓕 f S = ⟪f, χ S⟫. (Proposition 1.8 / our definition)

                        Equations
                        Instances For

                          𝓕 f S — the Fourier coefficient of f on the coordinate set S.

                          Equations
                          Instances For

                            Bridge lemmas #

                            theorem Complexity.BooleanAnalysis.expect_unfold {n : } (f : BooleanFunction n) :
                            expect f = 1 / 2 ^ n * x : Cube n, f x

                            Unfold 𝔼[f] to the explicit sum form 1/2^n · ∑_x f(x).

                            theorem Complexity.BooleanAnalysis.inner_eq_expect {n : } (f g : BooleanFunction n) :
                            inner f g = expect fun (x : Cube n) => f x * g x

                            The inner product equals the expectation of the product. This is the book's Definition 1.3: ⟪f, g⟫ = 𝔼[f·g].

                            §1.4 Mean, variance, covariance #

                            A function f : 𝔽₂ⁿ → ℝ is unbiased (or balanced) if 𝔼[f] = 0. (Definition 1.11)

                            Equations
                            Instances For

                              The variance of f : 𝔽₂ⁿ → ℝ, defined as Var[f] = 𝔼[f²] - 𝔼[f]². (Proposition 1.13)

                              Equations
                              Instances For

                                Var[f] — the variance of f.

                                Equations
                                • One or more equations did not get rendered due to their size.
                                Instances For

                                  The covariance of f, g : 𝔽₂ⁿ → ℝ, defined as Cov[f, g] = 𝔼[f·g] - 𝔼[f]·𝔼[g]. (Proposition 1.16)

                                  Equations
                                  • One or more equations did not get rendered due to their size.
                                  Instances For

                                    Cov[f, g] — the covariance of f and g.

                                    Equations
                                    • One or more equations did not get rendered due to their size.
                                    Instances For
                                      noncomputable def Complexity.BooleanAnalysis.indicator {n : } (P : Cube nProp) :

                                      The 0-1 indicator function of a predicate P on 𝔽₂ⁿ. (𝟙 P)(x) = 1 if P x, else 0.

                                      The book (Definition 1.22) defines 𝟙_A for a set A ⊆ 𝔽₂ⁿ. We generalize to predicates so that probability expressions like Pr_x[P(x)] = 𝔼[𝟙 P] read cleanly without Finset.univ.filter boilerplate. For the set version, use 𝟙 (· ∈ A).

                                      Equations
                                      Instances For

                                        𝟙 P — the 0-1 indicator function of predicate P.

                                        Equations
                                        • One or more equations did not get rendered due to their size.
                                        Instances For
                                          noncomputable def Complexity.BooleanAnalysis.prob {n : } (P : Cube nProp) :

                                          The uniform probability Pr_x[P(x)] = 𝔼[𝟙 P].

                                          Equations
                                          Instances For

                                            Pr[P] — the uniform probability of predicate P.

                                            Equations
                                            • One or more equations did not get rendered due to their size.
                                            Instances For
                                              noncomputable def Complexity.BooleanAnalysis.prob₂ {n : } (P : Cube nCube nProp) :

                                              The joint uniform probability Pr_{x,y}[P(x,y)] = 𝔼_x[𝔼_y[𝟙 (P x)]]. Equivalent to the uniform probability over the product space by Fubini.

                                              Equations
                                              • One or more equations did not get rendered due to their size.
                                              Instances For

                                                Pr₂[P] — the joint uniform probability of P over pairs.

                                                Equations
                                                • One or more equations did not get rendered due to their size.
                                                Instances For

                                                  The relative Hamming distance between functions f and g, dist(f, g) = Pr_x[f(x) ≠ g(x)]. (Definition 1.10)

                                                  Equations
                                                  Instances For

                                                    §1.4 Fourier weight distribution #

                                                    noncomputable def Complexity.BooleanAnalysis.fourierWeight {n : } (f : BooleanFunction n) (S : Finset (Fin n)) :

                                                    The Fourier weight of f on set S, defined as (𝓕 f S)². (Definition 1.17)

                                                    Equations
                                                    Instances For

                                                      The Fourier weight of f at degree k: 𝐖 f k = ∑_{|S|=k} (𝓕 f S)². (Definition 1.19)

                                                      Equations
                                                      Instances For

                                                        𝐖 f k — the Fourier weight of f at degree k.

                                                        Equations
                                                        Instances For

                                                          The degree-k part of f: f^{=k} = ∑_{|S|=k} 𝓕 f S · χ S. (Definition 1.19)

                                                          Equations
                                                          Instances For

                                                            The degree-at-most-k part of f: f^{≤k} = ∑_{|S|≤k} 𝓕 f S · χ S. (Definition 1.19)

                                                            Equations
                                                            Instances For

                                                              The Fourier weight of f at degrees above k: 𝐖^{>k}[f] = ∑_{|S|>k} (𝓕 f S)². (Definition 1.19)

                                                              Equations
                                                              Instances For

                                                                The (real) degree of f : 𝔽₂ⁿ → ℝ: deg(f) = max { |S| : 𝓕 f S ≠ 0 }. (Exercise 1.10, referenced in main text)

                                                                Returns for the zero function (which has no nonzero Fourier coefficients). The book leaves the degree undefined in this case. We use WithBot so that degree comparisons integrate cleanly with Mathlib's order theory.

                                                                Equations
                                                                Instances For

                                                                  §1.5 Probability densities and convolution #

                                                                  A probability density on 𝔽₂ⁿ is a nonneg function with 𝔼[φ] = 1. (Definition 1.20)

                                                                  Instances For

                                                                    The density function associated to a nonempty set A ⊆ 𝔽₂ⁿ: φ_A = (1 / 𝔼[𝟙 A]) · 𝟙 A. (Definition 1.22)

                                                                    Warning: This definition is junk when A = ∅, since it divides by 𝔼[𝟙 ∅] = 0. The book requires A to be nonempty. Theorems using setDensity should include a hypothesis A.Nonempty where needed.

                                                                    Equations
                                                                    • One or more equations did not get rendered due to their size.
                                                                    Instances For

                                                                      The convolution of f, g : 𝔽₂ⁿ → ℝ, defined by (f ⊛ g)(x) = 𝔼_y[f(y)·g(x + y)]. (Definition 1.24)

                                                                      Equations
                                                                      Instances For

                                                                        f ⊛ g — the convolution of f and g.

                                                                        Equations
                                                                        • One or more equations did not get rendered due to their size.
                                                                        Instances For

                                                                          §1.6 Linearity and the BLR test #

                                                                          A function f : 𝔽₂ⁿ → 𝔽₂ (encoded as BooleanFunction n with ±1 values) is linear if it equals some parity function χ S. (Definition 1.28)

                                                                          Equations
                                                                          Instances For

                                                                            A function f : 𝔽₂ⁿ → ℝ is multiplicative if f(x+y) = f(x)·f(y) for all x, y. This generalizes property (1) from Definition 1.28 to real-valued functions; the equivalence with IsLinear requires IsBooleanValued (see isLinear_iff_isMultiplicative).

                                                                            Equations
                                                                            Instances For

                                                                              Two Boolean-valued functions are ε-close if dist(f, g) ≤ ε. (Definition 1.29)

                                                                              Equations
                                                                              Instances For

                                                                                A Boolean-valued function is ε-close to a property P if there exists g satisfying P with dist(f, g) ≤ ε. (Definition 1.29)

                                                                                Equations
                                                                                Instances For

                                                                                  The BLR acceptance probability: Pr_{x,y}[f(x)·f(y) = f(x+y)], which equals 1/2 + 1/2 · ∑_S 𝓕 f S ^ 3.

                                                                                  Equations
                                                                                  Instances For