-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathBasic.lean
More file actions
822 lines (653 loc) · 31.3 KB
/
Copy pathBasic.lean
File metadata and controls
822 lines (653 loc) · 31.3 KB
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
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Johan Commelin
-/
module
public import Mathlib.Algebra.Algebra.Operations
public import Mathlib.Algebra.Star.TensorProduct
public import Mathlib.LinearAlgebra.TensorProduct.Tower
public import Mathlib.RingTheory.Adjoin.Basic
/-!
# The tensor product of R-algebras
This file provides results about the multiplicative structure on `A ⊗[R] B` when `R` is a
commutative (semi)ring and `A` and `B` are both `R`-algebras. On these tensor products,
multiplication is characterized by `(a₁ ⊗ₜ b₁) * (a₂ ⊗ₜ b₂) = (a₁ * a₂) ⊗ₜ (b₁ * b₂)`.
## Main declarations
- `Algebra.TensorProduct.semiring`: the ring structure on `A ⊗[R] B` for two `R`-algebras `A`, `B`.
- `Algebra.TensorProduct.leftAlgebra`: the `S`-algebra structure on `A ⊗[R] B`, for when `A` is
additionally an `S` algebra.
## References
* [C. Kassel, *Quantum Groups* (§II.4)][Kassel1995]
-/
@[expose] public section
assert_not_exists Equiv.Perm.cycleType
open scoped TensorProduct
open TensorProduct
namespace LinearMap
section liftBaseChange
variable {R M N} (A) [CommSemiring R] [CommSemiring A] [Algebra R A] [AddCommMonoid M]
variable [AddCommMonoid N] [Module R M] [Module R N] [Module A N] [IsScalarTower R A N]
/--
If `M` is an `R`-module and `N` is an `A`-module, then `A`-linear maps `A ⊗[R] M →ₗ[A] N`
correspond to `R` linear maps `M →ₗ[R] N` by composing with `M → A ⊗ M`, `x ↦ 1 ⊗ x`.
-/
def liftBaseChangeEquiv : (M →ₗ[R] N) ≃ₗ[A] (A ⊗[R] M →ₗ[A] N) :=
(LinearMap.ringLmapEquivSelf _ _ _).symm.trans (AlgebraTensorModule.lift.equiv _ _ _ _ _ _)
/-- If `N` is an `A` module, we may lift a linear map `M →ₗ[R] N` to `A ⊗[R] M →ₗ[A] N` -/
abbrev liftBaseChange (l : M →ₗ[R] N) : A ⊗[R] M →ₗ[A] N :=
LinearMap.liftBaseChangeEquiv A l
@[simp]
lemma liftBaseChange_tmul (l : M →ₗ[R] N) (x y) : l.liftBaseChange A (x ⊗ₜ y) = x • l y := rfl
lemma liftBaseChange_one_tmul (l : M →ₗ[R] N) (y) : l.liftBaseChange A (1 ⊗ₜ y) = l y := by simp
@[simp]
lemma liftBaseChangeEquiv_symm_apply (l : A ⊗[R] M →ₗ[A] N) (x) :
(liftBaseChangeEquiv A).symm l x = l (1 ⊗ₜ x) := rfl
lemma liftBaseChange_comp {P} [AddCommMonoid P] [Module A P] [Module R P] [IsScalarTower R A P]
(l : M →ₗ[R] N) (l' : N →ₗ[A] P) :
l' ∘ₗ l.liftBaseChange A = (l'.restrictScalars R ∘ₗ l).liftBaseChange A := by
ext
simp
@[simp]
lemma range_liftBaseChange (l : M →ₗ[R] N) :
LinearMap.range (l.liftBaseChange A) = Submodule.span A (LinearMap.range l) := by
apply le_antisymm
· rintro _ ⟨x, rfl⟩
induction x using TensorProduct.induction_on
· simp
· rw [LinearMap.liftBaseChange_tmul]
exact Submodule.smul_mem _ _ (Submodule.subset_span ⟨_, rfl⟩)
· rw [map_add]
exact add_mem ‹_› ‹_›
· rw [Submodule.span_le]
rintro _ ⟨x, rfl⟩
exact ⟨1 ⊗ₜ x, by simp⟩
end liftBaseChange
end LinearMap
namespace Algebra
namespace TensorProduct
universe uR uS uA uB uC uD uE uF
variable {R : Type uR} {R' : Type*} {S : Type uS} {T : Type*}
variable {A : Type uA} {B : Type uB} {C : Type uC} {D : Type uD} {E : Type uE} {F : Type uF}
/-!
### The `R`-algebra structure on `A ⊗[R] B`
-/
section AddCommMonoidWithOne
variable [CommSemiring R]
variable [AddCommMonoidWithOne A] [Module R A]
variable [AddCommMonoidWithOne B] [Module R B]
instance : One (A ⊗[R] B) where one := 1 ⊗ₜ 1
theorem one_def : (1 : A ⊗[R] B) = (1 : A) ⊗ₜ (1 : B) :=
rfl
instance instAddCommMonoidWithOne : AddCommMonoidWithOne (A ⊗[R] B) where
natCast n := n ⊗ₜ 1
natCast_zero := by simp
natCast_succ n := by simp [add_tmul, one_def]
add_comm := add_comm
theorem natCast_def (n : ℕ) : (n : A ⊗[R] B) = (n : A) ⊗ₜ (1 : B) := rfl
theorem natCast_def' (n : ℕ) : (n : A ⊗[R] B) = (1 : A) ⊗ₜ (n : B) := by
rw [natCast_def, ← nsmul_one, smul_tmul, nsmul_one]
end AddCommMonoidWithOne
section NonUnitalNonAssocSemiring
variable [CommSemiring R]
variable [NonUnitalNonAssocSemiring A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]
variable [NonUnitalNonAssocSemiring B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B]
/-- (Implementation detail)
The multiplication map on `A ⊗[R] B`,
as an `R`-bilinear map.
-/
@[irreducible]
def mul : A ⊗[R] B →ₗ[R] A ⊗[R] B →ₗ[R] A ⊗[R] B :=
TensorProduct.map₂ (LinearMap.mul R A) (LinearMap.mul R B)
unseal mul in
@[simp]
theorem mul_apply (a₁ a₂ : A) (b₁ b₂ : B) :
mul (a₁ ⊗ₜ[R] b₁) (a₂ ⊗ₜ[R] b₂) = (a₁ * a₂) ⊗ₜ[R] (b₁ * b₂) :=
rfl
-- providing this instance separately makes some downstream code substantially faster
instance instMul : Mul (A ⊗[R] B) where
mul a b := mul a b
unseal mul in
@[simp]
theorem tmul_mul_tmul (a₁ a₂ : A) (b₁ b₂ : B) :
a₁ ⊗ₜ[R] b₁ * a₂ ⊗ₜ[R] b₂ = (a₁ * a₂) ⊗ₜ[R] (b₁ * b₂) :=
rfl
unseal mul in
theorem _root_.SemiconjBy.tmul {a₁ a₂ a₃ : A} {b₁ b₂ b₃ : B}
(ha : SemiconjBy a₁ a₂ a₃) (hb : SemiconjBy b₁ b₂ b₃) :
SemiconjBy (a₁ ⊗ₜ[R] b₁) (a₂ ⊗ₜ[R] b₂) (a₃ ⊗ₜ[R] b₃) :=
congr_arg₂ (· ⊗ₜ[R] ·) ha.eq hb.eq
nonrec theorem _root_.Commute.tmul {a₁ a₂ : A} {b₁ b₂ : B}
(ha : Commute a₁ a₂) (hb : Commute b₁ b₂) :
Commute (a₁ ⊗ₜ[R] b₁) (a₂ ⊗ₜ[R] b₂) :=
ha.tmul hb
instance instNonUnitalNonAssocSemiring : NonUnitalNonAssocSemiring (A ⊗[R] B) where
left_distrib a b c := by simp [HMul.hMul, Mul.mul]
right_distrib a b c := by simp [HMul.hMul, Mul.mul]
zero_mul a := by simp [HMul.hMul, Mul.mul]
mul_zero a := by simp [HMul.hMul, Mul.mul]
-- we want `isScalarTower_right` to take priority since it's better for unification elsewhere
instance (priority := 100) isScalarTower_right [Monoid S] [DistribMulAction S A]
[IsScalarTower S A A] [SMulCommClass R S A] : IsScalarTower S (A ⊗[R] B) (A ⊗[R] B) where
smul_assoc r x y := by
change r • x * y = r • (x * y)
induction y with
| zero => simp [smul_zero]
| tmul a b => induction x with
| zero => simp [smul_zero]
| tmul a' b' =>
dsimp
rw [TensorProduct.smul_tmul', TensorProduct.smul_tmul', tmul_mul_tmul, smul_mul_assoc]
| add x y hx hy => simp [smul_add, add_mul _, *]
| add x y hx hy => simp [smul_add, mul_add _, *]
-- we want `Algebra.to_smulCommClass` to take priority since it's better for unification elsewhere
instance (priority := 100) sMulCommClass_right [Monoid S] [DistribMulAction S A]
[SMulCommClass S A A] [SMulCommClass R S A] : SMulCommClass S (A ⊗[R] B) (A ⊗[R] B) where
smul_comm r x y := by
change r • (x * y) = x * r • y
induction y with
| zero => simp [smul_zero]
| tmul a b => induction x with
| zero => simp [smul_zero]
| tmul a' b' =>
dsimp
rw [TensorProduct.smul_tmul', TensorProduct.smul_tmul', tmul_mul_tmul, mul_smul_comm]
| add x y hx hy => simp [smul_add, add_mul _, *]
| add x y hx hy => simp [smul_add, mul_add _, *]
end NonUnitalNonAssocSemiring
section NonAssocSemiring
variable [CommSemiring R]
variable [NonAssocSemiring A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]
variable [NonAssocSemiring B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B]
protected theorem one_mul (x : A ⊗[R] B) : mul (1 ⊗ₜ 1) x = x := by
refine TensorProduct.induction_on x ?_ ?_ ?_ <;> simp +contextual
protected theorem mul_one (x : A ⊗[R] B) : mul x (1 ⊗ₜ 1) = x := by
refine TensorProduct.induction_on x ?_ ?_ ?_ <;> simp +contextual
instance instNonAssocSemiring : NonAssocSemiring (A ⊗[R] B) where
one_mul := Algebra.TensorProduct.one_mul
mul_one := Algebra.TensorProduct.mul_one
toNonUnitalNonAssocSemiring := instNonUnitalNonAssocSemiring
__ := instAddCommMonoidWithOne
end NonAssocSemiring
section NonUnitalSemiring
variable [CommSemiring R]
variable [NonUnitalSemiring A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]
variable [NonUnitalSemiring B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B]
unseal mul in
protected theorem mul_assoc (x y z : A ⊗[R] B) : mul (mul x y) z = mul x (mul y z) := by
-- restate as an equality of morphisms so that we can use `ext`
suffices LinearMap.llcomp R _ _ _ mul ∘ₗ mul =
(LinearMap.llcomp R _ _ _ LinearMap.lflip.toLinearMap <|
LinearMap.llcomp R _ _ _ mul.flip ∘ₗ mul).flip by
exact DFunLike.congr_fun (DFunLike.congr_fun (DFunLike.congr_fun this x) y) z
ext xa xb ya yb za zb
exact congr_arg₂ (· ⊗ₜ ·) (mul_assoc xa ya za) (mul_assoc xb yb zb)
instance instNonUnitalSemiring : NonUnitalSemiring (A ⊗[R] B) where
mul_assoc := Algebra.TensorProduct.mul_assoc
end NonUnitalSemiring
section Semiring
variable [CommSemiring R]
variable [Semiring A] [Algebra R A]
variable [Semiring B] [Algebra R B]
variable [Semiring C] [Algebra R C]
instance instSemiring : Semiring (A ⊗[R] B) where
left_distrib a b c := by simp [HMul.hMul, Mul.mul]
right_distrib a b c := by simp [HMul.hMul, Mul.mul]
zero_mul a := by simp [HMul.hMul, Mul.mul]
mul_zero a := by simp [HMul.hMul, Mul.mul]
mul_assoc := Algebra.TensorProduct.mul_assoc
one_mul := Algebra.TensorProduct.one_mul
mul_one := Algebra.TensorProduct.mul_one
natCast_zero := AddMonoidWithOne.natCast_zero
natCast_succ := AddMonoidWithOne.natCast_succ
@[simp]
theorem tmul_pow (a : A) (b : B) (k : ℕ) : a ⊗ₜ[R] b ^ k = (a ^ k) ⊗ₜ[R] (b ^ k) := by
induction k with
| zero => simp [one_def]
| succ k ih => simp [pow_succ, ih]
/-- The ring morphism `A →+* A ⊗[R] B` sending `a` to `a ⊗ₜ 1`. -/
@[simps!]
def includeLeftRingHom : A →+* A ⊗[R] B where
__ := (AlgebraTensorModule.mk R R A B).flip 1 |>.toAddMonoidHom
map_one' := rfl
map_mul' := by simp
variable [CommSemiring S] [Algebra S A]
set_option backward.defeqAttrib.useBackward true in
instance leftAlgebra [SMulCommClass R S A] : Algebra S (A ⊗[R] B) :=
{ commutes' := fun r x => by
dsimp only [RingHom.toFun_eq_coe, RingHom.comp_apply, includeLeftRingHom_apply]
rw [algebraMap_eq_smul_one, ← smul_tmul', ← one_def, mul_smul_comm, smul_mul_assoc, mul_one,
one_mul]
smul_def' := fun r x => by
dsimp only [RingHom.toFun_eq_coe, RingHom.comp_apply, includeLeftRingHom_apply]
rw [algebraMap_eq_smul_one, ← smul_tmul', smul_mul_assoc, ← one_def, one_mul]
algebraMap := TensorProduct.includeLeftRingHom.comp (algebraMap S A) }
lemma algebraMap_def [SMulCommClass R S A] :
algebraMap S (A ⊗[R] B) = includeLeftRingHom.comp (algebraMap S A) := rfl
example : (Semiring.toNatAlgebra : Algebra ℕ (ℕ ⊗[ℕ] B)) = leftAlgebra := rfl
-- This is for the `undergrad.yaml` list.
/-- The tensor product of two `R`-algebras is an `R`-algebra. -/
instance instAlgebra : Algebra R (A ⊗[R] B) :=
inferInstance
@[simp]
theorem algebraMap_apply [SMulCommClass R S A] (r : S) :
algebraMap S (A ⊗[R] B) r = (algebraMap S A) r ⊗ₜ 1 :=
rfl
theorem algebraMap_apply' (r : R) :
algebraMap R (A ⊗[R] B) r = 1 ⊗ₜ algebraMap R B r := by
rw [algebraMap_apply, Algebra.algebraMap_eq_smul_one, Algebra.algebraMap_eq_smul_one, smul_tmul]
/-- The `R`-algebra morphism `A →ₐ[R] A ⊗[R] B` sending `a` to `a ⊗ₜ 1`. -/
def includeLeft [SMulCommClass R S A] : A →ₐ[S] A ⊗[R] B :=
{ includeLeftRingHom with commutes' := by simp }
@[simp]
theorem includeLeft_apply [SMulCommClass R S A] (a : A) :
(includeLeft : A →ₐ[S] A ⊗[R] B) a = a ⊗ₜ 1 :=
rfl
@[simp] theorem toLinearMap_includeLeft [SMulCommClass R S A] :
(includeLeft : A →ₐ[S] A ⊗[R] B).toLinearMap = (AlgebraTensorModule.mk R S A B).flip 1 := rfl
/-- The algebra morphism `B →ₐ[R] A ⊗[R] B` sending `b` to `1 ⊗ₜ b`. -/
def includeRight : B →ₐ[R] A ⊗[R] B where
__ := AlgebraTensorModule.mk R R A B 1 |>.toAddMonoidHom
map_one' := rfl
map_mul' := by simp
commutes' r := by simp [algebraMap_eq_smul_one', smul_tmul]
@[simp]
theorem includeRight_apply (b : B) : (includeRight : B →ₐ[R] A ⊗[R] B) b = 1 ⊗ₜ b :=
rfl
@[simp] theorem toLinearMap_includeRight :
(includeRight : B →ₐ[R] A ⊗[R] B).toLinearMap = AlgebraTensorModule.mk R R A B 1 := rfl
theorem includeLeftRingHom_comp_algebraMap :
(includeLeftRingHom.comp (algebraMap R A) : R →+* A ⊗[R] B) =
includeRight.toRingHom.comp (algebraMap R B) := by
ext
simp
section ext
variable [Algebra R S] [Algebra S C] [IsScalarTower R S A] [IsScalarTower R S C]
/-- A version of `TensorProduct.ext` for `AlgHom`.
Using this as the `@[ext]` lemma instead of `Algebra.TensorProduct.ext'` allows `ext` to apply
lemmas specific to `A →ₐ[S] _` and `B →ₐ[R] _`; notably this allows recursion into nested tensor
products of algebras.
See note [partially-applied ext lemmas]. -/
@[ext high]
theorem ext ⦃f g : (A ⊗[R] B) →ₐ[S] C⦄
(ha : f.comp includeLeft = g.comp includeLeft)
(hb : (f.restrictScalars R).comp includeRight = (g.restrictScalars R).comp includeRight) :
f = g := by
apply AlgHom.toLinearMap_injective
ext a b
have := congr_arg₂ HMul.hMul (AlgHom.congr_fun ha a) (AlgHom.congr_fun hb b)
dsimp at *
rwa [← map_mul, ← map_mul, tmul_mul_tmul, one_mul, mul_one] at this
theorem ext' {g h : A ⊗[R] B →ₐ[S] C} (H : ∀ a b, g (a ⊗ₜ b) = h (a ⊗ₜ b)) : g = h :=
ext (AlgHom.ext fun _ => H _ _) (AlgHom.ext fun _ => H _ _)
@[ext high]
lemma ringHom_ext {C : Type*} [Semiring C] {f g : A ⊗[R] B →+* C}
(h₁ : f.comp includeLeftRingHom = g.comp includeLeftRingHom)
(h₂ : f.comp includeRight.toRingHom = g.comp includeRight.toRingHom) : f = g := by
ext x
induction x with
| zero => simp
| add x y _ _ => simp_all
| tmul x y => simpa [← map_mul] using congr($h₁ x * $h₂ y)
end ext
end Semiring
section AddCommGroupWithOne
variable [CommSemiring R]
variable [AddCommGroupWithOne A] [Module R A]
variable [AddCommMonoidWithOne B] [Module R B]
instance instAddCommGroupWithOne : AddCommGroupWithOne (A ⊗[R] B) where
toAddCommGroup := TensorProduct.addCommGroup
__ := instAddCommMonoidWithOne
intCast z := z ⊗ₜ (1 : B)
intCast_ofNat n := by simp [natCast_def]
intCast_negSucc n := by simp [natCast_def, add_tmul, neg_tmul, one_def]
theorem intCast_def (z : ℤ) : (z : A ⊗[R] B) = (z : A) ⊗ₜ (1 : B) := rfl
end AddCommGroupWithOne
section NonUnitalNonAssocRing
variable [CommSemiring R]
variable [NonUnitalNonAssocRing A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]
variable [NonUnitalNonAssocSemiring B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B]
instance instNonUnitalNonAssocRing : NonUnitalNonAssocRing (A ⊗[R] B) where
toAddCommGroup := TensorProduct.addCommGroup
__ := instNonUnitalNonAssocSemiring
end NonUnitalNonAssocRing
section NonAssocRing
variable [CommSemiring R]
variable [NonAssocRing A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]
variable [NonAssocSemiring B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B]
instance instNonAssocRing : NonAssocRing (A ⊗[R] B) where
toAddCommGroup := TensorProduct.addCommGroup
__ := instNonAssocSemiring
__ := instAddCommGroupWithOne
end NonAssocRing
section NonUnitalRing
variable [CommSemiring R]
variable [NonUnitalRing A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]
variable [NonUnitalSemiring B] [Module R B] [SMulCommClass R B B] [IsScalarTower R B B]
instance instNonUnitalRing : NonUnitalRing (A ⊗[R] B) where
toAddCommGroup := TensorProduct.addCommGroup
__ := instNonUnitalSemiring
end NonUnitalRing
section CommSemiring
variable [CommSemiring R]
variable [CommSemiring A] [Algebra R A]
variable [CommSemiring B] [Algebra R B]
instance instCommSemiring : CommSemiring (A ⊗[R] B) where
toSemiring := inferInstance
mul_comm x y := by
refine TensorProduct.induction_on x ?_ ?_ ?_
· simp
· intro a₁ b₁
refine TensorProduct.induction_on y ?_ ?_ ?_
· simp
· intro a₂ b₂
simp [mul_comm]
· intro a₂ b₂ ha hb
simp [mul_add, add_mul, ha, hb]
· intro x₁ x₂ h₁ h₂
simp [mul_add, add_mul, h₁, h₂]
end CommSemiring
section Ring
variable [CommSemiring R]
variable [Ring A] [Algebra R A]
variable [Semiring B] [Algebra R B]
instance instRing : Ring (A ⊗[R] B) where
toSemiring := instSemiring
__ := TensorProduct.addCommGroup
__ := instNonAssocRing
theorem intCast_def' {B} [Ring B] [Algebra R B] (z : ℤ) : (z : A ⊗[R] B) = (1 : A) ⊗ₜ (z : B) := by
rw [intCast_def, ← zsmul_one, smul_tmul, zsmul_one]
-- verify there are no diamonds
example : (instRing : Ring (A ⊗[R] B)).toAddCommGroup = addCommGroup := by
with_reducible_and_instances rfl
-- fails at `with_reducible_and_instances rfl` https://github.com/leanprover-community/mathlib4/issues/10906
example : (Ring.toIntAlgebra _ : Algebra ℤ (ℤ ⊗[ℤ] A)) = leftAlgebra := rfl
end Ring
section CommRing
variable [CommSemiring R]
variable [CommRing A] [Algebra R A]
variable [CommSemiring B] [Algebra R B]
instance instCommRing : CommRing (A ⊗[R] B) :=
{ toRing := inferInstance
mul_comm := mul_comm }
end CommRing
section RightAlgebra
variable [CommSemiring R]
variable [Semiring A] [Algebra R A]
variable [CommSemiring B] [Algebra R B]
/-- `S ⊗[R] T` has a `T`-algebra structure. This is not a global instance or else the action of
`S` on `S ⊗[R] S` would be ambiguous. -/
abbrev rightAlgebra : Algebra B (A ⊗[R] B) where
smul b ab := TensorProduct.comm _ _ _ (b • (TensorProduct.comm _ _ _ ab))
algebraMap := Algebra.TensorProduct.includeRight.toRingHom
commutes' b ab := by
induction ab with
| zero => simp only [AlgHom.toRingHom_eq_coe, RingHom.coe_coe,
Algebra.TensorProduct.includeRight_apply, mul_zero, zero_mul]
| tmul x y =>
simp only [AlgHom.toRingHom_eq_coe, RingHom.coe_coe,
Algebra.TensorProduct.includeRight_apply, Algebra.TensorProduct.tmul_mul_tmul, one_mul,
mul_one, mul_comm]
| add x y _ _ =>
simp_all only [AlgHom.toRingHom_eq_coe, RingHom.coe_coe,
Algebra.TensorProduct.includeRight_apply, mul_add, add_mul]
smul_def' b ab := by
induction ab with
| zero =>
change (TensorProduct.comm R B A) _ = _
simp only [map_zero, smul_zero, AlgHom.toRingHom_eq_coe, RingHom.coe_coe,
includeRight_apply, mul_zero]
| tmul a b =>
change (TensorProduct.comm R B A) _ = _
simp only [smul_def, AlgHom.toRingHom_eq_coe, RingHom.coe_coe,
Algebra.TensorProduct.includeRight_apply,
algebraMap_apply, Algebra.algebraMap_self, RingHom.id_apply, comm_tmul,
tmul_mul_tmul]
| add x y hx hy =>
change (TensorProduct.comm R B A) _ = _ at ⊢ hx hy
simp only [map_add, smul_add, mul_add, ← hx, ← hy]
attribute [local instance] TensorProduct.rightAlgebra
lemma algebraMap_eq_includeRight :
letI := rightAlgebra (R := R) (A := A) (B := B)
algebraMap B (A ⊗[R] B) = includeRight (R := R) (A := A) (B := B) := rfl
instance right_isScalarTower : IsScalarTower R B (A ⊗[R] B) :=
IsScalarTower.of_algebraMap_eq fun r => (Algebra.TensorProduct.includeRight.commutes r).symm
lemma right_algebraMap_apply (b : B) : algebraMap B (A ⊗[R] B) b = 1 ⊗ₜ b := rfl
instance : SMulCommClass A B (A ⊗[R] B) where
smul_comm a b x := x.induction_on (by simp)
(fun _ _ ↦ by simp [Algebra.smul_def, right_algebraMap_apply, smul_tmul'])
fun _ _ h₁ h₂ ↦ by simpa using congr($h₁ + $h₂)
instance : SMulCommClass B A (A ⊗[R] B) := .symm ..
end RightAlgebra
/-- Verify that typeclass search finds the ring structure on `A ⊗[ℤ] B`
when `A` and `B` are merely rings, by treating both as `ℤ`-algebras.
-/
example [Ring A] [Ring B] : Ring (A ⊗[ℤ] B) := by infer_instance
/-- Verify that typeclass search finds the CommRing structure on `A ⊗[ℤ] B`
when `A` and `B` are merely `CommRing`s, by treating both as `ℤ`-algebras.
-/
example [CommRing A] [CommRing B] : CommRing (A ⊗[ℤ] B) := by infer_instance
variable (R A B) in
lemma closure_range_union_range_eq_top [CommRing R] [Ring A] [Ring B]
[Algebra R A] [Algebra R B] :
Subring.closure (Set.range (Algebra.TensorProduct.includeLeft : A →ₐ[R] A ⊗[R] B) ∪
Set.range Algebra.TensorProduct.includeRight) = ⊤ := by
rw [← top_le_iff]
rintro x -
induction x with
| zero => exact zero_mem _
| tmul x y =>
convert_to (Algebra.TensorProduct.includeLeftRingHom (R := R) x) *
(Algebra.TensorProduct.includeRight y) ∈ _
· simp
· exact mul_mem (Subring.subset_closure (.inl ⟨x, rfl⟩))
(Subring.subset_closure (.inr ⟨_, rfl⟩))
| add x y _ _ => exact add_mem ‹_› ‹_›
/-- If `s` generates `T` as an `R`-algebra,
then `{ 1 ⊗ x | x ∈ s }` generates `A ⊗[R] T` as an `A`-algebra. -/
lemma adjoin_one_tmul_image_eq_top [CommSemiring R] [CommSemiring A]
[Semiring B] [Algebra R A] [Algebra R B]
(s : Set B) (hs : adjoin R s = ⊤) : adjoin A (((1 : A) ⊗ₜ[R] ·) '' s) = ⊤ := by
suffices h : adjoin A ((⊤ : Subalgebra R B).map (includeRight (A := A)) : Set (A ⊗[R] B)) = ⊤ by
simp [← h, ← hs, AlgHom.map_adjoin, adjoin_adjoin_of_tower]
rw [← Algebra.toSubmodule_eq_top, ← top_le_iff, Algebra.map_top, ← Submodule.baseChange_top,
Submodule.baseChange_eq_span, Submodule.map_top]
exact span_le_adjoin _ _
variable [CommSemiring R] [CommSemiring S] [Algebra R S]
/-- If `M` is a `B`-module that is also an `A`-module, the canonical map
`M →ₗ[A] B ⊗[A] M` is injective. -/
lemma mk_one_injective_of_isScalarTower (M : Type*) [AddCommMonoid M]
[Module R M] [Module S M] [IsScalarTower R S M] :
Function.Injective (TensorProduct.mk R S M 1) := by
apply Function.RightInverse.injective (g := LinearMap.liftBaseChange S LinearMap.id)
intro m
simp
end TensorProduct
end Algebra
lemma Algebra.baseChange_lmul {R B : Type*} [CommSemiring R] [Semiring B] [Algebra R B]
{A : Type*} [CommSemiring A] [Algebra R A] (f : B) :
(Algebra.lmul R B f).baseChange A = Algebra.lmul A (A ⊗[R] B) (1 ⊗ₜ f) := by
ext i
simp
namespace TensorProduct.Algebra
variable {R A B M : Type*}
variable [CommSemiring R] [AddCommMonoid M] [Module R M]
variable [Semiring A] [Semiring B] [Module A M] [Module B M]
variable [Algebra R A] [Algebra R B]
variable [IsScalarTower R A M] [IsScalarTower R B M]
/-- An auxiliary definition, used for constructing the `Module (A ⊗[R] B) M` in
`TensorProduct.Algebra.module` below. -/
def moduleAux : A ⊗[R] B →ₗ[R] M →ₗ[R] M :=
TensorProduct.lift
{ toFun := fun a => a • (Algebra.lsmul R R M : B →ₐ[R] Module.End R M).toLinearMap
map_add' := fun r t => by
ext
simp only [add_smul, LinearMap.add_apply]
map_smul' := fun n r => by
ext
simp only [RingHom.id_apply, LinearMap.smul_apply, smul_assoc] }
theorem moduleAux_apply (a : A) (b : B) (m : M) : moduleAux (a ⊗ₜ[R] b) m = a • b • m :=
rfl
variable [SMulCommClass A B M]
/-- If `M` is a representation of two different `R`-algebras `A` and `B` whose actions commute,
then it is a representation the `R`-algebra `A ⊗[R] B`.
An important example arises from a semiring `S`; allowing `S` to act on itself via left and right
multiplication, the roles of `R`, `A`, `B`, `M` are played by `ℕ`, `S`, `Sᵐᵒᵖ`, `S`. This example
is important because a submodule of `S` as a `Module` over `S ⊗[ℕ] Sᵐᵒᵖ` is a two-sided ideal.
NB: This is not an instance because in the case `B = A` and `M = A ⊗[R] A` we would have a diamond
of `smul` actions. Furthermore, this would not be a mere definitional diamond but a true
mathematical diamond in which `A ⊗[R] A` had two distinct scalar actions on itself: one from its
multiplication, and one from this would-be instance. Arguably we could live with this but in any
case the real fix is to address the ambiguity in notation, probably along the lines outlined here:
https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/.234773.20base.20change/near/240929258
-/
@[instance_reducible]
protected def module : Module (A ⊗[R] B) M where
smul x m := moduleAux x m
zero_smul m := by simp only [(· • ·), map_zero, LinearMap.zero_apply]
smul_zero x := by simp only [(· • ·), map_zero]
smul_add x m₁ m₂ := by simp only [(· • ·), map_add]
add_smul x y m := by simp only [(· • ·), map_add, LinearMap.add_apply]
one_smul m := by
-- Porting note: was one `simp only`, not two
simp only [(· • ·), Algebra.TensorProduct.one_def]
simp only [moduleAux_apply, one_smul]
mul_smul x y m := by
refine TensorProduct.induction_on x ?_ ?_ ?_ <;> refine TensorProduct.induction_on y ?_ ?_ ?_
· simp only [(· • ·), mul_zero, map_zero, LinearMap.zero_apply]
· intro a b
simp only [(· • ·), zero_mul, map_zero, LinearMap.zero_apply]
· intro z w _ _
simp only [(· • ·), zero_mul, map_zero, LinearMap.zero_apply]
· intro a b
simp only [(· • ·), mul_zero, map_zero, LinearMap.zero_apply]
· intro a₁ b₁ a₂ b₂
-- Porting note: was one `simp only`, not two
simp only [(· • ·), Algebra.TensorProduct.tmul_mul_tmul]
simp only [moduleAux_apply, mul_smul, smul_comm a₁ b₂]
· intro z w hz hw a b
-- Porting note: was one `simp only`, but random stuff doesn't work
simp only [(· • ·)] at hz hw ⊢
simp only [moduleAux_apply, mul_add, map_add,
LinearMap.add_apply, moduleAux_apply, hz, hw]
· intro z w _ _
simp only [(· • ·), mul_zero, map_zero, LinearMap.zero_apply]
· intro a b z w hz hw
simp only [(· • ·)] at hz hw ⊢
simp only [map_add, add_mul, LinearMap.add_apply, hz, hw]
· intro u v _ _ z w hz hw
simp only [(· • ·)] at hz hw ⊢
simp only [add_mul, map_add, LinearMap.add_apply, hz, hw, add_add_add_comm]
attribute [local instance] TensorProduct.Algebra.module
theorem smul_def (a : A) (b : B) (m : M) : a ⊗ₜ[R] b • m = a • b • m :=
rfl
section Lemmas
theorem linearMap_comp_mul' :
Algebra.linearMap R (A ⊗[R] B) ∘ₗ LinearMap.mul' R R =
map (Algebra.linearMap R A) (Algebra.linearMap R B) := by
ext
simp only [AlgebraTensorModule.curry_apply, curry_apply, LinearMap.coe_restrictScalars, map_tmul,
Algebra.linearMap_apply, map_one, LinearMap.coe_comp, Function.comp_apply,
LinearMap.mul'_apply, mul_one, Algebra.TensorProduct.one_def]
end Lemmas
end TensorProduct.Algebra
open LinearMap in
lemma Submodule.map_range_rTensor_subtype_lid {R Q} [CommSemiring R] [AddCommMonoid Q]
[Module R Q] {I : Submodule R R} :
(range <| rTensor Q I.subtype).map (TensorProduct.lid R Q : R ⊗[R] Q →ₗ[R] Q) = I • ⊤ := by
rw [← map_top, ← Submodule.map_comp, map_top]
refine le_antisymm ?_ fun q h ↦ Submodule.smul_induction_on h
(fun r hr q _ ↦ ⟨⟨r, hr⟩ ⊗ₜ q, by simp⟩) (by simp +contextual [add_mem])
rintro _ ⟨t, rfl⟩
exact t.induction_on (by simp) (by simp +contextual [Submodule.smul_mem_smul])
(by simp +contextual [add_mem])
section
variable {R M S T : Type*} [CommSemiring R] [AddCommMonoid M] [Module R M]
[Semiring S] [Algebra R S] [Ring T] [Algebra R T]
variable (R S M) in
theorem TensorProduct.mk_surjective (h : Function.Surjective (algebraMap R S)) :
Function.Surjective (TensorProduct.mk R S M 1) := by
rw [← LinearMap.range_eq_top, ← top_le_iff, ← span_tmul_eq_top, Submodule.span_le]
rintro _ ⟨x, y, rfl⟩
obtain ⟨x, rfl⟩ := h x
rw [Algebra.algebraMap_eq_smul_one, smul_tmul]
exact ⟨x • y, rfl⟩
variable (S) in
lemma TensorProduct.flip_mk_surjective (h : Function.Surjective (algebraMap R T)) :
Function.Surjective ((TensorProduct.mk R S T).flip 1) := by
rw [← LinearMap.range_eq_top, ← top_le_iff, ← span_tmul_eq_top, Submodule.span_le]
rintro _ ⟨s, t, rfl⟩
obtain ⟨r, rfl⟩ := h t
rw [Algebra.algebraMap_eq_smul_one, ← smul_tmul]
exact ⟨r • s, rfl⟩
variable (T) in
lemma Algebra.TensorProduct.includeRight_surjective (h : Function.Surjective (algebraMap R S)) :
Function.Surjective (includeRight : T →ₐ[R] S ⊗[R] T) :=
TensorProduct.mk_surjective _ _ _ h
lemma Algebra.TensorProduct.includeLeft_surjective
(S A : Type*) [CommSemiring S] [Semiring A] [Algebra S A] [Algebra R A]
[SMulCommClass R S A] (h : Function.Surjective (algebraMap R T)) :
Function.Surjective (includeLeft : A →ₐ[S] A ⊗[R] T) :=
TensorProduct.flip_mk_surjective _ h
end
variable {R A B : Type*} [CommSemiring R] [NonUnitalNonAssocSemiring A]
[NonUnitalNonAssocSemiring B] [Module R A] [Module R B] [SMulCommClass R A A]
[SMulCommClass R B B] [IsScalarTower R A A] [IsScalarTower R B B]
@[simp]
theorem TensorProduct.Algebra.mul'_comp_tensorTensorTensorComm :
LinearMap.mul' R (A ⊗[R] B) ∘ₗ tensorTensorTensorComm R A A B B =
map (LinearMap.mul' R A) (LinearMap.mul' R B) := by
ext
simp
lemma LinearMap.mul'_tensor :
mul' R (A ⊗[R] B) = map (mul' R A) (mul' R B) ∘ₗ tensorTensorTensorComm R A B A B :=
ext_fourfold' <| by simp
lemma LinearMap.mulLeft_tmul (a : A) (b : B) :
mulLeft R (a ⊗ₜ[R] b) = map (mulLeft R a) (mulLeft R b) := by
ext; simp
lemma LinearMap.mulRight_tmul (a : A) (b : B) :
mulRight R (a ⊗ₜ[R] b) = map (mulRight R a) (mulRight R b) := by
ext; simp
namespace TensorProduct
variable [StarRing R] [StarRing A] [StarRing B] [StarModule R A] [StarModule R B]
noncomputable instance : StarMul (A ⊗[R] B) where
star_mul x y :=
x.induction_on (by simp) (fun _ _ ↦
y.induction_on (by simp)
fun _ _ ↦ by simp
fun _ _ h₁ h₂ ↦ by simp [add_mul, mul_add, h₁, h₂])
fun _ _ h₁ h₂ ↦ by simp [add_mul, mul_add, h₁, h₂]
noncomputable instance : StarRing (A ⊗[R] B) where
star_add := by simp
end TensorProduct
namespace AlgHom
variable (R S A B : Type*)
variable [CommSemiring R] [CommSemiring S] [Semiring A] [Semiring B] [Algebra R A] [Algebra S B]
variable [Algebra R S] [Algebra R B] [IsScalarTower R S B]
/-- Universal property of the base change of algebra.
An algebra map from the base change is equivalent to an algebra map over the base ring.
In categorical terms, this is an adjunction between:
1. `A ↦ S ⊗[R] A`, a functor `R-Alg ⥤ S-Alg` (the base change).
2. `B ↦ B`, a functor `S-Alg ⥤ R-Alg` (the restriction).
-/
def liftEquiv : (A →ₐ[R] B) ≃ (S ⊗[R] A →ₐ[S] B) where
toFun f :=
.ofLinearMap (.liftBaseChange S f) (by simp [Algebra.TensorProduct.one_def]) fun x y ↦ by
rw [← LinearMap.mul_apply_apply S, ← LinearMap.compr₂_apply,
← LinearMap.mul_apply_apply S, ← LinearMap.compl₁₂_apply]
congr; ext; simp
invFun f := f.restrictScalars R |>.comp Algebra.TensorProduct.includeRight
left_inv f := by ext; simp
right_inv f := Algebra.TensorProduct.ext (Subsingleton.elim _ _) <| by ext; simp
variable {R S A B}
@[simp] lemma liftEquiv_tmul (f : A →ₐ[R] B) (s : S) (a : A) :
f.liftEquiv R S A B (s ⊗ₜ a) = s • f a := rfl
@[simp] lemma liftEquiv_symm_apply (f : S ⊗[R] A →ₐ[S] B) (a : A) :
(liftEquiv ..).symm f a = f (1 ⊗ₜ[R] a) := rfl
@[ext high + 1]
lemma _root_.Algebra.TensorProduct.ext_ring {f g : S ⊗[R] A →ₐ[S] B}
(h : (AlgHom.restrictScalars R f).comp Algebra.TensorProduct.includeRight =
(AlgHom.restrictScalars R g).comp Algebra.TensorProduct.includeRight) :
f = g :=
liftEquiv .. |>.symm.injective h
end AlgHom