-- Mathlib/Algebra/Exact.lean
/-- When we have a commutative diagram from a sequence of two maps to another,
such that the left vertical map is surjective, the middle vertical map is bijective and the right
vertical map is injective, then the upper row is exact iff the lower row is.
See `ShortComplex.exact_iff_of_epi_of_isIso_of_mono` in the file
`Algebra.Homology.ShortComplex.Exact` for the categorical version of this result. -/
lemma exact_iff_of_surjective_of_bijective_of_injective
  {M₁ M₂ M₃ N₁ N₂ N₃ : Type*} [AddCommMonoid M₁] [AddCommMonoid M₂] [AddCommMonoid M₃]
  [AddCommMonoid N₁] [AddCommMonoid N₂] [AddCommMonoid N₃]
  (f : M₁ →+ M₂) (g : M₂ →+ M₃) (f' : N₁ →+ N₂) (g' : N₂ →+ N₃)
  (τ₁ : M₁ →+ N₁) (τ₂ : M₂ →+ N₂) (τ₃ : M₃ →+ N₃)
  (comm₁₂ : f'.comp τ₁ = τ₂.comp f)
  (comm₂₃ : g'.comp τ₂ = τ₃.comp g)
  (h₁ : Function.Surjective τ₁) (h₂ : Function.Bijective τ₂) (h₃ : Function.Injective τ₃) :
    Exact f g ↔ Exact f' g'

Proof state:
M₁ : Type u_8
M₂ : Type u_9
M₃ : Type u_10
N₁ : Type u_11
N₂ : Type u_12
N₃ : Type u_13
inst✝⁵ : AddCommMonoid M₁
inst✝⁴ : AddCommMonoid M₂
inst✝³ : AddCommMonoid M₃
inst✝² : AddCommMonoid N₁
inst✝¹ : AddCommMonoid N₂
inst✝ : AddCommMonoid N₃
f : M₁ →+ M₂
g : M₂ →+ M₃
f' : N₁ →+ N₂
g' : N₂ →+ N₃
τ₁ : M₁ →+ N₁
τ₂ : M₂ →+ N₂
τ₃ : M₃ →+ N₃
h₁ : Surjective ⇑τ₁
h₂ : Bijective ⇑τ₂
h₃ : Injective ⇑τ₃
comm₁₂ : ∀ (x : M₁), f' (τ₁ x) = τ₂ (f x)
comm₂₃ : ∀ (x : M₂), g' (τ₂ x) = τ₃ (g x)
⊢ Exact ⇑f ⇑g ↔ Exact ⇑f' ⇑g'

Tactic:
constructor

Result:
case mp
M₁ : Type u_8
M₂ : Type u_9
M₃ : Type u_10
N₁ : Type u_11
N₂ : Type u_12
N₃ : Type u_13
inst✝⁵ : AddCommMonoid M₁
inst✝⁴ : AddCommMonoid M₂
inst✝³ : AddCommMonoid M₃
inst✝² : AddCommMonoid N₁
inst✝¹ : AddCommMonoid N₂
inst✝ : AddCommMonoid N₃
f : M₁ →+ M₂
g : M₂ →+ M₃
f' : N₁ →+ N₂
g' : N₂ →+ N₃
τ₁ : M₁ →+ N₁
τ₂ : M₂ →+ N₂
τ₃ : M₃ →+ N₃
h₁ : Surjective ⇑τ₁
h₂ : Bijective ⇑τ₂
h₃ : Injective ⇑τ₃
comm₁₂ : ∀ (x : M₁), f' (τ₁ x) = τ₂ (f x)
comm₂₃ : ∀ (x : M₂), g' (τ₂ x) = τ₃ (g x)
⊢ Exact ⇑f ⇑g → Exact ⇑f' ⇑g'

case mpr
M₁ : Type u_8
M₂ : Type u_9
M₃ : Type u_10
N₁ : Type u_11
N₂ : Type u_12
N₃ : Type u_13
inst✝⁵ : AddCommMonoid M₁
inst✝⁴ : AddCommMonoid M₂
inst✝³ : AddCommMonoid M₃
inst✝² : AddCommMonoid N₁
inst✝¹ : AddCommMonoid N₂
inst✝ : AddCommMonoid N₃
f : M₁ →+ M₂
g : M₂ →+ M₃
f' : N₁ →+ N₂
g' : N₂ →+ N₃
τ₁ : M₁ →+ N₁
τ₂ : M₂ →+ N₂
τ₃ : M₃ →+ N₃
h₁ : Surjective ⇑τ₁
h₂ : Bijective ⇑τ₂
h₃ : Injective ⇑τ₃
comm₁₂ : ∀ (x : M₁), f' (τ₁ x) = τ₂ (f x)
comm₂₃ : ∀ (x : M₂), g' (τ₂ x) = τ₃ (g x)
⊢ Exact ⇑f' ⇑g' → Exact ⇑f ⇑g

Proof state:
M₁ : Type u_8
M₂ : Type u_9
M₃ : Type u_10
N₁ : Type u_11
N₂ : Type u_12
N₃ : Type u_13
inst✝⁵ : AddCommMonoid M₁
inst✝⁴ : AddCommMonoid M₂
inst✝³ : AddCommMonoid M₃
inst✝² : AddCommMonoid N₁
inst✝¹ : AddCommMonoid N₂
inst✝ : AddCommMonoid N₃
f : M₁ →+ M₂
g : M₂ →+ M₃
f' : N₁ →+ N₂
g' : N₂ →+ N₃
τ₁ : M₁ →+ N₁
τ₂ : M₂ →+ N₂
τ₃ : M₃ →+ N₃
h₁ : Surjective ⇑τ₁
h₂ : Bijective ⇑τ₂
h₃ : Injective ⇑τ₃
comm₁₂ : ∀ (x : M₁), f' (τ₁ x) = τ₂ (f x)
comm₂₃ : ∀ (x : M₂), g' (τ₂ x) = τ₃ (g x)
h : Exact ⇑f ⇑g
x₂ : M₂
x₁ : M₁
hy₁ : f' (τ₁ x₁) = τ₂ x₂
⊢ x₂ ∈ Set.range ⇑f

Tactic:
exact ⟨x₁, h₂.1 (by simpa only [comm₁₂] using hy₁)⟩

Result:
no goals

Proof state:
M₁ : Type u_8
M₂ : Type u_9
M₃ : Type u_10
N₁ : Type u_11
N₂ : Type u_12
N₃ : Type u_13
inst✝⁵ : AddCommMonoid M₁
inst✝⁴ : AddCommMonoid M₂
inst✝³ : AddCommMonoid M₃
inst✝² : AddCommMonoid N₁
inst✝¹ : AddCommMonoid N₂
inst✝ : AddCommMonoid N₃
f : M₁ →+ M₂
g : M₂ →+ M₃
f' : N₁ →+ N₂
g' : N₂ →+ N₃
τ₁ : M₁ →+ N₁
τ₂ : M₂ →+ N₂
τ₃ : M₃ →+ N₃
h₁ : Surjective ⇑τ₁
h₂ : Bijective ⇑τ₂
h₃ : Injective ⇑τ₃
comm₁₂ : ∀ (x : M₁), f' (τ₁ x) = τ₂ (f x)
comm₂₃ : ∀ (x : M₂), g' (τ₂ x) = τ₃ (g x)
h : Exact ⇑f ⇑g
x₁ : M₁
hx₂ : g' (τ₂ (f x₁)) = 0
⊢ f' (τ₁ x₁) = τ₂ (f x₁)

Tactic:
simp only [comm₁₂]

Result:
no goals

Proof state:
case mp.intro.mp.intro
M₁ : Type u_8
M₂ : Type u_9
M₃ : Type u_10
N₁ : Type u_11
N₂ : Type u_12
N₃ : Type u_13
inst✝⁵ : AddCommMonoid M₁
inst✝⁴ : AddCommMonoid M₂
inst✝³ : AddCommMonoid M₃
inst✝² : AddCommMonoid N₁
inst✝¹ : AddCommMonoid N₂
inst✝ : AddCommMonoid N₃
f : M₁ →+ M₂
g : M₂ →+ M₃
f' : N₁ →+ N₂
g' : N₂ →+ N₃
τ₁ : M₁ →+ N₁
τ₂ : M₂ →+ N₂
τ₃ : M₃ →+ N₃
h₁ : Surjective ⇑τ₁
h₂ : Bijective ⇑τ₂
h₃ : Injective ⇑τ₃
comm₁₂ : ∀ (x : M₁), f' (τ₁ x) = τ₂ (f x)
comm₂₃ : ∀ (x : M₂), g' (τ₂ x) = τ₃ (g x)
h : Exact ⇑f ⇑g
x₁ : M₁
hx₂ : g' (τ₂ (f x₁)) = 0
⊢ τ₂ (f x₁) ∈ Set.range ⇑f'

Tactic:
exact ⟨τ₁ x₁, by simp only [comm₁₂]⟩

Result:
no goals

Proof state:
case mpr.mpr
M₁ : Type u_8
M₂ : Type u_9
M₃ : Type u_10
N₁ : Type u_11
N₂ : Type u_12
N₃ : Type u_13
inst✝⁵ : AddCommMonoid M₁
inst✝⁴ : AddCommMonoid M₂
inst✝³ : AddCommMonoid M₃
inst✝² : AddCommMonoid N₁
inst✝¹ : AddCommMonoid N₂
inst✝ : AddCommMonoid N₃
f : M₁ →+ M₂
g : M₂ →+ M₃
f' : N₁ →+ N₂
g' : N₂ →+ N₃
τ₁ : M₁ →+ N₁
τ₂ : M₂ →+ N₂
τ₃ : M₃ →+ N₃
h₁ : Surjective ⇑τ₁
h₂ : Bijective ⇑τ₂
h₃ : Injective ⇑τ₃
comm₁₂ : ∀ (x : M₁), f' (τ₁ x) = τ₂ (f x)
comm₂₃ : ∀ (x : M₂), g' (τ₂ x) = τ₃ (g x)
h : Exact ⇑f' ⇑g'
x₂ : M₂
⊢ x₂ ∈ Set.range ⇑f → g x₂ = 0

Tactic:
rintro ⟨x₁, rfl⟩

Result:
case mpr.mpr.intro
M₁ : Type u_8
M₂ : Type u_9
M₃ : Type u_10
N₁ : Type u_11
N₂ : Type u_12
N₃ : Type u_13
inst✝⁵ : AddCommMonoid M₁
inst✝⁴ : AddCommMonoid M₂
inst✝³ : AddCommMonoid M₃
inst✝² : AddCommMonoid N₁
inst✝¹ : AddCommMonoid N₂
inst✝ : AddCommMonoid N₃
f : M₁ →+ M₂
g : M₂ →+ M₃
f' : N₁ →+ N₂
g' : N₂ →+ N₃
τ₁ : M₁ →+ N₁
τ₂ : M₂ →+ N₂
τ₃ : M₃ →+ N₃
h₁ : Surjective ⇑τ₁
h₂ : Bijective ⇑τ₂
h₃ : Injective ⇑τ₃
comm₁₂ : ∀ (x : M₁), f' (τ₁ x) = τ₂ (f x)
comm₂₃ : ∀ (x : M₂), g' (τ₂ x) = τ₃ (g x)
h : Exact ⇑f' ⇑g'
x₁ : M₁
⊢ g (f x₁) = 0

Proof state:
case mp.intro.mp
M₁ : Type u_8
M₂ : Type u_9
M₃ : Type u_10
N₁ : Type u_11
N₂ : Type u_12
N₃ : Type u_13
inst✝⁵ : AddCommMonoid M₁
inst✝⁴ : AddCommMonoid M₂
inst✝³ : AddCommMonoid M₃
inst✝² : AddCommMonoid N₁
inst✝¹ : AddCommMonoid N₂
inst✝ : AddCommMonoid N₃
f : M₁ →+ M₂
g : M₂ →+ M₃
f' : N₁ →+ N₂
g' : N₂ →+ N₃
τ₁ : M₁ →+ N₁
τ₂ : M₂ →+ N₂
τ₃ : M₃ →+ N₃
h₁ : Surjective ⇑τ₁
h₂ : Bijective ⇑τ₂
h₃ : Injective ⇑τ₃
comm₁₂ : ∀ (x : M₁), f' (τ₁ x) = τ₂ (f x)
comm₂₃ : ∀ (x : M₂), g' (τ₂ x) = τ₃ (g x)
h : Exact ⇑f ⇑g
x₂ : M₂
⊢ g' (τ₂ x₂) = 0 → τ₂ x₂ ∈ Set.range ⇑f'

Tactic:
intro hx₂

Result:
case mp.intro.mp
M₁ : Type u_8
M₂ : Type u_9
M₃ : Type u_10
N₁ : Type u_11
N₂ : Type u_12
N₃ : Type u_13
inst✝⁵ : AddCommMonoid M₁
inst✝⁴ : AddCommMonoid M₂
inst✝³ : AddCommMonoid M₃
inst✝² : AddCommMonoid N₁
inst✝¹ : AddCommMonoid N₂
inst✝ : AddCommMonoid N₃
f : M₁ →+ M₂
g : M₂ →+ M₃
f' : N₁ →+ N₂
g' : N₂ →+ N₃
τ₁ : M₁ →+ N₁
τ₂ : M₂ →+ N₂
τ₃ : M₃ →+ N₃
h₁ : Surjective ⇑τ₁
h₂ : Bijective ⇑τ₂
h₃ : Injective ⇑τ₃
comm₁₂ : ∀ (x : M₁), f' (τ₁ x) = τ₂ (f x)
comm₂₃ : ∀ (x : M₂), g' (τ₂ x) = τ₃ (g x)
h : Exact ⇑f ⇑g
x₂ : M₂
hx₂ : g' (τ₂ x₂) = 0
⊢ τ₂ x₂ ∈ Set.range ⇑f'