-
Notifications
You must be signed in to change notification settings - Fork 257
/
Basis.lean
1620 lines (1350 loc) · 66.4 KB
/
Basis.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Alexander Bentkamp
-/
import Mathlib.Algebra.BigOperators.Finsupp
import Mathlib.Algebra.BigOperators.Finprod
import Mathlib.Data.Fintype.BigOperators
import Mathlib.LinearAlgebra.Finsupp
import Mathlib.LinearAlgebra.LinearIndependent
import Mathlib.SetTheory.Cardinal.Cofinality
#align_import linear_algebra.basis from "leanprover-community/mathlib"@"13bce9a6b6c44f6b4c91ac1c1d2a816e2533d395"
/-!
# Bases
This file defines bases in a module or vector space.
It is inspired by Isabelle/HOL's linear algebra, and hence indirectly by HOL Light.
## Main definitions
All definitions are given for families of vectors, i.e. `v : ι → M` where `M` is the module or
vector space and `ι : Type*` is an arbitrary indexing type.
* `Basis ι R M` is the type of `ι`-indexed `R`-bases for a module `M`,
represented by a linear equiv `M ≃ₗ[R] ι →₀ R`.
* the basis vectors of a basis `b : Basis ι R M` are available as `b i`, where `i : ι`
* `Basis.repr` is the isomorphism sending `x : M` to its coordinates `Basis.repr x : ι →₀ R`.
The converse, turning this isomorphism into a basis, is called `Basis.ofRepr`.
* If `ι` is finite, there is a variant of `repr` called `Basis.equivFun b : M ≃ₗ[R] ι → R`
(saving you from having to work with `Finsupp`). The converse, turning this isomorphism into
a basis, is called `Basis.ofEquivFun`.
* `Basis.constr b R f` constructs a linear map `M₁ →ₗ[R] M₂` given the values `f : ι → M₂` at the
basis elements `⇑b : ι → M₁`.
* `Basis.reindex` uses an equiv to map a basis to a different indexing set.
* `Basis.map` uses a linear equiv to map a basis to a different module.
## Main statements
* `Basis.mk`: a linear independent set of vectors spanning the whole module determines a basis
* `Basis.ext` states that two linear maps are equal if they coincide on a basis.
Similar results are available for linear equivs (if they coincide on the basis vectors),
elements (if their coordinates coincide) and the functions `b.repr` and `⇑b`.
## Implementation notes
We use families instead of sets because it allows us to say that two identical vectors are linearly
dependent. For bases, this is useful as well because we can easily derive ordered bases by using an
ordered index type `ι`.
## Tags
basis, bases
-/
noncomputable section
universe u
open Function Set Submodule
open BigOperators
variable {ι : Type*} {ι' : Type*} {R : Type*} {R₂ : Type*} {K : Type*}
variable {M : Type*} {M' M'' : Type*} {V : Type u} {V' : Type*}
section Module
variable [Semiring R]
variable [AddCommMonoid M] [Module R M] [AddCommMonoid M'] [Module R M']
section
variable (ι R M)
/-- A `Basis ι R M` for a module `M` is the type of `ι`-indexed `R`-bases of `M`.
The basis vectors are available as `DFunLike.coe (b : Basis ι R M) : ι → M`.
To turn a linear independent family of vectors spanning `M` into a basis, use `Basis.mk`.
They are internally represented as linear equivs `M ≃ₗ[R] (ι →₀ R)`,
available as `Basis.repr`.
-/
structure Basis where
/-- `Basis.ofRepr` constructs a basis given an assignment of coordinates to each vector. -/
ofRepr ::
/-- `repr` is the linear equivalence sending a vector `x` to its coordinates:
the `c`s such that `x = ∑ i, c i`. -/
repr : M ≃ₗ[R] ι →₀ R
#align basis Basis
#align basis.repr Basis.repr
#align basis.of_repr Basis.ofRepr
end
instance uniqueBasis [Subsingleton R] : Unique (Basis ι R M) :=
⟨⟨⟨default⟩⟩, fun ⟨b⟩ => by rw [Subsingleton.elim b]⟩
#align unique_basis uniqueBasis
namespace Basis
instance : Inhabited (Basis ι R (ι →₀ R)) :=
⟨.ofRepr (LinearEquiv.refl _ _)⟩
variable (b b₁ : Basis ι R M) (i : ι) (c : R) (x : M)
section repr
theorem repr_injective : Injective (repr : Basis ι R M → M ≃ₗ[R] ι →₀ R) := fun f g h => by
cases f; cases g; congr
#align basis.repr_injective Basis.repr_injective
/-- `b i` is the `i`th basis vector. -/
instance instFunLike : FunLike (Basis ι R M) ι M where
coe b i := b.repr.symm (Finsupp.single i 1)
coe_injective' f g h := repr_injective <| LinearEquiv.symm_bijective.injective <|
LinearEquiv.toLinearMap_injective <| by ext; exact congr_fun h _
#align basis.fun_like Basis.instFunLike
@[simp]
theorem coe_ofRepr (e : M ≃ₗ[R] ι →₀ R) : ⇑(ofRepr e) = fun i => e.symm (Finsupp.single i 1) :=
rfl
#align basis.coe_of_repr Basis.coe_ofRepr
protected theorem injective [Nontrivial R] : Injective b :=
b.repr.symm.injective.comp fun _ _ => (Finsupp.single_left_inj (one_ne_zero : (1 : R) ≠ 0)).mp
#align basis.injective Basis.injective
theorem repr_symm_single_one : b.repr.symm (Finsupp.single i 1) = b i :=
rfl
#align basis.repr_symm_single_one Basis.repr_symm_single_one
theorem repr_symm_single : b.repr.symm (Finsupp.single i c) = c • b i :=
calc
b.repr.symm (Finsupp.single i c) = b.repr.symm (c • Finsupp.single i (1 : R)) := by
{ rw [Finsupp.smul_single', mul_one] }
_ = c • b i := by rw [LinearEquiv.map_smul, repr_symm_single_one]
#align basis.repr_symm_single Basis.repr_symm_single
@[simp]
theorem repr_self : b.repr (b i) = Finsupp.single i 1 :=
LinearEquiv.apply_symm_apply _ _
#align basis.repr_self Basis.repr_self
theorem repr_self_apply (j) [Decidable (i = j)] : b.repr (b i) j = if i = j then 1 else 0 := by
rw [repr_self, Finsupp.single_apply]
#align basis.repr_self_apply Basis.repr_self_apply
@[simp]
theorem repr_symm_apply (v) : b.repr.symm v = Finsupp.total ι M R b v :=
calc
b.repr.symm v = b.repr.symm (v.sum Finsupp.single) := by simp
_ = v.sum fun i vi => b.repr.symm (Finsupp.single i vi) := map_finsupp_sum ..
_ = Finsupp.total ι M R b v := by simp only [repr_symm_single, Finsupp.total_apply]
#align basis.repr_symm_apply Basis.repr_symm_apply
@[simp]
theorem coe_repr_symm : ↑b.repr.symm = Finsupp.total ι M R b :=
LinearMap.ext fun v => b.repr_symm_apply v
#align basis.coe_repr_symm Basis.coe_repr_symm
@[simp]
theorem repr_total (v) : b.repr (Finsupp.total _ _ _ b v) = v := by
rw [← b.coe_repr_symm]
exact b.repr.apply_symm_apply v
#align basis.repr_total Basis.repr_total
@[simp]
theorem total_repr : Finsupp.total _ _ _ b (b.repr x) = x := by
rw [← b.coe_repr_symm]
exact b.repr.symm_apply_apply x
#align basis.total_repr Basis.total_repr
theorem repr_range : LinearMap.range (b.repr : M →ₗ[R] ι →₀ R) = Finsupp.supported R R univ := by
rw [LinearEquiv.range, Finsupp.supported_univ]
#align basis.repr_range Basis.repr_range
theorem mem_span_repr_support (m : M) : m ∈ span R (b '' (b.repr m).support) :=
(Finsupp.mem_span_image_iff_total _).2 ⟨b.repr m, by simp [Finsupp.mem_supported_support]⟩
#align basis.mem_span_repr_support Basis.mem_span_repr_support
theorem repr_support_subset_of_mem_span (s : Set ι) {m : M}
(hm : m ∈ span R (b '' s)) : ↑(b.repr m).support ⊆ s := by
rcases (Finsupp.mem_span_image_iff_total _).1 hm with ⟨l, hl, rfl⟩
rwa [repr_total, ← Finsupp.mem_supported R l]
#align basis.repr_support_subset_of_mem_span Basis.repr_support_subset_of_mem_span
theorem mem_span_image {m : M} {s : Set ι} : m ∈ span R (b '' s) ↔ ↑(b.repr m).support ⊆ s :=
⟨repr_support_subset_of_mem_span _ _, fun h ↦
span_mono (image_subset _ h) (mem_span_repr_support b _)⟩
@[simp]
theorem self_mem_span_image [Nontrivial R] {i : ι} {s : Set ι} :
b i ∈ span R (b '' s) ↔ i ∈ s := by
simp [mem_span_image, Finsupp.support_single_ne_zero]
end repr
section Coord
/-- `b.coord i` is the linear function giving the `i`'th coordinate of a vector
with respect to the basis `b`.
`b.coord i` is an element of the dual space. In particular, for
finite-dimensional spaces it is the `ι`th basis vector of the dual space.
-/
@[simps!]
def coord : M →ₗ[R] R :=
Finsupp.lapply i ∘ₗ ↑b.repr
#align basis.coord Basis.coord
theorem forall_coord_eq_zero_iff {x : M} : (∀ i, b.coord i x = 0) ↔ x = 0 :=
Iff.trans (by simp only [b.coord_apply, DFunLike.ext_iff, Finsupp.zero_apply])
b.repr.map_eq_zero_iff
#align basis.forall_coord_eq_zero_iff Basis.forall_coord_eq_zero_iff
/-- The sum of the coordinates of an element `m : M` with respect to a basis. -/
noncomputable def sumCoords : M →ₗ[R] R :=
(Finsupp.lsum ℕ fun _ => LinearMap.id) ∘ₗ (b.repr : M →ₗ[R] ι →₀ R)
#align basis.sum_coords Basis.sumCoords
@[simp]
theorem coe_sumCoords : (b.sumCoords : M → R) = fun m => (b.repr m).sum fun _ => id :=
rfl
#align basis.coe_sum_coords Basis.coe_sumCoords
theorem coe_sumCoords_eq_finsum : (b.sumCoords : M → R) = fun m => ∑ᶠ i, b.coord i m := by
ext m
simp only [Basis.sumCoords, Basis.coord, Finsupp.lapply_apply, LinearMap.id_coe,
LinearEquiv.coe_coe, Function.comp_apply, Finsupp.coe_lsum, LinearMap.coe_comp,
finsum_eq_sum _ (b.repr m).finite_support, Finsupp.sum, Finset.finite_toSet_toFinset, id.def,
Finsupp.fun_support_eq]
#align basis.coe_sum_coords_eq_finsum Basis.coe_sumCoords_eq_finsum
@[simp high]
theorem coe_sumCoords_of_fintype [Fintype ι] : (b.sumCoords : M → R) = ∑ i, b.coord i := by
ext m
-- Porting note: - `eq_self_iff_true`
-- + `comp_apply` `LinearMap.coeFn_sum`
simp only [sumCoords, Finsupp.sum_fintype, LinearMap.id_coe, LinearEquiv.coe_coe, coord_apply,
id.def, Fintype.sum_apply, imp_true_iff, Finsupp.coe_lsum, LinearMap.coe_comp, comp_apply,
LinearMap.coeFn_sum]
#align basis.coe_sum_coords_of_fintype Basis.coe_sumCoords_of_fintype
@[simp]
theorem sumCoords_self_apply : b.sumCoords (b i) = 1 := by
simp only [Basis.sumCoords, LinearMap.id_coe, LinearEquiv.coe_coe, id.def, Basis.repr_self,
Function.comp_apply, Finsupp.coe_lsum, LinearMap.coe_comp, Finsupp.sum_single_index]
#align basis.sum_coords_self_apply Basis.sumCoords_self_apply
theorem dvd_coord_smul (i : ι) (m : M) (r : R) : r ∣ b.coord i (r • m) :=
⟨b.coord i m, by simp⟩
#align basis.dvd_coord_smul Basis.dvd_coord_smul
theorem coord_repr_symm (b : Basis ι R M) (i : ι) (f : ι →₀ R) :
b.coord i (b.repr.symm f) = f i := by
simp only [repr_symm_apply, coord_apply, repr_total]
#align basis.coord_repr_symm Basis.coord_repr_symm
end Coord
section Ext
variable {R₁ : Type*} [Semiring R₁] {σ : R →+* R₁} {σ' : R₁ →+* R}
variable [RingHomInvPair σ σ'] [RingHomInvPair σ' σ]
variable {M₁ : Type*} [AddCommMonoid M₁] [Module R₁ M₁]
/-- Two linear maps are equal if they are equal on basis vectors. -/
theorem ext {f₁ f₂ : M →ₛₗ[σ] M₁} (h : ∀ i, f₁ (b i) = f₂ (b i)) : f₁ = f₂ := by
ext x
rw [← b.total_repr x, Finsupp.total_apply, Finsupp.sum]
simp only [map_sum, LinearMap.map_smulₛₗ, h]
#align basis.ext Basis.ext
/-- Two linear equivs are equal if they are equal on basis vectors. -/
theorem ext' {f₁ f₂ : M ≃ₛₗ[σ] M₁} (h : ∀ i, f₁ (b i) = f₂ (b i)) : f₁ = f₂ := by
ext x
rw [← b.total_repr x, Finsupp.total_apply, Finsupp.sum]
simp only [map_sum, LinearEquiv.map_smulₛₗ, h]
#align basis.ext' Basis.ext'
/-- Two elements are equal iff their coordinates are equal. -/
theorem ext_elem_iff {x y : M} : x = y ↔ ∀ i, b.repr x i = b.repr y i := by
simp only [← DFunLike.ext_iff, EmbeddingLike.apply_eq_iff_eq]
#align basis.ext_elem_iff Basis.ext_elem_iff
alias ⟨_, _root_.Basis.ext_elem⟩ := ext_elem_iff
#align basis.ext_elem Basis.ext_elem
theorem repr_eq_iff {b : Basis ι R M} {f : M →ₗ[R] ι →₀ R} :
↑b.repr = f ↔ ∀ i, f (b i) = Finsupp.single i 1 :=
⟨fun h i => h ▸ b.repr_self i, fun h => b.ext fun i => (b.repr_self i).trans (h i).symm⟩
#align basis.repr_eq_iff Basis.repr_eq_iff
theorem repr_eq_iff' {b : Basis ι R M} {f : M ≃ₗ[R] ι →₀ R} :
b.repr = f ↔ ∀ i, f (b i) = Finsupp.single i 1 :=
⟨fun h i => h ▸ b.repr_self i, fun h => b.ext' fun i => (b.repr_self i).trans (h i).symm⟩
#align basis.repr_eq_iff' Basis.repr_eq_iff'
theorem apply_eq_iff {b : Basis ι R M} {x : M} {i : ι} : b i = x ↔ b.repr x = Finsupp.single i 1 :=
⟨fun h => h ▸ b.repr_self i, fun h => b.repr.injective ((b.repr_self i).trans h.symm)⟩
#align basis.apply_eq_iff Basis.apply_eq_iff
/-- An unbundled version of `repr_eq_iff` -/
theorem repr_apply_eq (f : M → ι → R) (hadd : ∀ x y, f (x + y) = f x + f y)
(hsmul : ∀ (c : R) (x : M), f (c • x) = c • f x) (f_eq : ∀ i, f (b i) = Finsupp.single i 1)
(x : M) (i : ι) : b.repr x i = f x i := by
let f_i : M →ₗ[R] R :=
{ toFun := fun x => f x i
-- Porting note: `dsimp only []` is required for beta reduction.
map_add' := fun _ _ => by dsimp only []; rw [hadd, Pi.add_apply]
map_smul' := fun _ _ => by simp [hsmul, Pi.smul_apply] }
have : Finsupp.lapply i ∘ₗ ↑b.repr = f_i := by
refine' b.ext fun j => _
show b.repr (b j) i = f (b j) i
rw [b.repr_self, f_eq]
calc
b.repr x i = f_i x := by
{ rw [← this]
rfl }
_ = f x i := rfl
#align basis.repr_apply_eq Basis.repr_apply_eq
/-- Two bases are equal if they assign the same coordinates. -/
theorem eq_ofRepr_eq_repr {b₁ b₂ : Basis ι R M} (h : ∀ x i, b₁.repr x i = b₂.repr x i) : b₁ = b₂ :=
repr_injective <| by ext; apply h
#align basis.eq_of_repr_eq_repr Basis.eq_ofRepr_eq_repr
/-- Two bases are equal if their basis vectors are the same. -/
@[ext]
theorem eq_of_apply_eq {b₁ b₂ : Basis ι R M} : (∀ i, b₁ i = b₂ i) → b₁ = b₂ :=
DFunLike.ext _ _
#align basis.eq_of_apply_eq Basis.eq_of_apply_eq
end Ext
section Map
variable (f : M ≃ₗ[R] M')
/-- Apply the linear equivalence `f` to the basis vectors. -/
@[simps]
protected def map : Basis ι R M' :=
ofRepr (f.symm.trans b.repr)
#align basis.map Basis.map
@[simp]
theorem map_apply (i) : b.map f i = f (b i) :=
rfl
#align basis.map_apply Basis.map_apply
theorem coe_map : (b.map f : ι → M') = f ∘ b :=
rfl
end Map
section MapCoeffs
variable {R' : Type*} [Semiring R'] [Module R' M] (f : R ≃+* R')
(h : ∀ (c) (x : M), f c • x = c • x)
attribute [local instance] SMul.comp.isScalarTower
/-- If `R` and `R'` are isomorphic rings that act identically on a module `M`,
then a basis for `M` as `R`-module is also a basis for `M` as `R'`-module.
See also `Basis.algebraMapCoeffs` for the case where `f` is equal to `algebraMap`.
-/
@[simps (config := { simpRhs := true })]
def mapCoeffs : Basis ι R' M := by
letI : Module R' R := Module.compHom R (↑f.symm : R' →+* R)
haveI : IsScalarTower R' R M :=
{ smul_assoc := fun x y z => by
-- Porting note: `dsimp [(· • ·)]` is unavailable because
-- `HSMul.hsmul` becomes `SMul.smul`.
change (f.symm x * y) • z = x • (y • z)
rw [mul_smul, ← h, f.apply_symm_apply] }
exact ofRepr <| (b.repr.restrictScalars R').trans <|
Finsupp.mapRange.linearEquiv (Module.compHom.toLinearEquiv f.symm).symm
#align basis.map_coeffs Basis.mapCoeffs
theorem mapCoeffs_apply (i : ι) : b.mapCoeffs f h i = b i :=
apply_eq_iff.mpr <| by
-- Porting note: in Lean 3, these were automatically inferred from the definition of
-- `mapCoeffs`.
letI : Module R' R := Module.compHom R (↑f.symm : R' →+* R)
haveI : IsScalarTower R' R M :=
{ smul_assoc := fun x y z => by
-- Porting note: `dsimp [(· • ·)]` is unavailable because
-- `HSMul.hsmul` becomes `SMul.smul`.
change (f.symm x * y) • z = x • (y • z)
rw [mul_smul, ← h, f.apply_symm_apply] }
simp
#align basis.map_coeffs_apply Basis.mapCoeffs_apply
@[simp]
theorem coe_mapCoeffs : (b.mapCoeffs f h : ι → M) = b :=
funext <| b.mapCoeffs_apply f h
#align basis.coe_map_coeffs Basis.coe_mapCoeffs
end MapCoeffs
section Reindex
variable (b' : Basis ι' R M')
variable (e : ι ≃ ι')
/-- `b.reindex (e : ι ≃ ι')` is a basis indexed by `ι'` -/
def reindex : Basis ι' R M :=
.ofRepr (b.repr.trans (Finsupp.domLCongr e))
#align basis.reindex Basis.reindex
theorem reindex_apply (i' : ι') : b.reindex e i' = b (e.symm i') :=
show (b.repr.trans (Finsupp.domLCongr e)).symm (Finsupp.single i' 1) =
b.repr.symm (Finsupp.single (e.symm i') 1)
by rw [LinearEquiv.symm_trans_apply, Finsupp.domLCongr_symm, Finsupp.domLCongr_single]
#align basis.reindex_apply Basis.reindex_apply
@[simp]
theorem coe_reindex : (b.reindex e : ι' → M) = b ∘ e.symm :=
funext (b.reindex_apply e)
#align basis.coe_reindex Basis.coe_reindex
theorem repr_reindex_apply (i' : ι') : (b.reindex e).repr x i' = b.repr x (e.symm i') :=
show (Finsupp.domLCongr e : _ ≃ₗ[R] _) (b.repr x) i' = _ by simp
#align basis.repr_reindex_apply Basis.repr_reindex_apply
@[simp]
theorem repr_reindex : (b.reindex e).repr x = (b.repr x).mapDomain e :=
DFunLike.ext _ _ <| by simp [repr_reindex_apply]
#align basis.repr_reindex Basis.repr_reindex
@[simp]
theorem reindex_refl : b.reindex (Equiv.refl ι) = b :=
eq_of_apply_eq fun i => by simp
#align basis.reindex_refl Basis.reindex_refl
/-- `simp` can prove this as `Basis.coe_reindex` + `EquivLike.range_comp` -/
theorem range_reindex : Set.range (b.reindex e) = Set.range b := by
simp [coe_reindex, range_comp]
#align basis.range_reindex Basis.range_reindex
@[simp]
theorem sumCoords_reindex : (b.reindex e).sumCoords = b.sumCoords := by
ext x
simp only [coe_sumCoords, repr_reindex]
exact Finsupp.sum_mapDomain_index (fun _ => rfl) fun _ _ _ => rfl
#align basis.sum_coords_reindex Basis.sumCoords_reindex
/-- `b.reindex_range` is a basis indexed by `range b`, the basis vectors themselves. -/
def reindexRange : Basis (range b) R M :=
haveI := Classical.dec (Nontrivial R)
if h : Nontrivial R then
letI := h
b.reindex (Equiv.ofInjective b (Basis.injective b))
else
letI : Subsingleton R := not_nontrivial_iff_subsingleton.mp h
.ofRepr (Module.subsingletonEquiv R M (range b))
#align basis.reindex_range Basis.reindexRange
theorem reindexRange_self (i : ι) (h := Set.mem_range_self i) : b.reindexRange ⟨b i, h⟩ = b i := by
by_cases htr : Nontrivial R
· letI := htr
simp [htr, reindexRange, reindex_apply, Equiv.apply_ofInjective_symm b.injective,
Subtype.coe_mk]
· letI : Subsingleton R := not_nontrivial_iff_subsingleton.mp htr
letI := Module.subsingleton R M
simp [reindexRange, eq_iff_true_of_subsingleton]
#align basis.reindex_range_self Basis.reindexRange_self
theorem reindexRange_repr_self (i : ι) :
b.reindexRange.repr (b i) = Finsupp.single ⟨b i, mem_range_self i⟩ 1 :=
calc
b.reindexRange.repr (b i) = b.reindexRange.repr (b.reindexRange ⟨b i, mem_range_self i⟩) :=
congr_arg _ (b.reindexRange_self _ _).symm
_ = Finsupp.single ⟨b i, mem_range_self i⟩ 1 := b.reindexRange.repr_self _
#align basis.reindex_range_repr_self Basis.reindexRange_repr_self
@[simp]
theorem reindexRange_apply (x : range b) : b.reindexRange x = x := by
rcases x with ⟨bi, ⟨i, rfl⟩⟩
exact b.reindexRange_self i
#align basis.reindex_range_apply Basis.reindexRange_apply
theorem reindexRange_repr' (x : M) {bi : M} {i : ι} (h : b i = bi) :
b.reindexRange.repr x ⟨bi, ⟨i, h⟩⟩ = b.repr x i := by
nontriviality
subst h
apply (b.repr_apply_eq (fun x i => b.reindexRange.repr x ⟨b i, _⟩) _ _ _ x i).symm
· intro x y
ext i
simp only [Pi.add_apply, LinearEquiv.map_add, Finsupp.coe_add]
· intro c x
ext i
simp only [Pi.smul_apply, LinearEquiv.map_smul, Finsupp.coe_smul]
· intro i
ext j
simp only [reindexRange_repr_self]
apply Finsupp.single_apply_left (f := fun i => (⟨b i, _⟩ : Set.range b))
exact fun i j h => b.injective (Subtype.mk.inj h)
#align basis.reindex_range_repr' Basis.reindexRange_repr'
@[simp]
theorem reindexRange_repr (x : M) (i : ι) (h := Set.mem_range_self i) :
b.reindexRange.repr x ⟨b i, h⟩ = b.repr x i :=
b.reindexRange_repr' _ rfl
#align basis.reindex_range_repr Basis.reindexRange_repr
section Fintype
variable [Fintype ι] [DecidableEq M]
/-- `b.reindexFinsetRange` is a basis indexed by `Finset.univ.image b`,
the finite set of basis vectors themselves. -/
def reindexFinsetRange : Basis (Finset.univ.image b) R M :=
b.reindexRange.reindex ((Equiv.refl M).subtypeEquiv (by simp))
#align basis.reindex_finset_range Basis.reindexFinsetRange
theorem reindexFinsetRange_self (i : ι) (h := Finset.mem_image_of_mem b (Finset.mem_univ i)) :
b.reindexFinsetRange ⟨b i, h⟩ = b i := by
rw [reindexFinsetRange, reindex_apply, reindexRange_apply]
rfl
#align basis.reindex_finset_range_self Basis.reindexFinsetRange_self
@[simp]
theorem reindexFinsetRange_apply (x : Finset.univ.image b) : b.reindexFinsetRange x = x := by
rcases x with ⟨bi, hbi⟩
rcases Finset.mem_image.mp hbi with ⟨i, -, rfl⟩
exact b.reindexFinsetRange_self i
#align basis.reindex_finset_range_apply Basis.reindexFinsetRange_apply
theorem reindexFinsetRange_repr_self (i : ι) :
b.reindexFinsetRange.repr (b i) =
Finsupp.single ⟨b i, Finset.mem_image_of_mem b (Finset.mem_univ i)⟩ 1 := by
ext ⟨bi, hbi⟩
rw [reindexFinsetRange, repr_reindex, Finsupp.mapDomain_equiv_apply, reindexRange_repr_self]
-- Porting note: replaced a `convert; refl` with `simp`
simp [Finsupp.single_apply]
#align basis.reindex_finset_range_repr_self Basis.reindexFinsetRange_repr_self
@[simp]
theorem reindexFinsetRange_repr (x : M) (i : ι)
(h := Finset.mem_image_of_mem b (Finset.mem_univ i)) :
b.reindexFinsetRange.repr x ⟨b i, h⟩ = b.repr x i := by simp [reindexFinsetRange]
#align basis.reindex_finset_range_repr Basis.reindexFinsetRange_repr
end Fintype
end Reindex
protected theorem linearIndependent : LinearIndependent R b :=
linearIndependent_iff.mpr fun l hl =>
calc
l = b.repr (Finsupp.total _ _ _ b l) := (b.repr_total l).symm
_ = 0 := by rw [hl, LinearEquiv.map_zero]
#align basis.linear_independent Basis.linearIndependent
protected theorem ne_zero [Nontrivial R] (i) : b i ≠ 0 :=
b.linearIndependent.ne_zero i
#align basis.ne_zero Basis.ne_zero
protected theorem mem_span (x : M) : x ∈ span R (range b) :=
span_mono (image_subset_range _ _) (mem_span_repr_support b x)
#align basis.mem_span Basis.mem_span
@[simp]
protected theorem span_eq : span R (range b) = ⊤ :=
eq_top_iff.mpr fun x _ => b.mem_span x
#align basis.span_eq Basis.span_eq
theorem index_nonempty (b : Basis ι R M) [Nontrivial M] : Nonempty ι := by
obtain ⟨x, y, ne⟩ : ∃ x y : M, x ≠ y := Nontrivial.exists_pair_ne
obtain ⟨i, _⟩ := not_forall.mp (mt b.ext_elem_iff.2 ne)
exact ⟨i⟩
#align basis.index_nonempty Basis.index_nonempty
/-- If the submodule `P` has a basis, `x ∈ P` iff it is a linear combination of basis vectors. -/
theorem mem_submodule_iff {P : Submodule R M} (b : Basis ι R P) {x : M} :
x ∈ P ↔ ∃ c : ι →₀ R, x = Finsupp.sum c fun i x => x • (b i : M) := by
conv_lhs =>
rw [← P.range_subtype, ← Submodule.map_top, ← b.span_eq, Submodule.map_span, ← Set.range_comp,
← Finsupp.range_total]
simp [@eq_comm _ x, Function.comp, Finsupp.total_apply]
#align basis.mem_submodule_iff Basis.mem_submodule_iff
section Constr
variable (S : Type*) [Semiring S] [Module S M']
variable [SMulCommClass R S M']
/-- Construct a linear map given the value at the basis, called `Basis.constr b S f` where `b` is
a basis, `f` is the value of the linear map over the elements of the basis, and `S` is an
extra semiring (typically `S = R` or `S = ℕ`).
This definition is parameterized over an extra `Semiring S`,
such that `SMulCommClass R S M'` holds.
If `R` is commutative, you can set `S := R`; if `R` is not commutative,
you can recover an `AddEquiv` by setting `S := ℕ`.
See library note [bundled maps over different rings].
-/
def constr : (ι → M') ≃ₗ[S] M →ₗ[R] M' where
toFun f := (Finsupp.total M' M' R id).comp <| Finsupp.lmapDomain R R f ∘ₗ ↑b.repr
invFun f i := f (b i)
left_inv f := by
ext
simp
right_inv f := by
refine' b.ext fun i => _
simp
map_add' f g := by
refine' b.ext fun i => _
simp
map_smul' c f := by
refine' b.ext fun i => _
simp
#align basis.constr Basis.constr
theorem constr_def (f : ι → M') :
constr (M' := M') b S f = Finsupp.total M' M' R id ∘ₗ Finsupp.lmapDomain R R f ∘ₗ ↑b.repr :=
rfl
#align basis.constr_def Basis.constr_def
theorem constr_apply (f : ι → M') (x : M) :
constr (M' := M') b S f x = (b.repr x).sum fun b a => a • f b := by
simp only [constr_def, LinearMap.comp_apply, Finsupp.lmapDomain_apply, Finsupp.total_apply]
rw [Finsupp.sum_mapDomain_index] <;> simp [add_smul]
#align basis.constr_apply Basis.constr_apply
@[simp]
theorem constr_basis (f : ι → M') (i : ι) : (constr (M' := M') b S f : M → M') (b i) = f i := by
simp [Basis.constr_apply, b.repr_self]
#align basis.constr_basis Basis.constr_basis
theorem constr_eq {g : ι → M'} {f : M →ₗ[R] M'} (h : ∀ i, g i = f (b i)) :
constr (M' := M') b S g = f :=
b.ext fun i => (b.constr_basis S g i).trans (h i)
#align basis.constr_eq Basis.constr_eq
theorem constr_self (f : M →ₗ[R] M') : (constr (M' := M') b S fun i => f (b i)) = f :=
b.constr_eq S fun _ => rfl
#align basis.constr_self Basis.constr_self
theorem constr_range {f : ι → M'} :
LinearMap.range (constr (M' := M') b S f) = span R (range f) := by
rw [b.constr_def S f, LinearMap.range_comp, LinearMap.range_comp, LinearEquiv.range, ←
Finsupp.supported_univ, Finsupp.lmapDomain_supported, ← Set.image_univ, ←
Finsupp.span_image_eq_map_total, Set.image_id]
#align basis.constr_range Basis.constr_range
@[simp]
theorem constr_comp (f : M' →ₗ[R] M') (v : ι → M') :
constr (M' := M') b S (f ∘ v) = f.comp (constr (M' := M') b S v) :=
b.ext fun i => by simp only [Basis.constr_basis, LinearMap.comp_apply, Function.comp]
#align basis.constr_comp Basis.constr_comp
end Constr
section Equiv
variable (b' : Basis ι' R M') (e : ι ≃ ι')
variable [AddCommMonoid M''] [Module R M'']
/-- If `b` is a basis for `M` and `b'` a basis for `M'`, and the index types are equivalent,
`b.equiv b' e` is a linear equivalence `M ≃ₗ[R] M'`, mapping `b i` to `b' (e i)`. -/
protected def equiv : M ≃ₗ[R] M' :=
b.repr.trans (b'.reindex e.symm).repr.symm
#align basis.equiv Basis.equiv
@[simp]
theorem equiv_apply : b.equiv b' e (b i) = b' (e i) := by simp [Basis.equiv]
#align basis.equiv_apply Basis.equiv_apply
@[simp]
theorem equiv_refl : b.equiv b (Equiv.refl ι) = LinearEquiv.refl R M :=
b.ext' fun i => by simp
#align basis.equiv_refl Basis.equiv_refl
@[simp]
theorem equiv_symm : (b.equiv b' e).symm = b'.equiv b e.symm :=
b'.ext' fun i => (b.equiv b' e).injective (by simp)
#align basis.equiv_symm Basis.equiv_symm
@[simp]
theorem equiv_trans {ι'' : Type*} (b'' : Basis ι'' R M'') (e : ι ≃ ι') (e' : ι' ≃ ι'') :
(b.equiv b' e).trans (b'.equiv b'' e') = b.equiv b'' (e.trans e') :=
b.ext' fun i => by simp
#align basis.equiv_trans Basis.equiv_trans
@[simp]
theorem map_equiv (b : Basis ι R M) (b' : Basis ι' R M') (e : ι ≃ ι') :
b.map (b.equiv b' e) = b'.reindex e.symm := by
ext i
simp
#align basis.map_equiv Basis.map_equiv
end Equiv
section Prod
variable (b' : Basis ι' R M')
/-- `Basis.prod` maps an `ι`-indexed basis for `M` and an `ι'`-indexed basis for `M'`
to an `ι ⊕ ι'`-index basis for `M × M'`.
For the specific case of `R × R`, see also `Basis.finTwoProd`. -/
protected def prod : Basis (Sum ι ι') R (M × M') :=
ofRepr ((b.repr.prod b'.repr).trans (Finsupp.sumFinsuppLEquivProdFinsupp R).symm)
#align basis.prod Basis.prod
@[simp]
theorem prod_repr_inl (x) (i) : (b.prod b').repr x (Sum.inl i) = b.repr x.1 i :=
rfl
#align basis.prod_repr_inl Basis.prod_repr_inl
@[simp]
theorem prod_repr_inr (x) (i) : (b.prod b').repr x (Sum.inr i) = b'.repr x.2 i :=
rfl
#align basis.prod_repr_inr Basis.prod_repr_inr
theorem prod_apply_inl_fst (i) : (b.prod b' (Sum.inl i)).1 = b i :=
b.repr.injective <| by
ext j
simp only [Basis.prod, Basis.coe_ofRepr, LinearEquiv.symm_trans_apply, LinearEquiv.prod_symm,
LinearEquiv.prod_apply, b.repr.apply_symm_apply, LinearEquiv.symm_symm, repr_self,
Equiv.toFun_as_coe, Finsupp.fst_sumFinsuppLEquivProdFinsupp]
apply Finsupp.single_apply_left Sum.inl_injective
#align basis.prod_apply_inl_fst Basis.prod_apply_inl_fst
theorem prod_apply_inr_fst (i) : (b.prod b' (Sum.inr i)).1 = 0 :=
b.repr.injective <| by
ext i
simp only [Basis.prod, Basis.coe_ofRepr, LinearEquiv.symm_trans_apply, LinearEquiv.prod_symm,
LinearEquiv.prod_apply, b.repr.apply_symm_apply, LinearEquiv.symm_symm, repr_self,
Equiv.toFun_as_coe, Finsupp.fst_sumFinsuppLEquivProdFinsupp, LinearEquiv.map_zero,
Finsupp.zero_apply]
apply Finsupp.single_eq_of_ne Sum.inr_ne_inl
#align basis.prod_apply_inr_fst Basis.prod_apply_inr_fst
theorem prod_apply_inl_snd (i) : (b.prod b' (Sum.inl i)).2 = 0 :=
b'.repr.injective <| by
ext j
simp only [Basis.prod, Basis.coe_ofRepr, LinearEquiv.symm_trans_apply, LinearEquiv.prod_symm,
LinearEquiv.prod_apply, b'.repr.apply_symm_apply, LinearEquiv.symm_symm, repr_self,
Equiv.toFun_as_coe, Finsupp.snd_sumFinsuppLEquivProdFinsupp, LinearEquiv.map_zero,
Finsupp.zero_apply]
apply Finsupp.single_eq_of_ne Sum.inl_ne_inr
#align basis.prod_apply_inl_snd Basis.prod_apply_inl_snd
theorem prod_apply_inr_snd (i) : (b.prod b' (Sum.inr i)).2 = b' i :=
b'.repr.injective <| by
ext i
simp only [Basis.prod, Basis.coe_ofRepr, LinearEquiv.symm_trans_apply, LinearEquiv.prod_symm,
LinearEquiv.prod_apply, b'.repr.apply_symm_apply, LinearEquiv.symm_symm, repr_self,
Equiv.toFun_as_coe, Finsupp.snd_sumFinsuppLEquivProdFinsupp]
apply Finsupp.single_apply_left Sum.inr_injective
#align basis.prod_apply_inr_snd Basis.prod_apply_inr_snd
@[simp]
theorem prod_apply (i) :
b.prod b' i = Sum.elim (LinearMap.inl R M M' ∘ b) (LinearMap.inr R M M' ∘ b') i := by
ext <;> cases i <;>
simp only [prod_apply_inl_fst, Sum.elim_inl, LinearMap.inl_apply, prod_apply_inr_fst,
Sum.elim_inr, LinearMap.inr_apply, prod_apply_inl_snd, prod_apply_inr_snd, Function.comp]
#align basis.prod_apply Basis.prod_apply
end Prod
section NoZeroSMulDivisors
-- Can't be an instance because the basis can't be inferred.
protected theorem noZeroSMulDivisors [NoZeroDivisors R] (b : Basis ι R M) :
NoZeroSMulDivisors R M :=
⟨fun {c x} hcx => by
exact or_iff_not_imp_right.mpr fun hx => by
rw [← b.total_repr x, ← LinearMap.map_smul] at hcx
have := linearIndependent_iff.mp b.linearIndependent (c • b.repr x) hcx
rw [smul_eq_zero] at this
exact this.resolve_right fun hr => hx (b.repr.map_eq_zero_iff.mp hr)⟩
#align basis.no_zero_smul_divisors Basis.noZeroSMulDivisors
protected theorem smul_eq_zero [NoZeroDivisors R] (b : Basis ι R M) {c : R} {x : M} :
c • x = 0 ↔ c = 0 ∨ x = 0 :=
@smul_eq_zero _ _ _ _ _ b.noZeroSMulDivisors _ _
#align basis.smul_eq_zero Basis.smul_eq_zero
theorem eq_bot_of_rank_eq_zero [NoZeroDivisors R] (b : Basis ι R M) (N : Submodule R M)
(rank_eq : ∀ {m : ℕ} (v : Fin m → N), LinearIndependent R ((↑) ∘ v : Fin m → M) → m = 0) :
N = ⊥ := by
rw [Submodule.eq_bot_iff]
intro x hx
contrapose! rank_eq with x_ne
refine' ⟨1, fun _ => ⟨x, hx⟩, _, one_ne_zero⟩
rw [Fintype.linearIndependent_iff]
rintro g sum_eq i
cases' i with _ hi
simp only [Function.const_apply, Fin.default_eq_zero, Submodule.coe_mk, Finset.univ_unique,
Function.comp_const, Finset.sum_singleton] at sum_eq
convert (b.smul_eq_zero.mp sum_eq).resolve_right x_ne
#align eq_bot_of_rank_eq_zero Basis.eq_bot_of_rank_eq_zero
end NoZeroSMulDivisors
section Singleton
/-- `Basis.singleton ι R` is the basis sending the unique element of `ι` to `1 : R`. -/
protected def singleton (ι R : Type*) [Unique ι] [Semiring R] : Basis ι R R :=
ofRepr
{ toFun := fun x => Finsupp.single default x
invFun := fun f => f default
left_inv := fun x => by simp
right_inv := fun f => Finsupp.unique_ext (by simp)
map_add' := fun x y => by simp
map_smul' := fun c x => by simp }
#align basis.singleton Basis.singleton
@[simp]
theorem singleton_apply (ι R : Type*) [Unique ι] [Semiring R] (i) : Basis.singleton ι R i = 1 :=
apply_eq_iff.mpr (by simp [Basis.singleton])
#align basis.singleton_apply Basis.singleton_apply
@[simp]
theorem singleton_repr (ι R : Type*) [Unique ι] [Semiring R] (x i) :
(Basis.singleton ι R).repr x i = x := by simp [Basis.singleton, Unique.eq_default i]
#align basis.singleton_repr Basis.singleton_repr
theorem basis_singleton_iff {R M : Type*} [Ring R] [Nontrivial R] [AddCommGroup M] [Module R M]
[NoZeroSMulDivisors R M] (ι : Type*) [Unique ι] :
Nonempty (Basis ι R M) ↔ ∃ x ≠ 0, ∀ y : M, ∃ r : R, r • x = y := by
constructor
· rintro ⟨b⟩
refine' ⟨b default, b.linearIndependent.ne_zero _, _⟩
simpa [span_singleton_eq_top_iff, Set.range_unique] using b.span_eq
· rintro ⟨x, nz, w⟩
refine ⟨ofRepr <| LinearEquiv.symm
{ toFun := fun f => f default • x
invFun := fun y => Finsupp.single default (w y).choose
left_inv := fun f => Finsupp.unique_ext ?_
right_inv := fun y => ?_
map_add' := fun y z => ?_
map_smul' := fun c y => ?_ }⟩
· simp [Finsupp.add_apply, add_smul]
· simp only [Finsupp.coe_smul, Pi.smul_apply, RingHom.id_apply]
rw [← smul_assoc]
· refine' smul_left_injective _ nz _
simp only [Finsupp.single_eq_same]
exact (w (f default • x)).choose_spec
· simp only [Finsupp.single_eq_same]
exact (w y).choose_spec
#align basis.basis_singleton_iff Basis.basis_singleton_iff
end Singleton
section Empty
variable (M)
/-- If `M` is a subsingleton and `ι` is empty, this is the unique `ι`-indexed basis for `M`. -/
protected def empty [Subsingleton M] [IsEmpty ι] : Basis ι R M :=
ofRepr 0
#align basis.empty Basis.empty
instance emptyUnique [Subsingleton M] [IsEmpty ι] : Unique (Basis ι R M) where
default := Basis.empty M
uniq := fun _ => congr_arg ofRepr <| Subsingleton.elim _ _
#align basis.empty_unique Basis.emptyUnique
end Empty
end Basis
section Fintype
open Basis
open Fintype
/-- A module over `R` with a finite basis is linearly equivalent to functions from its basis to `R`.
-/
def Basis.equivFun [Finite ι] (b : Basis ι R M) : M ≃ₗ[R] ι → R :=
LinearEquiv.trans b.repr
({ Finsupp.equivFunOnFinite with
toFun := (↑)
map_add' := Finsupp.coe_add
map_smul' := Finsupp.coe_smul } :
(ι →₀ R) ≃ₗ[R] ι → R)
#align basis.equiv_fun Basis.equivFun
/-- A module over a finite ring that admits a finite basis is finite. -/
def Module.fintypeOfFintype [Fintype ι] (b : Basis ι R M) [Fintype R] : Fintype M :=
haveI := Classical.decEq ι
Fintype.ofEquiv _ b.equivFun.toEquiv.symm
#align module.fintype_of_fintype Module.fintypeOfFintype
theorem Module.card_fintype [Fintype ι] (b : Basis ι R M) [Fintype R] [Fintype M] :
card M = card R ^ card ι := by
classical
calc
card M = card (ι → R) := card_congr b.equivFun.toEquiv
_ = card R ^ card ι := card_fun
#align module.card_fintype Module.card_fintype
/-- Given a basis `v` indexed by `ι`, the canonical linear equivalence between `ι → R` and `M` maps
a function `x : ι → R` to the linear combination `∑_i x i • v i`. -/
@[simp]
theorem Basis.equivFun_symm_apply [Fintype ι] (b : Basis ι R M) (x : ι → R) :
b.equivFun.symm x = ∑ i, x i • b i := by
simp [Basis.equivFun, Finsupp.total_apply, Finsupp.sum_fintype, Finsupp.equivFunOnFinite]
#align basis.equiv_fun_symm_apply Basis.equivFun_symm_apply
@[simp]
theorem Basis.equivFun_apply [Finite ι] (b : Basis ι R M) (u : M) : b.equivFun u = b.repr u :=
rfl
#align basis.equiv_fun_apply Basis.equivFun_apply
@[simp]
theorem Basis.map_equivFun [Finite ι] (b : Basis ι R M) (f : M ≃ₗ[R] M') :
(b.map f).equivFun = f.symm.trans b.equivFun :=
rfl
#align basis.map_equiv_fun Basis.map_equivFun
theorem Basis.sum_equivFun [Fintype ι] (b : Basis ι R M) (u : M) :
∑ i, b.equivFun u i • b i = u := by
rw [← b.equivFun_symm_apply, b.equivFun.symm_apply_apply]
#align basis.sum_equiv_fun Basis.sum_equivFun
theorem Basis.sum_repr [Fintype ι] (b : Basis ι R M) (u : M) : ∑ i, b.repr u i • b i = u :=
b.sum_equivFun u
#align basis.sum_repr Basis.sum_repr
@[simp]
theorem Basis.equivFun_self [Finite ι] [DecidableEq ι] (b : Basis ι R M) (i j : ι) :
b.equivFun (b i) j = if i = j then 1 else 0 := by rw [b.equivFun_apply, b.repr_self_apply]
#align basis.equiv_fun_self Basis.equivFun_self
theorem Basis.repr_sum_self [Fintype ι] (b : Basis ι R M) (c : ι → R) :
b.repr (∑ i, c i • b i) = c := by
simp_rw [← b.equivFun_symm_apply, ← b.equivFun_apply, b.equivFun.apply_symm_apply]
#align basis.repr_sum_self Basis.repr_sum_self
/-- Define a basis by mapping each vector `x : M` to its coordinates `e x : ι → R`,
as long as `ι` is finite. -/
def Basis.ofEquivFun [Finite ι] (e : M ≃ₗ[R] ι → R) : Basis ι R M :=
.ofRepr <| e.trans <| LinearEquiv.symm <| Finsupp.linearEquivFunOnFinite R R ι
#align basis.of_equiv_fun Basis.ofEquivFun
@[simp]
theorem Basis.ofEquivFun_repr_apply [Finite ι] (e : M ≃ₗ[R] ι → R) (x : M) (i : ι) :
(Basis.ofEquivFun e).repr x i = e x i :=
rfl
#align basis.of_equiv_fun_repr_apply Basis.ofEquivFun_repr_apply
@[simp]
theorem Basis.coe_ofEquivFun [Finite ι] [DecidableEq ι] (e : M ≃ₗ[R] ι → R) :
(Basis.ofEquivFun e : ι → M) = fun i => e.symm (Function.update 0 i 1) :=
funext fun i =>
e.injective <|
funext fun j => by
simp [Basis.ofEquivFun, ← Finsupp.single_eq_pi_single, Finsupp.single_eq_update]
#align basis.coe_of_equiv_fun Basis.coe_ofEquivFun
@[simp]
theorem Basis.ofEquivFun_equivFun [Finite ι] (v : Basis ι R M) :
Basis.ofEquivFun v.equivFun = v :=
Basis.repr_injective <| by ext; rfl
#align basis.of_equiv_fun_equiv_fun Basis.ofEquivFun_equivFun
@[simp]
theorem Basis.equivFun_ofEquivFun [Finite ι] (e : M ≃ₗ[R] ι → R) :
(Basis.ofEquivFun e).equivFun = e := by
ext j
simp_rw [Basis.equivFun_apply, Basis.ofEquivFun_repr_apply]
#align basis.equiv_fun_of_equiv_fun Basis.equivFun_ofEquivFun
variable (S : Type*) [Semiring S] [Module S M']
variable [SMulCommClass R S M']
@[simp]
theorem Basis.constr_apply_fintype [Fintype ι] (b : Basis ι R M) (f : ι → M') (x : M) :
(constr (M' := M') b S f : M → M') x = ∑ i, b.equivFun x i • f i := by
simp [b.constr_apply, b.equivFun_apply, Finsupp.sum_fintype]
#align basis.constr_apply_fintype Basis.constr_apply_fintype
/-- If the submodule `P` has a finite basis,
`x ∈ P` iff it is a linear combination of basis vectors. -/
theorem Basis.mem_submodule_iff' [Fintype ι] {P : Submodule R M} (b : Basis ι R P) {x : M} :
x ∈ P ↔ ∃ c : ι → R, x = ∑ i, c i • (b i : M) :=
b.mem_submodule_iff.trans <|
Finsupp.equivFunOnFinite.exists_congr_left.trans <|
exists_congr fun c => by simp [Finsupp.sum_fintype, Finsupp.equivFunOnFinite]
#align basis.mem_submodule_iff' Basis.mem_submodule_iff'
theorem Basis.coord_equivFun_symm [Finite ι] (b : Basis ι R M) (i : ι) (f : ι → R) :
b.coord i (b.equivFun.symm f) = f i :=
b.coord_repr_symm i (Finsupp.equivFunOnFinite.symm f)
#align basis.coord_equiv_fun_symm Basis.coord_equivFun_symm