Datasets:

Modalities:
Text
Languages:
English
Libraries:
Datasets
License:
Zhangir Azerbayev commited on
Commit
fc5e983
1 Parent(s): 58f396b

I think it's all done!

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. fetch_books_and_formal.py +14 -15
  2. formal/lean/mathlib/algebra/algebra/basic.lean +28 -3
  3. formal/lean/mathlib/algebra/algebra/bilinear.lean +112 -86
  4. formal/lean/mathlib/algebra/algebra/operations.lean +25 -5
  5. formal/lean/mathlib/algebra/algebra/subalgebra/basic.lean +13 -14
  6. formal/lean/mathlib/algebra/algebra/tower.lean +1 -1
  7. formal/lean/mathlib/algebra/algebra/unitization.lean +3 -5
  8. formal/lean/mathlib/algebra/big_operators/basic.lean +167 -29
  9. formal/lean/mathlib/algebra/big_operators/fin.lean +47 -0
  10. formal/lean/mathlib/algebra/big_operators/multiset.lean +31 -0
  11. formal/lean/mathlib/algebra/big_operators/norm_num.lean +89 -89
  12. formal/lean/mathlib/algebra/big_operators/ring.lean +1 -1
  13. formal/lean/mathlib/algebra/category/FinVect.lean +23 -25
  14. formal/lean/mathlib/algebra/category/FinVect/limits.lean +1 -1
  15. formal/lean/mathlib/algebra/category/Group/epi_mono.lean +79 -2
  16. formal/lean/mathlib/algebra/category/Group/equivalence_Group_AddGroup.lean +86 -0
  17. formal/lean/mathlib/algebra/category/Module/adjunctions.lean +1 -1
  18. formal/lean/mathlib/algebra/category/Module/change_of_rings.lean +65 -0
  19. formal/lean/mathlib/algebra/char_p/algebra.lean +3 -0
  20. formal/lean/mathlib/algebra/char_p/basic.lean +11 -8
  21. formal/lean/mathlib/algebra/char_p/char_and_card.lean +13 -7
  22. formal/lean/mathlib/algebra/direct_sum/internal.lean +1 -2
  23. formal/lean/mathlib/algebra/direct_sum/ring.lean +1 -1
  24. formal/lean/mathlib/algebra/field/basic.lean +40 -39
  25. formal/lean/mathlib/algebra/field_power.lean +6 -24
  26. formal/lean/mathlib/algebra/group/prod.lean +1 -1
  27. formal/lean/mathlib/algebra/group/to_additive.lean +2 -0
  28. formal/lean/mathlib/algebra/group/units.lean +40 -7
  29. formal/lean/mathlib/algebra/group_with_zero/power.lean +2 -6
  30. formal/lean/mathlib/algebra/hom/equiv.lean +13 -0
  31. formal/lean/mathlib/algebra/hom/group_action.lean +2 -2
  32. formal/lean/mathlib/algebra/hom/group_instances.lean +17 -2
  33. formal/lean/mathlib/algebra/hom/ring.lean +4 -0
  34. formal/lean/mathlib/algebra/hom/units.lean +1 -1
  35. formal/lean/mathlib/algebra/homology/complex_shape.lean +1 -1
  36. formal/lean/mathlib/algebra/homology/homological_complex.lean +13 -13
  37. formal/lean/mathlib/algebra/homology/homotopy.lean +1 -1
  38. formal/lean/mathlib/algebra/homology/short_exact/preadditive.lean +1 -1
  39. formal/lean/mathlib/algebra/indicator_function.lean +2 -6
  40. formal/lean/mathlib/algebra/lie/base_change.lean +3 -3
  41. formal/lean/mathlib/algebra/lie/nilpotent.lean +6 -3
  42. formal/lean/mathlib/algebra/lie/of_associative.lean +1 -1
  43. formal/lean/mathlib/algebra/module/basic.lean +7 -1
  44. formal/lean/mathlib/algebra/module/bimodule.lean +136 -0
  45. formal/lean/mathlib/algebra/module/equiv.lean +49 -4
  46. formal/lean/mathlib/algebra/module/linear_map.lean +21 -1
  47. formal/lean/mathlib/algebra/module/localized_module.lean +1 -1
  48. formal/lean/mathlib/algebra/monoid_algebra/basic.lean +21 -6
  49. formal/lean/mathlib/algebra/monoid_algebra/degree.lean +154 -0
  50. formal/lean/mathlib/algebra/order/archimedean.lean +43 -15
fetch_books_and_formal.py CHANGED
@@ -104,7 +104,7 @@ def lean(creds):
104
  {
105
  "author": "leanprover-community",
106
  "repo": "mathlib",
107
- "sha": "e2ba6de0eb20eed7f16a19c3abf6904fad937fa4",
108
  "repo_dir": "src",
109
  "save_path": os.path.join(save_dir, "mathlib"),
110
  },
@@ -118,7 +118,7 @@ def lean(creds):
118
  {
119
  "author": "leanprover-community",
120
  "repo": "sphere-eversion",
121
- "sha": "3a2e501bbb2512870c98c3e6831a6067b3c826b8",
122
  "repo_dir": "src",
123
  "save_path": os.path.join(save_dir, "sphere-eversion"),
124
  },
@@ -506,20 +506,19 @@ def napkin(creds):
506
 
507
  def main():
508
  creds = ("zhangir-azerbayev", os.environ["GITHUB_TOKEN"])
509
- #napkin(creds)
510
- #cring(creds)
511
- # naturalproofs_proofwiki(testing=False)
512
- #stacks(creds)
513
- #mizar(creds)
514
- #afp(testing=False)
515
  setmm(creds)
516
- #trench()
517
- #hott(creds)
518
- #stein(creds)
519
- #coq(creds)
520
- #lean(creds)
521
- #hol()
522
- #cam()
523
 
524
 
525
  if __name__ == "__main__":
 
104
  {
105
  "author": "leanprover-community",
106
  "repo": "mathlib",
107
+ "sha": "63138639ca195344ae96aa77f3a02b90a3ac5c68",
108
  "repo_dir": "src",
109
  "save_path": os.path.join(save_dir, "mathlib"),
110
  },
 
118
  {
119
  "author": "leanprover-community",
120
  "repo": "sphere-eversion",
121
+ "sha": "cb378966c3c02d9e4ee83040d20c51782fa351ae",
122
  "repo_dir": "src",
123
  "save_path": os.path.join(save_dir, "sphere-eversion"),
124
  },
 
506
 
507
  def main():
508
  creds = ("zhangir-azerbayev", os.environ["GITHUB_TOKEN"])
509
+ napkin(creds)
510
+ cring(creds)
511
+ stacks(creds)
512
+ mizar(creds)
513
+ afp(testing=False)
 
514
  setmm(creds)
515
+ trench()
516
+ hott(creds)
517
+ stein(creds)
518
+ coq(creds)
519
+ lean(creds)
520
+ hol()
521
+ cam()
522
 
523
 
524
  if __name__ == "__main__":
formal/lean/mathlib/algebra/algebra/basic.lean CHANGED
@@ -112,7 +112,7 @@ An associative unital `R`-algebra is a semiring `A` equipped with a map into its
112
 
113
  See the implementation notes in this file for discussion of the details of this definition.
114
  -/
115
- @[nolint has_inhabited_instance]
116
  class algebra (R : Type u) (A : Type v) [comm_semiring R] [semiring A]
117
  extends has_smul R A, R →+* A :=
118
  (commutes' : ∀ r x, to_fun r * x = x * to_fun r)
@@ -261,6 +261,11 @@ search (and was here first). -/
261
  (r • x) * y = r • (x * y) :=
262
  smul_mul_assoc r x y
263
 
 
 
 
 
 
264
  section
265
  variables {r : R} {a : A}
266
 
@@ -474,7 +479,7 @@ end module
474
 
475
  set_option old_structure_cmd true
476
  /-- Defining the homomorphism in the category R-Alg. -/
477
- @[nolint has_inhabited_instance]
478
  structure alg_hom (R : Type u) (A : Type v) (B : Type w)
479
  [comm_semiring R] [semiring A] [semiring B] [algebra R A] [algebra R B] extends ring_hom A B :=
480
  (commutes' : ∀ r : R, to_fun (algebra_map R A r) = algebra_map R B r)
@@ -695,6 +700,17 @@ lemma map_list_prod (s : list A) :
695
  φ s.prod = (s.map φ).prod :=
696
  φ.to_ring_hom.map_list_prod s
697
 
 
 
 
 
 
 
 
 
 
 
 
698
  section prod
699
 
700
  /-- First projection as `alg_hom`. -/
@@ -797,6 +813,13 @@ instance to_alg_hom_class (F R A B : Type*)
797
  map_one := map_one,
798
  .. h }
799
 
 
 
 
 
 
 
 
800
  end alg_equiv_class
801
 
802
  namespace alg_equiv
@@ -1225,7 +1248,9 @@ This is a stronger version of `mul_semiring_action.to_ring_hom` and
1225
  `distrib_mul_action.to_linear_map`. -/
1226
  @[simps]
1227
  def to_alg_hom (m : M) : A →ₐ[R] A :=
1228
- alg_hom.mk' (mul_semiring_action.to_ring_hom _ _ m) (smul_comm _)
 
 
1229
 
1230
  theorem to_alg_hom_injective [has_faithful_smul M A] :
1231
  function.injective (mul_semiring_action.to_alg_hom R A : M → A →ₐ[R] A) :=
 
112
 
113
  See the implementation notes in this file for discussion of the details of this definition.
114
  -/
115
+ @[nolint has_nonempty_instance]
116
  class algebra (R : Type u) (A : Type v) [comm_semiring R] [semiring A]
117
  extends has_smul R A, R →+* A :=
118
  (commutes' : ∀ r x, to_fun r * x = x * to_fun r)
 
261
  (r • x) * y = r • (x * y) :=
262
  smul_mul_assoc r x y
263
 
264
+ @[simp]
265
+ lemma _root_.smul_algebra_map {α : Type*} [monoid α] [mul_distrib_mul_action α A]
266
+ [smul_comm_class α R A] (a : α) (r : R) : a • algebra_map R A r = algebra_map R A r :=
267
+ by rw [algebra_map_eq_smul_one, smul_comm a r (1 : A), smul_one]
268
+
269
  section
270
  variables {r : R} {a : A}
271
 
 
479
 
480
  set_option old_structure_cmd true
481
  /-- Defining the homomorphism in the category R-Alg. -/
482
+ @[nolint has_nonempty_instance]
483
  structure alg_hom (R : Type u) (A : Type v) (B : Type w)
484
  [comm_semiring R] [semiring A] [semiring B] [algebra R A] [algebra R B] extends ring_hom A B :=
485
  (commutes' : ∀ r : R, to_fun (algebra_map R A r) = algebra_map R B r)
 
700
  φ s.prod = (s.map φ).prod :=
701
  φ.to_ring_hom.map_list_prod s
702
 
703
+ @[simps mul one {attrs := []}] instance End : monoid (A →ₐ[R] A) :=
704
+ { mul := comp,
705
+ mul_assoc := λ ϕ ψ χ, rfl,
706
+ one := alg_hom.id R A,
707
+ one_mul := λ ϕ, ext $ λ x, rfl,
708
+ mul_one := λ ϕ, ext $ λ x, rfl }
709
+
710
+ @[simp] lemma one_apply (x : A) : (1 : A →ₐ[R] A) x = x := rfl
711
+
712
+ @[simp] lemma mul_apply (φ ψ : A →ₐ[R] A) (x : A) : (φ * ψ) x = φ (ψ x) := rfl
713
+
714
  section prod
715
 
716
  /-- First projection as `alg_hom`. -/
 
813
  map_one := map_one,
814
  .. h }
815
 
816
+ @[priority 100]
817
+ instance to_linear_equiv_class (F R A B : Type*)
818
+ [comm_semiring R] [semiring A] [semiring B] [algebra R A] [algebra R B]
819
+ [h : alg_equiv_class F R A B] : linear_equiv_class F R A B :=
820
+ { map_smulₛₗ := λ f, map_smulₛₗ f,
821
+ ..h }
822
+
823
  end alg_equiv_class
824
 
825
  namespace alg_equiv
 
1248
  `distrib_mul_action.to_linear_map`. -/
1249
  @[simps]
1250
  def to_alg_hom (m : M) : A →ₐ[R] A :=
1251
+ { to_fun := λ a, m a,
1252
+ commutes' := smul_algebra_map _,
1253
+ ..mul_semiring_action.to_ring_hom _ _ m }
1254
 
1255
  theorem to_alg_hom_injective [has_faithful_smul M A] :
1256
  function.injective (mul_semiring_action.to_alg_hom R A : M → A →ₐ[R] A) :=
formal/lean/mathlib/algebra/algebra/bilinear.lean CHANGED
@@ -5,6 +5,7 @@ Authors: Kenny Lau, Yury Kudryashov
5
  -/
6
  import algebra.algebra.basic
7
  import algebra.hom.iterate
 
8
  import linear_algebra.tensor_product
9
 
10
  /-!
@@ -15,143 +16,168 @@ in order to avoid importing `linear_algebra.bilinear_map` and
15
  `linear_algebra.tensor_product` unnecessarily.
16
  -/
17
 
18
- universes u v w
19
-
20
- namespace algebra
21
-
22
  open_locale tensor_product
23
  open module
24
 
25
- section
26
 
27
- variables (R A : Type*) [comm_semiring R] [semiring A] [algebra R A]
28
 
29
- /-- The multiplication in an algebra is a bilinear map.
 
 
 
30
 
31
  A weaker version of this for semirings exists as `add_monoid_hom.mul`. -/
32
- def lmul : A →ₐ[R] (End R A) :=
33
- { map_one' := by { ext a, exact one_mul a },
34
- map_mul' := by { intros a b, ext c, exact mul_assoc a b c },
35
- map_zero' := by { ext a, exact zero_mul a },
36
- commutes' := by { intro r, ext a, dsimp, rw [smul_def] },
37
- .. (show A →ₗ[R] A →ₗ[R] A, from linear_map.mk₂ R (*)
38
- (λ x y z, add_mul x y z)
39
- (λ c x y, by rw [smul_def, smul_def, mul_assoc _ x y])
40
- (λ x y z, mul_add x y z)
41
- (λ c x y, by rw [smul_def, smul_def, left_comm])) }
42
 
43
- variables {R A}
 
 
44
 
45
- @[simp] lemma lmul_apply (p q : A) : lmul R A p q = p * q := rfl
46
 
 
 
47
 
48
- variables (R)
 
49
 
50
- /-- The multiplication on the left in an algebra is a linear map. -/
51
- def lmul_left (r : A) : A →ₗ[R] A :=
52
- lmul R A r
53
 
54
- @[simp] lemma lmul_left_to_add_monoid_hom (r : A) :
55
- (lmul_left R r : A →+ A) = add_monoid_hom.mul_left r :=
56
- fun_like.coe_injective rfl
57
 
58
- /-- The multiplication on the right in an algebra is a linear map. -/
59
- def lmul_right (r : A) : A →ₗ[R] A :=
60
- (lmul R A).to_linear_map.flip r
61
 
62
- @[simp] lemma lmul_right_to_add_monoid_hom (r : A) :
63
- (lmul_right R r : A →+ A) = add_monoid_hom.mul_right r :=
64
- fun_like.coe_injective rfl
65
 
66
- /-- Simultaneous multiplication on the left and right is a linear map. -/
67
- def lmul_left_right (vw: A × A) : A →ₗ[R] A :=
68
- (lmul_right R vw.2).comp (lmul_left R vw.1)
 
69
 
70
- lemma commute_lmul_left_right (a b : A) :
71
- commute (lmul_left R a) (lmul_right R b) :=
72
- by { ext c, exact (mul_assoc a c b).symm, }
 
 
 
 
 
 
 
 
 
 
 
73
 
74
- /-- The multiplication map on an algebra, as an `R`-linear map from `A [R] A` to `A`. -/
75
- def lmul' : A [R] A →ₗ[R] A :=
76
- tensor_product.lift (lmul R A).to_linear_map
 
 
 
 
 
 
 
77
 
78
  variables {R A}
79
 
80
- @[simp] lemma lmul'_apply {x y : A} : lmul' R (x ⊗ₜ y) = x * y :=
81
- by simp only [algebra.lmul', tensor_product.lift.tmul, alg_hom.to_linear_map_apply, lmul_apply]
 
 
 
 
 
 
 
 
82
 
83
- @[simp] lemma lmul_left_apply (p q : A) : lmul_left R p q = p * q := rfl
84
- @[simp] lemma lmul_right_apply (p q : A) : lmul_right R p q = q * p := rfl
85
- @[simp] lemma lmul_left_right_apply (vw : A × A) (p : A) :
86
- lmul_left_right R vw p = vw.1 * p * vw.2 := rfl
87
 
88
- @[simp] lemma lmul_left_one : lmul_left R (1:A) = linear_map.id :=
89
- by { ext, simp only [linear_map.id_coe, one_mul, id.def, lmul_left_apply] }
90
 
91
- @[simp] lemma lmul_left_mul (a b : A) :
92
- lmul_left R (a * b) = (lmul_left R a).comp (lmul_left R b) :=
93
- by { ext, simp only [lmul_left_apply, linear_map.comp_apply, mul_assoc] }
94
 
95
- @[simp] lemma lmul_right_one : lmul_right R (1:A) = linear_map.id :=
96
- by { ext, simp only [linear_map.id_coe, mul_one, id.def, lmul_right_apply] }
97
 
98
- @[simp] lemma lmul_right_mul (a b : A) :
99
- lmul_right R (a * b) = (lmul_right R b).comp (lmul_right R a) :=
100
- by { ext, simp only [lmul_right_apply, linear_map.comp_apply, mul_assoc] }
 
 
 
 
101
 
102
- @[simp] lemma lmul_left_zero_eq_zero :
103
- lmul_left R (0 : A) = 0 :=
104
- (lmul R A).map_zero
105
 
106
- @[simp] lemma lmul_right_zero_eq_zero :
107
- lmul_right R (0 : A) = 0 :=
108
- (lmul R A).to_linear_map.flip.map_zero
109
 
110
- @[simp] lemma lmul_left_eq_zero_iff (a : A) :
111
- lmul_left R a = 0 ↔ a = 0 :=
112
  begin
113
  split; intros h,
114
- { rw [← mul_one a, ← lmul_left_apply a 1, h, linear_map.zero_apply], },
115
- { rw h, exact lmul_left_zero_eq_zero, },
116
  end
117
 
118
- @[simp] lemma lmul_right_eq_zero_iff (a : A) :
119
- lmul_right R a = 0 ↔ a = 0 :=
120
  begin
121
  split; intros h,
122
- { rw [← one_mul a, ← lmul_right_apply a 1, h, linear_map.zero_apply], },
123
- { rw h, exact lmul_right_zero_eq_zero, },
124
  end
125
 
126
- @[simp] lemma pow_lmul_left (a : A) (n : ℕ) :
127
- (lmul_left R a) ^ n = lmul_left R (a ^ n) :=
128
- ((lmul R A).map_pow a n).symm
129
 
130
- @[simp] lemma pow_lmul_right (a : A) (n : ℕ) :
131
- (lmul_right R a) ^ n = lmul_right R (a ^ n) :=
132
- linear_map.coe_injective $ ((lmul_right R a).coe_pow n).symm ▸ (mul_right_iterate a n)
133
 
 
 
 
 
 
 
 
 
 
 
134
  end
135
 
136
- section
 
 
137
 
138
  variables {R A : Type*} [comm_semiring R] [ring A] [algebra R A]
139
 
140
- lemma lmul_left_injective [no_zero_divisors A] {x : A} (hx : x ≠ 0) :
141
- function.injective (lmul_left R x) :=
142
  by { letI : is_domain A := { exists_pair_ne := ⟨x, 0, hx⟩, ..‹ring A›, ..‹no_zero_divisors A› },
143
  exact mul_right_injective₀ hx }
144
 
145
- lemma lmul_right_injective [no_zero_divisors A] {x : A} (hx : x ≠ 0) :
146
- function.injective (lmul_right R x) :=
147
  by { letI : is_domain A := { exists_pair_ne := ⟨x, 0, hx⟩, ..‹ring A›, ..‹no_zero_divisors A› },
148
  exact mul_left_injective₀ hx }
149
 
150
- lemma lmul_injective [no_zero_divisors A] {x : A} (hx : x ≠ 0) :
151
- function.injective (lmul R A x) :=
152
  by { letI : is_domain A := { exists_pair_ne := ⟨x, 0, hx⟩, ..‹ring A›, ..‹no_zero_divisors A› },
153
  exact mul_right_injective₀ hx }
154
 
155
- end
156
 
157
- end algebra
 
5
  -/
6
  import algebra.algebra.basic
7
  import algebra.hom.iterate
8
+ import algebra.hom.non_unital_alg
9
  import linear_algebra.tensor_product
10
 
11
  /-!
 
16
  `linear_algebra.tensor_product` unnecessarily.
17
  -/
18
 
 
 
 
 
19
  open_locale tensor_product
20
  open module
21
 
22
+ namespace linear_map
23
 
24
+ section non_unital_non_assoc
25
 
26
+ variables (R A : Type*) [comm_semiring R] [non_unital_non_assoc_semiring A]
27
+ [module R A] [smul_comm_class R A A] [is_scalar_tower R A A]
28
+
29
+ /-- The multiplication in a non-unital non-associative algebra is a bilinear map.
30
 
31
  A weaker version of this for semirings exists as `add_monoid_hom.mul`. -/
32
+ def mul : A →ₗ[R] A →ₗ[R] A := linear_map.mk₂ R (*) add_mul smul_mul_assoc mul_add mul_smul_comm
 
 
 
 
 
 
 
 
 
33
 
34
+ /-- The multiplication map on a non-unital algebra, as an `R`-linear map from `A ⊗[R] A` to `A`. -/
35
+ def mul' : A ⊗[R] A →ₗ[R] A :=
36
+ tensor_product.lift (mul R A)
37
 
38
+ variables {A}
39
 
40
+ /-- The multiplication on the left in a non-unital algebra is a linear map. -/
41
+ def mul_left (a : A) : A →ₗ[R] A := mul R A a
42
 
43
+ /-- The multiplication on the right in an algebra is a linear map. -/
44
+ def mul_right (a : A) : A →ₗ[R] A := (mul R A).flip a
45
 
46
+ /-- Simultaneous multiplication on the left and right is a linear map. -/
47
+ def mul_left_right (ab : A × A) : A →ₗ[R] A := (mul_right R ab.snd).comp (mul_left R ab.fst)
 
48
 
49
+ @[simp] lemma mul_left_to_add_monoid_hom (a : A) :
50
+ (mul_left R a : A →+ A) = add_monoid_hom.mul_left a := rfl
 
51
 
52
+ @[simp] lemma mul_right_to_add_monoid_hom (a : A) :
53
+ (mul_right R a : A →+ A) = add_monoid_hom.mul_right a := rfl
 
54
 
55
+ variables {R}
 
 
56
 
57
+ @[simp] lemma mul_apply' (a b : A) : mul R A a b = a * b := rfl
58
+ @[simp] lemma mul_left_apply (a b : A) : mul_left R a b = a * b := rfl
59
+ @[simp] lemma mul_right_apply (a b : A) : mul_right R a b = b * a := rfl
60
+ @[simp] lemma mul_left_right_apply (a b x : A) : mul_left_right R (a, b) x = a * x * b := rfl
61
 
62
+ @[simp] lemma mul'_apply {a b : A} : mul' R A (a ⊗ₜ b) = a * b :=
63
+ by simp only [linear_map.mul', tensor_product.lift.tmul, mul_apply']
64
+
65
+ @[simp] lemma mul_left_zero_eq_zero :
66
+ mul_left R (0 : A) = 0 :=
67
+ (mul R A).map_zero
68
+
69
+ @[simp] lemma mul_right_zero_eq_zero :
70
+ mul_right R (0 : A) = 0 :=
71
+ (mul R A).flip.map_zero
72
+
73
+ end non_unital_non_assoc
74
+
75
+ section non_unital
76
 
77
+ variables (R A : Type*) [comm_semiring R] [non_unital_semiring A]
78
+ [module R A] [smul_comm_class R A A] [is_scalar_tower R A A]
79
+
80
+ /-- The multiplication in a non-unital algebra is a bilinear map.
81
+
82
+ A weaker version of this for non-unital non-associative algebras exists as `linear_map.mul`. -/
83
+ def _root_.non_unital_alg_hom.lmul : A →ₙₐ[R] (End R A) :=
84
+ { map_mul' := by { intros a b, ext c, exact mul_assoc a b c },
85
+ map_zero' := by { ext a, exact zero_mul a },
86
+ .. (mul R A) }
87
 
88
  variables {R A}
89
 
90
+ @[simp]
91
+ lemma _root_.non_unital_alg_hom.coe_lmul_eq_mul : ⇑(non_unital_alg_hom.lmul R A) = mul R A := rfl
92
+
93
+ lemma commute_mul_left_right (a b : A) :
94
+ commute (mul_left R a) (mul_right R b) :=
95
+ by { ext c, exact (mul_assoc a c b).symm, }
96
+
97
+ @[simp] lemma mul_left_mul (a b : A) :
98
+ mul_left R (a * b) = (mul_left R a).comp (mul_left R b) :=
99
+ by { ext, simp only [mul_left_apply, comp_apply, mul_assoc] }
100
 
101
+ @[simp] lemma mul_right_mul (a b : A) :
102
+ mul_right R (a * b) = (mul_right R b).comp (mul_right R a) :=
103
+ by { ext, simp only [mul_right_apply, comp_apply, mul_assoc] }
 
104
 
105
+ end non_unital
 
106
 
107
+ section semiring
108
+
109
+ variables (R A : Type*) [comm_semiring R] [semiring A] [algebra R A]
110
 
111
+ /-- The multiplication in an algebra is an algebra homomorphism into the endomorphisms on
112
+ the algebra.
113
 
114
+ A weaker version of this for non-unital algebras exists as `non_unital_alg_hom.mul`. -/
115
+ def _root_.algebra.lmul : A →ₐ[R] (End R A) :=
116
+ { map_one' := by { ext a, exact one_mul a },
117
+ map_mul' := by { intros a b, ext c, exact mul_assoc a b c },
118
+ map_zero' := by { ext a, exact zero_mul a },
119
+ commutes' := by { intro r, ext a, exact (algebra.smul_def r a).symm, },
120
+ .. (linear_map.mul R A) }
121
 
122
+ variables {R A}
 
 
123
 
124
+ @[simp] lemma _root_.algebra.coe_lmul_eq_mul : ⇑(algebra.lmul R A) = mul R A := rfl
 
 
125
 
126
+ @[simp] lemma mul_left_eq_zero_iff (a : A) :
127
+ mul_left R a = 0 ↔ a = 0 :=
128
  begin
129
  split; intros h,
130
+ { rw [← mul_one a, ← mul_left_apply a 1, h, linear_map.zero_apply], },
131
+ { rw h, exact mul_left_zero_eq_zero, },
132
  end
133
 
134
+ @[simp] lemma mul_right_eq_zero_iff (a : A) :
135
+ mul_right R a = 0 ↔ a = 0 :=
136
  begin
137
  split; intros h,
138
+ { rw [← one_mul a, ← mul_right_apply a 1, h, linear_map.zero_apply], },
139
+ { rw h, exact mul_right_zero_eq_zero, },
140
  end
141
 
142
+ @[simp] lemma mul_left_one : mul_left R (1:A) = linear_map.id :=
143
+ by { ext, simp only [linear_map.id_coe, one_mul, id.def, mul_left_apply] }
 
144
 
145
+ @[simp] lemma mul_right_one : mul_right R (1:A) = linear_map.id :=
146
+ by { ext, simp only [linear_map.id_coe, mul_one, id.def, mul_right_apply] }
 
147
 
148
+ @[simp] lemma pow_mul_left (a : A) (n : ℕ) :
149
+ (mul_left R a) ^ n = mul_left R (a ^ n) :=
150
+ by simpa only [mul_left, ←algebra.coe_lmul_eq_mul] using ((algebra.lmul R A).map_pow a n).symm
151
+
152
+ @[simp] lemma pow_mul_right (a : A) (n : ℕ) :
153
+ (mul_right R a) ^ n = mul_right R (a ^ n) :=
154
+ begin
155
+ simp only [mul_right, ←algebra.coe_lmul_eq_mul],
156
+ exact linear_map.coe_injective
157
+ (((mul_right R a).coe_pow n).symm ▸ (mul_right_iterate a n)),
158
  end
159
 
160
+ end semiring
161
+
162
+ section ring
163
 
164
  variables {R A : Type*} [comm_semiring R] [ring A] [algebra R A]
165
 
166
+ lemma mul_left_injective [no_zero_divisors A] {x : A} (hx : x ≠ 0) :
167
+ function.injective (mul_left R x) :=
168
  by { letI : is_domain A := { exists_pair_ne := ⟨x, 0, hx⟩, ..‹ring A›, ..‹no_zero_divisors A› },
169
  exact mul_right_injective₀ hx }
170
 
171
+ lemma mul_right_injective [no_zero_divisors A] {x : A} (hx : x ≠ 0) :
172
+ function.injective (mul_right R x) :=
173
  by { letI : is_domain A := { exists_pair_ne := ⟨x, 0, hx⟩, ..‹ring A›, ..‹no_zero_divisors A› },
174
  exact mul_left_injective₀ hx }
175
 
176
+ lemma mul_injective [no_zero_divisors A] {x : A} (hx : x ≠ 0) :
177
+ function.injective (mul R A x) :=
178
  by { letI : is_domain A := { exists_pair_ne := ⟨x, 0, hx⟩, ..‹ring A›, ..‹no_zero_divisors A› },
179
  exact mul_right_injective₀ hx }
180
 
181
+ end ring
182
 
183
+ end linear_map
formal/lean/mathlib/algebra/algebra/operations.lean CHANGED
@@ -18,7 +18,7 @@ An interface for multiplication and division of sub-R-modules of an R-algebra A
18
 
19
  ## Main definitions
20
 
21
- Let `R` be a commutative ring (or semiring) and aet `A` be an `R`-algebra.
22
 
23
  * `1 : submodule R A` : the R-submodule R of the R-algebra A
24
  * `has_mul (submodule R A)` : multiplication of two sub-R-modules M and N of A is defined to be
@@ -28,6 +28,9 @@ Let `R` be a commutative ring (or semiring) and aet `A` be an `R`-algebra.
28
 
29
  It is proved that `submodule R A` is a semiring, and also an algebra over `set A`.
30
 
 
 
 
31
  ## Tags
32
 
33
  multiplication of submodules, division of submodules, submodule semiring
@@ -118,7 +121,7 @@ by rw [←map_equiv_eq_comap_symm, map_op_one]
118
 
119
  /-- Multiplication of sub-R-modules of an R-algebra A. The submodule `M * N` is the
120
  smallest R-submodule of `A` containing the elements `m * n` for `m ∈ M` and `n ∈ N`. -/
121
- instance : has_mul (submodule R A) := ⟨submodule.map₂ (algebra.lmul R A).to_linear_map
122
 
123
  theorem mul_mem_mul (hm : m ∈ M) (hn : n ∈ N) : m * n ∈ M * N := apply_mem_map₂ _ hm hn
124
 
@@ -128,7 +131,7 @@ lemma mul_to_add_submonoid (M N : submodule R A) :
128
  (M * N).to_add_submonoid = M.to_add_submonoid * N.to_add_submonoid :=
129
  begin
130
  dsimp [has_mul.mul],
131
- simp_rw [←algebra.lmul_left_to_add_monoid_hom R, algebra.lmul_left, ←map_to_add_submonoid _ N,
132
  map₂],
133
  rw supr_to_add_submonoid,
134
  refl,
@@ -189,7 +192,7 @@ image2_subset_map₂ (algebra.lmul R A).to_linear_map M N
189
  protected lemma map_mul {A'} [semiring A'] [algebra R A'] (f : A →ₐ[R] A') :
190
  map f.to_linear_map (M * N) = map f.to_linear_map M * map f.to_linear_map N :=
191
  calc map f.to_linear_map (M * N)
192
- = ⨆ (i : M), (N.map (lmul R A i)).map f.to_linear_map : map_supr _ _
193
  ... = map f.to_linear_map M * map f.to_linear_map N :
194
  begin
195
  apply congr_arg Sup,
@@ -454,6 +457,23 @@ def span.ring_hom : set_semiring A →+* submodule R A :=
454
  map_add' := span_union,
455
  map_mul' := λ s t, by erw [span_mul_span, ← image_mul_prod] }
456
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
457
  end ring
458
 
459
  section comm_ring
@@ -512,7 +532,7 @@ lemma smul_le_smul {s t : set_semiring A} {M N : submodule R A} (h₁ : s.down
512
  mul_le_mul (span_mono h₁) h₂
513
 
514
  lemma smul_singleton (a : A) (M : submodule R A) :
515
- ({a} : set A).up • M = M.map (lmul_left _ a) :=
516
  begin
517
  conv_lhs {rw ← span_eq M},
518
  change span _ _ * span _ _ = _,
 
18
 
19
  ## Main definitions
20
 
21
+ Let `R` be a commutative ring (or semiring) and let `A` be an `R`-algebra.
22
 
23
  * `1 : submodule R A` : the R-submodule R of the R-algebra A
24
  * `has_mul (submodule R A)` : multiplication of two sub-R-modules M and N of A is defined to be
 
28
 
29
  It is proved that `submodule R A` is a semiring, and also an algebra over `set A`.
30
 
31
+ Additionally, in the `pointwise` locale we promote `submodule.pointwise_distrib_mul_action` to a
32
+ `mul_semiring_action` as `submodule.pointwise_mul_semiring_action`.
33
+
34
  ## Tags
35
 
36
  multiplication of submodules, division of submodules, submodule semiring
 
121
 
122
  /-- Multiplication of sub-R-modules of an R-algebra A. The submodule `M * N` is the
123
  smallest R-submodule of `A` containing the elements `m * n` for `m ∈ M` and `n ∈ N`. -/
124
+ instance : has_mul (submodule R A) := ⟨submodule.map₂ $ linear_map.mul R A⟩
125
 
126
  theorem mul_mem_mul (hm : m ∈ M) (hn : n ∈ N) : m * n ∈ M * N := apply_mem_map₂ _ hm hn
127
 
 
131
  (M * N).to_add_submonoid = M.to_add_submonoid * N.to_add_submonoid :=
132
  begin
133
  dsimp [has_mul.mul],
134
+ simp_rw [←linear_map.mul_left_to_add_monoid_hom R, linear_map.mul_left, ←map_to_add_submonoid _ N,
135
  map₂],
136
  rw supr_to_add_submonoid,
137
  refl,
 
192
  protected lemma map_mul {A'} [semiring A'] [algebra R A'] (f : A →ₐ[R] A') :
193
  map f.to_linear_map (M * N) = map f.to_linear_map M * map f.to_linear_map N :=
194
  calc map f.to_linear_map (M * N)
195
+ = ⨆ (i : M), (N.map (linear_map.mul R A i)).map f.to_linear_map : map_supr _ _
196
  ... = map f.to_linear_map M * map f.to_linear_map N :
197
  begin
198
  apply congr_arg Sup,
 
457
  map_add' := span_union,
458
  map_mul' := λ s t, by erw [span_mul_span, ← image_mul_prod] }
459
 
460
+ section
461
+ variables {α : Type*} [monoid α] [mul_semiring_action α A] [smul_comm_class α R A]
462
+
463
+ /-- The action on a submodule corresponding to applying the action to every element.
464
+
465
+ This is available as an instance in the `pointwise` locale.
466
+
467
+ This is a stronger version of `submodule.pointwise_distrib_mul_action`. -/
468
+ protected def pointwise_mul_semiring_action : mul_semiring_action α (submodule R A) :=
469
+ { smul_mul := λ r x y, submodule.map_mul x y $ mul_semiring_action.to_alg_hom R A r,
470
+ smul_one := λ r, submodule.map_one $ mul_semiring_action.to_alg_hom R A r,
471
+ ..submodule.pointwise_distrib_mul_action }
472
+
473
+ localized "attribute [instance] submodule.pointwise_mul_semiring_action" in pointwise
474
+
475
+ end
476
+
477
  end ring
478
 
479
  section comm_ring
 
532
  mul_le_mul (span_mono h₁) h₂
533
 
534
  lemma smul_singleton (a : A) (M : submodule R A) :
535
+ ({a} : set A).up • M = M.map (linear_map.mul_left _ a) :=
536
  begin
537
  conv_lhs {rw ← span_eq M},
538
  change span _ _ * span _ _ = _,
formal/lean/mathlib/algebra/algebra/subalgebra/basic.lean CHANGED
@@ -305,7 +305,7 @@ def to_submodule_equiv (S : subalgebra R A) : S.to_submodule ≃ₗ[R] S :=
305
  linear_equiv.of_eq _ _ rfl
306
 
307
  /-- Transport a subalgebra via an algebra homomorphism. -/
308
- def map (S : subalgebra R A) (f : A →ₐ[R] B) : subalgebra R B :=
309
  { algebra_map_mem' := λ r, f.commutes r ▸ set.mem_image_of_mem _ (S.algebra_map_mem r),
310
  .. S.to_subsemiring.map (f : A →+* B) }
311
 
@@ -313,9 +313,9 @@ lemma map_mono {S₁ S₂ : subalgebra R A} {f : A →ₐ[R] B} :
313
  S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=
314
  set.image_subset f
315
 
316
- lemma map_injective {S₁ S₂ : subalgebra R A} (f : A →ₐ[R] B)
317
- (hf : function.injective f) (ih : S₁.map f = S₂.map f) : S₁ = S₂ :=
318
- ext $ set.ext_iff.1 $ set.image_injective.2 hf $ set.ext $ set_like.ext_iff.mp ih
319
 
320
  @[simp] lemma map_id (S : subalgebra R A) : S.map (alg_hom.id R A) = S :=
321
  set_like.coe_injective $ set.image_id _
@@ -325,7 +325,7 @@ lemma map_map (S : subalgebra R A) (g : B →ₐ[R] C) (f : A →ₐ[R] B) :
325
  set_like.coe_injective $ set.image_image _ _ _
326
 
327
  lemma mem_map {S : subalgebra R A} {f : A →ₐ[R] B} {y : B} :
328
- y ∈ map S f ↔ ∃ x ∈ S, f x = y :=
329
  subsemiring.mem_map
330
 
331
  lemma map_to_submodule {S : subalgebra R A} {f : A →ₐ[R] B} :
@@ -341,16 +341,16 @@ set_like.coe_injective rfl
341
  rfl
342
 
343
  /-- Preimage of a subalgebra under an algebra homomorphism. -/
344
- def comap (S : subalgebra R B) (f : A →ₐ[R] B) : subalgebra R A :=
345
  { algebra_map_mem' := λ r, show f (algebra_map R A r) ∈ S,
346
  from (f.commutes r).symm ▸ S.algebra_map_mem r,
347
  .. S.to_subsemiring.comap (f : A →+* B) }
348
 
349
  theorem map_le {S : subalgebra R A} {f : A →ₐ[R] B} {U : subalgebra R B} :
350
- map S f ≤ U ↔ S ≤ comap U f :=
351
  set.image_subset_iff
352
 
353
- lemma gc_map_comap (f : A →ₐ[R] B) : galois_connection (λ S, map S f) (λ S, comap S f) :=
354
  λ S U, map_le
355
 
356
  @[simp] lemma mem_comap (S : subalgebra R B) (f : A →ₐ[R] B) (x : A) :
@@ -648,14 +648,14 @@ algebra.eq_top_iff
648
  @[simp] theorem range_id : (alg_hom.id R A).range = ⊤ :=
649
  set_like.coe_injective set.range_id
650
 
651
- @[simp] theorem map_top (f : A →ₐ[R] B) : subalgebra.map (⊤ : subalgebra R A) f = f.range :=
652
  set_like.coe_injective set.image_univ
653
 
654
- @[simp] theorem map_bot (f : A →ₐ[R] B) : subalgebra.map (⊥ : subalgebra R A) f = ⊥ :=
655
  set_like.coe_injective $
656
  by simp only [← set.range_comp, (∘), algebra.coe_bot, subalgebra.coe_map, f.commutes]
657
 
658
- @[simp] theorem comap_top (f : A →ₐ[R] B) : subalgebra.comap (⊤ : subalgebra R B) f = ⊤ :=
659
  eq_top_iff.2 $ λ x, mem_top
660
 
661
  /-- `alg_hom` to `⊤ : subalgebra R A`. -/
@@ -810,12 +810,11 @@ variables (S₁ : subalgebra R B)
810
 
811
  /-- The product of two subalgebras is a subalgebra. -/
812
  def prod : subalgebra R (A × B) :=
813
- { carrier := (S : set A) ×ˢ (S₁ : set B),
814
  algebra_map_mem' := λ r, ⟨algebra_map_mem _ _, algebra_map_mem _ _⟩,
815
  .. S.to_subsemiring.prod S₁.to_subsemiring }
816
 
817
- @[simp] lemma coe_prod :
818
- (prod S S₁ : set (A × B)) = (S : set A) ×ˢ (S₁ : set B):= rfl
819
 
820
  lemma prod_to_submodule :
821
  (S.prod S₁).to_submodule = S.to_submodule.prod S₁.to_submodule := rfl
 
305
  linear_equiv.of_eq _ _ rfl
306
 
307
  /-- Transport a subalgebra via an algebra homomorphism. -/
308
+ def map (f : A →ₐ[R] B) (S : subalgebra R A) : subalgebra R B :=
309
  { algebra_map_mem' := λ r, f.commutes r ▸ set.mem_image_of_mem _ (S.algebra_map_mem r),
310
  .. S.to_subsemiring.map (f : A →+* B) }
311
 
 
313
  S₁ ≤ S₂ → S₁.map f ≤ S₂.map f :=
314
  set.image_subset f
315
 
316
+ lemma map_injective {f : A →ₐ[R] B} (hf : function.injective f) :
317
+ function.injective (map f) :=
318
+ λ S₁ S₂ ih, ext $ set.ext_iff.1 $ set.image_injective.2 hf $ set.ext $ set_like.ext_iff.mp ih
319
 
320
  @[simp] lemma map_id (S : subalgebra R A) : S.map (alg_hom.id R A) = S :=
321
  set_like.coe_injective $ set.image_id _
 
325
  set_like.coe_injective $ set.image_image _ _ _
326
 
327
  lemma mem_map {S : subalgebra R A} {f : A →ₐ[R] B} {y : B} :
328
+ y ∈ map f S ↔ ∃ x ∈ S, f x = y :=
329
  subsemiring.mem_map
330
 
331
  lemma map_to_submodule {S : subalgebra R A} {f : A →ₐ[R] B} :
 
341
  rfl
342
 
343
  /-- Preimage of a subalgebra under an algebra homomorphism. -/
344
+ def comap (f : A →ₐ[R] B) (S : subalgebra R B) : subalgebra R A :=
345
  { algebra_map_mem' := λ r, show f (algebra_map R A r) ∈ S,
346
  from (f.commutes r).symm ▸ S.algebra_map_mem r,
347
  .. S.to_subsemiring.comap (f : A →+* B) }
348
 
349
  theorem map_le {S : subalgebra R A} {f : A →ₐ[R] B} {U : subalgebra R B} :
350
+ map f S ≤ U ↔ S ≤ comap f U :=
351
  set.image_subset_iff
352
 
353
+ lemma gc_map_comap (f : A →ₐ[R] B) : galois_connection (map f) (comap f) :=
354
  λ S U, map_le
355
 
356
  @[simp] lemma mem_comap (S : subalgebra R B) (f : A →ₐ[R] B) (x : A) :
 
648
  @[simp] theorem range_id : (alg_hom.id R A).range = ⊤ :=
649
  set_like.coe_injective set.range_id
650
 
651
+ @[simp] theorem map_top (f : A →ₐ[R] B) : (⊤ : subalgebra R A).map f = f.range :=
652
  set_like.coe_injective set.image_univ
653
 
654
+ @[simp] theorem map_bot (f : A →ₐ[R] B) : (⊥ : subalgebra R A).map f = ⊥ :=
655
  set_like.coe_injective $
656
  by simp only [← set.range_comp, (∘), algebra.coe_bot, subalgebra.coe_map, f.commutes]
657
 
658
+ @[simp] theorem comap_top (f : A →ₐ[R] B) : (⊤ : subalgebra R B).comap f = ⊤ :=
659
  eq_top_iff.2 $ λ x, mem_top
660
 
661
  /-- `alg_hom` to `⊤ : subalgebra R A`. -/
 
810
 
811
  /-- The product of two subalgebras is a subalgebra. -/
812
  def prod : subalgebra R (A × B) :=
813
+ { carrier := S ×ˢ S₁,
814
  algebra_map_mem' := λ r, ⟨algebra_map_mem _ _, algebra_map_mem _ _⟩,
815
  .. S.to_subsemiring.prod S₁.to_subsemiring }
816
 
817
+ @[simp] lemma coe_prod : (prod S S₁ : set (A × B)) = S ×ˢ S₁ := rfl
 
818
 
819
  lemma prod_to_submodule :
820
  (S.prod S₁).to_submodule = S.to_submodule.prod S₁.to_submodule := rfl
formal/lean/mathlib/algebra/algebra/tower.lean CHANGED
@@ -48,7 +48,7 @@ def lsmul : A →ₐ[R] module.End R M :=
48
  @[simp] lemma lsmul_coe (a : A) : (lsmul R M a : M → M) = (•) a := rfl
49
 
50
  lemma lmul_algebra_map (x : R) :
51
- lmul R A (algebra_map R A x) = algebra.lsmul R A x :=
52
  eq.symm $ linear_map.ext $ smul_def x
53
 
54
  end algebra
 
48
  @[simp] lemma lsmul_coe (a : A) : (lsmul R M a : M → M) = (•) a := rfl
49
 
50
  lemma lmul_algebra_map (x : R) :
51
+ algebra.lmul R A (algebra_map R A x) = algebra.lsmul R A x :=
52
  eq.symm $ linear_map.ext $ smul_def x
53
 
54
  end algebra
formal/lean/mathlib/algebra/algebra/unitization.lean CHANGED
@@ -345,9 +345,8 @@ instance [comm_monoid R] [non_unital_semiring A] [distrib_mul_action R A] [is_sc
345
  abel },
346
  ..unitization.mul_one_class }
347
 
348
- -- This should work for `non_unital_comm_semiring`s, but we don't seem to have those
349
- instance [comm_monoid R] [comm_semiring A] [distrib_mul_action R A] [is_scalar_tower R A A]
350
- [smul_comm_class R A A] : comm_monoid (unitization R A) :=
351
  { mul_comm := λ x₁ x₂, ext (mul_comm x₁.1 x₂.1) $
352
  show x₁.1 • x₂.2 + x₂.1 • x₁.2 + x₁.2 * x₂.2 = x₂.1 • x₁.2 + x₁.1 • x₂.2 + x₂.2 * x₁.2,
353
  by rw [add_comm (x₁.1 • x₂.2), mul_comm],
@@ -358,8 +357,7 @@ instance [comm_semiring R] [non_unital_semiring A] [module R A] [is_scalar_tower
358
  { ..unitization.monoid,
359
  ..unitization.non_assoc_semiring }
360
 
361
- -- This should work for `non_unital_comm_semiring`s, but we don't seem to have those
362
- instance [comm_semiring R] [comm_semiring A] [module R A] [is_scalar_tower R A A]
363
  [smul_comm_class R A A] : comm_semiring (unitization R A) :=
364
  { ..unitization.comm_monoid,
365
  ..unitization.non_assoc_semiring }
 
345
  abel },
346
  ..unitization.mul_one_class }
347
 
348
+ instance [comm_monoid R] [non_unital_comm_semiring A] [distrib_mul_action R A]
349
+ [is_scalar_tower R A A] [smul_comm_class R A A] : comm_monoid (unitization R A) :=
 
350
  { mul_comm := λ x₁ x₂, ext (mul_comm x₁.1 x₂.1) $
351
  show x₁.1 • x₂.2 + x₂.1 • x₁.2 + x₁.2 * x₂.2 = x₂.1 • x₁.2 + x₁.1 • x₂.2 + x₂.2 * x₁.2,
352
  by rw [add_comm (x₁.1 • x₂.2), mul_comm],
 
357
  { ..unitization.monoid,
358
  ..unitization.non_assoc_semiring }
359
 
360
+ instance [comm_semiring R] [non_unital_comm_semiring A] [module R A] [is_scalar_tower R A A]
 
361
  [smul_comm_class R A A] : comm_semiring (unitization R A) :=
362
  { ..unitization.comm_monoid,
363
  ..unitization.non_assoc_semiring }
formal/lean/mathlib/algebra/big_operators/basic.lean CHANGED
@@ -39,7 +39,7 @@ See the documentation of `to_additive.attr` for more information.
39
  -/
40
 
41
  universes u v w
42
- variables {β : Type u} {α : Type v} {γ : Type w}
43
 
44
  open fin
45
 
@@ -512,24 +512,24 @@ eq.trans (by rw one_mul; refl) fold_op_distrib
512
 
513
  @[to_additive]
514
  lemma prod_product {s : finset γ} {t : finset α} {f : γ×α → β} :
515
- (∏ x in s.product t, f x) = ∏ x in s, ∏ y in t, f (x, y) :=
516
- prod_finset_product (s.product t) s (λ a, t) (λ p, mem_product)
517
 
518
  /-- An uncurried version of `finset.prod_product`. -/
519
  @[to_additive "An uncurried version of `finset.sum_product`"]
520
  lemma prod_product' {s : finset γ} {t : finset α} {f : γ → α → β} :
521
- (∏ x in s.product t, f x.1 x.2) = ∏ x in s, ∏ y in t, f x y :=
522
  prod_product
523
 
524
  @[to_additive]
525
  lemma prod_product_right {s : finset γ} {t : finset α} {f : γ×α → β} :
526
- (∏ x in s.product t, f x) = ∏ y in t, ∏ x in s, f (x, y) :=
527
- prod_finset_product_right (s.product t) t (λ a, s) (λ p, mem_product.trans and.comm)
528
 
529
  /-- An uncurried version of `finset.prod_product_right`. -/
530
  @[to_additive "An uncurried version of `finset.prod_product_right`"]
531
  lemma prod_product_right' {s : finset γ} {t : finset α} {f : γ → α → β} :
532
- (∏ x in s.product t, f x.1 x.2) = ∏ y in t, ∏ x in s, f x y :=
533
  prod_product_right
534
 
535
  /-- Generalization of `finset.prod_comm` to the case when the inner `finset`s depend on the outer
@@ -1015,6 +1015,10 @@ begin
1015
  rw [count_eq_zero_of_not_mem hx, pow_zero],
1016
  end
1017
 
 
 
 
 
1018
  open multiset
1019
 
1020
  @[to_additive] lemma prod_multiset_map_count [decidable_eq α] (s : multiset α)
@@ -1099,6 +1103,16 @@ lemma prod_range_div' {M : Type*} [comm_group M] (f : ℕ → M) (n : ℕ) :
1099
  ∏ i in range n, (f i / f (i + 1)) = f 0 / f n :=
1100
  by apply prod_range_induction; simp
1101
 
 
 
 
 
 
 
 
 
 
 
1102
  /--
1103
  A telescoping sum along `{0, ..., n-1}` of an `ℕ`-valued function
1104
  reduces to the difference of the last and first terms
@@ -1291,9 +1305,13 @@ begin
1291
  end
1292
 
1293
  /-- Taking a product over `s : finset α` is the same as multiplying the value on a single element
1294
- `f a` by the product of `s.erase a`. -/
 
 
1295
  @[to_additive "Taking a sum over `s : finset α` is the same as adding the value on a single element
1296
- `f a` to the sum over `s.erase a`."]
 
 
1297
  lemma mul_prod_erase [decidable_eq α] (s : finset α) (f : α → β) {a : α} (h : a ∈ s) :
1298
  f a * (∏ x in s.erase a, f x) = ∏ x in s, f x :=
1299
  by rw [← prod_insert (not_mem_erase a s), insert_erase h]
@@ -1388,17 +1406,6 @@ lemma sum_boole {s : finset α} {p : α → Prop} [non_assoc_semiring β] {hp :
1388
  (∑ x in s, if p x then (1 : β) else (0 : β)) = (s.filter p).card :=
1389
  by simp [sum_ite]
1390
 
1391
- lemma eq_sum_range_sub [add_comm_group β] (f : ℕ → β) (n : ℕ) :
1392
- f n = f 0 + ∑ i in range n, (f (i+1) - f i) :=
1393
- by rw [finset.sum_range_sub, add_sub_cancel'_right]
1394
-
1395
- lemma eq_sum_range_sub' [add_comm_group β] (f : ℕ → β) (n : ℕ) :
1396
- f n = ∑ i in range (n + 1), if i = 0 then f 0 else f i - f (i - 1) :=
1397
- begin
1398
- conv_lhs { rw [finset.eq_sum_range_sub f] },
1399
- simp [finset.sum_range_succ', add_comm]
1400
- end
1401
-
1402
  lemma _root_.commute.sum_right [non_unital_non_assoc_semiring β] (s : finset α)
1403
  (f : α → β) (b : β) (h : ∀ i ∈ s, commute b (f i)) :
1404
  commute b (∑ i in s, f i) :=
@@ -1539,13 +1546,7 @@ end prod_eq_zero
1539
  lemma prod_unique_nonempty {α β : Type*} [comm_monoid β] [unique α]
1540
  (s : finset α) (f : α → β) (h : s.nonempty) :
1541
  (∏ x in s, f x) = f default :=
1542
- begin
1543
- obtain ⟨a, ha⟩ := h,
1544
- have : s = {a},
1545
- { ext b,
1546
- simpa [subsingleton.elim a b] using ha },
1547
- rw [this, finset.prod_singleton, subsingleton.elim a default]
1548
- end
1549
 
1550
  end finset
1551
 
@@ -1596,8 +1597,8 @@ by rw [univ_unique, prod_singleton]
1596
  (∏ x : α, f x) = 1 :=
1597
  by rw [eq_empty_of_is_empty (univ : finset α), finset.prod_empty]
1598
 
1599
- @[to_additive]
1600
- lemma prod_subsingleton {α β : Type*} [comm_monoid β] [subsingleton α] (f : α → β) (a : α) :
1601
  (∏ x : α, f x) = f a :=
1602
  begin
1603
  haveI : unique α := unique_of_subsingleton a,
@@ -1631,8 +1632,85 @@ end list
1631
 
1632
  namespace multiset
1633
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1634
  variables [decidable_eq α]
1635
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1636
  @[simp] lemma to_finset_sum_count_eq (s : multiset α) :
1637
  (∑ a in s.to_finset, s.count a) = s.card :=
1638
  multiset.induction_on s rfl
@@ -1780,3 +1858,63 @@ begin
1780
  simp only [his, finset.sum_insert, not_false_iff],
1781
  exact (int.nat_abs_add_le _ _).trans (add_le_add le_rfl IH) }
1782
  end
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  -/
40
 
41
  universes u v w
42
+ variables {ι : Type*} {β : Type u} {α : Type v} {γ : Type w}
43
 
44
  open fin
45
 
 
512
 
513
  @[to_additive]
514
  lemma prod_product {s : finset γ} {t : finset α} {f : γ×α → β} :
515
+ (∏ x in s ×ˢ t, f x) = ∏ x in s, ∏ y in t, f (x, y) :=
516
+ prod_finset_product (s ×ˢ t) s (λ a, t) (λ p, mem_product)
517
 
518
  /-- An uncurried version of `finset.prod_product`. -/
519
  @[to_additive "An uncurried version of `finset.sum_product`"]
520
  lemma prod_product' {s : finset γ} {t : finset α} {f : γ → α → β} :
521
+ (∏ x in s ×ˢ t, f x.1 x.2) = ∏ x in s, ∏ y in t, f x y :=
522
  prod_product
523
 
524
  @[to_additive]
525
  lemma prod_product_right {s : finset γ} {t : finset α} {f : γ×α → β} :
526
+ (∏ x in s ×ˢ t, f x) = ∏ y in t, ∏ x in s, f (x, y) :=
527
+ prod_finset_product_right (s ×ˢ t) t (λ a, s) (λ p, mem_product.trans and.comm)
528
 
529
  /-- An uncurried version of `finset.prod_product_right`. -/
530
  @[to_additive "An uncurried version of `finset.prod_product_right`"]
531
  lemma prod_product_right' {s : finset γ} {t : finset α} {f : γ → α → β} :
532
+ (∏ x in s ×ˢ t, f x.1 x.2) = ∏ y in t, ∏ x in s, f x y :=
533
  prod_product_right
534
 
535
  /-- Generalization of `finset.prod_comm` to the case when the inner `finset`s depend on the outer
 
1015
  rw [count_eq_zero_of_not_mem hx, pow_zero],
1016
  end
1017
 
1018
+ lemma sum_filter_count_eq_countp [decidable_eq α] (p : α → Prop) [decidable_pred p] (l : list α) :
1019
+ ∑ x in l.to_finset.filter p, l.count x = l.countp p :=
1020
+ by simp [finset.sum, sum_map_count_dedup_filter_eq_countp p l]
1021
+
1022
  open multiset
1023
 
1024
  @[to_additive] lemma prod_multiset_map_count [decidable_eq α] (s : multiset α)
 
1103
  ∏ i in range n, (f i / f (i + 1)) = f 0 / f n :=
1104
  by apply prod_range_induction; simp
1105
 
1106
+ @[to_additive]
1107
+ lemma eq_prod_range_div {M : Type*} [comm_group M] (f : ℕ → M) (n : ℕ) :
1108
+ f n = f 0 * ∏ i in range n, (f (i + 1) / f i) :=
1109
+ by rw [prod_range_div, mul_div_cancel'_right]
1110
+
1111
+ @[to_additive]
1112
+ lemma eq_prod_range_div' {M : Type*} [comm_group M] (f : ℕ → M) (n : ℕ) :
1113
+ f n = ∏ i in range (n + 1), if i = 0 then f 0 else f i / f (i - 1) :=
1114
+ by { conv_lhs { rw [finset.eq_prod_range_div f] }, simp [finset.prod_range_succ', mul_comm] }
1115
+
1116
  /--
1117
  A telescoping sum along `{0, ..., n-1}` of an `ℕ`-valued function
1118
  reduces to the difference of the last and first terms
 
1305
  end
1306
 
1307
  /-- Taking a product over `s : finset α` is the same as multiplying the value on a single element
1308
+ `f a` by the product of `s.erase a`.
1309
+
1310
+ See `multiset.prod_map_erase` for the `multiset` version. -/
1311
  @[to_additive "Taking a sum over `s : finset α` is the same as adding the value on a single element
1312
+ `f a` to the sum over `s.erase a`.
1313
+
1314
+ See `multiset.sum_map_erase` for the `multiset` version."]
1315
  lemma mul_prod_erase [decidable_eq α] (s : finset α) (f : α → β) {a : α} (h : a ∈ s) :
1316
  f a * (∏ x in s.erase a, f x) = ∏ x in s, f x :=
1317
  by rw [← prod_insert (not_mem_erase a s), insert_erase h]
 
1406
  (∑ x in s, if p x then (1 : β) else (0 : β)) = (s.filter p).card :=
1407
  by simp [sum_ite]
1408
 
 
 
 
 
 
 
 
 
 
 
 
1409
  lemma _root_.commute.sum_right [non_unital_non_assoc_semiring β] (s : finset α)
1410
  (f : α → β) (b : β) (h : ∀ i ∈ s, commute b (f i)) :
1411
  commute b (∑ i in s, f i) :=
 
1546
  lemma prod_unique_nonempty {α β : Type*} [comm_monoid β] [unique α]
1547
  (s : finset α) (f : α → β) (h : s.nonempty) :
1548
  (∏ x in s, f x) = f default :=
1549
+ by rw [h.eq_singleton_default, finset.prod_singleton]
 
 
 
 
 
 
1550
 
1551
  end finset
1552
 
 
1597
  (∏ x : α, f x) = 1 :=
1598
  by rw [eq_empty_of_is_empty (univ : finset α), finset.prod_empty]
1599
 
1600
+ @[to_additive] lemma prod_subsingleton {α β : Type*} [comm_monoid β] [subsingleton α] [fintype α]
1601
+ (f : α → β) (a : α) :
1602
  (∏ x : α, f x) = f a :=
1603
  begin
1604
  haveI : unique α := unique_of_subsingleton a,
 
1632
 
1633
  namespace multiset
1634
 
1635
+ lemma disjoint_list_sum_left {a : multiset α} {l : list (multiset α)} :
1636
+ multiset.disjoint l.sum a ↔ ∀ b ∈ l, multiset.disjoint b a :=
1637
+ begin
1638
+ induction l with b bs ih,
1639
+ { simp only [zero_disjoint, list.not_mem_nil, is_empty.forall_iff, forall_const, list.sum_nil], },
1640
+ { simp_rw [list.sum_cons, disjoint_add_left, list.mem_cons_iff, forall_eq_or_imp],
1641
+ simp [and.congr_left_iff, iff_self, ih], },
1642
+ end
1643
+
1644
+ lemma disjoint_list_sum_right {a : multiset α} {l : list (multiset α)} :
1645
+ multiset.disjoint a l.sum ↔ ∀ b ∈ l, multiset.disjoint a b :=
1646
+ by simpa only [disjoint_comm] using disjoint_list_sum_left
1647
+
1648
+ lemma disjoint_sum_left {a : multiset α} {i : multiset (multiset α)} :
1649
+ multiset.disjoint i.sum a ↔ ∀ b ∈ i, multiset.disjoint b a :=
1650
+ quotient.induction_on i $ λ l, begin
1651
+ rw [quot_mk_to_coe, multiset.coe_sum],
1652
+ exact disjoint_list_sum_left,
1653
+ end
1654
+
1655
+ lemma disjoint_sum_right {a : multiset α} {i : multiset (multiset α)} :
1656
+ multiset.disjoint a i.sum ↔ ∀ b ∈ i, multiset.disjoint a b :=
1657
+ by simpa only [disjoint_comm] using disjoint_sum_left
1658
+
1659
+ lemma disjoint_finset_sum_left {β : Type*} {i : finset β} {f : β → multiset α} {a : multiset α} :
1660
+ multiset.disjoint (i.sum f) a ↔ ∀ b ∈ i, multiset.disjoint (f b) a :=
1661
+ begin
1662
+ convert (@disjoint_sum_left _ a) (map f i.val),
1663
+ simp [finset.mem_def, and.congr_left_iff, iff_self],
1664
+ end
1665
+
1666
+ lemma disjoint_finset_sum_right {β : Type*} {i : finset β} {f : β → multiset α} {a : multiset α} :
1667
+ multiset.disjoint a (i.sum f) ↔ ∀ b ∈ i, multiset.disjoint a (f b) :=
1668
+ by simpa only [disjoint_comm] using disjoint_finset_sum_left
1669
+
1670
  variables [decidable_eq α]
1671
 
1672
+ lemma add_eq_union_left_of_le {x y z : multiset α} (h : y ≤ x) :
1673
+ z + x = z ∪ y ↔ z.disjoint x ∧ x = y :=
1674
+ begin
1675
+ rw ←add_eq_union_iff_disjoint,
1676
+ split,
1677
+ { intro h0,
1678
+ rw and_iff_right_of_imp,
1679
+ { exact (le_of_add_le_add_left $ h0.trans_le $ union_le_add z y).antisymm h, },
1680
+ { rintro rfl,
1681
+ exact h0, } },
1682
+ { rintro ⟨h0, rfl⟩,
1683
+ exact h0, }
1684
+ end
1685
+
1686
+ lemma add_eq_union_right_of_le {x y z : multiset α} (h : z ≤ y) :
1687
+ x + y = x ∪ z ↔ y = z ∧ x.disjoint y :=
1688
+ by simpa only [and_comm] using add_eq_union_left_of_le h
1689
+
1690
+ lemma finset_sum_eq_sup_iff_disjoint {β : Type*} {i : finset β} {f : β → multiset α} :
1691
+ i.sum f = i.sup f ↔ ∀ x y ∈ i, x ≠ y → multiset.disjoint (f x) (f y) :=
1692
+ begin
1693
+ induction i using finset.cons_induction_on with z i hz hr,
1694
+ { simp only [finset.not_mem_empty, is_empty.forall_iff, implies_true_iff,
1695
+ finset.sum_empty, finset.sup_empty, bot_eq_zero, eq_self_iff_true], },
1696
+ { simp_rw [finset.sum_cons hz, finset.sup_cons, finset.mem_cons, multiset.sup_eq_union,
1697
+ forall_eq_or_imp, ne.def, eq_self_iff_true, not_true, is_empty.forall_iff, true_and,
1698
+ imp_and_distrib, forall_and_distrib, ←hr, @eq_comm _ z],
1699
+ have := λ x ∈ i, ne_of_mem_of_not_mem H hz,
1700
+ simp only [this, not_false_iff, true_implies_iff] {contextual := tt},
1701
+ simp_rw [←disjoint_finset_sum_left, ←disjoint_finset_sum_right, disjoint_comm, ←and_assoc,
1702
+ and_self],
1703
+ exact add_eq_union_left_of_le (finset.sup_le (λ x hx, le_sum_of_mem (mem_map_of_mem f hx))), },
1704
+ end
1705
+
1706
+ lemma sup_powerset_len {α : Type*} [decidable_eq α] (x : multiset α) :
1707
+ finset.sup (finset.range (x.card + 1)) (λ k, x.powerset_len k) = x.powerset :=
1708
+ begin
1709
+ convert bind_powerset_len x,
1710
+ rw [multiset.bind, multiset.join, ←finset.range_coe, ←finset.sum_eq_multiset_sum],
1711
+ exact eq.symm (finset_sum_eq_sup_iff_disjoint.mpr (λ _ _ _ _ h, disjoint_powerset_len x h)),
1712
+ end
1713
+
1714
  @[simp] lemma to_finset_sum_count_eq (s : multiset α) :
1715
  (∑ a in s.to_finset, s.count a) = s.card :=
1716
  multiset.induction_on s rfl
 
1858
  simp only [his, finset.sum_insert, not_false_iff],
1859
  exact (int.nat_abs_add_le _ _).trans (add_le_add le_rfl IH) }
1860
  end
1861
+
1862
+ /-! ### `additive`, `multiplicative` -/
1863
+
1864
+ open additive multiplicative
1865
+
1866
+ section monoid
1867
+ variables [monoid α]
1868
+
1869
+ @[simp] lemma of_mul_list_prod (s : list α) : of_mul s.prod = (s.map of_mul).sum :=
1870
+ by simpa [of_mul]
1871
+
1872
+ @[simp] lemma to_mul_list_sum (s : list (additive α)) :
1873
+ to_mul s.sum = (s.map to_mul).prod := by simpa [to_mul, of_mul]
1874
+
1875
+ end monoid
1876
+
1877
+ section add_monoid
1878
+ variables [add_monoid α]
1879
+
1880
+ @[simp] lemma of_add_list_prod (s : list α) : of_add s.sum = (s.map of_add).prod :=
1881
+ by simpa [of_add]
1882
+
1883
+ @[simp] lemma to_add_list_sum (s : list (multiplicative α)) :
1884
+ to_add s.prod = (s.map to_add).sum := by simpa [to_add, of_add]
1885
+
1886
+ end add_monoid
1887
+
1888
+ section comm_monoid
1889
+ variables [comm_monoid α]
1890
+
1891
+ @[simp] lemma of_mul_multiset_prod (s : multiset α) :
1892
+ of_mul s.prod = (s.map of_mul).sum := by simpa [of_mul]
1893
+
1894
+ @[simp] lemma to_mul_multiset_sum (s : multiset (additive α)) :
1895
+ to_mul s.sum = (s.map to_mul).prod := by simpa [to_mul, of_mul]
1896
+
1897
+ @[simp] lemma of_mul_prod (s : finset ι) (f : ι → α) :
1898
+ of_mul (∏ i in s, f i) = ∑ i in s, of_mul (f i) := rfl
1899
+
1900
+ @[simp] lemma to_mul_sum (s : finset ι) (f : ι → additive α) :
1901
+ to_mul (∑ i in s, f i) = ∏ i in s, to_mul (f i) := rfl
1902
+
1903
+ end comm_monoid
1904
+
1905
+ section add_comm_monoid
1906
+ variables [add_comm_monoid α]
1907
+
1908
+ @[simp] lemma of_add_multiset_prod (s : multiset α) :
1909
+ of_add s.sum = (s.map of_add).prod := by simpa [of_add]
1910
+
1911
+ @[simp] lemma to_add_multiset_sum (s : multiset (multiplicative α)) :
1912
+ to_add s.prod = (s.map to_add).sum := by simpa [to_add, of_add]
1913
+
1914
+ @[simp] lemma of_add_sum (s : finset ι) (f : ι → α) :
1915
+ of_add (∑ i in s, f i) = ∏ i in s, of_add (f i) := rfl
1916
+
1917
+ @[simp] lemma to_add_prod (s : finset ι) (f : ι → multiplicative α) :
1918
+ to_add (∏ i in s, f i) = ∑ i in s, to_add (f i) := rfl
1919
+
1920
+ end add_comm_monoid
formal/lean/mathlib/algebra/big_operators/fin.lean CHANGED
@@ -95,6 +95,30 @@ by simp
95
  ∏ i, f i = f 0 * f 1 :=
96
  by simp [prod_univ_succ]
97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  lemma sum_pow_mul_eq_add_pow {n : ℕ} {R : Type*} [comm_semiring R] (a b : R) :
99
  ∑ s : finset (fin n), a ^ s.card * b ^ (n - s.card) = (a + b) ^ n :=
100
  by simpa using fintype.sum_pow_mul_eq_add_pow (fin n) a b
@@ -157,6 +181,29 @@ by simp [partial_prod, list.take_succ, list.of_fn_nth_val, dif_pos j.is_lt, ←o
157
  partial_prod f j.succ = f 0 * partial_prod (fin.tail f) j :=
158
  by simpa [partial_prod]
159
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  end partial_prod
161
 
162
  end fin
 
95
  ∏ i, f i = f 0 * f 1 :=
96
  by simp [prod_univ_succ]
97
 
98
+ @[to_additive] theorem prod_univ_three [comm_monoid β] (f : fin 3 → β) :
99
+ ∏ i, f i = f 0 * f 1 * f 2 :=
100
+ by { rw [prod_univ_cast_succ, prod_univ_two], refl }
101
+
102
+ @[to_additive] theorem prod_univ_four [comm_monoid β] (f : fin 4 → β) :
103
+ ∏ i, f i = f 0 * f 1 * f 2 * f 3 :=
104
+ by { rw [prod_univ_cast_succ, prod_univ_three], refl }
105
+
106
+ @[to_additive] theorem prod_univ_five [comm_monoid β] (f : fin 5 → β) :
107
+ ∏ i, f i = f 0 * f 1 * f 2 * f 3 * f 4 :=
108
+ by { rw [prod_univ_cast_succ, prod_univ_four], refl }
109
+
110
+ @[to_additive] theorem prod_univ_six [comm_monoid β] (f : fin 6 → β) :
111
+ ∏ i, f i = f 0 * f 1 * f 2 * f 3 * f 4 * f 5 :=
112
+ by { rw [prod_univ_cast_succ, prod_univ_five], refl }
113
+
114
+ @[to_additive] theorem prod_univ_seven [comm_monoid β] (f : fin 7 → β) :
115
+ ∏ i, f i = f 0 * f 1 * f 2 * f 3 * f 4 * f 5 * f 6 :=
116
+ by { rw [prod_univ_cast_succ, prod_univ_six], refl }
117
+
118
+ @[to_additive] theorem prod_univ_eight [comm_monoid β] (f : fin 8 → β) :
119
+ ∏ i, f i = f 0 * f 1 * f 2 * f 3 * f 4 * f 5 * f 6 * f 7 :=
120
+ by { rw [prod_univ_cast_succ, prod_univ_seven], refl }
121
+
122
  lemma sum_pow_mul_eq_add_pow {n : ℕ} {R : Type*} [comm_semiring R] (a b : R) :
123
  ∑ s : finset (fin n), a ^ s.card * b ^ (n - s.card) = (a + b) ^ n :=
124
  by simpa using fintype.sum_pow_mul_eq_add_pow (fin n) a b
 
181
  partial_prod f j.succ = f 0 * partial_prod (fin.tail f) j :=
182
  by simpa [partial_prod]
183
 
184
+ @[to_additive] lemma partial_prod_left_inv {G : Type*} [group G] (f : fin (n + 1) → G) :
185
+ f 0 • partial_prod (λ i : fin n, (f i)⁻¹ * f i.succ) = f :=
186
+ funext $ λ x, fin.induction_on x (by simp) (λ x hx,
187
+ begin
188
+ simp only [coe_eq_cast_succ, pi.smul_apply, smul_eq_mul] at hx ⊢,
189
+ rw [partial_prod_succ, ←mul_assoc, hx, mul_inv_cancel_left],
190
+ end)
191
+
192
+ @[to_additive] lemma partial_prod_right_inv {G : Type*} [group G]
193
+ (g : G) (f : fin n → G) (i : fin n) :
194
+ ((g • partial_prod f) i)⁻¹ * (g • partial_prod f) i.succ = f i :=
195
+ begin
196
+ cases i with i hn,
197
+ induction i with i hi generalizing hn,
198
+ { simp [←fin.succ_mk, partial_prod_succ] },
199
+ { specialize hi (lt_trans (nat.lt_succ_self i) hn),
200
+ simp only [mul_inv_rev, fin.coe_eq_cast_succ, fin.succ_mk, fin.cast_succ_mk,
201
+ smul_eq_mul, pi.smul_apply] at hi ⊢,
202
+ rw [←fin.succ_mk _ _ (lt_trans (nat.lt_succ_self _) hn), ←fin.succ_mk],
203
+ simp only [partial_prod_succ, mul_inv_rev, fin.cast_succ_mk],
204
+ assoc_rw [hi, inv_mul_cancel_left] }
205
+ end
206
+
207
  end partial_prod
208
 
209
  end fin
formal/lean/mathlib/algebra/big_operators/multiset.lean CHANGED
@@ -58,6 +58,12 @@ lemma prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s := foldr_cons _ _ _
58
  lemma prod_erase [decidable_eq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod :=
59
  by rw [← s.coe_to_list, coe_erase, coe_prod, coe_prod, list.prod_erase ((s.mem_to_list a).2 h)]
60
 
 
 
 
 
 
 
61
  @[simp, to_additive]
62
  lemma prod_singleton (a : α) : prod {a} = a :=
63
  by simp only [mul_one, prod_cons, singleton_eq_cons, eq_self_iff_true, prod_zero]
@@ -78,6 +84,22 @@ lemma prod_nsmul (m : multiset α) : ∀ (n : ℕ), (n • m).prod = m.prod ^ n
78
  @[simp, to_additive] lemma prod_repeat (a : α) (n : ℕ) : (repeat a n).prod = a ^ n :=
79
  by simp [repeat, list.prod_repeat]
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  @[to_additive]
82
  lemma pow_count [decidable_eq α] (a : α) : a ^ s.count a = (s.filter (eq a)).prod :=
83
  by rw [filter_eq, prod_repeat]
@@ -319,6 +341,15 @@ lemma prod_eq_one_iff [canonically_ordered_monoid α] {m : multiset α} :
319
  m.prod = 1 ↔ ∀ x ∈ m, x = (1 : α) :=
320
  quotient.induction_on m $ λ l, by simpa using list.prod_eq_one_iff l
321
 
 
 
 
 
 
 
 
 
 
322
  @[to_additive]
323
  lemma le_prod_of_mem [canonically_ordered_monoid α] {m : multiset α} {a : α} (h : a ∈ m) :
324
  a ≤ m.prod :=
 
58
  lemma prod_erase [decidable_eq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod :=
59
  by rw [← s.coe_to_list, coe_erase, coe_prod, coe_prod, list.prod_erase ((s.mem_to_list a).2 h)]
60
 
61
+ @[simp, to_additive]
62
+ lemma prod_map_erase [decidable_eq ι] {a : ι} (h : a ∈ m) :
63
+ f a * ((m.erase a).map f).prod = (m.map f).prod :=
64
+ by rw [← m.coe_to_list, coe_erase, coe_map, coe_map, coe_prod, coe_prod,
65
+ list.prod_map_erase f ((m.mem_to_list a).2 h)]
66
+
67
  @[simp, to_additive]
68
  lemma prod_singleton (a : α) : prod {a} = a :=
69
  by simp only [mul_one, prod_cons, singleton_eq_cons, eq_self_iff_true, prod_zero]
 
84
  @[simp, to_additive] lemma prod_repeat (a : α) (n : ℕ) : (repeat a n).prod = a ^ n :=
85
  by simp [repeat, list.prod_repeat]
86
 
87
+ @[to_additive]
88
+ lemma prod_map_eq_pow_single [decidable_eq ι] (i : ι) (hf : ∀ i' ≠ i, i' ∈ m → f i' = 1) :
89
+ (m.map f).prod = f i ^ m.count i :=
90
+ begin
91
+ induction m using quotient.induction_on with l,
92
+ simp [list.prod_map_eq_pow_single i f hf],
93
+ end
94
+
95
+ @[to_additive]
96
+ lemma prod_eq_pow_single [decidable_eq α] (a : α) (h : ∀ a' ≠ a, a' ∈ s → a' = 1) :
97
+ s.prod = a ^ (s.count a) :=
98
+ begin
99
+ induction s using quotient.induction_on with l,
100
+ simp [list.prod_eq_pow_single a h],
101
+ end
102
+
103
  @[to_additive]
104
  lemma pow_count [decidable_eq α] (a : α) : a ^ s.count a = (s.filter (eq a)).prod :=
105
  by rw [filter_eq, prod_repeat]
 
341
  m.prod = 1 ↔ ∀ x ∈ m, x = (1 : α) :=
342
  quotient.induction_on m $ λ l, by simpa using list.prod_eq_one_iff l
343
 
344
+ /-- Slightly more general version of `multiset.prod_eq_one_iff` for a non-ordered `monoid` -/
345
+ @[to_additive "Slightly more general version of `multiset.sum_eq_zero_iff`
346
+ for a non-ordered `add_monoid`"]
347
+ lemma prod_eq_one [comm_monoid α] {m : multiset α} (h : ∀ x ∈ m, x = (1 : α)) : m.prod = 1 :=
348
+ begin
349
+ induction m using quotient.induction_on with l,
350
+ simp [list.prod_eq_one h],
351
+ end
352
+
353
  @[to_additive]
354
  lemma le_prod_of_mem [canonically_ordered_monoid α] {m : multiset α} {a : α} (h : a ∈ m) :
355
  a ≤ m.prod :=
formal/lean/mathlib/algebra/big_operators/norm_num.lean CHANGED
@@ -83,72 +83,6 @@ meta def list.decide_mem (decide_eq : expr → expr → tactic (bool × expr)) :
83
  pf ← i_to_expr ``(list.not_mem_cons %%head_pf %%tail_pf),
84
  pure (ff, pf)
85
 
86
- lemma finset.insert_eq_coe_list_of_mem {α : Type*} [decidable_eq α] (x : α) (xs : finset α)
87
- {xs' : list α} (h : x ∈ xs') (nd_xs : xs'.nodup)
88
- (hxs' : xs = finset.mk ↑xs' (multiset.coe_nodup.mpr nd_xs)) :
89
- insert x xs = finset.mk ↑xs' (multiset.coe_nodup.mpr nd_xs) :=
90
- have h : x ∈ xs, by simpa [hxs'] using h,
91
- by rw [finset.insert_eq_of_mem h, hxs']
92
-
93
- lemma finset.insert_eq_coe_list_cons {α : Type*} [decidable_eq α] (x : α) (xs : finset α)
94
- {xs' : list α} (h : x ∉ xs') (nd_xs : xs'.nodup) (nd_xxs : (x :: xs').nodup)
95
- (hxs' : xs = finset.mk ↑xs' (multiset.coe_nodup.mpr nd_xs)) :
96
- insert x xs = finset.mk ↑(x :: xs') (multiset.coe_nodup.mpr nd_xxs) :=
97
- have h : x ∉ xs, by simpa [hxs'] using h,
98
- by { rw [← finset.val_inj, finset.insert_val_of_not_mem h, hxs'], simp only [multiset.cons_coe] }
99
-
100
- /-- Convert an expression denoting a finset to a list of elements,
101
- a proof that this list is equal to the original finset,
102
- and a proof that the list contains no duplicates.
103
-
104
- We return a list rather than a finset, so we can more easily iterate over it
105
- (without having to prove that our tactics are independent of the order of iteration,
106
- which is in general not true).
107
-
108
- `decide_eq` is a (partial) decision procedure for determining whether two
109
- elements of the finset are equal, for example to parse `{2, 1, 2}` into `[2, 1]`.
110
- -/
111
- meta def eval_finset (decide_eq : expr → expr → tactic (bool × expr)) :
112
- expr → tactic (list expr × expr × expr)
113
- | e@`(has_emptyc.emptyc) := do
114
- eq ← mk_eq_refl e,
115
- nd ← i_to_expr ``(list.nodup_nil),
116
- pure ([], eq, nd)
117
- | e@`(has_singleton.singleton %%x) := do
118
- eq ← mk_eq_refl e,
119
- nd ← i_to_expr ``(list.nodup_singleton %%x),
120
- pure ([x], eq, nd)
121
- | `(@@has_insert.insert (@@finset.has_insert %%dec) %%x %%xs) := do
122
- (exs, xs_eq, xs_nd) ← eval_finset xs,
123
- (is_mem, mem_pf) ← list.decide_mem decide_eq x exs,
124
- if is_mem then do
125
- pf ← i_to_expr ``(finset.insert_eq_coe_list_of_mem %%x %%xs %%mem_pf %%xs_nd %%xs_eq),
126
- pure (exs, pf, xs_nd)
127
- else do
128
- nd ← i_to_expr ``(list.nodup_cons.mpr ⟨%%mem_pf, %%xs_nd⟩),
129
- pf ← i_to_expr ``(finset.insert_eq_coe_list_cons %%x %%xs %%mem_pf %%xs_nd %%nd %%xs_eq),
130
- pure (x :: exs, pf, nd)
131
- | `(@@finset.univ %%ft) := do
132
- -- Convert the fintype instance expression `ft` to a list of its elements.
133
- -- Unfold it to the `fintype.mk` constructor and a list of arguments.
134
- `fintype.mk ← get_app_fn_const_whnf ft
135
- | fail (to_fmt "Unknown fintype expression" ++ format.line ++ to_fmt ft),
136
- [_, args, _] ← get_app_args_whnf ft | fail (to_fmt "Expected 3 arguments to `fintype.mk`"),
137
- eval_finset args
138
- | e@`(finset.range %%en) := do
139
- n ← expr.to_nat en,
140
- eis ← (list.range n).mmap (λ i, expr.of_nat `(ℕ) i),
141
- eq ← mk_eq_refl e,
142
- nd ← i_to_expr ``(list.nodup_range %%en),
143
- pure (eis, eq, nd)
144
- | e@`(finset.fin_range %%en) := do
145
- n ← expr.to_nat en,
146
- eis ← (list.fin_range n).mmap (λ i, expr.of_nat `(fin %%en) i),
147
- eq ← mk_eq_refl e,
148
- nd ← i_to_expr ``(list.nodup_fin_range %%en),
149
- pure (eis, eq, nd)
150
- | e := fail (to_fmt "Unknown finset expression" ++ format.line ++ to_fmt e)
151
-
152
  lemma list.map_cons_congr {α β : Type*} (f : α → β) {x : α} {xs : list α} {fx : β} {fxs : list β}
153
  (h₁ : f x = fx) (h₂ : xs.map f = fxs) : (x :: xs).map f = fx :: fxs :=
154
  by rw [list.map_cons, h₁, h₂]
@@ -164,6 +98,36 @@ meta def eval_list_map (ef : expr) : list expr → tactic (list expr × expr)
164
  eq ← i_to_expr ``(list.map_cons_congr %%ef %%fx_eq %%fxs_eq),
165
  pure (fx :: fxs, eq)
166
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  lemma multiset.cons_congr {α : Type*} (x : α) {xs : multiset α} {xs' : list α}
168
  (xs_eq : (xs' : multiset α) = xs) : (list.cons x xs' : multiset α) = x ::ₘ xs :=
169
  by rw [← xs_eq]; refl
@@ -209,35 +173,71 @@ meta def eval_multiset : expr → tactic (list expr × expr)
209
  pure (ys, eq)
210
  | e := fail (to_fmt "Unknown multiset expression" ++ format.line ++ to_fmt e)
211
 
212
- lemma list.cons_congr {α : Type*} (x : α) {xs : list α} {xs' : list α} (xs_eq : xs' = xs) :
213
- x :: xs' = x :: xs :=
214
- by rw xs_eq
 
 
 
215
 
216
- lemma list.map_congrβ : Type*} (f : α → β) {xs xs' : list α}
217
- {ys : list β} (xs_eq : xs = xs') (ys_eq : xs'.map f = ys) :
218
- xs.map f = ys :=
219
- by rw [← ys_eq, xs_eq]
 
 
220
 
221
- /-- Convert an expression denoting a list to a list of elements. -/
222
- meta def eval_list : expr tactic (list expr × expr)
223
- | e@`(list.nil) := do
 
 
 
 
 
 
 
 
 
 
 
224
  eq ← mk_eq_refl e,
225
- pure ([], eq)
226
- | e@`(list.cons %%x %%xs) := do
227
- (xs, xs_eq) eval_list xs,
228
- eq ← i_to_expr ``(list.cons_congr %%x %%xs_eq),
229
- pure (x :: xs, eq)
230
- | e@`(list.range %%en) := do
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  n ← expr.to_nat en,
232
  eis ← (list.range n).mmap (λ i, expr.of_nat `(ℕ) i),
233
  eq ← mk_eq_refl e,
234
- pure (eis, eq)
235
- | `(@list.map %%α %%β %%ef %%exs) := do
236
- (xs, xs_eq) eval_list exs,
237
- (ys, ys_eq) eval_list_map ef xs,
238
- eqi_to_expr ``(list.map_congr %%ef %%xs_eq %%ys_eq),
239
- pure (ys, eq)
240
- | e := fail (to_fmt "Unknown list expression" ++ format.line ++ to_fmt e)
 
 
241
 
242
  @[to_additive]
243
  lemma list.prod_cons_congr {α : Type*} [monoid α] (xs : list α) (x y z : α)
 
83
  pf ← i_to_expr ``(list.not_mem_cons %%head_pf %%tail_pf),
84
  pure (ff, pf)
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  lemma list.map_cons_congr {α β : Type*} (f : α → β) {x : α} {xs : list α} {fx : β} {fxs : list β}
87
  (h₁ : f x = fx) (h₂ : xs.map f = fxs) : (x :: xs).map f = fx :: fxs :=
88
  by rw [list.map_cons, h₁, h₂]
 
98
  eq ← i_to_expr ``(list.map_cons_congr %%ef %%fx_eq %%fxs_eq),
99
  pure (fx :: fxs, eq)
100
 
101
+ lemma list.cons_congr {α : Type*} (x : α) {xs : list α} {xs' : list α} (xs_eq : xs' = xs) :
102
+ x :: xs' = x :: xs :=
103
+ by rw xs_eq
104
+
105
+ lemma list.map_congr {α β : Type*} (f : α → β) {xs xs' : list α}
106
+ {ys : list β} (xs_eq : xs = xs') (ys_eq : xs'.map f = ys) :
107
+ xs.map f = ys :=
108
+ by rw [← ys_eq, xs_eq]
109
+
110
+ /-- Convert an expression denoting a list to a list of elements. -/
111
+ meta def eval_list : expr → tactic (list expr × expr)
112
+ | e@`(list.nil) := do
113
+ eq ← mk_eq_refl e,
114
+ pure ([], eq)
115
+ | e@`(list.cons %%x %%xs) := do
116
+ (xs, xs_eq) ← eval_list xs,
117
+ eq ← i_to_expr ``(list.cons_congr %%x %%xs_eq),
118
+ pure (x :: xs, eq)
119
+ | e@`(list.range %%en) := do
120
+ n ← expr.to_nat en,
121
+ eis ← (list.range n).mmap (λ i, expr.of_nat `(ℕ) i),
122
+ eq ← mk_eq_refl e,
123
+ pure (eis, eq)
124
+ | `(@list.map %%α %%β %%ef %%exs) := do
125
+ (xs, xs_eq) ← eval_list exs,
126
+ (ys, ys_eq) ← eval_list_map ef xs,
127
+ eq ← i_to_expr ``(list.map_congr %%ef %%xs_eq %%ys_eq),
128
+ pure (ys, eq)
129
+ | e := fail (to_fmt "Unknown list expression" ++ format.line ++ to_fmt e)
130
+
131
  lemma multiset.cons_congr {α : Type*} (x : α) {xs : multiset α} {xs' : list α}
132
  (xs_eq : (xs' : multiset α) = xs) : (list.cons x xs' : multiset α) = x ::ₘ xs :=
133
  by rw [← xs_eq]; refl
 
173
  pure (ys, eq)
174
  | e := fail (to_fmt "Unknown multiset expression" ++ format.line ++ to_fmt e)
175
 
176
+ lemma finset.insert_eq_coe_list_of_mem {α : Type*} [decidable_eq α] (x : α) (xs : finset α)
177
+ {xs' : list α} (h : x xs') (nd_xs : xs'.nodup)
178
+ (hxs' : xs = finset.mk ↑xs' (multiset.coe_nodup.mpr nd_xs)) :
179
+ insert x xs = finset.mk ↑xs' (multiset.coe_nodup.mpr nd_xs) :=
180
+ have h : x ∈ xs, by simpa [hxs'] using h,
181
+ by rw [finset.insert_eq_of_mem h, hxs']
182
 
183
+ lemma finset.insert_eq_coe_list_cons {α : Type*} [decidable_eq α] (x : α) (xs : finset α)
184
+ {xs' : list α} (h : x xs') (nd_xs : xs'.nodup) (nd_xxs : (x :: xs').nodup)
185
+ (hxs' : xs = finset.mk ↑xs' (multiset.coe_nodup.mpr nd_xs)) :
186
+ insert x xs = finset.mk ↑(x :: xs') (multiset.coe_nodup.mpr nd_xxs) :=
187
+ have h : x ∉ xs, by simpa [hxs'] using h,
188
+ by { rw [← finset.val_inj, finset.insert_val_of_not_mem h, hxs'], simp only [multiset.cons_coe] }
189
 
190
+ /-- Convert an expression denoting a finset to a list of elements,
191
+ a proof that this list is equal to the original finset,
192
+ and a proof that the list contains no duplicates.
193
+
194
+ We return a list rather than a finset, so we can more easily iterate over it
195
+ (without having to prove that our tactics are independent of the order of iteration,
196
+ which is in general not true).
197
+
198
+ `decide_eq` is a (partial) decision procedure for determining whether two
199
+ elements of the finset are equal, for example to parse `{2, 1, 2}` into `[2, 1]`.
200
+ -/
201
+ meta def eval_finset (decide_eq : expr → expr → tactic (bool × expr)) :
202
+ expr → tactic (list expr × expr × expr)
203
+ | e@`(has_emptyc.emptyc) := do
204
  eq ← mk_eq_refl e,
205
+ nd ← i_to_expr ``(list.nodup_nil),
206
+ pure ([], eq, nd)
207
+ | e@`(has_singleton.singleton %%x) := do
208
+ eq ← mk_eq_refl e,
209
+ nd i_to_expr ``(list.nodup_singleton %%x),
210
+ pure ([x], eq, nd)
211
+ | `(@@has_insert.insert (@@finset.has_insert %%dec) %%x %%xs) := do
212
+ (exs, xs_eq, xs_nd) ← eval_finset xs,
213
+ (is_mem, mem_pf) ← list.decide_mem decide_eq x exs,
214
+ if is_mem then do
215
+ pf ← i_to_expr ``(finset.insert_eq_coe_list_of_mem %%x %%xs %%mem_pf %%xs_nd %%xs_eq),
216
+ pure (exs, pf, xs_nd)
217
+ else do
218
+ nd ← i_to_expr ``(list.nodup_cons.mpr ⟨%%mem_pf, %%xs_nd⟩),
219
+ pf ← i_to_expr ``(finset.insert_eq_coe_list_cons %%x %%xs %%mem_pf %%xs_nd %%nd %%xs_eq),
220
+ pure (x :: exs, pf, nd)
221
+ | `(@@finset.univ %%ft) := do
222
+ -- Convert the fintype instance expression `ft` to a list of its elements.
223
+ -- Unfold it to the `fintype.mk` constructor and a list of arguments.
224
+ `fintype.mk ← get_app_fn_const_whnf ft
225
+ | fail (to_fmt "Unknown fintype expression" ++ format.line ++ to_fmt ft),
226
+ [_, args, _] ← get_app_args_whnf ft | fail (to_fmt "Expected 3 arguments to `fintype.mk`"),
227
+ eval_finset args
228
+ | e@`(finset.range %%en) := do
229
  n ← expr.to_nat en,
230
  eis ← (list.range n).mmap (λ i, expr.of_nat `(ℕ) i),
231
  eq ← mk_eq_refl e,
232
+ nd ← i_to_expr ``(list.nodup_range %%en),
233
+ pure (eis, eq, nd)
234
+ | e@`(finset.fin_range %%en) := do
235
+ nexpr.to_nat en,
236
+ eis ← (list.fin_range n).mmap i, expr.of_nat `(fin %%en) i),
237
+ eq ← mk_eq_refl e,
238
+ nd i_to_expr ``(list.nodup_fin_range %%en),
239
+ pure (eis, eq, nd)
240
+ | e := fail (to_fmt "Unknown finset expression" ++ format.line ++ to_fmt e)
241
 
242
  @[to_additive]
243
  lemma list.prod_cons_congr {α : Type*} [monoid α] (xs : list α) (x y z : α)
formal/lean/mathlib/algebra/big_operators/ring.lean CHANGED
@@ -52,7 +52,7 @@ add_monoid_hom.map_sum (add_monoid_hom.mul_left b) _ s
52
 
53
  lemma sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : finset ι₁) (s₂ : finset ι₂)
54
  (f₁ : ι₁ → β) (f₂ : ι₂ → β) :
55
- (∑ x₁ in s₁, f₁ x₁) * (∑ x₂ in s₂, f₂ x₂) = ∑ p in s₁.product s₂, f₁ p.1 * f₂ p.2 :=
56
  by { rw [sum_product, sum_mul, sum_congr rfl], intros, rw mul_sum }
57
 
58
  end semiring
 
52
 
53
  lemma sum_mul_sum {ι₁ : Type*} {ι₂ : Type*} (s₁ : finset ι₁) (s₂ : finset ι₂)
54
  (f₁ : ι₁ → β) (f₂ : ι₂ → β) :
55
+ (∑ x₁ in s₁, f₁ x₁) * (∑ x₂ in s₂, f₂ x₂) = ∑ p in s ×ˢ s₂, f₁ p.1 * f₂ p.2 :=
56
  by { rw [sum_product, sum_mul, sum_congr rfl], intros, rw mul_sum }
57
 
58
  end semiring
formal/lean/mathlib/algebra/category/FinVect.lean CHANGED
@@ -31,22 +31,21 @@ instance monoidal_predicate_finite_dimensional :
31
  { prop_id' := finite_dimensional.finite_dimensional_self K,
32
  prop_tensor' := λ X Y hX hY, by exactI module.finite.tensor_product K X Y }
33
 
 
 
 
 
34
  /-- Define `FinVect` as the subtype of `Module.{u} K` of finite dimensional vector spaces. -/
35
- @[derive [large_category, λ α, has_coe_to_sort α (Sort*), concrete_category, monoidal_category,
36
- symmetric_category]]
37
- def FinVect := { V : Module.{u} K // finite_dimensional K V }
38
 
39
  namespace FinVect
40
 
41
- instance finite_dimensional (V : FinVect K) : finite_dimensional K V := V.prop
42
 
43
  instance : inhabited (FinVect K) := ⟨⟨Module.of K K, finite_dimensional.finite_dimensional_self K⟩⟩
44
 
45
- instance : has_coe (FinVect.{u} K) (Module.{u} K) := { coe := λ V, V.1, }
46
-
47
- protected lemma coe_comp {U V W : FinVect K} (f : U ⟶ V) (g : V ⟶ W) :
48
- ((f ≫ g) : U → W) = (g : V → W) ∘ (f : U → V) := rfl
49
-
50
  /-- Lift an unbundled vector space to `FinVect K`. -/
51
  def of (V : Type u) [add_comm_group V] [module K V] [finite_dimensional K V] : FinVect K :=
52
  ⟨Module.of K V, by { change finite_dimensional K V, apply_instance }⟩
@@ -57,46 +56,45 @@ by { dsimp [FinVect], apply_instance, }
57
  instance : full (forget₂ (FinVect K) (Module.{u} K)) :=
58
  { preimage := λ X Y f, f, }
59
 
60
- variables (V : FinVect K)
 
 
61
 
62
  /-- The dual module is the dual in the rigid monoidal category `FinVect K`. -/
63
  def FinVect_dual : FinVect K :=
64
- ⟨Module.of K (module.dual K V), subspace.module.dual.finite_dimensional⟩
65
-
66
- instance : has_coe_to_fun (FinVect_dual K V) (λ _, V → K) :=
67
- { coe := λ v, by { change V →ₗ[K] K at v, exact v, } }
68
 
69
  open category_theory.monoidal_category
70
 
71
  /-- The coevaluation map is defined in `linear_algebra.coevaluation`. -/
72
  def FinVect_coevaluation : 𝟙_ (FinVect K) ⟶ V ⊗ (FinVect_dual K V) :=
73
- by apply coevaluation K V
74
 
75
  lemma FinVect_coevaluation_apply_one : FinVect_coevaluation K V (1 : K) =
76
- ∑ (i : basis.of_vector_space_index K V),
77
- (basis.of_vector_space K V) i ⊗ₜ[K] (basis.of_vector_space K V).coord i :=
78
- by apply coevaluation_apply_one K V
79
 
80
  /-- The evaluation morphism is given by the contraction map. -/
81
  def FinVect_evaluation : (FinVect_dual K V) ⊗ V ⟶ 𝟙_ (FinVect K) :=
82
- by apply contract_left K V
83
 
84
  @[simp]
85
- lemma FinVect_evaluation_apply (f : (FinVect_dual K V)) (x : V) :
86
- (FinVect_evaluation K V) (f ⊗ₜ x) = f x :=
87
  by apply contract_left_apply f x
88
 
89
  private theorem coevaluation_evaluation :
90
  let V' : FinVect K := FinVect_dual K V in
91
  (𝟙 V' ⊗ (FinVect_coevaluation K V)) ≫ (α_ V' V V').inv ≫ (FinVect_evaluation K V ⊗ 𝟙 V')
92
  = (ρ_ V').hom ≫ (λ_ V').inv :=
93
- by apply contract_left_assoc_coevaluation K V
94
 
95
  private theorem evaluation_coevaluation :
96
  (FinVect_coevaluation K V ⊗ 𝟙 V)
97
  ≫ (α_ V (FinVect_dual K V) V).hom ≫ (𝟙 V ⊗ FinVect_evaluation K V)
98
  = (λ_ V).hom ≫ (ρ_ V).inv :=
99
- by apply contract_left_assoc_coevaluation' K V
100
 
101
  instance exact_pairing : exact_pairing V (FinVect_dual K V) :=
102
  { coevaluation := FinVect_coevaluation K V,
@@ -108,11 +106,11 @@ instance right_dual : has_right_dual V := ⟨FinVect_dual K V⟩
108
 
109
  instance right_rigid_category : right_rigid_category (FinVect K) := { }
110
 
111
- variables {K V} (W : FinVect K)
112
 
113
  /-- Converts and isomorphism in the category `FinVect` to a `linear_equiv` between the underlying
114
  vector spaces. -/
115
- def iso_to_linear_equiv {V W : FinVect K} (i : V ≅ W) : V ≃ₗ[K] W :=
116
  ((forget₂ (FinVect.{u} K) (Module.{u} K)).map_iso i).to_linear_equiv
117
 
118
  lemma iso.conj_eq_conj {V W : FinVect K} (i : V ≅ W) (f : End V) :
 
31
  { prop_id' := finite_dimensional.finite_dimensional_self K,
32
  prop_tensor' := λ X Y hX hY, by exactI module.finite.tensor_product K X Y }
33
 
34
+ instance closed_predicate_finite_dimensional :
35
+ monoidal_category.closed_predicate (λ V : Module.{u} K, finite_dimensional K V) :=
36
+ { prop_ihom' := λ X Y hX hY, by exactI @linear_map.finite_dimensional K _ X _ _ hX Y _ _ hY }
37
+
38
  /-- Define `FinVect` as the subtype of `Module.{u} K` of finite dimensional vector spaces. -/
39
+ @[derive [large_category, concrete_category, monoidal_category, symmetric_category,
40
+ monoidal_closed]]
41
+ def FinVect := full_subcategory (λ (V : Module.{u} K), finite_dimensional K V)
42
 
43
  namespace FinVect
44
 
45
+ instance finite_dimensional (V : FinVect K) : finite_dimensional K V.obj := V.property
46
 
47
  instance : inhabited (FinVect K) := ⟨⟨Module.of K K, finite_dimensional.finite_dimensional_self K⟩⟩
48
 
 
 
 
 
 
49
  /-- Lift an unbundled vector space to `FinVect K`. -/
50
  def of (V : Type u) [add_comm_group V] [module K V] [finite_dimensional K V] : FinVect K :=
51
  ⟨Module.of K V, by { change finite_dimensional K V, apply_instance }⟩
 
56
  instance : full (forget₂ (FinVect K) (Module.{u} K)) :=
57
  { preimage := λ X Y f, f, }
58
 
59
+ variables (V W : FinVect K)
60
+
61
+ @[simp] lemma ihom_obj : (ihom V).obj W = FinVect.of K (V.obj →ₗ[K] W.obj) := rfl
62
 
63
  /-- The dual module is the dual in the rigid monoidal category `FinVect K`. -/
64
  def FinVect_dual : FinVect K :=
65
+ ⟨Module.of K (module.dual K V.obj), subspace.module.dual.finite_dimensional⟩
 
 
 
66
 
67
  open category_theory.monoidal_category
68
 
69
  /-- The coevaluation map is defined in `linear_algebra.coevaluation`. -/
70
  def FinVect_coevaluation : 𝟙_ (FinVect K) ⟶ V ⊗ (FinVect_dual K V) :=
71
+ by apply coevaluation K V.obj
72
 
73
  lemma FinVect_coevaluation_apply_one : FinVect_coevaluation K V (1 : K) =
74
+ ∑ (i : basis.of_vector_space_index K V.obj),
75
+ (basis.of_vector_space K V.obj) i ⊗ₜ[K] (basis.of_vector_space K V.obj).coord i :=
76
+ by apply coevaluation_apply_one K V.obj
77
 
78
  /-- The evaluation morphism is given by the contraction map. -/
79
  def FinVect_evaluation : (FinVect_dual K V) ⊗ V ⟶ 𝟙_ (FinVect K) :=
80
+ by apply contract_left K V.obj
81
 
82
  @[simp]
83
+ lemma FinVect_evaluation_apply (f : (FinVect_dual K V).obj) (x : V.obj) :
84
+ (FinVect_evaluation K V) (f ⊗ₜ x) = f.to_fun x :=
85
  by apply contract_left_apply f x
86
 
87
  private theorem coevaluation_evaluation :
88
  let V' : FinVect K := FinVect_dual K V in
89
  (𝟙 V' ⊗ (FinVect_coevaluation K V)) ≫ (α_ V' V V').inv ≫ (FinVect_evaluation K V ⊗ 𝟙 V')
90
  = (ρ_ V').hom ≫ (λ_ V').inv :=
91
+ by apply contract_left_assoc_coevaluation K V.obj
92
 
93
  private theorem evaluation_coevaluation :
94
  (FinVect_coevaluation K V ⊗ 𝟙 V)
95
  ≫ (α_ V (FinVect_dual K V) V).hom ≫ (𝟙 V ⊗ FinVect_evaluation K V)
96
  = (λ_ V).hom ≫ (ρ_ V).inv :=
97
+ by apply contract_left_assoc_coevaluation' K V.obj
98
 
99
  instance exact_pairing : exact_pairing V (FinVect_dual K V) :=
100
  { coevaluation := FinVect_coevaluation K V,
 
106
 
107
  instance right_rigid_category : right_rigid_category (FinVect K) := { }
108
 
109
+ variables {K V}
110
 
111
  /-- Converts and isomorphism in the category `FinVect` to a `linear_equiv` between the underlying
112
  vector spaces. -/
113
+ def iso_to_linear_equiv {V W : FinVect K} (i : V ≅ W) : V.obj ≃ₗ[K] W.obj :=
114
  ((forget₂ (FinVect.{u} K) (Module.{u} K)).map_iso i).to_linear_equiv
115
 
116
  lemma iso.conj_eq_conj {V W : FinVect K} (i : V ≅ W) (f : End V) :
formal/lean/mathlib/algebra/category/FinVect/limits.lean CHANGED
@@ -48,7 +48,7 @@ instance (F : J ⥤ FinVect k) :
48
  finite_dimensional k (limit (F ⋙ forget₂ (FinVect k) (Module.{v} k)) : Module.{v} k) :=
49
  begin
50
  haveI : ∀ j, finite_dimensional k ((F ⋙ forget₂ (FinVect k) (Module.{v} k)).obj j),
51
- { intro j, change finite_dimensional k (F.obj j), apply_instance, },
52
  exact finite_dimensional.of_injective
53
  (limit_subobject_product (F ⋙ forget₂ (FinVect k) (Module.{v} k)))
54
  ((Module.mono_iff_injective _).1 (by apply_instance)),
 
48
  finite_dimensional k (limit (F ⋙ forget₂ (FinVect k) (Module.{v} k)) : Module.{v} k) :=
49
  begin
50
  haveI : ∀ j, finite_dimensional k ((F ⋙ forget₂ (FinVect k) (Module.{v} k)).obj j),
51
+ { intro j, change finite_dimensional k (F.obj j).obj, apply_instance, },
52
  exact finite_dimensional.of_injective
53
  (limit_subobject_product (F ⋙ forget₂ (FinVect k) (Module.{v} k)))
54
  ((Module.mono_iff_injective _).1 (by apply_instance)),
formal/lean/mathlib/algebra/category/Group/epi_mono.lean CHANGED
@@ -3,7 +3,7 @@ Copyright (c) 2022 Jujian Zhang. All rights reserved.
3
  Released under Apache 2.0 license as described in the file LICENSE.
4
  Authors: Jujian Zhang
5
  -/
6
- import algebra.category.Group.basic
7
  import category_theory.epi_mono
8
  import group_theory.quotient_group
9
 
@@ -23,6 +23,7 @@ open quotient_group
23
 
24
  variables {A : Type u} {B : Type v}
25
 
 
26
  variables [group A] [group B]
27
 
28
  @[to_additive add_monoid_hom.ker_eq_bot_of_cancel]
@@ -30,6 +31,28 @@ lemma ker_eq_bot_of_cancel {f : A →* B} (h : ∀ (u v : f.ker →* A), f.comp
30
  f.ker = ⊥ :=
31
  by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by tidy))
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  end monoid_hom
34
 
35
  section
@@ -61,7 +84,7 @@ local notation `X` := set.range (function.swap left_coset f.range.carrier)
61
  /--
62
  Define `X'` to be the set of all left cosets with an extra point at "infinity".
63
  -/
64
- @[nolint has_inhabited_instance]
65
  inductive X_with_infinity
66
  | from_coset : set.range (function.swap left_coset f.range.carrier) → X_with_infinity
67
  | infinity : X_with_infinity
@@ -281,4 +304,58 @@ iff.trans (epi_iff_surjective _) (subgroup.eq_top_iff' f.range).symm
281
 
282
  end Group
283
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
284
  end
 
3
  Released under Apache 2.0 license as described in the file LICENSE.
4
  Authors: Jujian Zhang
5
  -/
6
+ import algebra.category.Group.equivalence_Group_AddGroup
7
  import category_theory.epi_mono
8
  import group_theory.quotient_group
9
 
 
23
 
24
  variables {A : Type u} {B : Type v}
25
 
26
+ section
27
  variables [group A] [group B]
28
 
29
  @[to_additive add_monoid_hom.ker_eq_bot_of_cancel]
 
31
  f.ker = ⊥ :=
32
  by simpa using _root_.congr_arg range (h f.ker.subtype 1 (by tidy))
33
 
34
+ end
35
+
36
+ section
37
+ variables [comm_group A] [comm_group B]
38
+
39
+ @[to_additive add_monoid_hom.range_eq_top_of_cancel]
40
+ lemma range_eq_top_of_cancel {f : A →* B}
41
+ (h : ∀ (u v : B →* B ⧸ f.range), u.comp f = v.comp f → u = v) :
42
+ f.range = ⊤ :=
43
+ begin
44
+ specialize h 1 (quotient_group.mk' _) _,
45
+ { ext1,
46
+ simp only [one_apply, coe_comp, coe_mk', function.comp_app],
47
+ rw [show (1 : B ⧸ f.range) = (1 : B), from quotient_group.coe_one _, quotient_group.eq,
48
+ inv_one, one_mul],
49
+ exact ⟨x, rfl⟩, },
50
+ replace h : (quotient_group.mk' _).ker = (1 : B →* B ⧸ f.range).ker := by rw h,
51
+ rwa [ker_one, quotient_group.ker_mk] at h,
52
+ end
53
+
54
+ end
55
+
56
  end monoid_hom
57
 
58
  section
 
84
  /--
85
  Define `X'` to be the set of all left cosets with an extra point at "infinity".
86
  -/
87
+ @[nolint has_nonempty_instance]
88
  inductive X_with_infinity
89
  | from_coset : set.range (function.swap left_coset f.range.carrier) → X_with_infinity
90
  | infinity : X_with_infinity
 
304
 
305
  end Group
306
 
307
+ namespace AddGroup
308
+ variables {A B : AddGroup.{u}} (f : A ⟶ B)
309
+
310
+ lemma epi_iff_surjective : epi f ↔ function.surjective f :=
311
+ begin
312
+ have i1 : epi f ↔ epi (Group_AddGroup_equivalence.inverse.map f),
313
+ { refine ⟨_, Group_AddGroup_equivalence.inverse.epi_of_epi_map⟩,
314
+ introsI e',
315
+ apply Group_AddGroup_equivalence.inverse.map_epi },
316
+ rwa Group.epi_iff_surjective at i1,
317
+ end
318
+
319
+ lemma epi_iff_range_eq_top : epi f ↔ f.range = ⊤ :=
320
+ iff.trans (epi_iff_surjective _) (add_subgroup.eq_top_iff' f.range).symm
321
+
322
+ end AddGroup
323
+
324
+ namespace CommGroup
325
+ variables {A B : CommGroup.{u}} (f : A ⟶ B)
326
+
327
+ @[to_additive AddCommGroup.ker_eq_bot_of_mono]
328
+ lemma ker_eq_bot_of_mono [mono f] : f.ker = ⊥ :=
329
+ monoid_hom.ker_eq_bot_of_cancel $ λ u v,
330
+ (@cancel_mono _ _ _ _ _ f _ (show CommGroup.of f.ker ⟶ A, from u) _).1
331
+
332
+ @[to_additive AddCommGroup.mono_iff_ker_eq_bot]
333
+ lemma mono_iff_ker_eq_bot : mono f ↔ f.ker = ⊥ :=
334
+ ⟨λ h, @@ker_eq_bot_of_mono f h,
335
+ λ h, concrete_category.mono_of_injective _ $ (monoid_hom.ker_eq_bot_iff f).1 h⟩
336
+
337
+ @[to_additive AddCommGroup.mono_iff_injective]
338
+ lemma mono_iff_injective : mono f ↔ function.injective f :=
339
+ iff.trans (mono_iff_ker_eq_bot f) $ monoid_hom.ker_eq_bot_iff f
340
+
341
+ @[to_additive]
342
+ lemma range_eq_top_of_epi [epi f] : f.range = ⊤ :=
343
+ monoid_hom.range_eq_top_of_cancel $ λ u v h,
344
+ (@cancel_epi _ _ _ _ _ f _ (show B ⟶ ⟨B ⧸ monoid_hom.range f⟩, from u) v).1 h
345
+
346
+ @[to_additive]
347
+ lemma epi_iff_range_eq_top : epi f ↔ f.range = ⊤ :=
348
+ ⟨λ hf, by exactI range_eq_top_of_epi _,
349
+ λ hf, concrete_category.epi_of_surjective _ $ monoid_hom.range_top_iff_surjective.mp hf⟩
350
+
351
+ @[to_additive]
352
+ lemma epi_iff_surjective : epi f ↔ function.surjective f :=
353
+ by rw [epi_iff_range_eq_top, monoid_hom.range_top_iff_surjective]
354
+
355
+ @[to_additive]
356
+ instance : functor.preserves_epimorphisms (forget₂ CommGroup Group) :=
357
+ { preserves := λ X Y f e, by rwa [epi_iff_surjective, ←@Group.epi_iff_surjective ⟨X⟩ ⟨Y⟩ f] at e }
358
+
359
+ end CommGroup
360
+
361
  end
formal/lean/mathlib/algebra/category/Group/equivalence_Group_AddGroup.lean ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /-
2
+ Copyright (c) 2022 Jujian Zhang. All rights reserved.
3
+ Released under Apache 2.0 license as described in the file LICENSE.
4
+ Authors: Jujian Zhang
5
+ -/
6
+ import algebra.category.Group.basic
7
+
8
+ /-!
9
+ # Equivalence between `Group` and `AddGroup`
10
+
11
+ This file contains two equivalences:
12
+ * `Group_AddGroup_equivalence` : the equivalence between `Group` and `AddGroup` by sending
13
+ `X : Group` to `additive X` and `Y : AddGroup` to `multiplicative Y`.
14
+ * `CommGroup_AddCommGroup_equivlance` : the equivalence between `CommGroup` and `AddCommGroup` by
15
+ sending `X : CommGroup` to `additive X` and `Y : AddCommGroup` to `multiplicative Y`.
16
+ -/
17
+
18
+ open category_theory
19
+
20
+ namespace Group
21
+
22
+ /--
23
+ The functor `Group ⥤ AddGroup` by sending `X ↦ additive X` and `f ↦ f`.
24
+ -/
25
+ @[simps] def to_AddGroup : Group ⥤ AddGroup :=
26
+ { obj := λ X, AddGroup.of (additive X),
27
+ map := λ X Y, monoid_hom.to_additive }
28
+
29
+ end Group
30
+
31
+ namespace CommGroup
32
+
33
+ /--
34
+ The functor `CommGroup ⥤ AddCommGroup` by sending `X ↦ additive X` and `f ↦ f`.
35
+ -/
36
+ @[simps] def to_AddCommGroup : CommGroup ⥤ AddCommGroup :=
37
+ { obj := λ X, AddCommGroup.of (additive X),
38
+ map := λ X Y, monoid_hom.to_additive }
39
+
40
+ end CommGroup
41
+
42
+ namespace AddGroup
43
+
44
+ /--
45
+ The functor `AddGroup ⥤ Group` by sending `X ↦ multiplicative Y` and `f ↦ f`.
46
+ -/
47
+ @[simps] def to_Group : AddGroup ⥤ Group :=
48
+ { obj := λ X, Group.of (multiplicative X),
49
+ map := λ X Y, add_monoid_hom.to_multiplicative }
50
+
51
+ end AddGroup
52
+
53
+ namespace AddCommGroup
54
+
55
+ /--
56
+ The functor `AddCommGroup ⥤ CommGroup` by sending `X ↦ multiplicative Y` and `f ↦ f`.
57
+ -/
58
+ @[simps] def to_CommGroup : AddCommGroup ⥤ CommGroup :=
59
+ { obj := λ X, CommGroup.of (multiplicative X),
60
+ map := λ X Y, add_monoid_hom.to_multiplicative }
61
+
62
+ end AddCommGroup
63
+
64
+ /--
65
+ The equivalence of categories between `Group` and `AddGroup`
66
+ -/
67
+ @[simps] def Group_AddGroup_equivalence : Group ≌ AddGroup :=
68
+ equivalence.mk Group.to_AddGroup AddGroup.to_Group
69
+ (nat_iso.of_components
70
+ (λ X, mul_equiv.to_Group_iso (mul_equiv.multiplicative_additive X))
71
+ (λ X Y f, rfl))
72
+ (nat_iso.of_components
73
+ (λ X, add_equiv.to_AddGroup_iso (add_equiv.additive_multiplicative X))
74
+ (λ X Y f, rfl))
75
+
76
+ /--
77
+ The equivalence of categories between `CommGroup` and `AddCommGroup`.
78
+ -/
79
+ @[simps] def CommGroup_AddCommGroup_equivalence : CommGroup ≌ AddCommGroup :=
80
+ equivalence.mk CommGroup.to_AddCommGroup AddCommGroup.to_CommGroup
81
+ (nat_iso.of_components
82
+ (λ X, mul_equiv.to_CommGroup_iso (mul_equiv.multiplicative_additive X))
83
+ (λ X Y f, rfl))
84
+ (nat_iso.of_components
85
+ (λ X, add_equiv.to_AddCommGroup_iso (add_equiv.additive_multiplicative X))
86
+ (λ X Y f, rfl))
formal/lean/mathlib/algebra/category/Module/adjunctions.lean CHANGED
@@ -156,7 +156,7 @@ universes v u
156
  we will equip with a category structure where the morphisms are formal `R`-linear combinations
157
  of the morphisms in `C`.
158
  -/
159
- @[nolint unused_arguments has_inhabited_instance]
160
  def Free (R : Type*) (C : Type u) := C
161
 
162
  /--
 
156
  we will equip with a category structure where the morphisms are formal `R`-linear combinations
157
  of the morphisms in `C`.
158
  -/
159
+ @[nolint unused_arguments has_nonempty_instance]
160
  def Free (R : Type*) (C : Type u) := C
161
 
162
  /--
formal/lean/mathlib/algebra/category/Module/change_of_rings.lean ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /-
2
+ Copyright (c) 2022 Jujian Zhang. All rights reserved.
3
+ Released under Apache 2.0 license as described in the file LICENSE.
4
+ Authors: Jujian Zhang
5
+ -/
6
+ import algebra.category.Module.basic
7
+
8
+ /-!
9
+ # Change Of Rings
10
+
11
+ ## Main definitions
12
+
13
+ * `category_theory.Module.restrict_scalars`: given rings `R, S` and a ring homomorphism `R ⟶ S`,
14
+ then `restrict_scalars : Module S ⥤ Module R` is defined by `M ↦ M` where `M : S-module` is seen
15
+ as `R-module` by `r • m := f r • m` and `S`-linear map `l : M ⟶ M'` is `R`-linear as well.
16
+ -/
17
+
18
+
19
+ namespace category_theory.Module
20
+
21
+ universes v u₁ u₂
22
+
23
+ namespace restrict_scalars
24
+
25
+ variables {R : Type u₁} {S : Type u₂} [ring R] [ring S] (f : R →+* S)
26
+ variable (M : Module.{v} S)
27
+
28
+ /-- Any `S`-module M is also an `R`-module via a ring homomorphism `f : R ⟶ S` by defining
29
+ `r • m := f r • m` (`module.comp_hom`). This is called restriction of scalars. -/
30
+ def obj' : Module R :=
31
+ { carrier := M,
32
+ is_module := module.comp_hom M f }
33
+
34
+ /--
35
+ Given an `S`-linear map `g : M → M'` between `S`-modules, `g` is also `R`-linear between `M` and
36
+ `M'` by means of restriction of scalars.
37
+ -/
38
+ def map' {M M' : Module.{v} S} (g : M ⟶ M') :
39
+ obj' f M ⟶ obj' f M' :=
40
+ { map_smul' := λ r, g.map_smul (f r), ..g }
41
+
42
+ end restrict_scalars
43
+
44
+ /--
45
+ The restriction of scalars operation is functorial. For any `f : R →+* S` a ring homomorphism,
46
+ * an `S`-module `M` can be considered as `R`-module by `r • m = f r • m`
47
+ * an `S`-linear map is also `R`-linear
48
+ -/
49
+ def restrict_scalars {R : Type u₁} {S : Type u₂} [ring R] [ring S] (f : R →+* S) :
50
+ Module.{v} S ⥤ Module.{v} R :=
51
+ { obj := restrict_scalars.obj' f,
52
+ map := λ _ _, restrict_scalars.map' f,
53
+ map_id' := λ _, linear_map.ext $ λ m, rfl,
54
+ map_comp' := λ _ _ _ g h, linear_map.ext $ λ m, rfl }
55
+
56
+ @[simp] lemma restrict_scalars.map_apply {R : Type u₁} {S : Type u₂} [ring R] [ring S] (f : R →+* S)
57
+ {M M' : Module.{v} S} (g : M ⟶ M') (x) : (restrict_scalars f).map g x = g x := rfl
58
+
59
+ @[simp] lemma restrict_scalars.smul_def {R : Type u₁} {S : Type u₂} [ring R] [ring S] (f : R →+* S)
60
+ {M : Module.{v} S} (r : R) (m : (restrict_scalars f).obj M) : r • m = (f r • m : M) := rfl
61
+
62
+ @[simp] lemma restrict_scalars.smul_def' {R : Type u₁} {S : Type u₂} [ring R] [ring S] (f : R →+* S)
63
+ {M : Module.{v} S} (r : R) (m : M) : (r • m : (restrict_scalars f).obj M) = (f r • m : M) := rfl
64
+
65
+ end category_theory.Module
formal/lean/mathlib/algebra/char_p/algebra.lean CHANGED
@@ -65,6 +65,9 @@ variables (K L : Type*) [field K] [comm_semiring L] [nontrivial L] [algebra K L]
65
  lemma algebra.char_p_iff (p : ℕ) : char_p K p ↔ char_p L p :=
66
  (algebra_map K L).char_p_iff_char_p p
67
 
 
 
 
68
  end
69
 
70
  namespace free_algebra
 
65
  lemma algebra.char_p_iff (p : ℕ) : char_p K p ↔ char_p L p :=
66
  (algebra_map K L).char_p_iff_char_p p
67
 
68
+ lemma algebra.ring_char_eq : ring_char K = ring_char L :=
69
+ by { rw [ring_char.eq_iff, algebra.char_p_iff K L], apply ring_char.char_p }
70
+
71
  end
72
 
73
  namespace free_algebra
formal/lean/mathlib/algebra/char_p/basic.lean CHANGED
@@ -349,13 +349,16 @@ calc (k : R) = ↑(k % p + p * (k / p)) : by rw [nat.mod_add_div]
349
  ... = ↑(k % p) : by simp [cast_eq_zero]
350
 
351
  /-- The characteristic of a finite ring cannot be zero. -/
352
- theorem char_ne_zero_of_fintype (p : ℕ) [hc : char_p R p] [fintype R] : p ≠ 0 :=
353
- assume h : p = 0,
354
- have char_zero R := @char_p_to_char_zero R _ (h ▸ hc),
355
- absurd (@nat.cast_injective R _ this) (not_injective_infinite_fintype coe)
 
 
 
356
 
357
- lemma ring_char_ne_zero_of_fintype [fintype R] : ring_char R ≠ 0 :=
358
- char_ne_zero_of_fintype R (ring_char R)
359
 
360
  end
361
 
@@ -432,11 +435,11 @@ end semiring
432
 
433
  section ring
434
 
435
- variables (R) [ring R] [no_zero_divisors R] [nontrivial R] [fintype R]
436
 
437
  theorem char_is_prime (p : ℕ) [char_p R p] :
438
  p.prime :=
439
- or.resolve_right (char_is_prime_or_zero R p) (char_ne_zero_of_fintype R p)
440
 
441
  end ring
442
 
 
349
  ... = ↑(k % p) : by simp [cast_eq_zero]
350
 
351
  /-- The characteristic of a finite ring cannot be zero. -/
352
+ theorem char_ne_zero_of_finite (p : ℕ) [char_p R p] [finite R] : p ≠ 0 :=
353
+ begin
354
+ unfreezingI { rintro rfl },
355
+ haveI : char_zero R := char_p_to_char_zero R,
356
+ casesI nonempty_fintype R,
357
+ exact absurd nat.cast_injective (not_injective_infinite_fintype (coe : ℕ → R))
358
+ end
359
 
360
+ lemma ring_char_ne_zero_of_finite [finite R] : ring_char R ≠ 0 :=
361
+ char_ne_zero_of_finite R (ring_char R)
362
 
363
  end
364
 
 
435
 
436
  section ring
437
 
438
+ variables (R) [ring R] [no_zero_divisors R] [nontrivial R] [finite R]
439
 
440
  theorem char_is_prime (p : ℕ) [char_p R p] :
441
  p.prime :=
442
+ or.resolve_right (char_is_prime_or_zero R p) (char_ne_zero_of_finite R p)
443
 
444
  end ring
445
 
formal/lean/mathlib/algebra/char_p/char_and_card.lean CHANGED
@@ -15,12 +15,14 @@ We prove some results relating characteristic and cardinality of finite rings
15
  characterstic, cardinality, ring
16
  -/
17
 
18
- /-- A prime `p` is a unit in a finite commutative ring `R`
19
- iff it does not divide the characteristic. -/
20
- lemma is_unit_iff_not_dvd_char (R : Type*) [comm_ring R] [fintype R] (p : ℕ) [fact p.prime] :
 
21
  is_unit (p : R) ↔ ¬ p ∣ ring_char R :=
22
  begin
23
  have hch := char_p.cast_eq_zero R (ring_char R),
 
24
  split,
25
  { rintros h₁ ⟨q, hq⟩,
26
  rcases is_unit.exists_left_inv h₁ with ⟨a, ha⟩,
@@ -29,8 +31,7 @@ begin
29
  rintro ⟨r, hr⟩,
30
  rw [hr, ← mul_assoc, mul_comm p, mul_assoc] at hq,
31
  nth_rewrite 0 ← mul_one (ring_char R) at hq,
32
- exact nat.prime.not_dvd_one (fact.out p.prime)
33
- ⟨r, mul_left_cancel₀ (char_p.char_ne_zero_of_fintype R (ring_char R)) hq⟩,
34
  end,
35
  have h₄ := mt (char_p.int_cast_eq_zero_iff R (ring_char R) q).mp,
36
  apply_fun (coe : ℕ → R) at hq,
@@ -39,14 +40,19 @@ begin
39
  norm_cast at h₄,
40
  exact h₄ h₃ hq.symm, },
41
  { intro h,
42
- rcases nat.is_coprime_iff_coprime.mpr ((nat.prime.coprime_iff_not_dvd (fact.out _)).mpr h)
43
- with ⟨a, b, hab⟩,
44
  apply_fun (coe : ℤ → R) at hab,
45
  push_cast at hab,
46
  rw [hch, mul_zero, add_zero, mul_comm] at hab,
47
  exact is_unit_of_mul_eq_one (p : R) a hab, },
48
  end
49
 
 
 
 
 
 
 
50
  /-- The prime divisors of the characteristic of a finite commutative ring are exactly
51
  the prime divisors of its cardinality. -/
52
  lemma prime_dvd_char_iff_dvd_card {R : Type*} [comm_ring R] [fintype R] (p : ℕ) [fact p.prime] :
 
15
  characterstic, cardinality, ring
16
  -/
17
 
18
+ /-- A prime `p` is a unit in a commutative ring `R` of nonzero characterstic iff it does not divide
19
+ the characteristic. -/
20
+ lemma is_unit_iff_not_dvd_char_of_ring_char_ne_zero (R : Type*) [comm_ring R] (p : ℕ) [fact p.prime]
21
+ (hR : ring_char R ≠ 0) :
22
  is_unit (p : R) ↔ ¬ p ∣ ring_char R :=
23
  begin
24
  have hch := char_p.cast_eq_zero R (ring_char R),
25
+ have hp : p.prime := fact.out p.prime,
26
  split,
27
  { rintros h₁ ⟨q, hq⟩,
28
  rcases is_unit.exists_left_inv h₁ with ⟨a, ha⟩,
 
31
  rintro ⟨r, hr⟩,
32
  rw [hr, ← mul_assoc, mul_comm p, mul_assoc] at hq,
33
  nth_rewrite 0 ← mul_one (ring_char R) at hq,
34
+ exact nat.prime.not_dvd_one hp ⟨r, mul_left_cancel₀ hR hq⟩,
 
35
  end,
36
  have h₄ := mt (char_p.int_cast_eq_zero_iff R (ring_char R) q).mp,
37
  apply_fun (coe : ℕ → R) at hq,
 
40
  norm_cast at h₄,
41
  exact h₄ h₃ hq.symm, },
42
  { intro h,
43
+ rcases (hp.coprime_iff_not_dvd.mpr h).is_coprime with ⟨a, b, hab⟩,
 
44
  apply_fun (coe : ℤ → R) at hab,
45
  push_cast at hab,
46
  rw [hch, mul_zero, add_zero, mul_comm] at hab,
47
  exact is_unit_of_mul_eq_one (p : R) a hab, },
48
  end
49
 
50
+ /-- A prime `p` is a unit in a finite commutative ring `R`
51
+ iff it does not divide the characteristic. -/
52
+ lemma is_unit_iff_not_dvd_char (R : Type*) [comm_ring R] (p : ℕ) [fact p.prime] [finite R] :
53
+ is_unit (p : R) ↔ ¬ p ∣ ring_char R :=
54
+ is_unit_iff_not_dvd_char_of_ring_char_ne_zero R p $ char_p.char_ne_zero_of_finite R (ring_char R)
55
+
56
  /-- The prime divisors of the characteristic of a finite commutative ring are exactly
57
  the prime divisors of its cardinality. -/
58
  lemma prime_dvd_char_iff_dvd_card {R : Type*} [comm_ring R] [fintype R] (p : ℕ) [fact p.prime] :
formal/lean/mathlib/algebra/direct_sum/internal.lean CHANGED
@@ -152,8 +152,7 @@ lemma direct_sum.coe_mul_apply [add_monoid ι] [semiring R] [set_like σ R]
152
  [add_submonoid_class σ R] (A : ι → σ) [set_like.graded_monoid A]
153
  [Π (i : ι) (x : A i), decidable (x ≠ 0)] (r r' : ⨁ i, A i) (i : ι) :
154
  ((r * r') i : R) =
155
- ∑ ij in finset.filter (λ ij : ι × ι, ij.1 + ij.2 = i) (r.support.product r'.support),
156
- r ij.1 * r' ij.2 :=
157
  begin
158
  rw [direct_sum.mul_eq_sum_support_ghas_mul, dfinsupp.finset_sum_apply,
159
  add_submonoid_class.coe_finset_sum],
 
152
  [add_submonoid_class σ R] (A : ι → σ) [set_like.graded_monoid A]
153
  [Π (i : ι) (x : A i), decidable (x ≠ 0)] (r r' : ⨁ i, A i) (i : ι) :
154
  ((r * r') i : R) =
155
+ ∑ ij in (r.support ×ˢ r'.support).filter (λ ij : ι × ι, ij.1 + ij.2 = i), r ij.1 * r' ij.2 :=
 
156
  begin
157
  rw [direct_sum.mul_eq_sum_support_ghas_mul, dfinsupp.finset_sum_apply,
158
  add_submonoid_class.coe_finset_sum],
formal/lean/mathlib/algebra/direct_sum/ring.lean CHANGED
@@ -269,7 +269,7 @@ open_locale big_operators
269
  lemma mul_eq_sum_support_ghas_mul
270
  [Π (i : ι) (x : A i), decidable (x ≠ 0)] (a a' : ⨁ i, A i) :
271
  a * a' =
272
- (ij : ι × ι) in (dfinsupp.support a).product (dfinsupp.support a'),
273
  direct_sum.of _ _ (graded_monoid.ghas_mul.mul (a ij.fst) (a' ij.snd)) :=
274
  begin
275
  change direct_sum.mul_hom _ a a' = _,
 
269
  lemma mul_eq_sum_support_ghas_mul
270
  [Π (i : ι) (x : A i), decidable (x ≠ 0)] (a a' : ⨁ i, A i) :
271
  a * a' =
272
+ ∑ ij in dfinsupp.support a ×ˢ dfinsupp.support a',
273
  direct_sum.of _ _ (graded_monoid.ghas_mul.mul (a ij.fst) (a' ij.snd)) :=
274
  begin
275
  change direct_sum.mul_hom _ a a' = _,
formal/lean/mathlib/algebra/field/basic.lean CHANGED
@@ -144,36 +144,8 @@ by rwa [add_comm, add_div', add_comm]
144
 
145
  end division_semiring
146
 
147
- section division_ring
148
- variables [division_ring K] {a b : K}
149
-
150
- namespace rat
151
-
152
- /-- Construct the canonical injection from `ℚ` into an arbitrary
153
- division ring. If the field has positive characteristic `p`,
154
- we define `1 / p = 1 / 0 = 0` for consistency with our
155
- division by zero convention. -/
156
- -- see Note [coercion into rings]
157
- @[priority 900] instance cast_coe {K : Type*} [has_rat_cast K] : has_coe_t ℚ K :=
158
- ⟨has_rat_cast.rat_cast⟩
159
-
160
- theorem cast_mk' (a b h1 h2) : ((⟨a, b, h1, h2⟩ : ℚ) : K) = a * b⁻¹ :=
161
- division_ring.rat_cast_mk _ _ _ _
162
-
163
- theorem cast_def : ∀ (r : ℚ), (r : K) = r.num / r.denom
164
- | ⟨a, b, h1, h2⟩ := (cast_mk' _ _ _ _).trans (div_eq_mul_inv _ _).symm
165
-
166
- @[priority 100]
167
- instance smul_division_ring : has_smul ℚ K :=
168
- ⟨division_ring.qsmul⟩
169
-
170
- lemma smul_def (a : ℚ) (x : K) : a • x = ↑a * x := division_ring.qsmul_eq_mul' a x
171
-
172
- end rat
173
-
174
- local attribute [simp]
175
- division_def mul_comm mul_assoc
176
- mul_left_comm mul_inv_cancel inv_mul_cancel
177
 
178
  lemma one_div_neg_one_eq_neg_one : (1:K) / (-1) = -1 :=
179
  have (-1) * (-1) = (1:K), by rw [neg_mul_neg, one_mul],
@@ -202,6 +174,44 @@ by simp [neg_div]
202
  lemma neg_div_neg_eq (a b : K) : (-a) / (-b) = a / b :=
203
  by rw [div_neg_eq_neg_div, neg_div, neg_neg]
204
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
205
  @[simp] lemma div_neg_self {a : K} (h : a ≠ 0) : a / -a = -1 :=
206
  by rw [div_neg_eq_neg_div, div_self h]
207
 
@@ -221,18 +231,9 @@ by simpa only [← @div_self _ _ b h] using (div_sub_div_same a b b).symm
221
 
222
  lemma div_sub_one {a b : K} (h : b ≠ 0) : a / b - 1 = (a - b) / b := (div_sub_same h).symm
223
 
224
- lemma neg_inv : - a⁻¹ = (- a)⁻¹ :=
225
- by rw [inv_eq_one_div, inv_eq_one_div, div_neg_eq_neg_div]
226
-
227
  lemma sub_div (a b c : K) : (a - b) / c = a / c - b / c :=
228
  (div_sub_div_same _ _ _).symm
229
 
230
- lemma div_neg (a : K) : a / -b = -(a / b) :=
231
- by rw [← div_neg_eq_neg_div]
232
-
233
- lemma inv_neg : (-a)⁻¹ = -(a⁻¹) :=
234
- by rw neg_inv
235
-
236
  lemma one_div_mul_sub_mul_one_div_eq_one_div_add_one_div (ha : a ≠ 0) (hb : b ≠ 0) :
237
  (1 / a) * (b - a) * (1 / b) = 1 / a - 1 / b :=
238
  by rw [(mul_sub_left_distrib (1 / a)), (one_div_mul_cancel ha), mul_sub_right_distrib,
 
144
 
145
  end division_semiring
146
 
147
+ section division_monoid
148
+ variables [division_monoid K] [has_distrib_neg K] {a b : K}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
 
150
  lemma one_div_neg_one_eq_neg_one : (1:K) / (-1) = -1 :=
151
  have (-1) * (-1) = (1:K), by rw [neg_mul_neg, one_mul],
 
174
  lemma neg_div_neg_eq (a b : K) : (-a) / (-b) = a / b :=
175
  by rw [div_neg_eq_neg_div, neg_div, neg_neg]
176
 
177
+ lemma neg_inv : - a⁻¹ = (- a)⁻¹ :=
178
+ by rw [inv_eq_one_div, inv_eq_one_div, div_neg_eq_neg_div]
179
+
180
+ lemma div_neg (a : K) : a / -b = -(a / b) :=
181
+ by rw [← div_neg_eq_neg_div]
182
+
183
+ lemma inv_neg : (-a)⁻¹ = -(a⁻¹) :=
184
+ by rw neg_inv
185
+
186
+ end division_monoid
187
+
188
+ section division_ring
189
+ variables [division_ring K] {a b : K}
190
+
191
+ namespace rat
192
+
193
+ /-- Construct the canonical injection from `ℚ` into an arbitrary
194
+ division ring. If the field has positive characteristic `p`,
195
+ we define `1 / p = 1 / 0 = 0` for consistency with our
196
+ division by zero convention. -/
197
+ -- see Note [coercion into rings]
198
+ @[priority 900] instance cast_coe {K : Type*} [has_rat_cast K] : has_coe_t ℚ K :=
199
+ ⟨has_rat_cast.rat_cast⟩
200
+
201
+ theorem cast_mk' (a b h1 h2) : ((⟨a, b, h1, h2⟩ : ℚ) : K) = a * b⁻¹ :=
202
+ division_ring.rat_cast_mk _ _ _ _
203
+
204
+ theorem cast_def : ∀ (r : ℚ), (r : K) = r.num / r.denom
205
+ | ⟨a, b, h1, h2⟩ := (cast_mk' _ _ _ _).trans (div_eq_mul_inv _ _).symm
206
+
207
+ @[priority 100]
208
+ instance smul_division_ring : has_smul ℚ K :=
209
+ ⟨division_ring.qsmul⟩
210
+
211
+ lemma smul_def (a : ℚ) (x : K) : a • x = ↑a * x := division_ring.qsmul_eq_mul' a x
212
+
213
+ end rat
214
+
215
  @[simp] lemma div_neg_self {a : K} (h : a ≠ 0) : a / -a = -1 :=
216
  by rw [div_neg_eq_neg_div, div_self h]
217
 
 
231
 
232
  lemma div_sub_one {a b : K} (h : b ≠ 0) : a / b - 1 = (a - b) / b := (div_sub_same h).symm
233
 
 
 
 
234
  lemma sub_div (a b c : K) : (a - b) / c = a / c - b / c :=
235
  (div_sub_div_same _ _ _).symm
236
 
 
 
 
 
 
 
237
  lemma one_div_mul_sub_mul_one_div_eq_one_div_add_one_div (ha : a ≠ 0) (hb : b ≠ 0) :
238
  (1 / a) * (b - a) * (1 / b) = 1 / a - 1 / b :=
239
  by rw [(mul_sub_left_distrib (1 / a)), (one_div_mul_cancel ha), mul_sub_right_distrib,
formal/lean/mathlib/algebra/field_power.lean CHANGED
@@ -48,19 +48,11 @@ lemma zpow_pos_of_pos (ha : 0 < a) : ∀ (z : ℤ), 0 < a ^ z
48
 
49
  lemma zpow_le_of_le (ha : 1 ≤ a) (h : m ≤ n) : a ^ m ≤ a ^ n :=
50
  begin
51
- induction m with m m; induction n with n n,
52
- { simp only [of_nat_eq_coe, zpow_coe_nat],
53
- exact pow_le_pow ha (le_of_coe_nat_le_coe_nat h) },
54
- { cases h.not_lt ((neg_succ_lt_zero _).trans_le $ of_nat_nonneg _) },
55
- { simp only [zpow_neg_succ_of_nat, one_div, of_nat_eq_coe, zpow_coe_nat],
56
- apply le_trans (inv_le_one _); apply one_le_pow_of_one_le ha },
57
- { simp only [zpow_neg_succ_of_nat],
58
- apply (inv_le_inv _ _).2,
59
- { apply pow_le_pow ha,
60
- have : -(↑(m+1) : ℤ) ≤ -(↑(n+1) : ℤ), from h,
61
- have h' := le_of_neg_le_neg this,
62
- apply le_of_coe_nat_le_coe_nat h' },
63
- repeat { apply pow_pos (zero_lt_one.trans_le ha) } }
64
  end
65
 
66
  lemma pow_le_max_of_min_le (hx : 1 ≤ x) {a b c : ℤ} (h : min a b ≤ c) :
@@ -159,17 +151,7 @@ lemma zpow_two_pos_of_ne_zero (h : a ≠ 0) : 0 < a ^ (2 : ℤ) := zpow_bit0_pos
159
  le_iff_le_iff_lt_iff_lt.2 zpow_bit1_neg_iff
160
 
161
  @[simp] theorem zpow_bit1_nonpos_iff : a ^ bit1 n ≤ 0 ↔ a ≤ 0 :=
162
- begin
163
- rw [le_iff_lt_or_eq, zpow_bit1_neg_iff],
164
- split,
165
- { rintro (h | h),
166
- { exact h.le },
167
- { exact (zpow_eq_zero h).le } },
168
- { intro h,
169
- rcases eq_or_lt_of_le h with rfl|h,
170
- { exact or.inr (zero_zpow _ (bit1_ne_zero n)) },
171
- { exact or.inl h } }
172
- end
173
 
174
  @[simp] theorem zpow_bit1_pos_iff : 0 < a ^ bit1 n ↔ 0 < a :=
175
  lt_iff_lt_of_le_iff_le zpow_bit1_nonpos_iff
 
48
 
49
  lemma zpow_le_of_le (ha : 1 ≤ a) (h : m ≤ n) : a ^ m ≤ a ^ n :=
50
  begin
51
+ have ha₀ : 0 < a, from one_pos.trans_le ha,
52
+ lift n - m to ℕ using sub_nonneg.2 h with k hk,
53
+ calc a ^ m = a ^ m * 1 : (mul_one _).symm
54
+ ... a ^ m * a ^ k : mul_le_mul_of_nonneg_left (one_le_pow_of_one_le ha _) (zpow_nonneg ha₀.le _)
55
+ ... = a ^ n : by rw [← zpow_coe_nat, ← zpow_add₀ ha₀.ne', hk, add_sub_cancel'_right]
 
 
 
 
 
 
 
 
56
  end
57
 
58
  lemma pow_le_max_of_min_le (hx : 1 ≤ x) {a b c : ℤ} (h : min a b ≤ c) :
 
151
  le_iff_le_iff_lt_iff_lt.2 zpow_bit1_neg_iff
152
 
153
  @[simp] theorem zpow_bit1_nonpos_iff : a ^ bit1 n ≤ 0 ↔ a ≤ 0 :=
154
+ by rw [le_iff_lt_or_eq, le_iff_lt_or_eq, zpow_bit1_neg_iff, zpow_eq_zero_iff (bit1_ne_zero n)]
 
 
 
 
 
 
 
 
 
 
155
 
156
  @[simp] theorem zpow_bit1_pos_iff : 0 < a ^ bit1 n ↔ 0 < a :=
157
  lt_iff_lt_of_le_iff_le zpow_bit1_nonpos_iff
formal/lean/mathlib/algebra/group/prod.lean CHANGED
@@ -495,7 +495,7 @@ open mul_opposite
495
  /-- Canonical homomorphism of monoids from `αˣ` into `α × αᵐᵒᵖ`.
496
  Used mainly to define the natural topology of `αˣ`. -/
497
  @[to_additive "Canonical homomorphism of additive monoids from `add_units α` into `α × αᵃᵒᵖ`.
498
- Used mainly to define the natural topology of `add_units α`."]
499
  def embed_product (α : Type*) [monoid α] : αˣ →* α × αᵐᵒᵖ :=
500
  { to_fun := λ x, ⟨x, op ↑x⁻¹⟩,
501
  map_one' := by simp only [inv_one, eq_self_iff_true, units.coe_one, op_one, prod.mk_eq_one,
 
495
  /-- Canonical homomorphism of monoids from `αˣ` into `α × αᵐᵒᵖ`.
496
  Used mainly to define the natural topology of `αˣ`. -/
497
  @[to_additive "Canonical homomorphism of additive monoids from `add_units α` into `α × αᵃᵒᵖ`.
498
+ Used mainly to define the natural topology of `add_units α`.", simps]
499
  def embed_product (α : Type*) [monoid α] : αˣ →* α × αᵐᵒᵖ :=
500
  { to_fun := λ x, ⟨x, op ↑x⁻¹⟩,
501
  map_one' := by simp only [inv_one, eq_self_iff_true, units.coe_one, op_one, prod.mk_eq_one,
formal/lean/mathlib/algebra/group/to_additive.lean CHANGED
@@ -219,6 +219,8 @@ meta def tr : bool → list string → list string
219
  | is_comm ("npow" :: s) := add_comm_prefix is_comm "nsmul" :: tr ff s
220
  | is_comm ("zpow" :: s) := add_comm_prefix is_comm "zsmul" :: tr ff s
221
  | is_comm ("is" :: "square" :: s) := add_comm_prefix is_comm "even" :: tr ff s
 
 
222
  | is_comm ("is" :: "regular" :: s) := add_comm_prefix is_comm "is_add_regular" :: tr ff s
223
  | is_comm ("is" :: "left" :: "regular" :: s) :=
224
  add_comm_prefix is_comm "is_add_left_regular" :: tr ff s
 
219
  | is_comm ("npow" :: s) := add_comm_prefix is_comm "nsmul" :: tr ff s
220
  | is_comm ("zpow" :: s) := add_comm_prefix is_comm "zsmul" :: tr ff s
221
  | is_comm ("is" :: "square" :: s) := add_comm_prefix is_comm "even" :: tr ff s
222
+ | is_comm ("is" :: "scalar" :: "tower" :: s) :=
223
+ add_comm_prefix is_comm "vadd_assoc_class" :: tr ff s
224
  | is_comm ("is" :: "regular" :: s) := add_comm_prefix is_comm "is_add_regular" :: tr ff s
225
  | is_comm ("is" :: "left" :: "regular" :: s) :=
226
  add_comm_prefix is_comm "is_add_left_regular" :: tr ff s
formal/lean/mathlib/algebra/group/units.lean CHANGED
@@ -1,7 +1,7 @@
1
  /-
2
  Copyright (c) 2017 Kenny Lau. All rights reserved.
3
  Released under Apache 2.0 license as described in the file LICENSE.
4
- Authors: Kenny Lau, Mario Carneiro, Johannes Hölzl, Chris Hughes, Jens Wagemaker
5
  -/
6
  import algebra.group.basic
7
  import logic.nontrivial
@@ -250,6 +250,10 @@ infix ` /ₚ `:70 := divp
250
  theorem divp_assoc (a b : α) (u : αˣ) : a * b /ₚ u = a * (b /ₚ u) :=
251
  mul_assoc _ _ _
252
 
 
 
 
 
253
  @[simp] theorem divp_inv (u : αˣ) : a /ₚ u⁻¹ = a * u := rfl
254
 
255
  @[simp] theorem divp_mul_cancel (a : α) (u : αˣ) : a /ₚ u * u = a :=
@@ -261,31 +265,60 @@ mul_assoc _ _ _
261
  @[simp] theorem divp_left_inj (u : αˣ) {a b : α} : a /ₚ u = b /ₚ u ↔ a = b :=
262
  units.mul_left_inj _
263
 
264
- theorem divp_divp_eq_divp_mul (x : α) (u₁ u₂ : αˣ) : (x /ₚ u₁) /ₚ u₂ = x /ₚ (u₂ * u₁) :=
 
265
  by simp only [divp, mul_inv_rev, units.coe_mul, mul_assoc]
266
 
267
- theorem divp_eq_iff_mul_eq {x : α} {u : αˣ} {y : α} : x /ₚ u = y ↔ y * u = x :=
268
  u.mul_left_inj.symm.trans $ by rw [divp_mul_cancel]; exact ⟨eq.symm, eq.symm⟩
269
 
 
 
 
270
  theorem divp_eq_one_iff_eq {a : α} {u : αˣ} : a /ₚ u = 1 ↔ a = u :=
271
  (units.mul_left_inj u).symm.trans $ by rw [divp_mul_cancel, one_mul]
272
 
273
  @[simp] theorem one_divp (u : αˣ) : 1 /ₚ u = ↑u⁻¹ :=
274
  one_mul _
275
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
276
  end monoid
277
 
278
  section comm_monoid
279
 
280
  variables [comm_monoid α]
281
 
282
- theorem divp_eq_divp_iff {x y : α} {ux uy : αˣ} :
 
 
 
 
283
  x /ₚ ux = y /ₚ uy ↔ x * uy = y * ux :=
284
- by rw [divp_eq_iff_mul_eq, mul_comm, ← divp_assoc, divp_eq_iff_mul_eq, mul_comm y ux]
285
 
286
- theorem divp_mul_divp (x y : α) (ux uy : αˣ) :
 
287
  (x /ₚ ux) * (y /ₚ uy) = (x * y) /ₚ (ux * uy) :=
288
- by rw [← divp_divp_eq_divp_mul, divp_assoc, mul_comm x, divp_assoc, mul_comm]
289
 
290
  end comm_monoid
291
 
 
1
  /-
2
  Copyright (c) 2017 Kenny Lau. All rights reserved.
3
  Released under Apache 2.0 license as described in the file LICENSE.
4
+ Authors: Kenny Lau, Mario Carneiro, Johannes Hölzl, Chris Hughes, Jens Wagemaker, Jon Eugster
5
  -/
6
  import algebra.group.basic
7
  import logic.nontrivial
 
250
  theorem divp_assoc (a b : α) (u : αˣ) : a * b /ₚ u = a * (b /ₚ u) :=
251
  mul_assoc _ _ _
252
 
253
+ /-- `field_simp` needs the reverse direction of `divp_assoc` to move all `/ₚ` to the right. -/
254
+ @[field_simps] lemma divp_assoc' (x y : α) (u : αˣ) : x * (y /ₚ u) = (x * y) /ₚ u :=
255
+ (divp_assoc _ _ _).symm
256
+
257
  @[simp] theorem divp_inv (u : αˣ) : a /ₚ u⁻¹ = a * u := rfl
258
 
259
  @[simp] theorem divp_mul_cancel (a : α) (u : αˣ) : a /ₚ u * u = a :=
 
265
  @[simp] theorem divp_left_inj (u : αˣ) {a b : α} : a /ₚ u = b /ₚ u ↔ a = b :=
266
  units.mul_left_inj _
267
 
268
+ @[field_simps] theorem divp_divp_eq_divp_mul (x : α) (u₁ u₂ : αˣ) :
269
+ (x /ₚ u₁) /ₚ u₂ = x /ₚ (u₂ * u₁) :=
270
  by simp only [divp, mul_inv_rev, units.coe_mul, mul_assoc]
271
 
272
+ @[field_simps] theorem divp_eq_iff_mul_eq {x : α} {u : αˣ} {y : α} : x /ₚ u = y ↔ y * u = x :=
273
  u.mul_left_inj.symm.trans $ by rw [divp_mul_cancel]; exact ⟨eq.symm, eq.symm⟩
274
 
275
+ @[field_simps] theorem eq_divp_iff_mul_eq {x : α} {u : αˣ} {y : α} : x = y /ₚ u ↔ x * u = y :=
276
+ by rw [eq_comm, divp_eq_iff_mul_eq]
277
+
278
  theorem divp_eq_one_iff_eq {a : α} {u : αˣ} : a /ₚ u = 1 ↔ a = u :=
279
  (units.mul_left_inj u).symm.trans $ by rw [divp_mul_cancel, one_mul]
280
 
281
  @[simp] theorem one_divp (u : αˣ) : 1 /ₚ u = ↑u⁻¹ :=
282
  one_mul _
283
 
284
+ /-- Used for `field_simp` to deal with inverses of units. -/
285
+ @[field_simps] lemma inv_eq_one_divp (u : αˣ) : ↑u⁻¹ = 1 /ₚ u :=
286
+ by rw one_divp
287
+
288
+ /--
289
+ Used for `field_simp` to deal with inverses of units. This form of the lemma
290
+ is essential since `field_simp` likes to use `inv_eq_one_div` to rewrite
291
+ `↑u⁻¹ = ↑(1 / u)`.
292
+ -/
293
+ @[field_simps] lemma inv_eq_one_divp' (u : αˣ) :
294
+ ((1 / u : αˣ) : α) = 1 /ₚ u :=
295
+ by rw [one_div, one_divp]
296
+
297
+ /--
298
+ `field_simp` moves division inside `αˣ` to the right, and this lemma
299
+ lifts the calculation to `α`.
300
+ -/
301
+ @[field_simps] lemma coe_div_eq_divp (u₁ u₂ : αˣ) : ↑(u₁ / u₂) = ↑u₁ /ₚ u₂ :=
302
+ by rw [divp, division_def, units.coe_mul]
303
+
304
  end monoid
305
 
306
  section comm_monoid
307
 
308
  variables [comm_monoid α]
309
 
310
+ @[field_simps] theorem divp_mul_eq_mul_divp (x y : α) (u : αˣ) : x /ₚ u * y = x * y /ₚ u :=
311
+ by simp_rw [divp, mul_assoc, mul_comm]
312
+
313
+ -- Theoretically redundant as `field_simp` lemma.
314
+ @[field_simps] lemma divp_eq_divp_iff {x y : α} {ux uy : αˣ} :
315
  x /ₚ ux = y /ₚ uy ↔ x * uy = y * ux :=
316
+ by rw [divp_eq_iff_mul_eq, divp_mul_eq_mul_divp, divp_eq_iff_mul_eq]
317
 
318
+ -- Theoretically redundant as `field_simp` lemma.
319
+ @[field_simps] lemma divp_mul_divp (x y : α) (ux uy : αˣ) :
320
  (x /ₚ ux) * (y /ₚ uy) = (x * y) /ₚ (ux * uy) :=
321
+ by rw [divp_mul_eq_mul_divp, divp_assoc', divp_divp_eq_divp_mul]
322
 
323
  end comm_monoid
324
 
formal/lean/mathlib/algebra/group_with_zero/power.lean CHANGED
@@ -134,13 +134,9 @@ by rw [zpow_bit1₀, (commute.refl a).mul_zpow]
134
  lemma zpow_eq_zero {x : G₀} {n : ℤ} (h : x ^ n = 0) : x = 0 :=
135
  classical.by_contradiction $ λ hx, zpow_ne_zero_of_ne_zero hx n h
136
 
137
- lemma zpow_eq_zero_iff {a : G₀} {n : ℤ} (hn : 0 < n) :
138
  a ^ n = 0 ↔ a = 0 :=
139
- begin
140
- refine ⟨zpow_eq_zero, _⟩,
141
- rintros rfl,
142
- exact zero_zpow _ hn.ne'
143
- end
144
 
145
  lemma zpow_ne_zero {x : G₀} (n : ℤ) : x ≠ 0 → x ^ n ≠ 0 :=
146
  mt zpow_eq_zero
 
134
  lemma zpow_eq_zero {x : G₀} {n : ℤ} (h : x ^ n = 0) : x = 0 :=
135
  classical.by_contradiction $ λ hx, zpow_ne_zero_of_ne_zero hx n h
136
 
137
+ lemma zpow_eq_zero_iff {a : G₀} {n : ℤ} (hn : n 0) :
138
  a ^ n = 0 ↔ a = 0 :=
139
+ ⟨zpow_eq_zero, λ ha, ha.symm ▸ zero_zpow _ hn⟩
 
 
 
 
140
 
141
  lemma zpow_ne_zero {x : G₀} (n : ℤ) : x ≠ 0 → x ^ n ≠ 0 :=
142
  mt zpow_eq_zero
formal/lean/mathlib/algebra/hom/equiv.lean CHANGED
@@ -729,3 +729,16 @@ def mul_equiv.to_additive'' [add_zero_class G] [mul_one_class H] :
729
  add_equiv.to_multiplicative''.symm
730
 
731
  end type_tags
 
 
 
 
 
 
 
 
 
 
 
 
 
 
729
  add_equiv.to_multiplicative''.symm
730
 
731
  end type_tags
732
+
733
+ section
734
+ variables (G) (H)
735
+
736
+ /-- `additive (multiplicative G)` is just `G`. -/
737
+ def add_equiv.additive_multiplicative [add_zero_class G] : additive (multiplicative G) ≃+ G :=
738
+ mul_equiv.to_additive'' (mul_equiv.refl (multiplicative G))
739
+
740
+ /-- `multiplicative (additive H)` is just `H`. -/
741
+ def mul_equiv.multiplicative_additive [mul_one_class H] : multiplicative (additive H) ≃* H :=
742
+ add_equiv.to_multiplicative'' (add_equiv.refl (additive H))
743
+
744
+ end
formal/lean/mathlib/algebra/hom/group_action.lean CHANGED
@@ -54,7 +54,7 @@ variables (G : Type*) [group G] (H : subgroup G)
54
  set_option old_structure_cmd true
55
 
56
  /-- Equivariant functions. -/
57
- @[nolint has_inhabited_instance]
58
  structure mul_action_hom :=
59
  (to_fun : X → Y)
60
  (map_smul' : ∀ (m : M') (x : X), to_fun (m • x) = m • to_fun x)
@@ -258,7 +258,7 @@ end semiring
258
  end distrib_mul_action_hom
259
 
260
  /-- Equivariant ring homomorphisms. -/
261
- @[nolint has_inhabited_instance]
262
  structure mul_semiring_action_hom extends R →+[M] S, R →+* S.
263
 
264
  /-- Reinterpret an equivariant ring homomorphism as a ring homomorphism. -/
 
54
  set_option old_structure_cmd true
55
 
56
  /-- Equivariant functions. -/
57
+ @[nolint has_nonempty_instance]
58
  structure mul_action_hom :=
59
  (to_fun : X → Y)
60
  (map_smul' : ∀ (m : M') (x : X), to_fun (m • x) = m • to_fun x)
 
258
  end distrib_mul_action_hom
259
 
260
  /-- Equivariant ring homomorphisms. -/
261
+ @[nolint has_nonempty_instance]
262
  structure mul_semiring_action_hom extends R →+[M] S, R →+* S.
263
 
264
  /-- Reinterpret an equivariant ring homomorphism as a ring homomorphism. -/
formal/lean/mathlib/algebra/hom/group_instances.lean CHANGED
@@ -69,10 +69,24 @@ instance [add_comm_monoid M] : semiring (add_monoid.End M) :=
69
  .. add_monoid.End.monoid M,
70
  .. add_monoid_hom.add_comm_monoid }
71
 
 
 
 
 
 
 
 
72
  instance [add_comm_group M] : ring (add_monoid.End M) :=
73
- { .. add_monoid.End.semiring,
 
 
 
74
  .. add_monoid_hom.add_comm_group }
75
 
 
 
 
 
76
  /-!
77
  ### Morphisms of morphisms
78
 
@@ -208,7 +222,8 @@ variables {R S : Type*} [non_unital_non_assoc_semiring R] [non_unital_non_assoc_
208
 
209
  This is a more-strongly bundled version of `add_monoid_hom.mul_left` and `add_monoid_hom.mul_right`.
210
 
211
- A stronger version of this exists for algebras as `algebra.lmul`.
 
212
  -/
213
  def add_monoid_hom.mul : R →+ R →+ R :=
214
  { to_fun := add_monoid_hom.mul_left,
 
69
  .. add_monoid.End.monoid M,
70
  .. add_monoid_hom.add_comm_monoid }
71
 
72
+ /-- See also `add_monoid.End.nat_cast_def`. -/
73
+ @[simp] lemma add_monoid.End.nat_cast_apply [add_comm_monoid M] (n : ℕ) (m : M) :
74
+ (↑n : add_monoid.End M) m = n • m := rfl
75
+
76
+ instance [add_comm_group M] : add_comm_group (add_monoid.End M) :=
77
+ add_monoid_hom.add_comm_group
78
+
79
  instance [add_comm_group M] : ring (add_monoid.End M) :=
80
+ { int_cast := λ z, z • 1,
81
+ int_cast_of_nat := of_nat_zsmul _,
82
+ int_cast_neg_succ_of_nat := zsmul_neg_succ_of_nat _,
83
+ .. add_monoid.End.semiring,
84
  .. add_monoid_hom.add_comm_group }
85
 
86
+ /-- See also `add_monoid.End.int_cast_def`. -/
87
+ @[simp] lemma add_monoid.End.int_cast_apply [add_comm_group M] (z : ℤ) (m : M) :
88
+ (↑z : add_monoid.End M) m = z • m := rfl
89
+
90
  /-!
91
  ### Morphisms of morphisms
92
 
 
222
 
223
  This is a more-strongly bundled version of `add_monoid_hom.mul_left` and `add_monoid_hom.mul_right`.
224
 
225
+ Stronger versions of this exists for algebras as `linear_map.mul`, `non_unital_alg_hom.mul`
226
+ and `algebra.lmul`.
227
  -/
228
  def add_monoid_hom.mul : R →+ R →+ R :=
229
  { to_fun := add_monoid_hom.mul_left,
formal/lean/mathlib/algebra/hom/ring.lean CHANGED
@@ -413,6 +413,10 @@ mt f.codomain_trivial_iff_map_one_eq_zero.mpr zero_ne_one
413
  lemma domain_nontrivial [nontrivial β] : nontrivial α :=
414
  ⟨⟨1, 0, mt (λ h, show f 1 = 0, by rw [h, map_zero]) f.map_one_ne_zero⟩⟩
415
 
 
 
 
 
416
  end
417
 
418
  /-- Ring homomorphisms preserve additive inverse. -/
 
413
  lemma domain_nontrivial [nontrivial β] : nontrivial α :=
414
  ⟨⟨1, 0, mt (λ h, show f 1 = 0, by rw [h, map_zero]) f.map_one_ne_zero⟩⟩
415
 
416
+ lemma codomain_trivial (f : α →+* β) [h : subsingleton α] : subsingleton β :=
417
+ (subsingleton_or_nontrivial β).resolve_right
418
+ (λ _, by exactI not_nontrivial_iff_subsingleton.mpr h f.domain_nontrivial)
419
+
420
  end
421
 
422
  /-- Ring homomorphisms preserve additive inverse. -/
formal/lean/mathlib/algebra/hom/units.lean CHANGED
@@ -76,7 +76,7 @@ variables [division_monoid α]
76
  @[simp, norm_cast, to_additive] lemma coe_zpow : ∀ (u : αˣ) (n : ℤ), ((u ^ n : αˣ) : α) = u ^ n :=
77
  (units.coe_hom α).map_zpow
78
 
79
- lemma _root_.divp_eq_div (a : α) (u : αˣ) : a /ₚ u = a / u :=
80
  by rw [div_eq_mul_inv, divp, u.coe_inv]
81
 
82
  end division_monoid
 
76
  @[simp, norm_cast, to_additive] lemma coe_zpow : ∀ (u : αˣ) (n : ℤ), ((u ^ n : αˣ) : α) = u ^ n :=
77
  (units.coe_hom α).map_zpow
78
 
79
+ @[field_simps] lemma _root_.divp_eq_div (a : α) (u : αˣ) : a /ₚ u = a / u :=
80
  by rw [div_eq_mul_inv, divp, u.coe_inv]
81
 
82
  end division_monoid
formal/lean/mathlib/algebra/homology/complex_shape.lean CHANGED
@@ -55,7 +55,7 @@ This means that the shape consists of some union of lines, rays, intervals, and
55
 
56
  Below we define `c.next` and `c.prev` which provide these related elements.
57
  -/
58
- @[ext, nolint has_inhabited_instance]
59
  structure complex_shape (ι : Type*) :=
60
  (rel : ι → ι → Prop)
61
  (next_eq : ∀ {i j j'}, rel i j → rel i j' → j = j')
 
55
 
56
  Below we define `c.next` and `c.prev` which provide these related elements.
57
  -/
58
+ @[ext, nolint has_nonempty_instance]
59
  structure complex_shape (ι : Type*) :=
60
  (rel : ι → ι → Prop)
61
  (next_eq : ∀ {i j j'}, rel i j → rel i j' → j = j')
formal/lean/mathlib/algebra/homology/homological_complex.lean CHANGED
@@ -27,7 +27,7 @@ and similarly `cochain_complex V α`, with `i = j + 1`.
27
  There is a category structure, where morphisms are chain maps.
28
 
29
  For `C : homological_complex V c`, we define `C.X_next i`, which is either `C.X j` for some
30
- arbitrarily chosen `j` such that `c.r i j`, or the zero object if there is no such `j`.
31
  Similarly we have `C.X_prev j`.
32
  Defined in terms of these we have `C.d_from i : C.X i ⟶ C.X_next i` and
33
  `C.d_to j : C.X_prev j ⟶ C.X j`, which are either defined as `C.d i j`, or zero, as needed.
@@ -299,7 +299,7 @@ def X_prev_iso {i j : ι} (r : c.rel i j) :
299
  eq_to_iso $ by rw ← c.prev_eq' r
300
 
301
  /-- If there is no `i` so `c.rel i j`, then `C.X_prev j` is isomorphic to `C.X j`. -/
302
- def X_prev_iso_zero {j : ι} (h : ¬c.rel (c.prev j) j) :
303
  C.X_prev j ≅ C.X j :=
304
  eq_to_iso $ congr_arg C.X begin
305
  dsimp [complex_shape.prev],
@@ -308,7 +308,7 @@ eq_to_iso $ congr_arg C.X begin
308
  rw this at h, contradiction,
309
  end
310
 
311
- /-- Either `C.X j`, if there is some `j` with `c.rel i j`, or `C.X j`. -/
312
  abbreviation X_next (i : ι) : V := C.X (c.next i)
313
 
314
  /-- If `c.rel i j`, then `C.X_next i` is isomorphic to `C.X j`. -/
@@ -316,8 +316,8 @@ def X_next_iso {i j : ι} (r : c.rel i j) :
316
  C.X_next i ≅ C.X j :=
317
  eq_to_iso $ by rw ← c.next_eq' r
318
 
319
- /-- If there is no `j` so `c.rel i j`, then `C.X_next i` is isomorphic to `0`. -/
320
- def X_next_iso_zero {i : ι} (h : ¬c.rel i (c.next i)) :
321
  C.X_next i ≅ C.X i :=
322
  eq_to_iso $ congr_arg C.X begin
323
  dsimp [complex_shape.next],
@@ -364,16 +364,16 @@ C.shape _ _ h
364
  (C.X_prev_iso r).inv ≫ C.d_to j = C.d i j :=
365
  by simp [C.d_to_eq r]
366
 
367
- @[simp, reassoc] lemma X_prev_iso_zero_comp_d_to {j : ι} (h : ¬c.rel (c.prev j) j) :
368
- (C.X_prev_iso_zero h).inv ≫ C.d_to j = 0 :=
369
  by simp [h]
370
 
371
  @[simp, reassoc] lemma d_from_comp_X_next_iso {i j : ι} (r : c.rel i j) :
372
  C.d_from i ≫ (C.X_next_iso r).hom = C.d i j :=
373
  by simp [C.d_from_eq r]
374
 
375
- @[simp, reassoc] lemma d_from_comp_X_next_iso_zero {i : ι} (h : ¬c.rel i (c.next i)) :
376
- C.d_from i ≫ (C.X_next_iso_zero h).hom = 0 :=
377
  by simp [h]
378
 
379
  @[simp]
@@ -430,7 +430,7 @@ by { ext, simp, }
430
 
431
  /-! Lemmas relating chain maps and `d_to`/`d_from`. -/
432
 
433
- /-- `f.prev j` is `f.f i` if there is some `r i j`, and zero otherwise. -/
434
  abbreviation prev (f : hom C₁ C₂) (j : ι) : C₁.X_prev j ⟶ C₂.X_prev j := f.f _
435
 
436
  lemma prev_eq (f : hom C₁ C₂) {i j : ι} (w : c.rel i j) :
@@ -440,7 +440,7 @@ begin
440
  simp only [X_prev_iso, eq_to_iso_refl, iso.refl_hom, iso.refl_inv, id_comp, comp_id],
441
  end
442
 
443
- /-- `f.next i` is `f.f j` if there is some `r i j`, and zero otherwise. -/
444
  abbreviation next (f : hom C₁ C₂) (i : ι) : C₁.X_next i ⟶ C₂.X_next i := f.f _
445
 
446
  lemma next_eq (f : hom C₁ C₂) {i j : ι} (w : c.rel i j) :
@@ -552,7 +552,7 @@ Auxiliary structure for setting up the recursion in `mk`.
552
  This is purely an implementation detail: for some reason just using the dependent 6-tuple directly
553
  results in `mk_aux` taking much longer (well over the `-T100000` limit) to elaborate.
554
  -/
555
- @[nolint has_inhabited_instance]
556
  structure mk_struct :=
557
  (X₀ X₁ X₂ : V)
558
  (d₀ : X₁ ⟶ X₀)
@@ -745,7 +745,7 @@ Auxiliary structure for setting up the recursion in `mk`.
745
  This is purely an implementation detail: for some reason just using the dependent 6-tuple directly
746
  results in `mk_aux` taking much longer (well over the `-T100000` limit) to elaborate.
747
  -/
748
- @[nolint has_inhabited_instance]
749
  structure mk_struct :=
750
  (X₀ X₁ X₂ : V)
751
  (d₀ : X₀ ⟶ X₁)
 
27
  There is a category structure, where morphisms are chain maps.
28
 
29
  For `C : homological_complex V c`, we define `C.X_next i`, which is either `C.X j` for some
30
+ arbitrarily chosen `j` such that `c.r i j`, or `C.X i` if there is no such `j`.
31
  Similarly we have `C.X_prev j`.
32
  Defined in terms of these we have `C.d_from i : C.X i ⟶ C.X_next i` and
33
  `C.d_to j : C.X_prev j ⟶ C.X j`, which are either defined as `C.d i j`, or zero, as needed.
 
299
  eq_to_iso $ by rw ← c.prev_eq' r
300
 
301
  /-- If there is no `i` so `c.rel i j`, then `C.X_prev j` is isomorphic to `C.X j`. -/
302
+ def X_prev_iso_self {j : ι} (h : ¬c.rel (c.prev j) j) :
303
  C.X_prev j ≅ C.X j :=
304
  eq_to_iso $ congr_arg C.X begin
305
  dsimp [complex_shape.prev],
 
308
  rw this at h, contradiction,
309
  end
310
 
311
+ /-- Either `C.X j`, if there is some `j` with `c.rel i j`, or `C.X i`. -/
312
  abbreviation X_next (i : ι) : V := C.X (c.next i)
313
 
314
  /-- If `c.rel i j`, then `C.X_next i` is isomorphic to `C.X j`. -/
 
316
  C.X_next i ≅ C.X j :=
317
  eq_to_iso $ by rw ← c.next_eq' r
318
 
319
+ /-- If there is no `j` so `c.rel i j`, then `C.X_next i` is isomorphic to `C.X i`. -/
320
+ def X_next_iso_self {i : ι} (h : ¬c.rel i (c.next i)) :
321
  C.X_next i ≅ C.X i :=
322
  eq_to_iso $ congr_arg C.X begin
323
  dsimp [complex_shape.next],
 
364
  (C.X_prev_iso r).inv ≫ C.d_to j = C.d i j :=
365
  by simp [C.d_to_eq r]
366
 
367
+ @[simp, reassoc] lemma X_prev_iso_self_comp_d_to {j : ι} (h : ¬c.rel (c.prev j) j) :
368
+ (C.X_prev_iso_self h).inv ≫ C.d_to j = 0 :=
369
  by simp [h]
370
 
371
  @[simp, reassoc] lemma d_from_comp_X_next_iso {i j : ι} (r : c.rel i j) :
372
  C.d_from i ≫ (C.X_next_iso r).hom = C.d i j :=
373
  by simp [C.d_from_eq r]
374
 
375
+ @[simp, reassoc] lemma d_from_comp_X_next_iso_self {i : ι} (h : ¬c.rel i (c.next i)) :
376
+ C.d_from i ≫ (C.X_next_iso_self h).hom = 0 :=
377
  by simp [h]
378
 
379
  @[simp]
 
430
 
431
  /-! Lemmas relating chain maps and `d_to`/`d_from`. -/
432
 
433
+ /-- `f.prev j` is `f.f i` if there is some `r i j`, and `f.f j` otherwise. -/
434
  abbreviation prev (f : hom C₁ C₂) (j : ι) : C₁.X_prev j ⟶ C₂.X_prev j := f.f _
435
 
436
  lemma prev_eq (f : hom C₁ C₂) {i j : ι} (w : c.rel i j) :
 
440
  simp only [X_prev_iso, eq_to_iso_refl, iso.refl_hom, iso.refl_inv, id_comp, comp_id],
441
  end
442
 
443
+ /-- `f.next i` is `f.f j` if there is some `r i j`, and `f.f j` otherwise. -/
444
  abbreviation next (f : hom C₁ C₂) (i : ι) : C₁.X_next i ⟶ C₂.X_next i := f.f _
445
 
446
  lemma next_eq (f : hom C₁ C₂) {i j : ι} (w : c.rel i j) :
 
552
  This is purely an implementation detail: for some reason just using the dependent 6-tuple directly
553
  results in `mk_aux` taking much longer (well over the `-T100000` limit) to elaborate.
554
  -/
555
+ @[nolint has_nonempty_instance]
556
  structure mk_struct :=
557
  (X₀ X₁ X₂ : V)
558
  (d₀ : X₁ ⟶ X₀)
 
745
  This is purely an implementation detail: for some reason just using the dependent 6-tuple directly
746
  results in `mk_aux` taking much longer (well over the `-T100000` limit) to elaborate.
747
  -/
748
+ @[nolint has_nonempty_instance]
749
  structure mk_struct :=
750
  (X₀ X₁ X₂ : V)
751
  (d₀ : X₀ ⟶ X₁)
formal/lean/mathlib/algebra/homology/homotopy.lean CHANGED
@@ -113,7 +113,7 @@ end
113
  A homotopy `h` between chain maps `f` and `g` consists of components `h i j : C.X i ⟶ D.X j`
114
  which are zero unless `c.rel j i`, satisfying the homotopy condition.
115
  -/
116
- @[ext, nolint has_inhabited_instance]
117
  structure homotopy (f g : C ⟶ D) :=
118
  (hom : Π i j, C.X i ⟶ D.X j)
119
  (zero' : ∀ i j, ¬ c.rel j i → hom i j = 0 . obviously)
 
113
  A homotopy `h` between chain maps `f` and `g` consists of components `h i j : C.X i ⟶ D.X j`
114
  which are zero unless `c.rel j i`, satisfying the homotopy condition.
115
  -/
116
+ @[ext, nolint has_nonempty_instance]
117
  structure homotopy (f g : C ⟶ D) :=
118
  (hom : Π i j, C.X i ⟶ D.X j)
119
  (zero' : ∀ i j, ¬ c.rel j i → hom i j = 0 . obviously)
formal/lean/mathlib/algebra/homology/short_exact/preadditive.lean CHANGED
@@ -167,7 +167,7 @@ end preadditive
167
  /-- A *splitting* of a sequence `A -f⟶ B -g⟶ C` is an isomorphism
168
  to the short exact sequence `0 ⟶ A ⟶ A ⊞ C ⟶ C ⟶ 0` such that
169
  the vertical maps on the left and the right are the identity. -/
170
- @[nolint has_inhabited_instance]
171
  structure splitting [has_zero_morphisms 𝒜] [has_binary_biproducts 𝒜] :=
172
  (iso : B ≅ A ⊞ C)
173
  (comp_iso_eq_inl : f ≫ iso.hom = biprod.inl)
 
167
  /-- A *splitting* of a sequence `A -f⟶ B -g⟶ C` is an isomorphism
168
  to the short exact sequence `0 ⟶ A ⟶ A ⊞ C ⟶ C ⟶ 0` such that
169
  the vertical maps on the left and the right are the identity. -/
170
+ @[nolint has_nonempty_instance]
171
  structure splitting [has_zero_morphisms 𝒜] [has_binary_biproducts 𝒜] :=
172
  (iso : B ≅ A ⊞ C)
173
  (comp_iso_eq_inl : f ≫ iso.hom = biprod.inl)
formal/lean/mathlib/algebra/indicator_function.lean CHANGED
@@ -457,12 +457,8 @@ lemma inter_indicator_one {s t : set α} :
457
  funext (λ _, by simpa only [← inter_indicator_mul, pi.mul_apply, pi.one_apply, one_mul])
458
 
459
  lemma indicator_prod_one {s : set α} {t : set β} {x : α} {y : β} :
460
- (s ×ˢ t : set _).indicator (1 : _ → M) (x, y) = s.indicator 1 x * t.indicator 1 y :=
461
- begin
462
- letI := classical.dec_pred (∈ s),
463
- letI := classical.dec_pred (∈ t),
464
- simp [indicator_apply, ← ite_and],
465
- end
466
 
467
  variables (M) [nontrivial M]
468
 
 
457
  funext (λ _, by simpa only [← inter_indicator_mul, pi.mul_apply, pi.one_apply, one_mul])
458
 
459
  lemma indicator_prod_one {s : set α} {t : set β} {x : α} {y : β} :
460
+ (s ×ˢ t).indicator (1 : _ → M) (x, y) = s.indicator 1 x * t.indicator 1 y :=
461
+ by { classical, simp [indicator_apply, ←ite_and] }
 
 
 
 
462
 
463
  variables (M) [nontrivial M]
464
 
formal/lean/mathlib/algebra/lie/base_change.lean CHANGED
@@ -40,7 +40,7 @@ support in the tensor product library, it is far easier to bootstrap like this,
40
  definition below. -/
41
  private def bracket' : (A ⊗[R] L) →ₗ[R] (A ⊗[R] L) →ₗ[R] A ⊗[R] L :=
42
  tensor_product.curry $
43
- (tensor_product.map (algebra.lmul' R) (lie_module.to_module_hom R L L : L ⊗[R] L →ₗ[R] L))
44
  ∘ₗ ↑(tensor_product.tensor_tensor_tensor_comm R A L A L)
45
 
46
  @[simp] private lemma bracket'_tmul (s t : A) (x y : L) :
@@ -115,8 +115,8 @@ begin
115
  { simp only [lie_zero, smul_zero], },
116
  { intros a₂ l₂,
117
  simp only [bracket_def, bracket', tensor_product.smul_tmul', mul_left_comm a₁ a a₂,
118
- tensor_product.curry_apply, algebra.lmul'_apply, algebra.id.smul_eq_mul, function.comp_app,
119
- linear_equiv.coe_coe, linear_map.coe_comp, tensor_product.map_tmul,
120
  tensor_product.tensor_tensor_tensor_comm_tmul], },
121
  { intros z₁ z₂ h₁ h₂,
122
  simp only [h₁, h₂, smul_add, lie_add], }, },
 
40
  definition below. -/
41
  private def bracket' : (A ⊗[R] L) →ₗ[R] (A ⊗[R] L) →ₗ[R] A ⊗[R] L :=
42
  tensor_product.curry $
43
+ (tensor_product.map (linear_map.mul' R _) (lie_module.to_module_hom R L L : L ⊗[R] L →ₗ[R] L))
44
  ∘ₗ ↑(tensor_product.tensor_tensor_tensor_comm R A L A L)
45
 
46
  @[simp] private lemma bracket'_tmul (s t : A) (x y : L) :
 
115
  { simp only [lie_zero, smul_zero], },
116
  { intros a₂ l₂,
117
  simp only [bracket_def, bracket', tensor_product.smul_tmul', mul_left_comm a₁ a a₂,
118
+ tensor_product.curry_apply, linear_map.mul'_apply, algebra.id.smul_eq_mul,
119
+ function.comp_app, linear_equiv.coe_coe, linear_map.coe_comp, tensor_product.map_tmul,
120
  tensor_product.tensor_tensor_tensor_comm_tmul], },
121
  { intros z₁ z₂ h₁ h₂,
122
  simp only [h₁, h₂, smul_add, lie_add], }, },
formal/lean/mathlib/algebra/lie/nilpotent.lean CHANGED
@@ -691,9 +691,12 @@ lemma lie_algebra.ad_nilpotent_of_nilpotent {a : A} (h : is_nilpotent a) :
691
  is_nilpotent (lie_algebra.ad R A a) :=
692
  begin
693
  rw lie_algebra.ad_eq_lmul_left_sub_lmul_right,
694
- have hl : is_nilpotent (algebra.lmul_left R a), { rwa algebra.is_nilpotent_lmul_left_iff, },
695
- have hr : is_nilpotent (algebra.lmul_right R a), { rwa algebra.is_nilpotent_lmul_right_iff, },
696
- exact (algebra.commute_lmul_left_right R a a).is_nilpotent_sub hl hr,
 
 
 
697
  end
698
 
699
  variables {R}
 
691
  is_nilpotent (lie_algebra.ad R A a) :=
692
  begin
693
  rw lie_algebra.ad_eq_lmul_left_sub_lmul_right,
694
+ have hl : is_nilpotent (linear_map.mul_left R a),
695
+ { rwa linear_map.is_nilpotent_mul_left_iff, },
696
+ have hr : is_nilpotent (linear_map.mul_right R a),
697
+ { rwa linear_map.is_nilpotent_mul_right_iff, },
698
+ have := @linear_map.commute_mul_left_right R A _ _ _ _ _ a a,
699
+ exact this.is_nilpotent_sub hl hr,
700
  end
701
 
702
  variables {R}
formal/lean/mathlib/algebra/lie/of_associative.lean CHANGED
@@ -234,7 +234,7 @@ end lie_submodule
234
  open lie_algebra
235
 
236
  lemma lie_algebra.ad_eq_lmul_left_sub_lmul_right (A : Type v) [ring A] [algebra R A] :
237
- (ad R A : A → module.End R A) = algebra.lmul_left R - algebra.lmul_right R :=
238
  by { ext a b, simp [lie_ring.of_associative_ring_bracket], }
239
 
240
  lemma lie_subalgebra.ad_comp_incl_eq (K : lie_subalgebra R L) (x : K) :
 
234
  open lie_algebra
235
 
236
  lemma lie_algebra.ad_eq_lmul_left_sub_lmul_right (A : Type v) [ring A] [algebra R A] :
237
+ (ad R A : A → module.End R A) = linear_map.mul_left R - linear_map.mul_right R :=
238
  by { ext a b, simp [lie_ring.of_associative_ring_bracket], }
239
 
240
  lemma lie_subalgebra.ad_comp_incl_eq (K : lie_subalgebra R L) (x : K) :
formal/lean/mathlib/algebra/module/basic.lean CHANGED
@@ -71,6 +71,9 @@ instance add_comm_monoid.nat_module : module ℕ M :=
71
  zero_smul := zero_nsmul,
72
  add_smul := λ r s x, add_nsmul x r s }
73
 
 
 
 
74
  theorem add_smul : (r + s) • x = r • x + s • x := module.add_smul r s x
75
 
76
  lemma convex.combo_self {a b : R} (h : a + b = 1) (x : M) : a • x + b • x = x :=
@@ -197,11 +200,14 @@ instance add_comm_group.int_module : module ℤ M :=
197
  zero_smul := zero_zsmul,
198
  add_smul := λ r s x, add_zsmul x r s }
199
 
 
 
 
200
  /-- A structure containing most informations as in a module, except the fields `zero_smul`
201
  and `smul_zero`. As these fields can be deduced from the other ones when `M` is an `add_comm_group`,
202
  this provides a way to construct a module structure by checking less properties, in
203
  `module.of_core`. -/
204
- @[nolint has_inhabited_instance]
205
  structure module.core extends has_smul R M :=
206
  (smul_add : ∀(r : R) (x y : M), r • (x + y) = r • x + r • y)
207
  (add_smul : ∀(r s : R) (x : M), (r + s) • x = r • x + s • x)
 
71
  zero_smul := zero_nsmul,
72
  add_smul := λ r s x, add_nsmul x r s }
73
 
74
+ lemma add_monoid.End.nat_cast_def (n : ℕ) :
75
+ (↑n : add_monoid.End M) = distrib_mul_action.to_add_monoid_End ℕ M n := rfl
76
+
77
  theorem add_smul : (r + s) • x = r • x + s • x := module.add_smul r s x
78
 
79
  lemma convex.combo_self {a b : R} (h : a + b = 1) (x : M) : a • x + b • x = x :=
 
200
  zero_smul := zero_zsmul,
201
  add_smul := λ r s x, add_zsmul x r s }
202
 
203
+ lemma add_monoid.End.int_cast_def (z : ℤ) :
204
+ (↑z : add_monoid.End M) = distrib_mul_action.to_add_monoid_End ℤ M z := rfl
205
+
206
  /-- A structure containing most informations as in a module, except the fields `zero_smul`
207
  and `smul_zero`. As these fields can be deduced from the other ones when `M` is an `add_comm_group`,
208
  this provides a way to construct a module structure by checking less properties, in
209
  `module.of_core`. -/
210
+ @[nolint has_nonempty_instance]
211
  structure module.core extends has_smul R M :=
212
  (smul_add : ∀(r : R) (x y : M), r • (x + y) = r • x + r • y)
213
  (add_smul : ∀(r s : R) (x : M), (r + s) • x = r • x + s • x)
formal/lean/mathlib/algebra/module/bimodule.lean ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /-
2
+ Copyright (c) 2022 Oliver Nash. All rights reserved.
3
+ Released under Apache 2.0 license as described in the file LICENSE.
4
+ Authors: Oliver Nash
5
+ -/
6
+ import ring_theory.tensor_product
7
+
8
+ /-!
9
+ # Bimodules
10
+
11
+ One frequently encounters situations in which several sets of scalars act on a single space, subject
12
+ to compatibility condition(s). A distinguished instance of this is the theory of bimodules: one has
13
+ two rings `R`, `S` acting on an additive group `M`, with `R` acting covariantly ("on the left")
14
+ and `S` acting contravariantly ("on the right"). The compatibility condition is just:
15
+ `(r • m) • s = r • (m • s)` for all `r : R`, `s : S`, `m : M`.
16
+
17
+ This situation can be set up in Mathlib as:
18
+ ```lean
19
+ variables (R S M : Type*) [ring R] [ring S]
20
+ variables [add_comm_group M] [module R M] [module Sᵐᵒᵖ M] [smul_comm_class R Sᵐᵒᵖ M]
21
+ ```
22
+ The key fact is:
23
+ ```lean
24
+ example : module (R ⊗[ℕ] Sᵐᵒᵖ) M := tensor_product.algebra.module
25
+ ```
26
+ Note that the corresponding result holds for the canonically isomorphic ring `R ⊗[ℤ] Sᵐᵒᵖ` but it is
27
+ preferable to use the `R ⊗[ℕ] Sᵐᵒᵖ` instance since it works without additive inverses.
28
+
29
+ Bimodules are thus just a special case of `module`s and most of their properties follow from the
30
+ theory of `module`s`. In particular a two-sided submodule of a bimodule is simply a term of type
31
+ `submodule (R ⊗[ℕ] Sᵐᵒᵖ) M`.
32
+
33
+ This file is a place to collect results which are specific to bimodules.
34
+
35
+ ## Main definitions
36
+
37
+ * `subbimodule.mk`
38
+ * `subbimodule.smul_mem`
39
+ * `subbimodule.smul_mem'`
40
+ * `subbimodule.to_submodule`
41
+ * `subbimodule.to_submodule'`
42
+
43
+ ## Implementation details
44
+
45
+ For many definitions and lemmas it is preferable to set things up without opposites, i.e., as:
46
+ `[module S M] [smul_comm_class R S M]` rather than `[module Sᵐᵒᵖ M] [smul_comm_class R Sᵐᵒᵖ M]`.
47
+ The corresponding results for opposites then follow automatically and do not require taking
48
+ advantage of the fact that `(Sᵐᵒᵖ)ᵐᵒᵖ` is defeq to `S`.
49
+
50
+ ## TODO
51
+
52
+ Develop the theory of two-sided ideals, which have type `submodule (R ⊗[ℕ] Rᵐᵒᵖ) R`.
53
+
54
+ -/
55
+
56
+ open_locale tensor_product
57
+
58
+ local attribute [instance] tensor_product.algebra.module
59
+
60
+ namespace subbimodule
61
+
62
+ section algebra
63
+
64
+ variables {R A B M : Type*}
65
+ variables [comm_semiring R] [add_comm_monoid M] [module R M]
66
+ variables [semiring A] [semiring B] [module A M] [module B M]
67
+ variables [algebra R A] [algebra R B]
68
+ variables [is_scalar_tower R A M] [is_scalar_tower R B M]
69
+ variables [smul_comm_class A B M]
70
+
71
+ /-- A constructor for a subbimodule which demands closure under the two sets of scalars
72
+ individually, rather than jointly via their tensor product.
73
+
74
+ Note that `R` plays no role but it is convenient to make this generalisation to support the cases
75
+ `R = ℕ` and `R = ℤ` which both show up naturally. See also `base_change`. -/
76
+ @[simps] def mk (p : add_submonoid M)
77
+ (hA : ∀ (a : A) {m : M}, m ∈ p → a • m ∈ p)
78
+ (hB : ∀ (b : B) {m : M}, m ∈ p → b • m ∈ p) : submodule (A ⊗[R] B) M :=
79
+ { carrier := p,
80
+ smul_mem' := λ ab m, tensor_product.induction_on ab
81
+ (λ hm, by simpa only [zero_smul] using p.zero_mem)
82
+ (λ a b hm, by simpa only [tensor_product.algebra.smul_def] using hA a (hB b hm))
83
+ (λ z w hz hw hm, by simpa only [add_smul] using p.add_mem (hz hm) (hw hm)),
84
+ .. p }
85
+
86
+ lemma smul_mem (p : submodule (A ⊗[R] B) M) (a : A) {m : M} (hm : m ∈ p) : a • m ∈ p :=
87
+ begin
88
+ suffices : a • m = a ⊗ₜ[R] (1 : B) • m, { exact this.symm ▸ p.smul_mem _ hm, },
89
+ simp [tensor_product.algebra.smul_def],
90
+ end
91
+
92
+ lemma smul_mem' (p : submodule (A ⊗[R] B) M) (b : B) {m : M} (hm : m ∈ p) : b • m ∈ p :=
93
+ begin
94
+ suffices : b • m = (1 : A) ⊗ₜ[R] b • m, { exact this.symm ▸ p.smul_mem _ hm, },
95
+ simp [tensor_product.algebra.smul_def],
96
+ end
97
+
98
+ /-- If `A` and `B` are also `algebra`s over yet another set of scalars `S` then we may "base change"
99
+ from `R` to `S`. -/
100
+ @[simps] def base_change (S : Type*) [comm_semiring S] [module S M] [algebra S A] [algebra S B]
101
+ [is_scalar_tower S A M] [is_scalar_tower S B M] (p : submodule (A ⊗[R] B) M) :
102
+ submodule (A ⊗[S] B) M :=
103
+ mk p.to_add_submonoid (smul_mem p) (smul_mem' p)
104
+
105
+ /-- Forgetting the `B` action, a `submodule` over `A ⊗[R] B` is just a `submodule` over `A`. -/
106
+ @[simps] def to_submodule (p : submodule (A ⊗[R] B) M) : submodule A M :=
107
+ { carrier := p,
108
+ smul_mem' := smul_mem p,
109
+ .. p }
110
+
111
+ /-- Forgetting the `A` action, a `submodule` over `A ⊗[R] B` is just a `submodule` over `B`. -/
112
+ @[simps] def to_submodule' (p : submodule (A ⊗[R] B) M) : submodule B M :=
113
+ { carrier := p,
114
+ smul_mem' := smul_mem' p,
115
+ .. p }
116
+
117
+ end algebra
118
+
119
+ section ring
120
+
121
+ variables (R S M : Type*) [ring R] [ring S]
122
+ variables [add_comm_group M] [module R M] [module S M] [smul_comm_class R S M]
123
+
124
+ /-- A `submodule` over `R ⊗[ℕ] S` is naturally also a `submodule` over the canonically-isomorphic
125
+ ring `R ⊗[ℤ] S`. -/
126
+ @[simps] def to_subbimodule_int (p : submodule (R ⊗[ℕ] S) M) : submodule (R ⊗[ℤ] S) M :=
127
+ base_change ℤ p
128
+
129
+ /-- A `submodule` over `R ⊗[ℤ] S` is naturally also a `submodule` over the canonically-isomorphic
130
+ ring `R ⊗[ℕ] S`. -/
131
+ @[simps] def to_subbimodule_nat (p : submodule (R ⊗[ℤ] S) M) : submodule (R ⊗[ℕ] S) M :=
132
+ base_change ℕ p
133
+
134
+ end ring
135
+
136
+ end subbimodule
formal/lean/mathlib/algebra/module/equiv.lean CHANGED
@@ -45,13 +45,12 @@ section
45
  set_option old_structure_cmd true
46
 
47
  /-- A linear equivalence is an invertible linear map. -/
48
- @[nolint has_inhabited_instance]
49
  structure linear_equiv {R : Type*} {S : Type*} [semiring R] [semiring S] (σ : R →+* S)
50
  {σ' : S →+* R} [ring_hom_inv_pair σ σ'] [ring_hom_inv_pair σ' σ]
51
  (M : Type*) (M₂ : Type*)
52
  [add_comm_monoid M] [add_comm_monoid M₂] [module R M] [module S M₂]
53
  extends linear_map σ M M₂, M ≃+ M₂
54
- end
55
 
56
  attribute [nolint doc_blame] linear_equiv.to_linear_map
57
  attribute [nolint doc_blame] linear_equiv.to_add_equiv
@@ -60,6 +59,49 @@ notation M ` ≃ₛₗ[`:50 σ `] ` M₂ := linear_equiv σ M M₂
60
  notation M ` ≃ₗ[`:50 R `] ` M₂ := linear_equiv (ring_hom.id R) M M₂
61
  notation M ` ≃ₗ⋆[`:50 R `] ` M₂ := linear_equiv (star_ring_end R) M M₂
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  namespace linear_equiv
64
 
65
  section add_comm_monoid
@@ -101,9 +143,12 @@ lemma to_linear_map_injective :
101
  (e₁ : M →ₛₗ[σ] M₂) = e₂ ↔ e₁ = e₂ :=
102
  to_linear_map_injective.eq_iff
103
 
104
- instance : semilinear_map_class (M ≃ₛₗ[σ] M₂) σ M M₂ :=
105
  { coe := linear_equiv.to_fun,
106
- coe_injective' := λ f g h, to_linear_map_injective (fun_like.coe_injective h),
 
 
 
107
  map_add := map_add',
108
  map_smulₛₗ := map_smul' }
109
 
 
45
  set_option old_structure_cmd true
46
 
47
  /-- A linear equivalence is an invertible linear map. -/
48
+ @[nolint has_nonempty_instance]
49
  structure linear_equiv {R : Type*} {S : Type*} [semiring R] [semiring S] (σ : R →+* S)
50
  {σ' : S →+* R} [ring_hom_inv_pair σ σ'] [ring_hom_inv_pair σ' σ]
51
  (M : Type*) (M₂ : Type*)
52
  [add_comm_monoid M] [add_comm_monoid M₂] [module R M] [module S M₂]
53
  extends linear_map σ M M₂, M ≃+ M₂
 
54
 
55
  attribute [nolint doc_blame] linear_equiv.to_linear_map
56
  attribute [nolint doc_blame] linear_equiv.to_add_equiv
 
59
  notation M ` ≃ₗ[`:50 R `] ` M₂ := linear_equiv (ring_hom.id R) M M₂
60
  notation M ` ≃ₗ⋆[`:50 R `] ` M₂ := linear_equiv (star_ring_end R) M M₂
61
 
62
+ /-- `semilinear_equiv_class F σ M M₂` asserts `F` is a type of bundled `σ`-semilinear equivs
63
+ `M → M₂`.
64
+
65
+ See also `linear_equiv_class F R M M₂` for the case where `σ` is the identity map on `R`.
66
+
67
+ A map `f` between an `R`-module and an `S`-module over a ring homomorphism `σ : R →+* S`
68
+ is semilinear if it satisfies the two properties `f (x + y) = f x + f y` and
69
+ `f (c • x) = (σ c) • f x`. -/
70
+ class semilinear_equiv_class (F : Type*) {R S : out_param Type*} [semiring R] [semiring S]
71
+ (σ : out_param $ R →+* S) {σ' : out_param $ S →+* R}
72
+ [ring_hom_inv_pair σ σ'] [ring_hom_inv_pair σ' σ] (M M₂ : out_param Type*)
73
+ [add_comm_monoid M] [add_comm_monoid M₂] [module R M] [module S M₂]
74
+ extends add_equiv_class F M M₂ :=
75
+ (map_smulₛₗ : ∀ (f : F) (r : R) (x : M), f (r • x) = (σ r) • f x)
76
+
77
+ -- `R, S, σ, σ'` become metavars, but it's OK since they are outparams.
78
+ attribute [nolint dangerous_instance] semilinear_equiv_class.to_add_equiv_class
79
+
80
+ /-- `linear_equiv_class F R M M₂` asserts `F` is a type of bundled `R`-linear equivs `M → M₂`.
81
+ This is an abbreviation for `semilinear_equiv_class F (ring_hom.id R) M M₂`.
82
+ -/
83
+ abbreviation linear_equiv_class (F : Type*) (R M M₂ : out_param Type*)
84
+ [semiring R] [add_comm_monoid M] [add_comm_monoid M₂] [module R M] [module R M₂] :=
85
+ semilinear_equiv_class F (ring_hom.id R) M M₂
86
+
87
+ end
88
+
89
+ namespace semilinear_equiv_class
90
+
91
+ variables (F : Type*) [semiring R] [semiring S]
92
+ variables [add_comm_monoid M] [add_comm_monoid M₁] [add_comm_monoid M₂]
93
+ variables [module R M] [module S M₂] {σ : R →+* S} {σ' : S →+* R}
94
+
95
+ -- `σ'` becomes a metavariable, but it's OK since it's an outparam
96
+ @[priority 100, nolint dangerous_instance]
97
+ instance [ring_hom_inv_pair σ σ'] [ring_hom_inv_pair σ' σ] [s : semilinear_equiv_class F σ M M₂] :
98
+ semilinear_map_class F σ M M₂ :=
99
+ { coe := (coe : F → M → M₂),
100
+ coe_injective' := @fun_like.coe_injective F _ _ _,
101
+ ..s }
102
+
103
+ end semilinear_equiv_class
104
+
105
  namespace linear_equiv
106
 
107
  section add_comm_monoid
 
143
  (e₁ : M →ₛₗ[σ] M₂) = e₂ ↔ e₁ = e₂ :=
144
  to_linear_map_injective.eq_iff
145
 
146
+ instance : semilinear_equiv_class (M ≃ₛₗ[σ] M₂) σ M M₂ :=
147
  { coe := linear_equiv.to_fun,
148
+ inv := linear_equiv.inv_fun,
149
+ coe_injective' := λ f g h₁ h₂, by { cases f, cases g, congr' },
150
+ left_inv := linear_equiv.left_inv,
151
+ right_inv := linear_equiv.right_inv,
152
  map_add := map_add',
153
  map_smulₛₗ := map_smul' }
154
 
formal/lean/mathlib/algebra/module/linear_map.lean CHANGED
@@ -811,12 +811,26 @@ instance _root_.module.End.semiring : semiring (module.End R M) :=
811
  zero_mul := zero_comp,
812
  left_distrib := λ f g h, comp_add _ _ _,
813
  right_distrib := λ f g h, add_comp _ _ _,
 
 
 
814
  .. add_monoid_with_one.unary,
815
  .. _root_.module.End.monoid,
816
  .. linear_map.add_comm_monoid }
817
 
 
 
 
 
818
  instance _root_.module.End.ring : ring (module.End R N₁) :=
819
- { ..module.End.semiring, ..linear_map.add_comm_group }
 
 
 
 
 
 
 
820
 
821
  section
822
  variables [monoid S] [distrib_mul_action S M] [smul_comm_class R S M]
@@ -930,4 +944,10 @@ def module_End_self_op : R ≃+* module.End Rᵐᵒᵖ R :=
930
  right_inv := λ f, linear_map.ext_ring_op $ mul_one _,
931
  ..module.to_module_End _ _ }
932
 
 
 
 
 
 
 
933
  end module
 
811
  zero_mul := zero_comp,
812
  left_distrib := λ f g h, comp_add _ _ _,
813
  right_distrib := λ f g h, add_comp _ _ _,
814
+ nat_cast := λ n, n • 1,
815
+ nat_cast_zero := add_monoid.nsmul_zero' _,
816
+ nat_cast_succ := λ n, (add_monoid.nsmul_succ' n 1).trans (add_comm _ _),
817
  .. add_monoid_with_one.unary,
818
  .. _root_.module.End.monoid,
819
  .. linear_map.add_comm_monoid }
820
 
821
+ /-- See also `module.End.nat_cast_def`. -/
822
+ @[simp] lemma _root_.module.End.nat_cast_apply (n : ℕ) (m : M) :
823
+ (↑n : module.End R M) m = n • m := rfl
824
+
825
  instance _root_.module.End.ring : ring (module.End R N₁) :=
826
+ { int_cast := λ z, z • 1,
827
+ int_cast_of_nat := of_nat_zsmul _,
828
+ int_cast_neg_succ_of_nat := zsmul_neg_succ_of_nat _,
829
+ ..module.End.semiring, ..linear_map.add_comm_group }
830
+
831
+ /-- See also `module.End.int_cast_def`. -/
832
+ @[simp] lemma _root_.module.End.int_cast_apply (z : ℤ) (m : N₁) :
833
+ (↑z : module.End R N₁) m = z • m := rfl
834
 
835
  section
836
  variables [monoid S] [distrib_mul_action S M] [smul_comm_class R S M]
 
944
  right_inv := λ f, linear_map.ext_ring_op $ mul_one _,
945
  ..module.to_module_End _ _ }
946
 
947
+ lemma End.nat_cast_def (n : ℕ) [add_comm_monoid N₁] [module R N₁] :
948
+ (↑n : module.End R N₁) = module.to_module_End R N₁ n := rfl
949
+
950
+ lemma End.int_cast_def (z : ℤ) [add_comm_group N₁] [module R N₁] :
951
+ (↑z : module.End R N₁) = module.to_module_End R N₁ z := rfl
952
+
953
  end module
formal/lean/mathlib/algebra/module/localized_module.lean CHANGED
@@ -70,7 +70,7 @@ instance r.setoid : setoid (M × S) :=
70
  If `S` is a multiplicative subset of a ring `R` and `M` an `R`-module, then
71
  we can localize `M` by `S`.
72
  -/
73
- @[nolint has_inhabited_instance]
74
  def _root_.localized_module : Type (max u v) := quotient (r.setoid S M)
75
 
76
  section
 
70
  If `S` is a multiplicative subset of a ring `R` and `M` an `R`-module, then
71
  we can localize `M` by `S`.
72
  -/
73
+ @[nolint has_nonempty_instance]
74
  def _root_.localized_module : Type (max u v) := quotient (r.setoid S M)
75
 
76
  section
formal/lean/mathlib/algebra/monoid_algebra/basic.lean CHANGED
@@ -183,6 +183,8 @@ instance : non_assoc_semiring (monoid_algebra k G) :=
183
  single_zero, sum_zero, add_zero, mul_one, sum_single],
184
  ..monoid_algebra.non_unital_non_assoc_semiring }
185
 
 
 
186
  end mul_one_class
187
 
188
  /-! #### Semiring structure -/
@@ -244,11 +246,16 @@ instance [ring k] [semigroup G] : non_unital_ring (monoid_algebra k G) :=
244
  .. monoid_algebra.non_unital_semiring }
245
 
246
  instance [ring k] [mul_one_class G] : non_assoc_ring (monoid_algebra k G) :=
247
- { .. monoid_algebra.add_comm_group,
 
 
 
248
  .. monoid_algebra.non_assoc_semiring }
249
 
 
 
250
  instance [ring k] [monoid G] : ring (monoid_algebra k G) :=
251
- { .. monoid_algebra.non_unital_non_assoc_ring,
252
  .. monoid_algebra.semiring }
253
 
254
  instance [comm_ring k] [comm_semigroup G] : non_unital_comm_ring (monoid_algebra k G) :=
@@ -318,8 +325,8 @@ lemma mul_apply_antidiagonal [has_mul G] (f g : monoid_algebra k G) (x : G) (s :
318
  let F : G × G → k := λ p, by classical; exact if p.1 * p.2 = x then f p.1 * g p.2 else 0 in
319
  calc (f * g) x = (∑ a₁ in f.support, ∑ a₂ in g.support, F (a₁, a₂)) :
320
  mul_apply f g x
321
- ... = ∑ p in f.support.product g.support, F p : finset.sum_product.symm
322
- ... = ∑ p in (f.support.product g.support).filter (λ p : G × G, p.1 * p.2 = x), f p.1 * g p.2 :
323
  (finset.sum_filter _ _).symm
324
  ... = ∑ p in s.filter (λ p : G × G, p.1 ∈ f.support ∧ p.2 ∈ g.support), f p.1 * g p.2 :
325
  sum_congr (by { ext, simp only [mem_filter, mem_product, hs, and_comm] }) (λ _ _, rfl)
@@ -1029,6 +1036,8 @@ instance : non_assoc_semiring (add_monoid_algebra k G) :=
1029
  single_zero, sum_zero, add_zero, mul_one, sum_single],
1030
  .. add_monoid_algebra.non_unital_non_assoc_semiring }
1031
 
 
 
1032
  end mul_one_class
1033
 
1034
  /-! #### Semiring structure -/
@@ -1091,11 +1100,17 @@ instance [ring k] [add_semigroup G] : non_unital_ring (add_monoid_algebra k G) :
1091
  .. add_monoid_algebra.non_unital_semiring }
1092
 
1093
  instance [ring k] [add_zero_class G] : non_assoc_ring (add_monoid_algebra k G) :=
1094
- { .. add_monoid_algebra.add_comm_group,
 
 
 
1095
  .. add_monoid_algebra.non_assoc_semiring }
1096
 
 
 
 
1097
  instance [ring k] [add_monoid G] : ring (add_monoid_algebra k G) :=
1098
- { .. add_monoid_algebra.non_unital_non_assoc_ring,
1099
  .. add_monoid_algebra.semiring }
1100
 
1101
  instance [comm_ring k] [add_comm_semigroup G] : non_unital_comm_ring (add_monoid_algebra k G) :=
 
183
  single_zero, sum_zero, add_zero, mul_one, sum_single],
184
  ..monoid_algebra.non_unital_non_assoc_semiring }
185
 
186
+ lemma nat_cast_def (n : ℕ) : (n : monoid_algebra k G) = single 1 n := rfl
187
+
188
  end mul_one_class
189
 
190
  /-! #### Semiring structure -/
 
246
  .. monoid_algebra.non_unital_semiring }
247
 
248
  instance [ring k] [mul_one_class G] : non_assoc_ring (monoid_algebra k G) :=
249
+ { int_cast := λ z, single 1 (z : k),
250
+ int_cast_of_nat := λ n, by simpa,
251
+ int_cast_neg_succ_of_nat := λ n, by simpa,
252
+ .. monoid_algebra.add_comm_group,
253
  .. monoid_algebra.non_assoc_semiring }
254
 
255
+ lemma int_cast_def [ring k] [mul_one_class G] (z : ℤ) : (z : monoid_algebra k G) = single 1 z := rfl
256
+
257
  instance [ring k] [monoid G] : ring (monoid_algebra k G) :=
258
+ { .. monoid_algebra.non_assoc_ring,
259
  .. monoid_algebra.semiring }
260
 
261
  instance [comm_ring k] [comm_semigroup G] : non_unital_comm_ring (monoid_algebra k G) :=
 
325
  let F : G × G → k := λ p, by classical; exact if p.1 * p.2 = x then f p.1 * g p.2 else 0 in
326
  calc (f * g) x = (∑ a₁ in f.support, ∑ a₂ in g.support, F (a₁, a₂)) :
327
  mul_apply f g x
328
+ ... = ∑ p in f.support ×ˢ g.support, F p : finset.sum_product.symm
329
+ ... = ∑ p in (f.support ×ˢ g.support).filter (λ p : G × G, p.1 * p.2 = x), f p.1 * g p.2 :
330
  (finset.sum_filter _ _).symm
331
  ... = ∑ p in s.filter (λ p : G × G, p.1 ∈ f.support ∧ p.2 ∈ g.support), f p.1 * g p.2 :
332
  sum_congr (by { ext, simp only [mem_filter, mem_product, hs, and_comm] }) (λ _ _, rfl)
 
1036
  single_zero, sum_zero, add_zero, mul_one, sum_single],
1037
  .. add_monoid_algebra.non_unital_non_assoc_semiring }
1038
 
1039
+ lemma nat_cast_def (n : ℕ) : (n : add_monoid_algebra k G) = single 0 n := rfl
1040
+
1041
  end mul_one_class
1042
 
1043
  /-! #### Semiring structure -/
 
1100
  .. add_monoid_algebra.non_unital_semiring }
1101
 
1102
  instance [ring k] [add_zero_class G] : non_assoc_ring (add_monoid_algebra k G) :=
1103
+ { int_cast := λ z, single 0 (z : k),
1104
+ int_cast_of_nat := λ n, by simpa,
1105
+ int_cast_neg_succ_of_nat := λ n, by simpa,
1106
+ .. add_monoid_algebra.add_comm_group,
1107
  .. add_monoid_algebra.non_assoc_semiring }
1108
 
1109
+ lemma int_cast_def [ring k] [add_zero_class G] (z : ℤ) :
1110
+ (z : add_monoid_algebra k G) = single 0 z := rfl
1111
+
1112
  instance [ring k] [add_monoid G] : ring (add_monoid_algebra k G) :=
1113
+ { .. add_monoid_algebra.non_assoc_ring,
1114
  .. add_monoid_algebra.semiring }
1115
 
1116
  instance [comm_ring k] [add_comm_semigroup G] : non_unital_comm_ring (add_monoid_algebra k G) :=
formal/lean/mathlib/algebra/monoid_algebra/degree.lean ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /-
2
+ Copyright (c) 2022 Damiano Testa. All rights reserved.
3
+ Released under Apache 2.0 license as described in the file LICENSE.
4
+ Authors: Damiano Testa
5
+ -/
6
+ import algebra.monoid_algebra.basic
7
+
8
+ /-!
9
+ # Lemmas about the `sup` and `inf` of the support of `add_monoid_algebra`
10
+
11
+ ## TODO
12
+ The current plan is to state and prove lemmas about `finset.sup (finsupp.support f) D` with a
13
+ "generic" degree/weight function `D` from the grading Type `A` to a somewhat ordered Type `B`.
14
+
15
+ Next, the general lemmas get specialized for some yet-to-be-defined `degree`s.
16
+ -/
17
+
18
+ variables {R A T B ι : Type*}
19
+
20
+ namespace add_monoid_algebra
21
+ open_locale classical big_operators
22
+
23
+ /-! ### Results about the `finset.sup` and `finset.inf` of `finsupp.support` -/
24
+
25
+ section general_results_assuming_semilattice_sup
26
+ variables [semilattice_sup B] [order_bot B] [semilattice_inf T] [order_top T]
27
+
28
+ section semiring
29
+ variables [semiring R]
30
+
31
+ section explicit_degrees
32
+ /-!
33
+
34
+ In this section, we use `degb` and `degt` to denote "degree functions" on `A` with values in
35
+ a type with *b*ot or *t*op respectively.
36
+ -/
37
+ variables (degb : A → B) (degt : A → T) (f g : add_monoid_algebra R A)
38
+
39
+ lemma sup_support_add_le : (f + g).support.sup degb ≤ (f.support.sup degb) ⊔ (g.support.sup degb) :=
40
+ (finset.sup_mono finsupp.support_add).trans_eq finset.sup_union
41
+
42
+ lemma le_inf_support_add : f.support.inf degt ⊓ g.support.inf degt ≤ (f + g).support.inf degt :=
43
+ sup_support_add_le (λ a : A, order_dual.to_dual (degt a)) f g
44
+
45
+ end explicit_degrees
46
+
47
+ section add_only
48
+ variables [has_add A] [has_add B] [has_add T]
49
+ [covariant_class B B (+) (≤)] [covariant_class B B (function.swap (+)) (≤)]
50
+ [covariant_class T T (+) (≤)] [covariant_class T T (function.swap (+)) (≤)]
51
+
52
+ lemma sup_support_mul_le {degb : A → B} (degbm : ∀ {a b}, degb (a + b) ≤ degb a + degb b)
53
+ (f g : add_monoid_algebra R A) :
54
+ (f * g).support.sup degb ≤ f.support.sup degb + g.support.sup degb :=
55
+ begin
56
+ refine (finset.sup_mono $ support_mul _ _).trans _,
57
+ simp_rw [finset.sup_bUnion, finset.sup_singleton],
58
+ refine (finset.sup_le $ λ fd fds, finset.sup_le $ λ gd gds, degbm.trans $ add_le_add _ _);
59
+ exact finset.le_sup ‹_›,
60
+ end
61
+
62
+ lemma le_inf_support_mul {degt : A → T} (degtm : ∀ {a b}, degt a + degt b ≤ degt (a + b))
63
+ (f g : add_monoid_algebra R A) :
64
+ f.support.inf degt + g.support.inf degt ≤ (f * g).support.inf degt :=
65
+ order_dual.of_dual_le_of_dual.mpr $
66
+ sup_support_mul_le (λ a b, order_dual.of_dual_le_of_dual.mp degtm) f g
67
+
68
+ end add_only
69
+
70
+ section add_monoids
71
+ variables [add_monoid A]
72
+ [add_monoid B] [covariant_class B B (+) (≤)] [covariant_class B B (function.swap (+)) (≤)]
73
+ [add_monoid T] [covariant_class T T (+) (≤)] [covariant_class T T (function.swap (+)) (≤)]
74
+ {degb : A → B} {degt : A → T}
75
+
76
+ lemma sup_support_list_prod_le (degb0 : degb 0 ≤ 0)
77
+ (degbm : ∀ a b, degb (a + b) ≤ degb a + degb b) :
78
+ ∀ l : list (add_monoid_algebra R A),
79
+ l.prod.support.sup degb ≤ (l.map (λ f : add_monoid_algebra R A, f.support.sup degb)).sum
80
+ | [] := begin
81
+ rw [list.map_nil, finset.sup_le_iff, list.prod_nil, list.sum_nil],
82
+ exact λ a ha, by rwa [finset.mem_singleton.mp (finsupp.support_single_subset ha)]
83
+ end
84
+ | (f::fs) := begin
85
+ rw [list.prod_cons, list.map_cons, list.sum_cons],
86
+ exact (sup_support_mul_le degbm _ _).trans (add_le_add_left (sup_support_list_prod_le _) _)
87
+ end
88
+
89
+ lemma le_inf_support_list_prod (degt0 : 0 ≤ degt 0) (degtm : ∀ a b, degt a + degt b ≤ degt (a + b))
90
+ (l : list (add_monoid_algebra R A)) :
91
+ (l.map (λ f : add_monoid_algebra R A, f.support.inf degt)).sum ≤ l.prod.support.inf degt :=
92
+ order_dual.of_dual_le_of_dual.mpr $ sup_support_list_prod_le
93
+ (order_dual.of_dual_le_of_dual.mp degt0) (λ a b, order_dual.of_dual_le_of_dual.mp (degtm _ _)) l
94
+
95
+ lemma sup_support_pow_le (degb0 : degb 0 ≤ 0) (degbm : ∀ a b, degb (a + b) ≤ degb a + degb b)
96
+ (n : ℕ) (f : add_monoid_algebra R A) :
97
+ (f ^ n).support.sup degb ≤ n • (f.support.sup degb) :=
98
+ begin
99
+ rw [← list.prod_repeat, ←list.sum_repeat],
100
+ refine (sup_support_list_prod_le degb0 degbm _).trans_eq _,
101
+ rw list.map_repeat,
102
+ end
103
+
104
+ lemma le_inf_support_pow (degt0 : 0 ≤ degt 0) (degtm : ∀ a b, degt a + degt b ≤ degt (a + b))
105
+ (n : ℕ) (f : add_monoid_algebra R A) :
106
+ n • (f.support.inf degt) ≤ (f ^ n).support.inf degt :=
107
+ order_dual.of_dual_le_of_dual.mpr $ sup_support_pow_le (order_dual.of_dual_le_of_dual.mp degt0)
108
+ (λ a b, order_dual.of_dual_le_of_dual.mp (degtm _ _)) n f
109
+
110
+ end add_monoids
111
+
112
+ end semiring
113
+
114
+ section commutative_lemmas
115
+ variables [comm_semiring R] [add_comm_monoid A]
116
+ [add_comm_monoid B] [covariant_class B B (+) (≤)] [covariant_class B B (function.swap (+)) (≤)]
117
+ [add_comm_monoid T] [covariant_class T T (+) (≤)] [covariant_class T T (function.swap (+)) (≤)]
118
+ {degb : A → B} {degt : A → T}
119
+
120
+ lemma sup_support_multiset_prod_le
121
+ (degb0 : degb 0 ≤ 0) (degbm : ∀ a b, degb (a + b) ≤ degb a + degb b)
122
+ (m : multiset (add_monoid_algebra R A)) :
123
+ m.prod.support.sup degb ≤ (m.map (λ f : add_monoid_algebra R A, f.support.sup degb)).sum :=
124
+ begin
125
+ induction m using quot.induction_on,
126
+ rw [multiset.quot_mk_to_coe'', multiset.coe_map, multiset.coe_sum, multiset.coe_prod],
127
+ exact sup_support_list_prod_le degb0 degbm m,
128
+ end
129
+
130
+ lemma le_inf_support_multiset_prod
131
+ (degt0 : 0 ≤ degt 0) (degtm : ∀ a b, degt a + degt b ≤ degt (a + b))
132
+ (m : multiset (add_monoid_algebra R A)) :
133
+ (m.map (λ f : add_monoid_algebra R A, f.support.inf degt)).sum ≤ m.prod.support.inf degt :=
134
+ order_dual.of_dual_le_of_dual.mpr $
135
+ sup_support_multiset_prod_le (order_dual.of_dual_le_of_dual.mp degt0)
136
+ (λ a b, order_dual.of_dual_le_of_dual.mp (degtm _ _)) m
137
+
138
+ lemma sup_support_finset_prod_le
139
+ (degb0 : degb 0 ≤ 0) (degbm : ∀ a b, degb (a + b) ≤ degb a + degb b)
140
+ (s : finset ι) (f : ι → add_monoid_algebra R A) :
141
+ (∏ i in s, f i).support.sup degb ≤ ∑ i in s, (f i).support.sup degb :=
142
+ (sup_support_multiset_prod_le degb0 degbm _).trans_eq $ congr_arg _ $ multiset.map_map _ _ _
143
+
144
+ lemma le_inf_support_finset_prod
145
+ (degt0 : 0 ≤ degt 0) (degtm : ∀ a b, degt a + degt b ≤ degt (a + b))
146
+ (s : finset ι) (f : ι → add_monoid_algebra R A) :
147
+ ∑ i in s, (f i).support.inf degt ≤ (∏ i in s, f i).support.inf degt :=
148
+ le_of_eq_of_le (by rw [multiset.map_map]; refl) (le_inf_support_multiset_prod degt0 degtm _)
149
+
150
+ end commutative_lemmas
151
+
152
+ end general_results_assuming_semilattice_sup
153
+
154
+ end add_monoid_algebra
formal/lean/mathlib/algebra/order/archimedean.lean CHANGED
@@ -109,26 +109,13 @@ let ⟨n, h⟩ := archimedean.arch x hy in
109
  (add_nonneg zero_le_two hy.le) _
110
  ... = (y + 1) ^ n : by rw [add_comm]⟩
111
 
112
- section linear_ordered_ring
113
- variables [linear_ordered_ring α] [archimedean α]
114
 
115
  lemma pow_unbounded_of_one_lt (x : α) {y : α} (hy1 : 1 < y) :
116
  ∃ n : ℕ, x < y ^ n :=
117
  sub_add_cancel y 1 ▸ add_one_pow_unbounded_of_pos _ (sub_pos.2 hy1)
118
 
119
- /-- Every x greater than or equal to 1 is between two successive
120
- natural-number powers of every y greater than one. -/
121
- lemma exists_nat_pow_near {x : α} {y : α} (hx : 1 ≤ x) (hy : 1 < y) :
122
- ∃ n : ℕ, y ^ n ≤ x ∧ x < y ^ (n + 1) :=
123
- have h : ∃ n : ℕ, x < y ^ n, from pow_unbounded_of_one_lt _ hy,
124
- by classical; exact let n := nat.find h in
125
- have hn : x < y ^ n, from nat.find_spec h,
126
- have hnp : 0 < n, from pos_iff_ne_zero.2 (λ hn0,
127
- by rw [hn0, pow_zero] at hn; exact (not_le_of_gt hn hx)),
128
- have hnsp : nat.pred n + 1 = n, from nat.succ_pred_eq_of_pos hnp,
129
- have hltn : nat.pred n < n, from nat.pred_lt (ne_of_gt hnp),
130
- ⟨nat.pred n, le_of_not_lt (nat.find_min h hltn), by rwa hnsp⟩
131
-
132
  theorem exists_int_gt (x : α) : ∃ n : ℤ, x < n :=
133
  let ⟨n, h⟩ := exists_nat_gt x in ⟨n, by rwa int.cast_coe_nat⟩
134
 
@@ -149,6 +136,24 @@ begin
149
  exact ⟨λ h, le_trans (int.cast_le.2 h) h₁, h₂ z⟩,
150
  end
151
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  end linear_ordered_ring
153
 
154
  section linear_ordered_field
@@ -276,6 +281,22 @@ archimedean_iff_nat_lt.trans
276
  λ H x, let ⟨n, h⟩ := H x in ⟨n+1,
277
  lt_of_le_of_lt h (nat.cast_lt.2 (lt_add_one _))⟩⟩
278
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
279
  lemma archimedean_iff_rat_lt : archimedean α ↔ ∀ x : α, ∃ q : ℚ, x < q :=
280
  ⟨@exists_rat_gt α _,
281
  λ H, archimedean_iff_nat_lt.2 $ λ x,
@@ -308,3 +329,10 @@ noncomputable def archimedean.floor_ring (α) [linear_ordered_ring α] [archimed
308
  floor_ring α :=
309
  floor_ring.of_floor α (λ a, classical.some (exists_floor a))
310
  (λ z a, (classical.some_spec (exists_floor a) z).symm)
 
 
 
 
 
 
 
 
109
  (add_nonneg zero_le_two hy.le) _
110
  ... = (y + 1) ^ n : by rw [add_comm]⟩
111
 
112
+ section ordered_ring
113
+ variables [ordered_ring α] [nontrivial α] [archimedean α]
114
 
115
  lemma pow_unbounded_of_one_lt (x : α) {y : α} (hy1 : 1 < y) :
116
  ∃ n : ℕ, x < y ^ n :=
117
  sub_add_cancel y 1 ▸ add_one_pow_unbounded_of_pos _ (sub_pos.2 hy1)
118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  theorem exists_int_gt (x : α) : ∃ n : ℤ, x < n :=
120
  let ⟨n, h⟩ := exists_nat_gt x in ⟨n, by rwa int.cast_coe_nat⟩
121
 
 
136
  exact ⟨λ h, le_trans (int.cast_le.2 h) h₁, h₂ z⟩,
137
  end
138
 
139
+ end ordered_ring
140
+
141
+ section linear_ordered_ring
142
+ variables [linear_ordered_ring α] [archimedean α]
143
+
144
+ /-- Every x greater than or equal to 1 is between two successive
145
+ natural-number powers of every y greater than one. -/
146
+ lemma exists_nat_pow_near {x : α} {y : α} (hx : 1 ≤ x) (hy : 1 < y) :
147
+ ∃ n : ℕ, y ^ n ≤ x ∧ x < y ^ (n + 1) :=
148
+ have h : ∃ n : ℕ, x < y ^ n, from pow_unbounded_of_one_lt _ hy,
149
+ by classical; exact let n := nat.find h in
150
+ have hn : x < y ^ n, from nat.find_spec h,
151
+ have hnp : 0 < n, from pos_iff_ne_zero.2 (λ hn0,
152
+ by rw [hn0, pow_zero] at hn; exact (not_le_of_gt hn hx)),
153
+ have hnsp : nat.pred n + 1 = n, from nat.succ_pred_eq_of_pos hnp,
154
+ have hltn : nat.pred n < n, from nat.pred_lt (ne_of_gt hnp),
155
+ ⟨nat.pred n, le_of_not_lt (nat.find_min h hltn), by rwa hnsp⟩
156
+
157
  end linear_ordered_ring
158
 
159
  section linear_ordered_field
 
281
  λ H x, let ⟨n, h⟩ := H x in ⟨n+1,
282
  lt_of_le_of_lt h (nat.cast_lt.2 (lt_add_one _))⟩⟩
283
 
284
+ lemma archimedean_iff_int_lt : archimedean α ↔ ∀ x : α, ∃ n : ℤ, x < n :=
285
+ ⟨@exists_int_gt α _ _,
286
+ begin
287
+ rw archimedean_iff_nat_lt,
288
+ intros h x,
289
+ obtain ⟨n, h⟩ := h x,
290
+ refine ⟨n.to_nat, h.trans_le _⟩,
291
+ exact_mod_cast int.le_to_nat _,
292
+ end⟩
293
+
294
+ lemma archimedean_iff_int_le : archimedean α ↔ ∀ x : α, ∃ n : ℤ, x ≤ n :=
295
+ archimedean_iff_int_lt.trans
296
+ ⟨λ H x, (H x).imp $ λ _, le_of_lt,
297
+ λ H x, let ⟨n, h⟩ := H x in ⟨n+1,
298
+ lt_of_le_of_lt h (int.cast_lt.2 (lt_add_one _))⟩⟩
299
+
300
  lemma archimedean_iff_rat_lt : archimedean α ↔ ∀ x : α, ∃ q : ℚ, x < q :=
301
  ⟨@exists_rat_gt α _,
302
  λ H, archimedean_iff_nat_lt.2 $ λ x,
 
329
  floor_ring α :=
330
  floor_ring.of_floor α (λ a, classical.some (exists_floor a))
331
  (λ z a, (classical.some_spec (exists_floor a) z).symm)
332
+
333
+ /-- A linear ordered field that is a floor ring is archimedean. -/
334
+ lemma floor_ring.archimedean (α) [linear_ordered_field α] [floor_ring α] : archimedean α :=
335
+ begin
336
+ rw archimedean_iff_int_le,
337
+ exact λ x, ⟨⌈x⌉, int.le_ceil x⟩
338
+ end