-- Lean 4 proof step from Mathlib.RingTheory.Polynomial.UniqueFactorization (goal)
Goal:
R : Type u_1
inst : CommSemiring R
inst_1 : NoZeroDivisors R
inst_2 : WfDvdMonoid R
f : R[X]
p :
  ∀ {a b : R[X]},
    DvdNotUnit a b →
      Prod.Lex.{0, u_1} (β := R) (fun (x1 x2 : WithTop (WithBot ℕ)) ↦ x1 < x2) DvdNotUnit
        ((fun (p : R[X]) ↦ (if p = 0 then ⊤ else (↑p.degree : WithTop (WithBot ℕ)), p.leadingCoeff)) a)
        ((fun (p : R[X]) ↦ (if p = 0 then ⊤ else (↑p.degree : WithTop (WithBot ℕ)), p.leadingCoeff)) b)
p₁ :
  ∀ {a : R[X]} (ane0 : a ≠ 0) (c : R[X]) (not_unit_c : ¬IsUnit c),
    Prod.Lex.{0, u_1} (β := R) (fun (x1 x2 : WithTop (WithBot ℕ)) ↦ x1 < x2) DvdNotUnit
      ((fun (p : R[X]) ↦ (if p = 0 then ⊤ else (↑p.degree : WithTop (WithBot ℕ)), p.leadingCoeff)) a)
      ((fun (p : R[X]) ↦ (if p = 0 then ⊤ else (↑p.degree : WithTop (WithBot ℕ)), p.leadingCoeff)) (a * c))
p₂ :
  ∀ {a : R[X]} (ane0 : a ≠ 0) (c : R[X]) (not_unit_c : ¬IsUnit c),
    Prod.Lex (fun (x1 x2 : WithTop (WithBot ℕ)) ↦ x1 < x2) DvdNotUnit
      (if a = 0 then ⊤ else (↑a.degree : WithTop (WithBot ℕ)), a.leadingCoeff)
      (if a * c = 0 then ⊤ else (↑(a * c).degree : WithTop (WithBot ℕ)), (a * c).leadingCoeff)
p₃ :
  ∀ {a : R[X]} (ane0 : a ≠ 0) (c : R[X]) (not_unit_c : ¬IsUnit c),
    Prod.Lex (fun (x1 x2 : WithTop (WithBot ℕ)) ↦ x1 < x2) DvdNotUnit
      ((↑a.degree : WithTop (WithBot ℕ)), a.leadingCoeff)
      (if a * c = 0 then ⊤ else (↑(a.degree + c.degree) : WithTop (WithBot ℕ)), (a * c).leadingCoeff)
pos :
  ∀ {a : R[X]} (ane0 : a ≠ 0) (c : R[X]) (not_unit_c : ¬IsUnit c) (hac : a * c = 0),
    Prod.Lex (fun (x1 x2 : WithTop (WithBot ℕ)) ↦ x1 < x2) DvdNotUnit
      ((↑a.degree : WithTop (WithBot ℕ)), a.leadingCoeff) (⊤, (a * c).leadingCoeff)
neg neg₁ :
  ∀ {a : R[X]} (ane0 : a ≠ 0) (c : R[X]) (not_unit_c : ¬IsUnit c) (hac : ¬a * c = 0),
    Prod.Lex (fun (x1 x2 : WithTop (WithBot ℕ)) ↦ x1 < x2) DvdNotUnit
      ((↑a.degree : WithTop (WithBot ℕ)), a.leadingCoeff)
      ((↑(a.degree + c.degree) : WithTop (WithBot ℕ)), (a * c).leadingCoeff)
neg₂ :
  ∀ {a : R[X]} (ane0 : a ≠ 0) (c : R[X]) (not_unit_c : ¬IsUnit c) (hac : ¬a * c = 0) (cne0 : c ≠ 0),
    Prod.Lex (fun (x1 x2 : WithTop (WithBot ℕ)) ↦ x1 < x2) DvdNotUnit
      ((↑a.degree : WithTop (WithBot ℕ)), a.leadingCoeff)
      ((↑(a.degree + c.degree) : WithTop (WithBot ℕ)), (a * c).leadingCoeff)
neg₃ :
  ∀ {a : R[X]} (ane0 : a ≠ 0) (c : R[X]) (not_unit_c : ¬IsUnit c) (hac : ¬a * c = 0) (cne0 : c ≠ 0),
    Prod.Lex (fun (x1 x2 : WithTop (WithBot ℕ)) ↦ x1 < x2) DvdNotUnit
      ((↑a.degree : WithTop (WithBot ℕ)), a.leadingCoeff)
      ((↑(a.degree + c.degree) : WithTop (WithBot ℕ)), a.leadingCoeff * c.leadingCoeff)
⊢ WellFounded.{u_1 + 1} (α := R[X]) DvdNotUnit
have pos₁ : ∀ {a : R[X]} (ane0 : a ≠ 0) (c : R[X]) (not_unit_c : ¬IsUnit c) (hac : ¬a * c = 0) (cne0 : c ≠ 0)
  (hdeg : c.degree = (↑0 : WithBot ℕ)),
  Prod.Lex (fun (x1 x2 : WithTop (WithBot ℕ)) ↦ x1 < x2) DvdNotUnit ((↑a.degree : WithTop (WithBot ℕ)), a.leadingCoeff)
    ((↑(a.degree + c.degree) : WithTop (WithBot ℕ)), a.leadingCoeff * c.leadingCoeff)
Tactic: classical
      refine
        RelHomClass.wellFounded
          (⟨fun p : R[X] =>
              ((if p = 0 then ⊤ else ↑p.degree : WithTop (WithBot ℕ)), p.leadingCoeff), ?_⟩ :
            DvdNotUnit →r Prod.Lex (· < ·) DvdNotUnit)
          (wellFounded_lt.prod_lex ‹WfDvdMonoid R›.wf)
      rintro a b ⟨ane0, ⟨c, ⟨not_unit_c, rfl⟩⟩⟩
      dsimp
      rw [Polynomial.degree_mul, if_neg ane0]
      split_ifs with hac
      · rw [hac, Polynomial.leadingCoeff_zero]
        apply Prod.Lex.left
        exact WithTop.coe_lt_top _
      have cne0 : c ≠ 0 := right_ne_zero_of_mul hac
      simp only [Polynomial.leadingCoeff_mul]
      by_cases hdeg : c.degree = (0 : ℕ)
      · simp only [hdeg, Nat.cast_zero, add_zero]
        refine Prod.Lex.right _ ⟨?_, ⟨c.leadingCoeff, fun unit_c => not_unit_c ?_, rfl⟩⟩
        · rwa [Ne, Polynomial.leadingCoeff_eq_zero]
        rw [Polynomial.isUnit_iff, Polynomial.eq_C_of_degree_eq_zero hdeg]
        use c.leadingCoeff, unit_c
        rw [Polynomial.leadingCoeff, Polynomial.natDegree_eq_of_degree_eq_some hdeg]
      · apply Prod.Lex.left
        rw [Polynomial.degree_eq_natDegree cne0] at *
        simp only [Nat.cast_inj] at hdeg
        rw [WithTop.coe_lt_coe, Polynomial.degree_eq_natDegree ane0, ← Nat.cast_add, Nat.cast_lt]
        exact lt_add_of_pos_right _ (Nat.pos_of_ne_zero hdeg)