Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

[Merged by Bors] - feat(analysis/inner_product_space/gram_schmidt_ortho): Gram-Schmidt Orthogonalization and Orthonormalization #12857

Closed
wants to merge 69 commits into from
Closed
Changes from 3 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
d02693b
doc(linear_algebra): Gram-Schmidt Orthogonalization and Orthornormali…
Biiiilly Mar 21, 2022
89b0132
change from review
Biiiilly Mar 21, 2022
3c498d5
change import
Biiiilly Mar 21, 2022
bd02f66
changes from review
Biiiilly Mar 21, 2022
8769f46
changes from reviews
Biiiilly Mar 21, 2022
6f87999
changes from review
Biiiilly Mar 21, 2022
49238f0
changes from reviews
Biiiilly Mar 22, 2022
6b8e358
changes from reviews
Biiiilly Mar 22, 2022
63c3e86
changes from reviews
Biiiilly Mar 22, 2022
31af760
changes from reviews
Biiiilly Mar 22, 2022
ee95b97
changes from reviews
Biiiilly Mar 23, 2022
6c8964b
change some doc-strings
Biiiilly Mar 23, 2022
15c0b54
add proof of span
Biiiilly Mar 26, 2022
6e55b6e
change doc
Biiiilly Mar 26, 2022
5f329da
changes from reviews
Biiiilly Mar 26, 2022
ba9d844
changes from reviews
Biiiilly Mar 26, 2022
4e9899f
changes from reviews
Biiiilly Mar 26, 2022
40772c0
add doc to def of gs process
Biiiilly Mar 26, 2022
ad7fc34
change doc of inner notation
Biiiilly Mar 27, 2022
8c9e27e
changes from reviews
Biiiilly Mar 27, 2022
4ca03b5
change some
Biiiilly Mar 28, 2022
d385acb
change some small mistakes
Biiiilly Mar 28, 2022
c1d567e
change small mistake
Biiiilly Mar 28, 2022
928e45a
change from reviews
Biiiilly Mar 31, 2022
fda0a2b
change path to inner product space
Biiiilly Mar 31, 2022
d1ab7e6
add TODO
Biiiilly Apr 5, 2022
3c1f2a9
change from reviews
Biiiilly Apr 5, 2022
607af4f
change from reviews
Biiiilly Apr 5, 2022
8ff5618
change from review
Biiiilly Apr 5, 2022
280dd61
change from review
Biiiilly Apr 5, 2022
67c9d61
change Iic to range
Biiiilly Apr 6, 2022
b206c41
add gram_schmidt_orhogonal
Biiiilly Apr 6, 2022
a553ce5
change from reviews
Biiiilly Apr 10, 2022
4e176ee
suffices
Biiiilly Apr 12, 2022
be24d1b
simplify span proof
Biiiilly Apr 13, 2022
baa718a
simp span
Biiiilly Apr 14, 2022
f454a3c
change line length
Biiiilly Apr 14, 2022
19e1c52
change from review about induction and indent
Biiiilly Apr 14, 2022
bd76fb8
change some mistake
Biiiilly Apr 14, 2022
bb71c43
simp nezero proof
Biiiilly Apr 14, 2022
9caf604
simp proof
Biiiilly Apr 14, 2022
5f727c0
change doc
Biiiilly Apr 15, 2022
8319da4
simp proof
Biiiilly Apr 15, 2022
9c18e8a
simp proof
Biiiilly Apr 15, 2022
c3d0cde
changes
Biiiilly Apr 15, 2022
47c0e56
changess
Biiiilly Apr 15, 2022
26945ed
simp proof
Biiiilly Apr 15, 2022
2482b0a
simp proof again
Biiiilly Apr 15, 2022
14a3537
simp simp proof
Biiiilly Apr 15, 2022
1abfff2
simp proof
Biiiilly Apr 16, 2022
962091a
simp
Biiiilly Apr 16, 2022
b3afd14
change from review
Biiiilly Apr 17, 2022
4e3996b
Iic_succ
Biiiilly Apr 17, 2022
0360e03
add Iic_succ
Biiiilly Apr 17, 2022
7865671
simp proof
Biiiilly Apr 17, 2022
e8506b4
simp proof aaaagin
Biiiilly Apr 18, 2022
06d7d6d
iicsucc
Biiiilly Apr 19, 2022
f04f835
Merge remote-tracking branch 'origin' into GS_doc
Biiiilly Apr 19, 2022
3c5f8c5
add Iic_succ
Biiiilly Apr 19, 2022
aeeb897
small mis
Biiiilly Apr 19, 2022
c2aede2
cleanup weird induction
eric-wieser Apr 19, 2022
74d8e45
change from review
Biiiilly Apr 19, 2022
2f66e94
change from review
Biiiilly Apr 19, 2022
f6c8abe
change from review
Biiiilly Apr 19, 2022
e96ead0
change doc
Biiiilly Apr 20, 2022
ee54f41
change doc
Biiiilly Apr 20, 2022
431b352
change doc
Biiiilly Apr 20, 2022
418d5ca
change doc
Biiiilly Apr 20, 2022
736430f
change doc
Biiiilly Apr 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions src/linear_algebra/gram_schmidt_ortho.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/-
Copyright (c) 2022 Jiale Miao. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jiale Miao, Kevin Buzzard
-/

import tactic.basic
import algebra.big_operators.basic
import analysis.inner_product_space.basic
import analysis.normed_space.is_R_or_C

/-!
# Gram-Schmidt Orthogonalization and Orthonormalization

In this file we introduce Gram-Schmidt Orthogonalization and Orthonormalization

## Main results

- `proj` : projection between two vectors in the inner product space
- `GS` : Gram-Schmidt Process
- `GS_Orthogonal` : the proof that "GS" produces an orthogonal system of vectors
- `GS_unit` : Normalized "Gram-Schmidt" (i.e each vector in this system has unit length)
- `GS_Orthornormal` : the proof that "GS_unit" produces an orthornormal system of vectors
-/

open_locale big_operators

variables (𝕜 : Type*) (E : Type*) [is_R_or_C 𝕜] [inner_product_space 𝕜 E]
Biiiilly marked this conversation as resolved.
Show resolved Hide resolved

/-- projection in the inner product space -/
def proj (u v : E) : E := ((inner u v) / (inner u u) : 𝕜) • u

Biiiilly marked this conversation as resolved.
Show resolved Hide resolved
/-- Definition of Gram-Schmidt Process -/
def GS (f : ℕ → E) : ℕ → E
| n := f n - ∑ i in finset.range(n),
if h1 : i < n then proj 𝕜 E (GS i) (f n) else f 37
Biiiilly marked this conversation as resolved.
Show resolved Hide resolved

/-- This helps us to get rid of 'ite' in the definition of GS -/
@[simp] lemma GS_n_1 (f : ℕ → E) (n : ℕ) :
GS 𝕜 E f (n + 1) = f (n + 1) - ∑ i in finset.range(n + 1), proj 𝕜 E (GS 𝕜 E f i) (f (n + 1)) :=
begin
rw [GS, sub_right_inj],
apply finset.sum_congr rfl,
intros x hx,
rw finset.mem_range at hx,
rw if_pos hx,
end

/-- inner product defined as add_monoid_hom -/
def inner_product_hom (v : E) [inner_product_space 𝕜 E] : E →+ 𝕜 :=
{ to_fun := inner v,
map_zero' := inner_zero_right,
map_add' := λ x y, inner_add_right }

lemma inner_eq_inner_hom (v x : E) : inner v x = inner_product_hom 𝕜 E v x := rfl

lemma inner_hom_eq_inner (v x : E) : inner_product_hom 𝕜 E v x = inner v x := rfl

/-- # Gram-Schmidt Orthogonalisation -/
theorem GS_Orthogonal (f : ℕ → E) (c : ℕ) :
∀ (a b : ℕ), a < b → b ≤ c → (inner (GS 𝕜 E f a) (GS 𝕜 E f b) : 𝕜) = 0 :=
begin
induction c with c hc,
Biiiilly marked this conversation as resolved.
Show resolved Hide resolved
{ intros a b ha hb, simp at hb, simp [hb] at ha, contradiction },
{ intros a b ha hb, rw nat.le_add_one_iff at hb, cases hb with hb₁ hb₂,
Biiiilly marked this conversation as resolved.
Show resolved Hide resolved
{ specialize hc a b, simp [ha, hb₁] at hc, exact hc },
Biiiilly marked this conversation as resolved.
Show resolved Hide resolved
{ simp [GS_n_1, hb₂, inner_sub_right],
rw [inner_eq_inner_hom, inner_eq_inner_hom],
rw map_sum (inner_product_hom 𝕜 E (GS 𝕜 E f a))
Biiiilly marked this conversation as resolved.
Show resolved Hide resolved
(λi, proj 𝕜 E (GS 𝕜 E f i) (f (c + 1))) (finset.range(c + 1)),
have h₀ : ∀ x ∈ finset.range(c + 1), x ≠ a
→ (inner_product_hom 𝕜 E (GS 𝕜 E f a)) (proj 𝕜 E (GS 𝕜 E f x) (f (c + 1))) = 0,
{ intros x hx₁ hx₂, simp [proj, inner_hom_eq_inner], rw inner_smul_right,
have hxa : x < a ∨ a < x := ne.lt_or_lt hx₂, cases hxa with hxa₁ hxa₂,
Biiiilly marked this conversation as resolved.
Show resolved Hide resolved
{ have ha₂ : a ≤ c,
{ rw hb₂ at ha, exact nat.lt_succ_iff.mp ha },
specialize hc x a, simp [hxa₁, ha₂] at hc,
simp only [mul_eq_zero, div_eq_zero_iff, inner_self_eq_zero], right,
rwa inner_eq_zero_sym at hc },
{ rw [finset.mem_range, nat.lt_succ_iff] at hx₁,
specialize hc a x, simp [hxa₂, hx₁] at hc,
simp only [mul_eq_zero, div_eq_zero_iff, inner_self_eq_zero], right,
exact hc }},
rw hb₂ at ha,
have ha₂ : a ∈ finset.range(c+1) := finset.mem_range.mpr ha,
rw finset.sum_eq_single_of_mem a ha₂ h₀, clear h₀,
simp [inner_hom_eq_inner, proj], rw inner_smul_right,
by_cases inner (GS 𝕜 E f a) (GS 𝕜 E f a) = (0 : 𝕜),
{ simp [inner_self_eq_zero] at h,
repeat {rw h}, simp only [inner_zero_left, mul_zero, sub_zero] },
{ simp [h] }}}
end

theorem GS_orthogonal' (f : ℕ → E) :
∀ (a b : ℕ), a < b → (inner (GS 𝕜 E f a) (GS 𝕜 E f b) : 𝕜) = 0 :=
begin
intros a b h,
have hb : b ≤ b + 1 := by linarith,
exact GS_Orthogonal 𝕜 E f (b + 1) a b h hb,
end

/-- Generalised Gram-Schmidt Orthorgonalization -/
theorem GS_orthogonal'' (f : ℕ → E) :
∀ (a b : ℕ), a ≠ b → (inner (GS 𝕜 E f a) (GS 𝕜 E f b) : 𝕜) = 0 :=
begin
intros a b h,
have hab : a < b ∨ b < a := ne.lt_or_lt h,
cases hab with ha hb,
Biiiilly marked this conversation as resolved.
Show resolved Hide resolved
{ exact GS_orthogonal' 𝕜 E f a b ha },
{ rw inner_eq_zero_sym,
exact GS_orthogonal' 𝕜 E f b a hb }
end

/-- Normalized Gram-Schmidt Process -/
noncomputable def GS_unit (f : ℕ → E) : ℕ → E
| n := (∥ GS 𝕜 E f n ∥ : 𝕜)⁻¹ • (GS 𝕜 E f n)
Biiiilly marked this conversation as resolved.
Show resolved Hide resolved

lemma GS_unit_length (f : ℕ → E) (n : ℕ) (hf : GS 𝕜 E f n ≠ 0) :
∥ GS_unit 𝕜 E f n ∥ = 1 := by simp only [GS_unit, norm_smul_inv_norm hf]

/-- # Gram-Schmidt Orthonormalization -/
Biiiilly marked this conversation as resolved.
Show resolved Hide resolved
theorem GS_Orthonormal (f : ℕ → E) (h : ∀ n, GS 𝕜 E f n ≠ 0) :
orthonormal 𝕜 (GS_unit 𝕜 E f) :=
begin
simp [orthonormal], split,
{ simp [GS_unit_length, h] },
{ intros i j hij,
have hij1 : i < j ∨ j < i := ne.lt_or_lt hij,
cases hij1 with hij2 hij3,
{ simp [GS_unit, inner_smul_left, inner_smul_right], repeat {right},
have hj : j ≤ j + 1 := by linarith,
exact GS_Orthogonal 𝕜 E f (j+1) i j hij2 hj },
{ simp [GS_unit, inner_smul_left, inner_smul_right], repeat {right},
have hi : i ≤ i + 1 := by linarith, rw inner_eq_zero_sym,
exact GS_Orthogonal 𝕜 E f (i+1) j i hij3 hi }}
end