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

Commit ad4040d

Browse files
committed
feat(algebra/opposites): provide npow and gpow explicitly, prove op_gpow and unop_gpow (#9659)
By populating the `npow` and `gpow` fields in the obvious way, `op_pow` and `unop_pow` are true definitionally. This adds the new lemmas `op_gpow` and `unop_gpow` which works for `group`s and `division_ring`s too. Note that we do not provide an explicit `div` in `div_inv_monoid`, because there is no "reversed division" operator to define it via. This also reorders the lemmas so that the definitional lemmas are available before any proof obligations might appear in stronger typeclasses.
1 parent 34ffb15 commit ad4040d

File tree

2 files changed

+80
-58
lines changed

2 files changed

+80
-58
lines changed

src/algebra/group_power/lemmas.lean

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -918,20 +918,13 @@ lemma conj_pow' (u : units M) (x : M) (n : ℕ) : (↑(u⁻¹) * x * u)^n = ↑(
918918
end units
919919

920920
namespace opposite
921-
variables [monoid M]
921+
922922
/-- Moving to the opposite monoid commutes with taking powers. -/
923-
@[simp] lemma op_pow (x : M) (n : ℕ) : op (x ^ n) = (op x) ^ n :=
924-
begin
925-
induction n with n h,
926-
{ simp },
927-
{ rw [pow_succ', op_mul, h, pow_succ] }
928-
end
923+
@[simp] lemma op_pow [monoid M] (x : M) (n : ℕ) : op (x ^ n) = (op x) ^ n := rfl
924+
@[simp] lemma unop_pow [monoid M] (x : Mᵒᵖ) (n : ℕ) : unop (x ^ n) = (unop x) ^ n := rfl
929925

930-
@[simp] lemma unop_pow (x : Mᵒᵖ) (n : ℕ) : unop (x ^ n) = (unop x) ^ n :=
931-
begin
932-
induction n with n h,
933-
{ simp },
934-
{ rw [pow_succ', unop_mul, h, pow_succ] }
935-
end
926+
/-- Moving to the opposite group or group_with_zero commutes with taking powers. -/
927+
@[simp] lemma op_gpow [div_inv_monoid M] (x : M) (z : ℤ) : op (x ^ z) = (op x) ^ z := rfl
928+
@[simp] lemma unop_gpow [div_inv_monoid M] (x : Mᵒᵖ) (z : ℤ) : unop (x ^ z) = (unop x) ^ z := rfl
936929

937930
end opposite

src/algebra/opposites.lean

Lines changed: 74 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,62 @@ universes u
2222

2323
variables (α : Type u)
2424

25+
instance [has_zero α] : has_zero (opposite α) :=
26+
{ zero := op 0 }
27+
28+
instance [has_one α] : has_one (opposite α) :=
29+
{ one := op 1 }
30+
2531
instance [has_add α] : has_add (opposite α) :=
2632
{ add := λ x y, op (unop x + unop y) }
2733

2834
instance [has_sub α] : has_sub (opposite α) :=
2935
{ sub := λ x y, op (unop x - unop y) }
3036

37+
instance [has_neg α] : has_neg (opposite α) :=
38+
{ neg := λ x, op $ -(unop x) }
39+
40+
instance [has_mul α] : has_mul (opposite α) :=
41+
{ mul := λ x y, op (unop y * unop x) }
42+
43+
instance [has_inv α] : has_inv (opposite α) :=
44+
{ inv := λ x, op $ (unop x)⁻¹ }
45+
46+
instance (R : Type*) [has_scalar R α] : has_scalar R (opposite α) :=
47+
{ smul := λ c x, op (c • unop x) }
48+
49+
section
50+
variables (α)
51+
52+
@[simp] lemma op_zero [has_zero α] : op (0 : α) = 0 := rfl
53+
@[simp] lemma unop_zero [has_zero α] : unop (0 : αᵒᵖ) = 0 := rfl
54+
55+
@[simp] lemma op_one [has_one α] : op (1 : α) = 1 := rfl
56+
@[simp] lemma unop_one [has_one α] : unop (1 : αᵒᵖ) = 1 := rfl
57+
58+
variable {α}
59+
60+
@[simp] lemma op_add [has_add α] (x y : α) : op (x + y) = op x + op y := rfl
61+
@[simp] lemma unop_add [has_add α] (x y : αᵒᵖ) : unop (x + y) = unop x + unop y := rfl
62+
63+
@[simp] lemma op_neg [has_neg α] (x : α) : op (-x) = -op x := rfl
64+
@[simp] lemma unop_neg [has_neg α] (x : αᵒᵖ) : unop (-x) = -unop x := rfl
65+
66+
@[simp] lemma op_mul [has_mul α] (x y : α) : op (x * y) = op y * op x := rfl
67+
@[simp] lemma unop_mul [has_mul α] (x y : αᵒᵖ) : unop (x * y) = unop y * unop x := rfl
68+
69+
@[simp] lemma op_inv [has_inv α] (x : α) : op (x⁻¹) = (op x)⁻¹ := rfl
70+
@[simp] lemma unop_inv [has_inv α] (x : αᵒᵖ) : unop (x⁻¹) = (unop x)⁻¹ := rfl
71+
72+
@[simp] lemma op_sub [add_group α] (x y : α) : op (x - y) = op x - op y := rfl
73+
@[simp] lemma unop_sub [add_group α] (x y : αᵒᵖ) : unop (x - y) = unop x - unop y := rfl
74+
75+
@[simp] lemma op_smul {R : Type*} [has_scalar R α] (c : R) (a : α) : op (c • a) = c • op a := rfl
76+
@[simp] lemma unop_smul {R : Type*} [has_scalar R α] (c : R) (a : αᵒᵖ) :
77+
unop (c • a) = c • unop a := rfl
78+
79+
end
80+
3181
instance [add_semigroup α] : add_semigroup (opposite α) :=
3282
{ add_assoc := λ x y z, unop_injective $ add_assoc (unop x) (unop y) (unop z),
3383
.. opposite.has_add α }
@@ -44,8 +94,6 @@ instance [add_comm_semigroup α] : add_comm_semigroup (opposite α) :=
4494
{ add_comm := λ x y, unop_injective $ add_comm (unop x) (unop y),
4595
.. opposite.add_semigroup α }
4696

47-
instance [has_zero α] : has_zero (opposite α) :=
48-
{ zero := op 0 }
4997

5098
instance [nontrivial α] : nontrivial (opposite α) :=
5199
let ⟨x, y, h⟩ := exists_pair_ne α in nontrivial_of_ne (op x) (op y) (op_injective.ne h)
@@ -76,9 +124,6 @@ instance [add_monoid α] : add_monoid (opposite α) :=
76124
instance [add_comm_monoid α] : add_comm_monoid (opposite α) :=
77125
{ .. opposite.add_monoid α, .. opposite.add_comm_semigroup α }
78126

79-
instance [has_neg α] : has_neg (opposite α) :=
80-
{ neg := λ x, op $ -(unop x) }
81-
82127
instance [add_group α] : add_group (opposite α) :=
83128
{ add_left_neg := λ x, unop_injective $ add_left_neg $ unop x,
84129
sub_eq_add_neg := λ x y, unop_injective $ sub_eq_add_neg (unop x) (unop y),
@@ -87,9 +132,6 @@ instance [add_group α] : add_group (opposite α) :=
87132
instance [add_comm_group α] : add_comm_group (opposite α) :=
88133
{ .. opposite.add_group α, .. opposite.add_comm_monoid α }
89134

90-
instance [has_mul α] : has_mul (opposite α) :=
91-
{ mul := λ x y, op (unop y * unop x) }
92-
93135
instance [semigroup α] : semigroup (opposite α) :=
94136
{ mul_assoc := λ x y z, unop_injective $ eq.symm $ mul_assoc (unop z) (unop y) (unop x),
95137
.. opposite.has_mul α }
@@ -106,9 +148,6 @@ instance [comm_semigroup α] : comm_semigroup (opposite α) :=
106148
{ mul_comm := λ x y, unop_injective $ mul_comm (unop y) (unop x),
107149
.. opposite.semigroup α }
108150

109-
instance [has_one α] : has_one (opposite α) :=
110-
{ one := op 1 }
111-
112151
section
113152
local attribute [semireducible] opposite
114153
@[simp] lemma unop_eq_one_iff {α} [has_one α] (a : αᵒᵖ) : a.unop = 1 ↔ a = 1 :=
@@ -124,7 +163,15 @@ instance [mul_one_class α] : mul_one_class (opposite α) :=
124163
.. opposite.has_mul α, .. opposite.has_one α }
125164

126165
instance [monoid α] : monoid (opposite α) :=
127-
{ .. opposite.semigroup α, .. opposite.mul_one_class α }
166+
{ npow := λ n x, op $ monoid.npow n x.unop,
167+
npow_zero' := λ x, unop_injective $ monoid.npow_zero' x.unop,
168+
npow_succ' := λ n x, unop_injective $ (monoid.npow_succ' n x.unop).trans begin
169+
dsimp,
170+
induction n with n ih,
171+
{ rw [monoid.npow_zero', one_mul, mul_one] },
172+
{ rw [monoid.npow_succ' n x.unop, mul_assoc, ih], },
173+
end,
174+
.. opposite.semigroup α, .. opposite.mul_one_class α }
128175

129176
instance [right_cancel_monoid α] : left_cancel_monoid (opposite α) :=
130177
{ .. opposite.left_cancel_semigroup α, ..opposite.monoid α }
@@ -141,12 +188,21 @@ instance [comm_monoid α] : comm_monoid (opposite α) :=
141188
instance [cancel_comm_monoid α] : cancel_comm_monoid (opposite α) :=
142189
{ .. opposite.cancel_monoid α, ..opposite.comm_monoid α }
143190

144-
instance [has_inv α] : has_inv (opposite α) :=
145-
{ inv := λ x, op $ (unop x)⁻¹ }
191+
instance [div_inv_monoid α] : div_inv_monoid (opposite α) :=
192+
{ gpow := λ n x, op $ div_inv_monoid.gpow n x.unop,
193+
gpow_zero' := λ x, unop_injective $ div_inv_monoid.gpow_zero' x.unop,
194+
gpow_succ' := λ n x, unop_injective $ (div_inv_monoid.gpow_succ' n x.unop).trans begin
195+
dsimp,
196+
induction n with n ih,
197+
{ rw [int.of_nat_zero, div_inv_monoid.gpow_zero', one_mul, mul_one] },
198+
{ rw [div_inv_monoid.gpow_succ' n x.unop, mul_assoc, ih], },
199+
end,
200+
gpow_neg' := λ z x, unop_injective $ div_inv_monoid.gpow_neg' z x.unop,
201+
.. opposite.monoid α, .. opposite.has_inv α }
146202

147203
instance [group α] : group (opposite α) :=
148204
{ mul_left_inv := λ x, unop_injective $ mul_inv_self $ unop x,
149-
.. opposite.monoid α, .. opposite.has_inv α }
205+
.. opposite.div_inv_monoid α, }
150206

151207
instance [comm_group α] : comm_group (opposite α) :=
152208
{ .. opposite.group α, .. opposite.comm_monoid α }
@@ -181,7 +237,8 @@ instance [non_assoc_semiring α] : non_assoc_semiring (opposite α) :=
181237
{ .. opposite.mul_zero_one_class α, .. opposite.non_unital_non_assoc_semiring α }
182238

183239
instance [semiring α] : semiring (opposite α) :=
184-
{ .. opposite.non_unital_semiring α, .. opposite.non_assoc_semiring α }
240+
{ .. opposite.non_unital_semiring α, .. opposite.non_assoc_semiring α,
241+
.. opposite.monoid_with_zero α }
185242

186243
instance [comm_semiring α] : comm_semiring (opposite α) :=
187244
{ .. opposite.semiring α, .. opposite.comm_semigroup α }
@@ -203,17 +260,14 @@ instance [integral_domain α] : integral_domain (opposite α) :=
203260
instance [group_with_zero α] : group_with_zero (opposite α) :=
204261
{ mul_inv_cancel := λ x hx, unop_injective $ inv_mul_cancel $ unop_injective.ne hx,
205262
inv_zero := unop_injective inv_zero,
206-
.. opposite.monoid_with_zero α, .. opposite.nontrivial α, .. opposite.has_inv α }
263+
.. opposite.monoid_with_zero α, .. opposite.div_inv_monoid α, .. opposite.nontrivial α }
207264

208265
instance [division_ring α] : division_ring (opposite α) :=
209266
{ .. opposite.group_with_zero α, .. opposite.ring α }
210267

211268
instance [field α] : field (opposite α) :=
212269
{ .. opposite.division_ring α, .. opposite.comm_ring α }
213270

214-
instance (R : Type*) [has_scalar R α] : has_scalar R (opposite α) :=
215-
{ smul := λ c x, op (c • unop x) }
216-
217271
instance (R : Type*) [monoid R] [mul_action R α] : mul_action R (opposite α) :=
218272
{ one_smul := λ x, unop_injective $ one_smul R (unop x),
219273
mul_smul := λ r₁ r₂ x, unop_injective $ mul_smul r₁ r₂ (unop x),
@@ -285,33 +339,8 @@ instance _root_.cancel_monoid_with_zero.to_has_faithful_opposite_scalar
285339
[cancel_monoid_with_zero α] [nontrivial α] : has_faithful_scalar (opposite α) α :=
286340
⟨λ x y h, unop_injective $ mul_left_cancel₀ one_ne_zero (h 1)⟩
287341

288-
@[simp] lemma op_zero [has_zero α] : op (0 : α) = 0 := rfl
289-
@[simp] lemma unop_zero [has_zero α] : unop (0 : αᵒᵖ) = 0 := rfl
290-
291-
@[simp] lemma op_one [has_one α] : op (1 : α) = 1 := rfl
292-
@[simp] lemma unop_one [has_one α] : unop (1 : αᵒᵖ) = 1 := rfl
293-
294342
variable {α}
295343

296-
@[simp] lemma op_add [has_add α] (x y : α) : op (x + y) = op x + op y := rfl
297-
@[simp] lemma unop_add [has_add α] (x y : αᵒᵖ) : unop (x + y) = unop x + unop y := rfl
298-
299-
@[simp] lemma op_neg [has_neg α] (x : α) : op (-x) = -op x := rfl
300-
@[simp] lemma unop_neg [has_neg α] (x : αᵒᵖ) : unop (-x) = -unop x := rfl
301-
302-
@[simp] lemma op_mul [has_mul α] (x y : α) : op (x * y) = op y * op x := rfl
303-
@[simp] lemma unop_mul [has_mul α] (x y : αᵒᵖ) : unop (x * y) = unop y * unop x := rfl
304-
305-
@[simp] lemma op_inv [has_inv α] (x : α) : op (x⁻¹) = (op x)⁻¹ := rfl
306-
@[simp] lemma unop_inv [has_inv α] (x : αᵒᵖ) : unop (x⁻¹) = (unop x)⁻¹ := rfl
307-
308-
@[simp] lemma op_sub [add_group α] (x y : α) : op (x - y) = op x - op y := rfl
309-
@[simp] lemma unop_sub [add_group α] (x y : αᵒᵖ) : unop (x - y) = unop x - unop y := rfl
310-
311-
@[simp] lemma op_smul {R : Type*} [has_scalar R α] (c : R) (a : α) : op (c • a) = c • op a := rfl
312-
@[simp] lemma unop_smul {R : Type*} [has_scalar R α] (c : R) (a : αᵒᵖ) :
313-
unop (c • a) = c • unop a := rfl
314-
315344
lemma semiconj_by.op [has_mul α] {a x y : α} (h : semiconj_by a x y) :
316345
semiconj_by (op a) (op y) (op x) :=
317346
begin

0 commit comments

Comments
 (0)