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

Commit e6c787f

Browse files
committed
feat(algebra/opposites): add has_scalar (opposite α) α instances (#7630)
The action is defined as: ```lean lemma op_smul_eq_mul [monoid α] {a a' : α} : op a • a' = a' * a := rfl ``` We have a few of places in the library where we prove things about `r • b`, and then extract a proof of `a * b = a • b` for free. However, we have no way to do this for `b * a` right now unless multiplication is commutative. By adding this action, we have `b * a = op a • b` so in many cases could reuse the smul lemma. This instance does not create a diamond: ```lean -- the two paths to `mul_action (opposite α) (opposite α)` are defeq example [monoid α] : monoid.to_mul_action (opposite α) = opposite.mul_action α (opposite α) := rfl ``` [Zulip](https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/Right.20multiplication.20as.20a.20mul_action/near/239012917)
1 parent 1a2781a commit e6c787f

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/algebra/module/opposites.lean

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,28 @@ cycles.
1616
namespace opposite
1717
universes u v
1818

19-
variables (R : Type u) {M : Type v} [semiring R] [add_comm_monoid M] [module R M]
19+
variables (R : Type u) {M : Type v}
20+
21+
/-- Like `mul_zero_class.to_smul_with_zero`, but multiplies on the right. -/
22+
instance mul_zero_class.to_opposite_smul_with_zero [mul_zero_class R] :
23+
smul_with_zero (opposite R) R :=
24+
{ smul := λ c x, x * c.unop,
25+
smul_zero := λ x, zero_mul _,
26+
zero_smul := mul_zero }
27+
28+
/-- Like `monoid_with_zero.to_mul_action_with_zero`, but multiplies on the right. -/
29+
instance monoid_with_zero.to_opposite_mul_action_with_zero [monoid_with_zero R] :
30+
mul_action_with_zero (opposite R) R :=
31+
{ ..mul_zero_class.to_opposite_smul_with_zero R,
32+
..monoid.to_opposite_mul_action R }
33+
34+
/-- Like `semiring.to_module`, but multiplies on the right. -/
35+
instance semiring.to_opposite_module [semiring R] : module (opposite R) R :=
36+
{ smul_add := λ r x y, add_mul _ _ _,
37+
add_smul := λ r s x, mul_add _ _ _,
38+
..mul_zero_class.to_opposite_smul_with_zero R }
39+
40+
variables [semiring R] [add_comm_monoid M] [module R M]
2041

2142
/-- `opposite.distrib_mul_action` extends to a `module` -/
2243
instance : module R (opposite M) :=

src/algebra/opposites.lean

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,18 @@ instance (R : Type*) [monoid R] [add_monoid α] [distrib_mul_action R α] :
186186
smul_zero := λ r, unop_injective $ smul_zero r,
187187
..opposite.mul_action α R }
188188

189+
/-- Like `monoid.to_mul_action`, but multiplies on the right. -/
190+
instance monoid.to_opposite_mul_action [monoid α] : mul_action (opposite α) α :=
191+
{ smul := λ c x, x * c.unop,
192+
one_smul := mul_one,
193+
mul_smul := λ x y r, (mul_assoc _ _ _).symm }
194+
195+
-- The above instance does not create an unwanted diamond, the two paths to
196+
-- `mul_action (opposite α) (opposite α)` are defeq.
197+
example [monoid α] : monoid.to_mul_action (opposite α) = opposite.mul_action α (opposite α) := rfl
198+
199+
lemma op_smul_eq_mul [monoid α] {a a' : α} : op a • a' = a' * a := rfl
200+
189201
@[simp] lemma op_zero [has_zero α] : op (0 : α) = 0 := rfl
190202
@[simp] lemma unop_zero [has_zero α] : unop (0 : αᵒᵖ) = 0 := rfl
191203

0 commit comments

Comments
 (0)