Module docstring
{"# Degree of polynomials that are units "}
{"# Degree of polynomials that are units "}
Polynomial.natDegree_eq_zero_of_isUnit
      theorem
     (h : IsUnit p) : natDegree p = 0
        lemma natDegree_eq_zero_of_isUnit (h : IsUnit p) : natDegree p = 0 := by
  nontriviality R
  obtain ⟨q, hq⟩ := h.exists_right_inv
  have := natDegree_mul (left_ne_zero_of_mul_eq_one hq) (right_ne_zero_of_mul_eq_one hq)
  rw [hq, natDegree_one, eq_comm, add_eq_zero] at this
  exact this.1
        Polynomial.degree_eq_zero_of_isUnit
      theorem
     [Nontrivial R] (h : IsUnit p) : degree p = 0
        lemma degree_eq_zero_of_isUnit [Nontrivial R] (h : IsUnit p) : degree p = 0 :=
  (natDegree_eq_zero_iff_degree_le_zero.mp <| natDegree_eq_zero_of_isUnit h).antisymm
    (zero_le_degree_iff.mpr h.ne_zero)
        Polynomial.degree_coe_units
      theorem
     [Nontrivial R] (u : R[X]ˣ) : degree (u : R[X]) = 0
        @[simp]
lemma degree_coe_units [Nontrivial R] (u : R[X]R[X]ˣ) : degree (u : R[X]) = 0 :=
  degree_eq_zero_of_isUnit ⟨u, rfl⟩
        Polynomial.isUnit_iff
      theorem
     : IsUnit p ↔ ∃ r : R, IsUnit r ∧ C r = p
        /-- Characterization of a unit of a polynomial ring over an integral domain `R`.
See `Polynomial.isUnit_iff_coeff_isUnit_isNilpotent` when `R` is a commutative ring. -/
lemma isUnit_iff : IsUnitIsUnit p ↔ ∃ r : R, IsUnit r ∧ C r = p :=
  ⟨fun hp =>
    ⟨p.coeff 0,
      let h := eq_C_of_natDegree_eq_zero (natDegree_eq_zero_of_isUnit hp)
      ⟨isUnit_C.1 (h ▸ hp), h.symm⟩⟩,
    fun ⟨_, hr, hrp⟩ => hrp ▸ isUnit_C.2 hr⟩
        Polynomial.not_isUnit_of_degree_pos
      theorem
     (p : R[X]) (hpl : 0 < p.degree) : ¬IsUnit p
        lemma not_isUnit_of_degree_pos (p : R[X]) (hpl : 0 < p.degree) : ¬ IsUnit p := by
  cases subsingleton_or_nontrivial R
  · simp [Subsingleton.elim p 0] at hpl
  intro h
  simp [degree_eq_zero_of_isUnit h] at hpl
        Polynomial.not_isUnit_of_natDegree_pos
      theorem
     (p : R[X]) (hpl : 0 < p.natDegree) : ¬IsUnit p
        lemma not_isUnit_of_natDegree_pos (p : R[X]) (hpl : 0 < p.natDegree) : ¬ IsUnit p :=
  not_isUnit_of_degree_pos _ (natDegree_pos_iff_degree_pos.mp hpl)
        Polynomial.natDegree_coe_units
      theorem
     (u : R[X]ˣ) : natDegree (u : R[X]) = 0
        @[simp] lemma natDegree_coe_units (u : R[X]R[X]ˣ) : natDegree (u : R[X]) = 0 := by
  nontriviality R
  exact natDegree_eq_of_degree_eq_some (degree_coe_units u)
        Polynomial.coeff_coe_units_zero_ne_zero
      theorem
     [Nontrivial R] (u : R[X]ˣ) : coeff (u : R[X]) 0 ≠ 0
        theorem coeff_coe_units_zero_ne_zero [Nontrivial R] (u : R[X]R[X]ˣ) : coeffcoeff (u : R[X]) 0 ≠ 0 := by
  conv in 0 => rw [← natDegree_coe_units u]
  rw [← leadingCoeff, Ne, leadingCoeff_eq_zero]
  exact Units.ne_zero _
        Polynomial.Monic.C_dvd_iff_isUnit
      theorem
     {a : R} : C a ∣ p ↔ IsUnit a
        lemma Monic.C_dvd_iff_isUnit {a : R} : CC a ∣ pC a ∣ p ↔ IsUnit a where
  mp h := isUnit_iff_dvd_one.mpr <| hp.coeff_natDegree ▸ (C_dvd_iff_dvd_coeff _ _).mp h p.natDegree
  mpr ha := (ha.map C).dvd
        Polynomial.Monic.degree_pos_of_not_isUnit
      theorem
     (hu : ¬IsUnit p) : 0 < degree p
        lemma Monic.degree_pos_of_not_isUnit (hu : ¬IsUnit p) : 0 < degree p :=
  hp.degree_pos.mpr fun hp' ↦ (hp' ▸ hu) isUnit_one
        Polynomial.Monic.natDegree_pos_of_not_isUnit
      theorem
     (hu : ¬IsUnit p) : 0 < natDegree p
        lemma Monic.natDegree_pos_of_not_isUnit (hu : ¬IsUnit p) : 0 < natDegree p :=
  hp.natDegree_pos.mpr fun hp' ↦ (hp' ▸ hu) isUnit_one
        Polynomial.degree_pos_of_not_isUnit_of_dvd_monic
      theorem
     (ha : ¬IsUnit a) (hap : a ∣ p) : 0 < degree a
        lemma degree_pos_of_not_isUnit_of_dvd_monic (ha : ¬IsUnit a) (hap : a ∣ p) : 0 < degree a := by
  contrapose! ha with h
  rw [Polynomial.eq_C_of_degree_le_zero h] at hap ⊢
  simpa [hp.C_dvd_iff_isUnit, isUnit_C] using hap
        Polynomial.natDegree_pos_of_not_isUnit_of_dvd_monic
      theorem
     (ha : ¬IsUnit a) (hap : a ∣ p) : 0 < natDegree a
        lemma natDegree_pos_of_not_isUnit_of_dvd_monic (ha : ¬IsUnit a) (hap : a ∣ p) : 0 < natDegree a :=
  natDegree_pos_iff_degree_pos.mpr <| degree_pos_of_not_isUnit_of_dvd_monic hp ha hap