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

Commit 9f0d61b

Browse files
committed
fix(analysis/inner_product_space/pi_L2): add missing type cast functions (#18574)
The preferred way to convert between `ι → 𝕜` and `euclidean_space 𝕜 ι` is via `pi_Lp.equiv`, as this preserves the right typing information. We use the local notation `⟪x, y⟫ₑ` to refer the euclidean inner product of `x y : ι → 𝕜`, which inserts the casting within the notation. This adds a new definition `matrix.to_euclidean_lin` as a shorthand to turn a matrix into a `linear_map` over `euclidean_space`. It also generalizes `inner_matrix_row_row` and `inner_matrix_col_col` away from `fin n` to arbitrary index types.
1 parent 88b8a77 commit 9f0d61b

File tree

5 files changed

+58
-41
lines changed

5 files changed

+58
-41
lines changed

src/analysis/inner_product_space/adjoint.lean

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -434,14 +434,13 @@ open_locale complex_conjugate
434434

435435
/-- The adjoint of the linear map associated to a matrix is the linear map associated to the
436436
conjugate transpose of that matrix. -/
437-
lemma conj_transpose_eq_adjoint (A : matrix m n 𝕜) :
438-
to_lin' A.conj_transpose =
439-
@linear_map.adjoint _ (euclidean_space 𝕜 n) (euclidean_space 𝕜 m) _ _ _ _ _ (to_lin' A) :=
437+
lemma to_euclidean_lin_conj_transpose_eq_adjoint (A : matrix m n 𝕜) :
438+
A.conj_transpose.to_euclidean_lin = A.to_euclidean_lin.adjoint :=
440439
begin
441-
rw @linear_map.eq_adjoint_iff _ (euclidean_space 𝕜 m) (euclidean_space 𝕜 n),
440+
rw linear_map.eq_adjoint_iff,
442441
intros x y,
443-
convert dot_product_assoc (conj ∘ (id x : m → 𝕜)) y A using 1,
444-
simp [dot_product, mul_vec, ring_hom.map_sum, ← star_ring_end_apply, mul_comm],
442+
simp_rw [euclidean_space.inner_eq_star_dot_product, pi_Lp_equiv_to_euclidean_lin,
443+
to_lin'_apply, star_mul_vec, conj_transpose_conj_transpose, dot_product_mul_vec],
445444
end
446445

447446
end matrix

src/analysis/inner_product_space/pi_L2.lean

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ lemma finrank_euclidean_space_fin {n : ℕ} :
138138
lemma euclidean_space.inner_eq_star_dot_product (x y : euclidean_space 𝕜 ι) :
139139
⟪x, y⟫ = matrix.dot_product (star $ pi_Lp.equiv _ _ x) (pi_Lp.equiv _ _ y) := rfl
140140

141+
lemma euclidean_space.inner_pi_Lp_equiv_symm (x y : ι → 𝕜) :
142+
⟪(pi_Lp.equiv 2 _).symm x, (pi_Lp.equiv 2 _).symm y⟫ = matrix.dot_product (star x) y := rfl
143+
141144
/-- A finite, mutually orthogonal family of subspaces of `E`, which span `E`, induce an isometry
142145
from `E` to `pi_Lp 2` of the subspaces equipped with the `L2` inner product. -/
143146
def direct_sum.is_internal.isometry_L2_of_orthogonal_family
@@ -815,18 +818,41 @@ section matrix
815818

816819
open_locale matrix
817820

818-
variables {n m : ℕ}
821+
variables {m n : Type*}
822+
823+
namespace matrix
824+
variables [fintype m] [fintype n] [decidable_eq n]
825+
826+
/-- `matrix.to_lin'` adapted for `euclidean_space 𝕜 _`. -/
827+
def to_euclidean_lin : matrix m n 𝕜 ≃ₗ[𝕜] (euclidean_space 𝕜 n →ₗ[𝕜] euclidean_space 𝕜 m) :=
828+
matrix.to_lin' ≪≫ₗ linear_equiv.arrow_congr
829+
(pi_Lp.linear_equiv _ 𝕜 (λ _ : n, 𝕜)).symm (pi_Lp.linear_equiv _ 𝕜 (λ _ : m, 𝕜)).symm
830+
831+
@[simp]
832+
lemma to_euclidean_lin_pi_Lp_equiv_symm (A : matrix m n 𝕜) (x : n → 𝕜) :
833+
A.to_euclidean_lin ((pi_Lp.equiv _ _).symm x) = (pi_Lp.equiv _ _).symm (A.to_lin' x) := rfl
834+
835+
@[simp]
836+
lemma pi_Lp_equiv_to_euclidean_lin (A : matrix m n 𝕜) (x : euclidean_space 𝕜 n) :
837+
pi_Lp.equiv _ _ (A.to_euclidean_lin x) = A.to_lin' (pi_Lp.equiv _ _ x) := rfl
838+
839+
/- `matrix.to_euclidean_lin` is the same as `matrix.to_lin` applied to `pi_Lp.basis_fun`, -/
840+
lemma to_euclidean_lin_eq_to_lin :
841+
(to_euclidean_lin : matrix m n 𝕜 ≃ₗ[𝕜] _) =
842+
matrix.to_lin (pi_Lp.basis_fun _ _ _) (pi_Lp.basis_fun _ _ _) := rfl
843+
844+
end matrix
819845

820-
local notation `⟪`x`, `y`⟫ₘ` := @inner 𝕜 (euclidean_space 𝕜 (fin m)) _ x y
821-
local notation `⟪`x`, `y`⟫ₙ` := @inner 𝕜 (euclidean_space 𝕜 (fin n)) _ x y
846+
local notation `⟪`x`, `y`⟫ₑ` := @inner 𝕜 _ _ ((pi_Lp.equiv 2 _).symm x) ((pi_Lp.equiv 2 _).symm y)
822847

823-
/-- The inner product of a row of A and a row of B is an entry of B ⬝ Aᴴ. -/
824-
lemma inner_matrix_row_row (A B : matrix (fin n) (fin m) 𝕜) (i j : (fin n)) :
825-
⟪A i, B j⟫ₘ = (B ⬝ Aᴴ) j i := by {simp only [inner, matrix.mul_apply, star_ring_end_apply,
826-
matrix.conj_transpose_apply,mul_comm]}
848+
/-- The inner product of a row of `A` and a row of `B` is an entry of `B ⬝ Aᴴ`. -/
849+
lemma inner_matrix_row_row [fintype n] (A B : matrix m n 𝕜) (i j : m) :
850+
⟪A i, B j⟫ₑ = (B ⬝ Aᴴ) j i :=
851+
by simp_rw [euclidean_space.inner_pi_Lp_equiv_symm, matrix.mul_apply', matrix.dot_product_comm,
852+
matrix.conj_transpose_apply, pi.star_def]
827853

828-
/-- The inner product of a column of A and a column of B is an entry of Aᴴ ⬝ B -/
829-
lemma inner_matrix_col_col (A B : matrix (fin n) (fin m) 𝕜) (i j : (fin m)) :
830-
⟪Aᵀ i, Bᵀ j⟫ = (Aᴴ ⬝ B) i j := rfl
854+
/-- The inner product of a column of `A` and a column of `B` is an entry of `Aᴴ ⬝ B`. -/
855+
lemma inner_matrix_col_col [fintype m] (A B : matrix m n 𝕜) (i j : n) :
856+
⟪Aᵀ i, Bᵀ j⟫ = (Aᴴ ⬝ B) i j := rfl
831857

832858
end matrix

src/linear_algebra/matrix/hermitian.lean

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ variables {α β : Type*} {m n : Type*} {A : matrix n n α}
2525

2626
open_locale matrix
2727

28-
local notation `⟪`x`, `y`⟫` := @inner α (pi_Lp 2 (λ (_ : n), α)) _ x y
28+
local notation `⟪`x`, `y`⟫` := @inner α _ _ x y
2929

3030
section non_unital_semiring
3131

@@ -200,14 +200,11 @@ funext h.coe_re_apply_self
200200

201201
/-- A matrix is hermitian iff the corresponding linear map is self adjoint. -/
202202
lemma is_hermitian_iff_is_symmetric [fintype n] [decidable_eq n] {A : matrix n n α} :
203-
is_hermitian A ↔ linear_map.is_symmetric
204-
((pi_Lp.linear_equiv 2 α (λ _ : n, α)).symm.conj A.to_lin' : module.End α (pi_Lp 2 _)) :=
203+
is_hermitian A ↔ A.to_euclidean_lin.is_symmetric :=
205204
begin
206205
rw [linear_map.is_symmetric, (pi_Lp.equiv 2 (λ _ : n, α)).symm.surjective.forall₂],
207-
simp only [linear_equiv.conj_apply, linear_map.comp_apply, linear_equiv.coe_coe,
208-
pi_Lp.linear_equiv_apply, pi_Lp.linear_equiv_symm_apply, linear_equiv.symm_symm],
209-
simp_rw [euclidean_space.inner_eq_star_dot_product, equiv.apply_symm_apply, to_lin'_apply,
210-
star_mul_vec, dot_product_mul_vec],
206+
simp only [to_euclidean_lin_pi_Lp_equiv_symm, euclidean_space.inner_pi_Lp_equiv_symm,
207+
to_lin'_apply, star_mul_vec, dot_product_mul_vec],
211208
split,
212209
{ rintro (h : Aᴴ = A) x y,
213210
rw h },

src/linear_algebra/matrix/ldl.lean

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ decomposed as `S = LDLᴴ` where `L` is a lower-triangular matrix and `D` is a d
3030
variables {𝕜 : Type*} [is_R_or_C 𝕜]
3131
variables {n : Type*} [linear_order n] [is_well_order n (<)] [locally_finite_order_bot n]
3232

33-
local notation `⟪`x`, `y`⟫` :=
34-
@inner 𝕜 (n → 𝕜) (pi_Lp.inner_product_space (λ _, 𝕜)).to_has_inner x y
33+
local notation `⟪`x`, `y`⟫ₑ` := @inner 𝕜 _ _ ((pi_Lp.equiv 2 _).symm x) ((pi_Lp.equiv _ _).symm y)
3534

3635
open matrix
3736
open_locale matrix
@@ -42,7 +41,7 @@ applying Gram-Schmidt-Orthogonalization w.r.t. the inner product induced by `S
4241
basis vectors `pi.basis_fun`. -/
4342
noncomputable def LDL.lower_inv : matrix n n 𝕜 :=
4443
@gram_schmidt
45-
𝕜 (n → 𝕜) _ (inner_product_space.of_matrix hS.transpose) n _ _ _ (λ k, pi.basis_fun 𝕜 n k)
44+
𝕜 (n → 𝕜) _ (inner_product_space.of_matrix hS.transpose) n _ _ _ (pi.basis_fun 𝕜 n)
4645

4746
lemma LDL.lower_inv_eq_gram_schmidt_basis :
4847
LDL.lower_inv hS = ((pi.basis_fun 𝕜 n).to_matrix
@@ -64,15 +63,15 @@ begin
6463
end
6564

6665
lemma LDL.lower_inv_orthogonal {i j : n} (h₀ : i ≠ j) :
67-
⟪(LDL.lower_inv hS i), Sᵀ.mul_vec (LDL.lower_inv hS j)⟫ = 0 :=
66+
⟪(LDL.lower_inv hS i), Sᵀ.mul_vec (LDL.lower_inv hS j)⟫ = 0 :=
6867
show @inner 𝕜 (n → 𝕜) (inner_product_space.of_matrix hS.transpose).to_has_inner
6968
(LDL.lower_inv hS i)
7069
(LDL.lower_inv hS j) = 0,
7170
by apply gram_schmidt_orthogonal _ _ h₀
7271

7372
/-- The entries of the diagonal matrix `D` of the LDL decomposition. -/
7473
noncomputable def LDL.diag_entries : n → 𝕜 :=
75-
λ i, ⟪star (LDL.lower_inv hS i), S.mul_vec (star (LDL.lower_inv hS i))⟫
74+
λ i, ⟪star (LDL.lower_inv hS i), S.mul_vec (star (LDL.lower_inv hS i))⟫
7675

7776
/-- The diagonal matrix `D` of the LDL decomposition. -/
7877
noncomputable def LDL.diag : matrix n n 𝕜 := matrix.diagonal (LDL.diag_entries hS)
@@ -88,12 +87,12 @@ lemma LDL.diag_eq_lower_inv_conj : LDL.diag hS = LDL.lower_inv hS ⬝ S ⬝ (LDL
8887
begin
8988
ext i j,
9089
by_cases hij : i = j,
91-
{ simpa only [hij, LDL.diag, diagonal_apply_eq, LDL.diag_entries, matrix.mul_assoc, inner,
92-
pi.star_apply, is_R_or_C.star_def, star_ring_end_self_apply] },
90+
{ simpa only [hij, LDL.diag, diagonal_apply_eq, LDL.diag_entries, matrix.mul_assoc,
91+
euclidean_space.inner_pi_Lp_equiv_symm, star_star] },
9392
{ simp only [LDL.diag, hij, diagonal_apply_ne, ne.def, not_false_iff, mul_mul_apply],
9493
rw [conj_transpose, transpose_map, transpose_transpose, dot_product_mul_vec,
9594
(LDL.lower_inv_orthogonal hS (λ h : j = i, hij h.symm)).symm,
96-
← inner_conj_symm, mul_vec_transpose, euclidean_space.inner_eq_star_dot_product,
95+
← inner_conj_symm, mul_vec_transpose, euclidean_space.inner_pi_Lp_equiv_symm,
9796
← is_R_or_C.star_def, ← star_dot_product_star, dot_product_comm, star_star],
9897
refl }
9998
end

src/linear_algebra/matrix/spectrum.lean

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,14 @@ theorem spectral_theorem :
9090
begin
9191
rw [eigenvector_matrix_inv, pi_Lp.basis_to_matrix_basis_fun_mul],
9292
ext i j,
93-
have : linear_map.is_symmetric _ := is_hermitian_iff_is_symmetric.1 hA,
93+
have := is_hermitian_iff_is_symmetric.1 hA,
9494
convert this.diagonalization_basis_apply_self_apply finrank_euclidean_space
9595
(euclidean_space.single j 1)
96-
((fintype.equiv_of_card_eq (fintype.card_fin _)).symm i),
97-
{ dsimp only [linear_equiv.conj_apply_apply, pi_Lp.linear_equiv_apply,
98-
pi_Lp.linear_equiv_symm_apply, pi_Lp.equiv_single, linear_map.std_basis,
99-
linear_map.coe_single, pi_Lp.equiv_symm_single, linear_equiv.symm_symm,
100-
eigenvector_basis, to_lin'_apply],
101-
simp only [basis.to_matrix, basis.coe_to_orthonormal_basis_repr, basis.equiv_fun_apply],
102-
simp_rw [orthonormal_basis.coe_to_basis_repr_apply, orthonormal_basis.repr_reindex,
103-
linear_equiv.symm_symm, pi_Lp.linear_equiv_apply, pi_Lp.equiv_single, mul_vec_single,
104-
mul_one],
96+
((fintype.equiv_of_card_eq (fintype.card_fin _)).symm i) using 1,
97+
{ dsimp only [euclidean_space.single, to_euclidean_lin_pi_Lp_equiv_symm, to_lin'_apply,
98+
matrix.of_apply, is_hermitian.eigenvector_basis],
99+
simp_rw [mul_vec_single, mul_one, orthonormal_basis.coe_to_basis_repr_apply,
100+
orthonormal_basis.repr_reindex],
105101
refl },
106102
{ simp only [diagonal_mul, (∘), eigenvalues, eigenvector_basis],
107103
rw [basis.to_matrix_apply,

0 commit comments

Comments
 (0)