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

tactic: have _wf := div_wf_lemma h hq
state_before: 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)

tactic: have ih :=
  modByMonic_eq_sub_mul_div (p - C (leadingCoeff p) * X ^ (natDegree p - natDegree q) * q) hq
state_before: 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)

tactic: unfold modByMonic divByMonic divModByMonicAux
state_before: 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)

tactic: dsimp
state_before: 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

tactic: rw [dif_pos hq, if_pos h]
state_before: 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

tactic: rw [modByMonic, dif_pos hq] at ih
state_before: 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

tactic: refine' ih.trans _
state_before: 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

tactic: unfold divByMonic
state_before: 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

tactic: rw [dif_pos hq, dif_pos hq, if_pos h, mul_add, sub_add_eq_sub_sub, mul_comm]
state_before: 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

tactic: unfold modByMonic divByMonic divModByMonicAux
state_before: 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)

tactic: dsimp
state_before: 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

tactic: rw [dif_pos hq, if_neg h, dif_pos hq, if_neg h, MulZeroClass.mul_zero, sub_zero]
state_before: 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