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

Commit 2016a93

Browse files
committed
feat(linear_algebra): use finsets to define det and trace (#7778)
This PR replaces `∃ (s : set M) (b : basis s R M), s.finite` with `∃ (s : finset M), nonempty (basis s R M)` in the definitions in `linear_map.det` and `linear_map.trace`. This should make it much easier to unfold those definitions without having to modify the instance cache or supply implicit params. In particular, it should help a lot with #7667.
1 parent dabb41f commit 2016a93

File tree

6 files changed

+65
-37
lines changed

6 files changed

+65
-37
lines changed

src/linear_algebra/basis.lean

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,41 @@ end
333333
b.reindex_range.repr x ⟨b i, h⟩ = b.repr x i :=
334334
b.reindex_range_repr' _ rfl
335335

336+
section fintype
337+
338+
variables [fintype ι]
339+
340+
/-- `b.reindex_finset_range` is a basis indexed by `finset.univ.image b`,
341+
the finite set of basis vectors themselves. -/
342+
def reindex_finset_range : basis (finset.univ.image b) R M :=
343+
b.reindex_range.reindex ((equiv.refl M).subtype_equiv (by simp))
344+
345+
lemma reindex_finset_range_self (i : ι) (h := finset.mem_image_of_mem b (finset.mem_univ i)) :
346+
b.reindex_finset_range ⟨b i, h⟩ = b i :=
347+
by { rw [reindex_finset_range, reindex_apply, reindex_range_apply], refl }
348+
349+
@[simp] lemma reindex_finset_range_apply (x : finset.univ.image b) :
350+
b.reindex_finset_range x = x :=
351+
by { rcases x with ⟨bi, hbi⟩, rcases finset.mem_image.mp hbi with ⟨i, -, rfl⟩,
352+
exact b.reindex_finset_range_self i }
353+
354+
lemma reindex_finset_range_repr_self (i : ι) :
355+
b.reindex_finset_range.repr (b i) =
356+
finsupp.single ⟨b i, finset.mem_image_of_mem b (finset.mem_univ i)⟩ 1 :=
357+
begin
358+
ext ⟨bi, hbi⟩,
359+
rw [reindex_finset_range, reindex_repr, reindex_range_repr_self],
360+
convert finsupp.single_apply_left ((equiv.refl M).subtype_equiv _).symm.injective _ _ _,
361+
refl
362+
end
363+
364+
@[simp] lemma reindex_finset_range_repr (x : M) (i : ι)
365+
(h := finset.mem_image_of_mem b (finset.mem_univ i)) :
366+
b.reindex_finset_range.repr x ⟨b i, h⟩ = b.repr x i :=
367+
by simp [reindex_finset_range]
368+
369+
end fintype
370+
336371
end reindex
337372

338373
protected lemma linear_independent : linear_independent R b :=

src/linear_algebra/determinant.lean

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ open_locale classical
158158
If there is no finite basis on `M`, the result is `1` instead.
159159
-/
160160
protected def det : (M →ₗ[A] M) →* A :=
161-
if H : ∃ (s : set M) (b : basis s A M), s.finite
162-
then @linear_map.det_aux _ _ _ _ H.some_spec.some_spec.some _ _ _ (trunc.mk H.some_spec.some)
161+
if H : ∃ (s : finset M), nonempty (basis s A M)
162+
then linear_map.det_aux (trunc.mk H.some_spec.some)
163163
else 1
164164

165165
lemma coe_det [decidable_eq M] : ⇑(linear_map.det : (M →ₗ[A] M) →* A) =
166-
if H : ∃ (s : set M) (b : basis s A M), s.finite
167-
then @linear_map.det_aux _ _ _ _ H.some_spec.some_spec.some _ _ _ (trunc.mk H.some_spec.some)
166+
if H : ∃ (s : finset M), nonempty (basis s A M)
167+
then linear_map.det_aux (trunc.mk H.some_spec.some)
168168
else 1 :=
169169
by { ext, unfold linear_map.det,
170170
split_ifs,
@@ -178,18 +178,18 @@ attribute [irreducible] linear_map.det
178178

179179
-- Auxiliary lemma, the `simp` normal form goes in the other direction
180180
-- (using `linear_map.det_to_matrix`)
181-
lemma det_eq_det_to_matrix_of_finite_set [decidable_eq M]
182-
{s : set M} (b : basis s A M) [hs : fintype s] (f : M →ₗ[A] M) :
181+
lemma det_eq_det_to_matrix_of_finset [decidable_eq M]
182+
{s : finset M} (b : basis s A M) (f : M →ₗ[A] M) :
183183
f.det = matrix.det (linear_map.to_matrix b b f) :=
184-
have ∃ (s : set M) (b : basis s A M), s.finite,
185-
from ⟨s, b, ⟨hs⟩⟩,
184+
have ∃ (s : finset M), nonempty (basis s A M),
185+
from ⟨s, ⟨b⟩⟩,
186186
by rw [linear_map.coe_det, dif_pos, det_aux_def' _ b]; assumption
187187

188188
@[simp] lemma det_to_matrix
189189
(b : basis ι A M) (f : M →ₗ[A] M) :
190190
matrix.det (to_matrix b b f) = f.det :=
191191
by { haveI := classical.dec_eq M,
192-
rw [det_eq_det_to_matrix_of_finite_set b.reindex_range, det_to_matrix_eq_det_to_matrix b] }
192+
rw [det_eq_det_to_matrix_of_finset b.reindex_finset_range, det_to_matrix_eq_det_to_matrix b] }
193193

194194
@[simp]
195195
lemma det_comp (f g : M →ₗ[A] M) : (f.comp g).det = f.det * g.det :=

src/linear_algebra/finite_dimensional.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,10 @@ lemma finrank_eq_zero_of_not_exists_basis_finite
549549
(h : ¬ ∃ (s : set V) (b : basis.{v} (s : set V) K V), s.finite) : finrank K V = 0 :=
550550
finrank_eq_zero_of_basis_imp_not_finite (λ s b hs, h ⟨s, b, hs⟩)
551551

552+
lemma finrank_eq_zero_of_not_exists_basis_finset
553+
(h : ¬ ∃ (s : finset V), nonempty (basis s K V)) : finrank K V = 0 :=
554+
finrank_eq_zero_of_basis_imp_false (λ s b, h ⟨s, ⟨b⟩⟩)
555+
552556
variables (K V)
553557

554558
lemma finite_dimensional_bot : finite_dimensional K (⊥ : submodule K V) :=

src/linear_algebra/trace.lean

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,45 +64,36 @@ calc matrix.trace ι R R (linear_map.to_matrix b b f)
6464

6565
open_locale classical
6666

67-
theorem trace_aux_reindex_range [nontrivial R] : trace_aux R b.reindex_range = trace_aux R b :=
68-
linear_map.ext $ λ f,
69-
begin
70-
change ∑ i : set.range b, _ = ∑ i : ι, _, simp_rw [matrix.diag_apply], symmetry,
71-
convert (equiv.of_injective _ b.injective).sum_comp _, ext i,
72-
exact (linear_map.to_matrix_reindex_range b b f i i).symm
73-
end
74-
7567
variables (R) (M)
7668

7769
/-- Trace of an endomorphism independent of basis. -/
7870
def trace : (M →ₗ[R] M) →ₗ[R] R :=
79-
if H : ∃ (s : set M) (b : basis (s : set M) R M), s.finite
80-
then @trace_aux R _ _ _ _ _ _ (classical.choice H.some_spec.some_spec) H.some_spec.some
71+
if H : ∃ (s : finset M), nonempty (basis s R M)
72+
then trace_aux R H.some_spec.some
8173
else 0
8274

8375
variables (R) {M}
8476

8577
/-- Auxiliary lemma for `trace_eq_matrix_trace`. -/
86-
theorem trace_eq_matrix_trace_of_finite_set {s : set M} (b : basis s R M) (hs : fintype s)
78+
theorem trace_eq_matrix_trace_of_finset {s : finset M} (b : basis s R M)
8779
(f : M →ₗ[R] M) :
8880
trace R M f = matrix.trace s R R (linear_map.to_matrix b b f) :=
89-
have ∃ (s : set M) (b : basis (s : set M) R M), s.finite,
90-
from ⟨s, b, ⟨hs⟩⟩,
81+
have ∃ (s : finset M), nonempty (basis s R M),
82+
from ⟨s, ⟨b⟩⟩,
9183
by { rw [trace, dif_pos this, ← trace_aux_def], congr' 1, apply trace_aux_eq }
9284

9385
theorem trace_eq_matrix_trace (f : M →ₗ[R] M) :
9486
trace R M f = matrix.trace ι R R (linear_map.to_matrix b b f) :=
9587
if hR : nontrivial R
9688
then by haveI := hR;
97-
rw [trace_eq_matrix_trace_of_finite_set R b.reindex_range (set.fintype_range b),
98-
← trace_aux_def, ← trace_aux_def, trace_aux_reindex_range]
89+
rw [trace_eq_matrix_trace_of_finset R b.reindex_finset_range,
90+
← trace_aux_def, ← trace_aux_def, trace_aux_eq R b]
9991
else @subsingleton.elim _ (not_nontrivial_iff_subsingleton.mp hR) _ _
10092

10193
theorem trace_mul_comm (f g : M →ₗ[R] M) :
10294
trace R M (f * g) = trace R M (g * f) :=
103-
if H : ∃ (s : set M) (b : basis (s : set M) R M), s.finite then let ⟨s, b, hs⟩ := H in
104-
by { haveI := classical.choice hs,
105-
simp_rw [trace_eq_matrix_trace R b, linear_map.to_matrix_mul], apply matrix.trace_mul_comm }
95+
if H : ∃ (s : finset M), nonempty (basis s R M) then let ⟨s, ⟨b⟩⟩ := H in
96+
by { simp_rw [trace_eq_matrix_trace R b, linear_map.to_matrix_mul], apply matrix.trace_mul_comm }
10697
else by rw [trace, dif_neg H, linear_map.zero_apply, linear_map.zero_apply]
10798

10899
end linear_map

src/ring_theory/norm.lean

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ linear_map.det.comp (lmul R S).to_ring_hom.to_monoid_hom
6161
@[simp] lemma norm_apply (x : S) : norm R x = linear_map.det (lmul R S x) := rfl
6262

6363
lemma norm_eq_one_of_not_exists_basis
64-
(h : ¬ ∃ (s : set S) (b : basis s R S), s.finite) (x : S) : norm R x = 1 :=
64+
(h : ¬ ∃ (s : finset S), nonempty (basis s R S)) (x : S) : norm R x = 1 :=
6565
by { rw [norm_apply, linear_map.det], split_ifs with h, refl }
6666

6767
variables {R}
@@ -89,12 +89,11 @@ end
8989
@[simp]
9090
lemma norm_algebra_map (x : K) : norm K (algebra_map K L x) = x ^ finrank K L :=
9191
begin
92-
by_cases H : ∃ (s : set L) (b : basis s K L), s.finite,
93-
{ haveI : fintype H.some := H.some_spec.some_spec.some,
94-
rw [norm_algebra_map_of_basis H.some_spec.some, finrank_eq_card_basis H.some_spec.some] },
92+
by_cases H : ∃ (s : finset L), nonempty (basis s K L),
93+
{ rw [norm_algebra_map_of_basis H.some_spec.some, finrank_eq_card_basis H.some_spec.some] },
9594
{ rw [norm_eq_one_of_not_exists_basis K H, finrank_eq_zero_of_not_exists_basis, pow_zero],
9695
rintros ⟨s, ⟨b⟩⟩,
97-
exact H ⟨s, b, s.finite_to_set⟩ },
96+
exact H ⟨s, ⟨b⟩⟩ },
9897
end
9998

10099
section eq_prod_roots

src/ring_theory/trace.lean

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ noncomputable def trace : S →ₗ[R] R :=
6161
variables {S}
6262

6363
lemma trace_eq_zero_of_not_exists_basis
64-
(h : ¬ ∃ (s : set S) (b : basis s R S), s.finite) : trace R S = 0 :=
64+
(h : ¬ ∃ (s : finset S), nonempty (basis s R S)) : trace R S = 0 :=
6565
by { ext s, simp [linear_map.trace, h] }
6666

6767
include b
@@ -92,10 +92,9 @@ omit b
9292
@[simp]
9393
lemma trace_algebra_map (x : K) : trace K L (algebra_map K L x) = finrank K L • x :=
9494
begin
95-
by_cases H : ∃ (s : set L) (b : basis s K L), s.finite,
96-
{ haveI : fintype H.some := H.some_spec.some_spec.some,
97-
rw [trace_algebra_map_of_basis H.some_spec.some, finrank_eq_card_basis H.some_spec.some] },
98-
{ simp [trace_eq_zero_of_not_exists_basis K H, finrank_eq_zero_of_not_exists_basis_finite H] }
95+
by_cases H : ∃ (s : finset L), nonempty (basis s K L),
96+
{ rw [trace_algebra_map_of_basis H.some_spec.some, finrank_eq_card_basis H.some_spec.some] },
97+
{ simp [trace_eq_zero_of_not_exists_basis K H, finrank_eq_zero_of_not_exists_basis_finset H] }
9998
end
10099

101100
section trace_form

0 commit comments

Comments
 (0)