Skip to content

Commit 1845382

Browse files
kim-emalgebraic-dev
authored andcommitted
feat: generalize embedding of CommSemiring into its CommRing envelope to the noncommutative case (leanprover#8836)
This PR generalizes leanprover#8835 to the noncommutative case, allowing us to embed a `Lean.Grind.Semiring` into a `Lean.Grind.Ring`.
1 parent 7de1ca0 commit 1845382

File tree

1 file changed

+42
-15
lines changed

1 file changed

+42
-15
lines changed

src/Init/Grind/Ring/Envelope.lean

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ prelude
99
import Init.Grind.Ring.Basic
1010
import all Init.Data.AC
1111

12-
namespace Lean.Grind.CommRing
12+
namespace Lean.Grind.Ring
1313

14-
namespace OfCommSemiring
14+
namespace OfSemiring
1515
variable (α : Type u)
1616
attribute [local instance] Semiring.natCast Ring.intCast
17-
variable [CommSemiring α]
17+
variable [Semiring α]
1818

1919
-- Helper instance for `ac_rfl`
2020
local instance : Std.Associative (· + · : α → α → α) where
@@ -23,8 +23,6 @@ local instance : Std.Commutative (· + · : α → α → α) where
2323
comm := Semiring.add_comm
2424
local instance : Std.Associative (· * · : α → α → α) where
2525
assoc := Semiring.mul_assoc
26-
local instance : Std.Commutative (· * · : α → α → α) where
27-
comm := CommSemiring.mul_comm
2826

2927
@[local simp] private theorem exists_true : ∃ (_ : α), True := ⟨0, trivial⟩
3028

@@ -53,7 +51,7 @@ theorem r_trans {a b c : α × α} : r α a b → r α b c → r α a c := by
5351
rw [haux₁, haux₂] at h₁
5452
exact h₁
5553

56-
theorem mul_helper {α} [CommSemiring α]
54+
theorem mul_helper {α} [Semiring α]
5755
{a₁ b₁ a₂ b₂ a₃ b₃ a₄ b₄ k₁ k₂ : α}
5856
(h₁ : a₁ + b₃ + k₁ = b₁ + a₃ + k₁)
5957
(h₂ : a₂ + b₄ + k₂ = b₂ + a₄ + k₂)
@@ -183,12 +181,6 @@ theorem intCast_ofNat (n : Nat) : intCast (α := α) (OfNat.ofNat (α := Int) n)
183181
theorem ofNat_succ (a : Nat) : natCast (α := α) (a + 1) = add (natCast a) (natCast 1) := by
184182
simp; apply Quot.sound; simp [Semiring.natCast_add]
185183

186-
theorem mul_comm (a b : Q α) : mul a b = mul b a := by
187-
induction a using Quot.ind
188-
induction b using Quot.ind
189-
next a b =>
190-
cases a; cases b; simp; apply Quot.sound; simp; refine ⟨0, ?_⟩; ac_rfl
191-
192184
theorem mul_assoc (a b c : Q α) : mul (mul a b) c = mul a (mul b c) := by
193185
induction a using Quot.ind
194186
induction b using Quot.ind
@@ -238,19 +230,19 @@ private theorem pow_zero (a : Q α) : hPow a 0 = natCast 1 := rfl
238230

239231
private theorem pow_succ (a : Q α) (n : Nat) : hPow a (n+1) = mul (hPow a n) a := rfl
240232

241-
def ofCommSemiring : CommRing (Q α) := {
233+
def ofSemiring : Ring (Q α) := {
242234
ofNat := fun n => ⟨natCast n⟩
243235
natCast := ⟨natCast⟩
244236
intCast := ⟨intCast⟩
245237
add, sub, mul, neg, hPow
246238
add_comm, add_assoc, add_zero
247239
neg_add_cancel, sub_eq_add_neg
248-
mul_one, one_mul, zero_mul, mul_zero, mul_assoc, mul_comm,
240+
mul_one, one_mul, zero_mul, mul_zero, mul_assoc,
249241
left_distrib, right_distrib, pow_zero, pow_succ,
250242
intCast_neg, ofNat_succ
251243
}
252244

253-
attribute [local instance] ofCommSemiring
245+
attribute [local instance] ofSemiring
254246

255247
@[local simp] def toQ (a : α) : Q α :=
256248
Q.mk (a, 0)
@@ -306,5 +298,40 @@ theorem toQ_inj [AddRightCancel α] (a b : α) : toQ a = toQ b → a = b := by
306298
obtain ⟨k, h₁⟩ := h₁
307299
exact AddRightCancel.add_right_cancel a b k h₁
308300

301+
end OfSemiring
302+
end Lean.Grind.Ring
303+
304+
open Lean.Grind.Ring
305+
306+
namespace Lean.Grind.CommRing
307+
308+
namespace OfCommSemiring
309+
310+
variable (α : Type u) [CommSemiring α]
311+
312+
local instance : Std.Associative (· + · : α → α → α) where
313+
assoc := Semiring.add_assoc
314+
local instance : Std.Commutative (· + · : α → α → α) where
315+
comm := Semiring.add_comm
316+
local instance : Std.Associative (· * · : α → α → α) where
317+
assoc := Semiring.mul_assoc
318+
local instance : Std.Commutative (· * · : α → α → α) where
319+
comm := CommSemiring.mul_comm
320+
321+
variable {α}
322+
323+
attribute [local simp] OfSemiring.Q.mk OfSemiring.Q.liftOn₂ Semiring.add_zero
324+
325+
theorem mul_comm (a b : OfSemiring.Q α) : OfSemiring.mul a b = OfSemiring.mul b a := by
326+
induction a using Quot.ind
327+
induction b using Quot.ind
328+
next a b =>
329+
cases a; cases b; apply Quot.sound; refine ⟨0, ?_⟩; simp; ac_rfl
330+
331+
def ofCommSemiring : CommRing (OfSemiring.Q α) :=
332+
{ OfSemiring.ofSemiring with
333+
mul_comm := mul_comm }
334+
309335
end OfCommSemiring
336+
310337
end Lean.Grind.CommRing

0 commit comments

Comments
 (0)