l3lab/ntp-mathlib huggingface dataset:
@[simp]
theorem divByMonic_zero (p : R[X]) : p /ₘ 0 = 0 :=
  letI := Classical.decEq R
  if h : Monic (0 : R[X]) then by
    haveI := monic_zero_iff_subsingleton.mp h
    simp [eq_iff_true_of_subsingleton]
  else by unfold divByMonic divModByMonicAux; 

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q p : R[X]
this : DecidableEq R := Classical.decEq R
h : ¬Monic 0
⊢ (if h : Monic 0 then
      (if h_1 : degree 0 ≤ degree p ∧ p ≠ 0 then
          let z := C (leadingCoeff p) * X ^ (natDegree p - natDegree 0);
          let_fun _wf := (_ : degree (p - 0 * (C (leadingCoeff p) * X ^ (natDegree p - natDegree 0))) < degree p);
          let dm := divModByMonicAux (p - 0 * z) (_ : Monic 0);
          (z + dm.1, dm.2)
        else (0, p)).1
    else 0) =
    0

Next tactic:
rw [dif_neg h]
theorem modByMonic_eq_self_iff [Nontrivial R] (hq : Monic q) : p %ₘ q = p ↔ degree p < degree q :=
  ⟨fun h => h ▸ degree_modByMonic_lt _ hq, fun h => by
    

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝¹ : Ring R
p q : R[X]
inst✝ : Nontrivial R
hq : Monic q
h : degree p < degree q
⊢ p %ₘ q = p

Next tactic:
classical
    have : ¬degree q ≤ degree p := not_le_of_gt h
    unfold modByMonic divModByMonicAux; dsimp; rw [dif_pos hq, if_neg (mt And.left this)]
theorem modByMonic_eq_self_iff [Nontrivial R] (hq : Monic q) : p %ₘ q = p ↔ degree p < degree q :=
  ⟨fun h => h ▸ degree_modByMonic_lt _ hq, fun h => by
    classical
    

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝¹ : Ring R
p q : R[X]
inst✝ : Nontrivial R
hq : Monic q
h : degree p < degree q
⊢ p %ₘ q = p

Next tactic:
have : ¬degree q ≤ degree p := not_le_of_gt h
theorem modByMonic_eq_self_iff [Nontrivial R] (hq : Monic q) : p %ₘ q = p ↔ degree p < degree q :=
  ⟨fun h => h ▸ degree_modByMonic_lt _ hq, fun h => by
    classical
    have : ¬degree q ≤ degree p := not_le_of_gt h
    

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝¹ : Ring R
p q : R[X]
inst✝ : Nontrivial R
hq : Monic q
h : degree p < degree q
this : ¬degree q ≤ degree p
⊢ p %ₘ q = p

Next tactic:
unfold modByMonic divModByMonicAux
theorem modByMonic_eq_self_iff [Nontrivial R] (hq : Monic q) : p %ₘ q = p ↔ degree p < degree q :=
  ⟨fun h => h ▸ degree_modByMonic_lt _ hq, fun h => by
    classical
    have : ¬degree q ≤ degree p := not_le_of_gt h
    unfold modByMonic divModByMonicAux; 

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝¹ : Ring R
p q : R[X]
inst✝ : Nontrivial R
hq : Monic q
h : degree p < degree q
this : ¬degree q ≤ degree p
⊢ (if h : Monic q then
      (if h_1 : degree q ≤ degree p ∧ p ≠ 0 then
          let z := C (leadingCoeff p) * X ^ (natDegree p - natDegree q);
          let_fun _wf := (_ : degree (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) < degree p);
          let dm := divModByMonicAux (p - q * z) (_ : Monic q);
          (z + dm.1, dm.2)
        else (0, p)).2
    else p) =
    p

Next tactic:
dsimp
theorem modByMonic_eq_self_iff [Nontrivial R] (hq : Monic q) : p %ₘ q = p ↔ degree p < degree q :=
  ⟨fun h => h ▸ degree_modByMonic_lt _ hq, fun h => by
    classical
    have : ¬degree q ≤ degree p := not_le_of_gt h
    unfold modByMonic divModByMonicAux; dsimp; 

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝¹ : Ring R
p q : R[X]
inst✝ : Nontrivial R
hq : Monic q
h : degree p < degree q
this : ¬degree q ≤ degree p
⊢ (if h : Monic q then
      (if degree q ≤ degree p ∧ ¬p = 0 then
          (C (leadingCoeff p) * X ^ (natDegree p - natDegree q) +
              (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) (_ : Monic q)).1,
            (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) (_ : Monic q)).2)
        else (0, p)).2
    else p) =
    p

Next tactic:
rw [dif_pos hq, if_neg (mt And.left this)]
theorem degree_modByMonic_le (p : R[X]) {q : R[X]} (hq : Monic q) : degree (p %ₘ q) ≤ degree q := by
  

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q✝ p q : R[X]
hq : Monic q
⊢ degree (p %ₘ q) ≤ degree q

Next tactic:
nontriviality R
theorem degree_modByMonic_le (p : R[X]) {q : R[X]} (hq : Monic q) : degree (p %ₘ q) ≤ degree q := by
  nontriviality R
  

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q✝ p q : R[X]
hq : Monic q
✝ : Nontrivial R
⊢ degree (p %ₘ q) ≤ degree q

Next tactic:
exact (degree_modByMonic_lt _ hq).le
theorem X_dvd_sub_C : X ∣ p - C (p.coeff 0) := by
  

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p q : R[X]
⊢ X ∣ p - C (coeff p 0)

Next tactic:
simp [X_dvd_iff, coeff_C]
theorem modByMonic_eq_sub_mul_div :
    ∀ (p : R[X]) {q : R[X]} (_hq : Monic q), p %ₘ q = p - q * (p /ₘ q)
  | p, q, hq =>
    letI := Classical.decEq R
    if h : degree q ≤ degree p ∧ p ≠ 0 then by
      

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q✝ p q : R[X]
hq : Monic q
this : DecidableEq R := Classical.decEq R
h : degree q ≤ degree p ∧ p ≠ 0
⊢ p %ₘ q = p - q * (p /ₘ q)

Next tactic:
have _wf := div_wf_lemma h hq
theorem modByMonic_eq_sub_mul_div :
    ∀ (p : R[X]) {q : R[X]} (_hq : Monic q), p %ₘ q = p - q * (p /ₘ q)
  | p, q, hq =>
    letI := Classical.decEq R
    if h : degree q ≤ degree p ∧ p ≠ 0 then by
      have _wf := div_wf_lemma h hq
      

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q✝ p q : R[X]
hq : Monic q
this : DecidableEq R := Classical.decEq R
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) < degree p
⊢ p %ₘ q = p - q * (p /ₘ q)

Next tactic:
have ih := modByMonic_eq_sub_mul_div
        (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq
theorem modByMonic_eq_sub_mul_div :
    ∀ (p : R[X]) {q : R[X]} (_hq : Monic q), p %ₘ q = p - q * (p /ₘ q)
  | p, q, hq =>
    letI := Classical.decEq R
    if h : degree q ≤ degree p ∧ p ≠ 0 then by
      have _wf := div_wf_lemma h hq
      have ih := modByMonic_eq_sub_mul_div
        (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq
      

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q✝ p q : R[X]
hq : Monic q
this : DecidableEq R := Classical.decEq R
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) < degree p
ih :
  (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) %ₘ q =
    p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q)) -
      q * ((p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) /ₘ q)
⊢ p %ₘ q = p - q * (p /ₘ q)

Next tactic:
unfold modByMonic divByMonic divModByMonicAux
theorem modByMonic_eq_sub_mul_div :
    ∀ (p : R[X]) {q : R[X]} (_hq : Monic q), p %ₘ q = p - q * (p /ₘ q)
  | p, q, hq =>
    letI := Classical.decEq R
    if h : degree q ≤ degree p ∧ p ≠ 0 then by
      have _wf := div_wf_lemma h hq
      have ih := modByMonic_eq_sub_mul_div
        (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq
      unfold modByMonic divByMonic divModByMonicAux
      

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q✝ p q : R[X]
hq : Monic q
this : DecidableEq R := Classical.decEq R
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) < degree p
ih :
  (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) %ₘ q =
    p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q)) -
      q * ((p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) /ₘ q)
⊢ (if h : Monic q then
      (if h_1 : degree q ≤ degree p ∧ p ≠ 0 then
          let z := C (leadingCoeff p) * X ^ (natDegree p - natDegree q);
          let_fun _wf := (_ : degree (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) < degree p);
          let dm := divModByMonicAux (p - q * z) (_ : Monic q);
          (z + dm.1, dm.2)
        else (0, p)).2
    else p) =
    p -
      q *
        if h : Monic q then
          (if h_1 : degree q ≤ degree p ∧ p ≠ 0 then
              let z := C (leadingCoeff p) * X ^ (natDegree p - natDegree q);
              let_fun _wf := (_ : degree (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) < degree p);
              let dm := divModByMonicAux (p - q * z) (_ : Monic q);
              (z + dm.1, dm.2)
            else (0, p)).1
        else 0

Next tactic:
dsimp
theorem modByMonic_eq_sub_mul_div :
    ∀ (p : R[X]) {q : R[X]} (_hq : Monic q), p %ₘ q = p - q * (p /ₘ q)
  | p, q, hq =>
    letI := Classical.decEq R
    if h : degree q ≤ degree p ∧ p ≠ 0 then by
      have _wf := div_wf_lemma h hq
      have ih := modByMonic_eq_sub_mul_div
        (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq
      unfold modByMonic divByMonic divModByMonicAux
      dsimp
      

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q✝ p q : R[X]
hq : Monic q
this : DecidableEq R := Classical.decEq R
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) < degree p
ih :
  (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) %ₘ q =
    p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q)) -
      q * ((p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) /ₘ q)
⊢ (if h : Monic q then
      (if degree q ≤ degree p ∧ ¬p = 0 then
          (C (leadingCoeff p) * X ^ (natDegree p - natDegree q) +
              (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) (_ : Monic q)).1,
            (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) (_ : Monic q)).2)
        else (0, p)).2
    else p) =
    p -
      q *
        if h : Monic q then
          (if degree q ≤ degree p ∧ ¬p = 0 then
              (C (leadingCoeff p) * X ^ (natDegree p - natDegree q) +
                  (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) (_ : Monic q)).1,
                (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) (_ : Monic q)).2)
            else (0, p)).1
        else 0

Next tactic:
rw [dif_pos hq, if_pos h]
theorem modByMonic_eq_sub_mul_div :
    ∀ (p : R[X]) {q : R[X]} (_hq : Monic q), p %ₘ q = p - q * (p /ₘ q)
  | p, q, hq =>
    letI := Classical.decEq R
    if h : degree q ≤ degree p ∧ p ≠ 0 then by
      have _wf := div_wf_lemma h hq
      have ih := modByMonic_eq_sub_mul_div
        (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq
      unfold modByMonic divByMonic divModByMonicAux
      dsimp
      rw [dif_pos hq, if_pos h]
      

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q✝ p q : R[X]
hq : Monic q
this : DecidableEq R := Classical.decEq R
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) < degree p
ih :
  (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) %ₘ q =
    p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q)) -
      q * ((p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) /ₘ q)
⊢ (C (leadingCoeff p) * X ^ (natDegree p - natDegree q) +
          (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) (_ : Monic q)).1,
        (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) (_ : Monic q)).2).2 =
    p -
      q *
        if h : Monic q then
          (if degree q ≤ degree p ∧ ¬p = 0 then
              (C (leadingCoeff p) * X ^ (natDegree p - natDegree q) +
                  (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) (_ : Monic q)).1,
                (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) (_ : Monic q)).2)
            else (0, p)).1
        else 0

Next tactic:
rw [modByMonic, dif_pos hq] at ih
theorem modByMonic_eq_sub_mul_div :
    ∀ (p : R[X]) {q : R[X]} (_hq : Monic q), p %ₘ q = p - q * (p /ₘ q)
  | p, q, hq =>
    letI := Classical.decEq R
    if h : degree q ≤ degree p ∧ p ≠ 0 then by
      have _wf := div_wf_lemma h hq
      have ih := modByMonic_eq_sub_mul_div
        (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq
      unfold modByMonic divByMonic divModByMonicAux
      dsimp
      rw [dif_pos hq, if_pos h]
      rw [modByMonic, dif_pos hq] at ih
      

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q✝ p q : R[X]
hq : Monic q
this : DecidableEq R := Classical.decEq R
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) < degree p
ih :
  (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq).2 =
    p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q)) -
      q * ((p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) /ₘ q)
⊢ (C (leadingCoeff p) * X ^ (natDegree p - natDegree q) +
          (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) (_ : Monic q)).1,
        (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) (_ : Monic q)).2).2 =
    p -
      q *
        if h : Monic q then
          (if degree q ≤ degree p ∧ ¬p = 0 then
              (C (leadingCoeff p) * X ^ (natDegree p - natDegree q) +
                  (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) (_ : Monic q)).1,
                (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) (_ : Monic q)).2)
            else (0, p)).1
        else 0

Next tactic:
refine' ih.trans _
theorem modByMonic_eq_sub_mul_div :
    ∀ (p : R[X]) {q : R[X]} (_hq : Monic q), p %ₘ q = p - q * (p /ₘ q)
  | p, q, hq =>
    letI := Classical.decEq R
    if h : degree q ≤ degree p ∧ p ≠ 0 then by
      have _wf := div_wf_lemma h hq
      have ih := modByMonic_eq_sub_mul_div
        (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq
      unfold modByMonic divByMonic divModByMonicAux
      dsimp
      rw [dif_pos hq, if_pos h]
      rw [modByMonic, dif_pos hq] at ih
      refine' ih.trans _
      

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q✝ p q : R[X]
hq : Monic q
this : DecidableEq R := Classical.decEq R
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) < degree p
ih :
  (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq).2 =
    p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q)) -
      q * ((p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) /ₘ q)
⊢ p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q)) -
      q * ((p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) /ₘ q) =
    p -
      q *
        if h : Monic q then
          (if degree q ≤ degree p ∧ ¬p = 0 then
              (C (leadingCoeff p) * X ^ (natDegree p - natDegree q) +
                  (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) (_ : Monic q)).1,
                (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) (_ : Monic q)).2)
            else (0, p)).1
        else 0

Next tactic:
unfold divByMonic
theorem modByMonic_eq_sub_mul_div :
    ∀ (p : R[X]) {q : R[X]} (_hq : Monic q), p %ₘ q = p - q * (p /ₘ q)
  | p, q, hq =>
    letI := Classical.decEq R
    if h : degree q ≤ degree p ∧ p ≠ 0 then by
      have _wf := div_wf_lemma h hq
      have ih := modByMonic_eq_sub_mul_div
        (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq
      unfold modByMonic divByMonic divModByMonicAux
      dsimp
      rw [dif_pos hq, if_pos h]
      rw [modByMonic, dif_pos hq] at ih
      refine' ih.trans _
      unfold divByMonic
      

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q✝ p q : R[X]
hq : Monic q
this : DecidableEq R := Classical.decEq R
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) < degree p
ih :
  (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq).2 =
    p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q)) -
      q * ((p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) /ₘ q)
⊢ (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q)) -
      q *
        if hq : Monic q then (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq).1
        else 0) =
    p -
      q *
        if h : Monic q then
          (if degree q ≤ degree p ∧ ¬p = 0 then
              (C (leadingCoeff p) * X ^ (natDegree p - natDegree q) +
                  (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) (_ : Monic q)).1,
                (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) (_ : Monic q)).2)
            else (0, p)).1
        else 0

Next tactic:
rw [dif_pos hq, dif_pos hq, if_pos h, mul_add, sub_add_eq_sub_sub]
theorem modByMonic_eq_sub_mul_div :
    ∀ (p : R[X]) {q : R[X]} (_hq : Monic q), p %ₘ q = p - q * (p /ₘ q)
  | p, q, hq =>
    letI := Classical.decEq R
    if h : degree q ≤ degree p ∧ p ≠ 0 then by
      have _wf := div_wf_lemma h hq
      have ih := modByMonic_eq_sub_mul_div
        (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq
      unfold modByMonic divByMonic divModByMonicAux
      dsimp
      rw [dif_pos hq, if_pos h]
      rw [modByMonic, dif_pos hq] at ih
      refine' ih.trans _
      unfold divByMonic
      rw [dif_pos hq, dif_pos hq, if_pos h, mul_add, sub_add_eq_sub_sub]
    else by
      

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q✝ p q : R[X]
hq : Monic q
this : DecidableEq R := Classical.decEq R
h : ¬(degree q ≤ degree p ∧ p ≠ 0)
⊢ p %ₘ q = p - q * (p /ₘ q)

Next tactic:
unfold modByMonic divByMonic divModByMonicAux
theorem modByMonic_eq_sub_mul_div :
    ∀ (p : R[X]) {q : R[X]} (_hq : Monic q), p %ₘ q = p - q * (p /ₘ q)
  | p, q, hq =>
    letI := Classical.decEq R
    if h : degree q ≤ degree p ∧ p ≠ 0 then by
      have _wf := div_wf_lemma h hq
      have ih := modByMonic_eq_sub_mul_div
        (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq
      unfold modByMonic divByMonic divModByMonicAux
      dsimp
      rw [dif_pos hq, if_pos h]
      rw [modByMonic, dif_pos hq] at ih
      refine' ih.trans _
      unfold divByMonic
      rw [dif_pos hq, dif_pos hq, if_pos h, mul_add, sub_add_eq_sub_sub]
    else by
      unfold modByMonic divByMonic divModByMonicAux
      

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q✝ p q : R[X]
hq : Monic q
this : DecidableEq R := Classical.decEq R
h : ¬(degree q ≤ degree p ∧ p ≠ 0)
⊢ (if h : Monic q then
      (if h_1 : degree q ≤ degree p ∧ p ≠ 0 then
          let z := C (leadingCoeff p) * X ^ (natDegree p - natDegree q);
          let_fun _wf := (_ : degree (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) < degree p);
          let dm := divModByMonicAux (p - q * z) (_ : Monic q);
          (z + dm.1, dm.2)
        else (0, p)).2
    else p) =
    p -
      q *
        if h : Monic q then
          (if h_1 : degree q ≤ degree p ∧ p ≠ 0 then
              let z := C (leadingCoeff p) * X ^ (natDegree p - natDegree q);
              let_fun _wf := (_ : degree (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) < degree p);
              let dm := divModByMonicAux (p - q * z) (_ : Monic q);
              (z + dm.1, dm.2)
            else (0, p)).1
        else 0

Next tactic:
dsimp
theorem modByMonic_eq_sub_mul_div :
    ∀ (p : R[X]) {q : R[X]} (_hq : Monic q), p %ₘ q = p - q * (p /ₘ q)
  | p, q, hq =>
    letI := Classical.decEq R
    if h : degree q ≤ degree p ∧ p ≠ 0 then by
      have _wf := div_wf_lemma h hq
      have ih := modByMonic_eq_sub_mul_div
        (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) hq
      unfold modByMonic divByMonic divModByMonicAux
      dsimp
      rw [dif_pos hq, if_pos h]
      rw [modByMonic, dif_pos hq] at ih
      refine' ih.trans _
      unfold divByMonic
      rw [dif_pos hq, dif_pos hq, if_pos h, mul_add, sub_add_eq_sub_sub]
    else by
      unfold modByMonic divByMonic divModByMonicAux
      dsimp
      

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : Ring R
p✝ q✝ p q : R[X]
hq : Monic q
this : DecidableEq R := Classical.decEq R
h : ¬(degree q ≤ degree p ∧ p ≠ 0)
⊢ (if h : Monic q then
      (if degree q ≤ degree p ∧ ¬p = 0 then
          (C (leadingCoeff p) * X ^ (natDegree p - natDegree q) +
              (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) (_ : Monic q)).1,
            (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) (_ : Monic q)).2)
        else (0, p)).2
    else p) =
    p -
      q *
        if h : Monic q then
          (if degree q ≤ degree p ∧ ¬p = 0 then
              (C (leadingCoeff p) * X ^ (natDegree p - natDegree q) +
                  (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) (_ : Monic q)).1,
                (divModByMonicAux (p - q * (C (leadingCoeff p) * X ^ (natDegree p - natDegree q))) (_ : Monic q)).2)
            else (0, p)).1
        else 0

Next tactic:
rw [dif_pos hq, if_neg h, dif_pos hq, if_neg h, mul_zero, sub_zero]
theorem divByMonic_eq_zero_iff [Nontrivial R] (hq : Monic q) : p /ₘ q = 0 ↔ degree p < degree q :=
  ⟨fun h => by
    

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝¹ : Ring R
p q : R[X]
inst✝ : Nontrivial R
hq : Monic q
h : p /ₘ q = 0
⊢ degree p < degree q

Next tactic:
have := modByMonic_add_div p hq
theorem divByMonic_eq_zero_iff [Nontrivial R] (hq : Monic q) : p /ₘ q = 0 ↔ degree p < degree q :=
  ⟨fun h => by
    have := modByMonic_add_div p hq;
      

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝¹ : Ring R
p q : R[X]
inst✝ : Nontrivial R
hq : Monic q
h : p /ₘ q = 0
this : p %ₘ q + q * (p /ₘ q) = p
⊢ degree p < degree q

Next tactic:
rwa [h, mul_zero, add_zero, modByMonic_eq_self_iff hq] at this
theorem divByMonic_eq_zero_iff [Nontrivial R] (hq : Monic q) : p /ₘ q = 0 ↔ degree p < degree q :=
  ⟨fun h => by
    have := modByMonic_add_div p hq;
      rwa [h, mul_zero, add_zero, modByMonic_eq_self_iff hq] at this,
  fun h => by
    

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝¹ : Ring R
p q : R[X]
inst✝ : Nontrivial R
hq : Monic q
h : degree p < degree q
⊢ p /ₘ q = 0

Next tactic:
classical
    have : ¬degree q ≤ degree p := not_le_of_gt h
    unfold divByMonic divModByMonicAux; dsimp; rw [dif_pos hq, if_neg (mt And.left this)]
theorem divByMonic_eq_zero_iff [Nontrivial R] (hq : Monic q) : p /ₘ q = 0 ↔ degree p < degree q :=
  ⟨fun h => by
    have := modByMonic_add_div p hq;
      rwa [h, mul_zero, add_zero, modByMonic_eq_self_iff hq] at this,
  fun h => by
    classical
    

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝¹ : Ring R
p q : R[X]
inst✝ : Nontrivial R
hq : Monic q
h : degree p < degree q
⊢ p /ₘ q = 0

Next tactic:
have : ¬degree q ≤ degree p := not_le_of_gt h
theorem divByMonic_eq_zero_iff [Nontrivial R] (hq : Monic q) : p /ₘ q = 0 ↔ degree p < degree q :=
  ⟨fun h => by
    have := modByMonic_add_div p hq;
      rwa [h, mul_zero, add_zero, modByMonic_eq_self_iff hq] at this,
  fun h => by
    classical
    have : ¬degree q ≤ degree p := not_le_of_gt h
    

Proof state:
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝¹ : Ring R
p q : R[X]
inst✝ : Nontrivial R
hq : Monic q
h : degree p < degree q
this : ¬degree q ≤ degree p
⊢ p /ₘ q = 0

Next tactic:
unfold divByMonic divModByMonicAux