l3lab/ntp-mathlib huggingface dataset:
theorem eq_zero_or_eq_zero_of_mul_eq_zero [NoZeroDivisors R] (φ ψ : R⟦X⟧) (h : φ * ψ = 0) :
    φ = 0 ∨ ψ = 0 := by
  classical
  rw [or_iff_not_imp_left]
  intro H
  have ex : ∃ m, coeff R m φ ≠ 0 := by
    contrapose! H
    exact ext H
  let m := Nat.find ex
  have hm₁ : coeff R m φ ≠ 0 := Nat.find_spec ex
  have hm₂ : ∀ k < m, ¬coeff R k φ ≠ 0 := fun k => Nat.find_min ex
  ext n
  rw [(coeff R n).map_zero]
  induction' n using Nat.strong_induction_on with n ih
  replace h := congr_arg (coeff R (m + n)) h
  rw [LinearMap.map_zero, coeff_mul, Finset.sum_eq_single (m, n)] at h
  · replace h := NoZeroDivisors.eq_zero_or_eq_zero_of_mul_eq_zero h
    rw [or_iff_not_imp_left] at h
    exact h hm₁
  · rintro ⟨i, j⟩ hij hne
    by_cases hj : j < n
    · rw [ih j hj, mul_zero]
    by_cases hi : i < m
    · specialize hm₂ _ hi
      push_neg at hm₂
      rw [hm₂, zero_mul]
    rw [mem_antidiagonal] at hij
    push_neg at hi hj
    suffices m < i by
      have : m + n < i + j := add_lt_add_of_lt_of_le this hj
      exfalso
      exact ne_of_lt this hij.symm
    contrapose! hne
    obtain rfl := le_antisymm hi hne
    simpa [Ne.def, Prod.mk.inj_iff] using (add_right_inj m).mp hij
  · 

Proof state:
case h.h.h₁
R : Type u_1
inst✝¹ : Ring R
inst✝ : NoZeroDivisors R
φ ψ : R⟦X⟧
H : ¬φ = 0
ex : ∃ m, (coeff R m) φ ≠ 0
m : ℕ := Nat.find ex
hm₁ : (coeff R m) φ ≠ 0
hm₂ : ∀ k < m, ¬(coeff R k) φ ≠ 0
n : ℕ
ih : ∀ m < n, (coeff R m) ψ = 0
h : ∑ p in antidiagonal (m + n), (coeff R p.1) φ * (coeff R p.2) ψ = 0
⊢ (m, n) ∉ antidiagonal (m + n) → (coeff R (m, n).1) φ * (coeff R (m, n).2) ψ = 0

Next tactic:
contrapose!
theorem eq_zero_or_eq_zero_of_mul_eq_zero [NoZeroDivisors R] (φ ψ : R⟦X⟧) (h : φ * ψ = 0) :
    φ = 0 ∨ ψ = 0 := by
  classical
  rw [or_iff_not_imp_left]
  intro H
  have ex : ∃ m, coeff R m φ ≠ 0 := by
    contrapose! H
    exact ext H
  let m := Nat.find ex
  have hm₁ : coeff R m φ ≠ 0 := Nat.find_spec ex
  have hm₂ : ∀ k < m, ¬coeff R k φ ≠ 0 := fun k => Nat.find_min ex
  ext n
  rw [(coeff R n).map_zero]
  induction' n using Nat.strong_induction_on with n ih
  replace h := congr_arg (coeff R (m + n)) h
  rw [LinearMap.map_zero, coeff_mul, Finset.sum_eq_single (m, n)] at h
  · replace h := NoZeroDivisors.eq_zero_or_eq_zero_of_mul_eq_zero h
    rw [or_iff_not_imp_left] at h
    exact h hm₁
  · rintro ⟨i, j⟩ hij hne
    by_cases hj : j < n
    · rw [ih j hj, mul_zero]
    by_cases hi : i < m
    · specialize hm₂ _ hi
      push_neg at hm₂
      rw [hm₂, zero_mul]
    rw [mem_antidiagonal] at hij
    push_neg at hi hj
    suffices m < i by
      have : m + n < i + j := add_lt_add_of_lt_of_le this hj
      exfalso
      exact ne_of_lt this hij.symm
    contrapose! hne
    obtain rfl := le_antisymm hi hne
    simpa [Ne.def, Prod.mk.inj_iff] using (add_right_inj m).mp hij
  · contrapose!
    

Proof state:
case h.h.h₁
R : Type u_1
inst✝¹ : Ring R
inst✝ : NoZeroDivisors R
φ ψ : R⟦X⟧
H : ¬φ = 0
ex : ∃ m, (coeff R m) φ ≠ 0
m : ℕ := Nat.find ex
hm₁ : (coeff R m) φ ≠ 0
hm₂ : ∀ k < m, ¬(coeff R k) φ ≠ 0
n : ℕ
ih : ∀ m < n, (coeff R m) ψ = 0
h : ∑ p in antidiagonal (m + n), (coeff R p.1) φ * (coeff R p.2) ψ = 0
⊢ (coeff R (m, n).1) φ * (coeff R (m, n).2) ψ ≠ 0 → (m, n) ∈ antidiagonal (m + n)

Next tactic:
intro
theorem eq_zero_or_eq_zero_of_mul_eq_zero [NoZeroDivisors R] (φ ψ : R⟦X⟧) (h : φ * ψ = 0) :
    φ = 0 ∨ ψ = 0 := by
  classical
  rw [or_iff_not_imp_left]
  intro H
  have ex : ∃ m, coeff R m φ ≠ 0 := by
    contrapose! H
    exact ext H
  let m := Nat.find ex
  have hm₁ : coeff R m φ ≠ 0 := Nat.find_spec ex
  have hm₂ : ∀ k < m, ¬coeff R k φ ≠ 0 := fun k => Nat.find_min ex
  ext n
  rw [(coeff R n).map_zero]
  induction' n using Nat.strong_induction_on with n ih
  replace h := congr_arg (coeff R (m + n)) h
  rw [LinearMap.map_zero, coeff_mul, Finset.sum_eq_single (m, n)] at h
  · replace h := NoZeroDivisors.eq_zero_or_eq_zero_of_mul_eq_zero h
    rw [or_iff_not_imp_left] at h
    exact h hm₁
  · rintro ⟨i, j⟩ hij hne
    by_cases hj : j < n
    · rw [ih j hj, mul_zero]
    by_cases hi : i < m
    · specialize hm₂ _ hi
      push_neg at hm₂
      rw [hm₂, zero_mul]
    rw [mem_antidiagonal] at hij
    push_neg at hi hj
    suffices m < i by
      have : m + n < i + j := add_lt_add_of_lt_of_le this hj
      exfalso
      exact ne_of_lt this hij.symm
    contrapose! hne
    obtain rfl := le_antisymm hi hne
    simpa [Ne.def, Prod.mk.inj_iff] using (add_right_inj m).mp hij
  · contrapose!
    intro
    

Proof state:
case h.h.h₁
R : Type u_1
inst✝¹ : Ring R
inst✝ : NoZeroDivisors R
φ ψ : R⟦X⟧
H : ¬φ = 0
ex : ∃ m, (coeff R m) φ ≠ 0
m : ℕ := Nat.find ex
hm₁ : (coeff R m) φ ≠ 0
hm₂ : ∀ k < m, ¬(coeff R k) φ ≠ 0
n : ℕ
ih : ∀ m < n, (coeff R m) ψ = 0
h : ∑ p in antidiagonal (m + n), (coeff R p.1) φ * (coeff R p.2) ψ = 0
a✝ : (coeff R (m, n).1) φ * (coeff R (m, n).2) ψ ≠ 0
⊢ (m, n) ∈ antidiagonal (m + n)

Next tactic:
rw [mem_antidiagonal]
/-- The ideal spanned by the variable in the power series ring
 over an integral domain is a prime ideal.-/
theorem span_X_isPrime : (Ideal.span ({X} : Set R⟦X⟧)).IsPrime := by
  

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
⊢ Ideal.IsPrime (Ideal.span {X})

Next tactic:
suffices Ideal.span ({X} : Set R⟦X⟧) = RingHom.ker (constantCoeff R) by
    rw [this]
    exact RingHom.ker_isPrime _
/-- The ideal spanned by the variable in the power series ring
 over an integral domain is a prime ideal.-/
theorem span_X_isPrime : (Ideal.span ({X} : Set R⟦X⟧)).IsPrime := by
  suffices Ideal.span ({X} : Set R⟦X⟧) = RingHom.ker (constantCoeff R) by
    

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
this : Ideal.span {X} = RingHom.ker (constantCoeff R)
⊢ Ideal.IsPrime (Ideal.span {X})

Next tactic:
rw [this]
/-- The ideal spanned by the variable in the power series ring
 over an integral domain is a prime ideal.-/
theorem span_X_isPrime : (Ideal.span ({X} : Set R⟦X⟧)).IsPrime := by
  suffices Ideal.span ({X} : Set R⟦X⟧) = RingHom.ker (constantCoeff R) by
    rw [this]
    

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
this : Ideal.span {X} = RingHom.ker (constantCoeff R)
⊢ Ideal.IsPrime (RingHom.ker (constantCoeff R))

Next tactic:
exact RingHom.ker_isPrime _
/-- The ideal spanned by the variable in the power series ring
 over an integral domain is a prime ideal.-/
theorem span_X_isPrime : (Ideal.span ({X} : Set R⟦X⟧)).IsPrime := by
  suffices Ideal.span ({X} : Set R⟦X⟧) = RingHom.ker (constantCoeff R) by
    rw [this]
    exact RingHom.ker_isPrime _
  

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
⊢ Ideal.span {X} = RingHom.ker (constantCoeff R)

Next tactic:
apply Ideal.ext
/-- The ideal spanned by the variable in the power series ring
 over an integral domain is a prime ideal.-/
theorem span_X_isPrime : (Ideal.span ({X} : Set R⟦X⟧)).IsPrime := by
  suffices Ideal.span ({X} : Set R⟦X⟧) = RingHom.ker (constantCoeff R) by
    rw [this]
    exact RingHom.ker_isPrime _
  apply Ideal.ext
  

Proof state:
case h
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
⊢ ∀ (x : R⟦X⟧), x ∈ Ideal.span {X} ↔ x ∈ RingHom.ker (constantCoeff R)

Next tactic:
intro φ
/-- The ideal spanned by the variable in the power series ring
 over an integral domain is a prime ideal.-/
theorem span_X_isPrime : (Ideal.span ({X} : Set R⟦X⟧)).IsPrime := by
  suffices Ideal.span ({X} : Set R⟦X⟧) = RingHom.ker (constantCoeff R) by
    rw [this]
    exact RingHom.ker_isPrime _
  apply Ideal.ext
  intro φ
  

Proof state:
case h
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
φ : R⟦X⟧
⊢ φ ∈ Ideal.span {X} ↔ φ ∈ RingHom.ker (constantCoeff R)

Next tactic:
rw [RingHom.mem_ker, Ideal.mem_span_singleton, X_dvd_iff]
/-- The variable of the power series ring over an integral domain is prime.-/
theorem X_prime : Prime (X : R⟦X⟧) := by
  

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
⊢ Prime X

Next tactic:
rw [← Ideal.span_singleton_prime]
/-- The variable of the power series ring over an integral domain is prime.-/
theorem X_prime : Prime (X : R⟦X⟧) := by
  rw [← Ideal.span_singleton_prime]
  · 

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
⊢ Ideal.IsPrime (Ideal.span {X})

Next tactic:
exact span_X_isPrime
/-- The variable of the power series ring over an integral domain is prime.-/
theorem X_prime : Prime (X : R⟦X⟧) := by
  rw [← Ideal.span_singleton_prime]
  · exact span_X_isPrime
  · 

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
⊢ X ≠ 0

Next tactic:
intro h
/-- The variable of the power series ring over an integral domain is prime.-/
theorem X_prime : Prime (X : R⟦X⟧) := by
  rw [← Ideal.span_singleton_prime]
  · exact span_X_isPrime
  · intro h
    

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
h : X = 0
⊢ False

Next tactic:
simpa [map_zero (coeff R 1)] using congr_arg (coeff R 1) h
theorem rescale_injective {a : R} (ha : a ≠ 0) : Function.Injective (rescale a) := by
  

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
a : R
ha : a ≠ 0
⊢ Function.Injective ⇑(rescale a)

Next tactic:
intro p q h
theorem rescale_injective {a : R} (ha : a ≠ 0) : Function.Injective (rescale a) := by
  intro p q h
  

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
a : R
ha : a ≠ 0
p q : R⟦X⟧
h : (rescale a) p = (rescale a) q
⊢ p = q

Next tactic:
rw [PowerSeries.ext_iff] at *
theorem rescale_injective {a : R} (ha : a ≠ 0) : Function.Injective (rescale a) := by
  intro p q h
  rw [PowerSeries.ext_iff] at *
  

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
a : R
ha : a ≠ 0
p q : R⟦X⟧
h : ∀ (n : ℕ), (coeff R n) ((rescale a) p) = (coeff R n) ((rescale a) q)
⊢ ∀ (n : ℕ), (coeff R n) p = (coeff R n) q

Next tactic:
intro n
theorem rescale_injective {a : R} (ha : a ≠ 0) : Function.Injective (rescale a) := by
  intro p q h
  rw [PowerSeries.ext_iff] at *
  intro n
  

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
a : R
ha : a ≠ 0
p q : R⟦X⟧
h : ∀ (n : ℕ), (coeff R n) ((rescale a) p) = (coeff R n) ((rescale a) q)
n : ℕ
⊢ (coeff R n) p = (coeff R n) q

Next tactic:
specialize h n
theorem rescale_injective {a : R} (ha : a ≠ 0) : Function.Injective (rescale a) := by
  intro p q h
  rw [PowerSeries.ext_iff] at *
  intro n
  specialize h n
  

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
a : R
ha : a ≠ 0
p q : R⟦X⟧
n : ℕ
h : (coeff R n) ((rescale a) p) = (coeff R n) ((rescale a) q)
⊢ (coeff R n) p = (coeff R n) q

Next tactic:
rw [coeff_rescale, coeff_rescale, mul_eq_mul_left_iff] at h
theorem rescale_injective {a : R} (ha : a ≠ 0) : Function.Injective (rescale a) := by
  intro p q h
  rw [PowerSeries.ext_iff] at *
  intro n
  specialize h n
  rw [coeff_rescale, coeff_rescale, mul_eq_mul_left_iff] at h
  

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
a : R
ha : a ≠ 0
p q : R⟦X⟧
n : ℕ
h : (coeff R n) p = (coeff R n) q ∨ a ^ n = 0
⊢ (coeff R n) p = (coeff R n) q

Next tactic:
apply h.resolve_right
theorem rescale_injective {a : R} (ha : a ≠ 0) : Function.Injective (rescale a) := by
  intro p q h
  rw [PowerSeries.ext_iff] at *
  intro n
  specialize h n
  rw [coeff_rescale, coeff_rescale, mul_eq_mul_left_iff] at h
  apply h.resolve_right
  

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
a : R
ha : a ≠ 0
p q : R⟦X⟧
n : ℕ
h : (coeff R n) p = (coeff R n) q ∨ a ^ n = 0
⊢ ¬a ^ n = 0

Next tactic:
intro h'
theorem rescale_injective {a : R} (ha : a ≠ 0) : Function.Injective (rescale a) := by
  intro p q h
  rw [PowerSeries.ext_iff] at *
  intro n
  specialize h n
  rw [coeff_rescale, coeff_rescale, mul_eq_mul_left_iff] at h
  apply h.resolve_right
  intro h'
  

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : IsDomain R
a : R
ha : a ≠ 0
p q : R⟦X⟧
n : ℕ
h : (coeff R n) p = (coeff R n) q ∨ a ^ n = 0
h' : a ^ n = 0
⊢ False

Next tactic:
exact ha (pow_eq_zero h')
theorem coeff_inv (n) (φ : PowerSeries k) :
    coeff k n φ⁻¹ =
      if n = 0 then (constantCoeff k φ)⁻¹
      else
        -(constantCoeff k φ)⁻¹ *
          ∑ x in antidiagonal n,
            if x.2 < n then coeff k x.1 φ * coeff k x.2 φ⁻¹ else 0 :=
  by 

Proof state:
R : Type u_1
k : Type u_2
inst✝ : Field k
n : ℕ
φ : k⟦X⟧
⊢ (coeff k n) φ⁻¹ =
    if n = 0 then ((constantCoeff k) φ)⁻¹
    else -((constantCoeff k) φ)⁻¹ * ∑ x in antidiagonal n, if x.2 < n then (coeff k x.1) φ * (coeff k x.2) φ⁻¹ else 0

Next tactic:
rw [inv_eq_inv_aux, coeff_inv_aux n (constantCoeff k φ)⁻¹ φ]
theorem exists_coeff_ne_zero_iff_ne_zero : (∃ n : ℕ, coeff R n φ ≠ 0) ↔ φ ≠ 0 := by
  

Proof state:
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
⊢ (∃ n, (coeff R n) φ ≠ 0) ↔ φ ≠ 0

Next tactic:
refine' not_iff_not.mp _
theorem exists_coeff_ne_zero_iff_ne_zero : (∃ n : ℕ, coeff R n φ ≠ 0) ↔ φ ≠ 0 := by
  refine' not_iff_not.mp _
  

Proof state:
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
⊢ (¬∃ n, (coeff R n) φ ≠ 0) ↔ ¬φ ≠ 0

Next tactic:
push_neg
theorem exists_coeff_ne_zero_iff_ne_zero : (∃ n : ℕ, coeff R n φ ≠ 0) ↔ φ ≠ 0 := by
  refine' not_iff_not.mp _
  push_neg
  

Proof state:
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
⊢ (∀ (n : ℕ), (coeff R n) φ = 0) ↔ φ = 0

Next tactic:
simp [PowerSeries.ext_iff]
theorem order_finite_iff_ne_zero : (order φ).Dom ↔ φ ≠ 0 := by
  

Proof state:
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
⊢ (order φ).Dom ↔ φ ≠ 0

Next tactic:
simp only [order]
theorem order_finite_iff_ne_zero : (order φ).Dom ↔ φ ≠ 0 := by
  simp only [order]
  

Proof state:
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
⊢ (if h : φ = 0 then ⊤ else ↑(Nat.find (_ : ∃ n, (coeff R n) φ ≠ 0))).Dom ↔ φ ≠ 0

Next tactic:
constructor
theorem order_finite_iff_ne_zero : (order φ).Dom ↔ φ ≠ 0 := by
  simp only [order]
  constructor
  · 

Proof state:
case mp
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
⊢ (if h : φ = 0 then ⊤ else ↑(Nat.find (_ : ∃ n, (coeff R n) φ ≠ 0))).Dom → φ ≠ 0

Next tactic:
split_ifs with h
theorem order_finite_iff_ne_zero : (order φ).Dom ↔ φ ≠ 0 := by
  simp only [order]
  constructor
  · split_ifs with h <;> 

Proof state:
case pos
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
h : φ = 0
⊢ ⊤.Dom → φ ≠ 0

Next tactic:
intro H
theorem order_finite_iff_ne_zero : (order φ).Dom ↔ φ ≠ 0 := by
  simp only [order]
  constructor
  · split_ifs with h <;> 

Proof state:
case neg
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
h : ¬φ = 0
⊢ (↑(Nat.find (_ : ∃ n, (coeff R n) φ ≠ 0))).Dom → φ ≠ 0

Next tactic:
intro H
theorem order_finite_iff_ne_zero : (order φ).Dom ↔ φ ≠ 0 := by
  simp only [order]
  constructor
  · split_ifs with h <;> intro H
    · 

Proof state:
case pos
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
h : φ = 0
H : ⊤.Dom
⊢ φ ≠ 0

Next tactic:
contrapose! H
theorem order_finite_iff_ne_zero : (order φ).Dom ↔ φ ≠ 0 := by
  simp only [order]
  constructor
  · split_ifs with h <;> intro H
    · contrapose! H
      

Proof state:
case pos
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
h H : φ = 0
⊢ ¬⊤.Dom

Next tactic:
simp only [← Part.eq_none_iff']
theorem order_finite_iff_ne_zero : (order φ).Dom ↔ φ ≠ 0 := by
  simp only [order]
  constructor
  · split_ifs with h <;> intro H
    · contrapose! H
      simp only [← Part.eq_none_iff']
      

Proof state:
case pos
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
h H : φ = 0
⊢ ⊤ = Part.none

Next tactic:
rfl
theorem order_finite_iff_ne_zero : (order φ).Dom ↔ φ ≠ 0 := by
  simp only [order]
  constructor
  · split_ifs with h <;> intro H
    · contrapose! H
      simp only [← Part.eq_none_iff']
      rfl
    · 

Proof state:
case neg
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
h : ¬φ = 0
H : (↑(Nat.find (_ : ∃ n, (coeff R n) φ ≠ 0))).Dom
⊢ φ ≠ 0

Next tactic:
exact h
theorem order_finite_iff_ne_zero : (order φ).Dom ↔ φ ≠ 0 := by
  simp only [order]
  constructor
  · split_ifs with h <;> intro H
    · contrapose! H
      simp only [← Part.eq_none_iff']
      rfl
    · exact h
  · 

Proof state:
case mpr
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
⊢ φ ≠ 0 → (if h : φ = 0 then ⊤ else ↑(Nat.find (_ : ∃ n, (coeff R n) φ ≠ 0))).Dom

Next tactic:
intro h
theorem order_finite_iff_ne_zero : (order φ).Dom ↔ φ ≠ 0 := by
  simp only [order]
  constructor
  · split_ifs with h <;> intro H
    · contrapose! H
      simp only [← Part.eq_none_iff']
      rfl
    · exact h
  · intro h
    

Proof state:
case mpr
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
h : φ ≠ 0
⊢ (if h : φ = 0 then ⊤ else ↑(Nat.find (_ : ∃ n, (coeff R n) φ ≠ 0))).Dom

Next tactic:
simp [h]
/-- If the order of a formal power series is finite,
then the coefficient indexed by the order is nonzero.-/
theorem coeff_order (h : (order φ).Dom) : coeff R (φ.order.get h) φ ≠ 0 := by
  

Proof state:
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
h : (order φ).Dom
⊢ (coeff R (Part.get (order φ) h)) φ ≠ 0

Next tactic:
classical
  simp only [order, order_finite_iff_ne_zero.mp h, not_false_iff, dif_neg, PartENat.get_natCast']
  generalize_proofs h
  exact Nat.find_spec h
/-- If the order of a formal power series is finite,
then the coefficient indexed by the order is nonzero.-/
theorem coeff_order (h : (order φ).Dom) : coeff R (φ.order.get h) φ ≠ 0 := by
  classical
  

Proof state:
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
h : (order φ).Dom
⊢ (coeff R (Part.get (order φ) h)) φ ≠ 0

Next tactic:
simp only [order, order_finite_iff_ne_zero.mp h, not_false_iff, dif_neg, PartENat.get_natCast']
/-- If the order of a formal power series is finite,
then the coefficient indexed by the order is nonzero.-/
theorem coeff_order (h : (order φ).Dom) : coeff R (φ.order.get h) φ ≠ 0 := by
  classical
  simp only [order, order_finite_iff_ne_zero.mp h, not_false_iff, dif_neg, PartENat.get_natCast']
  

Proof state:
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
h : (order φ).Dom
⊢ (coeff R (Nat.find (_ : ∃ n, (coeff R n) φ ≠ 0))) φ ≠ 0

Next tactic:
generalize_proofs h
/-- If the order of a formal power series is finite,
then the coefficient indexed by the order is nonzero.-/
theorem coeff_order (h : (order φ).Dom) : coeff R (φ.order.get h) φ ≠ 0 := by
  classical
  simp only [order, order_finite_iff_ne_zero.mp h, not_false_iff, dif_neg, PartENat.get_natCast']
  generalize_proofs h
  

Proof state:
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
h✝ : (order φ).Dom
h : ∃ n, (coeff R n) φ ≠ 0
⊢ (coeff R (Nat.find h)) φ ≠ 0

Next tactic:
exact Nat.find_spec h
/-- If the `n`th coefficient of a formal power series is nonzero,
then the order of the power series is less than or equal to `n`.-/
theorem order_le (n : ℕ) (h : coeff R n φ ≠ 0) : order φ ≤ n := by
  

Proof state:
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
n : ℕ
h : (coeff R n) φ ≠ 0
⊢ order φ ≤ ↑n

Next tactic:
classical
  have _ :  ∃ n, coeff R n φ ≠ 0 := Exists.intro n h
  rw [order, dif_neg]
  · simp only [PartENat.coe_le_coe, Nat.find_le_iff]
    exact ⟨n, le_rfl, h⟩
  · exact exists_coeff_ne_zero_iff_ne_zero.mp ⟨n, h⟩
/-- If the `n`th coefficient of a formal power series is nonzero,
then the order of the power series is less than or equal to `n`.-/
theorem order_le (n : ℕ) (h : coeff R n φ ≠ 0) : order φ ≤ n := by
  classical
  

Proof state:
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
n : ℕ
h : (coeff R n) φ ≠ 0
⊢ order φ ≤ ↑n

Next tactic:
have _ :  ∃ n, coeff R n φ ≠ 0 := Exists.intro n h
/-- If the `n`th coefficient of a formal power series is nonzero,
then the order of the power series is less than or equal to `n`.-/
theorem order_le (n : ℕ) (h : coeff R n φ ≠ 0) : order φ ≤ n := by
  classical
  have _ :  ∃ n, coeff R n φ ≠ 0 := Exists.intro n h
  

Proof state:
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
n : ℕ
h : (coeff R n) φ ≠ 0
x✝ : ∃ n, (coeff R n) φ ≠ 0
⊢ order φ ≤ ↑n

Next tactic:
rw [order, dif_neg]
/-- If the `n`th coefficient of a formal power series is nonzero,
then the order of the power series is less than or equal to `n`.-/
theorem order_le (n : ℕ) (h : coeff R n φ ≠ 0) : order φ ≤ n := by
  classical
  have _ :  ∃ n, coeff R n φ ≠ 0 := Exists.intro n h
  rw [order, dif_neg]
  · 

Proof state:
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
n : ℕ
h : (coeff R n) φ ≠ 0
x✝ : ∃ n, (coeff R n) φ ≠ 0
⊢ ↑(Nat.find (_ : ∃ n, (coeff R n) φ ≠ 0)) ≤ ↑n

Next tactic:
simp only [PartENat.coe_le_coe, Nat.find_le_iff]
/-- If the `n`th coefficient of a formal power series is nonzero,
then the order of the power series is less than or equal to `n`.-/
theorem order_le (n : ℕ) (h : coeff R n φ ≠ 0) : order φ ≤ n := by
  classical
  have _ :  ∃ n, coeff R n φ ≠ 0 := Exists.intro n h
  rw [order, dif_neg]
  · simp only [PartENat.coe_le_coe, Nat.find_le_iff]
    

Proof state:
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
n : ℕ
h : (coeff R n) φ ≠ 0
x✝ : ∃ n, (coeff R n) φ ≠ 0
⊢ ∃ m ≤ n, (coeff R m) φ ≠ 0

Next tactic:
exact ⟨n, le_rfl, h⟩
/-- If the `n`th coefficient of a formal power series is nonzero,
then the order of the power series is less than or equal to `n`.-/
theorem order_le (n : ℕ) (h : coeff R n φ ≠ 0) : order φ ≤ n := by
  classical
  have _ :  ∃ n, coeff R n φ ≠ 0 := Exists.intro n h
  rw [order, dif_neg]
  · simp only [PartENat.coe_le_coe, Nat.find_le_iff]
    exact ⟨n, le_rfl, h⟩
  · 

Proof state:
case hnc
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
n : ℕ
h : (coeff R n) φ ≠ 0
x✝ : ∃ n, (coeff R n) φ ≠ 0
⊢ ¬φ = 0

Next tactic:
exact exists_coeff_ne_zero_iff_ne_zero.mp ⟨n, h⟩
/-- The `n`th coefficient of a formal power series is `0` if `n` is strictly
smaller than the order of the power series.-/
theorem coeff_of_lt_order (n : ℕ) (h : ↑n < order φ) : coeff R n φ = 0 := by
  

Proof state:
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
n : ℕ
h : ↑n < order φ
⊢ (coeff R n) φ = 0

Next tactic:
contrapose! h
/-- The `n`th coefficient of a formal power series is `0` if `n` is strictly
smaller than the order of the power series.-/
theorem coeff_of_lt_order (n : ℕ) (h : ↑n < order φ) : coeff R n φ = 0 := by
  contrapose! h
  

Proof state:
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
n : ℕ
h : (coeff R n) φ ≠ 0
⊢ order φ ≤ ↑n

Next tactic:
exact order_le _ h
/-- The `0` power series is the unique power series with infinite order.-/
@[simp]
theorem order_eq_top {φ : R⟦X⟧} : φ.order = ⊤ ↔ φ = 0 := by
  

Proof state:
R : Type u_1
inst✝ : Semiring R
φ✝ φ : R⟦X⟧
⊢ order φ = ⊤ ↔ φ = 0

Next tactic:
constructor
/-- The `0` power series is the unique power series with infinite order.-/
@[simp]
theorem order_eq_top {φ : R⟦X⟧} : φ.order = ⊤ ↔ φ = 0 := by
  constructor
  · 

Proof state:
case mp
R : Type u_1
inst✝ : Semiring R
φ✝ φ : R⟦X⟧
⊢ order φ = ⊤ → φ = 0

Next tactic:
intro h
/-- The `0` power series is the unique power series with infinite order.-/
@[simp]
theorem order_eq_top {φ : R⟦X⟧} : φ.order = ⊤ ↔ φ = 0 := by
  constructor
  · intro h
    

Proof state:
case mp
R : Type u_1
inst✝ : Semiring R
φ✝ φ : R⟦X⟧
h : order φ = ⊤
⊢ φ = 0

Next tactic:
ext n
/-- The `0` power series is the unique power series with infinite order.-/
@[simp]
theorem order_eq_top {φ : R⟦X⟧} : φ.order = ⊤ ↔ φ = 0 := by
  constructor
  · intro h
    ext n
    

Proof state:
case mp.h
R : Type u_1
inst✝ : Semiring R
φ✝ φ : R⟦X⟧
h : order φ = ⊤
n : ℕ
⊢ (coeff R n) φ = (coeff R n) 0

Next tactic:
rw [(coeff R n).map_zero, coeff_of_lt_order]
/-- The `0` power series is the unique power series with infinite order.-/
@[simp]
theorem order_eq_top {φ : R⟦X⟧} : φ.order = ⊤ ↔ φ = 0 := by
  constructor
  · intro h
    ext n
    rw [(coeff R n).map_zero, coeff_of_lt_order]
    

Proof state:
case mp.h.h
R : Type u_1
inst✝ : Semiring R
φ✝ φ : R⟦X⟧
h : order φ = ⊤
n : ℕ
⊢ ↑n < order φ

Next tactic:
simp [h]
/-- The `0` power series is the unique power series with infinite order.-/
@[simp]
theorem order_eq_top {φ : R⟦X⟧} : φ.order = ⊤ ↔ φ = 0 := by
  constructor
  · intro h
    ext n
    rw [(coeff R n).map_zero, coeff_of_lt_order]
    simp [h]
  · 

Proof state:
case mpr
R : Type u_1
inst✝ : Semiring R
φ✝ φ : R⟦X⟧
⊢ φ = 0 → order φ = ⊤

Next tactic:
rintro rfl
/-- The `0` power series is the unique power series with infinite order.-/
@[simp]
theorem order_eq_top {φ : R⟦X⟧} : φ.order = ⊤ ↔ φ = 0 := by
  constructor
  · intro h
    ext n
    rw [(coeff R n).map_zero, coeff_of_lt_order]
    simp [h]
  · rintro rfl
    

Proof state:
case mpr
R : Type u_1
inst✝ : Semiring R
φ : R⟦X⟧
⊢ order 0 = ⊤

Next tactic:
exact order_zero
/-- The order of a formal power series is at least `n` if
the `i`th coefficient is `0` for all `i < n`.-/
theorem nat_le_order (φ : R⟦X⟧) (n : ℕ) (h : ∀ i < n, coeff R i φ = 0) : ↑n ≤ order φ := by
  

Proof state:
R : Type u_1
inst✝ : Semiring R
φ✝ φ : R⟦X⟧
n : ℕ
h : ∀ i < n, (coeff R i) φ = 0
⊢ ↑n ≤ order φ

Next tactic:
by_contra H