From d12b2852041b2f566066b243afba23a1224ec657 Mon Sep 17 00:00:00 2001 From: Samuel Schlesinger Date: Sat, 23 May 2026 23:41:35 +0300 Subject: [PATCH] feat(Foundations/Combinatorics/BooleanFunctions): Fourier expansion, Plancherel, and Parseval MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Formalize Chapter 1 of O'Donnell's "Analysis of Boolean Functions" through Plancherel and Parseval. Sets up `HammingCube n = Fin n โ†’ ZMod 2` and the space `BooleanFunction n` of real-valued functions on the cube, carrying the uniform-measure Lยฒ inner product `โŸชf, gโŸซ = ๐”ผ[fยทg]` as an `InnerProductSpace โ„`. `BooleanFunction` is a `def` (not `abbrev`) to keep typeclass resolution from seeing through to the Pi-type sup norm. Defines the parity functions `ฯ‡ S` and Fourier coefficients `๐“• f S = โŸชf, ฯ‡ SโŸซ`, then proves the Fourier expansion theorem (Theorem 1.1, existence and uniqueness) and orthonormality of the parity functions (Theorem 1.5). Plancherel and Parseval follow from packaging the parity functions as an `OrthonormalBasis` and applying Mathlib's `sum_inner_mul_inner`. Ported from the standalone `SamuelSchlesinger/analysis-of-boolean-functions` repo; downstream content (variance, convolution, BLR, density theorems) is left for follow-up. --- Cslib.lean | 1 + .../BooleanFunctions/FourierExpansion.lean | 412 ++++++++++++++++++ references.bib | 9 + 3 files changed, 422 insertions(+) create mode 100644 Cslib/Foundations/Combinatorics/BooleanFunctions/FourierExpansion.lean diff --git a/Cslib.lean b/Cslib.lean index b504973c3..37552fe6d 100644 --- a/Cslib.lean +++ b/Cslib.lean @@ -46,6 +46,7 @@ public import Cslib.Crypto.Protocols.SecretSharing.Defs public import Cslib.Crypto.Protocols.SecretSharing.Scheme public import Cslib.Crypto.Protocols.SecretSharing.Shamir public import Cslib.Crypto.Protocols.SecretSharing.Shamir.Polynomial +public import Cslib.Foundations.Combinatorics.BooleanFunctions.FourierExpansion public import Cslib.Foundations.Combinatorics.InfiniteGraphRamsey public import Cslib.Foundations.Control.Monad.Free public import Cslib.Foundations.Control.Monad.Free.Effects diff --git a/Cslib/Foundations/Combinatorics/BooleanFunctions/FourierExpansion.lean b/Cslib/Foundations/Combinatorics/BooleanFunctions/FourierExpansion.lean new file mode 100644 index 000000000..960f08364 --- /dev/null +++ b/Cslib/Foundations/Combinatorics/BooleanFunctions/FourierExpansion.lean @@ -0,0 +1,412 @@ +/- +Copyright (c) 2026 Samuel Schlesinger. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: Samuel Schlesinger +-/ + +module + +public import Cslib.Init +public import Mathlib.Algebra.BigOperators.Expect +public import Mathlib.Analysis.InnerProductSpace.PiL2 +public import Mathlib.Data.ZMod.Basic + +/-! +# Fourier expansion of Boolean functions + +The cube `Fin n โ†’ ZMod 2` is paired with the `ยฑ1` encoding +`chi : ZMod 2 โ†’ โ„`, `b โ†ฆ (-1)^b`; a Boolean-valued function is one with +range `{-1, +1} โŠ‚ โ„`. + +Real-valued functions on the cube carry the uniform-measure `Lยฒ` inner +product `โŸชf, gโŸซ = ๐”ผ x, f x * g x`. The parity functions +`ฯ‡_S(x) = โˆ_{i โˆˆ S} (-1)^(xแตข)` form an orthonormal basis, and every function +has a unique Fourier expansion `f(x) = โˆ‘_S ๐“• f S ยท ฯ‡_S(x)` with +`๐“• f S = โŸชf, ฯ‡_SโŸซ`. + +This file formalizes Chapter 1 of [ODonnell2014] up to Parseval/Plancherel. + +## Main definitions + +- `HammingCube`: the Hamming cube `Fin n โ†’ ZMod 2`. +- `BooleanFunction`: real-valued functions on the Hamming cube, equipped with + the uniform-measure `Lยฒ` inner product as an `InnerProductSpace โ„`. +- `chi`: the `ยฑ1` encoding `ZMod 2 โ†’ โ„` sending `0 โ†ฆ 1` and `1 โ†ฆ -1`. +- `parityFun`: the parity function `ฯ‡_S : ๐”ฝโ‚‚โฟ โ†’ โ„`, + `(ฯ‡_S)(x) = โˆ_{i โˆˆ S} ฯ‡(xแตข)`. +- `fourierCoeff`: Fourier coefficient `๐“• f S = โŸชf, ฯ‡_SโŸซ`. +- `IsBooleanValued`: the predicate that `f` takes values in `{-1, 1}`. + +## Main results + +- `parityFun_orthonormal_apply`: `โŸชฯ‡_S, ฯ‡_TโŸซ = ฮด_{S,T}` + ([ODonnell2014], Theorem 1.5, orthonormality identity). +- `parityOrthonormalBasis`: the parity functions form an orthonormal basis + ([ODonnell2014], Theorem 1.5, basis form). +- `fourier_expansion`: every `f` equals `โˆ‘_S ๐“• f S ยท ฯ‡_S` pointwise + ([ODonnell2014], Theorem 1.1, existence). +- `fourier_uniqueness`: the Fourier coefficients are unique + ([ODonnell2014], Theorem 1.1, uniqueness). +- `plancherel`: `โŸชf, gโŸซ = โˆ‘_S ๐“• f S ยท ๐“• g S`. +- `parseval`: `โŸชf, fโŸซ = โˆ‘_S (๐“• f S)ยฒ`. + +## References + +* [R. O'Donnell, *Analysis of Boolean Functions*, Chapter 1][ODonnell2014] +-/ + +@[expose] public section + +namespace Cslib.Foundations.Combinatorics.BooleanFunctions + +open Finset +open scoped BigOperators + +variable {n : โ„•} + +/-! ### The Hamming cube and the space of Boolean functions -/ + +/-- The Hamming cube `๐”ฝโ‚‚โฟ`, modelled as `Fin n โ†’ ZMod 2`. -/ +abbrev HammingCube (n : โ„•) := Fin n โ†’ ZMod 2 + +/-- Real-valued functions on the Hamming cube, equipped with the uniform-measure +`Lยฒ` inner product `โŸชf, gโŸซ = ๐”ผ x, f x * g x`. -/ +def BooleanFunction (n : โ„•) := HammingCube n โ†’ โ„ + +namespace BooleanFunction + +noncomputable instance : CommRing (BooleanFunction n) := + inferInstanceAs (CommRing (HammingCube n โ†’ โ„)) +noncomputable instance : Module โ„ (BooleanFunction n) := + inferInstanceAs (Module โ„ (HammingCube n โ†’ โ„)) +noncomputable instance : Algebra โ„ (BooleanFunction n) := + inferInstanceAs (Algebra โ„ (HammingCube n โ†’ โ„)) +instance : Inhabited (BooleanFunction n) := + inferInstanceAs (Inhabited (HammingCube n โ†’ โ„)) + +instance : FunLike (BooleanFunction n) (HammingCube n) โ„ where + coe f := f + coe_injective' _ _ h := h + +@[ext] +theorem ext {f g : BooleanFunction n} (h : โˆ€ x, f x = g x) : f = g := + DFunLike.ext f g h + +@[simp] theorem zero_apply (x : HammingCube n) : (0 : BooleanFunction n) x = 0 := rfl +@[simp] theorem one_apply (x : HammingCube n) : (1 : BooleanFunction n) x = 1 := rfl +@[simp] theorem add_apply (f g : BooleanFunction n) (x : HammingCube n) : + (f + g) x = f x + g x := rfl +@[simp] theorem neg_apply (f : BooleanFunction n) (x : HammingCube n) : (-f) x = -(f x) := rfl +@[simp] theorem sub_apply (f g : BooleanFunction n) (x : HammingCube n) : + (f - g) x = f x - g x := rfl +@[simp] theorem mul_apply (f g : BooleanFunction n) (x : HammingCube n) : + (f * g) x = f x * g x := rfl +@[simp] theorem smul_apply (r : โ„) (f : BooleanFunction n) (x : HammingCube n) : + (r โ€ข f) x = r * f x := rfl + +@[simp] theorem sum_apply {ฮน : Type*} (s : Finset ฮน) (g : ฮน โ†’ BooleanFunction n) + (x : HammingCube n) : (โˆ‘ i โˆˆ s, g i) x = โˆ‘ i โˆˆ s, (g i) x := + Finset.sum_apply x s g + +/-! ### Inner product space structure -/ + +/-- Uniform-measure `Lยฒ` inner-product core on `BooleanFunction n`. -/ +@[reducible] +noncomputable def innerCore : InnerProductSpace.Core โ„ (BooleanFunction n) where + inner f g := (1 / (2 : โ„) ^ n) * โˆ‘ x : HammingCube n, f x * g x + conj_inner_symm f g := by + change (1 / (2 : โ„) ^ n) * โˆ‘ x : HammingCube n, g x * f x = + (1 / (2 : โ„) ^ n) * โˆ‘ x : HammingCube n, f x * g x + congr 1 + exact Finset.sum_congr rfl (fun x _ => mul_comm _ _) + re_inner_nonneg f := by + change 0 โ‰ค (1 / (2 : โ„) ^ n) * โˆ‘ x : HammingCube n, f x * f x + exact mul_nonneg (by positivity) + (Finset.sum_nonneg fun x _ => mul_self_nonneg (f x)) + add_left f g h := by + change (1 / (2 : โ„) ^ n) * โˆ‘ x : HammingCube n, (f + g) x * h x = + (1 / (2 : โ„) ^ n) * โˆ‘ x : HammingCube n, f x * h x + + (1 / (2 : โ„) ^ n) * โˆ‘ x : HammingCube n, g x * h x + simp [add_apply, add_mul, Finset.sum_add_distrib, mul_add] + smul_left f g r := by + change (1 / (2 : โ„) ^ n) * โˆ‘ x : HammingCube n, (r โ€ข f) x * g x = + r * ((1 / (2 : โ„) ^ n) * โˆ‘ x : HammingCube n, f x * g x) + rw [Finset.mul_sum, Finset.mul_sum, Finset.mul_sum] + refine Finset.sum_congr rfl fun x _ => ?_ + simp [smul_apply]; ring + definite f h := by + change (1 / (2 : โ„) ^ n) * โˆ‘ x : HammingCube n, f x * f x = 0 at h + have hsum : โˆ‘ x : HammingCube n, f x * f x = 0 := + (mul_eq_zero.mp h).resolve_left (by positivity) + ext x + simpa [mul_self_eq_zero] using + (Finset.sum_eq_zero_iff_of_nonneg fun x _ => mul_self_nonneg (f x)).mp hsum + x (Finset.mem_univ x) + +noncomputable instance : NormedAddCommGroup (BooleanFunction n) := + innerCore.toNormedAddCommGroup + +noncomputable instance innerProductSpace : InnerProductSpace โ„ (BooleanFunction n) := + InnerProductSpace.ofCore { __ := innerCore } + +theorem inner_def (f g : BooleanFunction n) : + @inner โ„ _ _ f g = (1 / (2 : โ„) ^ n) * โˆ‘ x : HammingCube n, f x * g x := rfl + +end BooleanFunction + +/-! ### Notation -/ + +/-- Inner product on `BooleanFunction n`. -/ +scoped notation "โŸช" f ", " g "โŸซ" => @inner โ„ (BooleanFunction _) _ f g + +/-- `Lยฒ` norm on `BooleanFunction n`. -/ +scoped notation "โ€–" f "โ€–โ‚‚" => @norm (BooleanFunction _) _ f + +/-! ### The `ยฑ1` encoding and parity functions -/ + +/-- A function on the Hamming cube is Boolean-valued if it takes values in +`{-1, 1}` ([ODonnell2014], ยง1.2). -/ +def IsBooleanValued (f : BooleanFunction n) : Prop := + โˆ€ x, f x = 1 โˆจ f x = -1 + +/-- The `ยฑ1` encoding `ฯ‡ : ZMod 2 โ†’ โ„`, `ฯ‡(b) = (-1)^b` +([ODonnell2014], ยง1.2). -/ +def chi : ZMod 2 โ†’ โ„ := fun b => if b = 0 then 1 else -1 + +/-- The parity function `ฯ‡_S : ๐”ฝโ‚‚โฟ โ†’ โ„` for `S โІ [n]`, defined by +`(ฯ‡_S)(x) = โˆ_{i โˆˆ S} ฯ‡(xแตข) = (-1)^(โˆ‘_{i โˆˆ S} xแตข)` +([ODonnell2014], Definition 1.2). -/ +noncomputable def parityFun (S : Finset (Fin n)) : BooleanFunction n := + fun x => โˆ i โˆˆ S, chi (x i) + +@[inherit_doc] scoped prefix:max "ฯ‡" => parityFun + +/-- The Fourier coefficient `๐“• f S = โŸชf, ฯ‡ SโŸซ` ([ODonnell2014], Proposition 1.8). +Its square `(๐“• f S)ยฒ` is called the *Fourier weight* of `f` on `S` +([ODonnell2014], Definition 1.17). -/ +noncomputable def fourierCoeff (f : BooleanFunction n) (S : Finset (Fin n)) : โ„ := + โŸชf, ฯ‡ SโŸซ + +@[inherit_doc] scoped notation "๐“•" => fourierCoeff + +/-- The uniform expectation over the Hamming cube equals `2โปโฟ ยท โˆ‘_x f(x)`. -/ +theorem expect_eq_sum_div_pow (f : HammingCube n โ†’ โ„) : + ๐”ผ x, f x = 1 / 2 ^ n * โˆ‘ x : HammingCube n, f x := by + rw [Finset.expect_eq_sum_div_card] + simp [Finset.card_univ, ZMod.card] + ring + +/-- `โŸชf, gโŸซ = ๐”ผ x, f x * g x` ([ODonnell2014], Definition 1.3). -/ +theorem inner_eq_expect (f g : BooleanFunction n) : + โŸชf, gโŸซ = ๐”ผ x, f x * g x := by + simp [BooleanFunction.inner_def, expect_eq_sum_div_pow] + +/-! ### Properties of the encoding `ฯ‡` -/ + +@[simp] theorem chi_zero : chi (0 : ZMod 2) = 1 := by simp [chi] + +@[simp] theorem chi_one : chi (1 : ZMod 2) = -1 := by simp [chi] + +@[simp] theorem chi_sq (b : ZMod 2) : chi b ^ 2 = 1 := by + fin_cases b <;> simp [chi] + +private theorem zmod2_cases (a : ZMod 2) : a = 0 โˆจ a = 1 := by + fin_cases a <;> tauto + +/-- `ฯ‡` is multiplicative on `ZMod 2`: `ฯ‡(a + b) = ฯ‡(a) ยท ฯ‡(b)`. -/ +@[simp] theorem chi_add (a b : ZMod 2) : chi (a + b) = chi a * chi b := by + rcases zmod2_cases a with rfl | rfl <;> rcases zmod2_cases b with rfl | rfl <;> + simp [chi, show (1 : ZMod 2) + 1 = 0 from Fin.ext (by decide)] + +/-! ### Properties of parity functions -/ + +@[simp] theorem parityFun_empty : (ฯ‡ (โˆ… : Finset (Fin n))) = fun _ => 1 := by + funext _; simp [parityFun] + +/-- Parity functions are multiplicative: `ฯ‡_S(x + y) = ฯ‡_S(x) ยท ฯ‡_S(y)` +([ODonnell2014], Equation 1.5). -/ +@[simp] theorem parityFun_add (S : Finset (Fin n)) (x y : HammingCube n) : + (ฯ‡ S) (x + y) = (ฯ‡ S) x * (ฯ‡ S) y := by + simp [parityFun, โ† Finset.prod_mul_distrib, chi_add] + +@[simp] theorem parityFun_sq (S : Finset (Fin n)) (x : HammingCube n) : (ฯ‡ S) x ^ 2 = 1 := by + simp [parityFun, โ† Finset.prod_pow] + +@[simp] theorem parityFun_zero (S : Finset (Fin n)) : (ฯ‡ S) 0 = 1 := by simp [parityFun] + +/-- `ฯ‡_S ยท ฯ‡_T = ฯ‡_{S โ–ณ T}` pointwise ([ODonnell2014], Fact 1.6). -/ +theorem parityFun_mul_apply (S T : Finset (Fin n)) (x : HammingCube n) : + (ฯ‡ S) x * (ฯ‡ T) x = (ฯ‡ (symmDiff S T)) x := by + simp only [parityFun] + have hsd : (S โˆช T) \ (S โˆฉ T) = symmDiff S T := by + ext i; simp [Finset.mem_symmDiff]; tauto + have hsdiff := hsd โ–ธ Finset.prod_sdiff + (Finset.inter_subset_union (s := S) (t := T)) (f := fun i => chi (x i)) + have hchi_sq : (โˆ i โˆˆ S โˆฉ T, chi (x i)) ^ 2 = 1 := by + rw [โ† Finset.prod_pow]; simp + rw [โ† Finset.prod_union_inter (sโ‚ := S) (sโ‚‚ := T) (f := fun i => chi (x i)), + โ† hsdiff, mul_assoc, โ† sq, hchi_sq, mul_one] + +/-- `๐”ผ x, ฯ‡_S x = 1` if `S = โˆ…` and `0` otherwise ([ODonnell2014], Fact 1.7). -/ +theorem expect_parityFun (S : Finset (Fin n)) : + ๐”ผ x, (ฯ‡ S) x = if S = โˆ… then 1 else 0 := by + split_ifs with h + ยท subst h + simp + ยท simp only [expect_eq_sum_div_pow] + obtain โŸจj, hjโŸฉ := Finset.nonempty_of_ne_empty h + let ej : HammingCube n := Pi.single j 1 + have hej : (ฯ‡ S) ej = -1 := by + simp only [parityFun] + have hprod : โˆ€ i โˆˆ S, chi (ej i) = if i = j then -1 else 1 := by + intro i _ + simp only [ej, Pi.single_apply] + split_ifs <;> simp + rw [Finset.prod_congr rfl hprod] + simp [hj] + suffices h0 : โˆ‘ x : HammingCube n, (ฯ‡ S) x = 0 by rw [h0, mul_zero] + have hself : โˆ‘ x : HammingCube n, (ฯ‡ S) x = -(โˆ‘ x : HammingCube n, (ฯ‡ S) x) := by + conv_lhs => + rw [Fintype.sum_equiv (Equiv.addRight ej) _ (fun y => -(ฯ‡ S) y) (fun x => by + change (ฯ‡ S) x = -(ฯ‡ S) (x + ej) + rw [parityFun_add, hej, mul_neg_one, neg_neg])] + rw [Finset.sum_neg_distrib] + linarith + +/-- The parity functions are orthonormal: `โŸชฯ‡_S, ฯ‡_TโŸซ = ฮด_{S,T}` +([ODonnell2014], Theorem 1.5, orthonormality identity). -/ +theorem parityFun_orthonormal_apply (S T : Finset (Fin n)) : + โŸชฯ‡ S, ฯ‡ TโŸซ = if S = T then 1 else 0 := by + rw [inner_eq_expect, funext (parityFun_mul_apply S T), expect_parityFun] + simp + +/-! ### The Fourier expansion theorem -/ + +/-- Sum of all parity functions at a point: `โˆ‘_S ฯ‡_S(z) = 2โฟ` if `z = 0`, else `0`. -/ +theorem sum_parityFun (z : HammingCube n) : + โˆ‘ S : Finset (Fin n), (ฯ‡ S) z = if z = 0 then (2 : โ„) ^ n else 0 := by + split_ifs with hz + ยท subst hz; simp [Finset.sum_const, Finset.card_univ] + ยท have โŸจj, hjโŸฉ : โˆƒ j, z j โ‰  0 := by + by_contra h + push Not at h + exact hz (funext (fun i => by simpa using h i)) + have hzj : z j = 1 := by + have := ZMod.val_lt (z j) + rcases (show (z j).val = 0 โˆจ (z j).val = 1 by omega) with h | h + ยท exact absurd (Fin.ext h : z j = 0) hj + ยท exact Fin.ext h + have hflip : โˆ€ S : Finset (Fin n), (ฯ‡ (symmDiff S {j})) z = -(ฯ‡ S) z := by + intro S + rw [โ† parityFun_mul_apply S {j} z] + simp only [parityFun, Finset.prod_singleton, hzj, chi_one, mul_neg_one] + have hself : โˆ‘ S : Finset (Fin n), (ฯ‡ S) z = -(โˆ‘ S : Finset (Fin n), (ฯ‡ S) z) := by + conv_lhs => + rw [Fintype.sum_equiv + ((symmDiff_right_involutive ({j} : Finset (Fin n))).toPerm) + _ (fun S => -(ฯ‡ S) z) (fun S => by + change (ฯ‡ S) z = -(ฯ‡ (symmDiff {j} S)) z + rw [symmDiff_comm, hflip]; ring)] + rw [Finset.sum_neg_distrib] + linarith + +/-- Fourier expansion ([ODonnell2014], Theorem 1.1, existence): +`f(x) = โˆ‘_S ๐“• f S ยท ฯ‡_S(x)`. -/ +theorem fourier_expansion (f : BooleanFunction n) (x : HammingCube n) : + f x = โˆ‘ S : Finset (Fin n), ๐“• f S * (ฯ‡ S) x := by + simp only [fourierCoeff, BooleanFunction.inner_def] + have hadd_zero : โˆ€ y : HammingCube n, y + x = 0 โ†” y = x := fun y => by + simp only [funext_iff] + refine forall_congr' fun i => ?_ + change y i + x i = 0 โ†” y i = x i + rw [add_eq_zero_iff_eq_neg, CharTwo.neg_eq] + conv_rhs => + arg 2; ext S + rw [show (1 / (2 : โ„) ^ n * โˆ‘ y, f y * (ฯ‡ S) y) * (ฯ‡ S) x = + โˆ‘ y : HammingCube n, 1 / (2 : โ„) ^ n * (f y * ((ฯ‡ S) (y + x))) from by + rw [mul_comm _ ((ฯ‡ S) x), Finset.mul_sum, Finset.mul_sum] + apply Finset.sum_congr rfl; intro y _ + rw [parityFun_add]; ring] + rw [Finset.sum_comm] + simp_rw [โ† Finset.mul_sum, sum_parityFun, hadd_zero, mul_ite, mul_zero] + rw [Finset.sum_ite_eq' Finset.univ x, if_pos (Finset.mem_univ _)] + field_simp + +/-- Fourier uniqueness ([ODonnell2014], Theorem 1.1, uniqueness): if +`f = โˆ‘_S c_S ยท ฯ‡_S` then `c = ๐“• f`. -/ +theorem fourier_uniqueness (f : BooleanFunction n) (c : Finset (Fin n) โ†’ โ„) + (h : โˆ€ x, f x = โˆ‘ S : Finset (Fin n), c S * (ฯ‡ S) x) (T : Finset (Fin n)) : + c T = ๐“• f T := by + have hortho : โˆ€ S, (1 / (2 : โ„) ^ n) * โˆ‘ x : HammingCube n, (ฯ‡ S) x * (ฯ‡ T) x = + if S = T then 1 else 0 := + fun S => by rw [โ† BooleanFunction.inner_def]; exact parityFun_orthonormal_apply S T + have hexpand : (fun x : HammingCube n => f x * (ฯ‡ T) x) = + (fun x => โˆ‘ S, c S * ((ฯ‡ S) x * (ฯ‡ T) x)) := + funext fun x => by + rw [h x, Finset.sum_mul]; exact Finset.sum_congr rfl fun _ _ => by ring + have hswap : โˆ‘ x : HammingCube n, f x * (ฯ‡ T) x = + โˆ‘ S : Finset (Fin n), c S * โˆ‘ x : HammingCube n, (ฯ‡ S) x * (ฯ‡ T) x := by + rw [hexpand, Finset.sum_comm] + exact Finset.sum_congr rfl fun _ _ => Finset.mul_sum .. |>.symm + have hmove : โˆ€ S, (1 / (2 : โ„) ^ n) * (c S * โˆ‘ x : HammingCube n, (ฯ‡ S) x * (ฯ‡ T) x) = + c S * ((1 / (2 : โ„) ^ n) * โˆ‘ x : HammingCube n, (ฯ‡ S) x * (ฯ‡ T) x) := + fun _ => by ring + simp only [fourierCoeff, BooleanFunction.inner_def] + rw [hswap, Finset.mul_sum] + simp_rw [hmove, hortho, mul_ite, mul_one, mul_zero, + Finset.sum_ite_eq', Finset.mem_univ, if_true] + +/-! ### Plancherel and Parseval -/ + +/-- The parity functions form an orthonormal family. -/ +theorem parityFun_orthonormal : Orthonormal โ„ (parityFun (n := n)) := + orthonormal_iff_ite.mpr parityFun_orthonormal_apply + +/-- The parity functions span `BooleanFunction n`. -/ +theorem parityFun_span : โŠค โ‰ค Submodule.span โ„ (Set.range (parityFun (n := n))) := by + intro f _ + have hf : f = โˆ‘ S : Finset (Fin n), fourierCoeff f S โ€ข parityFun S := by + ext x; simpa [BooleanFunction.smul_apply] using fourier_expansion f x + rw [hf] + exact Submodule.sum_mem _ fun S _ => + Submodule.smul_mem _ _ (Submodule.subset_span โŸจS, rflโŸฉ) + +/-- The parity functions form an orthonormal basis for `BooleanFunction n` +([ODonnell2014], Theorem 1.5, basis form). -/ +noncomputable def parityOrthonormalBasis : + OrthonormalBasis (Finset (Fin n)) โ„ (BooleanFunction n) := + OrthonormalBasis.mk parityFun_orthonormal parityFun_span + +@[simp] theorem parityOrthonormalBasis_apply (S : Finset (Fin n)) : + parityOrthonormalBasis (n := n) S = parityFun S := by + change (OrthonormalBasis.mk parityFun_orthonormal parityFun_span) S = _ + simp [OrthonormalBasis.coe_mk] + +/-- Plancherel's theorem: `โŸชf, gโŸซ = โˆ‘_S ๐“• f S ยท ๐“• g S`. -/ +theorem plancherel (f g : BooleanFunction n) : + โŸชf, gโŸซ = โˆ‘ S : Finset (Fin n), ๐“• f S * ๐“• g S := by + have h := parityOrthonormalBasis (n := n) |>.sum_inner_mul_inner f g + simp only [parityOrthonormalBasis_apply] at h + rw [โ† h] + refine Finset.sum_congr rfl fun S _ => ?_ + simp only [fourierCoeff] + rw [real_inner_comm (ฯ‡ S) g] + +/-- Parseval's theorem: `โŸชf, fโŸซ = โˆ‘_S (๐“• f S)ยฒ`. -/ +theorem parseval (f : BooleanFunction n) : + โŸชf, fโŸซ = โˆ‘ S : Finset (Fin n), (๐“• f S) ^ 2 := by + rw [plancherel] + exact Finset.sum_congr rfl fun S _ => (sq _).symm + +/-- Parseval's theorem for Boolean-valued functions: the Fourier weights +sum to `1`. -/ +theorem parseval_boolean (f : BooleanFunction n) (hf : IsBooleanValued f) : + โˆ‘ S : Finset (Fin n), (๐“• f S) ^ 2 = 1 := by + rw [โ† parseval] + simp only [BooleanFunction.inner_def] + have hsq : โˆ€ x : HammingCube n, f x * f x = 1 := by + intro x; rcases hf x with hx | hx <;> simp [hx] + rw [Finset.sum_congr rfl (fun x _ => hsq x)] + simp [Finset.sum_const, Finset.card_univ, ZMod.card] + +end Cslib.Foundations.Combinatorics.BooleanFunctions diff --git a/references.bib b/references.bib index f0d122d17..1606633c1 100644 --- a/references.bib +++ b/references.bib @@ -258,6 +258,15 @@ @article{ Nipkow2001 publisher = {Kluwer Academic Publishers} } +@book{ ODonnell2014, + author = {O'Donnell, Ryan}, + title = {Analysis of Boolean Functions}, + publisher = {Cambridge University Press}, + year = {2014}, + isbn = {978-1-107-03832-5}, + doi = {10.1017/CBO9781139814782} +} + @Book{ Sangiorgi2011, location = {Cambridge}, title = {Introduction to Bisimulation and Coinduction},