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

Commit 1cfdf5f

Browse files
committed
chore(linear_algebra/*): Lint (#16362)
Satisfy the `fintype_finite` and `fails_quickly` linters.
1 parent 443c02b commit 1cfdf5f

21 files changed

+118
-101
lines changed

src/geometry/euclidean/basic.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,8 @@ lemma orthogonal_projection_fn_vsub_mem_direction_orthogonal {s : affine_subspac
783783
direction_mk' p s.directionᗮ ▸
784784
vsub_mem_direction (orthogonal_projection_fn_mem_orthogonal p) (self_mem_mk' _ _)
785785

786+
local attribute [instance] affine_subspace.to_add_torsor
787+
786788
/-- The orthogonal projection of a point onto a nonempty affine
787789
subspace, whose direction is complete. The corresponding linear map
788790
(mapping a vector to the difference between the projections of two

src/geometry/euclidean/circumcenter.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ begin
377377
(λ i, hr i (set.mem_univ _))).symm
378378
end
379379

380+
local attribute [instance] affine_subspace.to_add_torsor
381+
380382
/-- The orthogonal projection of a point `p` onto the hyperplane spanned by the simplex's points. -/
381383
def orthogonal_projection_span {n : ℕ} (s : simplex ℝ P n) :
382384
P →ᵃ[ℝ] affine_span ℝ (set.range s.points) :=

src/linear_algebra/affine_space/affine_subspace.lean

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,9 @@ begin
376376
exact vsub_mem_direction hp hq2 }
377377
end
378378

379-
instance to_add_torsor (s : affine_subspace k P) [nonempty s] : add_torsor s.direction s :=
379+
/-- This is not an instance because it loops with `add_torsor.nonempty`. -/
380+
@[reducible] -- See note [reducible non instances]
381+
def to_add_torsor (s : affine_subspace k P) [nonempty s] : add_torsor s.direction s :=
380382
{ vadd := λ a b, ⟨(a:V) +ᵥ (b:P), vadd_mem_of_mem_direction a.2 b.2⟩,
381383
zero_vadd := by simp,
382384
add_vadd := λ a b c, by { ext, apply add_vadd },
@@ -385,6 +387,8 @@ instance to_add_torsor (s : affine_subspace k P) [nonempty s] : add_torsor s.dir
385387
vsub_vadd' := λ a b, by { ext, apply add_torsor.vsub_vadd' },
386388
vadd_vsub' := λ a b, by { ext, apply add_torsor.vadd_vsub' } }
387389

390+
local attribute [instance] to_add_torsor
391+
388392
@[simp, norm_cast] lemma coe_vsub (s : affine_subspace k P) [nonempty s] (a b : s) :
389393
↑(a -ᵥ b) = (a:P) -ᵥ (b:P) :=
390394
rfl

src/linear_algebra/affine_space/finite_dimensional.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ span_of_finite k $ h.vsub h
3939

4040
/-- The `vector_span` of a family indexed by a `fintype` is
4141
finite-dimensional. -/
42-
instance finite_dimensional_vector_span_of_fintype [fintype ι] (p : ι → P) :
42+
instance finite_dimensional_vector_span_range [_root_.finite ι] (p : ι → P) :
4343
finite_dimensional k (vector_span k (set.range p)) :=
4444
finite_dimensional_vector_span_of_finite k (set.finite_range _)
4545

4646
/-- The `vector_span` of a subset of a family indexed by a `fintype`
4747
is finite-dimensional. -/
48-
instance finite_dimensional_vector_span_image_of_fintype [fintype ι] (p : ι → P)
48+
instance finite_dimensional_vector_span_image_of_finite [_root_.finite ι] (p : ι → P)
4949
(s : set ι) : finite_dimensional k (vector_span k (p '' s)) :=
5050
finite_dimensional_vector_span_of_finite k (set.to_finite _)
5151

@@ -57,13 +57,13 @@ lemma finite_dimensional_direction_affine_span_of_finite {s : set P} (h : set.fi
5757

5858
/-- The direction of the affine span of a family indexed by a
5959
`fintype` is finite-dimensional. -/
60-
instance finite_dimensional_direction_affine_span_of_fintype [fintype ι] (p : ι → P) :
60+
instance finite_dimensional_direction_affine_span_range [_root_.finite ι] (p : ι → P) :
6161
finite_dimensional k (affine_span k (set.range p)).direction :=
6262
finite_dimensional_direction_affine_span_of_finite k (set.finite_range _)
6363

6464
/-- The direction of the affine span of a subset of a family indexed
6565
by a `fintype` is finite-dimensional. -/
66-
instance finite_dimensional_direction_affine_span_image_of_fintype [fintype ι] (p : ι → P)
66+
instance finite_dimensional_direction_affine_span_image_of_finite [_root_.finite ι] (p : ι → P)
6767
(s : set ι) : finite_dimensional k (affine_span k (p '' s)).direction :=
6868
finite_dimensional_direction_affine_span_of_finite k (set.to_finite _)
6969

src/linear_algebra/alternating.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ section basis
956956

957957
open alternating_map
958958

959-
variables {ι₁ : Type*} [fintype ι]
959+
variables {ι₁ : Type*} [finite ι]
960960
variables {R' : Type*} {N₁ N₂ : Type*} [comm_semiring R'] [add_comm_monoid N₁] [add_comm_monoid N₂]
961961
variables [module R' N₁] [module R' N₂]
962962

src/linear_algebra/determinant.lean

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,10 @@ begin
246246
simp [coe_det, H, this] }
247247
end
248248

249-
lemma det_zero' {ι : Type*} [fintype ι] [nonempty ι] (b : basis ι A M) :
249+
lemma det_zero' {ι : Type*} [finite ι] [nonempty ι] (b : basis ι A M) :
250250
linear_map.det (0 : M →ₗ[A] M) = 0 :=
251-
by { haveI := classical.dec_eq ι,
252-
rw [← det_to_matrix b, linear_equiv.map_zero, det_zero],
253-
assumption }
251+
by { haveI := classical.dec_eq ι, casesI nonempty_fintype ι,
252+
rwa [← det_to_matrix b, linear_equiv.map_zero, det_zero] }
254253

255254
/-- In a finite-dimensional vector space, the zero map has determinant `1` in dimension `0`,
256255
and `0` otherwise. We give a formula that also works in infinite dimension, where we define
@@ -491,11 +490,14 @@ begin
491490
simp [alternating_map.map_perm, basis.det_self]
492491
end
493492

494-
@[simp] lemma alternating_map.map_basis_eq_zero_iff (f : alternating_map R M R ι) :
493+
@[simp] lemma alternating_map.map_basis_eq_zero_iff {ι : Type*} [decidable_eq ι] [finite ι]
494+
(e : basis ι R M) (f : alternating_map R M R ι) :
495495
f e = 0 ↔ f = 0 :=
496-
⟨λ h, by simpa [h] using f.eq_smul_basis_det e, λ h, h.symm ▸ alternating_map.zero_apply _⟩
496+
⟨λ h, by { casesI nonempty_fintype ι, simpa [h] using f.eq_smul_basis_det e },
497+
λ h, h.symm ▸ alternating_map.zero_apply _⟩
497498

498-
lemma alternating_map.map_basis_ne_zero_iff (f : alternating_map R M R ι) :
499+
lemma alternating_map.map_basis_ne_zero_iff {ι : Type*} [decidable_eq ι] [finite ι]
500+
(e : basis ι R M) (f : alternating_map R M R ι) :
499501
f e ≠ 0 ↔ f ≠ 0 :=
500502
not_congr $ f.map_basis_eq_zero_iff e
501503

src/linear_algebra/dimension.lean

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,19 +988,21 @@ begin
988988
end
989989

990990
section fintype
991-
variable [fintype η]
992991
variables [∀i, add_comm_group (φ i)] [∀i, module K (φ i)]
993992

994993
open linear_map
995994

996-
lemma dim_pi : module.rank K (Πi, φ i) = cardinal.sum (λi, module.rank K (φ i)) :=
995+
lemma dim_pi [finite η] : module.rank K (Πi, φ i) = cardinal.sum (λi, module.rank K (φ i)) :=
997996
begin
997+
casesI nonempty_fintype η,
998998
let b := assume i, basis.of_vector_space K (φ i),
999999
let this : basis (Σ j, _) K (Π j, φ j) := pi.basis b,
10001000
rw [← cardinal.lift_inj, ← this.mk_eq_dim],
10011001
simp [← (b _).mk_range_eq_dim]
10021002
end
10031003

1004+
variable [fintype η]
1005+
10041006
lemma dim_fun {V η : Type u} [fintype η] [add_comm_group V] [module K V] :
10051007
module.rank K (η → V) = fintype.card η * module.rank K V :=
10061008
by rw [dim_pi, cardinal.sum_const', cardinal.mk_fintype]

src/linear_algebra/dual.lean

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -171,19 +171,15 @@ end
171171
theorem to_dual_ker : b.to_dual.ker = ⊥ :=
172172
ker_eq_bot'.mpr b.to_dual_inj
173173

174-
theorem to_dual_range [fin : fintype ι] : b.to_dual.range = ⊤ :=
174+
theorem to_dual_range [_root_.finite ι] : b.to_dual.range = ⊤ :=
175175
begin
176-
rw eq_top_iff',
177-
intro f,
176+
casesI nonempty_fintype ι,
177+
refine eq_top_iff'.2 (λ f, _),
178178
rw linear_map.mem_range,
179-
let lin_comb : ι →₀ R := finsupp.on_finset fin.elems (λ i, f.to_fun (b i)) _,
180-
{ use finsupp.total ι M R b lin_comb,
181-
apply b.ext,
182-
{ intros i,
183-
rw [b.to_dual_eq_repr _ i, repr_total b],
184-
{ refl } } },
185-
{ intros a _,
186-
apply fin.complete }
179+
let lin_comb : ι →₀ R := finsupp.equiv_fun_on_fintype.2 (λ i, f.to_fun (b i)),
180+
refine ⟨finsupp.total ι M R b lin_comb, b.ext $ λ i, _⟩,
181+
rw [b.to_dual_eq_repr _ i, repr_total b],
182+
refl,
187183
end
188184

189185
end comm_semiring
@@ -207,53 +203,52 @@ section comm_ring
207203
variables [comm_ring R] [add_comm_group M] [module R M] [decidable_eq ι]
208204
variables (b : basis ι R M)
209205

206+
section finite
207+
variables [_root_.finite ι]
208+
210209
/-- A vector space is linearly equivalent to its dual space. -/
211210
@[simps]
212-
def to_dual_equiv [fintype ι] : M ≃ₗ[R] (dual R M) :=
211+
def to_dual_equiv : M ≃ₗ[R] dual R M :=
213212
linear_equiv.of_bijective b.to_dual
214213
(ker_eq_bot.mp b.to_dual_ker) (range_eq_top.mp b.to_dual_range)
215214

216215
/-- Maps a basis for `V` to a basis for the dual space. -/
217-
def dual_basis [fintype ι] : basis ι R (dual R M) :=
218-
b.map b.to_dual_equiv
216+
def dual_basis : basis ι R (dual R M) := b.map b.to_dual_equiv
219217

220218
-- We use `j = i` to match `basis.repr_self`
221-
lemma dual_basis_apply_self [fintype ι] (i j : ι) :
222-
b.dual_basis i (b j) = if j = i then 1 else 0 :=
219+
lemma dual_basis_apply_self (i j : ι) : b.dual_basis i (b j) = if j = i then 1 else 0 :=
223220
by { convert b.to_dual_apply i j using 2, rw @eq_comm _ j i }
224221

225-
lemma total_dual_basis [fintype ι] (f : ι →₀ R) (i : ι) :
222+
lemma total_dual_basis (f : ι →₀ R) (i : ι) :
226223
finsupp.total ι (dual R M) R b.dual_basis f (b i) = f i :=
227224
begin
225+
casesI nonempty_fintype ι,
228226
rw [finsupp.total_apply, finsupp.sum_fintype, linear_map.sum_apply],
229227
{ simp_rw [linear_map.smul_apply, smul_eq_mul, dual_basis_apply_self, mul_boole,
230228
finset.sum_ite_eq, if_pos (finset.mem_univ i)] },
231229
{ intro, rw zero_smul },
232230
end
233231

234-
lemma dual_basis_repr [fintype ι] (l : dual R M) (i : ι) :
235-
b.dual_basis.repr l i = l (b i) :=
232+
lemma dual_basis_repr (l : dual R M) (i : ι) : b.dual_basis.repr l i = l (b i) :=
236233
by rw [← total_dual_basis b, basis.total_repr b.dual_basis l]
237234

238-
lemma dual_basis_equiv_fun [fintype ι] (l : dual R M) (i : ι) :
239-
b.dual_basis.equiv_fun l i = l (b i) :=
240-
by rw [basis.equiv_fun_apply, dual_basis_repr]
241-
242-
lemma dual_basis_apply [fintype ι] (i : ι) (m : M) : b.dual_basis i m = b.repr m i :=
243-
b.to_dual_apply_right i m
235+
lemma dual_basis_apply (i : ι) (m : M) : b.dual_basis i m = b.repr m i := b.to_dual_apply_right i m
244236

245-
@[simp] lemma coe_dual_basis [fintype ι] :
246-
⇑b.dual_basis = b.coord :=
247-
by { ext i x, apply dual_basis_apply }
237+
@[simp] lemma coe_dual_basis : ⇑b.dual_basis = b.coord := by { ext i x, apply dual_basis_apply }
248238

249-
@[simp] lemma to_dual_to_dual [fintype ι] :
250-
b.dual_basis.to_dual.comp b.to_dual = dual.eval R M :=
239+
@[simp] lemma to_dual_to_dual : b.dual_basis.to_dual.comp b.to_dual = dual.eval R M :=
251240
begin
252241
refine b.ext (λ i, b.dual_basis.ext (λ j, _)),
253242
rw [linear_map.comp_apply, to_dual_apply_left, coe_to_dual_self, ← coe_dual_basis,
254243
dual.eval_apply, basis.repr_self, finsupp.single_apply, dual_basis_apply_self]
255244
end
256245

246+
end finite
247+
248+
lemma dual_basis_equiv_fun [fintype ι] (l : dual R M) (i : ι) :
249+
b.dual_basis.equiv_fun l i = l (b i) :=
250+
by rw [basis.equiv_fun_apply, dual_basis_repr]
251+
257252
theorem eval_ker {ι : Type*} (b : basis ι R M) :
258253
(dual.eval R M).ker = ⊥ :=
259254
begin
@@ -263,20 +258,20 @@ begin
263258
exact (basis.forall_coord_eq_zero_iff _).mp (λ i, hm (b.coord i))
264259
end
265260

266-
lemma eval_range {ι : Type*} [fintype ι] (b : basis ι R M) :
267-
(eval R M).range = ⊤ :=
261+
lemma eval_range {ι : Type*} [_root_.finite ι] (b : basis ι R M) : (eval R M).range = ⊤ :=
268262
begin
269263
classical,
264+
casesI nonempty_fintype ι,
270265
rw [← b.to_dual_to_dual, range_comp, b.to_dual_range, map_top, to_dual_range _],
271266
apply_instance
272267
end
273268

274269
/-- A module with a basis is linearly equivalent to the dual of its dual space. -/
275-
def eval_equiv {ι : Type*} [fintype ι] (b : basis ι R M) : M ≃ₗ[R] dual R (dual R M) :=
270+
def eval_equiv {ι : Type*} [_root_.finite ι] (b : basis ι R M) : M ≃ₗ[R] dual R (dual R M) :=
276271
linear_equiv.of_bijective (eval R M)
277272
(ker_eq_bot.mp b.eval_ker) (range_eq_top.mp b.eval_range)
278273

279-
@[simp] lemma eval_equiv_to_linear_map {ι : Type*} [fintype ι] (b : basis ι R M) :
274+
@[simp] lemma eval_equiv_to_linear_map {ι : Type*} [_root_.finite ι] (b : basis ι R M) :
280275
(b.eval_equiv).to_linear_map = dual.eval R M := rfl
281276

282277
section
@@ -294,16 +289,17 @@ end
294289
end comm_ring
295290

296291
/-- `simp` normal form version of `total_dual_basis` -/
297-
@[simp] lemma total_coord [comm_ring R] [add_comm_group M] [module R M] [fintype ι]
292+
@[simp] lemma total_coord [comm_ring R] [add_comm_group M] [module R M] [_root_.finite ι]
298293
(b : basis ι R M) (f : ι →₀ R) (i : ι) :
299294
finsupp.total ι (dual R M) R b.coord f (b i) = f i :=
300295
by { haveI := classical.dec_eq ι, rw [← coe_dual_basis, total_dual_basis] }
301296

302-
-- TODO(jmc): generalize to rings, once `module.rank` is generalized
303-
theorem dual_dim_eq [field K] [add_comm_group V] [module K V] [fintype ι] (b : basis ι K V) :
297+
lemma dual_dim_eq [comm_ring K] [add_comm_group V] [module K V] [_root_.finite ι]
298+
(b : basis ι K V) :
304299
cardinal.lift (module.rank K V) = module.rank K (dual K V) :=
305300
begin
306301
classical,
302+
casesI nonempty_fintype ι,
307303
have := linear_equiv.lift_dim_eq b.to_dual_equiv,
308304
simp only [cardinal.lift_umax] at this,
309305
rw [this, ← cardinal.lift_umax],

src/linear_algebra/finsupp_vector_space.lean

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ begin
200200
... = _ : by rw [← cardinal.lift_inj.1 hs.mk_eq_dim, cardinal.power_def]
201201
end
202202

203-
lemma cardinal_lt_aleph_0_of_finite_dimensional [fintype K] [finite_dimensional K V] : #V < ℵ₀ :=
203+
lemma cardinal_lt_aleph_0_of_finite_dimensional [_root_.finite K] [finite_dimensional K V] :
204+
#V < ℵ₀ :=
204205
begin
205206
letI : is_noetherian K V := is_noetherian.iff_fg.2 infer_instance,
206207
rw cardinal_mk_eq_cardinal_mk_field_pow_dim K V,

src/linear_algebra/free_module/finite/basic.lean

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,22 @@ begin
5959
(linear_map.to_matrix (module.free.choose_basis R M) (module.free.choose_basis R N)).symm,
6060
end
6161

62-
variables {R M}
62+
variables {R}
6363

6464
/-- A free module with a basis indexed by a `fintype` is finite. -/
65-
lemma _root_.module.finite.of_basis {R : Type*} {M : Type*} {ι : Type*} [comm_ring R]
66-
[add_comm_group M] [module R M] [fintype ι] (b : basis ι R M) : module.finite R M :=
65+
lemma _root_.module.finite.of_basis {R M ι : Type*} [comm_ring R] [add_comm_group M] [module R M]
66+
[finite ι] (b : basis ι R M) : module.finite R M :=
6767
begin
68+
casesI nonempty_fintype ι,
6869
classical,
6970
refine ⟨⟨finset.univ.image b, _⟩⟩,
7071
simp only [set.image_univ, finset.coe_univ, finset.coe_image, basis.span_eq],
7172
end
7273

73-
instance _root_.module.finite.matrix {ι₁ : Type*} [fintype ι₁] {ι₂ : Type*} [fintype ι₂] :
74+
instance _root_.module.finite.matrix {ι₁ ι₂ : Type*} [finite ι₁] [finite ι₂] :
7475
module.finite R (matrix ι₁ ι₂ R) :=
75-
module.finite.of_basis $ pi.basis $ λ i, pi.basis_fun R _
76-
77-
variables (M)
76+
by { casesI nonempty_fintype ι₁, casesI nonempty_fintype ι₂,
77+
exact module.finite.of_basis (pi.basis $ λ i, pi.basis_fun R _) }
7878

7979
instance _root_.module.finite.linear_map [module.finite R M] [module.finite R N] :
8080
module.finite R (M →ₗ[R] N) :=

0 commit comments

Comments
 (0)