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

Commit ffb99a3

Browse files
urkudgebner
andcommitted
chore(algebra/group/type_tags): add additive.to_mul etc (#2363)
Don't make `additive` and `multiplicative` irreducible (yet?) because it breaks compilation here and there. Also prove that homomorphisms from `ℕ`, `ℤ` and their `multiplicative` versions are defined by the image of `1`. Co-authored-by: Gabriel Ebner <gebner@gebner.org>
1 parent 8b21231 commit ffb99a3

File tree

3 files changed

+153
-63
lines changed

3 files changed

+153
-63
lines changed

src/algebra/group/type_tags.lean

Lines changed: 80 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,54 @@ def additive (α : Type*) := α
2727
multiplicative structure. -/
2828
def multiplicative (α : Type*) := α
2929

30-
instance [inhabited α] : inhabited (additive α) := ⟨(default _ : α)⟩
31-
instance [inhabited α] : inhabited (multiplicative α) := ⟨(default _ : α)⟩
30+
/-- Reinterpret `x : α` as an element of `additive α`. -/
31+
def additive.of_mul (x : α) : additive α := x
32+
33+
/-- Reinterpret `x : additive α` as an element of `α`. -/
34+
def additive.to_mul (x : additive α) : α := x
35+
36+
lemma of_mul_inj : function.injective (@additive.of_mul α) := λ _ _, id
37+
lemma to_mul_inj : function.injective (@additive.to_mul α) := λ _ _, id
38+
39+
/-- Reinterpret `x : α` as an element of `multiplicative α`. -/
40+
def multiplicative.of_add (x : α) : multiplicative α := x
41+
42+
/-- Reinterpret `x : multiplicative α` as an element of `α`. -/
43+
def multiplicative.to_add (x : multiplicative α) : α := x
44+
45+
lemma of_add_inj : function.injective (@multiplicative.of_add α) := λ _ _, id
46+
lemma to_add_inj : function.injective (@multiplicative.to_add α) := λ _ _, id
47+
48+
@[simp] lemma to_add_of_add (x : α) : (multiplicative.of_add x).to_add = x := rfl
49+
@[simp] lemma of_add_to_add (x : multiplicative α) : multiplicative.of_add x.to_add = x := rfl
50+
51+
@[simp] lemma to_mul_of_mul (x : α) : (additive.of_mul x).to_mul = x := rfl
52+
@[simp] lemma of_mul_to_mul (x : additive α) : additive.of_mul x.to_mul = x := rfl
53+
54+
instance [inhabited α] : inhabited (additive α) := ⟨additive.of_mul (default α)⟩
55+
instance [inhabited α] : inhabited (multiplicative α) := ⟨multiplicative.of_add (default α)⟩
3256

3357
instance additive.has_add [has_mul α] : has_add (additive α) :=
34-
{ add := ((*) : α → α → α) }
58+
{ add := λ x y, additive.of_mul (x.to_mul * y.to_mul) }
3559

3660
instance [has_add α] : has_mul (multiplicative α) :=
37-
{ mul := ((+) : α → α → α) }
61+
{ mul := λ x y, multiplicative.of_add (x.to_add + y.to_add) }
62+
63+
@[simp] lemma of_add_add [has_add α] (x y : α) :
64+
multiplicative.of_add (x + y) = multiplicative.of_add x * multiplicative.of_add y :=
65+
rfl
66+
67+
@[simp] lemma to_add_mul [has_add α] (x y : multiplicative α) :
68+
(x * y).to_add = x.to_add + y.to_add :=
69+
rfl
70+
71+
@[simp] lemma of_mul_mul [has_mul α] (x y : α) :
72+
additive.of_mul (x * y) = additive.of_mul x + additive.of_mul y :=
73+
rfl
74+
75+
@[simp] lemma to_mul_add [has_mul α] (x y : additive α) :
76+
(x + y).to_mul = x.to_mul * y.to_mul :=
77+
rfl
3878

3979
instance [semigroup α] : add_semigroup (additive α) :=
4080
{ add_assoc := @mul_assoc α _,
@@ -68,43 +108,63 @@ instance [add_right_cancel_semigroup α] : right_cancel_semigroup (multiplicativ
68108
{ mul_right_cancel := @add_right_cancel _ _,
69109
..multiplicative.semigroup }
70110

111+
instance [has_one α] : has_zero (additive α) := ⟨additive.of_mul 1
112+
113+
@[simp] lemma of_mul_one [has_one α] : @additive.of_mul α 1 = 0 := rfl
114+
115+
@[simp] lemma to_mul_zero [has_one α] : (0 : additive α).to_mul = 1 := rfl
116+
117+
instance [has_zero α] : has_one (multiplicative α) := ⟨multiplicative.of_add 0
118+
119+
@[simp] lemma of_add_zero [has_zero α] : @multiplicative.of_add α 0 = 1 := rfl
120+
121+
@[simp] lemma to_add_one [has_zero α] : (1 : multiplicative α).to_add = 0 := rfl
122+
71123
instance [monoid α] : add_monoid (additive α) :=
72-
{ zero := (1 : α),
124+
{ zero := 0,
73125
zero_add := @one_mul _ _,
74126
add_zero := @mul_one _ _,
75127
..additive.add_semigroup }
76128

77129
instance [add_monoid α] : monoid (multiplicative α) :=
78-
{ one := (0 : α),
130+
{ one := 1,
79131
one_mul := @zero_add _ _,
80132
mul_one := @add_zero _ _,
81133
..multiplicative.semigroup }
82134

83135
instance [comm_monoid α] : add_comm_monoid (additive α) :=
84-
{ add_comm := @mul_comm α _,
85-
..additive.add_monoid }
136+
{ .. additive.add_monoid, .. additive.add_comm_semigroup }
86137

87138
instance [add_comm_monoid α] : comm_monoid (multiplicative α) :=
88-
{ mul_comm := @add_comm α _,
89-
..multiplicative.monoid }
139+
{ ..multiplicative.monoid, .. multiplicative.comm_semigroup }
140+
141+
instance [has_inv α] : has_neg (additive α) := ⟨λ x, multiplicative.of_add x.to_mul⁻¹⟩
142+
143+
@[simp] lemma of_mul_inv [has_inv α] (x : α) : additive.of_mul x⁻¹ = -(additive.of_mul x) := rfl
144+
145+
@[simp] lemma to_mul_neg [has_inv α] (x : additive α) : (-x).to_mul = x.to_mul⁻¹ := rfl
146+
147+
instance [has_neg α] : has_inv (multiplicative α) := ⟨λ x, additive.of_mul (-x.to_add)⟩
148+
149+
@[simp] lemma of_add_neg [has_neg α] (x : α) :
150+
multiplicative.of_add (-x) = (multiplicative.of_add x)⁻¹ := rfl
151+
152+
@[simp] lemma to_add_inv [has_neg α] (x : multiplicative α) :
153+
(x⁻¹).to_add = -x.to_add := rfl
90154

91155
instance [group α] : add_group (additive α) :=
92-
{ neg := @has_inv.inv α _,
93-
add_left_neg := @mul_left_inv _ _,
94-
..additive.add_monoid }
156+
{ add_left_neg := @mul_left_inv α _,
157+
.. additive.has_neg, .. additive.add_monoid }
95158

96159
instance [add_group α] : group (multiplicative α) :=
97-
{ inv := @has_neg.neg α _,
98-
mul_left_inv := @add_left_neg _ _,
99-
..multiplicative.monoid }
160+
{ mul_left_inv := @add_left_neg α _,
161+
.. multiplicative.has_inv, ..multiplicative.monoid }
100162

101163
instance [comm_group α] : add_comm_group (additive α) :=
102-
{ add_comm := @mul_comm α _,
103-
..additive.add_group }
164+
{ .. additive.add_group, .. additive.add_comm_monoid }
104165

105166
instance [add_comm_group α] : comm_group (multiplicative α) :=
106-
{ mul_comm := @add_comm α _,
107-
..multiplicative.group }
167+
{ .. multiplicative.group, .. multiplicative.comm_monoid }
108168

109169
/-- Reinterpret `f : α →+ β` as `multiplicative α →* multiplicative β`. -/
110170
def add_monoid_hom.to_multiplicative [add_monoid α] [add_monoid β] (f : α →+ β) :

src/algebra/group_power.lean

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Jeremy Avigad, Robert Y. Lewis
55
-/
66

7-
import data.int.basic
7+
import data.int.basic data.equiv.basic
88

99
/-!
1010
# Power operations on monoids and groups
@@ -23,8 +23,10 @@ We define instances of `has_pow M ℕ`, for monoids `M`, and `has_pow G ℤ` for
2323
We adopt the convention that `0^0 = 1`.
2424
-/
2525

26-
variables {M : Type*} {N : Type*} {G : Type*} {H : Type*} {A : Type*} {B : Type*}
27-
{R : Type*} {S : Type*}
26+
universes u v w x y z u₁ u₂
27+
28+
variables {M : Type u} {N : Type v} {G : Type w} {H : Type x} {A : Type y} {B : Type z}
29+
{R : Type u₁} {S : Type u₂}
2830

2931
/-- The power operation in a monoid. `a^n = a*a*...*a` n times. -/
3032
def monoid.pow [has_mul M] [has_one M] (a : M) : ℕ → M
@@ -668,3 +670,41 @@ end int
668670

669671
@[simp] lemma neg_square {α} [ring α] (z : α) : (-z)^2 = z^2 :=
670672
by simp [pow, monoid.pow]
673+
674+
@[simp] lemma pow_of_add [add_monoid A] (x : A) (n : ℕ) :
675+
multiplicative.of_add (n • x) = (multiplicative.of_add x)^n := rfl
676+
677+
@[simp] lemma gpow_of_add [add_group A] (x : A) (n : ℤ) :
678+
multiplicative.of_add (n •ℤ x) = (multiplicative.of_add x)^n := rfl
679+
680+
variables (M G A)
681+
682+
/-- Monoid homomorphisms from `multiplicative ℕ` are defined by the image
683+
of `multiplicative.of_add 1`. -/
684+
def powers_hom [monoid M] : M ≃ (multiplicative ℕ →* M) :=
685+
{ to_fun := λ x, ⟨λ n, x ^ n.to_add, pow_zero x, λ m n, pow_add x m n⟩,
686+
inv_fun := λ f, f (multiplicative.of_add 1),
687+
left_inv := pow_one,
688+
right_inv := λ f, monoid_hom.ext $ λ n, by { simp [← f.map_pow, ← pow_of_add] } }
689+
690+
/-- Monoid homomorphisms from `multiplicative ℤ` are defined by the image
691+
of `multiplicative.of_add 1`. -/
692+
def gpowers_hom [group G] : G ≃ (multiplicative ℤ →* G) :=
693+
{ to_fun := λ x, ⟨λ n, x ^ n.to_add, gpow_zero x, λ m n, gpow_add x m n⟩,
694+
inv_fun := λ f, f (multiplicative.of_add 1),
695+
left_inv := gpow_one,
696+
right_inv := λ f, monoid_hom.ext $ λ n, by { simp [← f.map_gpow, ← gpow_of_add] } }
697+
698+
/-- Additive homomorphisms from `ℕ` are defined by the image of `1`. -/
699+
def multiples_hom [add_monoid A] : A ≃ (ℕ →+ A) :=
700+
{ to_fun := λ x, ⟨λ n, n • x, add_monoid.zero_smul x, λ m n, add_monoid.add_smul _ _ _⟩,
701+
inv_fun := λ f, f 1,
702+
left_inv := add_monoid.one_smul,
703+
right_inv := λ f, add_monoid_hom.ext $ λ n, by simp [← f.map_smul] }
704+
705+
/-- Additive homomorphisms from `ℤ` are defined by the image of `1`. -/
706+
def gmultiples_hom [add_group A] : A ≃ (ℤ →+ A) :=
707+
{ to_fun := λ x, ⟨λ n, n •ℤ x, zero_gsmul x, λ m n, add_gsmul _ _ _⟩,
708+
inv_fun := λ f, f 1,
709+
left_inv := one_gsmul,
710+
right_inv := λ f, add_monoid_hom.ext $ λ n, by simp [← f.map_gsmul] }

src/group_theory/submonoid.lean

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -729,20 +729,6 @@ lemma closure_union (s t : set M) : closure (s ∪ t) = closure s ⊔ closure t
729729
lemma closure_Union {ι} (s : ι → set M) : closure (⋃ i, s i) = ⨆ i, closure (s i) :=
730730
(submonoid.gi M).gc.l_supr
731731

732-
/-- The submonoid generated by an element of a monoid equals the set of natural number powers of
733-
the element. -/
734-
lemma mem_closure_singleton {x y : M} : y ∈ closure ({x} : set M) ↔ ∃ n:ℕ, x^n=y :=
735-
begin
736-
refine ⟨λ hy, closure_induction hy _ _ _,
737-
λ ⟨n, hn⟩, hn ▸ pow_mem _ (subset_closure $ mem_singleton x) n⟩,
738-
{ intros y hy,
739-
rw [eq_of_mem_singleton hy],
740-
exact ⟨1, pow_one x⟩ },
741-
{ exact ⟨0, rfl⟩ },
742-
{ rintros _ _ ⟨n, rfl⟩ ⟨m, rfl⟩,
743-
exact ⟨n + m, pow_add x n m⟩ }
744-
end
745-
746732
@[to_additive]
747733
lemma mem_supr_of_directed {ι} [hι : nonempty ι] {S : ι → submonoid M} (hS : directed (≤) S)
748734
{x : M} :
@@ -896,32 +882,6 @@ def prod_equiv (s : submonoid M) (t : submonoid N) : s.prod t ≃* s × t :=
896882

897883
end submonoid
898884

899-
namespace add_submonoid
900-
901-
open set
902-
903-
lemma smul_mem (S : add_submonoid A) {x : A} (hx : x ∈ S) :
904-
∀ n : ℕ, add_monoid.smul n x ∈ S
905-
| 0 := S.zero_mem
906-
| (n+1) := S.add_mem hx (smul_mem n)
907-
908-
/-- The `add_submonoid` generated by an element of an `add_monoid` equals the set of
909-
natural number multiples of the element. -/
910-
lemma mem_closure_singleton {x y : A} :
911-
y ∈ closure ({x} : set A) ↔ ∃ n:ℕ, add_monoid.smul n x = y :=
912-
begin
913-
refine ⟨λ hy, closure_induction hy _ _ _,
914-
λ ⟨n, hn⟩, hn ▸ smul_mem _ (subset_closure $ mem_singleton x) n⟩,
915-
{ intros y hy,
916-
rw [eq_of_mem_singleton hy],
917-
exact ⟨1, add_monoid.one_smul x⟩ },
918-
{ exact ⟨0, rfl⟩ },
919-
{ rintros _ _ ⟨n, rfl⟩ ⟨m, rfl⟩,
920-
exact ⟨n + m, add_monoid.add_smul x n m⟩ }
921-
end
922-
923-
end add_submonoid
924-
925885
namespace monoid_hom
926886

927887
variables {N : Type*} {P : Type*} [monoid N] [monoid P] (S : submonoid M)
@@ -1056,6 +1016,15 @@ S.subtype.cod_restrict _ (λ x, h x.2)
10561016
lemma range_subtype (s : submonoid M) : s.subtype.mrange = s :=
10571017
ext' $ (coe_mrange _).trans $ set.range_coe_subtype s
10581018

1019+
lemma closure_singleton_eq (x : M) : closure ({x} : set M) = (powers_hom M x).mrange :=
1020+
closure_eq_of_le (set.singleton_subset_iff.2 ⟨multiplicative.of_add 1, trivial, pow_one x⟩) $
1021+
λ x ⟨n, _, hn⟩, hn ▸ pow_mem _ (subset_closure $ set.mem_singleton _) _
1022+
1023+
/-- The submonoid generated by an element of a monoid equals the set of natural number powers of
1024+
the element. -/
1025+
lemma mem_closure_singleton {x y : M} : y ∈ closure ({x} : set M) ↔ ∃ n:ℕ, x^n=y :=
1026+
by rw [closure_singleton_eq, mem_mrange]; refl
1027+
10591028
@[to_additive]
10601029
lemma closure_eq_mrange (s : set M) : closure s = (free_monoid.lift s M coe).mrange :=
10611030
by rw [mrange, ← free_monoid.closure_range_of, map_mclosure,
@@ -1133,6 +1102,27 @@ by simp only [sup_eq_range, mem_mrange, coprod_apply, prod.exists, submonoid.exi
11331102

11341103
end submonoid
11351104

1105+
namespace add_submonoid
1106+
1107+
open set
1108+
1109+
lemma smul_mem (S : add_submonoid A) {x : A} (hx : x ∈ S) :
1110+
∀ n : ℕ, add_monoid.smul n x ∈ S
1111+
| 0 := S.zero_mem
1112+
| (n+1) := S.add_mem hx (smul_mem n)
1113+
1114+
lemma closure_singleton_eq (x : A) : closure ({x} : set A) = (multiples_hom A x).mrange :=
1115+
closure_eq_of_le (set.singleton_subset_iff.21, trivial, add_monoid.one_smul x⟩) $
1116+
λ x ⟨n, _, hn⟩, hn ▸ smul_mem _ (subset_closure $ set.mem_singleton _) _
1117+
1118+
/-- The `add_submonoid` generated by an element of an `add_monoid` equals the set of
1119+
natural number multiples of the element. -/
1120+
lemma mem_closure_singleton {x y : A} : y ∈ closure ({x} : set A) ↔ ∃ n:ℕ, add_monoid.smul n x = y :=
1121+
by rw [closure_singleton_eq, add_monoid_hom.mem_mrange]; refl
1122+
1123+
end add_submonoid
1124+
1125+
11361126
namespace mul_equiv
11371127

11381128
variables {S T : submonoid M}

0 commit comments

Comments
 (0)