/
Basic.lean
2156 lines (1726 loc) · 92.4 KB
/
Basic.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, Yury G. Kudryashov, Scott Morrison
-/
import Mathlib.Algebra.Algebra.Equiv
import Mathlib.Algebra.Algebra.NonUnitalHom
import Mathlib.Algebra.BigOperators.Finsupp
import Mathlib.Algebra.Module.BigOperators
import Mathlib.Data.Finsupp.Basic
import Mathlib.LinearAlgebra.Finsupp
#align_import algebra.monoid_algebra.basic from "leanprover-community/mathlib"@"949dc57e616a621462062668c9f39e4e17b64b69"
/-!
# Monoid algebras
When the domain of a `Finsupp` has a multiplicative or additive structure, we can define
a convolution product. To mathematicians this structure is known as the "monoid algebra",
i.e. the finite formal linear combinations over a given semiring of elements of the monoid.
The "group ring" ℤ[G] or the "group algebra" k[G] are typical uses.
In fact the construction of the "monoid algebra" makes sense when `G` is not even a monoid, but
merely a magma, i.e., when `G` carries a multiplication which is not required to satisfy any
conditions at all. In this case the construction yields a not-necessarily-unital,
not-necessarily-associative algebra but it is still adjoint to the forgetful functor from such
algebras to magmas, and we prove this as `MonoidAlgebra.liftMagma`.
In this file we define `MonoidAlgebra k G := G →₀ k`, and `AddMonoidAlgebra k G`
in the same way, and then define the convolution product on these.
When the domain is additive, this is used to define polynomials:
```
Polynomial R := AddMonoidAlgebra R ℕ
MvPolynomial σ α := AddMonoidAlgebra R (σ →₀ ℕ)
```
When the domain is multiplicative, e.g. a group, this will be used to define the group ring.
## Notation
We introduce the notation `R[A]` for `AddMonoidAlgebra R A`.
## Implementation note
Unfortunately because additive and multiplicative structures both appear in both cases,
it doesn't appear to be possible to make much use of `to_additive`, and we just settle for
saying everything twice.
Similarly, I attempted to just define
`k[G] := MonoidAlgebra k (Multiplicative G)`, but the definitional equality
`Multiplicative G = G` leaks through everywhere, and seems impossible to use.
-/
noncomputable section
open BigOperators
open Finset
open Finsupp hiding single mapDomain
universe u₁ u₂ u₃ u₄
variable (k : Type u₁) (G : Type u₂) (H : Type*) {R : Type*}
/-! ### Multiplicative monoids -/
section
variable [Semiring k]
/-- The monoid algebra over a semiring `k` generated by the monoid `G`.
It is the type of finite formal `k`-linear combinations of terms of `G`,
endowed with the convolution product.
-/
def MonoidAlgebra : Type max u₁ u₂ :=
G →₀ k
#align monoid_algebra MonoidAlgebra
-- Porting note: The compiler couldn't derive this.
instance MonoidAlgebra.inhabited : Inhabited (MonoidAlgebra k G) :=
inferInstanceAs (Inhabited (G →₀ k))
#align monoid_algebra.inhabited MonoidAlgebra.inhabited
-- Porting note: The compiler couldn't derive this.
instance MonoidAlgebra.addCommMonoid : AddCommMonoid (MonoidAlgebra k G) :=
inferInstanceAs (AddCommMonoid (G →₀ k))
#align monoid_algebra.add_comm_monoid MonoidAlgebra.addCommMonoid
instance MonoidAlgebra.instIsCancelAdd [IsCancelAdd k] : IsCancelAdd (MonoidAlgebra k G) :=
inferInstanceAs (IsCancelAdd (G →₀ k))
instance MonoidAlgebra.coeFun : CoeFun (MonoidAlgebra k G) fun _ => G → k :=
Finsupp.instCoeFun
#align monoid_algebra.has_coe_to_fun MonoidAlgebra.coeFun
end
namespace MonoidAlgebra
variable {k G}
section
variable [Semiring k] [NonUnitalNonAssocSemiring R]
-- Porting note: `reducible` cannot be `local`, so we replace some definitions and theorems with
-- new ones which have new types.
abbrev single (a : G) (b : k) : MonoidAlgebra k G := Finsupp.single a b
theorem single_zero (a : G) : (single a 0 : MonoidAlgebra k G) = 0 := Finsupp.single_zero a
theorem single_add (a : G) (b₁ b₂ : k) : single a (b₁ + b₂) = single a b₁ + single a b₂ :=
Finsupp.single_add a b₁ b₂
@[simp]
theorem sum_single_index {N} [AddCommMonoid N] {a : G} {b : k} {h : G → k → N}
(h_zero : h a 0 = 0) :
(single a b).sum h = h a b := Finsupp.sum_single_index h_zero
@[simp]
theorem sum_single (f : MonoidAlgebra k G) : f.sum single = f :=
Finsupp.sum_single f
theorem single_apply {a a' : G} {b : k} [Decidable (a = a')] :
single a b a' = if a = a' then b else 0 :=
Finsupp.single_apply
@[simp]
theorem single_eq_zero {a : G} {b : k} : single a b = 0 ↔ b = 0 := Finsupp.single_eq_zero
abbrev mapDomain {G' : Type*} (f : G → G') (v : MonoidAlgebra k G) : MonoidAlgebra k G' :=
Finsupp.mapDomain f v
theorem mapDomain_sum {k' G' : Type*} [Semiring k'] {f : G → G'} {s : MonoidAlgebra k' G}
{v : G → k' → MonoidAlgebra k G} :
mapDomain f (s.sum v) = s.sum fun a b => mapDomain f (v a b) :=
Finsupp.mapDomain_sum
/-- A non-commutative version of `MonoidAlgebra.lift`: given an additive homomorphism `f : k →+ R`
and a homomorphism `g : G → R`, returns the additive homomorphism from
`MonoidAlgebra k G` such that `liftNC f g (single a b) = f b * g a`. If `f` is a ring homomorphism
and the range of either `f` or `g` is in center of `R`, then the result is a ring homomorphism. If
`R` is a `k`-algebra and `f = algebraMap k R`, then the result is an algebra homomorphism called
`MonoidAlgebra.lift`. -/
def liftNC (f : k →+ R) (g : G → R) : MonoidAlgebra k G →+ R :=
liftAddHom fun x : G => (AddMonoidHom.mulRight (g x)).comp f
#align monoid_algebra.lift_nc MonoidAlgebra.liftNC
@[simp]
theorem liftNC_single (f : k →+ R) (g : G → R) (a : G) (b : k) :
liftNC f g (single a b) = f b * g a :=
liftAddHom_apply_single _ _ _
#align monoid_algebra.lift_nc_single MonoidAlgebra.liftNC_single
end
section Mul
variable [Semiring k] [Mul G]
/-- The product of `f g : MonoidAlgebra k G` is the finitely supported function
whose value at `a` is the sum of `f x * g y` over all pairs `x, y`
such that `x * y = a`. (Think of the group ring of a group.) -/
instance mul : Mul (MonoidAlgebra k G) :=
⟨fun f g => f.sum fun a₁ b₁ => g.sum fun a₂ b₂ => single (a₁ * a₂) (b₁ * b₂)⟩
#align monoid_algebra.has_mul MonoidAlgebra.mul
theorem mul_def {f g : MonoidAlgebra k G} :
f * g = f.sum fun a₁ b₁ => g.sum fun a₂ b₂ => single (a₁ * a₂) (b₁ * b₂) :=
rfl
#align monoid_algebra.mul_def MonoidAlgebra.mul_def
instance nonUnitalNonAssocSemiring : NonUnitalNonAssocSemiring (MonoidAlgebra k G) :=
{ Finsupp.instAddCommMonoid with
-- Porting note: `refine` & `exact` are required because `simp` behaves differently.
left_distrib := fun f g h => by
haveI := Classical.decEq G
simp only [mul_def]
refine Eq.trans (congr_arg (sum f) (funext₂ fun a₁ b₁ => sum_add_index ?_ ?_)) ?_ <;>
simp only [mul_add, mul_zero, single_zero, single_add, forall_true_iff, sum_add]
right_distrib := fun f g h => by
haveI := Classical.decEq G
simp only [mul_def]
refine Eq.trans (sum_add_index ?_ ?_) ?_ <;>
simp only [add_mul, zero_mul, single_zero, single_add, forall_true_iff, sum_zero, sum_add]
zero_mul := fun f => by
simp only [mul_def]
exact sum_zero_index
mul_zero := fun f => by
simp only [mul_def]
exact Eq.trans (congr_arg (sum f) (funext₂ fun a₁ b₁ => sum_zero_index)) sum_zero }
#align monoid_algebra.non_unital_non_assoc_semiring MonoidAlgebra.nonUnitalNonAssocSemiring
variable [Semiring R]
theorem liftNC_mul {g_hom : Type*} [FunLike g_hom G R] [MulHomClass g_hom G R]
(f : k →+* R) (g : g_hom) (a b : MonoidAlgebra k G)
(h_comm : ∀ {x y}, y ∈ a.support → Commute (f (b x)) (g y)) :
liftNC (f : k →+ R) g (a * b) = liftNC (f : k →+ R) g a * liftNC (f : k →+ R) g b := by
conv_rhs => rw [← sum_single a, ← sum_single b]
-- Porting note: `(liftNC _ g).map_finsupp_sum` → `map_finsupp_sum`
simp_rw [mul_def, map_finsupp_sum, liftNC_single, Finsupp.sum_mul, Finsupp.mul_sum]
refine Finset.sum_congr rfl fun y hy => Finset.sum_congr rfl fun x _hx => ?_
simp [mul_assoc, (h_comm hy).left_comm]
#align monoid_algebra.lift_nc_mul MonoidAlgebra.liftNC_mul
end Mul
section Semigroup
variable [Semiring k] [Semigroup G] [Semiring R]
instance nonUnitalSemiring : NonUnitalSemiring (MonoidAlgebra k G) :=
{ MonoidAlgebra.nonUnitalNonAssocSemiring with
mul_assoc := fun f g h => by
-- Porting note: `reducible` cannot be `local` so proof gets long.
simp only [mul_def]
rw [sum_sum_index]; congr; ext a₁ b₁
rw [sum_sum_index, sum_sum_index]; congr; ext a₂ b₂
rw [sum_sum_index, sum_single_index]; congr; ext a₃ b₃
rw [sum_single_index, mul_assoc, mul_assoc]
all_goals simp only [single_zero, single_add, forall_true_iff, add_mul,
mul_add, zero_mul, mul_zero, sum_zero, sum_add] }
#align monoid_algebra.non_unital_semiring MonoidAlgebra.nonUnitalSemiring
end Semigroup
section One
variable [NonAssocSemiring R] [Semiring k] [One G]
/-- The unit of the multiplication is `single 1 1`, i.e. the function
that is `1` at `1` and zero elsewhere. -/
instance one : One (MonoidAlgebra k G) :=
⟨single 1 1⟩
#align monoid_algebra.has_one MonoidAlgebra.one
theorem one_def : (1 : MonoidAlgebra k G) = single 1 1 :=
rfl
#align monoid_algebra.one_def MonoidAlgebra.one_def
@[simp]
theorem liftNC_one {g_hom : Type*} [FunLike g_hom G R] [OneHomClass g_hom G R]
(f : k →+* R) (g : g_hom) :
liftNC (f : k →+ R) g 1 = 1 := by simp [one_def]
#align monoid_algebra.lift_nc_one MonoidAlgebra.liftNC_one
end One
section MulOneClass
variable [Semiring k] [MulOneClass G]
instance nonAssocSemiring : NonAssocSemiring (MonoidAlgebra k G) :=
{ MonoidAlgebra.nonUnitalNonAssocSemiring with
natCast := fun n => single 1 n
natCast_zero := by simp
natCast_succ := fun _ => by simp; rfl
one_mul := fun f => by
simp only [mul_def, one_def, sum_single_index, zero_mul, single_zero, sum_zero, zero_add,
one_mul, sum_single]
mul_one := fun f => by
simp only [mul_def, one_def, sum_single_index, mul_zero, single_zero, sum_zero, add_zero,
mul_one, sum_single] }
#align monoid_algebra.non_assoc_semiring MonoidAlgebra.nonAssocSemiring
theorem natCast_def (n : ℕ) : (n : MonoidAlgebra k G) = single (1 : G) (n : k) :=
rfl
#align monoid_algebra.nat_cast_def MonoidAlgebra.natCast_def
end MulOneClass
/-! #### Semiring structure -/
section Semiring
variable [Semiring k] [Monoid G]
instance semiring : Semiring (MonoidAlgebra k G) :=
{ MonoidAlgebra.nonUnitalSemiring,
MonoidAlgebra.nonAssocSemiring with }
#align monoid_algebra.semiring MonoidAlgebra.semiring
variable [Semiring R]
/-- `liftNC` as a `RingHom`, for when `f x` and `g y` commute -/
def liftNCRingHom (f : k →+* R) (g : G →* R) (h_comm : ∀ x y, Commute (f x) (g y)) :
MonoidAlgebra k G →+* R :=
{ liftNC (f : k →+ R) g with
map_one' := liftNC_one _ _
map_mul' := fun _a _b => liftNC_mul _ _ _ _ fun {_ _} _ => h_comm _ _ }
#align monoid_algebra.lift_nc_ring_hom MonoidAlgebra.liftNCRingHom
end Semiring
instance nonUnitalCommSemiring [CommSemiring k] [CommSemigroup G] :
NonUnitalCommSemiring (MonoidAlgebra k G) :=
{ MonoidAlgebra.nonUnitalSemiring with
mul_comm := fun f g => by
simp only [mul_def, Finsupp.sum, mul_comm]
rw [Finset.sum_comm]
simp only [mul_comm] }
#align monoid_algebra.non_unital_comm_semiring MonoidAlgebra.nonUnitalCommSemiring
instance nontrivial [Semiring k] [Nontrivial k] [Nonempty G] : Nontrivial (MonoidAlgebra k G) :=
Finsupp.instNontrivial
#align monoid_algebra.nontrivial MonoidAlgebra.nontrivial
/-! #### Derived instances -/
section DerivedInstances
instance commSemiring [CommSemiring k] [CommMonoid G] : CommSemiring (MonoidAlgebra k G) :=
{ MonoidAlgebra.nonUnitalCommSemiring, MonoidAlgebra.semiring with }
#align monoid_algebra.comm_semiring MonoidAlgebra.commSemiring
instance unique [Semiring k] [Subsingleton k] : Unique (MonoidAlgebra k G) :=
Finsupp.uniqueOfRight
#align monoid_algebra.unique MonoidAlgebra.unique
instance addCommGroup [Ring k] : AddCommGroup (MonoidAlgebra k G) :=
Finsupp.instAddCommGroup
#align monoid_algebra.add_comm_group MonoidAlgebra.addCommGroup
instance nonUnitalNonAssocRing [Ring k] [Mul G] : NonUnitalNonAssocRing (MonoidAlgebra k G) :=
{ MonoidAlgebra.addCommGroup, MonoidAlgebra.nonUnitalNonAssocSemiring with }
#align monoid_algebra.non_unital_non_assoc_ring MonoidAlgebra.nonUnitalNonAssocRing
instance nonUnitalRing [Ring k] [Semigroup G] : NonUnitalRing (MonoidAlgebra k G) :=
{ MonoidAlgebra.addCommGroup, MonoidAlgebra.nonUnitalSemiring with }
#align monoid_algebra.non_unital_ring MonoidAlgebra.nonUnitalRing
instance nonAssocRing [Ring k] [MulOneClass G] : NonAssocRing (MonoidAlgebra k G) :=
{ MonoidAlgebra.addCommGroup,
MonoidAlgebra.nonAssocSemiring with
intCast := fun z => single 1 (z : k)
-- Porting note: Both were `simpa`.
intCast_ofNat := fun n => by simp; rfl
intCast_negSucc := fun n => by simp; rfl }
#align monoid_algebra.non_assoc_ring MonoidAlgebra.nonAssocRing
theorem intCast_def [Ring k] [MulOneClass G] (z : ℤ) :
(z : MonoidAlgebra k G) = single (1 : G) (z : k) :=
rfl
#align monoid_algebra.int_cast_def MonoidAlgebra.intCast_def
instance ring [Ring k] [Monoid G] : Ring (MonoidAlgebra k G) :=
{ MonoidAlgebra.nonAssocRing, MonoidAlgebra.semiring with }
#align monoid_algebra.ring MonoidAlgebra.ring
instance nonUnitalCommRing [CommRing k] [CommSemigroup G] :
NonUnitalCommRing (MonoidAlgebra k G) :=
{ MonoidAlgebra.nonUnitalCommSemiring, MonoidAlgebra.nonUnitalRing with }
#align monoid_algebra.non_unital_comm_ring MonoidAlgebra.nonUnitalCommRing
instance commRing [CommRing k] [CommMonoid G] : CommRing (MonoidAlgebra k G) :=
{ MonoidAlgebra.nonUnitalCommRing, MonoidAlgebra.ring with }
#align monoid_algebra.comm_ring MonoidAlgebra.commRing
variable {S : Type*}
instance smulZeroClass [Semiring k] [SMulZeroClass R k] : SMulZeroClass R (MonoidAlgebra k G) :=
Finsupp.smulZeroClass
#align monoid_algebra.smul_zero_class MonoidAlgebra.smulZeroClass
instance distribSMul [Semiring k] [DistribSMul R k] : DistribSMul R (MonoidAlgebra k G) :=
Finsupp.distribSMul _ _
#align monoid_algebra.distrib_smul MonoidAlgebra.distribSMul
instance distribMulAction [Monoid R] [Semiring k] [DistribMulAction R k] :
DistribMulAction R (MonoidAlgebra k G) :=
Finsupp.distribMulAction G k
#align monoid_algebra.distrib_mul_action MonoidAlgebra.distribMulAction
instance module [Semiring R] [Semiring k] [Module R k] : Module R (MonoidAlgebra k G) :=
Finsupp.module G k
#align monoid_algebra.module MonoidAlgebra.module
instance faithfulSMul [Monoid R] [Semiring k] [DistribMulAction R k] [FaithfulSMul R k]
[Nonempty G] : FaithfulSMul R (MonoidAlgebra k G) :=
Finsupp.faithfulSMul
#align monoid_algebra.has_faithful_smul MonoidAlgebra.faithfulSMul
instance isScalarTower [Semiring k] [SMulZeroClass R k] [SMulZeroClass S k] [SMul R S]
[IsScalarTower R S k] : IsScalarTower R S (MonoidAlgebra k G) :=
Finsupp.isScalarTower G k
#align monoid_algebra.is_scalar_tower MonoidAlgebra.isScalarTower
instance smulCommClass [Monoid R] [Monoid S] [Semiring k] [DistribMulAction R k]
[DistribMulAction S k] [SMulCommClass R S k] : SMulCommClass R S (MonoidAlgebra k G) :=
Finsupp.smulCommClass G k
#align monoid_algebra.smul_comm_tower MonoidAlgebra.smulCommClass
instance isCentralScalar [Monoid R] [Semiring k] [DistribMulAction R k] [DistribMulAction Rᵐᵒᵖ k]
[IsCentralScalar R k] : IsCentralScalar R (MonoidAlgebra k G) :=
Finsupp.isCentralScalar G k
#align monoid_algebra.is_central_scalar MonoidAlgebra.isCentralScalar
/-- This is not an instance as it conflicts with `MonoidAlgebra.distribMulAction` when `G = kˣ`.
-/
def comapDistribMulActionSelf [Group G] [Semiring k] : DistribMulAction G (MonoidAlgebra k G) :=
Finsupp.comapDistribMulAction
#align monoid_algebra.comap_distrib_mul_action_self MonoidAlgebra.comapDistribMulActionSelf
end DerivedInstances
section MiscTheorems
variable [Semiring k]
-- attribute [local reducible] MonoidAlgebra -- Porting note: `reducible` cannot be `local`.
theorem mul_apply [DecidableEq G] [Mul G] (f g : MonoidAlgebra k G) (x : G) :
(f * g) x = f.sum fun a₁ b₁ => g.sum fun a₂ b₂ => if a₁ * a₂ = x then b₁ * b₂ else 0 := by
-- Porting note: `reducible` cannot be `local` so proof gets long.
rw [mul_def, Finsupp.sum_apply]; congr; ext
rw [Finsupp.sum_apply]; congr; ext
apply single_apply
#align monoid_algebra.mul_apply MonoidAlgebra.mul_apply
theorem mul_apply_antidiagonal [Mul G] (f g : MonoidAlgebra k G) (x : G) (s : Finset (G × G))
(hs : ∀ {p : G × G}, p ∈ s ↔ p.1 * p.2 = x) : (f * g) x = ∑ p in s, f p.1 * g p.2 := by
classical exact
let F : G × G → k := fun p => if p.1 * p.2 = x then f p.1 * g p.2 else 0
calc
(f * g) x = ∑ a₁ in f.support, ∑ a₂ in g.support, F (a₁, a₂) := mul_apply f g x
_ = ∑ p in f.support ×ˢ g.support, F p := Finset.sum_product.symm
_ = ∑ p in (f.support ×ˢ g.support).filter fun p : G × G => p.1 * p.2 = x, f p.1 * g p.2 :=
(Finset.sum_filter _ _).symm
_ = ∑ p in s.filter fun p : G × G => p.1 ∈ f.support ∧ p.2 ∈ g.support, f p.1 * g p.2 :=
(sum_congr
(by
ext
simp only [mem_filter, mem_product, hs, and_comm])
fun _ _ => rfl)
_ = ∑ p in s, f p.1 * g p.2 :=
sum_subset (filter_subset _ _) fun p hps hp => by
simp only [mem_filter, mem_support_iff, not_and, Classical.not_not] at hp ⊢
by_cases h1 : f p.1 = 0
· rw [h1, zero_mul]
· rw [hp hps h1, mul_zero]
#align monoid_algebra.mul_apply_antidiagonal MonoidAlgebra.mul_apply_antidiagonal
@[simp]
theorem single_mul_single [Mul G] {a₁ a₂ : G} {b₁ b₂ : k} :
single a₁ b₁ * single a₂ b₂ = single (a₁ * a₂) (b₁ * b₂) :=
(sum_single_index (by simp only [zero_mul, single_zero, sum_zero])).trans
(sum_single_index (by rw [mul_zero, single_zero]))
#align monoid_algebra.single_mul_single MonoidAlgebra.single_mul_single
theorem single_commute_single [Mul G] {a₁ a₂ : G} {b₁ b₂ : k}
(ha : Commute a₁ a₂) (hb : Commute b₁ b₂) :
Commute (single a₁ b₁) (single a₂ b₂) :=
single_mul_single.trans <| congr_arg₂ single ha hb |>.trans single_mul_single.symm
theorem single_commute [Mul G] {a : G} {b : k} (ha : ∀ a', Commute a a') (hb : ∀ b', Commute b b') :
∀ f : MonoidAlgebra k G, Commute (single a b) f :=
suffices AddMonoidHom.mulLeft (single a b) = AddMonoidHom.mulRight (single a b) from
DFunLike.congr_fun this
addHom_ext' fun a' => AddMonoidHom.ext fun b' => single_commute_single (ha a') (hb b')
@[simp]
theorem single_pow [Monoid G] {a : G} {b : k} : ∀ n : ℕ, single a b ^ n = single (a ^ n) (b ^ n)
| 0 => by
simp only [pow_zero]
rfl
| n + 1 => by simp only [pow_succ, single_pow n, single_mul_single]
#align monoid_algebra.single_pow MonoidAlgebra.single_pow
section
/-- Like `Finsupp.mapDomain_zero`, but for the `1` we define in this file -/
@[simp]
theorem mapDomain_one {α : Type*} {β : Type*} {α₂ : Type*} [Semiring β] [One α] [One α₂]
{F : Type*} [FunLike F α α₂] [OneHomClass F α α₂] (f : F) :
(mapDomain f (1 : MonoidAlgebra β α) : MonoidAlgebra β α₂) = (1 : MonoidAlgebra β α₂) := by
simp_rw [one_def, mapDomain_single, map_one]
#align monoid_algebra.map_domain_one MonoidAlgebra.mapDomain_one
/-- Like `Finsupp.mapDomain_add`, but for the convolutive multiplication we define in this file -/
theorem mapDomain_mul {α : Type*} {β : Type*} {α₂ : Type*} [Semiring β] [Mul α] [Mul α₂]
{F : Type*} [FunLike F α α₂] [MulHomClass F α α₂] (f : F) (x y : MonoidAlgebra β α) :
mapDomain f (x * y) = mapDomain f x * mapDomain f y := by
simp_rw [mul_def, mapDomain_sum, mapDomain_single, map_mul]
rw [Finsupp.sum_mapDomain_index]
· congr
ext a b
rw [Finsupp.sum_mapDomain_index]
· simp
· simp [mul_add]
· simp
· simp [add_mul]
#align monoid_algebra.map_domain_mul MonoidAlgebra.mapDomain_mul
variable (k G)
/-- The embedding of a magma into its magma algebra. -/
@[simps]
def ofMagma [Mul G] : G →ₙ* MonoidAlgebra k G where
toFun a := single a 1
map_mul' a b := by simp only [mul_def, mul_one, sum_single_index, single_eq_zero, mul_zero]
#align monoid_algebra.of_magma MonoidAlgebra.ofMagma
#align monoid_algebra.of_magma_apply MonoidAlgebra.ofMagma_apply
/-- The embedding of a unital magma into its magma algebra. -/
@[simps]
def of [MulOneClass G] : G →* MonoidAlgebra k G :=
{ ofMagma k G with
toFun := fun a => single a 1
map_one' := rfl }
#align monoid_algebra.of MonoidAlgebra.of
#align monoid_algebra.of_apply MonoidAlgebra.of_apply
end
theorem smul_of [MulOneClass G] (g : G) (r : k) : r • of k G g = single g r := by
-- porting note (#10745): was `simp`.
rw [of_apply, smul_single', mul_one]
#align monoid_algebra.smul_of MonoidAlgebra.smul_of
theorem of_injective [MulOneClass G] [Nontrivial k] :
Function.Injective (of k G) := fun a b h => by
simpa using (single_eq_single_iff _ _ _ _).mp h
#align monoid_algebra.of_injective MonoidAlgebra.of_injective
theorem of_commute [MulOneClass G] {a : G} (h : ∀ a', Commute a a') (f : MonoidAlgebra k G) :
Commute (of k G a) f :=
single_commute h Commute.one_left f
/-- `Finsupp.single` as a `MonoidHom` from the product type into the monoid algebra.
Note the order of the elements of the product are reversed compared to the arguments of
`Finsupp.single`.
-/
@[simps]
def singleHom [MulOneClass G] : k × G →* MonoidAlgebra k G where
toFun a := single a.2 a.1
map_one' := rfl
map_mul' _a _b := single_mul_single.symm
#align monoid_algebra.single_hom MonoidAlgebra.singleHom
#align monoid_algebra.single_hom_apply MonoidAlgebra.singleHom_apply
theorem mul_single_apply_aux [Mul G] (f : MonoidAlgebra k G) {r : k} {x y z : G}
(H : ∀ a, a * x = z ↔ a = y) : (f * single x r) z = f y * r := by
classical exact
have A :
∀ a₁ b₁,
((single x r).sum fun a₂ b₂ => ite (a₁ * a₂ = z) (b₁ * b₂) 0) =
ite (a₁ * x = z) (b₁ * r) 0 :=
fun a₁ b₁ => sum_single_index <| by simp
calc
(HMul.hMul (β := MonoidAlgebra k G) f (single x r)) z =
sum f fun a b => if a = y then b * r else 0 := by simp only [mul_apply, A, H]
_ = if y ∈ f.support then f y * r else 0 := f.support.sum_ite_eq' _ _
_ = f y * r := by split_ifs with h <;> simp at h <;> simp [h]
#align monoid_algebra.mul_single_apply_aux MonoidAlgebra.mul_single_apply_aux
theorem mul_single_one_apply [MulOneClass G] (f : MonoidAlgebra k G) (r : k) (x : G) :
(HMul.hMul (β := MonoidAlgebra k G) f (single 1 r)) x = f x * r :=
f.mul_single_apply_aux fun a => by rw [mul_one]
#align monoid_algebra.mul_single_one_apply MonoidAlgebra.mul_single_one_apply
theorem mul_single_apply_of_not_exists_mul [Mul G] (r : k) {g g' : G} (x : MonoidAlgebra k G)
(h : ¬∃ d, g' = d * g) : (x * single g r) g' = 0 := by
classical
rw [mul_apply, Finsupp.sum_comm, Finsupp.sum_single_index]
swap
· simp_rw [Finsupp.sum, mul_zero, ite_self, Finset.sum_const_zero]
· apply Finset.sum_eq_zero
simp_rw [ite_eq_right_iff]
rintro g'' _hg'' rfl
exfalso
exact h ⟨_, rfl⟩
#align monoid_algebra.mul_single_apply_of_not_exists_mul MonoidAlgebra.mul_single_apply_of_not_exists_mul
theorem single_mul_apply_aux [Mul G] (f : MonoidAlgebra k G) {r : k} {x y z : G}
(H : ∀ a, x * a = y ↔ a = z) : (single x r * f) y = r * f z := by
classical exact
have : (f.sum fun a b => ite (x * a = y) (0 * b) 0) = 0 := by simp
calc
(HMul.hMul (α := MonoidAlgebra k G) (single x r) f) y =
sum f fun a b => ite (x * a = y) (r * b) 0 :=
(mul_apply _ _ _).trans <| sum_single_index this
_ = f.sum fun a b => ite (a = z) (r * b) 0 := by simp only [H]
_ = if z ∈ f.support then r * f z else 0 := f.support.sum_ite_eq' _ _
_ = _ := by split_ifs with h <;> simp at h <;> simp [h]
#align monoid_algebra.single_mul_apply_aux MonoidAlgebra.single_mul_apply_aux
theorem single_one_mul_apply [MulOneClass G] (f : MonoidAlgebra k G) (r : k) (x : G) :
(single (1 : G) r * f) x = r * f x :=
f.single_mul_apply_aux fun a => by rw [one_mul]
#align monoid_algebra.single_one_mul_apply MonoidAlgebra.single_one_mul_apply
theorem single_mul_apply_of_not_exists_mul [Mul G] (r : k) {g g' : G} (x : MonoidAlgebra k G)
(h : ¬∃ d, g' = g * d) : (single g r * x) g' = 0 := by
classical
rw [mul_apply, Finsupp.sum_single_index]
swap
· simp_rw [Finsupp.sum, zero_mul, ite_self, Finset.sum_const_zero]
· apply Finset.sum_eq_zero
simp_rw [ite_eq_right_iff]
rintro g'' _hg'' rfl
exfalso
exact h ⟨_, rfl⟩
#align monoid_algebra.single_mul_apply_of_not_exists_mul MonoidAlgebra.single_mul_apply_of_not_exists_mul
theorem liftNC_smul [MulOneClass G] {R : Type*} [Semiring R] (f : k →+* R) (g : G →* R) (c : k)
(φ : MonoidAlgebra k G) : liftNC (f : k →+ R) g (c • φ) = f c * liftNC (f : k →+ R) g φ := by
suffices (liftNC (↑f) g).comp (smulAddHom k (MonoidAlgebra k G) c) =
(AddMonoidHom.mulLeft (f c)).comp (liftNC (↑f) g) from
DFunLike.congr_fun this φ
-- Porting note: `ext` couldn't a find appropriate theorem.
refine addHom_ext' fun a => AddMonoidHom.ext fun b => ?_
-- Porting note: `reducible` cannot be `local` so the proof gets more complex.
unfold MonoidAlgebra
simp only [AddMonoidHom.coe_comp, Function.comp_apply, singleAddHom_apply, smulAddHom_apply,
smul_single, smul_eq_mul, AddMonoidHom.coe_mulLeft]
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [liftNC_single, liftNC_single]; rw [AddMonoidHom.coe_coe, map_mul, mul_assoc]
#align monoid_algebra.lift_nc_smul MonoidAlgebra.liftNC_smul
end MiscTheorems
/-! #### Non-unital, non-associative algebra structure -/
section NonUnitalNonAssocAlgebra
variable (k) [Semiring k] [DistribSMul R k] [Mul G]
instance isScalarTower_self [IsScalarTower R k k] :
IsScalarTower R (MonoidAlgebra k G) (MonoidAlgebra k G) :=
⟨fun t a b => by
-- Porting note: `ext` → `refine Finsupp.ext fun _ => ?_`
refine Finsupp.ext fun m => ?_
-- Porting note: `refine` & `rw` are required because `simp` behaves differently.
classical
simp only [smul_eq_mul, mul_apply]
rw [coe_smul]
refine Eq.trans (sum_smul_index' (g := a) (b := t) ?_) ?_ <;>
simp only [mul_apply, Finsupp.smul_sum, smul_ite, smul_mul_assoc,
zero_mul, ite_self, imp_true_iff, sum_zero, Pi.smul_apply, smul_zero]⟩
#align monoid_algebra.is_scalar_tower_self MonoidAlgebra.isScalarTower_self
/-- Note that if `k` is a `CommSemiring` then we have `SMulCommClass k k k` and so we can take
`R = k` in the below. In other words, if the coefficients are commutative amongst themselves, they
also commute with the algebra multiplication. -/
instance smulCommClass_self [SMulCommClass R k k] :
SMulCommClass R (MonoidAlgebra k G) (MonoidAlgebra k G) :=
⟨fun t a b => by
-- Porting note: `ext` → `refine Finsupp.ext fun _ => ?_`
refine Finsupp.ext fun m => ?_
-- Porting note: `refine` & `rw` are required because `simp` behaves differently.
classical
simp only [smul_eq_mul, mul_apply]
rw [coe_smul]
refine Eq.symm (Eq.trans (congr_arg (sum a)
(funext₂ fun a₁ b₁ => sum_smul_index' (g := b) (b := t) ?_)) ?_) <;>
simp only [mul_apply, Finsupp.sum, Finset.smul_sum, smul_ite, mul_smul_comm,
imp_true_iff, ite_eq_right_iff, Pi.smul_apply, mul_zero, smul_zero]⟩
#align monoid_algebra.smul_comm_class_self MonoidAlgebra.smulCommClass_self
instance smulCommClass_symm_self [SMulCommClass k R k] :
SMulCommClass (MonoidAlgebra k G) R (MonoidAlgebra k G) :=
⟨fun t a b => by
haveI := SMulCommClass.symm k R k
rw [← smul_comm]⟩
#align monoid_algebra.smul_comm_class_symm_self MonoidAlgebra.smulCommClass_symm_self
variable {A : Type u₃} [NonUnitalNonAssocSemiring A]
/-- A non_unital `k`-algebra homomorphism from `MonoidAlgebra k G` is uniquely defined by its
values on the functions `single a 1`. -/
theorem nonUnitalAlgHom_ext [DistribMulAction k A] {φ₁ φ₂ : MonoidAlgebra k G →ₙₐ[k] A}
(h : ∀ x, φ₁ (single x 1) = φ₂ (single x 1)) : φ₁ = φ₂ :=
NonUnitalAlgHom.to_distribMulActionHom_injective <|
Finsupp.distribMulActionHom_ext' fun a => DistribMulActionHom.ext_ring (h a)
#align monoid_algebra.non_unital_alg_hom_ext MonoidAlgebra.nonUnitalAlgHom_ext
/-- See note [partially-applied ext lemmas]. -/
@[ext high]
theorem nonUnitalAlgHom_ext' [DistribMulAction k A] {φ₁ φ₂ : MonoidAlgebra k G →ₙₐ[k] A}
(h : φ₁.toMulHom.comp (ofMagma k G) = φ₂.toMulHom.comp (ofMagma k G)) : φ₁ = φ₂ :=
nonUnitalAlgHom_ext k <| DFunLike.congr_fun h
#align monoid_algebra.non_unital_alg_hom_ext' MonoidAlgebra.nonUnitalAlgHom_ext'
/-- The functor `G ↦ MonoidAlgebra k G`, from the category of magmas to the category of non-unital,
non-associative algebras over `k` is adjoint to the forgetful functor in the other direction. -/
@[simps apply_apply symm_apply]
def liftMagma [Module k A] [IsScalarTower k A A] [SMulCommClass k A A] :
(G →ₙ* A) ≃ (MonoidAlgebra k G →ₙₐ[k] A) where
toFun f :=
{ liftAddHom fun x => (smulAddHom k A).flip (f x) with
toFun := fun a => a.sum fun m t => t • f m
map_smul' := fun t' a => by
-- Porting note(#12129): additional beta reduction needed
beta_reduce
rw [Finsupp.smul_sum, sum_smul_index']
· simp_rw [smul_assoc, MonoidHom.id_apply]
· intro m
exact zero_smul k (f m)
map_mul' := fun a₁ a₂ => by
let g : G → k → A := fun m t => t • f m
have h₁ : ∀ m, g m 0 = 0 := by
intro m
exact zero_smul k (f m)
have h₂ : ∀ (m) (t₁ t₂ : k), g m (t₁ + t₂) = g m t₁ + g m t₂ := by
intros
rw [← add_smul]
-- Porting note: `reducible` cannot be `local` so proof gets long.
simp_rw [Finsupp.mul_sum, Finsupp.sum_mul, smul_mul_smul, ← f.map_mul, mul_def,
sum_comm a₂ a₁]
rw [sum_sum_index h₁ h₂]; congr; ext
rw [sum_sum_index h₁ h₂]; congr; ext
rw [sum_single_index (h₁ _)] }
invFun F := F.toMulHom.comp (ofMagma k G)
left_inv f := by
ext m
simp only [NonUnitalAlgHom.coe_mk, ofMagma_apply, NonUnitalAlgHom.toMulHom_eq_coe,
sum_single_index, Function.comp_apply, one_smul, zero_smul, MulHom.coe_comp,
NonUnitalAlgHom.coe_to_mulHom]
right_inv F := by
-- Porting note: `ext` → `refine nonUnitalAlgHom_ext' k (MulHom.ext fun m => ?_)`
refine nonUnitalAlgHom_ext' k (MulHom.ext fun m => ?_)
simp only [NonUnitalAlgHom.coe_mk, ofMagma_apply, NonUnitalAlgHom.toMulHom_eq_coe,
sum_single_index, Function.comp_apply, one_smul, zero_smul, MulHom.coe_comp,
NonUnitalAlgHom.coe_to_mulHom]
#align monoid_algebra.lift_magma MonoidAlgebra.liftMagma
#align monoid_algebra.lift_magma_apply_apply MonoidAlgebra.liftMagma_apply_apply
#align monoid_algebra.lift_magma_symm_apply MonoidAlgebra.liftMagma_symm_apply
end NonUnitalNonAssocAlgebra
/-! #### Algebra structure -/
section Algebra
-- attribute [local reducible] MonoidAlgebra -- Porting note: `reducible` cannot be `local`.
theorem single_one_comm [CommSemiring k] [MulOneClass G] (r : k) (f : MonoidAlgebra k G) :
single (1 : G) r * f = f * single (1 : G) r :=
single_commute Commute.one_left (Commute.all _) f
#align monoid_algebra.single_one_comm MonoidAlgebra.single_one_comm
/-- `Finsupp.single 1` as a `RingHom` -/
@[simps]
def singleOneRingHom [Semiring k] [MulOneClass G] : k →+* MonoidAlgebra k G :=
{ Finsupp.singleAddHom 1 with
map_one' := rfl
map_mul' := fun x y => by
-- Porting note (#10691): Was `rw`.
simp only [ZeroHom.toFun_eq_coe, AddMonoidHom.toZeroHom_coe, singleAddHom_apply,
single_mul_single, mul_one] }
#align monoid_algebra.single_one_ring_hom MonoidAlgebra.singleOneRingHom
#align monoid_algebra.single_one_ring_hom_apply MonoidAlgebra.singleOneRingHom_apply
/-- If `f : G → H` is a multiplicative homomorphism between two monoids, then
`Finsupp.mapDomain f` is a ring homomorphism between their monoid algebras. -/
@[simps]
def mapDomainRingHom (k : Type*) {H F : Type*} [Semiring k] [Monoid G] [Monoid H]
[FunLike F G H] [MonoidHomClass F G H] (f : F) : MonoidAlgebra k G →+* MonoidAlgebra k H :=
{ (Finsupp.mapDomain.addMonoidHom f : MonoidAlgebra k G →+ MonoidAlgebra k H) with
map_one' := mapDomain_one f
map_mul' := fun x y => mapDomain_mul f x y }
#align monoid_algebra.map_domain_ring_hom MonoidAlgebra.mapDomainRingHom
#align monoid_algebra.map_domain_ring_hom_apply MonoidAlgebra.mapDomainRingHom_apply
/-- If two ring homomorphisms from `MonoidAlgebra k G` are equal on all `single a 1`
and `single 1 b`, then they are equal. -/
theorem ringHom_ext {R} [Semiring k] [MulOneClass G] [Semiring R] {f g : MonoidAlgebra k G →+* R}
(h₁ : ∀ b, f (single 1 b) = g (single 1 b)) (h_of : ∀ a, f (single a 1) = g (single a 1)) :
f = g :=
RingHom.coe_addMonoidHom_injective <|
addHom_ext fun a b => by
rw [← single, ← one_mul a, ← mul_one b, ← single_mul_single]
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [AddMonoidHom.coe_coe f, AddMonoidHom.coe_coe g]; rw [f.map_mul, g.map_mul, h₁, h_of]
#align monoid_algebra.ring_hom_ext MonoidAlgebra.ringHom_ext
/-- If two ring homomorphisms from `MonoidAlgebra k G` are equal on all `single a 1`
and `single 1 b`, then they are equal.
See note [partially-applied ext lemmas]. -/
@[ext high]
theorem ringHom_ext' {R} [Semiring k] [MulOneClass G] [Semiring R] {f g : MonoidAlgebra k G →+* R}
(h₁ : f.comp singleOneRingHom = g.comp singleOneRingHom)
(h_of :
(f : MonoidAlgebra k G →* R).comp (of k G) = (g : MonoidAlgebra k G →* R).comp (of k G)) :
f = g :=
ringHom_ext (RingHom.congr_fun h₁) (DFunLike.congr_fun h_of)
#align monoid_algebra.ring_hom_ext' MonoidAlgebra.ringHom_ext'
/-- The instance `Algebra k (MonoidAlgebra A G)` whenever we have `Algebra k A`.
In particular this provides the instance `Algebra k (MonoidAlgebra k G)`.
-/
instance algebra {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] :
Algebra k (MonoidAlgebra A G) :=
{ singleOneRingHom.comp (algebraMap k A) with
-- Porting note: `ext` → `refine Finsupp.ext fun _ => ?_`
smul_def' := fun r a => by
refine Finsupp.ext fun _ => ?_
-- Porting note: Newly required.
rw [Finsupp.coe_smul]
simp [single_one_mul_apply, Algebra.smul_def, Pi.smul_apply]
commutes' := fun r f => by
refine Finsupp.ext fun _ => ?_
simp [single_one_mul_apply, mul_single_one_apply, Algebra.commutes] }
/-- `Finsupp.single 1` as an `AlgHom` -/
@[simps! apply]
def singleOneAlgHom {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] :
A →ₐ[k] MonoidAlgebra A G :=
{ singleOneRingHom with
commutes' := fun r => by
-- Porting note: `ext` → `refine Finsupp.ext fun _ => ?_`
refine Finsupp.ext fun _ => ?_
simp
rfl }
#align monoid_algebra.single_one_alg_hom MonoidAlgebra.singleOneAlgHom
#align monoid_algebra.single_one_alg_hom_apply MonoidAlgebra.singleOneAlgHom_apply
@[simp]
theorem coe_algebraMap {A : Type*} [CommSemiring k] [Semiring A] [Algebra k A] [Monoid G] :
⇑(algebraMap k (MonoidAlgebra A G)) = single 1 ∘ algebraMap k A :=
rfl
#align monoid_algebra.coe_algebra_map MonoidAlgebra.coe_algebraMap
theorem single_eq_algebraMap_mul_of [CommSemiring k] [Monoid G] (a : G) (b : k) :
single a b = algebraMap k (MonoidAlgebra k G) b * of k G a := by simp
#align monoid_algebra.single_eq_algebra_map_mul_of MonoidAlgebra.single_eq_algebraMap_mul_of
theorem single_algebraMap_eq_algebraMap_mul_of {A : Type*} [CommSemiring k] [Semiring A]
[Algebra k A] [Monoid G] (a : G) (b : k) :
single a (algebraMap k A b) = algebraMap k (MonoidAlgebra A G) b * of A G a := by simp
#align monoid_algebra.single_algebra_map_eq_algebra_map_mul_of MonoidAlgebra.single_algebraMap_eq_algebraMap_mul_of
theorem induction_on [Semiring k] [Monoid G] {p : MonoidAlgebra k G → Prop} (f : MonoidAlgebra k G)
(hM : ∀ g, p (of k G g)) (hadd : ∀ f g : MonoidAlgebra k G, p f → p g → p (f + g))
(hsmul : ∀ (r : k) (f), p f → p (r • f)) : p f := by
refine' Finsupp.induction_linear f _ (fun f g hf hg => hadd f g hf hg) fun g r => _
· simpa using hsmul 0 (of k G 1) (hM 1)
· convert hsmul r (of k G g) (hM g)
-- Porting note: Was `simp only`.
rw [of_apply, smul_single', mul_one]
#align monoid_algebra.induction_on MonoidAlgebra.induction_on
end Algebra
section lift
variable [CommSemiring k] [Monoid G] [Monoid H]
variable {A : Type u₃} [Semiring A] [Algebra k A] {B : Type*} [Semiring B] [Algebra k B]
/-- `liftNCRingHom` as an `AlgHom`, for when `f` is an `AlgHom` -/
def liftNCAlgHom (f : A →ₐ[k] B) (g : G →* B) (h_comm : ∀ x y, Commute (f x) (g y)) :
MonoidAlgebra A G →ₐ[k] B :=
{ liftNCRingHom (f : A →+* B) g h_comm with
commutes' := by simp [liftNCRingHom] }
#align monoid_algebra.lift_nc_alg_hom MonoidAlgebra.liftNCAlgHom
/-- A `k`-algebra homomorphism from `MonoidAlgebra k G` is uniquely defined by its
values on the functions `single a 1`. -/
theorem algHom_ext ⦃φ₁ φ₂ : MonoidAlgebra k G →ₐ[k] A⦄
(h : ∀ x, φ₁ (single x 1) = φ₂ (single x 1)) : φ₁ = φ₂ :=
AlgHom.toLinearMap_injective <| Finsupp.lhom_ext' fun a => LinearMap.ext_ring (h a)
#align monoid_algebra.alg_hom_ext MonoidAlgebra.algHom_ext
-- Porting note: The priority must be `high`.
/-- See note [partially-applied ext lemmas]. -/
@[ext high]
theorem algHom_ext' ⦃φ₁ φ₂ : MonoidAlgebra k G →ₐ[k] A⦄
(h :
(φ₁ : MonoidAlgebra k G →* A).comp (of k G) = (φ₂ : MonoidAlgebra k G →* A).comp (of k G)) :
φ₁ = φ₂ :=
algHom_ext <| DFunLike.congr_fun h
#align monoid_algebra.alg_hom_ext' MonoidAlgebra.algHom_ext'
variable (k G A)
/-- Any monoid homomorphism `G →* A` can be lifted to an algebra homomorphism
`MonoidAlgebra k G →ₐ[k] A`. -/
def lift : (G →* A) ≃ (MonoidAlgebra k G →ₐ[k] A) where
invFun f := (f : MonoidAlgebra k G →* A).comp (of k G)
toFun F := liftNCAlgHom (Algebra.ofId k A) F fun _ _ => Algebra.commutes _ _
left_inv f := by
ext
simp [liftNCAlgHom, liftNCRingHom]
right_inv F := by
ext
simp [liftNCAlgHom, liftNCRingHom]
#align monoid_algebra.lift MonoidAlgebra.lift
variable {k G H A}
theorem lift_apply' (F : G →* A) (f : MonoidAlgebra k G) :
lift k G A F f = f.sum fun a b => algebraMap k A b * F a :=
rfl
#align monoid_algebra.lift_apply' MonoidAlgebra.lift_apply'
theorem lift_apply (F : G →* A) (f : MonoidAlgebra k G) :
lift k G A F f = f.sum fun a b => b • F a := by simp only [lift_apply', Algebra.smul_def]
#align monoid_algebra.lift_apply MonoidAlgebra.lift_apply
theorem lift_def (F : G →* A) : ⇑(lift k G A F) = liftNC ((algebraMap k A : k →+* A) : k →+ A) F :=
rfl
#align monoid_algebra.lift_def MonoidAlgebra.lift_def
@[simp]
theorem lift_symm_apply (F : MonoidAlgebra k G →ₐ[k] A) (x : G) :
(lift k G A).symm F x = F (single x 1) :=
rfl
#align monoid_algebra.lift_symm_apply MonoidAlgebra.lift_symm_apply
@[simp]
theorem lift_single (F : G →* A) (a b) : lift k G A F (single a b) = b • F a := by
rw [lift_def, liftNC_single, Algebra.smul_def, AddMonoidHom.coe_coe]
#align monoid_algebra.lift_single MonoidAlgebra.lift_single
theorem lift_of (F : G →* A) (x) : lift k G A F (of k G x) = F x := by simp
#align monoid_algebra.lift_of MonoidAlgebra.lift_of
theorem lift_unique' (F : MonoidAlgebra k G →ₐ[k] A) :
F = lift k G A ((F : MonoidAlgebra k G →* A).comp (of k G)) :=
((lift k G A).apply_symm_apply F).symm
#align monoid_algebra.lift_unique' MonoidAlgebra.lift_unique'
/-- Decomposition of a `k`-algebra homomorphism from `MonoidAlgebra k G` by
its values on `F (single a 1)`. -/
theorem lift_unique (F : MonoidAlgebra k G →ₐ[k] A) (f : MonoidAlgebra k G) :
F f = f.sum fun a b => b • F (single a 1) := by
conv_lhs =>
rw [lift_unique' F]
simp [lift_apply]
#align monoid_algebra.lift_unique MonoidAlgebra.lift_unique
/-- If `f : G → H` is a homomorphism between two magmas, then
`Finsupp.mapDomain f` is a non-unital algebra homomorphism between their magma algebras. -/
@[simps apply]
def mapDomainNonUnitalAlgHom (k A : Type*) [CommSemiring k] [Semiring A] [Algebra k A]
{G H F : Type*} [Mul G] [Mul H] [FunLike F G H] [MulHomClass F G H] (f : F) :
MonoidAlgebra A G →ₙₐ[k] MonoidAlgebra A H :=
{ (Finsupp.mapDomain.addMonoidHom f : MonoidAlgebra A G →+ MonoidAlgebra A H) with
map_mul' := fun x y => mapDomain_mul f x y
map_smul' := fun r x => mapDomain_smul r x }
#align monoid_algebra.map_domain_non_unital_alg_hom MonoidAlgebra.mapDomainNonUnitalAlgHom
#align monoid_algebra.map_domain_non_unital_alg_hom_apply MonoidAlgebra.mapDomainNonUnitalAlgHom_apply
variable (A) in
theorem mapDomain_algebraMap {F : Type*} [FunLike F G H] [MonoidHomClass F G H] (f : F) (r : k) :
mapDomain f (algebraMap k (MonoidAlgebra A G) r) = algebraMap k (MonoidAlgebra A H) r := by
simp only [coe_algebraMap, mapDomain_single, map_one, (· ∘ ·)]
#align monoid_algebra.map_domain_algebra_map MonoidAlgebra.mapDomain_algebraMap
/-- If `f : G → H` is a multiplicative homomorphism between two monoids, then
`Finsupp.mapDomain f` is an algebra homomorphism between their monoid algebras. -/
@[simps!]
def mapDomainAlgHom (k A : Type*) [CommSemiring k] [Semiring A] [Algebra k A] {H F : Type*}
[Monoid H] [FunLike F G H] [MonoidHomClass F G H] (f : F) :
MonoidAlgebra A G →ₐ[k] MonoidAlgebra A H :=
{ mapDomainRingHom A f with commutes' := mapDomain_algebraMap A f }
#align monoid_algebra.map_domain_alg_hom MonoidAlgebra.mapDomainAlgHom
#align monoid_algebra.map_domain_alg_hom_apply MonoidAlgebra.mapDomainAlgHom_apply
variable (k A)
/-- If `e : G ≃* H` is a multiplicative equivalence between two monoids, then
`MonoidAlgebra.domCongr e` is an algebra equivalence between their monoid algebras. -/
def domCongr (e : G ≃* H) : MonoidAlgebra A G ≃ₐ[k] MonoidAlgebra A H :=
AlgEquiv.ofLinearEquiv
(Finsupp.domLCongr e : (G →₀ A) ≃ₗ[k] (H →₀ A))
((equivMapDomain_eq_mapDomain _ _).trans <| mapDomain_one e)
(fun f g => (equivMapDomain_eq_mapDomain _ _).trans <| (mapDomain_mul e f g).trans <|
congr_arg₂ _ (equivMapDomain_eq_mapDomain _ _).symm (equivMapDomain_eq_mapDomain _ _).symm)
theorem domCongr_toAlgHom (e : G ≃* H) : (domCongr k A e).toAlgHom = mapDomainAlgHom k A e :=
AlgHom.ext fun _ => equivMapDomain_eq_mapDomain _ _
@[simp] theorem domCongr_apply (e : G ≃* H) (f : MonoidAlgebra A G) (h : H) :
domCongr k A e f h = f (e.symm h) :=
rfl
@[simp] theorem domCongr_support (e : G ≃* H) (f : MonoidAlgebra A G) :
(domCongr k A e f).support = f.support.map e :=
rfl
@[simp] theorem domCongr_single (e : G ≃* H) (g : G) (a : A) :
domCongr k A e (single g a) = single (e g) a :=
Finsupp.equivMapDomain_single _ _ _
@[simp] theorem domCongr_refl : domCongr k A (MulEquiv.refl G) = AlgEquiv.refl :=
AlgEquiv.ext fun _ => Finsupp.ext fun _ => rfl