Theorem: Polynomial.div_modByMonic_unique
File: Mathlib/Data/Polynomial/Div.lean

tactic: nontriviality R
state_before: R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p q✝ : R[X]
f g : R[X]
q r : R[X]
hg : Monic g
h : r + g * q = f ∧ degree r < degree g
⊢ f /ₘ g = q ∧ f %ₘ g = r

tactic: have h₁ : r - f %ₘ g = -g * (q - f /ₘ g) :=
  eq_of_sub_eq_zero
    (by
      rw [← sub_eq_zero_of_eq (h.1.trans (modByMonic_add_div f hg).symm)]
      simp [mul_add, mul_comm, sub_eq_add_neg, add_comm, add_left_comm, add_assoc])
state_before: R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p q✝ : R[X]
f g : R[X]
q r : R[X]
hg : Monic g
h : r + g * q = f ∧ degree r < degree g
✝ : Nontrivial R
⊢ f /ₘ g = q ∧ f %ₘ g = r

tactic: have h₂ : degree (r - f %ₘ g) = degree (g * (q - f /ₘ g)) := by simp [h₁]
state_before: R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p q✝ : R[X]
f g : R[X]
q r : R[X]
hg : Monic g
h : r + g * q = f ∧ degree r < degree g
✝ : Nontrivial R
h₁ : r - f %ₘ g = -g * (q - f /ₘ g)
⊢ f /ₘ g = q ∧ f %ₘ g = r

tactic: have h₄ : degree (r - f %ₘ g) < degree g :=
  calc
    degree (r - f %ₘ g) ≤ max (degree r) (degree (f %ₘ g)) := degree_sub_le _ _
    _ < degree g := max_lt_iff.2 ⟨h.2, degree_modByMonic_lt _ hg⟩
state_before: R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p q✝ : R[X]
f g : R[X]
q r : R[X]
hg : Monic g
h : r + g * q = f ∧ degree r < degree g
✝ : Nontrivial R
h₁ : r - f %ₘ g = -g * (q - f /ₘ g)
h₂ : degree (r - f %ₘ g) = degree (g * (q - f /ₘ g))
⊢ f /ₘ g = q ∧ f %ₘ g = r

tactic: have h₅ : q - f /ₘ g = 0 :=
  _root_.by_contradiction fun hqf =>
    not_le_of_gt h₄ <|
      calc
        degree g ≤ degree g + degree (q - f /ₘ g) := by
          erw [degree_eq_natDegree hg.ne_zero, degree_eq_natDegree hqf, WithBot.coe_le_coe]
          exact Nat.le_add_right _ _
        _ = degree (r - f %ₘ g) := by rw [h₂, degree_mul']; simpa [Monic.def.1 hg]
state_before: R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p q✝ : R[X]
f g : R[X]
q r : R[X]
hg : Monic g
h : r + g * q = f ∧ degree r < degree g
✝ : Nontrivial R
h₁ : r - f %ₘ g = -g * (q - f /ₘ g)
h₂ : degree (r - f %ₘ g) = degree (g * (q - f /ₘ g))
h₄ : degree (r - f %ₘ g) < degree g
⊢ f /ₘ g = q ∧ f %ₘ g = r

tactic: exact ⟨Eq.symm <| eq_of_sub_eq_zero h₅, Eq.symm <| eq_of_sub_eq_zero <| by simpa [h₅] using h₁⟩
state_before: R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p q✝ : R[X]
f g : R[X]
q r : R[X]
hg : Monic g
h : r + g * q = f ∧ degree r < degree g
✝ : Nontrivial R
h₁ : r - f %ₘ g = -g * (q - f /ₘ g)
h₂ : degree (r - f %ₘ g) = degree (g * (q - f /ₘ g))
h₄ : degree (r - f %ₘ g) < degree g
h₅ : q - f /ₘ g = 0
⊢ f /ₘ g = q ∧ f %ₘ g = r

tactic: rw [← sub_eq_zero_of_eq (h.1.trans (modByMonic_add_div f hg).symm)]
state_before: R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p q✝ : R[X]
f g : R[X]
q r : R[X]
hg : Monic g
h : r + g * q = f ∧ degree r < degree g
✝ : Nontrivial R
⊢ r - f %ₘ g - -g * (q - f /ₘ g) = 0

tactic: simp [mul_add, mul_comm, sub_eq_add_neg, add_comm, add_left_comm, add_assoc]
state_before: R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p q✝ : R[X]
f g : R[X]
q r : R[X]
hg : Monic g
h : r + g * q = f ∧ degree r < degree g
✝ : Nontrivial R
⊢ r - f %ₘ g - -g * (q - f /ₘ g) = r + g * q - (f %ₘ g + g * (f /ₘ g))

tactic: simp [h₁]
state_before: R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p q✝ : R[X]
f g : R[X]
q r : R[X]
hg : Monic g
h : r + g * q = f ∧ degree r < degree g
✝ : Nontrivial R
h₁ : r - f %ₘ g = -g * (q - f /ₘ g)
⊢ degree (r - f %ₘ g) = degree (g * (q - f /ₘ g))

tactic: erw [degree_eq_natDegree hg.ne_zero, degree_eq_natDegree hqf, WithBot.coe_le_coe]
state_before: R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p q✝ : R[X]
f g : R[X]
q r : R[X]
hg : Monic g
h : r + g * q = f ∧ degree r < degree g
✝ : Nontrivial R
h₁ : r - f %ₘ g = -g * (q - f /ₘ g)
h₂ : degree (r - f %ₘ g) = degree (g * (q - f /ₘ g))
h₄ : degree (r - f %ₘ g) < degree g
hqf : ¬q - f /ₘ g = 0
⊢ degree g ≤ degree g + degree (q - f /ₘ g)

tactic: exact Nat.le_add_right _ _
state_before: R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p q✝ : R[X]
f g : R[X]
q r : R[X]
hg : Monic g
h : r + g * q = f ∧ degree r < degree g
✝ : Nontrivial R
h₁ : r - f %ₘ g = -g * (q - f /ₘ g)
h₂ : degree (r - f %ₘ g) = degree (g * (q - f /ₘ g))
h₄ : degree (r - f %ₘ g) < degree g
hqf : ¬q - f /ₘ g = 0
⊢ ↑(natDegree g) ≤ (fun x x_1 => x + x_1) ↑(natDegree g) ↑(natDegree (q - f /ₘ g))

tactic: rw [h₂, degree_mul']
state_before: R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p q✝ : R[X]
f g : R[X]
q r : R[X]
hg : Monic g
h : r + g * q = f ∧ degree r < degree g
✝ : Nontrivial R
h₁ : r - f %ₘ g = -g * (q - f /ₘ g)
h₂ : degree (r - f %ₘ g) = degree (g * (q - f /ₘ g))
h₄ : degree (r - f %ₘ g) < degree g
hqf : ¬q - f /ₘ g = 0
⊢ degree g + degree (q - f /ₘ g) = degree (r - f %ₘ g)

tactic: simpa [Monic.def.1 hg]
state_before: R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p q✝ : R[X]
f g : R[X]
q r : R[X]
hg : Monic g
h : r + g * q = f ∧ degree r < degree g
✝ : Nontrivial R
h₁ : r - f %ₘ g = -g * (q - f /ₘ g)
h₂ : degree (r - f %ₘ g) = degree (g * (q - f /ₘ g))
h₄ : degree (r - f %ₘ g) < degree g
hqf : ¬q - f /ₘ g = 0
⊢ leadingCoeff g * leadingCoeff (q - f /ₘ g) ≠ 0

tactic: simpa [h₅] using h₁
state_before: R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p q✝ : R[X]
f g : R[X]
q r : R[X]
hg : Monic g
h : r + g * q = f ∧ degree r < degree g
✝ : Nontrivial R
h₁ : r - f %ₘ g = -g * (q - f /ₘ g)
h₂ : degree (r - f %ₘ g) = degree (g * (q - f /ₘ g))
h₄ : degree (r - f %ₘ g) < degree g
h₅ : q - f /ₘ g = 0
⊢ r - f %ₘ g = 0