Module docstring
{"# Canonically ordered rings and semirings. "}
{"# Canonically ordered rings and semirings. "}
CanonicallyOrderedCommSemiring
      structure
    (R : Type*) extends CanonicallyOrderedAddCommMonoid R,
    CommSemiring R
        /-- A canonically ordered commutative semiring is an ordered, commutative semiring in which `a ≤ b`
iff there exists `c` with `b = a + c`. This is satisfied by the natural numbers, for example, but
not the integers or other ordered groups. -/
@[deprecated "Use `[OrderedCommSemiring R] [CanonicallyOrderedAdd R] [NoZeroDivisors R]` instead."
  (since := "2025-01-13")]
structure CanonicallyOrderedCommSemiring (R : Type*) extends CanonicallyOrderedAddCommMonoid R,
    CommSemiring R where
  /-- No zero divisors. -/
  protected eq_zero_or_eq_zero_of_mul_eq_zero : ∀ {a b : R}, a * b = 0 → a = 0 ∨ b = 0
        CanonicallyOrderedAdd.toZeroLEOneClass
      instance
     [AddZeroClass R] [One R] [LE R] [CanonicallyOrderedAdd R] : ZeroLEOneClass R
        instance (priority := 10) CanonicallyOrderedAdd.toZeroLEOneClass
    [AddZeroClass R] [One R] [LE R] [CanonicallyOrderedAdd R] : ZeroLEOneClass R where
  zero_le_one := zero_le _
        Odd.pos
      theorem
     [Semiring R] [PartialOrder R] [CanonicallyOrderedAdd R] [Nontrivial R] {a : R} : Odd a → 0 < a
        lemma Odd.pos [Semiring R] [PartialOrder R] [CanonicallyOrderedAdd R] [Nontrivial R] {a : R} :
    Odd a → 0 < a := by
  rintro ⟨k, rfl⟩; simp
        CanonicallyOrderedAdd.toMulLeftMono
      instance
     [NonUnitalNonAssocSemiring R] [LE R] [CanonicallyOrderedAdd R] : MulLeftMono R
        instance (priority := 100) toMulLeftMono [NonUnitalNonAssocSemiring R]
    [LE R] [CanonicallyOrderedAdd R] : MulLeftMono R := by
  refine ⟨fun a b c h => ?_⟩; dsimp
  rcases exists_add_of_le h with ⟨c, rfl⟩
  rw [mul_add]
  apply self_le_add_right
        CanonicallyOrderedAdd.toIsOrderedMonoid
      theorem
     : IsOrderedMonoid R
        lemma toIsOrderedMonoid : IsOrderedMonoid R where
  mul_le_mul_left _ _ := mul_le_mul_left'
        CanonicallyOrderedAdd.toIsOrderedRing
      theorem
     : IsOrderedRing R
        lemma toIsOrderedRing : IsOrderedRing R where
  zero_le_one := zero_le _
  add_le_add_left _ _ := add_le_add_left
  mul_le_mul_of_nonneg_left _ _ _ h _ := mul_le_mul_left' h _
  mul_le_mul_of_nonneg_right _ _ _ h _ := mul_le_mul_right' h _
        CanonicallyOrderedAdd.mul_pos
      theorem
     [NoZeroDivisors R] {a b : R} : 0 < a * b ↔ 0 < a ∧ 0 < b
        @[simp]
protected theorem mul_pos [NoZeroDivisors R] {a b : R} :
    0 < a * b ↔ 0 < a ∧ 0 < b := by
  simp only [pos_iff_ne_zero, ne_eq, mul_eq_zero, not_or]
        CanonicallyOrderedAdd.pow_pos
      theorem
     [NoZeroDivisors R] {a : R} (ha : 0 < a) (n : ℕ) : 0 < a ^ n
        lemma pow_pos [NoZeroDivisors R] {a : R} (ha : 0 < a) (n : ℕ) : 0 < a ^ n :=
  pos_iff_ne_zero.2 <| pow_ne_zero _ ha.ne'
        CanonicallyOrderedAdd.mul_lt_mul_of_lt_of_lt
      theorem
     [PosMulStrictMono R] {a b c d : R} (hab : a < b) (hcd : c < d) : a * c < b * d
        protected lemma mul_lt_mul_of_lt_of_lt
    [PosMulStrictMono R] {a b c d : R} (hab : a < b) (hcd : c < d) :
    a * c < b * d := by
  -- TODO: This should be an instance but it currently times out
  have := posMulStrictMono_iff_mulPosStrictMono.1 ‹_›
  obtain rfl | hc := eq_zero_or_pos c
  · rw [mul_zero]
    exact mul_pos ((zero_le _).trans_lt hab) hcd
  · exact mul_lt_mul_of_pos' hab hcd hc ((zero_le _).trans_lt hab)
        AddLECancellable.mul_tsub
      theorem
     {a b c : R} (h : AddLECancellable (a * c)) : a * (b - c) = a * b - a * c
        protected theorem mul_tsub {a b c : R}
    (h : AddLECancellable (a * c)) : a * (b - c) = a * b - a * c := by
  obtain (hbc | hcb) := total_of (· ≤ ·) b c
  · rw [tsub_eq_zero_iff_le.2 hbc, mul_zero, tsub_eq_zero_iff_le.2 (mul_le_mul_left' hbc a)]
  · apply h.eq_tsub_of_add_eq
    rw [← mul_add, tsub_add_cancel_of_le hcb]
        AddLECancellable.tsub_mul
      theorem
     [MulRightMono R] {a b c : R} (h : AddLECancellable (b * c)) : (a - b) * c = a * c - b * c
        protected theorem tsub_mul [MulRightMono R] {a b c : R}
    (h : AddLECancellable (b * c)) : (a - b) * c = a * c - b * c := by
  obtain (hab | hba) := total_of (· ≤ ·) a b
  · rw [tsub_eq_zero_iff_le.2 hab, zero_mul, tsub_eq_zero_iff_le.2 (mul_le_mul_right' hab c)]
  · apply h.eq_tsub_of_add_eq
    rw [← add_mul, tsub_add_cancel_of_le hba]
        mul_tsub
      theorem
     (a b c : R) : a * (b - c) = a * b - a * c
        theorem mul_tsub (a b c : R) : a * (b - c) = a * b - a * c :=
  Contravariant.AddLECancellable.mul_tsub
        tsub_mul
      theorem
     [MulRightMono R] (a b c : R) : (a - b) * c = a * c - b * c
        theorem tsub_mul [MulRightMono R] (a b c : R) :
    (a - b) * c = a * c - b * c :=
  Contravariant.AddLECancellable.tsub_mul
        mul_tsub_one
      theorem
     [AddLeftReflectLE R] (a b : R) : a * (b - 1) = a * b - a
        lemma mul_tsub_one [AddLeftReflectLE R] (a b : R) :
    a * (b - 1) = a * b - a := by rw [mul_tsub, mul_one]
        tsub_one_mul
      theorem
     [MulRightMono R] [AddLeftReflectLE R] (a b : R) : (a - 1) * b = a * b - b
        lemma tsub_one_mul [MulRightMono R] [AddLeftReflectLE R] (a b : R) :
    (a - 1) * b = a * b - b := by rw [tsub_mul, one_mul]
        mul_self_tsub_mul_self
      theorem
     (a b : R) : a * a - b * b = (a + b) * (a - b)
        /-- The `tsub` version of `mul_self_sub_mul_self`. Notably, this holds for `Nat` and `NNReal`. -/
theorem mul_self_tsub_mul_self (a b : R) :
    a * a - b * b = (a + b) * (a - b) := by
  rw [mul_tsub, add_mul, add_mul, tsub_add_eq_tsub_tsub, mul_comm b a, add_tsub_cancel_right]
        sq_tsub_sq
      theorem
     (a b : R) : a ^ 2 - b ^ 2 = (a + b) * (a - b)
        /-- The `tsub` version of `sq_sub_sq`. Notably, this holds for `Nat` and `NNReal`. -/
theorem sq_tsub_sq (a b : R) : a ^ 2 - b ^ 2 = (a + b) * (a - b) := by
  rw [sq, sq, mul_self_tsub_mul_self]
        mul_self_tsub_one
      theorem
     (a : R) : a * a - 1 = (a + 1) * (a - 1)
        theorem mul_self_tsub_one (a : R) : a * a - 1 = (a + 1) * (a - 1) := by
  rw [← mul_self_tsub_mul_self, mul_one]