R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p✝ q✝ p q : R[X]
hq : Monic q
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p
⊢ p %ₘ q = p - q * (p /ₘ q)
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p✝ q✝ p q : R[X]
hq : Monic q
h : degree q ≤ degree p ∧ p ≠ 0
⊢ p %ₘ q = p - q * (p /ₘ q)
have _wf := div_wf_lemma h hq
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p✝ q✝ p q : R[X]
hq : Monic q
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p
ih :
  (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) %ₘ q =
    p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q -
      q * ((p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) /ₘ q)
⊢ p %ₘ q = p - q * (p /ₘ q)
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p✝ q✝ p q : R[X]
hq : Monic q
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p
⊢ p %ₘ q = p - q * (p /ₘ q)
have ih :=
  modByMonic_eq_sub_mul_div (p - C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) hq
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p✝ q✝ p q : R[X]
hq : Monic q
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p
ih :
  (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) %ₘ q =
    p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q -
      q * ((p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * 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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p);
          let dm := divModByMonicAux (p - z * q) (_ : Monic q);
          (z + dm.fst, dm.snd)
        else (0, p)).snd
    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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p);
              let dm := divModByMonicAux (p - z * q) (_ : Monic q);
              (z + dm.fst, dm.snd)
            else (0, p)).fst
        else 0
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p✝ q✝ p q : R[X]
hq : Monic q
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p
ih :
  (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) %ₘ q =
    p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q -
      q * ((p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) /ₘ q)
⊢ p %ₘ q = p - q * (p /ₘ q)
unfold modByMonic divByMonic divModByMonicAux
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p✝ q✝ p q : R[X]
hq : Monic q
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p
ih :
  (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) %ₘ q =
    p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q -
      q * ((p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * 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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).fst,
            (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).snd)
        else (0, p)).snd
    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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).fst,
                (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).snd)
            else (0, p)).fst
        else 0
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p✝ q✝ p q : R[X]
hq : Monic q
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p
ih :
  (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) %ₘ q =
    p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q -
      q * ((p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * 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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p);
          let dm := divModByMonicAux (p - z * q) (_ : Monic q);
          (z + dm.fst, dm.snd)
        else (0, p)).snd
    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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p);
              let dm := divModByMonicAux (p - z * q) (_ : Monic q);
              (z + dm.fst, dm.snd)
            else (0, p)).fst
        else 0
dsimp
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p✝ q✝ p q : R[X]
hq : Monic q
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p
ih :
  (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) %ₘ q =
    p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q -
      q * ((p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) /ₘ q)
⊢ (↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) +
          (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).fst,
        (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).snd).snd =
    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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).fst,
                (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).snd)
            else (0, p)).fst
        else 0
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p✝ q✝ p q : R[X]
hq : Monic q
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p
ih :
  (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) %ₘ q =
    p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q -
      q * ((p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * 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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).fst,
            (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).snd)
        else (0, p)).snd
    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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).fst,
                (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).snd)
            else (0, p)).fst
        else 0
rw [dif_pos hq, if_pos h]
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p✝ q✝ p q : R[X]
hq : Monic q
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p
ih :
  (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) hq).snd =
    p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q -
      q * ((p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) /ₘ q)
⊢ (↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) +
          (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).fst,
        (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).snd).snd =
    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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).fst,
                (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).snd)
            else (0, p)).fst
        else 0
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p✝ q✝ p q : R[X]
hq : Monic q
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p
ih :
  (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) %ₘ q =
    p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q -
      q * ((p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) /ₘ q)
⊢ (↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) +
          (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).fst,
        (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).snd).snd =
    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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).fst,
                (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).snd)
            else (0, p)).fst
        else 0
rw [modByMonic, dif_pos hq] at ih
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p✝ q✝ p q : R[X]
hq : Monic q
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p
ih :
  (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) hq).snd =
    p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q -
      q * ((p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) /ₘ q)
⊢ p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q -
      q * ((p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * 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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).fst,
                (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).snd)
            else (0, p)).fst
        else 0
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p✝ q✝ p q : R[X]
hq : Monic q
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p
ih :
  (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) hq).snd =
    p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q -
      q * ((p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) /ₘ q)
⊢ (↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) +
          (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).fst,
        (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).snd).snd =
    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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).fst,
                (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).snd)
            else (0, p)).fst
        else 0
refine' ih.trans _
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p✝ q✝ p q : R[X]
hq : Monic q
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p
ih :
  (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) hq).snd =
    p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q -
      q * ((p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) /ₘ q)
⊢ (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q -
      q *
        if hq : Monic q then (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) hq).fst
        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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).fst,
                (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).snd)
            else (0, p)).fst
        else 0
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p✝ q✝ p q : R[X]
hq : Monic q
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p
ih :
  (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) hq).snd =
    p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q -
      q * ((p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) /ₘ q)
⊢ p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q -
      q * ((p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * 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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).fst,
                (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).snd)
            else (0, p)).fst
        else 0
unfold divByMonic
no goals
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p✝ q✝ p q : R[X]
hq : Monic q
h : degree q ≤ degree p ∧ p ≠ 0
_wf : degree (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p
ih :
  (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) hq).snd =
    p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q -
      q * ((p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) /ₘ q)
⊢ (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q -
      q *
        if hq : Monic q then (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) hq).fst
        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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).fst,
                (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).snd)
            else (0, p)).fst
        else 0
rw [dif_pos hq, dif_pos hq, if_pos h, mul_add, sub_add_eq_sub_sub, mul_comm]
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p✝ q✝ p q : R[X]
hq : Monic q
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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p);
          let dm := divModByMonicAux (p - z * q) (_ : Monic q);
          (z + dm.fst, dm.snd)
        else (0, p)).snd
    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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p);
              let dm := divModByMonicAux (p - z * q) (_ : Monic q);
              (z + dm.fst, dm.snd)
            else (0, p)).fst
        else 0
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p✝ q✝ p q : R[X]
hq : Monic q
h : ¬(degree q ≤ degree p ∧ p ≠ 0)
⊢ p %ₘ q = p - q * (p /ₘ q)
unfold modByMonic divByMonic divModByMonicAux
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p✝ q✝ p q : R[X]
hq : Monic q
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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).fst,
            (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).snd)
        else (0, p)).snd
    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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).fst,
                (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).snd)
            else (0, p)).fst
        else 0
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p✝ q✝ p q : R[X]
hq : Monic q
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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p);
          let dm := divModByMonicAux (p - z * q) (_ : Monic q);
          (z + dm.fst, dm.snd)
        else (0, p)).snd
    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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) < degree p);
              let dm := divModByMonicAux (p - z * q) (_ : Monic q);
              (z + dm.fst, dm.snd)
            else (0, p)).fst
        else 0
dsimp
no goals
R : Type u
S : Type v
T : Type w
A : Type z
a b : R
n : ℕ
inst✝ : CommRing R
p✝ q✝ p q : R[X]
hq : Monic q
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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).fst,
            (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).snd)
        else (0, p)).snd
    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 - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).fst,
                (divModByMonicAux (p - ↑C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) (_ : Monic q)).snd)
            else (0, p)).fst
        else 0
rw [dif_pos hq, if_neg h, dif_pos hq, if_neg h, MulZeroClass.mul_zero, sub_zero]