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

Commit abaabc8

Browse files
committed
chore(algebra/group_power/lemmas): turn [zn]smul lemmas into instances (#13002)
This adds new instances such that: * `mul_[zn]smul_assoc` is `←smul_mul_assoc` * `mul_[zn]smul_left` is `←mul_smul_comm` This also makes `noncomm_ring` slightly smarter, and able to handle scalar actions by `nat`. Thanks to Christopher, this generalizes these instances to non-associative and non-unital rings. Co-authored-by: Christopher Hoskin <christopher.hoskin@gmail.com>
1 parent 0e1387b commit abaabc8

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

src/algebra/group_power/lemmas.lean

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,21 @@ by induction n with n ih; [rw [zero_nsmul, nat.cast_zero, mul_zero],
342342
@[simp] theorem nsmul_eq_mul [semiring R] (n : ℕ) (a : R) : n • a = n * a :=
343343
by rw [nsmul_eq_mul', (n.cast_commute a).eq]
344344

345-
theorem mul_nsmul_left [semiring R] (a b : R) (n : ℕ) : n • (a * b) = a * (n • b) :=
346-
by rw [nsmul_eq_mul', nsmul_eq_mul', mul_assoc]
347-
348-
theorem mul_nsmul_assoc [semiring R] (a b : R) (n : ℕ) : n • (a * b) = n • a * b :=
349-
by rw [nsmul_eq_mul, nsmul_eq_mul, mul_assoc]
345+
/-- Note that `add_comm_monoid.nat_smul_comm_class` requires stronger assumptions on `R`. -/
346+
instance non_unital_non_assoc_semiring.nat_smul_comm_class [non_unital_non_assoc_semiring R] :
347+
smul_comm_class ℕ R R :=
348+
⟨λ n x y, match n with
349+
| 0 := by simp_rw [zero_nsmul, smul_eq_mul, mul_zero]
350+
| (n + 1) := by simp_rw [succ_nsmul, smul_eq_mul, mul_add, ←smul_eq_mul, _match n]
351+
end
352+
353+
/-- Note that `add_comm_monoid.nat_is_scalar_tower` requires stronger assumptions on `R`. -/
354+
instance non_unital_non_assoc_semiring.nat_is_scalar_tower [non_unital_non_assoc_semiring R] :
355+
is_scalar_tower ℕ R R :=
356+
⟨λ n x y, match n with
357+
| 0 := by simp_rw [zero_nsmul, smul_eq_mul, zero_mul]
358+
| (n + 1) := by simp_rw [succ_nsmul, ←_match n, smul_eq_mul, add_mul]
359+
end
350360

351361
@[simp, norm_cast] theorem nat.cast_pow [semiring R] (n m : ℕ) : (↑(n ^ m) : R) = ↑n ^ m :=
352362
begin
@@ -383,11 +393,21 @@ by { dsimp [bit1], rw [mul_add, mul_bit0, mul_one], }
383393
theorem zsmul_eq_mul' [ring R] (a : R) (n : ℤ) : n • a = a * n :=
384394
by rw [zsmul_eq_mul, (n.cast_commute a).eq]
385395

386-
theorem mul_zsmul_left [ring R] (a b : R) (n : ℤ) : n • (a * b) = a * (n • b) :=
387-
by rw [zsmul_eq_mul', zsmul_eq_mul', mul_assoc]
388-
389-
theorem mul_zsmul_assoc [ring R] (a b : R) (n : ℤ) : n • (a * b) = n • a * b :=
390-
by rw [zsmul_eq_mul, zsmul_eq_mul, mul_assoc]
396+
/-- Note that `add_comm_group.int_smul_comm_class` requires stronger assumptions on `R`. -/
397+
instance non_unital_non_assoc_ring.int_smul_comm_class [non_unital_non_assoc_ring R] :
398+
smul_comm_class ℤ R R :=
399+
⟨λ n x y, match n with
400+
| (n : ℕ) := by simp_rw [coe_nat_zsmul, smul_comm]
401+
| -[1+n] := by simp_rw [zsmul_neg_succ_of_nat, smul_eq_mul, mul_neg, mul_smul_comm]
402+
end
403+
404+
/-- Note that `add_comm_group.int_is_scalar_tower` requires stronger assumptions on `R`. -/
405+
instance non_unital_non_assoc_ring.int_is_scalar_tower [non_unital_non_assoc_ring R] :
406+
is_scalar_tower ℤ R R :=
407+
⟨λ n x y, match n with
408+
| (n : ℕ) := by simp_rw [coe_nat_zsmul, smul_assoc]
409+
| -[1+n] := by simp_rw [zsmul_neg_succ_of_nat, smul_eq_mul, neg_mul, smul_mul_assoc]
410+
end
391411

392412
lemma zsmul_int_int (a b : ℤ) : a • b = a * b := by simp
393413

src/tactic/noncomm_ring.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ meta def noncomm_ring :=
2626
-- Replace multiplication by numerals with `zsmul`.
2727
bit0_mul, mul_bit0, bit1_mul, mul_bit1, one_mul, mul_one, zero_mul, mul_zero,
2828
-- Pull `zsmul n` out the front so `abel` can see them.
29-
←mul_zsmul_assoc, ←mul_zsmul_left,
29+
mul_smul_comm, smul_mul_assoc,
3030
-- Pull out negations.
3131
neg_mul, mul_neg] {fail_if_unchanged := ff};
3232
abel]

test/noncomm_ring.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ example : a ^ 3 = a * a * a := by noncomm_ring
2222
example : (-a) * b = -(a * b) := by noncomm_ring
2323
example : a * (-b) = -(a * b) := by noncomm_ring
2424
example : a * (b + c + b + c - 2*b) = 2*a*c := by noncomm_ring
25+
example : a * (b + c + b + c - (2 : ℕ) • b) = 2*a*c := by noncomm_ring
2526
example : (a + b)^2 = a^2 + a*b + b*a + b^2 := by noncomm_ring
2627
example : (a - b)^2 = a^2 - a*b - b*a + b^2 := by noncomm_ring
2728
example : (a + b)^3 = a^3 + a^2*b + a*b*a + a*b^2 + b*a^2 + b*a*b + b^2*a + b^3 := by noncomm_ring

0 commit comments

Comments
 (0)