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

Commit b1c2339

Browse files
refactor(linear_algebra/matrix/finite_dimensional): deduplicate (#18770)
* `matrix.finrank_matrix` was a duplicate of `finite_dimensional.finrank_matrix`. * `linear_map.finrank_linear_map` was a duplicate of `finrank_linear_hom`, now merged to `finite_dimensional.finrank_linear_map` * `finite_dimensional.linear_map` was a duplicate of `linear_map.finite_dimensional` and can be golfed using `module.finite.linear_map` * `finite_dimensional.matrix` can be golfed using `module.finite.matrix` For now, I've left behind `finite_dimensional` instances, but proved them in terms of the `module.finite` versions. To enable this, some imports have been adjusted. The resulting import structure substantially cuts the dependencies consumed by `linear_algebra.matrix.to_lin`; it no longer needs `module.rank` to be available. Co-authored-by: Jeremy Tan Jie Rui <e0191785@u.nus.edu>
1 parent 45ce392 commit b1c2339

File tree

12 files changed

+59
-106
lines changed

12 files changed

+59
-106
lines changed

src/algebra/category/fgModule/basic.lean

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Authors: Jakob von Raumer
66
import category_theory.monoidal.rigid.basic
77
import category_theory.monoidal.subcategory
88
import linear_algebra.coevaluation
9+
import linear_algebra.free_module.finite.matrix
910
import algebra.category.Module.monoidal
1011

1112
/-!
@@ -131,7 +132,7 @@ instance (V W : fgModule K) : module.finite K (V ⟶ W) :=
131132

132133
instance closed_predicate_module_finite :
133134
monoidal_category.closed_predicate (λ V : Module.{u} K, module.finite K V) :=
134-
{ prop_ihom' := λ X Y hX hY, by exactI @linear_map.finite_dimensional K _ X _ _ hX Y _ _ hY }
135+
{ prop_ihom' := λ X Y hX hY, by exactI @module.finite.linear_map K X Y _ _ _ _ _ _ _ hX hY }
135136

136137
instance : monoidal_closed (fgModule K) := by dsimp_result { dsimp [fgModule], apply_instance, }
137138

src/analysis/normed_space/finite_dimension.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import analysis.normed_space.add_torsor
88
import analysis.normed_space.affine_isometry
99
import analysis.normed_space.operator_norm
1010
import analysis.normed_space.riesz_lemma
11-
import linear_algebra.matrix.to_lin
1211
import topology.algebra.module.finite_dimension
1312
import topology.algebra.infinite_sum.module
1413
import topology.instances.matrix

src/field_theory/tower.lean

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,25 +114,10 @@ theorem subalgebra.is_simple_order_of_finrank_prime (A) [ring A] [is_domain A] [
114114
end }
115115
/- TODO: `intermediate_field` version -/
116116

117-
instance linear_map (F : Type u) (V : Type v) (W : Type w)
118-
[field F] [add_comm_group V] [module F V] [add_comm_group W] [module F W]
119-
[finite_dimensional F V] [finite_dimensional F W] :
120-
finite_dimensional F (V →ₗ[F] W) :=
121-
let b := basis.of_vector_space F V, c := basis.of_vector_space F W in
122-
(matrix.to_lin b c).finite_dimensional
123-
124-
lemma finrank_linear_map (F : Type u) (V : Type v) (W : Type w)
125-
[field F] [add_comm_group V] [module F V] [add_comm_group W] [module F W]
126-
[finite_dimensional F V] [finite_dimensional F W] :
127-
finrank F (V →ₗ[F] W) = finrank F V * finrank F W :=
128-
let b := basis.of_vector_space F V, c := basis.of_vector_space F W in
129-
by rw [linear_equiv.finrank_eq (linear_map.to_matrix b c), matrix.finrank_matrix,
130-
finrank_eq_card_basis b, finrank_eq_card_basis c, mul_comm]
131-
132117
-- TODO: generalize by removing [finite_dimensional F K]
133118
-- V = ⊕F,
134119
-- (V →ₗ[F] K) = ((⊕F) →ₗ[F] K) = (⊕ (F →ₗ[F] K)) = ⊕K
135-
instance linear_map' (F : Type u) (K : Type v) (V : Type w)
120+
instance _root_.linear_map.finite_dimensional'' (F : Type u) (K : Type v) (V : Type w)
136121
[field F] [field K] [algebra F K] [finite_dimensional F K]
137122
[add_comm_group V] [module F V] [finite_dimensional F V] :
138123
finite_dimensional K (V →ₗ[F] K) :=

src/linear_algebra/bilinear_form.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Authors: Andreas Swerdlow, Kexing Ying
55
-/
66

77
import linear_algebra.dual
8+
import linear_algebra.free_module.finite.matrix
89
import linear_algebra.matrix.to_lin
910

1011
/-!

src/linear_algebra/determinant.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Copyright (c) 2019 Johannes Hölzl. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
55
-/
6+
import linear_algebra.finite_dimensional
67
import linear_algebra.general_linear_group
78
import linear_algebra.matrix.reindex
89
import tactic.field_simp

src/linear_algebra/free_module/finite/matrix.lean

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Authors: Riccardo Brasca
55
-/
66

77
import linear_algebra.finrank
8-
import linear_algebra.free_module.finite.basic
8+
import linear_algebra.free_module.finite.rank
99
import linear_algebra.matrix.to_lin
1010

1111
/-!
@@ -25,25 +25,26 @@ universes u v w
2525

2626
variables (R : Type u) (M : Type v) (N : Type w)
2727

28-
namespace module.free
28+
open module.free (choose_basis)
29+
open finite_dimensional (finrank)
2930

3031
section comm_ring
3132

3233
variables [comm_ring R] [add_comm_group M] [module R M] [module.free R M]
3334
variables [add_comm_group N] [module R N] [module.free R N]
3435

35-
instance linear_map [module.finite R M] [module.finite R N] : module.free R (M →ₗ[R] N) :=
36+
instance module.free.linear_map [module.finite R M] [module.finite R N] :
37+
module.free R (M →ₗ[R] N) :=
3638
begin
3739
casesI subsingleton_or_nontrivial R,
3840
{ apply module.free.of_subsingleton' },
3941
classical,
40-
exact of_equiv
41-
(linear_map.to_matrix (module.free.choose_basis R M) (module.free.choose_basis R N)).symm,
42+
exact module.free.of_equiv (linear_map.to_matrix (choose_basis R M) (choose_basis R N)).symm,
4243
end
4344

4445
variables {R}
4546

46-
instance _root_.module.finite.linear_map [module.finite R M] [module.finite R N] :
47+
instance module.finite.linear_map [module.finite R M] [module.finite R N] :
4748
module.finite R (M →ₗ[R] N) :=
4849
begin
4950
casesI subsingleton_or_nontrivial R,
@@ -60,10 +61,10 @@ section integer
6061
variables [add_comm_group M] [module.finite ℤ M] [module.free ℤ M]
6162
variables [add_comm_group N] [module.finite ℤ N] [module.free ℤ N]
6263

63-
instance _root_.module.finite.add_monoid_hom : module.finite ℤ (M →+ N) :=
64+
instance module.finite.add_monoid_hom : module.finite ℤ (M →+ N) :=
6465
module.finite.equiv (add_monoid_hom_lequiv_int ℤ).symm
6566

66-
instance add_monoid_hom : module.free ℤ (M →+ N) :=
67+
instance module.free.add_monoid_hom : module.free ℤ (M →+ N) :=
6768
begin
6869
letI : module.free ℤ (M →ₗ[ℤ] N) := module.free.linear_map _ _ _,
6970
exact module.free.of_equiv (add_monoid_hom_lequiv_int ℤ).symm
@@ -73,25 +74,30 @@ end integer
7374

7475
section comm_ring
7576

76-
open finite_dimensional
77-
7877
variables [comm_ring R] [strong_rank_condition R]
7978
variables [add_comm_group M] [module R M] [module.free R M] [module.finite R M]
8079
variables [add_comm_group N] [module R N] [module.free R N] [module.finite R N]
8180

8281
/-- The finrank of `M →ₗ[R] N` is `(finrank R M) * (finrank R N)`. -/
83-
--TODO: this should follow from `linear_equiv.finrank_eq`, that is over a field.
84-
lemma finrank_linear_hom : finrank R (M →ₗ[R] N) = (finrank R M) * (finrank R N) :=
82+
lemma finite_dimensional.finrank_linear_map :
83+
finrank R (M →ₗ[R] N) = (finrank R M) * (finrank R N) :=
8584
begin
8685
classical,
8786
letI := nontrivial_of_invariant_basis_number R,
8887
have h := (linear_map.to_matrix (choose_basis R M) (choose_basis R N)),
89-
let b := (matrix.std_basis _ _ _).map h.symm,
90-
rw [finrank, rank_eq_card_basis b, ← cardinal.mk_fintype, cardinal.mk_to_nat_eq_card, finrank,
91-
finrank, rank_eq_card_choose_basis_index, rank_eq_card_choose_basis_index,
92-
cardinal.mk_to_nat_eq_card, cardinal.mk_to_nat_eq_card, fintype.card_prod, mul_comm]
88+
simp_rw [h.finrank_eq, finite_dimensional.finrank_matrix,
89+
finite_dimensional.finrank_eq_card_choose_basis_index, mul_comm],
9390
end
9491

9592
end comm_ring
9693

97-
end module.free
94+
lemma matrix.rank_vec_mul_vec {K m n : Type u}
95+
[comm_ring K] [strong_rank_condition K] [fintype n] [decidable_eq n]
96+
(w : m → K) (v : n → K) :
97+
(matrix.vec_mul_vec w v).to_lin'.rank ≤ 1 :=
98+
begin
99+
rw [matrix.vec_mul_vec_eq, matrix.to_lin'_mul],
100+
refine le_trans (linear_map.rank_comp_le_left _ _) _,
101+
refine (linear_map.rank_le_domain _).trans_eq _,
102+
rw [rank_fun', fintype.card_unit, nat.cast_one]
103+
end

src/linear_algebra/free_module/finite/rank.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ end
9090

9191
/-- If `m` and `n` are `fintype`, the finrank of `m × n` matrices is
9292
`(fintype.card m) * (fintype.card n)`. -/
93-
lemma finrank_matrix (m n : Type v) [fintype m] [fintype n] :
93+
lemma finrank_matrix (m n : Type*) [fintype m] [fintype n] :
9494
finrank R (matrix m n R) = (card m) * (card n) :=
9595
by { simp [finrank] }
9696

src/linear_algebra/matrix/diagonal.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
55
-/
66
import linear_algebra.matrix.to_lin
7+
import linear_algebra.free_module.rank
78

89
/-!
910
# Diagonal matrices

src/linear_algebra/matrix/finite_dimensional.lean

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@ Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
55
-/
66
import data.matrix.basic
77
import linear_algebra.finite_dimensional
8+
import linear_algebra.free_module.finite.matrix
9+
import linear_algebra.matrix.to_lin
810

911
/-!
1012
# The finite-dimensional space of matrices
1113
12-
This file shows that `m` by `n` matrices form a finite-dimensional space,
13-
and proves the `finrank` of that space is equal to `card m * card n`.
14+
This file shows that `m` by `n` matrices form a finite-dimensional space.
15+
Note that this is proven more generally elsewhere over modules as `module.finite.matrix`; this file
16+
exists only to provide an entry in the instance list for `finite_dimensional`.
1417
1518
## Main definitions
1619
1720
* `matrix.finite_dimensional`: matrices form a finite dimensional vector space over a field `K`
18-
* `matrix.finrank_matrix`: the `finrank` of `matrix m n R` is `card m * card n`
21+
* `linear_map.finite_dimensional`
1922
2023
## Tags
2124
@@ -32,17 +35,28 @@ section finite_dimensional
3235
variables {m n : Type*} {R : Type v} [field R]
3336

3437
instance [finite m] [finite n] : finite_dimensional R (matrix m n R) :=
35-
linear_equiv.finite_dimensional (linear_equiv.curry R m n)
36-
37-
/--
38-
The dimension of the space of finite dimensional matrices
39-
is the product of the number of rows and columns.
40-
-/
41-
@[simp] lemma finrank_matrix [fintype m] [fintype n] :
42-
finite_dimensional.finrank R (matrix m n R) = fintype.card m * fintype.card n :=
43-
by rw [@linear_equiv.finrank_eq R (matrix m n R) _ _ _ _ _ _ (linear_equiv.curry R m n).symm,
44-
finite_dimensional.finrank_fintype_fun_eq_card, fintype.card_prod]
38+
module.finite.matrix
4539

4640
end finite_dimensional
4741

4842
end matrix
43+
44+
namespace linear_map
45+
46+
variables {K : Type*} [field K]
47+
variables {V : Type*} [add_comm_group V] [module K V] [finite_dimensional K V]
48+
variables {W : Type*} [add_comm_group W] [module K W] [finite_dimensional K W]
49+
50+
instance finite_dimensional : finite_dimensional K (V →ₗ[K] W) :=
51+
module.finite.linear_map _ _
52+
53+
variables {A : Type*} [ring A] [algebra K A] [module A V] [is_scalar_tower K A V]
54+
[module A W] [is_scalar_tower K A W]
55+
56+
/-- Linear maps over a `k`-algebra are finite dimensional (over `k`) if both the source and
57+
target are, as they form a subspace of all `k`-linear maps. -/
58+
instance finite_dimensional' : finite_dimensional K (V →ₗ[A] W) :=
59+
finite_dimensional.of_injective (restrict_scalars_linear_map K A V W)
60+
(restrict_scalars_injective _)
61+
62+
end linear_map

src/linear_algebra/matrix/to_lin.lean

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Authors: Johannes Hölzl, Patrick Massot, Casper Putz, Anne Baanen
55
-/
66
import data.matrix.block
77
import data.matrix.notation
8-
import linear_algebra.matrix.finite_dimensional
98
import linear_algebra.std_basis
109
import ring_theory.algebra_tower
1110
import algebra.module.algebra
@@ -342,17 +341,6 @@ lemma linear_map.to_matrix_alg_equiv'_mul
342341
(f * g).to_matrix_alg_equiv' = f.to_matrix_alg_equiv' ⬝ g.to_matrix_alg_equiv' :=
343342
linear_map.to_matrix_alg_equiv'_comp f g
344343

345-
lemma matrix.rank_vec_mul_vec {K m n : Type u}
346-
[comm_ring K] [strong_rank_condition K] [fintype n] [decidable_eq n]
347-
(w : m → K) (v : n → K) :
348-
rank (vec_mul_vec w v).to_lin' ≤ 1 :=
349-
begin
350-
rw [vec_mul_vec_eq, matrix.to_lin'_mul],
351-
refine le_trans (rank_comp_le_left _ _) _,
352-
refine (rank_le_domain _).trans_eq _,
353-
rw [rank_fun', fintype.card_unit, nat.cast_one]
354-
end
355-
356344
end to_matrix'
357345

358346
section to_matrix
@@ -723,51 +711,6 @@ end lmul_tower
723711

724712
end algebra
725713

726-
namespace linear_map
727-
728-
section finite_dimensional
729-
730-
open_locale classical
731-
732-
variables {K : Type*} [field K]
733-
variables {V : Type*} [add_comm_group V] [module K V] [finite_dimensional K V]
734-
variables {W : Type*} [add_comm_group W] [module K W] [finite_dimensional K W]
735-
736-
instance finite_dimensional : finite_dimensional K (V →ₗ[K] W) :=
737-
linear_equiv.finite_dimensional
738-
(linear_map.to_matrix (basis.of_vector_space K V) (basis.of_vector_space K W)).symm
739-
740-
section
741-
742-
variables {A : Type*} [ring A] [algebra K A] [module A V] [is_scalar_tower K A V]
743-
[module A W] [is_scalar_tower K A W]
744-
745-
/-- Linear maps over a `k`-algebra are finite dimensional (over `k`) if both the source and
746-
target are, as they form a subspace of all `k`-linear maps. -/
747-
instance finite_dimensional' : finite_dimensional K (V →ₗ[A] W) :=
748-
finite_dimensional.of_injective (restrict_scalars_linear_map K A V W)
749-
(restrict_scalars_injective _)
750-
751-
end
752-
753-
/--
754-
The dimension of the space of linear transformations is the product of the dimensions of the
755-
domain and codomain.
756-
-/
757-
@[simp] lemma finrank_linear_map :
758-
finite_dimensional.finrank K (V →ₗ[K] W) =
759-
(finite_dimensional.finrank K V) * (finite_dimensional.finrank K W) :=
760-
begin
761-
let hbV := basis.of_vector_space K V,
762-
let hbW := basis.of_vector_space K W,
763-
rw [linear_equiv.finrank_eq (linear_map.to_matrix hbV hbW), matrix.finrank_matrix,
764-
finite_dimensional.finrank_eq_card_basis hbV, finite_dimensional.finrank_eq_card_basis hbW,
765-
mul_comm],
766-
end
767-
768-
end finite_dimensional
769-
end linear_map
770-
771714
section
772715

773716
variables {R : Type v} [comm_ring R] {n : Type*} [decidable_eq n]

0 commit comments

Comments
 (0)