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
  

Proof state:
case intro.intro.intro
ι : 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₁
hnm : S.f n = m - m'
cn : ι →₀ R
hn : (Finsupp.sum cn fun i a => a • v i) = n
⊢ m ∈ span R (range u)

Next tactic:
rw [← hn, map_finsupp_sum] at hnm
/-- 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
  

Proof state:
case intro.intro.intro
ι : 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
⊢ m ∈ span R (range u)

Next tactic:
rw [← sub_add_cancel m m', ← hnm,]
/-- 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,]
  

Proof state:
case intro.intro.intro
ι : 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
⊢ (Finsupp.sum cn fun a b => S.f (b • v a)) + m' ∈ span R (range u)

Next tactic:
simp only [SMulHomClass.map_smul]
/-- 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]
  

Proof state:
case intro.intro.intro
ι : 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
⊢ ((Finsupp.sum cn fun a b => b • S.f (v a)) + Finsupp.sum cm fun j a => a • u (Sum.inr j)) ∈ span R (range u)

Next tactic:
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
/-- 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 

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₁
β✝ : 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
⊢ (Finsupp.sum cn fun a b => b • S.f (v a)) = Finsupp.sum cn fun a b => b • u (Sum.inl a)

Next tactic:
congr
/-- 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; 

Proof state:
case e_g
ι : 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
⊢ (fun a b => b • S.f (v a)) = fun a b => b • u (Sum.inl a)

Next tactic:
ext a b
/-- 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; 

Proof state:
case e_g.h.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
a : ι
b : R
⊢ b • S.f (v a) = b • u (Sum.inl a)

Next tactic:
change b • (S.f ∘ v) a = _
/-- 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 = _; 

Proof state:
case e_g.h.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
a : ι
b : R
⊢ b • (⇑S.f ∘ v) a = b • u (Sum.inl a)

Next tactic:
rw [← huv]
/-- 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]; 

Proof state:
case e_g.h.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
a : ι
b : R
⊢ b • (u ∘ Sum.inl) a = b • u (Sum.inl a)

Next tactic:
rfl
/-- 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
  

Proof state:
case intro.intro.intro
ι : 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 cn fun a b => b • S.f (v a)) + Finsupp.sum cm fun j a => a • u (Sum.inr j)) ∈ span R (range u)

Next tactic:
rw [hn']
/-- 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']
  

Proof state:
case intro.intro.intro
ι : 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 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:
apply add_mem
/-- 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
  · 

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 cn fun a b => b • u (Sum.inl a)) ∈ span R (range u)

Next tactic:
rw [Finsupp.mem_span_range_iff_exists_finsupp]