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
      @[instance_reducible]
      Equations
      • One or more equations did not get rendered due to their size.
      @[instance_reducible]
      Equations
      • One or more equations did not get rendered due to their size.
      @[instance_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) :
      (∑ i ∈ s, g i) x = ∑ i ∈ s, 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 𝔽₂ⁿ.

        @[instance_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
        @[instance_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 n → Prop) :

                                      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 n → Prop) :

                                          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 n → Cube n → Prop) :

                                              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 functions are ε-close if dist(f, g) ≤ ε, where dist is the fraction of inputs on which they differ (Definition 1.29, stated there for Boolean-valued functions; no Boolean-valuedness is required here).

                                                                              Equations
                                                                              Instances For

                                                                                A function is ε-close to a property P if there exists g satisfying P with dist(f, g) ≤ ε (Definition 1.29, stated there for Boolean-valued functions; no Boolean-valuedness is required here).

                                                                                Equations
                                                                                Instances For

                                                                                  The BLR acceptance probability: Pr_{x,y}[f(x)·f(y) = f(x+y)]. For Boolean-valued f it equals 1/2 + 1/2 · ∑_S 𝓕 f S ^ 3 (blrAcceptProb_eq); without that hypothesis the identity can fail (for f = 0 the probability is 1).

                                                                                  Equations
                                                                                  Instances For