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

Commit cef5898

Browse files
committed
chore(linear_algebra): generalize conversion between matrices and bilinear forms to semirings (#14263)
Only one lemma was moved (`dual_distrib_apply`), none were renamed, and no proofs were meaningfully changed. Section markers were shuffled around, and some variables exchanged for variables with weaker typeclass assumptions. A few other things have been generalized to semiring at the same time; `linear_map.trace` and `linear_map.smul_rightₗ`
1 parent e09e877 commit cef5898

File tree

9 files changed

+131
-112
lines changed

9 files changed

+131
-112
lines changed

src/linear_algebra/basic.lean

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -418,12 +418,6 @@ def dom_restrict'
418418
@[simp] lemma dom_restrict'_apply (f : M →ₗ[R] M₂) (p : submodule R M) (x : p) :
419419
dom_restrict' p f x = f x := rfl
420420

421-
end comm_semiring
422-
423-
section comm_ring
424-
variables [comm_ring R] [add_comm_group M] [add_comm_group M₂] [add_comm_group M₃]
425-
variables [module R M] [module R M₂] [module R M₃]
426-
427421
/--
428422
The family of linear maps `M₂ → M` parameterised by `f ∈ M₂ → R`, `x ∈ M`, is linear in `f`, `x`.
429423
-/
@@ -438,7 +432,7 @@ def smul_rightₗ : (M₂ →ₗ[R] R) →ₗ[R] M →ₗ[R] M₂ →ₗ[R] M :=
438432
@[simp] lemma smul_rightₗ_apply (f : M₂ →ₗ[R] R) (x : M) (c : M₂) :
439433
(smul_rightₗ : (M₂ →ₗ[R] R) →ₗ[R] M →ₗ[R] M₂ →ₗ[R] M) f x c = (f c) • x := rfl
440434

441-
end comm_ring
435+
end comm_semiring
442436

443437
end linear_map
444438

src/linear_algebra/bilinear_form.lean

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -616,20 +616,20 @@ end
616616

617617
section basis
618618

619-
variables {B₃ F₃ : bilin_form R₃ M₃}
620-
variables {ι : Type*} (b : basis ι R₃ M₃)
619+
variables {F₂ : bilin_form R₂ M₂}
620+
variables {ι : Type*} (b : basis ι R₂ M₂)
621621

622622
/-- Two bilinear forms are equal when they are equal on all basis vectors. -/
623-
lemma ext_basis (h : ∀ i j, B (b i) (b j) = F (b i) (b j)) : B = F :=
623+
lemma ext_basis (h : ∀ i j, B (b i) (b j) = F (b i) (b j)) : B = F :=
624624
to_lin.injective $ b.ext $ λ i, b.ext $ λ j, h i j
625625

626626
/-- Write out `B x y` as a sum over `B (b i) (b j)` if `b` is a basis. -/
627-
lemma sum_repr_mul_repr_mul (x y : M) :
628-
(b.repr x).sum (λ i xi, (b.repr y).sum (λ j yj, xi • yj • B (b i) (b j))) = B x y :=
627+
lemma sum_repr_mul_repr_mul (x y : M) :
628+
(b.repr x).sum (λ i xi, (b.repr y).sum (λ j yj, xi • yj • B (b i) (b j))) = B x y :=
629629
begin
630630
conv_rhs { rw [← b.total_repr x, ← b.total_repr y] },
631631
simp_rw [finsupp.total_apply, finsupp.sum, sum_left, sum_right,
632-
smul_left, smul_right, smul_eq_mul]
632+
smul_left, smul_right, smul_eq_mul],
633633
end
634634

635635
end basis
@@ -781,18 +781,15 @@ def is_pair_self_adjoint_submodule : submodule R₂ (module.End R₂ M₂) :=
781781
f ∈ is_pair_self_adjoint_submodule B₂ F₂ ↔ is_pair_self_adjoint B₂ F₂ f :=
782782
by refl
783783

784-
variables {M₃' : Type*} [add_comm_group M₃'] [module R₃ M₃']
785-
variables (B₃ F₃ : bilin_form R₃ M₃)
786-
787-
lemma is_pair_self_adjoint_equiv (e : M₃' ≃ₗ[R₃] M₃) (f : module.End R₃ M₃) :
788-
is_pair_self_adjoint B₃ F₃ f ↔
789-
is_pair_self_adjoint (B₃.comp ↑e ↑e) (F₃.comp ↑e ↑e) (e.symm.conj f) :=
784+
lemma is_pair_self_adjoint_equiv (e : M₂' ≃ₗ[R₂] M₂) (f : module.End R₂ M₂) :
785+
is_pair_self_adjoint B₂ F₂ f ↔
786+
is_pair_self_adjoint (B₂.comp ↑e ↑e) (F₂.comp ↑e ↑e) (e.symm.conj f) :=
790787
begin
791-
have hₗ : (F.comp ↑e ↑e).comp_left (e.symm.conj f) = (F.comp_left f).comp ↑e ↑e :=
788+
have hₗ : (F.comp ↑e ↑e).comp_left (e.symm.conj f) = (F.comp_left f).comp ↑e ↑e :=
792789
by { ext, simp [linear_equiv.symm_conj_apply], },
793-
have hᵣ : (B.comp ↑e ↑e).comp_right (e.symm.conj f) = (B.comp_right f).comp ↑e ↑e :=
790+
have hᵣ : (B.comp ↑e ↑e).comp_right (e.symm.conj f) = (B.comp_right f).comp ↑e ↑e :=
794791
by { ext, simp [linear_equiv.conj_apply], },
795-
have he : function.surjective (⇑(↑e : M' →ₗ[R] M) : M' → M) := e.surjective,
792+
have he : function.surjective (⇑(↑e : M' →ₗ[R] M) : M' → M) := e.surjective,
796793
show bilin_form.is_adjoint_pair _ _ _ _ ↔ bilin_form.is_adjoint_pair _ _ _ _,
797794
rw [is_adjoint_pair_iff_comp_left_eq_comp_right, is_adjoint_pair_iff_comp_left_eq_comp_right,
798795
hᵣ, hₗ, comp_inj _ _ he he],
@@ -818,6 +815,8 @@ def self_adjoint_submodule := is_pair_self_adjoint_submodule B₂ B₂
818815
@[simp] lemma mem_self_adjoint_submodule (f : module.End R₂ M₂) :
819816
f ∈ B₂.self_adjoint_submodule ↔ B₂.is_self_adjoint f := iff.rfl
820817

818+
variables (B₃ : bilin_form R₃ M₃)
819+
821820
/-- The set of skew-adjoint endomorphisms of a module with bilinear form is a submodule. (In fact
822821
it is a Lie subalgebra.) -/
823822
def skew_adjoint_submodule := is_pair_self_adjoint_submodule (-B₃) B₃

src/linear_algebra/contraction.lean

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ some basic properties of these maps.
2020
contraction, dual module, tensor product
2121
-/
2222

23-
variables (R M N P Q : Type*) [add_comm_group M]
24-
variables [add_comm_group N] [add_comm_group P] [add_comm_group Q]
23+
variables {ι : Type*} (R M N P Q : Type*)
2524

2625
local attribute [ext] tensor_product.ext
2726

@@ -30,10 +29,11 @@ section contraction
3029
open tensor_product linear_map matrix
3130
open_locale tensor_product big_operators
3231

33-
section comm_ring
34-
35-
variables [comm_ring R] [module R M] [module R N] [module R P] [module R Q]
36-
variables {ι : Type*} [decidable_eq ι] [fintype ι] (b : basis ι R M)
32+
section comm_semiring
33+
variables [comm_semiring R]
34+
variables [add_comm_monoid M] [add_comm_monoid N] [add_comm_monoid P] [add_comm_monoid Q]
35+
variables [module R M] [module R N] [module R P] [module R Q]
36+
variables [decidable_eq ι] [fintype ι] (b : basis ι R M)
3737

3838
/-- The natural left-handed pairing between a module and its dual. -/
3939
def contract_left : (module.dual R M) ⊗ M →ₗ[R] R := (uncurry _ _ _ _).to_fun linear_map.id
@@ -100,6 +100,16 @@ begin
100100
rw [and_iff_not_or_not, not_not] at hij, cases hij; simp [hij],
101101
end
102102

103+
end comm_semiring
104+
105+
section comm_ring
106+
variables [comm_ring R]
107+
variables [add_comm_group M] [add_comm_group N] [add_comm_group P] [add_comm_group Q]
108+
variables [module R M] [module R N] [module R P] [module R Q]
109+
variables [decidable_eq ι] [fintype ι] (b : basis ι R M)
110+
111+
variables {R M N P Q}
112+
103113
/-- If `M` is free, the natural linear map $M^* ⊗ N → Hom(M, N)$ is an equivalence. This function
104114
provides this equivalence in return for a basis of `M`. -/
105115
@[simps apply]
@@ -157,7 +167,9 @@ open module tensor_product linear_map
157167

158168
section comm_ring
159169

160-
variables [comm_ring R] [module R M] [module R N] [module R P] [module R Q]
170+
variables [comm_ring R]
171+
variables [add_comm_group M] [add_comm_group N] [add_comm_group P] [add_comm_group Q]
172+
variables [module R M] [module R N] [module R P] [module R Q]
161173
variables [free R M] [finite R M] [free R N] [finite R N] [nontrivial R]
162174

163175
/-- When `M` is a finite free module, the map `ltensor_hom_to_hom_ltensor` is an equivalence. Note

src/linear_algebra/dual.lean

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ section dual_pair
351351
open module
352352

353353
variables {R M ι : Type*}
354-
variables [comm_ring R] [add_comm_group M] [module R M] [decidable_eq ι]
354+
variables [comm_semiring R] [add_comm_monoid M] [module R M] [decidable_eq ι]
355355

356356
/-- `e` and `ε` have characteristic properties of a basis and its dual -/
357357
@[nolint has_inhabited_instance]
@@ -448,7 +448,7 @@ namespace submodule
448448

449449
universes u v w
450450

451-
variables {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M] [module R M]
451+
variables {R : Type u} {M : Type v} [comm_semiring R] [add_comm_monoid M] [module R M]
452452
variable {W : submodule R M}
453453

454454
/-- The `dual_restrict` of a submodule `W` of `M` is the linear map from the
@@ -464,7 +464,7 @@ linear_map.dom_restrict' W
464464

465465
/-- The `dual_annihilator` of a submodule `W` is the set of linear maps `φ` such
466466
that `φ w = 0` for all `w ∈ W`. -/
467-
def dual_annihilator {R : Type u} {M : Type v} [comm_ring R] [add_comm_group M]
467+
def dual_annihilator {R : Type u} {M : Type v} [comm_semiring R] [add_comm_monoid M]
468468
[module R M] (W : submodule R M) : submodule R $ module.dual R M :=
469469
W.dual_restrict.ker
470470

@@ -624,11 +624,12 @@ end
624624

625625
end subspace
626626

627-
variables {R : Type*} [comm_ring R] {M₁ : Type*} {M₂ : Type*}
628-
variables [add_comm_group M₁] [module R M₁] [add_comm_group M₂] [module R M₂]
629-
630627
open module
631628

629+
section dual_map
630+
variables {R : Type*} [comm_semiring R] {M₁ : Type*} {M₂ : Type*}
631+
variables [add_comm_monoid M₁] [module R M₁] [add_comm_monoid M₂] [module R M₂]
632+
632633
/-- Given a linear map `f : M₁ →ₗ[R] M₂`, `f.dual_map` is the linear map between the dual of
633634
`M₂` and `M₁` such that it maps the functional `φ` to `φ ∘ f`. -/
634635
def linear_map.dual_map (f : M₁ →ₗ[R] M₂) : dual R M₂ →ₗ[R] dual R M₁ :=
@@ -680,7 +681,11 @@ lemma linear_equiv.dual_map_trans {M₃ : Type*} [add_comm_group M₃] [module R
680681
g.dual_map.trans f.dual_map = (f.trans g).dual_map :=
681682
rfl
682683

684+
end dual_map
685+
683686
namespace linear_map
687+
variables {R : Type*} [comm_semiring R] {M₁ : Type*} {M₂ : Type*}
688+
variables [add_comm_monoid M₁] [module R M₁] [add_comm_monoid M₂] [module R M₂]
684689

685690
variable (f : M₁ →ₗ[R] M₂)
686691

@@ -767,9 +772,7 @@ end linear_map
767772

768773
namespace tensor_product
769774

770-
variables (R) (M : Type*) (N : Type*)
771-
variables [add_comm_group M] [add_comm_group N]
772-
variables [module R M] [module R N]
775+
variables (R : Type*) (M : Type*) (N : Type*)
773776

774777
variables {ι κ : Type*}
775778
variables [decidable_eq ι] [decidable_eq κ]
@@ -782,7 +785,10 @@ local attribute [ext] tensor_product.ext
782785

783786
open tensor_product
784787
open linear_map
785-
open module (dual)
788+
789+
section
790+
variables [comm_semiring R] [add_comm_monoid M] [add_comm_monoid N]
791+
variables [module R M] [module R N]
786792

787793
/--
788794
The canonical linear map from `dual M ⊗ dual N` to `dual (M ⊗ N)`,
@@ -794,6 +800,18 @@ def dual_distrib : (dual R M) ⊗[R] (dual R N) →ₗ[R] dual R (M ⊗[R] N) :=
794800

795801
variables {R M N}
796802

803+
@[simp]
804+
lemma dual_distrib_apply (f : dual R M) (g : dual R N) (m : M) (n : N) :
805+
dual_distrib R M N (f ⊗ₜ g) (m ⊗ₜ n) = f m * g n :=
806+
by simp only [dual_distrib, coe_comp, function.comp_app, hom_tensor_hom_map_apply,
807+
comp_right_apply, linear_equiv.coe_coe, map_tmul, lid_tmul, algebra.id.smul_eq_mul]
808+
809+
end
810+
811+
variables {R M N}
812+
variables [comm_ring R] [add_comm_group M] [add_comm_group N]
813+
variables [module R M] [module R N]
814+
797815
/--
798816
An inverse to `dual_tensor_dual_map` given bases.
799817
-/
@@ -803,12 +821,6 @@ def dual_distrib_inv_of_basis (b : basis ι R M) (c : basis κ R N) :
803821
∑ i j, (ring_lmap_equiv_self R ℕ _).symm (b.dual_basis i ⊗ₜ c.dual_basis j)
804822
∘ₗ applyₗ (c j) ∘ₗ applyₗ (b i) ∘ₗ (lcurry R M N R)
805823

806-
@[simp]
807-
lemma dual_distrib_apply (f : dual R M) (g : dual R N) (m : M) (n : N) :
808-
dual_distrib R M N (f ⊗ₜ g) (m ⊗ₜ n) = f m * g n :=
809-
by simp only [dual_distrib, coe_comp, function.comp_app, hom_tensor_hom_map_apply,
810-
comp_right_apply, linear_equiv.coe_coe, map_tmul, lid_tmul, algebra.id.smul_eq_mul]
811-
812824
@[simp]
813825
lemma dual_distrib_inv_of_basis_apply (b : basis ι R M) (c : basis κ R N)
814826
(f : dual R (M ⊗[R] N)) : dual_distrib_inv_of_basis b c f =

src/linear_algebra/matrix/basis.lean

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ open_locale matrix
3838
section basis_to_matrix
3939

4040
variables {ι ι' κ κ' : Type*}
41-
variables {R M : Type*} [comm_ring R] [add_comm_group M] [module R M]
41+
variables {R M : Type*} [comm_semiring R] [add_comm_monoid M] [module R M]
42+
variables {R₂ M₂ : Type*} [comm_ring R₂] [add_comm_group M₂] [module R₂ M₂]
4243

4344
open function matrix
4445

@@ -84,7 +85,7 @@ begin
8485
end
8586

8687
/-- The basis constructed by `units_smul` has vectors given by a diagonal matrix. -/
87-
@[simp] lemma to_matrix_units_smul [decidable_eq ι] (w : ι → ) :
88+
@[simp] lemma to_matrix_units_smul [decidable_eq ι] (e : basis ι R₂ M₂) (w : ι → R₂ˣ) :
8889
e.to_matrix (e.units_smul w) = diagonal (coe ∘ w) :=
8990
begin
9091
ext i j,
@@ -94,7 +95,8 @@ begin
9495
end
9596

9697
/-- The basis constructed by `is_unit_smul` has vectors given by a diagonal matrix. -/
97-
@[simp] lemma to_matrix_is_unit_smul [decidable_eq ι] {w : ι → R} (hw : ∀ i, is_unit (w i)) :
98+
@[simp] lemma to_matrix_is_unit_smul [decidable_eq ι] (e : basis ι R₂ M₂) {w : ι → R₂}
99+
(hw : ∀ i, is_unit (w i)) :
98100
e.to_matrix (e.is_unit_smul hw) = diagonal w :=
99101
e.to_matrix_units_smul _
100102

@@ -147,7 +149,7 @@ end basis
147149

148150
section mul_linear_map_to_matrix
149151

150-
variables {N : Type*} [add_comm_group N] [module R N]
152+
variables {N : Type*} [add_comm_monoid N] [module R N]
151153
variables (b : basis ι R M) (b' : basis ι' R M) (c : basis κ R N) (c' : basis κ' R N)
152154
variables (f : M →ₗ[R] N)
153155

0 commit comments

Comments
 (0)