Laplacian.lean
Lean 4 source, lean/DataMiningAsObservation/Laplacian.lean at commit bccca4f. Appendix C, Machine-checked statements, says what each file proves. All Lean files.
/-
Laplacian.lean. Equation 0.19, the graph Laplacian.
For a graph with symmetric nonnegative weights and degrees equal to the row sums, the
Laplacian quadratic form of a function on the nodes is half the weighted sum of squared
differences across edges. It is therefore nonnegative, and it is zero on every constant
function, which is why the eigenvectors from the smallest eigenvalue up are the smoothest
functions on the graph. The file states the form for the unnormalized Laplacian `D − A`.
Equation 0.19's normalized form is the same quadratic form in the coordinates `D^{1/2} y`.
-/
import Mathlib
namespace DMO.Laplacian
open Finset
variable {ι : Type*} [Fintype ι]
/-- The Laplacian quadratic form `y' (D − A) y` with degrees `d` and weights `a`. -/
def quad (d : ι → ℝ) (a : ι → ι → ℝ) (y : ι → ℝ) : ℝ :=
∑ i, d i * y i ^ 2 - ∑ i, ∑ j, a i j * y i * y j
/-- **The edge form.** With degrees the row sums and symmetric weights, the quadratic form is
half the weighted sum of squared differences. -/
theorem quad_eq (d : ι → ℝ) (a : ι → ι → ℝ) (hd : ∀ i, d i = ∑ j, a i j)
(hsymm : ∀ i j, a i j = a j i) (y : ι → ℝ) :
quad d a y = (∑ i, ∑ j, a i j * (y i - y j) ^ 2) / 2 := by
unfold quad
have h1 : ∑ i, d i * y i ^ 2 = ∑ i, ∑ j, a i j * y i ^ 2 := by
refine Finset.sum_congr rfl fun i _ => ?_
rw [hd i, Finset.sum_mul]
have h2 : ∑ i, ∑ j, a i j * y j ^ 2 = ∑ i, ∑ j, a i j * y i ^ 2 := by
rw [Finset.sum_comm]
refine Finset.sum_congr rfl fun i _ => Finset.sum_congr rfl fun j _ => ?_
rw [hsymm]
have h3 : ∑ i, ∑ j, a i j * (y i - y j) ^ 2
= ∑ i, ∑ j, a i j * y i ^ 2 + ∑ i, ∑ j, a i j * y j ^ 2 - 2 * ∑ i, ∑ j, a i j * y i * y j := by
rw [Finset.mul_sum, ← Finset.sum_add_distrib, ← Finset.sum_sub_distrib]
refine Finset.sum_congr rfl fun i _ => ?_
rw [Finset.mul_sum, ← Finset.sum_add_distrib, ← Finset.sum_sub_distrib]
refine Finset.sum_congr rfl fun j _ => ?_
ring
rw [h3, h2, h1]
ring
/-- **The form is nonnegative** for nonnegative weights. -/
theorem quad_nonneg (d : ι → ℝ) (a : ι → ι → ℝ) (hd : ∀ i, d i = ∑ j, a i j)
(hsymm : ∀ i j, a i j = a j i) (ha : ∀ i j, 0 ≤ a i j) (y : ι → ℝ) : 0 ≤ quad d a y := by
rw [quad_eq d a hd hsymm]
apply div_nonneg _ (by norm_num)
exact Finset.sum_nonneg fun i _ => Finset.sum_nonneg fun j _ => mul_nonneg (ha i j) (sq_nonneg _)
/-- **Constant functions are the smoothest.** The form vanishes on every constant. -/
theorem quad_const (d : ι → ℝ) (a : ι → ι → ℝ) (hd : ∀ i, d i = ∑ j, a i j)
(hsymm : ∀ i j, a i j = a j i) (c : ℝ) : quad d a (fun _ => c) = 0 := by
rw [quad_eq d a hd hsymm]
simp
/-- A function that differs across an edge of positive weight has positive form, so the
constants are the only functions the Laplacian sends to zero on a connected edge. -/
theorem quad_pos_of_edge (d : ι → ℝ) (a : ι → ι → ℝ) (hd : ∀ i, d i = ∑ j, a i j)
(hsymm : ∀ i j, a i j = a j i) (ha : ∀ i j, 0 ≤ a i j) (y : ι → ℝ) (i j : ι)
(hij : 0 < a i j) (hy : y i ≠ y j) : 0 < quad d a y := by
rw [quad_eq d a hd hsymm]
have hne : y i - y j ≠ 0 := sub_ne_zero.2 hy
have hsq : 0 < (y i - y j) ^ 2 := by positivity
have hterm : 0 < a i j * (y i - y j) ^ 2 := mul_pos hij hsq
have h1 : a i j * (y i - y j) ^ 2 ≤ ∑ j', a i j' * (y i - y j') ^ 2 :=
Finset.single_le_sum (f := fun j' => a i j' * (y i - y j') ^ 2)
(fun j' _ => mul_nonneg (ha i j') (sq_nonneg _)) (Finset.mem_univ j)
have h2 : ∑ j', a i j' * (y i - y j') ^ 2 ≤ ∑ i', ∑ j', a i' j' * (y i' - y j') ^ 2 :=
Finset.single_le_sum (f := fun i' => ∑ j', a i' j' * (y i' - y j') ^ 2)
(fun i' _ => Finset.sum_nonneg fun j' _ => mul_nonneg (ha i' j') (sq_nonneg _))
(Finset.mem_univ i)
apply div_pos _ (by norm_num)
linarith
end DMO.Laplacian