l3lab/ntp-mathlib huggingface dataset:
/-- In the commutative diagram
```
    f     g
 X₁ --→ X₂ --→ X₃
 ↑      ↑      ↑
v|     u|     w|
 ι  → ι ⊕ ι' ← ι'
```
where the top row is an exact sequence of modules and the maps on the bottom are `Sum.inl` and
`Sum.inr`. If `v` spans `X₁` and `w` spans `X₃`, then `u` spans `X₂`. -/
theorem span_exact (huv : u ∘ Sum.inl = S.f ∘ v)
    (hv : ⊤ ≤ span R (range v))
    (hw : ⊤ ≤ span R (range (S.g ∘ u ∘ Sum.inr))) :
    ⊤ ≤ span R (range u) := by
  intro m _
  have hgm : S.g m ∈ span R (range (S.g ∘ u ∘ Sum.inr)) := hw mem_top
  rw [Finsupp.mem_span_range_iff_exists_finsupp] at hgm
  obtain ⟨cm, hm⟩ := hgm
  let m' : S.X₂ := Finsupp.sum cm fun j a ↦ a • (u (Sum.inr j))
  have hsub : m - m' ∈ LinearMap.range S.f
  · rw [hS.moduleCat_range_eq_ker]
    simp only [LinearMap.mem_ker, map_sub, sub_eq_zero]
    rw [← hm, map_finsupp_sum]
    simp only [Function.comp_apply, SMulHomClass.map_smul]
  obtain ⟨n, hnm⟩ := hsub
  have hn : n ∈ span R (range v) := hv mem_top
  rw [Finsupp.mem_span_range_iff_exists_finsupp] at hn
  obtain ⟨cn, hn⟩ := hn
  rw [← hn, map_finsupp_sum] at hnm
  rw [← sub_add_cancel m m', ← hnm,]
  simp only [SMulHomClass.map_smul]
  have hn' : (Finsupp.sum cn fun a b ↦ b • S.f (v a)) =
      (Finsupp.sum cn fun a b ↦ b • u (Sum.inl a)) :=
    by congr; ext a b; change b • (S.f ∘ v) a = _; rw [← huv]; rfl
  rw [hn']
  apply add_mem
  · rw [Finsupp.mem_span_range_iff_exists_finsupp]
    

Proof state:
case intro.intro.intro.a
ι : Type u_1
ι' : Type u_2
R : Type u_3
inst✝ : Ring R
S : ShortComplex (ModuleCat R)
hS : ShortComplex.Exact S
hS' : ShortComplex.ShortExact S
v : ι → ↑S.X₁
β✝ : Type u_4
u : ι ⊕ β✝ → ↑S.X₂
huv : u ∘ Sum.inl = ⇑S.f ∘ v
hv : ⊤ ≤ span R (range v)
hw : ⊤ ≤ span R (range (⇑S.g ∘ u ∘ Sum.inr))
m : ↑S.X₂
a✝ : m ∈ ⊤
cm : β✝ →₀ R
hm : (Finsupp.sum cm fun i a => a • (⇑S.g ∘ u ∘ Sum.inr) i) = S.g m
m' : ↑S.X₂ := Finsupp.sum cm fun j a => a • u (Sum.inr j)
n : ↑S.X₁
cn : ι →₀ R
hnm : (Finsupp.sum cn fun a b => S.f (b • v a)) = m - m'
hn : (Finsupp.sum cn fun i a => a • v i) = n
hn' : (Finsupp.sum cn fun a b => b • S.f (v a)) = Finsupp.sum cn fun a b => b • u (Sum.inl a)
⊢ ∃ c, (Finsupp.sum c fun i a => a • u i) = Finsupp.sum cn fun a b => b • u (Sum.inl a)

Next tactic:
use cn.mapDomain (Sum.inl)
/-- In the commutative diagram
```
    f     g
 X₁ --→ X₂ --→ X₃
 ↑      ↑      ↑
v|     u|     w|
 ι  → ι ⊕ ι' ← ι'
```
where the top row is an exact sequence of modules and the maps on the bottom are `Sum.inl` and
`Sum.inr`. If `v` spans `X₁` and `w` spans `X₃`, then `u` spans `X₂`. -/
theorem span_exact (huv : u ∘ Sum.inl = S.f ∘ v)
    (hv : ⊤ ≤ span R (range v))
    (hw : ⊤ ≤ span R (range (S.g ∘ u ∘ Sum.inr))) :
    ⊤ ≤ span R (range u) := by
  intro m _
  have hgm : S.g m ∈ span R (range (S.g ∘ u ∘ Sum.inr)) := hw mem_top
  rw [Finsupp.mem_span_range_iff_exists_finsupp] at hgm
  obtain ⟨cm, hm⟩ := hgm
  let m' : S.X₂ := Finsupp.sum cm fun j a ↦ a • (u (Sum.inr j))
  have hsub : m - m' ∈ LinearMap.range S.f
  · rw [hS.moduleCat_range_eq_ker]
    simp only [LinearMap.mem_ker, map_sub, sub_eq_zero]
    rw [← hm, map_finsupp_sum]
    simp only [Function.comp_apply, SMulHomClass.map_smul]
  obtain ⟨n, hnm⟩ := hsub
  have hn : n ∈ span R (range v) := hv mem_top
  rw [Finsupp.mem_span_range_iff_exists_finsupp] at hn
  obtain ⟨cn, hn⟩ := hn
  rw [← hn, map_finsupp_sum] at hnm
  rw [← sub_add_cancel m m', ← hnm,]
  simp only [SMulHomClass.map_smul]
  have hn' : (Finsupp.sum cn fun a b ↦ b • S.f (v a)) =
      (Finsupp.sum cn fun a b ↦ b • u (Sum.inl a)) :=
    by congr; ext a b; change b • (S.f ∘ v) a = _; rw [← huv]; rfl
  rw [hn']
  apply add_mem
  · rw [Finsupp.mem_span_range_iff_exists_finsupp]
    use cn.mapDomain (Sum.inl)
    

Proof state:
case h
ι : Type u_1
ι' : Type u_2
R : Type u_3
inst✝ : Ring R
S : ShortComplex (ModuleCat R)
hS : ShortComplex.Exact S
hS' : ShortComplex.ShortExact S
v : ι → ↑S.X₁
β✝ : Type u_4
u : ι ⊕ β✝ → ↑S.X₂
huv : u ∘ Sum.inl = ⇑S.f ∘ v
hv : ⊤ ≤ span R (range v)
hw : ⊤ ≤ span R (range (⇑S.g ∘ u ∘ Sum.inr))
m : ↑S.X₂
a✝ : m ∈ ⊤
cm : β✝ →₀ R
hm : (Finsupp.sum cm fun i a => a • (⇑S.g ∘ u ∘ Sum.inr) i) = S.g m
m' : ↑S.X₂ := Finsupp.sum cm fun j a => a • u (Sum.inr j)
n : ↑S.X₁
cn : ι →₀ R
hnm : (Finsupp.sum cn fun a b => S.f (b • v a)) = m - m'
hn : (Finsupp.sum cn fun i a => a • v i) = n
hn' : (Finsupp.sum cn fun a b => b • S.f (v a)) = Finsupp.sum cn fun a b => b • u (Sum.inl a)
⊢ (Finsupp.sum (Finsupp.mapDomain Sum.inl cn) fun i a => a • u i) = Finsupp.sum cn fun a b => b • u (Sum.inl a)

Next tactic:
rw [Finsupp.sum_mapDomain_index_inj Sum.inl_injective]
/-- In the commutative diagram
```
    f     g
 X₁ --→ X₂ --→ X₃
 ↑      ↑      ↑
v|     u|     w|
 ι  → ι ⊕ ι' ← ι'
```
where the top row is an exact sequence of modules and the maps on the bottom are `Sum.inl` and
`Sum.inr`. If `v` spans `X₁` and `w` spans `X₃`, then `u` spans `X₂`. -/
theorem span_exact (huv : u ∘ Sum.inl = S.f ∘ v)
    (hv : ⊤ ≤ span R (range v))
    (hw : ⊤ ≤ span R (range (S.g ∘ u ∘ Sum.inr))) :
    ⊤ ≤ span R (range u) := by
  intro m _
  have hgm : S.g m ∈ span R (range (S.g ∘ u ∘ Sum.inr)) := hw mem_top
  rw [Finsupp.mem_span_range_iff_exists_finsupp] at hgm
  obtain ⟨cm, hm⟩ := hgm
  let m' : S.X₂ := Finsupp.sum cm fun j a ↦ a • (u (Sum.inr j))
  have hsub : m - m' ∈ LinearMap.range S.f
  · rw [hS.moduleCat_range_eq_ker]
    simp only [LinearMap.mem_ker, map_sub, sub_eq_zero]
    rw [← hm, map_finsupp_sum]
    simp only [Function.comp_apply, SMulHomClass.map_smul]
  obtain ⟨n, hnm⟩ := hsub
  have hn : n ∈ span R (range v) := hv mem_top
  rw [Finsupp.mem_span_range_iff_exists_finsupp] at hn
  obtain ⟨cn, hn⟩ := hn
  rw [← hn, map_finsupp_sum] at hnm
  rw [← sub_add_cancel m m', ← hnm,]
  simp only [SMulHomClass.map_smul]
  have hn' : (Finsupp.sum cn fun a b ↦ b • S.f (v a)) =
      (Finsupp.sum cn fun a b ↦ b • u (Sum.inl a)) :=
    by congr; ext a b; change b • (S.f ∘ v) a = _; rw [← huv]; rfl
  rw [hn']
  apply add_mem
  · rw [Finsupp.mem_span_range_iff_exists_finsupp]
    use cn.mapDomain (Sum.inl)
    rw [Finsupp.sum_mapDomain_index_inj Sum.inl_injective]
  · 

Proof state:
case intro.intro.intro.a
ι : Type u_1
ι' : Type u_2
R : Type u_3
inst✝ : Ring R
S : ShortComplex (ModuleCat R)
hS : ShortComplex.Exact S
hS' : ShortComplex.ShortExact S
v : ι → ↑S.X₁
β✝ : Type u_4
u : ι ⊕ β✝ → ↑S.X₂
huv : u ∘ Sum.inl = ⇑S.f ∘ v
hv : ⊤ ≤ span R (range v)
hw : ⊤ ≤ span R (range (⇑S.g ∘ u ∘ Sum.inr))
m : ↑S.X₂
a✝ : m ∈ ⊤
cm : β✝ →₀ R
hm : (Finsupp.sum cm fun i a => a • (⇑S.g ∘ u ∘ Sum.inr) i) = S.g m
m' : ↑S.X₂ := Finsupp.sum cm fun j a => a • u (Sum.inr j)
n : ↑S.X₁
cn : ι →₀ R
hnm : (Finsupp.sum cn fun a b => S.f (b • v a)) = m - m'
hn : (Finsupp.sum cn fun i a => a • v i) = n
hn' : (Finsupp.sum cn fun a b => b • S.f (v a)) = Finsupp.sum cn fun a b => b • u (Sum.inl a)
⊢ (Finsupp.sum cm fun j a => a • u (Sum.inr j)) ∈ span R (range u)

Next tactic:
rw [Finsupp.mem_span_range_iff_exists_finsupp]
/-- In the commutative diagram
```
    f     g
 X₁ --→ X₂ --→ X₃
 ↑      ↑      ↑
v|     u|     w|
 ι  → ι ⊕ ι' ← ι'
```
where the top row is an exact sequence of modules and the maps on the bottom are `Sum.inl` and
`Sum.inr`. If `v` spans `X₁` and `w` spans `X₃`, then `u` spans `X₂`. -/
theorem span_exact (huv : u ∘ Sum.inl = S.f ∘ v)
    (hv : ⊤ ≤ span R (range v))
    (hw : ⊤ ≤ span R (range (S.g ∘ u ∘ Sum.inr))) :
    ⊤ ≤ span R (range u) := by
  intro m _
  have hgm : S.g m ∈ span R (range (S.g ∘ u ∘ Sum.inr)) := hw mem_top
  rw [Finsupp.mem_span_range_iff_exists_finsupp] at hgm
  obtain ⟨cm, hm⟩ := hgm
  let m' : S.X₂ := Finsupp.sum cm fun j a ↦ a • (u (Sum.inr j))
  have hsub : m - m' ∈ LinearMap.range S.f
  · rw [hS.moduleCat_range_eq_ker]
    simp only [LinearMap.mem_ker, map_sub, sub_eq_zero]
    rw [← hm, map_finsupp_sum]
    simp only [Function.comp_apply, SMulHomClass.map_smul]
  obtain ⟨n, hnm⟩ := hsub
  have hn : n ∈ span R (range v) := hv mem_top
  rw [Finsupp.mem_span_range_iff_exists_finsupp] at hn
  obtain ⟨cn, hn⟩ := hn
  rw [← hn, map_finsupp_sum] at hnm
  rw [← sub_add_cancel m m', ← hnm,]
  simp only [SMulHomClass.map_smul]
  have hn' : (Finsupp.sum cn fun a b ↦ b • S.f (v a)) =
      (Finsupp.sum cn fun a b ↦ b • u (Sum.inl a)) :=
    by congr; ext a b; change b • (S.f ∘ v) a = _; rw [← huv]; rfl
  rw [hn']
  apply add_mem
  · rw [Finsupp.mem_span_range_iff_exists_finsupp]
    use cn.mapDomain (Sum.inl)
    rw [Finsupp.sum_mapDomain_index_inj Sum.inl_injective]
  · rw [Finsupp.mem_span_range_iff_exists_finsupp]
    

Proof state:
case intro.intro.intro.a
ι : Type u_1
ι' : Type u_2
R : Type u_3
inst✝ : Ring R
S : ShortComplex (ModuleCat R)
hS : ShortComplex.Exact S
hS' : ShortComplex.ShortExact S
v : ι → ↑S.X₁
β✝ : Type u_4
u : ι ⊕ β✝ → ↑S.X₂
huv : u ∘ Sum.inl = ⇑S.f ∘ v
hv : ⊤ ≤ span R (range v)
hw : ⊤ ≤ span R (range (⇑S.g ∘ u ∘ Sum.inr))
m : ↑S.X₂
a✝ : m ∈ ⊤
cm : β✝ →₀ R
hm : (Finsupp.sum cm fun i a => a • (⇑S.g ∘ u ∘ Sum.inr) i) = S.g m
m' : ↑S.X₂ := Finsupp.sum cm fun j a => a • u (Sum.inr j)
n : ↑S.X₁
cn : ι →₀ R
hnm : (Finsupp.sum cn fun a b => S.f (b • v a)) = m - m'
hn : (Finsupp.sum cn fun i a => a • v i) = n
hn' : (Finsupp.sum cn fun a b => b • S.f (v a)) = Finsupp.sum cn fun a b => b • u (Sum.inl a)
⊢ ∃ c, (Finsupp.sum c fun i a => a • u i) = Finsupp.sum cm fun j a => a • u (Sum.inr j)

Next tactic:
use cm.mapDomain (Sum.inr)
/-- In the commutative diagram
```
    f     g
 X₁ --→ X₂ --→ X₃
 ↑      ↑      ↑
v|     u|     w|
 ι  → ι ⊕ ι' ← ι'
```
where the top row is an exact sequence of modules and the maps on the bottom are `Sum.inl` and
`Sum.inr`. If `v` spans `X₁` and `w` spans `X₃`, then `u` spans `X₂`. -/
theorem span_exact (huv : u ∘ Sum.inl = S.f ∘ v)
    (hv : ⊤ ≤ span R (range v))
    (hw : ⊤ ≤ span R (range (S.g ∘ u ∘ Sum.inr))) :
    ⊤ ≤ span R (range u) := by
  intro m _
  have hgm : S.g m ∈ span R (range (S.g ∘ u ∘ Sum.inr)) := hw mem_top
  rw [Finsupp.mem_span_range_iff_exists_finsupp] at hgm
  obtain ⟨cm, hm⟩ := hgm
  let m' : S.X₂ := Finsupp.sum cm fun j a ↦ a • (u (Sum.inr j))
  have hsub : m - m' ∈ LinearMap.range S.f
  · rw [hS.moduleCat_range_eq_ker]
    simp only [LinearMap.mem_ker, map_sub, sub_eq_zero]
    rw [← hm, map_finsupp_sum]
    simp only [Function.comp_apply, SMulHomClass.map_smul]
  obtain ⟨n, hnm⟩ := hsub
  have hn : n ∈ span R (range v) := hv mem_top
  rw [Finsupp.mem_span_range_iff_exists_finsupp] at hn
  obtain ⟨cn, hn⟩ := hn
  rw [← hn, map_finsupp_sum] at hnm
  rw [← sub_add_cancel m m', ← hnm,]
  simp only [SMulHomClass.map_smul]
  have hn' : (Finsupp.sum cn fun a b ↦ b • S.f (v a)) =
      (Finsupp.sum cn fun a b ↦ b • u (Sum.inl a)) :=
    by congr; ext a b; change b • (S.f ∘ v) a = _; rw [← huv]; rfl
  rw [hn']
  apply add_mem
  · rw [Finsupp.mem_span_range_iff_exists_finsupp]
    use cn.mapDomain (Sum.inl)
    rw [Finsupp.sum_mapDomain_index_inj Sum.inl_injective]
  · rw [Finsupp.mem_span_range_iff_exists_finsupp]
    use cm.mapDomain (Sum.inr)
    

Proof state:
case h
ι : Type u_1
ι' : Type u_2
R : Type u_3
inst✝ : Ring R
S : ShortComplex (ModuleCat R)
hS : ShortComplex.Exact S
hS' : ShortComplex.ShortExact S
v : ι → ↑S.X₁
β✝ : Type u_4
u : ι ⊕ β✝ → ↑S.X₂
huv : u ∘ Sum.inl = ⇑S.f ∘ v
hv : ⊤ ≤ span R (range v)
hw : ⊤ ≤ span R (range (⇑S.g ∘ u ∘ Sum.inr))
m : ↑S.X₂
a✝ : m ∈ ⊤
cm : β✝ →₀ R
hm : (Finsupp.sum cm fun i a => a • (⇑S.g ∘ u ∘ Sum.inr) i) = S.g m
m' : ↑S.X₂ := Finsupp.sum cm fun j a => a • u (Sum.inr j)
n : ↑S.X₁
cn : ι →₀ R
hnm : (Finsupp.sum cn fun a b => S.f (b • v a)) = m - m'
hn : (Finsupp.sum cn fun i a => a • v i) = n
hn' : (Finsupp.sum cn fun a b => b • S.f (v a)) = Finsupp.sum cn fun a b => b • u (Sum.inl a)
⊢ (Finsupp.sum (Finsupp.mapDomain Sum.inr cm) fun i a => a • u i) = Finsupp.sum cm fun j a => a • u (Sum.inr j)

Next tactic:
rw [Finsupp.sum_mapDomain_index_inj Sum.inr_injective]
/-- Given an exact sequence `X₁ ⟶ X₂ ⟶ X₃ ⟶ 0` of `R`-modules and spanning
    families `v : ι → X₁` and `w : ι' → X₃`, we get a spanning family `ι ⊕ ι' → X₂` -/
theorem span_rightExact {w : ι' → S.X₃} (hv : ⊤ ≤ span R (range v))
    (hw : ⊤ ≤ span R (range w)) (hE : Epi S.g) :
    ⊤ ≤ span R (range (Sum.elim (S.f ∘ v) (S.g.toFun.invFun ∘ w))) := by
  

Proof state:
ι : Type u_1
ι' : Type u_2
R : Type u_3
inst✝ : Ring R
S : ShortComplex (ModuleCat R)
hS : ShortComplex.Exact S
hS' : ShortComplex.ShortExact S
v : ι → ↑S.X₁
w : ι' → ↑S.X₃
hv : ⊤ ≤ span R (range v)
hw : ⊤ ≤ span R (range w)
hE : Epi S.g
⊢ ⊤ ≤ span R (range (Sum.elim (⇑S.f ∘ v) (Function.invFun S.g.toFun ∘ w)))

Next tactic:
refine' span_exact hS _ hv _
/-- Given an exact sequence `X₁ ⟶ X₂ ⟶ X₃ ⟶ 0` of `R`-modules and spanning
    families `v : ι → X₁` and `w : ι' → X₃`, we get a spanning family `ι ⊕ ι' → X₂` -/
theorem span_rightExact {w : ι' → S.X₃} (hv : ⊤ ≤ span R (range v))
    (hw : ⊤ ≤ span R (range w)) (hE : Epi S.g) :
    ⊤ ≤ span R (range (Sum.elim (S.f ∘ v) (S.g.toFun.invFun ∘ w))) := by
  refine' span_exact hS _ hv _
  · 

Proof state:
case refine'_1
ι : Type u_1
ι' : Type u_2
R : Type u_3
inst✝ : Ring R
S : ShortComplex (ModuleCat R)
hS : ShortComplex.Exact S
hS' : ShortComplex.ShortExact S
v : ι → ↑S.X₁
w : ι' → ↑S.X₃
hv : ⊤ ≤ span R (range v)
hw : ⊤ ≤ span R (range w)
hE : Epi S.g
⊢ Sum.elim (⇑S.f ∘ v) (Function.invFun S.g.toFun ∘ w) ∘ Sum.inl = ⇑S.f ∘ v

Next tactic:
simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, Sum.elim_comp_inl]
/-- Given an exact sequence `X₁ ⟶ X₂ ⟶ X₃ ⟶ 0` of `R`-modules and spanning
    families `v : ι → X₁` and `w : ι' → X₃`, we get a spanning family `ι ⊕ ι' → X₂` -/
theorem span_rightExact {w : ι' → S.X₃} (hv : ⊤ ≤ span R (range v))
    (hw : ⊤ ≤ span R (range w)) (hE : Epi S.g) :
    ⊤ ≤ span R (range (Sum.elim (S.f ∘ v) (S.g.toFun.invFun ∘ w))) := by
  refine' span_exact hS _ hv _
  · simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, Sum.elim_comp_inl]
  · 

Proof state:
case refine'_2
ι : Type u_1
ι' : Type u_2
R : Type u_3
inst✝ : Ring R
S : ShortComplex (ModuleCat R)
hS : ShortComplex.Exact S
hS' : ShortComplex.ShortExact S
v : ι → ↑S.X₁
w : ι' → ↑S.X₃
hv : ⊤ ≤ span R (range v)
hw : ⊤ ≤ span R (range w)
hE : Epi S.g
⊢ ⊤ ≤ span R (range (⇑S.g ∘ Sum.elim (⇑S.f ∘ v) (Function.invFun S.g.toFun ∘ w) ∘ Sum.inr))

Next tactic:
convert hw
/-- Given an exact sequence `X₁ ⟶ X₂ ⟶ X₃ ⟶ 0` of `R`-modules and spanning
    families `v : ι → X₁` and `w : ι' → X₃`, we get a spanning family `ι ⊕ ι' → X₂` -/
theorem span_rightExact {w : ι' → S.X₃} (hv : ⊤ ≤ span R (range v))
    (hw : ⊤ ≤ span R (range w)) (hE : Epi S.g) :
    ⊤ ≤ span R (range (Sum.elim (S.f ∘ v) (S.g.toFun.invFun ∘ w))) := by
  refine' span_exact hS _ hv _
  · simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, Sum.elim_comp_inl]
  · convert hw
    

Proof state:
case h.e'_4.h.e'_6.h.e'_3
ι : Type u_1
ι' : Type u_2
R : Type u_3
inst✝ : Ring R
S : ShortComplex (ModuleCat R)
hS : ShortComplex.Exact S
hS' : ShortComplex.ShortExact S
v : ι → ↑S.X₁
w : ι' → ↑S.X₃
hv : ⊤ ≤ span R (range v)
hw : ⊤ ≤ span R (range w)
hE : Epi S.g
⊢ ⇑S.g ∘ Sum.elim (⇑S.f ∘ v) (Function.invFun S.g.toFun ∘ w) ∘ Sum.inr = w

Next tactic:
simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, Sum.elim_comp_inr]
/-- Given an exact sequence `X₁ ⟶ X₂ ⟶ X₃ ⟶ 0` of `R`-modules and spanning
    families `v : ι → X₁` and `w : ι' → X₃`, we get a spanning family `ι ⊕ ι' → X₂` -/
theorem span_rightExact {w : ι' → S.X₃} (hv : ⊤ ≤ span R (range v))
    (hw : ⊤ ≤ span R (range w)) (hE : Epi S.g) :
    ⊤ ≤ span R (range (Sum.elim (S.f ∘ v) (S.g.toFun.invFun ∘ w))) := by
  refine' span_exact hS _ hv _
  · simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, Sum.elim_comp_inl]
  · convert hw
    simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, Sum.elim_comp_inr]
    

Proof state:
case h.e'_4.h.e'_6.h.e'_3
ι : Type u_1
ι' : Type u_2
R : Type u_3
inst✝ : Ring R
S : ShortComplex (ModuleCat R)
hS : ShortComplex.Exact S
hS' : ShortComplex.ShortExact S
v : ι → ↑S.X₁
w : ι' → ↑S.X₃
hv : ⊤ ≤ span R (range v)
hw : ⊤ ≤ span R (range w)
hE : Epi S.g
⊢ ⇑S.g ∘ Function.invFun ⇑S.g ∘ w = w

Next tactic:
rw [ModuleCat.epi_iff_surjective] at hE
/-- Given an exact sequence `X₁ ⟶ X₂ ⟶ X₃ ⟶ 0` of `R`-modules and spanning
    families `v : ι → X₁` and `w : ι' → X₃`, we get a spanning family `ι ⊕ ι' → X₂` -/
theorem span_rightExact {w : ι' → S.X₃} (hv : ⊤ ≤ span R (range v))
    (hw : ⊤ ≤ span R (range w)) (hE : Epi S.g) :
    ⊤ ≤ span R (range (Sum.elim (S.f ∘ v) (S.g.toFun.invFun ∘ w))) := by
  refine' span_exact hS _ hv _
  · simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, Sum.elim_comp_inl]
  · convert hw
    simp only [AddHom.toFun_eq_coe, LinearMap.coe_toAddHom, Sum.elim_comp_inr]
    rw [ModuleCat.epi_iff_surjective] at hE
    

Proof state:
case h.e'_4.h.e'_6.h.e'_3
ι : Type u_1
ι' : Type u_2
R : Type u_3
inst✝ : Ring R
S : ShortComplex (ModuleCat R)
hS : ShortComplex.Exact S
hS' : ShortComplex.ShortExact S
v : ι → ↑S.X₁
w : ι' → ↑S.X₃
hv : ⊤ ≤ span R (range v)
hw : ⊤ ≤ span R (range w)
hE : Function.Surjective ⇑S.g
⊢ ⇑S.g ∘ Function.invFun ⇑S.g ∘ w = w

Next tactic:
rw [← Function.comp.assoc, Function.RightInverse.comp_eq_id (Function.rightInverse_invFun hE),
      Function.comp.left_id]
theorem free_shortExact_rank_add [Module.Free R S.X₁] [Module.Free R S.X₃]
    [StrongRankCondition R] :
    Module.rank R S.X₂ = Module.rank R S.X₁ + Module.rank R S.X₃ := by
  

Proof state:
ι : Type u_1
ι' : Type u_2
R : Type u_3
inst✝³ : Ring R
S : ShortComplex (ModuleCat R)
hS : ShortComplex.Exact S
hS' : ShortComplex.ShortExact S
v : ι → ↑S.X₁
inst✝² : Module.Free R ↑S.X₁
inst✝¹ : Module.Free R ↑S.X₃
inst✝ : StrongRankCondition R
⊢ Module.rank R ↑S.X₂ = Module.rank R ↑S.X₁ + Module.rank R ↑S.X₃

Next tactic:
haveI := free_shortExact hS'
theorem free_shortExact_rank_add [Module.Free R S.X₁] [Module.Free R S.X₃]
    [StrongRankCondition R] :
    Module.rank R S.X₂ = Module.rank R S.X₁ + Module.rank R S.X₃ := by
  haveI := free_shortExact hS'
  

Proof state:
ι : Type u_1
ι' : Type u_2
R : Type u_3
inst✝³ : Ring R
S : ShortComplex (ModuleCat R)
hS : ShortComplex.Exact S
hS' : ShortComplex.ShortExact S
v : ι → ↑S.X₁
inst✝² : Module.Free R ↑S.X₁
inst✝¹ : Module.Free R ↑S.X₃
inst✝ : StrongRankCondition R
this : Module.Free R ↑S.X₂
⊢ Module.rank R ↑S.X₂ = Module.rank R ↑S.X₁ + Module.rank R ↑S.X₃

Next tactic:
rw [Module.Free.rank_eq_card_chooseBasisIndex, Module.Free.rank_eq_card_chooseBasisIndex R S.X₁,
    Module.Free.rank_eq_card_chooseBasisIndex R S.X₃, Cardinal.add_def, Cardinal.eq]
theorem free_shortExact_rank_add [Module.Free R S.X₁] [Module.Free R S.X₃]
    [StrongRankCondition R] :
    Module.rank R S.X₂ = Module.rank R S.X₁ + Module.rank R S.X₃ := by
  haveI := free_shortExact hS'
  rw [Module.Free.rank_eq_card_chooseBasisIndex, Module.Free.rank_eq_card_chooseBasisIndex R S.X₁,
    Module.Free.rank_eq_card_chooseBasisIndex R S.X₃, Cardinal.add_def, Cardinal.eq]
  

Proof state:
ι : Type u_1
ι' : Type u_2
R : Type u_3
inst✝³ : Ring R
S : ShortComplex (ModuleCat R)
hS : ShortComplex.Exact S
hS' : ShortComplex.ShortExact S
v : ι → ↑S.X₁
inst✝² : Module.Free R ↑S.X₁
inst✝¹ : Module.Free R ↑S.X₃
inst✝ : StrongRankCondition R
this : Module.Free R ↑S.X₂
⊢ Nonempty
    (Module.Free.ChooseBasisIndex R ↑S.X₂ ≃ Module.Free.ChooseBasisIndex R ↑S.X₁ ⊕ Module.Free.ChooseBasisIndex R ↑S.X₃)

Next tactic:
exact ⟨Basis.indexEquiv (Module.Free.chooseBasis R S.X₂) (Basis.ofShortExact hS'
    (Module.Free.chooseBasis R S.X₁) (Module.Free.chooseBasis R S.X₃))⟩
theorem free_shortExact_finrank_add [Module.Free R S.X₁] [Module.Free R S.X₃]
    [Module.Finite R S.X₁] [Module.Finite R S.X₃]
    (hN : FiniteDimensional.finrank R S.X₁ = n)
    (hP : FiniteDimensional.finrank R S.X₃ = p)
    [StrongRankCondition R] :
    FiniteDimensional.finrank R S.X₂ = n + p := by
  

Proof state:
ι : Type u_1
ι' : Type u_2
R : Type u_3
inst✝⁵ : Ring R
S : ShortComplex (ModuleCat R)
hS : ShortComplex.Exact S
hS' : ShortComplex.ShortExact S
v : ι → ↑S.X₁
n p : ℕ
inst✝⁴ : Module.Free R ↑S.X₁
inst✝³ : Module.Free R ↑S.X₃
inst✝² : Module.Finite R ↑S.X₁
inst✝¹ : Module.Finite R ↑S.X₃
hN : FiniteDimensional.finrank R ↑S.X₁ = n
hP : FiniteDimensional.finrank R ↑S.X₃ = p
inst✝ : StrongRankCondition R
⊢ FiniteDimensional.finrank R ↑S.X₂ = n + p

Next tactic:
apply FiniteDimensional.finrank_eq_of_rank_eq
theorem free_shortExact_finrank_add [Module.Free R S.X₁] [Module.Free R S.X₃]
    [Module.Finite R S.X₁] [Module.Finite R S.X₃]
    (hN : FiniteDimensional.finrank R S.X₁ = n)
    (hP : FiniteDimensional.finrank R S.X₃ = p)
    [StrongRankCondition R] :
    FiniteDimensional.finrank R S.X₂ = n + p := by
  apply FiniteDimensional.finrank_eq_of_rank_eq
  

Proof state:
case h
ι : Type u_1
ι' : Type u_2
R : Type u_3
inst✝⁵ : Ring R
S : ShortComplex (ModuleCat R)
hS : ShortComplex.Exact S
hS' : ShortComplex.ShortExact S
v : ι → ↑S.X₁
n p : ℕ
inst✝⁴ : Module.Free R ↑S.X₁
inst✝³ : Module.Free R ↑S.X₃
inst✝² : Module.Finite R ↑S.X₁
inst✝¹ : Module.Finite R ↑S.X₃
hN : FiniteDimensional.finrank R ↑S.X₁ = n
hP : FiniteDimensional.finrank R ↑S.X₃ = p
inst✝ : StrongRankCondition R
⊢ Module.rank R ↑S.X₂ = ↑(n + p)

Next tactic:
rw [free_shortExact_rank_add hS', ← hN, ← hP]
theorem free_shortExact_finrank_add [Module.Free R S.X₁] [Module.Free R S.X₃]
    [Module.Finite R S.X₁] [Module.Finite R S.X₃]
    (hN : FiniteDimensional.finrank R S.X₁ = n)
    (hP : FiniteDimensional.finrank R S.X₃ = p)
    [StrongRankCondition R] :
    FiniteDimensional.finrank R S.X₂ = n + p := by
  apply FiniteDimensional.finrank_eq_of_rank_eq
  rw [free_shortExact_rank_add hS', ← hN, ← hP]
  

Proof state:
case h
ι : Type u_1
ι' : Type u_2
R : Type u_3
inst✝⁵ : Ring R
S : ShortComplex (ModuleCat R)
hS : ShortComplex.Exact S
hS' : ShortComplex.ShortExact S
v : ι → ↑S.X₁
n p : ℕ
inst✝⁴ : Module.Free R ↑S.X₁
inst✝³ : Module.Free R ↑S.X₃
inst✝² : Module.Finite R ↑S.X₁
inst✝¹ : Module.Finite R ↑S.X₃
hN : FiniteDimensional.finrank R ↑S.X₁ = n
hP : FiniteDimensional.finrank R ↑S.X₃ = p
inst✝ : StrongRankCondition R
⊢ Module.rank R ↑S.X₁ + Module.rank R ↑S.X₃ = ↑(FiniteDimensional.finrank R ↑S.X₁ + FiniteDimensional.finrank R ↑S.X₃)

Next tactic:
simp only [Nat.cast_add, FiniteDimensional.finrank_eq_rank]
theorem PiToModule.fromMatrix_apply_single_one [DecidableEq ι] (A : Matrix ι ι R) (j : ι) :
    PiToModule.fromMatrix R b A (Pi.single j 1) = ∑ i : ι, A i j • b i := by
  

Proof state:
ι : Type u_1
inst✝⁴ : Fintype ι
M : Type u_2
inst✝³ : AddCommGroup M
R : Type u_3
inst✝² : CommRing R
inst✝¹ : Module R M
I : Ideal R
b : ι → M
hb : Submodule.span R (Set.range b) = ⊤
inst✝ : DecidableEq ι
A : Matrix ι ι R
j : ι
⊢ ((fromMatrix R b) A) (Pi.single j 1) = ∑ i : ι, A i j • b i

Next tactic:
rw [PiToModule.fromMatrix_apply, Fintype.total_apply, Matrix.mulVec_single]
theorem PiToModule.fromMatrix_apply_single_one [DecidableEq ι] (A : Matrix ι ι R) (j : ι) :
    PiToModule.fromMatrix R b A (Pi.single j 1) = ∑ i : ι, A i j • b i := by
  rw [PiToModule.fromMatrix_apply, Fintype.total_apply, Matrix.mulVec_single]
  

Proof state:
ι : Type u_1
inst✝⁴ : Fintype ι
M : Type u_2
inst✝³ : AddCommGroup M
R : Type u_3
inst✝² : CommRing R
inst✝¹ : Module R M
I : Ideal R
b : ι → M
hb : Submodule.span R (Set.range b) = ⊤
inst✝ : DecidableEq ι
A : Matrix ι ι R
j : ι
⊢ ∑ i : ι, (fun i => A i j * 1) i • b i = ∑ i : ι, A i j • b i

Next tactic:
simp_rw [mul_one]
theorem PiToModule.fromEnd_apply_single_one [DecidableEq ι] (f : Module.End R M) (i : ι) :
    PiToModule.fromEnd R b f (Pi.single i 1) = f (b i) := by
  

Proof state:
ι : Type u_1
inst✝⁴ : Fintype ι
M : Type u_2
inst✝³ : AddCommGroup M
R : Type u_3
inst✝² : CommRing R
inst✝¹ : Module R M
I : Ideal R
b : ι → M
hb : Submodule.span R (Set.range b) = ⊤
inst✝ : DecidableEq ι
f : Module.End R M
i : ι
⊢ ((fromEnd R b) f) (Pi.single i 1) = f (b i)

Next tactic:
rw [PiToModule.fromEnd_apply]
theorem PiToModule.fromEnd_apply_single_one [DecidableEq ι] (f : Module.End R M) (i : ι) :
    PiToModule.fromEnd R b f (Pi.single i 1) = f (b i) := by
  rw [PiToModule.fromEnd_apply]
  

Proof state:
ι : Type u_1
inst✝⁴ : Fintype ι
M : Type u_2
inst✝³ : AddCommGroup M
R : Type u_3
inst✝² : CommRing R
inst✝¹ : Module R M
I : Ideal R
b : ι → M
hb : Submodule.span R (Set.range b) = ⊤
inst✝ : DecidableEq ι
f : Module.End R M
i : ι
⊢ f (((Fintype.total R R) b) (Pi.single i 1)) = f (b i)

Next tactic:
congr