Orthogonal.lean

Lean 4 source, lean/DataMiningAsObservation/Orthogonal.lean at commit bccca4f. Appendix C, Machine-checked statements, says what each file proves. All Lean files.

/-
Orthogonal.lean. Chapter 0 section 0.1 and section 0.2, orthogonality.

Two vectors are orthogonal when their dot product is zero. The relation is symmetric, it
survives rescaling, every vector is orthogonal to zero, the squared length of a sum of
orthogonal vectors is the sum of the squared lengths, and the residual of a projection is
orthogonal to the direction projected on, which is why a projection splits a vector into a
read part and a nuisance part.
-/
import Mathlib
import DataMiningAsObservation.Projection

namespace DMO.Orthogonal

open DMO.Projection

variable {n : ℕ}

/-- Orthogonality. -/
def IsOrth (u v : Fin n → ℝ) : Prop := u ⬝ᵥ v = 0

/-- **Orthogonality is symmetric.** -/
theorem orth_symm (u v : Fin n → ℝ) : IsOrth u v ↔ IsOrth v u := by
  unfold IsOrth
  rw [dotProduct_comm]

/-- **Pythagoras.** -/
theorem pythagoras (u v : Fin n → ℝ) (h : IsOrth u v) :
    (u + v) ⬝ᵥ (u + v) = u ⬝ᵥ u + v ⬝ᵥ v := by
  have h' : u ⬝ᵥ v = 0 := h
  rw [add_dotProduct, dotProduct_add, dotProduct_add, dotProduct_comm v u, h']
  ring

/-- **Orthogonality survives rescaling.** -/
theorem orth_smul (u v : Fin n → ℝ) (c : ℝ) (h : IsOrth u v) : IsOrth (c • u) v := by
  have h' : u ⬝ᵥ v = 0 := h
  show (c • u) ⬝ᵥ v = 0
  rw [smul_dotProduct, h', smul_zero]

/-- **Every vector is orthogonal to zero.** -/
theorem orth_zero (u : Fin n → ℝ) : IsOrth u 0 := by
  simp [IsOrth]

/-- **The residual of a projection is orthogonal to the direction.** -/
theorem residual_orth (u x : Fin n → ℝ) (hu : u ⬝ᵥ u = 1) : IsOrth u (x - proj u x) :=
  dot_sub_proj u x hu

end DMO.Orthogonal