Projection.lean
Lean 4 source, lean/DataMiningAsObservation/Projection.lean at commit bccca4f. Appendix C, Machine-checked statements, says what each file proves. All Lean files.
/-
Projection.lean. Equation 0.2, the projection onto a unit direction.
The projection of a vector onto a unit direction is the direction scaled by their dot
product. Projecting twice is projecting once, the remainder is orthogonal to the
direction, the projection is no longer than the vector, and adding anything orthogonal to
the direction leaves the projection unchanged. The last is the quotient a one-direction
reader takes, the linear classifier of chapter 6 among them.
-/
import Mathlib
namespace DMO.Projection
variable {n : ℕ}
/-- **Equation 0.2.** The projection of `x` onto the direction `u`. -/
def proj (u x : Fin n → ℝ) : Fin n → ℝ := (u ⬝ᵥ x) • u
/-- **Projecting twice is projecting once** for a unit direction. -/
theorem proj_proj (u x : Fin n → ℝ) (hu : u ⬝ᵥ u = 1) : proj u (proj u x) = proj u x := by
unfold proj
rw [dotProduct_smul, hu, smul_eq_mul, mul_one]
/-- **The remainder is orthogonal to the direction.** -/
theorem dot_sub_proj (u x : Fin n → ℝ) (hu : u ⬝ᵥ u = 1) : u ⬝ᵥ (x - proj u x) = 0 := by
unfold proj
rw [dotProduct_sub, dotProduct_smul, hu, smul_eq_mul, mul_one, sub_self]
/-- **The projection is no longer than the vector.** -/
theorem proj_sq_le (u x : Fin n → ℝ) (hu : u ⬝ᵥ u = 1) : proj u x ⬝ᵥ proj u x ≤ x ⬝ᵥ x := by
unfold proj
rw [smul_dotProduct, dotProduct_smul, hu, smul_eq_mul, smul_eq_mul, mul_one]
have h := Finset.sum_mul_sq_le_sq_mul_sq Finset.univ u x
have h' : (u ⬝ᵥ x) ^ 2 ≤ (u ⬝ᵥ u) * (x ⬝ᵥ x) := by simpa [dotProduct, sq] using h
rw [hu, one_mul] at h'
nlinarith [h']
/-- **The quotient.** Adding anything orthogonal to the direction leaves the projection
unchanged, so a one-direction reader declares every such change the same. -/
theorem proj_add_orth (u x v : Fin n → ℝ) (hv : u ⬝ᵥ v = 0) : proj u (x + v) = proj u x := by
unfold proj
rw [dotProduct_add, hv, add_zero]
/-- The projection is linear in the vector. -/
theorem proj_add (u x y : Fin n → ℝ) : proj u (x + y) = proj u x + proj u y := by
unfold proj
rw [dotProduct_add, add_smul]
end DMO.Projection