l3lab/ntp-mathlib huggingface dataset:
instance [Faithful F] [CategoryWithHomology C] : F.ReflectsEpimorphisms where
  reflects {X Y} f hf := by
    let S := ShortComplex.mk f (0 : Y ⟶ Y) comp_zero
    exact (S.exact_iff_epi rfl).1
      ((ShortComplex.exact_map_iff_of_faithful S F).1
      (((S.map F).exact_iff_epi (by 

Proof state:
C : Type u_1
D : Type u_2
inst✝⁹ : Category.{?u.277757, u_1} C
inst✝⁸ : Category.{?u.277761, u_2} D
F : C ⥤ D
inst✝⁷ : Preadditive C
inst✝⁶ : Preadditive D
inst✝⁵ : HasZeroObject C
inst✝⁴ : HasZeroObject D
inst✝³ : PreservesZeroMorphisms F
inst✝² : PreservesHomology F
inst✝¹ : Faithful F
inst✝ : CategoryWithHomology C
X Y : C
f : X ⟶ Y
hf : Epi (F.map f)
S : ShortComplex C := ShortComplex.mk f 0 (_ : f ≫ 0 = 0)
⊢ (ShortComplex.map S F).g = 0

Next tactic:
simp
/-- This is the splitting of a short complex `S` in a balanced category induced by
a section of the morphism `S.g : S.X₂ ⟶ S.X₃` -/
noncomputable def ofExactOfSection (S : ShortComplex C) (hS : S.Exact) (s : S.X₃ ⟶ S.X₂)
    (s_g : s ≫ S.g = 𝟙 S.X₃) (hf : Mono S.f) :
    S.Splitting where
  r := hS.lift (𝟙 S.X₂ - S.g ≫ s) (by 

Proof state:
C : Type u_1
D : Type u_2
inst✝³ : Category.{?u.281047, u_1} C
inst✝² : Category.{?u.281051, u_2} D
inst✝¹ : Preadditive C
inst✝ : Balanced C
S : ShortComplex C
hS : Exact S
s : S.X₃ ⟶ S.X₂
s_g : s ≫ S.g = 𝟙 S.X₃
hf : Mono S.f
⊢ (𝟙 S.X₂ - S.g ≫ s) ≫ S.g = 0

Next tactic:
simp [s_g]
/-- This is the splitting of a short complex `S` in a balanced category induced by
a section of the morphism `S.g : S.X₂ ⟶ S.X₃` -/
noncomputable def ofExactOfSection (S : ShortComplex C) (hS : S.Exact) (s : S.X₃ ⟶ S.X₂)
    (s_g : s ≫ S.g = 𝟙 S.X₃) (hf : Mono S.f) :
    S.Splitting where
  r := hS.lift (𝟙 S.X₂ - S.g ≫ s) (by simp [s_g])
  s := s
  f_r := by 

Proof state:
C : Type u_1
D : Type u_2
inst✝³ : Category.{?u.281047, u_1} C
inst✝² : Category.{?u.281051, u_2} D
inst✝¹ : Preadditive C
inst✝ : Balanced C
S : ShortComplex C
hS : Exact S
s : S.X₃ ⟶ S.X₂
s_g : s ≫ S.g = 𝟙 S.X₃
hf : Mono S.f
⊢ S.f ≫ Exact.lift hS (𝟙 S.X₂ - S.g ≫ s) (_ : (𝟙 S.X₂ - S.g ≫ s) ≫ S.g = 0) = 𝟙 S.X₁

Next tactic:
rw [← cancel_mono S.f, assoc, Exact.lift_f, comp_sub, comp_id,
    zero_assoc, zero_comp, sub_zero, id_comp]
/-- This is the splitting of a short complex `S` in a balanced category induced by
a retraction of the morphism `S.f : S.X₁ ⟶ S.X₂` -/
noncomputable def ofExactOfRetraction (S : ShortComplex C) (hS : S.Exact) (r : S.X₂ ⟶ S.X₁)
    (f_r : S.f ≫ r = 𝟙 S.X₁) (hg : Epi S.g) :
    S.Splitting where
  r := r
  s := hS.desc (𝟙 S.X₂ - r ≫ S.f) (by 

Proof state:
C : Type u_1
D : Type u_2
inst✝³ : Category.{?u.286200, u_1} C
inst✝² : Category.{?u.286204, u_2} D
inst✝¹ : Preadditive C
inst✝ : Balanced C
S : ShortComplex C
hS : Exact S
r : S.X₂ ⟶ S.X₁
f_r : S.f ≫ r = 𝟙 S.X₁
hg : Epi S.g
⊢ S.f ≫ (𝟙 S.X₂ - r ≫ S.f) = 0

Next tactic:
simp [reassoc_of% f_r]
/-- This is the splitting of a short complex `S` in a balanced category induced by
a retraction of the morphism `S.f : S.X₁ ⟶ S.X₂` -/
noncomputable def ofExactOfRetraction (S : ShortComplex C) (hS : S.Exact) (r : S.X₂ ⟶ S.X₁)
    (f_r : S.f ≫ r = 𝟙 S.X₁) (hg : Epi S.g) :
    S.Splitting where
  r := r
  s := hS.desc (𝟙 S.X₂ - r ≫ S.f) (by simp [reassoc_of% f_r])
  f_r := f_r
  s_g := by
    

Proof state:
C : Type u_1
D : Type u_2
inst✝³ : Category.{?u.286200, u_1} C
inst✝² : Category.{?u.286204, u_2} D
inst✝¹ : Preadditive C
inst✝ : Balanced C
S : ShortComplex C
hS : Exact S
r : S.X₂ ⟶ S.X₁
f_r : S.f ≫ r = 𝟙 S.X₁
hg : Epi S.g
⊢ Exact.desc hS (𝟙 S.X₂ - r ≫ S.f) (_ : S.f ≫ (𝟙 S.X₂ - r ≫ S.f) = 0) ≫ S.g = 𝟙 S.X₃

Next tactic:
rw [← cancel_epi S.g, Exact.g_desc_assoc, sub_comp, id_comp, assoc, zero,
      comp_zero, sub_zero, comp_id]
/-- Any commutative ring satisfies the `StrongRankCondition`. -/
instance (priority := 100) commRing_strongRankCondition : StrongRankCondition R := by
  

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : Nontrivial R
⊢ StrongRankCondition R

Next tactic:
suffices ∀ n, ∀ f : (Fin (n + 1) → R) →ₗ[R] Fin n → R, ¬Injective f by
    rwa [strongRankCondition_iff_succ R]
/-- Any commutative ring satisfies the `StrongRankCondition`. -/
instance (priority := 100) commRing_strongRankCondition : StrongRankCondition R := by
  suffices ∀ n, ∀ f : (Fin (n + 1) → R) →ₗ[R] Fin n → R, ¬Injective f by
    

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : Nontrivial R
this : ∀ (n : ℕ) (f : (Fin (n + 1) → R) →ₗ[R] Fin n → R), ¬Injective ⇑f
⊢ StrongRankCondition R

Next tactic:
rwa [strongRankCondition_iff_succ R]
/-- Any commutative ring satisfies the `StrongRankCondition`. -/
instance (priority := 100) commRing_strongRankCondition : StrongRankCondition R := by
  suffices ∀ n, ∀ f : (Fin (n + 1) → R) →ₗ[R] Fin n → R, ¬Injective f by
    rwa [strongRankCondition_iff_succ R]
  

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : Nontrivial R
⊢ ∀ (n : ℕ) (f : (Fin (n + 1) → R) →ₗ[R] Fin n → R), ¬Injective ⇑f

Next tactic:
intro n f
/-- Any commutative ring satisfies the `StrongRankCondition`. -/
instance (priority := 100) commRing_strongRankCondition : StrongRankCondition R := by
  suffices ∀ n, ∀ f : (Fin (n + 1) → R) →ₗ[R] Fin n → R, ¬Injective f by
    rwa [strongRankCondition_iff_succ R]
  intro n f
  

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : Nontrivial R
n : ℕ
f : (Fin (n + 1) → R) →ₗ[R] Fin n → R
⊢ ¬Injective ⇑f

Next tactic:
by_contra hf
/-- Any commutative ring satisfies the `StrongRankCondition`. -/
instance (priority := 100) commRing_strongRankCondition : StrongRankCondition R := by
  suffices ∀ n, ∀ f : (Fin (n + 1) → R) →ₗ[R] Fin n → R, ¬Injective f by
    rwa [strongRankCondition_iff_succ R]
  intro n f
  by_contra hf
  -- Porting note: Lean can now find these instances without help...
  -- letI : Module.Finite R (Fin n.succ → R) := Module.Finite.pi
  -- letI : Module.Free R (Fin n.succ → R) := Module.Free.pi _ _
  

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : Nontrivial R
n : ℕ
f : (Fin (n + 1) → R) →ₗ[R] Fin n → R
hf : Injective ⇑f
⊢ False

Next tactic:
let g : (Fin (n + 1) → R) →ₗ[R] Fin (n + 1) → R := (ExtendByZero.linearMap R castSucc).comp f
/-- Any commutative ring satisfies the `StrongRankCondition`. -/
instance (priority := 100) commRing_strongRankCondition : StrongRankCondition R := by
  suffices ∀ n, ∀ f : (Fin (n + 1) → R) →ₗ[R] Fin n → R, ¬Injective f by
    rwa [strongRankCondition_iff_succ R]
  intro n f
  by_contra hf
  -- Porting note: Lean can now find these instances without help...
  -- letI : Module.Finite R (Fin n.succ → R) := Module.Finite.pi
  -- letI : Module.Free R (Fin n.succ → R) := Module.Free.pi _ _
  let g : (Fin (n + 1) → R) →ₗ[R] Fin (n + 1) → R := (ExtendByZero.linearMap R castSucc).comp f
  

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : Nontrivial R
n : ℕ
f : (Fin (n + 1) → R) →ₗ[R] Fin n → R
hf : Injective ⇑f
g : (Fin (n + 1) → R) →ₗ[R] Fin (n + 1) → R := ExtendByZero.linearMap R castSucc ∘ₗ f
⊢ False

Next tactic:
have hg : Injective g := (extend_injective Fin.strictMono_castSucc.injective _).comp hf
/-- Any commutative ring satisfies the `StrongRankCondition`. -/
instance (priority := 100) commRing_strongRankCondition : StrongRankCondition R := by
  suffices ∀ n, ∀ f : (Fin (n + 1) → R) →ₗ[R] Fin n → R, ¬Injective f by
    rwa [strongRankCondition_iff_succ R]
  intro n f
  by_contra hf
  -- Porting note: Lean can now find these instances without help...
  -- letI : Module.Finite R (Fin n.succ → R) := Module.Finite.pi
  -- letI : Module.Free R (Fin n.succ → R) := Module.Free.pi _ _
  let g : (Fin (n + 1) → R) →ₗ[R] Fin (n + 1) → R := (ExtendByZero.linearMap R castSucc).comp f
  have hg : Injective g := (extend_injective Fin.strictMono_castSucc.injective _).comp hf
  

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : Nontrivial R
n : ℕ
f : (Fin (n + 1) → R) →ₗ[R] Fin n → R
hf : Injective ⇑f
g : (Fin (n + 1) → R) →ₗ[R] Fin (n + 1) → R := ExtendByZero.linearMap R castSucc ∘ₗ f
hg : Injective ⇑g
⊢ False

Next tactic:
have hnex : ¬∃ i : Fin n, castSucc i = last n :=
    fun ⟨i, hi⟩ => ne_of_lt (castSucc_lt_last i) hi
/-- Any commutative ring satisfies the `StrongRankCondition`. -/
instance (priority := 100) commRing_strongRankCondition : StrongRankCondition R := by
  suffices ∀ n, ∀ f : (Fin (n + 1) → R) →ₗ[R] Fin n → R, ¬Injective f by
    rwa [strongRankCondition_iff_succ R]
  intro n f
  by_contra hf
  -- Porting note: Lean can now find these instances without help...
  -- letI : Module.Finite R (Fin n.succ → R) := Module.Finite.pi
  -- letI : Module.Free R (Fin n.succ → R) := Module.Free.pi _ _
  let g : (Fin (n + 1) → R) →ₗ[R] Fin (n + 1) → R := (ExtendByZero.linearMap R castSucc).comp f
  have hg : Injective g := (extend_injective Fin.strictMono_castSucc.injective _).comp hf
  have hnex : ¬∃ i : Fin n, castSucc i = last n :=
    fun ⟨i, hi⟩ => ne_of_lt (castSucc_lt_last i) hi
  

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : Nontrivial R
n : ℕ
f : (Fin (n + 1) → R) →ₗ[R] Fin n → R
hf : Injective ⇑f
g : (Fin (n + 1) → R) →ₗ[R] Fin (n + 1) → R := ExtendByZero.linearMap R castSucc ∘ₗ f
hg : Injective ⇑g
hnex : ¬∃ i, castSucc i = last n
⊢ False

Next tactic:
let a₀ := (minpoly R g).coeff 0
/-- Any commutative ring satisfies the `StrongRankCondition`. -/
instance (priority := 100) commRing_strongRankCondition : StrongRankCondition R := by
  suffices ∀ n, ∀ f : (Fin (n + 1) → R) →ₗ[R] Fin n → R, ¬Injective f by
    rwa [strongRankCondition_iff_succ R]
  intro n f
  by_contra hf
  -- Porting note: Lean can now find these instances without help...
  -- letI : Module.Finite R (Fin n.succ → R) := Module.Finite.pi
  -- letI : Module.Free R (Fin n.succ → R) := Module.Free.pi _ _
  let g : (Fin (n + 1) → R) →ₗ[R] Fin (n + 1) → R := (ExtendByZero.linearMap R castSucc).comp f
  have hg : Injective g := (extend_injective Fin.strictMono_castSucc.injective _).comp hf
  have hnex : ¬∃ i : Fin n, castSucc i = last n :=
    fun ⟨i, hi⟩ => ne_of_lt (castSucc_lt_last i) hi
  let a₀ := (minpoly R g).coeff 0
  

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : Nontrivial R
n : ℕ
f : (Fin (n + 1) → R) →ₗ[R] Fin n → R
hf : Injective ⇑f
g : (Fin (n + 1) → R) →ₗ[R] Fin (n + 1) → R := ExtendByZero.linearMap R castSucc ∘ₗ f
hg : Injective ⇑g
hnex : ¬∃ i, castSucc i = last n
a₀ : R := coeff (minpoly R g) 0
⊢ False

Next tactic:
have : a₀ ≠ 0 := minpoly_coeff_zero_of_injective hg
/-- Any commutative ring satisfies the `StrongRankCondition`. -/
instance (priority := 100) commRing_strongRankCondition : StrongRankCondition R := by
  suffices ∀ n, ∀ f : (Fin (n + 1) → R) →ₗ[R] Fin n → R, ¬Injective f by
    rwa [strongRankCondition_iff_succ R]
  intro n f
  by_contra hf
  -- Porting note: Lean can now find these instances without help...
  -- letI : Module.Finite R (Fin n.succ → R) := Module.Finite.pi
  -- letI : Module.Free R (Fin n.succ → R) := Module.Free.pi _ _
  let g : (Fin (n + 1) → R) →ₗ[R] Fin (n + 1) → R := (ExtendByZero.linearMap R castSucc).comp f
  have hg : Injective g := (extend_injective Fin.strictMono_castSucc.injective _).comp hf
  have hnex : ¬∃ i : Fin n, castSucc i = last n :=
    fun ⟨i, hi⟩ => ne_of_lt (castSucc_lt_last i) hi
  let a₀ := (minpoly R g).coeff 0
  have : a₀ ≠ 0 := minpoly_coeff_zero_of_injective hg
  

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : Nontrivial R
n : ℕ
f : (Fin (n + 1) → R) →ₗ[R] Fin n → R
hf : Injective ⇑f
g : (Fin (n + 1) → R) →ₗ[R] Fin (n + 1) → R := ExtendByZero.linearMap R castSucc ∘ₗ f
hg : Injective ⇑g
hnex : ¬∃ i, castSucc i = last n
a₀ : R := coeff (minpoly R g) 0
this : a₀ ≠ 0
⊢ False

Next tactic:
have : a₀ = 0 := by
    -- Evaluate `(minpoly R g) g` at the vector `(0,...,0,1)`
    have heval := LinearMap.congr_fun (minpoly.aeval R g) (Pi.single (Fin.last n) 1)
    obtain ⟨P, hP⟩ := X_dvd_iff.2 (erase_same (minpoly R g) 0)
    rw [← monomial_add_erase (minpoly R g) 0, hP] at heval
    replace heval := congr_fun heval (Fin.last n)
    -- Porting note: ...it's just that this line gives a timeout without slightly raising heartbeats
    simpa [hnex] using heval
/-- Any commutative ring satisfies the `StrongRankCondition`. -/
instance (priority := 100) commRing_strongRankCondition : StrongRankCondition R := by
  suffices ∀ n, ∀ f : (Fin (n + 1) → R) →ₗ[R] Fin n → R, ¬Injective f by
    rwa [strongRankCondition_iff_succ R]
  intro n f
  by_contra hf
  -- Porting note: Lean can now find these instances without help...
  -- letI : Module.Finite R (Fin n.succ → R) := Module.Finite.pi
  -- letI : Module.Free R (Fin n.succ → R) := Module.Free.pi _ _
  let g : (Fin (n + 1) → R) →ₗ[R] Fin (n + 1) → R := (ExtendByZero.linearMap R castSucc).comp f
  have hg : Injective g := (extend_injective Fin.strictMono_castSucc.injective _).comp hf
  have hnex : ¬∃ i : Fin n, castSucc i = last n :=
    fun ⟨i, hi⟩ => ne_of_lt (castSucc_lt_last i) hi
  let a₀ := (minpoly R g).coeff 0
  have : a₀ ≠ 0 := minpoly_coeff_zero_of_injective hg
  have : a₀ = 0 := by
    -- Evaluate `(minpoly R g) g` at the vector `(0,...,0,1)`
    

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : Nontrivial R
n : ℕ
f : (Fin (n + 1) → R) →ₗ[R] Fin n → R
hf : Injective ⇑f
g : (Fin (n + 1) → R) →ₗ[R] Fin (n + 1) → R := ExtendByZero.linearMap R castSucc ∘ₗ f
hg : Injective ⇑g
hnex : ¬∃ i, castSucc i = last n
a₀ : R := coeff (minpoly R g) 0
this : a₀ ≠ 0
⊢ a₀ = 0

Next tactic:
have heval := LinearMap.congr_fun (minpoly.aeval R g) (Pi.single (Fin.last n) 1)
/-- Any commutative ring satisfies the `StrongRankCondition`. -/
instance (priority := 100) commRing_strongRankCondition : StrongRankCondition R := by
  suffices ∀ n, ∀ f : (Fin (n + 1) → R) →ₗ[R] Fin n → R, ¬Injective f by
    rwa [strongRankCondition_iff_succ R]
  intro n f
  by_contra hf
  -- Porting note: Lean can now find these instances without help...
  -- letI : Module.Finite R (Fin n.succ → R) := Module.Finite.pi
  -- letI : Module.Free R (Fin n.succ → R) := Module.Free.pi _ _
  let g : (Fin (n + 1) → R) →ₗ[R] Fin (n + 1) → R := (ExtendByZero.linearMap R castSucc).comp f
  have hg : Injective g := (extend_injective Fin.strictMono_castSucc.injective _).comp hf
  have hnex : ¬∃ i : Fin n, castSucc i = last n :=
    fun ⟨i, hi⟩ => ne_of_lt (castSucc_lt_last i) hi
  let a₀ := (minpoly R g).coeff 0
  have : a₀ ≠ 0 := minpoly_coeff_zero_of_injective hg
  have : a₀ = 0 := by
    -- Evaluate `(minpoly R g) g` at the vector `(0,...,0,1)`
    have heval := LinearMap.congr_fun (minpoly.aeval R g) (Pi.single (Fin.last n) 1)
    

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : Nontrivial R
n : ℕ
f : (Fin (n + 1) → R) →ₗ[R] Fin n → R
hf : Injective ⇑f
g : (Fin (n + 1) → R) →ₗ[R] Fin (n + 1) → R := ExtendByZero.linearMap R castSucc ∘ₗ f
hg : Injective ⇑g
hnex : ¬∃ i, castSucc i = last n
a₀ : R := coeff (minpoly R g) 0
this : a₀ ≠ 0
heval : ((aeval g) (minpoly R g)) (Pi.single (last n) 1) = 0 (Pi.single (last n) 1)
⊢ a₀ = 0

Next tactic:
obtain ⟨P, hP⟩ := X_dvd_iff.2 (erase_same (minpoly R g) 0)
/-- Any commutative ring satisfies the `StrongRankCondition`. -/
instance (priority := 100) commRing_strongRankCondition : StrongRankCondition R := by
  suffices ∀ n, ∀ f : (Fin (n + 1) → R) →ₗ[R] Fin n → R, ¬Injective f by
    rwa [strongRankCondition_iff_succ R]
  intro n f
  by_contra hf
  -- Porting note: Lean can now find these instances without help...
  -- letI : Module.Finite R (Fin n.succ → R) := Module.Finite.pi
  -- letI : Module.Free R (Fin n.succ → R) := Module.Free.pi _ _
  let g : (Fin (n + 1) → R) →ₗ[R] Fin (n + 1) → R := (ExtendByZero.linearMap R castSucc).comp f
  have hg : Injective g := (extend_injective Fin.strictMono_castSucc.injective _).comp hf
  have hnex : ¬∃ i : Fin n, castSucc i = last n :=
    fun ⟨i, hi⟩ => ne_of_lt (castSucc_lt_last i) hi
  let a₀ := (minpoly R g).coeff 0
  have : a₀ ≠ 0 := minpoly_coeff_zero_of_injective hg
  have : a₀ = 0 := by
    -- Evaluate `(minpoly R g) g` at the vector `(0,...,0,1)`
    have heval := LinearMap.congr_fun (minpoly.aeval R g) (Pi.single (Fin.last n) 1)
    obtain ⟨P, hP⟩ := X_dvd_iff.2 (erase_same (minpoly R g) 0)
    

Proof state:
case intro
R : Type u_1
inst✝¹ : CommRing R
inst✝ : Nontrivial R
n : ℕ
f : (Fin (n + 1) → R) →ₗ[R] Fin n → R
hf : Injective ⇑f
g : (Fin (n + 1) → R) →ₗ[R] Fin (n + 1) → R := ExtendByZero.linearMap R castSucc ∘ₗ f
hg : Injective ⇑g
hnex : ¬∃ i, castSucc i = last n
a₀ : R := coeff (minpoly R g) 0
this : a₀ ≠ 0
heval : ((aeval g) (minpoly R g)) (Pi.single (last n) 1) = 0 (Pi.single (last n) 1)
P : R[X]
hP : erase 0 (minpoly R g) = X * P
⊢ a₀ = 0

Next tactic:
rw [← monomial_add_erase (minpoly R g) 0, hP] at heval
/-- Any commutative ring satisfies the `StrongRankCondition`. -/
instance (priority := 100) commRing_strongRankCondition : StrongRankCondition R := by
  suffices ∀ n, ∀ f : (Fin (n + 1) → R) →ₗ[R] Fin n → R, ¬Injective f by
    rwa [strongRankCondition_iff_succ R]
  intro n f
  by_contra hf
  -- Porting note: Lean can now find these instances without help...
  -- letI : Module.Finite R (Fin n.succ → R) := Module.Finite.pi
  -- letI : Module.Free R (Fin n.succ → R) := Module.Free.pi _ _
  let g : (Fin (n + 1) → R) →ₗ[R] Fin (n + 1) → R := (ExtendByZero.linearMap R castSucc).comp f
  have hg : Injective g := (extend_injective Fin.strictMono_castSucc.injective _).comp hf
  have hnex : ¬∃ i : Fin n, castSucc i = last n :=
    fun ⟨i, hi⟩ => ne_of_lt (castSucc_lt_last i) hi
  let a₀ := (minpoly R g).coeff 0
  have : a₀ ≠ 0 := minpoly_coeff_zero_of_injective hg
  have : a₀ = 0 := by
    -- Evaluate `(minpoly R g) g` at the vector `(0,...,0,1)`
    have heval := LinearMap.congr_fun (minpoly.aeval R g) (Pi.single (Fin.last n) 1)
    obtain ⟨P, hP⟩ := X_dvd_iff.2 (erase_same (minpoly R g) 0)
    rw [← monomial_add_erase (minpoly R g) 0, hP] at heval
    

Proof state:
case intro
R : Type u_1
inst✝¹ : CommRing R
inst✝ : Nontrivial R
n : ℕ
f : (Fin (n + 1) → R) →ₗ[R] Fin n → R
hf : Injective ⇑f
g : (Fin (n + 1) → R) →ₗ[R] Fin (n + 1) → R := ExtendByZero.linearMap R castSucc ∘ₗ f
hg : Injective ⇑g
hnex : ¬∃ i, castSucc i = last n
a₀ : R := coeff (minpoly R g) 0
this : a₀ ≠ 0
P : R[X]
heval : ((aeval g) ((monomial 0) (coeff (minpoly R g) 0) + X * P)) (Pi.single (last n) 1) = 0 (Pi.single (last n) 1)
hP : erase 0 (minpoly R g) = X * P
⊢ a₀ = 0

Next tactic:
replace heval := congr_fun heval (Fin.last n)
/-- Any commutative ring satisfies the `StrongRankCondition`. -/
instance (priority := 100) commRing_strongRankCondition : StrongRankCondition R := by
  suffices ∀ n, ∀ f : (Fin (n + 1) → R) →ₗ[R] Fin n → R, ¬Injective f by
    rwa [strongRankCondition_iff_succ R]
  intro n f
  by_contra hf
  -- Porting note: Lean can now find these instances without help...
  -- letI : Module.Finite R (Fin n.succ → R) := Module.Finite.pi
  -- letI : Module.Free R (Fin n.succ → R) := Module.Free.pi _ _
  let g : (Fin (n + 1) → R) →ₗ[R] Fin (n + 1) → R := (ExtendByZero.linearMap R castSucc).comp f
  have hg : Injective g := (extend_injective Fin.strictMono_castSucc.injective _).comp hf
  have hnex : ¬∃ i : Fin n, castSucc i = last n :=
    fun ⟨i, hi⟩ => ne_of_lt (castSucc_lt_last i) hi
  let a₀ := (minpoly R g).coeff 0
  have : a₀ ≠ 0 := minpoly_coeff_zero_of_injective hg
  have : a₀ = 0 := by
    -- Evaluate `(minpoly R g) g` at the vector `(0,...,0,1)`
    have heval := LinearMap.congr_fun (minpoly.aeval R g) (Pi.single (Fin.last n) 1)
    obtain ⟨P, hP⟩ := X_dvd_iff.2 (erase_same (minpoly R g) 0)
    rw [← monomial_add_erase (minpoly R g) 0, hP] at heval
    replace heval := congr_fun heval (Fin.last n)
    -- Porting note: ...it's just that this line gives a timeout without slightly raising heartbeats
    

Proof state:
case intro
R : Type u_1
inst✝¹ : CommRing R
inst✝ : Nontrivial R
n : ℕ
f : (Fin (n + 1) → R) →ₗ[R] Fin n → R
hf : Injective ⇑f
g : (Fin (n + 1) → R) →ₗ[R] Fin (n + 1) → R := ExtendByZero.linearMap R castSucc ∘ₗ f
hg : Injective ⇑g
hnex : ¬∃ i, castSucc i = last n
a₀ : R := coeff (minpoly R g) 0
this : a₀ ≠ 0
P : R[X]
hP : erase 0 (minpoly R g) = X * P
heval :
  ((aeval g) ((monomial 0) (coeff (minpoly R g) 0) + X * P)) (Pi.single (last n) 1) (last n) =
    0 (Pi.single (last n) 1) (last n)
⊢ a₀ = 0

Next tactic:
simpa [hnex] using heval
/-- Any commutative ring satisfies the `StrongRankCondition`. -/
instance (priority := 100) commRing_strongRankCondition : StrongRankCondition R := by
  suffices ∀ n, ∀ f : (Fin (n + 1) → R) →ₗ[R] Fin n → R, ¬Injective f by
    rwa [strongRankCondition_iff_succ R]
  intro n f
  by_contra hf
  -- Porting note: Lean can now find these instances without help...
  -- letI : Module.Finite R (Fin n.succ → R) := Module.Finite.pi
  -- letI : Module.Free R (Fin n.succ → R) := Module.Free.pi _ _
  let g : (Fin (n + 1) → R) →ₗ[R] Fin (n + 1) → R := (ExtendByZero.linearMap R castSucc).comp f
  have hg : Injective g := (extend_injective Fin.strictMono_castSucc.injective _).comp hf
  have hnex : ¬∃ i : Fin n, castSucc i = last n :=
    fun ⟨i, hi⟩ => ne_of_lt (castSucc_lt_last i) hi
  let a₀ := (minpoly R g).coeff 0
  have : a₀ ≠ 0 := minpoly_coeff_zero_of_injective hg
  have : a₀ = 0 := by
    -- Evaluate `(minpoly R g) g` at the vector `(0,...,0,1)`
    have heval := LinearMap.congr_fun (minpoly.aeval R g) (Pi.single (Fin.last n) 1)
    obtain ⟨P, hP⟩ := X_dvd_iff.2 (erase_same (minpoly R g) 0)
    rw [← monomial_add_erase (minpoly R g) 0, hP] at heval
    replace heval := congr_fun heval (Fin.last n)
    -- Porting note: ...it's just that this line gives a timeout without slightly raising heartbeats
    simpa [hnex] using heval
  

Proof state:
R : Type u_1
inst✝¹ : CommRing R
inst✝ : Nontrivial R
n : ℕ
f : (Fin (n + 1) → R) →ₗ[R] Fin n → R
hf : Injective ⇑f
g : (Fin (n + 1) → R) →ₗ[R] Fin (n + 1) → R := ExtendByZero.linearMap R castSucc ∘ₗ f
hg : Injective ⇑g
hnex : ¬∃ i, castSucc i = last n
a₀ : R := coeff (minpoly R g) 0
this✝ : a₀ ≠ 0
this : a₀ = 0
⊢ False

Next tactic:
contradiction
@[simp]
theorem coeff_scaleRoots (p : R[X]) (s : R) (i : ℕ) :
    (scaleRoots p s).coeff i = coeff p i * s ^ (p.natDegree - i) := by
  

Proof state:
R : Type u_1
S : Type u_2
A : Type u_3
K : Type u_4
inst✝¹ : Semiring R
inst✝ : Semiring S
p : R[X]
s : R
i : ℕ
⊢ coeff (scaleRoots p s) i = coeff p i * s ^ (natDegree p - i)

Next tactic:
simp (config := { contextual := true }) [scaleRoots, coeff_monomial]
theorem coeff_scaleRoots_natDegree (p : R[X]) (s : R) :
    (scaleRoots p s).coeff p.natDegree = p.leadingCoeff := by
  

Proof state:
R : Type u_1
S : Type u_2
A : Type u_3
K : Type u_4
inst✝¹ : Semiring R
inst✝ : Semiring S
p : R[X]
s : R
⊢ coeff (scaleRoots p s) (natDegree p) = leadingCoeff p

Next tactic:
rw [leadingCoeff, coeff_scaleRoots, tsub_self, pow_zero, mul_one]
@[simp]
theorem zero_scaleRoots (s : R) : scaleRoots 0 s = 0 := by
  

Proof state:
R : Type u_1
S : Type u_2
A : Type u_3
K : Type u_4
inst✝¹ : Semiring R
inst✝ : Semiring S
s : R
⊢ scaleRoots 0 s = 0

Next tactic:
ext
@[simp]
theorem zero_scaleRoots (s : R) : scaleRoots 0 s = 0 := by
  ext
  

Proof state:
case a
R : Type u_1
S : Type u_2
A : Type u_3
K : Type u_4
inst✝¹ : Semiring R
inst✝ : Semiring S
s : R
n✝ : ℕ
⊢ coeff (scaleRoots 0 s) n✝ = coeff 0 n✝

Next tactic:
simp
theorem scaleRoots_ne_zero {p : R[X]} (hp : p ≠ 0) (s : R) : scaleRoots p s ≠ 0 := by
  

Proof state:
R : Type u_1
S : Type u_2
A : Type u_3
K : Type u_4
inst✝¹ : Semiring R
inst✝ : Semiring S
p : R[X]
hp : p ≠ 0
s : R
⊢ scaleRoots p s ≠ 0

Next tactic:
intro h
theorem scaleRoots_ne_zero {p : R[X]} (hp : p ≠ 0) (s : R) : scaleRoots p s ≠ 0 := by
  intro h
  

Proof state:
R : Type u_1
S : Type u_2
A : Type u_3
K : Type u_4
inst✝¹ : Semiring R
inst✝ : Semiring S
p : R[X]
hp : p ≠ 0
s : R
h : scaleRoots p s = 0
⊢ False

Next tactic:
have : p.coeff p.natDegree ≠ 0 := mt leadingCoeff_eq_zero.mp hp
theorem scaleRoots_ne_zero {p : R[X]} (hp : p ≠ 0) (s : R) : scaleRoots p s ≠ 0 := by
  intro h
  have : p.coeff p.natDegree ≠ 0 := mt leadingCoeff_eq_zero.mp hp
  

Proof state:
R : Type u_1
S : Type u_2
A : Type u_3
K : Type u_4
inst✝¹ : Semiring R
inst✝ : Semiring S
p : R[X]
hp : p ≠ 0
s : R
h : scaleRoots p s = 0
this : coeff p (natDegree p) ≠ 0
⊢ False

Next tactic:
have : (scaleRoots p s).coeff p.natDegree = 0 :=
    congr_fun (congr_arg (coeff : R[X] → ℕ → R) h) p.natDegree