path stringlengths 11 71 | content stringlengths 75 124k |
|---|---|
Analysis\SpecialFunctions\Trigonometric\Angle.lean | /-
Copyright (c) 2019 Calle Sönne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Calle Sönne
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic
import Mathlib.Analysis.Normed.Group.AddCircle
import Mathlib.Algebra.CharZero.Quotient
import Mathlib.Topology.Instances.Sign
/-!
# The type of angles
In this file we define `Real.Angle` to be the quotient group `ℝ/2πℤ` and prove a few simple lemmas
about trigonometric functions and angles.
-/
open Real
noncomputable section
namespace Real
-- Porting note: can't derive `NormedAddCommGroup, Inhabited`
/-- The type of angles -/
def Angle : Type :=
AddCircle (2 * π)
namespace Angle
-- Porting note (#10754): added due to missing instances due to no deriving
instance : NormedAddCommGroup Angle :=
inferInstanceAs (NormedAddCommGroup (AddCircle (2 * π)))
-- Porting note (#10754): added due to missing instances due to no deriving
instance : Inhabited Angle :=
inferInstanceAs (Inhabited (AddCircle (2 * π)))
-- Porting note (#10754): added due to missing instances due to no deriving
-- also, without this, a plain `QuotientAddGroup.mk`
-- causes coerced terms to be of type `ℝ ⧸ AddSubgroup.zmultiples (2 * π)`
/-- The canonical map from `ℝ` to the quotient `Angle`. -/
@[coe]
protected def coe (r : ℝ) : Angle := QuotientAddGroup.mk r
instance : Coe ℝ Angle := ⟨Angle.coe⟩
instance : CircularOrder Real.Angle :=
QuotientAddGroup.circularOrder (hp' := ⟨by norm_num [pi_pos]⟩)
@[continuity]
theorem continuous_coe : Continuous ((↑) : ℝ → Angle) :=
continuous_quotient_mk'
/-- Coercion `ℝ → Angle` as an additive homomorphism. -/
def coeHom : ℝ →+ Angle :=
QuotientAddGroup.mk' _
@[simp]
theorem coe_coeHom : (coeHom : ℝ → Angle) = ((↑) : ℝ → Angle) :=
rfl
/-- An induction principle to deduce results for `Angle` from those for `ℝ`, used with
`induction θ using Real.Angle.induction_on`. -/
@[elab_as_elim]
protected theorem induction_on {p : Angle → Prop} (θ : Angle) (h : ∀ x : ℝ, p x) : p θ :=
Quotient.inductionOn' θ h
@[simp]
theorem coe_zero : ↑(0 : ℝ) = (0 : Angle) :=
rfl
@[simp]
theorem coe_add (x y : ℝ) : ↑(x + y : ℝ) = (↑x + ↑y : Angle) :=
rfl
@[simp]
theorem coe_neg (x : ℝ) : ↑(-x : ℝ) = -(↑x : Angle) :=
rfl
@[simp]
theorem coe_sub (x y : ℝ) : ↑(x - y : ℝ) = (↑x - ↑y : Angle) :=
rfl
theorem coe_nsmul (n : ℕ) (x : ℝ) : ↑(n • x : ℝ) = n • (↑x : Angle) :=
rfl
theorem coe_zsmul (z : ℤ) (x : ℝ) : ↑(z • x : ℝ) = z • (↑x : Angle) :=
rfl
@[simp, norm_cast]
theorem natCast_mul_eq_nsmul (x : ℝ) (n : ℕ) : ↑((n : ℝ) * x) = n • (↑x : Angle) := by
simpa only [nsmul_eq_mul] using coeHom.map_nsmul x n
@[simp, norm_cast]
theorem intCast_mul_eq_zsmul (x : ℝ) (n : ℤ) : ↑((n : ℝ) * x : ℝ) = n • (↑x : Angle) := by
simpa only [zsmul_eq_mul] using coeHom.map_zsmul x n
@[deprecated (since := "2024-05-25")] alias coe_nat_mul_eq_nsmul := natCast_mul_eq_nsmul
@[deprecated (since := "2024-05-25")] alias coe_int_mul_eq_zsmul := intCast_mul_eq_zsmul
theorem angle_eq_iff_two_pi_dvd_sub {ψ θ : ℝ} : (θ : Angle) = ψ ↔ ∃ k : ℤ, θ - ψ = 2 * π * k := by
simp only [QuotientAddGroup.eq, AddSubgroup.zmultiples_eq_closure,
AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm]
-- Porting note: added `rw`, `simp [Angle.coe, QuotientAddGroup.eq]` doesn't fire otherwise
rw [Angle.coe, Angle.coe, QuotientAddGroup.eq]
simp only [AddSubgroup.zmultiples_eq_closure,
AddSubgroup.mem_closure_singleton, zsmul_eq_mul', (sub_eq_neg_add _ _).symm, eq_comm]
@[simp]
theorem coe_two_pi : ↑(2 * π : ℝ) = (0 : Angle) :=
angle_eq_iff_two_pi_dvd_sub.2 ⟨1, by rw [sub_zero, Int.cast_one, mul_one]⟩
@[simp]
theorem neg_coe_pi : -(π : Angle) = π := by
rw [← coe_neg, angle_eq_iff_two_pi_dvd_sub]
use -1
simp [two_mul, sub_eq_add_neg]
@[simp]
theorem two_nsmul_coe_div_two (θ : ℝ) : (2 : ℕ) • (↑(θ / 2) : Angle) = θ := by
rw [← coe_nsmul, two_nsmul, add_halves]
@[simp]
theorem two_zsmul_coe_div_two (θ : ℝ) : (2 : ℤ) • (↑(θ / 2) : Angle) = θ := by
rw [← coe_zsmul, two_zsmul, add_halves]
-- Porting note (#10618): @[simp] can prove it
theorem two_nsmul_neg_pi_div_two : (2 : ℕ) • (↑(-π / 2) : Angle) = π := by
rw [two_nsmul_coe_div_two, coe_neg, neg_coe_pi]
-- Porting note (#10618): @[simp] can prove it
theorem two_zsmul_neg_pi_div_two : (2 : ℤ) • (↑(-π / 2) : Angle) = π := by
rw [two_zsmul, ← two_nsmul, two_nsmul_neg_pi_div_two]
theorem sub_coe_pi_eq_add_coe_pi (θ : Angle) : θ - π = θ + π := by
rw [sub_eq_add_neg, neg_coe_pi]
@[simp]
theorem two_nsmul_coe_pi : (2 : ℕ) • (π : Angle) = 0 := by simp [← natCast_mul_eq_nsmul]
@[simp]
theorem two_zsmul_coe_pi : (2 : ℤ) • (π : Angle) = 0 := by simp [← intCast_mul_eq_zsmul]
@[simp]
theorem coe_pi_add_coe_pi : (π : Real.Angle) + π = 0 := by rw [← two_nsmul, two_nsmul_coe_pi]
theorem zsmul_eq_iff {ψ θ : Angle} {z : ℤ} (hz : z ≠ 0) :
z • ψ = z • θ ↔ ∃ k : Fin z.natAbs, ψ = θ + (k : ℕ) • (2 * π / z : ℝ) :=
QuotientAddGroup.zmultiples_zsmul_eq_zsmul_iff hz
theorem nsmul_eq_iff {ψ θ : Angle} {n : ℕ} (hz : n ≠ 0) :
n • ψ = n • θ ↔ ∃ k : Fin n, ψ = θ + (k : ℕ) • (2 * π / n : ℝ) :=
QuotientAddGroup.zmultiples_nsmul_eq_nsmul_iff hz
theorem two_zsmul_eq_iff {ψ θ : Angle} : (2 : ℤ) • ψ = (2 : ℤ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by
have : Int.natAbs 2 = 2 := rfl
rw [zsmul_eq_iff two_ne_zero, this, Fin.exists_fin_two, Fin.val_zero,
Fin.val_one, zero_smul, add_zero, one_smul, Int.cast_two,
mul_div_cancel_left₀ (_ : ℝ) two_ne_zero]
theorem two_nsmul_eq_iff {ψ θ : Angle} : (2 : ℕ) • ψ = (2 : ℕ) • θ ↔ ψ = θ ∨ ψ = θ + ↑π := by
simp_rw [← natCast_zsmul, Nat.cast_ofNat, two_zsmul_eq_iff]
theorem two_nsmul_eq_zero_iff {θ : Angle} : (2 : ℕ) • θ = 0 ↔ θ = 0 ∨ θ = π := by
convert two_nsmul_eq_iff <;> simp
theorem two_nsmul_ne_zero_iff {θ : Angle} : (2 : ℕ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by
rw [← not_or, ← two_nsmul_eq_zero_iff]
theorem two_zsmul_eq_zero_iff {θ : Angle} : (2 : ℤ) • θ = 0 ↔ θ = 0 ∨ θ = π := by
simp_rw [two_zsmul, ← two_nsmul, two_nsmul_eq_zero_iff]
theorem two_zsmul_ne_zero_iff {θ : Angle} : (2 : ℤ) • θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by
rw [← not_or, ← two_zsmul_eq_zero_iff]
theorem eq_neg_self_iff {θ : Angle} : θ = -θ ↔ θ = 0 ∨ θ = π := by
rw [← add_eq_zero_iff_eq_neg, ← two_nsmul, two_nsmul_eq_zero_iff]
theorem ne_neg_self_iff {θ : Angle} : θ ≠ -θ ↔ θ ≠ 0 ∧ θ ≠ π := by
rw [← not_or, ← eq_neg_self_iff.not]
theorem neg_eq_self_iff {θ : Angle} : -θ = θ ↔ θ = 0 ∨ θ = π := by rw [eq_comm, eq_neg_self_iff]
theorem neg_ne_self_iff {θ : Angle} : -θ ≠ θ ↔ θ ≠ 0 ∧ θ ≠ π := by
rw [← not_or, ← neg_eq_self_iff.not]
theorem two_nsmul_eq_pi_iff {θ : Angle} : (2 : ℕ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by
have h : (π : Angle) = ((2 : ℕ) • (π / 2 : ℝ):) := by rw [two_nsmul, add_halves]
nth_rw 1 [h]
rw [coe_nsmul, two_nsmul_eq_iff]
-- Porting note: `congr` didn't simplify the goal of iff of `Or`s
convert Iff.rfl
rw [add_comm, ← coe_add, ← sub_eq_zero, ← coe_sub, neg_div, ← neg_sub, sub_neg_eq_add, add_assoc,
add_halves, ← two_mul, coe_neg, coe_two_pi, neg_zero]
theorem two_zsmul_eq_pi_iff {θ : Angle} : (2 : ℤ) • θ = π ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by
rw [two_zsmul, ← two_nsmul, two_nsmul_eq_pi_iff]
theorem cos_eq_iff_coe_eq_or_eq_neg {θ ψ : ℝ} :
cos θ = cos ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) = -ψ := by
constructor
· intro Hcos
rw [← sub_eq_zero, cos_sub_cos, mul_eq_zero, mul_eq_zero, neg_eq_zero,
eq_false (two_ne_zero' ℝ), false_or_iff, sin_eq_zero_iff, sin_eq_zero_iff] at Hcos
rcases Hcos with (⟨n, hn⟩ | ⟨n, hn⟩)
· right
rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), ← sub_eq_iff_eq_add] at hn
rw [← hn, coe_sub, eq_neg_iff_add_eq_zero, sub_add_cancel, mul_assoc, intCast_mul_eq_zsmul,
mul_comm, coe_two_pi, zsmul_zero]
· left
rw [eq_div_iff_mul_eq (two_ne_zero' ℝ), eq_sub_iff_add_eq] at hn
rw [← hn, coe_add, mul_assoc, intCast_mul_eq_zsmul, mul_comm, coe_two_pi, zsmul_zero,
zero_add]
· rw [angle_eq_iff_two_pi_dvd_sub, ← coe_neg, angle_eq_iff_two_pi_dvd_sub]
rintro (⟨k, H⟩ | ⟨k, H⟩)
· rw [← sub_eq_zero, cos_sub_cos, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ),
mul_comm π _, sin_int_mul_pi, mul_zero]
rw [← sub_eq_zero, cos_sub_cos, ← sub_neg_eq_add, H, mul_assoc 2 π k,
mul_div_cancel_left₀ _ (two_ne_zero' ℝ), mul_comm π _, sin_int_mul_pi, mul_zero,
zero_mul]
theorem sin_eq_iff_coe_eq_or_add_eq_pi {θ ψ : ℝ} :
sin θ = sin ψ ↔ (θ : Angle) = ψ ∨ (θ : Angle) + ψ = π := by
constructor
· intro Hsin
rw [← cos_pi_div_two_sub, ← cos_pi_div_two_sub] at Hsin
cases' cos_eq_iff_coe_eq_or_eq_neg.mp Hsin with h h
· left
rw [coe_sub, coe_sub] at h
exact sub_right_inj.1 h
right
rw [coe_sub, coe_sub, eq_neg_iff_add_eq_zero, add_sub, sub_add_eq_add_sub, ← coe_add,
add_halves, sub_sub, sub_eq_zero] at h
exact h.symm
· rw [angle_eq_iff_two_pi_dvd_sub, ← eq_sub_iff_add_eq, ← coe_sub, angle_eq_iff_two_pi_dvd_sub]
rintro (⟨k, H⟩ | ⟨k, H⟩)
· rw [← sub_eq_zero, sin_sub_sin, H, mul_assoc 2 π k, mul_div_cancel_left₀ _ (two_ne_zero' ℝ),
mul_comm π _, sin_int_mul_pi, mul_zero, zero_mul]
have H' : θ + ψ = 2 * k * π + π := by
rwa [← sub_add, sub_add_eq_add_sub, sub_eq_iff_eq_add, mul_assoc, mul_comm π _, ←
mul_assoc] at H
rw [← sub_eq_zero, sin_sub_sin, H', add_div, mul_assoc 2 _ π,
mul_div_cancel_left₀ _ (two_ne_zero' ℝ), cos_add_pi_div_two, sin_int_mul_pi, neg_zero,
mul_zero]
theorem cos_sin_inj {θ ψ : ℝ} (Hcos : cos θ = cos ψ) (Hsin : sin θ = sin ψ) : (θ : Angle) = ψ := by
cases' cos_eq_iff_coe_eq_or_eq_neg.mp Hcos with hc hc; · exact hc
cases' sin_eq_iff_coe_eq_or_add_eq_pi.mp Hsin with hs hs; · exact hs
rw [eq_neg_iff_add_eq_zero, hs] at hc
obtain ⟨n, hn⟩ : ∃ n, n • _ = _ := QuotientAddGroup.leftRel_apply.mp (Quotient.exact' hc)
rw [← neg_one_mul, add_zero, ← sub_eq_zero, zsmul_eq_mul, ← mul_assoc, ← sub_mul, mul_eq_zero,
eq_false (ne_of_gt pi_pos), or_false_iff, sub_neg_eq_add, ← Int.cast_zero, ← Int.cast_one,
← Int.cast_ofNat, ← Int.cast_mul, ← Int.cast_add, Int.cast_inj] at hn
have : (n * 2 + 1) % (2 : ℤ) = 0 % (2 : ℤ) := congr_arg (· % (2 : ℤ)) hn
rw [add_comm, Int.add_mul_emod_self] at this
exact absurd this one_ne_zero
/-- The sine of a `Real.Angle`. -/
def sin (θ : Angle) : ℝ :=
sin_periodic.lift θ
@[simp]
theorem sin_coe (x : ℝ) : sin (x : Angle) = Real.sin x :=
rfl
@[continuity]
theorem continuous_sin : Continuous sin :=
Real.continuous_sin.quotient_liftOn' _
/-- The cosine of a `Real.Angle`. -/
def cos (θ : Angle) : ℝ :=
cos_periodic.lift θ
@[simp]
theorem cos_coe (x : ℝ) : cos (x : Angle) = Real.cos x :=
rfl
@[continuity]
theorem continuous_cos : Continuous cos :=
Real.continuous_cos.quotient_liftOn' _
theorem cos_eq_real_cos_iff_eq_or_eq_neg {θ : Angle} {ψ : ℝ} :
cos θ = Real.cos ψ ↔ θ = ψ ∨ θ = -ψ := by
induction θ using Real.Angle.induction_on
exact cos_eq_iff_coe_eq_or_eq_neg
theorem cos_eq_iff_eq_or_eq_neg {θ ψ : Angle} : cos θ = cos ψ ↔ θ = ψ ∨ θ = -ψ := by
induction ψ using Real.Angle.induction_on
exact cos_eq_real_cos_iff_eq_or_eq_neg
theorem sin_eq_real_sin_iff_eq_or_add_eq_pi {θ : Angle} {ψ : ℝ} :
sin θ = Real.sin ψ ↔ θ = ψ ∨ θ + ψ = π := by
induction θ using Real.Angle.induction_on
exact sin_eq_iff_coe_eq_or_add_eq_pi
theorem sin_eq_iff_eq_or_add_eq_pi {θ ψ : Angle} : sin θ = sin ψ ↔ θ = ψ ∨ θ + ψ = π := by
induction ψ using Real.Angle.induction_on
exact sin_eq_real_sin_iff_eq_or_add_eq_pi
@[simp]
theorem sin_zero : sin (0 : Angle) = 0 := by rw [← coe_zero, sin_coe, Real.sin_zero]
-- Porting note (#10618): @[simp] can prove it
theorem sin_coe_pi : sin (π : Angle) = 0 := by rw [sin_coe, Real.sin_pi]
theorem sin_eq_zero_iff {θ : Angle} : sin θ = 0 ↔ θ = 0 ∨ θ = π := by
nth_rw 1 [← sin_zero]
rw [sin_eq_iff_eq_or_add_eq_pi]
simp
theorem sin_ne_zero_iff {θ : Angle} : sin θ ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by
rw [← not_or, ← sin_eq_zero_iff]
@[simp]
theorem sin_neg (θ : Angle) : sin (-θ) = -sin θ := by
induction θ using Real.Angle.induction_on
exact Real.sin_neg _
theorem sin_antiperiodic : Function.Antiperiodic sin (π : Angle) := by
intro θ
induction θ using Real.Angle.induction_on
exact Real.sin_antiperiodic _
@[simp]
theorem sin_add_pi (θ : Angle) : sin (θ + π) = -sin θ :=
sin_antiperiodic θ
@[simp]
theorem sin_sub_pi (θ : Angle) : sin (θ - π) = -sin θ :=
sin_antiperiodic.sub_eq θ
@[simp]
theorem cos_zero : cos (0 : Angle) = 1 := by rw [← coe_zero, cos_coe, Real.cos_zero]
-- Porting note (#10618): @[simp] can prove it
theorem cos_coe_pi : cos (π : Angle) = -1 := by rw [cos_coe, Real.cos_pi]
@[simp]
theorem cos_neg (θ : Angle) : cos (-θ) = cos θ := by
induction θ using Real.Angle.induction_on
exact Real.cos_neg _
theorem cos_antiperiodic : Function.Antiperiodic cos (π : Angle) := by
intro θ
induction θ using Real.Angle.induction_on
exact Real.cos_antiperiodic _
@[simp]
theorem cos_add_pi (θ : Angle) : cos (θ + π) = -cos θ :=
cos_antiperiodic θ
@[simp]
theorem cos_sub_pi (θ : Angle) : cos (θ - π) = -cos θ :=
cos_antiperiodic.sub_eq θ
theorem cos_eq_zero_iff {θ : Angle} : cos θ = 0 ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by
rw [← cos_pi_div_two, ← cos_coe, cos_eq_iff_eq_or_eq_neg, ← coe_neg, ← neg_div]
theorem sin_add (θ₁ θ₂ : Real.Angle) : sin (θ₁ + θ₂) = sin θ₁ * cos θ₂ + cos θ₁ * sin θ₂ := by
induction θ₁ using Real.Angle.induction_on
induction θ₂ using Real.Angle.induction_on
exact Real.sin_add _ _
theorem cos_add (θ₁ θ₂ : Real.Angle) : cos (θ₁ + θ₂) = cos θ₁ * cos θ₂ - sin θ₁ * sin θ₂ := by
induction θ₂ using Real.Angle.induction_on
induction θ₁ using Real.Angle.induction_on
exact Real.cos_add _ _
@[simp]
theorem cos_sq_add_sin_sq (θ : Real.Angle) : cos θ ^ 2 + sin θ ^ 2 = 1 := by
induction θ using Real.Angle.induction_on
exact Real.cos_sq_add_sin_sq _
theorem sin_add_pi_div_two (θ : Angle) : sin (θ + ↑(π / 2)) = cos θ := by
induction θ using Real.Angle.induction_on
exact Real.sin_add_pi_div_two _
theorem sin_sub_pi_div_two (θ : Angle) : sin (θ - ↑(π / 2)) = -cos θ := by
induction θ using Real.Angle.induction_on
exact Real.sin_sub_pi_div_two _
theorem sin_pi_div_two_sub (θ : Angle) : sin (↑(π / 2) - θ) = cos θ := by
induction θ using Real.Angle.induction_on
exact Real.sin_pi_div_two_sub _
theorem cos_add_pi_div_two (θ : Angle) : cos (θ + ↑(π / 2)) = -sin θ := by
induction θ using Real.Angle.induction_on
exact Real.cos_add_pi_div_two _
theorem cos_sub_pi_div_two (θ : Angle) : cos (θ - ↑(π / 2)) = sin θ := by
induction θ using Real.Angle.induction_on
exact Real.cos_sub_pi_div_two _
theorem cos_pi_div_two_sub (θ : Angle) : cos (↑(π / 2) - θ) = sin θ := by
induction θ using Real.Angle.induction_on
exact Real.cos_pi_div_two_sub _
theorem abs_sin_eq_of_two_nsmul_eq {θ ψ : Angle} (h : (2 : ℕ) • θ = (2 : ℕ) • ψ) :
|sin θ| = |sin ψ| := by
rw [two_nsmul_eq_iff] at h
rcases h with (rfl | rfl)
· rfl
· rw [sin_add_pi, abs_neg]
theorem abs_sin_eq_of_two_zsmul_eq {θ ψ : Angle} (h : (2 : ℤ) • θ = (2 : ℤ) • ψ) :
|sin θ| = |sin ψ| := by
simp_rw [two_zsmul, ← two_nsmul] at h
exact abs_sin_eq_of_two_nsmul_eq h
theorem abs_cos_eq_of_two_nsmul_eq {θ ψ : Angle} (h : (2 : ℕ) • θ = (2 : ℕ) • ψ) :
|cos θ| = |cos ψ| := by
rw [two_nsmul_eq_iff] at h
rcases h with (rfl | rfl)
· rfl
· rw [cos_add_pi, abs_neg]
theorem abs_cos_eq_of_two_zsmul_eq {θ ψ : Angle} (h : (2 : ℤ) • θ = (2 : ℤ) • ψ) :
|cos θ| = |cos ψ| := by
simp_rw [two_zsmul, ← two_nsmul] at h
exact abs_cos_eq_of_two_nsmul_eq h
@[simp]
theorem coe_toIcoMod (θ ψ : ℝ) : ↑(toIcoMod two_pi_pos ψ θ) = (θ : Angle) := by
rw [angle_eq_iff_two_pi_dvd_sub]
refine ⟨-toIcoDiv two_pi_pos ψ θ, ?_⟩
rw [toIcoMod_sub_self, zsmul_eq_mul, mul_comm]
@[simp]
theorem coe_toIocMod (θ ψ : ℝ) : ↑(toIocMod two_pi_pos ψ θ) = (θ : Angle) := by
rw [angle_eq_iff_two_pi_dvd_sub]
refine ⟨-toIocDiv two_pi_pos ψ θ, ?_⟩
rw [toIocMod_sub_self, zsmul_eq_mul, mul_comm]
/-- Convert a `Real.Angle` to a real number in the interval `Ioc (-π) π`. -/
def toReal (θ : Angle) : ℝ :=
(toIocMod_periodic two_pi_pos (-π)).lift θ
theorem toReal_coe (θ : ℝ) : (θ : Angle).toReal = toIocMod two_pi_pos (-π) θ :=
rfl
theorem toReal_coe_eq_self_iff {θ : ℝ} : (θ : Angle).toReal = θ ↔ -π < θ ∧ θ ≤ π := by
rw [toReal_coe, toIocMod_eq_self two_pi_pos]
ring_nf
rfl
theorem toReal_coe_eq_self_iff_mem_Ioc {θ : ℝ} : (θ : Angle).toReal = θ ↔ θ ∈ Set.Ioc (-π) π := by
rw [toReal_coe_eq_self_iff, ← Set.mem_Ioc]
theorem toReal_injective : Function.Injective toReal := by
intro θ ψ h
induction θ using Real.Angle.induction_on
induction ψ using Real.Angle.induction_on
simpa [toReal_coe, toIocMod_eq_toIocMod, zsmul_eq_mul, mul_comm _ (2 * π), ←
angle_eq_iff_two_pi_dvd_sub, eq_comm] using h
@[simp]
theorem toReal_inj {θ ψ : Angle} : θ.toReal = ψ.toReal ↔ θ = ψ :=
toReal_injective.eq_iff
@[simp]
theorem coe_toReal (θ : Angle) : (θ.toReal : Angle) = θ := by
induction θ using Real.Angle.induction_on
exact coe_toIocMod _ _
theorem neg_pi_lt_toReal (θ : Angle) : -π < θ.toReal := by
induction θ using Real.Angle.induction_on
exact left_lt_toIocMod _ _ _
theorem toReal_le_pi (θ : Angle) : θ.toReal ≤ π := by
induction θ using Real.Angle.induction_on
convert toIocMod_le_right two_pi_pos _ _
ring
theorem abs_toReal_le_pi (θ : Angle) : |θ.toReal| ≤ π :=
abs_le.2 ⟨(neg_pi_lt_toReal _).le, toReal_le_pi _⟩
theorem toReal_mem_Ioc (θ : Angle) : θ.toReal ∈ Set.Ioc (-π) π :=
⟨neg_pi_lt_toReal _, toReal_le_pi _⟩
@[simp]
theorem toIocMod_toReal (θ : Angle) : toIocMod two_pi_pos (-π) θ.toReal = θ.toReal := by
induction θ using Real.Angle.induction_on
rw [toReal_coe]
exact toIocMod_toIocMod _ _ _ _
@[simp]
theorem toReal_zero : (0 : Angle).toReal = 0 := by
rw [← coe_zero, toReal_coe_eq_self_iff]
exact ⟨Left.neg_neg_iff.2 Real.pi_pos, Real.pi_pos.le⟩
@[simp]
theorem toReal_eq_zero_iff {θ : Angle} : θ.toReal = 0 ↔ θ = 0 := by
nth_rw 1 [← toReal_zero]
exact toReal_inj
@[simp]
theorem toReal_pi : (π : Angle).toReal = π := by
rw [toReal_coe_eq_self_iff]
exact ⟨Left.neg_lt_self Real.pi_pos, le_refl _⟩
@[simp]
theorem toReal_eq_pi_iff {θ : Angle} : θ.toReal = π ↔ θ = π := by rw [← toReal_inj, toReal_pi]
theorem pi_ne_zero : (π : Angle) ≠ 0 := by
rw [← toReal_injective.ne_iff, toReal_pi, toReal_zero]
exact Real.pi_ne_zero
@[simp]
theorem toReal_pi_div_two : ((π / 2 : ℝ) : Angle).toReal = π / 2 :=
toReal_coe_eq_self_iff.2 <| by constructor <;> linarith [pi_pos]
@[simp]
theorem toReal_eq_pi_div_two_iff {θ : Angle} : θ.toReal = π / 2 ↔ θ = (π / 2 : ℝ) := by
rw [← toReal_inj, toReal_pi_div_two]
@[simp]
theorem toReal_neg_pi_div_two : ((-π / 2 : ℝ) : Angle).toReal = -π / 2 :=
toReal_coe_eq_self_iff.2 <| by constructor <;> linarith [pi_pos]
@[simp]
theorem toReal_eq_neg_pi_div_two_iff {θ : Angle} : θ.toReal = -π / 2 ↔ θ = (-π / 2 : ℝ) := by
rw [← toReal_inj, toReal_neg_pi_div_two]
theorem pi_div_two_ne_zero : ((π / 2 : ℝ) : Angle) ≠ 0 := by
rw [← toReal_injective.ne_iff, toReal_pi_div_two, toReal_zero]
exact div_ne_zero Real.pi_ne_zero two_ne_zero
theorem neg_pi_div_two_ne_zero : ((-π / 2 : ℝ) : Angle) ≠ 0 := by
rw [← toReal_injective.ne_iff, toReal_neg_pi_div_two, toReal_zero]
exact div_ne_zero (neg_ne_zero.2 Real.pi_ne_zero) two_ne_zero
theorem abs_toReal_coe_eq_self_iff {θ : ℝ} : |(θ : Angle).toReal| = θ ↔ 0 ≤ θ ∧ θ ≤ π :=
⟨fun h => h ▸ ⟨abs_nonneg _, abs_toReal_le_pi _⟩, fun h =>
(toReal_coe_eq_self_iff.2 ⟨(Left.neg_neg_iff.2 Real.pi_pos).trans_le h.1, h.2⟩).symm ▸
abs_eq_self.2 h.1⟩
theorem abs_toReal_neg_coe_eq_self_iff {θ : ℝ} : |(-θ : Angle).toReal| = θ ↔ 0 ≤ θ ∧ θ ≤ π := by
refine ⟨fun h => h ▸ ⟨abs_nonneg _, abs_toReal_le_pi _⟩, fun h => ?_⟩
by_cases hnegpi : θ = π; · simp [hnegpi, Real.pi_pos.le]
rw [← coe_neg,
toReal_coe_eq_self_iff.2
⟨neg_lt_neg (lt_of_le_of_ne h.2 hnegpi), (neg_nonpos.2 h.1).trans Real.pi_pos.le⟩,
abs_neg, abs_eq_self.2 h.1]
theorem abs_toReal_eq_pi_div_two_iff {θ : Angle} :
|θ.toReal| = π / 2 ↔ θ = (π / 2 : ℝ) ∨ θ = (-π / 2 : ℝ) := by
rw [abs_eq (div_nonneg Real.pi_pos.le two_pos.le), ← neg_div, toReal_eq_pi_div_two_iff,
toReal_eq_neg_pi_div_two_iff]
theorem nsmul_toReal_eq_mul {n : ℕ} (h : n ≠ 0) {θ : Angle} :
(n • θ).toReal = n * θ.toReal ↔ θ.toReal ∈ Set.Ioc (-π / n) (π / n) := by
nth_rw 1 [← coe_toReal θ]
have h' : 0 < (n : ℝ) := mod_cast Nat.pos_of_ne_zero h
rw [← coe_nsmul, nsmul_eq_mul, toReal_coe_eq_self_iff, Set.mem_Ioc, div_lt_iff' h',
le_div_iff' h']
theorem two_nsmul_toReal_eq_two_mul {θ : Angle} :
((2 : ℕ) • θ).toReal = 2 * θ.toReal ↔ θ.toReal ∈ Set.Ioc (-π / 2) (π / 2) :=
mod_cast nsmul_toReal_eq_mul two_ne_zero
theorem two_zsmul_toReal_eq_two_mul {θ : Angle} :
((2 : ℤ) • θ).toReal = 2 * θ.toReal ↔ θ.toReal ∈ Set.Ioc (-π / 2) (π / 2) := by
rw [two_zsmul, ← two_nsmul, two_nsmul_toReal_eq_two_mul]
theorem toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff {θ : ℝ} {k : ℤ} :
(θ : Angle).toReal = θ - 2 * k * π ↔ θ ∈ Set.Ioc ((2 * k - 1 : ℝ) * π) ((2 * k + 1) * π) := by
rw [← sub_zero (θ : Angle), ← zsmul_zero k, ← coe_two_pi, ← coe_zsmul, ← coe_sub, zsmul_eq_mul, ←
mul_assoc, mul_comm (k : ℝ), toReal_coe_eq_self_iff, Set.mem_Ioc]
exact ⟨fun h => ⟨by linarith, by linarith⟩, fun h => ⟨by linarith, by linarith⟩⟩
theorem toReal_coe_eq_self_sub_two_pi_iff {θ : ℝ} :
(θ : Angle).toReal = θ - 2 * π ↔ θ ∈ Set.Ioc π (3 * π) := by
convert @toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff θ 1 <;> norm_num
theorem toReal_coe_eq_self_add_two_pi_iff {θ : ℝ} :
(θ : Angle).toReal = θ + 2 * π ↔ θ ∈ Set.Ioc (-3 * π) (-π) := by
convert @toReal_coe_eq_self_sub_two_mul_int_mul_pi_iff θ (-1) using 2 <;> norm_num
theorem two_nsmul_toReal_eq_two_mul_sub_two_pi {θ : Angle} :
((2 : ℕ) • θ).toReal = 2 * θ.toReal - 2 * π ↔ π / 2 < θ.toReal := by
nth_rw 1 [← coe_toReal θ]
rw [← coe_nsmul, two_nsmul, ← two_mul, toReal_coe_eq_self_sub_two_pi_iff, Set.mem_Ioc]
exact
⟨fun h => by linarith, fun h =>
⟨(div_lt_iff' (zero_lt_two' ℝ)).1 h, by linarith [pi_pos, toReal_le_pi θ]⟩⟩
theorem two_zsmul_toReal_eq_two_mul_sub_two_pi {θ : Angle} :
((2 : ℤ) • θ).toReal = 2 * θ.toReal - 2 * π ↔ π / 2 < θ.toReal := by
rw [two_zsmul, ← two_nsmul, two_nsmul_toReal_eq_two_mul_sub_two_pi]
theorem two_nsmul_toReal_eq_two_mul_add_two_pi {θ : Angle} :
((2 : ℕ) • θ).toReal = 2 * θ.toReal + 2 * π ↔ θ.toReal ≤ -π / 2 := by
nth_rw 1 [← coe_toReal θ]
rw [← coe_nsmul, two_nsmul, ← two_mul, toReal_coe_eq_self_add_two_pi_iff, Set.mem_Ioc]
refine
⟨fun h => by linarith, fun h =>
⟨by linarith [pi_pos, neg_pi_lt_toReal θ], (le_div_iff' (zero_lt_two' ℝ)).1 h⟩⟩
theorem two_zsmul_toReal_eq_two_mul_add_two_pi {θ : Angle} :
((2 : ℤ) • θ).toReal = 2 * θ.toReal + 2 * π ↔ θ.toReal ≤ -π / 2 := by
rw [two_zsmul, ← two_nsmul, two_nsmul_toReal_eq_two_mul_add_two_pi]
@[simp]
theorem sin_toReal (θ : Angle) : Real.sin θ.toReal = sin θ := by
conv_rhs => rw [← coe_toReal θ, sin_coe]
@[simp]
theorem cos_toReal (θ : Angle) : Real.cos θ.toReal = cos θ := by
conv_rhs => rw [← coe_toReal θ, cos_coe]
theorem cos_nonneg_iff_abs_toReal_le_pi_div_two {θ : Angle} : 0 ≤ cos θ ↔ |θ.toReal| ≤ π / 2 := by
nth_rw 1 [← coe_toReal θ]
rw [abs_le, cos_coe]
refine ⟨fun h => ?_, cos_nonneg_of_mem_Icc⟩
by_contra hn
rw [not_and_or, not_le, not_le] at hn
refine (not_lt.2 h) ?_
rcases hn with (hn | hn)
· rw [← Real.cos_neg]
refine cos_neg_of_pi_div_two_lt_of_lt (by linarith) ?_
linarith [neg_pi_lt_toReal θ]
· refine cos_neg_of_pi_div_two_lt_of_lt hn ?_
linarith [toReal_le_pi θ]
theorem cos_pos_iff_abs_toReal_lt_pi_div_two {θ : Angle} : 0 < cos θ ↔ |θ.toReal| < π / 2 := by
rw [lt_iff_le_and_ne, lt_iff_le_and_ne, cos_nonneg_iff_abs_toReal_le_pi_div_two, ←
and_congr_right]
rintro -
rw [Ne, Ne, not_iff_not, @eq_comm ℝ 0, abs_toReal_eq_pi_div_two_iff, cos_eq_zero_iff]
theorem cos_neg_iff_pi_div_two_lt_abs_toReal {θ : Angle} : cos θ < 0 ↔ π / 2 < |θ.toReal| := by
rw [← not_le, ← not_le, not_iff_not, cos_nonneg_iff_abs_toReal_le_pi_div_two]
theorem abs_cos_eq_abs_sin_of_two_nsmul_add_two_nsmul_eq_pi {θ ψ : Angle}
(h : (2 : ℕ) • θ + (2 : ℕ) • ψ = π) : |cos θ| = |sin ψ| := by
rw [← eq_sub_iff_add_eq, ← two_nsmul_coe_div_two, ← nsmul_sub, two_nsmul_eq_iff] at h
rcases h with (rfl | rfl) <;> simp [cos_pi_div_two_sub]
theorem abs_cos_eq_abs_sin_of_two_zsmul_add_two_zsmul_eq_pi {θ ψ : Angle}
(h : (2 : ℤ) • θ + (2 : ℤ) • ψ = π) : |cos θ| = |sin ψ| := by
simp_rw [two_zsmul, ← two_nsmul] at h
exact abs_cos_eq_abs_sin_of_two_nsmul_add_two_nsmul_eq_pi h
/-- The tangent of a `Real.Angle`. -/
def tan (θ : Angle) : ℝ :=
sin θ / cos θ
theorem tan_eq_sin_div_cos (θ : Angle) : tan θ = sin θ / cos θ :=
rfl
@[simp]
theorem tan_coe (x : ℝ) : tan (x : Angle) = Real.tan x := by
rw [tan, sin_coe, cos_coe, Real.tan_eq_sin_div_cos]
@[simp]
theorem tan_zero : tan (0 : Angle) = 0 := by rw [← coe_zero, tan_coe, Real.tan_zero]
-- Porting note (#10618): @[simp] can now prove it
theorem tan_coe_pi : tan (π : Angle) = 0 := by rw [tan_coe, Real.tan_pi]
theorem tan_periodic : Function.Periodic tan (π : Angle) := by
intro θ
induction θ using Real.Angle.induction_on
rw [← coe_add, tan_coe, tan_coe]
exact Real.tan_periodic _
@[simp]
theorem tan_add_pi (θ : Angle) : tan (θ + π) = tan θ :=
tan_periodic θ
@[simp]
theorem tan_sub_pi (θ : Angle) : tan (θ - π) = tan θ :=
tan_periodic.sub_eq θ
@[simp]
theorem tan_toReal (θ : Angle) : Real.tan θ.toReal = tan θ := by
conv_rhs => rw [← coe_toReal θ, tan_coe]
theorem tan_eq_of_two_nsmul_eq {θ ψ : Angle} (h : (2 : ℕ) • θ = (2 : ℕ) • ψ) : tan θ = tan ψ := by
rw [two_nsmul_eq_iff] at h
rcases h with (rfl | rfl)
· rfl
· exact tan_add_pi _
theorem tan_eq_of_two_zsmul_eq {θ ψ : Angle} (h : (2 : ℤ) • θ = (2 : ℤ) • ψ) : tan θ = tan ψ := by
simp_rw [two_zsmul, ← two_nsmul] at h
exact tan_eq_of_two_nsmul_eq h
theorem tan_eq_inv_of_two_nsmul_add_two_nsmul_eq_pi {θ ψ : Angle}
(h : (2 : ℕ) • θ + (2 : ℕ) • ψ = π) : tan ψ = (tan θ)⁻¹ := by
induction θ using Real.Angle.induction_on
induction ψ using Real.Angle.induction_on
rw [← smul_add, ← coe_add, ← coe_nsmul, two_nsmul, ← two_mul, angle_eq_iff_two_pi_dvd_sub] at h
rcases h with ⟨k, h⟩
rw [sub_eq_iff_eq_add, ← mul_inv_cancel_left₀ two_ne_zero π, mul_assoc, ← mul_add,
mul_right_inj' (two_ne_zero' ℝ), ← eq_sub_iff_add_eq', mul_inv_cancel_left₀ two_ne_zero π,
inv_mul_eq_div, mul_comm] at h
rw [tan_coe, tan_coe, ← tan_pi_div_two_sub, h, add_sub_assoc, add_comm]
exact Real.tan_periodic.int_mul _ _
theorem tan_eq_inv_of_two_zsmul_add_two_zsmul_eq_pi {θ ψ : Angle}
(h : (2 : ℤ) • θ + (2 : ℤ) • ψ = π) : tan ψ = (tan θ)⁻¹ := by
simp_rw [two_zsmul, ← two_nsmul] at h
exact tan_eq_inv_of_two_nsmul_add_two_nsmul_eq_pi h
/-- The sign of a `Real.Angle` is `0` if the angle is `0` or `π`, `1` if the angle is strictly
between `0` and `π` and `-1` is the angle is strictly between `-π` and `0`. It is defined as the
sign of the sine of the angle. -/
def sign (θ : Angle) : SignType :=
SignType.sign (sin θ)
@[simp]
theorem sign_zero : (0 : Angle).sign = 0 := by
rw [sign, sin_zero, _root_.sign_zero]
@[simp]
theorem sign_coe_pi : (π : Angle).sign = 0 := by rw [sign, sin_coe_pi, _root_.sign_zero]
@[simp]
theorem sign_neg (θ : Angle) : (-θ).sign = -θ.sign := by
simp_rw [sign, sin_neg, Left.sign_neg]
theorem sign_antiperiodic : Function.Antiperiodic sign (π : Angle) := fun θ => by
rw [sign, sign, sin_add_pi, Left.sign_neg]
@[simp]
theorem sign_add_pi (θ : Angle) : (θ + π).sign = -θ.sign :=
sign_antiperiodic θ
@[simp]
theorem sign_pi_add (θ : Angle) : ((π : Angle) + θ).sign = -θ.sign := by rw [add_comm, sign_add_pi]
@[simp]
theorem sign_sub_pi (θ : Angle) : (θ - π).sign = -θ.sign :=
sign_antiperiodic.sub_eq θ
@[simp]
theorem sign_pi_sub (θ : Angle) : ((π : Angle) - θ).sign = θ.sign := by
simp [sign_antiperiodic.sub_eq']
theorem sign_eq_zero_iff {θ : Angle} : θ.sign = 0 ↔ θ = 0 ∨ θ = π := by
rw [sign, _root_.sign_eq_zero_iff, sin_eq_zero_iff]
theorem sign_ne_zero_iff {θ : Angle} : θ.sign ≠ 0 ↔ θ ≠ 0 ∧ θ ≠ π := by
rw [← not_or, ← sign_eq_zero_iff]
theorem toReal_neg_iff_sign_neg {θ : Angle} : θ.toReal < 0 ↔ θ.sign = -1 := by
rw [sign, ← sin_toReal, sign_eq_neg_one_iff]
rcases lt_trichotomy θ.toReal 0 with (h | h | h)
· exact ⟨fun _ => Real.sin_neg_of_neg_of_neg_pi_lt h (neg_pi_lt_toReal θ), fun _ => h⟩
· simp [h]
· exact
⟨fun hn => False.elim (h.asymm hn), fun hn =>
False.elim (hn.not_le (sin_nonneg_of_nonneg_of_le_pi h.le (toReal_le_pi θ)))⟩
theorem toReal_nonneg_iff_sign_nonneg {θ : Angle} : 0 ≤ θ.toReal ↔ 0 ≤ θ.sign := by
rcases lt_trichotomy θ.toReal 0 with (h | h | h)
· refine ⟨fun hn => False.elim (h.not_le hn), fun hn => ?_⟩
rw [toReal_neg_iff_sign_neg.1 h] at hn
exact False.elim (hn.not_lt (by decide))
· simp [h, sign, ← sin_toReal]
· refine ⟨fun _ => ?_, fun _ => h.le⟩
rw [sign, ← sin_toReal, sign_nonneg_iff]
exact sin_nonneg_of_nonneg_of_le_pi h.le (toReal_le_pi θ)
@[simp]
theorem sign_toReal {θ : Angle} (h : θ ≠ π) : SignType.sign θ.toReal = θ.sign := by
rcases lt_trichotomy θ.toReal 0 with (ht | ht | ht)
· simp [ht, toReal_neg_iff_sign_neg.1 ht]
· simp [sign, ht, ← sin_toReal]
· rw [sign, ← sin_toReal, sign_pos ht,
sign_pos
(sin_pos_of_pos_of_lt_pi ht ((toReal_le_pi θ).lt_of_ne (toReal_eq_pi_iff.not.2 h)))]
theorem coe_abs_toReal_of_sign_nonneg {θ : Angle} (h : 0 ≤ θ.sign) : ↑|θ.toReal| = θ := by
rw [abs_eq_self.2 (toReal_nonneg_iff_sign_nonneg.2 h), coe_toReal]
theorem neg_coe_abs_toReal_of_sign_nonpos {θ : Angle} (h : θ.sign ≤ 0) : -↑|θ.toReal| = θ := by
rw [SignType.nonpos_iff] at h
rcases h with (h | h)
· rw [abs_of_neg (toReal_neg_iff_sign_neg.2 h), coe_neg, neg_neg, coe_toReal]
· rw [sign_eq_zero_iff] at h
rcases h with (rfl | rfl) <;> simp [abs_of_pos Real.pi_pos]
theorem eq_iff_sign_eq_and_abs_toReal_eq {θ ψ : Angle} :
θ = ψ ↔ θ.sign = ψ.sign ∧ |θ.toReal| = |ψ.toReal| := by
refine ⟨?_, fun h => ?_⟩
· rintro rfl
exact ⟨rfl, rfl⟩
rcases h with ⟨hs, hr⟩
rw [abs_eq_abs] at hr
rcases hr with (hr | hr)
· exact toReal_injective hr
· by_cases h : θ = π
· rw [h, toReal_pi, ← neg_eq_iff_eq_neg] at hr
exact False.elim ((neg_pi_lt_toReal ψ).ne hr)
· by_cases h' : ψ = π
· rw [h', toReal_pi] at hr
exact False.elim ((neg_pi_lt_toReal θ).ne hr.symm)
· rw [← sign_toReal h, ← sign_toReal h', hr, Left.sign_neg, SignType.neg_eq_self_iff,
_root_.sign_eq_zero_iff, toReal_eq_zero_iff] at hs
rw [hs, toReal_zero, neg_zero, toReal_eq_zero_iff] at hr
rw [hr, hs]
theorem eq_iff_abs_toReal_eq_of_sign_eq {θ ψ : Angle} (h : θ.sign = ψ.sign) :
θ = ψ ↔ |θ.toReal| = |ψ.toReal| := by simpa [h] using @eq_iff_sign_eq_and_abs_toReal_eq θ ψ
@[simp]
theorem sign_coe_pi_div_two : (↑(π / 2) : Angle).sign = 1 := by
rw [sign, sin_coe, sin_pi_div_two, sign_one]
@[simp]
theorem sign_coe_neg_pi_div_two : (↑(-π / 2) : Angle).sign = -1 := by
rw [sign, sin_coe, neg_div, Real.sin_neg, sin_pi_div_two, Left.sign_neg, sign_one]
theorem sign_coe_nonneg_of_nonneg_of_le_pi {θ : ℝ} (h0 : 0 ≤ θ) (hpi : θ ≤ π) :
0 ≤ (θ : Angle).sign := by
rw [sign, sign_nonneg_iff]
exact sin_nonneg_of_nonneg_of_le_pi h0 hpi
theorem sign_neg_coe_nonpos_of_nonneg_of_le_pi {θ : ℝ} (h0 : 0 ≤ θ) (hpi : θ ≤ π) :
(-θ : Angle).sign ≤ 0 := by
rw [sign, sign_nonpos_iff, sin_neg, Left.neg_nonpos_iff]
exact sin_nonneg_of_nonneg_of_le_pi h0 hpi
theorem sign_two_nsmul_eq_sign_iff {θ : Angle} :
((2 : ℕ) • θ).sign = θ.sign ↔ θ = π ∨ |θ.toReal| < π / 2 := by
by_cases hpi : θ = π; · simp [hpi]
rw [or_iff_right hpi]
refine ⟨fun h => ?_, fun h => ?_⟩
· by_contra hle
rw [not_lt, le_abs, le_neg] at hle
have hpi' : θ.toReal ≠ π := by simpa using hpi
rcases hle with (hle | hle) <;> rcases hle.eq_or_lt with (heq | hlt)
· rw [← coe_toReal θ, ← heq] at h
simp at h
· rw [← sign_toReal hpi, sign_pos (pi_div_two_pos.trans hlt), ← sign_toReal,
two_nsmul_toReal_eq_two_mul_sub_two_pi.2 hlt, _root_.sign_neg] at h
· simp at h
· rw [← mul_sub]
exact mul_neg_of_pos_of_neg two_pos (sub_neg.2 ((toReal_le_pi _).lt_of_ne hpi'))
· intro he
simp [he] at h
· rw [← coe_toReal θ, heq] at h
simp at h
· rw [← sign_toReal hpi, _root_.sign_neg (hlt.trans (Left.neg_neg_iff.2 pi_div_two_pos)), ←
sign_toReal] at h
swap
· intro he
simp [he] at h
rw [← neg_div] at hlt
rw [two_nsmul_toReal_eq_two_mul_add_two_pi.2 hlt.le, sign_pos] at h
· simp at h
· linarith [neg_pi_lt_toReal θ]
· have hpi' : (2 : ℕ) • θ ≠ π := by
rw [Ne, two_nsmul_eq_pi_iff, not_or]
constructor
· rintro rfl
simp [pi_pos, div_pos, abs_of_pos] at h
· rintro rfl
rw [toReal_neg_pi_div_two] at h
simp [pi_pos, div_pos, neg_div, abs_of_pos] at h
rw [abs_lt, ← neg_div] at h
rw [← sign_toReal hpi, ← sign_toReal hpi', two_nsmul_toReal_eq_two_mul.2 ⟨h.1, h.2.le⟩,
sign_mul, sign_pos (zero_lt_two' ℝ), one_mul]
theorem sign_two_zsmul_eq_sign_iff {θ : Angle} :
((2 : ℤ) • θ).sign = θ.sign ↔ θ = π ∨ |θ.toReal| < π / 2 := by
rw [two_zsmul, ← two_nsmul, sign_two_nsmul_eq_sign_iff]
theorem continuousAt_sign {θ : Angle} (h0 : θ ≠ 0) (hpi : θ ≠ π) : ContinuousAt sign θ :=
(continuousAt_sign_of_ne_zero (sin_ne_zero_iff.2 ⟨h0, hpi⟩)).comp continuous_sin.continuousAt
theorem _root_.ContinuousOn.angle_sign_comp {α : Type*} [TopologicalSpace α] {f : α → Angle}
{s : Set α} (hf : ContinuousOn f s) (hs : ∀ z ∈ s, f z ≠ 0 ∧ f z ≠ π) :
ContinuousOn (sign ∘ f) s := by
refine (ContinuousAt.continuousOn fun θ hθ => ?_).comp hf (Set.mapsTo_image f s)
obtain ⟨z, hz, rfl⟩ := hθ
exact continuousAt_sign (hs _ hz).1 (hs _ hz).2
/-- Suppose a function to angles is continuous on a connected set and never takes the values `0`
or `π` on that set. Then the values of the function on that set all have the same sign. -/
theorem sign_eq_of_continuousOn {α : Type*} [TopologicalSpace α] {f : α → Angle} {s : Set α}
{x y : α} (hc : IsConnected s) (hf : ContinuousOn f s) (hs : ∀ z ∈ s, f z ≠ 0 ∧ f z ≠ π)
(hx : x ∈ s) (hy : y ∈ s) : (f y).sign = (f x).sign :=
(hc.image _ (hf.angle_sign_comp hs)).isPreconnected.subsingleton (Set.mem_image_of_mem _ hy)
(Set.mem_image_of_mem _ hx)
end Angle
end Real
|
Analysis\SpecialFunctions\Trigonometric\Arctan.lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Complex
/-!
# The `arctan` function.
Inequalities, identities and `Real.tan` as a `PartialHomeomorph` between `(-(π / 2), π / 2)`
and the whole line.
The result of `arctan x + arctan y` is given by `arctan_add`, `arctan_add_eq_add_pi` or
`arctan_add_eq_sub_pi` depending on whether `x * y < 1` and `0 < x`. As an application of
`arctan_add` we give four Machin-like formulas (linear combinations of arctangents equal to
`π / 4 = arctan 1`), including John Machin's original one at
`four_mul_arctan_inv_5_sub_arctan_inv_239`.
-/
noncomputable section
namespace Real
open Set Filter
open scoped Topology Real
theorem tan_add {x y : ℝ}
(h : ((∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y ≠ (2 * l + 1) * π / 2) ∨
(∃ k : ℤ, x = (2 * k + 1) * π / 2) ∧ ∃ l : ℤ, y = (2 * l + 1) * π / 2) :
tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) := by
simpa only [← Complex.ofReal_inj, Complex.ofReal_sub, Complex.ofReal_add, Complex.ofReal_div,
Complex.ofReal_mul, Complex.ofReal_tan] using
@Complex.tan_add (x : ℂ) (y : ℂ) (by convert h <;> norm_cast)
theorem tan_add' {x y : ℝ}
(h : (∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y ≠ (2 * l + 1) * π / 2) :
tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) :=
tan_add (Or.inl h)
theorem tan_two_mul {x : ℝ} : tan (2 * x) = 2 * tan x / (1 - tan x ^ 2) := by
have := @Complex.tan_two_mul x
norm_cast at *
theorem tan_int_mul_pi_div_two (n : ℤ) : tan (n * π / 2) = 0 :=
tan_eq_zero_iff.mpr (by use n)
theorem continuousOn_tan : ContinuousOn tan {x | cos x ≠ 0} := by
suffices ContinuousOn (fun x => sin x / cos x) {x | cos x ≠ 0} by
have h_eq : (fun x => sin x / cos x) = tan := by ext1 x; rw [tan_eq_sin_div_cos]
rwa [h_eq] at this
exact continuousOn_sin.div continuousOn_cos fun x => id
@[continuity]
theorem continuous_tan : Continuous fun x : {x | cos x ≠ 0} => tan x :=
continuousOn_iff_continuous_restrict.1 continuousOn_tan
theorem continuousOn_tan_Ioo : ContinuousOn tan (Ioo (-(π / 2)) (π / 2)) := by
refine ContinuousOn.mono continuousOn_tan fun x => ?_
simp only [and_imp, mem_Ioo, mem_setOf_eq, Ne]
rw [cos_eq_zero_iff]
rintro hx_gt hx_lt ⟨r, hxr_eq⟩
rcases le_or_lt 0 r with h | h
· rw [lt_iff_not_ge] at hx_lt
refine hx_lt ?_
rw [hxr_eq, ← one_mul (π / 2), mul_div_assoc, ge_iff_le, mul_le_mul_right (half_pos pi_pos)]
simp [h]
· rw [lt_iff_not_ge] at hx_gt
refine hx_gt ?_
rw [hxr_eq, ← one_mul (π / 2), mul_div_assoc, ge_iff_le, neg_mul_eq_neg_mul,
mul_le_mul_right (half_pos pi_pos)]
have hr_le : r ≤ -1 := by rwa [Int.lt_iff_add_one_le, ← le_neg_iff_add_nonpos_right] at h
rw [← le_sub_iff_add_le, mul_comm, ← le_div_iff]
· norm_num
rw [← Int.cast_one, ← Int.cast_neg]; norm_cast
· exact zero_lt_two
theorem surjOn_tan : SurjOn tan (Ioo (-(π / 2)) (π / 2)) univ :=
have := neg_lt_self pi_div_two_pos
continuousOn_tan_Ioo.surjOn_of_tendsto (nonempty_Ioo.2 this)
(by rw [tendsto_comp_coe_Ioo_atBot this]; exact tendsto_tan_neg_pi_div_two)
(by rw [tendsto_comp_coe_Ioo_atTop this]; exact tendsto_tan_pi_div_two)
theorem tan_surjective : Function.Surjective tan := fun _ => surjOn_tan.subset_range trivial
theorem image_tan_Ioo : tan '' Ioo (-(π / 2)) (π / 2) = univ :=
univ_subset_iff.1 surjOn_tan
/-- `Real.tan` as an `OrderIso` between `(-(π / 2), π / 2)` and `ℝ`. -/
def tanOrderIso : Ioo (-(π / 2)) (π / 2) ≃o ℝ :=
(strictMonoOn_tan.orderIso _ _).trans <|
(OrderIso.setCongr _ _ image_tan_Ioo).trans OrderIso.Set.univ
/-- Inverse of the `tan` function, returns values in the range `-π / 2 < arctan x` and
`arctan x < π / 2` -/
@[pp_nodot]
noncomputable def arctan (x : ℝ) : ℝ :=
tanOrderIso.symm x
@[simp]
theorem tan_arctan (x : ℝ) : tan (arctan x) = x :=
tanOrderIso.apply_symm_apply x
theorem arctan_mem_Ioo (x : ℝ) : arctan x ∈ Ioo (-(π / 2)) (π / 2) :=
Subtype.coe_prop _
@[simp]
theorem range_arctan : range arctan = Ioo (-(π / 2)) (π / 2) :=
((EquivLike.surjective _).range_comp _).trans Subtype.range_coe
theorem arctan_tan {x : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2) : arctan (tan x) = x :=
Subtype.ext_iff.1 <| tanOrderIso.symm_apply_apply ⟨x, hx₁, hx₂⟩
theorem cos_arctan_pos (x : ℝ) : 0 < cos (arctan x) :=
cos_pos_of_mem_Ioo <| arctan_mem_Ioo x
theorem cos_sq_arctan (x : ℝ) : cos (arctan x) ^ 2 = 1 / (1 + x ^ 2) := by
rw_mod_cast [one_div, ← inv_one_add_tan_sq (cos_arctan_pos x).ne', tan_arctan]
theorem sin_arctan (x : ℝ) : sin (arctan x) = x / √(1 + x ^ 2) := by
rw_mod_cast [← tan_div_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan]
theorem cos_arctan (x : ℝ) : cos (arctan x) = 1 / √(1 + x ^ 2) := by
rw_mod_cast [one_div, ← inv_sqrt_one_add_tan_sq (cos_arctan_pos x), tan_arctan]
theorem arctan_lt_pi_div_two (x : ℝ) : arctan x < π / 2 :=
(arctan_mem_Ioo x).2
theorem neg_pi_div_two_lt_arctan (x : ℝ) : -(π / 2) < arctan x :=
(arctan_mem_Ioo x).1
theorem arctan_eq_arcsin (x : ℝ) : arctan x = arcsin (x / √(1 + x ^ 2)) :=
Eq.symm <| arcsin_eq_of_sin_eq (sin_arctan x) (mem_Icc_of_Ioo <| arctan_mem_Ioo x)
theorem arcsin_eq_arctan {x : ℝ} (h : x ∈ Ioo (-(1 : ℝ)) 1) :
arcsin x = arctan (x / √(1 - x ^ 2)) := by
rw_mod_cast [arctan_eq_arcsin, div_pow, sq_sqrt, one_add_div, div_div, ← sqrt_mul,
mul_div_cancel₀, sub_add_cancel, sqrt_one, div_one] <;> simp at h <;> nlinarith [h.1, h.2]
@[simp]
theorem arctan_zero : arctan 0 = 0 := by simp [arctan_eq_arcsin]
@[mono]
theorem arctan_strictMono : StrictMono arctan := tanOrderIso.symm.strictMono
theorem arctan_injective : arctan.Injective := arctan_strictMono.injective
@[simp]
theorem arctan_eq_zero_iff {x : ℝ} : arctan x = 0 ↔ x = 0 :=
.trans (by rw [arctan_zero]) arctan_injective.eq_iff
theorem tendsto_arctan_atTop : Tendsto arctan atTop (𝓝[<] (π / 2)) :=
tendsto_Ioo_atTop.mp tanOrderIso.symm.tendsto_atTop
theorem tendsto_arctan_atBot : Tendsto arctan atBot (𝓝[>] (-(π / 2))) :=
tendsto_Ioo_atBot.mp tanOrderIso.symm.tendsto_atBot
theorem arctan_eq_of_tan_eq {x y : ℝ} (h : tan x = y) (hx : x ∈ Ioo (-(π / 2)) (π / 2)) :
arctan y = x :=
injOn_tan (arctan_mem_Ioo _) hx (by rw [tan_arctan, h])
@[simp]
theorem arctan_one : arctan 1 = π / 4 :=
arctan_eq_of_tan_eq tan_pi_div_four <| by constructor <;> linarith [pi_pos]
@[simp]
theorem arctan_neg (x : ℝ) : arctan (-x) = -arctan x := by simp [arctan_eq_arcsin, neg_div]
theorem arctan_eq_arccos {x : ℝ} (h : 0 ≤ x) : arctan x = arccos (√(1 + x ^ 2))⁻¹ := by
rw [arctan_eq_arcsin, arccos_eq_arcsin]; swap; · exact inv_nonneg.2 (sqrt_nonneg _)
congr 1
rw_mod_cast [← sqrt_inv, sq_sqrt, ← one_div, one_sub_div, add_sub_cancel_left, sqrt_div,
sqrt_sq h]
all_goals positivity
-- The junk values for `arccos` and `sqrt` make this true even for `1 < x`.
theorem arccos_eq_arctan {x : ℝ} (h : 0 < x) : arccos x = arctan (√(1 - x ^ 2) / x) := by
rw [arccos, eq_comm]
refine arctan_eq_of_tan_eq ?_ ⟨?_, ?_⟩
· rw_mod_cast [tan_pi_div_two_sub, tan_arcsin, inv_div]
· linarith only [arcsin_le_pi_div_two x, pi_pos]
· linarith only [arcsin_pos.2 h]
theorem arctan_inv_of_pos {x : ℝ} (h : 0 < x) : arctan x⁻¹ = π / 2 - arctan x := by
rw [← arctan_tan (x := _ - _), tan_pi_div_two_sub, tan_arctan]
· norm_num
exact (arctan_lt_pi_div_two x).trans (half_lt_self_iff.mpr pi_pos)
· rw [sub_lt_self_iff, ← arctan_zero]
exact tanOrderIso.symm.strictMono h
theorem arctan_inv_of_neg {x : ℝ} (h : x < 0) : arctan x⁻¹ = -(π / 2) - arctan x := by
have := arctan_inv_of_pos (neg_pos.mpr h)
rwa [inv_neg, arctan_neg, neg_eq_iff_eq_neg, neg_sub', arctan_neg, neg_neg] at this
section ArctanAdd
lemma arctan_ne_mul_pi_div_two {x : ℝ} : ∀ (k : ℤ), arctan x ≠ (2 * k + 1) * π / 2 := by
by_contra!
obtain ⟨k, h⟩ := this
obtain ⟨lb, ub⟩ := arctan_mem_Ioo x
rw [h, neg_eq_neg_one_mul, mul_div_assoc, mul_lt_mul_right (by positivity)] at lb
rw [h, ← one_mul (π / 2), mul_div_assoc, mul_lt_mul_right (by positivity)] at ub
norm_cast at lb ub; change -1 < _ at lb; omega
lemma arctan_add_arctan_lt_pi_div_two {x y : ℝ} (h : x * y < 1) : arctan x + arctan y < π / 2 := by
cases' le_or_lt y 0 with hy hy
· rw [← add_zero (π / 2), ← arctan_zero]
exact add_lt_add_of_lt_of_le (arctan_lt_pi_div_two _) (tanOrderIso.symm.monotone hy)
· rw [← lt_div_iff hy, ← inv_eq_one_div] at h
replace h : arctan x < arctan y⁻¹ := tanOrderIso.symm.strictMono h
rwa [arctan_inv_of_pos hy, lt_tsub_iff_right] at h
theorem arctan_add {x y : ℝ} (h : x * y < 1) :
arctan x + arctan y = arctan ((x + y) / (1 - x * y)) := by
rw [← arctan_tan (x := _ + _)]
· congr
conv_rhs => rw [← tan_arctan x, ← tan_arctan y]
exact tan_add' ⟨arctan_ne_mul_pi_div_two, arctan_ne_mul_pi_div_two⟩
· rw [neg_lt, neg_add, ← arctan_neg, ← arctan_neg]
rw [← neg_mul_neg] at h
exact arctan_add_arctan_lt_pi_div_two h
· exact arctan_add_arctan_lt_pi_div_two h
theorem arctan_add_eq_add_pi {x y : ℝ} (h : 1 < x * y) (hx : 0 < x) :
arctan x + arctan y = arctan ((x + y) / (1 - x * y)) + π := by
have hy : 0 < y := by
have := mul_pos_iff.mp (zero_lt_one.trans h)
simpa [hx, hx.asymm]
have k := arctan_add (mul_inv x y ▸ inv_lt_one h)
rw [arctan_inv_of_pos hx, arctan_inv_of_pos hy, show _ + _ = π - (arctan x + arctan y) by ring,
sub_eq_iff_eq_add, ← sub_eq_iff_eq_add', sub_eq_add_neg, ← arctan_neg, add_comm] at k
convert k.symm using 3
field_simp
rw [show -x + -y = -(x + y) by ring, show x * y - 1 = -(1 - x * y) by ring, neg_div_neg_eq]
theorem arctan_add_eq_sub_pi {x y : ℝ} (h : 1 < x * y) (hx : x < 0) :
arctan x + arctan y = arctan ((x + y) / (1 - x * y)) - π := by
rw [← neg_mul_neg] at h
have k := arctan_add_eq_add_pi h (neg_pos.mpr hx)
rw [show _ / _ = -((x + y) / (1 - x * y)) by ring, ← neg_inj] at k
simp only [arctan_neg, neg_add, neg_neg, ← sub_eq_add_neg _ π] at k
exact k
theorem two_mul_arctan {x : ℝ} (h₁ : -1 < x) (h₂ : x < 1) :
2 * arctan x = arctan (2 * x / (1 - x ^ 2)) := by
rw [two_mul, arctan_add (by nlinarith)]; congr 1; ring
theorem two_mul_arctan_add_pi {x : ℝ} (h : 1 < x) :
2 * arctan x = arctan (2 * x / (1 - x ^ 2)) + π := by
rw [two_mul, arctan_add_eq_add_pi (by nlinarith) (by linarith)]; congr 2; ring
theorem two_mul_arctan_sub_pi {x : ℝ} (h : x < -1) :
2 * arctan x = arctan (2 * x / (1 - x ^ 2)) - π := by
rw [two_mul, arctan_add_eq_sub_pi (by nlinarith) (by linarith)]; congr 2; ring
theorem arctan_inv_2_add_arctan_inv_3 : arctan 2⁻¹ + arctan 3⁻¹ = π / 4 := by
rw [arctan_add] <;> norm_num
theorem two_mul_arctan_inv_2_sub_arctan_inv_7 : 2 * arctan 2⁻¹ - arctan 7⁻¹ = π / 4 := by
rw [two_mul_arctan, ← arctan_one, sub_eq_iff_eq_add, arctan_add] <;> norm_num
theorem two_mul_arctan_inv_3_add_arctan_inv_7 : 2 * arctan 3⁻¹ + arctan 7⁻¹ = π / 4 := by
rw [two_mul_arctan, arctan_add] <;> norm_num
/-- **John Machin's 1706 formula**, which he used to compute π to 100 decimal places. -/
theorem four_mul_arctan_inv_5_sub_arctan_inv_239 : 4 * arctan 5⁻¹ - arctan 239⁻¹ = π / 4 := by
rw [show 4 * arctan _ = 2 * (2 * _) by ring, two_mul_arctan, two_mul_arctan, ← arctan_one,
sub_eq_iff_eq_add, arctan_add] <;> norm_num
end ArctanAdd
@[continuity]
theorem continuous_arctan : Continuous arctan :=
continuous_subtype_val.comp tanOrderIso.toHomeomorph.continuous_invFun
theorem continuousAt_arctan {x : ℝ} : ContinuousAt arctan x :=
continuous_arctan.continuousAt
/-- `Real.tan` as a `PartialHomeomorph` between `(-(π / 2), π / 2)` and the whole line. -/
def tanPartialHomeomorph : PartialHomeomorph ℝ ℝ where
toFun := tan
invFun := arctan
source := Ioo (-(π / 2)) (π / 2)
target := univ
map_source' := mapsTo_univ _ _
map_target' y _ := arctan_mem_Ioo y
left_inv' _ hx := arctan_tan hx.1 hx.2
right_inv' y _ := tan_arctan y
open_source := isOpen_Ioo
open_target := isOpen_univ
continuousOn_toFun := continuousOn_tan_Ioo
continuousOn_invFun := continuous_arctan.continuousOn
@[simp]
theorem coe_tanPartialHomeomorph : ⇑tanPartialHomeomorph = tan :=
rfl
@[simp]
theorem coe_tanPartialHomeomorph_symm : ⇑tanPartialHomeomorph.symm = arctan :=
rfl
end Real
|
Analysis\SpecialFunctions\Trigonometric\ArctanDeriv.lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Arctan
import Mathlib.Analysis.SpecialFunctions.Trigonometric.ComplexDeriv
/-!
# Derivatives of the `tan` and `arctan` functions.
Continuity and derivatives of the tangent and arctangent functions.
-/
noncomputable section
namespace Real
open Set Filter
open scoped Topology Real
theorem hasStrictDerivAt_tan {x : ℝ} (h : cos x ≠ 0) : HasStrictDerivAt tan (1 / cos x ^ 2) x :=
mod_cast (Complex.hasStrictDerivAt_tan (by exact mod_cast h)).real_of_complex
theorem hasDerivAt_tan {x : ℝ} (h : cos x ≠ 0) : HasDerivAt tan (1 / cos x ^ 2) x :=
mod_cast (Complex.hasDerivAt_tan (by exact mod_cast h)).real_of_complex
theorem tendsto_abs_tan_of_cos_eq_zero {x : ℝ} (hx : cos x = 0) :
Tendsto (fun x => abs (tan x)) (𝓝[≠] x) atTop := by
have hx : Complex.cos x = 0 := mod_cast hx
simp only [← Complex.abs_ofReal, Complex.ofReal_tan]
refine (Complex.tendsto_abs_tan_of_cos_eq_zero hx).comp ?_
refine Tendsto.inf Complex.continuous_ofReal.continuousAt ?_
exact tendsto_principal_principal.2 fun y => mt Complex.ofReal_inj.1
theorem tendsto_abs_tan_atTop (k : ℤ) :
Tendsto (fun x => abs (tan x)) (𝓝[≠] ((2 * k + 1) * π / 2)) atTop :=
tendsto_abs_tan_of_cos_eq_zero <| cos_eq_zero_iff.2 ⟨k, rfl⟩
theorem continuousAt_tan {x : ℝ} : ContinuousAt tan x ↔ cos x ≠ 0 := by
refine ⟨fun hc h₀ => ?_, fun h => (hasDerivAt_tan h).continuousAt⟩
exact not_tendsto_nhds_of_tendsto_atTop (tendsto_abs_tan_of_cos_eq_zero h₀) _
(hc.norm.tendsto.mono_left inf_le_left)
theorem differentiableAt_tan {x : ℝ} : DifferentiableAt ℝ tan x ↔ cos x ≠ 0 :=
⟨fun h => continuousAt_tan.1 h.continuousAt, fun h => (hasDerivAt_tan h).differentiableAt⟩
@[simp]
theorem deriv_tan (x : ℝ) : deriv tan x = 1 / cos x ^ 2 :=
if h : cos x = 0 then by
have : ¬DifferentiableAt ℝ tan x := mt differentiableAt_tan.1 (Classical.not_not.2 h)
simp [deriv_zero_of_not_differentiableAt this, h, sq]
else (hasDerivAt_tan h).deriv
@[simp]
theorem contDiffAt_tan {n x} : ContDiffAt ℝ n tan x ↔ cos x ≠ 0 :=
⟨fun h => continuousAt_tan.1 h.continuousAt, fun h =>
(Complex.contDiffAt_tan.2 <| mod_cast h).real_of_complex⟩
theorem hasDerivAt_tan_of_mem_Ioo {x : ℝ} (h : x ∈ Ioo (-(π / 2) : ℝ) (π / 2)) :
HasDerivAt tan (1 / cos x ^ 2) x :=
hasDerivAt_tan (cos_pos_of_mem_Ioo h).ne'
theorem differentiableAt_tan_of_mem_Ioo {x : ℝ} (h : x ∈ Ioo (-(π / 2) : ℝ) (π / 2)) :
DifferentiableAt ℝ tan x :=
(hasDerivAt_tan_of_mem_Ioo h).differentiableAt
theorem hasStrictDerivAt_arctan (x : ℝ) : HasStrictDerivAt arctan (1 / (1 + x ^ 2)) x := by
have A : cos (arctan x) ≠ 0 := (cos_arctan_pos x).ne'
simpa [cos_sq_arctan] using
tanPartialHomeomorph.hasStrictDerivAt_symm trivial (by simpa) (hasStrictDerivAt_tan A)
theorem hasDerivAt_arctan (x : ℝ) : HasDerivAt arctan (1 / (1 + x ^ 2)) x :=
(hasStrictDerivAt_arctan x).hasDerivAt
theorem hasDerivAt_arctan' (x : ℝ) : HasDerivAt arctan (1 + x ^ 2)⁻¹ x :=
one_div (1 + x ^ 2) ▸ hasDerivAt_arctan x
theorem differentiableAt_arctan (x : ℝ) : DifferentiableAt ℝ arctan x :=
(hasDerivAt_arctan x).differentiableAt
theorem differentiable_arctan : Differentiable ℝ arctan :=
differentiableAt_arctan
@[simp]
theorem deriv_arctan : deriv arctan = fun (x : ℝ) => 1 / (1 + x ^ 2) :=
funext fun x => (hasDerivAt_arctan x).deriv
theorem contDiff_arctan {n : ℕ∞} : ContDiff ℝ n arctan :=
contDiff_iff_contDiffAt.2 fun x =>
have : cos (arctan x) ≠ 0 := (cos_arctan_pos x).ne'
tanPartialHomeomorph.contDiffAt_symm_deriv (by simpa) trivial (hasDerivAt_tan this)
(contDiffAt_tan.2 this)
end Real
section
/-!
### Lemmas for derivatives of the composition of `Real.arctan` with a differentiable function
In this section we register lemmas for the derivatives of the composition of `Real.arctan` with a
differentiable function, for standalone use and use with `simp`. -/
open Real
section deriv
variable {f : ℝ → ℝ} {f' x : ℝ} {s : Set ℝ}
theorem HasStrictDerivAt.arctan (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => arctan (f x)) (1 / (1 + f x ^ 2) * f') x :=
(Real.hasStrictDerivAt_arctan (f x)).comp x hf
theorem HasDerivAt.arctan (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => arctan (f x)) (1 / (1 + f x ^ 2) * f') x :=
(Real.hasDerivAt_arctan (f x)).comp x hf
theorem HasDerivWithinAt.arctan (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => arctan (f x)) (1 / (1 + f x ^ 2) * f') s x :=
(Real.hasDerivAt_arctan (f x)).comp_hasDerivWithinAt x hf
theorem derivWithin_arctan (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) :
derivWithin (fun x => arctan (f x)) s x = 1 / (1 + f x ^ 2) * derivWithin f s x :=
hf.hasDerivWithinAt.arctan.derivWithin hxs
@[simp]
theorem deriv_arctan (hc : DifferentiableAt ℝ f x) :
deriv (fun x => arctan (f x)) x = 1 / (1 + f x ^ 2) * deriv f x :=
hc.hasDerivAt.arctan.deriv
end deriv
section fderiv
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : E → ℝ} {f' : E →L[ℝ] ℝ} {x : E}
{s : Set E} {n : ℕ∞}
theorem HasStrictFDerivAt.arctan (hf : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (fun x => arctan (f x)) ((1 / (1 + f x ^ 2)) • f') x :=
(hasStrictDerivAt_arctan (f x)).comp_hasStrictFDerivAt x hf
theorem HasFDerivAt.arctan (hf : HasFDerivAt f f' x) :
HasFDerivAt (fun x => arctan (f x)) ((1 / (1 + f x ^ 2)) • f') x :=
(hasDerivAt_arctan (f x)).comp_hasFDerivAt x hf
theorem HasFDerivWithinAt.arctan (hf : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (fun x => arctan (f x)) ((1 / (1 + f x ^ 2)) • f') s x :=
(hasDerivAt_arctan (f x)).comp_hasFDerivWithinAt x hf
theorem fderivWithin_arctan (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) :
fderivWithin ℝ (fun x => arctan (f x)) s x = (1 / (1 + f x ^ 2)) • fderivWithin ℝ f s x :=
hf.hasFDerivWithinAt.arctan.fderivWithin hxs
@[simp]
theorem fderiv_arctan (hc : DifferentiableAt ℝ f x) :
fderiv ℝ (fun x => arctan (f x)) x = (1 / (1 + f x ^ 2)) • fderiv ℝ f x :=
hc.hasFDerivAt.arctan.fderiv
theorem DifferentiableWithinAt.arctan (hf : DifferentiableWithinAt ℝ f s x) :
DifferentiableWithinAt ℝ (fun x => Real.arctan (f x)) s x :=
hf.hasFDerivWithinAt.arctan.differentiableWithinAt
@[simp]
theorem DifferentiableAt.arctan (hc : DifferentiableAt ℝ f x) :
DifferentiableAt ℝ (fun x => arctan (f x)) x :=
hc.hasFDerivAt.arctan.differentiableAt
theorem DifferentiableOn.arctan (hc : DifferentiableOn ℝ f s) :
DifferentiableOn ℝ (fun x => arctan (f x)) s := fun x h => (hc x h).arctan
@[simp]
theorem Differentiable.arctan (hc : Differentiable ℝ f) : Differentiable ℝ fun x => arctan (f x) :=
fun x => (hc x).arctan
theorem ContDiffAt.arctan (h : ContDiffAt ℝ n f x) : ContDiffAt ℝ n (fun x => arctan (f x)) x :=
contDiff_arctan.contDiffAt.comp x h
theorem ContDiff.arctan (h : ContDiff ℝ n f) : ContDiff ℝ n fun x => arctan (f x) :=
contDiff_arctan.comp h
theorem ContDiffWithinAt.arctan (h : ContDiffWithinAt ℝ n f s x) :
ContDiffWithinAt ℝ n (fun x => arctan (f x)) s x :=
contDiff_arctan.comp_contDiffWithinAt h
theorem ContDiffOn.arctan (h : ContDiffOn ℝ n f s) : ContDiffOn ℝ n (fun x => arctan (f x)) s :=
contDiff_arctan.comp_contDiffOn h
end fderiv
end
|
Analysis\SpecialFunctions\Trigonometric\Basic.lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import Mathlib.Analysis.SpecialFunctions.Exp
import Mathlib.Tactic.Positivity.Core
import Mathlib.Algebra.Ring.NegOnePow
/-!
# Trigonometric functions
## Main definitions
This file contains the definition of `π`.
See also `Analysis.SpecialFunctions.Trigonometric.Inverse` and
`Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse trigonometric functions.
See also `Analysis.SpecialFunctions.Complex.Arg` and
`Analysis.SpecialFunctions.Complex.Log` for the complex argument function
and the complex logarithm.
## Main statements
Many basic inequalities on the real trigonometric functions are established.
The continuity of the usual trigonometric functions is proved.
Several facts about the real trigonometric functions have the proofs deferred to
`Analysis.SpecialFunctions.Trigonometric.Complex`,
as they are most easily proved by appealing to the corresponding fact for
complex trigonometric functions.
See also `Analysis.SpecialFunctions.Trigonometric.Chebyshev` for the multiple angle formulas
in terms of Chebyshev polynomials.
## Tags
sin, cos, tan, angle
-/
noncomputable section
open scoped Classical
open Topology Filter Set
namespace Complex
@[continuity, fun_prop]
theorem continuous_sin : Continuous sin := by
change Continuous fun z => (exp (-z * I) - exp (z * I)) * I / 2
continuity
@[fun_prop]
theorem continuousOn_sin {s : Set ℂ} : ContinuousOn sin s :=
continuous_sin.continuousOn
@[continuity, fun_prop]
theorem continuous_cos : Continuous cos := by
change Continuous fun z => (exp (z * I) + exp (-z * I)) / 2
continuity
@[fun_prop]
theorem continuousOn_cos {s : Set ℂ} : ContinuousOn cos s :=
continuous_cos.continuousOn
@[continuity, fun_prop]
theorem continuous_sinh : Continuous sinh := by
change Continuous fun z => (exp z - exp (-z)) / 2
continuity
@[continuity, fun_prop]
theorem continuous_cosh : Continuous cosh := by
change Continuous fun z => (exp z + exp (-z)) / 2
continuity
end Complex
namespace Real
variable {x y z : ℝ}
@[continuity, fun_prop]
theorem continuous_sin : Continuous sin :=
Complex.continuous_re.comp (Complex.continuous_sin.comp Complex.continuous_ofReal)
@[fun_prop]
theorem continuousOn_sin {s} : ContinuousOn sin s :=
continuous_sin.continuousOn
@[continuity, fun_prop]
theorem continuous_cos : Continuous cos :=
Complex.continuous_re.comp (Complex.continuous_cos.comp Complex.continuous_ofReal)
@[fun_prop]
theorem continuousOn_cos {s} : ContinuousOn cos s :=
continuous_cos.continuousOn
@[continuity, fun_prop]
theorem continuous_sinh : Continuous sinh :=
Complex.continuous_re.comp (Complex.continuous_sinh.comp Complex.continuous_ofReal)
@[continuity, fun_prop]
theorem continuous_cosh : Continuous cosh :=
Complex.continuous_re.comp (Complex.continuous_cosh.comp Complex.continuous_ofReal)
end Real
namespace Real
theorem exists_cos_eq_zero : 0 ∈ cos '' Icc (1 : ℝ) 2 :=
intermediate_value_Icc' (by norm_num) continuousOn_cos
⟨le_of_lt cos_two_neg, le_of_lt cos_one_pos⟩
/-- The number π = 3.14159265... Defined here using choice as twice a zero of cos in [1,2], from
which one can derive all its properties. For explicit bounds on π, see `Data.Real.Pi.Bounds`. -/
protected noncomputable def pi : ℝ :=
2 * Classical.choose exists_cos_eq_zero
@[inherit_doc]
scoped notation "π" => Real.pi
@[simp]
theorem cos_pi_div_two : cos (π / 2) = 0 := by
rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)]
exact (Classical.choose_spec exists_cos_eq_zero).2
theorem one_le_pi_div_two : (1 : ℝ) ≤ π / 2 := by
rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)]
exact (Classical.choose_spec exists_cos_eq_zero).1.1
theorem pi_div_two_le_two : π / 2 ≤ 2 := by
rw [Real.pi, mul_div_cancel_left₀ _ (two_ne_zero' ℝ)]
exact (Classical.choose_spec exists_cos_eq_zero).1.2
theorem two_le_pi : (2 : ℝ) ≤ π :=
(div_le_div_right (show (0 : ℝ) < 2 by norm_num)).1
(by rw [div_self (two_ne_zero' ℝ)]; exact one_le_pi_div_two)
theorem pi_le_four : π ≤ 4 :=
(div_le_div_right (show (0 : ℝ) < 2 by norm_num)).1
(calc
π / 2 ≤ 2 := pi_div_two_le_two
_ = 4 / 2 := by norm_num)
@[bound]
theorem pi_pos : 0 < π :=
lt_of_lt_of_le (by norm_num) two_le_pi
@[bound]
theorem pi_nonneg : 0 ≤ π :=
pi_pos.le
theorem pi_ne_zero : π ≠ 0 :=
pi_pos.ne'
theorem pi_div_two_pos : 0 < π / 2 :=
half_pos pi_pos
theorem two_pi_pos : 0 < 2 * π := by linarith [pi_pos]
end Real
namespace Mathlib.Meta.Positivity
open Lean.Meta Qq
/-- Extension for the `positivity` tactic: `π` is always positive. -/
@[positivity Real.pi]
def evalRealPi : PositivityExt where eval {u α} _zα _pα e := do
match u, α, e with
| 0, ~q(ℝ), ~q(Real.pi) =>
assertInstancesCommute
pure (.positive q(Real.pi_pos))
| _, _, _ => throwError "not Real.pi"
end Mathlib.Meta.Positivity
namespace NNReal
open Real
open Real NNReal
/-- `π` considered as a nonnegative real. -/
noncomputable def pi : ℝ≥0 :=
⟨π, Real.pi_pos.le⟩
@[simp]
theorem coe_real_pi : (pi : ℝ) = π :=
rfl
theorem pi_pos : 0 < pi := mod_cast Real.pi_pos
theorem pi_ne_zero : pi ≠ 0 :=
pi_pos.ne'
end NNReal
namespace Real
open Real
@[simp]
theorem sin_pi : sin π = 0 := by
rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), two_mul, add_div, sin_add, cos_pi_div_two]; simp
@[simp]
theorem cos_pi : cos π = -1 := by
rw [← mul_div_cancel_left₀ π (two_ne_zero' ℝ), mul_div_assoc, cos_two_mul, cos_pi_div_two]
norm_num
@[simp]
theorem sin_two_pi : sin (2 * π) = 0 := by simp [two_mul, sin_add]
@[simp]
theorem cos_two_pi : cos (2 * π) = 1 := by simp [two_mul, cos_add]
theorem sin_antiperiodic : Function.Antiperiodic sin π := by simp [sin_add]
theorem sin_periodic : Function.Periodic sin (2 * π) :=
sin_antiperiodic.periodic_two_mul
@[simp]
theorem sin_add_pi (x : ℝ) : sin (x + π) = -sin x :=
sin_antiperiodic x
@[simp]
theorem sin_add_two_pi (x : ℝ) : sin (x + 2 * π) = sin x :=
sin_periodic x
@[simp]
theorem sin_sub_pi (x : ℝ) : sin (x - π) = -sin x :=
sin_antiperiodic.sub_eq x
@[simp]
theorem sin_sub_two_pi (x : ℝ) : sin (x - 2 * π) = sin x :=
sin_periodic.sub_eq x
@[simp]
theorem sin_pi_sub (x : ℝ) : sin (π - x) = sin x :=
neg_neg (sin x) ▸ sin_neg x ▸ sin_antiperiodic.sub_eq'
@[simp]
theorem sin_two_pi_sub (x : ℝ) : sin (2 * π - x) = -sin x :=
sin_neg x ▸ sin_periodic.sub_eq'
@[simp]
theorem sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 :=
sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n
@[simp]
theorem sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 :=
sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n
@[simp]
theorem sin_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.nat_mul n x
@[simp]
theorem sin_add_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.int_mul n x
@[simp]
theorem sin_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_nat_mul_eq n
@[simp]
theorem sin_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_int_mul_eq n
@[simp]
theorem sin_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.nat_mul_sub_eq n
@[simp]
theorem sin_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.int_mul_sub_eq n
theorem sin_add_int_mul_pi (x : ℝ) (n : ℤ) : sin (x + n * π) = (-1) ^ n * sin x :=
n.coe_negOnePow ℝ ▸ sin_antiperiodic.add_int_mul_eq n
theorem sin_add_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x + n * π) = (-1) ^ n * sin x :=
sin_antiperiodic.add_nat_mul_eq n
theorem sin_sub_int_mul_pi (x : ℝ) (n : ℤ) : sin (x - n * π) = (-1) ^ n * sin x :=
n.coe_negOnePow ℝ ▸ sin_antiperiodic.sub_int_mul_eq n
theorem sin_sub_nat_mul_pi (x : ℝ) (n : ℕ) : sin (x - n * π) = (-1) ^ n * sin x :=
sin_antiperiodic.sub_nat_mul_eq n
theorem sin_int_mul_pi_sub (x : ℝ) (n : ℤ) : sin (n * π - x) = -((-1) ^ n * sin x) := by
simpa only [sin_neg, mul_neg, Int.coe_negOnePow] using sin_antiperiodic.int_mul_sub_eq n
theorem sin_nat_mul_pi_sub (x : ℝ) (n : ℕ) : sin (n * π - x) = -((-1) ^ n * sin x) := by
simpa only [sin_neg, mul_neg] using sin_antiperiodic.nat_mul_sub_eq n
theorem cos_antiperiodic : Function.Antiperiodic cos π := by simp [cos_add]
theorem cos_periodic : Function.Periodic cos (2 * π) :=
cos_antiperiodic.periodic_two_mul
@[simp]
theorem cos_add_pi (x : ℝ) : cos (x + π) = -cos x :=
cos_antiperiodic x
@[simp]
theorem cos_add_two_pi (x : ℝ) : cos (x + 2 * π) = cos x :=
cos_periodic x
@[simp]
theorem cos_sub_pi (x : ℝ) : cos (x - π) = -cos x :=
cos_antiperiodic.sub_eq x
@[simp]
theorem cos_sub_two_pi (x : ℝ) : cos (x - 2 * π) = cos x :=
cos_periodic.sub_eq x
@[simp]
theorem cos_pi_sub (x : ℝ) : cos (π - x) = -cos x :=
cos_neg x ▸ cos_antiperiodic.sub_eq'
@[simp]
theorem cos_two_pi_sub (x : ℝ) : cos (2 * π - x) = cos x :=
cos_neg x ▸ cos_periodic.sub_eq'
@[simp]
theorem cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.nat_mul_eq n).trans cos_zero
@[simp]
theorem cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.int_mul_eq n).trans cos_zero
@[simp]
theorem cos_add_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.nat_mul n x
@[simp]
theorem cos_add_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.int_mul n x
@[simp]
theorem cos_sub_nat_mul_two_pi (x : ℝ) (n : ℕ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_nat_mul_eq n
@[simp]
theorem cos_sub_int_mul_two_pi (x : ℝ) (n : ℤ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_int_mul_eq n
@[simp]
theorem cos_nat_mul_two_pi_sub (x : ℝ) (n : ℕ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.nat_mul_sub_eq n
@[simp]
theorem cos_int_mul_two_pi_sub (x : ℝ) (n : ℤ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.int_mul_sub_eq n
theorem cos_add_int_mul_pi (x : ℝ) (n : ℤ) : cos (x + n * π) = (-1) ^ n * cos x :=
n.coe_negOnePow ℝ ▸ cos_antiperiodic.add_int_mul_eq n
theorem cos_add_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x + n * π) = (-1) ^ n * cos x :=
cos_antiperiodic.add_nat_mul_eq n
theorem cos_sub_int_mul_pi (x : ℝ) (n : ℤ) : cos (x - n * π) = (-1) ^ n * cos x :=
n.coe_negOnePow ℝ ▸ cos_antiperiodic.sub_int_mul_eq n
theorem cos_sub_nat_mul_pi (x : ℝ) (n : ℕ) : cos (x - n * π) = (-1) ^ n * cos x :=
cos_antiperiodic.sub_nat_mul_eq n
theorem cos_int_mul_pi_sub (x : ℝ) (n : ℤ) : cos (n * π - x) = (-1) ^ n * cos x :=
n.coe_negOnePow ℝ ▸ cos_neg x ▸ cos_antiperiodic.int_mul_sub_eq n
theorem cos_nat_mul_pi_sub (x : ℝ) (n : ℕ) : cos (n * π - x) = (-1) ^ n * cos x :=
cos_neg x ▸ cos_antiperiodic.nat_mul_sub_eq n
-- Porting note (#10618): was @[simp], but simp can prove it
theorem cos_nat_mul_two_pi_add_pi (n : ℕ) : cos (n * (2 * π) + π) = -1 := by
simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic
-- Porting note (#10618): was @[simp], but simp can prove it
theorem cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 := by
simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic
-- Porting note (#10618): was @[simp], but simp can prove it
theorem cos_nat_mul_two_pi_sub_pi (n : ℕ) : cos (n * (2 * π) - π) = -1 := by
simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic
-- Porting note (#10618): was @[simp], but simp can prove it
theorem cos_int_mul_two_pi_sub_pi (n : ℤ) : cos (n * (2 * π) - π) = -1 := by
simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic
theorem sin_pos_of_pos_of_lt_pi {x : ℝ} (h0x : 0 < x) (hxp : x < π) : 0 < sin x :=
if hx2 : x ≤ 2 then sin_pos_of_pos_of_le_two h0x hx2
else
have : (2 : ℝ) + 2 = 4 := by norm_num
have : π - x ≤ 2 :=
sub_le_iff_le_add.2 (le_trans pi_le_four (this ▸ add_le_add_left (le_of_not_ge hx2) _))
sin_pi_sub x ▸ sin_pos_of_pos_of_le_two (sub_pos.2 hxp) this
theorem sin_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo 0 π) : 0 < sin x :=
sin_pos_of_pos_of_lt_pi hx.1 hx.2
theorem sin_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc 0 π) : 0 ≤ sin x := by
rw [← closure_Ioo pi_ne_zero.symm] at hx
exact
closure_lt_subset_le continuous_const continuous_sin
(closure_mono (fun y => sin_pos_of_mem_Ioo) hx)
theorem sin_nonneg_of_nonneg_of_le_pi {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π) : 0 ≤ sin x :=
sin_nonneg_of_mem_Icc ⟨h0x, hxp⟩
theorem sin_neg_of_neg_of_neg_pi_lt {x : ℝ} (hx0 : x < 0) (hpx : -π < x) : sin x < 0 :=
neg_pos.1 <| sin_neg x ▸ sin_pos_of_pos_of_lt_pi (neg_pos.2 hx0) (neg_lt.1 hpx)
theorem sin_nonpos_of_nonnpos_of_neg_pi_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -π ≤ x) : sin x ≤ 0 :=
neg_nonneg.1 <| sin_neg x ▸ sin_nonneg_of_nonneg_of_le_pi (neg_nonneg.2 hx0) (neg_le.1 hpx)
@[simp]
theorem sin_pi_div_two : sin (π / 2) = 1 :=
have : sin (π / 2) = 1 ∨ sin (π / 2) = -1 := by
simpa [sq, mul_self_eq_one_iff] using sin_sq_add_cos_sq (π / 2)
this.resolve_right fun h =>
show ¬(0 : ℝ) < -1 by norm_num <|
h ▸ sin_pos_of_pos_of_lt_pi pi_div_two_pos (half_lt_self pi_pos)
theorem sin_add_pi_div_two (x : ℝ) : sin (x + π / 2) = cos x := by simp [sin_add]
theorem sin_sub_pi_div_two (x : ℝ) : sin (x - π / 2) = -cos x := by simp [sub_eq_add_neg, sin_add]
theorem sin_pi_div_two_sub (x : ℝ) : sin (π / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add]
theorem cos_add_pi_div_two (x : ℝ) : cos (x + π / 2) = -sin x := by simp [cos_add]
theorem cos_sub_pi_div_two (x : ℝ) : cos (x - π / 2) = sin x := by simp [sub_eq_add_neg, cos_add]
theorem cos_pi_div_two_sub (x : ℝ) : cos (π / 2 - x) = sin x := by
rw [← cos_neg, neg_sub, cos_sub_pi_div_two]
theorem cos_pos_of_mem_Ioo {x : ℝ} (hx : x ∈ Ioo (-(π / 2)) (π / 2)) : 0 < cos x :=
sin_add_pi_div_two x ▸ sin_pos_of_mem_Ioo ⟨by linarith [hx.1], by linarith [hx.2]⟩
theorem cos_nonneg_of_mem_Icc {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : 0 ≤ cos x :=
sin_add_pi_div_two x ▸ sin_nonneg_of_mem_Icc ⟨by linarith [hx.1], by linarith [hx.2]⟩
theorem cos_nonneg_of_neg_pi_div_two_le_of_le {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) :
0 ≤ cos x :=
cos_nonneg_of_mem_Icc ⟨hl, hu⟩
theorem cos_neg_of_pi_div_two_lt_of_lt {x : ℝ} (hx₁ : π / 2 < x) (hx₂ : x < π + π / 2) :
cos x < 0 :=
neg_pos.1 <| cos_pi_sub x ▸ cos_pos_of_mem_Ioo ⟨by linarith, by linarith⟩
theorem cos_nonpos_of_pi_div_two_le_of_le {x : ℝ} (hx₁ : π / 2 ≤ x) (hx₂ : x ≤ π + π / 2) :
cos x ≤ 0 :=
neg_nonneg.1 <| cos_pi_sub x ▸ cos_nonneg_of_mem_Icc ⟨by linarith, by linarith⟩
theorem sin_eq_sqrt_one_sub_cos_sq {x : ℝ} (hl : 0 ≤ x) (hu : x ≤ π) :
sin x = √(1 - cos x ^ 2) := by
rw [← abs_sin_eq_sqrt_one_sub_cos_sq, abs_of_nonneg (sin_nonneg_of_nonneg_of_le_pi hl hu)]
theorem cos_eq_sqrt_one_sub_sin_sq {x : ℝ} (hl : -(π / 2) ≤ x) (hu : x ≤ π / 2) :
cos x = √(1 - sin x ^ 2) := by
rw [← abs_cos_eq_sqrt_one_sub_sin_sq, abs_of_nonneg (cos_nonneg_of_mem_Icc ⟨hl, hu⟩)]
lemma cos_half {x : ℝ} (hl : -π ≤ x) (hr : x ≤ π) : cos (x / 2) = sqrt ((1 + cos x) / 2) := by
have : 0 ≤ cos (x / 2) := cos_nonneg_of_mem_Icc <| by constructor <;> linarith
rw [← sqrt_sq this, cos_sq, add_div, two_mul, add_halves]
lemma abs_sin_half (x : ℝ) : |sin (x / 2)| = sqrt ((1 - cos x) / 2) := by
rw [← sqrt_sq_eq_abs, sin_sq_eq_half_sub, two_mul, add_halves, sub_div]
lemma sin_half_eq_sqrt {x : ℝ} (hl : 0 ≤ x) (hr : x ≤ 2 * π) :
sin (x / 2) = sqrt ((1 - cos x) / 2) := by
rw [← abs_sin_half, abs_of_nonneg]
apply sin_nonneg_of_nonneg_of_le_pi <;> linarith
lemma sin_half_eq_neg_sqrt {x : ℝ} (hl : -(2 * π) ≤ x) (hr : x ≤ 0) :
sin (x / 2) = -sqrt ((1 - cos x) / 2) := by
rw [← abs_sin_half, abs_of_nonpos, neg_neg]
apply sin_nonpos_of_nonnpos_of_neg_pi_le <;> linarith
theorem sin_eq_zero_iff_of_lt_of_lt {x : ℝ} (hx₁ : -π < x) (hx₂ : x < π) : sin x = 0 ↔ x = 0 :=
⟨fun h => by
contrapose! h
cases h.lt_or_lt with
| inl h0 => exact (sin_neg_of_neg_of_neg_pi_lt h0 hx₁).ne
| inr h0 => exact (sin_pos_of_pos_of_lt_pi h0 hx₂).ne',
fun h => by simp [h]⟩
theorem sin_eq_zero_iff {x : ℝ} : sin x = 0 ↔ ∃ n : ℤ, (n : ℝ) * π = x :=
⟨fun h =>
⟨⌊x / π⌋,
le_antisymm (sub_nonneg.1 (Int.sub_floor_div_mul_nonneg _ pi_pos))
(sub_nonpos.1 <|
le_of_not_gt fun h₃ =>
(sin_pos_of_pos_of_lt_pi h₃ (Int.sub_floor_div_mul_lt _ pi_pos)).ne
(by simp [sub_eq_add_neg, sin_add, h, sin_int_mul_pi]))⟩,
fun ⟨n, hn⟩ => hn ▸ sin_int_mul_pi _⟩
theorem sin_ne_zero_iff {x : ℝ} : sin x ≠ 0 ↔ ∀ n : ℤ, (n : ℝ) * π ≠ x := by
rw [← not_exists, not_iff_not, sin_eq_zero_iff]
theorem sin_eq_zero_iff_cos_eq {x : ℝ} : sin x = 0 ↔ cos x = 1 ∨ cos x = -1 := by
rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq x, sq, sq, ← sub_eq_iff_eq_add, sub_self]
exact ⟨fun h => by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ Eq.symm⟩
theorem cos_eq_one_iff (x : ℝ) : cos x = 1 ↔ ∃ n : ℤ, (n : ℝ) * (2 * π) = x :=
⟨fun h =>
let ⟨n, hn⟩ := sin_eq_zero_iff.1 (sin_eq_zero_iff_cos_eq.2 (Or.inl h))
⟨n / 2,
(Int.emod_two_eq_zero_or_one n).elim
(fun hn0 => by
rwa [← mul_assoc, ← @Int.cast_two ℝ, ← Int.cast_mul,
Int.ediv_mul_cancel ((Int.dvd_iff_emod_eq_zero _ _).2 hn0)])
fun hn1 => by
rw [← Int.emod_add_ediv n 2, hn1, Int.cast_add, Int.cast_one, add_mul, one_mul, add_comm,
mul_comm (2 : ℤ), Int.cast_mul, mul_assoc, Int.cast_two] at hn
rw [← hn, cos_int_mul_two_pi_add_pi] at h
exact absurd h (by norm_num)⟩,
fun ⟨n, hn⟩ => hn ▸ cos_int_mul_two_pi _⟩
theorem cos_eq_one_iff_of_lt_of_lt {x : ℝ} (hx₁ : -(2 * π) < x) (hx₂ : x < 2 * π) :
cos x = 1 ↔ x = 0 :=
⟨fun h => by
rcases (cos_eq_one_iff _).1 h with ⟨n, rfl⟩
rw [mul_lt_iff_lt_one_left two_pi_pos] at hx₂
rw [neg_lt, neg_mul_eq_neg_mul, mul_lt_iff_lt_one_left two_pi_pos] at hx₁
norm_cast at hx₁ hx₂
obtain rfl : n = 0 := le_antisymm (by omega) (by omega)
simp, fun h => by simp [h]⟩
theorem sin_lt_sin_of_lt_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hy₂ : y ≤ π / 2)
(hxy : x < y) : sin x < sin y := by
rw [← sub_pos, sin_sub_sin]
have : 0 < sin ((y - x) / 2) := by apply sin_pos_of_pos_of_lt_pi <;> linarith
have : 0 < cos ((y + x) / 2) := by refine cos_pos_of_mem_Ioo ⟨?_, ?_⟩ <;> linarith
positivity
theorem strictMonoOn_sin : StrictMonoOn sin (Icc (-(π / 2)) (π / 2)) := fun _ hx _ hy hxy =>
sin_lt_sin_of_lt_of_le_pi_div_two hx.1 hy.2 hxy
theorem cos_lt_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x < y) :
cos y < cos x := by
rw [← sin_pi_div_two_sub, ← sin_pi_div_two_sub]
apply sin_lt_sin_of_lt_of_le_pi_div_two <;> linarith
theorem cos_lt_cos_of_nonneg_of_le_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π / 2)
(hxy : x < y) : cos y < cos x :=
cos_lt_cos_of_nonneg_of_le_pi hx₁ (hy₂.trans (by linarith)) hxy
theorem strictAntiOn_cos : StrictAntiOn cos (Icc 0 π) := fun _ hx _ hy hxy =>
cos_lt_cos_of_nonneg_of_le_pi hx.1 hy.2 hxy
theorem cos_le_cos_of_nonneg_of_le_pi {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y ≤ π) (hxy : x ≤ y) :
cos y ≤ cos x :=
(strictAntiOn_cos.le_iff_le ⟨hx₁.trans hxy, hy₂⟩ ⟨hx₁, hxy.trans hy₂⟩).2 hxy
theorem sin_le_sin_of_le_of_le_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) ≤ x) (hy₂ : y ≤ π / 2)
(hxy : x ≤ y) : sin x ≤ sin y :=
(strictMonoOn_sin.le_iff_le ⟨hx₁, hxy.trans hy₂⟩ ⟨hx₁.trans hxy, hy₂⟩).2 hxy
theorem injOn_sin : InjOn sin (Icc (-(π / 2)) (π / 2)) :=
strictMonoOn_sin.injOn
theorem injOn_cos : InjOn cos (Icc 0 π) :=
strictAntiOn_cos.injOn
theorem surjOn_sin : SurjOn sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) := by
simpa only [sin_neg, sin_pi_div_two] using
intermediate_value_Icc (neg_le_self pi_div_two_pos.le) continuous_sin.continuousOn
theorem surjOn_cos : SurjOn cos (Icc 0 π) (Icc (-1) 1) := by
simpa only [cos_zero, cos_pi] using intermediate_value_Icc' pi_pos.le continuous_cos.continuousOn
theorem sin_mem_Icc (x : ℝ) : sin x ∈ Icc (-1 : ℝ) 1 :=
⟨neg_one_le_sin x, sin_le_one x⟩
theorem cos_mem_Icc (x : ℝ) : cos x ∈ Icc (-1 : ℝ) 1 :=
⟨neg_one_le_cos x, cos_le_one x⟩
theorem mapsTo_sin (s : Set ℝ) : MapsTo sin s (Icc (-1 : ℝ) 1) := fun x _ => sin_mem_Icc x
theorem mapsTo_cos (s : Set ℝ) : MapsTo cos s (Icc (-1 : ℝ) 1) := fun x _ => cos_mem_Icc x
theorem bijOn_sin : BijOn sin (Icc (-(π / 2)) (π / 2)) (Icc (-1) 1) :=
⟨mapsTo_sin _, injOn_sin, surjOn_sin⟩
theorem bijOn_cos : BijOn cos (Icc 0 π) (Icc (-1) 1) :=
⟨mapsTo_cos _, injOn_cos, surjOn_cos⟩
@[simp]
theorem range_cos : range cos = (Icc (-1) 1 : Set ℝ) :=
Subset.antisymm (range_subset_iff.2 cos_mem_Icc) surjOn_cos.subset_range
@[simp]
theorem range_sin : range sin = (Icc (-1) 1 : Set ℝ) :=
Subset.antisymm (range_subset_iff.2 sin_mem_Icc) surjOn_sin.subset_range
theorem range_cos_infinite : (range Real.cos).Infinite := by
rw [Real.range_cos]
exact Icc_infinite (by norm_num)
theorem range_sin_infinite : (range Real.sin).Infinite := by
rw [Real.range_sin]
exact Icc_infinite (by norm_num)
section CosDivSq
variable (x : ℝ)
/-- the series `sqrtTwoAddSeries x n` is `sqrt(2 + sqrt(2 + ... ))` with `n` square roots,
starting with `x`. We define it here because `cos (pi / 2 ^ (n+1)) = sqrtTwoAddSeries 0 n / 2`
-/
@[simp]
noncomputable def sqrtTwoAddSeries (x : ℝ) : ℕ → ℝ
| 0 => x
| n + 1 => √(2 + sqrtTwoAddSeries x n)
theorem sqrtTwoAddSeries_zero : sqrtTwoAddSeries x 0 = x := by simp
theorem sqrtTwoAddSeries_one : sqrtTwoAddSeries 0 1 = √2 := by simp
theorem sqrtTwoAddSeries_two : sqrtTwoAddSeries 0 2 = √(2 + √2) := by simp
theorem sqrtTwoAddSeries_zero_nonneg : ∀ n : ℕ, 0 ≤ sqrtTwoAddSeries 0 n
| 0 => le_refl 0
| _ + 1 => sqrt_nonneg _
theorem sqrtTwoAddSeries_nonneg {x : ℝ} (h : 0 ≤ x) : ∀ n : ℕ, 0 ≤ sqrtTwoAddSeries x n
| 0 => h
| _ + 1 => sqrt_nonneg _
theorem sqrtTwoAddSeries_lt_two : ∀ n : ℕ, sqrtTwoAddSeries 0 n < 2
| 0 => by norm_num
| n + 1 => by
refine lt_of_lt_of_le ?_ (sqrt_sq zero_lt_two.le).le
rw [sqrtTwoAddSeries, sqrt_lt_sqrt_iff, ← lt_sub_iff_add_lt']
· refine (sqrtTwoAddSeries_lt_two n).trans_le ?_
norm_num
· exact add_nonneg zero_le_two (sqrtTwoAddSeries_zero_nonneg n)
theorem sqrtTwoAddSeries_succ (x : ℝ) :
∀ n : ℕ, sqrtTwoAddSeries x (n + 1) = sqrtTwoAddSeries (√(2 + x)) n
| 0 => rfl
| n + 1 => by rw [sqrtTwoAddSeries, sqrtTwoAddSeries_succ _ _, sqrtTwoAddSeries]
theorem sqrtTwoAddSeries_monotone_left {x y : ℝ} (h : x ≤ y) :
∀ n : ℕ, sqrtTwoAddSeries x n ≤ sqrtTwoAddSeries y n
| 0 => h
| n + 1 => by
rw [sqrtTwoAddSeries, sqrtTwoAddSeries]
exact sqrt_le_sqrt (add_le_add_left (sqrtTwoAddSeries_monotone_left h _) _)
@[simp]
theorem cos_pi_over_two_pow : ∀ n : ℕ, cos (π / 2 ^ (n + 1)) = sqrtTwoAddSeries 0 n / 2
| 0 => by simp
| n + 1 => by
have A : (1 : ℝ) < 2 ^ (n + 1) := one_lt_pow one_lt_two n.succ_ne_zero
have B : π / 2 ^ (n + 1) < π := div_lt_self pi_pos A
have C : 0 < π / 2 ^ (n + 1) := by positivity
rw [pow_succ, div_mul_eq_div_div, cos_half, cos_pi_over_two_pow n, sqrtTwoAddSeries,
add_div_eq_mul_add_div, one_mul, ← div_mul_eq_div_div, sqrt_div, sqrt_mul_self] <;>
linarith [sqrtTwoAddSeries_nonneg le_rfl n]
theorem sin_sq_pi_over_two_pow (n : ℕ) :
sin (π / 2 ^ (n + 1)) ^ 2 = 1 - (sqrtTwoAddSeries 0 n / 2) ^ 2 := by
rw [sin_sq, cos_pi_over_two_pow]
theorem sin_sq_pi_over_two_pow_succ (n : ℕ) :
sin (π / 2 ^ (n + 2)) ^ 2 = 1 / 2 - sqrtTwoAddSeries 0 n / 4 := by
rw [sin_sq_pi_over_two_pow, sqrtTwoAddSeries, div_pow, sq_sqrt, add_div, ← sub_sub]
· congr
· norm_num
· norm_num
· exact add_nonneg two_pos.le (sqrtTwoAddSeries_zero_nonneg _)
@[simp]
theorem sin_pi_over_two_pow_succ (n : ℕ) :
sin (π / 2 ^ (n + 2)) = √(2 - sqrtTwoAddSeries 0 n) / 2 := by
rw [eq_div_iff_mul_eq two_ne_zero, eq_comm, sqrt_eq_iff_sq_eq, mul_pow,
sin_sq_pi_over_two_pow_succ, sub_mul]
· congr <;> norm_num
· rw [sub_nonneg]
exact (sqrtTwoAddSeries_lt_two _).le
refine mul_nonneg (sin_nonneg_of_nonneg_of_le_pi ?_ ?_) zero_le_two
· positivity
· exact div_le_self pi_pos.le <| one_le_pow_of_one_le one_le_two _
@[simp]
theorem cos_pi_div_four : cos (π / 4) = √2 / 2 := by
trans cos (π / 2 ^ 2)
· congr
norm_num
· simp
@[simp]
theorem sin_pi_div_four : sin (π / 4) = √2 / 2 := by
trans sin (π / 2 ^ 2)
· congr
norm_num
· simp
@[simp]
theorem cos_pi_div_eight : cos (π / 8) = √(2 + √2) / 2 := by
trans cos (π / 2 ^ 3)
· congr
norm_num
· simp
@[simp]
theorem sin_pi_div_eight : sin (π / 8) = √(2 - √2) / 2 := by
trans sin (π / 2 ^ 3)
· congr
norm_num
· simp
@[simp]
theorem cos_pi_div_sixteen : cos (π / 16) = √(2 + √(2 + √2)) / 2 := by
trans cos (π / 2 ^ 4)
· congr
norm_num
· simp
@[simp]
theorem sin_pi_div_sixteen : sin (π / 16) = √(2 - √(2 + √2)) / 2 := by
trans sin (π / 2 ^ 4)
· congr
norm_num
· simp
@[simp]
theorem cos_pi_div_thirty_two : cos (π / 32) = √(2 + √(2 + √(2 + √2))) / 2 := by
trans cos (π / 2 ^ 5)
· congr
norm_num
· simp
@[simp]
theorem sin_pi_div_thirty_two : sin (π / 32) = √(2 - √(2 + √(2 + √2))) / 2 := by
trans sin (π / 2 ^ 5)
· congr
norm_num
· simp
-- This section is also a convenient location for other explicit values of `sin` and `cos`.
/-- The cosine of `π / 3` is `1 / 2`. -/
@[simp]
theorem cos_pi_div_three : cos (π / 3) = 1 / 2 := by
have h₁ : (2 * cos (π / 3) - 1) ^ 2 * (2 * cos (π / 3) + 2) = 0 := by
have : cos (3 * (π / 3)) = cos π := by
congr 1
ring
linarith [cos_pi, cos_three_mul (π / 3)]
cases' mul_eq_zero.mp h₁ with h h
· linarith [pow_eq_zero h]
· have : cos π < cos (π / 3) := by
refine cos_lt_cos_of_nonneg_of_le_pi ?_ le_rfl ?_ <;> linarith [pi_pos]
linarith [cos_pi]
/-- The cosine of `π / 6` is `√3 / 2`. -/
@[simp]
theorem cos_pi_div_six : cos (π / 6) = √3 / 2 := by
rw [show (6 : ℝ) = 3 * 2 by norm_num, div_mul_eq_div_div, cos_half, cos_pi_div_three, one_add_div,
← div_mul_eq_div_div, two_add_one_eq_three, sqrt_div, sqrt_mul_self] <;> linarith [pi_pos]
/-- The square of the cosine of `π / 6` is `3 / 4` (this is sometimes more convenient than the
result for cosine itself). -/
theorem sq_cos_pi_div_six : cos (π / 6) ^ 2 = 3 / 4 := by
rw [cos_pi_div_six, div_pow, sq_sqrt] <;> norm_num
/-- The sine of `π / 6` is `1 / 2`. -/
@[simp]
theorem sin_pi_div_six : sin (π / 6) = 1 / 2 := by
rw [← cos_pi_div_two_sub, ← cos_pi_div_three]
congr
ring
/-- The square of the sine of `π / 3` is `3 / 4` (this is sometimes more convenient than the
result for cosine itself). -/
theorem sq_sin_pi_div_three : sin (π / 3) ^ 2 = 3 / 4 := by
rw [← cos_pi_div_two_sub, ← sq_cos_pi_div_six]
congr
ring
/-- The sine of `π / 3` is `√3 / 2`. -/
@[simp]
theorem sin_pi_div_three : sin (π / 3) = √3 / 2 := by
rw [← cos_pi_div_two_sub, ← cos_pi_div_six]
congr
ring
end CosDivSq
/-- `Real.sin` as an `OrderIso` between `[-(π / 2), π / 2]` and `[-1, 1]`. -/
def sinOrderIso : Icc (-(π / 2)) (π / 2) ≃o Icc (-1 : ℝ) 1 :=
(strictMonoOn_sin.orderIso _ _).trans <| OrderIso.setCongr _ _ bijOn_sin.image_eq
@[simp]
theorem coe_sinOrderIso_apply (x : Icc (-(π / 2)) (π / 2)) : (sinOrderIso x : ℝ) = sin x :=
rfl
theorem sinOrderIso_apply (x : Icc (-(π / 2)) (π / 2)) : sinOrderIso x = ⟨sin x, sin_mem_Icc x⟩ :=
rfl
@[simp]
theorem tan_pi_div_four : tan (π / 4) = 1 := by
rw [tan_eq_sin_div_cos, cos_pi_div_four, sin_pi_div_four]
have h : √2 / 2 > 0 := by positivity
exact div_self (ne_of_gt h)
@[simp]
theorem tan_pi_div_two : tan (π / 2) = 0 := by simp [tan_eq_sin_div_cos]
@[simp]
theorem tan_pi_div_six : tan (π / 6) = 1 / sqrt 3 := by
rw [tan_eq_sin_div_cos, sin_pi_div_six, cos_pi_div_six]
ring
@[simp]
theorem tan_pi_div_three : tan (π / 3) = sqrt 3 := by
rw [tan_eq_sin_div_cos, sin_pi_div_three, cos_pi_div_three]
ring
theorem tan_pos_of_pos_of_lt_pi_div_two {x : ℝ} (h0x : 0 < x) (hxp : x < π / 2) : 0 < tan x := by
rw [tan_eq_sin_div_cos]
exact div_pos (sin_pos_of_pos_of_lt_pi h0x (by linarith)) (cos_pos_of_mem_Ioo ⟨by linarith, hxp⟩)
theorem tan_nonneg_of_nonneg_of_le_pi_div_two {x : ℝ} (h0x : 0 ≤ x) (hxp : x ≤ π / 2) : 0 ≤ tan x :=
match lt_or_eq_of_le h0x, lt_or_eq_of_le hxp with
| Or.inl hx0, Or.inl hxp => le_of_lt (tan_pos_of_pos_of_lt_pi_div_two hx0 hxp)
| Or.inl _, Or.inr hxp => by simp [hxp, tan_eq_sin_div_cos]
| Or.inr hx0, _ => by simp [hx0.symm]
theorem tan_neg_of_neg_of_pi_div_two_lt {x : ℝ} (hx0 : x < 0) (hpx : -(π / 2) < x) : tan x < 0 :=
neg_pos.1 (tan_neg x ▸ tan_pos_of_pos_of_lt_pi_div_two (by linarith) (by linarith [pi_pos]))
theorem tan_nonpos_of_nonpos_of_neg_pi_div_two_le {x : ℝ} (hx0 : x ≤ 0) (hpx : -(π / 2) ≤ x) :
tan x ≤ 0 :=
neg_nonneg.1 (tan_neg x ▸ tan_nonneg_of_nonneg_of_le_pi_div_two (by linarith) (by linarith))
theorem strictMonoOn_tan : StrictMonoOn tan (Ioo (-(π / 2)) (π / 2)) := by
rintro x hx y hy hlt
rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos,
div_lt_div_iff (cos_pos_of_mem_Ioo hx) (cos_pos_of_mem_Ioo hy), mul_comm, ← sub_pos, ← sin_sub]
exact sin_pos_of_pos_of_lt_pi (sub_pos.2 hlt) <| by linarith [hx.1, hy.2]
theorem tan_lt_tan_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hy₂ : y < π / 2)
(hxy : x < y) : tan x < tan y :=
strictMonoOn_tan ⟨hx₁, hxy.trans hy₂⟩ ⟨hx₁.trans hxy, hy₂⟩ hxy
theorem tan_lt_tan_of_nonneg_of_lt_pi_div_two {x y : ℝ} (hx₁ : 0 ≤ x) (hy₂ : y < π / 2)
(hxy : x < y) : tan x < tan y :=
tan_lt_tan_of_lt_of_lt_pi_div_two (by linarith) hy₂ hxy
theorem injOn_tan : InjOn tan (Ioo (-(π / 2)) (π / 2)) :=
strictMonoOn_tan.injOn
theorem tan_inj_of_lt_of_lt_pi_div_two {x y : ℝ} (hx₁ : -(π / 2) < x) (hx₂ : x < π / 2)
(hy₁ : -(π / 2) < y) (hy₂ : y < π / 2) (hxy : tan x = tan y) : x = y :=
injOn_tan ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩ hxy
theorem tan_periodic : Function.Periodic tan π := by
simpa only [Function.Periodic, tan_eq_sin_div_cos] using sin_antiperiodic.div cos_antiperiodic
@[simp]
theorem tan_pi : tan π = 0 := by rw [tan_periodic.eq, tan_zero]
theorem tan_add_pi (x : ℝ) : tan (x + π) = tan x :=
tan_periodic x
theorem tan_sub_pi (x : ℝ) : tan (x - π) = tan x :=
tan_periodic.sub_eq x
theorem tan_pi_sub (x : ℝ) : tan (π - x) = -tan x :=
tan_neg x ▸ tan_periodic.sub_eq'
theorem tan_pi_div_two_sub (x : ℝ) : tan (π / 2 - x) = (tan x)⁻¹ := by
rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, inv_div, sin_pi_div_two_sub, cos_pi_div_two_sub]
theorem tan_nat_mul_pi (n : ℕ) : tan (n * π) = 0 :=
tan_zero ▸ tan_periodic.nat_mul_eq n
theorem tan_int_mul_pi (n : ℤ) : tan (n * π) = 0 :=
tan_zero ▸ tan_periodic.int_mul_eq n
theorem tan_add_nat_mul_pi (x : ℝ) (n : ℕ) : tan (x + n * π) = tan x :=
tan_periodic.nat_mul n x
theorem tan_add_int_mul_pi (x : ℝ) (n : ℤ) : tan (x + n * π) = tan x :=
tan_periodic.int_mul n x
theorem tan_sub_nat_mul_pi (x : ℝ) (n : ℕ) : tan (x - n * π) = tan x :=
tan_periodic.sub_nat_mul_eq n
theorem tan_sub_int_mul_pi (x : ℝ) (n : ℤ) : tan (x - n * π) = tan x :=
tan_periodic.sub_int_mul_eq n
theorem tan_nat_mul_pi_sub (x : ℝ) (n : ℕ) : tan (n * π - x) = -tan x :=
tan_neg x ▸ tan_periodic.nat_mul_sub_eq n
theorem tan_int_mul_pi_sub (x : ℝ) (n : ℤ) : tan (n * π - x) = -tan x :=
tan_neg x ▸ tan_periodic.int_mul_sub_eq n
theorem tendsto_sin_pi_div_two : Tendsto sin (𝓝[<] (π / 2)) (𝓝 1) := by
convert continuous_sin.continuousWithinAt.tendsto
simp
theorem tendsto_cos_pi_div_two : Tendsto cos (𝓝[<] (π / 2)) (𝓝[>] 0) := by
apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within
· convert continuous_cos.continuousWithinAt.tendsto
simp
· filter_upwards [Ioo_mem_nhdsWithin_Iio
(right_mem_Ioc.mpr (neg_lt_self pi_div_two_pos))] with x hx using cos_pos_of_mem_Ioo hx
theorem tendsto_tan_pi_div_two : Tendsto tan (𝓝[<] (π / 2)) atTop := by
convert tendsto_cos_pi_div_two.inv_tendsto_zero.atTop_mul zero_lt_one tendsto_sin_pi_div_two
using 1
simp only [Pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos]
theorem tendsto_sin_neg_pi_div_two : Tendsto sin (𝓝[>] (-(π / 2))) (𝓝 (-1)) := by
convert continuous_sin.continuousWithinAt.tendsto using 2
simp
theorem tendsto_cos_neg_pi_div_two : Tendsto cos (𝓝[>] (-(π / 2))) (𝓝[>] 0) := by
apply tendsto_nhdsWithin_of_tendsto_nhds_of_eventually_within
· convert continuous_cos.continuousWithinAt.tendsto
simp
· filter_upwards [Ioo_mem_nhdsWithin_Ioi
(left_mem_Ico.mpr (neg_lt_self pi_div_two_pos))] with x hx using cos_pos_of_mem_Ioo hx
theorem tendsto_tan_neg_pi_div_two : Tendsto tan (𝓝[>] (-(π / 2))) atBot := by
convert tendsto_cos_neg_pi_div_two.inv_tendsto_zero.atTop_mul_neg (by norm_num)
tendsto_sin_neg_pi_div_two using 1
simp only [Pi.inv_apply, ← div_eq_inv_mul, ← tan_eq_sin_div_cos]
end Real
namespace Complex
open Real
theorem sin_eq_zero_iff_cos_eq {z : ℂ} : sin z = 0 ↔ cos z = 1 ∨ cos z = -1 := by
rw [← mul_self_eq_one_iff, ← sin_sq_add_cos_sq, sq, sq, ← sub_eq_iff_eq_add, sub_self]
exact ⟨fun h => by rw [h, mul_zero], eq_zero_of_mul_self_eq_zero ∘ Eq.symm⟩
@[simp]
theorem cos_pi_div_two : cos (π / 2) = 0 :=
calc
cos (π / 2) = Real.cos (π / 2) := by rw [ofReal_cos]; simp
_ = 0 := by simp
@[simp]
theorem sin_pi_div_two : sin (π / 2) = 1 :=
calc
sin (π / 2) = Real.sin (π / 2) := by rw [ofReal_sin]; simp
_ = 1 := by simp
@[simp]
theorem sin_pi : sin π = 0 := by rw [← ofReal_sin, Real.sin_pi]; simp
@[simp]
theorem cos_pi : cos π = -1 := by rw [← ofReal_cos, Real.cos_pi]; simp
@[simp]
theorem sin_two_pi : sin (2 * π) = 0 := by simp [two_mul, sin_add]
@[simp]
theorem cos_two_pi : cos (2 * π) = 1 := by simp [two_mul, cos_add]
theorem sin_antiperiodic : Function.Antiperiodic sin π := by simp [sin_add]
theorem sin_periodic : Function.Periodic sin (2 * π) :=
sin_antiperiodic.periodic_two_mul
theorem sin_add_pi (x : ℂ) : sin (x + π) = -sin x :=
sin_antiperiodic x
theorem sin_add_two_pi (x : ℂ) : sin (x + 2 * π) = sin x :=
sin_periodic x
theorem sin_sub_pi (x : ℂ) : sin (x - π) = -sin x :=
sin_antiperiodic.sub_eq x
theorem sin_sub_two_pi (x : ℂ) : sin (x - 2 * π) = sin x :=
sin_periodic.sub_eq x
theorem sin_pi_sub (x : ℂ) : sin (π - x) = sin x :=
neg_neg (sin x) ▸ sin_neg x ▸ sin_antiperiodic.sub_eq'
theorem sin_two_pi_sub (x : ℂ) : sin (2 * π - x) = -sin x :=
sin_neg x ▸ sin_periodic.sub_eq'
theorem sin_nat_mul_pi (n : ℕ) : sin (n * π) = 0 :=
sin_antiperiodic.nat_mul_eq_of_eq_zero sin_zero n
theorem sin_int_mul_pi (n : ℤ) : sin (n * π) = 0 :=
sin_antiperiodic.int_mul_eq_of_eq_zero sin_zero n
theorem sin_add_nat_mul_two_pi (x : ℂ) (n : ℕ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.nat_mul n x
theorem sin_add_int_mul_two_pi (x : ℂ) (n : ℤ) : sin (x + n * (2 * π)) = sin x :=
sin_periodic.int_mul n x
theorem sin_sub_nat_mul_two_pi (x : ℂ) (n : ℕ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_nat_mul_eq n
theorem sin_sub_int_mul_two_pi (x : ℂ) (n : ℤ) : sin (x - n * (2 * π)) = sin x :=
sin_periodic.sub_int_mul_eq n
theorem sin_nat_mul_two_pi_sub (x : ℂ) (n : ℕ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.nat_mul_sub_eq n
theorem sin_int_mul_two_pi_sub (x : ℂ) (n : ℤ) : sin (n * (2 * π) - x) = -sin x :=
sin_neg x ▸ sin_periodic.int_mul_sub_eq n
theorem cos_antiperiodic : Function.Antiperiodic cos π := by simp [cos_add]
theorem cos_periodic : Function.Periodic cos (2 * π) :=
cos_antiperiodic.periodic_two_mul
theorem cos_add_pi (x : ℂ) : cos (x + π) = -cos x :=
cos_antiperiodic x
theorem cos_add_two_pi (x : ℂ) : cos (x + 2 * π) = cos x :=
cos_periodic x
theorem cos_sub_pi (x : ℂ) : cos (x - π) = -cos x :=
cos_antiperiodic.sub_eq x
theorem cos_sub_two_pi (x : ℂ) : cos (x - 2 * π) = cos x :=
cos_periodic.sub_eq x
theorem cos_pi_sub (x : ℂ) : cos (π - x) = -cos x :=
cos_neg x ▸ cos_antiperiodic.sub_eq'
theorem cos_two_pi_sub (x : ℂ) : cos (2 * π - x) = cos x :=
cos_neg x ▸ cos_periodic.sub_eq'
theorem cos_nat_mul_two_pi (n : ℕ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.nat_mul_eq n).trans cos_zero
theorem cos_int_mul_two_pi (n : ℤ) : cos (n * (2 * π)) = 1 :=
(cos_periodic.int_mul_eq n).trans cos_zero
theorem cos_add_nat_mul_two_pi (x : ℂ) (n : ℕ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.nat_mul n x
theorem cos_add_int_mul_two_pi (x : ℂ) (n : ℤ) : cos (x + n * (2 * π)) = cos x :=
cos_periodic.int_mul n x
theorem cos_sub_nat_mul_two_pi (x : ℂ) (n : ℕ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_nat_mul_eq n
theorem cos_sub_int_mul_two_pi (x : ℂ) (n : ℤ) : cos (x - n * (2 * π)) = cos x :=
cos_periodic.sub_int_mul_eq n
theorem cos_nat_mul_two_pi_sub (x : ℂ) (n : ℕ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.nat_mul_sub_eq n
theorem cos_int_mul_two_pi_sub (x : ℂ) (n : ℤ) : cos (n * (2 * π) - x) = cos x :=
cos_neg x ▸ cos_periodic.int_mul_sub_eq n
theorem cos_nat_mul_two_pi_add_pi (n : ℕ) : cos (n * (2 * π) + π) = -1 := by
simpa only [cos_zero] using (cos_periodic.nat_mul n).add_antiperiod_eq cos_antiperiodic
theorem cos_int_mul_two_pi_add_pi (n : ℤ) : cos (n * (2 * π) + π) = -1 := by
simpa only [cos_zero] using (cos_periodic.int_mul n).add_antiperiod_eq cos_antiperiodic
theorem cos_nat_mul_two_pi_sub_pi (n : ℕ) : cos (n * (2 * π) - π) = -1 := by
simpa only [cos_zero] using (cos_periodic.nat_mul n).sub_antiperiod_eq cos_antiperiodic
theorem cos_int_mul_two_pi_sub_pi (n : ℤ) : cos (n * (2 * π) - π) = -1 := by
simpa only [cos_zero] using (cos_periodic.int_mul n).sub_antiperiod_eq cos_antiperiodic
theorem sin_add_pi_div_two (x : ℂ) : sin (x + π / 2) = cos x := by simp [sin_add]
theorem sin_sub_pi_div_two (x : ℂ) : sin (x - π / 2) = -cos x := by simp [sub_eq_add_neg, sin_add]
theorem sin_pi_div_two_sub (x : ℂ) : sin (π / 2 - x) = cos x := by simp [sub_eq_add_neg, sin_add]
theorem cos_add_pi_div_two (x : ℂ) : cos (x + π / 2) = -sin x := by simp [cos_add]
theorem cos_sub_pi_div_two (x : ℂ) : cos (x - π / 2) = sin x := by simp [sub_eq_add_neg, cos_add]
theorem cos_pi_div_two_sub (x : ℂ) : cos (π / 2 - x) = sin x := by
rw [← cos_neg, neg_sub, cos_sub_pi_div_two]
theorem tan_periodic : Function.Periodic tan π := by
simpa only [tan_eq_sin_div_cos] using sin_antiperiodic.div cos_antiperiodic
theorem tan_add_pi (x : ℂ) : tan (x + π) = tan x :=
tan_periodic x
theorem tan_sub_pi (x : ℂ) : tan (x - π) = tan x :=
tan_periodic.sub_eq x
theorem tan_pi_sub (x : ℂ) : tan (π - x) = -tan x :=
tan_neg x ▸ tan_periodic.sub_eq'
theorem tan_pi_div_two_sub (x : ℂ) : tan (π / 2 - x) = (tan x)⁻¹ := by
rw [tan_eq_sin_div_cos, tan_eq_sin_div_cos, inv_div, sin_pi_div_two_sub, cos_pi_div_two_sub]
theorem tan_nat_mul_pi (n : ℕ) : tan (n * π) = 0 :=
tan_zero ▸ tan_periodic.nat_mul_eq n
theorem tan_int_mul_pi (n : ℤ) : tan (n * π) = 0 :=
tan_zero ▸ tan_periodic.int_mul_eq n
theorem tan_add_nat_mul_pi (x : ℂ) (n : ℕ) : tan (x + n * π) = tan x :=
tan_periodic.nat_mul n x
theorem tan_add_int_mul_pi (x : ℂ) (n : ℤ) : tan (x + n * π) = tan x :=
tan_periodic.int_mul n x
theorem tan_sub_nat_mul_pi (x : ℂ) (n : ℕ) : tan (x - n * π) = tan x :=
tan_periodic.sub_nat_mul_eq n
theorem tan_sub_int_mul_pi (x : ℂ) (n : ℤ) : tan (x - n * π) = tan x :=
tan_periodic.sub_int_mul_eq n
theorem tan_nat_mul_pi_sub (x : ℂ) (n : ℕ) : tan (n * π - x) = -tan x :=
tan_neg x ▸ tan_periodic.nat_mul_sub_eq n
theorem tan_int_mul_pi_sub (x : ℂ) (n : ℤ) : tan (n * π - x) = -tan x :=
tan_neg x ▸ tan_periodic.int_mul_sub_eq n
theorem exp_antiperiodic : Function.Antiperiodic exp (π * I) := by simp [exp_add, exp_mul_I]
theorem exp_periodic : Function.Periodic exp (2 * π * I) :=
(mul_assoc (2 : ℂ) π I).symm ▸ exp_antiperiodic.periodic_two_mul
theorem exp_mul_I_antiperiodic : Function.Antiperiodic (fun x => exp (x * I)) π := by
simpa only [mul_inv_cancel_right₀ I_ne_zero] using exp_antiperiodic.mul_const I_ne_zero
theorem exp_mul_I_periodic : Function.Periodic (fun x => exp (x * I)) (2 * π) :=
exp_mul_I_antiperiodic.periodic_two_mul
@[simp]
theorem exp_pi_mul_I : exp (π * I) = -1 :=
exp_zero ▸ exp_antiperiodic.eq
@[simp]
theorem exp_two_pi_mul_I : exp (2 * π * I) = 1 :=
exp_periodic.eq.trans exp_zero
@[simp]
theorem exp_nat_mul_two_pi_mul_I (n : ℕ) : exp (n * (2 * π * I)) = 1 :=
(exp_periodic.nat_mul_eq n).trans exp_zero
@[simp]
theorem exp_int_mul_two_pi_mul_I (n : ℤ) : exp (n * (2 * π * I)) = 1 :=
(exp_periodic.int_mul_eq n).trans exp_zero
@[simp]
theorem exp_add_pi_mul_I (z : ℂ) : exp (z + π * I) = -exp z :=
exp_antiperiodic z
@[simp]
theorem exp_sub_pi_mul_I (z : ℂ) : exp (z - π * I) = -exp z :=
exp_antiperiodic.sub_eq z
/-- A supporting lemma for the **Phragmen-Lindelöf principle** in a horizontal strip. If `z : ℂ`
belongs to a horizontal strip `|Complex.im z| ≤ b`, `b ≤ π / 2`, and `a ≤ 0`, then
$$\left|exp^{a\left(e^{z}+e^{-z}\right)}\right| \le e^{a\cos b \exp^{|re z|}}.$$
-/
theorem abs_exp_mul_exp_add_exp_neg_le_of_abs_im_le {a b : ℝ} (ha : a ≤ 0) {z : ℂ} (hz : |z.im| ≤ b)
(hb : b ≤ π / 2) :
abs (exp (a * (exp z + exp (-z)))) ≤ Real.exp (a * Real.cos b * Real.exp |z.re|) := by
simp only [abs_exp, Real.exp_le_exp, re_ofReal_mul, add_re, exp_re, neg_im, Real.cos_neg, ←
add_mul, mul_assoc, mul_comm (Real.cos b), neg_re, ← Real.cos_abs z.im]
have : Real.exp |z.re| ≤ Real.exp z.re + Real.exp (-z.re) :=
apply_abs_le_add_of_nonneg (fun x => (Real.exp_pos x).le) z.re
refine mul_le_mul_of_nonpos_left (mul_le_mul this ?_ ?_ ((Real.exp_pos _).le.trans this)) ha
· exact
Real.cos_le_cos_of_nonneg_of_le_pi (_root_.abs_nonneg _)
(hb.trans <| half_le_self <| Real.pi_pos.le) hz
· refine Real.cos_nonneg_of_mem_Icc ⟨?_, hb⟩
exact (neg_nonpos.2 <| Real.pi_div_two_pos.le).trans ((_root_.abs_nonneg _).trans hz)
end Complex
|
Analysis\SpecialFunctions\Trigonometric\Bounds.lean | /-
Copyright (c) 2022 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler, Yaël Dillies
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.ArctanDeriv
/-!
# Polynomial bounds for trigonometric functions
## Main statements
This file contains upper and lower bounds for real trigonometric functions in terms
of polynomials. See `Trigonometric.Basic` for more elementary inequalities, establishing
the ranges of these functions, and their monotonicity in suitable intervals.
Here we prove the following:
* `sin_lt`: for `x > 0` we have `sin x < x`.
* `sin_gt_sub_cube`: For `0 < x ≤ 1` we have `x - x ^ 3 / 4 < sin x`.
* `lt_tan`: for `0 < x < π/2` we have `x < tan x`.
* `cos_le_one_div_sqrt_sq_add_one` and `cos_lt_one_div_sqrt_sq_add_one`: for
`-3 * π / 2 ≤ x ≤ 3 * π / 2`, we have `cos x ≤ 1 / sqrt (x ^ 2 + 1)`, with strict inequality if
`x ≠ 0`. (This bound is not quite optimal, but not far off)
## Tags
sin, cos, tan, angle
-/
open Set
namespace Real
variable {x : ℝ}
/-- For 0 < x, we have sin x < x. -/
theorem sin_lt (h : 0 < x) : sin x < x := by
cases' lt_or_le 1 x with h' h'
· exact (sin_le_one x).trans_lt h'
have hx : |x| = x := abs_of_nonneg h.le
have := le_of_abs_le (sin_bound <| show |x| ≤ 1 by rwa [hx])
rw [sub_le_iff_le_add', hx] at this
apply this.trans_lt
rw [sub_add, sub_lt_self_iff, sub_pos, div_eq_mul_inv (x ^ 3)]
refine mul_lt_mul' ?_ (by norm_num) (by norm_num) (pow_pos h 3)
apply pow_le_pow_of_le_one h.le h'
norm_num
lemma sin_le (hx : 0 ≤ x) : sin x ≤ x := by
obtain rfl | hx := hx.eq_or_lt
· simp
· exact (sin_lt hx).le
lemma lt_sin (hx : x < 0) : x < sin x := by simpa using sin_lt <| neg_pos.2 hx
lemma le_sin (hx : x ≤ 0) : x ≤ sin x := by simpa using sin_le <| neg_nonneg.2 hx
lemma one_sub_sq_div_two_le_cos : 1 - x ^ 2 / 2 ≤ cos x := by
wlog hx₀ : 0 ≤ x
· simpa using this $ neg_nonneg.2 $ le_of_not_le hx₀
suffices MonotoneOn (fun x ↦ cos x + x ^ 2 / 2) (Ici 0) by
simpa using this left_mem_Ici hx₀ hx₀
refine monotoneOn_of_hasDerivWithinAt_nonneg
(convex_Ici _) (by fun_prop)
(fun x _ ↦ ((hasDerivAt_cos ..).add <| (hasDerivAt_pow ..).div_const _).hasDerivWithinAt)
fun x hx ↦ ?_
simpa [mul_div_cancel_left₀] using sin_le <| interior_subset hx
/-- **Jordan's inequality**. -/
lemma two_div_pi_mul_le_sin (hx₀ : 0 ≤ x) (hx : x ≤ π / 2) : 2 / π * x ≤ sin x := by
rw [← sub_nonneg]
suffices ConcaveOn ℝ (Icc 0 (π / 2)) (fun x ↦ sin x - 2 / π * x) by
refine (le_min ?_ ?_).trans $ this.min_le_of_mem_Icc ⟨hx₀, hx⟩ <;> field_simp
exact concaveOn_of_hasDerivWithinAt2_nonpos (convex_Icc ..)
(Continuous.continuousOn $ by fun_prop)
(fun x _ ↦ ((hasDerivAt_sin ..).sub $ (hasDerivAt_id ..).const_mul (2 / π)).hasDerivWithinAt)
(fun x _ ↦ (hasDerivAt_cos ..).hasDerivWithinAt.sub_const _)
fun x hx ↦ neg_nonpos.2 $ sin_nonneg_of_mem_Icc $ Icc_subset_Icc_right (by linarith) $
interior_subset hx
/-- **Jordan's inequality** for negative values. -/
lemma sin_le_two_div_pi_mul (hx : -(π / 2) ≤ x) (hx₀ : x ≤ 0) : sin x ≤ 2 / π * x := by
simpa using two_div_pi_mul_le_sin (neg_nonneg.2 hx₀) (neg_le.2 hx)
/-- **Jordan's inequality** for `cos`. -/
lemma one_sub_two_div_pi_mul_le_cos (hx₀ : 0 ≤ x) (hx : x ≤ π / 2) : 1 - 2 / π * x ≤ cos x := by
simpa [sin_pi_div_two_sub, mul_sub, div_mul_div_comm, mul_comm π, div_self two_pi_pos.ne']
using two_div_pi_mul_le_sin (x := π / 2 - x) (by simpa) (by simpa)
lemma cos_quadratic_upper_bound (hx : |x| ≤ π) : cos x ≤ 1 - 2 / π ^ 2 * x ^ 2 := by
wlog hx₀ : 0 ≤ x
· simpa using this (by rwa [abs_neg]) $ neg_nonneg.2 $ le_of_not_le hx₀
rw [abs_of_nonneg hx₀] at hx
-- TODO: `compute_deriv` tactic?
have hderiv (x) : HasDerivAt (fun x ↦ 1 - 2 / π ^ 2 * x ^ 2 - cos x) _ x :=
(((hasDerivAt_pow ..).const_mul _).const_sub _).sub $ hasDerivAt_cos _
simp only [Nat.cast_ofNat, Nat.succ_sub_succ_eq_sub, tsub_zero, pow_one, ← neg_sub', neg_sub,
← mul_assoc] at hderiv
have hmono : MonotoneOn (fun x ↦ 1 - 2 / π ^ 2 * x ^ 2 - cos x) (Icc 0 (π / 2)) := by
-- Compiles without this option, but somewhat slower.
set_option tactic.skipAssignedInstances false in
refine monotoneOn_of_hasDerivWithinAt_nonneg
(convex_Icc ..)
(Continuous.continuousOn $ by fun_prop)
(fun x _ ↦ (hderiv _).hasDerivWithinAt)
fun x hx ↦ sub_nonneg.2 ?_
have ⟨hx₀, hx⟩ := interior_subset hx
calc 2 / π ^ 2 * 2 * x
= 2 / π * (2 / π * x) := by ring
_ ≤ 1 * sin x := by
gcongr; exacts [div_le_one_of_le two_le_pi (by positivity), two_div_pi_mul_le_sin hx₀ hx]
_ = sin x := one_mul _
have hconc : ConcaveOn ℝ (Icc (π / 2) π) (fun x ↦ 1 - 2 / π ^ 2 * x ^ 2 - cos x) := by
-- Compiles without this option, but somewhat slower.
set_option tactic.skipAssignedInstances false in
refine concaveOn_of_hasDerivWithinAt2_nonpos (convex_Icc ..)
(Continuous.continuousOn $ by fun_prop) (fun x _ ↦ (hderiv _).hasDerivWithinAt)
(fun x _ ↦ ((hasDerivAt_sin ..).sub $ (hasDerivAt_id ..).const_mul _).hasDerivWithinAt)
fun x hx ↦ ?_
have ⟨hx, hx'⟩ := interior_subset hx
calc
_ ≤ (0 : ℝ) - 0 := by
gcongr
· exact cos_nonpos_of_pi_div_two_le_of_le hx $ hx'.trans $ by linarith
· positivity
_ = 0 := sub_zero _
rw [← sub_nonneg]
obtain hx' | hx' := le_total x (π / 2)
· simpa using hmono (left_mem_Icc.2 $ by positivity) ⟨hx₀, hx'⟩ hx₀
· refine (le_min ?_ ?_).trans $ hconc.min_le_of_mem_Icc ⟨hx', hx⟩ <;> field_simp <;> norm_num
/-- For 0 < x ≤ 1 we have x - x ^ 3 / 4 < sin x.
This is also true for x > 1, but it's nontrivial for x just above 1. This inequality is not
tight; the tighter inequality is sin x > x - x ^ 3 / 6 for all x > 0, but this inequality has
a simpler proof. -/
theorem sin_gt_sub_cube {x : ℝ} (h : 0 < x) (h' : x ≤ 1) : x - x ^ 3 / 4 < sin x := by
have hx : |x| = x := abs_of_nonneg h.le
have := neg_le_of_abs_le (sin_bound <| show |x| ≤ 1 by rwa [hx])
rw [le_sub_iff_add_le, hx] at this
refine lt_of_lt_of_le ?_ this
have : x ^ 3 / ↑4 - x ^ 3 / ↑6 = x ^ 3 * 12⁻¹ := by norm_num [div_eq_mul_inv, ← mul_sub]
rw [add_comm, sub_add, sub_neg_eq_add, sub_lt_sub_iff_left, ← lt_sub_iff_add_lt', this]
refine mul_lt_mul' ?_ (by norm_num) (by norm_num) (pow_pos h 3)
apply pow_le_pow_of_le_one h.le h'
norm_num
/-- The derivative of `tan x - x` is `1/(cos x)^2 - 1` away from the zeroes of cos. -/
theorem deriv_tan_sub_id (x : ℝ) (h : cos x ≠ 0) :
deriv (fun y : ℝ => tan y - y) x = 1 / cos x ^ 2 - 1 :=
HasDerivAt.deriv <| by simpa using (hasDerivAt_tan h).add (hasDerivAt_id x).neg
/-- For all `0 < x < π/2` we have `x < tan x`.
This is proved by checking that the function `tan x - x` vanishes
at zero and has non-negative derivative. -/
theorem lt_tan {x : ℝ} (h1 : 0 < x) (h2 : x < π / 2) : x < tan x := by
let U := Ico 0 (π / 2)
have intU : interior U = Ioo 0 (π / 2) := interior_Ico
have half_pi_pos : 0 < π / 2 := div_pos pi_pos two_pos
have cos_pos : ∀ {y : ℝ}, y ∈ U → 0 < cos y := by
intro y hy
exact cos_pos_of_mem_Ioo (Ico_subset_Ioo_left (neg_lt_zero.mpr half_pi_pos) hy)
have sin_pos : ∀ {y : ℝ}, y ∈ interior U → 0 < sin y := by
intro y hy
rw [intU] at hy
exact sin_pos_of_mem_Ioo (Ioo_subset_Ioo_right (div_le_self pi_pos.le one_le_two) hy)
have tan_cts_U : ContinuousOn tan U := by
apply ContinuousOn.mono continuousOn_tan
intro z hz
simp only [mem_setOf_eq]
exact (cos_pos hz).ne'
have tan_minus_id_cts : ContinuousOn (fun y : ℝ => tan y - y) U := tan_cts_U.sub continuousOn_id
have deriv_pos : ∀ y : ℝ, y ∈ interior U → 0 < deriv (fun y' : ℝ => tan y' - y') y := by
intro y hy
have := cos_pos (interior_subset hy)
simp only [deriv_tan_sub_id y this.ne', one_div, gt_iff_lt, sub_pos]
norm_cast
have bd2 : cos y ^ 2 < 1 := by
apply lt_of_le_of_ne y.cos_sq_le_one
rw [cos_sq']
simpa only [Ne, sub_eq_self, sq_eq_zero_iff] using (sin_pos hy).ne'
rwa [lt_inv, inv_one]
· exact zero_lt_one
simpa only [sq, mul_self_pos] using this.ne'
have mono := strictMonoOn_of_deriv_pos (convex_Ico 0 (π / 2)) tan_minus_id_cts deriv_pos
have zero_in_U : (0 : ℝ) ∈ U := by rwa [left_mem_Ico]
have x_in_U : x ∈ U := ⟨h1.le, h2⟩
simpa only [tan_zero, sub_zero, sub_pos] using mono zero_in_U x_in_U h1
theorem le_tan {x : ℝ} (h1 : 0 ≤ x) (h2 : x < π / 2) : x ≤ tan x := by
rcases eq_or_lt_of_le h1 with (rfl | h1')
· rw [tan_zero]
· exact le_of_lt (lt_tan h1' h2)
theorem cos_lt_one_div_sqrt_sq_add_one {x : ℝ} (hx1 : -(3 * π / 2) ≤ x) (hx2 : x ≤ 3 * π / 2)
(hx3 : x ≠ 0) : cos x < (1 / √(x ^ 2 + 1) : ℝ) := by
suffices ∀ {y : ℝ}, 0 < y → y ≤ 3 * π / 2 → cos y < 1 / sqrt (y ^ 2 + 1) by
rcases lt_or_lt_iff_ne.mpr hx3.symm with ⟨h⟩
· exact this h hx2
· convert this (by linarith : 0 < -x) (by linarith) using 1
· rw [cos_neg]
· rw [neg_sq]
intro y hy1 hy2
have hy3 : ↑0 < y ^ 2 + 1 := by linarith [sq_nonneg y]
rcases lt_or_le y (π / 2) with (hy2' | hy1')
· -- Main case : `0 < y < π / 2`
have hy4 : 0 < cos y := cos_pos_of_mem_Ioo ⟨by linarith, hy2'⟩
rw [← abs_of_nonneg (cos_nonneg_of_mem_Icc ⟨by linarith, hy2'.le⟩), ←
abs_of_nonneg (one_div_nonneg.mpr (sqrt_nonneg _)), ← sq_lt_sq, div_pow, one_pow,
sq_sqrt hy3.le, lt_one_div (pow_pos hy4 _) hy3, ← inv_one_add_tan_sq hy4.ne', one_div,
inv_inv, add_comm, add_lt_add_iff_left, sq_lt_sq, abs_of_pos hy1,
abs_of_nonneg (tan_nonneg_of_nonneg_of_le_pi_div_two hy1.le hy2'.le)]
exact Real.lt_tan hy1 hy2'
· -- Easy case : `π / 2 ≤ y ≤ 3 * π / 2`
refine lt_of_le_of_lt ?_ (one_div_pos.mpr <| sqrt_pos_of_pos hy3)
exact cos_nonpos_of_pi_div_two_le_of_le hy1' (by linarith [pi_pos])
theorem cos_le_one_div_sqrt_sq_add_one {x : ℝ} (hx1 : -(3 * π / 2) ≤ x) (hx2 : x ≤ 3 * π / 2) :
cos x ≤ (1 : ℝ) / √(x ^ 2 + 1) := by
rcases eq_or_ne x 0 with (rfl | hx3)
· simp
· exact (cos_lt_one_div_sqrt_sq_add_one hx1 hx2 hx3).le
end Real
|
Analysis\SpecialFunctions\Trigonometric\Chebyshev.lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import Mathlib.Algebra.Polynomial.AlgebraMap
import Mathlib.Data.Complex.Exponential
import Mathlib.Data.Complex.Module
import Mathlib.RingTheory.Polynomial.Chebyshev
/-!
# Multiple angle formulas in terms of Chebyshev polynomials
This file gives the trigonometric characterizations of Chebyshev polynomials, for both the real
(`Real.cos`) and complex (`Complex.cos`) cosine.
-/
namespace Polynomial.Chebyshev
open Polynomial
variable {R A : Type*} [CommRing R] [CommRing A] [Algebra R A]
@[simp]
theorem aeval_T (x : A) (n : ℤ) : aeval x (T R n) = (T A n).eval x := by
rw [aeval_def, eval₂_eq_eval_map, map_T]
@[simp]
theorem aeval_U (x : A) (n : ℤ) : aeval x (U R n) = (U A n).eval x := by
rw [aeval_def, eval₂_eq_eval_map, map_U]
@[simp]
theorem algebraMap_eval_T (x : R) (n : ℤ) :
algebraMap R A ((T R n).eval x) = (T A n).eval (algebraMap R A x) := by
rw [← aeval_algebraMap_apply_eq_algebraMap_eval, aeval_T]
@[simp]
theorem algebraMap_eval_U (x : R) (n : ℤ) :
algebraMap R A ((U R n).eval x) = (U A n).eval (algebraMap R A x) := by
rw [← aeval_algebraMap_apply_eq_algebraMap_eval, aeval_U]
-- Porting note: added type ascriptions to the statement
@[simp, norm_cast]
theorem complex_ofReal_eval_T : ∀ (x : ℝ) n, (((T ℝ n).eval x : ℝ) : ℂ) = (T ℂ n).eval (x : ℂ) :=
@algebraMap_eval_T ℝ ℂ _ _ _
-- Porting note: added type ascriptions to the statement
@[simp, norm_cast]
theorem complex_ofReal_eval_U : ∀ (x : ℝ) n, (((U ℝ n).eval x : ℝ) : ℂ) = (U ℂ n).eval (x : ℂ) :=
@algebraMap_eval_U ℝ ℂ _ _ _
/-! ### Complex versions -/
section Complex
open Complex
variable (θ : ℂ)
/-- The `n`-th Chebyshev polynomial of the first kind evaluates on `cos θ` to the
value `cos (n * θ)`. -/
@[simp]
theorem T_complex_cos (n : ℤ) : (T ℂ n).eval (cos θ) = cos (n * θ) := by
induction n using Polynomial.Chebyshev.induct with
| zero => simp
| one => simp
| add_two n ih1 ih2 =>
simp only [T_add_two, eval_sub, eval_mul, eval_X, eval_ofNat, ih1, ih2, sub_eq_iff_eq_add,
cos_add_cos]
push_cast
ring_nf
| neg_add_one n ih1 ih2 =>
simp only [T_sub_one, eval_sub, eval_mul, eval_X, eval_ofNat, ih1, ih2, sub_eq_iff_eq_add',
cos_add_cos]
push_cast
ring_nf
/-- The `n`-th Chebyshev polynomial of the second kind evaluates on `cos θ` to the
value `sin ((n + 1) * θ) / sin θ`. -/
@[simp]
theorem U_complex_cos (n : ℤ) : (U ℂ n).eval (cos θ) * sin θ = sin ((n + 1) * θ) := by
induction n using Polynomial.Chebyshev.induct with
| zero => simp
| one => simp [one_add_one_eq_two, sin_two_mul]; ring
| add_two n ih1 ih2 =>
simp only [U_add_two, add_sub_cancel_right, eval_sub, eval_mul, eval_X, eval_ofNat, sub_mul,
mul_assoc, ih1, ih2, sub_eq_iff_eq_add, sin_add_sin]
push_cast
ring_nf
| neg_add_one n ih1 ih2 =>
simp only [U_sub_one, add_sub_cancel_right, eval_sub, eval_mul, eval_X, eval_ofNat, sub_mul,
mul_assoc, ih1, ih2, sub_eq_iff_eq_add', sin_add_sin]
push_cast
ring_nf
end Complex
/-! ### Real versions -/
section Real
open Real
variable (θ : ℝ) (n : ℤ)
/-- The `n`-th Chebyshev polynomial of the first kind evaluates on `cos θ` to the
value `cos (n * θ)`. -/
@[simp]
theorem T_real_cos : (T ℝ n).eval (cos θ) = cos (n * θ) := mod_cast T_complex_cos θ n
/-- The `n`-th Chebyshev polynomial of the second kind evaluates on `cos θ` to the
value `sin ((n + 1) * θ) / sin θ`. -/
@[simp]
theorem U_real_cos : (U ℝ n).eval (cos θ) * sin θ = sin ((n + 1) * θ) :=
mod_cast U_complex_cos θ n
end Real
end Polynomial.Chebyshev
|
Analysis\SpecialFunctions\Trigonometric\Complex.lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import Mathlib.Algebra.QuadraticDiscriminant
import Mathlib.Analysis.Convex.SpecificFunctions.Deriv
import Mathlib.Analysis.SpecialFunctions.Pow.Complex
/-!
# Complex trigonometric functions
Basic facts and derivatives for the complex trigonometric functions.
Several facts about the real trigonometric functions have the proofs deferred here, rather than
`Analysis.SpecialFunctions.Trigonometric.Basic`,
as they are most easily proved by appealing to the corresponding fact for complex trigonometric
functions, or require additional imports which are not available in that file.
-/
noncomputable section
namespace Complex
open Set Filter
open scoped Real
theorem cos_eq_zero_iff {θ : ℂ} : cos θ = 0 ↔ ∃ k : ℤ, θ = (2 * k + 1) * π / 2 := by
have h : (exp (θ * I) + exp (-θ * I)) / 2 = 0 ↔ exp (2 * θ * I) = -1 := by
rw [@div_eq_iff _ _ (exp (θ * I) + exp (-θ * I)) 2 0 two_ne_zero, zero_mul,
add_eq_zero_iff_eq_neg, neg_eq_neg_one_mul, ← div_eq_iff (exp_ne_zero _), ← exp_sub]
ring_nf
rw [cos, h, ← exp_pi_mul_I, exp_eq_exp_iff_exists_int, mul_right_comm]
refine exists_congr fun x => ?_
refine (iff_of_eq <| congr_arg _ ?_).trans (mul_right_inj' <| mul_ne_zero two_ne_zero I_ne_zero)
field_simp; ring
theorem cos_ne_zero_iff {θ : ℂ} : cos θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ (2 * k + 1) * π / 2 := by
rw [← not_exists, not_iff_not, cos_eq_zero_iff]
theorem sin_eq_zero_iff {θ : ℂ} : sin θ = 0 ↔ ∃ k : ℤ, θ = k * π := by
rw [← Complex.cos_sub_pi_div_two, cos_eq_zero_iff]
constructor
· rintro ⟨k, hk⟩
use k + 1
field_simp [eq_add_of_sub_eq hk]
ring
· rintro ⟨k, rfl⟩
use k - 1
field_simp
ring
theorem sin_ne_zero_iff {θ : ℂ} : sin θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ k * π := by
rw [← not_exists, not_iff_not, sin_eq_zero_iff]
/-- The tangent of a complex number is equal to zero
iff this number is equal to `k * π / 2` for an integer `k`.
Note that this lemma takes into account that we use zero as the junk value for division by zero.
See also `Complex.tan_eq_zero_iff'`. -/
theorem tan_eq_zero_iff {θ : ℂ} : tan θ = 0 ↔ ∃ k : ℤ, k * π / 2 = θ := by
rw [tan, div_eq_zero_iff, ← mul_eq_zero, ← mul_right_inj' two_ne_zero, mul_zero,
← mul_assoc, ← sin_two_mul, sin_eq_zero_iff]
field_simp [mul_comm, eq_comm]
theorem tan_ne_zero_iff {θ : ℂ} : tan θ ≠ 0 ↔ ∀ k : ℤ, (k * π / 2 : ℂ) ≠ θ := by
rw [← not_exists, not_iff_not, tan_eq_zero_iff]
theorem tan_int_mul_pi_div_two (n : ℤ) : tan (n * π / 2) = 0 :=
tan_eq_zero_iff.mpr (by use n)
/-- If the tangent of a complex number is well-defined,
then it is equal to zero iff the number is equal to `k * π` for an integer `k`.
See also `Complex.tan_eq_zero_iff` for a version that takes into account junk values of `θ`. -/
theorem tan_eq_zero_iff' {θ : ℂ} (hθ : cos θ ≠ 0) : tan θ = 0 ↔ ∃ k : ℤ, k * π = θ := by
simp only [tan, hθ, div_eq_zero_iff, sin_eq_zero_iff]; simp [eq_comm]
theorem cos_eq_cos_iff {x y : ℂ} : cos x = cos y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = 2 * k * π - x :=
calc
cos x = cos y ↔ cos x - cos y = 0 := sub_eq_zero.symm
_ ↔ -2 * sin ((x + y) / 2) * sin ((x - y) / 2) = 0 := by rw [cos_sub_cos]
_ ↔ sin ((x + y) / 2) = 0 ∨ sin ((x - y) / 2) = 0 := by simp [(by norm_num : (2 : ℂ) ≠ 0)]
_ ↔ sin ((x - y) / 2) = 0 ∨ sin ((x + y) / 2) = 0 := or_comm
_ ↔ (∃ k : ℤ, y = 2 * k * π + x) ∨ ∃ k : ℤ, y = 2 * k * π - x := by
apply or_congr <;>
field_simp [sin_eq_zero_iff, (by norm_num : -(2 : ℂ) ≠ 0), eq_sub_iff_add_eq',
sub_eq_iff_eq_add, mul_comm (2 : ℂ), mul_right_comm _ (2 : ℂ)]
constructor <;> · rintro ⟨k, rfl⟩; use -k; simp
_ ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = 2 * k * π - x := exists_or.symm
theorem sin_eq_sin_iff {x y : ℂ} :
sin x = sin y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = (2 * k + 1) * π - x := by
simp only [← Complex.cos_sub_pi_div_two, cos_eq_cos_iff, sub_eq_iff_eq_add]
refine exists_congr fun k => or_congr ?_ ?_ <;> refine Eq.congr rfl ?_ <;> field_simp <;> ring
theorem cos_eq_one_iff {x : ℂ} : cos x = 1 ↔ ∃ k : ℤ, k * (2 * π) = x := by
rw [← cos_zero, eq_comm, cos_eq_cos_iff]
simp [mul_assoc, mul_left_comm, eq_comm]
theorem cos_eq_neg_one_iff {x : ℂ} : cos x = -1 ↔ ∃ k : ℤ, π + k * (2 * π) = x := by
rw [← neg_eq_iff_eq_neg, ← cos_sub_pi, cos_eq_one_iff]
simp only [eq_sub_iff_add_eq']
theorem sin_eq_one_iff {x : ℂ} : sin x = 1 ↔ ∃ k : ℤ, π / 2 + k * (2 * π) = x := by
rw [← cos_sub_pi_div_two, cos_eq_one_iff]
simp only [eq_sub_iff_add_eq']
theorem sin_eq_neg_one_iff {x : ℂ} : sin x = -1 ↔ ∃ k : ℤ, -(π / 2) + k * (2 * π) = x := by
rw [← neg_eq_iff_eq_neg, ← cos_add_pi_div_two, cos_eq_one_iff]
simp only [← sub_eq_neg_add, sub_eq_iff_eq_add]
theorem tan_add {x y : ℂ}
(h : ((∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y ≠ (2 * l + 1) * π / 2) ∨
(∃ k : ℤ, x = (2 * k + 1) * π / 2) ∧ ∃ l : ℤ, y = (2 * l + 1) * π / 2) :
tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) := by
rcases h with (⟨h1, h2⟩ | ⟨⟨k, rfl⟩, ⟨l, rfl⟩⟩)
· rw [tan, sin_add, cos_add, ←
div_div_div_cancel_right (sin x * cos y + cos x * sin y)
(mul_ne_zero (cos_ne_zero_iff.mpr h1) (cos_ne_zero_iff.mpr h2)),
add_div, sub_div]
simp only [← div_mul_div_comm, tan, mul_one, one_mul, div_self (cos_ne_zero_iff.mpr h1),
div_self (cos_ne_zero_iff.mpr h2)]
· haveI t := tan_int_mul_pi_div_two
obtain ⟨hx, hy, hxy⟩ := t (2 * k + 1), t (2 * l + 1), t (2 * k + 1 + (2 * l + 1))
simp only [Int.cast_add, Int.cast_two, Int.cast_mul, Int.cast_one, hx, hy] at hx hy hxy
rw [hx, hy, add_zero, zero_div, mul_div_assoc, mul_div_assoc, ←
add_mul (2 * (k : ℂ) + 1) (2 * l + 1) (π / 2), ← mul_div_assoc, hxy]
theorem tan_add' {x y : ℂ}
(h : (∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y ≠ (2 * l + 1) * π / 2) :
tan (x + y) = (tan x + tan y) / (1 - tan x * tan y) :=
tan_add (Or.inl h)
theorem tan_two_mul {z : ℂ} : tan (2 * z) = (2 : ℂ) * tan z / ((1 : ℂ) - tan z ^ 2) := by
by_cases h : ∀ k : ℤ, z ≠ (2 * k + 1) * π / 2
· rw [two_mul, two_mul, sq, tan_add (Or.inl ⟨h, h⟩)]
· rw [not_forall_not] at h
rw [two_mul, two_mul, sq, tan_add (Or.inr ⟨h, h⟩)]
theorem tan_add_mul_I {x y : ℂ}
(h :
((∀ k : ℤ, x ≠ (2 * k + 1) * π / 2) ∧ ∀ l : ℤ, y * I ≠ (2 * l + 1) * π / 2) ∨
(∃ k : ℤ, x = (2 * k + 1) * π / 2) ∧ ∃ l : ℤ, y * I = (2 * l + 1) * π / 2) :
tan (x + y * I) = (tan x + tanh y * I) / (1 - tan x * tanh y * I) := by
rw [tan_add h, tan_mul_I, mul_assoc]
theorem tan_eq {z : ℂ}
(h :
((∀ k : ℤ, (z.re : ℂ) ≠ (2 * k + 1) * π / 2) ∧
∀ l : ℤ, (z.im : ℂ) * I ≠ (2 * l + 1) * π / 2) ∨
(∃ k : ℤ, (z.re : ℂ) = (2 * k + 1) * π / 2) ∧
∃ l : ℤ, (z.im : ℂ) * I = (2 * l + 1) * π / 2) :
tan z = (tan z.re + tanh z.im * I) / (1 - tan z.re * tanh z.im * I) := by
convert tan_add_mul_I h; exact (re_add_im z).symm
open scoped Topology
theorem continuousOn_tan : ContinuousOn tan {x | cos x ≠ 0} :=
continuousOn_sin.div continuousOn_cos fun _x => id
@[continuity]
theorem continuous_tan : Continuous fun x : {x | cos x ≠ 0} => tan x :=
continuousOn_iff_continuous_restrict.1 continuousOn_tan
theorem cos_eq_iff_quadratic {z w : ℂ} :
cos z = w ↔ exp (z * I) ^ 2 - 2 * w * exp (z * I) + 1 = 0 := by
rw [← sub_eq_zero]
field_simp [cos, exp_neg, exp_ne_zero]
refine Eq.congr ?_ rfl
ring
theorem cos_surjective : Function.Surjective cos := by
intro x
obtain ⟨w, w₀, hw⟩ : ∃ w ≠ 0, 1 * w * w + -2 * x * w + 1 = 0 := by
rcases exists_quadratic_eq_zero one_ne_zero
⟨_, (cpow_nat_inv_pow _ two_ne_zero).symm.trans <| pow_two _⟩ with
⟨w, hw⟩
refine ⟨w, ?_, hw⟩
rintro rfl
simp only [zero_add, one_ne_zero, mul_zero] at hw
refine ⟨log w / I, cos_eq_iff_quadratic.2 ?_⟩
rw [div_mul_cancel₀ _ I_ne_zero, exp_log w₀]
convert hw using 1
ring
@[simp]
theorem range_cos : Set.range cos = Set.univ :=
cos_surjective.range_eq
theorem sin_surjective : Function.Surjective sin := by
intro x
rcases cos_surjective x with ⟨z, rfl⟩
exact ⟨z + π / 2, sin_add_pi_div_two z⟩
@[simp]
theorem range_sin : Set.range sin = Set.univ :=
sin_surjective.range_eq
end Complex
namespace Real
open scoped Real
theorem cos_eq_zero_iff {θ : ℝ} : cos θ = 0 ↔ ∃ k : ℤ, θ = (2 * k + 1) * π / 2 :=
mod_cast @Complex.cos_eq_zero_iff θ
theorem cos_ne_zero_iff {θ : ℝ} : cos θ ≠ 0 ↔ ∀ k : ℤ, θ ≠ (2 * k + 1) * π / 2 :=
mod_cast @Complex.cos_ne_zero_iff θ
theorem cos_eq_cos_iff {x y : ℝ} : cos x = cos y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = 2 * k * π - x :=
mod_cast @Complex.cos_eq_cos_iff x y
theorem sin_eq_sin_iff {x y : ℝ} :
sin x = sin y ↔ ∃ k : ℤ, y = 2 * k * π + x ∨ y = (2 * k + 1) * π - x :=
mod_cast @Complex.sin_eq_sin_iff x y
theorem cos_eq_neg_one_iff {x : ℝ} : cos x = -1 ↔ ∃ k : ℤ, π + k * (2 * π) = x :=
mod_cast @Complex.cos_eq_neg_one_iff x
theorem sin_eq_one_iff {x : ℝ} : sin x = 1 ↔ ∃ k : ℤ, π / 2 + k * (2 * π) = x :=
mod_cast @Complex.sin_eq_one_iff x
theorem sin_eq_neg_one_iff {x : ℝ} : sin x = -1 ↔ ∃ k : ℤ, -(π / 2) + k * (2 * π) = x :=
mod_cast @Complex.sin_eq_neg_one_iff x
theorem tan_eq_zero_iff {θ : ℝ} : tan θ = 0 ↔ ∃ k : ℤ, k * π / 2 = θ :=
mod_cast @Complex.tan_eq_zero_iff θ
theorem tan_eq_zero_iff' {θ : ℝ} (hθ : cos θ ≠ 0) : tan θ = 0 ↔ ∃ k : ℤ, k * π = θ := by
revert hθ
exact_mod_cast @Complex.tan_eq_zero_iff' θ
theorem tan_ne_zero_iff {θ : ℝ} : tan θ ≠ 0 ↔ ∀ k : ℤ, k * π / 2 ≠ θ :=
mod_cast @Complex.tan_ne_zero_iff θ
theorem lt_sin_mul {x : ℝ} (hx : 0 < x) (hx' : x < 1) : x < sin (π / 2 * x) := by
simpa [mul_comm x] using
strictConcaveOn_sin_Icc.2 ⟨le_rfl, pi_pos.le⟩ ⟨pi_div_two_pos.le, half_le_self pi_pos.le⟩
pi_div_two_pos.ne (sub_pos.2 hx') hx
theorem le_sin_mul {x : ℝ} (hx : 0 ≤ x) (hx' : x ≤ 1) : x ≤ sin (π / 2 * x) := by
simpa [mul_comm x] using
strictConcaveOn_sin_Icc.concaveOn.2 ⟨le_rfl, pi_pos.le⟩
⟨pi_div_two_pos.le, half_le_self pi_pos.le⟩ (sub_nonneg.2 hx') hx
theorem mul_lt_sin {x : ℝ} (hx : 0 < x) (hx' : x < π / 2) : 2 / π * x < sin x := by
rw [← inv_div]
simpa [-inv_div, mul_inv_cancel_left₀ pi_div_two_pos.ne'] using @lt_sin_mul ((π / 2)⁻¹ * x)
(mul_pos (inv_pos.2 pi_div_two_pos) hx) (by rwa [← div_eq_inv_mul, div_lt_one pi_div_two_pos])
/-- In the range `[0, π / 2]`, we have a linear lower bound on `sin`. This inequality forms one half
of Jordan's inequality, the other half is `Real.sin_lt` -/
theorem mul_le_sin {x : ℝ} (hx : 0 ≤ x) (hx' : x ≤ π / 2) : 2 / π * x ≤ sin x := by
rw [← inv_div]
simpa [-inv_div, mul_inv_cancel_left₀ pi_div_two_pos.ne'] using @le_sin_mul ((π / 2)⁻¹ * x)
(mul_nonneg (inv_nonneg.2 pi_div_two_pos.le) hx)
(by rwa [← div_eq_inv_mul, div_le_one pi_div_two_pos])
end Real
|
Analysis\SpecialFunctions\Trigonometric\ComplexDeriv.lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Complex
/-!
# Complex trigonometric functions
Basic facts and derivatives for the complex trigonometric functions.
-/
noncomputable section
namespace Complex
open Set Filter
open scoped Real
theorem hasStrictDerivAt_tan {x : ℂ} (h : cos x ≠ 0) : HasStrictDerivAt tan (1 / cos x ^ 2) x := by
convert (hasStrictDerivAt_sin x).div (hasStrictDerivAt_cos x) h using 1
rw_mod_cast [← sin_sq_add_cos_sq x]
ring
theorem hasDerivAt_tan {x : ℂ} (h : cos x ≠ 0) : HasDerivAt tan (1 / cos x ^ 2) x :=
(hasStrictDerivAt_tan h).hasDerivAt
open scoped Topology
theorem tendsto_abs_tan_of_cos_eq_zero {x : ℂ} (hx : cos x = 0) :
Tendsto (fun x => abs (tan x)) (𝓝[≠] x) atTop := by
simp only [tan_eq_sin_div_cos, ← norm_eq_abs, norm_div]
have A : sin x ≠ 0 := fun h => by simpa [*, sq] using sin_sq_add_cos_sq x
have B : Tendsto cos (𝓝[≠] x) (𝓝[≠] 0) :=
hx ▸ (hasDerivAt_cos x).tendsto_punctured_nhds (neg_ne_zero.2 A)
exact continuous_sin.continuousWithinAt.norm.mul_atTop (norm_pos_iff.2 A)
(tendsto_norm_nhdsWithin_zero.comp B).inv_tendsto_zero
theorem tendsto_abs_tan_atTop (k : ℤ) :
Tendsto (fun x => abs (tan x)) (𝓝[≠] ((2 * k + 1) * π / 2 : ℂ)) atTop :=
tendsto_abs_tan_of_cos_eq_zero <| cos_eq_zero_iff.2 ⟨k, rfl⟩
@[simp]
theorem continuousAt_tan {x : ℂ} : ContinuousAt tan x ↔ cos x ≠ 0 := by
refine ⟨fun hc h₀ => ?_, fun h => (hasDerivAt_tan h).continuousAt⟩
exact not_tendsto_nhds_of_tendsto_atTop (tendsto_abs_tan_of_cos_eq_zero h₀) _
(hc.norm.tendsto.mono_left inf_le_left)
@[simp]
theorem differentiableAt_tan {x : ℂ} : DifferentiableAt ℂ tan x ↔ cos x ≠ 0 :=
⟨fun h => continuousAt_tan.1 h.continuousAt, fun h => (hasDerivAt_tan h).differentiableAt⟩
@[simp]
theorem deriv_tan (x : ℂ) : deriv tan x = 1 / cos x ^ 2 :=
if h : cos x = 0 then by
have : ¬DifferentiableAt ℂ tan x := mt differentiableAt_tan.1 (Classical.not_not.2 h)
simp [deriv_zero_of_not_differentiableAt this, h, sq]
else (hasDerivAt_tan h).deriv
@[simp]
theorem contDiffAt_tan {x : ℂ} {n : ℕ∞} : ContDiffAt ℂ n tan x ↔ cos x ≠ 0 :=
⟨fun h => continuousAt_tan.1 h.continuousAt, contDiff_sin.contDiffAt.div contDiff_cos.contDiffAt⟩
end Complex
|
Analysis\SpecialFunctions\Trigonometric\Cotangent.lean | /-
Copyright (c) 2024 Chris Birkbeck. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Birkbeck
-/
import Mathlib.Analysis.Complex.UpperHalfPlane.Exp
/-!
# Cotangent
This file contains lemmas about the cotangent function, including useful series expansions.
-/
open Real Complex BigOperators Filter
open scoped UpperHalfPlane Topology
lemma Complex.cot_eq_exp_ratio (z : ℂ) :
cot z = (Complex.exp (2 * I * z) + 1) / (I * (1 - Complex.exp (2 * I * z))) := by
rw [Complex.cot, Complex.sin, Complex.cos]
field_simp
have h1 : exp (z * I) + exp (-(z * I)) = exp (-(z * I)) * (exp (2 * I * z) + 1) := by
rw [mul_add, ← Complex.exp_add]
simp only [mul_one, add_left_inj]
ring_nf
have h2 : (exp (-(z * I)) - exp (z * I)) * I = exp (-(z * I)) * (I * (1 - exp (2 * I * z))) := by
ring_nf
rw [mul_assoc, ← Complex.exp_add]
ring_nf
rw [h1, h2, mul_div_mul_left _ _ (Complex.exp_ne_zero _)]
/- The version one probably wants to use more. -/
lemma Complex.cot_pi_eq_exp_ratio (z : ℂ) :
cot (π * z) = (Complex.exp (2 * π * I * z) + 1) / (I * (1 - Complex.exp (2 * π * I * z))) := by
rw [cot_eq_exp_ratio (π * z)]
ring_nf
/- This is the version one probably wants, which is why the pi's are there. -/
theorem pi_mul_cot_pi_q_exp (z : ℍ) :
π * cot (π * z) = π * I - 2 * π * I * ∑' n : ℕ, Complex.exp (2 * π * I * z) ^ n := by
have h1 : π * ((exp (2 * π * I * z) + 1) / (I * (1 - exp (2 * π * I * z)))) =
-π * I * ((exp (2 * π * I * z) + 1) * (1 / (1 - exp (2 * π * I * z)))) := by
simp only [div_mul_eq_div_mul_one_div, div_I, one_div, neg_mul, mul_neg, neg_inj]
ring
rw [cot_pi_eq_exp_ratio, h1, one_div, (tsum_geometric_of_norm_lt_one
(UpperHalfPlane.abs_exp_two_pi_I_lt_one z)).symm, add_comm, geom_series_mul_one_add
(Complex.exp (2 * π * I * (z : ℂ))) (UpperHalfPlane.abs_exp_two_pi_I_lt_one _)]
ring
|
Analysis\SpecialFunctions\Trigonometric\Deriv.lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import Mathlib.Order.Monotone.Odd
import Mathlib.Analysis.Calculus.LogDeriv
import Mathlib.Analysis.SpecialFunctions.ExpDeriv
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic
/-!
# Differentiability of trigonometric functions
## Main statements
The differentiability of the usual trigonometric functions is proved, and their derivatives are
computed.
## Tags
sin, cos, tan, angle
-/
noncomputable section
open scoped Topology Filter
open Set
namespace Complex
/-- The complex sine function is everywhere strictly differentiable, with the derivative `cos x`. -/
theorem hasStrictDerivAt_sin (x : ℂ) : HasStrictDerivAt sin (cos x) x := by
simp only [cos, div_eq_mul_inv]
convert ((((hasStrictDerivAt_id x).neg.mul_const I).cexp.sub
((hasStrictDerivAt_id x).mul_const I).cexp).mul_const I).mul_const (2 : ℂ)⁻¹ using 1
simp only [Function.comp, id]
rw [sub_mul, mul_assoc, mul_assoc, I_mul_I, neg_one_mul, neg_neg, mul_one, one_mul, mul_assoc,
I_mul_I, mul_neg_one, sub_neg_eq_add, add_comm]
/-- The complex sine function is everywhere differentiable, with the derivative `cos x`. -/
theorem hasDerivAt_sin (x : ℂ) : HasDerivAt sin (cos x) x :=
(hasStrictDerivAt_sin x).hasDerivAt
theorem contDiff_sin {n} : ContDiff ℂ n sin :=
(((contDiff_neg.mul contDiff_const).cexp.sub (contDiff_id.mul contDiff_const).cexp).mul
contDiff_const).div_const _
theorem differentiable_sin : Differentiable ℂ sin := fun x => (hasDerivAt_sin x).differentiableAt
theorem differentiableAt_sin {x : ℂ} : DifferentiableAt ℂ sin x :=
differentiable_sin x
@[simp]
theorem deriv_sin : deriv sin = cos :=
funext fun x => (hasDerivAt_sin x).deriv
/-- The complex cosine function is everywhere strictly differentiable, with the derivative
`-sin x`. -/
theorem hasStrictDerivAt_cos (x : ℂ) : HasStrictDerivAt cos (-sin x) x := by
simp only [sin, div_eq_mul_inv, neg_mul_eq_neg_mul]
convert (((hasStrictDerivAt_id x).mul_const I).cexp.add
((hasStrictDerivAt_id x).neg.mul_const I).cexp).mul_const (2 : ℂ)⁻¹ using 1
simp only [Function.comp, id]
ring
/-- The complex cosine function is everywhere differentiable, with the derivative `-sin x`. -/
theorem hasDerivAt_cos (x : ℂ) : HasDerivAt cos (-sin x) x :=
(hasStrictDerivAt_cos x).hasDerivAt
theorem contDiff_cos {n} : ContDiff ℂ n cos :=
((contDiff_id.mul contDiff_const).cexp.add (contDiff_neg.mul contDiff_const).cexp).div_const _
theorem differentiable_cos : Differentiable ℂ cos := fun x => (hasDerivAt_cos x).differentiableAt
theorem differentiableAt_cos {x : ℂ} : DifferentiableAt ℂ cos x :=
differentiable_cos x
theorem deriv_cos {x : ℂ} : deriv cos x = -sin x :=
(hasDerivAt_cos x).deriv
@[simp]
theorem deriv_cos' : deriv cos = fun x => -sin x :=
funext fun _ => deriv_cos
/-- The complex hyperbolic sine function is everywhere strictly differentiable, with the derivative
`cosh x`. -/
theorem hasStrictDerivAt_sinh (x : ℂ) : HasStrictDerivAt sinh (cosh x) x := by
simp only [cosh, div_eq_mul_inv]
convert ((hasStrictDerivAt_exp x).sub (hasStrictDerivAt_id x).neg.cexp).mul_const (2 : ℂ)⁻¹
using 1
rw [id, mul_neg_one, sub_eq_add_neg, neg_neg]
/-- The complex hyperbolic sine function is everywhere differentiable, with the derivative
`cosh x`. -/
theorem hasDerivAt_sinh (x : ℂ) : HasDerivAt sinh (cosh x) x :=
(hasStrictDerivAt_sinh x).hasDerivAt
theorem contDiff_sinh {n} : ContDiff ℂ n sinh :=
(contDiff_exp.sub contDiff_neg.cexp).div_const _
theorem differentiable_sinh : Differentiable ℂ sinh := fun x => (hasDerivAt_sinh x).differentiableAt
theorem differentiableAt_sinh {x : ℂ} : DifferentiableAt ℂ sinh x :=
differentiable_sinh x
@[simp]
theorem deriv_sinh : deriv sinh = cosh :=
funext fun x => (hasDerivAt_sinh x).deriv
/-- The complex hyperbolic cosine function is everywhere strictly differentiable, with the
derivative `sinh x`. -/
theorem hasStrictDerivAt_cosh (x : ℂ) : HasStrictDerivAt cosh (sinh x) x := by
simp only [sinh, div_eq_mul_inv]
convert ((hasStrictDerivAt_exp x).add (hasStrictDerivAt_id x).neg.cexp).mul_const (2 : ℂ)⁻¹
using 1
rw [id, mul_neg_one, sub_eq_add_neg]
/-- The complex hyperbolic cosine function is everywhere differentiable, with the derivative
`sinh x`. -/
theorem hasDerivAt_cosh (x : ℂ) : HasDerivAt cosh (sinh x) x :=
(hasStrictDerivAt_cosh x).hasDerivAt
theorem contDiff_cosh {n} : ContDiff ℂ n cosh :=
(contDiff_exp.add contDiff_neg.cexp).div_const _
theorem differentiable_cosh : Differentiable ℂ cosh := fun x => (hasDerivAt_cosh x).differentiableAt
theorem differentiableAt_cosh {x : ℂ} : DifferentiableAt ℂ cosh x :=
differentiable_cosh x
@[simp]
theorem deriv_cosh : deriv cosh = sinh :=
funext fun x => (hasDerivAt_cosh x).deriv
end Complex
section
/-! ### Simp lemmas for derivatives of `fun x => Complex.cos (f x)` etc., `f : ℂ → ℂ` -/
variable {f : ℂ → ℂ} {f' x : ℂ} {s : Set ℂ}
/-! #### `Complex.cos` -/
theorem HasStrictDerivAt.ccos (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) * f') x :=
(Complex.hasStrictDerivAt_cos (f x)).comp x hf
theorem HasDerivAt.ccos (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) * f') x :=
(Complex.hasDerivAt_cos (f x)).comp x hf
theorem HasDerivWithinAt.ccos (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) * f') s x :=
(Complex.hasDerivAt_cos (f x)).comp_hasDerivWithinAt x hf
theorem derivWithin_ccos (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
derivWithin (fun x => Complex.cos (f x)) s x = -Complex.sin (f x) * derivWithin f s x :=
hf.hasDerivWithinAt.ccos.derivWithin hxs
@[simp]
theorem deriv_ccos (hc : DifferentiableAt ℂ f x) :
deriv (fun x => Complex.cos (f x)) x = -Complex.sin (f x) * deriv f x :=
hc.hasDerivAt.ccos.deriv
/-! #### `Complex.sin` -/
theorem HasStrictDerivAt.csin (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) * f') x :=
(Complex.hasStrictDerivAt_sin (f x)).comp x hf
theorem HasDerivAt.csin (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) * f') x :=
(Complex.hasDerivAt_sin (f x)).comp x hf
theorem HasDerivWithinAt.csin (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => Complex.sin (f x)) (Complex.cos (f x) * f') s x :=
(Complex.hasDerivAt_sin (f x)).comp_hasDerivWithinAt x hf
theorem derivWithin_csin (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
derivWithin (fun x => Complex.sin (f x)) s x = Complex.cos (f x) * derivWithin f s x :=
hf.hasDerivWithinAt.csin.derivWithin hxs
@[simp]
theorem deriv_csin (hc : DifferentiableAt ℂ f x) :
deriv (fun x => Complex.sin (f x)) x = Complex.cos (f x) * deriv f x :=
hc.hasDerivAt.csin.deriv
/-! #### `Complex.cosh` -/
theorem HasStrictDerivAt.ccosh (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) * f') x :=
(Complex.hasStrictDerivAt_cosh (f x)).comp x hf
theorem HasDerivAt.ccosh (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) * f') x :=
(Complex.hasDerivAt_cosh (f x)).comp x hf
theorem HasDerivWithinAt.ccosh (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) * f') s x :=
(Complex.hasDerivAt_cosh (f x)).comp_hasDerivWithinAt x hf
theorem derivWithin_ccosh (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
derivWithin (fun x => Complex.cosh (f x)) s x = Complex.sinh (f x) * derivWithin f s x :=
hf.hasDerivWithinAt.ccosh.derivWithin hxs
@[simp]
theorem deriv_ccosh (hc : DifferentiableAt ℂ f x) :
deriv (fun x => Complex.cosh (f x)) x = Complex.sinh (f x) * deriv f x :=
hc.hasDerivAt.ccosh.deriv
/-! #### `Complex.sinh` -/
theorem HasStrictDerivAt.csinh (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) * f') x :=
(Complex.hasStrictDerivAt_sinh (f x)).comp x hf
theorem HasDerivAt.csinh (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) * f') x :=
(Complex.hasDerivAt_sinh (f x)).comp x hf
theorem HasDerivWithinAt.csinh (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) * f') s x :=
(Complex.hasDerivAt_sinh (f x)).comp_hasDerivWithinAt x hf
theorem derivWithin_csinh (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
derivWithin (fun x => Complex.sinh (f x)) s x = Complex.cosh (f x) * derivWithin f s x :=
hf.hasDerivWithinAt.csinh.derivWithin hxs
@[simp]
theorem deriv_csinh (hc : DifferentiableAt ℂ f x) :
deriv (fun x => Complex.sinh (f x)) x = Complex.cosh (f x) * deriv f x :=
hc.hasDerivAt.csinh.deriv
end
section
/-! ### Simp lemmas for derivatives of `fun x => Complex.cos (f x)` etc., `f : E → ℂ` -/
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] {f : E → ℂ} {f' : E →L[ℂ] ℂ} {x : E}
{s : Set E}
/-! #### `Complex.cos` -/
theorem HasStrictFDerivAt.ccos (hf : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) • f') x :=
(Complex.hasStrictDerivAt_cos (f x)).comp_hasStrictFDerivAt x hf
theorem HasFDerivAt.ccos (hf : HasFDerivAt f f' x) :
HasFDerivAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) • f') x :=
(Complex.hasDerivAt_cos (f x)).comp_hasFDerivAt x hf
theorem HasFDerivWithinAt.ccos (hf : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (fun x => Complex.cos (f x)) (-Complex.sin (f x) • f') s x :=
(Complex.hasDerivAt_cos (f x)).comp_hasFDerivWithinAt x hf
theorem DifferentiableWithinAt.ccos (hf : DifferentiableWithinAt ℂ f s x) :
DifferentiableWithinAt ℂ (fun x => Complex.cos (f x)) s x :=
hf.hasFDerivWithinAt.ccos.differentiableWithinAt
@[simp]
theorem DifferentiableAt.ccos (hc : DifferentiableAt ℂ f x) :
DifferentiableAt ℂ (fun x => Complex.cos (f x)) x :=
hc.hasFDerivAt.ccos.differentiableAt
theorem DifferentiableOn.ccos (hc : DifferentiableOn ℂ f s) :
DifferentiableOn ℂ (fun x => Complex.cos (f x)) s := fun x h => (hc x h).ccos
@[simp]
theorem Differentiable.ccos (hc : Differentiable ℂ f) :
Differentiable ℂ fun x => Complex.cos (f x) := fun x => (hc x).ccos
theorem fderivWithin_ccos (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
fderivWithin ℂ (fun x => Complex.cos (f x)) s x = -Complex.sin (f x) • fderivWithin ℂ f s x :=
hf.hasFDerivWithinAt.ccos.fderivWithin hxs
@[simp]
theorem fderiv_ccos (hc : DifferentiableAt ℂ f x) :
fderiv ℂ (fun x => Complex.cos (f x)) x = -Complex.sin (f x) • fderiv ℂ f x :=
hc.hasFDerivAt.ccos.fderiv
theorem ContDiff.ccos {n} (h : ContDiff ℂ n f) : ContDiff ℂ n fun x => Complex.cos (f x) :=
Complex.contDiff_cos.comp h
theorem ContDiffAt.ccos {n} (hf : ContDiffAt ℂ n f x) :
ContDiffAt ℂ n (fun x => Complex.cos (f x)) x :=
Complex.contDiff_cos.contDiffAt.comp x hf
theorem ContDiffOn.ccos {n} (hf : ContDiffOn ℂ n f s) :
ContDiffOn ℂ n (fun x => Complex.cos (f x)) s :=
Complex.contDiff_cos.comp_contDiffOn hf
theorem ContDiffWithinAt.ccos {n} (hf : ContDiffWithinAt ℂ n f s x) :
ContDiffWithinAt ℂ n (fun x => Complex.cos (f x)) s x :=
Complex.contDiff_cos.contDiffAt.comp_contDiffWithinAt x hf
/-! #### `Complex.sin` -/
theorem HasStrictFDerivAt.csin (hf : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) • f') x :=
(Complex.hasStrictDerivAt_sin (f x)).comp_hasStrictFDerivAt x hf
theorem HasFDerivAt.csin (hf : HasFDerivAt f f' x) :
HasFDerivAt (fun x => Complex.sin (f x)) (Complex.cos (f x) • f') x :=
(Complex.hasDerivAt_sin (f x)).comp_hasFDerivAt x hf
theorem HasFDerivWithinAt.csin (hf : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (fun x => Complex.sin (f x)) (Complex.cos (f x) • f') s x :=
(Complex.hasDerivAt_sin (f x)).comp_hasFDerivWithinAt x hf
theorem DifferentiableWithinAt.csin (hf : DifferentiableWithinAt ℂ f s x) :
DifferentiableWithinAt ℂ (fun x => Complex.sin (f x)) s x :=
hf.hasFDerivWithinAt.csin.differentiableWithinAt
@[simp]
theorem DifferentiableAt.csin (hc : DifferentiableAt ℂ f x) :
DifferentiableAt ℂ (fun x => Complex.sin (f x)) x :=
hc.hasFDerivAt.csin.differentiableAt
theorem DifferentiableOn.csin (hc : DifferentiableOn ℂ f s) :
DifferentiableOn ℂ (fun x => Complex.sin (f x)) s := fun x h => (hc x h).csin
@[simp]
theorem Differentiable.csin (hc : Differentiable ℂ f) :
Differentiable ℂ fun x => Complex.sin (f x) := fun x => (hc x).csin
theorem fderivWithin_csin (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
fderivWithin ℂ (fun x => Complex.sin (f x)) s x = Complex.cos (f x) • fderivWithin ℂ f s x :=
hf.hasFDerivWithinAt.csin.fderivWithin hxs
@[simp]
theorem fderiv_csin (hc : DifferentiableAt ℂ f x) :
fderiv ℂ (fun x => Complex.sin (f x)) x = Complex.cos (f x) • fderiv ℂ f x :=
hc.hasFDerivAt.csin.fderiv
theorem ContDiff.csin {n} (h : ContDiff ℂ n f) : ContDiff ℂ n fun x => Complex.sin (f x) :=
Complex.contDiff_sin.comp h
theorem ContDiffAt.csin {n} (hf : ContDiffAt ℂ n f x) :
ContDiffAt ℂ n (fun x => Complex.sin (f x)) x :=
Complex.contDiff_sin.contDiffAt.comp x hf
theorem ContDiffOn.csin {n} (hf : ContDiffOn ℂ n f s) :
ContDiffOn ℂ n (fun x => Complex.sin (f x)) s :=
Complex.contDiff_sin.comp_contDiffOn hf
theorem ContDiffWithinAt.csin {n} (hf : ContDiffWithinAt ℂ n f s x) :
ContDiffWithinAt ℂ n (fun x => Complex.sin (f x)) s x :=
Complex.contDiff_sin.contDiffAt.comp_contDiffWithinAt x hf
/-! #### `Complex.cosh` -/
theorem HasStrictFDerivAt.ccosh (hf : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) • f') x :=
(Complex.hasStrictDerivAt_cosh (f x)).comp_hasStrictFDerivAt x hf
theorem HasFDerivAt.ccosh (hf : HasFDerivAt f f' x) :
HasFDerivAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) • f') x :=
(Complex.hasDerivAt_cosh (f x)).comp_hasFDerivAt x hf
theorem HasFDerivWithinAt.ccosh (hf : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (fun x => Complex.cosh (f x)) (Complex.sinh (f x) • f') s x :=
(Complex.hasDerivAt_cosh (f x)).comp_hasFDerivWithinAt x hf
theorem DifferentiableWithinAt.ccosh (hf : DifferentiableWithinAt ℂ f s x) :
DifferentiableWithinAt ℂ (fun x => Complex.cosh (f x)) s x :=
hf.hasFDerivWithinAt.ccosh.differentiableWithinAt
@[simp]
theorem DifferentiableAt.ccosh (hc : DifferentiableAt ℂ f x) :
DifferentiableAt ℂ (fun x => Complex.cosh (f x)) x :=
hc.hasFDerivAt.ccosh.differentiableAt
theorem DifferentiableOn.ccosh (hc : DifferentiableOn ℂ f s) :
DifferentiableOn ℂ (fun x => Complex.cosh (f x)) s := fun x h => (hc x h).ccosh
@[simp]
theorem Differentiable.ccosh (hc : Differentiable ℂ f) :
Differentiable ℂ fun x => Complex.cosh (f x) := fun x => (hc x).ccosh
theorem fderivWithin_ccosh (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
fderivWithin ℂ (fun x => Complex.cosh (f x)) s x = Complex.sinh (f x) • fderivWithin ℂ f s x :=
hf.hasFDerivWithinAt.ccosh.fderivWithin hxs
@[simp]
theorem fderiv_ccosh (hc : DifferentiableAt ℂ f x) :
fderiv ℂ (fun x => Complex.cosh (f x)) x = Complex.sinh (f x) • fderiv ℂ f x :=
hc.hasFDerivAt.ccosh.fderiv
theorem ContDiff.ccosh {n} (h : ContDiff ℂ n f) : ContDiff ℂ n fun x => Complex.cosh (f x) :=
Complex.contDiff_cosh.comp h
theorem ContDiffAt.ccosh {n} (hf : ContDiffAt ℂ n f x) :
ContDiffAt ℂ n (fun x => Complex.cosh (f x)) x :=
Complex.contDiff_cosh.contDiffAt.comp x hf
theorem ContDiffOn.ccosh {n} (hf : ContDiffOn ℂ n f s) :
ContDiffOn ℂ n (fun x => Complex.cosh (f x)) s :=
Complex.contDiff_cosh.comp_contDiffOn hf
theorem ContDiffWithinAt.ccosh {n} (hf : ContDiffWithinAt ℂ n f s x) :
ContDiffWithinAt ℂ n (fun x => Complex.cosh (f x)) s x :=
Complex.contDiff_cosh.contDiffAt.comp_contDiffWithinAt x hf
/-! #### `Complex.sinh` -/
theorem HasStrictFDerivAt.csinh (hf : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) • f') x :=
(Complex.hasStrictDerivAt_sinh (f x)).comp_hasStrictFDerivAt x hf
theorem HasFDerivAt.csinh (hf : HasFDerivAt f f' x) :
HasFDerivAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) • f') x :=
(Complex.hasDerivAt_sinh (f x)).comp_hasFDerivAt x hf
theorem HasFDerivWithinAt.csinh (hf : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (fun x => Complex.sinh (f x)) (Complex.cosh (f x) • f') s x :=
(Complex.hasDerivAt_sinh (f x)).comp_hasFDerivWithinAt x hf
theorem DifferentiableWithinAt.csinh (hf : DifferentiableWithinAt ℂ f s x) :
DifferentiableWithinAt ℂ (fun x => Complex.sinh (f x)) s x :=
hf.hasFDerivWithinAt.csinh.differentiableWithinAt
@[simp]
theorem DifferentiableAt.csinh (hc : DifferentiableAt ℂ f x) :
DifferentiableAt ℂ (fun x => Complex.sinh (f x)) x :=
hc.hasFDerivAt.csinh.differentiableAt
theorem DifferentiableOn.csinh (hc : DifferentiableOn ℂ f s) :
DifferentiableOn ℂ (fun x => Complex.sinh (f x)) s := fun x h => (hc x h).csinh
@[simp]
theorem Differentiable.csinh (hc : Differentiable ℂ f) :
Differentiable ℂ fun x => Complex.sinh (f x) := fun x => (hc x).csinh
theorem fderivWithin_csinh (hf : DifferentiableWithinAt ℂ f s x) (hxs : UniqueDiffWithinAt ℂ s x) :
fderivWithin ℂ (fun x => Complex.sinh (f x)) s x = Complex.cosh (f x) • fderivWithin ℂ f s x :=
hf.hasFDerivWithinAt.csinh.fderivWithin hxs
@[simp]
theorem fderiv_csinh (hc : DifferentiableAt ℂ f x) :
fderiv ℂ (fun x => Complex.sinh (f x)) x = Complex.cosh (f x) • fderiv ℂ f x :=
hc.hasFDerivAt.csinh.fderiv
theorem ContDiff.csinh {n} (h : ContDiff ℂ n f) : ContDiff ℂ n fun x => Complex.sinh (f x) :=
Complex.contDiff_sinh.comp h
theorem ContDiffAt.csinh {n} (hf : ContDiffAt ℂ n f x) :
ContDiffAt ℂ n (fun x => Complex.sinh (f x)) x :=
Complex.contDiff_sinh.contDiffAt.comp x hf
theorem ContDiffOn.csinh {n} (hf : ContDiffOn ℂ n f s) :
ContDiffOn ℂ n (fun x => Complex.sinh (f x)) s :=
Complex.contDiff_sinh.comp_contDiffOn hf
theorem ContDiffWithinAt.csinh {n} (hf : ContDiffWithinAt ℂ n f s x) :
ContDiffWithinAt ℂ n (fun x => Complex.sinh (f x)) s x :=
Complex.contDiff_sinh.contDiffAt.comp_contDiffWithinAt x hf
end
namespace Real
variable {x y z : ℝ}
theorem hasStrictDerivAt_sin (x : ℝ) : HasStrictDerivAt sin (cos x) x :=
(Complex.hasStrictDerivAt_sin x).real_of_complex
theorem hasDerivAt_sin (x : ℝ) : HasDerivAt sin (cos x) x :=
(hasStrictDerivAt_sin x).hasDerivAt
theorem contDiff_sin {n} : ContDiff ℝ n sin :=
Complex.contDiff_sin.real_of_complex
theorem differentiable_sin : Differentiable ℝ sin := fun x => (hasDerivAt_sin x).differentiableAt
theorem differentiableAt_sin : DifferentiableAt ℝ sin x :=
differentiable_sin x
@[simp]
theorem deriv_sin : deriv sin = cos :=
funext fun x => (hasDerivAt_sin x).deriv
theorem hasStrictDerivAt_cos (x : ℝ) : HasStrictDerivAt cos (-sin x) x :=
(Complex.hasStrictDerivAt_cos x).real_of_complex
theorem hasDerivAt_cos (x : ℝ) : HasDerivAt cos (-sin x) x :=
(Complex.hasDerivAt_cos x).real_of_complex
theorem contDiff_cos {n} : ContDiff ℝ n cos :=
Complex.contDiff_cos.real_of_complex
theorem differentiable_cos : Differentiable ℝ cos := fun x => (hasDerivAt_cos x).differentiableAt
theorem differentiableAt_cos : DifferentiableAt ℝ cos x :=
differentiable_cos x
theorem deriv_cos : deriv cos x = -sin x :=
(hasDerivAt_cos x).deriv
@[simp]
theorem deriv_cos' : deriv cos = fun x => -sin x :=
funext fun _ => deriv_cos
theorem hasStrictDerivAt_sinh (x : ℝ) : HasStrictDerivAt sinh (cosh x) x :=
(Complex.hasStrictDerivAt_sinh x).real_of_complex
theorem hasDerivAt_sinh (x : ℝ) : HasDerivAt sinh (cosh x) x :=
(Complex.hasDerivAt_sinh x).real_of_complex
theorem contDiff_sinh {n} : ContDiff ℝ n sinh :=
Complex.contDiff_sinh.real_of_complex
theorem differentiable_sinh : Differentiable ℝ sinh := fun x => (hasDerivAt_sinh x).differentiableAt
theorem differentiableAt_sinh : DifferentiableAt ℝ sinh x :=
differentiable_sinh x
@[simp]
theorem deriv_sinh : deriv sinh = cosh :=
funext fun x => (hasDerivAt_sinh x).deriv
theorem hasStrictDerivAt_cosh (x : ℝ) : HasStrictDerivAt cosh (sinh x) x :=
(Complex.hasStrictDerivAt_cosh x).real_of_complex
theorem hasDerivAt_cosh (x : ℝ) : HasDerivAt cosh (sinh x) x :=
(Complex.hasDerivAt_cosh x).real_of_complex
theorem contDiff_cosh {n} : ContDiff ℝ n cosh :=
Complex.contDiff_cosh.real_of_complex
theorem differentiable_cosh : Differentiable ℝ cosh := fun x => (hasDerivAt_cosh x).differentiableAt
theorem differentiableAt_cosh : DifferentiableAt ℝ cosh x :=
differentiable_cosh x
@[simp]
theorem deriv_cosh : deriv cosh = sinh :=
funext fun x => (hasDerivAt_cosh x).deriv
/-- `sinh` is strictly monotone. -/
theorem sinh_strictMono : StrictMono sinh :=
strictMono_of_deriv_pos <| by rw [Real.deriv_sinh]; exact cosh_pos
/-- `sinh` is injective, `∀ a b, sinh a = sinh b → a = b`. -/
theorem sinh_injective : Function.Injective sinh :=
sinh_strictMono.injective
@[simp]
theorem sinh_inj : sinh x = sinh y ↔ x = y :=
sinh_injective.eq_iff
@[simp]
theorem sinh_le_sinh : sinh x ≤ sinh y ↔ x ≤ y :=
sinh_strictMono.le_iff_le
@[simp]
theorem sinh_lt_sinh : sinh x < sinh y ↔ x < y :=
sinh_strictMono.lt_iff_lt
@[simp] lemma sinh_eq_zero : sinh x = 0 ↔ x = 0 := by rw [← @sinh_inj x, sinh_zero]
lemma sinh_ne_zero : sinh x ≠ 0 ↔ x ≠ 0 := sinh_eq_zero.not
@[simp]
theorem sinh_pos_iff : 0 < sinh x ↔ 0 < x := by simpa only [sinh_zero] using @sinh_lt_sinh 0 x
@[simp]
theorem sinh_nonpos_iff : sinh x ≤ 0 ↔ x ≤ 0 := by simpa only [sinh_zero] using @sinh_le_sinh x 0
@[simp]
theorem sinh_neg_iff : sinh x < 0 ↔ x < 0 := by simpa only [sinh_zero] using @sinh_lt_sinh x 0
@[simp]
theorem sinh_nonneg_iff : 0 ≤ sinh x ↔ 0 ≤ x := by simpa only [sinh_zero] using @sinh_le_sinh 0 x
theorem abs_sinh (x : ℝ) : |sinh x| = sinh |x| := by
cases le_total x 0 <;> simp [abs_of_nonneg, abs_of_nonpos, *]
theorem cosh_strictMonoOn : StrictMonoOn cosh (Ici 0) :=
strictMonoOn_of_deriv_pos (convex_Ici _) continuous_cosh.continuousOn fun x hx => by
rw [interior_Ici, mem_Ioi] at hx; rwa [deriv_cosh, sinh_pos_iff]
@[simp]
theorem cosh_le_cosh : cosh x ≤ cosh y ↔ |x| ≤ |y| :=
cosh_abs x ▸ cosh_abs y ▸ cosh_strictMonoOn.le_iff_le (abs_nonneg x) (abs_nonneg y)
@[simp]
theorem cosh_lt_cosh : cosh x < cosh y ↔ |x| < |y| :=
lt_iff_lt_of_le_iff_le cosh_le_cosh
@[simp]
theorem one_le_cosh (x : ℝ) : 1 ≤ cosh x :=
cosh_zero ▸ cosh_le_cosh.2 (by simp only [_root_.abs_zero, _root_.abs_nonneg])
@[simp]
theorem one_lt_cosh : 1 < cosh x ↔ x ≠ 0 :=
cosh_zero ▸ cosh_lt_cosh.trans (by simp only [_root_.abs_zero, abs_pos])
theorem sinh_sub_id_strictMono : StrictMono fun x => sinh x - x := by
-- Porting note: `by simp; abel` was just `by simp` in mathlib3.
refine strictMono_of_odd_strictMonoOn_nonneg (fun x => by simp; abel) ?_
refine strictMonoOn_of_deriv_pos (convex_Ici _) ?_ fun x hx => ?_
· exact (continuous_sinh.sub continuous_id).continuousOn
· rw [interior_Ici, mem_Ioi] at hx
rw [deriv_sub, deriv_sinh, deriv_id'', sub_pos, one_lt_cosh]
exacts [hx.ne', differentiableAt_sinh, differentiableAt_id]
@[simp]
theorem self_le_sinh_iff : x ≤ sinh x ↔ 0 ≤ x :=
calc
x ≤ sinh x ↔ sinh 0 - 0 ≤ sinh x - x := by simp
_ ↔ 0 ≤ x := sinh_sub_id_strictMono.le_iff_le
@[simp]
theorem sinh_le_self_iff : sinh x ≤ x ↔ x ≤ 0 :=
calc
sinh x ≤ x ↔ sinh x - x ≤ sinh 0 - 0 := by simp
_ ↔ x ≤ 0 := sinh_sub_id_strictMono.le_iff_le
@[simp]
theorem self_lt_sinh_iff : x < sinh x ↔ 0 < x :=
lt_iff_lt_of_le_iff_le sinh_le_self_iff
@[simp]
theorem sinh_lt_self_iff : sinh x < x ↔ x < 0 :=
lt_iff_lt_of_le_iff_le self_le_sinh_iff
end Real
section
/-! ### Simp lemmas for derivatives of `fun x => Real.cos (f x)` etc., `f : ℝ → ℝ` -/
variable {f : ℝ → ℝ} {f' x : ℝ} {s : Set ℝ}
/-! #### `Real.cos` -/
theorem HasStrictDerivAt.cos (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => Real.cos (f x)) (-Real.sin (f x) * f') x :=
(Real.hasStrictDerivAt_cos (f x)).comp x hf
theorem HasDerivAt.cos (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => Real.cos (f x)) (-Real.sin (f x) * f') x :=
(Real.hasDerivAt_cos (f x)).comp x hf
theorem HasDerivWithinAt.cos (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => Real.cos (f x)) (-Real.sin (f x) * f') s x :=
(Real.hasDerivAt_cos (f x)).comp_hasDerivWithinAt x hf
theorem derivWithin_cos (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) :
derivWithin (fun x => Real.cos (f x)) s x = -Real.sin (f x) * derivWithin f s x :=
hf.hasDerivWithinAt.cos.derivWithin hxs
@[simp]
theorem deriv_cos (hc : DifferentiableAt ℝ f x) :
deriv (fun x => Real.cos (f x)) x = -Real.sin (f x) * deriv f x :=
hc.hasDerivAt.cos.deriv
/-! #### `Real.sin` -/
theorem HasStrictDerivAt.sin (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => Real.sin (f x)) (Real.cos (f x) * f') x :=
(Real.hasStrictDerivAt_sin (f x)).comp x hf
theorem HasDerivAt.sin (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => Real.sin (f x)) (Real.cos (f x) * f') x :=
(Real.hasDerivAt_sin (f x)).comp x hf
theorem HasDerivWithinAt.sin (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => Real.sin (f x)) (Real.cos (f x) * f') s x :=
(Real.hasDerivAt_sin (f x)).comp_hasDerivWithinAt x hf
theorem derivWithin_sin (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) :
derivWithin (fun x => Real.sin (f x)) s x = Real.cos (f x) * derivWithin f s x :=
hf.hasDerivWithinAt.sin.derivWithin hxs
@[simp]
theorem deriv_sin (hc : DifferentiableAt ℝ f x) :
deriv (fun x => Real.sin (f x)) x = Real.cos (f x) * deriv f x :=
hc.hasDerivAt.sin.deriv
/-! #### `Real.cosh` -/
theorem HasStrictDerivAt.cosh (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => Real.cosh (f x)) (Real.sinh (f x) * f') x :=
(Real.hasStrictDerivAt_cosh (f x)).comp x hf
theorem HasDerivAt.cosh (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => Real.cosh (f x)) (Real.sinh (f x) * f') x :=
(Real.hasDerivAt_cosh (f x)).comp x hf
theorem HasDerivWithinAt.cosh (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => Real.cosh (f x)) (Real.sinh (f x) * f') s x :=
(Real.hasDerivAt_cosh (f x)).comp_hasDerivWithinAt x hf
theorem derivWithin_cosh (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) :
derivWithin (fun x => Real.cosh (f x)) s x = Real.sinh (f x) * derivWithin f s x :=
hf.hasDerivWithinAt.cosh.derivWithin hxs
@[simp]
theorem deriv_cosh (hc : DifferentiableAt ℝ f x) :
deriv (fun x => Real.cosh (f x)) x = Real.sinh (f x) * deriv f x :=
hc.hasDerivAt.cosh.deriv
/-! #### `Real.sinh` -/
theorem HasStrictDerivAt.sinh (hf : HasStrictDerivAt f f' x) :
HasStrictDerivAt (fun x => Real.sinh (f x)) (Real.cosh (f x) * f') x :=
(Real.hasStrictDerivAt_sinh (f x)).comp x hf
theorem HasDerivAt.sinh (hf : HasDerivAt f f' x) :
HasDerivAt (fun x => Real.sinh (f x)) (Real.cosh (f x) * f') x :=
(Real.hasDerivAt_sinh (f x)).comp x hf
theorem HasDerivWithinAt.sinh (hf : HasDerivWithinAt f f' s x) :
HasDerivWithinAt (fun x => Real.sinh (f x)) (Real.cosh (f x) * f') s x :=
(Real.hasDerivAt_sinh (f x)).comp_hasDerivWithinAt x hf
theorem derivWithin_sinh (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) :
derivWithin (fun x => Real.sinh (f x)) s x = Real.cosh (f x) * derivWithin f s x :=
hf.hasDerivWithinAt.sinh.derivWithin hxs
@[simp]
theorem deriv_sinh (hc : DifferentiableAt ℝ f x) :
deriv (fun x => Real.sinh (f x)) x = Real.cosh (f x) * deriv f x :=
hc.hasDerivAt.sinh.deriv
end
section
/-! ### Simp lemmas for derivatives of `fun x => Real.cos (f x)` etc., `f : E → ℝ` -/
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] {f : E → ℝ} {f' : E →L[ℝ] ℝ} {x : E}
{s : Set E}
/-! #### `Real.cos` -/
theorem HasStrictFDerivAt.cos (hf : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (fun x => Real.cos (f x)) (-Real.sin (f x) • f') x :=
(Real.hasStrictDerivAt_cos (f x)).comp_hasStrictFDerivAt x hf
theorem HasFDerivAt.cos (hf : HasFDerivAt f f' x) :
HasFDerivAt (fun x => Real.cos (f x)) (-Real.sin (f x) • f') x :=
(Real.hasDerivAt_cos (f x)).comp_hasFDerivAt x hf
theorem HasFDerivWithinAt.cos (hf : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (fun x => Real.cos (f x)) (-Real.sin (f x) • f') s x :=
(Real.hasDerivAt_cos (f x)).comp_hasFDerivWithinAt x hf
theorem DifferentiableWithinAt.cos (hf : DifferentiableWithinAt ℝ f s x) :
DifferentiableWithinAt ℝ (fun x => Real.cos (f x)) s x :=
hf.hasFDerivWithinAt.cos.differentiableWithinAt
@[simp]
theorem DifferentiableAt.cos (hc : DifferentiableAt ℝ f x) :
DifferentiableAt ℝ (fun x => Real.cos (f x)) x :=
hc.hasFDerivAt.cos.differentiableAt
theorem DifferentiableOn.cos (hc : DifferentiableOn ℝ f s) :
DifferentiableOn ℝ (fun x => Real.cos (f x)) s := fun x h => (hc x h).cos
@[simp]
theorem Differentiable.cos (hc : Differentiable ℝ f) : Differentiable ℝ fun x => Real.cos (f x) :=
fun x => (hc x).cos
theorem fderivWithin_cos (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) :
fderivWithin ℝ (fun x => Real.cos (f x)) s x = -Real.sin (f x) • fderivWithin ℝ f s x :=
hf.hasFDerivWithinAt.cos.fderivWithin hxs
@[simp]
theorem fderiv_cos (hc : DifferentiableAt ℝ f x) :
fderiv ℝ (fun x => Real.cos (f x)) x = -Real.sin (f x) • fderiv ℝ f x :=
hc.hasFDerivAt.cos.fderiv
theorem ContDiff.cos {n} (h : ContDiff ℝ n f) : ContDiff ℝ n fun x => Real.cos (f x) :=
Real.contDiff_cos.comp h
theorem ContDiffAt.cos {n} (hf : ContDiffAt ℝ n f x) : ContDiffAt ℝ n (fun x => Real.cos (f x)) x :=
Real.contDiff_cos.contDiffAt.comp x hf
theorem ContDiffOn.cos {n} (hf : ContDiffOn ℝ n f s) : ContDiffOn ℝ n (fun x => Real.cos (f x)) s :=
Real.contDiff_cos.comp_contDiffOn hf
theorem ContDiffWithinAt.cos {n} (hf : ContDiffWithinAt ℝ n f s x) :
ContDiffWithinAt ℝ n (fun x => Real.cos (f x)) s x :=
Real.contDiff_cos.contDiffAt.comp_contDiffWithinAt x hf
/-! #### `Real.sin` -/
theorem HasStrictFDerivAt.sin (hf : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (fun x => Real.sin (f x)) (Real.cos (f x) • f') x :=
(Real.hasStrictDerivAt_sin (f x)).comp_hasStrictFDerivAt x hf
theorem HasFDerivAt.sin (hf : HasFDerivAt f f' x) :
HasFDerivAt (fun x => Real.sin (f x)) (Real.cos (f x) • f') x :=
(Real.hasDerivAt_sin (f x)).comp_hasFDerivAt x hf
theorem HasFDerivWithinAt.sin (hf : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (fun x => Real.sin (f x)) (Real.cos (f x) • f') s x :=
(Real.hasDerivAt_sin (f x)).comp_hasFDerivWithinAt x hf
theorem DifferentiableWithinAt.sin (hf : DifferentiableWithinAt ℝ f s x) :
DifferentiableWithinAt ℝ (fun x => Real.sin (f x)) s x :=
hf.hasFDerivWithinAt.sin.differentiableWithinAt
@[simp]
theorem DifferentiableAt.sin (hc : DifferentiableAt ℝ f x) :
DifferentiableAt ℝ (fun x => Real.sin (f x)) x :=
hc.hasFDerivAt.sin.differentiableAt
theorem DifferentiableOn.sin (hc : DifferentiableOn ℝ f s) :
DifferentiableOn ℝ (fun x => Real.sin (f x)) s := fun x h => (hc x h).sin
@[simp]
theorem Differentiable.sin (hc : Differentiable ℝ f) : Differentiable ℝ fun x => Real.sin (f x) :=
fun x => (hc x).sin
theorem fderivWithin_sin (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) :
fderivWithin ℝ (fun x => Real.sin (f x)) s x = Real.cos (f x) • fderivWithin ℝ f s x :=
hf.hasFDerivWithinAt.sin.fderivWithin hxs
@[simp]
theorem fderiv_sin (hc : DifferentiableAt ℝ f x) :
fderiv ℝ (fun x => Real.sin (f x)) x = Real.cos (f x) • fderiv ℝ f x :=
hc.hasFDerivAt.sin.fderiv
theorem ContDiff.sin {n} (h : ContDiff ℝ n f) : ContDiff ℝ n fun x => Real.sin (f x) :=
Real.contDiff_sin.comp h
theorem ContDiffAt.sin {n} (hf : ContDiffAt ℝ n f x) : ContDiffAt ℝ n (fun x => Real.sin (f x)) x :=
Real.contDiff_sin.contDiffAt.comp x hf
theorem ContDiffOn.sin {n} (hf : ContDiffOn ℝ n f s) : ContDiffOn ℝ n (fun x => Real.sin (f x)) s :=
Real.contDiff_sin.comp_contDiffOn hf
theorem ContDiffWithinAt.sin {n} (hf : ContDiffWithinAt ℝ n f s x) :
ContDiffWithinAt ℝ n (fun x => Real.sin (f x)) s x :=
Real.contDiff_sin.contDiffAt.comp_contDiffWithinAt x hf
/-! #### `Real.cosh` -/
theorem HasStrictFDerivAt.cosh (hf : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (fun x => Real.cosh (f x)) (Real.sinh (f x) • f') x :=
(Real.hasStrictDerivAt_cosh (f x)).comp_hasStrictFDerivAt x hf
theorem HasFDerivAt.cosh (hf : HasFDerivAt f f' x) :
HasFDerivAt (fun x => Real.cosh (f x)) (Real.sinh (f x) • f') x :=
(Real.hasDerivAt_cosh (f x)).comp_hasFDerivAt x hf
theorem HasFDerivWithinAt.cosh (hf : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (fun x => Real.cosh (f x)) (Real.sinh (f x) • f') s x :=
(Real.hasDerivAt_cosh (f x)).comp_hasFDerivWithinAt x hf
theorem DifferentiableWithinAt.cosh (hf : DifferentiableWithinAt ℝ f s x) :
DifferentiableWithinAt ℝ (fun x => Real.cosh (f x)) s x :=
hf.hasFDerivWithinAt.cosh.differentiableWithinAt
@[simp]
theorem DifferentiableAt.cosh (hc : DifferentiableAt ℝ f x) :
DifferentiableAt ℝ (fun x => Real.cosh (f x)) x :=
hc.hasFDerivAt.cosh.differentiableAt
theorem DifferentiableOn.cosh (hc : DifferentiableOn ℝ f s) :
DifferentiableOn ℝ (fun x => Real.cosh (f x)) s := fun x h => (hc x h).cosh
@[simp]
theorem Differentiable.cosh (hc : Differentiable ℝ f) : Differentiable ℝ fun x => Real.cosh (f x) :=
fun x => (hc x).cosh
theorem fderivWithin_cosh (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) :
fderivWithin ℝ (fun x => Real.cosh (f x)) s x = Real.sinh (f x) • fderivWithin ℝ f s x :=
hf.hasFDerivWithinAt.cosh.fderivWithin hxs
@[simp]
theorem fderiv_cosh (hc : DifferentiableAt ℝ f x) :
fderiv ℝ (fun x => Real.cosh (f x)) x = Real.sinh (f x) • fderiv ℝ f x :=
hc.hasFDerivAt.cosh.fderiv
theorem ContDiff.cosh {n} (h : ContDiff ℝ n f) : ContDiff ℝ n fun x => Real.cosh (f x) :=
Real.contDiff_cosh.comp h
theorem ContDiffAt.cosh {n} (hf : ContDiffAt ℝ n f x) :
ContDiffAt ℝ n (fun x => Real.cosh (f x)) x :=
Real.contDiff_cosh.contDiffAt.comp x hf
theorem ContDiffOn.cosh {n} (hf : ContDiffOn ℝ n f s) :
ContDiffOn ℝ n (fun x => Real.cosh (f x)) s :=
Real.contDiff_cosh.comp_contDiffOn hf
theorem ContDiffWithinAt.cosh {n} (hf : ContDiffWithinAt ℝ n f s x) :
ContDiffWithinAt ℝ n (fun x => Real.cosh (f x)) s x :=
Real.contDiff_cosh.contDiffAt.comp_contDiffWithinAt x hf
/-! #### `Real.sinh` -/
theorem HasStrictFDerivAt.sinh (hf : HasStrictFDerivAt f f' x) :
HasStrictFDerivAt (fun x => Real.sinh (f x)) (Real.cosh (f x) • f') x :=
(Real.hasStrictDerivAt_sinh (f x)).comp_hasStrictFDerivAt x hf
theorem HasFDerivAt.sinh (hf : HasFDerivAt f f' x) :
HasFDerivAt (fun x => Real.sinh (f x)) (Real.cosh (f x) • f') x :=
(Real.hasDerivAt_sinh (f x)).comp_hasFDerivAt x hf
theorem HasFDerivWithinAt.sinh (hf : HasFDerivWithinAt f f' s x) :
HasFDerivWithinAt (fun x => Real.sinh (f x)) (Real.cosh (f x) • f') s x :=
(Real.hasDerivAt_sinh (f x)).comp_hasFDerivWithinAt x hf
theorem DifferentiableWithinAt.sinh (hf : DifferentiableWithinAt ℝ f s x) :
DifferentiableWithinAt ℝ (fun x => Real.sinh (f x)) s x :=
hf.hasFDerivWithinAt.sinh.differentiableWithinAt
@[simp]
theorem DifferentiableAt.sinh (hc : DifferentiableAt ℝ f x) :
DifferentiableAt ℝ (fun x => Real.sinh (f x)) x :=
hc.hasFDerivAt.sinh.differentiableAt
theorem DifferentiableOn.sinh (hc : DifferentiableOn ℝ f s) :
DifferentiableOn ℝ (fun x => Real.sinh (f x)) s := fun x h => (hc x h).sinh
@[simp]
theorem Differentiable.sinh (hc : Differentiable ℝ f) : Differentiable ℝ fun x => Real.sinh (f x) :=
fun x => (hc x).sinh
theorem fderivWithin_sinh (hf : DifferentiableWithinAt ℝ f s x) (hxs : UniqueDiffWithinAt ℝ s x) :
fderivWithin ℝ (fun x => Real.sinh (f x)) s x = Real.cosh (f x) • fderivWithin ℝ f s x :=
hf.hasFDerivWithinAt.sinh.fderivWithin hxs
@[simp]
theorem fderiv_sinh (hc : DifferentiableAt ℝ f x) :
fderiv ℝ (fun x => Real.sinh (f x)) x = Real.cosh (f x) • fderiv ℝ f x :=
hc.hasFDerivAt.sinh.fderiv
theorem ContDiff.sinh {n} (h : ContDiff ℝ n f) : ContDiff ℝ n fun x => Real.sinh (f x) :=
Real.contDiff_sinh.comp h
theorem ContDiffAt.sinh {n} (hf : ContDiffAt ℝ n f x) :
ContDiffAt ℝ n (fun x => Real.sinh (f x)) x :=
Real.contDiff_sinh.contDiffAt.comp x hf
theorem ContDiffOn.sinh {n} (hf : ContDiffOn ℝ n f s) :
ContDiffOn ℝ n (fun x => Real.sinh (f x)) s :=
Real.contDiff_sinh.comp_contDiffOn hf
theorem ContDiffWithinAt.sinh {n} (hf : ContDiffWithinAt ℝ n f s x) :
ContDiffWithinAt ℝ n (fun x => Real.sinh (f x)) s x :=
Real.contDiff_sinh.contDiffAt.comp_contDiffWithinAt x hf
section LogDeriv
@[simp]
theorem Complex.logDeriv_sin : logDeriv (Complex.sin) = Complex.cot := by
ext
rw [logDeriv, Complex.deriv_sin, Pi.div_apply, Complex.cot]
@[simp]
theorem Real.logDeriv_sin : logDeriv (Real.sin) = Real.cot := by
ext
rw [logDeriv, Real.deriv_sin, Pi.div_apply, Real.cot_eq_cos_div_sin]
@[simp]
theorem Complex.logDeriv_cos : logDeriv (Complex.cos) = -Complex.tan := by
ext
rw [logDeriv, Complex.deriv_cos', Pi.div_apply, Pi.neg_apply, Complex.tan, neg_div]
@[simp]
theorem Real.logDeriv_cos : logDeriv (Real.cos) = -Real.tan := by
ext
rw [logDeriv, Real.deriv_cos', Pi.div_apply, Pi.neg_apply, neg_div, Real.tan_eq_sin_div_cos ]
@[simp]
theorem Complex.logDeriv_cosh : logDeriv (Complex.cosh) = Complex.tanh := by
ext
rw [logDeriv, Complex.deriv_cosh, Pi.div_apply, Complex.tanh]
@[simp]
theorem Real.logDeriv_cosh : logDeriv (Real.cosh) = Real.tanh := by
ext
rw [logDeriv, Real.deriv_cosh, Pi.div_apply, Real.tanh_eq_sinh_div_cosh]
@[simp]
theorem Complex.LogDeriv_exp : logDeriv (Complex.exp) = 1 := by
ext
rw [logDeriv, Complex.deriv_exp, Pi.div_apply, ← exp_sub, sub_self, exp_zero, Pi.one_apply]
@[simp]
theorem Real.LogDeriv_exp : logDeriv (Real.exp) = 1 := by
ext
rw [logDeriv, Real.deriv_exp, Pi.div_apply, ← exp_sub, sub_self, exp_zero, Pi.one_apply]
end LogDeriv
end
namespace Mathlib.Meta.Positivity
open Lean Meta Qq
private alias ⟨_, sinh_pos_of_pos⟩ := Real.sinh_pos_iff
private alias ⟨_, sinh_nonneg_of_nonneg⟩ := Real.sinh_nonneg_iff
private alias ⟨_, sinh_ne_zero_of_ne_zero⟩ := Real.sinh_ne_zero
/-- Extension for the `positivity` tactic: `Real.sinh` is positive/nonnegative/nonzero if its input
is. -/
@[positivity Real.sinh _]
def evalSinh : PositivityExt where eval {u α} _ _ e := do
let zα : Q(Zero ℝ) := q(inferInstance)
let pα : Q(PartialOrder ℝ) := q(inferInstance)
match u, α, e with
| 0, ~q(ℝ), ~q(Real.sinh $a) =>
assumeInstancesCommute
match ← core zα pα a with
| .positive pa => return .positive q(sinh_pos_of_pos $pa)
| .nonnegative pa => return .nonnegative q(sinh_nonneg_of_nonneg $pa)
| .nonzero pa => return .nonzero q(sinh_ne_zero_of_ne_zero $pa)
| _ => return .none
| _, _, _ => throwError "not Real.sinh"
example (x : ℝ) (hx : 0 < x) : 0 < x.sinh := by positivity
example (x : ℝ) (hx : 0 ≤ x) : 0 ≤ x.sinh := by positivity
example (x : ℝ) (hx : x ≠ 0) : x.sinh ≠ 0 := by positivity
end Mathlib.Meta.Positivity
|
Analysis\SpecialFunctions\Trigonometric\EulerSineProd.lean | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import Mathlib.Analysis.SpecialFunctions.Integrals
import Mathlib.MeasureTheory.Integral.PeakFunction
/-! # Euler's infinite product for the sine function
This file proves the infinite product formula
$$ \sin \pi z = \pi z \prod_{n = 1}^\infty \left(1 - \frac{z ^ 2}{n ^ 2}\right) $$
for any real or complex `z`. Our proof closely follows the article
[Salwinski, *Euler's Sine Product Formula: An Elementary Proof*][salwinski2018]: the basic strategy
is to prove a recurrence relation for the integrals `∫ x in 0..π/2, cos 2 z x * cos x ^ (2 * n)`,
generalising the arguments used to prove Wallis' limit formula for `π`.
-/
open scoped Real Topology
open Real Set Filter intervalIntegral MeasureTheory.MeasureSpace
namespace EulerSine
section IntegralRecursion
/-! ## Recursion formula for the integral of `cos (2 * z * x) * cos x ^ n`
We evaluate the integral of `cos (2 * z * x) * cos x ^ n`, for any complex `z` and even integers
`n`, via repeated integration by parts. -/
variable {z : ℂ} {n : ℕ}
theorem antideriv_cos_comp_const_mul (hz : z ≠ 0) (x : ℝ) :
HasDerivAt (fun y : ℝ => Complex.sin (2 * z * y) / (2 * z)) (Complex.cos (2 * z * x)) x := by
have a : HasDerivAt (fun y : ℂ => y * (2 * z)) _ x := hasDerivAt_mul_const _
have b : HasDerivAt (fun y : ℂ => Complex.sin (y * (2 * z))) _ x :=
HasDerivAt.comp (x : ℂ) (Complex.hasDerivAt_sin (x * (2 * z))) a
have c := b.comp_ofReal.div_const (2 * z)
field_simp at c; simp only [fun y => mul_comm y (2 * z)] at c
exact c
theorem antideriv_sin_comp_const_mul (hz : z ≠ 0) (x : ℝ) :
HasDerivAt (fun y : ℝ => -Complex.cos (2 * z * y) / (2 * z)) (Complex.sin (2 * z * x)) x := by
have a : HasDerivAt (fun y : ℂ => y * (2 * z)) _ x := hasDerivAt_mul_const _
have b : HasDerivAt (fun y : ℂ => Complex.cos (y * (2 * z))) _ x :=
HasDerivAt.comp (x : ℂ) (Complex.hasDerivAt_cos (x * (2 * z))) a
have c := (b.comp_ofReal.div_const (2 * z)).neg
field_simp at c; simp only [fun y => mul_comm y (2 * z)] at c
exact c
theorem integral_cos_mul_cos_pow_aux (hn : 2 ≤ n) (hz : z ≠ 0) :
(∫ x in (0 : ℝ)..π / 2, Complex.cos (2 * z * x) * (cos x : ℂ) ^ n) =
n / (2 * z) *
∫ x in (0 : ℝ)..π / 2, Complex.sin (2 * z * x) * sin x * (cos x : ℂ) ^ (n - 1) := by
have der1 :
∀ x : ℝ,
x ∈ uIcc 0 (π / 2) →
HasDerivAt (fun y : ℝ => (cos y : ℂ) ^ n) (-n * sin x * (cos x : ℂ) ^ (n - 1)) x := by
intro x _
have b : HasDerivAt (fun y : ℝ => (cos y : ℂ)) (-sin x) x := by
simpa using (hasDerivAt_cos x).ofReal_comp
convert HasDerivAt.comp x (hasDerivAt_pow _ _) b using 1
ring
convert (config := { sameFun := true })
integral_mul_deriv_eq_deriv_mul der1 (fun x _ => antideriv_cos_comp_const_mul hz x) _ _ using 2
· ext1 x; rw [mul_comm]
· rw [Complex.ofReal_zero, mul_zero, Complex.sin_zero, zero_div, mul_zero, sub_zero,
cos_pi_div_two, Complex.ofReal_zero, zero_pow (by positivity : n ≠ 0), zero_mul, zero_sub,
← integral_neg, ← integral_const_mul]
refine integral_congr fun x _ => ?_
field_simp; ring
· apply Continuous.intervalIntegrable
exact
(continuous_const.mul (Complex.continuous_ofReal.comp continuous_sin)).mul
((Complex.continuous_ofReal.comp continuous_cos).pow (n - 1))
· apply Continuous.intervalIntegrable
exact Complex.continuous_cos.comp (continuous_const.mul Complex.continuous_ofReal)
theorem integral_sin_mul_sin_mul_cos_pow_eq (hn : 2 ≤ n) (hz : z ≠ 0) :
(∫ x in (0 : ℝ)..π / 2, Complex.sin (2 * z * x) * sin x * (cos x : ℂ) ^ (n - 1)) =
(n / (2 * z) * ∫ x in (0 : ℝ)..π / 2, Complex.cos (2 * z * x) * (cos x : ℂ) ^ n) -
(n - 1) / (2 * z) *
∫ x in (0 : ℝ)..π / 2, Complex.cos (2 * z * x) * (cos x : ℂ) ^ (n - 2) := by
have der1 :
∀ x : ℝ,
x ∈ uIcc 0 (π / 2) →
HasDerivAt (fun y : ℝ => sin y * (cos y : ℂ) ^ (n - 1))
((cos x : ℂ) ^ n - (n - 1) * (sin x : ℂ) ^ 2 * (cos x : ℂ) ^ (n - 2)) x := by
intro x _
have c := HasDerivAt.comp (x : ℂ) (hasDerivAt_pow (n - 1) _) (Complex.hasDerivAt_cos x)
convert ((Complex.hasDerivAt_sin x).mul c).comp_ofReal using 1
· ext1 y; simp only [Complex.ofReal_sin, Complex.ofReal_cos, Function.comp]
· simp only [Complex.ofReal_cos, Complex.ofReal_sin]
rw [mul_neg, mul_neg, ← sub_eq_add_neg, Function.comp_apply]
congr 1
· rw [← pow_succ', Nat.sub_add_cancel (by omega : 1 ≤ n)]
· have : ((n - 1 : ℕ) : ℂ) = (n : ℂ) - 1 := by
rw [Nat.cast_sub (one_le_two.trans hn), Nat.cast_one]
rw [Nat.sub_sub, this]
ring
convert
integral_mul_deriv_eq_deriv_mul der1 (fun x _ => antideriv_sin_comp_const_mul hz x) _ _ using 1
· refine integral_congr fun x _ => ?_
ring_nf
· -- now a tedious rearrangement of terms
-- gather into a single integral, and deal with continuity subgoals:
rw [sin_zero, cos_pi_div_two, Complex.ofReal_zero, zero_pow, zero_mul,
mul_zero, zero_mul, zero_mul, sub_zero, zero_sub, ←
integral_neg, ← integral_const_mul, ← integral_const_mul, ← integral_sub]
rotate_left
· apply Continuous.intervalIntegrable
exact
continuous_const.mul
((Complex.continuous_cos.comp (continuous_const.mul Complex.continuous_ofReal)).mul
((Complex.continuous_ofReal.comp continuous_cos).pow n))
· apply Continuous.intervalIntegrable
exact
continuous_const.mul
((Complex.continuous_cos.comp (continuous_const.mul Complex.continuous_ofReal)).mul
((Complex.continuous_ofReal.comp continuous_cos).pow (n - 2)))
· exact Nat.sub_ne_zero_of_lt hn
refine integral_congr fun x _ => ?_
dsimp only
-- get rid of real trig functions and divisions by 2 * z:
rw [Complex.ofReal_cos, Complex.ofReal_sin, Complex.sin_sq, ← mul_div_right_comm, ←
mul_div_right_comm, ← sub_div, mul_div, ← neg_div]
congr 1
have : Complex.cos x ^ n = Complex.cos x ^ (n - 2) * Complex.cos x ^ 2 := by
conv_lhs => rw [← Nat.sub_add_cancel hn, pow_add]
rw [this]
ring
· apply Continuous.intervalIntegrable
exact
((Complex.continuous_ofReal.comp continuous_cos).pow n).sub
((continuous_const.mul ((Complex.continuous_ofReal.comp continuous_sin).pow 2)).mul
((Complex.continuous_ofReal.comp continuous_cos).pow (n - 2)))
· apply Continuous.intervalIntegrable
exact Complex.continuous_sin.comp (continuous_const.mul Complex.continuous_ofReal)
/-- Note this also holds for `z = 0`, but we do not need this case for `sin_pi_mul_eq`. -/
theorem integral_cos_mul_cos_pow (hn : 2 ≤ n) (hz : z ≠ 0) :
(((1 : ℂ) - (4 : ℂ) * z ^ 2 / (n : ℂ) ^ 2) *
∫ x in (0 : ℝ)..π / 2, Complex.cos (2 * z * x) * (cos x : ℂ) ^ n) =
(n - 1 : ℂ) / n *
∫ x in (0 : ℝ)..π / 2, Complex.cos (2 * z * x) * (cos x : ℂ) ^ (n - 2) := by
have nne : (n : ℂ) ≠ 0 := by
contrapose! hn; rw [Nat.cast_eq_zero] at hn; rw [hn]; exact zero_lt_two
have := integral_cos_mul_cos_pow_aux hn hz
rw [integral_sin_mul_sin_mul_cos_pow_eq hn hz, sub_eq_neg_add, mul_add, ← sub_eq_iff_eq_add]
at this
convert congr_arg (fun u : ℂ => -u * (2 * z) ^ 2 / n ^ 2) this using 1 <;> field_simp <;> ring
/-- Note this also holds for `z = 0`, but we do not need this case for `sin_pi_mul_eq`. -/
theorem integral_cos_mul_cos_pow_even (n : ℕ) (hz : z ≠ 0) :
(((1 : ℂ) - z ^ 2 / ((n : ℂ) + 1) ^ 2) *
∫ x in (0 : ℝ)..π / 2, Complex.cos (2 * z * x) * (cos x : ℂ) ^ (2 * n + 2)) =
(2 * n + 1 : ℂ) / (2 * n + 2) *
∫ x in (0 : ℝ)..π / 2, Complex.cos (2 * z * x) * (cos x : ℂ) ^ (2 * n) := by
convert integral_cos_mul_cos_pow (by omega : 2 ≤ 2 * n + 2) hz using 3
· simp only [Nat.cast_add, Nat.cast_mul, Nat.cast_two]
nth_rw 2 [← mul_one (2 : ℂ)]
rw [← mul_add, mul_pow, ← div_div]
ring
· push_cast; ring
· push_cast; ring
/-- Relate the integral `cos x ^ n` over `[0, π/2]` to the integral of `sin x ^ n` over `[0, π]`,
which is studied in `Data.Real.Pi.Wallis` and other places. -/
theorem integral_cos_pow_eq (n : ℕ) :
(∫ x in (0 : ℝ)..π / 2, cos x ^ n) = 1 / 2 * ∫ x in (0 : ℝ)..π, sin x ^ n := by
rw [mul_comm (1 / 2 : ℝ), ← div_eq_iff (one_div_ne_zero (two_ne_zero' ℝ)), ← div_mul, div_one,
mul_two]
have L : IntervalIntegrable _ volume 0 (π / 2) := (continuous_sin.pow n).intervalIntegrable _ _
have R : IntervalIntegrable _ volume (π / 2) π := (continuous_sin.pow n).intervalIntegrable _ _
rw [← integral_add_adjacent_intervals L R]
congr 1
· nth_rw 1 [(by ring : 0 = π / 2 - π / 2)]
nth_rw 3 [(by ring : π / 2 = π / 2 - 0)]
rw [← integral_comp_sub_left]
refine integral_congr fun x _ => ?_
rw [cos_pi_div_two_sub]
· nth_rw 3 [(by ring : π = π / 2 + π / 2)]
nth_rw 2 [(by ring : π / 2 = 0 + π / 2)]
rw [← integral_comp_add_right]
refine integral_congr fun x _ => ?_
rw [sin_add_pi_div_two]
theorem integral_cos_pow_pos (n : ℕ) : 0 < ∫ x in (0 : ℝ)..π / 2, cos x ^ n :=
(integral_cos_pow_eq n).symm ▸ mul_pos one_half_pos (integral_sin_pow_pos _)
/-- Finite form of Euler's sine product, with remainder term expressed as a ratio of cosine
integrals. -/
theorem sin_pi_mul_eq (z : ℂ) (n : ℕ) :
Complex.sin (π * z) =
((π * z * ∏ j ∈ Finset.range n, ((1 : ℂ) - z ^ 2 / ((j : ℂ) + 1) ^ 2)) *
∫ x in (0 : ℝ)..π / 2, Complex.cos (2 * z * x) * (cos x : ℂ) ^ (2 * n)) /
(∫ x in (0 : ℝ)..π / 2, cos x ^ (2 * n) : ℝ) := by
rcases eq_or_ne z 0 with (rfl | hz)
· simp
induction' n with n hn
· simp_rw [mul_zero, pow_zero, mul_one, Finset.prod_range_zero, mul_one,
integral_one, sub_zero]
rw [integral_cos_mul_complex (mul_ne_zero two_ne_zero hz), Complex.ofReal_zero,
mul_zero, Complex.sin_zero, zero_div, sub_zero,
(by push_cast; field_simp; ring : 2 * z * ↑(π / 2) = π * z)]
field_simp [Complex.ofReal_ne_zero.mpr pi_pos.ne']
ring
· rw [hn, Finset.prod_range_succ]
set A := ∏ j ∈ Finset.range n, ((1 : ℂ) - z ^ 2 / ((j : ℂ) + 1) ^ 2)
set B := ∫ x in (0 : ℝ)..π / 2, Complex.cos (2 * z * x) * (cos x : ℂ) ^ (2 * n)
set C := ∫ x in (0 : ℝ)..π / 2, cos x ^ (2 * n)
have aux' : 2 * n.succ = 2 * n + 2 := by rw [Nat.succ_eq_add_one, mul_add, mul_one]
have : (∫ x in (0 : ℝ)..π / 2, cos x ^ (2 * n.succ)) = (2 * (n : ℝ) + 1) / (2 * n + 2) * C := by
rw [integral_cos_pow_eq]
dsimp only [C]
rw [integral_cos_pow_eq, aux', integral_sin_pow, sin_zero, sin_pi, pow_succ',
zero_mul, zero_mul, zero_mul, sub_zero, zero_div,
zero_add, ← mul_assoc, ← mul_assoc, mul_comm (1 / 2 : ℝ) _, Nat.cast_mul, Nat.cast_eq_ofNat]
rw [this]
change
π * z * A * B / C =
(π * z * (A * ((1 : ℂ) - z ^ 2 / ((n : ℂ) + 1) ^ 2)) *
∫ x in (0 : ℝ)..π / 2, Complex.cos (2 * z * x) * (cos x : ℂ) ^ (2 * n.succ)) /
((2 * n + 1) / (2 * n + 2) * C : ℝ)
have :
(π * z * (A * ((1 : ℂ) - z ^ 2 / ((n : ℂ) + 1) ^ 2)) *
∫ x in (0 : ℝ)..π / 2, Complex.cos (2 * z * x) * (cos x : ℂ) ^ (2 * n.succ)) =
π * z * A *
(((1 : ℂ) - z ^ 2 / (n.succ : ℂ) ^ 2) *
∫ x in (0 : ℝ)..π / 2, Complex.cos (2 * z * x) * (cos x : ℂ) ^ (2 * n.succ)) := by
nth_rw 2 [Nat.succ_eq_add_one]
rw [Nat.cast_add_one]
ring
rw [this]
suffices
(((1 : ℂ) - z ^ 2 / (n.succ : ℂ) ^ 2) *
∫ x in (0 : ℝ)..π / 2, Complex.cos (2 * z * x) * (cos x : ℂ) ^ (2 * n.succ)) =
(2 * n + 1) / (2 * n + 2) * B by
rw [this, Complex.ofReal_mul, Complex.ofReal_div]
have : (C : ℂ) ≠ 0 := Complex.ofReal_ne_zero.mpr (integral_cos_pow_pos _).ne'
have : 2 * (n : ℂ) + 1 ≠ 0 := by
convert (Nat.cast_add_one_ne_zero (2 * n) : (↑(2 * n) + 1 : ℂ) ≠ 0)
simp
have : 2 * (n : ℂ) + 2 ≠ 0 := by
convert (Nat.cast_add_one_ne_zero (2 * n + 1) : (↑(2 * n + 1) + 1 : ℂ) ≠ 0) using 1
push_cast; ring
field_simp; ring
convert integral_cos_mul_cos_pow_even n hz
rw [Nat.cast_succ]
end IntegralRecursion
/-! ## Conclusion of the proof
The main theorem `Complex.tendsto_euler_sin_prod`, and its real variant
`Real.tendsto_euler_sin_prod`, now follow by combining `sin_pi_mul_eq` with a lemma
stating that the sequence of measures on `[0, π/2]` given by integration against `cos x ^ n`
(suitably normalised) tends to the Dirac measure at 0, as a special case of the general result
`tendsto_setIntegral_pow_smul_of_unique_maximum_of_isCompact_of_continuousOn`. -/
theorem tendsto_integral_cos_pow_mul_div {f : ℝ → ℂ} (hf : ContinuousOn f (Icc 0 (π / 2))) :
Tendsto
(fun n : ℕ => (∫ x in (0 : ℝ)..π / 2, (cos x : ℂ) ^ n * f x) /
(∫ x in (0 : ℝ)..π / 2, cos x ^ n : ℝ))
atTop (𝓝 <| f 0) := by
simp_rw [div_eq_inv_mul (α := ℂ), ← Complex.ofReal_inv, integral_of_le pi_div_two_pos.le,
← MeasureTheory.integral_Icc_eq_integral_Ioc, ← Complex.ofReal_pow, ← Complex.real_smul]
have c_lt : ∀ y : ℝ, y ∈ Icc 0 (π / 2) → y ≠ 0 → cos y < cos 0 := fun y hy hy' =>
cos_lt_cos_of_nonneg_of_le_pi_div_two (le_refl 0) hy.2 (lt_of_le_of_ne hy.1 hy'.symm)
have c_nonneg : ∀ x : ℝ, x ∈ Icc 0 (π / 2) → 0 ≤ cos x := fun x hx =>
cos_nonneg_of_mem_Icc ((Icc_subset_Icc_left (neg_nonpos_of_nonneg pi_div_two_pos.le)) hx)
have c_zero_pos : 0 < cos 0 := by rw [cos_zero]; exact zero_lt_one
have zero_mem : (0 : ℝ) ∈ closure (interior (Icc 0 (π / 2))) := by
rw [interior_Icc, closure_Ioo pi_div_two_pos.ne, left_mem_Icc]
exact pi_div_two_pos.le
exact
tendsto_setIntegral_pow_smul_of_unique_maximum_of_isCompact_of_continuousOn isCompact_Icc
continuousOn_cos c_lt c_nonneg c_zero_pos zero_mem hf
/-- Euler's infinite product formula for the complex sine function. -/
theorem _root_.Complex.tendsto_euler_sin_prod (z : ℂ) :
Tendsto (fun n : ℕ => π * z * ∏ j ∈ Finset.range n, ((1 : ℂ) - z ^ 2 / ((j : ℂ) + 1) ^ 2))
atTop (𝓝 <| Complex.sin (π * z)) := by
have A :
Tendsto
(fun n : ℕ =>
((π * z * ∏ j ∈ Finset.range n, ((1 : ℂ) - z ^ 2 / ((j : ℂ) + 1) ^ 2)) *
∫ x in (0 : ℝ)..π / 2, Complex.cos (2 * z * x) * (cos x : ℂ) ^ (2 * n)) /
(∫ x in (0 : ℝ)..π / 2, cos x ^ (2 * n) : ℝ))
atTop (𝓝 <| _) :=
Tendsto.congr (fun n => sin_pi_mul_eq z n) tendsto_const_nhds
have : 𝓝 (Complex.sin (π * z)) = 𝓝 (Complex.sin (π * z) * 1) := by rw [mul_one]
simp_rw [this, mul_div_assoc] at A
convert (tendsto_mul_iff_of_ne_zero _ one_ne_zero).mp A
suffices Tendsto (fun n : ℕ =>
(∫ x in (0 : ℝ)..π / 2, Complex.cos (2 * z * x) * (cos x : ℂ) ^ n) /
(∫ x in (0 : ℝ)..π / 2, cos x ^ n : ℝ)) atTop (𝓝 1) from
this.comp (tendsto_id.const_mul_atTop' zero_lt_two)
have : ContinuousOn (fun x : ℝ => Complex.cos (2 * z * x)) (Icc 0 (π / 2)) :=
(Complex.continuous_cos.comp (continuous_const.mul Complex.continuous_ofReal)).continuousOn
convert tendsto_integral_cos_pow_mul_div this using 1
· ext1 n; congr 2 with x : 1; rw [mul_comm]
· rw [Complex.ofReal_zero, mul_zero, Complex.cos_zero]
/-- Euler's infinite product formula for the real sine function. -/
theorem _root_.Real.tendsto_euler_sin_prod (x : ℝ) :
Tendsto (fun n : ℕ => π * x * ∏ j ∈ Finset.range n, ((1 : ℝ) - x ^ 2 / ((j : ℝ) + 1) ^ 2))
atTop (𝓝 <| sin (π * x)) := by
convert (Complex.continuous_re.tendsto _).comp (Complex.tendsto_euler_sin_prod x) using 1
· ext1 n
rw [Function.comp_apply, ← Complex.ofReal_mul, Complex.re_ofReal_mul]
suffices
(∏ j ∈ Finset.range n, (1 - x ^ 2 / (j + 1) ^ 2) : ℂ) =
(∏ j ∈ Finset.range n, (1 - x ^ 2 / (j + 1) ^ 2) : ℝ) by
rw [this, Complex.ofReal_re]
rw [Complex.ofReal_prod]
refine Finset.prod_congr (by rfl) fun n _ => ?_
norm_cast
· rw [← Complex.ofReal_mul, ← Complex.ofReal_sin, Complex.ofReal_re]
end EulerSine
|
Analysis\SpecialFunctions\Trigonometric\Inverse.lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic
import Mathlib.Topology.Order.ProjIcc
/-!
# Inverse trigonometric functions.
See also `Analysis.SpecialFunctions.Trigonometric.Arctan` for the inverse tan function.
(This is delayed as it is easier to set up after developing complex trigonometric functions.)
Basic inequalities on trigonometric functions.
-/
noncomputable section
open scoped Classical
open Topology Filter
open Set Filter
open Real
namespace Real
variable {x y : ℝ}
/-- Inverse of the `sin` function, returns values in the range `-π / 2 ≤ arcsin x ≤ π / 2`.
It defaults to `-π / 2` on `(-∞, -1)` and to `π / 2` to `(1, ∞)`. -/
@[pp_nodot]
noncomputable def arcsin : ℝ → ℝ :=
Subtype.val ∘ IccExtend (neg_le_self zero_le_one) sinOrderIso.symm
theorem arcsin_mem_Icc (x : ℝ) : arcsin x ∈ Icc (-(π / 2)) (π / 2) :=
Subtype.coe_prop _
@[simp]
theorem range_arcsin : range arcsin = Icc (-(π / 2)) (π / 2) := by
rw [arcsin, range_comp Subtype.val]
simp [Icc]
theorem arcsin_le_pi_div_two (x : ℝ) : arcsin x ≤ π / 2 :=
(arcsin_mem_Icc x).2
theorem neg_pi_div_two_le_arcsin (x : ℝ) : -(π / 2) ≤ arcsin x :=
(arcsin_mem_Icc x).1
theorem arcsin_projIcc (x : ℝ) :
arcsin (projIcc (-1) 1 (neg_le_self zero_le_one) x) = arcsin x := by
rw [arcsin, Function.comp_apply, IccExtend_val, Function.comp_apply, IccExtend,
Function.comp_apply]
theorem sin_arcsin' {x : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) : sin (arcsin x) = x := by
simpa [arcsin, IccExtend_of_mem _ _ hx, -OrderIso.apply_symm_apply] using
Subtype.ext_iff.1 (sinOrderIso.apply_symm_apply ⟨x, hx⟩)
theorem sin_arcsin {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : sin (arcsin x) = x :=
sin_arcsin' ⟨hx₁, hx₂⟩
theorem arcsin_sin' {x : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) : arcsin (sin x) = x :=
injOn_sin (arcsin_mem_Icc _) hx <| by rw [sin_arcsin (neg_one_le_sin _) (sin_le_one _)]
theorem arcsin_sin {x : ℝ} (hx₁ : -(π / 2) ≤ x) (hx₂ : x ≤ π / 2) : arcsin (sin x) = x :=
arcsin_sin' ⟨hx₁, hx₂⟩
theorem strictMonoOn_arcsin : StrictMonoOn arcsin (Icc (-1) 1) :=
(Subtype.strictMono_coe _).comp_strictMonoOn <|
sinOrderIso.symm.strictMono.strictMonoOn_IccExtend _
theorem monotone_arcsin : Monotone arcsin :=
(Subtype.mono_coe _).comp <| sinOrderIso.symm.monotone.IccExtend _
theorem injOn_arcsin : InjOn arcsin (Icc (-1) 1) :=
strictMonoOn_arcsin.injOn
theorem arcsin_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) :
arcsin x = arcsin y ↔ x = y :=
injOn_arcsin.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩
@[continuity]
theorem continuous_arcsin : Continuous arcsin :=
continuous_subtype_val.comp sinOrderIso.symm.continuous.Icc_extend'
theorem continuousAt_arcsin {x : ℝ} : ContinuousAt arcsin x :=
continuous_arcsin.continuousAt
theorem arcsin_eq_of_sin_eq {x y : ℝ} (h₁ : sin x = y) (h₂ : x ∈ Icc (-(π / 2)) (π / 2)) :
arcsin y = x := by
subst y
exact injOn_sin (arcsin_mem_Icc _) h₂ (sin_arcsin' (sin_mem_Icc x))
@[simp]
theorem arcsin_zero : arcsin 0 = 0 :=
arcsin_eq_of_sin_eq sin_zero ⟨neg_nonpos.2 pi_div_two_pos.le, pi_div_two_pos.le⟩
@[simp]
theorem arcsin_one : arcsin 1 = π / 2 :=
arcsin_eq_of_sin_eq sin_pi_div_two <| right_mem_Icc.2 (neg_le_self pi_div_two_pos.le)
theorem arcsin_of_one_le {x : ℝ} (hx : 1 ≤ x) : arcsin x = π / 2 := by
rw [← arcsin_projIcc, projIcc_of_right_le _ hx, Subtype.coe_mk, arcsin_one]
theorem arcsin_neg_one : arcsin (-1) = -(π / 2) :=
arcsin_eq_of_sin_eq (by rw [sin_neg, sin_pi_div_two]) <|
left_mem_Icc.2 (neg_le_self pi_div_two_pos.le)
theorem arcsin_of_le_neg_one {x : ℝ} (hx : x ≤ -1) : arcsin x = -(π / 2) := by
rw [← arcsin_projIcc, projIcc_of_le_left _ hx, Subtype.coe_mk, arcsin_neg_one]
@[simp]
theorem arcsin_neg (x : ℝ) : arcsin (-x) = -arcsin x := by
rcases le_total x (-1) with hx₁ | hx₁
· rw [arcsin_of_le_neg_one hx₁, neg_neg, arcsin_of_one_le (le_neg.2 hx₁)]
rcases le_total 1 x with hx₂ | hx₂
· rw [arcsin_of_one_le hx₂, arcsin_of_le_neg_one (neg_le_neg hx₂)]
refine arcsin_eq_of_sin_eq ?_ ?_
· rw [sin_neg, sin_arcsin hx₁ hx₂]
· exact ⟨neg_le_neg (arcsin_le_pi_div_two _), neg_le.2 (neg_pi_div_two_le_arcsin _)⟩
theorem arcsin_le_iff_le_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) :
arcsin x ≤ y ↔ x ≤ sin y := by
rw [← arcsin_sin' hy, strictMonoOn_arcsin.le_iff_le hx (sin_mem_Icc _), arcsin_sin' hy]
theorem arcsin_le_iff_le_sin' {x y : ℝ} (hy : y ∈ Ico (-(π / 2)) (π / 2)) :
arcsin x ≤ y ↔ x ≤ sin y := by
rcases le_total x (-1) with hx₁ | hx₁
· simp [arcsin_of_le_neg_one hx₁, hy.1, hx₁.trans (neg_one_le_sin _)]
cases' lt_or_le 1 x with hx₂ hx₂
· simp [arcsin_of_one_le hx₂.le, hy.2.not_le, (sin_le_one y).trans_lt hx₂]
exact arcsin_le_iff_le_sin ⟨hx₁, hx₂⟩ (mem_Icc_of_Ico hy)
theorem le_arcsin_iff_sin_le {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) :
x ≤ arcsin y ↔ sin x ≤ y := by
rw [← neg_le_neg_iff, ← arcsin_neg,
arcsin_le_iff_le_sin ⟨neg_le_neg hy.2, neg_le.2 hy.1⟩ ⟨neg_le_neg hx.2, neg_le.2 hx.1⟩, sin_neg,
neg_le_neg_iff]
theorem le_arcsin_iff_sin_le' {x y : ℝ} (hx : x ∈ Ioc (-(π / 2)) (π / 2)) :
x ≤ arcsin y ↔ sin x ≤ y := by
rw [← neg_le_neg_iff, ← arcsin_neg, arcsin_le_iff_le_sin' ⟨neg_le_neg hx.2, neg_lt.2 hx.1⟩,
sin_neg, neg_le_neg_iff]
theorem arcsin_lt_iff_lt_sin {x y : ℝ} (hx : x ∈ Icc (-1 : ℝ) 1) (hy : y ∈ Icc (-(π / 2)) (π / 2)) :
arcsin x < y ↔ x < sin y :=
not_le.symm.trans <| (not_congr <| le_arcsin_iff_sin_le hy hx).trans not_le
theorem arcsin_lt_iff_lt_sin' {x y : ℝ} (hy : y ∈ Ioc (-(π / 2)) (π / 2)) :
arcsin x < y ↔ x < sin y :=
not_le.symm.trans <| (not_congr <| le_arcsin_iff_sin_le' hy).trans not_le
theorem lt_arcsin_iff_sin_lt {x y : ℝ} (hx : x ∈ Icc (-(π / 2)) (π / 2)) (hy : y ∈ Icc (-1 : ℝ) 1) :
x < arcsin y ↔ sin x < y :=
not_le.symm.trans <| (not_congr <| arcsin_le_iff_le_sin hy hx).trans not_le
theorem lt_arcsin_iff_sin_lt' {x y : ℝ} (hx : x ∈ Ico (-(π / 2)) (π / 2)) :
x < arcsin y ↔ sin x < y :=
not_le.symm.trans <| (not_congr <| arcsin_le_iff_le_sin' hx).trans not_le
theorem arcsin_eq_iff_eq_sin {x y : ℝ} (hy : y ∈ Ioo (-(π / 2)) (π / 2)) :
arcsin x = y ↔ x = sin y := by
simp only [le_antisymm_iff, arcsin_le_iff_le_sin' (mem_Ico_of_Ioo hy),
le_arcsin_iff_sin_le' (mem_Ioc_of_Ioo hy)]
@[simp]
theorem arcsin_nonneg {x : ℝ} : 0 ≤ arcsin x ↔ 0 ≤ x :=
(le_arcsin_iff_sin_le' ⟨neg_lt_zero.2 pi_div_two_pos, pi_div_two_pos.le⟩).trans <| by
rw [sin_zero]
@[simp]
theorem arcsin_nonpos {x : ℝ} : arcsin x ≤ 0 ↔ x ≤ 0 :=
neg_nonneg.symm.trans <| arcsin_neg x ▸ arcsin_nonneg.trans neg_nonneg
@[simp]
theorem arcsin_eq_zero_iff {x : ℝ} : arcsin x = 0 ↔ x = 0 := by simp [le_antisymm_iff]
@[simp]
theorem zero_eq_arcsin_iff {x} : 0 = arcsin x ↔ x = 0 :=
eq_comm.trans arcsin_eq_zero_iff
@[simp]
theorem arcsin_pos {x : ℝ} : 0 < arcsin x ↔ 0 < x :=
lt_iff_lt_of_le_iff_le arcsin_nonpos
@[simp]
theorem arcsin_lt_zero {x : ℝ} : arcsin x < 0 ↔ x < 0 :=
lt_iff_lt_of_le_iff_le arcsin_nonneg
@[simp]
theorem arcsin_lt_pi_div_two {x : ℝ} : arcsin x < π / 2 ↔ x < 1 :=
(arcsin_lt_iff_lt_sin' (right_mem_Ioc.2 <| neg_lt_self pi_div_two_pos)).trans <| by
rw [sin_pi_div_two]
@[simp]
theorem neg_pi_div_two_lt_arcsin {x : ℝ} : -(π / 2) < arcsin x ↔ -1 < x :=
(lt_arcsin_iff_sin_lt' <| left_mem_Ico.2 <| neg_lt_self pi_div_two_pos).trans <| by
rw [sin_neg, sin_pi_div_two]
@[simp]
theorem arcsin_eq_pi_div_two {x : ℝ} : arcsin x = π / 2 ↔ 1 ≤ x :=
⟨fun h => not_lt.1 fun h' => (arcsin_lt_pi_div_two.2 h').ne h, arcsin_of_one_le⟩
@[simp]
theorem pi_div_two_eq_arcsin {x} : π / 2 = arcsin x ↔ 1 ≤ x :=
eq_comm.trans arcsin_eq_pi_div_two
@[simp]
theorem pi_div_two_le_arcsin {x} : π / 2 ≤ arcsin x ↔ 1 ≤ x :=
(arcsin_le_pi_div_two x).le_iff_eq.trans pi_div_two_eq_arcsin
@[simp]
theorem arcsin_eq_neg_pi_div_two {x : ℝ} : arcsin x = -(π / 2) ↔ x ≤ -1 :=
⟨fun h => not_lt.1 fun h' => (neg_pi_div_two_lt_arcsin.2 h').ne' h, arcsin_of_le_neg_one⟩
@[simp]
theorem neg_pi_div_two_eq_arcsin {x} : -(π / 2) = arcsin x ↔ x ≤ -1 :=
eq_comm.trans arcsin_eq_neg_pi_div_two
@[simp]
theorem arcsin_le_neg_pi_div_two {x} : arcsin x ≤ -(π / 2) ↔ x ≤ -1 :=
(neg_pi_div_two_le_arcsin x).le_iff_eq.trans arcsin_eq_neg_pi_div_two
@[simp]
theorem pi_div_four_le_arcsin {x} : π / 4 ≤ arcsin x ↔ √2 / 2 ≤ x := by
rw [← sin_pi_div_four, le_arcsin_iff_sin_le']
have := pi_pos
constructor <;> linarith
theorem mapsTo_sin_Ioo : MapsTo sin (Ioo (-(π / 2)) (π / 2)) (Ioo (-1) 1) := fun x h => by
rwa [mem_Ioo, ← arcsin_lt_pi_div_two, ← neg_pi_div_two_lt_arcsin, arcsin_sin h.1.le h.2.le]
/-- `Real.sin` as a `PartialHomeomorph` between `(-π / 2, π / 2)` and `(-1, 1)`. -/
@[simp]
def sinPartialHomeomorph : PartialHomeomorph ℝ ℝ where
toFun := sin
invFun := arcsin
source := Ioo (-(π / 2)) (π / 2)
target := Ioo (-1) 1
map_source' := mapsTo_sin_Ioo
map_target' _ hy := ⟨neg_pi_div_two_lt_arcsin.2 hy.1, arcsin_lt_pi_div_two.2 hy.2⟩
left_inv' _ hx := arcsin_sin hx.1.le hx.2.le
right_inv' _ hy := sin_arcsin hy.1.le hy.2.le
open_source := isOpen_Ioo
open_target := isOpen_Ioo
continuousOn_toFun := continuous_sin.continuousOn
continuousOn_invFun := continuous_arcsin.continuousOn
theorem cos_arcsin_nonneg (x : ℝ) : 0 ≤ cos (arcsin x) :=
cos_nonneg_of_mem_Icc ⟨neg_pi_div_two_le_arcsin _, arcsin_le_pi_div_two _⟩
-- The junk values for `arcsin` and `sqrt` make this true even outside `[-1, 1]`.
theorem cos_arcsin (x : ℝ) : cos (arcsin x) = √(1 - x ^ 2) := by
by_cases hx₁ : -1 ≤ x; swap
· rw [not_le] at hx₁
rw [arcsin_of_le_neg_one hx₁.le, cos_neg, cos_pi_div_two, sqrt_eq_zero_of_nonpos]
nlinarith
by_cases hx₂ : x ≤ 1; swap
· rw [not_le] at hx₂
rw [arcsin_of_one_le hx₂.le, cos_pi_div_two, sqrt_eq_zero_of_nonpos]
nlinarith
have : sin (arcsin x) ^ 2 + cos (arcsin x) ^ 2 = 1 := sin_sq_add_cos_sq (arcsin x)
rw [← eq_sub_iff_add_eq', ← sqrt_inj (sq_nonneg _) (sub_nonneg.2 (sin_sq_le_one (arcsin x))), sq,
sqrt_mul_self (cos_arcsin_nonneg _)] at this
rw [this, sin_arcsin hx₁ hx₂]
-- The junk values for `arcsin` and `sqrt` make this true even outside `[-1, 1]`.
theorem tan_arcsin (x : ℝ) : tan (arcsin x) = x / √(1 - x ^ 2) := by
rw [tan_eq_sin_div_cos, cos_arcsin]
by_cases hx₁ : -1 ≤ x; swap
· have h : √(1 - x ^ 2) = 0 := sqrt_eq_zero_of_nonpos (by nlinarith)
rw [h]
simp
by_cases hx₂ : x ≤ 1; swap
· have h : √(1 - x ^ 2) = 0 := sqrt_eq_zero_of_nonpos (by nlinarith)
rw [h]
simp
rw [sin_arcsin hx₁ hx₂]
/-- Inverse of the `cos` function, returns values in the range `0 ≤ arccos x` and `arccos x ≤ π`.
It defaults to `π` on `(-∞, -1)` and to `0` to `(1, ∞)`. -/
@[pp_nodot]
noncomputable def arccos (x : ℝ) : ℝ :=
π / 2 - arcsin x
theorem arccos_eq_pi_div_two_sub_arcsin (x : ℝ) : arccos x = π / 2 - arcsin x :=
rfl
theorem arcsin_eq_pi_div_two_sub_arccos (x : ℝ) : arcsin x = π / 2 - arccos x := by simp [arccos]
theorem arccos_le_pi (x : ℝ) : arccos x ≤ π := by
unfold arccos; linarith [neg_pi_div_two_le_arcsin x]
theorem arccos_nonneg (x : ℝ) : 0 ≤ arccos x := by
unfold arccos; linarith [arcsin_le_pi_div_two x]
@[simp]
theorem arccos_pos {x : ℝ} : 0 < arccos x ↔ x < 1 := by simp [arccos]
theorem cos_arccos {x : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) : cos (arccos x) = x := by
rw [arccos, cos_pi_div_two_sub, sin_arcsin hx₁ hx₂]
theorem arccos_cos {x : ℝ} (hx₁ : 0 ≤ x) (hx₂ : x ≤ π) : arccos (cos x) = x := by
rw [arccos, ← sin_pi_div_two_sub, arcsin_sin] <;> simp [sub_eq_add_neg] <;> linarith
lemma arccos_eq_of_eq_cos (hy₀ : 0 ≤ y) (hy₁ : y ≤ π) (hxy : x = cos y) : arccos x = y := by
rw [hxy, arccos_cos hy₀ hy₁]
theorem strictAntiOn_arccos : StrictAntiOn arccos (Icc (-1) 1) := fun _ hx _ hy h =>
sub_lt_sub_left (strictMonoOn_arcsin hx hy h) _
theorem arccos_injOn : InjOn arccos (Icc (-1) 1) :=
strictAntiOn_arccos.injOn
theorem arccos_inj {x y : ℝ} (hx₁ : -1 ≤ x) (hx₂ : x ≤ 1) (hy₁ : -1 ≤ y) (hy₂ : y ≤ 1) :
arccos x = arccos y ↔ x = y :=
arccos_injOn.eq_iff ⟨hx₁, hx₂⟩ ⟨hy₁, hy₂⟩
@[simp]
theorem arccos_zero : arccos 0 = π / 2 := by simp [arccos]
@[simp]
theorem arccos_one : arccos 1 = 0 := by simp [arccos]
@[simp]
theorem arccos_neg_one : arccos (-1) = π := by simp [arccos, add_halves]
@[simp]
theorem arccos_eq_zero {x} : arccos x = 0 ↔ 1 ≤ x := by simp [arccos, sub_eq_zero]
@[simp]
theorem arccos_eq_pi_div_two {x} : arccos x = π / 2 ↔ x = 0 := by simp [arccos]
@[simp]
theorem arccos_eq_pi {x} : arccos x = π ↔ x ≤ -1 := by
rw [arccos, sub_eq_iff_eq_add, ← sub_eq_iff_eq_add', div_two_sub_self, neg_pi_div_two_eq_arcsin]
theorem arccos_neg (x : ℝ) : arccos (-x) = π - arccos x := by
rw [← add_halves π, arccos, arcsin_neg, arccos, add_sub_assoc, sub_sub_self, sub_neg_eq_add]
theorem arccos_of_one_le {x : ℝ} (hx : 1 ≤ x) : arccos x = 0 := by
rw [arccos, arcsin_of_one_le hx, sub_self]
theorem arccos_of_le_neg_one {x : ℝ} (hx : x ≤ -1) : arccos x = π := by
rw [arccos, arcsin_of_le_neg_one hx, sub_neg_eq_add, add_halves]
-- The junk values for `arccos` and `sqrt` make this true even outside `[-1, 1]`.
theorem sin_arccos (x : ℝ) : sin (arccos x) = √(1 - x ^ 2) := by
by_cases hx₁ : -1 ≤ x; swap
· rw [not_le] at hx₁
rw [arccos_of_le_neg_one hx₁.le, sin_pi, sqrt_eq_zero_of_nonpos]
nlinarith
by_cases hx₂ : x ≤ 1; swap
· rw [not_le] at hx₂
rw [arccos_of_one_le hx₂.le, sin_zero, sqrt_eq_zero_of_nonpos]
nlinarith
rw [arccos_eq_pi_div_two_sub_arcsin, sin_pi_div_two_sub, cos_arcsin]
@[simp]
theorem arccos_le_pi_div_two {x} : arccos x ≤ π / 2 ↔ 0 ≤ x := by simp [arccos]
@[simp]
theorem arccos_lt_pi_div_two {x : ℝ} : arccos x < π / 2 ↔ 0 < x := by simp [arccos]
@[simp]
theorem arccos_le_pi_div_four {x} : arccos x ≤ π / 4 ↔ √2 / 2 ≤ x := by
rw [arccos, ← pi_div_four_le_arcsin]
constructor <;>
· intro
linarith
@[continuity]
theorem continuous_arccos : Continuous arccos :=
continuous_const.sub continuous_arcsin
-- The junk values for `arccos` and `sqrt` make this true even outside `[-1, 1]`.
theorem tan_arccos (x : ℝ) : tan (arccos x) = √(1 - x ^ 2) / x := by
rw [arccos, tan_pi_div_two_sub, tan_arcsin, inv_div]
-- The junk values for `arccos` and `sqrt` make this true even for `1 < x`.
theorem arccos_eq_arcsin {x : ℝ} (h : 0 ≤ x) : arccos x = arcsin (√(1 - x ^ 2)) :=
(arcsin_eq_of_sin_eq (sin_arccos _)
⟨(Left.neg_nonpos_iff.2 (div_nonneg pi_pos.le (by norm_num))).trans (arccos_nonneg _),
arccos_le_pi_div_two.2 h⟩).symm
-- The junk values for `arcsin` and `sqrt` make this true even for `1 < x`.
theorem arcsin_eq_arccos {x : ℝ} (h : 0 ≤ x) : arcsin x = arccos (√(1 - x ^ 2)) := by
rw [eq_comm, ← cos_arcsin]
exact
arccos_cos (arcsin_nonneg.2 h)
((arcsin_le_pi_div_two _).trans (div_le_self pi_pos.le one_le_two))
end Real
|
Analysis\SpecialFunctions\Trigonometric\InverseDeriv.lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Benjamin Davidson
-/
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Deriv
/-!
# derivatives of the inverse trigonometric functions
Derivatives of `arcsin` and `arccos`.
-/
noncomputable section
open scoped Topology Filter Real
open Set
namespace Real
section Arcsin
theorem deriv_arcsin_aux {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) :
HasStrictDerivAt arcsin (1 / √(1 - x ^ 2)) x ∧ ContDiffAt ℝ ⊤ arcsin x := by
cases' h₁.lt_or_lt with h₁ h₁
· have : 1 - x ^ 2 < 0 := by nlinarith [h₁]
rw [sqrt_eq_zero'.2 this.le, div_zero]
have : arcsin =ᶠ[𝓝 x] fun _ => -(π / 2) :=
(gt_mem_nhds h₁).mono fun y hy => arcsin_of_le_neg_one hy.le
exact ⟨(hasStrictDerivAt_const _ _).congr_of_eventuallyEq this.symm,
contDiffAt_const.congr_of_eventuallyEq this⟩
cases' h₂.lt_or_lt with h₂ h₂
· have : 0 < √(1 - x ^ 2) := sqrt_pos.2 (by nlinarith [h₁, h₂])
simp only [← cos_arcsin, one_div] at this ⊢
exact ⟨sinPartialHomeomorph.hasStrictDerivAt_symm ⟨h₁, h₂⟩ this.ne' (hasStrictDerivAt_sin _),
sinPartialHomeomorph.contDiffAt_symm_deriv this.ne' ⟨h₁, h₂⟩ (hasDerivAt_sin _)
contDiff_sin.contDiffAt⟩
· have : 1 - x ^ 2 < 0 := by nlinarith [h₂]
rw [sqrt_eq_zero'.2 this.le, div_zero]
have : arcsin =ᶠ[𝓝 x] fun _ => π / 2 := (lt_mem_nhds h₂).mono fun y hy => arcsin_of_one_le hy.le
exact ⟨(hasStrictDerivAt_const _ _).congr_of_eventuallyEq this.symm,
contDiffAt_const.congr_of_eventuallyEq this⟩
theorem hasStrictDerivAt_arcsin {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) :
HasStrictDerivAt arcsin (1 / √(1 - x ^ 2)) x :=
(deriv_arcsin_aux h₁ h₂).1
theorem hasDerivAt_arcsin {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) :
HasDerivAt arcsin (1 / √(1 - x ^ 2)) x :=
(hasStrictDerivAt_arcsin h₁ h₂).hasDerivAt
theorem contDiffAt_arcsin {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) {n : ℕ∞} : ContDiffAt ℝ n arcsin x :=
(deriv_arcsin_aux h₁ h₂).2.of_le le_top
theorem hasDerivWithinAt_arcsin_Ici {x : ℝ} (h : x ≠ -1) :
HasDerivWithinAt arcsin (1 / √(1 - x ^ 2)) (Ici x) x := by
rcases eq_or_ne x 1 with (rfl | h')
· convert (hasDerivWithinAt_const (1 : ℝ) _ (π / 2)).congr _ _ <;>
simp (config := { contextual := true }) [arcsin_of_one_le]
· exact (hasDerivAt_arcsin h h').hasDerivWithinAt
theorem hasDerivWithinAt_arcsin_Iic {x : ℝ} (h : x ≠ 1) :
HasDerivWithinAt arcsin (1 / √(1 - x ^ 2)) (Iic x) x := by
rcases em (x = -1) with (rfl | h')
· convert (hasDerivWithinAt_const (-1 : ℝ) _ (-(π / 2))).congr _ _ <;>
simp (config := { contextual := true }) [arcsin_of_le_neg_one]
· exact (hasDerivAt_arcsin h' h).hasDerivWithinAt
theorem differentiableWithinAt_arcsin_Ici {x : ℝ} :
DifferentiableWithinAt ℝ arcsin (Ici x) x ↔ x ≠ -1 := by
refine ⟨?_, fun h => (hasDerivWithinAt_arcsin_Ici h).differentiableWithinAt⟩
rintro h rfl
have : sin ∘ arcsin =ᶠ[𝓝[≥] (-1 : ℝ)] id := by
filter_upwards [Icc_mem_nhdsWithin_Ici ⟨le_rfl, neg_lt_self (zero_lt_one' ℝ)⟩] with x using
sin_arcsin'
have := h.hasDerivWithinAt.sin.congr_of_eventuallyEq this.symm (by simp)
simpa using (uniqueDiffOn_Ici _ _ left_mem_Ici).eq_deriv _ this (hasDerivWithinAt_id _ _)
theorem differentiableWithinAt_arcsin_Iic {x : ℝ} :
DifferentiableWithinAt ℝ arcsin (Iic x) x ↔ x ≠ 1 := by
refine ⟨fun h => ?_, fun h => (hasDerivWithinAt_arcsin_Iic h).differentiableWithinAt⟩
rw [← neg_neg x, ← image_neg_Ici] at h
have := (h.comp (-x) differentiableWithinAt_id.neg (mapsTo_image _ _)).neg
simpa [(· ∘ ·), differentiableWithinAt_arcsin_Ici] using this
theorem differentiableAt_arcsin {x : ℝ} : DifferentiableAt ℝ arcsin x ↔ x ≠ -1 ∧ x ≠ 1 :=
⟨fun h => ⟨differentiableWithinAt_arcsin_Ici.1 h.differentiableWithinAt,
differentiableWithinAt_arcsin_Iic.1 h.differentiableWithinAt⟩,
fun h => (hasDerivAt_arcsin h.1 h.2).differentiableAt⟩
@[simp]
theorem deriv_arcsin : deriv arcsin = fun x => 1 / √(1 - x ^ 2) := by
funext x
by_cases h : x ≠ -1 ∧ x ≠ 1
· exact (hasDerivAt_arcsin h.1 h.2).deriv
· rw [deriv_zero_of_not_differentiableAt (mt differentiableAt_arcsin.1 h)]
simp only [not_and_or, Ne, Classical.not_not] at h
rcases h with (rfl | rfl) <;> simp
theorem differentiableOn_arcsin : DifferentiableOn ℝ arcsin {-1, 1}ᶜ := fun _x hx =>
(differentiableAt_arcsin.2
⟨fun h => hx (Or.inl h), fun h => hx (Or.inr h)⟩).differentiableWithinAt
theorem contDiffOn_arcsin {n : ℕ∞} : ContDiffOn ℝ n arcsin {-1, 1}ᶜ := fun _x hx =>
(contDiffAt_arcsin (mt Or.inl hx) (mt Or.inr hx)).contDiffWithinAt
theorem contDiffAt_arcsin_iff {x : ℝ} {n : ℕ∞} : ContDiffAt ℝ n arcsin x ↔ n = 0 ∨ x ≠ -1 ∧ x ≠ 1 :=
⟨fun h => or_iff_not_imp_left.2 fun hn => differentiableAt_arcsin.1 <| h.differentiableAt <|
ENat.one_le_iff_ne_zero.2 hn,
fun h => h.elim (fun hn => hn.symm ▸ (contDiff_zero.2 continuous_arcsin).contDiffAt) fun hx =>
contDiffAt_arcsin hx.1 hx.2⟩
end Arcsin
section Arccos
theorem hasStrictDerivAt_arccos {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) :
HasStrictDerivAt arccos (-(1 / √(1 - x ^ 2))) x :=
(hasStrictDerivAt_arcsin h₁ h₂).const_sub (π / 2)
theorem hasDerivAt_arccos {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) :
HasDerivAt arccos (-(1 / √(1 - x ^ 2))) x :=
(hasDerivAt_arcsin h₁ h₂).const_sub (π / 2)
theorem contDiffAt_arccos {x : ℝ} (h₁ : x ≠ -1) (h₂ : x ≠ 1) {n : ℕ∞} : ContDiffAt ℝ n arccos x :=
contDiffAt_const.sub (contDiffAt_arcsin h₁ h₂)
theorem hasDerivWithinAt_arccos_Ici {x : ℝ} (h : x ≠ -1) :
HasDerivWithinAt arccos (-(1 / √(1 - x ^ 2))) (Ici x) x :=
(hasDerivWithinAt_arcsin_Ici h).const_sub _
theorem hasDerivWithinAt_arccos_Iic {x : ℝ} (h : x ≠ 1) :
HasDerivWithinAt arccos (-(1 / √(1 - x ^ 2))) (Iic x) x :=
(hasDerivWithinAt_arcsin_Iic h).const_sub _
theorem differentiableWithinAt_arccos_Ici {x : ℝ} :
DifferentiableWithinAt ℝ arccos (Ici x) x ↔ x ≠ -1 :=
(differentiableWithinAt_const_sub_iff _).trans differentiableWithinAt_arcsin_Ici
theorem differentiableWithinAt_arccos_Iic {x : ℝ} :
DifferentiableWithinAt ℝ arccos (Iic x) x ↔ x ≠ 1 :=
(differentiableWithinAt_const_sub_iff _).trans differentiableWithinAt_arcsin_Iic
theorem differentiableAt_arccos {x : ℝ} : DifferentiableAt ℝ arccos x ↔ x ≠ -1 ∧ x ≠ 1 :=
(differentiableAt_const _).sub_iff_right.trans differentiableAt_arcsin
@[simp]
theorem deriv_arccos : deriv arccos = fun x => -(1 / √(1 - x ^ 2)) :=
funext fun x => (deriv_const_sub _).trans <| by simp only [deriv_arcsin]
theorem differentiableOn_arccos : DifferentiableOn ℝ arccos {-1, 1}ᶜ :=
differentiableOn_arcsin.const_sub _
theorem contDiffOn_arccos {n : ℕ∞} : ContDiffOn ℝ n arccos {-1, 1}ᶜ :=
contDiffOn_const.sub contDiffOn_arcsin
theorem contDiffAt_arccos_iff {x : ℝ} {n : ℕ∞} :
ContDiffAt ℝ n arccos x ↔ n = 0 ∨ x ≠ -1 ∧ x ≠ 1 := by
refine Iff.trans ⟨fun h => ?_, fun h => ?_⟩ contDiffAt_arcsin_iff <;>
simpa [arccos] using (contDiffAt_const (c := π / 2)).sub h
end Arccos
end Real
|
Analysis\SpecialFunctions\Trigonometric\Series.lean | /-
Copyright (c) 2023 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser, Yaël Dillies
-/
import Mathlib.Analysis.SpecialFunctions.Exponential
/-!
# Trigonometric functions as sums of infinite series
In this file we express trigonometric functions in terms of their series expansion.
## Main results
* `Complex.hasSum_cos`, `Complex.cos_eq_tsum`: `Complex.cos` as the sum of an infinite series.
* `Real.hasSum_cos`, `Real.cos_eq_tsum`: `Real.cos` as the sum of an infinite series.
* `Complex.hasSum_sin`, `Complex.sin_eq_tsum`: `Complex.sin` as the sum of an infinite series.
* `Real.hasSum_sin`, `Real.sin_eq_tsum`: `Real.sin` as the sum of an infinite series.
-/
open NormedSpace
open scoped Nat
/-! ### `cos` and `sin` for `ℝ` and `ℂ` -/
section SinCos
theorem Complex.hasSum_cos' (z : ℂ) :
HasSum (fun n : ℕ => (z * Complex.I) ^ (2 * n) / ↑(2 * n)!) (Complex.cos z) := by
rw [Complex.cos, Complex.exp_eq_exp_ℂ]
have := ((expSeries_div_hasSum_exp ℂ (z * Complex.I)).add
(expSeries_div_hasSum_exp ℂ (-z * Complex.I))).div_const 2
replace := (Nat.divModEquiv 2).symm.hasSum_iff.mpr this
dsimp [Function.comp_def] at this
simp_rw [← mul_comm 2 _] at this
refine this.prod_fiberwise fun k => ?_
dsimp only
convert hasSum_fintype (_ : Fin 2 → ℂ) using 1
rw [Fin.sum_univ_two]
simp_rw [Fin.val_zero, Fin.val_one, add_zero, pow_succ, pow_mul, mul_pow, neg_sq, ← two_mul,
neg_mul, mul_neg, neg_div, add_right_neg, zero_div, add_zero,
mul_div_cancel_left₀ _ (two_ne_zero : (2 : ℂ) ≠ 0)]
theorem Complex.hasSum_sin' (z : ℂ) :
HasSum (fun n : ℕ => (z * Complex.I) ^ (2 * n + 1) / ↑(2 * n + 1)! / Complex.I)
(Complex.sin z) := by
rw [Complex.sin, Complex.exp_eq_exp_ℂ]
have := (((expSeries_div_hasSum_exp ℂ (-z * Complex.I)).sub
(expSeries_div_hasSum_exp ℂ (z * Complex.I))).mul_right Complex.I).div_const 2
replace := (Nat.divModEquiv 2).symm.hasSum_iff.mpr this
dsimp [Function.comp_def] at this
simp_rw [← mul_comm 2 _] at this
refine this.prod_fiberwise fun k => ?_
dsimp only
convert hasSum_fintype (_ : Fin 2 → ℂ) using 1
rw [Fin.sum_univ_two]
simp_rw [Fin.val_zero, Fin.val_one, add_zero, pow_succ, pow_mul, mul_pow, neg_sq, sub_self,
zero_mul, zero_div, zero_add, neg_mul, mul_neg, neg_div, ← neg_add', ← two_mul,
neg_mul, neg_div, mul_assoc, mul_div_cancel_left₀ _ (two_ne_zero : (2 : ℂ) ≠ 0), Complex.div_I]
/-- The power series expansion of `Complex.cos`. -/
theorem Complex.hasSum_cos (z : ℂ) :
HasSum (fun n : ℕ => (-1) ^ n * z ^ (2 * n) / ↑(2 * n)!) (Complex.cos z) := by
convert Complex.hasSum_cos' z using 1
simp_rw [mul_pow, pow_mul, Complex.I_sq, mul_comm]
/-- The power series expansion of `Complex.sin`. -/
theorem Complex.hasSum_sin (z : ℂ) :
HasSum (fun n : ℕ => (-1) ^ n * z ^ (2 * n + 1) / ↑(2 * n + 1)!) (Complex.sin z) := by
convert Complex.hasSum_sin' z using 1
simp_rw [mul_pow, pow_succ, pow_mul, Complex.I_sq, ← mul_assoc, mul_div_assoc, div_right_comm,
div_self Complex.I_ne_zero, mul_comm _ ((-1 : ℂ) ^ _), mul_one_div, mul_div_assoc, mul_assoc]
theorem Complex.cos_eq_tsum' (z : ℂ) :
Complex.cos z = ∑' n : ℕ, (z * Complex.I) ^ (2 * n) / ↑(2 * n)! :=
(Complex.hasSum_cos' z).tsum_eq.symm
theorem Complex.sin_eq_tsum' (z : ℂ) :
Complex.sin z = ∑' n : ℕ, (z * Complex.I) ^ (2 * n + 1) / ↑(2 * n + 1)! / Complex.I :=
(Complex.hasSum_sin' z).tsum_eq.symm
theorem Complex.cos_eq_tsum (z : ℂ) :
Complex.cos z = ∑' n : ℕ, (-1) ^ n * z ^ (2 * n) / ↑(2 * n)! :=
(Complex.hasSum_cos z).tsum_eq.symm
theorem Complex.sin_eq_tsum (z : ℂ) :
Complex.sin z = ∑' n : ℕ, (-1) ^ n * z ^ (2 * n + 1) / ↑(2 * n + 1)! :=
(Complex.hasSum_sin z).tsum_eq.symm
/-- The power series expansion of `Real.cos`. -/
theorem Real.hasSum_cos (r : ℝ) :
HasSum (fun n : ℕ => (-1) ^ n * r ^ (2 * n) / ↑(2 * n)!) (Real.cos r) :=
mod_cast Complex.hasSum_cos r
/-- The power series expansion of `Real.sin`. -/
theorem Real.hasSum_sin (r : ℝ) :
HasSum (fun n : ℕ => (-1) ^ n * r ^ (2 * n + 1) / ↑(2 * n + 1)!) (Real.sin r) :=
mod_cast Complex.hasSum_sin r
theorem Real.cos_eq_tsum (r : ℝ) : Real.cos r = ∑' n : ℕ, (-1) ^ n * r ^ (2 * n) / ↑(2 * n)! :=
(Real.hasSum_cos r).tsum_eq.symm
theorem Real.sin_eq_tsum (r : ℝ) :
Real.sin r = ∑' n : ℕ, (-1) ^ n * r ^ (2 * n + 1) / ↑(2 * n + 1)! :=
(Real.hasSum_sin r).tsum_eq.symm
end SinCos
/-! ### `cosh` and `sinh` for `ℝ` and `ℂ` -/
section SinhCosh
namespace Complex
/-- The power series expansion of `Complex.cosh`. -/
lemma hasSum_cosh (z : ℂ) : HasSum (fun n ↦ z ^ (2 * n) / ↑(2 * n)!) (cosh z) := by
simpa [mul_assoc, cos_mul_I] using hasSum_cos' (z * I)
/-- The power series expansion of `Complex.sinh`. -/
lemma hasSum_sinh (z : ℂ) : HasSum (fun n ↦ z ^ (2 * n + 1) / ↑(2 * n + 1)!) (sinh z) := by
simpa [mul_assoc, sin_mul_I, neg_pow z, pow_add, pow_mul, neg_mul, neg_div]
using (hasSum_sin' (z * I)).mul_right (-I)
lemma cosh_eq_tsum (z : ℂ) : cosh z = ∑' n, z ^ (2 * n) / ↑(2 * n)! := z.hasSum_cosh.tsum_eq.symm
lemma sinh_eq_tsum (z : ℂ) : sinh z = ∑' n, z ^ (2 * n + 1) / ↑(2 * n + 1)! :=
z.hasSum_sinh.tsum_eq.symm
end Complex
namespace Real
/-- The power series expansion of `Real.cosh`. -/
lemma hasSum_cosh (r : ℝ) : HasSum (fun n ↦ r ^ (2 * n) / ↑(2 * n)!) (cosh r) :=
mod_cast Complex.hasSum_cosh r
/-- The power series expansion of `Real.sinh`. -/
lemma hasSum_sinh (r : ℝ) : HasSum (fun n ↦ r ^ (2 * n + 1) / ↑(2 * n + 1)!) (sinh r) :=
mod_cast Complex.hasSum_sinh r
lemma cosh_eq_tsum (r : ℝ) : cosh r = ∑' n, r ^ (2 * n) / ↑(2 * n)! := r.hasSum_cosh.tsum_eq.symm
lemma sinh_eq_tsum (r : ℝ) : sinh r = ∑' n, r ^ (2 * n + 1) / ↑(2 * n + 1)! :=
r.hasSum_sinh.tsum_eq.symm
lemma cosh_le_exp_half_sq (x : ℝ) : cosh x ≤ exp (x ^ 2 / 2) := by
rw [cosh_eq_tsum, exp_eq_exp_ℝ, exp_eq_tsum]
refine tsum_le_tsum (fun i ↦ ?_) x.hasSum_cosh.summable <| expSeries_summable' (x ^ 2 / 2)
simp only [div_pow, pow_mul, smul_eq_mul, inv_mul_eq_div, div_div]
gcongr
norm_cast
exact Nat.two_pow_mul_factorial_le_factorial_two_mul _
end Real
end SinhCosh
|
Analysis\SpecificLimits\Basic.lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Johannes Hölzl, Yury G. Kudryashov, Patrick Massot
-/
import Mathlib.Algebra.GeomSum
import Mathlib.Order.Filter.Archimedean
import Mathlib.Order.Iterate
import Mathlib.Topology.Algebra.Algebra
import Mathlib.Topology.Algebra.InfiniteSum.Real
import Mathlib.Topology.Instances.EReal
/-!
# A collection of specific limit computations
This file, by design, is independent of `NormedSpace` in the import hierarchy. It contains
important specific limit computations in metric spaces, in ordered rings/fields, and in specific
instances of these such as `ℝ`, `ℝ≥0` and `ℝ≥0∞`.
-/
noncomputable section
open scoped Classical
open Set Function Filter Finset Metric
open scoped Classical
open Topology Nat uniformity NNReal ENNReal
variable {α : Type*} {β : Type*} {ι : Type*}
theorem tendsto_inverse_atTop_nhds_zero_nat : Tendsto (fun n : ℕ ↦ (n : ℝ)⁻¹) atTop (𝓝 0) :=
tendsto_inv_atTop_zero.comp tendsto_natCast_atTop_atTop
@[deprecated (since := "2024-01-31")]
alias tendsto_inverse_atTop_nhds_0_nat := tendsto_inverse_atTop_nhds_zero_nat
theorem tendsto_const_div_atTop_nhds_zero_nat (C : ℝ) :
Tendsto (fun n : ℕ ↦ C / n) atTop (𝓝 0) := by
simpa only [mul_zero] using tendsto_const_nhds.mul tendsto_inverse_atTop_nhds_zero_nat
@[deprecated (since := "2024-01-31")]
alias tendsto_const_div_atTop_nhds_0_nat := tendsto_const_div_atTop_nhds_zero_nat
theorem tendsto_one_div_atTop_nhds_zero_nat : Tendsto (fun n : ℕ ↦ 1/(n : ℝ)) atTop (𝓝 0) :=
tendsto_const_div_atTop_nhds_zero_nat 1
@[deprecated (since := "2024-01-31")]
alias tendsto_one_div_atTop_nhds_0_nat := tendsto_one_div_atTop_nhds_zero_nat
theorem NNReal.tendsto_inverse_atTop_nhds_zero_nat :
Tendsto (fun n : ℕ ↦ (n : ℝ≥0)⁻¹) atTop (𝓝 0) := by
rw [← NNReal.tendsto_coe]
exact _root_.tendsto_inverse_atTop_nhds_zero_nat
@[deprecated (since := "2024-01-31")]
alias NNReal.tendsto_inverse_atTop_nhds_0_nat := NNReal.tendsto_inverse_atTop_nhds_zero_nat
theorem NNReal.tendsto_const_div_atTop_nhds_zero_nat (C : ℝ≥0) :
Tendsto (fun n : ℕ ↦ C / n) atTop (𝓝 0) := by
simpa using tendsto_const_nhds.mul NNReal.tendsto_inverse_atTop_nhds_zero_nat
@[deprecated (since := "2024-01-31")]
alias NNReal.tendsto_const_div_atTop_nhds_0_nat := NNReal.tendsto_const_div_atTop_nhds_zero_nat
theorem EReal.tendsto_const_div_atTop_nhds_zero_nat {C : EReal} (h : C ≠ ⊥) (h' : C ≠ ⊤) :
Tendsto (fun n : ℕ ↦ C / n) atTop (𝓝 0) := by
have : (fun n : ℕ ↦ C / n) = fun n : ℕ ↦ ((C.toReal / n : ℝ) : EReal) := by
ext n
nth_rw 1 [← coe_toReal h' h, ← coe_coe_eq_natCast n, ← coe_div C.toReal n]
rw [this, ← coe_zero, tendsto_coe]
exact _root_.tendsto_const_div_atTop_nhds_zero_nat C.toReal
theorem tendsto_one_div_add_atTop_nhds_zero_nat :
Tendsto (fun n : ℕ ↦ 1 / ((n : ℝ) + 1)) atTop (𝓝 0) :=
suffices Tendsto (fun n : ℕ ↦ 1 / (↑(n + 1) : ℝ)) atTop (𝓝 0) by simpa
(tendsto_add_atTop_iff_nat 1).2 (_root_.tendsto_const_div_atTop_nhds_zero_nat 1)
@[deprecated (since := "2024-01-31")]
alias tendsto_one_div_add_atTop_nhds_0_nat := tendsto_one_div_add_atTop_nhds_zero_nat
theorem NNReal.tendsto_algebraMap_inverse_atTop_nhds_zero_nat (𝕜 : Type*) [Semiring 𝕜]
[Algebra ℝ≥0 𝕜] [TopologicalSpace 𝕜] [ContinuousSMul ℝ≥0 𝕜] :
Tendsto (algebraMap ℝ≥0 𝕜 ∘ fun n : ℕ ↦ (n : ℝ≥0)⁻¹) atTop (𝓝 0) := by
convert (continuous_algebraMap ℝ≥0 𝕜).continuousAt.tendsto.comp
tendsto_inverse_atTop_nhds_zero_nat
rw [map_zero]
@[deprecated (since := "2024-01-31")]
alias NNReal.tendsto_algebraMap_inverse_atTop_nhds_0_nat :=
NNReal.tendsto_algebraMap_inverse_atTop_nhds_zero_nat
theorem tendsto_algebraMap_inverse_atTop_nhds_zero_nat (𝕜 : Type*) [Semiring 𝕜] [Algebra ℝ 𝕜]
[TopologicalSpace 𝕜] [ContinuousSMul ℝ 𝕜] :
Tendsto (algebraMap ℝ 𝕜 ∘ fun n : ℕ ↦ (n : ℝ)⁻¹) atTop (𝓝 0) :=
NNReal.tendsto_algebraMap_inverse_atTop_nhds_zero_nat 𝕜
@[deprecated (since := "2024-01-31")]
alias tendsto_algebraMap_inverse_atTop_nhds_0_nat :=
_root_.tendsto_algebraMap_inverse_atTop_nhds_zero_nat
/-- The limit of `n / (n + x)` is 1, for any constant `x` (valid in `ℝ` or any topological division
algebra over `ℝ`, e.g., `ℂ`).
TODO: introduce a typeclass saying that `1 / n` tends to 0 at top, making it possible to get this
statement simultaneously on `ℚ`, `ℝ` and `ℂ`. -/
theorem tendsto_natCast_div_add_atTop {𝕜 : Type*} [DivisionRing 𝕜] [TopologicalSpace 𝕜]
[CharZero 𝕜] [Algebra ℝ 𝕜] [ContinuousSMul ℝ 𝕜] [TopologicalDivisionRing 𝕜] (x : 𝕜) :
Tendsto (fun n : ℕ ↦ (n : 𝕜) / (n + x)) atTop (𝓝 1) := by
convert Tendsto.congr' ((eventually_ne_atTop 0).mp (eventually_of_forall fun n hn ↦ _)) _
· exact fun n : ℕ ↦ 1 / (1 + x / n)
· field_simp [Nat.cast_ne_zero.mpr hn]
· have : 𝓝 (1 : 𝕜) = 𝓝 (1 / (1 + x * (0 : 𝕜))) := by
rw [mul_zero, add_zero, div_one]
rw [this]
refine tendsto_const_nhds.div (tendsto_const_nhds.add ?_) (by simp)
simp_rw [div_eq_mul_inv]
refine tendsto_const_nhds.mul ?_
have := ((continuous_algebraMap ℝ 𝕜).tendsto _).comp tendsto_inverse_atTop_nhds_zero_nat
rw [map_zero, Filter.tendsto_atTop'] at this
refine Iff.mpr tendsto_atTop' ?_
intros
simp_all only [comp_apply, map_inv₀, map_natCast]
/-! ### Powers -/
theorem tendsto_add_one_pow_atTop_atTop_of_pos [LinearOrderedSemiring α] [Archimedean α] {r : α}
(h : 0 < r) : Tendsto (fun n : ℕ ↦ (r + 1) ^ n) atTop atTop :=
tendsto_atTop_atTop_of_monotone' (fun _ _ ↦ pow_le_pow_right <| le_add_of_nonneg_left h.le) <|
not_bddAbove_iff.2 fun _ ↦ Set.exists_range_iff.2 <| add_one_pow_unbounded_of_pos _ h
theorem tendsto_pow_atTop_atTop_of_one_lt [LinearOrderedRing α] [Archimedean α] {r : α}
(h : 1 < r) : Tendsto (fun n : ℕ ↦ r ^ n) atTop atTop :=
sub_add_cancel r 1 ▸ tendsto_add_one_pow_atTop_atTop_of_pos (sub_pos.2 h)
theorem Nat.tendsto_pow_atTop_atTop_of_one_lt {m : ℕ} (h : 1 < m) :
Tendsto (fun n : ℕ ↦ m ^ n) atTop atTop :=
tsub_add_cancel_of_le (le_of_lt h) ▸ tendsto_add_one_pow_atTop_atTop_of_pos (tsub_pos_of_lt h)
theorem tendsto_pow_atTop_nhds_zero_of_lt_one {𝕜 : Type*} [LinearOrderedField 𝕜] [Archimedean 𝕜]
[TopologicalSpace 𝕜] [OrderTopology 𝕜] {r : 𝕜} (h₁ : 0 ≤ r) (h₂ : r < 1) :
Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝 0) :=
h₁.eq_or_lt.elim
(fun hr ↦ (tendsto_add_atTop_iff_nat 1).mp <| by
simp [_root_.pow_succ, ← hr, tendsto_const_nhds])
(fun hr ↦
have := one_lt_inv hr h₂ |> tendsto_pow_atTop_atTop_of_one_lt
(tendsto_inv_atTop_zero.comp this).congr fun n ↦ by simp)
@[deprecated (since := "2024-01-31")]
alias tendsto_pow_atTop_nhds_0_of_lt_1 := tendsto_pow_atTop_nhds_zero_of_lt_one
@[simp] theorem tendsto_pow_atTop_nhds_zero_iff {𝕜 : Type*} [LinearOrderedField 𝕜] [Archimedean 𝕜]
[TopologicalSpace 𝕜] [OrderTopology 𝕜] {r : 𝕜} :
Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝 0) ↔ |r| < 1 := by
rw [tendsto_zero_iff_abs_tendsto_zero]
refine ⟨fun h ↦ by_contra (fun hr_le ↦ ?_), fun h ↦ ?_⟩
· by_cases hr : 1 = |r|
· replace h : Tendsto (fun n : ℕ ↦ |r|^n) atTop (𝓝 0) := by simpa only [← abs_pow, h]
simp only [hr.symm, one_pow] at h
exact zero_ne_one <| tendsto_nhds_unique h tendsto_const_nhds
· apply @not_tendsto_nhds_of_tendsto_atTop 𝕜 ℕ _ _ _ _ atTop _ (fun n ↦ |r| ^ n) _ 0 _
· refine (pow_right_strictMono <| lt_of_le_of_ne (le_of_not_lt hr_le)
hr).monotone.tendsto_atTop_atTop (fun b ↦ ?_)
obtain ⟨n, hn⟩ := (pow_unbounded_of_one_lt b (lt_of_le_of_ne (le_of_not_lt hr_le) hr))
exact ⟨n, le_of_lt hn⟩
· simpa only [← abs_pow]
· simpa only [← abs_pow] using (tendsto_pow_atTop_nhds_zero_of_lt_one (abs_nonneg r)) h
@[deprecated (since := "2024-01-31")]
alias tendsto_pow_atTop_nhds_0_iff := tendsto_pow_atTop_nhds_zero_iff
theorem tendsto_pow_atTop_nhdsWithin_zero_of_lt_one {𝕜 : Type*} [LinearOrderedField 𝕜]
[Archimedean 𝕜] [TopologicalSpace 𝕜] [OrderTopology 𝕜] {r : 𝕜} (h₁ : 0 < r) (h₂ : r < 1) :
Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝[>] 0) :=
tendsto_inf.2
⟨tendsto_pow_atTop_nhds_zero_of_lt_one h₁.le h₂,
tendsto_principal.2 <| eventually_of_forall fun _ ↦ pow_pos h₁ _⟩
@[deprecated (since := "2024-01-31")]
alias tendsto_pow_atTop_nhdsWithin_0_of_lt_1 := tendsto_pow_atTop_nhdsWithin_zero_of_lt_one
theorem uniformity_basis_dist_pow_of_lt_one {α : Type*} [PseudoMetricSpace α] {r : ℝ} (h₀ : 0 < r)
(h₁ : r < 1) :
(uniformity α).HasBasis (fun _ : ℕ ↦ True) fun k ↦ { p : α × α | dist p.1 p.2 < r ^ k } :=
Metric.mk_uniformity_basis (fun _ _ ↦ pow_pos h₀ _) fun _ ε0 ↦
(exists_pow_lt_of_lt_one ε0 h₁).imp fun _ hk ↦ ⟨trivial, hk.le⟩
@[deprecated (since := "2024-01-31")]
alias uniformity_basis_dist_pow_of_lt_1 := uniformity_basis_dist_pow_of_lt_one
theorem geom_lt {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) {n : ℕ} (hn : 0 < n)
(h : ∀ k < n, c * u k < u (k + 1)) : c ^ n * u 0 < u n := by
apply (monotone_mul_left_of_nonneg hc).seq_pos_lt_seq_of_le_of_lt hn _ _ h
· simp
· simp [_root_.pow_succ', mul_assoc, le_refl]
theorem geom_le {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) (n : ℕ) (h : ∀ k < n, c * u k ≤ u (k + 1)) :
c ^ n * u 0 ≤ u n := by
apply (monotone_mul_left_of_nonneg hc).seq_le_seq n _ _ h <;>
simp [_root_.pow_succ', mul_assoc, le_refl]
theorem lt_geom {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) {n : ℕ} (hn : 0 < n)
(h : ∀ k < n, u (k + 1) < c * u k) : u n < c ^ n * u 0 := by
apply (monotone_mul_left_of_nonneg hc).seq_pos_lt_seq_of_lt_of_le hn _ h _
· simp
· simp [_root_.pow_succ', mul_assoc, le_refl]
theorem le_geom {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) (n : ℕ) (h : ∀ k < n, u (k + 1) ≤ c * u k) :
u n ≤ c ^ n * u 0 := by
apply (monotone_mul_left_of_nonneg hc).seq_le_seq n _ h _ <;>
simp [_root_.pow_succ', mul_assoc, le_refl]
/-- If a sequence `v` of real numbers satisfies `k * v n ≤ v (n+1)` with `1 < k`,
then it goes to +∞. -/
theorem tendsto_atTop_of_geom_le {v : ℕ → ℝ} {c : ℝ} (h₀ : 0 < v 0) (hc : 1 < c)
(hu : ∀ n, c * v n ≤ v (n + 1)) : Tendsto v atTop atTop :=
(tendsto_atTop_mono fun n ↦ geom_le (zero_le_one.trans hc.le) n fun k _ ↦ hu k) <|
(tendsto_pow_atTop_atTop_of_one_lt hc).atTop_mul_const h₀
theorem NNReal.tendsto_pow_atTop_nhds_zero_of_lt_one {r : ℝ≥0} (hr : r < 1) :
Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝 0) :=
NNReal.tendsto_coe.1 <| by
simp only [NNReal.coe_pow, NNReal.coe_zero,
_root_.tendsto_pow_atTop_nhds_zero_of_lt_one r.coe_nonneg hr]
@[deprecated (since := "2024-01-31")]
alias NNReal.tendsto_pow_atTop_nhds_0_of_lt_1 := NNReal.tendsto_pow_atTop_nhds_zero_of_lt_one
@[simp]
protected theorem NNReal.tendsto_pow_atTop_nhds_zero_iff {r : ℝ≥0} :
Tendsto (fun n : ℕ => r ^ n) atTop (𝓝 0) ↔ r < 1 :=
⟨fun h => by simpa [coe_pow, coe_zero, abs_eq, coe_lt_one, val_eq_coe] using
tendsto_pow_atTop_nhds_zero_iff.mp <| tendsto_coe.mpr h, tendsto_pow_atTop_nhds_zero_of_lt_one⟩
theorem ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one {r : ℝ≥0∞} (hr : r < 1) :
Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝 0) := by
rcases ENNReal.lt_iff_exists_coe.1 hr with ⟨r, rfl, hr'⟩
rw [← ENNReal.coe_zero]
norm_cast at *
apply NNReal.tendsto_pow_atTop_nhds_zero_of_lt_one hr
@[deprecated (since := "2024-01-31")]
alias ENNReal.tendsto_pow_atTop_nhds_0_of_lt_1 := ENNReal.tendsto_pow_atTop_nhds_zero_of_lt_one
@[simp]
protected theorem ENNReal.tendsto_pow_atTop_nhds_zero_iff {r : ℝ≥0∞} :
Tendsto (fun n : ℕ => r ^ n) atTop (𝓝 0) ↔ r < 1 := by
refine ⟨fun h ↦ ?_, tendsto_pow_atTop_nhds_zero_of_lt_one⟩
lift r to NNReal
· refine fun hr ↦ top_ne_zero (tendsto_nhds_unique (EventuallyEq.tendsto ?_) (hr ▸ h))
exact eventually_atTop.mpr ⟨1, fun _ hn ↦ pow_eq_top_iff.mpr ⟨rfl, Nat.pos_iff_ne_zero.mp hn⟩⟩
rw [← coe_zero] at h
norm_cast at h ⊢
exact NNReal.tendsto_pow_atTop_nhds_zero_iff.mp h
@[simp]
protected theorem ENNReal.tendsto_pow_atTop_nhds_top_iff {r : ℝ≥0∞} :
Tendsto (fun n ↦ r^n) atTop (𝓝 ∞) ↔ 1 < r := by
refine ⟨?_, ?_⟩
· contrapose!
intro r_le_one h_tends
specialize h_tends (Ioi_mem_nhds one_lt_top)
simp only [Filter.mem_map, mem_atTop_sets, ge_iff_le, Set.mem_preimage, Set.mem_Ioi] at h_tends
obtain ⟨n, hn⟩ := h_tends
exact lt_irrefl _ <| lt_of_lt_of_le (hn n le_rfl) <| pow_le_one n (zero_le _) r_le_one
· intro r_gt_one
have obs := @Tendsto.inv ℝ≥0∞ ℕ _ _ _ (fun n ↦ (r⁻¹)^n) atTop 0
simp only [ENNReal.tendsto_pow_atTop_nhds_zero_iff, inv_zero] at obs
simpa [← ENNReal.inv_pow] using obs <| ENNReal.inv_lt_one.mpr r_gt_one
/-! ### Geometric series-/
section Geometric
theorem hasSum_geometric_of_lt_one {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) :
HasSum (fun n : ℕ ↦ r ^ n) (1 - r)⁻¹ :=
have : r ≠ 1 := ne_of_lt h₂
have : Tendsto (fun n ↦ (r ^ n - 1) * (r - 1)⁻¹) atTop (𝓝 ((0 - 1) * (r - 1)⁻¹)) :=
((tendsto_pow_atTop_nhds_zero_of_lt_one h₁ h₂).sub tendsto_const_nhds).mul tendsto_const_nhds
(hasSum_iff_tendsto_nat_of_nonneg (pow_nonneg h₁) _).mpr <| by
simp_all [neg_inv, geom_sum_eq, div_eq_mul_inv]
@[deprecated (since := "2024-01-31")] alias hasSum_geometric_of_lt_1 := hasSum_geometric_of_lt_one
theorem summable_geometric_of_lt_one {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) :
Summable fun n : ℕ ↦ r ^ n :=
⟨_, hasSum_geometric_of_lt_one h₁ h₂⟩
@[deprecated (since := "2024-01-31")]
alias summable_geometric_of_lt_1 := summable_geometric_of_lt_one
theorem tsum_geometric_of_lt_one {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) : ∑' n : ℕ, r ^ n = (1 - r)⁻¹ :=
(hasSum_geometric_of_lt_one h₁ h₂).tsum_eq
@[deprecated (since := "2024-01-31")] alias tsum_geometric_of_lt_1 := tsum_geometric_of_lt_one
theorem hasSum_geometric_two : HasSum (fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n) 2 := by
convert hasSum_geometric_of_lt_one _ _ <;> norm_num
theorem summable_geometric_two : Summable fun n : ℕ ↦ ((1 : ℝ) / 2) ^ n :=
⟨_, hasSum_geometric_two⟩
theorem summable_geometric_two_encode {ι : Type*} [Encodable ι] :
Summable fun i : ι ↦ (1 / 2 : ℝ) ^ Encodable.encode i :=
summable_geometric_two.comp_injective Encodable.encode_injective
theorem tsum_geometric_two : (∑' n : ℕ, ((1 : ℝ) / 2) ^ n) = 2 :=
hasSum_geometric_two.tsum_eq
theorem sum_geometric_two_le (n : ℕ) : (∑ i ∈ range n, (1 / (2 : ℝ)) ^ i) ≤ 2 := by
have : ∀ i, 0 ≤ (1 / (2 : ℝ)) ^ i := by
intro i
apply pow_nonneg
norm_num
convert sum_le_tsum (range n) (fun i _ ↦ this i) summable_geometric_two
exact tsum_geometric_two.symm
theorem tsum_geometric_inv_two : (∑' n : ℕ, (2 : ℝ)⁻¹ ^ n) = 2 :=
(inv_eq_one_div (2 : ℝ)).symm ▸ tsum_geometric_two
/-- The sum of `2⁻¹ ^ i` for `n ≤ i` equals `2 * 2⁻¹ ^ n`. -/
theorem tsum_geometric_inv_two_ge (n : ℕ) :
(∑' i, ite (n ≤ i) ((2 : ℝ)⁻¹ ^ i) 0) = 2 * 2⁻¹ ^ n := by
have A : Summable fun i : ℕ ↦ ite (n ≤ i) ((2⁻¹ : ℝ) ^ i) 0 := by
simpa only [← piecewise_eq_indicator, one_div]
using summable_geometric_two.indicator {i | n ≤ i}
have B : ((Finset.range n).sum fun i : ℕ ↦ ite (n ≤ i) ((2⁻¹ : ℝ) ^ i) 0) = 0 :=
Finset.sum_eq_zero fun i hi ↦
ite_eq_right_iff.2 fun h ↦ (lt_irrefl _ ((Finset.mem_range.1 hi).trans_le h)).elim
simp only [← _root_.sum_add_tsum_nat_add n A, B, if_true, zero_add, zero_le',
le_add_iff_nonneg_left, pow_add, _root_.tsum_mul_right, tsum_geometric_inv_two]
theorem hasSum_geometric_two' (a : ℝ) : HasSum (fun n : ℕ ↦ a / 2 / 2 ^ n) a := by
convert HasSum.mul_left (a / 2)
(hasSum_geometric_of_lt_one (le_of_lt one_half_pos) one_half_lt_one) using 1
· funext n
simp only [one_div, inv_pow]
rfl
· norm_num
theorem summable_geometric_two' (a : ℝ) : Summable fun n : ℕ ↦ a / 2 / 2 ^ n :=
⟨a, hasSum_geometric_two' a⟩
theorem tsum_geometric_two' (a : ℝ) : ∑' n : ℕ, a / 2 / 2 ^ n = a :=
(hasSum_geometric_two' a).tsum_eq
/-- **Sum of a Geometric Series** -/
theorem NNReal.hasSum_geometric {r : ℝ≥0} (hr : r < 1) : HasSum (fun n : ℕ ↦ r ^ n) (1 - r)⁻¹ := by
apply NNReal.hasSum_coe.1
push_cast
rw [NNReal.coe_sub (le_of_lt hr)]
exact hasSum_geometric_of_lt_one r.coe_nonneg hr
theorem NNReal.summable_geometric {r : ℝ≥0} (hr : r < 1) : Summable fun n : ℕ ↦ r ^ n :=
⟨_, NNReal.hasSum_geometric hr⟩
theorem tsum_geometric_nnreal {r : ℝ≥0} (hr : r < 1) : ∑' n : ℕ, r ^ n = (1 - r)⁻¹ :=
(NNReal.hasSum_geometric hr).tsum_eq
/-- The series `pow r` converges to `(1-r)⁻¹`. For `r < 1` the RHS is a finite number,
and for `1 ≤ r` the RHS equals `∞`. -/
@[simp]
theorem ENNReal.tsum_geometric (r : ℝ≥0∞) : ∑' n : ℕ, r ^ n = (1 - r)⁻¹ := by
cases' lt_or_le r 1 with hr hr
· rcases ENNReal.lt_iff_exists_coe.1 hr with ⟨r, rfl, hr'⟩
norm_cast at *
convert ENNReal.tsum_coe_eq (NNReal.hasSum_geometric hr)
rw [ENNReal.coe_inv <| ne_of_gt <| tsub_pos_iff_lt.2 hr, coe_sub, coe_one]
· rw [tsub_eq_zero_iff_le.mpr hr, ENNReal.inv_zero, ENNReal.tsum_eq_iSup_nat, iSup_eq_top]
refine fun a ha ↦
(ENNReal.exists_nat_gt (lt_top_iff_ne_top.1 ha)).imp fun n hn ↦ lt_of_lt_of_le hn ?_
calc
(n : ℝ≥0∞) = ∑ i ∈ range n, 1 := by rw [sum_const, nsmul_one, card_range]
_ ≤ ∑ i ∈ range n, r ^ i := by gcongr; apply one_le_pow_of_one_le' hr
theorem ENNReal.tsum_geometric_add_one (r : ℝ≥0∞) : ∑' n : ℕ, r ^ (n + 1) = r * (1 - r)⁻¹ := by
simp only [_root_.pow_succ', ENNReal.tsum_mul_left, ENNReal.tsum_geometric]
end Geometric
/-!
### Sequences with geometrically decaying distance in metric spaces
In this paragraph, we discuss sequences in metric spaces or emetric spaces for which the distance
between two consecutive terms decays geometrically. We show that such sequences are Cauchy
sequences, and bound their distances to the limit. We also discuss series with geometrically
decaying terms.
-/
section EdistLeGeometric
variable [PseudoEMetricSpace α] (r C : ℝ≥0∞) (hr : r < 1) (hC : C ≠ ⊤) {f : ℕ → α}
(hu : ∀ n, edist (f n) (f (n + 1)) ≤ C * r ^ n)
/-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, `C ≠ ∞`, `r < 1`,
then `f` is a Cauchy sequence. -/
theorem cauchySeq_of_edist_le_geometric : CauchySeq f := by
refine cauchySeq_of_edist_le_of_tsum_ne_top _ hu ?_
rw [ENNReal.tsum_mul_left, ENNReal.tsum_geometric]
refine ENNReal.mul_ne_top hC (ENNReal.inv_ne_top.2 ?_)
exact (tsub_pos_iff_lt.2 hr).ne'
/-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, then the distance from
`f n` to the limit of `f` is bounded above by `C * r^n / (1 - r)`. -/
theorem edist_le_of_edist_le_geometric_of_tendsto {a : α} (ha : Tendsto f atTop (𝓝 a)) (n : ℕ) :
edist (f n) a ≤ C * r ^ n / (1 - r) := by
convert edist_le_tsum_of_edist_le_of_tendsto _ hu ha _
simp only [pow_add, ENNReal.tsum_mul_left, ENNReal.tsum_geometric, div_eq_mul_inv, mul_assoc]
/-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, then the distance from
`f 0` to the limit of `f` is bounded above by `C / (1 - r)`. -/
theorem edist_le_of_edist_le_geometric_of_tendsto₀ {a : α} (ha : Tendsto f atTop (𝓝 a)) :
edist (f 0) a ≤ C / (1 - r) := by
simpa only [_root_.pow_zero, mul_one] using edist_le_of_edist_le_geometric_of_tendsto r C hu ha 0
end EdistLeGeometric
section EdistLeGeometricTwo
variable [PseudoEMetricSpace α] (C : ℝ≥0∞) (hC : C ≠ ⊤) {f : ℕ → α}
(hu : ∀ n, edist (f n) (f (n + 1)) ≤ C / 2 ^ n) {a : α} (ha : Tendsto f atTop (𝓝 a))
/-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then `f` is a Cauchy sequence. -/
theorem cauchySeq_of_edist_le_geometric_two : CauchySeq f := by
simp only [div_eq_mul_inv, ENNReal.inv_pow] at hu
refine cauchySeq_of_edist_le_geometric 2⁻¹ C ?_ hC hu
simp [ENNReal.one_lt_two]
/-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then the distance from
`f n` to the limit of `f` is bounded above by `2 * C * 2^-n`. -/
theorem edist_le_of_edist_le_geometric_two_of_tendsto (n : ℕ) : edist (f n) a ≤ 2 * C / 2 ^ n := by
simp only [div_eq_mul_inv, ENNReal.inv_pow] at *
rw [mul_assoc, mul_comm]
convert edist_le_of_edist_le_geometric_of_tendsto 2⁻¹ C hu ha n using 1
rw [ENNReal.one_sub_inv_two, div_eq_mul_inv, inv_inv]
/-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then the distance from
`f 0` to the limit of `f` is bounded above by `2 * C`. -/
theorem edist_le_of_edist_le_geometric_two_of_tendsto₀ : edist (f 0) a ≤ 2 * C := by
simpa only [_root_.pow_zero, div_eq_mul_inv, inv_one, mul_one] using
edist_le_of_edist_le_geometric_two_of_tendsto C hu ha 0
end EdistLeGeometricTwo
section LeGeometric
variable [PseudoMetricSpace α] {r C : ℝ} (hr : r < 1) {f : ℕ → α}
(hu : ∀ n, dist (f n) (f (n + 1)) ≤ C * r ^ n)
theorem aux_hasSum_of_le_geometric : HasSum (fun n : ℕ ↦ C * r ^ n) (C / (1 - r)) := by
rcases sign_cases_of_C_mul_pow_nonneg fun n ↦ dist_nonneg.trans (hu n) with (rfl | ⟨_, r₀⟩)
· simp [hasSum_zero]
· refine HasSum.mul_left C ?_
simpa using hasSum_geometric_of_lt_one r₀ hr
variable (r C)
/-- If `dist (f n) (f (n+1))` is bounded by `C * r^n`, `r < 1`, then `f` is a Cauchy sequence.
Note that this lemma does not assume `0 ≤ C` or `0 ≤ r`. -/
theorem cauchySeq_of_le_geometric : CauchySeq f :=
cauchySeq_of_dist_le_of_summable _ hu ⟨_, aux_hasSum_of_le_geometric hr hu⟩
/-- If `dist (f n) (f (n+1))` is bounded by `C * r^n`, `r < 1`, then the distance from
`f n` to the limit of `f` is bounded above by `C * r^n / (1 - r)`. -/
theorem dist_le_of_le_geometric_of_tendsto₀ {a : α} (ha : Tendsto f atTop (𝓝 a)) :
dist (f 0) a ≤ C / (1 - r) :=
(aux_hasSum_of_le_geometric hr hu).tsum_eq ▸
dist_le_tsum_of_dist_le_of_tendsto₀ _ hu ⟨_, aux_hasSum_of_le_geometric hr hu⟩ ha
/-- If `dist (f n) (f (n+1))` is bounded by `C * r^n`, `r < 1`, then the distance from
`f 0` to the limit of `f` is bounded above by `C / (1 - r)`. -/
theorem dist_le_of_le_geometric_of_tendsto {a : α} (ha : Tendsto f atTop (𝓝 a)) (n : ℕ) :
dist (f n) a ≤ C * r ^ n / (1 - r) := by
have := aux_hasSum_of_le_geometric hr hu
convert dist_le_tsum_of_dist_le_of_tendsto _ hu ⟨_, this⟩ ha n
simp only [pow_add, mul_left_comm C, mul_div_right_comm]
rw [mul_comm]
exact (this.mul_left _).tsum_eq.symm
variable (hu₂ : ∀ n, dist (f n) (f (n + 1)) ≤ C / 2 / 2 ^ n)
/-- If `dist (f n) (f (n+1))` is bounded by `(C / 2) / 2^n`, then `f` is a Cauchy sequence. -/
theorem cauchySeq_of_le_geometric_two : CauchySeq f :=
cauchySeq_of_dist_le_of_summable _ hu₂ <| ⟨_, hasSum_geometric_two' C⟩
/-- If `dist (f n) (f (n+1))` is bounded by `(C / 2) / 2^n`, then the distance from
`f 0` to the limit of `f` is bounded above by `C`. -/
theorem dist_le_of_le_geometric_two_of_tendsto₀ {a : α} (ha : Tendsto f atTop (𝓝 a)) :
dist (f 0) a ≤ C :=
tsum_geometric_two' C ▸ dist_le_tsum_of_dist_le_of_tendsto₀ _ hu₂ (summable_geometric_two' C) ha
/-- If `dist (f n) (f (n+1))` is bounded by `(C / 2) / 2^n`, then the distance from
`f n` to the limit of `f` is bounded above by `C / 2^n`. -/
theorem dist_le_of_le_geometric_two_of_tendsto {a : α} (ha : Tendsto f atTop (𝓝 a)) (n : ℕ) :
dist (f n) a ≤ C / 2 ^ n := by
convert dist_le_tsum_of_dist_le_of_tendsto _ hu₂ (summable_geometric_two' C) ha n
simp only [add_comm n, pow_add, ← div_div]
symm
exact ((hasSum_geometric_two' C).div_const _).tsum_eq
end LeGeometric
/-! ### Summability tests based on comparison with geometric series -/
/-- A series whose terms are bounded by the terms of a converging geometric series converges. -/
theorem summable_one_div_pow_of_le {m : ℝ} {f : ℕ → ℕ} (hm : 1 < m) (fi : ∀ i, i ≤ f i) :
Summable fun i ↦ 1 / m ^ f i := by
refine .of_nonneg_of_le (fun a ↦ by positivity) (fun a ↦ ?_)
(summable_geometric_of_lt_one (one_div_nonneg.mpr (zero_le_one.trans hm.le))
((one_div_lt (zero_lt_one.trans hm) zero_lt_one).mpr (one_div_one.le.trans_lt hm)))
rw [div_pow, one_pow]
refine (one_div_le_one_div ?_ ?_).mpr (pow_le_pow_right hm.le (fi a)) <;>
exact pow_pos (zero_lt_one.trans hm) _
/-! ### Positive sequences with small sums on countable types -/
/-- For any positive `ε`, define on an encodable type a positive sequence with sum less than `ε` -/
def posSumOfEncodable {ε : ℝ} (hε : 0 < ε) (ι) [Encodable ι] :
{ ε' : ι → ℝ // (∀ i, 0 < ε' i) ∧ ∃ c, HasSum ε' c ∧ c ≤ ε } := by
let f n := ε / 2 / 2 ^ n
have hf : HasSum f ε := hasSum_geometric_two' _
have f0 : ∀ n, 0 < f n := fun n ↦ div_pos (half_pos hε) (pow_pos zero_lt_two _)
refine ⟨f ∘ Encodable.encode, fun i ↦ f0 _, ?_⟩
rcases hf.summable.comp_injective (@Encodable.encode_injective ι _) with ⟨c, hg⟩
refine ⟨c, hg, hasSum_le_inj _ (@Encodable.encode_injective ι _) ?_ ?_ hg hf⟩
· intro i _
exact le_of_lt (f0 _)
· intro n
exact le_rfl
theorem Set.Countable.exists_pos_hasSum_le {ι : Type*} {s : Set ι} (hs : s.Countable) {ε : ℝ}
(hε : 0 < ε) : ∃ ε' : ι → ℝ, (∀ i, 0 < ε' i) ∧ ∃ c, HasSum (fun i : s ↦ ε' i) c ∧ c ≤ ε := by
haveI := hs.toEncodable
rcases posSumOfEncodable hε s with ⟨f, hf0, ⟨c, hfc, hcε⟩⟩
refine ⟨fun i ↦ if h : i ∈ s then f ⟨i, h⟩ else 1, fun i ↦ ?_, ⟨c, ?_, hcε⟩⟩
· conv_rhs => simp
split_ifs
exacts [hf0 _, zero_lt_one]
· simpa only [Subtype.coe_prop, dif_pos, Subtype.coe_eta]
theorem Set.Countable.exists_pos_forall_sum_le {ι : Type*} {s : Set ι} (hs : s.Countable) {ε : ℝ}
(hε : 0 < ε) : ∃ ε' : ι → ℝ,
(∀ i, 0 < ε' i) ∧ ∀ t : Finset ι, ↑t ⊆ s → ∑ i ∈ t, ε' i ≤ ε := by
rcases hs.exists_pos_hasSum_le hε with ⟨ε', hpos, c, hε'c, hcε⟩
refine ⟨ε', hpos, fun t ht ↦ ?_⟩
rw [← sum_subtype_of_mem _ ht]
refine (sum_le_hasSum _ ?_ hε'c).trans hcε
exact fun _ _ ↦ (hpos _).le
namespace NNReal
theorem exists_pos_sum_of_countable {ε : ℝ≥0} (hε : ε ≠ 0) (ι) [Countable ι] :
∃ ε' : ι → ℝ≥0, (∀ i, 0 < ε' i) ∧ ∃ c, HasSum ε' c ∧ c < ε := by
cases nonempty_encodable ι
obtain ⟨a, a0, aε⟩ := exists_between (pos_iff_ne_zero.2 hε)
obtain ⟨ε', hε', c, hc, hcε⟩ := posSumOfEncodable a0 ι
exact
⟨fun i ↦ ⟨ε' i, (hε' i).le⟩, fun i ↦ NNReal.coe_lt_coe.1 <| hε' i,
⟨c, hasSum_le (fun i ↦ (hε' i).le) hasSum_zero hc⟩, NNReal.hasSum_coe.1 hc,
aε.trans_le' <| NNReal.coe_le_coe.1 hcε⟩
end NNReal
namespace ENNReal
theorem exists_pos_sum_of_countable {ε : ℝ≥0∞} (hε : ε ≠ 0) (ι) [Countable ι] :
∃ ε' : ι → ℝ≥0, (∀ i, 0 < ε' i) ∧ (∑' i, (ε' i : ℝ≥0∞)) < ε := by
rcases exists_between (pos_iff_ne_zero.2 hε) with ⟨r, h0r, hrε⟩
rcases lt_iff_exists_coe.1 hrε with ⟨x, rfl, _⟩
rcases NNReal.exists_pos_sum_of_countable (coe_pos.1 h0r).ne' ι with ⟨ε', hp, c, hc, hcr⟩
exact ⟨ε', hp, (ENNReal.tsum_coe_eq hc).symm ▸ lt_trans (coe_lt_coe.2 hcr) hrε⟩
theorem exists_pos_sum_of_countable' {ε : ℝ≥0∞} (hε : ε ≠ 0) (ι) [Countable ι] :
∃ ε' : ι → ℝ≥0∞, (∀ i, 0 < ε' i) ∧ ∑' i, ε' i < ε :=
let ⟨δ, δpos, hδ⟩ := exists_pos_sum_of_countable hε ι
⟨fun i ↦ δ i, fun i ↦ ENNReal.coe_pos.2 (δpos i), hδ⟩
theorem exists_pos_tsum_mul_lt_of_countable {ε : ℝ≥0∞} (hε : ε ≠ 0) {ι} [Countable ι] (w : ι → ℝ≥0∞)
(hw : ∀ i, w i ≠ ∞) : ∃ δ : ι → ℝ≥0, (∀ i, 0 < δ i) ∧ (∑' i, (w i * δ i : ℝ≥0∞)) < ε := by
lift w to ι → ℝ≥0 using hw
rcases exists_pos_sum_of_countable hε ι with ⟨δ', Hpos, Hsum⟩
have : ∀ i, 0 < max 1 (w i) := fun i ↦ zero_lt_one.trans_le (le_max_left _ _)
refine ⟨fun i ↦ δ' i / max 1 (w i), fun i ↦ div_pos (Hpos _) (this i), ?_⟩
refine lt_of_le_of_lt (ENNReal.tsum_le_tsum fun i ↦ ?_) Hsum
rw [coe_div (this i).ne']
refine mul_le_of_le_div' (mul_le_mul_left' (ENNReal.inv_le_inv.2 ?_) _)
exact coe_le_coe.2 (le_max_right _ _)
end ENNReal
/-!
### Factorial
-/
theorem factorial_tendsto_atTop : Tendsto Nat.factorial atTop atTop :=
tendsto_atTop_atTop_of_monotone (fun _ _ ↦ Nat.factorial_le) fun n ↦ ⟨n, n.self_le_factorial⟩
theorem tendsto_factorial_div_pow_self_atTop :
Tendsto (fun n ↦ n ! / (n : ℝ) ^ n : ℕ → ℝ) atTop (𝓝 0) :=
tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds
(tendsto_const_div_atTop_nhds_zero_nat 1)
(eventually_of_forall fun n ↦
div_nonneg (mod_cast n.factorial_pos.le)
(pow_nonneg (mod_cast n.zero_le) _))
(by
refine (eventually_gt_atTop 0).mono fun n hn ↦ ?_
rcases Nat.exists_eq_succ_of_ne_zero hn.ne.symm with ⟨k, rfl⟩
rw [← prod_range_add_one_eq_factorial, pow_eq_prod_const, div_eq_mul_inv, ← inv_eq_one_div,
prod_natCast, Nat.cast_succ, ← prod_inv_distrib, ← prod_mul_distrib,
Finset.prod_range_succ']
simp only [prod_range_succ', one_mul, Nat.cast_add, zero_add, Nat.cast_one]
refine
mul_le_of_le_one_left (inv_nonneg.mpr <| mod_cast hn.le) (prod_le_one ?_ ?_) <;>
intro x hx <;>
rw [Finset.mem_range] at hx
· positivity
· refine (div_le_one <| mod_cast hn).mpr ?_
norm_cast
omega)
/-!
### Ceil and floor
-/
section
theorem tendsto_nat_floor_atTop {α : Type*} [LinearOrderedSemiring α] [FloorSemiring α] :
Tendsto (fun x : α ↦ ⌊x⌋₊) atTop atTop :=
Nat.floor_mono.tendsto_atTop_atTop fun x ↦ ⟨max 0 (x + 1), by simp [Nat.le_floor_iff]⟩
lemma tendsto_nat_ceil_atTop {α : Type*} [LinearOrderedSemiring α] [FloorSemiring α] :
Tendsto (fun x : α ↦ ⌈x⌉₊) atTop atTop := by
refine Nat.ceil_mono.tendsto_atTop_atTop (fun x ↦ ⟨x, ?_⟩)
simp only [Nat.ceil_natCast, le_refl]
lemma tendsto_nat_floor_mul_atTop {α : Type _} [LinearOrderedSemifield α] [FloorSemiring α]
[Archimedean α] (a : α) (ha : 0 < a) : Tendsto (fun (x : ℕ) => ⌊a * x⌋₊) atTop atTop :=
Tendsto.comp tendsto_nat_floor_atTop
<| Tendsto.const_mul_atTop ha tendsto_natCast_atTop_atTop
variable {R : Type*} [TopologicalSpace R] [LinearOrderedField R] [OrderTopology R] [FloorRing R]
theorem tendsto_nat_floor_mul_div_atTop {a : R} (ha : 0 ≤ a) :
Tendsto (fun x ↦ (⌊a * x⌋₊ : R) / x) atTop (𝓝 a) := by
have A : Tendsto (fun x : R ↦ a - x⁻¹) atTop (𝓝 (a - 0)) :=
tendsto_const_nhds.sub tendsto_inv_atTop_zero
rw [sub_zero] at A
apply tendsto_of_tendsto_of_tendsto_of_le_of_le' A tendsto_const_nhds
· refine eventually_atTop.2 ⟨1, fun x hx ↦ ?_⟩
simp only [le_div_iff (zero_lt_one.trans_le hx), _root_.sub_mul,
inv_mul_cancel (zero_lt_one.trans_le hx).ne']
have := Nat.lt_floor_add_one (a * x)
linarith
· refine eventually_atTop.2 ⟨1, fun x hx ↦ ?_⟩
rw [div_le_iff (zero_lt_one.trans_le hx)]
simp [Nat.floor_le (mul_nonneg ha (zero_le_one.trans hx))]
theorem tendsto_nat_floor_div_atTop : Tendsto (fun x ↦ (⌊x⌋₊ : R) / x) atTop (𝓝 1) := by
simpa using tendsto_nat_floor_mul_div_atTop (zero_le_one' R)
theorem tendsto_nat_ceil_mul_div_atTop {a : R} (ha : 0 ≤ a) :
Tendsto (fun x ↦ (⌈a * x⌉₊ : R) / x) atTop (𝓝 a) := by
have A : Tendsto (fun x : R ↦ a + x⁻¹) atTop (𝓝 (a + 0)) :=
tendsto_const_nhds.add tendsto_inv_atTop_zero
rw [add_zero] at A
apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds A
· refine eventually_atTop.2 ⟨1, fun x hx ↦ ?_⟩
rw [le_div_iff (zero_lt_one.trans_le hx)]
exact Nat.le_ceil _
· refine eventually_atTop.2 ⟨1, fun x hx ↦ ?_⟩
simp [div_le_iff (zero_lt_one.trans_le hx), inv_mul_cancel (zero_lt_one.trans_le hx).ne',
(Nat.ceil_lt_add_one (mul_nonneg ha (zero_le_one.trans hx))).le, add_mul]
theorem tendsto_nat_ceil_div_atTop : Tendsto (fun x ↦ (⌈x⌉₊ : R) / x) atTop (𝓝 1) := by
simpa using tendsto_nat_ceil_mul_div_atTop (zero_le_one' R)
lemma Nat.tendsto_div_const_atTop {n : ℕ} (hn : n ≠ 0) : Tendsto (· / n) atTop atTop := by
rw [Tendsto, map_div_atTop_eq_nat n hn.bot_lt]
end
|
Analysis\SpecificLimits\FloorPow.lean | /-
Copyright (c) 2022 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Analysis.SpecialFunctions.Pow.Real
/-!
# Results on discretized exponentials
We state several auxiliary results pertaining to sequences of the form `⌊c^n⌋₊`.
* `tendsto_div_of_monotone_of_tendsto_div_floor_pow`: If a monotone sequence `u` is such that
`u ⌊c^n⌋₊ / ⌊c^n⌋₊` converges to a limit `l` for all `c > 1`, then `u n / n` tends to `l`.
* `sum_div_nat_floor_pow_sq_le_div_sq`: The sum of `1/⌊c^i⌋₊^2` above a threshold `j` is comparable
to `1/j^2`, up to a multiplicative constant.
-/
open Filter Finset
open Topology
/-- If a monotone sequence `u` is such that `u n / n` tends to a limit `l` along subsequences with
exponential growth rate arbitrarily close to `1`, then `u n / n` tends to `l`. -/
theorem tendsto_div_of_monotone_of_exists_subseq_tendsto_div (u : ℕ → ℝ) (l : ℝ)
(hmono : Monotone u)
(hlim : ∀ a : ℝ, 1 < a → ∃ c : ℕ → ℕ, (∀ᶠ n in atTop, (c (n + 1) : ℝ) ≤ a * c n) ∧
Tendsto c atTop atTop ∧ Tendsto (fun n => u (c n) / c n) atTop (𝓝 l)) :
Tendsto (fun n => u n / n) atTop (𝓝 l) := by
/- To check the result up to some `ε > 0`, we use a sequence `c` for which the ratio
`c (N+1) / c N` is bounded by `1 + ε`. Sandwiching a given `n` between two consecutive values of
`c`, say `c N` and `c (N+1)`, one can then bound `u n / n` from above by `u (c N) / c (N - 1)`
and from below by `u (c (N - 1)) / c N` (using that `u` is monotone), which are both comparable
to the limit `l` up to `1 + ε`.
We give a version of this proof by clearing out denominators first, to avoid discussing the sign
of different quantities. -/
have lnonneg : 0 ≤ l := by
rcases hlim 2 one_lt_two with ⟨c, _, ctop, clim⟩
have : Tendsto (fun n => u 0 / c n) atTop (𝓝 0) :=
tendsto_const_nhds.div_atTop (tendsto_natCast_atTop_iff.2 ctop)
apply le_of_tendsto_of_tendsto' this clim fun n => ?_
gcongr
exact hmono (zero_le _)
have A : ∀ ε : ℝ, 0 < ε → ∀ᶠ n in atTop, u n - n * l ≤ ε * (1 + ε + l) * n := by
intro ε εpos
rcases hlim (1 + ε) ((lt_add_iff_pos_right _).2 εpos) with ⟨c, cgrowth, ctop, clim⟩
have L : ∀ᶠ n in atTop, u (c n) - c n * l ≤ ε * c n := by
rw [← tendsto_sub_nhds_zero_iff, ← Asymptotics.isLittleO_one_iff ℝ,
Asymptotics.isLittleO_iff] at clim
filter_upwards [clim εpos, ctop (Ioi_mem_atTop 0)] with n hn cnpos'
have cnpos : 0 < c n := cnpos'
calc
u (c n) - c n * l = (u (c n) / c n - l) * c n := by
simp only [cnpos.ne', Ne, Nat.cast_eq_zero, not_false_iff, field_simps]
_ ≤ ε * c n := by
gcongr
refine (le_abs_self _).trans ?_
simpa using hn
obtain ⟨a, ha⟩ :
∃ a : ℕ, ∀ b : ℕ, a ≤ b → (c (b + 1) : ℝ) ≤ (1 + ε) * c b ∧ u (c b) - c b * l ≤ ε * c b :=
eventually_atTop.1 (cgrowth.and L)
let M := ((Finset.range (a + 1)).image fun i => c i).max' (by simp)
filter_upwards [Ici_mem_atTop M] with n hn
have exN : ∃ N, n < c N := by
rcases (tendsto_atTop.1 ctop (n + 1)).exists with ⟨N, hN⟩
exact ⟨N, by linarith only [hN]⟩
let N := Nat.find exN
have ncN : n < c N := Nat.find_spec exN
have aN : a + 1 ≤ N := by
by_contra! h
have cNM : c N ≤ M := by
apply le_max'
apply mem_image_of_mem
exact mem_range.2 h
exact lt_irrefl _ ((cNM.trans hn).trans_lt ncN)
have Npos : 0 < N := lt_of_lt_of_le Nat.succ_pos' aN
have cNn : c (N - 1) ≤ n := by
have : N - 1 < N := Nat.pred_lt Npos.ne'
simpa only [not_lt] using Nat.find_min exN this
have IcN : (c N : ℝ) ≤ (1 + ε) * c (N - 1) := by
have A : a ≤ N - 1 := by
apply @Nat.le_of_add_le_add_right a 1 (N - 1)
rw [Nat.sub_add_cancel Npos]
exact aN
have B : N - 1 + 1 = N := Nat.succ_pred_eq_of_pos Npos
have := (ha _ A).1
rwa [B] at this
calc
u n - n * l ≤ u (c N) - c (N - 1) * l := by gcongr; exact hmono ncN.le
_ = u (c N) - c N * l + (c N - c (N - 1)) * l := by ring
_ ≤ ε * c N + ε * c (N - 1) * l := by
gcongr
· exact (ha N (a.le_succ.trans aN)).2
· linarith only [IcN]
_ ≤ ε * ((1 + ε) * c (N - 1)) + ε * c (N - 1) * l := by gcongr
_ = ε * (1 + ε + l) * c (N - 1) := by ring
_ ≤ ε * (1 + ε + l) * n := by gcongr
have B : ∀ ε : ℝ, 0 < ε → ∀ᶠ n : ℕ in atTop, (n : ℝ) * l - u n ≤ ε * (1 + l) * n := by
intro ε εpos
rcases hlim (1 + ε) ((lt_add_iff_pos_right _).2 εpos) with ⟨c, cgrowth, ctop, clim⟩
have L : ∀ᶠ n : ℕ in atTop, (c n : ℝ) * l - u (c n) ≤ ε * c n := by
rw [← tendsto_sub_nhds_zero_iff, ← Asymptotics.isLittleO_one_iff ℝ,
Asymptotics.isLittleO_iff] at clim
filter_upwards [clim εpos, ctop (Ioi_mem_atTop 0)] with n hn cnpos'
have cnpos : 0 < c n := cnpos'
calc
(c n : ℝ) * l - u (c n) = -(u (c n) / c n - l) * c n := by
simp only [cnpos.ne', Ne, Nat.cast_eq_zero, not_false_iff, neg_sub, field_simps]
_ ≤ ε * c n := by
gcongr
refine le_trans (neg_le_abs _) ?_
simpa using hn
obtain ⟨a, ha⟩ :
∃ a : ℕ,
∀ b : ℕ, a ≤ b → (c (b + 1) : ℝ) ≤ (1 + ε) * c b ∧ (c b : ℝ) * l - u (c b) ≤ ε * c b :=
eventually_atTop.1 (cgrowth.and L)
let M := ((Finset.range (a + 1)).image fun i => c i).max' (by simp)
filter_upwards [Ici_mem_atTop M] with n hn
have exN : ∃ N, n < c N := by
rcases (tendsto_atTop.1 ctop (n + 1)).exists with ⟨N, hN⟩
exact ⟨N, by linarith only [hN]⟩
let N := Nat.find exN
have ncN : n < c N := Nat.find_spec exN
have aN : a + 1 ≤ N := by
by_contra! h
have cNM : c N ≤ M := by
apply le_max'
apply mem_image_of_mem
exact mem_range.2 h
exact lt_irrefl _ ((cNM.trans hn).trans_lt ncN)
have Npos : 0 < N := lt_of_lt_of_le Nat.succ_pos' aN
have aN' : a ≤ N - 1 := by
apply @Nat.le_of_add_le_add_right a 1 (N - 1)
rw [Nat.sub_add_cancel Npos]
exact aN
have cNn : c (N - 1) ≤ n := by
have : N - 1 < N := Nat.pred_lt Npos.ne'
simpa only [not_lt] using Nat.find_min exN this
calc
(n : ℝ) * l - u n ≤ c N * l - u (c (N - 1)) := by
gcongr
exact hmono cNn
_ ≤ (1 + ε) * c (N - 1) * l - u (c (N - 1)) := by
gcongr
have B : N - 1 + 1 = N := Nat.succ_pred_eq_of_pos Npos
simpa [B] using (ha _ aN').1
_ = c (N - 1) * l - u (c (N - 1)) + ε * c (N - 1) * l := by ring
_ ≤ ε * c (N - 1) + ε * c (N - 1) * l := add_le_add (ha _ aN').2 le_rfl
_ = ε * (1 + l) * c (N - 1) := by ring
_ ≤ ε * (1 + l) * n := by gcongr
refine tendsto_order.2 ⟨fun d hd => ?_, fun d hd => ?_⟩
· obtain ⟨ε, hε, εpos⟩ : ∃ ε : ℝ, d + ε * (1 + l) < l ∧ 0 < ε := by
have L : Tendsto (fun ε => d + ε * (1 + l)) (𝓝[>] 0) (𝓝 (d + 0 * (1 + l))) := by
apply Tendsto.mono_left _ nhdsWithin_le_nhds
exact tendsto_const_nhds.add (tendsto_id.mul tendsto_const_nhds)
simp only [zero_mul, add_zero] at L
exact (((tendsto_order.1 L).2 l hd).and self_mem_nhdsWithin).exists
filter_upwards [B ε εpos, Ioi_mem_atTop 0] with n hn npos
simp_rw [div_eq_inv_mul]
calc
d < (n : ℝ)⁻¹ * n * (l - ε * (1 + l)) := by
rw [inv_mul_cancel, one_mul]
· linarith only [hε]
· exact Nat.cast_ne_zero.2 (ne_of_gt npos)
_ = (n : ℝ)⁻¹ * (n * l - ε * (1 + l) * n) := by ring
_ ≤ (n : ℝ)⁻¹ * u n := by gcongr; linarith only [hn]
· obtain ⟨ε, hε, εpos⟩ : ∃ ε : ℝ, l + ε * (1 + ε + l) < d ∧ 0 < ε := by
have L : Tendsto (fun ε => l + ε * (1 + ε + l)) (𝓝[>] 0) (𝓝 (l + 0 * (1 + 0 + l))) := by
apply Tendsto.mono_left _ nhdsWithin_le_nhds
exact
tendsto_const_nhds.add
(tendsto_id.mul ((tendsto_const_nhds.add tendsto_id).add tendsto_const_nhds))
simp only [zero_mul, add_zero] at L
exact (((tendsto_order.1 L).2 d hd).and self_mem_nhdsWithin).exists
filter_upwards [A ε εpos, Ioi_mem_atTop 0] with n hn (npos : 0 < n)
calc
u n / n ≤ (n * l + ε * (1 + ε + l) * n) / n := by gcongr; linarith only [hn]
_ = (l + ε * (1 + ε + l)) := by field_simp; ring
_ < d := hε
/-- If a monotone sequence `u` is such that `u ⌊c^n⌋₊ / ⌊c^n⌋₊` converges to a limit `l` for all
`c > 1`, then `u n / n` tends to `l`. It is even enough to have the assumption for a sequence of
`c`s converging to `1`. -/
theorem tendsto_div_of_monotone_of_tendsto_div_floor_pow (u : ℕ → ℝ) (l : ℝ) (hmono : Monotone u)
(c : ℕ → ℝ) (cone : ∀ k, 1 < c k) (clim : Tendsto c atTop (𝓝 1))
(hc : ∀ k, Tendsto (fun n : ℕ => u ⌊c k ^ n⌋₊ / ⌊c k ^ n⌋₊) atTop (𝓝 l)) :
Tendsto (fun n => u n / n) atTop (𝓝 l) := by
apply tendsto_div_of_monotone_of_exists_subseq_tendsto_div u l hmono
intro a ha
obtain ⟨k, hk⟩ : ∃ k, c k < a := ((tendsto_order.1 clim).2 a ha).exists
refine
⟨fun n => ⌊c k ^ n⌋₊, ?_,
(tendsto_nat_floor_atTop (α := ℝ)).comp (tendsto_pow_atTop_atTop_of_one_lt (cone k)), hc k⟩
have H : ∀ n : ℕ, (0 : ℝ) < ⌊c k ^ n⌋₊ := by
intro n
refine zero_lt_one.trans_le ?_
simp only [Real.rpow_natCast, Nat.one_le_cast, Nat.one_le_floor_iff,
one_le_pow_of_one_le (cone k).le n]
have A :
Tendsto (fun n : ℕ => (⌊c k ^ (n + 1)⌋₊ : ℝ) / c k ^ (n + 1) * c k / (⌊c k ^ n⌋₊ / c k ^ n))
atTop (𝓝 (1 * c k / 1)) := by
refine Tendsto.div (Tendsto.mul ?_ tendsto_const_nhds) ?_ one_ne_zero
· refine tendsto_nat_floor_div_atTop.comp ?_
exact (tendsto_pow_atTop_atTop_of_one_lt (cone k)).comp (tendsto_add_atTop_nat 1)
· refine tendsto_nat_floor_div_atTop.comp ?_
exact tendsto_pow_atTop_atTop_of_one_lt (cone k)
have B : Tendsto (fun n : ℕ => (⌊c k ^ (n + 1)⌋₊ : ℝ) / ⌊c k ^ n⌋₊) atTop (𝓝 (c k)) := by
simp only [one_mul, div_one] at A
convert A using 1
ext1 n
field_simp [(zero_lt_one.trans (cone k)).ne', (H n).ne']
ring
filter_upwards [(tendsto_order.1 B).2 a hk] with n hn
exact (div_le_iff (H n)).1 hn.le
/-- The sum of `1/(c^i)^2` above a threshold `j` is comparable to `1/j^2`, up to a multiplicative
constant. -/
theorem sum_div_pow_sq_le_div_sq (N : ℕ) {j : ℝ} (hj : 0 < j) {c : ℝ} (hc : 1 < c) :
(∑ i ∈ (range N).filter (j < c ^ ·), (1 : ℝ) / (c ^ i) ^ 2) ≤ c ^ 3 * (c - 1)⁻¹ / j ^ 2 := by
have cpos : 0 < c := zero_lt_one.trans hc
have A : (0 : ℝ) < c⁻¹ ^ 2 := sq_pos_of_pos (inv_pos.2 cpos)
have B : c ^ 2 * ((1 : ℝ) - c⁻¹ ^ 2)⁻¹ ≤ c ^ 3 * (c - 1)⁻¹ := by
rw [← div_eq_mul_inv, ← div_eq_mul_inv, div_le_div_iff _ (sub_pos.2 hc)]
swap
· exact sub_pos.2 (pow_lt_one (inv_nonneg.2 cpos.le) (inv_lt_one hc) two_ne_zero)
have : c ^ 3 = c ^ 2 * c := by ring
simp only [mul_sub, this, mul_one, inv_pow, sub_le_sub_iff_left]
rw [mul_assoc, mul_comm c, ← mul_assoc, mul_inv_cancel (sq_pos_of_pos cpos).ne', one_mul]
simpa using pow_le_pow_right hc.le one_le_two
have C : c⁻¹ ^ 2 < 1 := pow_lt_one (inv_nonneg.2 cpos.le) (inv_lt_one hc) two_ne_zero
calc
(∑ i ∈ (range N).filter (j < c ^ ·), (1 : ℝ) / (c ^ i) ^ 2) ≤
∑ i ∈ Ico ⌊Real.log j / Real.log c⌋₊ N, (1 : ℝ) / (c ^ i) ^ 2 := by
refine sum_le_sum_of_subset_of_nonneg (fun i hi ↦ ?_) (by intros; positivity)
simp only [mem_filter, mem_range] at hi
simp only [hi.1, mem_Ico, and_true_iff]
apply Nat.floor_le_of_le
apply le_of_lt
rw [div_lt_iff (Real.log_pos hc), ← Real.log_pow]
exact Real.log_lt_log hj hi.2
_ = ∑ i ∈ Ico ⌊Real.log j / Real.log c⌋₊ N, (c⁻¹ ^ 2) ^ i := by
congr 1 with i
simp [← pow_mul, mul_comm]
_ ≤ (c⁻¹ ^ 2) ^ ⌊Real.log j / Real.log c⌋₊ / ((1 : ℝ) - c⁻¹ ^ 2) :=
geom_sum_Ico_le_of_lt_one (sq_nonneg _) C
_ ≤ (c⁻¹ ^ 2) ^ (Real.log j / Real.log c - 1) / ((1 : ℝ) - c⁻¹ ^ 2) := by
gcongr
· exact sub_nonneg.2 C.le
· rw [← Real.rpow_natCast]
exact Real.rpow_le_rpow_of_exponent_ge A C.le (Nat.sub_one_lt_floor _).le
_ = c ^ 2 * ((1 : ℝ) - c⁻¹ ^ 2)⁻¹ / j ^ 2 := by
have I : (c⁻¹ ^ 2) ^ (Real.log j / Real.log c) = (1 : ℝ) / j ^ 2 := by
apply Real.log_injOn_pos (Real.rpow_pos_of_pos A _)
· rw [Set.mem_Ioi]; positivity
rw [Real.log_rpow A]
simp only [one_div, Real.log_inv, Real.log_pow, Nat.cast_one, mul_neg, neg_inj]
field_simp [(Real.log_pos hc).ne']
ring
rw [Real.rpow_sub A, I]
have : c ^ 2 - 1 ≠ 0 := (sub_pos.2 (one_lt_pow hc two_ne_zero)).ne'
field_simp [hj.ne', (zero_lt_one.trans hc).ne']
ring
_ ≤ c ^ 3 * (c - 1)⁻¹ / j ^ 2 := by gcongr
theorem mul_pow_le_nat_floor_pow {c : ℝ} (hc : 1 < c) (i : ℕ) : (1 - c⁻¹) * c ^ i ≤ ⌊c ^ i⌋₊ := by
have cpos : 0 < c := zero_lt_one.trans hc
rcases eq_or_ne i 0 with (rfl | hi)
· simp only [pow_zero, Nat.floor_one, Nat.cast_one, mul_one, sub_le_self_iff, inv_nonneg, cpos.le]
calc
(1 - c⁻¹) * c ^ i = c ^ i - c ^ i * c⁻¹ := by ring
_ ≤ c ^ i - 1 := by
gcongr
simpa only [← div_eq_mul_inv, one_le_div cpos, pow_one] using le_self_pow hc.le hi
_ ≤ ⌊c ^ i⌋₊ := (Nat.sub_one_lt_floor _).le
/-- The sum of `1/⌊c^i⌋₊^2` above a threshold `j` is comparable to `1/j^2`, up to a multiplicative
constant. -/
theorem sum_div_nat_floor_pow_sq_le_div_sq (N : ℕ) {j : ℝ} (hj : 0 < j) {c : ℝ} (hc : 1 < c) :
(∑ i ∈ (range N).filter (j < ⌊c ^ ·⌋₊), (1 : ℝ) / (⌊c ^ i⌋₊ : ℝ) ^ 2) ≤
c ^ 5 * (c - 1)⁻¹ ^ 3 / j ^ 2 := by
have cpos : 0 < c := zero_lt_one.trans hc
have A : 0 < 1 - c⁻¹ := sub_pos.2 (inv_lt_one hc)
calc
(∑ i ∈ (range N).filter (j < ⌊c ^ ·⌋₊), (1 : ℝ) / (⌊c ^ i⌋₊ : ℝ) ^ 2) ≤
∑ i ∈ (range N).filter (j < c ^ ·), (1 : ℝ) / (⌊c ^ i⌋₊ : ℝ) ^ 2 := by
apply sum_le_sum_of_subset_of_nonneg
· exact monotone_filter_right _ fun k hk ↦ hk.trans_le <| Nat.floor_le (by positivity)
· intros; positivity
_ ≤ ∑ i ∈ (range N).filter (j < c ^ ·), (1 - c⁻¹)⁻¹ ^ 2 * ((1 : ℝ) / (c ^ i) ^ 2) := by
refine sum_le_sum fun i _hi => ?_
rw [mul_div_assoc', mul_one, div_le_div_iff]; rotate_left
· apply sq_pos_of_pos
refine zero_lt_one.trans_le ?_
simp only [Nat.le_floor, one_le_pow_of_one_le, hc.le, Nat.one_le_cast, Nat.cast_one]
· exact sq_pos_of_pos (pow_pos cpos _)
rw [one_mul, ← mul_pow]
gcongr
rw [← div_eq_inv_mul, le_div_iff A, mul_comm]
exact mul_pow_le_nat_floor_pow hc i
_ ≤ (1 - c⁻¹)⁻¹ ^ 2 * (c ^ 3 * (c - 1)⁻¹) / j ^ 2 := by
rw [← mul_sum, ← mul_div_assoc']
gcongr
exact sum_div_pow_sq_le_div_sq N hj hc
_ = c ^ 5 * (c - 1)⁻¹ ^ 3 / j ^ 2 := by
congr 1
field_simp [(sub_pos.2 hc).ne']
ring!
|
Analysis\SpecificLimits\Normed.lean | /-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker, Sébastien Gouëzel, Yury G. Kudryashov, Dylan MacKenzie, Patrick Massot
-/
import Mathlib.Algebra.BigOperators.Module
import Mathlib.Algebra.Order.Field.Basic
import Mathlib.Order.Filter.ModEq
import Mathlib.Analysis.Asymptotics.Asymptotics
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Data.List.TFAE
import Mathlib.Analysis.Normed.Module.Basic
/-!
# A collection of specific limit computations
This file contains important specific limit computations in (semi-)normed groups/rings/spaces, as
well as such computations in `ℝ` when the natural proof passes through a fact about normed spaces.
-/
noncomputable section
open scoped Classical
open Set Function Filter Finset Metric Asymptotics
open scoped Classical
open Topology Nat uniformity NNReal ENNReal
variable {α : Type*} {β : Type*} {ι : Type*}
theorem tendsto_norm_atTop_atTop : Tendsto (norm : ℝ → ℝ) atTop atTop :=
tendsto_abs_atTop_atTop
theorem summable_of_absolute_convergence_real {f : ℕ → ℝ} :
(∃ r, Tendsto (fun n ↦ ∑ i ∈ range n, |f i|) atTop (𝓝 r)) → Summable f
| ⟨r, hr⟩ => by
refine .of_norm ⟨r, (hasSum_iff_tendsto_nat_of_nonneg ?_ _).2 ?_⟩
· exact fun i ↦ norm_nonneg _
· simpa only using hr
/-! ### Powers -/
theorem tendsto_norm_zero' {𝕜 : Type*} [NormedAddCommGroup 𝕜] :
Tendsto (norm : 𝕜 → ℝ) (𝓝[≠] 0) (𝓝[>] 0) :=
tendsto_norm_zero.inf <| tendsto_principal_principal.2 fun _ hx ↦ norm_pos_iff.2 hx
namespace NormedField
theorem tendsto_norm_inverse_nhdsWithin_0_atTop {𝕜 : Type*} [NormedDivisionRing 𝕜] :
Tendsto (fun x : 𝕜 ↦ ‖x⁻¹‖) (𝓝[≠] 0) atTop :=
(tendsto_inv_zero_atTop.comp tendsto_norm_zero').congr fun x ↦ (norm_inv x).symm
theorem tendsto_norm_zpow_nhdsWithin_0_atTop {𝕜 : Type*} [NormedDivisionRing 𝕜] {m : ℤ}
(hm : m < 0) :
Tendsto (fun x : 𝕜 ↦ ‖x ^ m‖) (𝓝[≠] 0) atTop := by
rcases neg_surjective m with ⟨m, rfl⟩
rw [neg_lt_zero] at hm; lift m to ℕ using hm.le; rw [Int.natCast_pos] at hm
simp only [norm_pow, zpow_neg, zpow_natCast, ← inv_pow]
exact (tendsto_pow_atTop hm.ne').comp NormedField.tendsto_norm_inverse_nhdsWithin_0_atTop
/-- The (scalar) product of a sequence that tends to zero with a bounded one also tends to zero. -/
theorem tendsto_zero_smul_of_tendsto_zero_of_bounded {ι 𝕜 𝔸 : Type*} [NormedDivisionRing 𝕜]
[NormedAddCommGroup 𝔸] [Module 𝕜 𝔸] [BoundedSMul 𝕜 𝔸] {l : Filter ι} {ε : ι → 𝕜} {f : ι → 𝔸}
(hε : Tendsto ε l (𝓝 0)) (hf : Filter.IsBoundedUnder (· ≤ ·) l (norm ∘ f)) :
Tendsto (ε • f) l (𝓝 0) := by
rw [← isLittleO_one_iff 𝕜] at hε ⊢
simpa using IsLittleO.smul_isBigO hε (hf.isBigO_const (one_ne_zero : (1 : 𝕜) ≠ 0))
@[simp]
theorem continuousAt_zpow {𝕜 : Type*} [NontriviallyNormedField 𝕜] {m : ℤ} {x : 𝕜} :
ContinuousAt (fun x ↦ x ^ m) x ↔ x ≠ 0 ∨ 0 ≤ m := by
refine ⟨?_, continuousAt_zpow₀ _ _⟩
contrapose!; rintro ⟨rfl, hm⟩ hc
exact not_tendsto_atTop_of_tendsto_nhds (hc.tendsto.mono_left nhdsWithin_le_nhds).norm
(tendsto_norm_zpow_nhdsWithin_0_atTop hm)
@[simp]
theorem continuousAt_inv {𝕜 : Type*} [NontriviallyNormedField 𝕜] {x : 𝕜} :
ContinuousAt Inv.inv x ↔ x ≠ 0 := by
simpa [(zero_lt_one' ℤ).not_le] using @continuousAt_zpow _ _ (-1) x
end NormedField
theorem isLittleO_pow_pow_of_lt_left {r₁ r₂ : ℝ} (h₁ : 0 ≤ r₁) (h₂ : r₁ < r₂) :
(fun n : ℕ ↦ r₁ ^ n) =o[atTop] fun n ↦ r₂ ^ n :=
have H : 0 < r₂ := h₁.trans_lt h₂
(isLittleO_of_tendsto fun _ hn ↦ False.elim <| H.ne' <| pow_eq_zero hn) <|
(tendsto_pow_atTop_nhds_zero_of_lt_one
(div_nonneg h₁ (h₁.trans h₂.le)) ((div_lt_one H).2 h₂)).congr fun _ ↦ div_pow _ _ _
theorem isBigO_pow_pow_of_le_left {r₁ r₂ : ℝ} (h₁ : 0 ≤ r₁) (h₂ : r₁ ≤ r₂) :
(fun n : ℕ ↦ r₁ ^ n) =O[atTop] fun n ↦ r₂ ^ n :=
h₂.eq_or_lt.elim (fun h ↦ h ▸ isBigO_refl _ _) fun h ↦ (isLittleO_pow_pow_of_lt_left h₁ h).isBigO
theorem isLittleO_pow_pow_of_abs_lt_left {r₁ r₂ : ℝ} (h : |r₁| < |r₂|) :
(fun n : ℕ ↦ r₁ ^ n) =o[atTop] fun n ↦ r₂ ^ n := by
refine (IsLittleO.of_norm_left ?_).of_norm_right
exact (isLittleO_pow_pow_of_lt_left (abs_nonneg r₁) h).congr (pow_abs r₁) (pow_abs r₂)
open List in
/-- Various statements equivalent to the fact that `f n` grows exponentially slower than `R ^ n`.
* 0: $f n = o(a ^ n)$ for some $-R < a < R$;
* 1: $f n = o(a ^ n)$ for some $0 < a < R$;
* 2: $f n = O(a ^ n)$ for some $-R < a < R$;
* 3: $f n = O(a ^ n)$ for some $0 < a < R$;
* 4: there exist `a < R` and `C` such that one of `C` and `R` is positive and $|f n| ≤ Ca^n$
for all `n`;
* 5: there exists `0 < a < R` and a positive `C` such that $|f n| ≤ Ca^n$ for all `n`;
* 6: there exists `a < R` such that $|f n| ≤ a ^ n$ for sufficiently large `n`;
* 7: there exists `0 < a < R` such that $|f n| ≤ a ^ n$ for sufficiently large `n`.
NB: For backwards compatibility, if you add more items to the list, please append them at the end of
the list. -/
theorem TFAE_exists_lt_isLittleO_pow (f : ℕ → ℝ) (R : ℝ) :
TFAE
[∃ a ∈ Ioo (-R) R, f =o[atTop] (a ^ ·), ∃ a ∈ Ioo 0 R, f =o[atTop] (a ^ ·),
∃ a ∈ Ioo (-R) R, f =O[atTop] (a ^ ·), ∃ a ∈ Ioo 0 R, f =O[atTop] (a ^ ·),
∃ a < R, ∃ C : ℝ, (0 < C ∨ 0 < R) ∧ ∀ n, |f n| ≤ C * a ^ n,
∃ a ∈ Ioo 0 R, ∃ C > 0, ∀ n, |f n| ≤ C * a ^ n, ∃ a < R, ∀ᶠ n in atTop, |f n| ≤ a ^ n,
∃ a ∈ Ioo 0 R, ∀ᶠ n in atTop, |f n| ≤ a ^ n] := by
have A : Ico 0 R ⊆ Ioo (-R) R :=
fun x hx ↦ ⟨(neg_lt_zero.2 (hx.1.trans_lt hx.2)).trans_le hx.1, hx.2⟩
have B : Ioo 0 R ⊆ Ioo (-R) R := Subset.trans Ioo_subset_Ico_self A
-- First we prove that 1-4 are equivalent using 2 → 3 → 4, 1 → 3, and 2 → 1
tfae_have 1 → 3
· exact fun ⟨a, ha, H⟩ ↦ ⟨a, ha, H.isBigO⟩
tfae_have 2 → 1
· exact fun ⟨a, ha, H⟩ ↦ ⟨a, B ha, H⟩
tfae_have 3 → 2
· rintro ⟨a, ha, H⟩
rcases exists_between (abs_lt.2 ha) with ⟨b, hab, hbR⟩
exact ⟨b, ⟨(abs_nonneg a).trans_lt hab, hbR⟩,
H.trans_isLittleO (isLittleO_pow_pow_of_abs_lt_left (hab.trans_le (le_abs_self b)))⟩
tfae_have 2 → 4
· exact fun ⟨a, ha, H⟩ ↦ ⟨a, ha, H.isBigO⟩
tfae_have 4 → 3
· exact fun ⟨a, ha, H⟩ ↦ ⟨a, B ha, H⟩
-- Add 5 and 6 using 4 → 6 → 5 → 3
tfae_have 4 → 6
· rintro ⟨a, ha, H⟩
rcases bound_of_isBigO_nat_atTop H with ⟨C, hC₀, hC⟩
refine ⟨a, ha, C, hC₀, fun n ↦ ?_⟩
simpa only [Real.norm_eq_abs, abs_pow, abs_of_nonneg ha.1.le] using hC (pow_ne_zero n ha.1.ne')
tfae_have 6 → 5
· exact fun ⟨a, ha, C, H₀, H⟩ ↦ ⟨a, ha.2, C, Or.inl H₀, H⟩
tfae_have 5 → 3
· rintro ⟨a, ha, C, h₀, H⟩
rcases sign_cases_of_C_mul_pow_nonneg fun n ↦ (abs_nonneg _).trans (H n) with (rfl | ⟨hC₀, ha₀⟩)
· obtain rfl : f = 0 := by
ext n
simpa using H n
simp only [lt_irrefl, false_or_iff] at h₀
exact ⟨0, ⟨neg_lt_zero.2 h₀, h₀⟩, isBigO_zero _ _⟩
exact ⟨a, A ⟨ha₀, ha⟩,
isBigO_of_le' _ fun n ↦ (H n).trans <| mul_le_mul_of_nonneg_left (le_abs_self _) hC₀.le⟩
-- Add 7 and 8 using 2 → 8 → 7 → 3
tfae_have 2 → 8
· rintro ⟨a, ha, H⟩
refine ⟨a, ha, (H.def zero_lt_one).mono fun n hn ↦ ?_⟩
rwa [Real.norm_eq_abs, Real.norm_eq_abs, one_mul, abs_pow, abs_of_pos ha.1] at hn
tfae_have 8 → 7
· exact fun ⟨a, ha, H⟩ ↦ ⟨a, ha.2, H⟩
tfae_have 7 → 3
· rintro ⟨a, ha, H⟩
have : 0 ≤ a := nonneg_of_eventually_pow_nonneg (H.mono fun n ↦ (abs_nonneg _).trans)
refine ⟨a, A ⟨this, ha⟩, IsBigO.of_bound 1 ?_⟩
simpa only [Real.norm_eq_abs, one_mul, abs_pow, abs_of_nonneg this]
-- Porting note: used to work without explicitly having 6 → 7
tfae_have 6 → 7
· exact fun h ↦ tfae_8_to_7 <| tfae_2_to_8 <| tfae_3_to_2 <| tfae_5_to_3 <| tfae_6_to_5 h
tfae_finish
/-- For any natural `k` and a real `r > 1` we have `n ^ k = o(r ^ n)` as `n → ∞`. -/
theorem isLittleO_pow_const_const_pow_of_one_lt {R : Type*} [NormedRing R] (k : ℕ) {r : ℝ}
(hr : 1 < r) : (fun n ↦ (n : R) ^ k : ℕ → R) =o[atTop] fun n ↦ r ^ n := by
have : Tendsto (fun x : ℝ ↦ x ^ k) (𝓝[>] 1) (𝓝 1) :=
((continuous_id.pow k).tendsto' (1 : ℝ) 1 (one_pow _)).mono_left inf_le_left
obtain ⟨r' : ℝ, hr' : r' ^ k < r, h1 : 1 < r'⟩ :=
((this.eventually (gt_mem_nhds hr)).and self_mem_nhdsWithin).exists
have h0 : 0 ≤ r' := zero_le_one.trans h1.le
suffices (fun n ↦ (n : R) ^ k : ℕ → R) =O[atTop] fun n : ℕ ↦ (r' ^ k) ^ n from
this.trans_isLittleO (isLittleO_pow_pow_of_lt_left (pow_nonneg h0 _) hr')
conv in (r' ^ _) ^ _ => rw [← pow_mul, mul_comm, pow_mul]
suffices ∀ n : ℕ, ‖(n : R)‖ ≤ (r' - 1)⁻¹ * ‖(1 : R)‖ * ‖r' ^ n‖ from
(isBigO_of_le' _ this).pow _
intro n
rw [mul_right_comm]
refine n.norm_cast_le.trans (mul_le_mul_of_nonneg_right ?_ (norm_nonneg _))
simpa [_root_.div_eq_inv_mul, Real.norm_eq_abs, abs_of_nonneg h0] using n.cast_le_pow_div_sub h1
/-- For a real `r > 1` we have `n = o(r ^ n)` as `n → ∞`. -/
theorem isLittleO_coe_const_pow_of_one_lt {R : Type*} [NormedRing R] {r : ℝ} (hr : 1 < r) :
((↑) : ℕ → R) =o[atTop] fun n ↦ r ^ n := by
simpa only [pow_one] using @isLittleO_pow_const_const_pow_of_one_lt R _ 1 _ hr
/-- If `‖r₁‖ < r₂`, then for any natural `k` we have `n ^ k r₁ ^ n = o (r₂ ^ n)` as `n → ∞`. -/
theorem isLittleO_pow_const_mul_const_pow_const_pow_of_norm_lt {R : Type*} [NormedRing R] (k : ℕ)
{r₁ : R} {r₂ : ℝ} (h : ‖r₁‖ < r₂) :
(fun n ↦ (n : R) ^ k * r₁ ^ n : ℕ → R) =o[atTop] fun n ↦ r₂ ^ n := by
by_cases h0 : r₁ = 0
· refine (isLittleO_zero _ _).congr' (mem_atTop_sets.2 <| ⟨1, fun n hn ↦ ?_⟩) EventuallyEq.rfl
simp [zero_pow (one_le_iff_ne_zero.1 hn), h0]
rw [← Ne, ← norm_pos_iff] at h0
have A : (fun n ↦ (n : R) ^ k : ℕ → R) =o[atTop] fun n ↦ (r₂ / ‖r₁‖) ^ n :=
isLittleO_pow_const_const_pow_of_one_lt k ((one_lt_div h0).2 h)
suffices (fun n ↦ r₁ ^ n) =O[atTop] fun n ↦ ‖r₁‖ ^ n by
simpa [div_mul_cancel₀ _ (pow_pos h0 _).ne'] using A.mul_isBigO this
exact IsBigO.of_bound 1 (by simpa using eventually_norm_pow_le r₁)
theorem tendsto_pow_const_div_const_pow_of_one_lt (k : ℕ) {r : ℝ} (hr : 1 < r) :
Tendsto (fun n ↦ (n : ℝ) ^ k / r ^ n : ℕ → ℝ) atTop (𝓝 0) :=
(isLittleO_pow_const_const_pow_of_one_lt k hr).tendsto_div_nhds_zero
/-- If `|r| < 1`, then `n ^ k r ^ n` tends to zero for any natural `k`. -/
theorem tendsto_pow_const_mul_const_pow_of_abs_lt_one (k : ℕ) {r : ℝ} (hr : |r| < 1) :
Tendsto (fun n ↦ (n : ℝ) ^ k * r ^ n : ℕ → ℝ) atTop (𝓝 0) := by
by_cases h0 : r = 0
· exact tendsto_const_nhds.congr'
(mem_atTop_sets.2 ⟨1, fun n hn ↦ by simp [zero_lt_one.trans_le hn |>.ne', h0]⟩)
have hr' : 1 < |r|⁻¹ := one_lt_inv (abs_pos.2 h0) hr
rw [tendsto_zero_iff_norm_tendsto_zero]
simpa [div_eq_mul_inv] using tendsto_pow_const_div_const_pow_of_one_lt k hr'
/-- If `0 ≤ r < 1`, then `n ^ k r ^ n` tends to zero for any natural `k`.
This is a specialized version of `tendsto_pow_const_mul_const_pow_of_abs_lt_one`, singled out
for ease of application. -/
theorem tendsto_pow_const_mul_const_pow_of_lt_one (k : ℕ) {r : ℝ} (hr : 0 ≤ r) (h'r : r < 1) :
Tendsto (fun n ↦ (n : ℝ) ^ k * r ^ n : ℕ → ℝ) atTop (𝓝 0) :=
tendsto_pow_const_mul_const_pow_of_abs_lt_one k (abs_lt.2 ⟨neg_one_lt_zero.trans_le hr, h'r⟩)
/-- If `|r| < 1`, then `n * r ^ n` tends to zero. -/
theorem tendsto_self_mul_const_pow_of_abs_lt_one {r : ℝ} (hr : |r| < 1) :
Tendsto (fun n ↦ n * r ^ n : ℕ → ℝ) atTop (𝓝 0) := by
simpa only [pow_one] using tendsto_pow_const_mul_const_pow_of_abs_lt_one 1 hr
/-- If `0 ≤ r < 1`, then `n * r ^ n` tends to zero. This is a specialized version of
`tendsto_self_mul_const_pow_of_abs_lt_one`, singled out for ease of application. -/
theorem tendsto_self_mul_const_pow_of_lt_one {r : ℝ} (hr : 0 ≤ r) (h'r : r < 1) :
Tendsto (fun n ↦ n * r ^ n : ℕ → ℝ) atTop (𝓝 0) := by
simpa only [pow_one] using tendsto_pow_const_mul_const_pow_of_lt_one 1 hr h'r
/-- In a normed ring, the powers of an element x with `‖x‖ < 1` tend to zero. -/
theorem tendsto_pow_atTop_nhds_zero_of_norm_lt_one {R : Type*} [NormedRing R] {x : R}
(h : ‖x‖ < 1) :
Tendsto (fun n : ℕ ↦ x ^ n) atTop (𝓝 0) := by
apply squeeze_zero_norm' (eventually_norm_pow_le x)
exact tendsto_pow_atTop_nhds_zero_of_lt_one (norm_nonneg _) h
@[deprecated (since := "2024-01-31")]
alias tendsto_pow_atTop_nhds_0_of_norm_lt_1 := tendsto_pow_atTop_nhds_zero_of_norm_lt_one
theorem tendsto_pow_atTop_nhds_zero_of_abs_lt_one {r : ℝ} (h : |r| < 1) :
Tendsto (fun n : ℕ ↦ r ^ n) atTop (𝓝 0) :=
tendsto_pow_atTop_nhds_zero_of_norm_lt_one h
@[deprecated (since := "2024-01-31")]
alias tendsto_pow_atTop_nhds_0_of_abs_lt_1 := tendsto_pow_atTop_nhds_zero_of_abs_lt_one
/-! ### Geometric series-/
section Geometric
variable {K : Type*} [NormedDivisionRing K] {ξ : K}
theorem hasSum_geometric_of_norm_lt_one (h : ‖ξ‖ < 1) : HasSum (fun n : ℕ ↦ ξ ^ n) (1 - ξ)⁻¹ := by
have xi_ne_one : ξ ≠ 1 := by
contrapose! h
simp [h]
have A : Tendsto (fun n ↦ (ξ ^ n - 1) * (ξ - 1)⁻¹) atTop (𝓝 ((0 - 1) * (ξ - 1)⁻¹)) :=
((tendsto_pow_atTop_nhds_zero_of_norm_lt_one h).sub tendsto_const_nhds).mul tendsto_const_nhds
rw [hasSum_iff_tendsto_nat_of_summable_norm]
· simpa [geom_sum_eq, xi_ne_one, neg_inv, div_eq_mul_inv] using A
· simp [norm_pow, summable_geometric_of_lt_one (norm_nonneg _) h]
@[deprecated (since := "2024-01-31")]
alias hasSum_geometric_of_norm_lt_1 := hasSum_geometric_of_norm_lt_one
theorem summable_geometric_of_norm_lt_one (h : ‖ξ‖ < 1) : Summable fun n : ℕ ↦ ξ ^ n :=
⟨_, hasSum_geometric_of_norm_lt_one h⟩
@[deprecated (since := "2024-01-31")]
alias summable_geometric_of_norm_lt_1 := summable_geometric_of_norm_lt_one
theorem tsum_geometric_of_norm_lt_one (h : ‖ξ‖ < 1) : ∑' n : ℕ, ξ ^ n = (1 - ξ)⁻¹ :=
(hasSum_geometric_of_norm_lt_one h).tsum_eq
@[deprecated (since := "2024-01-31")]
alias tsum_geometric_of_norm_lt_1 := tsum_geometric_of_norm_lt_one
theorem hasSum_geometric_of_abs_lt_one {r : ℝ} (h : |r| < 1) :
HasSum (fun n : ℕ ↦ r ^ n) (1 - r)⁻¹ :=
hasSum_geometric_of_norm_lt_one h
@[deprecated (since := "2024-01-31")]
alias hasSum_geometric_of_abs_lt_1 := hasSum_geometric_of_abs_lt_one
theorem summable_geometric_of_abs_lt_one {r : ℝ} (h : |r| < 1) : Summable fun n : ℕ ↦ r ^ n :=
summable_geometric_of_norm_lt_one h
@[deprecated (since := "2024-01-31")]
alias summable_geometric_of_abs_lt_1 := summable_geometric_of_abs_lt_one
theorem tsum_geometric_of_abs_lt_one {r : ℝ} (h : |r| < 1) : ∑' n : ℕ, r ^ n = (1 - r)⁻¹ :=
tsum_geometric_of_norm_lt_one h
@[deprecated (since := "2024-01-31")]
alias tsum_geometric_of_abs_lt_1 := tsum_geometric_of_abs_lt_one
/-- A geometric series in a normed field is summable iff the norm of the common ratio is less than
one. -/
@[simp]
theorem summable_geometric_iff_norm_lt_one : (Summable fun n : ℕ ↦ ξ ^ n) ↔ ‖ξ‖ < 1 := by
refine ⟨fun h ↦ ?_, summable_geometric_of_norm_lt_one⟩
obtain ⟨k : ℕ, hk : dist (ξ ^ k) 0 < 1⟩ :=
(h.tendsto_cofinite_zero.eventually (ball_mem_nhds _ zero_lt_one)).exists
simp only [norm_pow, dist_zero_right] at hk
rw [← one_pow k] at hk
exact lt_of_pow_lt_pow_left _ zero_le_one hk
@[deprecated (since := "2024-01-31")]
alias summable_geometric_iff_norm_lt_1 := summable_geometric_iff_norm_lt_one
end Geometric
section MulGeometric
theorem summable_norm_pow_mul_geometric_of_norm_lt_one {R : Type*} [NormedRing R] (k : ℕ) {r : R}
(hr : ‖r‖ < 1) : Summable fun n : ℕ ↦ ‖((n : R) ^ k * r ^ n : R)‖ := by
rcases exists_between hr with ⟨r', hrr', h⟩
exact summable_of_isBigO_nat (summable_geometric_of_lt_one ((norm_nonneg _).trans hrr'.le) h)
(isLittleO_pow_const_mul_const_pow_const_pow_of_norm_lt _ hrr').isBigO.norm_left
@[deprecated (since := "2024-01-31")]
alias summable_norm_pow_mul_geometric_of_norm_lt_1 := summable_norm_pow_mul_geometric_of_norm_lt_one
theorem summable_pow_mul_geometric_of_norm_lt_one {R : Type*} [NormedRing R] [CompleteSpace R]
(k : ℕ) {r : R} (hr : ‖r‖ < 1) : Summable (fun n ↦ (n : R) ^ k * r ^ n : ℕ → R) :=
.of_norm <| summable_norm_pow_mul_geometric_of_norm_lt_one _ hr
@[deprecated (since := "2024-01-31")]
alias summable_pow_mul_geometric_of_norm_lt_1 := summable_pow_mul_geometric_of_norm_lt_one
/-- If `‖r‖ < 1`, then `∑' n : ℕ, n * r ^ n = r / (1 - r) ^ 2`, `HasSum` version. -/
theorem hasSum_coe_mul_geometric_of_norm_lt_one {𝕜 : Type*} [NormedDivisionRing 𝕜] [CompleteSpace 𝕜]
{r : 𝕜} (hr : ‖r‖ < 1) : HasSum (fun n ↦ n * r ^ n : ℕ → 𝕜) (r / (1 - r) ^ 2) := by
have A : Summable (fun n ↦ (n : 𝕜) * r ^ n : ℕ → 𝕜) := by
simpa only [pow_one] using summable_pow_mul_geometric_of_norm_lt_one 1 hr
have B : HasSum (r ^ · : ℕ → 𝕜) (1 - r)⁻¹ := hasSum_geometric_of_norm_lt_one hr
refine A.hasSum_iff.2 ?_
have hr' : r ≠ 1 := by
rintro rfl
simp [lt_irrefl] at hr
set s : 𝕜 := ∑' n : ℕ, n * r ^ n
have : Commute (1 - r) s :=
.tsum_right _ fun _ =>
.sub_left (.one_left _) (.mul_right (Nat.commute_cast _ _) (.pow_right (.refl _) _))
calc
s = s * (1 - r) / (1 - r) := (mul_div_cancel_right₀ _ (sub_ne_zero.2 hr'.symm)).symm
_ = (1 - r) * s / (1 - r) := by rw [this.eq]
_ = (s - r * s) / (1 - r) := by rw [_root_.sub_mul, one_mul]
_ = (((0 : ℕ) * r ^ 0 + ∑' n : ℕ, (n + 1 : ℕ) * r ^ (n + 1)) - r * s) / (1 - r) := by
rw [← tsum_eq_zero_add A]
_ = ((r * ∑' n : ℕ, ↑(n + 1) * r ^ n) - r * s) / (1 - r) := by
simp only [cast_zero, pow_zero, mul_one, _root_.pow_succ', (Nat.cast_commute _ r).left_comm,
_root_.tsum_mul_left, zero_add]
_ = r / (1 - r) ^ 2 := by
simp [add_mul, tsum_add A B.summable, mul_add, B.tsum_eq, ← div_eq_mul_inv, sq,
div_mul_eq_div_div_swap]
@[deprecated (since := "2024-01-31")]
alias hasSum_coe_mul_geometric_of_norm_lt_1 := hasSum_coe_mul_geometric_of_norm_lt_one
/-- If `‖r‖ < 1`, then `∑' n : ℕ, n * r ^ n = r / (1 - r) ^ 2`. -/
theorem tsum_coe_mul_geometric_of_norm_lt_one {𝕜 : Type*} [NormedDivisionRing 𝕜] [CompleteSpace 𝕜]
{r : 𝕜} (hr : ‖r‖ < 1) : (∑' n : ℕ, n * r ^ n : 𝕜) = r / (1 - r) ^ 2 :=
(hasSum_coe_mul_geometric_of_norm_lt_one hr).tsum_eq
@[deprecated (since := "2024-01-31")]
alias tsum_coe_mul_geometric_of_norm_lt_1 := tsum_coe_mul_geometric_of_norm_lt_one
end MulGeometric
section SummableLeGeometric
variable [SeminormedAddCommGroup α] {r C : ℝ} {f : ℕ → α}
nonrec theorem SeminormedAddCommGroup.cauchySeq_of_le_geometric {C : ℝ} {r : ℝ} (hr : r < 1)
{u : ℕ → α} (h : ∀ n, ‖u n - u (n + 1)‖ ≤ C * r ^ n) : CauchySeq u :=
cauchySeq_of_le_geometric r C hr (by simpa [dist_eq_norm] using h)
theorem dist_partial_sum_le_of_le_geometric (hf : ∀ n, ‖f n‖ ≤ C * r ^ n) (n : ℕ) :
dist (∑ i ∈ range n, f i) (∑ i ∈ range (n + 1), f i) ≤ C * r ^ n := by
rw [sum_range_succ, dist_eq_norm, ← norm_neg, neg_sub, add_sub_cancel_left]
exact hf n
/-- If `‖f n‖ ≤ C * r ^ n` for all `n : ℕ` and some `r < 1`, then the partial sums of `f` form a
Cauchy sequence. This lemma does not assume `0 ≤ r` or `0 ≤ C`. -/
theorem cauchySeq_finset_of_geometric_bound (hr : r < 1) (hf : ∀ n, ‖f n‖ ≤ C * r ^ n) :
CauchySeq fun s : Finset ℕ ↦ ∑ x ∈ s, f x :=
cauchySeq_finset_of_norm_bounded _
(aux_hasSum_of_le_geometric hr (dist_partial_sum_le_of_le_geometric hf)).summable hf
/-- If `‖f n‖ ≤ C * r ^ n` for all `n : ℕ` and some `r < 1`, then the partial sums of `f` are within
distance `C * r ^ n / (1 - r)` of the sum of the series. This lemma does not assume `0 ≤ r` or
`0 ≤ C`. -/
theorem norm_sub_le_of_geometric_bound_of_hasSum (hr : r < 1) (hf : ∀ n, ‖f n‖ ≤ C * r ^ n) {a : α}
(ha : HasSum f a) (n : ℕ) : ‖(∑ x ∈ Finset.range n, f x) - a‖ ≤ C * r ^ n / (1 - r) := by
rw [← dist_eq_norm]
apply dist_le_of_le_geometric_of_tendsto r C hr (dist_partial_sum_le_of_le_geometric hf)
exact ha.tendsto_sum_nat
@[simp]
theorem dist_partial_sum (u : ℕ → α) (n : ℕ) :
dist (∑ k ∈ range (n + 1), u k) (∑ k ∈ range n, u k) = ‖u n‖ := by
simp [dist_eq_norm, sum_range_succ]
@[simp]
theorem dist_partial_sum' (u : ℕ → α) (n : ℕ) :
dist (∑ k ∈ range n, u k) (∑ k ∈ range (n + 1), u k) = ‖u n‖ := by
simp [dist_eq_norm', sum_range_succ]
theorem cauchy_series_of_le_geometric {C : ℝ} {u : ℕ → α} {r : ℝ} (hr : r < 1)
(h : ∀ n, ‖u n‖ ≤ C * r ^ n) : CauchySeq fun n ↦ ∑ k ∈ range n, u k :=
cauchySeq_of_le_geometric r C hr (by simp [h])
theorem NormedAddCommGroup.cauchy_series_of_le_geometric' {C : ℝ} {u : ℕ → α} {r : ℝ} (hr : r < 1)
(h : ∀ n, ‖u n‖ ≤ C * r ^ n) : CauchySeq fun n ↦ ∑ k ∈ range (n + 1), u k :=
(cauchy_series_of_le_geometric hr h).comp_tendsto <| tendsto_add_atTop_nat 1
theorem NormedAddCommGroup.cauchy_series_of_le_geometric'' {C : ℝ} {u : ℕ → α} {N : ℕ} {r : ℝ}
(hr₀ : 0 < r) (hr₁ : r < 1) (h : ∀ n ≥ N, ‖u n‖ ≤ C * r ^ n) :
CauchySeq fun n ↦ ∑ k ∈ range (n + 1), u k := by
set v : ℕ → α := fun n ↦ if n < N then 0 else u n
have hC : 0 ≤ C :=
(mul_nonneg_iff_of_pos_right <| pow_pos hr₀ N).mp ((norm_nonneg _).trans <| h N <| le_refl N)
have : ∀ n ≥ N, u n = v n := by
intro n hn
simp [v, hn, if_neg (not_lt.mpr hn)]
apply cauchySeq_sum_of_eventually_eq this
(NormedAddCommGroup.cauchy_series_of_le_geometric' hr₁ _)
· exact C
intro n
simp only [v]
split_ifs with H
· rw [norm_zero]
exact mul_nonneg hC (pow_nonneg hr₀.le _)
· push_neg at H
exact h _ H
/-- The term norms of any convergent series are bounded by a constant. -/
lemma exists_norm_le_of_cauchySeq (h : CauchySeq fun n ↦ ∑ k ∈ range n, f k) :
∃ C, ∀ n, ‖f n‖ ≤ C := by
obtain ⟨b, ⟨_, key, _⟩⟩ := cauchySeq_iff_le_tendsto_0.mp h
refine ⟨b 0, fun n ↦ ?_⟩
simpa only [dist_partial_sum'] using key n (n + 1) 0 (_root_.zero_le _) (_root_.zero_le _)
end SummableLeGeometric
section NormedRingGeometric
variable {R : Type*} [NormedRing R] [CompleteSpace R]
open NormedSpace
/-- A geometric series in a complete normed ring is summable.
Proved above (same name, different namespace) for not-necessarily-complete normed fields. -/
theorem NormedRing.summable_geometric_of_norm_lt_one (x : R) (h : ‖x‖ < 1) :
Summable fun n : ℕ ↦ x ^ n :=
have h1 : Summable fun n : ℕ ↦ ‖x‖ ^ n := summable_geometric_of_lt_one (norm_nonneg _) h
h1.of_norm_bounded_eventually_nat _ (eventually_norm_pow_le x)
@[deprecated (since := "2024-01-31")]
alias NormedRing.summable_geometric_of_norm_lt_1 := NormedRing.summable_geometric_of_norm_lt_one
/-- Bound for the sum of a geometric series in a normed ring. This formula does not assume that the
normed ring satisfies the axiom `‖1‖ = 1`. -/
theorem NormedRing.tsum_geometric_of_norm_lt_one (x : R) (h : ‖x‖ < 1) :
‖∑' n : ℕ, x ^ n‖ ≤ ‖(1 : R)‖ - 1 + (1 - ‖x‖)⁻¹ := by
rw [tsum_eq_zero_add (summable_geometric_of_norm_lt_one x h)]
simp only [_root_.pow_zero]
refine le_trans (norm_add_le _ _) ?_
have : ‖∑' b : ℕ, (fun n ↦ x ^ (n + 1)) b‖ ≤ (1 - ‖x‖)⁻¹ - 1 := by
refine tsum_of_norm_bounded ?_ fun b ↦ norm_pow_le' _ (Nat.succ_pos b)
convert (hasSum_nat_add_iff' 1).mpr (hasSum_geometric_of_lt_one (norm_nonneg x) h)
simp
linarith
@[deprecated (since := "2024-01-31")]
alias NormedRing.tsum_geometric_of_norm_lt_1 := NormedRing.tsum_geometric_of_norm_lt_one
theorem geom_series_mul_neg (x : R) (h : ‖x‖ < 1) : (∑' i : ℕ, x ^ i) * (1 - x) = 1 := by
have := (NormedRing.summable_geometric_of_norm_lt_one x h).hasSum.mul_right (1 - x)
refine tendsto_nhds_unique this.tendsto_sum_nat ?_
have : Tendsto (fun n : ℕ ↦ 1 - x ^ n) atTop (𝓝 1) := by
simpa using tendsto_const_nhds.sub (tendsto_pow_atTop_nhds_zero_of_norm_lt_one h)
convert← this
rw [← geom_sum_mul_neg, Finset.sum_mul]
theorem mul_neg_geom_series (x : R) (h : ‖x‖ < 1) : ((1 - x) * ∑' i : ℕ, x ^ i) = 1 := by
have := (NormedRing.summable_geometric_of_norm_lt_one x h).hasSum.mul_left (1 - x)
refine tendsto_nhds_unique this.tendsto_sum_nat ?_
have : Tendsto (fun n : ℕ ↦ 1 - x ^ n) atTop (𝓝 1) := by
simpa using tendsto_const_nhds.sub (tendsto_pow_atTop_nhds_zero_of_norm_lt_one h)
convert← this
rw [← mul_neg_geom_sum, Finset.mul_sum]
theorem geom_series_succ (x : R) (h : ‖x‖ < 1) : ∑' i : ℕ, x ^ (i + 1) = ∑' i : ℕ, x ^ i - 1 := by
rw [eq_sub_iff_add_eq, tsum_eq_zero_add (NormedRing.summable_geometric_of_norm_lt_one x h),
pow_zero, add_comm]
theorem geom_series_mul_shift (x : R) (h : ‖x‖ < 1) :
x * ∑' i : ℕ, x ^ i = ∑' i : ℕ, x ^ (i + 1) := by
simp_rw [← (NormedRing.summable_geometric_of_norm_lt_one _ h).tsum_mul_left, ← _root_.pow_succ']
theorem geom_series_mul_one_add (x : R) (h : ‖x‖ < 1) :
(1 + x) * ∑' i : ℕ, x ^ i = 2 * ∑' i : ℕ, x ^ i - 1 := by
rw [add_mul, one_mul, geom_series_mul_shift x h, geom_series_succ x h, two_mul, add_sub_assoc]
end NormedRingGeometric
/-! ### Summability tests based on comparison with geometric series -/
theorem summable_of_ratio_norm_eventually_le {α : Type*} [SeminormedAddCommGroup α]
[CompleteSpace α] {f : ℕ → α} {r : ℝ} (hr₁ : r < 1)
(h : ∀ᶠ n in atTop, ‖f (n + 1)‖ ≤ r * ‖f n‖) : Summable f := by
by_cases hr₀ : 0 ≤ r
· rw [eventually_atTop] at h
rcases h with ⟨N, hN⟩
rw [← @summable_nat_add_iff α _ _ _ _ N]
refine .of_norm_bounded (fun n ↦ ‖f N‖ * r ^ n)
(Summable.mul_left _ <| summable_geometric_of_lt_one hr₀ hr₁) fun n ↦ ?_
simp only
conv_rhs => rw [mul_comm, ← zero_add N]
refine le_geom (u := fun n ↦ ‖f (n + N)‖) hr₀ n fun i _ ↦ ?_
convert hN (i + N) (N.le_add_left i) using 3
ac_rfl
· push_neg at hr₀
refine .of_norm_bounded_eventually_nat 0 summable_zero ?_
filter_upwards [h] with _ hn
by_contra! h
exact not_lt.mpr (norm_nonneg _) (lt_of_le_of_lt hn <| mul_neg_of_neg_of_pos hr₀ h)
theorem summable_of_ratio_test_tendsto_lt_one {α : Type*} [NormedAddCommGroup α] [CompleteSpace α]
{f : ℕ → α} {l : ℝ} (hl₁ : l < 1) (hf : ∀ᶠ n in atTop, f n ≠ 0)
(h : Tendsto (fun n ↦ ‖f (n + 1)‖ / ‖f n‖) atTop (𝓝 l)) : Summable f := by
rcases exists_between hl₁ with ⟨r, hr₀, hr₁⟩
refine summable_of_ratio_norm_eventually_le hr₁ ?_
filter_upwards [eventually_le_of_tendsto_lt hr₀ h, hf] with _ _ h₁
rwa [← div_le_iff (norm_pos_iff.mpr h₁)]
theorem not_summable_of_ratio_norm_eventually_ge {α : Type*} [SeminormedAddCommGroup α] {f : ℕ → α}
{r : ℝ} (hr : 1 < r) (hf : ∃ᶠ n in atTop, ‖f n‖ ≠ 0)
(h : ∀ᶠ n in atTop, r * ‖f n‖ ≤ ‖f (n + 1)‖) : ¬Summable f := by
rw [eventually_atTop] at h
rcases h with ⟨N₀, hN₀⟩
rw [frequently_atTop] at hf
rcases hf N₀ with ⟨N, hNN₀ : N₀ ≤ N, hN⟩
rw [← @summable_nat_add_iff α _ _ _ _ N]
refine mt Summable.tendsto_atTop_zero
fun h' ↦ not_tendsto_atTop_of_tendsto_nhds (tendsto_norm_zero.comp h') ?_
convert tendsto_atTop_of_geom_le _ hr _
· refine lt_of_le_of_ne (norm_nonneg _) ?_
intro h''
specialize hN₀ N hNN₀
simp only [comp_apply, zero_add] at h''
exact hN h''.symm
· intro i
dsimp only [comp_apply]
convert hN₀ (i + N) (hNN₀.trans (N.le_add_left i)) using 3
ac_rfl
theorem not_summable_of_ratio_test_tendsto_gt_one {α : Type*} [SeminormedAddCommGroup α]
{f : ℕ → α} {l : ℝ} (hl : 1 < l) (h : Tendsto (fun n ↦ ‖f (n + 1)‖ / ‖f n‖) atTop (𝓝 l)) :
¬Summable f := by
have key : ∀ᶠ n in atTop, ‖f n‖ ≠ 0 := by
filter_upwards [eventually_ge_of_tendsto_gt hl h] with _ hn hc
rw [hc, _root_.div_zero] at hn
linarith
rcases exists_between hl with ⟨r, hr₀, hr₁⟩
refine not_summable_of_ratio_norm_eventually_ge hr₀ key.frequently ?_
filter_upwards [eventually_ge_of_tendsto_gt hr₁ h, key] with _ _ h₁
rwa [← le_div_iff (lt_of_le_of_ne (norm_nonneg _) h₁.symm)]
section NormedDivisionRing
variable [NormedDivisionRing α] [CompleteSpace α] {f : ℕ → α}
/-- If a power series converges at `w`, it converges absolutely at all `z` of smaller norm. -/
theorem summable_powerSeries_of_norm_lt {w z : α}
(h : CauchySeq fun n ↦ ∑ i ∈ range n, f i * w ^ i) (hz : ‖z‖ < ‖w‖) :
Summable fun n ↦ f n * z ^ n := by
have hw : 0 < ‖w‖ := (norm_nonneg z).trans_lt hz
obtain ⟨C, hC⟩ := exists_norm_le_of_cauchySeq h
rw [summable_iff_cauchySeq_finset]
refine cauchySeq_finset_of_geometric_bound (r := ‖z‖ / ‖w‖) (C := C) ((div_lt_one hw).mpr hz)
(fun n ↦ ?_)
rw [norm_mul, norm_pow, div_pow, ← mul_comm_div]
conv at hC => enter [n]; rw [norm_mul, norm_pow, ← _root_.le_div_iff (by positivity)]
exact mul_le_mul_of_nonneg_right (hC n) (pow_nonneg (norm_nonneg z) n)
/-- If a power series converges at 1, it converges absolutely at all `z` of smaller norm. -/
theorem summable_powerSeries_of_norm_lt_one {z : α}
(h : CauchySeq fun n ↦ ∑ i ∈ range n, f i) (hz : ‖z‖ < 1) :
Summable fun n ↦ f n * z ^ n :=
summable_powerSeries_of_norm_lt (w := 1) (by simp [h]) (by simp [hz])
end NormedDivisionRing
section
/-! ### Dirichlet and alternating series tests -/
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E]
variable {b : ℝ} {f : ℕ → ℝ} {z : ℕ → E}
/-- **Dirichlet's test** for monotone sequences. -/
theorem Monotone.cauchySeq_series_mul_of_tendsto_zero_of_bounded (hfa : Monotone f)
(hf0 : Tendsto f atTop (𝓝 0)) (hgb : ∀ n, ‖∑ i ∈ range n, z i‖ ≤ b) :
CauchySeq fun n ↦ ∑ i ∈ range n, f i • z i := by
rw [← cauchySeq_shift 1]
simp_rw [Finset.sum_range_by_parts _ _ (Nat.succ _), sub_eq_add_neg, Nat.succ_sub_succ_eq_sub,
tsub_zero]
apply (NormedField.tendsto_zero_smul_of_tendsto_zero_of_bounded hf0
⟨b, eventually_map.mpr <| eventually_of_forall fun n ↦ hgb <| n + 1⟩).cauchySeq.add
refine CauchySeq.neg ?_
refine cauchySeq_range_of_norm_bounded _ ?_
(fun n ↦ ?_ : ∀ n, ‖(f (n + 1) + -f n) • (Finset.range (n + 1)).sum z‖ ≤ b * |f (n + 1) - f n|)
· simp_rw [abs_of_nonneg (sub_nonneg_of_le (hfa (Nat.le_succ _))), ← mul_sum]
apply Real.uniformContinuous_const_mul.comp_cauchySeq
simp_rw [sum_range_sub, sub_eq_add_neg]
exact (Tendsto.cauchySeq hf0).add_const
· rw [norm_smul, mul_comm]
exact mul_le_mul_of_nonneg_right (hgb _) (abs_nonneg _)
/-- **Dirichlet's test** for antitone sequences. -/
theorem Antitone.cauchySeq_series_mul_of_tendsto_zero_of_bounded (hfa : Antitone f)
(hf0 : Tendsto f atTop (𝓝 0)) (hzb : ∀ n, ‖∑ i ∈ range n, z i‖ ≤ b) :
CauchySeq fun n ↦ ∑ i ∈ range n, f i • z i := by
have hfa' : Monotone fun n ↦ -f n := fun _ _ hab ↦ neg_le_neg <| hfa hab
have hf0' : Tendsto (fun n ↦ -f n) atTop (𝓝 0) := by
convert hf0.neg
norm_num
convert (hfa'.cauchySeq_series_mul_of_tendsto_zero_of_bounded hf0' hzb).neg
simp
theorem norm_sum_neg_one_pow_le (n : ℕ) : ‖∑ i ∈ range n, (-1 : ℝ) ^ i‖ ≤ 1 := by
rw [neg_one_geom_sum]
split_ifs <;> norm_num
/-- The **alternating series test** for monotone sequences.
See also `Monotone.tendsto_alternating_series_of_tendsto_zero`. -/
theorem Monotone.cauchySeq_alternating_series_of_tendsto_zero (hfa : Monotone f)
(hf0 : Tendsto f atTop (𝓝 0)) : CauchySeq fun n ↦ ∑ i ∈ range n, (-1) ^ i * f i := by
simp_rw [mul_comm]
exact hfa.cauchySeq_series_mul_of_tendsto_zero_of_bounded hf0 norm_sum_neg_one_pow_le
/-- The **alternating series test** for monotone sequences. -/
theorem Monotone.tendsto_alternating_series_of_tendsto_zero (hfa : Monotone f)
(hf0 : Tendsto f atTop (𝓝 0)) :
∃ l, Tendsto (fun n ↦ ∑ i ∈ range n, (-1) ^ i * f i) atTop (𝓝 l) :=
cauchySeq_tendsto_of_complete <| hfa.cauchySeq_alternating_series_of_tendsto_zero hf0
/-- The **alternating series test** for antitone sequences.
See also `Antitone.tendsto_alternating_series_of_tendsto_zero`. -/
theorem Antitone.cauchySeq_alternating_series_of_tendsto_zero (hfa : Antitone f)
(hf0 : Tendsto f atTop (𝓝 0)) : CauchySeq fun n ↦ ∑ i ∈ range n, (-1) ^ i * f i := by
simp_rw [mul_comm]
exact hfa.cauchySeq_series_mul_of_tendsto_zero_of_bounded hf0 norm_sum_neg_one_pow_le
/-- The **alternating series test** for antitone sequences. -/
theorem Antitone.tendsto_alternating_series_of_tendsto_zero (hfa : Antitone f)
(hf0 : Tendsto f atTop (𝓝 0)) :
∃ l, Tendsto (fun n ↦ ∑ i ∈ range n, (-1) ^ i * f i) atTop (𝓝 l) :=
cauchySeq_tendsto_of_complete <| hfa.cauchySeq_alternating_series_of_tendsto_zero hf0
end
/-! ### Partial sum bounds on alternating convergent series -/
section
variable {E : Type*} [OrderedRing E] [TopologicalSpace E] [OrderClosedTopology E]
{l : E} {f : ℕ → E}
/-- Partial sums of an alternating monotone series with an even number of terms provide
upper bounds on the limit. -/
theorem Monotone.tendsto_le_alternating_series
(hfl : Tendsto (fun n ↦ ∑ i ∈ range n, (-1) ^ i * f i) atTop (𝓝 l))
(hfm : Monotone f) (k : ℕ) : l ≤ ∑ i ∈ range (2 * k), (-1) ^ i * f i := by
have ha : Antitone (fun n ↦ ∑ i ∈ range (2 * n), (-1) ^ i * f i) := by
refine antitone_nat_of_succ_le (fun n ↦ ?_)
rw [show 2 * (n + 1) = 2 * n + 1 + 1 by ring, sum_range_succ, sum_range_succ]
simp_rw [_root_.pow_succ', show (-1 : E) ^ (2 * n) = 1 by simp, neg_one_mul, one_mul,
← sub_eq_add_neg, sub_le_iff_le_add]
gcongr
exact hfm (by omega)
exact ha.le_of_tendsto (hfl.comp (tendsto_atTop_mono (fun n ↦ by dsimp; omega) tendsto_id)) _
/-- Partial sums of an alternating monotone series with an odd number of terms provide
lower bounds on the limit. -/
theorem Monotone.alternating_series_le_tendsto
(hfl : Tendsto (fun n ↦ ∑ i ∈ range n, (-1) ^ i * f i) atTop (𝓝 l))
(hfm : Monotone f) (k : ℕ) : ∑ i ∈ range (2 * k + 1), (-1) ^ i * f i ≤ l := by
have hm : Monotone (fun n ↦ ∑ i ∈ range (2 * n + 1), (-1) ^ i * f i) := by
refine monotone_nat_of_le_succ (fun n ↦ ?_)
rw [show 2 * (n + 1) = 2 * n + 1 + 1 by ring,
sum_range_succ _ (2 * n + 1 + 1), sum_range_succ _ (2 * n + 1)]
simp_rw [_root_.pow_succ', show (-1 : E) ^ (2 * n) = 1 by simp, neg_one_mul, neg_neg, one_mul,
← sub_eq_add_neg, sub_add_eq_add_sub, le_sub_iff_add_le]
gcongr
exact hfm (by omega)
exact hm.ge_of_tendsto (hfl.comp (tendsto_atTop_mono (fun n ↦ by dsimp; omega) tendsto_id)) _
/-- Partial sums of an alternating antitone series with an even number of terms provide
lower bounds on the limit. -/
theorem Antitone.alternating_series_le_tendsto
(hfl : Tendsto (fun n ↦ ∑ i ∈ range n, (-1) ^ i * f i) atTop (𝓝 l))
(hfa : Antitone f) (k : ℕ) : ∑ i ∈ range (2 * k), (-1) ^ i * f i ≤ l := by
have hm : Monotone (fun n ↦ ∑ i ∈ range (2 * n), (-1) ^ i * f i) := by
refine monotone_nat_of_le_succ (fun n ↦ ?_)
rw [show 2 * (n + 1) = 2 * n + 1 + 1 by ring, sum_range_succ, sum_range_succ]
simp_rw [_root_.pow_succ', show (-1 : E) ^ (2 * n) = 1 by simp, neg_one_mul, one_mul,
← sub_eq_add_neg, le_sub_iff_add_le]
gcongr
exact hfa (by omega)
exact hm.ge_of_tendsto (hfl.comp (tendsto_atTop_mono (fun n ↦ by dsimp; omega) tendsto_id)) _
/-- Partial sums of an alternating antitone series with an odd number of terms provide
upper bounds on the limit. -/
theorem Antitone.tendsto_le_alternating_series
(hfl : Tendsto (fun n ↦ ∑ i ∈ range n, (-1) ^ i * f i) atTop (𝓝 l))
(hfa : Antitone f) (k : ℕ) : l ≤ ∑ i ∈ range (2 * k + 1), (-1) ^ i * f i := by
have ha : Antitone (fun n ↦ ∑ i ∈ range (2 * n + 1), (-1) ^ i * f i) := by
refine antitone_nat_of_succ_le (fun n ↦ ?_)
rw [show 2 * (n + 1) = 2 * n + 1 + 1 by ring, sum_range_succ, sum_range_succ]
simp_rw [_root_.pow_succ', show (-1 : E) ^ (2 * n) = 1 by simp, neg_one_mul, neg_neg, one_mul,
← sub_eq_add_neg, sub_add_eq_add_sub, sub_le_iff_le_add]
gcongr
exact hfa (by omega)
exact ha.le_of_tendsto (hfl.comp (tendsto_atTop_mono (fun n ↦ by dsimp; omega) tendsto_id)) _
end
/-!
### Factorial
-/
/-- The series `∑' n, x ^ n / n!` is summable of any `x : ℝ`. See also `expSeries_div_summable`
for a version that also works in `ℂ`, and `NormedSpace.expSeries_summable'` for a version
that works in any normed algebra over `ℝ` or `ℂ`. -/
theorem Real.summable_pow_div_factorial (x : ℝ) : Summable (fun n ↦ x ^ n / n ! : ℕ → ℝ) := by
-- We start with trivial estimates
have A : (0 : ℝ) < ⌊‖x‖⌋₊ + 1 := zero_lt_one.trans_le (by simp)
have B : ‖x‖ / (⌊‖x‖⌋₊ + 1) < 1 := (div_lt_one A).2 (Nat.lt_floor_add_one _)
-- Then we apply the ratio test. The estimate works for `n ≥ ⌊‖x‖⌋₊`.
suffices ∀ n ≥ ⌊‖x‖⌋₊, ‖x ^ (n + 1) / (n + 1)!‖ ≤ ‖x‖ / (⌊‖x‖⌋₊ + 1) * ‖x ^ n / ↑n !‖ from
summable_of_ratio_norm_eventually_le B (eventually_atTop.2 ⟨⌊‖x‖⌋₊, this⟩)
-- Finally, we prove the upper estimate
intro n hn
calc
‖x ^ (n + 1) / (n + 1)!‖ = ‖x‖ / (n + 1) * ‖x ^ n / (n !)‖ := by
rw [_root_.pow_succ', Nat.factorial_succ, Nat.cast_mul, ← _root_.div_mul_div_comm, norm_mul,
norm_div, Real.norm_natCast, Nat.cast_succ]
_ ≤ ‖x‖ / (⌊‖x‖⌋₊ + 1) * ‖x ^ n / (n !)‖ := by gcongr
theorem Real.tendsto_pow_div_factorial_atTop (x : ℝ) :
Tendsto (fun n ↦ x ^ n / n ! : ℕ → ℝ) atTop (𝓝 0) :=
(Real.summable_pow_div_factorial x).tendsto_atTop_zero
|
Analysis\SpecificLimits\RCLike.lean | /-
Copyright (c) 2023 Xavier Généreux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Xavier Généreux, Patrick Massot
-/
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Analysis.RCLike.Basic
/-!
# A collection of specific limit computations for `RCLike`
-/
open Set Algebra Filter
open scoped Topology
variable (𝕜 : Type*) [RCLike 𝕜]
theorem RCLike.tendsto_inverse_atTop_nhds_zero_nat :
Tendsto (fun n : ℕ => (n : 𝕜)⁻¹) atTop (𝓝 0) := by
convert tendsto_algebraMap_inverse_atTop_nhds_zero_nat 𝕜
simp
@[deprecated (since := "2024-01-16")]
alias RCLike.tendsto_inverse_atTop_nhds_0_nat := RCLike.tendsto_inverse_atTop_nhds_zero_nat
|
Analysis\VonNeumannAlgebra\Basic.lean | /-
Copyright (c) 2022 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Analysis.Normed.Module.Dual
import Mathlib.Analysis.Complex.Basic
import Mathlib.Analysis.InnerProductSpace.Adjoint
/-!
# Von Neumann algebras
We give the "abstract" and "concrete" definitions of a von Neumann algebra.
We still have a major project ahead of us to show the equivalence between these definitions!
An abstract von Neumann algebra `WStarAlgebra M` is a C^* algebra with a Banach space predual,
per Sakai (1971).
A concrete von Neumann algebra `VonNeumannAlgebra H` (where `H` is a Hilbert space)
is a *-closed subalgebra of bounded operators on `H` which is equal to its double commutant.
We'll also need to prove the von Neumann double commutant theorem,
that the concrete definition is equivalent to a *-closed subalgebra which is weakly closed.
-/
universe u v
/-- Sakai's definition of a von Neumann algebra as a C^* algebra with a Banach space predual.
So that we can unambiguously talk about these "abstract" von Neumann algebras
in parallel with the "concrete" ones (weakly closed *-subalgebras of B(H)),
we name this definition `WStarAlgebra`.
Note that for now we only assert the mere existence of predual, rather than picking one.
This may later prove problematic, and need to be revisited.
Picking one may cause problems with definitional unification of different instances.
One the other hand, not picking one means that the weak-* topology
(which depends on a choice of predual) must be defined using the choice,
and we may be unhappy with the resulting opaqueness of the definition.
-/
class WStarAlgebra (M : Type u) [NormedRing M] [StarRing M] [CStarRing M] [Module ℂ M]
[NormedAlgebra ℂ M] [StarModule ℂ M] : Prop where
/-- There is a Banach space `X` whose dual is isometrically (conjugate-linearly) isomorphic
to the `WStarAlgebra`. -/
exists_predual :
∃ (X : Type u) (_ : NormedAddCommGroup X) (_ : NormedSpace ℂ X) (_ : CompleteSpace X),
Nonempty (NormedSpace.Dual ℂ X ≃ₗᵢ⋆[ℂ] M)
-- TODO: Without this, `VonNeumannAlgebra` times out. Why?
/-- The double commutant definition of a von Neumann algebra,
as a *-closed subalgebra of bounded operators on a Hilbert space,
which is equal to its double commutant.
Note that this definition is parameterised by the Hilbert space
on which the algebra faithfully acts, as is standard in the literature.
See `WStarAlgebra` for the abstract notion (a C^*-algebra with Banach space predual).
Note this is a bundled structure, parameterised by the Hilbert space `H`,
rather than a typeclass on the type of elements.
Thus we can't say that the bounded operators `H →L[ℂ] H` form a `VonNeumannAlgebra`
(although we will later construct the instance `WStarAlgebra (H →L[ℂ] H)`),
and instead will use `⊤ : VonNeumannAlgebra H`.
-/
-- Porting note: I don't think the nonempty instance linter exists yet
structure VonNeumannAlgebra (H : Type u) [NormedAddCommGroup H] [InnerProductSpace ℂ H]
[CompleteSpace H] extends StarSubalgebra ℂ (H →L[ℂ] H) where
/-- The double commutant (a.k.a. centralizer) of a `VonNeumannAlgebra` is itself. -/
centralizer_centralizer' : Set.centralizer (Set.centralizer carrier) = carrier
/-- Consider a von Neumann algebra acting on a Hilbert space `H` as a *-subalgebra of `H →L[ℂ] H`.
(That is, we forget that it is equal to its double commutant
or equivalently that it is closed in the weak and strong operator topologies.)
-/
add_decl_doc VonNeumannAlgebra.toStarSubalgebra
namespace VonNeumannAlgebra
variable {H : Type u} [NormedAddCommGroup H] [InnerProductSpace ℂ H] [CompleteSpace H]
instance instSetLike : SetLike (VonNeumannAlgebra H) (H →L[ℂ] H) where
coe S := S.carrier
coe_injective' S T h := by obtain ⟨⟨⟨⟨⟨⟨_, _⟩, _⟩, _⟩, _⟩, _⟩, _⟩ := S; cases T; congr
-- Porting note: `StarMemClass` should be in `Prop`?
noncomputable instance instStarMemClass : StarMemClass (VonNeumannAlgebra H) (H →L[ℂ] H) where
star_mem {s} := s.star_mem'
instance instSubringClass : SubringClass (VonNeumannAlgebra H) (H →L[ℂ] H) where
add_mem {s} := s.add_mem'
mul_mem {s} := s.mul_mem'
one_mem {s} := s.one_mem'
zero_mem {s} := s.zero_mem'
neg_mem {s} a ha := show -a ∈ s.toStarSubalgebra from neg_mem ha
@[simp]
theorem mem_carrier {S : VonNeumannAlgebra H} {x : H →L[ℂ] H} :
x ∈ S.toStarSubalgebra ↔ x ∈ (S : Set (H →L[ℂ] H)) :=
Iff.rfl
-- Porting note: changed the declaration because `simpNF` indicated the LHS simplifies to this.
@[simp]
theorem coe_toStarSubalgebra (S : VonNeumannAlgebra H) :
(S.toStarSubalgebra : Set (H →L[ℂ] H)) = S :=
rfl
@[simp]
theorem coe_mk (S : StarSubalgebra ℂ (H →L[ℂ] H)) (h) :
((⟨S, h⟩ : VonNeumannAlgebra H) : Set (H →L[ℂ] H)) = S :=
rfl
@[ext]
theorem ext {S T : VonNeumannAlgebra H} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T :=
SetLike.ext h
@[simp]
theorem centralizer_centralizer (S : VonNeumannAlgebra H) :
Set.centralizer (Set.centralizer (S : Set (H →L[ℂ] H))) = S :=
S.centralizer_centralizer'
/-- The centralizer of a `VonNeumannAlgebra`, as a `VonNeumannAlgebra`. -/
def commutant (S : VonNeumannAlgebra H) : VonNeumannAlgebra H where
toStarSubalgebra := StarSubalgebra.centralizer ℂ (S : Set (H →L[ℂ] H))
centralizer_centralizer' := by simp
@[simp]
theorem coe_commutant (S : VonNeumannAlgebra H) :
↑S.commutant = Set.centralizer (S : Set (H →L[ℂ] H)) := by
simp [commutant]
@[simp]
theorem mem_commutant_iff {S : VonNeumannAlgebra H} {z : H →L[ℂ] H} :
z ∈ S.commutant ↔ ∀ g ∈ S, g * z = z * g := by
rw [← SetLike.mem_coe, coe_commutant]
rfl
@[simp]
theorem commutant_commutant (S : VonNeumannAlgebra H) : S.commutant.commutant = S :=
SetLike.coe_injective <| by simp
end VonNeumannAlgebra
|
CategoryTheory\Action.lean | /-
Copyright (c) 2020 David Wärn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Wärn
-/
import Mathlib.CategoryTheory.Elements
import Mathlib.CategoryTheory.IsConnected
import Mathlib.CategoryTheory.SingleObj
import Mathlib.GroupTheory.GroupAction.Quotient
import Mathlib.GroupTheory.SemidirectProduct
/-!
# Actions as functors and as categories
From a multiplicative action M ↻ X, we can construct a functor from M to the category of
types, mapping the single object of M to X and an element `m : M` to map `X → X` given by
multiplication by `m`.
This functor induces a category structure on X -- a special case of the category of elements.
A morphism `x ⟶ y` in this category is simply a scalar `m : M` such that `m • x = y`. In the case
where M is a group, this category is a groupoid -- the *action groupoid*.
-/
open MulAction SemidirectProduct
namespace CategoryTheory
universe u
variable (M : Type*) [Monoid M] (X : Type u) [MulAction M X]
/-- A multiplicative action M ↻ X viewed as a functor mapping the single object of M to X
and an element `m : M` to the map `X → X` given by multiplication by `m`. -/
@[simps]
def actionAsFunctor : SingleObj M ⥤ Type u where
obj _ := X
map := (· • ·)
map_id _ := funext <| MulAction.one_smul
map_comp f g := funext fun x => (smul_smul g f x).symm
/-- A multiplicative action M ↻ X induces a category structure on X, where a morphism
from x to y is a scalar taking x to y. Due to implementation details, the object type
of this category is not equal to X, but is in bijection with X. -/
def ActionCategory :=
(actionAsFunctor M X).Elements
instance : Category (ActionCategory M X) := by
dsimp only [ActionCategory]
infer_instance
namespace ActionCategory
/-- The projection from the action category to the monoid, mapping a morphism to its
label. -/
def π : ActionCategory M X ⥤ SingleObj M :=
CategoryOfElements.π _
@[simp]
theorem π_map (p q : ActionCategory M X) (f : p ⟶ q) : (π M X).map f = f.val :=
rfl
@[simp]
theorem π_obj (p : ActionCategory M X) : (π M X).obj p = SingleObj.star M :=
Unit.ext _ _
variable {M X}
/-- The canonical map `ActionCategory M X → X`. It is given by `fun x => x.snd`, but
has a more explicit type. -/
protected def back : ActionCategory M X → X := fun x => x.snd
instance : CoeTC X (ActionCategory M X) :=
⟨fun x => ⟨(), x⟩⟩
@[simp]
theorem coe_back (x : X) : ActionCategory.back (x : ActionCategory M X) = x :=
rfl
@[simp]
theorem back_coe (x : ActionCategory M X) : ↑x.back = x := by cases x; rfl
variable (M X)
/-- An object of the action category given by M ↻ X corresponds to an element of X. -/
def objEquiv : X ≃ ActionCategory M X where
toFun x := x
invFun x := x.back
left_inv := coe_back
right_inv := back_coe
theorem hom_as_subtype (p q : ActionCategory M X) : (p ⟶ q) = { m : M // m • p.back = q.back } :=
rfl
instance [Inhabited X] : Inhabited (ActionCategory M X) :=
⟨show X from default⟩
instance [Nonempty X] : Nonempty (ActionCategory M X) :=
Nonempty.map (objEquiv M X) inferInstance
variable {X} (x : X)
/-- The stabilizer of a point is isomorphic to the endomorphism monoid at the
corresponding point. In fact they are definitionally equivalent. -/
def stabilizerIsoEnd : stabilizerSubmonoid M x ≃* @End (ActionCategory M X) _ x :=
MulEquiv.refl _
@[simp]
theorem stabilizerIsoEnd_apply (f : stabilizerSubmonoid M x) :
(stabilizerIsoEnd M x) f = f :=
rfl
@[simp 1100]
theorem stabilizerIsoEnd_symm_apply (f : End _) : (stabilizerIsoEnd M x).symm f = f :=
rfl
variable {M}
@[simp]
protected theorem id_val (x : ActionCategory M X) : Subtype.val (𝟙 x) = 1 :=
rfl
@[simp]
protected theorem comp_val {x y z : ActionCategory M X} (f : x ⟶ y) (g : y ⟶ z) :
(f ≫ g).val = g.val * f.val :=
rfl
instance [IsPretransitive M X] [Nonempty X] : IsConnected (ActionCategory M X) :=
zigzag_isConnected fun x y =>
Relation.ReflTransGen.single <|
Or.inl <| nonempty_subtype.mpr (show _ from exists_smul_eq M x.back y.back)
section Group
variable {G : Type*} [Group G] [MulAction G X]
instance : Groupoid (ActionCategory G X) :=
CategoryTheory.groupoidOfElements _
/-- Any subgroup of `G` is a vertex group in its action groupoid. -/
def endMulEquivSubgroup (H : Subgroup G) : End (objEquiv G (G ⧸ H) ↑(1 : G)) ≃* H :=
MulEquiv.trans (stabilizerIsoEnd G ((1 : G) : G ⧸ H)).symm
(MulEquiv.subgroupCongr <| stabilizer_quotient H)
/-- A target vertex `t` and a scalar `g` determine a morphism in the action groupoid. -/
def homOfPair (t : X) (g : G) : @Quiver.Hom (ActionCategory G X) _ (g⁻¹ • t :) t :=
Subtype.mk g (smul_inv_smul g t)
@[simp]
theorem homOfPair.val (t : X) (g : G) : (homOfPair t g).val = g :=
rfl
/-- Any morphism in the action groupoid is given by some pair. -/
protected def cases {P : ∀ ⦃a b : ActionCategory G X⦄, (a ⟶ b) → Sort*}
(hyp : ∀ t g, P (homOfPair t g)) ⦃a b⦄ (f : a ⟶ b) : P f := by
refine cast ?_ (hyp b.back f.val)
rcases a with ⟨⟨⟩, a : X⟩
rcases b with ⟨⟨⟩, b : X⟩
rcases f with ⟨g : G, h : g • a = b⟩
cases inv_smul_eq_iff.mpr h.symm
rfl
-- Porting note: added to ease the proof of `uncurry`
lemma cases' ⦃a' b' : ActionCategory G X⦄ (f : a' ⟶ b') :
∃ (a b : X) (g : G) (ha : a' = a) (hb : b' = b) (hg : a = g⁻¹ • b),
f = eqToHom (by rw [ha, hg]) ≫ homOfPair b g ≫ eqToHom (by rw [hb]) := by
revert a' b' f
exact ActionCategory.cases (fun t g => ⟨g⁻¹ • t, t, g, rfl, rfl, rfl, by simp⟩)
variable {H : Type*} [Group H]
/-- Given `G` acting on `X`, a functor from the corresponding action groupoid to a group `H`
can be curried to a group homomorphism `G →* (X → H) ⋊ G`. -/
@[simps]
def curry (F : ActionCategory G X ⥤ SingleObj H) : G →* (X → H) ⋊[mulAutArrow] G :=
have F_map_eq : ∀ {a b} {f : a ⟶ b}, F.map f = (F.map (homOfPair b.back f.val) : H) := by
apply ActionCategory.cases
intros
rfl
{ toFun := fun g => ⟨fun b => F.map (homOfPair b g), g⟩
map_one' := by
dsimp
ext1
· ext b
exact F_map_eq.symm.trans (F.map_id b)
rfl
map_mul' := by
intro g h
ext b
· exact F_map_eq.symm.trans (F.map_comp (homOfPair (g⁻¹ • b) h) (homOfPair b g))
rfl }
/-- Given `G` acting on `X`, a group homomorphism `φ : G →* (X → H) ⋊ G` can be uncurried to
a functor from the action groupoid to `H`, provided that `φ g = (_, g)` for all `g`. -/
@[simps]
def uncurry (F : G →* (X → H) ⋊[mulAutArrow] G) (sane : ∀ g, (F g).right = g) :
ActionCategory G X ⥤ SingleObj H where
obj _ := ()
map {_ b} f := (F f.val).left b.back
map_id x := by
dsimp
rw [F.map_one]
rfl
map_comp f g := by
-- Porting note: I was not able to use `ActionCategory.cases` here,
-- but `ActionCategory.cases'` seems as good; the original proof was:
-- intro x y z f g; revert y z g
-- refine' action_category.cases _
-- simp [single_obj.comp_as_mul, sane]
obtain ⟨_, z, γ₁, rfl, rfl, rfl, rfl⟩ := ActionCategory.cases' g
obtain ⟨_, y, γ₂, rfl, hy, rfl, rfl⟩ := ActionCategory.cases' f
obtain rfl : y = γ₁⁻¹ • z := congr_arg Sigma.snd hy.symm
simp [sane]
rfl
end Group
end ActionCategory
end CategoryTheory
|
CategoryTheory\Adhesive.lean | /-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.CategoryTheory.Extensive
import Mathlib.CategoryTheory.Limits.Shapes.KernelPair
import Mathlib.CategoryTheory.Limits.Constructions.EpiMono
/-!
# Adhesive categories
## Main definitions
- `CategoryTheory.IsPushout.IsVanKampen`: A convenience formulation for a pushout being
a van Kampen colimit.
- `CategoryTheory.Adhesive`: A category is adhesive if it has pushouts and pullbacks along
monomorphisms, and such pushouts are van Kampen.
## Main Results
- `CategoryTheory.Type.adhesive`: The category of `Type` is adhesive.
- `CategoryTheory.Adhesive.isPullback_of_isPushout_of_mono_left`: In adhesive categories,
pushouts along monomorphisms are pullbacks.
- `CategoryTheory.Adhesive.mono_of_isPushout_of_mono_left`: In adhesive categories,
monomorphisms are stable under pushouts.
- `CategoryTheory.Adhesive.toRegularMonoCategory`: Monomorphisms in adhesive categories are
regular (this implies that adhesive categories are balanced).
- `CategoryTheory.adhesive_functor`: The category `C ⥤ D` is adhesive if `D`
has all pullbacks and all pushouts and is adhesive
## References
- https://ncatlab.org/nlab/show/adhesive+category
- [Stephen Lack and Paweł Sobociński, Adhesive Categories][adhesive2004]
-/
namespace CategoryTheory
open Limits
universe v' u' v u
variable {J : Type v'} [Category.{u'} J] {C : Type u} [Category.{v} C]
variable {W X Y Z : C} {f : W ⟶ X} {g : W ⟶ Y} {h : X ⟶ Z} {i : Y ⟶ Z}
-- This only makes sense when the original diagram is a pushout.
/-- A convenience formulation for a pushout being a van Kampen colimit.
See `IsPushout.isVanKampen_iff` below. -/
@[nolint unusedArguments]
def IsPushout.IsVanKampen (_ : IsPushout f g h i) : Prop :=
∀ ⦃W' X' Y' Z' : C⦄ (f' : W' ⟶ X') (g' : W' ⟶ Y') (h' : X' ⟶ Z') (i' : Y' ⟶ Z') (αW : W' ⟶ W)
(αX : X' ⟶ X) (αY : Y' ⟶ Y) (αZ : Z' ⟶ Z) (_ : IsPullback f' αW αX f)
(_ : IsPullback g' αW αY g) (_ : CommSq h' αX αZ h) (_ : CommSq i' αY αZ i)
(_ : CommSq f' g' h' i'), IsPushout f' g' h' i' ↔ IsPullback h' αX αZ h ∧ IsPullback i' αY αZ i
theorem IsPushout.IsVanKampen.flip {H : IsPushout f g h i} (H' : H.IsVanKampen) :
H.flip.IsVanKampen := by
introv W' hf hg hh hi w
simpa only [IsPushout.flip_iff, IsPullback.flip_iff, and_comm] using
H' g' f' i' h' αW αY αX αZ hg hf hi hh w.flip
theorem IsPushout.isVanKampen_iff (H : IsPushout f g h i) :
H.IsVanKampen ↔ IsVanKampenColimit (PushoutCocone.mk h i H.w) := by
constructor
· intro H F' c' α fα eα hα
refine Iff.trans ?_
((H (F'.map WalkingSpan.Hom.fst) (F'.map WalkingSpan.Hom.snd) (c'.ι.app _) (c'.ι.app _)
(α.app _) (α.app _) (α.app _) fα (by convert hα WalkingSpan.Hom.fst)
(by convert hα WalkingSpan.Hom.snd) ?_ ?_ ?_).trans ?_)
· have : F'.map WalkingSpan.Hom.fst ≫ c'.ι.app WalkingSpan.left =
F'.map WalkingSpan.Hom.snd ≫ c'.ι.app WalkingSpan.right := by
simp only [Cocone.w]
rw [(IsColimit.equivOfNatIsoOfIso (diagramIsoSpan F') c' (PushoutCocone.mk _ _ this)
_).nonempty_congr]
· exact ⟨fun h => ⟨⟨this⟩, h⟩, fun h => h.2⟩
· refine Cocones.ext (Iso.refl c'.pt) ?_
rintro (_ | _ | _) <;> dsimp <;>
simp only [c'.w, Category.assoc, Category.id_comp, Category.comp_id]
· exact ⟨NatTrans.congr_app eα.symm _⟩
· exact ⟨NatTrans.congr_app eα.symm _⟩
· exact ⟨by simp⟩
constructor
· rintro ⟨h₁, h₂⟩ (_ | _ | _)
· rw [← c'.w WalkingSpan.Hom.fst]; exact (hα WalkingSpan.Hom.fst).paste_horiz h₁
exacts [h₁, h₂]
· intro h; exact ⟨h _, h _⟩
· introv H W' hf hg hh hi w
refine
Iff.trans ?_ ((H w.cocone ⟨by rintro (_ | _ | _); exacts [αW, αX, αY], ?_⟩ αZ ?_ ?_).trans ?_)
rotate_left
· rintro i _ (_ | _ | _)
· dsimp; simp only [Functor.map_id, Category.comp_id, Category.id_comp]
exacts [hf.w, hg.w]
· ext (_ | _ | _)
· dsimp; rw [PushoutCocone.condition_zero]; erw [Category.assoc, hh.w, hf.w_assoc]
exacts [hh.w.symm, hi.w.symm]
· rintro i _ (_ | _ | _)
· dsimp; simp_rw [Functor.map_id]
exact IsPullback.of_horiz_isIso ⟨by rw [Category.comp_id, Category.id_comp]⟩
exacts [hf, hg]
· constructor
· intro h; exact ⟨h WalkingCospan.left, h WalkingCospan.right⟩
· rintro ⟨h₁, h₂⟩ (_ | _ | _)
· dsimp; rw [PushoutCocone.condition_zero]; exact hf.paste_horiz h₁
exacts [h₁, h₂]
· exact ⟨fun h => h.2, fun h => ⟨w, h⟩⟩
theorem is_coprod_iff_isPushout {X E Y YE : C} (c : BinaryCofan X E) (hc : IsColimit c) {f : X ⟶ Y}
{iY : Y ⟶ YE} {fE : c.pt ⟶ YE} (H : CommSq f c.inl iY fE) :
Nonempty (IsColimit (BinaryCofan.mk (c.inr ≫ fE) iY)) ↔ IsPushout f c.inl iY fE := by
constructor
· rintro ⟨h⟩
refine ⟨H, ⟨Limits.PushoutCocone.isColimitAux' _ ?_⟩⟩
intro s
dsimp only [PushoutCocone.inr, PushoutCocone.mk] -- Porting note: Originally `dsimp`
refine ⟨h.desc (BinaryCofan.mk (c.inr ≫ s.inr) s.inl), h.fac _ ⟨WalkingPair.right⟩, ?_, ?_⟩
· apply BinaryCofan.IsColimit.hom_ext hc
· rw [← H.w_assoc]; erw [h.fac _ ⟨WalkingPair.right⟩]; exact s.condition
· rw [← Category.assoc]; exact h.fac _ ⟨WalkingPair.left⟩
· intro m e₁ e₂
apply BinaryCofan.IsColimit.hom_ext h
· dsimp only [BinaryCofan.mk, id] -- Porting note: Originally `dsimp`
rw [Category.assoc, e₂, eq_comm]; exact h.fac _ ⟨WalkingPair.left⟩
· refine e₁.trans (Eq.symm ?_); exact h.fac _ _
· refine fun H => ⟨?_⟩
fapply Limits.BinaryCofan.isColimitMk
· exact fun s => H.isColimit.desc (PushoutCocone.mk s.inr _ <|
(hc.fac (BinaryCofan.mk (f ≫ s.inr) s.inl) ⟨WalkingPair.left⟩).symm)
· intro s
erw [Category.assoc, H.isColimit.fac _ WalkingSpan.right, hc.fac]; rfl
· intro s; exact H.isColimit.fac _ WalkingSpan.left
· intro s m e₁ e₂
apply PushoutCocone.IsColimit.hom_ext H.isColimit
· symm; exact (H.isColimit.fac _ WalkingSpan.left).trans e₂.symm
· erw [H.isColimit.fac _ WalkingSpan.right]
apply BinaryCofan.IsColimit.hom_ext hc
· erw [hc.fac, ← H.w_assoc, e₂]; rfl
· refine ((Category.assoc _ _ _).symm.trans e₁).trans ?_; symm; exact hc.fac _ _
theorem IsPushout.isVanKampen_inl {W E X Z : C} (c : BinaryCofan W E) [FinitaryExtensive C]
[HasPullbacks C] (hc : IsColimit c) (f : W ⟶ X) (h : X ⟶ Z) (i : c.pt ⟶ Z)
(H : IsPushout f c.inl h i) : H.IsVanKampen := by
obtain ⟨hc₁⟩ := (is_coprod_iff_isPushout c hc H.1).mpr H
introv W' hf hg hh hi w
obtain ⟨hc₂⟩ := ((BinaryCofan.isVanKampen_iff _).mp (FinitaryExtensive.vanKampen c hc)
(BinaryCofan.mk _ (pullback.fst _ _)) _ _ _ hg.w.symm pullback.condition.symm).mpr
⟨hg, IsPullback.of_hasPullback αY c.inr⟩
refine (is_coprod_iff_isPushout _ hc₂ w).symm.trans ?_
refine ((BinaryCofan.isVanKampen_iff _).mp (FinitaryExtensive.vanKampen _ hc₁)
(BinaryCofan.mk _ _) (pullback.snd _ _) _ _ ?_ hh.w.symm).trans ?_
· dsimp; rw [← pullback.condition_assoc, Category.assoc, hi.w]
constructor
· rintro ⟨hc₃, hc₄⟩
refine ⟨hc₄, ?_⟩
let Y'' := pullback αZ i
let cmp : Y' ⟶ Y'' := pullback.lift i' αY hi.w
have e₁ : (g' ≫ cmp) ≫ pullback.snd _ _ = αW ≫ c.inl := by
rw [Category.assoc, pullback.lift_snd, hg.w]
have e₂ : (pullback.fst _ _ ≫ cmp : pullback αY c.inr ⟶ _) ≫ pullback.snd _ _ =
pullback.snd _ _ ≫ c.inr := by
rw [Category.assoc, pullback.lift_snd, pullback.condition]
obtain ⟨hc₄⟩ := ((BinaryCofan.isVanKampen_iff _).mp (FinitaryExtensive.vanKampen c hc)
(BinaryCofan.mk _ _) αW _ _ e₁.symm e₂.symm).mpr <| by
constructor
· apply IsPullback.of_right _ e₁ (IsPullback.of_hasPullback _ _)
rw [Category.assoc, pullback.lift_fst, ← H.w, ← w.w]; exact hf.paste_horiz hc₄
· apply IsPullback.of_right _ e₂ (IsPullback.of_hasPullback _ _)
rw [Category.assoc, pullback.lift_fst]; exact hc₃
rw [← Category.id_comp αZ, ← show cmp ≫ pullback.snd _ _ = αY from pullback.lift_snd _ _ _]
apply IsPullback.paste_vert _ (IsPullback.of_hasPullback αZ i)
have : cmp = (hc₂.coconePointUniqueUpToIso hc₄).hom := by
apply BinaryCofan.IsColimit.hom_ext hc₂
exacts [(hc₂.comp_coconePointUniqueUpToIso_hom hc₄ ⟨WalkingPair.left⟩).symm,
(hc₂.comp_coconePointUniqueUpToIso_hom hc₄ ⟨WalkingPair.right⟩).symm]
rw [this]
exact IsPullback.of_vert_isIso ⟨by rw [← this, Category.comp_id, pullback.lift_fst]⟩
· rintro ⟨hc₃, hc₄⟩
exact ⟨(IsPullback.of_hasPullback αY c.inr).paste_horiz hc₄, hc₃⟩
theorem IsPushout.IsVanKampen.isPullback_of_mono_left [Mono f] {H : IsPushout f g h i}
(H' : H.IsVanKampen) : IsPullback f g h i :=
((H' (𝟙 _) g g (𝟙 Y) (𝟙 _) f (𝟙 _) i (IsKernelPair.id_of_mono f)
(IsPullback.of_vert_isIso ⟨by simp⟩) H.1.flip ⟨rfl⟩ ⟨by simp⟩).mp
(IsPushout.of_horiz_isIso ⟨by simp⟩)).1.flip
theorem IsPushout.IsVanKampen.isPullback_of_mono_right [Mono g] {H : IsPushout f g h i}
(H' : H.IsVanKampen) : IsPullback f g h i :=
((H' f (𝟙 _) (𝟙 _) f (𝟙 _) (𝟙 _) g h (IsPullback.of_vert_isIso ⟨by simp⟩)
(IsKernelPair.id_of_mono g) ⟨rfl⟩ H.1 ⟨by simp⟩).mp
(IsPushout.of_vert_isIso ⟨by simp⟩)).2
theorem IsPushout.IsVanKampen.mono_of_mono_left [Mono f] {H : IsPushout f g h i}
(H' : H.IsVanKampen) : Mono i :=
IsKernelPair.mono_of_isIso_fst
((H' (𝟙 _) g g (𝟙 Y) (𝟙 _) f (𝟙 _) i (IsKernelPair.id_of_mono f)
(IsPullback.of_vert_isIso ⟨by simp⟩) H.1.flip ⟨rfl⟩ ⟨by simp⟩).mp
(IsPushout.of_horiz_isIso ⟨by simp⟩)).2
theorem IsPushout.IsVanKampen.mono_of_mono_right [Mono g] {H : IsPushout f g h i}
(H' : H.IsVanKampen) : Mono h :=
IsKernelPair.mono_of_isIso_fst
((H' f (𝟙 _) (𝟙 _) f (𝟙 _) (𝟙 _) g h (IsPullback.of_vert_isIso ⟨by simp⟩)
(IsKernelPair.id_of_mono g) ⟨rfl⟩ H.1 ⟨by simp⟩).mp
(IsPushout.of_vert_isIso ⟨by simp⟩)).1
/-- A category is adhesive if it has pushouts and pullbacks along monomorphisms,
and such pushouts are van Kampen. -/
class Adhesive (C : Type u) [Category.{v} C] : Prop where
[hasPullback_of_mono_left : ∀ {X Y S : C} (f : X ⟶ S) (g : Y ⟶ S) [Mono f], HasPullback f g]
[hasPushout_of_mono_left : ∀ {X Y S : C} (f : S ⟶ X) (g : S ⟶ Y) [Mono f], HasPushout f g]
van_kampen : ∀ {W X Y Z : C} {f : W ⟶ X} {g : W ⟶ Y} {h : X ⟶ Z} {i : Y ⟶ Z} [Mono f]
(H : IsPushout f g h i), H.IsVanKampen
attribute [instance] Adhesive.hasPullback_of_mono_left Adhesive.hasPushout_of_mono_left
theorem Adhesive.van_kampen' [Adhesive C] [Mono g] (H : IsPushout f g h i) : H.IsVanKampen :=
(Adhesive.van_kampen H.flip).flip
theorem Adhesive.isPullback_of_isPushout_of_mono_left [Adhesive C] (H : IsPushout f g h i)
[Mono f] : IsPullback f g h i :=
(Adhesive.van_kampen H).isPullback_of_mono_left
theorem Adhesive.isPullback_of_isPushout_of_mono_right [Adhesive C] (H : IsPushout f g h i)
[Mono g] : IsPullback f g h i :=
(Adhesive.van_kampen' H).isPullback_of_mono_right
theorem Adhesive.mono_of_isPushout_of_mono_left [Adhesive C] (H : IsPushout f g h i) [Mono f] :
Mono i :=
(Adhesive.van_kampen H).mono_of_mono_left
theorem Adhesive.mono_of_isPushout_of_mono_right [Adhesive C] (H : IsPushout f g h i) [Mono g] :
Mono h :=
(Adhesive.van_kampen' H).mono_of_mono_right
instance Type.adhesive : Adhesive (Type u) :=
⟨fun {_ _ _ _ f _ _ _ _} H =>
(IsPushout.isVanKampen_inl _ (Types.isCoprodOfMono f) _ _ _ H.flip).flip⟩
noncomputable instance (priority := 100) Adhesive.toRegularMonoCategory [Adhesive C] :
RegularMonoCategory C :=
⟨fun f _ =>
{ Z := pushout f f
left := pushout.inl _ _
right := pushout.inr _ _
w := pushout.condition
isLimit := (Adhesive.isPullback_of_isPushout_of_mono_left
(IsPushout.of_hasPushout f f)).isLimitFork }⟩
-- This then implies that adhesive categories are balanced
example [Adhesive C] : Balanced C :=
inferInstance
section functor
universe v'' u''
variable {D : Type u''} [Category.{v''} D]
instance adhesive_functor [Adhesive C] [HasPullbacks C] [HasPushouts C] :
Adhesive (D ⥤ C) := by
constructor
intros W X Y Z f g h i hf H
rw [IsPushout.isVanKampen_iff]
apply isVanKampenColimit_of_evaluation
intro x
refine (IsVanKampenColimit.precompose_isIso_iff (diagramIsoSpan _).inv).mp ?_
refine IsVanKampenColimit.of_iso ?_ (PushoutCocone.isoMk _).symm
refine (IsPushout.isVanKampen_iff (H.map ((evaluation _ _).obj x))).mp ?_
apply Adhesive.van_kampen
theorem adhesive_of_preserves_and_reflects (F : C ⥤ D) [Adhesive D]
[H₁ : ∀ {X Y S : C} (f : X ⟶ S) (g : Y ⟶ S) [Mono f], HasPullback f g]
[H₂ : ∀ {X Y S : C} (f : S ⟶ X) (g : S ⟶ Y) [Mono f], HasPushout f g]
[PreservesLimitsOfShape WalkingCospan F]
[ReflectsLimitsOfShape WalkingCospan F]
[PreservesColimitsOfShape WalkingSpan F]
[ReflectsColimitsOfShape WalkingSpan F] :
Adhesive C := by
apply Adhesive.mk (hasPullback_of_mono_left := H₁) (hasPushout_of_mono_left := H₂)
intros W X Y Z f g h i hf H
rw [IsPushout.isVanKampen_iff]
refine IsVanKampenColimit.of_mapCocone F ?_
refine (IsVanKampenColimit.precompose_isIso_iff (diagramIsoSpan _).inv).mp ?_
refine IsVanKampenColimit.of_iso ?_ (PushoutCocone.isoMk _).symm
refine (IsPushout.isVanKampen_iff (H.map F)).mp ?_
apply Adhesive.van_kampen
theorem adhesive_of_preserves_and_reflects_isomorphism (F : C ⥤ D)
[Adhesive D] [HasPullbacks C] [HasPushouts C]
[PreservesLimitsOfShape WalkingCospan F]
[PreservesColimitsOfShape WalkingSpan F]
[F.ReflectsIsomorphisms] :
Adhesive C := by
haveI : ReflectsLimitsOfShape WalkingCospan F :=
reflectsLimitsOfShapeOfReflectsIsomorphisms
haveI : ReflectsColimitsOfShape WalkingSpan F :=
reflectsColimitsOfShapeOfReflectsIsomorphisms
exact adhesive_of_preserves_and_reflects F
theorem adhesive_of_reflective [HasPullbacks D] [Adhesive C] [HasPullbacks C] [HasPushouts C]
[H₂ : ∀ {X Y S : D} (f : S ⟶ X) (g : S ⟶ Y) [Mono f], HasPushout f g]
{Gl : C ⥤ D} {Gr : D ⥤ C} (adj : Gl ⊣ Gr) [Gr.Full] [Gr.Faithful]
[PreservesLimitsOfShape WalkingCospan Gl] :
Adhesive D := by
have := adj.leftAdjointPreservesColimits
have := adj.rightAdjointPreservesLimits
apply Adhesive.mk (hasPushout_of_mono_left := H₂)
intro W X Y Z f g h i _ H
have := Adhesive.van_kampen (IsPushout.of_hasPushout (Gr.map f) (Gr.map g))
rw [IsPushout.isVanKampen_iff] at this ⊢
refine (IsVanKampenColimit.precompose_isIso_iff
(isoWhiskerLeft _ (asIso adj.counit) ≪≫ Functor.rightUnitor _).hom).mp ?_
refine ((this.precompose_isIso (spanCompIso _ _ _).hom).map_reflective adj).of_iso
(IsColimit.uniqueUpToIso ?_ ?_)
· exact isColimitOfPreserves Gl ((IsColimit.precomposeHomEquiv _ _).symm <| pushoutIsPushout _ _)
· exact (IsColimit.precomposeHomEquiv _ _).symm H.isColimit
end functor
end CategoryTheory
|
CategoryTheory\Balanced.lean | /-
Copyright (c) 2022 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.CategoryTheory.EpiMono
/-!
# Balanced categories
A category is called balanced if any morphism that is both monic and epic is an isomorphism.
Balanced categories arise frequently. For example, categories in which every monomorphism
(or epimorphism) is strong are balanced. Examples of this are abelian categories and toposes, such
as the category of types.
-/
universe v u
namespace CategoryTheory
variable {C : Type u} [Category.{v} C]
section
variable (C)
/-- A category is called balanced if any morphism that is both monic and epic is an isomorphism. -/
class Balanced : Prop where
isIso_of_mono_of_epi : ∀ {X Y : C} (f : X ⟶ Y) [Mono f] [Epi f], IsIso f
end
theorem isIso_of_mono_of_epi [Balanced C] {X Y : C} (f : X ⟶ Y) [Mono f] [Epi f] : IsIso f :=
Balanced.isIso_of_mono_of_epi _
theorem isIso_iff_mono_and_epi [Balanced C] {X Y : C} (f : X ⟶ Y) : IsIso f ↔ Mono f ∧ Epi f :=
⟨fun _ => ⟨inferInstance, inferInstance⟩, fun ⟨_, _⟩ => isIso_of_mono_of_epi _⟩
section
attribute [local instance] isIso_of_mono_of_epi
theorem balanced_opposite [Balanced C] : Balanced Cᵒᵖ :=
{ isIso_of_mono_of_epi := fun f fmono fepi => by
rw [← Quiver.Hom.op_unop f]
exact isIso_of_op _ }
end
end CategoryTheory
|
CategoryTheory\CatCommSq.lean | /-
Copyright (c) 2023 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.CategoryTheory.Equivalence
/-!
# 2-commutative squares of functors
Similarly as `CommSq.lean` defines the notion of commutative squares,
this file introduces the notion of 2-commutative squares of functors.
If `T : C₁ ⥤ C₂`, `L : C₁ ⥤ C₃`, `R : C₂ ⥤ C₄`, `B : C₃ ⥤ C₄` are functors,
then `[CatCommSq T L R B]` contains the datum of an isomorphism `T ⋙ R ≅ L ⋙ B`.
Future work: using this notion in the development of the localization of categories
(e.g. localization of adjunctions).
-/
namespace CategoryTheory
open Category
variable {C₁ C₂ C₃ C₄ C₅ C₆ : Type*} [Category C₁] [Category C₂] [Category C₃] [Category C₄]
[Category C₅] [Category C₆]
(T : C₁ ⥤ C₂) (L : C₁ ⥤ C₃) (R : C₂ ⥤ C₄) (B : C₃ ⥤ C₄)
/-- `CatCommSq T L R B` expresses that there is a 2-commutative square of functors, where
the functors `T`, `L`, `R` and `B` are respectively the left, top, right and bottom functors
of the square. -/
@[ext]
class CatCommSq where
/-- the isomorphism corresponding to a 2-commutative diagram -/
iso' : T ⋙ R ≅ L ⋙ B
namespace CatCommSq
/-- Assuming `[CatCommSq T L R B]`, `iso T L R B` is the isomorphism `T ⋙ R ≅ L ⋙ B`
given by the 2-commutative square. -/
def iso [h : CatCommSq T L R B] : T ⋙ R ≅ L ⋙ B := h.iso'
/-- Horizontal composition of 2-commutative squares -/
@[simps! iso'_hom_app iso'_inv_app]
def hComp (T₁ : C₁ ⥤ C₂) (T₂ : C₂ ⥤ C₃) (V₁ : C₁ ⥤ C₄) (V₂ : C₂ ⥤ C₅) (V₃ : C₃ ⥤ C₆)
(B₁ : C₄ ⥤ C₅) (B₂ : C₅ ⥤ C₆) [CatCommSq T₁ V₁ V₂ B₁] [CatCommSq T₂ V₂ V₃ B₂] :
CatCommSq (T₁ ⋙ T₂) V₁ V₃ (B₁ ⋙ B₂) where
iso' := Functor.associator _ _ _ ≪≫ isoWhiskerLeft T₁ (iso T₂ V₂ V₃ B₂) ≪≫
(Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (iso T₁ V₁ V₂ B₁) B₂ ≪≫
Functor.associator _ _ _
/-- Vertical composition of 2-commutative squares -/
@[simps! iso'_hom_app iso'_inv_app]
def vComp (L₁ : C₁ ⥤ C₂) (L₂ : C₂ ⥤ C₃) (H₁ : C₁ ⥤ C₄) (H₂ : C₂ ⥤ C₅) (H₃ : C₃ ⥤ C₆)
(R₁ : C₄ ⥤ C₅) (R₂ : C₅ ⥤ C₆) [CatCommSq H₁ L₁ R₁ H₂] [CatCommSq H₂ L₂ R₂ H₃] :
CatCommSq H₁ (L₁ ⋙ L₂) (R₁ ⋙ R₂) H₃ where
iso' := (Functor.associator _ _ _).symm ≪≫ isoWhiskerRight (iso H₁ L₁ R₁ H₂) R₂ ≪≫
Functor.associator _ _ _ ≪≫ isoWhiskerLeft L₁ (iso H₂ L₂ R₂ H₃) ≪≫
(Functor.associator _ _ _).symm
section
variable (T : C₁ ≌ C₂) (L : C₁ ⥤ C₃) (R : C₂ ⥤ C₄) (B : C₃ ≌ C₄)
/-- Horizontal inverse of a 2-commutative square -/
@[simps! iso'_hom_app iso'_inv_app]
def hInv (_ : CatCommSq T.functor L R B.functor) : CatCommSq T.inverse R L B.inverse where
iso' := isoWhiskerLeft _ (L.rightUnitor.symm ≪≫ isoWhiskerLeft L B.unitIso ≪≫
(Functor.associator _ _ _).symm ≪≫
isoWhiskerRight (iso T.functor L R B.functor).symm B.inverse ≪≫
Functor.associator _ _ _ ) ≪≫ (Functor.associator _ _ _).symm ≪≫
isoWhiskerRight T.counitIso _ ≪≫ Functor.leftUnitor _
lemma hInv_hInv (h : CatCommSq T.functor L R B.functor) :
hInv T.symm R L B.symm (hInv T L R B h) = h := by
ext X
erw [← cancel_mono (B.functor.map (L.map (T.unitIso.hom.app X))),
← h.iso'.hom.naturality (T.unitIso.hom.app X), hInv_iso'_hom_app, hInv_iso'_inv_app]
dsimp
simp only [Functor.comp_obj, assoc, ← Functor.map_comp, Iso.inv_hom_id_app,
Equivalence.counitInv_app_functor, Functor.map_id]
simp only [Functor.map_comp, Equivalence.fun_inv_map, assoc,
Equivalence.counitInv_functor_comp, comp_id, Iso.inv_hom_id_app_assoc]
rfl
/-- In a square of categories, when the top and bottom functors are part
of equivalence of categories, it is equivalent to show 2-commutativity for
the functors of these equivalences or for their inverses. -/
def hInvEquiv : CatCommSq T.functor L R B.functor ≃ CatCommSq T.inverse R L B.inverse where
toFun := hInv T L R B
invFun := hInv T.symm R L B.symm
left_inv := hInv_hInv T L R B
right_inv := hInv_hInv T.symm R L B.symm
end
section
variable (T : C₁ ⥤ C₂) (L : C₁ ≌ C₃) (R : C₂ ≌ C₄) (B : C₃ ⥤ C₄)
/-- Vertical inverse of a 2-commutative square -/
@[simps! iso'_hom_app iso'_inv_app]
def vInv (_ : CatCommSq T L.functor R.functor B) : CatCommSq B L.inverse R.inverse T where
iso' := isoWhiskerRight (B.leftUnitor.symm ≪≫ isoWhiskerRight L.counitIso.symm B ≪≫
Functor.associator _ _ _ ≪≫
isoWhiskerLeft L.inverse (iso T L.functor R.functor B).symm) R.inverse ≪≫
Functor.associator _ _ _ ≪≫ isoWhiskerLeft _ (Functor.associator _ _ _) ≪≫
(Functor.associator _ _ _ ).symm ≪≫ isoWhiskerLeft _ R.unitIso.symm ≪≫
Functor.rightUnitor _
lemma vInv_vInv (h : CatCommSq T L.functor R.functor B) :
vInv B L.symm R.symm T (vInv T L R B h) = h := by
ext X
erw [vInv_iso'_hom_app, vInv_iso'_inv_app]
dsimp
rw [← cancel_mono (B.map (L.functor.map (NatTrans.app L.unitIso.hom X)))]
erw [← (iso T L.functor R.functor B).hom.naturality (L.unitIso.hom.app X)]
dsimp
simp only [Functor.map_comp, Equivalence.fun_inv_map, Functor.comp_obj,
Functor.id_obj, assoc, Iso.inv_hom_id_app_assoc, Iso.inv_hom_id_app, comp_id]
erw [← B.map_comp, L.counit_app_functor, ← L.functor.map_comp, ← NatTrans.comp_app,
Iso.inv_hom_id, NatTrans.id_app, L.functor.map_id, B.map_id, comp_id, R.counit_app_functor,
← R.functor.map_comp_assoc, ← R.functor.map_comp_assoc, assoc, ← NatTrans.comp_app,
Iso.hom_inv_id, NatTrans.id_app, comp_id]
/-- In a square of categories, when the left and right functors are part
of equivalence of categories, it is equivalent to show 2-commutativity for
the functors of these equivalences or for their inverses. -/
def vInvEquiv : CatCommSq T L.functor R.functor B ≃ CatCommSq B L.inverse R.inverse T where
toFun := vInv T L R B
invFun := vInv B L.symm R.symm T
left_inv := vInv_vInv T L R B
right_inv := vInv_vInv B L.symm R.symm T
end
end CatCommSq
end CategoryTheory
|
CategoryTheory\ChosenFiniteProducts.lean | /-
Copyright (c) 2024 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz
-/
import Mathlib.CategoryTheory.Monoidal.OfChosenFiniteProducts.Symmetric
import Mathlib.CategoryTheory.Limits.Constructions.FiniteProductsOfBinaryProducts
/-!
# Categories with chosen finite products
We introduce a class, `ChosenFiniteProducts`, which bundles explicit choices
for a terminal object and binary products in a category `C`.
This is primarily useful for categories which have finite products with good
definitional properties, such as the category of types.
Given a category with such an instance, we also provide the associated
symmetric monoidal structure so that one can write `X ⊗ Y` for the explicit
binary product and `𝟙_ C` for the explicit terminal object.
# Projects
- Construct an instance of chosen finite products in the category of affine scheme, using
the tensor product.
- Construct chosen finite products in other categories appearing "in nature".
-/
namespace CategoryTheory
universe v u
/--
An instance of `ChosenFiniteProducts C` bundles an explicit choice of a binary
product of two objects of `C`, and a terminal object in `C`.
Users should use the monoidal notation: `X ⊗ Y` for the product and `𝟙_ C` for
the terminal object.
-/
class ChosenFiniteProducts (C : Type u) [Category.{v} C] where
/-- A choice of a limit binary fan for any two objects of the category. -/
product : (X Y : C) → Limits.LimitCone (Limits.pair X Y)
/-- A choice of a terminal object. -/
terminal : Limits.LimitCone (Functor.empty.{0} C)
namespace ChosenFiniteProducts
instance (priority := 100) (C : Type u) [Category.{v} C] [ChosenFiniteProducts C] :
MonoidalCategory C :=
monoidalOfChosenFiniteProducts terminal product
instance (priority := 100) (C : Type u) [Category.{v} C] [ChosenFiniteProducts C] :
SymmetricCategory C :=
symmetricOfChosenFiniteProducts _ _
variable {C : Type u} [Category.{v} C] [ChosenFiniteProducts C]
open MonoidalCategory
/--
The unique map to the terminal object.
-/
def toUnit (X : C) : X ⟶ 𝟙_ C :=
terminal.isLimit.lift <| .mk _ <| .mk (fun x => x.as.elim) fun x => x.as.elim
instance (X : C) : Unique (X ⟶ 𝟙_ C) where
default := toUnit _
uniq _ := terminal.isLimit.hom_ext fun ⟨j⟩ => j.elim
/--
This lemma follows from the preexisting `Unique` instance, but
it is often convenient to use it directly as `apply toUnit_unique` forcing
lean to do the necessary elaboration.
-/
lemma toUnit_unique {X : C} (f g : X ⟶ 𝟙_ _) : f = g :=
Subsingleton.elim _ _
/--
Construct a morphism to the product given its two components.
-/
def lift {T X Y : C} (f : T ⟶ X) (g : T ⟶ Y) : T ⟶ X ⊗ Y :=
(product X Y).isLimit.lift <| Limits.BinaryFan.mk f g
/--
The first projection from the product.
-/
def fst (X Y : C) : X ⊗ Y ⟶ X :=
letI F : Limits.BinaryFan X Y := (product X Y).cone
F.fst
/--
The second projection from the product.
-/
def snd (X Y : C) : X ⊗ Y ⟶ Y :=
letI F : Limits.BinaryFan X Y := (product X Y).cone
F.snd
@[reassoc (attr := simp)]
lemma lift_fst {T X Y : C} (f : T ⟶ X) (g : T ⟶ Y) : lift f g ≫ fst _ _ = f := by
simp [lift, fst]
@[reassoc (attr := simp)]
lemma lift_snd {T X Y : C} (f : T ⟶ X) (g : T ⟶ Y) : lift f g ≫ snd _ _ = g := by
simp [lift, snd]
@[ext 1050]
lemma hom_ext {T X Y : C} (f g : T ⟶ X ⊗ Y)
(h_fst : f ≫ fst _ _ = g ≫ fst _ _)
(h_snd : f ≫ snd _ _ = g ≫ snd _ _) :
f = g :=
(product X Y).isLimit.hom_ext fun ⟨j⟩ => j.recOn h_fst h_snd
@[reassoc (attr := simp)]
lemma tensorHom_fst {X₁ X₂ Y₁ Y₂ : C} (f : X₁ ⟶ X₂) (g : Y₁ ⟶ Y₂) :
(f ⊗ g) ≫ fst _ _ = fst _ _ ≫ f := lift_fst _ _
@[reassoc (attr := simp)]
lemma tensorHom_snd {X₁ X₂ Y₁ Y₂ : C} (f : X₁ ⟶ X₂) (g : Y₁ ⟶ Y₂) :
(f ⊗ g) ≫ snd _ _ = snd _ _ ≫ g := lift_snd _ _
@[reassoc (attr := simp)]
lemma whiskerLeft_fst (X : C) {Y₁ Y₂ : C} (g : Y₁ ⟶ Y₂) :
(X ◁ g) ≫ fst _ _ = fst _ _ :=
(tensorHom_fst _ _).trans (by simp)
@[reassoc (attr := simp)]
lemma whiskerLeft_snd (X : C) {Y₁ Y₂ : C} (g : Y₁ ⟶ Y₂) :
(X ◁ g) ≫ snd _ _ = snd _ _ ≫ g :=
tensorHom_snd _ _
@[reassoc (attr := simp)]
lemma whiskerRight_fst {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) :
(f ▷ Y) ≫ fst _ _ = fst _ _ ≫ f :=
tensorHom_fst _ _
@[reassoc (attr := simp)]
lemma whiskerRight_snd {X₁ X₂ : C} (f : X₁ ⟶ X₂) (Y : C) :
(f ▷ Y) ≫ snd _ _ = snd _ _ :=
(tensorHom_snd _ _).trans (by simp)
@[reassoc (attr := simp)]
lemma associator_hom_fst (X Y Z : C) :
(α_ X Y Z).hom ≫ fst _ _ = fst _ _ ≫ fst _ _ := lift_fst _ _
@[reassoc (attr := simp)]
lemma associator_hom_snd_fst (X Y Z : C) :
(α_ X Y Z).hom ≫ snd _ _ ≫ fst _ _ = fst _ _ ≫ snd _ _ := by
erw [lift_snd_assoc, lift_fst]
rfl
@[reassoc (attr := simp)]
lemma associator_hom_snd_snd (X Y Z : C) :
(α_ X Y Z).hom ≫ snd _ _ ≫ snd _ _ = snd _ _ := by
erw [lift_snd_assoc, lift_snd]
rfl
@[reassoc (attr := simp)]
lemma associator_inv_fst (X Y Z : C) :
(α_ X Y Z).inv ≫ fst _ _ ≫ fst _ _ = fst _ _ := by
erw [lift_fst_assoc, lift_fst]
rfl
@[reassoc (attr := simp)]
lemma associator_inv_fst_snd (X Y Z : C) :
(α_ X Y Z).inv ≫ fst _ _ ≫ snd _ _ = snd _ _ ≫ fst _ _ := by
erw [lift_fst_assoc, lift_snd]
rfl
@[reassoc (attr := simp)]
lemma associator_inv_snd (X Y Z : C) :
(α_ X Y Z).inv ≫ snd _ _ = snd _ _ ≫ snd _ _ := lift_snd _ _
/--
Construct an instance of `ChosenFiniteProducts C` given an instance of `HasFiniteProducts C`.
-/
noncomputable
def ofFiniteProducts
(C : Type u) [Category.{v} C] [Limits.HasFiniteProducts C] :
ChosenFiniteProducts C where
product X Y := Limits.getLimitCone (Limits.pair X Y)
terminal := Limits.getLimitCone (Functor.empty C)
instance (priority := 100) : Limits.HasFiniteProducts C :=
letI : ∀ (X Y : C), Limits.HasLimit (Limits.pair X Y) := fun _ _ =>
.mk <| ChosenFiniteProducts.product _ _
letI : Limits.HasBinaryProducts C := Limits.hasBinaryProducts_of_hasLimit_pair _
letI : Limits.HasTerminal C := Limits.hasTerminal_of_unique (𝟙_ _)
hasFiniteProducts_of_has_binary_and_terminal
end ChosenFiniteProducts
end CategoryTheory
|
CategoryTheory\ClosedUnderIsomorphisms.lean | /-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.CategoryTheory.Iso
import Mathlib.Order.Basic
/-! # Predicates on objects which are closed under isomorphisms
This file introduces the type class `ClosedUnderIsomorphisms P` for predicates
`P : C → Prop` on the objects of a category `C`.
-/
namespace CategoryTheory
variable {C : Type*} [Category C] (P Q : C → Prop)
/-- A predicate `C → Prop` on the objects of a category is closed under isomorphisms
if whenever `P X`, then all the objects `Y` that are isomorphic to `X` also satisfy `P Y`. -/
class ClosedUnderIsomorphisms : Prop where
of_iso {X Y : C} (_ : X ≅ Y) (_ : P X) : P Y
lemma mem_of_iso [ClosedUnderIsomorphisms P] {X Y : C} (e : X ≅ Y) (hX : P X) : P Y :=
ClosedUnderIsomorphisms.of_iso e hX
lemma mem_iff_of_iso [ClosedUnderIsomorphisms P] {X Y : C} (e : X ≅ Y) : P X ↔ P Y :=
⟨mem_of_iso P e, mem_of_iso P e.symm⟩
lemma mem_of_isIso [ClosedUnderIsomorphisms P] {X Y : C} (f : X ⟶ Y) [IsIso f] (hX : P X) : P Y :=
mem_of_iso P (asIso f) hX
lemma mem_iff_of_isIso [ClosedUnderIsomorphisms P] {X Y : C} (f : X ⟶ Y) [IsIso f] : P X ↔ P Y :=
mem_iff_of_iso P (asIso f)
/-- The closure by isomorphisms of a predicate on objects in a category. -/
def isoClosure : C → Prop := fun X => ∃ (Y : C) (_ : P Y), Nonempty (X ≅ Y)
lemma mem_isoClosure_iff (X : C) :
isoClosure P X ↔ ∃ (Y : C) (_ : P Y), Nonempty (X ≅ Y) := by rfl
variable {P} in
lemma mem_isoClosure {X Y : C} (h : P X) (e : X ⟶ Y) [IsIso e] : isoClosure P Y :=
⟨X, h, ⟨(asIso e).symm⟩⟩
lemma le_isoClosure : P ≤ isoClosure P :=
fun X hX => ⟨X, hX, ⟨Iso.refl X⟩⟩
variable {P Q} in
lemma monotone_isoClosure (h : P ≤ Q) : isoClosure P ≤ isoClosure Q := by
rintro X ⟨X', hX', ⟨e⟩⟩
exact ⟨X', h _ hX', ⟨e⟩⟩
lemma isoClosure_eq_self [ClosedUnderIsomorphisms P] : isoClosure P = P := by
apply le_antisymm
· intro X ⟨Y, hY, ⟨e⟩⟩
exact mem_of_iso P e.symm hY
· exact le_isoClosure P
lemma isoClosure_le_iff [ClosedUnderIsomorphisms Q] : isoClosure P ≤ Q ↔ P ≤ Q :=
⟨(le_isoClosure P).trans,
fun h => (monotone_isoClosure h).trans (by rw [isoClosure_eq_self])⟩
instance : ClosedUnderIsomorphisms (isoClosure P) where
of_iso := by
rintro X Y e ⟨Z, hZ, ⟨f⟩⟩
exact ⟨Z, hZ, ⟨e.symm.trans f⟩⟩
end CategoryTheory
|
CategoryTheory\CofilteredSystem.lean | /-
Copyright (c) 2022 Kyle Miller, Adam Topaz, Rémi Bottinelli, Junyan Xu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller, Adam Topaz, Rémi Bottinelli, Junyan Xu
-/
import Mathlib.CategoryTheory.Filtered.Basic
import Mathlib.Data.Set.Finite
import Mathlib.Data.Set.Subsingleton
import Mathlib.Topology.Category.TopCat.Limits.Konig
import Mathlib.Tactic.AdaptationNote
/-!
# Cofiltered systems
This file deals with properties of cofiltered (and inverse) systems.
## Main definitions
Given a functor `F : J ⥤ Type v`:
* For `j : J`, `F.eventualRange j` is the intersections of all ranges of morphisms `F.map f`
where `f` has codomain `j`.
* `F.IsMittagLeffler` states that the functor `F` satisfies the Mittag-Leffler
condition: the ranges of morphisms `F.map f` (with `f` having codomain `j`) stabilize.
* If `J` is cofiltered `F.toEventualRanges` is the subfunctor of `F` obtained by restriction
to `F.eventualRange`.
* `F.toPreimages` restricts a functor to preimages of a given set in some `F.obj i`. If `J` is
cofiltered, then it is Mittag-Leffler if `F` is, see `IsMittagLeffler.toPreimages`.
## Main statements
* `nonempty_sections_of_finite_cofiltered_system` shows that if `J` is cofiltered and each
`F.obj j` is nonempty and finite, `F.sections` is nonempty.
* `nonempty_sections_of_finite_inverse_system` is a specialization of the above to `J` being a
directed set (and `F : Jᵒᵖ ⥤ Type v`).
* `isMittagLeffler_of_exists_finite_range` shows that if `J` is cofiltered and for all `j`,
there exists some `i` and `f : i ⟶ j` such that the range of `F.map f` is finite, then
`F` is Mittag-Leffler.
* `surjective_toEventualRanges` shows that if `F` is Mittag-Leffler, then `F.toEventualRanges`
has all morphisms `F.map f` surjective.
## TODO
* Prove [Stacks: Lemma 0597](https://stacks.math.columbia.edu/tag/0597)
## References
* [Stacks: Mittag-Leffler systems](https://stacks.math.columbia.edu/tag/0594)
## Tags
Mittag-Leffler, surjective, eventual range, inverse system,
-/
universe u v w
open CategoryTheory CategoryTheory.IsCofiltered Set CategoryTheory.FunctorToTypes
section FiniteKonig
/-- This bootstraps `nonempty_sections_of_finite_inverse_system`. In this version,
the `F` functor is between categories of the same universe, and it is an easy
corollary to `TopCat.nonempty_limitCone_of_compact_t2_cofiltered_system`. -/
theorem nonempty_sections_of_finite_cofiltered_system.init {J : Type u} [SmallCategory J]
[IsCofilteredOrEmpty J] (F : J ⥤ Type u) [hf : ∀ j, Finite (F.obj j)]
[hne : ∀ j, Nonempty (F.obj j)] : F.sections.Nonempty := by
let F' : J ⥤ TopCat := F ⋙ TopCat.discrete
haveI : ∀ j, DiscreteTopology (F'.obj j) := fun _ => ⟨rfl⟩
haveI : ∀ j, Finite (F'.obj j) := hf
haveI : ∀ j, Nonempty (F'.obj j) := hne
obtain ⟨⟨u, hu⟩⟩ := TopCat.nonempty_limitCone_of_compact_t2_cofiltered_system.{u} F'
exact ⟨u, hu⟩
/-- The cofiltered limit of nonempty finite types is nonempty.
See `nonempty_sections_of_finite_inverse_system` for a specialization to inverse limits. -/
theorem nonempty_sections_of_finite_cofiltered_system {J : Type u} [Category.{w} J]
[IsCofilteredOrEmpty J] (F : J ⥤ Type v) [∀ j : J, Finite (F.obj j)]
[∀ j : J, Nonempty (F.obj j)] : F.sections.Nonempty := by
-- Step 1: lift everything to the `max u v w` universe.
let J' : Type max w v u := AsSmall.{max w v} J
let down : J' ⥤ J := AsSmall.down
let F' : J' ⥤ Type max u v w := down ⋙ F ⋙ uliftFunctor.{max u w, v}
haveI : ∀ i, Nonempty (F'.obj i) := fun i => ⟨⟨Classical.arbitrary (F.obj (down.obj i))⟩⟩
haveI : ∀ i, Finite (F'.obj i) := fun i => Finite.of_equiv (F.obj (down.obj i)) Equiv.ulift.symm
-- Step 2: apply the bootstrap theorem
cases isEmpty_or_nonempty J
· fconstructor <;> apply isEmptyElim
haveI : IsCofiltered J := ⟨⟩
obtain ⟨u, hu⟩ := nonempty_sections_of_finite_cofiltered_system.init F'
-- Step 3: interpret the results
use fun j => (u ⟨j⟩).down
intro j j' f
have h := @hu (⟨j⟩ : J') (⟨j'⟩ : J') (ULift.up f)
simp only [F', down, AsSmall.down, Functor.comp_map, uliftFunctor_map, Functor.op_map] at h
simp_rw [← h]
/-- The inverse limit of nonempty finite types is nonempty.
See `nonempty_sections_of_finite_cofiltered_system` for a generalization to cofiltered limits.
That version applies in almost all cases, and the only difference is that this version
allows `J` to be empty.
This may be regarded as a generalization of Kőnig's lemma.
To specialize: given a locally finite connected graph, take `Jᵒᵖ` to be `ℕ` and
`F j` to be length-`j` paths that start from an arbitrary fixed vertex.
Elements of `F.sections` can be read off as infinite rays in the graph. -/
theorem nonempty_sections_of_finite_inverse_system {J : Type u} [Preorder J] [IsDirected J (· ≤ ·)]
(F : Jᵒᵖ ⥤ Type v) [∀ j : Jᵒᵖ, Finite (F.obj j)] [∀ j : Jᵒᵖ, Nonempty (F.obj j)] :
F.sections.Nonempty := by
cases isEmpty_or_nonempty J
· haveI : IsEmpty Jᵒᵖ := ⟨fun j => isEmptyElim j.unop⟩ -- TODO: this should be a global instance
exact ⟨isEmptyElim, by apply isEmptyElim⟩
· exact nonempty_sections_of_finite_cofiltered_system _
end FiniteKonig
namespace CategoryTheory
namespace Functor
variable {J : Type u} [Category J] (F : J ⥤ Type v) {i j k : J} (s : Set (F.obj i))
/-- The eventual range of the functor `F : J ⥤ Type v` at index `j : J` is the intersection
of the ranges of all maps `F.map f` with `i : J` and `f : i ⟶ j`. -/
def eventualRange (j : J) :=
⋂ (i) (f : i ⟶ j), range (F.map f)
theorem mem_eventualRange_iff {x : F.obj j} :
x ∈ F.eventualRange j ↔ ∀ ⦃i⦄ (f : i ⟶ j), x ∈ range (F.map f) :=
mem_iInter₂
/-- The functor `F : J ⥤ Type v` satisfies the Mittag-Leffler condition if for all `j : J`,
there exists some `i : J` and `f : i ⟶ j` such that for all `k : J` and `g : k ⟶ j`, the range
of `F.map f` is contained in that of `F.map g`;
in other words (see `isMittagLeffler_iff_eventualRange`), the eventual range at `j` is attained
by some `f : i ⟶ j`. -/
def IsMittagLeffler : Prop :=
∀ j : J, ∃ (i : _) (f : i ⟶ j), ∀ ⦃k⦄ (g : k ⟶ j), range (F.map f) ⊆ range (F.map g)
theorem isMittagLeffler_iff_eventualRange :
F.IsMittagLeffler ↔ ∀ j : J, ∃ (i : _) (f : i ⟶ j), F.eventualRange j = range (F.map f) :=
forall_congr' fun _ =>
exists₂_congr fun _ _ =>
⟨fun h => (iInter₂_subset _ _).antisymm <| subset_iInter₂ h, fun h => h ▸ iInter₂_subset⟩
theorem IsMittagLeffler.subset_image_eventualRange (h : F.IsMittagLeffler) (f : j ⟶ i) :
F.eventualRange i ⊆ F.map f '' F.eventualRange j := by
obtain ⟨k, g, hg⟩ := F.isMittagLeffler_iff_eventualRange.1 h j
rw [hg]; intro x hx
obtain ⟨x, rfl⟩ := F.mem_eventualRange_iff.1 hx (g ≫ f)
exact ⟨_, ⟨x, rfl⟩, by rw [map_comp_apply]⟩
theorem eventualRange_eq_range_precomp (f : i ⟶ j) (g : j ⟶ k)
(h : F.eventualRange k = range (F.map g)) : F.eventualRange k = range (F.map <| f ≫ g) := by
apply subset_antisymm
· apply iInter₂_subset
· rw [h, F.map_comp]
apply range_comp_subset_range
theorem isMittagLeffler_of_surjective (h : ∀ ⦃i j : J⦄ (f : i ⟶ j), (F.map f).Surjective) :
F.IsMittagLeffler :=
fun j => ⟨j, 𝟙 j, fun k g => by rw [map_id, types_id, range_id, (h g).range_eq]⟩
/-- The subfunctor of `F` obtained by restricting to the preimages of a set `s ∈ F.obj i`. -/
@[simps]
def toPreimages : J ⥤ Type v where
obj j := ⋂ f : j ⟶ i, F.map f ⁻¹' s
map g := MapsTo.restrict (F.map g) _ _ fun x h => by
rw [mem_iInter] at h ⊢
intro f
rw [← mem_preimage, preimage_preimage, mem_preimage]
convert h (g ≫ f); rw [F.map_comp]; rfl
map_id j := by
#adaptation_note /-- nightly-2024-03-16: simp was
simp (config := { unfoldPartialApp := true }) only [MapsTo.restrict, Subtype.map, F.map_id] -/
simp only [MapsTo.restrict, Subtype.map_def, F.map_id]
ext
rfl
map_comp f g := by
#adaptation_note /-- nightly-2024-03-16: simp was
simp (config := { unfoldPartialApp := true }) only [MapsTo.restrict, Subtype.map, F.map_comp] -/
simp only [MapsTo.restrict, Subtype.map_def, F.map_comp]
rfl
instance toPreimages_finite [∀ j, Finite (F.obj j)] : ∀ j, Finite ((F.toPreimages s).obj j) :=
fun _ => Subtype.finite
variable [IsCofilteredOrEmpty J]
theorem eventualRange_mapsTo (f : j ⟶ i) :
(F.eventualRange j).MapsTo (F.map f) (F.eventualRange i) := fun x hx => by
rw [mem_eventualRange_iff] at hx ⊢
intro k f'
obtain ⟨l, g, g', he⟩ := cospan f f'
obtain ⟨x, rfl⟩ := hx g
rw [← map_comp_apply, he, F.map_comp]
exact ⟨_, rfl⟩
theorem IsMittagLeffler.eq_image_eventualRange (h : F.IsMittagLeffler) (f : j ⟶ i) :
F.eventualRange i = F.map f '' F.eventualRange j :=
(h.subset_image_eventualRange F f).antisymm <| mapsTo'.1 (F.eventualRange_mapsTo f)
theorem eventualRange_eq_iff {f : i ⟶ j} :
F.eventualRange j = range (F.map f) ↔
∀ ⦃k⦄ (g : k ⟶ i), range (F.map f) ⊆ range (F.map <| g ≫ f) := by
rw [subset_antisymm_iff, eventualRange, and_iff_right (iInter₂_subset _ _), subset_iInter₂_iff]
refine ⟨fun h k g => h _ _, fun h j' f' => ?_⟩
obtain ⟨k, g, g', he⟩ := cospan f f'
refine (h g).trans ?_
rw [he, F.map_comp]
apply range_comp_subset_range
theorem isMittagLeffler_iff_subset_range_comp : F.IsMittagLeffler ↔ ∀ j : J, ∃ (i : _) (f : i ⟶ j),
∀ ⦃k⦄ (g : k ⟶ i), range (F.map f) ⊆ range (F.map <| g ≫ f) := by
simp_rw [isMittagLeffler_iff_eventualRange, eventualRange_eq_iff]
theorem IsMittagLeffler.toPreimages (h : F.IsMittagLeffler) : (F.toPreimages s).IsMittagLeffler :=
(isMittagLeffler_iff_subset_range_comp _).2 fun j => by
obtain ⟨j₁, g₁, f₁, -⟩ := IsCofilteredOrEmpty.cone_objs i j
obtain ⟨j₂, f₂, h₂⟩ := F.isMittagLeffler_iff_eventualRange.1 h j₁
refine ⟨j₂, f₂ ≫ f₁, fun j₃ f₃ => ?_⟩
rintro _ ⟨⟨x, hx⟩, rfl⟩
have : F.map f₂ x ∈ F.eventualRange j₁ := by
rw [h₂]
exact ⟨_, rfl⟩
obtain ⟨y, hy, h₃⟩ := h.subset_image_eventualRange F (f₃ ≫ f₂) this
refine ⟨⟨y, mem_iInter.2 fun g₂ => ?_⟩, Subtype.ext ?_⟩
· obtain ⟨j₄, f₄, h₄⟩ := IsCofilteredOrEmpty.cone_maps g₂ ((f₃ ≫ f₂) ≫ g₁)
obtain ⟨y, rfl⟩ := F.mem_eventualRange_iff.1 hy f₄
rw [← map_comp_apply] at h₃
rw [mem_preimage, ← map_comp_apply, h₄, ← Category.assoc, map_comp_apply, h₃,
← map_comp_apply]
apply mem_iInter.1 hx
· simp_rw [toPreimages_map, MapsTo.val_restrict_apply]
rw [← Category.assoc, map_comp_apply, h₃, map_comp_apply]
theorem isMittagLeffler_of_exists_finite_range
(h : ∀ j : J, ∃ (i : _) (f : i ⟶ j), (range <| F.map f).Finite) : F.IsMittagLeffler := by
intro j
obtain ⟨i, hi, hf⟩ := h j
obtain ⟨m, ⟨i, f, hm⟩, hmin⟩ := Finset.wellFoundedLT.wf.has_min
{ s : Finset (F.obj j) | ∃ (i : _) (f : i ⟶ j), ↑s = range (F.map f) }
⟨_, i, hi, hf.coe_toFinset⟩
refine ⟨i, f, fun k g =>
(directedOn_range.mp <| F.ranges_directed j).is_bot_of_is_min ⟨⟨i, f⟩, rfl⟩ ?_ _ ⟨⟨k, g⟩, rfl⟩⟩
rintro _ ⟨⟨k', g'⟩, rfl⟩ hl
refine (eq_of_le_of_not_lt hl ?_).ge
have := hmin _ ⟨k', g', (m.finite_toSet.subset <| hm.substr hl).coe_toFinset⟩
rwa [Finset.lt_iff_ssubset, ← Finset.coe_ssubset, Set.Finite.coe_toFinset, hm] at this
/-- The subfunctor of `F` obtained by restricting to the eventual range at each index. -/
@[simps]
def toEventualRanges : J ⥤ Type v where
obj j := F.eventualRange j
map f := (F.eventualRange_mapsTo f).restrict _ _ _
map_id i := by
#adaptation_note /--- nightly-2024-03-16: simp was
simp (config := { unfoldPartialApp := true }) only [MapsTo.restrict, Subtype.map, F.map_id] -/
simp only [MapsTo.restrict, Subtype.map_def, F.map_id]
ext
rfl
map_comp _ _ := by
#adaptation_note /-- nightly-2024-03-16: simp was
simp (config := { unfoldPartialApp := true }) only [MapsTo.restrict, Subtype.map, F.map_comp] -/
simp only [MapsTo.restrict, Subtype.map_def, F.map_comp]
rfl
instance toEventualRanges_finite [∀ j, Finite (F.obj j)] : ∀ j, Finite (F.toEventualRanges.obj j) :=
fun _ => Subtype.finite
/-- The sections of the functor `F : J ⥤ Type v` are in bijection with the sections of
`F.toEventualRanges`. -/
def toEventualRangesSectionsEquiv : F.toEventualRanges.sections ≃ F.sections where
toFun s := ⟨_, fun f => Subtype.coe_inj.2 <| s.prop f⟩
invFun s :=
⟨fun j => ⟨_, mem_iInter₂.2 fun i f => ⟨_, s.prop f⟩⟩, fun f => Subtype.ext <| s.prop f⟩
left_inv _ := by
ext
rfl
right_inv _ := by
ext
rfl
/-- If `F` satisfies the Mittag-Leffler condition, its restriction to eventual ranges is a
surjective functor. -/
theorem surjective_toEventualRanges (h : F.IsMittagLeffler) ⦃i j⦄ (f : i ⟶ j) :
(F.toEventualRanges.map f).Surjective := fun ⟨x, hx⟩ => by
obtain ⟨y, hy, rfl⟩ := h.subset_image_eventualRange F f hx
exact ⟨⟨y, hy⟩, rfl⟩
/-- If `F` is nonempty at each index and Mittag-Leffler, then so is `F.toEventualRanges`. -/
theorem toEventualRanges_nonempty (h : F.IsMittagLeffler) [∀ j : J, Nonempty (F.obj j)] (j : J) :
Nonempty (F.toEventualRanges.obj j) := by
let ⟨i, f, h⟩ := F.isMittagLeffler_iff_eventualRange.1 h j
rw [toEventualRanges_obj, h]
infer_instance
/-- If `F` has all arrows surjective, then it "factors through a poset". -/
theorem thin_diagram_of_surjective (Fsur : ∀ ⦃i j : J⦄ (f : i ⟶ j), (F.map f).Surjective) {i j}
(f g : i ⟶ j) : F.map f = F.map g :=
let ⟨k, φ, hφ⟩ := IsCofilteredOrEmpty.cone_maps f g
(Fsur φ).injective_comp_right <| by simp_rw [← types_comp, ← F.map_comp, hφ]
theorem toPreimages_nonempty_of_surjective [hFn : ∀ j : J, Nonempty (F.obj j)]
(Fsur : ∀ ⦃i j : J⦄ (f : i ⟶ j), (F.map f).Surjective) (hs : s.Nonempty) (j) :
Nonempty ((F.toPreimages s).obj j) := by
simp only [toPreimages_obj, nonempty_coe_sort, nonempty_iInter, mem_preimage]
obtain h | ⟨⟨ji⟩⟩ := isEmpty_or_nonempty (j ⟶ i)
· exact ⟨(hFn j).some, fun ji => h.elim ji⟩
· obtain ⟨y, ys⟩ := hs
obtain ⟨x, rfl⟩ := Fsur ji y
exact ⟨x, fun ji' => (F.thin_diagram_of_surjective Fsur ji' ji).symm ▸ ys⟩
theorem eval_section_injective_of_eventually_injective {j}
(Finj : ∀ (i) (f : i ⟶ j), (F.map f).Injective) (i) (f : i ⟶ j) :
(fun s : F.sections => s.val j).Injective := by
refine fun s₀ s₁ h => Subtype.ext <| funext fun k => ?_
obtain ⟨m, mi, mk, _⟩ := IsCofilteredOrEmpty.cone_objs i k
dsimp at h
rw [← s₀.prop (mi ≫ f), ← s₁.prop (mi ≫ f)] at h
rw [← s₀.prop mk, ← s₁.prop mk]
exact congr_arg _ (Finj m (mi ≫ f) h)
section FiniteCofilteredSystem
variable [∀ j : J, Nonempty (F.obj j)] [∀ j : J, Finite (F.obj j)]
(Fsur : ∀ ⦃i j : J⦄ (f : i ⟶ j), (F.map f).Surjective)
theorem eval_section_surjective_of_surjective (i : J) :
(fun s : F.sections => s.val i).Surjective := fun x => by
let s : Set (F.obj i) := {x}
haveI := F.toPreimages_nonempty_of_surjective s Fsur (singleton_nonempty x)
obtain ⟨sec, h⟩ := nonempty_sections_of_finite_cofiltered_system (F.toPreimages s)
refine ⟨⟨fun j => (sec j).val, fun jk => by simpa [Subtype.ext_iff] using h jk⟩, ?_⟩
· have := (sec i).prop
simp only [mem_iInter, mem_preimage, mem_singleton_iff] at this
have := this (𝟙 i)
rwa [map_id_apply] at this
theorem eventually_injective [Nonempty J] [Finite F.sections] :
∃ j, ∀ (i) (f : i ⟶ j), (F.map f).Injective := by
haveI : ∀ j, Fintype (F.obj j) := fun j => Fintype.ofFinite (F.obj j)
haveI : Fintype F.sections := Fintype.ofFinite F.sections
have card_le : ∀ j, Fintype.card (F.obj j) ≤ Fintype.card F.sections :=
fun j => Fintype.card_le_of_surjective _ (F.eval_section_surjective_of_surjective Fsur j)
let fn j := Fintype.card F.sections - Fintype.card (F.obj j)
refine ⟨fn.argmin Nat.lt_wfRel.wf,
fun i f => ((Fintype.bijective_iff_surjective_and_card _).2
⟨Fsur f, le_antisymm ?_ (Fintype.card_le_of_surjective _ <| Fsur f)⟩).1⟩
rw [← Nat.sub_sub_self (card_le i), tsub_le_iff_tsub_le]
apply fn.argmin_le
end FiniteCofilteredSystem
end Functor
end CategoryTheory
|
CategoryTheory\CommSq.lean | /-
Copyright (c) 2022 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Joël Riou
-/
import Mathlib.CategoryTheory.Comma.Arrow
/-!
# Commutative squares
This file provide an API for commutative squares in categories.
If `top`, `left`, `right` and `bottom` are four morphisms which are the edges
of a square, `CommSq top left right bottom` is the predicate that this
square is commutative.
The structure `CommSq` is extended in `CategoryTheory/Shapes/Limits/CommSq.lean`
as `IsPullback` and `IsPushout` in order to define pullback and pushout squares.
## Future work
Refactor `LiftStruct` from `Arrow.lean` and lifting properties using `CommSq.lean`.
-/
namespace CategoryTheory
variable {C : Type*} [Category C]
/-- The proposition that a square
```
W ---f---> X
| |
g h
| |
v v
Y ---i---> Z
```
is a commuting square.
-/
structure CommSq {W X Y Z : C} (f : W ⟶ X) (g : W ⟶ Y) (h : X ⟶ Z) (i : Y ⟶ Z) : Prop where
/-- The square commutes. -/
w : f ≫ h = g ≫ i
attribute [reassoc] CommSq.w
namespace CommSq
variable {W X Y Z : C} {f : W ⟶ X} {g : W ⟶ Y} {h : X ⟶ Z} {i : Y ⟶ Z}
theorem flip (p : CommSq f g h i) : CommSq g f i h :=
⟨p.w.symm⟩
theorem of_arrow {f g : Arrow C} (h : f ⟶ g) : CommSq f.hom h.left h.right g.hom :=
⟨h.w.symm⟩
/-- The commutative square in the opposite category associated to a commutative square. -/
theorem op (p : CommSq f g h i) : CommSq i.op h.op g.op f.op :=
⟨by simp only [← op_comp, p.w]⟩
/-- The commutative square associated to a commutative square in the opposite category. -/
theorem unop {W X Y Z : Cᵒᵖ} {f : W ⟶ X} {g : W ⟶ Y} {h : X ⟶ Z} {i : Y ⟶ Z} (p : CommSq f g h i) :
CommSq i.unop h.unop g.unop f.unop :=
⟨by simp only [← unop_comp, p.w]⟩
theorem vert_inv {g : W ≅ Y} {h : X ≅ Z} (p : CommSq f g.hom h.hom i) :
CommSq i g.inv h.inv f :=
⟨by rw [Iso.comp_inv_eq, Category.assoc, Iso.eq_inv_comp, p.w]⟩
theorem horiz_inv {f : W ≅ X} {i : Y ≅ Z} (p : CommSq f.hom g h i.hom) :
CommSq f.inv h g i.inv :=
flip (vert_inv (flip p))
/-- The horizontal composition of two commutative squares as below is a commutative square.
```
W ---f---> X ---f'--> X'
| | |
g h h'
| | |
v v v
Y ---i---> Z ---i'--> Z'
```
-/
lemma horiz_comp {W X X' Y Z Z' : C} {f : W ⟶ X} {f' : X ⟶ X'} {g : W ⟶ Y} {h : X ⟶ Z}
{h' : X' ⟶ Z'} {i : Y ⟶ Z} {i' : Z ⟶ Z'} (hsq₁ : CommSq f g h i) (hsq₂ : CommSq f' h h' i') :
CommSq (f ≫ f') g h' (i ≫ i') :=
⟨by rw [← Category.assoc, Category.assoc, ← hsq₁.w, hsq₂.w, Category.assoc]⟩
/-- The vertical composition of two commutative squares as below is a commutative square.
```
W ---f---> X
| |
g h
| |
v v
Y ---i---> Z
| |
g' h'
| |
v v
Y'---i'--> Z'
```
-/
lemma vert_comp {W X Y Y' Z Z' : C} {f : W ⟶ X} {g : W ⟶ Y} {g' : Y ⟶ Y'} {h : X ⟶ Z}
{h' : Z ⟶ Z'} {i : Y ⟶ Z} {i' : Y' ⟶ Z'} (hsq₁ : CommSq f g h i) (hsq₂ : CommSq i g' h' i') :
CommSq f (g ≫ g') (h ≫ h') i' :=
flip (horiz_comp (flip hsq₁) (flip hsq₂))
end CommSq
namespace Functor
variable {D : Type*} [Category D]
variable (F : C ⥤ D) {W X Y Z : C} {f : W ⟶ X} {g : W ⟶ Y} {h : X ⟶ Z} {i : Y ⟶ Z}
theorem map_commSq (s : CommSq f g h i) : CommSq (F.map f) (F.map g) (F.map h) (F.map i) :=
⟨by simpa using congr_arg (fun k : W ⟶ Z => F.map k) s.w⟩
end Functor
alias CommSq.map := Functor.map_commSq
namespace CommSq
variable {A B X Y : C} {f : A ⟶ X} {i : A ⟶ B} {p : X ⟶ Y} {g : B ⟶ Y}
/-- Now we consider a square:
```
A ---f---> X
| |
i p
| |
v v
B ---g---> Y
```
The datum of a lift in a commutative square, i.e. an up-right-diagonal
morphism which makes both triangles commute. -/
-- porting note (#5171): removed @[nolint has_nonempty_instance]
@[ext]
structure LiftStruct (sq : CommSq f i p g) where
/-- The lift. -/
l : B ⟶ X
/-- The upper left triangle commutes. -/
fac_left : i ≫ l = f
/-- The lower right triangle commutes. -/
fac_right : l ≫ p = g
namespace LiftStruct
/-- A `LiftStruct` for a commutative square gives a `LiftStruct` for the
corresponding square in the opposite category. -/
@[simps]
def op {sq : CommSq f i p g} (l : LiftStruct sq) : LiftStruct sq.op where
l := l.l.op
fac_left := by rw [← op_comp, l.fac_right]
fac_right := by rw [← op_comp, l.fac_left]
/-- A `LiftStruct` for a commutative square in the opposite category
gives a `LiftStruct` for the corresponding square in the original category. -/
@[simps]
def unop {A B X Y : Cᵒᵖ} {f : A ⟶ X} {i : A ⟶ B} {p : X ⟶ Y} {g : B ⟶ Y} {sq : CommSq f i p g}
(l : LiftStruct sq) : LiftStruct sq.unop where
l := l.l.unop
fac_left := by rw [← unop_comp, l.fac_right]
fac_right := by rw [← unop_comp, l.fac_left]
/-- Equivalences of `LiftStruct` for a square and the corresponding square
in the opposite category. -/
@[simps]
def opEquiv (sq : CommSq f i p g) : LiftStruct sq ≃ LiftStruct sq.op where
toFun := op
invFun := unop
left_inv := by aesop_cat
right_inv := by aesop_cat
/-- Equivalences of `LiftStruct` for a square in the oppositive category and
the corresponding square in the original category. -/
def unopEquiv {A B X Y : Cᵒᵖ} {f : A ⟶ X} {i : A ⟶ B} {p : X ⟶ Y} {g : B ⟶ Y}
(sq : CommSq f i p g) : LiftStruct sq ≃ LiftStruct sq.unop where
toFun := unop
invFun := op
left_inv := by aesop_cat
right_inv := by aesop_cat
end LiftStruct
instance subsingleton_liftStruct_of_epi (sq : CommSq f i p g) [Epi i] :
Subsingleton (LiftStruct sq) :=
⟨fun l₁ l₂ => by
ext
rw [← cancel_epi i]
simp only [LiftStruct.fac_left]⟩
instance subsingleton_liftStruct_of_mono (sq : CommSq f i p g) [Mono p] :
Subsingleton (LiftStruct sq) :=
⟨fun l₁ l₂ => by
ext
rw [← cancel_mono p]
simp only [LiftStruct.fac_right]⟩
variable (sq : CommSq f i p g)
/-- The assertion that a square has a `LiftStruct`. -/
class HasLift : Prop where
/-- Square has a `LiftStruct`. -/
exists_lift : Nonempty sq.LiftStruct
namespace HasLift
variable {sq}
theorem mk' (l : sq.LiftStruct) : HasLift sq :=
⟨Nonempty.intro l⟩
variable (sq)
theorem iff : HasLift sq ↔ Nonempty sq.LiftStruct := by
constructor
exacts [fun h => h.exists_lift, fun h => mk h]
theorem iff_op : HasLift sq ↔ HasLift sq.op := by
rw [iff, iff]
exact Nonempty.congr (LiftStruct.opEquiv sq).toFun (LiftStruct.opEquiv sq).invFun
theorem iff_unop {A B X Y : Cᵒᵖ} {f : A ⟶ X} {i : A ⟶ B} {p : X ⟶ Y} {g : B ⟶ Y}
(sq : CommSq f i p g) : HasLift sq ↔ HasLift sq.unop := by
rw [iff, iff]
exact Nonempty.congr (LiftStruct.unopEquiv sq).toFun (LiftStruct.unopEquiv sq).invFun
end HasLift
/-- A choice of a diagonal morphism that is part of a `LiftStruct` when
the square has a lift. -/
noncomputable def lift [hsq : HasLift sq] : B ⟶ X :=
hsq.exists_lift.some.l
@[reassoc (attr := simp)]
theorem fac_left [hsq : HasLift sq] : i ≫ sq.lift = f :=
hsq.exists_lift.some.fac_left
@[reassoc (attr := simp)]
theorem fac_right [hsq : HasLift sq] : sq.lift ≫ p = g :=
hsq.exists_lift.some.fac_right
end CommSq
end CategoryTheory
|
CategoryTheory\ComposableArrows.lean | /-
Copyright (c) 2023 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.CategoryTheory.Category.Preorder
import Mathlib.CategoryTheory.EqToHom
import Mathlib.CategoryTheory.Functor.Const
import Mathlib.Order.Fin.Basic
import Mathlib.Tactic.FinCases
/-!
# Composable arrows
If `C` is a category, the type of `n`-simplices in the nerve of `C` identifies
to the type of functors `Fin (n + 1) ⥤ C`, which can be thought as families of `n` composable
arrows in `C`. In this file, we introduce and study this category `ComposableArrows C n`
of `n` composable arrows in `C`.
If `F : ComposableArrows C n`, we define `F.left` as the leftmost object, `F.right` as the
rightmost object, and `F.hom : F.left ⟶ F.right` is the canonical map.
The most significant definition in this file is the constructor
`F.precomp f : ComposableArrows C (n + 1)` for `F : ComposableArrows C n` and `f : X ⟶ F.left`:
"it shifts `F` towards the right and inserts `f` on the left". This `precomp` has
good definitional properties.
In the namespace `CategoryTheory.ComposableArrows`, we provide constructors
like `mk₁ f`, `mk₂ f g`, `mk₃ f g h` for `ComposableArrows C n` for small `n`.
TODO (@joelriou):
* redefine `Arrow C` as `ComposableArrow C 1`?
* construct some elements in `ComposableArrows m (Fin (n + 1))` for small `n`
the precomposition with which shall induce functors
`ComposableArrows C n ⥤ ComposableArrows C m` which correspond to simplicial operations
(specifically faces) with good definitional properties (this might be necessary for
up to `n = 7` in order to formalize spectral sequences following Verdier)
-/
/-!
New `simprocs` that run even in `dsimp` have caused breakages in this file.
(e.g. `dsimp` can now simplify `2 + 3` to `5`)
For now, we just turn off simprocs in this file.
We'll soon provide finer grained options here, e.g. to turn off simprocs only in `dsimp`, etc.
*However*, hopefully it is possible to refactor the material here so that no backwards compatibility
`set_option`s are required at all
-/
set_option simprocs false
namespace CategoryTheory
open Category
variable (C : Type*) [Category C]
/-- `ComposableArrows C n` is the type of functors `Fin (n + 1) ⥤ C`. -/
abbrev ComposableArrows (n : ℕ) := Fin (n + 1) ⥤ C
namespace ComposableArrows
variable {C} {n m : ℕ}
variable (F G : ComposableArrows C n)
/-- A wrapper for `omega` which prefaces it with some quick and useful attempts -/
macro "valid" : tactic =>
`(tactic| first | assumption | apply zero_le | apply le_rfl | transitivity <;> assumption | omega)
/-- The `i`th object (with `i : ℕ` such that `i ≤ n`) of `F : ComposableArrows C n`. -/
@[simp]
abbrev obj' (i : ℕ) (hi : i ≤ n := by valid) : C := F.obj ⟨i, by omega⟩
/-- The map `F.obj' i ⟶ F.obj' j` when `F : ComposableArrows C n`, and `i` and `j`
are natural numbers such that `i ≤ j ≤ n`. -/
@[simp]
abbrev map' (i j : ℕ) (hij : i ≤ j := by valid) (hjn : j ≤ n := by valid) :
F.obj ⟨i, by omega⟩ ⟶ F.obj ⟨j, by omega⟩ := F.map (homOfLE (by
simp only [Fin.mk_le_mk]
valid))
lemma map'_self (i : ℕ) (hi : i ≤ n := by valid) :
F.map' i i = 𝟙 _ := F.map_id _
lemma map'_comp (i j k : ℕ) (hij : i ≤ j := by valid)
(hjk : j ≤ k := by valid) (hk : k ≤ n := by valid) :
F.map' i k = F.map' i j ≫ F.map' j k :=
F.map_comp _ _
/-- The leftmost object of `F : ComposableArrows C n`. -/
abbrev left := obj' F 0
/-- The rightmost object of `F : ComposableArrows C n`. -/
abbrev right := obj' F n
/-- The canonical map `F.left ⟶ F.right` for `F : ComposableArrows C n`. -/
abbrev hom : F.left ⟶ F.right := map' F 0 n
variable {F G}
/-- The map `F.obj' i ⟶ G.obj' i` induced on `i`th objects by a morphism `F ⟶ G`
in `ComposableArrows C n` when `i` is a natural number such that `i ≤ n`. -/
@[simp]
abbrev app' (φ : F ⟶ G) (i : ℕ) (hi : i ≤ n := by valid) :
F.obj' i ⟶ G.obj' i := φ.app _
@[reassoc]
lemma naturality' (φ : F ⟶ G) (i j : ℕ) (hij : i ≤ j := by valid)
(hj : j ≤ n := by valid) :
F.map' i j ≫ app' φ j = app' φ i ≫ G.map' i j :=
φ.naturality _
/-- Constructor for `ComposableArrows C 0`. -/
@[simps!]
def mk₀ (X : C) : ComposableArrows C 0 := (Functor.const (Fin 1)).obj X
namespace Mk₁
variable (X₀ X₁ : C)
/-- The map which sends `0 : Fin 2` to `X₀` and `1` to `X₁`. -/
@[simp]
def obj : Fin 2 → C
| ⟨0, _⟩ => X₀
| ⟨1, _⟩ => X₁
variable {X₀ X₁}
variable (f : X₀ ⟶ X₁)
/-- The obvious map `obj X₀ X₁ i ⟶ obj X₀ X₁ j` whenever `i j : Fin 2` satisfy `i ≤ j`. -/
@[simp]
def map : ∀ (i j : Fin 2) (_ : i ≤ j), obj X₀ X₁ i ⟶ obj X₀ X₁ j
| ⟨0, _⟩, ⟨0, _⟩, _ => 𝟙 _
| ⟨0, _⟩, ⟨1, _⟩, _ => f
| ⟨1, _⟩, ⟨1, _⟩, _ => 𝟙 _
lemma map_id (i : Fin 2) : map f i i (by simp) = 𝟙 _ :=
match i with
| 0 => rfl
| 1 => rfl
lemma map_comp {i j k : Fin 2} (hij : i ≤ j) (hjk : j ≤ k) :
map f i k (hij.trans hjk) = map f i j hij ≫ map f j k hjk :=
match i with
| 0 =>
match j with
| 0 => by rw [map_id, id_comp]
| 1 => by
obtain rfl : k = 1 := k.eq_one_of_neq_zero (by rintro rfl; simp at hjk)
rw [map_id, comp_id]
| 1 => by
obtain rfl := j.eq_one_of_neq_zero (by rintro rfl; simp at hij)
obtain rfl := k.eq_one_of_neq_zero (by rintro rfl; simp at hjk)
rw [map_id, id_comp]
end Mk₁
/-- Constructor for `ComposableArrows C 1`. -/
@[simps]
def mk₁ {X₀ X₁ : C} (f : X₀ ⟶ X₁) : ComposableArrows C 1 where
obj := Mk₁.obj X₀ X₁
map g := Mk₁.map f _ _ (leOfHom g)
map_id := Mk₁.map_id f
map_comp g g' := Mk₁.map_comp f (leOfHom g) (leOfHom g')
/-- Constructor for morphisms `F ⟶ G` in `ComposableArrows C n` which takes as inputs
a family of morphisms `F.obj i ⟶ G.obj i` and the naturality condition only for the
maps in `Fin (n + 1)` given by inequalities of the form `i ≤ i + 1`. -/
@[simps]
def homMk {F G : ComposableArrows C n} (app : ∀ i, F.obj i ⟶ G.obj i)
(w : ∀ (i : ℕ) (hi : i < n), F.map' i (i + 1) ≫ app _ = app _ ≫ G.map' i (i + 1)) :
F ⟶ G where
app := app
naturality := by
suffices ∀ (k i j : ℕ) (hj : i + k = j) (hj' : j ≤ n),
F.map' i j ≫ app _ = app _ ≫ G.map' i j by
rintro ⟨i, hi⟩ ⟨j, hj⟩ hij
have hij' := leOfHom hij
simp only [Fin.mk_le_mk] at hij'
obtain ⟨k, hk⟩ := Nat.le.dest hij'
exact this k i j hk (by valid)
intro k
induction' k with k hk
· intro i j hj hj'
simp only [Nat.zero_eq, add_zero] at hj
obtain rfl := hj
rw [F.map'_self i, G.map'_self i, id_comp, comp_id]
· intro i j hj hj'
rw [← add_assoc] at hj
subst hj
rw [F.map'_comp i (i + k) (i + k + 1), G.map'_comp i (i + k) (i + k + 1), assoc,
w (i + k) (by valid), reassoc_of% (hk i (i + k) rfl (by valid))]
/-- Constructor for isomorphisms `F ≅ G` in `ComposableArrows C n` which takes as inputs
a family of isomorphisms `F.obj i ≅ G.obj i` and the naturality condition only for the
maps in `Fin (n + 1)` given by inequalities of the form `i ≤ i + 1`. -/
@[simps]
def isoMk {F G : ComposableArrows C n} (app : ∀ i, F.obj i ≅ G.obj i)
(w : ∀ (i : ℕ) (hi : i < n),
F.map' i (i + 1) ≫ (app _).hom = (app _).hom ≫ G.map' i (i + 1)) :
F ≅ G where
hom := homMk (fun i => (app i).hom) w
inv := homMk (fun i => (app i).inv) (fun i hi => by
dsimp only
rw [← cancel_epi ((app _).hom), ← reassoc_of% (w i hi), Iso.hom_inv_id, comp_id,
Iso.hom_inv_id_assoc])
lemma ext {F G : ComposableArrows C n} (h : ∀ i, F.obj i = G.obj i)
(w : ∀ (i : ℕ) (hi : i < n), F.map' i (i + 1) =
eqToHom (h _) ≫ G.map' i (i + 1) ≫ eqToHom (h _).symm) : F = G :=
Functor.ext_of_iso
(isoMk (fun i => eqToIso (h i)) (fun i hi => by simp [w i hi])) h (fun i => rfl)
/-- Constructor for morphisms in `ComposableArrows C 0`. -/
@[simps!]
def homMk₀ {F G : ComposableArrows C 0} (f : F.obj' 0 ⟶ G.obj' 0) : F ⟶ G :=
homMk (fun i => match i with
| ⟨0, _⟩ => f) (fun i hi => by simp at hi)
@[ext]
lemma hom_ext₀ {F G : ComposableArrows C 0} {φ φ' : F ⟶ G}
(h : app' φ 0 = app' φ' 0) :
φ = φ' := by
ext i
fin_cases i
exact h
/-- Constructor for isomorphisms in `ComposableArrows C 0`. -/
@[simps!]
def isoMk₀ {F G : ComposableArrows C 0} (e : F.obj' 0 ≅ G.obj' 0) : F ≅ G where
hom := homMk₀ e.hom
inv := homMk₀ e.inv
lemma ext₀ {F G : ComposableArrows C 0} (h : F.obj' 0 = G.obj 0) : F = G :=
ext (fun i => match i with
| ⟨0, _⟩ => h) (fun i hi => by simp at hi)
lemma mk₀_surjective (F : ComposableArrows C 0) : ∃ (X : C), F = mk₀ X :=
⟨F.obj' 0, ext₀ rfl⟩
/-- Constructor for morphisms in `ComposableArrows C 1`. -/
@[simps!]
def homMk₁ {F G : ComposableArrows C 1}
(left : F.obj' 0 ⟶ G.obj' 0) (right : F.obj' 1 ⟶ G.obj' 1)
(w : F.map' 0 1 ≫ right = left ≫ G.map' 0 1 := by aesop_cat) :
F ⟶ G :=
homMk (fun i => match i with
| ⟨0, _⟩ => left
| ⟨1, _⟩ => right) (by
intro i hi
obtain rfl : i = 0 := by simpa using hi
exact w)
@[ext]
lemma hom_ext₁ {F G : ComposableArrows C 1} {φ φ' : F ⟶ G}
(h₀ : app' φ 0 = app' φ' 0) (h₁ : app' φ 1 = app' φ' 1) :
φ = φ' := by
ext i
match i with
| 0 => exact h₀
| 1 => exact h₁
/-- Constructor for isomorphisms in `ComposableArrows C 1`. -/
@[simps!]
def isoMk₁ {F G : ComposableArrows C 1}
(left : F.obj' 0 ≅ G.obj' 0) (right : F.obj' 1 ≅ G.obj' 1)
(w : F.map' 0 1 ≫ right.hom = left.hom ≫ G.map' 0 1 := by aesop_cat) :
F ≅ G where
hom := homMk₁ left.hom right.hom w
inv := homMk₁ left.inv right.inv (by
rw [← cancel_mono right.hom, assoc, assoc, w, right.inv_hom_id, left.inv_hom_id_assoc]
apply comp_id)
lemma map'_eq_hom₁ (F : ComposableArrows C 1) : F.map' 0 1 = F.hom := rfl
lemma ext₁ {F G : ComposableArrows C 1}
(left : F.left = G.left) (right : F.right = G.right)
(w : F.hom = eqToHom left ≫ G.hom ≫ eqToHom right.symm) : F = G :=
Functor.ext_of_iso (isoMk₁ (eqToIso left) (eqToIso right) (by simp [map'_eq_hom₁, w]))
(fun i => by fin_cases i <;> assumption)
(fun i => by fin_cases i <;> rfl)
lemma mk₁_surjective (X : ComposableArrows C 1) : ∃ (X₀ X₁ : C) (f : X₀ ⟶ X₁), X = mk₁ f :=
⟨_, _, X.map' 0 1, ext₁ rfl rfl (by simp)⟩
variable (F)
namespace Precomp
variable (X : C)
/-- The map `Fin (n + 1 + 1) → C` which "shifts" `F.obj'` to the right and inserts `X` in
the zeroth position. -/
def obj : Fin (n + 1 + 1) → C
| ⟨0, _⟩ => X
| ⟨i + 1, hi⟩ => F.obj' i
@[simp]
lemma obj_zero : obj F X 0 = X := rfl
@[simp]
lemma obj_one : obj F X 1 = F.obj' 0 := rfl
@[simp]
lemma obj_succ (i : ℕ) (hi : i + 1 < n + 1 + 1) : obj F X ⟨i + 1, hi⟩ = F.obj' i := rfl
variable {X} (f : X ⟶ F.left)
/-- Auxiliary definition for the action on maps of the functor `F.precomp f`.
It sends `0 ≤ 1` to `f` and `i + 1 ≤ j + 1` to `F.map' i j`. -/
def map : ∀ (i j : Fin (n + 1 + 1)) (_ : i ≤ j), obj F X i ⟶ obj F X j
| ⟨0, _⟩, ⟨0, _⟩, _ => 𝟙 X
| ⟨0, _⟩, ⟨1, _⟩, _ => f
| ⟨0, _⟩, ⟨j + 2, hj⟩, _ => f ≫ F.map' 0 (j + 1)
| ⟨i + 1, hi⟩, ⟨j + 1, hj⟩, hij => F.map' i j (by simpa using hij)
@[simp]
lemma map_zero_zero : map F f 0 0 (by simp) = 𝟙 X := rfl
@[simp]
lemma map_one_one : map F f 1 1 (by simp) = F.map (𝟙 _) := rfl
@[simp]
lemma map_zero_one : map F f 0 1 (by simp) = f := rfl
@[simp]
lemma map_zero_one' : map F f 0 ⟨0 + 1, by simp⟩ (by simp) = f := rfl
@[simp]
lemma map_zero_succ_succ (j : ℕ) (hj : j + 2 < n + 1 + 1) :
map F f 0 ⟨j + 2, hj⟩ (by simp) = f ≫ F.map' 0 (j+1) := rfl
@[simp]
lemma map_succ_succ (i j : ℕ) (hi : i + 1 < n + 1 + 1) (hj : j + 1 < n + 1 + 1)
(hij : i + 1 ≤ j + 1) :
map F f ⟨i + 1, hi⟩ ⟨j + 1, hj⟩ hij = F.map' i j := rfl
@[simp]
lemma map_one_succ (j : ℕ) (hj : j + 1 < n + 1 + 1) :
map F f 1 ⟨j + 1, hj⟩ (by simp [Fin.le_def]) = F.map' 0 j := rfl
lemma map_id (i : Fin (n + 1 + 1)) : map F f i i (by simp) = 𝟙 _ := by
obtain ⟨i, hi⟩ := i
cases i
· rfl
· apply F.map_id
lemma map_comp {i j k : Fin (n + 1 + 1)} (hij : i ≤ j) (hjk : j ≤ k) :
map F f i k (hij.trans hjk) = map F f i j hij ≫ map F f j k hjk := by
obtain ⟨i, hi⟩ := i
obtain ⟨j, hj⟩ := j
obtain ⟨k, hk⟩ := k
cases i
· obtain _ | _ | j := j
· dsimp
rw [id_comp]
· obtain _ | _ | k := k
· simp [Nat.succ.injEq] at hjk
· simp
· rfl
· obtain _ | _ | k := k
· simp [Fin.ext_iff] at hjk
· simp [Fin.le_def] at hjk
omega
· dsimp
rw [assoc, ← F.map_comp, homOfLE_comp]
· obtain _ | j := j
· simp [Fin.ext_iff] at hij
· obtain _ | k := k
· simp [Fin.ext_iff] at hjk
· dsimp
rw [← F.map_comp, homOfLE_comp]
end Precomp
/-- "Precomposition" of `F : ComposableArrows C n` by a morphism `f : X ⟶ F.left`. -/
@[simps]
def precomp {X : C} (f : X ⟶ F.left) : ComposableArrows C (n + 1) where
obj := Precomp.obj F X
map g := Precomp.map F f _ _ (leOfHom g)
map_id := Precomp.map_id F f
map_comp g g' := Precomp.map_comp F f (leOfHom g) (leOfHom g')
/-- Constructor for `ComposableArrows C 2`. -/
@[simp]
def mk₂ {X₀ X₁ X₂ : C} (f : X₀ ⟶ X₁) (g : X₁ ⟶ X₂) : ComposableArrows C 2 :=
(mk₁ g).precomp f
/-- Constructor for `ComposableArrows C 3`. -/
@[simp]
def mk₃ {X₀ X₁ X₂ X₃ : C} (f : X₀ ⟶ X₁) (g : X₁ ⟶ X₂) (h : X₂ ⟶ X₃) : ComposableArrows C 3 :=
(mk₂ g h).precomp f
/-- Constructor for `ComposableArrows C 4`. -/
@[simp]
def mk₄ {X₀ X₁ X₂ X₃ X₄ : C} (f : X₀ ⟶ X₁) (g : X₁ ⟶ X₂) (h : X₂ ⟶ X₃) (i : X₃ ⟶ X₄) :
ComposableArrows C 4 :=
(mk₃ g h i).precomp f
/-- Constructor for `ComposableArrows C 5`. -/
@[simp]
def mk₅ {X₀ X₁ X₂ X₃ X₄ X₅ : C} (f : X₀ ⟶ X₁) (g : X₁ ⟶ X₂) (h : X₂ ⟶ X₃)
(i : X₃ ⟶ X₄) (j : X₄ ⟶ X₅) :
ComposableArrows C 5 :=
(mk₄ g h i j).precomp f
section
variable {X₀ X₁ X₂ X₃ X₄ : C} (f : X₀ ⟶ X₁) (g : X₁ ⟶ X₂) (h : X₂ ⟶ X₃) (i : X₃ ⟶ X₄)
/-! These examples are meant to test the good definitional properties of `precomp`,
and that `dsimp` can see through. -/
example : map' (mk₂ f g) 0 1 = f := by dsimp
example : map' (mk₂ f g) 1 2 = g := by dsimp
example : map' (mk₂ f g) 0 2 = f ≫ g := by dsimp
example : (mk₂ f g).hom = f ≫ g := by dsimp
example : map' (mk₂ f g) 0 0 = 𝟙 _ := by dsimp
example : map' (mk₂ f g) 1 1 = 𝟙 _ := by dsimp
example : map' (mk₂ f g) 2 2 = 𝟙 _ := by dsimp
example : map' (mk₃ f g h) 0 1 = f := by dsimp
example : map' (mk₃ f g h) 1 2 = g := by dsimp
example : map' (mk₃ f g h) 2 3 = h := by dsimp
example : map' (mk₃ f g h) 0 3 = f ≫ g ≫ h := by dsimp
example : (mk₃ f g h).hom = f ≫ g ≫ h := by dsimp
example : map' (mk₃ f g h) 0 2 = f ≫ g := by dsimp
example : map' (mk₃ f g h) 1 3 = g ≫ h := by dsimp
end
/-- The map `ComposableArrows C m → ComposableArrows C n` obtained by precomposition with
a functor `Fin (n + 1) ⥤ Fin (m + 1)`. -/
@[simps!]
def whiskerLeft (F : ComposableArrows C m) (Φ : Fin (n + 1) ⥤ Fin (m + 1)) :
ComposableArrows C n := Φ ⋙ F
/-- The functor `ComposableArrows C m ⥤ ComposableArrows C n` obtained by precomposition with
a functor `Fin (n + 1) ⥤ Fin (m + 1)`. -/
@[simps!]
def whiskerLeftFunctor (Φ : Fin (n + 1) ⥤ Fin (m + 1)) :
ComposableArrows C m ⥤ ComposableArrows C n where
obj F := F.whiskerLeft Φ
map f := CategoryTheory.whiskerLeft Φ f
/-- The functor `Fin n ⥤ Fin (n + 1)` which sends `i` to `i.succ`. -/
@[simps]
def _root_.Fin.succFunctor (n : ℕ) : Fin n ⥤ Fin (n + 1) where
obj i := i.succ
map {i j} hij := homOfLE (Fin.succ_le_succ_iff.2 (leOfHom hij))
/-- The functor `ComposableArrows C (n + 1) ⥤ ComposableArrows C n` which forgets
the first arrow. -/
@[simps!]
def δ₀Functor : ComposableArrows C (n + 1) ⥤ ComposableArrows C n :=
whiskerLeftFunctor (Fin.succFunctor (n + 1))
/-- The `ComposableArrows C n` obtained by forgetting the first arrow. -/
abbrev δ₀ (F : ComposableArrows C (n + 1)) := δ₀Functor.obj F
@[simp]
lemma precomp_δ₀ {X : C} (f : X ⟶ F.left) : (F.precomp f).δ₀ = F := rfl
/-- The functor `Fin n ⥤ Fin (n + 1)` which sends `i` to `i.castSucc`. -/
@[simps]
def _root_.Fin.castSuccFunctor (n : ℕ) : Fin n ⥤ Fin (n + 1) where
obj i := i.castSucc
map hij := hij
/-- The functor `ComposableArrows C (n + 1) ⥤ ComposableArrows C n` which forgets
the last arrow. -/
@[simps!]
def δlastFunctor : ComposableArrows C (n + 1) ⥤ ComposableArrows C n :=
whiskerLeftFunctor (Fin.castSuccFunctor (n + 1))
/-- The `ComposableArrows C n` obtained by forgetting the first arrow. -/
abbrev δlast (F : ComposableArrows C (n + 1)) := δlastFunctor.obj F
section
variable {F G : ComposableArrows C (n + 1)}
/-- Inductive construction of morphisms in `ComposableArrows C (n + 1)`: in order to construct
a morphism `F ⟶ G`, it suffices to provide `α : F.obj' 0 ⟶ G.obj' 0` and `β : F.δ₀ ⟶ G.δ₀`
such that `F.map' 0 1 ≫ app' β 0 = α ≫ G.map' 0 1`. -/
def homMkSucc (α : F.obj' 0 ⟶ G.obj' 0) (β : F.δ₀ ⟶ G.δ₀)
(w : F.map' 0 1 ≫ app' β 0 = α ≫ G.map' 0 1) : F ⟶ G :=
homMk
(fun i => match i with
| ⟨0, _⟩ => α
| ⟨i + 1, hi⟩ => app' β i)
(fun i hi => by
obtain _ | i := i
· exact w
· exact naturality' β i (i + 1))
variable (α : F.obj' 0 ⟶ G.obj' 0) (β : F.δ₀ ⟶ G.δ₀)
(w : F.map' 0 1 ≫ app' β 0 = α ≫ G.map' 0 1)
@[simp]
lemma homMkSucc_app_zero : (homMkSucc α β w).app 0 = α := rfl
@[simp]
lemma homMkSucc_app_succ (i : ℕ) (hi : i + 1 < n + 1 + 1) :
(homMkSucc α β w).app ⟨i + 1, hi⟩ = app' β i := rfl
end
lemma hom_ext_succ {F G : ComposableArrows C (n + 1)} {f g : F ⟶ G}
(h₀ : app' f 0 = app' g 0) (h₁ : δ₀Functor.map f = δ₀Functor.map g) : f = g := by
ext ⟨i, hi⟩
obtain _ | i := i
· exact h₀
· exact congr_app h₁ ⟨i, by valid⟩
/-- Inductive construction of isomorphisms in `ComposableArrows C (n + 1)`: in order to
construct an isomorphism `F ≅ G`, it suffices to provide `α : F.obj' 0 ≅ G.obj' 0` and
`β : F.δ₀ ≅ G.δ₀` such that `F.map' 0 1 ≫ app' β.hom 0 = α.hom ≫ G.map' 0 1`. -/
@[simps]
def isoMkSucc {F G : ComposableArrows C (n + 1)} (α : F.obj' 0 ≅ G.obj' 0)
(β : F.δ₀ ≅ G.δ₀) (w : F.map' 0 1 ≫ app' β.hom 0 = α.hom ≫ G.map' 0 1) : F ≅ G where
hom := homMkSucc α.hom β.hom w
inv := homMkSucc α.inv β.inv (by
rw [← cancel_epi α.hom, ← reassoc_of% w, α.hom_inv_id_assoc, β.hom_inv_id_app]
dsimp
rw [comp_id])
hom_inv_id := by
apply hom_ext_succ
· simp
· ext ⟨i, hi⟩
simp
inv_hom_id := by
apply hom_ext_succ
· simp
· ext ⟨i, hi⟩
simp
lemma ext_succ {F G : ComposableArrows C (n + 1)} (h₀ : F.obj' 0 = G.obj' 0)
(h : F.δ₀ = G.δ₀) (w : F.map' 0 1 = eqToHom h₀ ≫ G.map' 0 1 ≫
eqToHom (Functor.congr_obj h.symm 0)) : F = G := by
have : ∀ i, F.obj i = G.obj i := by
intro ⟨i, hi⟩
cases' i with i
· exact h₀
· exact Functor.congr_obj h ⟨i, by valid⟩
exact Functor.ext_of_iso (isoMkSucc (eqToIso h₀) (eqToIso h) (by
rw [w]
dsimp [app']
erw [eqToHom_app, assoc, assoc, eqToHom_trans, eqToHom_refl, comp_id])) this (by
rintro ⟨i, hi⟩
dsimp
cases' i with i
· erw [homMkSucc_app_zero]
· erw [homMkSucc_app_succ]
dsimp [app']
erw [eqToHom_app])
lemma precomp_surjective (F : ComposableArrows C (n + 1)) :
∃ (F₀ : ComposableArrows C n) (X₀ : C) (f₀ : X₀ ⟶ F₀.left), F = F₀.precomp f₀ :=
⟨F.δ₀, _, F.map' 0 1, ext_succ rfl (by simp) (by simp)⟩
section
variable
{f g : ComposableArrows C 2}
(app₀ : f.obj' 0 ⟶ g.obj' 0) (app₁ : f.obj' 1 ⟶ g.obj' 1) (app₂ : f.obj' 2 ⟶ g.obj' 2)
(w₀ : f.map' 0 1 ≫ app₁ = app₀ ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂ = app₁ ≫ g.map' 1 2)
/-- Constructor for morphisms in `ComposableArrows C 2`. -/
def homMk₂ : f ⟶ g := homMkSucc app₀ (homMk₁ app₁ app₂ w₁) w₀
@[simp]
lemma homMk₂_app_zero : (homMk₂ app₀ app₁ app₂ w₀ w₁).app 0 = app₀ := rfl
@[simp]
lemma homMk₂_app_one : (homMk₂ app₀ app₁ app₂ w₀ w₁).app 1 = app₁ := rfl
@[simp]
lemma homMk₂_app_two : (homMk₂ app₀ app₁ app₂ w₀ w₁).app ⟨2, by valid⟩ = app₂ := rfl
end
@[ext]
lemma hom_ext₂ {f g : ComposableArrows C 2} {φ φ' : f ⟶ g}
(h₀ : app' φ 0 = app' φ' 0) (h₁ : app' φ 1 = app' φ' 1) (h₂ : app' φ 2 = app' φ' 2) :
φ = φ' :=
hom_ext_succ h₀ (hom_ext₁ h₁ h₂)
/-- Constructor for isomorphisms in `ComposableArrows C 2`. -/
@[simps]
def isoMk₂ {f g : ComposableArrows C 2}
(app₀ : f.obj' 0 ≅ g.obj' 0) (app₁ : f.obj' 1 ≅ g.obj' 1) (app₂ : f.obj' 2 ≅ g.obj' 2)
(w₀ : f.map' 0 1 ≫ app₁.hom = app₀.hom ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂.hom = app₁.hom ≫ g.map' 1 2) : f ≅ g where
hom := homMk₂ app₀.hom app₁.hom app₂.hom w₀ w₁
inv := homMk₂ app₀.inv app₁.inv app₂.inv
(by rw [← cancel_epi app₀.hom, ← reassoc_of% w₀, app₁.hom_inv_id,
comp_id, app₀.hom_inv_id_assoc])
(by rw [← cancel_epi app₁.hom, ← reassoc_of% w₁, app₂.hom_inv_id,
comp_id, app₁.hom_inv_id_assoc])
lemma ext₂ {f g : ComposableArrows C 2}
(h₀ : f.obj' 0 = g.obj' 0) (h₁ : f.obj' 1 = g.obj' 1) (h₂ : f.obj' 2 = g.obj' 2)
(w₀ : f.map' 0 1 = eqToHom h₀ ≫ g.map' 0 1 ≫ eqToHom h₁.symm)
(w₁ : f.map' 1 2 = eqToHom h₁ ≫ g.map' 1 2 ≫ eqToHom h₂.symm) : f = g :=
ext_succ h₀ (ext₁ h₁ h₂ w₁) w₀
lemma mk₂_surjective (X : ComposableArrows C 2) :
∃ (X₀ X₁ X₂ : C) (f₀ : X₀ ⟶ X₁) (f₁ : X₁ ⟶ X₂), X = mk₂ f₀ f₁ :=
⟨_, _, _, X.map' 0 1, X.map' 1 2, ext₂ rfl rfl rfl (by simp) (by simp)⟩
section
variable
{f g : ComposableArrows C 3}
(app₀ : f.obj' 0 ⟶ g.obj' 0) (app₁ : f.obj' 1 ⟶ g.obj' 1) (app₂ : f.obj' 2 ⟶ g.obj' 2)
(app₃ : f.obj' 3 ⟶ g.obj' 3)
(w₀ : f.map' 0 1 ≫ app₁ = app₀ ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂ = app₁ ≫ g.map' 1 2)
(w₂ : f.map' 2 3 ≫ app₃ = app₂ ≫ g.map' 2 3)
/-- Constructor for morphisms in `ComposableArrows C 3`. -/
def homMk₃ : f ⟶ g := homMkSucc app₀ (homMk₂ app₁ app₂ app₃ w₁ w₂) w₀
@[simp]
lemma homMk₃_app_zero : (homMk₃ app₀ app₁ app₂ app₃ w₀ w₁ w₂).app 0 = app₀ := rfl
@[simp]
lemma homMk₃_app_one : (homMk₃ app₀ app₁ app₂ app₃ w₀ w₁ w₂).app 1 = app₁ := rfl
@[simp]
lemma homMk₃_app_two : (homMk₃ app₀ app₁ app₂ app₃ w₀ w₁ w₂).app ⟨2, by valid⟩ = app₂ :=
rfl
@[simp]
lemma homMk₃_app_three : (homMk₃ app₀ app₁ app₂ app₃ w₀ w₁ w₂).app ⟨3, by valid⟩ = app₃ :=
rfl
end
@[ext]
lemma hom_ext₃ {f g : ComposableArrows C 3} {φ φ' : f ⟶ g}
(h₀ : app' φ 0 = app' φ' 0) (h₁ : app' φ 1 = app' φ' 1) (h₂ : app' φ 2 = app' φ' 2)
(h₃ : app' φ 3 = app' φ' 3) :
φ = φ' :=
hom_ext_succ h₀ (hom_ext₂ h₁ h₂ h₃)
/-- Constructor for isomorphisms in `ComposableArrows C 3`. -/
@[simps]
def isoMk₃ {f g : ComposableArrows C 3}
(app₀ : f.obj' 0 ≅ g.obj' 0) (app₁ : f.obj' 1 ≅ g.obj' 1) (app₂ : f.obj' 2 ≅ g.obj' 2)
(app₃ : f.obj' 3 ≅ g.obj' 3)
(w₀ : f.map' 0 1 ≫ app₁.hom = app₀.hom ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂.hom = app₁.hom ≫ g.map' 1 2)
(w₂ : f.map' 2 3 ≫ app₃.hom = app₂.hom ≫ g.map' 2 3) : f ≅ g where
hom := homMk₃ app₀.hom app₁.hom app₂.hom app₃.hom w₀ w₁ w₂
inv := homMk₃ app₀.inv app₁.inv app₂.inv app₃.inv
(by rw [← cancel_epi app₀.hom, ← reassoc_of% w₀, app₁.hom_inv_id,
comp_id, app₀.hom_inv_id_assoc])
(by rw [← cancel_epi app₁.hom, ← reassoc_of% w₁, app₂.hom_inv_id,
comp_id, app₁.hom_inv_id_assoc])
(by rw [← cancel_epi app₂.hom, ← reassoc_of% w₂, app₃.hom_inv_id,
comp_id, app₂.hom_inv_id_assoc])
lemma ext₃ {f g : ComposableArrows C 3}
(h₀ : f.obj' 0 = g.obj' 0) (h₁ : f.obj' 1 = g.obj' 1) (h₂ : f.obj' 2 = g.obj' 2)
(h₃ : f.obj' 3 = g.obj' 3)
(w₀ : f.map' 0 1 = eqToHom h₀ ≫ g.map' 0 1 ≫ eqToHom h₁.symm)
(w₁ : f.map' 1 2 = eqToHom h₁ ≫ g.map' 1 2 ≫ eqToHom h₂.symm)
(w₂ : f.map' 2 3 = eqToHom h₂ ≫ g.map' 2 3 ≫ eqToHom h₃.symm) : f = g :=
ext_succ h₀ (ext₂ h₁ h₂ h₃ w₁ w₂) w₀
lemma mk₃_surjective (X : ComposableArrows C 3) :
∃ (X₀ X₁ X₂ X₃ : C) (f₀ : X₀ ⟶ X₁) (f₁ : X₁ ⟶ X₂) (f₂ : X₂ ⟶ X₃), X = mk₃ f₀ f₁ f₂ :=
⟨_, _, _, _, X.map' 0 1, X.map' 1 2, X.map' 2 3,
ext₃ rfl rfl rfl rfl (by simp) (by simp) (by simp)⟩
section
variable
{f g : ComposableArrows C 4}
(app₀ : f.obj' 0 ⟶ g.obj' 0) (app₁ : f.obj' 1 ⟶ g.obj' 1) (app₂ : f.obj' 2 ⟶ g.obj' 2)
(app₃ : f.obj' 3 ⟶ g.obj' 3) (app₄ : f.obj' 4 ⟶ g.obj' 4)
(w₀ : f.map' 0 1 ≫ app₁ = app₀ ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂ = app₁ ≫ g.map' 1 2)
(w₂ : f.map' 2 3 ≫ app₃ = app₂ ≫ g.map' 2 3)
(w₃ : f.map' 3 4 ≫ app₄ = app₃ ≫ g.map' 3 4)
/-- Constructor for morphisms in `ComposableArrows C 4`. -/
def homMk₄ : f ⟶ g := homMkSucc app₀ (homMk₃ app₁ app₂ app₃ app₄ w₁ w₂ w₃) w₀
@[simp]
lemma homMk₄_app_zero : (homMk₄ app₀ app₁ app₂ app₃ app₄ w₀ w₁ w₂ w₃).app 0 = app₀ := rfl
@[simp]
lemma homMk₄_app_one : (homMk₄ app₀ app₁ app₂ app₃ app₄ w₀ w₁ w₂ w₃).app 1 = app₁ := rfl
@[simp]
lemma homMk₄_app_two :
(homMk₄ app₀ app₁ app₂ app₃ app₄ w₀ w₁ w₂ w₃).app ⟨2, by valid⟩ = app₂ := rfl
@[simp]
lemma homMk₄_app_three :
(homMk₄ app₀ app₁ app₂ app₃ app₄ w₀ w₁ w₂ w₃).app ⟨3, by valid⟩ = app₃ := rfl
@[simp]
lemma homMk₄_app_four :
(homMk₄ app₀ app₁ app₂ app₃ app₄ w₀ w₁ w₂ w₃).app ⟨4, by valid⟩ = app₄ := rfl
end
@[ext]
lemma hom_ext₄ {f g : ComposableArrows C 4} {φ φ' : f ⟶ g}
(h₀ : app' φ 0 = app' φ' 0) (h₁ : app' φ 1 = app' φ' 1) (h₂ : app' φ 2 = app' φ' 2)
(h₃ : app' φ 3 = app' φ' 3) (h₄ : app' φ 4 = app' φ' 4) :
φ = φ' :=
hom_ext_succ h₀ (hom_ext₃ h₁ h₂ h₃ h₄)
lemma map'_inv_eq_inv_map' {n m : ℕ} (h : n+1 ≤ m) {f g : ComposableArrows C m}
(app : f.obj' n ≅ g.obj' n) (app' : f.obj' (n+1) ≅ g.obj' (n+1))
(w : f.map' n (n+1) ≫ app'.hom = app.hom ≫ g.map' n (n+1)) :
map' g n (n+1) ≫ app'.inv = app.inv ≫ map' f n (n+1) := by
rw [← cancel_epi app.hom, ← reassoc_of% w, app'.hom_inv_id, comp_id, app.hom_inv_id_assoc]
/-- Constructor for isomorphisms in `ComposableArrows C 4`. -/
@[simps]
def isoMk₄ {f g : ComposableArrows C 4}
(app₀ : f.obj' 0 ≅ g.obj' 0) (app₁ : f.obj' 1 ≅ g.obj' 1) (app₂ : f.obj' 2 ≅ g.obj' 2)
(app₃ : f.obj' 3 ≅ g.obj' 3) (app₄ : f.obj' 4 ≅ g.obj' 4)
(w₀ : f.map' 0 1 ≫ app₁.hom = app₀.hom ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂.hom = app₁.hom ≫ g.map' 1 2)
(w₂ : f.map' 2 3 ≫ app₃.hom = app₂.hom ≫ g.map' 2 3)
(w₃ : f.map' 3 4 ≫ app₄.hom = app₃.hom ≫ g.map' 3 4) :
f ≅ g where
hom := homMk₄ app₀.hom app₁.hom app₂.hom app₃.hom app₄.hom w₀ w₁ w₂ w₃
inv := homMk₄ app₀.inv app₁.inv app₂.inv app₃.inv app₄.inv
(by rw [map'_inv_eq_inv_map' (by valid) app₀ app₁ w₀])
(by rw [map'_inv_eq_inv_map' (by valid) app₁ app₂ w₁])
(by rw [map'_inv_eq_inv_map' (by valid) app₂ app₃ w₂])
(by rw [map'_inv_eq_inv_map' (by valid) app₃ app₄ w₃])
lemma ext₄ {f g : ComposableArrows C 4}
(h₀ : f.obj' 0 = g.obj' 0) (h₁ : f.obj' 1 = g.obj' 1) (h₂ : f.obj' 2 = g.obj' 2)
(h₃ : f.obj' 3 = g.obj' 3) (h₄ : f.obj' 4 = g.obj' 4)
(w₀ : f.map' 0 1 = eqToHom h₀ ≫ g.map' 0 1 ≫ eqToHom h₁.symm)
(w₁ : f.map' 1 2 = eqToHom h₁ ≫ g.map' 1 2 ≫ eqToHom h₂.symm)
(w₂ : f.map' 2 3 = eqToHom h₂ ≫ g.map' 2 3 ≫ eqToHom h₃.symm)
(w₃ : f.map' 3 4 = eqToHom h₃ ≫ g.map' 3 4 ≫ eqToHom h₄.symm) :
f = g :=
ext_succ h₀ (ext₃ h₁ h₂ h₃ h₄ w₁ w₂ w₃) w₀
lemma mk₄_surjective (X : ComposableArrows C 4) :
∃ (X₀ X₁ X₂ X₃ X₄ : C) (f₀ : X₀ ⟶ X₁) (f₁ : X₁ ⟶ X₂) (f₂ : X₂ ⟶ X₃) (f₃ : X₃ ⟶ X₄),
X = mk₄ f₀ f₁ f₂ f₃ :=
⟨_, _, _, _, _, X.map' 0 1, X.map' 1 2, X.map' 2 3, X.map' 3 4,
ext₄ rfl rfl rfl rfl rfl (by simp) (by simp) (by simp) (by simp)⟩
section
variable
{f g : ComposableArrows C 5}
(app₀ : f.obj' 0 ⟶ g.obj' 0) (app₁ : f.obj' 1 ⟶ g.obj' 1) (app₂ : f.obj' 2 ⟶ g.obj' 2)
(app₃ : f.obj' 3 ⟶ g.obj' 3) (app₄ : f.obj' 4 ⟶ g.obj' 4) (app₅ : f.obj' 5 ⟶ g.obj' 5)
(w₀ : f.map' 0 1 ≫ app₁ = app₀ ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂ = app₁ ≫ g.map' 1 2)
(w₂ : f.map' 2 3 ≫ app₃ = app₂ ≫ g.map' 2 3)
(w₃ : f.map' 3 4 ≫ app₄ = app₃ ≫ g.map' 3 4)
(w₄ : f.map' 4 5 ≫ app₅ = app₄ ≫ g.map' 4 5)
/-- Constructor for morphisms in `ComposableArrows C 5`. -/
def homMk₅ : f ⟶ g := homMkSucc app₀ (homMk₄ app₁ app₂ app₃ app₄ app₅ w₁ w₂ w₃ w₄) w₀
@[simp]
lemma homMk₅_app_zero : (homMk₅ app₀ app₁ app₂ app₃ app₄ app₅ w₀ w₁ w₂ w₃ w₄).app 0 = app₀ := rfl
@[simp]
lemma homMk₅_app_one : (homMk₅ app₀ app₁ app₂ app₃ app₄ app₅ w₀ w₁ w₂ w₃ w₄).app 1 = app₁ := rfl
@[simp]
lemma homMk₅_app_two :
(homMk₅ app₀ app₁ app₂ app₃ app₄ app₅ w₀ w₁ w₂ w₃ w₄).app ⟨2, by valid⟩ = app₂ := rfl
@[simp]
lemma homMk₅_app_three :
(homMk₅ app₀ app₁ app₂ app₃ app₄ app₅ w₀ w₁ w₂ w₃ w₄).app ⟨3, by valid⟩ = app₃ := rfl
@[simp]
lemma homMk₅_app_four :
(homMk₅ app₀ app₁ app₂ app₃ app₄ app₅ w₀ w₁ w₂ w₃ w₄).app ⟨4, by valid⟩ = app₄ := rfl
@[simp]
lemma homMk₅_app_five :
(homMk₅ app₀ app₁ app₂ app₃ app₄ app₅ w₀ w₁ w₂ w₃ w₄).app ⟨5, by valid⟩ = app₅ := rfl
end
@[ext]
lemma hom_ext₅ {f g : ComposableArrows C 5} {φ φ' : f ⟶ g}
(h₀ : app' φ 0 = app' φ' 0) (h₁ : app' φ 1 = app' φ' 1) (h₂ : app' φ 2 = app' φ' 2)
(h₃ : app' φ 3 = app' φ' 3) (h₄ : app' φ 4 = app' φ' 4) (h₅ : app' φ 5 = app' φ' 5) :
φ = φ' :=
hom_ext_succ h₀ (hom_ext₄ h₁ h₂ h₃ h₄ h₅)
/-- Constructor for isomorphisms in `ComposableArrows C 5`. -/
@[simps]
def isoMk₅ {f g : ComposableArrows C 5}
(app₀ : f.obj' 0 ≅ g.obj' 0) (app₁ : f.obj' 1 ≅ g.obj' 1) (app₂ : f.obj' 2 ≅ g.obj' 2)
(app₃ : f.obj' 3 ≅ g.obj' 3) (app₄ : f.obj' 4 ≅ g.obj' 4) (app₅ : f.obj' 5 ≅ g.obj' 5)
(w₀ : f.map' 0 1 ≫ app₁.hom = app₀.hom ≫ g.map' 0 1)
(w₁ : f.map' 1 2 ≫ app₂.hom = app₁.hom ≫ g.map' 1 2)
(w₂ : f.map' 2 3 ≫ app₃.hom = app₂.hom ≫ g.map' 2 3)
(w₃ : f.map' 3 4 ≫ app₄.hom = app₃.hom ≫ g.map' 3 4)
(w₄ : f.map' 4 5 ≫ app₅.hom = app₄.hom ≫ g.map' 4 5) :
f ≅ g where
hom := homMk₅ app₀.hom app₁.hom app₂.hom app₃.hom app₄.hom app₅.hom w₀ w₁ w₂ w₃ w₄
inv := homMk₅ app₀.inv app₁.inv app₂.inv app₃.inv app₄.inv app₅.inv
(by rw [map'_inv_eq_inv_map' (by valid) app₀ app₁ w₀])
(by rw [map'_inv_eq_inv_map' (by valid) app₁ app₂ w₁])
(by rw [map'_inv_eq_inv_map' (by valid) app₂ app₃ w₂])
(by rw [map'_inv_eq_inv_map' (by valid) app₃ app₄ w₃])
(by rw [map'_inv_eq_inv_map' (by valid) app₄ app₅ w₄])
lemma ext₅ {f g : ComposableArrows C 5}
(h₀ : f.obj' 0 = g.obj' 0) (h₁ : f.obj' 1 = g.obj' 1) (h₂ : f.obj' 2 = g.obj' 2)
(h₃ : f.obj' 3 = g.obj' 3) (h₄ : f.obj' 4 = g.obj' 4) (h₅ : f.obj' 5 = g.obj' 5)
(w₀ : f.map' 0 1 = eqToHom h₀ ≫ g.map' 0 1 ≫ eqToHom h₁.symm)
(w₁ : f.map' 1 2 = eqToHom h₁ ≫ g.map' 1 2 ≫ eqToHom h₂.symm)
(w₂ : f.map' 2 3 = eqToHom h₂ ≫ g.map' 2 3 ≫ eqToHom h₃.symm)
(w₃ : f.map' 3 4 = eqToHom h₃ ≫ g.map' 3 4 ≫ eqToHom h₄.symm)
(w₄ : f.map' 4 5 = eqToHom h₄ ≫ g.map' 4 5 ≫ eqToHom h₅.symm) :
f = g :=
ext_succ h₀ (ext₄ h₁ h₂ h₃ h₄ h₅ w₁ w₂ w₃ w₄) w₀
lemma mk₅_surjective (X : ComposableArrows C 5) :
∃ (X₀ X₁ X₂ X₃ X₄ X₅ : C) (f₀ : X₀ ⟶ X₁) (f₁ : X₁ ⟶ X₂) (f₂ : X₂ ⟶ X₃)
(f₃ : X₃ ⟶ X₄) (f₄ : X₄ ⟶ X₅), X = mk₅ f₀ f₁ f₂ f₃ f₄ :=
⟨_, _, _, _, _, _, X.map' 0 1, X.map' 1 2, X.map' 2 3, X.map' 3 4, X.map' 4 5,
ext₅ rfl rfl rfl rfl rfl rfl (by simp) (by simp) (by simp) (by simp) (by simp)⟩
/-- The `i`th arrow of `F : ComposableArrows C n`. -/
def arrow (i : ℕ) (hi : i < n := by valid) :
ComposableArrows C 1 := mk₁ (F.map' i (i + 1))
section mkOfObjOfMapSucc
variable (obj : Fin (n + 1) → C) (mapSucc : ∀ (i : Fin n), obj i.castSucc ⟶ obj i.succ)
lemma mkOfObjOfMapSucc_exists : ∃ (F : ComposableArrows C n) (e : ∀ i, F.obj i ≅ obj i),
∀ (i : ℕ) (hi : i < n), mapSucc ⟨i, hi⟩ =
(e ⟨i, _⟩).inv ≫ F.map' i (i + 1) ≫ (e ⟨i + 1, _⟩).hom := by
clear F G
revert obj mapSucc
induction' n with n hn
· intro obj _
exact ⟨mk₀ (obj 0), fun 0 => Iso.refl _, fun i hi => by simp at hi⟩
· intro obj mapSucc
obtain ⟨F, e, h⟩ := hn (fun i => obj i.succ) (fun i => mapSucc i.succ)
refine ⟨F.precomp (mapSucc 0 ≫ (e 0).inv), fun i => match i with
| 0 => Iso.refl _
| ⟨i + 1, hi⟩ => e _, fun i hi => ?_⟩
obtain _ | i := i
· dsimp
rw [assoc, Iso.inv_hom_id, comp_id]
erw [id_comp]
· exact h i (by valid)
/-- Given `obj : Fin (n + 1) → C` and `mapSucc i : obj i.castSucc ⟶ obj i.succ`
for all `i : Fin n`, this is `F : ComposableArrows C n` such that `F.obj i` is
definitionally equal to `obj i` and such that `F.map' i (i + 1) = mapSucc ⟨i, hi⟩`. -/
noncomputable def mkOfObjOfMapSucc : ComposableArrows C n :=
(mkOfObjOfMapSucc_exists obj mapSucc).choose.copyObj obj
(mkOfObjOfMapSucc_exists obj mapSucc).choose_spec.choose
@[simp]
lemma mkOfObjOfMapSucc_obj (i : Fin (n + 1)) :
(mkOfObjOfMapSucc obj mapSucc).obj i = obj i := rfl
lemma mkOfObjOfMapSucc_map_succ (i : ℕ) (hi : i < n := by valid) :
(mkOfObjOfMapSucc obj mapSucc).map' i (i + 1) = mapSucc ⟨i, hi⟩ :=
((mkOfObjOfMapSucc_exists obj mapSucc).choose_spec.choose_spec i hi).symm
lemma mkOfObjOfMapSucc_arrow (i : ℕ) (hi : i < n := by valid) :
(mkOfObjOfMapSucc obj mapSucc).arrow i = mk₁ (mapSucc ⟨i, hi⟩) :=
ext₁ rfl rfl (by simpa using mkOfObjOfMapSucc_map_succ obj mapSucc i hi)
end mkOfObjOfMapSucc
variable (C n) in
/-- The equivalence `(ComposableArrows C n)ᵒᵖ ≌ ComposableArrows Cᵒᵖ n` obtained
by reversing the arrows. -/
@[simps!]
def opEquivalence : (ComposableArrows C n)ᵒᵖ ≌ ComposableArrows Cᵒᵖ n :=
((orderDualEquivalence (Fin (n + 1))).symm.trans
Fin.revOrderIso.equivalence).symm.congrLeft.op.trans
(Functor.leftOpRightOpEquiv (Fin (n + 1)) C)
end ComposableArrows
variable {C}
section
open ComposableArrows
variable {D : Type*} [Category D] (G : C ⥤ D) (n : ℕ)
/-- The functor `ComposableArrows C n ⥤ ComposableArrows D n` obtained by postcomposition
with a functor `C ⥤ D`. -/
@[simps!]
def Functor.mapComposableArrows :
ComposableArrows C n ⥤ ComposableArrows D n :=
(whiskeringRight _ _ _).obj G
/-- The functor `ComposableArrows C n ⥤ ComposableArrows D n` induced by `G : C ⥤ D`
commutes with `opEquivalence`. -/
def Functor.mapComposableArrowsOpIso :
G.mapComposableArrows n ⋙ (opEquivalence D n).functor.rightOp ≅
(opEquivalence C n).functor.rightOp ⋙ (G.op.mapComposableArrows n).op :=
Iso.refl _
end
end CategoryTheory
|
CategoryTheory\Conj.lean | /-
Copyright (c) 2019 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Algebra.Group.Units.Equiv
import Mathlib.CategoryTheory.Endomorphism
import Mathlib.CategoryTheory.HomCongr
/-!
# Conjugate morphisms by isomorphisms
An isomorphism `α : X ≅ Y` defines
- a monoid isomorphism
`CategoryTheory.Iso.conj : End X ≃* End Y` by `α.conj f = α.inv ≫ f ≫ α.hom`;
- a group isomorphism `CategoryTheory.Iso.conjAut : Aut X ≃* Aut Y` by
`α.conjAut f = α.symm ≪≫ f ≪≫ α`
using
`CategoryTheory.Iso.homCongr : (X ≅ X₁) → (Y ≅ Y₁) → (X ⟶ Y) ≃ (X₁ ⟶ Y₁)`
and `CategoryTheory.Iso.isoCongr : (f : X₁ ≅ X₂) → (g : Y₁ ≅ Y₂) → (X₁ ≅ Y₁) ≃ (X₂ ≅ Y₂)`
which are defined in `CategoryTheory.HomCongr`.
-/
universe v u
namespace CategoryTheory
namespace Iso
variable {C : Type u} [Category.{v} C]
variable {X Y : C} (α : X ≅ Y)
/-- An isomorphism between two objects defines a monoid isomorphism between their
monoid of endomorphisms. -/
def conj : End X ≃* End Y :=
{ homCongr α α with map_mul' := fun f g => homCongr_comp α α α g f }
theorem conj_apply (f : End X) : α.conj f = α.inv ≫ f ≫ α.hom :=
rfl
@[simp]
theorem conj_comp (f g : End X) : α.conj (f ≫ g) = α.conj f ≫ α.conj g :=
α.conj.map_mul g f
@[simp]
theorem conj_id : α.conj (𝟙 X) = 𝟙 Y :=
α.conj.map_one
@[simp]
theorem refl_conj (f : End X) : (Iso.refl X).conj f = f := by
rw [conj_apply, Iso.refl_inv, Iso.refl_hom, Category.id_comp, Category.comp_id]
@[simp]
theorem trans_conj {Z : C} (β : Y ≅ Z) (f : End X) : (α ≪≫ β).conj f = β.conj (α.conj f) :=
homCongr_trans α α β β f
@[simp]
theorem symm_self_conj (f : End X) : α.symm.conj (α.conj f) = f := by
rw [← trans_conj, α.self_symm_id, refl_conj]
@[simp]
theorem self_symm_conj (f : End Y) : α.conj (α.symm.conj f) = f :=
α.symm.symm_self_conj f
/- Porting note (#10618): removed `@[simp]`; simp can prove this -/
theorem conj_pow (f : End X) (n : ℕ) : α.conj (f ^ n) = α.conj f ^ n :=
α.conj.toMonoidHom.map_pow f n
-- Porting note (#11215): TODO: change definition so that `conjAut_apply` becomes a `rfl`?
/-- `conj` defines a group isomorphisms between groups of automorphisms -/
def conjAut : Aut X ≃* Aut Y :=
(Aut.unitsEndEquivAut X).symm.trans <| (Units.mapEquiv α.conj).trans <| Aut.unitsEndEquivAut Y
theorem conjAut_apply (f : Aut X) : α.conjAut f = α.symm ≪≫ f ≪≫ α := by aesop_cat
@[simp]
theorem conjAut_hom (f : Aut X) : (α.conjAut f).hom = α.conj f.hom :=
rfl
@[simp]
theorem trans_conjAut {Z : C} (β : Y ≅ Z) (f : Aut X) :
(α ≪≫ β).conjAut f = β.conjAut (α.conjAut f) := by
simp only [conjAut_apply, Iso.trans_symm, Iso.trans_assoc]
/- Porting note (#10618): removed `@[simp]`; simp can prove this -/
theorem conjAut_mul (f g : Aut X) : α.conjAut (f * g) = α.conjAut f * α.conjAut g :=
α.conjAut.map_mul f g
@[simp]
theorem conjAut_trans (f g : Aut X) : α.conjAut (f ≪≫ g) = α.conjAut f ≪≫ α.conjAut g :=
conjAut_mul α g f
/- Porting note (#10618): removed `@[simp]`; simp can prove this -/
theorem conjAut_pow (f : Aut X) (n : ℕ) : α.conjAut (f ^ n) = α.conjAut f ^ n :=
α.conjAut.toMonoidHom.map_pow f n
/- Porting note (#10618): removed `@[simp]`; simp can prove this -/
theorem conjAut_zpow (f : Aut X) (n : ℤ) : α.conjAut (f ^ n) = α.conjAut f ^ n :=
α.conjAut.toMonoidHom.map_zpow f n
end Iso
namespace Functor
universe v₁ u₁
variable {C : Type u} [Category.{v} C] {D : Type u₁} [Category.{v₁} D] (F : C ⥤ D)
theorem map_conj {X Y : C} (α : X ≅ Y) (f : End X) :
F.map (α.conj f) = (F.mapIso α).conj (F.map f) :=
map_homCongr F α α f
theorem map_conjAut (F : C ⥤ D) {X Y : C} (α : X ≅ Y) (f : Aut X) :
F.mapIso (α.conjAut f) = (F.mapIso α).conjAut (F.mapIso f) := by
ext; simp only [mapIso_hom, Iso.conjAut_hom, F.map_conj]
-- alternative proof: by simp only [Iso.conjAut_apply, F.mapIso_trans, F.mapIso_symm]
end Functor
end CategoryTheory
|
CategoryTheory\ConnectedComponents.lean | /-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import Mathlib.Data.List.Chain
import Mathlib.CategoryTheory.IsConnected
import Mathlib.CategoryTheory.Sigma.Basic
import Mathlib.CategoryTheory.FullSubcategory
/-!
# Connected components of a category
Defines a type `ConnectedComponents J` indexing the connected components of a category, and the
full subcategories giving each connected component: `Component j : Type u₁`.
We show that each `Component j` is in fact connected.
We show every category can be expressed as a disjoint union of its connected components, in
particular `Decomposed J` is the category (definitionally) given by the sigma-type of the connected
components of `J`, and it is shown that this is equivalent to `J`.
-/
universe v₁ v₂ v₃ u₁ u₂
noncomputable section
open CategoryTheory.Category
namespace CategoryTheory
attribute [instance 100] IsConnected.is_nonempty
variable {J : Type u₁} [Category.{v₁} J]
variable {C : Type u₂} [Category.{u₁} C]
/-- This type indexes the connected components of the category `J`. -/
def ConnectedComponents (J : Type u₁) [Category.{v₁} J] : Type u₁ :=
Quotient (Zigzag.setoid J)
instance [Inhabited J] : Inhabited (ConnectedComponents J) :=
⟨Quotient.mk'' default⟩
/-- Given an index for a connected component, produce the actual component as a full subcategory. -/
def Component (j : ConnectedComponents J) : Type u₁ :=
FullSubcategory fun k => Quotient.mk'' k = j
instance {j : ConnectedComponents J} : Category (Component j) :=
FullSubcategory.category _
-- Porting note: it was originally @[simps (config := { rhsMd := semireducible })]
/-- The inclusion functor from a connected component to the whole category. -/
@[simps!]
def Component.ι (j : ConnectedComponents J) : Component j ⥤ J :=
fullSubcategoryInclusion _
instance {j : ConnectedComponents J} : Functor.Full (Component.ι j) :=
FullSubcategory.full _
instance {j : ConnectedComponents J} : Functor.Faithful (Component.ι j) :=
FullSubcategory.faithful _
/-- Each connected component of the category is nonempty. -/
instance (j : ConnectedComponents J) : Nonempty (Component j) := by
induction j using Quotient.inductionOn'
exact ⟨⟨_, rfl⟩⟩
instance (j : ConnectedComponents J) : Inhabited (Component j) :=
Classical.inhabited_of_nonempty'
/-- Each connected component of the category is connected. -/
instance (j : ConnectedComponents J) : IsConnected (Component j) := by
-- Show it's connected by constructing a zigzag (in `Component j`) between any two objects
apply isConnected_of_zigzag
rintro ⟨j₁, hj₁⟩ ⟨j₂, rfl⟩
-- We know that the underlying objects j₁ j₂ have some zigzag between them in `J`
have h₁₂ : Zigzag j₁ j₂ := Quotient.exact' hj₁
-- Get an explicit zigzag as a list
rcases List.exists_chain_of_relationReflTransGen h₁₂ with ⟨l, hl₁, hl₂⟩
-- Everything which has a zigzag to j₂ can be lifted to the same component as `j₂`.
let f : ∀ x, Zigzag x j₂ → Component (Quotient.mk'' j₂) := fun x h => ⟨x, Quotient.sound' h⟩
-- Everything in our chosen zigzag from `j₁` to `j₂` has a zigzag to `j₂`.
have hf : ∀ a : J, a ∈ l → Zigzag a j₂ := by
intro i hi
apply List.Chain.induction (fun t => Zigzag t j₂) _ hl₁ hl₂ _ _ _ (List.mem_of_mem_tail hi)
· intro j k
apply Relation.ReflTransGen.head
· apply Relation.ReflTransGen.refl
-- Now lift the zigzag from `j₁` to `j₂` in `J` to the same thing in `component j`.
refine ⟨l.pmap f hf, ?_, ?_⟩
· refine @List.chain_pmap_of_chain _ _ _ _ _ f (fun x y _ _ h => ?_) _ _ hl₁ h₁₂ _
exact zag_of_zag_obj (Component.ι _) h
· erw [List.getLast_pmap _ f (j₁ :: l) (by simpa [h₁₂] using hf) (List.cons_ne_nil _ _)]
exact FullSubcategory.ext hl₂
/-- The disjoint union of `J`s connected components, written explicitly as a sigma-type with the
category structure.
This category is equivalent to `J`.
-/
abbrev Decomposed (J : Type u₁) [Category.{v₁} J] :=
Σj : ConnectedComponents J, Component j
-- This name may cause clashes further down the road, and so might need to be changed.
/--
The inclusion of each component into the decomposed category. This is just `sigma.incl` but having
this abbreviation helps guide typeclass search to get the right category instance on `decomposed J`.
-/
abbrev inclusion (j : ConnectedComponents J) : Component j ⥤ Decomposed J :=
Sigma.incl _
-- Porting note: it was originally @[simps (config := { rhsMd := semireducible })]
/-- The forward direction of the equivalence between the decomposed category and the original. -/
@[simps!]
def decomposedTo (J : Type u₁) [Category.{v₁} J] : Decomposed J ⥤ J :=
Sigma.desc Component.ι
@[simp]
theorem inclusion_comp_decomposedTo (j : ConnectedComponents J) :
inclusion j ⋙ decomposedTo J = Component.ι j :=
rfl
instance : (decomposedTo J).Full where
map_surjective := by
rintro ⟨j', X, hX⟩ ⟨k', Y, hY⟩ f
dsimp at f
have : j' = k' := by
rw [← hX, ← hY, Quotient.eq'']
exact Relation.ReflTransGen.single (Or.inl ⟨f⟩)
subst this
exact ⟨Sigma.SigmaHom.mk f, rfl⟩
instance : (decomposedTo J).Faithful where
map_injective := by
rintro ⟨_, j, rfl⟩ ⟨_, k, hY⟩ ⟨f⟩ ⟨_⟩ rfl
rfl
instance : (decomposedTo J).EssSurj where mem_essImage j := ⟨⟨_, j, rfl⟩, ⟨Iso.refl _⟩⟩
instance : (decomposedTo J).IsEquivalence where
-- Porting note: it was originally @[simps (config := { rhsMd := semireducible }) Functor]
/-- This gives that any category is equivalent to a disjoint union of connected categories. -/
@[simps! functor]
def decomposedEquiv : Decomposed J ≌ J :=
(decomposedTo J).asEquivalence
end CategoryTheory
|
CategoryTheory\Core.lean | /-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Control.EquivFunctor
import Mathlib.CategoryTheory.Groupoid
import Mathlib.CategoryTheory.Whiskering
import Mathlib.CategoryTheory.Types
/-!
# The core of a category
The core of a category `C` is the (non-full) subcategory of `C` consisting of all objects,
and all isomorphisms. We construct it as a `CategoryTheory.Groupoid`.
`CategoryTheory.Core.inclusion : Core C ⥤ C` gives the faithful inclusion into the original
category.
Any functor `F` from a groupoid `G` into `C` factors through `CategoryTheory.Core C`,
but this is not functorial with respect to `F`.
-/
namespace CategoryTheory
universe v₁ v₂ u₁ u₂
-- morphism levels before object levels. See note [CategoryTheory universes].
/-- The core of a category C is the groupoid whose morphisms are all the
isomorphisms of C. -/
-- Porting note(#5171): linter not yet ported
-- @[nolint has_nonempty_instance]
def Core (C : Type u₁) := C
variable {C : Type u₁} [Category.{v₁} C]
instance coreCategory : Groupoid.{v₁} (Core C) where
Hom (X Y : C) := X ≅ Y
id (X : C) := Iso.refl X
comp f g := Iso.trans f g
inv {X Y} f := Iso.symm f
namespace Core
@[simp]
/- Porting note: abomination -/
theorem id_hom (X : C) : Iso.hom (coreCategory.id X) = @CategoryStruct.id C _ X := by
rfl
@[simp]
theorem comp_hom {X Y Z : Core C} (f : X ⟶ Y) (g : Y ⟶ Z) : (f ≫ g).hom = f.hom ≫ g.hom :=
rfl
variable (C)
/-- The core of a category is naturally included in the category. -/
def inclusion : Core C ⥤ C where
obj := id
map f := f.hom
-- Porting note: This worked without proof before.
instance : (inclusion C).Faithful where
map_injective := by
intro _ _
apply Iso.ext
variable {C} {G : Type u₂} [Groupoid.{v₂} G]
-- Note that this function is not functorial
-- (consider the two functors from [0] to [1], and the natural transformation between them).
/-- A functor from a groupoid to a category C factors through the core of C. -/
def functorToCore (F : G ⥤ C) : G ⥤ Core C where
obj X := F.obj X
map f := { hom := F.map f, inv := F.map (Groupoid.inv f) }
/-- We can functorially associate to any functor from a groupoid to the core of a category `C`,
a functor from the groupoid to `C`, simply by composing with the embedding `Core C ⥤ C`.
-/
def forgetFunctorToCore : (G ⥤ Core C) ⥤ G ⥤ C :=
(whiskeringRight _ _ _).obj (inclusion C)
end Core
/-- `ofEquivFunctor m` lifts a type-level `EquivFunctor`
to a categorical functor `Core (Type u₁) ⥤ Core (Type u₂)`.
-/
def ofEquivFunctor (m : Type u₁ → Type u₂) [EquivFunctor m] : Core (Type u₁) ⥤ Core (Type u₂) where
obj := m
map f := (EquivFunctor.mapEquiv m f.toEquiv).toIso
map_id α := by apply Iso.ext; funext x; exact congr_fun (EquivFunctor.map_refl' _) x
map_comp f g := by
apply Iso.ext; funext x; dsimp
erw [Iso.toEquiv_comp, EquivFunctor.map_trans']
rw [Function.comp]
end CategoryTheory
|
CategoryTheory\Countable.lean | /-
Copyright (c) 2023 Dagur Asgeirsson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Dagur Asgeirsson
-/
import Mathlib.Data.Countable.Small
import Mathlib.CategoryTheory.EssentiallySmall
import Mathlib.CategoryTheory.FinCategory.Basic
import Mathlib.Data.Fintype.Card
/-!
# Countable categories
A category is countable in this sense if it has countably many objects and countably many morphisms.
-/
universe w v u
open scoped Classical
noncomputable section
namespace CategoryTheory
instance discreteCountable {α : Type*} [Countable α] : Countable (Discrete α) :=
Countable.of_equiv α discreteEquiv.symm
/-- A category with countably many objects and morphisms. -/
class CountableCategory (J : Type*) [Category J] : Prop where
countableObj : Countable J := by infer_instance
countableHom : ∀ j j' : J, Countable (j ⟶ j') := by infer_instance
attribute [instance] CountableCategory.countableObj CountableCategory.countableHom
instance countablerCategoryDiscreteOfCountable (J : Type*) [Countable J] :
CountableCategory (Discrete J) where
instance : CountableCategory ℕ where
namespace CountableCategory
variable (α : Type u) [Category.{v} α] [CountableCategory α]
/-- A countable category `α` is equivalent to a category with objects in `Type`. -/
abbrev ObjAsType : Type :=
InducedCategory α (equivShrink.{0} α).symm
instance : Countable (ObjAsType α) := Countable.of_equiv α (equivShrink.{0} α)
instance {i j : ObjAsType α} : Countable (i ⟶ j) :=
CountableCategory.countableHom ((equivShrink.{0} α).symm i) _
instance : CountableCategory (ObjAsType α) where
/-- The constructed category is indeed equivalent to `α`. -/
noncomputable def objAsTypeEquiv : ObjAsType α ≌ α :=
(inducedFunctor (equivShrink.{0} α).symm).asEquivalence
/-- A countable category `α` is equivalent to a *small* category with objects in `Type`. -/
def HomAsType := ShrinkHoms (ObjAsType α)
instance : LocallySmall.{0} (ObjAsType α) where
hom_small _ _ := inferInstance
instance : SmallCategory (HomAsType α) := inferInstanceAs <| SmallCategory (ShrinkHoms _)
instance : Countable (HomAsType α) := Countable.of_equiv α (equivShrink.{0} α)
instance {i j : HomAsType α} : Countable (i ⟶ j) :=
Countable.of_equiv ((ShrinkHoms.equivalence _).inverse.obj i ⟶
(ShrinkHoms.equivalence _).inverse.obj j)
(Functor.FullyFaithful.ofFullyFaithful _).homEquiv.symm
instance : CountableCategory (HomAsType α) where
/-- The constructed category is indeed equivalent to `α`. -/
noncomputable def homAsTypeEquiv : HomAsType α ≌ α :=
(ShrinkHoms.equivalence _).symm.trans (objAsTypeEquiv _)
end CountableCategory
instance (α : Type*) [Category α] [FinCategory α] : CountableCategory α where
instance : CountableCategory ℕ where
open Opposite
/-- The opposite of a countable category is countable. -/
instance countableCategoryOpposite {J : Type*} [Category J] [CountableCategory J] :
CountableCategory Jᵒᵖ where
countableObj := Countable.of_equiv _ equivToOpposite
countableHom j j' := Countable.of_equiv _ (opEquiv j j').symm
/-- Applying `ULift` to morphisms and objects of a category preserves countability. -/
instance countableCategoryUlift {J : Type v} [Category J] [CountableCategory J] :
CountableCategory.{max w v} (ULiftHom.{w, max w v} (ULift.{w, v} J)) where
countableObj := instCountableULift
countableHom := fun i j =>
have : Countable ((ULiftHom.objDown i).down ⟶ (ULiftHom.objDown j).down) := inferInstance
instCountableULift
end CategoryTheory
|
CategoryTheory\DifferentialObject.lean | /-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Algebra.Group.Basic
import Mathlib.Data.Int.Cast.Defs
import Mathlib.CategoryTheory.Shift.Basic
import Mathlib.CategoryTheory.ConcreteCategory.Basic
/-!
# Differential objects in a category.
A differential object in a category with zero morphisms and a shift is
an object `X` equipped with
a morphism `d : obj ⟶ obj⟦1⟧`, such that `d^2 = 0`.
We build the category of differential objects, and some basic constructions
such as the forgetful functor, zero morphisms and zero objects, and the shift functor
on differential objects.
-/
open CategoryTheory.Limits
universe v u
namespace CategoryTheory
variable (S : Type*) [AddMonoidWithOne S] (C : Type u) [Category.{v} C]
variable [HasZeroMorphisms C] [HasShift C S]
/-- A differential object in a category with zero morphisms and a shift is
an object `obj` equipped with
a morphism `d : obj ⟶ obj⟦1⟧`, such that `d^2 = 0`. -/
-- Porting note(#5171): removed `@[nolint has_nonempty_instance]`
structure DifferentialObject where
/-- The underlying object of a differential object. -/
obj : C
/-- The differential of a differential object. -/
d : obj ⟶ obj⟦(1 : S)⟧
/-- The differential `d` satisfies that `d² = 0`. -/
d_squared : d ≫ d⟦(1 : S)⟧' = 0 := by aesop_cat
attribute [reassoc (attr := simp)] DifferentialObject.d_squared
variable {S C}
namespace DifferentialObject
/-- A morphism of differential objects is a morphism commuting with the differentials. -/
@[ext] -- Porting note(#5171): removed `nolint has_nonempty_instance`
structure Hom (X Y : DifferentialObject S C) where
/-- The morphism between underlying objects of the two differentiable objects. -/
f : X.obj ⟶ Y.obj
comm : X.d ≫ f⟦1⟧' = f ≫ Y.d := by aesop_cat
attribute [reassoc (attr := simp)] Hom.comm
namespace Hom
/-- The identity morphism of a differential object. -/
@[simps]
def id (X : DifferentialObject S C) : Hom X X where
f := 𝟙 X.obj
/-- The composition of morphisms of differential objects. -/
@[simps]
def comp {X Y Z : DifferentialObject S C} (f : Hom X Y) (g : Hom Y Z) : Hom X Z where
f := f.f ≫ g.f
end Hom
instance categoryOfDifferentialObjects : Category (DifferentialObject S C) where
Hom := Hom
id := Hom.id
comp f g := Hom.comp f g
-- Porting note: added
@[ext]
theorem ext {A B : DifferentialObject S C} {f g : A ⟶ B} (w : f.f = g.f := by aesop_cat) : f = g :=
Hom.ext w
@[simp]
theorem id_f (X : DifferentialObject S C) : (𝟙 X : X ⟶ X).f = 𝟙 X.obj := rfl
@[simp]
theorem comp_f {X Y Z : DifferentialObject S C} (f : X ⟶ Y) (g : Y ⟶ Z) :
(f ≫ g).f = f.f ≫ g.f :=
rfl
@[simp]
theorem eqToHom_f {X Y : DifferentialObject S C} (h : X = Y) :
Hom.f (eqToHom h) = eqToHom (congr_arg _ h) := by
subst h
rw [eqToHom_refl, eqToHom_refl]
rfl
variable (S C)
/-- The forgetful functor taking a differential object to its underlying object. -/
def forget : DifferentialObject S C ⥤ C where
obj X := X.obj
map f := f.f
instance forget_faithful : (forget S C).Faithful where
variable {S C}
section
variable [(shiftFunctor C (1 : S)).PreservesZeroMorphisms]
instance {X Y : DifferentialObject S C} : Zero (X ⟶ Y) := ⟨{f := 0}⟩
@[simp]
theorem zero_f (P Q : DifferentialObject S C) : (0 : P ⟶ Q).f = 0 := rfl
instance hasZeroMorphisms : HasZeroMorphisms (DifferentialObject S C) where
end
/-- An isomorphism of differential objects gives an isomorphism of the underlying objects. -/
@[simps]
def isoApp {X Y : DifferentialObject S C} (f : X ≅ Y) : X.obj ≅ Y.obj where
hom := f.hom.f
inv := f.inv.f
hom_inv_id := by rw [← comp_f, Iso.hom_inv_id, id_f]
inv_hom_id := by rw [← comp_f, Iso.inv_hom_id, id_f]
@[simp]
theorem isoApp_refl (X : DifferentialObject S C) : isoApp (Iso.refl X) = Iso.refl X.obj := rfl
@[simp]
theorem isoApp_symm {X Y : DifferentialObject S C} (f : X ≅ Y) : isoApp f.symm = (isoApp f).symm :=
rfl
@[simp]
theorem isoApp_trans {X Y Z : DifferentialObject S C} (f : X ≅ Y) (g : Y ≅ Z) :
isoApp (f ≪≫ g) = isoApp f ≪≫ isoApp g := rfl
/-- An isomorphism of differential objects can be constructed
from an isomorphism of the underlying objects that commutes with the differentials. -/
@[simps]
def mkIso {X Y : DifferentialObject S C} (f : X.obj ≅ Y.obj) (hf : X.d ≫ f.hom⟦1⟧' = f.hom ≫ Y.d) :
X ≅ Y where
hom := ⟨f.hom, hf⟩
inv := ⟨f.inv, by
rw [← Functor.mapIso_inv, Iso.comp_inv_eq, Category.assoc, Iso.eq_inv_comp, Functor.mapIso_hom,
hf]⟩
hom_inv_id := by ext1; dsimp; exact f.hom_inv_id
inv_hom_id := by ext1; dsimp; exact f.inv_hom_id
end DifferentialObject
namespace Functor
universe v' u'
variable (D : Type u') [Category.{v'} D]
variable [HasZeroMorphisms D] [HasShift D S]
/-- A functor `F : C ⥤ D` which commutes with shift functors on `C` and `D` and preserves zero
morphisms can be lifted to a functor `DifferentialObject S C ⥤ DifferentialObject S D`. -/
@[simps]
def mapDifferentialObject (F : C ⥤ D)
(η : (shiftFunctor C (1 : S)).comp F ⟶ F.comp (shiftFunctor D (1 : S)))
(hF : ∀ c c', F.map (0 : c ⟶ c') = 0) : DifferentialObject S C ⥤ DifferentialObject S D where
obj X :=
{ obj := F.obj X.obj
d := F.map X.d ≫ η.app X.obj
d_squared := by
rw [Functor.map_comp, ← Functor.comp_map F (shiftFunctor D (1 : S))]
slice_lhs 2 3 => rw [← η.naturality X.d]
rw [Functor.comp_map]
slice_lhs 1 2 => rw [← F.map_comp, X.d_squared, hF]
rw [zero_comp, zero_comp] }
map f :=
{ f := F.map f.f
comm := by
dsimp
slice_lhs 2 3 => rw [← Functor.comp_map F (shiftFunctor D (1 : S)), ← η.naturality f.f]
slice_lhs 1 2 => rw [Functor.comp_map, ← F.map_comp, f.comm, F.map_comp]
rw [Category.assoc] }
map_id := by intros; ext; simp [autoParam]
map_comp := by intros; ext; simp [autoParam]
end Functor
end CategoryTheory
namespace CategoryTheory
namespace DifferentialObject
variable (S : Type*) [AddMonoidWithOne S] (C : Type u) [Category.{v} C]
variable [HasZeroObject C] [HasZeroMorphisms C] [HasShift C S]
variable [(shiftFunctor C (1 : S)).PreservesZeroMorphisms]
open scoped ZeroObject
instance hasZeroObject : HasZeroObject (DifferentialObject S C) where
zero := ⟨{ obj := 0, d := 0 },
{ unique_to := fun X => ⟨⟨⟨{ f := 0 }⟩, fun f => by ext⟩⟩,
unique_from := fun X => ⟨⟨⟨{ f := 0 }⟩, fun f => by ext⟩⟩ }⟩
end DifferentialObject
namespace DifferentialObject
variable (S : Type*) [AddMonoidWithOne S]
variable (C : Type (u + 1)) [LargeCategory C] [ConcreteCategory C] [HasZeroMorphisms C]
variable [HasShift C S]
instance concreteCategoryOfDifferentialObjects : ConcreteCategory (DifferentialObject S C) where
forget := forget S C ⋙ CategoryTheory.forget C
instance : HasForget₂ (DifferentialObject S C) C where
forget₂ := forget S C
end DifferentialObject
/-! The category of differential objects itself has a shift functor. -/
namespace DifferentialObject
variable {S : Type*} [AddCommGroupWithOne S] (C : Type u) [Category.{v} C]
variable [HasZeroMorphisms C] [HasShift C S]
noncomputable section
/-- The shift functor on `DifferentialObject S C`. -/
@[simps]
def shiftFunctor (n : S) : DifferentialObject S C ⥤ DifferentialObject S C where
obj X :=
{ obj := X.obj⟦n⟧
d := X.d⟦n⟧' ≫ (shiftComm _ _ _).hom
d_squared := by
rw [Functor.map_comp, Category.assoc, shiftComm_hom_comp_assoc, ← Functor.map_comp_assoc,
X.d_squared, Functor.map_zero, zero_comp] }
map f :=
{ f := f.f⟦n⟧'
comm := by
dsimp
erw [Category.assoc, shiftComm_hom_comp, ← Functor.map_comp_assoc, f.comm,
Functor.map_comp_assoc]
rfl }
map_id X := by ext1; dsimp; rw [Functor.map_id]
map_comp f g := by ext1; dsimp; rw [Functor.map_comp]
/-- The shift functor on `DifferentialObject S C` is additive. -/
@[simps!]
nonrec def shiftFunctorAdd (m n : S) :
shiftFunctor C (m + n) ≅ shiftFunctor C m ⋙ shiftFunctor C n := by
refine NatIso.ofComponents (fun X => mkIso (shiftAdd X.obj _ _) ?_) (fun f => ?_)
· dsimp
rw [← cancel_epi ((shiftFunctorAdd C m n).inv.app X.obj)]
simp only [Category.assoc, Iso.inv_hom_id_app_assoc]
erw [← NatTrans.naturality_assoc]
dsimp
simp only [Functor.map_comp, Category.assoc,
shiftFunctorComm_hom_app_comp_shift_shiftFunctorAdd_hom_app 1 m n X.obj,
Iso.inv_hom_id_app_assoc]
· ext; dsimp; exact NatTrans.naturality _ _
section
/-- The shift by zero is naturally isomorphic to the identity. -/
@[simps!]
def shiftZero : shiftFunctor C (0 : S) ≅ 𝟭 (DifferentialObject S C) := by
refine NatIso.ofComponents (fun X => mkIso ((shiftFunctorZero C S).app X.obj) ?_) (fun f => ?_)
· erw [← NatTrans.naturality]
dsimp
simp only [shiftFunctorZero_hom_app_shift, Category.assoc]
· aesop_cat
end
instance : HasShift (DifferentialObject S C) S :=
hasShiftMk _ _
{ F := shiftFunctor C
zero := shiftZero C
add := shiftFunctorAdd C
assoc_hom_app := fun m₁ m₂ m₃ X => by
ext1
convert shiftFunctorAdd_assoc_hom_app m₁ m₂ m₃ X.obj
dsimp [shiftFunctorAdd']
simp
zero_add_hom_app := fun n X => by
ext1
convert shiftFunctorAdd_zero_add_hom_app n X.obj
simp
add_zero_hom_app := fun n X => by
ext1
convert shiftFunctorAdd_add_zero_hom_app n X.obj
simp }
end
end DifferentialObject
end CategoryTheory
|
CategoryTheory\DiscreteCategory.lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Stephen Morgan, Scott Morrison, Floris van Doorn
-/
import Mathlib.CategoryTheory.EqToHom
import Mathlib.CategoryTheory.Pi.Basic
import Mathlib.Data.ULift
/-!
# Discrete categories
We define `Discrete α` as a structure containing a term `a : α` for any type `α`,
and use this type alias to provide a `SmallCategory` instance
whose only morphisms are the identities.
There is an annoying technical difficulty that it has turned out to be inconvenient
to allow categories with morphisms living in `Prop`,
so instead of defining `X ⟶ Y` in `Discrete α` as `X = Y`,
one might define it as `PLift (X = Y)`.
In fact, to allow `Discrete α` to be a `SmallCategory`
(i.e. with morphisms in the same universe as the objects),
we actually define the hom type `X ⟶ Y` as `ULift (PLift (X = Y))`.
`Discrete.functor` promotes a function `f : I → C` (for any category `C`) to a functor
`Discrete.functor f : Discrete I ⥤ C`.
Similarly, `Discrete.natTrans` and `Discrete.natIso` promote `I`-indexed families of morphisms,
or `I`-indexed families of isomorphisms to natural transformations or natural isomorphism.
We show equivalences of types are the same as (categorical) equivalences of the corresponding
discrete categories.
-/
namespace CategoryTheory
-- morphism levels before object levels. See note [CategoryTheory universes].
universe v₁ v₂ v₃ u₁ u₁' u₂ u₃
-- This is intentionally a structure rather than a type synonym
-- to enforce using `DiscreteEquiv` (or `Discrete.mk` and `Discrete.as`) to move between
-- `Discrete α` and `α`. Otherwise there is too much API leakage.
/-- A wrapper for promoting any type to a category,
with the only morphisms being equalities.
-/
@[ext, aesop safe cases (rule_sets := [CategoryTheory])]
structure Discrete (α : Type u₁) where
/-- A wrapper for promoting any type to a category,
with the only morphisms being equalities. -/
as : α
@[simp]
theorem Discrete.mk_as {α : Type u₁} (X : Discrete α) : Discrete.mk X.as = X := by
rfl
/-- `Discrete α` is equivalent to the original type `α`. -/
@[simps]
def discreteEquiv {α : Type u₁} : Discrete α ≃ α where
toFun := Discrete.as
invFun := Discrete.mk
left_inv := by aesop_cat
right_inv := by aesop_cat
instance {α : Type u₁} [DecidableEq α] : DecidableEq (Discrete α) :=
discreteEquiv.decidableEq
/-- The "Discrete" category on a type, whose morphisms are equalities.
Because we do not allow morphisms in `Prop` (only in `Type`),
somewhat annoyingly we have to define `X ⟶ Y` as `ULift (PLift (X = Y))`.
See <https://stacks.math.columbia.edu/tag/001A>
-/
instance discreteCategory (α : Type u₁) : SmallCategory (Discrete α) where
Hom X Y := ULift (PLift (X.as = Y.as))
id X := ULift.up (PLift.up rfl)
comp {X Y Z} g f := by
cases X
cases Y
cases Z
rcases f with ⟨⟨⟨⟩⟩⟩
exact g
namespace Discrete
variable {α : Type u₁}
instance [Inhabited α] : Inhabited (Discrete α) :=
⟨⟨default⟩⟩
instance [Subsingleton α] : Subsingleton (Discrete α) :=
⟨by aesop_cat⟩
instance instSubsingletonDiscreteHom (X Y : Discrete α) : Subsingleton (X ⟶ Y) :=
show Subsingleton (ULift (PLift _)) from inferInstance
/- Porting note: rewrote `discrete_cases` tactic -/
/-- A simple tactic to run `cases` on any `Discrete α` hypotheses. -/
macro "discrete_cases" : tactic =>
`(tactic| fail_if_no_progress casesm* Discrete _, (_ : Discrete _) ⟶ (_ : Discrete _), PLift _)
open Lean Elab Tactic in
/--
Use:
```
attribute [local aesop safe tactic (rule_sets := [CategoryTheory])]
CategoryTheory.Discrete.discreteCases
```
to locally gives `aesop_cat` the ability to call `cases` on
`Discrete` and `(_ : Discrete _) ⟶ (_ : Discrete _)` hypotheses.
-/
def discreteCases : TacticM Unit := do
evalTactic (← `(tactic| discrete_cases))
-- Porting note:
-- investigate turning on either
-- `attribute [aesop safe cases (rule_sets := [CategoryTheory])] Discrete`
-- or
-- `attribute [aesop safe tactic (rule_sets := [CategoryTheory])] discreteCases`
-- globally.
instance [Unique α] : Unique (Discrete α) :=
Unique.mk' (Discrete α)
/-- Extract the equation from a morphism in a discrete category. -/
theorem eq_of_hom {X Y : Discrete α} (i : X ⟶ Y) : X.as = Y.as :=
i.down.down
/-- Promote an equation between the wrapped terms in `X Y : Discrete α` to a morphism `X ⟶ Y`
in the discrete category. -/
protected abbrev eqToHom {X Y : Discrete α} (h : X.as = Y.as) : X ⟶ Y :=
eqToHom (by aesop_cat)
/-- Promote an equation between the wrapped terms in `X Y : Discrete α` to an isomorphism `X ≅ Y`
in the discrete category. -/
protected abbrev eqToIso {X Y : Discrete α} (h : X.as = Y.as) : X ≅ Y :=
eqToIso (by aesop_cat)
/-- A variant of `eqToHom` that lifts terms to the discrete category. -/
abbrev eqToHom' {a b : α} (h : a = b) : Discrete.mk a ⟶ Discrete.mk b :=
Discrete.eqToHom h
/-- A variant of `eqToIso` that lifts terms to the discrete category. -/
abbrev eqToIso' {a b : α} (h : a = b) : Discrete.mk a ≅ Discrete.mk b :=
Discrete.eqToIso h
@[simp]
theorem id_def (X : Discrete α) : ULift.up (PLift.up (Eq.refl X.as)) = 𝟙 X :=
rfl
variable {C : Type u₂} [Category.{v₂} C]
instance {I : Type u₁} {i j : Discrete I} (f : i ⟶ j) : IsIso f :=
⟨⟨Discrete.eqToHom (eq_of_hom f).symm, by aesop_cat⟩⟩
attribute [local aesop safe tactic (rule_sets := [CategoryTheory])]
CategoryTheory.Discrete.discreteCases
/-- Any function `I → C` gives a functor `Discrete I ⥤ C`. -/
def functor {I : Type u₁} (F : I → C) : Discrete I ⥤ C where
obj := F ∘ Discrete.as
map {X Y} f := by
dsimp
rcases f with ⟨⟨h⟩⟩
exact eqToHom (congrArg _ h)
@[simp]
theorem functor_obj {I : Type u₁} (F : I → C) (i : I) :
(Discrete.functor F).obj (Discrete.mk i) = F i :=
rfl
@[simp]
theorem functor_map {I : Type u₁} (F : I → C) {i : Discrete I} (f : i ⟶ i) :
(Discrete.functor F).map f = 𝟙 (F i.as) := by aesop_cat
@[deprecated (since := "2024-07-16")]
alias CategoryTheory.FreeMonoidalCategory.discrete_functor_map_eq_id := functor_map
@[simp]
theorem functor_obj_eq_as {I : Type u₁} (F : I → C) (X : Discrete I) :
(Discrete.functor F).obj X = F X.as :=
rfl
@[deprecated (since := "2024-07-16")]
alias CategoryTheory.FreeMonoidalCategory.discrete_functor_obj_eq_as := functor_obj_eq_as
/-- The discrete functor induced by a composition of maps can be written as a
composition of two discrete functors.
-/
@[simps!]
def functorComp {I : Type u₁} {J : Type u₁'} (f : J → C) (g : I → J) :
Discrete.functor (f ∘ g) ≅ Discrete.functor (Discrete.mk ∘ g) ⋙ Discrete.functor f :=
NatIso.ofComponents fun X => Iso.refl _
/-- For functors out of a discrete category,
a natural transformation is just a collection of maps,
as the naturality squares are trivial.
-/
@[simps]
def natTrans {I : Type u₁} {F G : Discrete I ⥤ C} (f : ∀ i : Discrete I, F.obj i ⟶ G.obj i) :
F ⟶ G where
app := f
naturality := fun {X Y} ⟨⟨g⟩⟩ => by
discrete_cases
rcases g
change F.map (𝟙 _) ≫ _ = _ ≫ G.map (𝟙 _)
simp
/-- For functors out of a discrete category,
a natural isomorphism is just a collection of isomorphisms,
as the naturality squares are trivial.
-/
@[simps!]
def natIso {I : Type u₁} {F G : Discrete I ⥤ C} (f : ∀ i : Discrete I, F.obj i ≅ G.obj i) :
F ≅ G :=
NatIso.ofComponents f fun ⟨⟨g⟩⟩ => by
discrete_cases
rcases g
change F.map (𝟙 _) ≫ _ = _ ≫ G.map (𝟙 _)
simp
instance {I : Type*} {F G : Discrete I ⥤ C} (f : ∀ i, F.obj i ⟶ G.obj i) [∀ i, IsIso (f i)] :
IsIso (Discrete.natTrans f) := by
change IsIso (Discrete.natIso (fun i => asIso (f i))).hom
infer_instance
@[simp]
theorem natIso_app {I : Type u₁} {F G : Discrete I ⥤ C} (f : ∀ i : Discrete I, F.obj i ≅ G.obj i)
(i : Discrete I) : (Discrete.natIso f).app i = f i := by aesop_cat
/-- Every functor `F` from a discrete category is naturally isomorphic (actually, equal) to
`Discrete.functor (F.obj)`. -/
@[simp]
def natIsoFunctor {I : Type u₁} {F : Discrete I ⥤ C} : F ≅ Discrete.functor (F.obj ∘ Discrete.mk) :=
natIso fun _ => Iso.refl _
/-- Composing `Discrete.functor F` with another functor `G` amounts to composing `F` with `G.obj` -/
@[simp]
def compNatIsoDiscrete {I : Type u₁} {D : Type u₃} [Category.{v₃} D] (F : I → C) (G : C ⥤ D) :
Discrete.functor F ⋙ G ≅ Discrete.functor (G.obj ∘ F) :=
natIso fun _ => Iso.refl _
/-- We can promote a type-level `Equiv` to
an equivalence between the corresponding `discrete` categories.
-/
@[simps]
def equivalence {I : Type u₁} {J : Type u₂} (e : I ≃ J) : Discrete I ≌ Discrete J where
functor := Discrete.functor (Discrete.mk ∘ (e : I → J))
inverse := Discrete.functor (Discrete.mk ∘ (e.symm : J → I))
unitIso :=
Discrete.natIso fun i => eqToIso (by aesop_cat)
counitIso :=
Discrete.natIso fun j => eqToIso (by aesop_cat)
/-- We can convert an equivalence of `discrete` categories to a type-level `Equiv`. -/
@[simps]
def equivOfEquivalence {α : Type u₁} {β : Type u₂} (h : Discrete α ≌ Discrete β) : α ≃ β where
toFun := Discrete.as ∘ h.functor.obj ∘ Discrete.mk
invFun := Discrete.as ∘ h.inverse.obj ∘ Discrete.mk
left_inv a := by simpa using eq_of_hom (h.unitIso.app (Discrete.mk a)).2
right_inv a := by simpa using eq_of_hom (h.counitIso.app (Discrete.mk a)).1
end Discrete
namespace Discrete
variable {J : Type v₁}
open Opposite
/-- A discrete category is equivalent to its opposite category. -/
@[simps! functor_obj_as inverse_obj]
protected def opposite (α : Type u₁) : (Discrete α)ᵒᵖ ≌ Discrete α :=
let F : Discrete α ⥤ (Discrete α)ᵒᵖ := Discrete.functor fun x => op (Discrete.mk x)
Equivalence.mk F.leftOp F
(NatIso.ofComponents fun ⟨X⟩ => Iso.refl _)
(Discrete.natIso fun ⟨X⟩ => Iso.refl _)
variable {C : Type u₂} [Category.{v₂} C]
@[simp]
theorem functor_map_id (F : Discrete J ⥤ C) {j : Discrete J} (f : j ⟶ j) :
F.map f = 𝟙 (F.obj j) := by
have h : f = 𝟙 j := by aesop_cat
rw [h]
simp
end Discrete
/-- The equivalence of categories `(J → C) ≌ (Discrete J ⥤ C)`. -/
@[simps]
def piEquivalenceFunctorDiscrete (J : Type u₂) (C : Type u₁) [Category.{v₁} C] :
(J → C) ≌ (Discrete J ⥤ C) where
functor :=
{ obj := fun F => Discrete.functor F
map := fun f => Discrete.natTrans (fun j => f j.as) }
inverse :=
{ obj := fun F j => F.obj ⟨j⟩
map := fun f j => f.app ⟨j⟩ }
unitIso := Iso.refl _
counitIso := NatIso.ofComponents (fun F => (NatIso.ofComponents (fun j => Iso.refl _)
(by
rintro ⟨x⟩ ⟨y⟩ f
obtain rfl : x = y := Discrete.eq_of_hom f
obtain rfl : f = 𝟙 _ := rfl
simp))) (by aesop_cat)
end CategoryTheory
|
CategoryTheory\Elements.lean | /-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.CategoryTheory.Comma.StructuredArrow
import Mathlib.CategoryTheory.Groupoid
import Mathlib.CategoryTheory.PUnit
/-!
# The category of elements
This file defines the category of elements, also known as (a special case of) the Grothendieck
construction.
Given a functor `F : C ⥤ Type`, an object of `F.Elements` is a pair `(X : C, x : F.obj X)`.
A morphism `(X, x) ⟶ (Y, y)` is a morphism `f : X ⟶ Y` in `C`, so `F.map f` takes `x` to `y`.
## Implementation notes
This construction is equivalent to a special case of a comma construction, so this is mostly just a
more convenient API. We prove the equivalence in
`CategoryTheory.CategoryOfElements.structuredArrowEquivalence`.
## References
* [Emily Riehl, *Category Theory in Context*, Section 2.4][riehl2017]
* <https://en.wikipedia.org/wiki/Category_of_elements>
* <https://ncatlab.org/nlab/show/category+of+elements>
## Tags
category of elements, Grothendieck construction, comma category
-/
namespace CategoryTheory
universe w v u
variable {C : Type u} [Category.{v} C]
/-- The type of objects for the category of elements of a functor `F : C ⥤ Type`
is a pair `(X : C, x : F.obj X)`.
-/
def Functor.Elements (F : C ⥤ Type w) :=
Σc : C, F.obj c
/-- Constructor for the type `F.Elements` when `F` is a functor to types. -/
abbrev Functor.elementsMk (F : C ⥤ Type w) (X : C) (x : F.obj X) : F.Elements := ⟨X, x⟩
-- Porting note: added because Sigma.ext would be triggered automatically
lemma Functor.Elements.ext {F : C ⥤ Type w} (x y : F.Elements) (h₁ : x.fst = y.fst)
(h₂ : F.map (eqToHom h₁) x.snd = y.snd) : x = y := by
cases x
cases y
cases h₁
simp only [eqToHom_refl, FunctorToTypes.map_id_apply] at h₂
simp [h₂]
/-- The category structure on `F.Elements`, for `F : C ⥤ Type`.
A morphism `(X, x) ⟶ (Y, y)` is a morphism `f : X ⟶ Y` in `C`, so `F.map f` takes `x` to `y`.
-/
instance categoryOfElements (F : C ⥤ Type w) : Category.{v} F.Elements where
Hom p q := { f : p.1 ⟶ q.1 // (F.map f) p.2 = q.2 }
id p := ⟨𝟙 p.1, by aesop_cat⟩
comp {X Y Z} f g := ⟨f.val ≫ g.val, by simp [f.2, g.2]⟩
namespace CategoryOfElements
/-- Constructor for morphisms in the category of elements of a functor to types. -/
@[simps]
def homMk {F : C ⥤ Type w} (x y : F.Elements) (f : x.1 ⟶ y.1) (hf : F.map f x.snd = y.snd) :
x ⟶ y :=
⟨f, hf⟩
@[ext]
theorem ext (F : C ⥤ Type w) {x y : F.Elements} (f g : x ⟶ y) (w : f.val = g.val) : f = g :=
Subtype.ext_val w
@[simp]
theorem comp_val {F : C ⥤ Type w} {p q r : F.Elements} {f : p ⟶ q} {g : q ⟶ r} :
(f ≫ g).val = f.val ≫ g.val :=
rfl
@[simp]
theorem id_val {F : C ⥤ Type w} {p : F.Elements} : (𝟙 p : p ⟶ p).val = 𝟙 p.1 :=
rfl
@[simp]
theorem map_snd {F : C ⥤ Type w} {p q : F.Elements} (f : p ⟶ q) : (F.map f.val) p.2 = q.2 :=
f.property
end CategoryOfElements
instance groupoidOfElements {G : Type u} [Groupoid.{v} G] (F : G ⥤ Type w) :
Groupoid F.Elements where
inv {p q} f :=
⟨Groupoid.inv f.val,
calc
F.map (Groupoid.inv f.val) q.2 = F.map (Groupoid.inv f.val) (F.map f.val p.2) := by rw [f.2]
_ = (F.map f.val ≫ F.map (Groupoid.inv f.val)) p.2 := rfl
_ = p.2 := by
rw [← F.map_comp]
simp
⟩
inv_comp _ := by
ext
simp
comp_inv _ := by
ext
simp
namespace CategoryOfElements
variable (F : C ⥤ Type w)
/-- The functor out of the category of elements which forgets the element. -/
@[simps]
def π : F.Elements ⥤ C where
obj X := X.1
map f := f.val
instance : (π F).Faithful where
instance : (π F).ReflectsIsomorphisms where
reflects {X Y} f h := ⟨⟨⟨inv ((π F).map f),
by rw [← map_snd f, ← FunctorToTypes.map_comp_apply]; simp⟩, by aesop_cat⟩⟩
/-- A natural transformation between functors induces a functor between the categories of elements.
-/
@[simps]
def map {F₁ F₂ : C ⥤ Type w} (α : F₁ ⟶ F₂) : F₁.Elements ⥤ F₂.Elements where
obj t := ⟨t.1, α.app t.1 t.2⟩
map {t₁ t₂} k := ⟨k.1, by simpa [map_snd] using (FunctorToTypes.naturality _ _ α k.1 t₁.2).symm⟩
@[simp]
theorem map_π {F₁ F₂ : C ⥤ Type w} (α : F₁ ⟶ F₂) : map α ⋙ π F₂ = π F₁ :=
rfl
/-- The forward direction of the equivalence `F.Elements ≅ (*, F)`. -/
def toStructuredArrow : F.Elements ⥤ StructuredArrow PUnit F where
obj X := StructuredArrow.mk fun _ => X.2
map {X Y} f := StructuredArrow.homMk f.val (by funext; simp [f.2])
@[simp]
theorem toStructuredArrow_obj (X) :
(toStructuredArrow F).obj X =
{ left := ⟨⟨⟩⟩
right := X.1
hom := fun _ => X.2 } :=
rfl
@[simp]
theorem to_comma_map_right {X Y} (f : X ⟶ Y) : ((toStructuredArrow F).map f).right = f.val :=
rfl
/-- The reverse direction of the equivalence `F.Elements ≅ (*, F)`. -/
def fromStructuredArrow : StructuredArrow PUnit F ⥤ F.Elements where
obj X := ⟨X.right, X.hom PUnit.unit⟩
map f := ⟨f.right, congr_fun f.w.symm PUnit.unit⟩
@[simp]
theorem fromStructuredArrow_obj (X) : (fromStructuredArrow F).obj X = ⟨X.right, X.hom PUnit.unit⟩ :=
rfl
@[simp]
theorem fromStructuredArrow_map {X Y} (f : X ⟶ Y) :
(fromStructuredArrow F).map f = ⟨f.right, congr_fun f.w.symm PUnit.unit⟩ :=
rfl
/-- The equivalence between the category of elements `F.Elements`
and the comma category `(*, F)`. -/
@[simps! functor_obj functor_map inverse_obj inverse_map unitIso_hom
unitIso_inv counitIso_hom counitIso_inv]
def structuredArrowEquivalence : F.Elements ≌ StructuredArrow PUnit F :=
Equivalence.mk (toStructuredArrow F) (fromStructuredArrow F)
(NatIso.ofComponents fun X => eqToIso (by aesop_cat))
(NatIso.ofComponents fun X => StructuredArrow.isoMk (Iso.refl _))
open Opposite
/-- The forward direction of the equivalence `F.Elementsᵒᵖ ≅ (yoneda, F)`,
given by `CategoryTheory.yonedaEquiv`.
-/
@[simps]
def toCostructuredArrow (F : Cᵒᵖ ⥤ Type v) : F.Elementsᵒᵖ ⥤ CostructuredArrow yoneda F where
obj X := CostructuredArrow.mk (yonedaEquiv.symm (unop X).2)
map f := by
fapply CostructuredArrow.homMk
· exact f.unop.val.unop
· ext Z y
dsimp [yonedaEquiv]
simp only [FunctorToTypes.map_comp_apply, ← f.unop.2]
/-- The reverse direction of the equivalence `F.Elementsᵒᵖ ≅ (yoneda, F)`,
given by `CategoryTheory.yonedaEquiv`.
-/
@[simps]
def fromCostructuredArrow (F : Cᵒᵖ ⥤ Type v) : (CostructuredArrow yoneda F)ᵒᵖ ⥤ F.Elements where
obj X := ⟨op (unop X).1, yonedaEquiv.1 (unop X).3⟩
map {X Y} f :=
⟨f.unop.1.op, by
convert (congr_fun ((unop X).hom.naturality f.unop.left.op) (𝟙 _)).symm
simp only [Equiv.toFun_as_coe, Quiver.Hom.unop_op, yonedaEquiv_apply, types_comp_apply,
Category.comp_id, yoneda_obj_map]
have : yoneda.map f.unop.left ≫ (unop X).hom = (unop Y).hom := by
convert f.unop.3
erw [← this]
simp only [yoneda_map_app, FunctorToTypes.comp]
erw [Category.id_comp]⟩
@[simp]
theorem fromCostructuredArrow_obj_mk (F : Cᵒᵖ ⥤ Type v) {X : C} (f : yoneda.obj X ⟶ F) :
(fromCostructuredArrow F).obj (op (CostructuredArrow.mk f)) = ⟨op X, yonedaEquiv.1 f⟩ :=
rfl
/-- The unit of the equivalence `F.Elementsᵒᵖ ≅ (yoneda, F)` is indeed iso. -/
theorem from_toCostructuredArrow_eq (F : Cᵒᵖ ⥤ Type v) :
(toCostructuredArrow F).rightOp ⋙ fromCostructuredArrow F = 𝟭 _ := by
refine Functor.ext ?_ ?_
· intro X
exact Functor.Elements.ext _ _ rfl (by simp [yonedaEquiv])
· intro X Y f
have : ∀ {a b : F.Elements} (H : a = b),
(eqToHom H).1 = eqToHom (show a.fst = b.fst by cases H; rfl) := by
rintro _ _ rfl
simp
ext
simp [this]
/-- The counit of the equivalence `F.Elementsᵒᵖ ≅ (yoneda, F)` is indeed iso. -/
theorem to_fromCostructuredArrow_eq (F : Cᵒᵖ ⥤ Type v) :
(fromCostructuredArrow F).rightOp ⋙ toCostructuredArrow F = 𝟭 _ := by
refine Functor.ext ?_ ?_
· intro X
cases' X with X_left X_right X_hom
cases X_right
simp only [Functor.id_obj, Functor.rightOp_obj, toCostructuredArrow_obj, Functor.comp_obj,
CostructuredArrow.mk]
congr
ext x f
convert congr_fun (X_hom.naturality f.op).symm (𝟙 X_left)
simp
· aesop
/-- The equivalence `F.Elementsᵒᵖ ≅ (yoneda, F)` given by yoneda lemma. -/
@[simps! functor_obj functor_map inverse_obj inverse_map unitIso_inv counitIso_hom counitIso_inv]
def costructuredArrowYonedaEquivalence (F : Cᵒᵖ ⥤ Type v) :
F.Elementsᵒᵖ ≌ CostructuredArrow yoneda F :=
Equivalence.mk (toCostructuredArrow F) (fromCostructuredArrow F).rightOp
(NatIso.op (eqToIso (from_toCostructuredArrow_eq F))) (eqToIso <| to_fromCostructuredArrow_eq F)
-- Porting note:
-- Running `@[simps! unitIso_hom]` is mysteriously slow.
-- We separate it out to avoid needing to increase the maxHeartbeats.
attribute [simps! unitIso_hom] costructuredArrowYonedaEquivalence
/-- The equivalence `(-.Elements)ᵒᵖ ≅ (yoneda, -)` of is actually a natural isomorphism of functors.
-/
theorem costructuredArrow_yoneda_equivalence_naturality {F₁ F₂ : Cᵒᵖ ⥤ Type v} (α : F₁ ⟶ F₂) :
(map α).op ⋙ toCostructuredArrow F₂ = toCostructuredArrow F₁ ⋙ CostructuredArrow.map α := by
fapply Functor.ext
· intro X
simp only [CostructuredArrow.map_mk, toCostructuredArrow_obj, Functor.op_obj,
Functor.comp_obj]
congr
ext _ f
simpa using congr_fun (α.naturality f.op).symm (unop X).snd
· simp [autoParam]
/-- The equivalence `F.elementsᵒᵖ ≌ (yoneda, F)` is compatible with the forgetful functors. -/
@[simps!]
def costructuredArrowYonedaEquivalenceFunctorProj (F : Cᵒᵖ ⥤ Type v) :
(costructuredArrowYonedaEquivalence F).functor ⋙ CostructuredArrow.proj _ _ ≅ (π F).leftOp :=
Iso.refl _
/-- The equivalence `F.elementsᵒᵖ ≌ (yoneda, F)` is compatible with the forgetful functors. -/
@[simps!]
def costructuredArrowYonedaEquivalenceInverseπ (F : Cᵒᵖ ⥤ Type v) :
(costructuredArrowYonedaEquivalence F).inverse ⋙ (π F).leftOp ≅ CostructuredArrow.proj _ _ :=
Iso.refl _
end CategoryOfElements
namespace Functor
/--
The initial object in the category of elements for a representable functor. In `isInitial` it is
shown that this is initial.
-/
def Elements.initial (A : C) : (yoneda.obj A).Elements :=
⟨Opposite.op A, 𝟙 _⟩
/-- Show that `Elements.initial A` is initial in the category of elements for the `yoneda` functor.
-/
def Elements.isInitial (A : C) : Limits.IsInitial (Elements.initial A) where
desc s := ⟨s.pt.2.op, Category.comp_id _⟩
uniq s m _ := by
simp_rw [← m.2]
dsimp [Elements.initial]
simp
fac := by rintro s ⟨⟨⟩⟩
end Functor
end CategoryTheory
|
CategoryTheory\Elementwise.lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Tactic.CategoryTheory.Elementwise
import Mathlib.CategoryTheory.ConcreteCategory.Basic
/-!
# Use the `elementwise` attribute to create applied versions of lemmas.
Usually we would use `@[elementwise]` at the point of definition,
however some early parts of the category theory library are imported by `Tactic.Elementwise`,
so we need to add the attribute after the fact.
-/
/-! We now add some `elementwise` attributes to lemmas that were proved earlier. -/
open CategoryTheory
attribute [elementwise (attr := simp)] Iso.hom_inv_id Iso.inv_hom_id
-- This list is incomplete, and it would probably be useful to add more.
set_option linter.existingAttributeWarning false in
attribute [elementwise (attr := simp)] IsIso.hom_inv_id IsIso.inv_hom_id
|
CategoryTheory\Endomorphism.lean | /-
Copyright (c) 2019 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, Scott Morrison, Simon Hudon
-/
import Mathlib.Algebra.Group.Action.Defs
import Mathlib.Algebra.Group.Equiv.Basic
import Mathlib.Algebra.Group.Units
import Mathlib.Algebra.Group.Units.Hom
import Mathlib.CategoryTheory.Groupoid
import Mathlib.CategoryTheory.Opposites
/-!
# Endomorphisms
Definition and basic properties of endomorphisms and automorphisms of an object in a category.
For each `X : C`, we provide `CategoryTheory.End X := X ⟶ X` with a monoid structure,
and `CategoryTheory.Aut X := X ≅ X` with a group structure.
-/
universe v v' u u'
namespace CategoryTheory
/-- Endomorphisms of an object in a category. Arguments order in multiplication agrees with
`Function.comp`, not with `CategoryTheory.CategoryStruct.comp`. -/
def End {C : Type u} [CategoryStruct.{v} C] (X : C) := X ⟶ X
namespace End
section Struct
variable {C : Type u} [CategoryStruct.{v} C] (X : C)
protected instance one : One (End X) := ⟨𝟙 X⟩
protected instance inhabited : Inhabited (End X) := ⟨𝟙 X⟩
/-- Multiplication of endomorphisms agrees with `Function.comp`, not with
`CategoryTheory.CategoryStruct.comp`. -/
protected instance mul : Mul (End X) := ⟨fun x y => y ≫ x⟩
variable {X}
/-- Assist the typechecker by expressing a morphism `X ⟶ X` as a term of `CategoryTheory.End X`. -/
def of (f : X ⟶ X) : End X := f
/-- Assist the typechecker by expressing an endomorphism `f : CategoryTheory.End X` as a term of
`X ⟶ X`. -/
def asHom (f : End X) : X ⟶ X := f
-- dsimp loops when applying this lemma to its LHS,
-- probably https://github.com/leanprover/lean4/pull/2867
@[simp, nolint simpNF] -- Porting note (#11215): TODO: use `of`/`asHom`?
theorem one_def : (1 : End X) = 𝟙 X := rfl
@[simp] -- Porting note (#11215): TODO: use `of`/`asHom`?
theorem mul_def (xs ys : End X) : xs * ys = ys ≫ xs := rfl
end Struct
/-- Endomorphisms of an object form a monoid -/
instance monoid {C : Type u} [Category.{v} C] {X : C} : Monoid (End X) where
mul_one := Category.id_comp
one_mul := Category.comp_id
mul_assoc := fun x y z => (Category.assoc z y x).symm
section MulAction
variable {C : Type u} [Category.{v} C]
open Opposite
instance mulActionRight {X Y : C} : MulAction (End Y) (X ⟶ Y) where
smul r f := f ≫ r
one_smul := Category.comp_id
mul_smul _ _ _ := Eq.symm <| Category.assoc _ _ _
instance mulActionLeft {X : Cᵒᵖ} {Y : C} : MulAction (End X) (unop X ⟶ Y) where
smul r f := r.unop ≫ f
one_smul := Category.id_comp
mul_smul _ _ _ := Category.assoc _ _ _
theorem smul_right {X Y : C} {r : End Y} {f : X ⟶ Y} : r • f = f ≫ r :=
rfl
theorem smul_left {X : Cᵒᵖ} {Y : C} {r : End X} {f : unop X ⟶ Y} : r • f = r.unop ≫ f :=
rfl
end MulAction
/-- In a groupoid, endomorphisms form a group -/
instance group {C : Type u} [Groupoid.{v} C] (X : C) : Group (End X) where
mul_left_inv := Groupoid.comp_inv
inv := Groupoid.inv
end End
theorem isUnit_iff_isIso {C : Type u} [Category.{v} C] {X : C} (f : End X) :
IsUnit (f : End X) ↔ IsIso f :=
⟨fun h => { out := ⟨h.unit.inv, ⟨h.unit.inv_val, h.unit.val_inv⟩⟩ }, fun h =>
⟨⟨f, inv f, by simp, by simp⟩, rfl⟩⟩
variable {C : Type u} [Category.{v} C] (X : C)
/-- Automorphisms of an object in a category.
The order of arguments in multiplication agrees with
`Function.comp`, not with `CategoryTheory.CategoryStruct.comp`.
-/
def Aut (X : C) := X ≅ X
namespace Aut
-- Porting note: added because `Iso.ext` is not triggered automatically
@[ext]
lemma ext {X : C} {φ₁ φ₂ : Aut X} (h : φ₁.hom = φ₂.hom) : φ₁ = φ₂ :=
Iso.ext h
protected instance inhabited : Inhabited (Aut X) := ⟨Iso.refl X⟩
instance : Group (Aut X) where
one := Iso.refl X
inv := Iso.symm
mul x y := Iso.trans y x
mul_assoc _ _ _ := (Iso.trans_assoc _ _ _).symm
one_mul := Iso.trans_refl
mul_one := Iso.refl_trans
mul_left_inv := Iso.self_symm_id
theorem Aut_mul_def (f g : Aut X) : f * g = g.trans f := rfl
theorem Aut_inv_def (f : Aut X) : f⁻¹ = f.symm := rfl
/-- Units in the monoid of endomorphisms of an object
are (multiplicatively) equivalent to automorphisms of that object.
-/
def unitsEndEquivAut : (End X)ˣ ≃* Aut X where
toFun f := ⟨f.1, f.2, f.4, f.3⟩
invFun f := ⟨f.1, f.2, f.4, f.3⟩
left_inv := fun ⟨f₁, f₂, f₃, f₄⟩ => rfl
right_inv := fun ⟨f₁, f₂, f₃, f₄⟩ => rfl
map_mul' f g := by cases f; cases g; rfl
/-- The inclusion of `Aut X` to `End X` as a monoid homomorphism. -/
@[simps!]
def toEnd (X : C) : Aut X →* End X := (Units.coeHom (End X)).comp (Aut.unitsEndEquivAut X).symm
/-- Isomorphisms induce isomorphisms of the automorphism group -/
def autMulEquivOfIso {X Y : C} (h : X ≅ Y) : Aut X ≃* Aut Y where
toFun x := { hom := h.inv ≫ x.hom ≫ h.hom, inv := h.inv ≫ x.inv ≫ h.hom }
invFun y := { hom := h.hom ≫ y.hom ≫ h.inv, inv := h.hom ≫ y.inv ≫ h.inv }
left_inv _ := by aesop_cat
right_inv _ := by aesop_cat
map_mul' := by simp [Aut_mul_def]
end Aut
namespace Functor
variable {D : Type u'} [Category.{v'} D] (f : C ⥤ D)
/-- `f.map` as a monoid hom between endomorphism monoids. -/
@[simps]
def mapEnd : End X →* End (f.obj X) where
toFun := f.map
map_mul' x y := f.map_comp y x
map_one' := f.map_id X
/-- `f.mapIso` as a group hom between automorphism groups. -/
def mapAut : Aut X →* Aut (f.obj X) where
toFun := f.mapIso
map_mul' x y := f.mapIso_trans y x
map_one' := f.mapIso_refl X
namespace FullyFaithful
variable {f}
variable (hf : FullyFaithful f)
/-- `mulEquivEnd` as an isomorphism between endomorphism monoids. -/
@[simps!]
noncomputable def mulEquivEnd (X : C) :
End X ≃* End (f.obj X) where
toEquiv := hf.homEquiv
__ := mapEnd X f
/-- `mulEquivAut` as an isomorphism between automorphism groups. -/
@[simps!]
noncomputable def autMulEquivOfFullyFaithful (X : C) :
Aut X ≃* Aut (f.obj X) where
toEquiv := hf.isoEquiv
__ := mapAut X f
end FullyFaithful
end Functor
end CategoryTheory
|
CategoryTheory\EpiMono.lean | /-
Copyright (c) 2019 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Scott Morrison
-/
import Mathlib.CategoryTheory.Opposites
import Mathlib.CategoryTheory.Groupoid
/-!
# Facts about epimorphisms and monomorphisms.
The definitions of `Epi` and `Mono` are in `CategoryTheory.Category`,
since they are used by some lemmas for `Iso`, which is used everywhere.
-/
universe v₁ v₂ u₁ u₂
namespace CategoryTheory
variable {C : Type u₁} [Category.{v₁} C]
instance unop_mono_of_epi {A B : Cᵒᵖ} (f : A ⟶ B) [Epi f] : Mono f.unop :=
⟨fun _ _ eq => Quiver.Hom.op_inj ((cancel_epi f).1 (Quiver.Hom.unop_inj eq))⟩
instance unop_epi_of_mono {A B : Cᵒᵖ} (f : A ⟶ B) [Mono f] : Epi f.unop :=
⟨fun _ _ eq => Quiver.Hom.op_inj ((cancel_mono f).1 (Quiver.Hom.unop_inj eq))⟩
instance op_mono_of_epi {A B : C} (f : A ⟶ B) [Epi f] : Mono f.op :=
⟨fun _ _ eq => Quiver.Hom.unop_inj ((cancel_epi f).1 (Quiver.Hom.op_inj eq))⟩
instance op_epi_of_mono {A B : C} (f : A ⟶ B) [Mono f] : Epi f.op :=
⟨fun _ _ eq => Quiver.Hom.unop_inj ((cancel_mono f).1 (Quiver.Hom.op_inj eq))⟩
/-- A split monomorphism is a morphism `f : X ⟶ Y` with a given retraction `retraction f : Y ⟶ X`
such that `f ≫ retraction f = 𝟙 X`.
Every split monomorphism is a monomorphism.
-/
/- Porting note(#5171): removed @[nolint has_nonempty_instance] -/
/- Porting note: `@[ext]` used to accept lemmas like this. Now we add an aesop rule -/
@[ext, aesop apply safe (rule_sets := [CategoryTheory])]
structure SplitMono {X Y : C} (f : X ⟶ Y) where
/-- The map splitting `f` -/
retraction : Y ⟶ X
/-- `f` composed with `retraction` is the identity -/
id : f ≫ retraction = 𝟙 X := by aesop_cat
attribute [reassoc (attr := simp)] SplitMono.id
/-- `IsSplitMono f` is the assertion that `f` admits a retraction -/
class IsSplitMono {X Y : C} (f : X ⟶ Y) : Prop where
/-- There is a splitting -/
exists_splitMono : Nonempty (SplitMono f)
/-- A constructor for `IsSplitMono f` taking a `SplitMono f` as an argument -/
theorem IsSplitMono.mk' {X Y : C} {f : X ⟶ Y} (sm : SplitMono f) : IsSplitMono f :=
⟨Nonempty.intro sm⟩
/-- A split epimorphism is a morphism `f : X ⟶ Y` with a given section `section_ f : Y ⟶ X`
such that `section_ f ≫ f = 𝟙 Y`.
(Note that `section` is a reserved keyword, so we append an underscore.)
Every split epimorphism is an epimorphism.
-/
/- Porting note(#5171): removed @[nolint has_nonempty_instance] -/
/- Porting note: `@[ext]` used to accept lemmas like this. Now we add an aesop rule -/
@[ext, aesop apply safe (rule_sets := [CategoryTheory])]
structure SplitEpi {X Y : C} (f : X ⟶ Y) where
/-- The map splitting `f` -/
section_ : Y ⟶ X
/-- `section_` composed with `f` is the identity -/
id : section_ ≫ f = 𝟙 Y := by aesop_cat
attribute [reassoc (attr := simp)] SplitEpi.id
/-- `IsSplitEpi f` is the assertion that `f` admits a section -/
class IsSplitEpi {X Y : C} (f : X ⟶ Y) : Prop where
/-- There is a splitting -/
exists_splitEpi : Nonempty (SplitEpi f)
/-- A constructor for `IsSplitEpi f` taking a `SplitEpi f` as an argument -/
theorem IsSplitEpi.mk' {X Y : C} {f : X ⟶ Y} (se : SplitEpi f) : IsSplitEpi f :=
⟨Nonempty.intro se⟩
/-- The chosen retraction of a split monomorphism. -/
noncomputable def retraction {X Y : C} (f : X ⟶ Y) [hf : IsSplitMono f] : Y ⟶ X :=
hf.exists_splitMono.some.retraction
@[reassoc (attr := simp)]
theorem IsSplitMono.id {X Y : C} (f : X ⟶ Y) [hf : IsSplitMono f] : f ≫ retraction f = 𝟙 X :=
hf.exists_splitMono.some.id
/-- The retraction of a split monomorphism has an obvious section. -/
def SplitMono.splitEpi {X Y : C} {f : X ⟶ Y} (sm : SplitMono f) : SplitEpi sm.retraction where
section_ := f
/-- The retraction of a split monomorphism is itself a split epimorphism. -/
instance retraction_isSplitEpi {X Y : C} (f : X ⟶ Y) [IsSplitMono f] :
IsSplitEpi (retraction f) :=
IsSplitEpi.mk' (SplitMono.splitEpi _)
/-- A split mono which is epi is an iso. -/
theorem isIso_of_epi_of_isSplitMono {X Y : C} (f : X ⟶ Y) [IsSplitMono f] [Epi f] : IsIso f :=
⟨⟨retraction f, ⟨by simp, by simp [← cancel_epi f]⟩⟩⟩
/-- The chosen section of a split epimorphism.
(Note that `section` is a reserved keyword, so we append an underscore.)
-/
noncomputable def section_ {X Y : C} (f : X ⟶ Y) [hf : IsSplitEpi f] : Y ⟶ X :=
hf.exists_splitEpi.some.section_
@[reassoc (attr := simp)]
theorem IsSplitEpi.id {X Y : C} (f : X ⟶ Y) [hf : IsSplitEpi f] : section_ f ≫ f = 𝟙 Y :=
hf.exists_splitEpi.some.id
/-- The section of a split epimorphism has an obvious retraction. -/
def SplitEpi.splitMono {X Y : C} {f : X ⟶ Y} (se : SplitEpi f) : SplitMono se.section_ where
retraction := f
/-- The section of a split epimorphism is itself a split monomorphism. -/
instance section_isSplitMono {X Y : C} (f : X ⟶ Y) [IsSplitEpi f] : IsSplitMono (section_ f) :=
IsSplitMono.mk' (SplitEpi.splitMono _)
/-- A split epi which is mono is an iso. -/
theorem isIso_of_mono_of_isSplitEpi {X Y : C} (f : X ⟶ Y) [Mono f] [IsSplitEpi f] : IsIso f :=
⟨⟨section_ f, ⟨by simp [← cancel_mono f], by simp⟩⟩⟩
/-- Every iso is a split mono. -/
instance (priority := 100) IsSplitMono.of_iso {X Y : C} (f : X ⟶ Y) [IsIso f] : IsSplitMono f :=
IsSplitMono.mk' { retraction := inv f }
/-- Every iso is a split epi. -/
instance (priority := 100) IsSplitEpi.of_iso {X Y : C} (f : X ⟶ Y) [IsIso f] : IsSplitEpi f :=
IsSplitEpi.mk' { section_ := inv f }
theorem SplitMono.mono {X Y : C} {f : X ⟶ Y} (sm : SplitMono f) : Mono f :=
{ right_cancellation := fun g h w => by replace w := w =≫ sm.retraction; simpa using w }
/-- Every split mono is a mono. -/
instance (priority := 100) IsSplitMono.mono {X Y : C} (f : X ⟶ Y) [hf : IsSplitMono f] : Mono f :=
hf.exists_splitMono.some.mono
theorem SplitEpi.epi {X Y : C} {f : X ⟶ Y} (se : SplitEpi f) : Epi f :=
{ left_cancellation := fun g h w => by replace w := se.section_ ≫= w; simpa using w }
/-- Every split epi is an epi. -/
instance (priority := 100) IsSplitEpi.epi {X Y : C} (f : X ⟶ Y) [hf : IsSplitEpi f] : Epi f :=
hf.exists_splitEpi.some.epi
/-- Every split mono whose retraction is mono is an iso. -/
theorem IsIso.of_mono_retraction' {X Y : C} {f : X ⟶ Y} (hf : SplitMono f) [Mono <| hf.retraction] :
IsIso f :=
⟨⟨hf.retraction, ⟨by simp, (cancel_mono_id <| hf.retraction).mp (by simp)⟩⟩⟩
/-- Every split mono whose retraction is mono is an iso. -/
theorem IsIso.of_mono_retraction {X Y : C} (f : X ⟶ Y) [hf : IsSplitMono f]
[hf' : Mono <| retraction f] : IsIso f :=
@IsIso.of_mono_retraction' _ _ _ _ _ hf.exists_splitMono.some hf'
/-- Every split epi whose section is epi is an iso. -/
theorem IsIso.of_epi_section' {X Y : C} {f : X ⟶ Y} (hf : SplitEpi f) [Epi <| hf.section_] :
IsIso f :=
⟨⟨hf.section_, ⟨(cancel_epi_id <| hf.section_).mp (by simp), by simp⟩⟩⟩
/-- Every split epi whose section is epi is an iso. -/
theorem IsIso.of_epi_section {X Y : C} (f : X ⟶ Y) [hf : IsSplitEpi f] [hf' : Epi <| section_ f] :
IsIso f :=
@IsIso.of_epi_section' _ _ _ _ _ hf.exists_splitEpi.some hf'
-- FIXME this has unnecessarily become noncomputable!
/-- A category where every morphism has a `Trunc` retraction is computably a groupoid. -/
noncomputable def Groupoid.ofTruncSplitMono
(all_split_mono : ∀ {X Y : C} (f : X ⟶ Y), Trunc (IsSplitMono f)) : Groupoid.{v₁} C := by
apply Groupoid.ofIsIso
intro X Y f
have ⟨a,_⟩ := Trunc.exists_rep <| all_split_mono f
have ⟨b,_⟩ := Trunc.exists_rep <| all_split_mono <| retraction f
apply IsIso.of_mono_retraction
section
variable (C)
/-- A split mono category is a category in which every monomorphism is split. -/
class SplitMonoCategory : Prop where
/-- All monos are split -/
isSplitMono_of_mono : ∀ {X Y : C} (f : X ⟶ Y) [Mono f], IsSplitMono f
/-- A split epi category is a category in which every epimorphism is split. -/
class SplitEpiCategory : Prop where
/-- All epis are split -/
isSplitEpi_of_epi : ∀ {X Y : C} (f : X ⟶ Y) [Epi f], IsSplitEpi f
end
/-- In a category in which every monomorphism is split, every monomorphism splits. This is not an
instance because it would create an instance loop. -/
theorem isSplitMono_of_mono [SplitMonoCategory C] {X Y : C} (f : X ⟶ Y) [Mono f] : IsSplitMono f :=
SplitMonoCategory.isSplitMono_of_mono _
/-- In a category in which every epimorphism is split, every epimorphism splits. This is not an
instance because it would create an instance loop. -/
theorem isSplitEpi_of_epi [SplitEpiCategory C] {X Y : C} (f : X ⟶ Y) [Epi f] : IsSplitEpi f :=
SplitEpiCategory.isSplitEpi_of_epi _
section
variable {D : Type u₂} [Category.{v₂} D]
/-- Split monomorphisms are also absolute monomorphisms. -/
@[simps]
def SplitMono.map {X Y : C} {f : X ⟶ Y} (sm : SplitMono f) (F : C ⥤ D) : SplitMono (F.map f) where
retraction := F.map sm.retraction
id := by rw [← Functor.map_comp, SplitMono.id, Functor.map_id]
/-- Split epimorphisms are also absolute epimorphisms. -/
@[simps]
def SplitEpi.map {X Y : C} {f : X ⟶ Y} (se : SplitEpi f) (F : C ⥤ D) : SplitEpi (F.map f) where
section_ := F.map se.section_
id := by rw [← Functor.map_comp, SplitEpi.id, Functor.map_id]
instance {X Y : C} (f : X ⟶ Y) [hf : IsSplitMono f] (F : C ⥤ D) : IsSplitMono (F.map f) :=
IsSplitMono.mk' (hf.exists_splitMono.some.map F)
instance {X Y : C} (f : X ⟶ Y) [hf : IsSplitEpi f] (F : C ⥤ D) : IsSplitEpi (F.map f) :=
IsSplitEpi.mk' (hf.exists_splitEpi.some.map F)
end
end CategoryTheory
|
CategoryTheory\EqToHom.lean | /-
Copyright (c) 2018 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Scott Morrison
-/
import Mathlib.CategoryTheory.Opposites
/-!
# Morphisms from equations between objects.
When working categorically, sometimes one encounters an equation `h : X = Y` between objects.
Your initial aversion to this is natural and appropriate:
you're in for some trouble, and if there is another way to approach the problem that won't
rely on this equality, it may be worth pursuing.
You have two options:
1. Use the equality `h` as one normally would in Lean (e.g. using `rw` and `subst`).
This may immediately cause difficulties, because in category theory everything is dependently
typed, and equations between objects quickly lead to nasty goals with `eq.rec`.
2. Promote `h` to a morphism using `eqToHom h : X ⟶ Y`, or `eqToIso h : X ≅ Y`.
This file introduces various `simp` lemmas which in favourable circumstances
result in the various `eqToHom` morphisms to drop out at the appropriate moment!
-/
universe v₁ v₂ v₃ u₁ u₂ u₃
-- morphism levels before object levels. See note [CategoryTheory universes].
namespace CategoryTheory
open Opposite
variable {C : Type u₁} [Category.{v₁} C]
/-- An equality `X = Y` gives us a morphism `X ⟶ Y`.
It is typically better to use this, rather than rewriting by the equality then using `𝟙 _`
which usually leads to dependent type theory hell.
-/
def eqToHom {X Y : C} (p : X = Y) : X ⟶ Y := by rw [p]; exact 𝟙 _
@[simp]
theorem eqToHom_refl (X : C) (p : X = X) : eqToHom p = 𝟙 X :=
rfl
@[reassoc (attr := simp)]
theorem eqToHom_trans {X Y Z : C} (p : X = Y) (q : Y = Z) :
eqToHom p ≫ eqToHom q = eqToHom (p.trans q) := by
cases p
cases q
simp
theorem comp_eqToHom_iff {X Y Y' : C} (p : Y = Y') (f : X ⟶ Y) (g : X ⟶ Y') :
f ≫ eqToHom p = g ↔ f = g ≫ eqToHom p.symm :=
{ mp := fun h => h ▸ by simp
mpr := fun h => by simp [eq_whisker h (eqToHom p)] }
theorem eqToHom_comp_iff {X X' Y : C} (p : X = X') (f : X ⟶ Y) (g : X' ⟶ Y) :
eqToHom p ≫ g = f ↔ g = eqToHom p.symm ≫ f :=
{ mp := fun h => h ▸ by simp
mpr := fun h => h ▸ by simp [whisker_eq _ h] }
variable {β : Sort*}
/-- We can push `eqToHom` to the left through families of morphisms. -/
-- The simpNF linter incorrectly claims that this will never apply.
-- https://github.com/leanprover-community/mathlib4/issues/5049
@[reassoc (attr := simp, nolint simpNF)]
theorem eqToHom_naturality {f g : β → C} (z : ∀ b, f b ⟶ g b) {j j' : β} (w : j = j') :
z j ≫ eqToHom (by simp [w]) = eqToHom (by simp [w]) ≫ z j' := by
cases w
simp
/-- A variant on `eqToHom_naturality` that helps Lean identify the families `f` and `g`. -/
-- The simpNF linter incorrectly claims that this will never apply.
-- https://github.com/leanprover-community/mathlib4/issues/5049
@[reassoc (attr := simp, nolint simpNF)]
theorem eqToHom_iso_hom_naturality {f g : β → C} (z : ∀ b, f b ≅ g b) {j j' : β} (w : j = j') :
(z j).hom ≫ eqToHom (by simp [w]) = eqToHom (by simp [w]) ≫ (z j').hom := by
cases w
simp
/-- A variant on `eqToHom_naturality` that helps Lean identify the families `f` and `g`. -/
-- The simpNF linter incorrectly claims that this will never apply.
-- https://github.com/leanprover-community/mathlib4/issues/5049
@[reassoc (attr := simp, nolint simpNF)]
theorem eqToHom_iso_inv_naturality {f g : β → C} (z : ∀ b, f b ≅ g b) {j j' : β} (w : j = j') :
(z j).inv ≫ eqToHom (by simp [w]) = eqToHom (by simp [w]) ≫ (z j').inv := by
cases w
simp
/-- Reducible form of congrArg_mpr_hom_left -/
@[simp]
theorem congrArg_cast_hom_left {X Y Z : C} (p : X = Y) (q : Y ⟶ Z) :
cast (congrArg (fun W : C => W ⟶ Z) p.symm) q = eqToHom p ≫ q := by
cases p
simp
/-- If we (perhaps unintentionally) perform equational rewriting on
the source object of a morphism,
we can replace the resulting `_.mpr f` term by a composition with an `eqToHom`.
It may be advisable to introduce any necessary `eqToHom` morphisms manually,
rather than relying on this lemma firing.
-/
theorem congrArg_mpr_hom_left {X Y Z : C} (p : X = Y) (q : Y ⟶ Z) :
(congrArg (fun W : C => W ⟶ Z) p).mpr q = eqToHom p ≫ q := by
cases p
simp
/-- Reducible form of `congrArg_mpr_hom_right` -/
@[simp]
theorem congrArg_cast_hom_right {X Y Z : C} (p : X ⟶ Y) (q : Z = Y) :
cast (congrArg (fun W : C => X ⟶ W) q.symm) p = p ≫ eqToHom q.symm := by
cases q
simp
/-- If we (perhaps unintentionally) perform equational rewriting on
the target object of a morphism,
we can replace the resulting `_.mpr f` term by a composition with an `eqToHom`.
It may be advisable to introduce any necessary `eqToHom` morphisms manually,
rather than relying on this lemma firing.
-/
theorem congrArg_mpr_hom_right {X Y Z : C} (p : X ⟶ Y) (q : Z = Y) :
(congrArg (fun W : C => X ⟶ W) q).mpr p = p ≫ eqToHom q.symm := by
cases q
simp
/-- An equality `X = Y` gives us an isomorphism `X ≅ Y`.
It is typically better to use this, rather than rewriting by the equality then using `Iso.refl _`
which usually leads to dependent type theory hell.
-/
def eqToIso {X Y : C} (p : X = Y) : X ≅ Y :=
⟨eqToHom p, eqToHom p.symm, by simp, by simp⟩
@[simp]
theorem eqToIso.hom {X Y : C} (p : X = Y) : (eqToIso p).hom = eqToHom p :=
rfl
@[simp]
theorem eqToIso.inv {X Y : C} (p : X = Y) : (eqToIso p).inv = eqToHom p.symm :=
rfl
@[simp]
theorem eqToIso_refl {X : C} (p : X = X) : eqToIso p = Iso.refl X :=
rfl
@[simp]
theorem eqToIso_trans {X Y Z : C} (p : X = Y) (q : Y = Z) :
eqToIso p ≪≫ eqToIso q = eqToIso (p.trans q) := by ext; simp
@[simp]
theorem eqToHom_op {X Y : C} (h : X = Y) : (eqToHom h).op = eqToHom (congr_arg op h.symm) := by
cases h
rfl
@[simp]
theorem eqToHom_unop {X Y : Cᵒᵖ} (h : X = Y) :
(eqToHom h).unop = eqToHom (congr_arg unop h.symm) := by
cases h
rfl
instance {X Y : C} (h : X = Y) : IsIso (eqToHom h) :=
(eqToIso h).isIso_hom
@[simp]
theorem inv_eqToHom {X Y : C} (h : X = Y) : inv (eqToHom h) = eqToHom h.symm := by
aesop_cat
variable {D : Type u₂} [Category.{v₂} D]
namespace Functor
/-- Proving equality between functors. This isn't an extensionality lemma,
because usually you don't really want to do this. -/
theorem ext {F G : C ⥤ D} (h_obj : ∀ X, F.obj X = G.obj X)
(h_map : ∀ X Y f,
F.map f = eqToHom (h_obj X) ≫ G.map f ≫ eqToHom (h_obj Y).symm := by aesop_cat) :
F = G := by
match F, G with
| mk F_pre _ _ , mk G_pre _ _ =>
match F_pre, G_pre with -- Porting note: did not unfold the Prefunctor unlike Lean3
| Prefunctor.mk F_obj _ , Prefunctor.mk G_obj _ =>
obtain rfl : F_obj = G_obj := by
ext X
apply h_obj
congr
funext X Y f
simpa using h_map X Y f
lemma ext_of_iso {F G : C ⥤ D} (e : F ≅ G) (hobj : ∀ X, F.obj X = G.obj X)
(happ : ∀ X, e.hom.app X = eqToHom (hobj X)) : F = G :=
Functor.ext hobj (fun X Y f => by
rw [← cancel_mono (e.hom.app Y), e.hom.naturality f, happ, happ, Category.assoc,
Category.assoc, eqToHom_trans, eqToHom_refl, Category.comp_id])
/-- Two morphisms are conjugate via eqToHom if and only if they are heterogeneously equal. -/
theorem conj_eqToHom_iff_heq {W X Y Z : C} (f : W ⟶ X) (g : Y ⟶ Z) (h : W = Y) (h' : X = Z) :
f = eqToHom h ≫ g ≫ eqToHom h'.symm ↔ HEq f g := by
cases h
cases h'
simp
/-- Proving equality between functors using heterogeneous equality. -/
theorem hext {F G : C ⥤ D} (h_obj : ∀ X, F.obj X = G.obj X)
(h_map : ∀ (X Y) (f : X ⟶ Y), HEq (F.map f) (G.map f)) : F = G :=
Functor.ext h_obj fun _ _ f => (conj_eqToHom_iff_heq _ _ (h_obj _) (h_obj _)).2 <| h_map _ _ f
-- Using equalities between functors.
theorem congr_obj {F G : C ⥤ D} (h : F = G) (X) : F.obj X = G.obj X := by rw [h]
theorem congr_hom {F G : C ⥤ D} (h : F = G) {X Y} (f : X ⟶ Y) :
F.map f = eqToHom (congr_obj h X) ≫ G.map f ≫ eqToHom (congr_obj h Y).symm := by
subst h; simp
theorem congr_inv_of_congr_hom (F G : C ⥤ D) {X Y : C} (e : X ≅ Y) (hX : F.obj X = G.obj X)
(hY : F.obj Y = G.obj Y)
(h₂ : F.map e.hom = eqToHom (by rw [hX]) ≫ G.map e.hom ≫ eqToHom (by rw [hY])) :
F.map e.inv = eqToHom (by rw [hY]) ≫ G.map e.inv ≫ eqToHom (by rw [hX]) := by
simp only [← IsIso.Iso.inv_hom e, Functor.map_inv, h₂, IsIso.inv_comp, inv_eqToHom,
Category.assoc]
section HEq
-- Composition of functors and maps w.r.t. heq
variable {E : Type u₃} [Category.{v₃} E] {F G : C ⥤ D} {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z}
theorem map_comp_heq (hx : F.obj X = G.obj X) (hy : F.obj Y = G.obj Y) (hz : F.obj Z = G.obj Z)
(hf : HEq (F.map f) (G.map f)) (hg : HEq (F.map g) (G.map g)) :
HEq (F.map (f ≫ g)) (G.map (f ≫ g)) := by
rw [F.map_comp, G.map_comp]
congr
theorem map_comp_heq' (hobj : ∀ X : C, F.obj X = G.obj X)
(hmap : ∀ {X Y} (f : X ⟶ Y), HEq (F.map f) (G.map f)) :
HEq (F.map (f ≫ g)) (G.map (f ≫ g)) := by
rw [Functor.hext hobj fun _ _ => hmap]
theorem precomp_map_heq (H : E ⥤ C) (hmap : ∀ {X Y} (f : X ⟶ Y), HEq (F.map f) (G.map f)) {X Y : E}
(f : X ⟶ Y) : HEq ((H ⋙ F).map f) ((H ⋙ G).map f) :=
hmap _
theorem postcomp_map_heq (H : D ⥤ E) (hx : F.obj X = G.obj X) (hy : F.obj Y = G.obj Y)
(hmap : HEq (F.map f) (G.map f)) : HEq ((F ⋙ H).map f) ((G ⋙ H).map f) := by
dsimp
congr
theorem postcomp_map_heq' (H : D ⥤ E) (hobj : ∀ X : C, F.obj X = G.obj X)
(hmap : ∀ {X Y} (f : X ⟶ Y), HEq (F.map f) (G.map f)) :
HEq ((F ⋙ H).map f) ((G ⋙ H).map f) := by rw [Functor.hext hobj fun _ _ => hmap]
theorem hcongr_hom {F G : C ⥤ D} (h : F = G) {X Y} (f : X ⟶ Y) : HEq (F.map f) (G.map f) := by
rw [h]
end HEq
end Functor
/-- This is not always a good idea as a `@[simp]` lemma,
as we lose the ability to use results that interact with `F`,
e.g. the naturality of a natural transformation.
In some files it may be appropriate to use `attribute [local simp] eqToHom_map`, however.
-/
theorem eqToHom_map (F : C ⥤ D) {X Y : C} (p : X = Y) :
F.map (eqToHom p) = eqToHom (congr_arg F.obj p) := by cases p; simp
@[reassoc (attr := simp)]
theorem eqToHom_map_comp (F : C ⥤ D) {X Y Z : C} (p : X = Y) (q : Y = Z) :
F.map (eqToHom p) ≫ F.map (eqToHom q) = F.map (eqToHom <| p.trans q) := by aesop_cat
/-- See the note on `eqToHom_map` regarding using this as a `simp` lemma.
-/
theorem eqToIso_map (F : C ⥤ D) {X Y : C} (p : X = Y) :
F.mapIso (eqToIso p) = eqToIso (congr_arg F.obj p) := by ext; cases p; simp
@[simp]
theorem eqToIso_map_trans (F : C ⥤ D) {X Y Z : C} (p : X = Y) (q : Y = Z) :
F.mapIso (eqToIso p) ≪≫ F.mapIso (eqToIso q) = F.mapIso (eqToIso <| p.trans q) := by aesop_cat
@[simp]
theorem eqToHom_app {F G : C ⥤ D} (h : F = G) (X : C) :
(eqToHom h : F ⟶ G).app X = eqToHom (Functor.congr_obj h X) := by subst h; rfl
theorem NatTrans.congr {F G : C ⥤ D} (α : F ⟶ G) {X Y : C} (h : X = Y) :
α.app X = F.map (eqToHom h) ≫ α.app Y ≫ G.map (eqToHom h.symm) := by
rw [α.naturality_assoc]
simp [eqToHom_map]
theorem eq_conj_eqToHom {X Y : C} (f : X ⟶ Y) : f = eqToHom rfl ≫ f ≫ eqToHom rfl := by
simp only [Category.id_comp, eqToHom_refl, Category.comp_id]
theorem dcongr_arg {ι : Type*} {F G : ι → C} (α : ∀ i, F i ⟶ G i) {i j : ι} (h : i = j) :
α i = eqToHom (congr_arg F h) ≫ α j ≫ eqToHom (congr_arg G h.symm) := by
subst h
simp
end CategoryTheory
|
CategoryTheory\Equivalence.lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Tim Baumann, Stephen Morgan, Scott Morrison, Floris van Doorn
-/
import Mathlib.CategoryTheory.Functor.FullyFaithful
import Mathlib.CategoryTheory.FullSubcategory
import Mathlib.CategoryTheory.Whiskering
import Mathlib.CategoryTheory.EssentialImage
import Mathlib.Tactic.CategoryTheory.Slice
/-!
# Equivalence of categories
An equivalence of categories `C` and `D` is a pair of functors `F : C ⥤ D` and `G : D ⥤ C` such
that `η : 𝟭 C ≅ F ⋙ G` and `ε : G ⋙ F ≅ 𝟭 D`. In many situations, equivalences are a better
notion of "sameness" of categories than the stricter isomorphism of categories.
Recall that one way to express that two functors `F : C ⥤ D` and `G : D ⥤ C` are adjoint is using
two natural transformations `η : 𝟭 C ⟶ F ⋙ G` and `ε : G ⋙ F ⟶ 𝟭 D`, called the unit and the
counit, such that the compositions `F ⟶ FGF ⟶ F` and `G ⟶ GFG ⟶ G` are the identity. Unfortunately,
it is not the case that the natural isomorphisms `η` and `ε` in the definition of an equivalence
automatically give an adjunction. However, it is true that
* if one of the two compositions is the identity, then so is the other, and
* given an equivalence of categories, it is always possible to refine `η` in such a way that the
identities are satisfied.
For this reason, in mathlib we define an equivalence to be a "half-adjoint equivalence", which is
a tuple `(F, G, η, ε)` as in the first paragraph such that the composite `F ⟶ FGF ⟶ F` is the
identity. By the remark above, this already implies that the tuple is an "adjoint equivalence",
i.e., that the composite `G ⟶ GFG ⟶ G` is also the identity.
We also define essentially surjective functors and show that a functor is an equivalence if and only
if it is full, faithful and essentially surjective.
## Main definitions
* `Equivalence`: bundled (half-)adjoint equivalences of categories
* `Functor.EssSurj`: type class on a functor `F` containing the data of the preimages
and the isomorphisms `F.obj (preimage d) ≅ d`.
* `Functor.IsEquivalence`: type class on a functor `F` which is full, faithful and
essentially surjective.
## Main results
* `Equivalence.mk`: upgrade an equivalence to a (half-)adjoint equivalence
* `isEquivalence_iff_of_iso`: when `F` and `G` are isomorphic functors,
`F` is an equivalence iff `G` is.
* `Functor.asEquivalenceFunctor`: construction of an equivalence of categories from
a functor `F` which satisfies the property `F.IsEquivalence` (i.e. `F` is full, faithful
and essentially surjective).
## Notations
We write `C ≌ D` (`\backcong`, not to be confused with `≅`/`\cong`) for a bundled equivalence.
-/
namespace CategoryTheory
open CategoryTheory.Functor NatIso Category
-- declare the `v`'s first; see `CategoryTheory.Category` for an explanation
universe v₁ v₂ v₃ u₁ u₂ u₃
/-- We define an equivalence as a (half)-adjoint equivalence, a pair of functors with
a unit and counit which are natural isomorphisms and the triangle law `Fη ≫ εF = 1`, or in other
words the composite `F ⟶ FGF ⟶ F` is the identity.
In `unit_inverse_comp`, we show that this is actually an adjoint equivalence, i.e., that the
composite `G ⟶ GFG ⟶ G` is also the identity.
The triangle equation is written as a family of equalities between morphisms, it is more
complicated if we write it as an equality of natural transformations, because then we would have
to insert natural transformations like `F ⟶ F1`.
See <https://stacks.math.columbia.edu/tag/001J>
-/
@[ext]
structure Equivalence (C : Type u₁) (D : Type u₂) [Category.{v₁} C] [Category.{v₂} D] where mk' ::
/-- A functor in one direction -/
functor : C ⥤ D
/-- A functor in the other direction -/
inverse : D ⥤ C
/-- The composition `functor ⋙ inverse` is isomorphic to the identity -/
unitIso : 𝟭 C ≅ functor ⋙ inverse
/-- The composition `inverse ⋙ functor` is also isomorphic to the identity -/
counitIso : inverse ⋙ functor ≅ 𝟭 D
/-- The natural isomorphisms compose to the identity. -/
functor_unitIso_comp :
∀ X : C, functor.map (unitIso.hom.app X) ≫ counitIso.hom.app (functor.obj X) =
𝟙 (functor.obj X) := by aesop_cat
/-- We infix the usual notation for an equivalence -/
infixr:10 " ≌ " => Equivalence
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D]
namespace Equivalence
/-- The unit of an equivalence of categories. -/
abbrev unit (e : C ≌ D) : 𝟭 C ⟶ e.functor ⋙ e.inverse :=
e.unitIso.hom
/-- The counit of an equivalence of categories. -/
abbrev counit (e : C ≌ D) : e.inverse ⋙ e.functor ⟶ 𝟭 D :=
e.counitIso.hom
/-- The inverse of the unit of an equivalence of categories. -/
abbrev unitInv (e : C ≌ D) : e.functor ⋙ e.inverse ⟶ 𝟭 C :=
e.unitIso.inv
/-- The inverse of the counit of an equivalence of categories. -/
abbrev counitInv (e : C ≌ D) : 𝟭 D ⟶ e.inverse ⋙ e.functor :=
e.counitIso.inv
/- While these abbreviations are convenient, they also cause some trouble,
preventing structure projections from unfolding. -/
@[simp]
theorem Equivalence_mk'_unit (functor inverse unit_iso counit_iso f) :
(⟨functor, inverse, unit_iso, counit_iso, f⟩ : C ≌ D).unit = unit_iso.hom :=
rfl
@[simp]
theorem Equivalence_mk'_counit (functor inverse unit_iso counit_iso f) :
(⟨functor, inverse, unit_iso, counit_iso, f⟩ : C ≌ D).counit = counit_iso.hom :=
rfl
@[simp]
theorem Equivalence_mk'_unitInv (functor inverse unit_iso counit_iso f) :
(⟨functor, inverse, unit_iso, counit_iso, f⟩ : C ≌ D).unitInv = unit_iso.inv :=
rfl
@[simp]
theorem Equivalence_mk'_counitInv (functor inverse unit_iso counit_iso f) :
(⟨functor, inverse, unit_iso, counit_iso, f⟩ : C ≌ D).counitInv = counit_iso.inv :=
rfl
@[reassoc (attr := simp)]
theorem functor_unit_comp (e : C ≌ D) (X : C) :
e.functor.map (e.unit.app X) ≫ e.counit.app (e.functor.obj X) = 𝟙 (e.functor.obj X) :=
e.functor_unitIso_comp X
@[reassoc (attr := simp)]
theorem counitInv_functor_comp (e : C ≌ D) (X : C) :
e.counitInv.app (e.functor.obj X) ≫ e.functor.map (e.unitInv.app X) = 𝟙 (e.functor.obj X) := by
erw [Iso.inv_eq_inv (e.functor.mapIso (e.unitIso.app X) ≪≫ e.counitIso.app (e.functor.obj X))
(Iso.refl _)]
exact e.functor_unit_comp X
theorem counitInv_app_functor (e : C ≌ D) (X : C) :
e.counitInv.app (e.functor.obj X) = e.functor.map (e.unit.app X) := by
symm
erw [← Iso.comp_hom_eq_id (e.counitIso.app _), functor_unit_comp]
rfl
theorem counit_app_functor (e : C ≌ D) (X : C) :
e.counit.app (e.functor.obj X) = e.functor.map (e.unitInv.app X) := by
erw [← Iso.hom_comp_eq_id (e.functor.mapIso (e.unitIso.app X)), functor_unit_comp]
rfl
/-- The other triangle equality. The proof follows the following proof in Globular:
http://globular.science/1905.001 -/
@[reassoc (attr := simp)]
theorem unit_inverse_comp (e : C ≌ D) (Y : D) :
e.unit.app (e.inverse.obj Y) ≫ e.inverse.map (e.counit.app Y) = 𝟙 (e.inverse.obj Y) := by
rw [← id_comp (e.inverse.map _), ← map_id e.inverse, ← counitInv_functor_comp, map_comp]
dsimp
rw [← Iso.hom_inv_id_assoc (e.unitIso.app _) (e.inverse.map (e.functor.map _)), app_hom, app_inv]
slice_lhs 2 3 => erw [e.unit.naturality]
slice_lhs 1 2 => erw [e.unit.naturality]
slice_lhs 4 4 =>
rw [← Iso.hom_inv_id_assoc (e.inverse.mapIso (e.counitIso.app _)) (e.unitInv.app _)]
slice_lhs 3 4 =>
erw [← map_comp e.inverse, e.counit.naturality]
erw [(e.counitIso.app _).hom_inv_id, map_id]
erw [id_comp]
slice_lhs 2 3 => erw [← map_comp e.inverse, e.counitIso.inv.naturality, map_comp]
slice_lhs 3 4 => erw [e.unitInv.naturality]
slice_lhs 4 5 => erw [← map_comp (e.functor ⋙ e.inverse), (e.unitIso.app _).hom_inv_id, map_id]
erw [id_comp]
slice_lhs 3 4 => erw [← e.unitInv.naturality]
slice_lhs 2 3 =>
erw [← map_comp e.inverse, ← e.counitIso.inv.naturality, (e.counitIso.app _).hom_inv_id,
map_id]
erw [id_comp, (e.unitIso.app _).hom_inv_id]; rfl
@[reassoc (attr := simp)]
theorem inverse_counitInv_comp (e : C ≌ D) (Y : D) :
e.inverse.map (e.counitInv.app Y) ≫ e.unitInv.app (e.inverse.obj Y) = 𝟙 (e.inverse.obj Y) := by
erw [Iso.inv_eq_inv (e.unitIso.app (e.inverse.obj Y) ≪≫ e.inverse.mapIso (e.counitIso.app Y))
(Iso.refl _)]
exact e.unit_inverse_comp Y
theorem unit_app_inverse (e : C ≌ D) (Y : D) :
e.unit.app (e.inverse.obj Y) = e.inverse.map (e.counitInv.app Y) := by
erw [← Iso.comp_hom_eq_id (e.inverse.mapIso (e.counitIso.app Y)), unit_inverse_comp]
dsimp
theorem unitInv_app_inverse (e : C ≌ D) (Y : D) :
e.unitInv.app (e.inverse.obj Y) = e.inverse.map (e.counit.app Y) := by
symm
erw [← Iso.hom_comp_eq_id (e.unitIso.app _), unit_inverse_comp]
rfl
@[reassoc, simp]
theorem fun_inv_map (e : C ≌ D) (X Y : D) (f : X ⟶ Y) :
e.functor.map (e.inverse.map f) = e.counit.app X ≫ f ≫ e.counitInv.app Y :=
(NatIso.naturality_2 e.counitIso f).symm
@[reassoc, simp]
theorem inv_fun_map (e : C ≌ D) (X Y : C) (f : X ⟶ Y) :
e.inverse.map (e.functor.map f) = e.unitInv.app X ≫ f ≫ e.unit.app Y :=
(NatIso.naturality_1 e.unitIso f).symm
section
-- In this section we convert an arbitrary equivalence to a half-adjoint equivalence.
variable {F : C ⥤ D} {G : D ⥤ C} (η : 𝟭 C ≅ F ⋙ G) (ε : G ⋙ F ≅ 𝟭 D)
/-- If `η : 𝟭 C ≅ F ⋙ G` is part of a (not necessarily half-adjoint) equivalence, we can upgrade it
to a refined natural isomorphism `adjointifyη η : 𝟭 C ≅ F ⋙ G` which exhibits the properties
required for a half-adjoint equivalence. See `Equivalence.mk`. -/
def adjointifyη : 𝟭 C ≅ F ⋙ G := by
calc
𝟭 C ≅ F ⋙ G := η
_ ≅ F ⋙ 𝟭 D ⋙ G := isoWhiskerLeft F (leftUnitor G).symm
_ ≅ F ⋙ (G ⋙ F) ⋙ G := isoWhiskerLeft F (isoWhiskerRight ε.symm G)
_ ≅ F ⋙ G ⋙ F ⋙ G := isoWhiskerLeft F (associator G F G)
_ ≅ (F ⋙ G) ⋙ F ⋙ G := (associator F G (F ⋙ G)).symm
_ ≅ 𝟭 C ⋙ F ⋙ G := isoWhiskerRight η.symm (F ⋙ G)
_ ≅ F ⋙ G := leftUnitor (F ⋙ G)
@[reassoc]
theorem adjointify_η_ε (X : C) :
F.map ((adjointifyη η ε).hom.app X) ≫ ε.hom.app (F.obj X) = 𝟙 (F.obj X) := by
dsimp [adjointifyη,Trans.trans]
simp only [comp_id, assoc, map_comp]
have := ε.hom.naturality (F.map (η.inv.app X)); dsimp at this; rw [this]; clear this
rw [← assoc _ _ (F.map _)]
have := ε.hom.naturality (ε.inv.app <| F.obj X); dsimp at this; rw [this]; clear this
have := (ε.app <| F.obj X).hom_inv_id; dsimp at this; rw [this]; clear this
rw [id_comp]; have := (F.mapIso <| η.app X).hom_inv_id; dsimp at this; rw [this]
end
/-- Every equivalence of categories consisting of functors `F` and `G` such that `F ⋙ G` and
`G ⋙ F` are naturally isomorphic to identity functors can be transformed into a half-adjoint
equivalence without changing `F` or `G`. -/
protected def mk (F : C ⥤ D) (G : D ⥤ C) (η : 𝟭 C ≅ F ⋙ G) (ε : G ⋙ F ≅ 𝟭 D) : C ≌ D :=
⟨F, G, adjointifyη η ε, ε, adjointify_η_ε η ε⟩
/-- Equivalence of categories is reflexive. -/
@[refl, simps]
def refl : C ≌ C :=
⟨𝟭 C, 𝟭 C, Iso.refl _, Iso.refl _, fun _ => Category.id_comp _⟩
instance : Inhabited (C ≌ C) :=
⟨refl⟩
/-- Equivalence of categories is symmetric. -/
@[symm, simps]
def symm (e : C ≌ D) : D ≌ C :=
⟨e.inverse, e.functor, e.counitIso.symm, e.unitIso.symm, e.inverse_counitInv_comp⟩
variable {E : Type u₃} [Category.{v₃} E]
/-- Equivalence of categories is transitive. -/
@[trans, simps]
def trans (e : C ≌ D) (f : D ≌ E) : C ≌ E where
functor := e.functor ⋙ f.functor
inverse := f.inverse ⋙ e.inverse
unitIso := by
refine Iso.trans e.unitIso ?_
exact isoWhiskerLeft e.functor (isoWhiskerRight f.unitIso e.inverse)
counitIso := by
refine Iso.trans ?_ f.counitIso
exact isoWhiskerLeft f.inverse (isoWhiskerRight e.counitIso f.functor)
-- We wouldn't have needed to give this proof if we'd used `Equivalence.mk`,
-- but we choose to avoid using that here, for the sake of good structure projection `simp`
-- lemmas.
functor_unitIso_comp X := by
dsimp
rw [← f.functor.map_comp_assoc, e.functor.map_comp, ← counitInv_app_functor, fun_inv_map,
Iso.inv_hom_id_app_assoc, assoc, Iso.inv_hom_id_app, counit_app_functor, ← Functor.map_comp]
erw [comp_id, Iso.hom_inv_id_app, Functor.map_id]
/-- Composing a functor with both functors of an equivalence yields a naturally isomorphic
functor. -/
def funInvIdAssoc (e : C ≌ D) (F : C ⥤ E) : e.functor ⋙ e.inverse ⋙ F ≅ F :=
(Functor.associator _ _ _).symm ≪≫ isoWhiskerRight e.unitIso.symm F ≪≫ F.leftUnitor
@[simp]
theorem funInvIdAssoc_hom_app (e : C ≌ D) (F : C ⥤ E) (X : C) :
(funInvIdAssoc e F).hom.app X = F.map (e.unitInv.app X) := by
dsimp [funInvIdAssoc]
aesop_cat
@[simp]
theorem funInvIdAssoc_inv_app (e : C ≌ D) (F : C ⥤ E) (X : C) :
(funInvIdAssoc e F).inv.app X = F.map (e.unit.app X) := by
dsimp [funInvIdAssoc]
aesop_cat
/-- Composing a functor with both functors of an equivalence yields a naturally isomorphic
functor. -/
def invFunIdAssoc (e : C ≌ D) (F : D ⥤ E) : e.inverse ⋙ e.functor ⋙ F ≅ F :=
(Functor.associator _ _ _).symm ≪≫ isoWhiskerRight e.counitIso F ≪≫ F.leftUnitor
@[simp]
theorem invFunIdAssoc_hom_app (e : C ≌ D) (F : D ⥤ E) (X : D) :
(invFunIdAssoc e F).hom.app X = F.map (e.counit.app X) := by
dsimp [invFunIdAssoc]
aesop_cat
@[simp]
theorem invFunIdAssoc_inv_app (e : C ≌ D) (F : D ⥤ E) (X : D) :
(invFunIdAssoc e F).inv.app X = F.map (e.counitInv.app X) := by
dsimp [invFunIdAssoc]
aesop_cat
/-- If `C` is equivalent to `D`, then `C ⥤ E` is equivalent to `D ⥤ E`. -/
@[simps! functor inverse unitIso counitIso]
def congrLeft (e : C ≌ D) : C ⥤ E ≌ D ⥤ E :=
Equivalence.mk ((whiskeringLeft _ _ _).obj e.inverse) ((whiskeringLeft _ _ _).obj e.functor)
(NatIso.ofComponents fun F => (e.funInvIdAssoc F).symm)
(NatIso.ofComponents fun F => e.invFunIdAssoc F)
/-- If `C` is equivalent to `D`, then `E ⥤ C` is equivalent to `E ⥤ D`. -/
@[simps! functor inverse unitIso counitIso]
def congrRight (e : C ≌ D) : E ⥤ C ≌ E ⥤ D :=
Equivalence.mk ((whiskeringRight _ _ _).obj e.functor) ((whiskeringRight _ _ _).obj e.inverse)
(NatIso.ofComponents
fun F => F.rightUnitor.symm ≪≫ isoWhiskerLeft F e.unitIso ≪≫ Functor.associator _ _ _)
(NatIso.ofComponents
fun F => Functor.associator _ _ _ ≪≫ isoWhiskerLeft F e.counitIso ≪≫ F.rightUnitor)
section CancellationLemmas
variable (e : C ≌ D)
/- We need special forms of `cancel_natIso_hom_right(_assoc)` and
`cancel_natIso_inv_right(_assoc)` for units and counits, because neither `simp` or `rw` will apply
those lemmas in this setting without providing `e.unitIso` (or similar) as an explicit argument.
We also provide the lemmas for length four compositions, since they're occasionally useful.
(e.g. in proving that equivalences take monos to monos) -/
@[simp]
theorem cancel_unit_right {X Y : C} (f f' : X ⟶ Y) :
f ≫ e.unit.app Y = f' ≫ e.unit.app Y ↔ f = f' := by simp only [cancel_mono]
@[simp]
theorem cancel_unitInv_right {X Y : C} (f f' : X ⟶ e.inverse.obj (e.functor.obj Y)) :
f ≫ e.unitInv.app Y = f' ≫ e.unitInv.app Y ↔ f = f' := by simp only [cancel_mono]
@[simp]
theorem cancel_counit_right {X Y : D} (f f' : X ⟶ e.functor.obj (e.inverse.obj Y)) :
f ≫ e.counit.app Y = f' ≫ e.counit.app Y ↔ f = f' := by simp only [cancel_mono]
@[simp]
theorem cancel_counitInv_right {X Y : D} (f f' : X ⟶ Y) :
f ≫ e.counitInv.app Y = f' ≫ e.counitInv.app Y ↔ f = f' := by simp only [cancel_mono]
@[simp]
theorem cancel_unit_right_assoc {W X X' Y : C} (f : W ⟶ X) (g : X ⟶ Y) (f' : W ⟶ X') (g' : X' ⟶ Y) :
f ≫ g ≫ e.unit.app Y = f' ≫ g' ≫ e.unit.app Y ↔ f ≫ g = f' ≫ g' := by
simp only [← Category.assoc, cancel_mono]
@[simp]
theorem cancel_counitInv_right_assoc {W X X' Y : D} (f : W ⟶ X) (g : X ⟶ Y) (f' : W ⟶ X')
(g' : X' ⟶ Y) : f ≫ g ≫ e.counitInv.app Y = f' ≫ g' ≫ e.counitInv.app Y ↔ f ≫ g = f' ≫ g' := by
simp only [← Category.assoc, cancel_mono]
@[simp]
theorem cancel_unit_right_assoc' {W X X' Y Y' Z : C} (f : W ⟶ X) (g : X ⟶ Y) (h : Y ⟶ Z)
(f' : W ⟶ X') (g' : X' ⟶ Y') (h' : Y' ⟶ Z) :
f ≫ g ≫ h ≫ e.unit.app Z = f' ≫ g' ≫ h' ≫ e.unit.app Z ↔ f ≫ g ≫ h = f' ≫ g' ≫ h' := by
simp only [← Category.assoc, cancel_mono]
@[simp]
theorem cancel_counitInv_right_assoc' {W X X' Y Y' Z : D} (f : W ⟶ X) (g : X ⟶ Y) (h : Y ⟶ Z)
(f' : W ⟶ X') (g' : X' ⟶ Y') (h' : Y' ⟶ Z) :
f ≫ g ≫ h ≫ e.counitInv.app Z = f' ≫ g' ≫ h' ≫ e.counitInv.app Z ↔
f ≫ g ≫ h = f' ≫ g' ≫ h' := by simp only [← Category.assoc, cancel_mono]
end CancellationLemmas
section
-- There's of course a monoid structure on `C ≌ C`,
-- but let's not encourage using it.
-- The power structure is nevertheless useful.
/-- Natural number powers of an auto-equivalence. Use `(^)` instead. -/
def powNat (e : C ≌ C) : ℕ → (C ≌ C)
| 0 => Equivalence.refl
| 1 => e
| n + 2 => e.trans (powNat e (n + 1))
/-- Powers of an auto-equivalence. Use `(^)` instead. -/
def pow (e : C ≌ C) : ℤ → (C ≌ C)
| Int.ofNat n => e.powNat n
| Int.negSucc n => e.symm.powNat (n + 1)
instance : Pow (C ≌ C) ℤ :=
⟨pow⟩
@[simp]
theorem pow_zero (e : C ≌ C) : e ^ (0 : ℤ) = Equivalence.refl :=
rfl
@[simp]
theorem pow_one (e : C ≌ C) : e ^ (1 : ℤ) = e :=
rfl
@[simp]
theorem pow_neg_one (e : C ≌ C) : e ^ (-1 : ℤ) = e.symm :=
rfl
-- TODO as necessary, add the natural isomorphisms `(e^a).trans e^b ≅ e^(a+b)`.
-- At this point, we haven't even defined the category of equivalences.
-- Note: the better formulation of this would involve `HasShift`.
end
/-- The functor of an equivalence of categories is essentially surjective.
See <https://stacks.math.columbia.edu/tag/02C3>.
-/
instance essSurj_functor (e : C ≌ E) : e.functor.EssSurj :=
⟨fun Y => ⟨e.inverse.obj Y, ⟨e.counitIso.app Y⟩⟩⟩
instance essSurj_inverse (e : C ≌ E) : e.inverse.EssSurj :=
e.symm.essSurj_functor
/-- The functor of an equivalence of categories is fully faithful. -/
def fullyFaithfulFunctor (e : C ≌ E) : e.functor.FullyFaithful where
preimage {X Y} f := e.unitIso.hom.app X ≫ e.inverse.map f ≫ e.unitIso.inv.app Y
/-- The inverse of an equivalence of categories is fully faithful. -/
def fullyFaithfulInverse (e : C ≌ E) : e.inverse.FullyFaithful where
preimage {X Y} f := e.counitIso.inv.app X ≫ e.functor.map f ≫ e.counitIso.hom.app Y
/-- The functor of an equivalence of categories is faithful.
See <https://stacks.math.columbia.edu/tag/02C3>.
-/
instance faithful_functor (e : C ≌ E) : e.functor.Faithful :=
e.fullyFaithfulFunctor.faithful
instance faithful_inverse (e : C ≌ E) : e.inverse.Faithful :=
e.fullyFaithfulInverse.faithful
/-- The functor of an equivalence of categories is full.
See <https://stacks.math.columbia.edu/tag/02C3>.
-/
instance full_functor (e : C ≌ E) : e.functor.Full :=
e.fullyFaithfulFunctor.full
instance full_inverse (e : C ≌ E) : e.inverse.Full :=
e.fullyFaithfulInverse.full
/-- If `e : C ≌ D` is an equivalence of categories, and `iso : e.functor ≅ G` is
an isomorphism, then there is an equivalence of categories whose functor is `G`. -/
@[simps!]
def changeFunctor (e : C ≌ D) {G : C ⥤ D} (iso : e.functor ≅ G) : C ≌ D where
functor := G
inverse := e.inverse
unitIso := e.unitIso ≪≫ isoWhiskerRight iso _
counitIso := isoWhiskerLeft _ iso.symm ≪≫ e.counitIso
/-- Compatibility of `changeFunctor` with identity isomorphisms of functors -/
theorem changeFunctor_refl (e : C ≌ D) : e.changeFunctor (Iso.refl _) = e := by aesop_cat
/-- Compatibility of `changeFunctor` with the composition of isomorphisms of functors -/
theorem changeFunctor_trans (e : C ≌ D) {G G' : C ⥤ D} (iso₁ : e.functor ≅ G) (iso₂ : G ≅ G') :
(e.changeFunctor iso₁).changeFunctor iso₂ = e.changeFunctor (iso₁ ≪≫ iso₂) := by aesop_cat
/-- If `e : C ≌ D` is an equivalence of categories, and `iso : e.functor ≅ G` is
an isomorphism, then there is an equivalence of categories whose inverse is `G`. -/
@[simps!]
def changeInverse (e : C ≌ D) {G : D ⥤ C} (iso : e.inverse ≅ G) : C ≌ D where
functor := e.functor
inverse := G
unitIso := e.unitIso ≪≫ isoWhiskerLeft _ iso
counitIso := isoWhiskerRight iso.symm _ ≪≫ e.counitIso
functor_unitIso_comp X := by
dsimp
rw [← map_comp_assoc, assoc, iso.hom_inv_id_app, comp_id, functor_unit_comp]
end Equivalence
/-- A functor is an equivalence of categories if it is faithful, full and
essentially surjective. -/
class Functor.IsEquivalence (F : C ⥤ D) : Prop where
faithful : F.Faithful := by infer_instance
full : F.Full := by infer_instance
essSurj : F.EssSurj := by infer_instance
instance Equivalence.isEquivalence_functor (F : C ≌ D) : IsEquivalence F.functor where
instance Equivalence.isEquivalence_inverse (F : C ≌ D) : IsEquivalence F.inverse :=
F.symm.isEquivalence_functor
namespace Functor
namespace IsEquivalence
attribute [instance] faithful full essSurj
/-- To see that a functor is an equivalence, it suffices to provide an inverse functor `G` such that
`F ⋙ G` and `G ⋙ F` are naturally isomorphic to identity functors. -/
protected lemma mk' {F : C ⥤ D} (G : D ⥤ C) (η : 𝟭 C ≅ F ⋙ G) (ε : G ⋙ F ≅ 𝟭 D) :
IsEquivalence F :=
inferInstanceAs (IsEquivalence (Equivalence.mk F G η ε).functor)
end IsEquivalence
/-- A quasi-inverse `D ⥤ C` to a functor that `F : C ⥤ D` that is an equivalence,
i.e. faithful, full, and essentially surjective. -/
noncomputable def inv (F : C ⥤ D) [F.IsEquivalence] : D ⥤ C where
obj X := F.objPreimage X
map {X Y} f := F.preimage ((F.objObjPreimageIso X).hom ≫ f ≫ (F.objObjPreimageIso Y).inv)
map_id X := by apply F.map_injective; aesop_cat
map_comp {X Y Z} f g := by apply F.map_injective; simp
/-- Interpret a functor that is an equivalence as an equivalence.
See <https://stacks.math.columbia.edu/tag/02C3>. -/
@[simps functor]
noncomputable def asEquivalence (F : C ⥤ D) [F.IsEquivalence] : C ≌ D where
functor := F
inverse := F.inv
unitIso := NatIso.ofComponents
(fun X => (F.preimageIso <| F.objObjPreimageIso <| F.obj X).symm)
(fun f => F.map_injective (by simp [inv]))
counitIso := NatIso.ofComponents F.objObjPreimageIso (by simp [inv])
instance isEquivalence_refl : IsEquivalence (𝟭 C) :=
Equivalence.refl.isEquivalence_functor
instance isEquivalence_inv (F : C ⥤ D) [IsEquivalence F] : IsEquivalence F.inv :=
F.asEquivalence.symm.isEquivalence_functor
variable {E : Type u₃} [Category.{v₃} E]
instance isEquivalence_trans (F : C ⥤ D) (G : D ⥤ E) [IsEquivalence F] [IsEquivalence G] :
IsEquivalence (F ⋙ G) where
instance (F : C ⥤ D) [IsEquivalence F] : IsEquivalence ((whiskeringLeft C D E).obj F) :=
(inferInstance : IsEquivalence (Equivalence.congrLeft F.asEquivalence).inverse)
instance (F : C ⥤ D) [IsEquivalence F] : IsEquivalence ((whiskeringRight E C D).obj F) :=
(inferInstance : IsEquivalence (Equivalence.congrRight F.asEquivalence).functor)
end Functor
namespace Functor
@[simp]
theorem fun_inv_map (F : C ⥤ D) [IsEquivalence F] (X Y : D) (f : X ⟶ Y) :
F.map (F.inv.map f) = F.asEquivalence.counit.app X ≫ f ≫ F.asEquivalence.counitInv.app Y := by
erw [NatIso.naturality_2]
rfl
@[simp]
theorem inv_fun_map (F : C ⥤ D) [IsEquivalence F] (X Y : C) (f : X ⟶ Y) :
F.inv.map (F.map f) = F.asEquivalence.unitInv.app X ≫ f ≫ F.asEquivalence.unit.app Y := by
erw [NatIso.naturality_1]
rfl
lemma isEquivalence_of_iso {F G : C ⥤ D} (e : F ≅ G) [F.IsEquivalence] : G.IsEquivalence :=
((asEquivalence F).changeFunctor e).isEquivalence_functor
lemma isEquivalence_iff_of_iso {F G : C ⥤ D} (e : F ≅ G) :
F.IsEquivalence ↔ G.IsEquivalence :=
⟨fun _ => isEquivalence_of_iso e, fun _ => isEquivalence_of_iso e.symm⟩
/-- If `G` and `F ⋙ G` are equivalence of categories, then `F` is also an equivalence. -/
lemma isEquivalence_of_comp_right {E : Type*} [Category E] (F : C ⥤ D) (G : D ⥤ E)
[IsEquivalence G] [IsEquivalence (F ⋙ G)] : IsEquivalence F := by
rw [isEquivalence_iff_of_iso (F.rightUnitor.symm ≪≫ isoWhiskerLeft F (G.asEquivalence.unitIso))]
exact ((F ⋙ G).asEquivalence.trans G.asEquivalence.symm).isEquivalence_functor
/-- If `F` and `F ⋙ G` are equivalence of categories, then `G` is also an equivalence. -/
lemma isEquivalence_of_comp_left {E : Type*} [Category E] (F : C ⥤ D) (G : D ⥤ E)
[IsEquivalence F] [IsEquivalence (F ⋙ G)] : IsEquivalence G := by
rw [isEquivalence_iff_of_iso (G.leftUnitor.symm ≪≫
isoWhiskerRight F.asEquivalence.counitIso.symm G)]
exact (F.asEquivalence.symm.trans (F ⋙ G).asEquivalence).isEquivalence_functor
end Functor
namespace Equivalence
instance essSurjInducedFunctor {C' : Type*} (e : C' ≃ D) : (inducedFunctor e).EssSurj where
mem_essImage Y := ⟨e.symm Y, by simpa using ⟨default⟩⟩
noncomputable instance inducedFunctorOfEquiv {C' : Type*} (e : C' ≃ D) :
IsEquivalence (inducedFunctor e) where
noncomputable instance fullyFaithfulToEssImage (F : C ⥤ D) [F.Full] [F.Faithful] :
IsEquivalence F.toEssImage where
end Equivalence
namespace Iso
variable {E : Type u₃} [Category.{v₃} E] {F : C ⥤ E} {G : C ⥤ D} {H : D ⥤ E}
/-- Construct an isomorphism `F ⋙ H.inverse ≅ G` from an isomorphism `F ≅ G ⋙ H.functor`. -/
@[simps!]
def compInverseIso {H : D ≌ E} (i : F ≅ G ⋙ H.functor) : F ⋙ H.inverse ≅ G :=
isoWhiskerRight i H.inverse ≪≫
associator G _ H.inverse ≪≫ isoWhiskerLeft G H.unitIso.symm ≪≫ G.rightUnitor
/-- Construct an isomorphism `G ≅ F ⋙ H.inverse` from an isomorphism `G ⋙ H.functor ≅ F`. -/
@[simps!]
def isoCompInverse {H : D ≌ E} (i : G ⋙ H.functor ≅ F) : G ≅ F ⋙ H.inverse :=
G.rightUnitor.symm ≪≫ isoWhiskerLeft G H.unitIso ≪≫ (associator _ _ _).symm ≪≫
isoWhiskerRight i H.inverse
/-- Construct an isomorphism `G.inverse ⋙ F ≅ H` from an isomorphism `F ≅ G.functor ⋙ H`. -/
@[simps!]
def inverseCompIso {G : C ≌ D} (i : F ≅ G.functor ⋙ H) : G.inverse ⋙ F ≅ H :=
isoWhiskerLeft G.inverse i ≪≫ (associator _ _ _).symm ≪≫
isoWhiskerRight G.counitIso H ≪≫ H.leftUnitor
/-- Construct an isomorphism `H ≅ G.inverse ⋙ F` from an isomorphism `G.functor ⋙ H ≅ F`. -/
@[simps!]
def isoInverseComp {G : C ≌ D} (i : G.functor ⋙ H ≅ F) : H ≅ G.inverse ⋙ F :=
H.leftUnitor.symm ≪≫ isoWhiskerRight G.counitIso.symm H ≪≫ associator _ _ _
≪≫ isoWhiskerLeft G.inverse i
end Iso
@[deprecated (since := "2024-04-06")] alias IsEquivalence := Functor.IsEquivalence
@[deprecated (since := "2024-04-06")] alias IsEquivalence.fun_inv_map := Functor.fun_inv_map
@[deprecated (since := "2024-04-06")] alias IsEquivalence.inv_fun_map := Functor.inv_fun_map
@[deprecated (since := "2024-04-06")] alias IsEquivalence.ofIso := Equivalence.changeFunctor
@[deprecated (since := "2024-04-06")]
alias IsEquivalence.ofIso_trans := Equivalence.changeFunctor_trans
@[deprecated (since := "2024-04-06")]
alias IsEquivalence.ofIso_refl := Equivalence.changeFunctor_refl
@[deprecated (since := "2024-04-06")]
alias IsEquivalence.equivOfIso := Functor.isEquivalence_iff_of_iso
@[deprecated (since := "2024-04-06")]
alias IsEquivalence.cancelCompRight := Functor.isEquivalence_of_comp_right
@[deprecated (since := "2024-04-06")]
alias IsEquivalence.cancelCompLeft := Functor.isEquivalence_of_comp_left
end CategoryTheory
|
CategoryTheory\EssentialImage.lean | /-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import Mathlib.CategoryTheory.NatIso
import Mathlib.CategoryTheory.FullSubcategory
/-!
# Essential image of a functor
The essential image `essImage` of a functor consists of the objects in the target category which
are isomorphic to an object in the image of the object function.
This, for instance, allows us to talk about objects belonging to a subcategory expressed as a
functor rather than a subtype, preserving the principle of equivalence. For example this lets us
define exponential ideals.
The essential image can also be seen as a subcategory of the target category, and witnesses that
a functor decomposes into an essentially surjective functor and a fully faithful functor.
(TODO: show that this decomposition forms an orthogonal factorisation system).
-/
universe v₁ v₂ v₃ u₁ u₂ u₃
noncomputable section
namespace CategoryTheory
variable {C : Type u₁} {D : Type u₂} {E : Type u₃}
[Category.{v₁} C] [Category.{v₂} D] [Category.{v₃} E] {F : C ⥤ D}
namespace Functor
/-- The essential image of a functor `F` consists of those objects in the target category which are
isomorphic to an object in the image of the function `F.obj`. In other words, this is the closure
under isomorphism of the function `F.obj`.
This is the "non-evil" way of describing the image of a functor.
-/
def essImage (F : C ⥤ D) : Set D := fun Y => ∃ X : C, Nonempty (F.obj X ≅ Y)
/-- Get the witnessing object that `Y` is in the subcategory given by `F`. -/
def essImage.witness {Y : D} (h : Y ∈ F.essImage) : C :=
h.choose
/-- Extract the isomorphism between `F.obj h.witness` and `Y` itself. -/
-- Porting note: in the next, the dot notation `h.witness` no longer works
def essImage.getIso {Y : D} (h : Y ∈ F.essImage) : F.obj (essImage.witness h) ≅ Y :=
Classical.choice h.choose_spec
/-- Being in the essential image is a "hygienic" property: it is preserved under isomorphism. -/
theorem essImage.ofIso {Y Y' : D} (h : Y ≅ Y') (hY : Y ∈ essImage F) : Y' ∈ essImage F :=
hY.imp fun _ => Nonempty.map (· ≪≫ h)
/-- If `Y` is in the essential image of `F` then it is in the essential image of `F'` as long as
`F ≅ F'`.
-/
theorem essImage.ofNatIso {F' : C ⥤ D} (h : F ≅ F') {Y : D} (hY : Y ∈ essImage F) :
Y ∈ essImage F' :=
hY.imp fun X => Nonempty.map fun t => h.symm.app X ≪≫ t
/-- Isomorphic functors have equal essential images. -/
theorem essImage_eq_of_natIso {F' : C ⥤ D} (h : F ≅ F') : essImage F = essImage F' :=
funext fun _ => propext ⟨essImage.ofNatIso h, essImage.ofNatIso h.symm⟩
/-- An object in the image is in the essential image. -/
theorem obj_mem_essImage (F : D ⥤ C) (Y : D) : F.obj Y ∈ essImage F :=
⟨Y, ⟨Iso.refl _⟩⟩
/-- The essential image of a functor, interpreted as a full subcategory of the target category. -/
-- Porting note: no hasNonEmptyInstance linter yet
def EssImageSubcategory (F : C ⥤ D) :=
FullSubcategory F.essImage
-- Porting note: `deriving Category` is not able to derive this instance
instance : Category (EssImageSubcategory F) :=
(inferInstance : Category.{v₂} (FullSubcategory _))
/-- The essential image as a subcategory has a fully faithful inclusion into the target category. -/
@[simps!]
def essImageInclusion (F : C ⥤ D) : F.EssImageSubcategory ⥤ D :=
fullSubcategoryInclusion _
-- Porting note: `deriving Full` is not able to derive this instance
instance : Full (essImageInclusion F) :=
(inferInstance : Full (fullSubcategoryInclusion _))
-- Porting note: `deriving Faithful` is not able to derive this instance
instance : Faithful (essImageInclusion F) :=
(inferInstance : Faithful (fullSubcategoryInclusion _))
/--
Given a functor `F : C ⥤ D`, we have an (essentially surjective) functor from `C` to the essential
image of `F`.
-/
@[simps!]
def toEssImage (F : C ⥤ D) : C ⥤ F.EssImageSubcategory :=
FullSubcategory.lift _ F (obj_mem_essImage _)
/-- The functor `F` factorises through its essential image, where the first functor is essentially
surjective and the second is fully faithful.
-/
@[simps!]
def toEssImageCompEssentialImageInclusion (F : C ⥤ D) : F.toEssImage ⋙ F.essImageInclusion ≅ F :=
FullSubcategory.lift_comp_inclusion _ _ _
/-- A functor `F : C ⥤ D` is essentially surjective if every object of `D` is in the essential
image of `F`. In other words, for every `Y : D`, there is some `X : C` with `F.obj X ≅ Y`.
See <https://stacks.math.columbia.edu/tag/001C>.
-/
class EssSurj (F : C ⥤ D) : Prop where
/-- All the objects of the target category are in the essential image. -/
mem_essImage (Y : D) : Y ∈ F.essImage
instance EssSurj.toEssImage : EssSurj F.toEssImage where
mem_essImage := fun ⟨_, hY⟩ =>
⟨_, ⟨⟨_, _, hY.getIso.hom_inv_id, hY.getIso.inv_hom_id⟩⟩⟩
theorem essSurj_of_surj (h : Function.Surjective F.obj) : EssSurj F where
mem_essImage Y := by
obtain ⟨X, rfl⟩ := h Y
apply obj_mem_essImage
variable (F)
variable [F.EssSurj]
/-- Given an essentially surjective functor, we can find a preimage for every object `Y` in the
codomain. Applying the functor to this preimage will yield an object isomorphic to `Y`, see
`obj_obj_preimage_iso`. -/
def objPreimage (Y : D) : C :=
essImage.witness (@EssSurj.mem_essImage _ _ _ _ F _ Y)
/-- Applying an essentially surjective functor to a preimage of `Y` yields an object that is
isomorphic to `Y`. -/
def objObjPreimageIso (Y : D) : F.obj (F.objPreimage Y) ≅ Y :=
Functor.essImage.getIso _
/-- The induced functor of a faithful functor is faithful. -/
instance Faithful.toEssImage (F : C ⥤ D) [Faithful F] : Faithful F.toEssImage :=
Faithful.of_comp_iso F.toEssImageCompEssentialImageInclusion
/-- The induced functor of a full functor is full. -/
instance Full.toEssImage (F : C ⥤ D) [Full F] : Full F.toEssImage :=
Full.of_comp_faithful_iso F.toEssImageCompEssentialImageInclusion
instance instEssSurjId : EssSurj (𝟭 C) where
mem_essImage Y := ⟨Y, ⟨Iso.refl _⟩⟩
lemma essSurj_of_iso {F G : C ⥤ D} [EssSurj F] (α : F ≅ G) : EssSurj G where
mem_essImage Y := Functor.essImage.ofNatIso α (EssSurj.mem_essImage Y)
instance essSurj_comp (F : C ⥤ D) (G : D ⥤ E) [F.EssSurj] [G.EssSurj] :
(F ⋙ G).EssSurj where
mem_essImage Z := ⟨_, ⟨G.mapIso (F.objObjPreimageIso _) ≪≫ G.objObjPreimageIso Z⟩⟩
lemma essSurj_of_comp_fully_faithful (F : C ⥤ D) (G : D ⥤ E) [(F ⋙ G).EssSurj]
[G.Faithful] [G.Full] : F.EssSurj where
mem_essImage X := ⟨_, ⟨G.preimageIso ((F ⋙ G).objObjPreimageIso (G.obj X))⟩⟩
end Functor
@[deprecated (since := "2024-04-06")] alias EssSurj := Functor.EssSurj
@[deprecated (since := "2024-04-06")] alias Iso.map_essSurj := Functor.essSurj_of_iso
end CategoryTheory
|
CategoryTheory\EssentiallySmall.lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.CategoryTheory.Category.ULift
import Mathlib.CategoryTheory.Skeletal
import Mathlib.Logic.UnivLE
import Mathlib.Logic.Small.Basic
/-!
# Essentially small categories.
A category given by `(C : Type u) [Category.{v} C]` is `w`-essentially small
if there exists a `SmallModel C : Type w` equipped with `[SmallCategory (SmallModel C)]` and an
equivalence `C ≌ SmallModel C`.
A category is `w`-locally small if every hom type is `w`-small.
The main theorem here is that a category is `w`-essentially small iff
the type `Skeleton C` is `w`-small, and `C` is `w`-locally small.
-/
universe w v v' u u'
open CategoryTheory
variable (C : Type u) [Category.{v} C]
namespace CategoryTheory
/-- A category is `EssentiallySmall.{w}` if there exists
an equivalence to some `S : Type w` with `[SmallCategory S]`. -/
@[pp_with_univ]
class EssentiallySmall (C : Type u) [Category.{v} C] : Prop where
/-- An essentially small category is equivalent to some small category. -/
equiv_smallCategory : ∃ (S : Type w) (_ : SmallCategory S), Nonempty (C ≌ S)
/-- Constructor for `EssentiallySmall C` from an explicit small category witness. -/
theorem EssentiallySmall.mk' {C : Type u} [Category.{v} C] {S : Type w} [SmallCategory S]
(e : C ≌ S) : EssentiallySmall.{w} C :=
⟨⟨S, _, ⟨e⟩⟩⟩
/-- An arbitrarily chosen small model for an essentially small category.
-/
-- Porting note(#5171) removed @[nolint has_nonempty_instance]
@[pp_with_univ]
def SmallModel (C : Type u) [Category.{v} C] [EssentiallySmall.{w} C] : Type w :=
Classical.choose (@EssentiallySmall.equiv_smallCategory C _ _)
noncomputable instance smallCategorySmallModel (C : Type u) [Category.{v} C]
[EssentiallySmall.{w} C] : SmallCategory (SmallModel C) :=
Classical.choose (Classical.choose_spec (@EssentiallySmall.equiv_smallCategory C _ _))
/-- The (noncomputable) categorical equivalence between
an essentially small category and its small model.
-/
noncomputable def equivSmallModel (C : Type u) [Category.{v} C] [EssentiallySmall.{w} C] :
C ≌ SmallModel C :=
Nonempty.some
(Classical.choose_spec (Classical.choose_spec (@EssentiallySmall.equiv_smallCategory C _ _)))
theorem essentiallySmall_congr {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D]
(e : C ≌ D) : EssentiallySmall.{w} C ↔ EssentiallySmall.{w} D := by
fconstructor
· rintro ⟨S, 𝒮, ⟨f⟩⟩
exact EssentiallySmall.mk' (e.symm.trans f)
· rintro ⟨S, 𝒮, ⟨f⟩⟩
exact EssentiallySmall.mk' (e.trans f)
theorem Discrete.essentiallySmallOfSmall {α : Type u} [Small.{w} α] :
EssentiallySmall.{w} (Discrete α) :=
⟨⟨Discrete (Shrink α), ⟨inferInstance, ⟨Discrete.equivalence (equivShrink _)⟩⟩⟩⟩
theorem essentiallySmallSelf : EssentiallySmall.{max w v u} C :=
EssentiallySmall.mk' (AsSmall.equiv : C ≌ AsSmall.{w} C)
/-- A category is `w`-locally small if every hom set is `w`-small.
See `ShrinkHoms C` for a category instance where every hom set has been replaced by a small model.
-/
@[pp_with_univ]
class LocallySmall (C : Type u) [Category.{v} C] : Prop where
/-- A locally small category has small hom-types. -/
hom_small : ∀ X Y : C, Small.{w} (X ⟶ Y) := by infer_instance
instance (C : Type u) [Category.{v} C] [LocallySmall.{w} C] (X Y : C) : Small.{w, v} (X ⟶ Y) :=
LocallySmall.hom_small X Y
theorem locallySmall_of_faithful {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D]
(F : C ⥤ D) [F.Faithful] [LocallySmall.{w} D] : LocallySmall.{w} C where
hom_small {_ _} := small_of_injective F.map_injective
theorem locallySmall_congr {C : Type u} [Category.{v} C] {D : Type u'} [Category.{v'} D]
(e : C ≌ D) : LocallySmall.{w} C ↔ LocallySmall.{w} D :=
⟨fun _ => locallySmall_of_faithful e.inverse, fun _ => locallySmall_of_faithful e.functor⟩
instance (priority := 100) locallySmall_self (C : Type u) [Category.{v} C] :
LocallySmall.{v} C where
instance (priority := 100) locallySmall_of_univLE (C : Type u) [Category.{v} C] [UnivLE.{v, w}] :
LocallySmall.{w} C where
theorem locallySmall_max {C : Type u} [Category.{v} C] : LocallySmall.{max v w} C where
hom_small _ _ := small_max.{w} _
instance (priority := 100) locallySmall_of_essentiallySmall (C : Type u) [Category.{v} C]
[EssentiallySmall.{w} C] : LocallySmall.{w} C :=
(locallySmall_congr (equivSmallModel C)).mpr (CategoryTheory.locallySmall_self _)
/-- We define a type alias `ShrinkHoms C` for `C`. When we have `LocallySmall.{w} C`,
we'll put a `Category.{w}` instance on `ShrinkHoms C`.
-/
-- Porting note(#5171): removed @[nolint has_nonempty_instance]
@[pp_with_univ]
def ShrinkHoms (C : Type u) :=
C
namespace ShrinkHoms
section
variable {C' : Type*}
-- a fresh variable with no category instance attached
/-- Help the typechecker by explicitly translating from `C` to `ShrinkHoms C`. -/
def toShrinkHoms {C' : Type*} (X : C') : ShrinkHoms C' :=
X
/-- Help the typechecker by explicitly translating from `ShrinkHoms C` to `C`. -/
def fromShrinkHoms {C' : Type*} (X : ShrinkHoms C') : C' :=
X
@[simp]
theorem to_from (X : C') : fromShrinkHoms (toShrinkHoms X) = X :=
rfl
@[simp]
theorem from_to (X : ShrinkHoms C') : toShrinkHoms (fromShrinkHoms X) = X :=
rfl
end
variable [LocallySmall.{w} C]
@[simps]
noncomputable instance : Category.{w} (ShrinkHoms C) where
Hom X Y := Shrink (fromShrinkHoms X ⟶ fromShrinkHoms Y)
id X := equivShrink _ (𝟙 (fromShrinkHoms X))
comp f g := equivShrink _ ((equivShrink _).symm f ≫ (equivShrink _).symm g)
/-- Implementation of `ShrinkHoms.equivalence`. -/
@[simps]
noncomputable def functor : C ⥤ ShrinkHoms C where
obj X := toShrinkHoms X
map {X Y} f := equivShrink (X ⟶ Y) f
/-- Implementation of `ShrinkHoms.equivalence`. -/
@[simps]
noncomputable def inverse : ShrinkHoms C ⥤ C where
obj X := fromShrinkHoms X
map {X Y} f := (equivShrink (fromShrinkHoms X ⟶ fromShrinkHoms Y)).symm f
/-- The categorical equivalence between `C` and `ShrinkHoms C`, when `C` is locally small.
-/
@[simps!]
noncomputable def equivalence : C ≌ ShrinkHoms C :=
Equivalence.mk (functor C) (inverse C)
(NatIso.ofComponents fun X => Iso.refl X)
(NatIso.ofComponents fun X => Iso.refl X)
end ShrinkHoms
namespace Shrink
noncomputable instance [Small.{w} C] : Category.{v} (Shrink.{w} C) :=
InducedCategory.category (equivShrink C).symm
/-- The categorical equivalence between `C` and `Shrink C`, when `C` is small. -/
noncomputable def equivalence [Small.{w} C] : C ≌ Shrink.{w} C :=
(inducedFunctor (equivShrink C).symm).asEquivalence.symm
end Shrink
/-- A category is essentially small if and only if
the underlying type of its skeleton (i.e. the "set" of isomorphism classes) is small,
and it is locally small.
-/
theorem essentiallySmall_iff (C : Type u) [Category.{v} C] :
EssentiallySmall.{w} C ↔ Small.{w} (Skeleton C) ∧ LocallySmall.{w} C := by
-- This theorem is the only bit of real work in this file.
fconstructor
· intro h
fconstructor
· rcases h with ⟨S, 𝒮, ⟨e⟩⟩
refine ⟨⟨Skeleton S, ⟨?_⟩⟩⟩
exact e.skeletonEquiv
· infer_instance
· rintro ⟨⟨S, ⟨e⟩⟩, L⟩
let e' := (ShrinkHoms.equivalence C).skeletonEquiv.symm
letI : Category S := InducedCategory.category (e'.trans e).symm
refine ⟨⟨S, this, ⟨?_⟩⟩⟩
refine (ShrinkHoms.equivalence C).trans <|
(skeletonEquivalence (ShrinkHoms C)).symm.trans
((inducedFunctor (e'.trans e).symm).asEquivalence.symm)
theorem essentiallySmall_of_small_of_locallySmall [Small.{w} C] [LocallySmall.{w} C] :
EssentiallySmall.{w} C :=
(essentiallySmall_iff C).2 ⟨small_of_surjective Quotient.exists_rep, by infer_instance⟩
section FullSubcategory
instance locallySmall_fullSubcategory [LocallySmall.{w} C] (P : C → Prop) :
LocallySmall.{w} (FullSubcategory P) :=
locallySmall_of_faithful <| fullSubcategoryInclusion P
instance essentiallySmall_fullSubcategory_mem (s : Set C) [Small.{w} s] [LocallySmall.{w} C] :
EssentiallySmall.{w} (FullSubcategory (· ∈ s)) :=
suffices Small.{w} (FullSubcategory (· ∈ s)) from essentiallySmall_of_small_of_locallySmall _
small_of_injective (f := fun x => (⟨x.1, x.2⟩ : s)) (by aesop_cat)
end FullSubcategory
/-- Any thin category is locally small.
-/
instance (priority := 100) locallySmall_of_thin {C : Type u} [Category.{v} C] [Quiver.IsThin C] :
LocallySmall.{w} C where
/--
A thin category is essentially small if and only if the underlying type of its skeleton is small.
-/
theorem essentiallySmall_iff_of_thin {C : Type u} [Category.{v} C] [Quiver.IsThin C] :
EssentiallySmall.{w} C ↔ Small.{w} (Skeleton C) := by
simp [essentiallySmall_iff, CategoryTheory.locallySmall_of_thin]
instance [Small.{w} C] : Small.{w} (Discrete C) := small_map discreteEquiv
end CategoryTheory
|
CategoryTheory\Extensive.lean | /-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.CategoryTheory.Limits.Shapes.Pullback.CommSq
import Mathlib.CategoryTheory.Limits.Shapes.StrictInitial
import Mathlib.CategoryTheory.Limits.Shapes.Types
import Mathlib.Topology.Category.TopCat.Limits.Pullbacks
import Mathlib.CategoryTheory.Limits.FunctorCategory
import Mathlib.CategoryTheory.Limits.Constructions.FiniteProductsOfBinaryProducts
import Mathlib.CategoryTheory.Limits.VanKampen
/-!
# Extensive categories
## Main definitions
- `CategoryTheory.FinitaryExtensive`: A category is (finitary) extensive if it has finite
coproducts, and binary coproducts are van Kampen.
## Main Results
- `CategoryTheory.hasStrictInitialObjects_of_finitaryExtensive`: The initial object
in extensive categories is strict.
- `CategoryTheory.FinitaryExtensive.mono_inr_of_isColimit`: Coproduct injections are monic in
extensive categories.
- `CategoryTheory.BinaryCofan.isPullback_initial_to_of_isVanKampen`: In extensive categories,
sums are disjoint, i.e. the pullback of `X ⟶ X ⨿ Y` and `Y ⟶ X ⨿ Y` is the initial object.
- `CategoryTheory.types.finitaryExtensive`: The category of types is extensive.
- `CategoryTheory.FinitaryExtensive_TopCat`:
The category `Top` is extensive.
- `CategoryTheory.FinitaryExtensive_functor`: The category `C ⥤ D` is extensive if `D`
has all pullbacks and is extensive.
- `CategoryTheory.FinitaryExtensive.isVanKampen_finiteCoproducts`: Finite coproducts in a
finitary extensive category are van Kampen.
## TODO
Show that the following are finitary extensive:
- `Scheme`
- `AffineScheme` (`CommRingᵒᵖ`)
## References
- https://ncatlab.org/nlab/show/extensive+category
- [Carboni et al, Introduction to extensive and distributive categories][CARBONI1993145]
-/
open CategoryTheory.Limits
namespace CategoryTheory
universe v' u' v u v'' u''
variable {J : Type v'} [Category.{u'} J] {C : Type u} [Category.{v} C]
variable {D : Type u''} [Category.{v''} D]
section Extensive
variable {X Y : C}
/-- A category has pullback of inclusions if it has all pullbacks along coproduct injections. -/
class HasPullbacksOfInclusions (C : Type u) [Category.{v} C] [HasBinaryCoproducts C] : Prop where
[hasPullbackInl : ∀ {X Y Z : C} (f : Z ⟶ X ⨿ Y), HasPullback coprod.inl f]
attribute [instance] HasPullbacksOfInclusions.hasPullbackInl
/--
A functor preserves pullback of inclusions if it preserves all pullbacks along coproduct injections.
-/
class PreservesPullbacksOfInclusions {C : Type*} [Category C] {D : Type*} [Category D]
(F : C ⥤ D) [HasBinaryCoproducts C] where
[preservesPullbackInl : ∀ {X Y Z : C} (f : Z ⟶ X ⨿ Y), PreservesLimit (cospan coprod.inl f) F]
attribute [instance] PreservesPullbacksOfInclusions.preservesPullbackInl
/-- A category is (finitary) pre-extensive if it has finite coproducts,
and binary coproducts are universal. -/
class FinitaryPreExtensive (C : Type u) [Category.{v} C] : Prop where
[hasFiniteCoproducts : HasFiniteCoproducts C]
[hasPullbacksOfInclusions : HasPullbacksOfInclusions C]
/-- In a finitary extensive category, all coproducts are van Kampen-/
universal' : ∀ {X Y : C} (c : BinaryCofan X Y), IsColimit c → IsUniversalColimit c
attribute [instance] FinitaryPreExtensive.hasFiniteCoproducts
attribute [instance] FinitaryPreExtensive.hasPullbacksOfInclusions
/-- A category is (finitary) extensive if it has finite coproducts,
and binary coproducts are van Kampen. -/
class FinitaryExtensive (C : Type u) [Category.{v} C] : Prop where
[hasFiniteCoproducts : HasFiniteCoproducts C]
[hasPullbacksOfInclusions : HasPullbacksOfInclusions C]
/-- In a finitary extensive category, all coproducts are van Kampen-/
van_kampen' : ∀ {X Y : C} (c : BinaryCofan X Y), IsColimit c → IsVanKampenColimit c
attribute [instance] FinitaryExtensive.hasFiniteCoproducts
attribute [instance] FinitaryExtensive.hasPullbacksOfInclusions
theorem FinitaryExtensive.vanKampen [FinitaryExtensive C] {F : Discrete WalkingPair ⥤ C}
(c : Cocone F) (hc : IsColimit c) : IsVanKampenColimit c := by
let X := F.obj ⟨WalkingPair.left⟩
let Y := F.obj ⟨WalkingPair.right⟩
have : F = pair X Y := by
apply Functor.hext
· rintro ⟨⟨⟩⟩ <;> rfl
· rintro ⟨⟨⟩⟩ ⟨j⟩ ⟨⟨rfl : _ = j⟩⟩ <;> simp
clear_value X Y
subst this
exact FinitaryExtensive.van_kampen' c hc
namespace HasPullbacksOfInclusions
instance (priority := 100) [HasBinaryCoproducts C] [HasPullbacks C] :
HasPullbacksOfInclusions C := ⟨⟩
variable [HasBinaryCoproducts C] [HasPullbacksOfInclusions C] {X Y Z : C} (f : Z ⟶ X ⨿ Y)
instance preservesPullbackInl' :
HasPullback f coprod.inl :=
hasPullback_symmetry _ _
instance hasPullbackInr' :
HasPullback f coprod.inr := by
have : IsPullback (𝟙 _) (f ≫ (coprod.braiding X Y).hom) f (coprod.braiding Y X).hom :=
IsPullback.of_horiz_isIso ⟨by simp⟩
have := (IsPullback.of_hasPullback (f ≫ (coprod.braiding X Y).hom) coprod.inl).paste_horiz this
simp only [coprod.braiding_hom, Category.comp_id, colimit.ι_desc, BinaryCofan.mk_pt,
BinaryCofan.ι_app_left, BinaryCofan.mk_inl] at this
exact ⟨⟨⟨_, this.isLimit⟩⟩⟩
instance hasPullbackInr :
HasPullback coprod.inr f :=
hasPullback_symmetry _ _
end HasPullbacksOfInclusions
namespace PreservesPullbacksOfInclusions
variable {D : Type*} [Category D] [HasBinaryCoproducts C] (F : C ⥤ D)
noncomputable
instance (priority := 100) [PreservesLimitsOfShape WalkingCospan F] :
PreservesPullbacksOfInclusions F := ⟨⟩
variable [PreservesPullbacksOfInclusions F] {X Y Z : C} (f : Z ⟶ X ⨿ Y)
noncomputable
instance preservesPullbackInl' :
PreservesLimit (cospan f coprod.inl) F :=
preservesPullbackSymmetry _ _ _
noncomputable
instance preservesPullbackInr' :
PreservesLimit (cospan f coprod.inr) F := by
apply preservesLimitOfIsoDiagram (K₁ := cospan (f ≫ (coprod.braiding X Y).hom) coprod.inl)
apply cospanExt (Iso.refl _) (Iso.refl _) (coprod.braiding X Y).symm <;> simp
noncomputable
instance preservesPullbackInr :
PreservesLimit (cospan coprod.inr f) F :=
preservesPullbackSymmetry _ _ _
end PreservesPullbacksOfInclusions
instance (priority := 100) FinitaryExtensive.toFinitaryPreExtensive [FinitaryExtensive C] :
FinitaryPreExtensive C :=
⟨fun c hc ↦ (FinitaryExtensive.van_kampen' c hc).isUniversal⟩
theorem FinitaryExtensive.mono_inr_of_isColimit [FinitaryExtensive C] {c : BinaryCofan X Y}
(hc : IsColimit c) : Mono c.inr :=
BinaryCofan.mono_inr_of_isVanKampen (FinitaryExtensive.vanKampen c hc)
theorem FinitaryExtensive.mono_inl_of_isColimit [FinitaryExtensive C] {c : BinaryCofan X Y}
(hc : IsColimit c) : Mono c.inl :=
FinitaryExtensive.mono_inr_of_isColimit (BinaryCofan.isColimitFlip hc)
instance [FinitaryExtensive C] (X Y : C) : Mono (coprod.inl : X ⟶ X ⨿ Y) :=
(FinitaryExtensive.mono_inl_of_isColimit (coprodIsCoprod X Y) : _)
instance [FinitaryExtensive C] (X Y : C) : Mono (coprod.inr : Y ⟶ X ⨿ Y) :=
(FinitaryExtensive.mono_inr_of_isColimit (coprodIsCoprod X Y) : _)
theorem FinitaryExtensive.isPullback_initial_to_binaryCofan [FinitaryExtensive C]
{c : BinaryCofan X Y} (hc : IsColimit c) :
IsPullback (initial.to _) (initial.to _) c.inl c.inr :=
BinaryCofan.isPullback_initial_to_of_isVanKampen (FinitaryExtensive.vanKampen c hc)
instance (priority := 100) hasStrictInitialObjects_of_finitaryPreExtensive
[FinitaryPreExtensive C] : HasStrictInitialObjects C :=
hasStrictInitial_of_isUniversal (FinitaryPreExtensive.universal' _
((BinaryCofan.isColimit_iff_isIso_inr initialIsInitial _).mpr (by
dsimp
infer_instance)).some)
theorem finitaryExtensive_iff_of_isTerminal (C : Type u) [Category.{v} C] [HasFiniteCoproducts C]
[HasPullbacksOfInclusions C]
(T : C) (HT : IsTerminal T) (c₀ : BinaryCofan T T) (hc₀ : IsColimit c₀) :
FinitaryExtensive C ↔ IsVanKampenColimit c₀ := by
refine ⟨fun H => H.van_kampen' c₀ hc₀, fun H => ?_⟩
constructor
simp_rw [BinaryCofan.isVanKampen_iff] at H ⊢
intro X Y c hc X' Y' c' αX αY f hX hY
obtain ⟨d, hd, hd'⟩ :=
Limits.BinaryCofan.IsColimit.desc' hc (HT.from _ ≫ c₀.inl) (HT.from _ ≫ c₀.inr)
rw [H c' (αX ≫ HT.from _) (αY ≫ HT.from _) (f ≫ d) (by rw [← reassoc_of% hX, hd, Category.assoc])
(by rw [← reassoc_of% hY, hd', Category.assoc])]
obtain ⟨hl, hr⟩ := (H c (HT.from _) (HT.from _) d hd.symm hd'.symm).mp ⟨hc⟩
rw [hl.paste_vert_iff hX.symm, hr.paste_vert_iff hY.symm]
instance types.finitaryExtensive : FinitaryExtensive (Type u) := by
classical
rw [finitaryExtensive_iff_of_isTerminal (Type u) PUnit Types.isTerminalPunit _
(Types.binaryCoproductColimit _ _)]
apply BinaryCofan.isVanKampen_mk _ _ (fun X Y => Types.binaryCoproductColimit X Y) _
fun f g => (Limits.Types.pullbackLimitCone f g).2
· intros _ _ _ _ f hαX hαY
constructor
· refine ⟨⟨hαX.symm⟩, ⟨PullbackCone.isLimitAux' _ ?_⟩⟩
intro s
have : ∀ x, ∃! y, s.fst x = Sum.inl y := by
intro x
cases' h : s.fst x with val val
· simp only [Types.binaryCoproductCocone_pt, Functor.const_obj_obj, Sum.inl.injEq,
exists_unique_eq']
· apply_fun f at h
cases ((congr_fun s.condition x).symm.trans h).trans (congr_fun hαY val : _).symm
delta ExistsUnique at this
choose l hl hl' using this
exact ⟨l, (funext hl).symm, Types.isTerminalPunit.hom_ext _ _,
fun {l'} h₁ _ => funext fun x => hl' x (l' x) (congr_fun h₁ x).symm⟩
· refine ⟨⟨hαY.symm⟩, ⟨PullbackCone.isLimitAux' _ ?_⟩⟩
intro s
have : ∀ x, ∃! y, s.fst x = Sum.inr y := by
intro x
cases' h : s.fst x with val val
· apply_fun f at h
cases ((congr_fun s.condition x).symm.trans h).trans (congr_fun hαX val : _).symm
· simp only [Types.binaryCoproductCocone_pt, Functor.const_obj_obj, Sum.inr.injEq,
exists_unique_eq']
delta ExistsUnique at this
choose l hl hl' using this
exact ⟨l, (funext hl).symm, Types.isTerminalPunit.hom_ext _ _,
fun {l'} h₁ _ => funext fun x => hl' x (l' x) (congr_fun h₁ x).symm⟩
· intro Z f
dsimp [Limits.Types.binaryCoproductCocone]
delta Types.PullbackObj
have : ∀ x, f x = Sum.inl PUnit.unit ∨ f x = Sum.inr PUnit.unit := by
intro x
rcases f x with (⟨⟨⟩⟩ | ⟨⟨⟩⟩)
exacts [Or.inl rfl, Or.inr rfl]
let eX : { p : Z × PUnit // f p.fst = Sum.inl p.snd } ≃ { x : Z // f x = Sum.inl PUnit.unit } :=
⟨fun p => ⟨p.1.1, by convert p.2⟩, fun x => ⟨⟨_, _⟩, x.2⟩, fun _ => by ext; rfl,
fun _ => by ext; rfl⟩
let eY : { p : Z × PUnit // f p.fst = Sum.inr p.snd } ≃ { x : Z // f x = Sum.inr PUnit.unit } :=
⟨fun p => ⟨p.1.1, p.2.trans (congr_arg Sum.inr <| Subsingleton.elim _ _)⟩,
fun x => ⟨⟨_, _⟩, x.2⟩, fun _ => by ext; rfl, fun _ => by ext; rfl⟩
fapply BinaryCofan.isColimitMk
· exact fun s x => dite _ (fun h => s.inl <| eX.symm ⟨x, h⟩)
fun h => s.inr <| eY.symm ⟨x, (this x).resolve_left h⟩
· intro s
ext ⟨⟨x, ⟨⟩⟩, _⟩
dsimp
split_ifs <;> rfl
· intro s
ext ⟨⟨x, ⟨⟩⟩, hx⟩
dsimp
split_ifs with h
· cases h.symm.trans hx
· rfl
· intro s m e₁ e₂
ext x
split_ifs
· rw [← e₁]
rfl
· rw [← e₂]
rfl
section TopCat
/-- (Implementation) An auxiliary lemma for the proof that `TopCat` is finitary extensive. -/
noncomputable def finitaryExtensiveTopCatAux (Z : TopCat.{u})
(f : Z ⟶ TopCat.of (PUnit.{u + 1} ⊕ PUnit.{u + 1})) :
IsColimit (BinaryCofan.mk
(TopCat.pullbackFst f (TopCat.binaryCofan (TopCat.of PUnit) (TopCat.of PUnit)).inl)
(TopCat.pullbackFst f (TopCat.binaryCofan (TopCat.of PUnit) (TopCat.of PUnit)).inr)) := by
have h₁ : Set.range (TopCat.pullbackFst f (TopCat.binaryCofan (.of PUnit) (.of PUnit)).inl) =
f ⁻¹' Set.range Sum.inl := by
apply le_antisymm
· rintro _ ⟨x, rfl⟩; exact ⟨PUnit.unit, x.2.symm⟩
· rintro x ⟨⟨⟩, hx⟩; refine ⟨⟨⟨x, PUnit.unit⟩, hx.symm⟩, rfl⟩
have h₂ : Set.range (TopCat.pullbackFst f (TopCat.binaryCofan (.of PUnit) (.of PUnit)).inr) =
f ⁻¹' Set.range Sum.inr := by
apply le_antisymm
· rintro _ ⟨x, rfl⟩; exact ⟨PUnit.unit, x.2.symm⟩
· rintro x ⟨⟨⟩, hx⟩; refine ⟨⟨⟨x, PUnit.unit⟩, hx.symm⟩, rfl⟩
refine ((TopCat.binaryCofan_isColimit_iff _).mpr ⟨?_, ?_, ?_⟩).some
· refine ⟨(Homeomorph.prodPUnit Z).embedding.comp embedding_subtype_val, ?_⟩
convert f.2.1 _ isOpen_range_inl
· refine ⟨(Homeomorph.prodPUnit Z).embedding.comp embedding_subtype_val, ?_⟩
convert f.2.1 _ isOpen_range_inr
· convert Set.isCompl_range_inl_range_inr.preimage f
instance finitaryExtensive_TopCat : FinitaryExtensive TopCat.{u} := by
rw [finitaryExtensive_iff_of_isTerminal TopCat.{u} _ TopCat.isTerminalPUnit _
(TopCat.binaryCofanIsColimit _ _)]
apply BinaryCofan.isVanKampen_mk _ _ (fun X Y => TopCat.binaryCofanIsColimit X Y) _
fun f g => TopCat.pullbackConeIsLimit f g
· intro X' Y' αX αY f hαX hαY
constructor
· refine ⟨⟨hαX.symm⟩, ⟨PullbackCone.isLimitAux' _ ?_⟩⟩
intro s
have : ∀ x, ∃! y, s.fst x = Sum.inl y := by
intro x
cases' h : s.fst x with val val
· exact ⟨val, rfl, fun y h => Sum.inl_injective h.symm⟩
· apply_fun f at h
cases ((ConcreteCategory.congr_hom s.condition x).symm.trans h).trans
(ConcreteCategory.congr_hom hαY val : _).symm
delta ExistsUnique at this
choose l hl hl' using this
refine ⟨⟨l, ?_⟩, ContinuousMap.ext fun a => (hl a).symm, TopCat.isTerminalPUnit.hom_ext _ _,
fun {l'} h₁ _ => ContinuousMap.ext fun x =>
hl' x (l' x) (ConcreteCategory.congr_hom h₁ x).symm⟩
apply (embedding_inl (X := X') (Y := Y')).toInducing.continuous_iff.mpr
convert s.fst.2 using 1
exact (funext hl).symm
· refine ⟨⟨hαY.symm⟩, ⟨PullbackCone.isLimitAux' _ ?_⟩⟩
intro s
have : ∀ x, ∃! y, s.fst x = Sum.inr y := by
intro x
cases' h : s.fst x with val val
· apply_fun f at h
cases ((ConcreteCategory.congr_hom s.condition x).symm.trans h).trans
(ConcreteCategory.congr_hom hαX val : _).symm
· exact ⟨val, rfl, fun y h => Sum.inr_injective h.symm⟩
delta ExistsUnique at this
choose l hl hl' using this
refine ⟨⟨l, ?_⟩, ContinuousMap.ext fun a => (hl a).symm, TopCat.isTerminalPUnit.hom_ext _ _,
fun {l'} h₁ _ =>
ContinuousMap.ext fun x => hl' x (l' x) (ConcreteCategory.congr_hom h₁ x).symm⟩
apply (embedding_inr (X := X') (Y := Y')).toInducing.continuous_iff.mpr
convert s.fst.2 using 1
exact (funext hl).symm
· intro Z f
exact finitaryExtensiveTopCatAux Z f
end TopCat
section Functor
theorem finitaryExtensive_of_reflective
[HasFiniteCoproducts D] [HasPullbacksOfInclusions D] [FinitaryExtensive C]
{Gl : C ⥤ D} {Gr : D ⥤ C} (adj : Gl ⊣ Gr) [Gr.Full] [Gr.Faithful]
[∀ X Y (f : X ⟶ Gl.obj Y), HasPullback (Gr.map f) (adj.unit.app Y)]
[∀ X Y (f : X ⟶ Gl.obj Y), PreservesLimit (cospan (Gr.map f) (adj.unit.app Y)) Gl]
[PreservesPullbacksOfInclusions Gl] :
FinitaryExtensive D := by
have : PreservesColimitsOfSize Gl := adj.leftAdjointPreservesColimits
constructor
intros X Y c hc
apply (IsVanKampenColimit.precompose_isIso_iff
(isoWhiskerLeft _ (asIso adj.counit) ≪≫ Functor.rightUnitor _).hom).mp
have : ∀ (Z : C) (i : Discrete WalkingPair) (f : Z ⟶ (colimit.cocone (pair X Y ⋙ Gr)).pt),
PreservesLimit (cospan f ((colimit.cocone (pair X Y ⋙ Gr)).ι.app i)) Gl := by
have : pair X Y ⋙ Gr = pair (Gr.obj X) (Gr.obj Y) := by
apply Functor.hext
· rintro ⟨⟨⟩⟩ <;> rfl
· rintro ⟨⟨⟩⟩ ⟨j⟩ ⟨⟨rfl : _ = j⟩⟩ <;> simp
rw [this]
rintro Z ⟨_|_⟩ f <;> dsimp <;> infer_instance
refine ((FinitaryExtensive.vanKampen _ (colimit.isColimit <| pair X Y ⋙ _)).map_reflective
adj).of_iso (IsColimit.uniqueUpToIso ?_ ?_)
· exact isColimitOfPreserves Gl (colimit.isColimit _)
· exact (IsColimit.precomposeHomEquiv _ _).symm hc
instance finitaryExtensive_functor [HasPullbacks C] [FinitaryExtensive C] :
FinitaryExtensive (D ⥤ C) :=
haveI : HasFiniteCoproducts (D ⥤ C) := ⟨fun _ => Limits.functorCategoryHasColimitsOfShape⟩
⟨fun c hc => isVanKampenColimit_of_evaluation _ c fun _ =>
FinitaryExtensive.vanKampen _ <| PreservesColimit.preserves hc⟩
noncomputable
instance {C} [Category C] {D} [Category D] (F : C ⥤ D)
{X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [IsIso f] : PreservesLimit (cospan f g) F :=
have := hasPullback_of_left_iso f g
preservesLimitOfPreservesLimitCone (IsPullback.of_hasPullback f g).isLimit
((isLimitMapConePullbackConeEquiv _ pullback.condition).symm
(IsPullback.of_vert_isIso ⟨by simp only [← F.map_comp, pullback.condition]⟩).isLimit)
noncomputable
instance {C} [Category C] {D} [Category D] (F : C ⥤ D)
{X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z) [IsIso g] : PreservesLimit (cospan f g) F :=
preservesPullbackSymmetry _ _ _
theorem finitaryExtensive_of_preserves_and_reflects (F : C ⥤ D) [FinitaryExtensive D]
[HasFiniteCoproducts C] [HasPullbacksOfInclusions C]
[PreservesPullbacksOfInclusions F]
[ReflectsLimitsOfShape WalkingCospan F] [PreservesColimitsOfShape (Discrete WalkingPair) F]
[ReflectsColimitsOfShape (Discrete WalkingPair) F] : FinitaryExtensive C := by
constructor
intros X Y c hc
refine IsVanKampenColimit.of_iso ?_ (hc.uniqueUpToIso (coprodIsCoprod X Y)).symm
have (i : Discrete WalkingPair) (Z : C) (f : Z ⟶ X ⨿ Y) :
PreservesLimit (cospan f ((BinaryCofan.mk coprod.inl coprod.inr).ι.app i)) F := by
rcases i with ⟨_|_⟩ <;> dsimp <;> infer_instance
refine (FinitaryExtensive.vanKampen _
(isColimitOfPreserves F (coprodIsCoprod X Y))).of_mapCocone F
theorem finitaryExtensive_of_preserves_and_reflects_isomorphism (F : C ⥤ D) [FinitaryExtensive D]
[HasFiniteCoproducts C] [HasPullbacks C] [PreservesLimitsOfShape WalkingCospan F]
[PreservesColimitsOfShape (Discrete WalkingPair) F] [F.ReflectsIsomorphisms] :
FinitaryExtensive C := by
haveI : ReflectsLimitsOfShape WalkingCospan F := reflectsLimitsOfShapeOfReflectsIsomorphisms
haveI : ReflectsColimitsOfShape (Discrete WalkingPair) F :=
reflectsColimitsOfShapeOfReflectsIsomorphisms
exact finitaryExtensive_of_preserves_and_reflects F
end Functor
section FiniteCoproducts
theorem FinitaryPreExtensive.isUniversal_finiteCoproducts_Fin [FinitaryPreExtensive C] {n : ℕ}
{F : Discrete (Fin n) ⥤ C} {c : Cocone F} (hc : IsColimit c) : IsUniversalColimit c := by
let f : Fin n → C := F.obj ∘ Discrete.mk
have : F = Discrete.functor f :=
Functor.hext (fun _ ↦ rfl) (by rintro ⟨i⟩ ⟨j⟩ ⟨⟨rfl : i = j⟩⟩; simp [f])
clear_value f
subst this
induction' n with n IH
· exact (isVanKampenColimit_of_isEmpty _ hc).isUniversal
· apply IsUniversalColimit.of_iso _
((extendCofanIsColimit f (coproductIsCoproduct _) (coprodIsCoprod _ _)).uniqueUpToIso hc)
apply @isUniversalColimit_extendCofan _ _ _ _ _ _ _ _ ?_
· apply IH
exact coproductIsCoproduct _
· apply FinitaryPreExtensive.universal'
exact coprodIsCoprod _ _
· dsimp
infer_instance
theorem FinitaryPreExtensive.isUniversal_finiteCoproducts [FinitaryPreExtensive C] {ι : Type*}
[Finite ι] {F : Discrete ι ⥤ C} {c : Cocone F} (hc : IsColimit c) : IsUniversalColimit c := by
obtain ⟨n, ⟨e⟩⟩ := Finite.exists_equiv_fin ι
apply (IsUniversalColimit.whiskerEquivalence_iff (Discrete.equivalence e).symm).mp
apply FinitaryPreExtensive.isUniversal_finiteCoproducts_Fin
exact (IsColimit.whiskerEquivalenceEquiv (Discrete.equivalence e).symm) hc
theorem FinitaryExtensive.isVanKampen_finiteCoproducts_Fin [FinitaryExtensive C] {n : ℕ}
{F : Discrete (Fin n) ⥤ C} {c : Cocone F} (hc : IsColimit c) : IsVanKampenColimit c := by
let f : Fin n → C := F.obj ∘ Discrete.mk
have : F = Discrete.functor f :=
Functor.hext (fun _ ↦ rfl) (by rintro ⟨i⟩ ⟨j⟩ ⟨⟨rfl : i = j⟩⟩; simp [f])
clear_value f
subst this
induction' n with n IH
· exact isVanKampenColimit_of_isEmpty _ hc
· apply IsVanKampenColimit.of_iso _
((extendCofanIsColimit f (coproductIsCoproduct _) (coprodIsCoprod _ _)).uniqueUpToIso hc)
apply @isVanKampenColimit_extendCofan _ _ _ _ _ _ _ _ ?_
· apply IH
exact coproductIsCoproduct _
· apply FinitaryExtensive.van_kampen'
exact coprodIsCoprod _ _
· dsimp
infer_instance
theorem FinitaryExtensive.isVanKampen_finiteCoproducts [FinitaryExtensive C] {ι : Type*}
[Finite ι] {F : Discrete ι ⥤ C} {c : Cocone F} (hc : IsColimit c) : IsVanKampenColimit c := by
obtain ⟨n, ⟨e⟩⟩ := Finite.exists_equiv_fin ι
apply (IsVanKampenColimit.whiskerEquivalence_iff (Discrete.equivalence e).symm).mp
apply FinitaryExtensive.isVanKampen_finiteCoproducts_Fin
exact (IsColimit.whiskerEquivalenceEquiv (Discrete.equivalence e).symm) hc
lemma FinitaryPreExtensive.hasPullbacks_of_is_coproduct [FinitaryPreExtensive C] {ι : Type*}
[Finite ι] {F : Discrete ι ⥤ C} {c : Cocone F} (hc : IsColimit c) (i : Discrete ι) {X : C}
(g : X ⟶ _) : HasPullback g (c.ι.app i) := by
classical
let f : ι → C := F.obj ∘ Discrete.mk
have : F = Discrete.functor f :=
Functor.hext (fun i ↦ rfl) (by rintro ⟨i⟩ ⟨j⟩ ⟨⟨rfl : i = j⟩⟩; simp [f])
clear_value f
subst this
change Cofan f at c
obtain ⟨i⟩ := i
let e : ∐ f ≅ f i ⨿ (∐ fun j : ({i}ᶜ : Set ι) ↦ f j) :=
{ hom := Sigma.desc (fun j ↦ if h : j = i then eqToHom (congr_arg f h) ≫ coprod.inl else
Sigma.ι (fun j : ({i}ᶜ : Set ι) ↦ f j) ⟨j, h⟩ ≫ coprod.inr)
inv := coprod.desc (Sigma.ι f i) (Sigma.desc fun j ↦ Sigma.ι f j)
hom_inv_id := by aesop_cat
inv_hom_id := by
ext j
· simp
· simp only [coprod.desc_comp, colimit.ι_desc, Cofan.mk_pt, Cofan.mk_ι_app,
eqToHom_refl, Category.id_comp, dite_true, BinaryCofan.mk_pt, BinaryCofan.ι_app_right,
BinaryCofan.mk_inr, colimit.ι_desc_assoc, Discrete.functor_obj, Category.comp_id]
exact dif_neg j.prop }
let e' : c.pt ≅ f i ⨿ (∐ fun j : ({i}ᶜ : Set ι) ↦ f j) :=
hc.coconePointUniqueUpToIso (getColimitCocone _).2 ≪≫ e
have : coprod.inl ≫ e'.inv = c.ι.app ⟨i⟩ := by
simp only [e', Iso.trans_inv, coprod.desc_comp, colimit.ι_desc, BinaryCofan.mk_pt,
BinaryCofan.ι_app_left, BinaryCofan.mk_inl]
exact colimit.comp_coconePointUniqueUpToIso_inv _ _
clear_value e'
rw [← this]
have : IsPullback (𝟙 _) (g ≫ e'.hom) g e'.inv := IsPullback.of_horiz_isIso ⟨by simp⟩
exact ⟨⟨⟨_, ((IsPullback.of_hasPullback (g ≫ e'.hom) coprod.inl).paste_horiz this).isLimit⟩⟩⟩
lemma FinitaryExtensive.mono_ι [FinitaryExtensive C] {ι : Type*} [Finite ι] {F : Discrete ι ⥤ C}
{c : Cocone F} (hc : IsColimit c) (i : Discrete ι) :
Mono (c.ι.app i) :=
mono_of_cofan_isVanKampen (isVanKampen_finiteCoproducts hc) _
instance [FinitaryExtensive C] {ι : Type*} [Finite ι] (X : ι → C) (i : ι) :
Mono (Sigma.ι X i) :=
FinitaryExtensive.mono_ι (coproductIsCoproduct _) ⟨i⟩
lemma FinitaryExtensive.isPullback_initial_to [FinitaryExtensive C]
{ι : Type*} [Finite ι] {F : Discrete ι ⥤ C}
{c : Cocone F} (hc : IsColimit c) (i j : Discrete ι) (e : i ≠ j) :
IsPullback (initial.to _) (initial.to _) (c.ι.app i) (c.ι.app j) :=
isPullback_initial_to_of_cofan_isVanKampen (isVanKampen_finiteCoproducts hc) i j e
lemma FinitaryExtensive.isPullback_initial_to_sigma_ι [FinitaryExtensive C] {ι : Type*} [Finite ι]
(X : ι → C) (i j : ι) (e : i ≠ j) :
IsPullback (initial.to _) (initial.to _) (Sigma.ι X i) (Sigma.ι X j) :=
FinitaryExtensive.isPullback_initial_to (coproductIsCoproduct _) ⟨i⟩ ⟨j⟩
(ne_of_apply_ne Discrete.as e)
instance FinitaryPreExtensive.hasPullbacks_of_inclusions [FinitaryPreExtensive C] {X Z : C}
{α : Type*} (f : X ⟶ Z) {Y : (a : α) → C} (i : (a : α) → Y a ⟶ Z) [Finite α]
[hi : IsIso (Sigma.desc i)] (a : α) : HasPullback f (i a) := by
apply FinitaryPreExtensive.hasPullbacks_of_is_coproduct (c := Cofan.mk Z i)
exact @IsColimit.ofPointIso (t := Cofan.mk Z i) (P := _) hi
lemma FinitaryPreExtensive.sigma_desc_iso [FinitaryPreExtensive C] {α : Type} [Finite α] {X : C}
{Z : α → C} (π : (a : α) → Z a ⟶ X) {Y : C} (f : Y ⟶ X) (hπ : IsIso (Sigma.desc π)) :
IsIso (Sigma.desc ((fun _ ↦ pullback.fst _ _) : (a : α) → pullback f (π a) ⟶ _)) := by
suffices IsColimit (Cofan.mk _ ((fun _ ↦ pullback.fst _ _) : (a : α) → pullback f (π a) ⟶ _)) by
change IsIso (this.coconePointUniqueUpToIso (getColimitCocone _).2).inv
infer_instance
let this : IsColimit (Cofan.mk X π) := by
refine @IsColimit.ofPointIso (t := Cofan.mk X π) (P := coproductIsCoproduct Z) ?_
convert hπ
simp [coproductIsCoproduct]
refine (FinitaryPreExtensive.isUniversal_finiteCoproducts this
(Cofan.mk _ ((fun _ ↦ pullback.fst _ _) : (a : α) → pullback f (π a) ⟶ _))
(Discrete.natTrans fun i ↦ pullback.snd _ _) f ?_
(NatTrans.equifibered_of_discrete _) ?_).some
· ext
simp [pullback.condition]
· exact fun j ↦ IsPullback.of_hasPullback f (π j.as)
end FiniteCoproducts
end Extensive
end CategoryTheory
|
CategoryTheory\FintypeCat.lean | /-
Copyright (c) 2020 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Adam Topaz
-/
import Mathlib.CategoryTheory.ConcreteCategory.Basic
import Mathlib.CategoryTheory.FullSubcategory
import Mathlib.CategoryTheory.Skeletal
import Mathlib.Data.Fintype.Card
/-!
# The category of finite types.
We define the category of finite types, denoted `FintypeCat` as
(bundled) types with a `Fintype` instance.
We also define `FintypeCat.Skeleton`, the standard skeleton of `FintypeCat` whose objects
are `Fin n` for `n : ℕ`. We prove that the obvious inclusion functor
`FintypeCat.Skeleton ⥤ FintypeCat` is an equivalence of categories in
`FintypeCat.Skeleton.equivalence`.
We prove that `FintypeCat.Skeleton` is a skeleton of `FintypeCat` in `FintypeCat.isSkeleton`.
-/
open scoped Classical
open CategoryTheory
/-- The category of finite types. -/
def FintypeCat :=
Bundled Fintype
namespace FintypeCat
instance : CoeSort FintypeCat Type* :=
Bundled.coeSort
/-- Construct a bundled `FintypeCat` from the underlying type and typeclass. -/
def of (X : Type*) [Fintype X] : FintypeCat :=
Bundled.of X
instance : Inhabited FintypeCat :=
⟨of PEmpty⟩
instance {X : FintypeCat} : Fintype X :=
X.2
instance : Category FintypeCat :=
InducedCategory.category Bundled.α
/-- The fully faithful embedding of `FintypeCat` into the category of types. -/
@[simps!]
def incl : FintypeCat ⥤ Type* :=
inducedFunctor _
instance : incl.Full := InducedCategory.full _
instance : incl.Faithful := InducedCategory.faithful _
instance concreteCategoryFintype : ConcreteCategory FintypeCat :=
⟨incl⟩
/- Help typeclass inference infer fullness of forgetful functor. -/
instance : (forget FintypeCat).Full := inferInstanceAs <| FintypeCat.incl.Full
@[simp]
theorem id_apply (X : FintypeCat) (x : X) : (𝟙 X : X → X) x = x :=
rfl
@[simp]
theorem comp_apply {X Y Z : FintypeCat} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g) x = g (f x) :=
rfl
@[simp]
lemma hom_inv_id_apply {X Y : FintypeCat} (f : X ≅ Y) (x : X) : f.inv (f.hom x) = x :=
congr_fun f.hom_inv_id x
@[simp]
lemma inv_hom_id_apply {X Y : FintypeCat} (f : X ≅ Y) (y : Y) : f.hom (f.inv y) = y :=
congr_fun f.inv_hom_id y
-- Porting note (#10688): added to ease automation
@[ext]
lemma hom_ext {X Y : FintypeCat} (f g : X ⟶ Y) (h : ∀ x, f x = g x) : f = g := by
funext
apply h
-- See `equivEquivIso` in the root namespace for the analogue in `Type`.
/-- Equivalences between finite types are the same as isomorphisms in `FintypeCat`. -/
@[simps]
def equivEquivIso {A B : FintypeCat} : A ≃ B ≃ (A ≅ B) where
toFun e :=
{ hom := e
inv := e.symm }
invFun i :=
{ toFun := i.hom
invFun := i.inv
left_inv := congr_fun i.hom_inv_id
right_inv := congr_fun i.inv_hom_id }
left_inv := by aesop_cat
right_inv := by aesop_cat
universe u
/--
The "standard" skeleton for `FintypeCat`. This is the full subcategory of `FintypeCat`
spanned by objects of the form `ULift (Fin n)` for `n : ℕ`. We parameterize the objects
of `Fintype.Skeleton` directly as `ULift ℕ`, as the type `ULift (Fin m) ≃ ULift (Fin n)`
is nonempty if and only if `n = m`. Specifying universes, `Skeleton : Type u` is a small
skeletal category equivalent to `Fintype.{u}`.
-/
def Skeleton : Type u :=
ULift ℕ
namespace Skeleton
/-- Given any natural number `n`, this creates the associated object of `Fintype.Skeleton`. -/
def mk : ℕ → Skeleton :=
ULift.up
instance : Inhabited Skeleton :=
⟨mk 0⟩
/-- Given any object of `Fintype.Skeleton`, this returns the associated natural number. -/
def len : Skeleton → ℕ :=
ULift.down
@[ext]
theorem ext (X Y : Skeleton) : X.len = Y.len → X = Y :=
ULift.ext _ _
instance : SmallCategory Skeleton.{u} where
Hom X Y := ULift.{u} (Fin X.len) → ULift.{u} (Fin Y.len)
id _ := id
comp f g := g ∘ f
theorem is_skeletal : Skeletal Skeleton.{u} := fun X Y ⟨h⟩ =>
ext _ _ <|
Fin.equiv_iff_eq.mp <|
Nonempty.intro <|
{ toFun := fun x => (h.hom ⟨x⟩).down
invFun := fun x => (h.inv ⟨x⟩).down
left_inv := by
intro a
change ULift.down _ = _
rw [ULift.up_down]
change ((h.hom ≫ h.inv) _).down = _
simp
rfl
right_inv := by
intro a
change ULift.down _ = _
rw [ULift.up_down]
change ((h.inv ≫ h.hom) _).down = _
simp
rfl }
/-- The canonical fully faithful embedding of `Fintype.Skeleton` into `FintypeCat`. -/
def incl : Skeleton.{u} ⥤ FintypeCat.{u} where
obj X := FintypeCat.of (ULift (Fin X.len))
map f := f
instance : incl.Full where map_surjective f := ⟨f, rfl⟩
instance : incl.Faithful where
instance : incl.EssSurj :=
Functor.EssSurj.mk fun X =>
let F := Fintype.equivFin X
⟨mk (Fintype.card X),
Nonempty.intro
{ hom := F.symm ∘ ULift.down
inv := ULift.up ∘ F }⟩
noncomputable instance : incl.IsEquivalence where
/-- The equivalence between `Fintype.Skeleton` and `Fintype`. -/
noncomputable def equivalence : Skeleton ≌ FintypeCat :=
incl.asEquivalence
@[simp]
theorem incl_mk_nat_card (n : ℕ) : Fintype.card (incl.obj (mk n)) = n := by
convert Finset.card_fin n
apply Fintype.ofEquiv_card
end Skeleton
/-- `Fintype.Skeleton` is a skeleton of `Fintype`. -/
lemma isSkeleton : IsSkeletonOf FintypeCat Skeleton Skeleton.incl where
skel := Skeleton.is_skeletal
eqv := by infer_instance
end FintypeCat
|
CategoryTheory\FullSubcategory.lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Reid Barton
-/
import Mathlib.CategoryTheory.Functor.FullyFaithful
/-!
# Induced categories and full subcategories
Given a category `D` and a function `F : C → D `from a type `C` to the
objects of `D`, there is an essentially unique way to give `C` a
category structure such that `F` becomes a fully faithful functor,
namely by taking $$ Hom_C(X, Y) = Hom_D(FX, FY) $$. We call this the
category induced from `D` along `F`.
As a special case, if `C` is a subtype of `D`,
this produces the full subcategory of `D` on the objects belonging to `C`.
In general the induced category is equivalent to the full subcategory of `D` on the
image of `F`.
## Implementation notes
It looks odd to make `D` an explicit argument of `InducedCategory`,
when it is determined by the argument `F` anyways. The reason to make `D`
explicit is in order to control its syntactic form, so that instances
like `InducedCategory.has_forget₂` (elsewhere) refer to the correct
form of `D`. This is used to set up several algebraic categories like
def CommMon : Type (u+1) := InducedCategory Mon (Bundled.map @CommMonoid.toMonoid)
-- not `InducedCategory (Bundled Monoid) (Bundled.map @CommMonoid.toMonoid)`,
-- even though `MonCat = Bundled Monoid`!
-/
namespace CategoryTheory
universe v v₂ u₁ u₂
-- morphism levels before object levels. See note [CategoryTheory universes].
section Induced
variable {C : Type u₁} (D : Type u₂) [Category.{v} D]
variable (F : C → D)
/-- `InducedCategory D F`, where `F : C → D`, is a typeclass synonym for `C`,
which provides a category structure so that the morphisms `X ⟶ Y` are the morphisms
in `D` from `F X` to `F Y`.
-/
-- Porting note(#5171): removed @[nolint has_nonempty_instance]
@[nolint unusedArguments]
def InducedCategory (_F : C → D) : Type u₁ :=
C
variable {D}
instance InducedCategory.hasCoeToSort {α : Sort*} [CoeSort D α] :
CoeSort (InducedCategory D F) α :=
⟨fun c => F c⟩
instance InducedCategory.category : Category.{v} (InducedCategory D F) where
Hom X Y := F X ⟶ F Y
id X := 𝟙 (F X)
comp f g := f ≫ g
/-- The forgetful functor from an induced category to the original category,
forgetting the extra data.
-/
@[simps]
def inducedFunctor : InducedCategory D F ⥤ D where
obj := F
map f := f
/-- The induced functor `inducedFunctor F : InducedCategory D F ⥤ D` is fully faithful. -/
def fullyFaithfulInducedFunctor : (inducedFunctor F).FullyFaithful where
preimage f := f
instance InducedCategory.full : (inducedFunctor F).Full :=
(fullyFaithfulInducedFunctor F).full
instance InducedCategory.faithful : (inducedFunctor F).Faithful :=
(fullyFaithfulInducedFunctor F).faithful
end Induced
section FullSubcategory
variable {C : Type u₁} [Category.{v} C]
variable (Z : C → Prop)
/--
A subtype-like structure for full subcategories. Morphisms just ignore the property. We don't use
actual subtypes since the simp-normal form `↑X` of `X.val` does not work well for full
subcategories.
See <https://stacks.math.columbia.edu/tag/001D>. We do not define 'strictly full' subcategories.
-/
@[ext]
structure FullSubcategory where
/-- The category of which this is a full subcategory-/
obj : C
/-- The predicate satisfied by all objects in this subcategory-/
property : Z obj
instance FullSubcategory.category : Category.{v} (FullSubcategory Z) :=
InducedCategory.category FullSubcategory.obj
-- these lemmas are not particularly well-typed, so would probably be dangerous as simp lemmas
lemma FullSubcategory.id_def (X : FullSubcategory Z) : 𝟙 X = 𝟙 X.obj := rfl
lemma FullSubcategory.comp_def {X Y Z : FullSubcategory Z} (f : X ⟶ Y) (g : Y ⟶ Z) :
f ≫ g = (f ≫ g : X.obj ⟶ Z.obj) := rfl
/-- The forgetful functor from a full subcategory into the original category
("forgetting" the condition).
-/
def fullSubcategoryInclusion : FullSubcategory Z ⥤ C :=
inducedFunctor FullSubcategory.obj
@[simp]
theorem fullSubcategoryInclusion.obj {X} : (fullSubcategoryInclusion Z).obj X = X.obj :=
rfl
@[simp]
theorem fullSubcategoryInclusion.map {X Y} {f : X ⟶ Y} : (fullSubcategoryInclusion Z).map f = f :=
rfl
/-- The inclusion of a full subcategory is fully faithful. -/
abbrev fullyFaithfulFullSubcategoryInclusion :
(fullSubcategoryInclusion Z).FullyFaithful :=
fullyFaithfulInducedFunctor _
instance FullSubcategory.full : (fullSubcategoryInclusion Z).Full :=
(fullyFaithfulFullSubcategoryInclusion _).full
instance FullSubcategory.faithful : (fullSubcategoryInclusion Z).Faithful :=
(fullyFaithfulFullSubcategoryInclusion _).faithful
variable {Z} {Z' : C → Prop}
/-- An implication of predicates `Z → Z'` induces a functor between full subcategories. -/
@[simps]
def FullSubcategory.map (h : ∀ ⦃X⦄, Z X → Z' X) : FullSubcategory Z ⥤ FullSubcategory Z' where
obj X := ⟨X.1, h X.2⟩
map f := f
instance FullSubcategory.full_map (h : ∀ ⦃X⦄, Z X → Z' X) :
(FullSubcategory.map h).Full where map_surjective f := ⟨f, rfl⟩
instance FullSubcategory.faithful_map (h : ∀ ⦃X⦄, Z X → Z' X) :
(FullSubcategory.map h).Faithful where
@[simp]
theorem FullSubcategory.map_inclusion (h : ∀ ⦃X⦄, Z X → Z' X) :
FullSubcategory.map h ⋙ fullSubcategoryInclusion Z' = fullSubcategoryInclusion Z :=
rfl
section lift
variable {D : Type u₂} [Category.{v₂} D] (P Q : D → Prop)
/-- A functor which maps objects to objects satisfying a certain property induces a lift through
the full subcategory of objects satisfying that property. -/
@[simps]
def FullSubcategory.lift (F : C ⥤ D) (hF : ∀ X, P (F.obj X)) : C ⥤ FullSubcategory P where
obj X := ⟨F.obj X, hF X⟩
map f := F.map f
@[simp]
theorem FullSubcategory.lift_comp_inclusion_eq (F : C ⥤ D) (hF : ∀ X, P (F.obj X)) :
FullSubcategory.lift P F hF ⋙ fullSubcategoryInclusion P = F :=
rfl
/-- Composing the lift of a functor through a full subcategory with the inclusion yields the
original functor. This is actually true definitionally. -/
def FullSubcategory.lift_comp_inclusion (F : C ⥤ D) (hF : ∀ X, P (F.obj X)) :
FullSubcategory.lift P F hF ⋙ fullSubcategoryInclusion P ≅ F :=
Iso.refl _
@[simp]
theorem fullSubcategoryInclusion_obj_lift_obj (F : C ⥤ D) (hF : ∀ X, P (F.obj X)) {X : C} :
(fullSubcategoryInclusion P).obj ((FullSubcategory.lift P F hF).obj X) = F.obj X :=
rfl
@[simp]
theorem fullSubcategoryInclusion_map_lift_map (F : C ⥤ D) (hF : ∀ X, P (F.obj X)) {X Y : C}
(f : X ⟶ Y) :
(fullSubcategoryInclusion P).map ((FullSubcategory.lift P F hF).map f) = F.map f :=
rfl
instance (F : C ⥤ D) (hF : ∀ X, P (F.obj X)) [F.Faithful] :
(FullSubcategory.lift P F hF).Faithful :=
Functor.Faithful.of_comp_iso (FullSubcategory.lift_comp_inclusion P F hF)
instance (F : C ⥤ D) (hF : ∀ X, P (F.obj X)) [F.Full] : (FullSubcategory.lift P F hF).Full :=
Functor.Full.of_comp_faithful_iso (FullSubcategory.lift_comp_inclusion P F hF)
@[simp]
theorem FullSubcategory.lift_comp_map (F : C ⥤ D) (hF : ∀ X, P (F.obj X)) (h : ∀ ⦃X⦄, P X → Q X) :
FullSubcategory.lift P F hF ⋙ FullSubcategory.map h =
FullSubcategory.lift Q F fun X => h (hF X) :=
rfl
end lift
end FullSubcategory
end CategoryTheory
|
CategoryTheory\Generator.lean | /-
Copyright (c) 2022 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.CategoryTheory.Balanced
import Mathlib.CategoryTheory.Limits.EssentiallySmall
import Mathlib.CategoryTheory.Limits.Opposites
import Mathlib.CategoryTheory.Limits.Shapes.ZeroMorphisms
import Mathlib.CategoryTheory.Subobject.Lattice
import Mathlib.CategoryTheory.Subobject.WellPowered
import Mathlib.Data.Set.Opposite
import Mathlib.Data.Set.Subsingleton
/-!
# Separating and detecting sets
There are several non-equivalent notions of a generator of a category. Here, we consider two of
them:
* We say that `𝒢` is a separating set if the functors `C(G, -)` for `G ∈ 𝒢` are collectively
faithful, i.e., if `h ≫ f = h ≫ g` for all `h` with domain in `𝒢` implies `f = g`.
* We say that `𝒢` is a detecting set if the functors `C(G, -)` collectively reflect isomorphisms,
i.e., if any `h` with domain in `𝒢` uniquely factors through `f`, then `f` is an isomorphism.
There are, of course, also the dual notions of coseparating and codetecting sets.
## Main results
We
* define predicates `IsSeparating`, `IsCoseparating`, `IsDetecting` and `IsCodetecting` on
sets of objects;
* show that separating and coseparating are dual notions;
* show that detecting and codetecting are dual notions;
* show that if `C` has equalizers, then detecting implies separating;
* show that if `C` has coequalizers, then codetecting implies separating;
* show that if `C` is balanced, then separating implies detecting and coseparating implies
codetecting;
* show that `∅` is separating if and only if `∅` is coseparating if and only if `C` is thin;
* show that `∅` is detecting if and only if `∅` is codetecting if and only if `C` is a groupoid;
* define predicates `IsSeparator`, `IsCoseparator`, `IsDetector` and `IsCodetector` as the
singleton counterparts to the definitions for sets above and restate the above results in this
situation;
* show that `G` is a separator if and only if `coyoneda.obj (op G)` is faithful (and the dual);
* show that `G` is a detector if and only if `coyoneda.obj (op G)` reflects isomorphisms (and the
dual).
## Future work
* We currently don't have any examples yet.
* We will want typeclasses `HasSeparator C` and similar.
-/
universe w v₁ v₂ u₁ u₂
open CategoryTheory.Limits Opposite
namespace CategoryTheory
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D]
/-- We say that `𝒢` is a separating set if the functors `C(G, -)` for `G ∈ 𝒢` are collectively
faithful, i.e., if `h ≫ f = h ≫ g` for all `h` with domain in `𝒢` implies `f = g`. -/
def IsSeparating (𝒢 : Set C) : Prop :=
∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ G ∈ 𝒢, ∀ (h : G ⟶ X), h ≫ f = h ≫ g) → f = g
/-- We say that `𝒢` is a coseparating set if the functors `C(-, G)` for `G ∈ 𝒢` are collectively
faithful, i.e., if `f ≫ h = g ≫ h` for all `h` with codomain in `𝒢` implies `f = g`. -/
def IsCoseparating (𝒢 : Set C) : Prop :=
∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ G ∈ 𝒢, ∀ (h : Y ⟶ G), f ≫ h = g ≫ h) → f = g
/-- We say that `𝒢` is a detecting set if the functors `C(G, -)` collectively reflect isomorphisms,
i.e., if any `h` with domain in `𝒢` uniquely factors through `f`, then `f` is an isomorphism. -/
def IsDetecting (𝒢 : Set C) : Prop :=
∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ G ∈ 𝒢, ∀ (h : G ⟶ Y), ∃! h' : G ⟶ X, h' ≫ f = h) → IsIso f
/-- We say that `𝒢` is a codetecting set if the functors `C(-, G)` collectively reflect
isomorphisms, i.e., if any `h` with codomain in `G` uniquely factors through `f`, then `f` is
an isomorphism. -/
def IsCodetecting (𝒢 : Set C) : Prop :=
∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ G ∈ 𝒢, ∀ (h : X ⟶ G), ∃! h' : Y ⟶ G, f ≫ h' = h) → IsIso f
section Dual
theorem isSeparating_op_iff (𝒢 : Set C) : IsSeparating 𝒢.op ↔ IsCoseparating 𝒢 := by
refine ⟨fun h𝒢 X Y f g hfg => ?_, fun h𝒢 X Y f g hfg => ?_⟩
· refine Quiver.Hom.op_inj (h𝒢 _ _ fun G hG h => Quiver.Hom.unop_inj ?_)
simpa only [unop_comp, Quiver.Hom.unop_op] using hfg _ (Set.mem_op.1 hG) _
· refine Quiver.Hom.unop_inj (h𝒢 _ _ fun G hG h => Quiver.Hom.op_inj ?_)
simpa only [op_comp, Quiver.Hom.op_unop] using hfg _ (Set.op_mem_op.2 hG) _
theorem isCoseparating_op_iff (𝒢 : Set C) : IsCoseparating 𝒢.op ↔ IsSeparating 𝒢 := by
refine ⟨fun h𝒢 X Y f g hfg => ?_, fun h𝒢 X Y f g hfg => ?_⟩
· refine Quiver.Hom.op_inj (h𝒢 _ _ fun G hG h => Quiver.Hom.unop_inj ?_)
simpa only [unop_comp, Quiver.Hom.unop_op] using hfg _ (Set.mem_op.1 hG) _
· refine Quiver.Hom.unop_inj (h𝒢 _ _ fun G hG h => Quiver.Hom.op_inj ?_)
simpa only [op_comp, Quiver.Hom.op_unop] using hfg _ (Set.op_mem_op.2 hG) _
theorem isCoseparating_unop_iff (𝒢 : Set Cᵒᵖ) : IsCoseparating 𝒢.unop ↔ IsSeparating 𝒢 := by
rw [← isSeparating_op_iff, Set.unop_op]
theorem isSeparating_unop_iff (𝒢 : Set Cᵒᵖ) : IsSeparating 𝒢.unop ↔ IsCoseparating 𝒢 := by
rw [← isCoseparating_op_iff, Set.unop_op]
theorem isDetecting_op_iff (𝒢 : Set C) : IsDetecting 𝒢.op ↔ IsCodetecting 𝒢 := by
refine ⟨fun h𝒢 X Y f hf => ?_, fun h𝒢 X Y f hf => ?_⟩
· refine (isIso_op_iff _).1 (h𝒢 _ fun G hG h => ?_)
obtain ⟨t, ht, ht'⟩ := hf (unop G) (Set.mem_op.1 hG) h.unop
exact
⟨t.op, Quiver.Hom.unop_inj ht, fun y hy => Quiver.Hom.unop_inj (ht' _ (Quiver.Hom.op_inj hy))⟩
· refine (isIso_unop_iff _).1 (h𝒢 _ fun G hG h => ?_)
obtain ⟨t, ht, ht'⟩ := hf (op G) (Set.op_mem_op.2 hG) h.op
refine ⟨t.unop, Quiver.Hom.op_inj ht, fun y hy => Quiver.Hom.op_inj (ht' _ ?_)⟩
exact Quiver.Hom.unop_inj (by simpa only using hy)
theorem isCodetecting_op_iff (𝒢 : Set C) : IsCodetecting 𝒢.op ↔ IsDetecting 𝒢 := by
refine ⟨fun h𝒢 X Y f hf => ?_, fun h𝒢 X Y f hf => ?_⟩
· refine (isIso_op_iff _).1 (h𝒢 _ fun G hG h => ?_)
obtain ⟨t, ht, ht'⟩ := hf (unop G) (Set.mem_op.1 hG) h.unop
exact
⟨t.op, Quiver.Hom.unop_inj ht, fun y hy => Quiver.Hom.unop_inj (ht' _ (Quiver.Hom.op_inj hy))⟩
· refine (isIso_unop_iff _).1 (h𝒢 _ fun G hG h => ?_)
obtain ⟨t, ht, ht'⟩ := hf (op G) (Set.op_mem_op.2 hG) h.op
refine ⟨t.unop, Quiver.Hom.op_inj ht, fun y hy => Quiver.Hom.op_inj (ht' _ ?_)⟩
exact Quiver.Hom.unop_inj (by simpa only using hy)
theorem isDetecting_unop_iff (𝒢 : Set Cᵒᵖ) : IsDetecting 𝒢.unop ↔ IsCodetecting 𝒢 := by
rw [← isCodetecting_op_iff, Set.unop_op]
theorem isCodetecting_unop_iff {𝒢 : Set Cᵒᵖ} : IsCodetecting 𝒢.unop ↔ IsDetecting 𝒢 := by
rw [← isDetecting_op_iff, Set.unop_op]
end Dual
theorem IsDetecting.isSeparating [HasEqualizers C] {𝒢 : Set C} (h𝒢 : IsDetecting 𝒢) :
IsSeparating 𝒢 := fun _ _ f g hfg =>
have : IsIso (equalizer.ι f g) := h𝒢 _ fun _ hG _ => equalizer.existsUnique _ (hfg _ hG _)
eq_of_epi_equalizer
section
theorem IsCodetecting.isCoseparating [HasCoequalizers C] {𝒢 : Set C} :
IsCodetecting 𝒢 → IsCoseparating 𝒢 := by
simpa only [← isSeparating_op_iff, ← isDetecting_op_iff] using IsDetecting.isSeparating
end
theorem IsSeparating.isDetecting [Balanced C] {𝒢 : Set C} (h𝒢 : IsSeparating 𝒢) :
IsDetecting 𝒢 := by
intro X Y f hf
refine
(isIso_iff_mono_and_epi _).2 ⟨⟨fun g h hgh => h𝒢 _ _ fun G hG i => ?_⟩, ⟨fun g h hgh => ?_⟩⟩
· obtain ⟨t, -, ht⟩ := hf G hG (i ≫ g ≫ f)
rw [ht (i ≫ g) (Category.assoc _ _ _), ht (i ≫ h) (hgh.symm ▸ Category.assoc _ _ _)]
· refine h𝒢 _ _ fun G hG i => ?_
obtain ⟨t, rfl, -⟩ := hf G hG i
rw [Category.assoc, hgh, Category.assoc]
section
attribute [local instance] balanced_opposite
theorem IsCoseparating.isCodetecting [Balanced C] {𝒢 : Set C} :
IsCoseparating 𝒢 → IsCodetecting 𝒢 := by
simpa only [← isDetecting_op_iff, ← isSeparating_op_iff] using IsSeparating.isDetecting
end
theorem isDetecting_iff_isSeparating [HasEqualizers C] [Balanced C] (𝒢 : Set C) :
IsDetecting 𝒢 ↔ IsSeparating 𝒢 :=
⟨IsDetecting.isSeparating, IsSeparating.isDetecting⟩
theorem isCodetecting_iff_isCoseparating [HasCoequalizers C] [Balanced C] {𝒢 : Set C} :
IsCodetecting 𝒢 ↔ IsCoseparating 𝒢 :=
⟨IsCodetecting.isCoseparating, IsCoseparating.isCodetecting⟩
section Mono
theorem IsSeparating.mono {𝒢 : Set C} (h𝒢 : IsSeparating 𝒢) {ℋ : Set C} (h𝒢ℋ : 𝒢 ⊆ ℋ) :
IsSeparating ℋ := fun _ _ _ _ hfg => h𝒢 _ _ fun _ hG _ => hfg _ (h𝒢ℋ hG) _
theorem IsCoseparating.mono {𝒢 : Set C} (h𝒢 : IsCoseparating 𝒢) {ℋ : Set C} (h𝒢ℋ : 𝒢 ⊆ ℋ) :
IsCoseparating ℋ := fun _ _ _ _ hfg => h𝒢 _ _ fun _ hG _ => hfg _ (h𝒢ℋ hG) _
theorem IsDetecting.mono {𝒢 : Set C} (h𝒢 : IsDetecting 𝒢) {ℋ : Set C} (h𝒢ℋ : 𝒢 ⊆ ℋ) :
IsDetecting ℋ := fun _ _ _ hf => h𝒢 _ fun _ hG _ => hf _ (h𝒢ℋ hG) _
theorem IsCodetecting.mono {𝒢 : Set C} (h𝒢 : IsCodetecting 𝒢) {ℋ : Set C} (h𝒢ℋ : 𝒢 ⊆ ℋ) :
IsCodetecting ℋ := fun _ _ _ hf => h𝒢 _ fun _ hG _ => hf _ (h𝒢ℋ hG) _
end Mono
section Empty
theorem thin_of_isSeparating_empty (h : IsSeparating (∅ : Set C)) : Quiver.IsThin C := fun _ _ =>
⟨fun _ _ => h _ _ fun _ => False.elim⟩
theorem isSeparating_empty_of_thin [Quiver.IsThin C] : IsSeparating (∅ : Set C) :=
fun _ _ _ _ _ => Subsingleton.elim _ _
theorem thin_of_isCoseparating_empty (h : IsCoseparating (∅ : Set C)) : Quiver.IsThin C :=
fun _ _ => ⟨fun _ _ => h _ _ fun _ => False.elim⟩
theorem isCoseparating_empty_of_thin [Quiver.IsThin C] : IsCoseparating (∅ : Set C) :=
fun _ _ _ _ _ => Subsingleton.elim _ _
theorem groupoid_of_isDetecting_empty (h : IsDetecting (∅ : Set C)) {X Y : C} (f : X ⟶ Y) :
IsIso f :=
h _ fun _ => False.elim
theorem isDetecting_empty_of_groupoid [∀ {X Y : C} (f : X ⟶ Y), IsIso f] :
IsDetecting (∅ : Set C) := fun _ _ _ _ => inferInstance
theorem groupoid_of_isCodetecting_empty (h : IsCodetecting (∅ : Set C)) {X Y : C} (f : X ⟶ Y) :
IsIso f :=
h _ fun _ => False.elim
theorem isCodetecting_empty_of_groupoid [∀ {X Y : C} (f : X ⟶ Y), IsIso f] :
IsCodetecting (∅ : Set C) := fun _ _ _ _ => inferInstance
end Empty
theorem isSeparating_iff_epi (𝒢 : Set C)
[∀ A : C, HasCoproduct fun f : ΣG : 𝒢, (G : C) ⟶ A => (f.1 : C)] :
IsSeparating 𝒢 ↔ ∀ A : C, Epi (Sigma.desc (@Sigma.snd 𝒢 fun G => (G : C) ⟶ A)) := by
refine ⟨fun h A => ⟨fun u v huv => h _ _ fun G hG f => ?_⟩, fun h X Y f g hh => ?_⟩
· simpa using Sigma.ι (fun f : ΣG : 𝒢, (G : C) ⟶ A => (f.1 : C)) ⟨⟨G, hG⟩, f⟩ ≫= huv
· haveI := h X
refine
(cancel_epi (Sigma.desc (@Sigma.snd 𝒢 fun G => (G : C) ⟶ X))).1 (colimit.hom_ext fun j => ?_)
simpa using hh j.as.1.1 j.as.1.2 j.as.2
theorem isCoseparating_iff_mono (𝒢 : Set C)
[∀ A : C, HasProduct fun f : ΣG : 𝒢, A ⟶ (G : C) => (f.1 : C)] :
IsCoseparating 𝒢 ↔ ∀ A : C, Mono (Pi.lift (@Sigma.snd 𝒢 fun G => A ⟶ (G : C))) := by
refine ⟨fun h A => ⟨fun u v huv => h _ _ fun G hG f => ?_⟩, fun h X Y f g hh => ?_⟩
· simpa using huv =≫ Pi.π (fun f : ΣG : 𝒢, A ⟶ (G : C) => (f.1 : C)) ⟨⟨G, hG⟩, f⟩
· haveI := h Y
refine (cancel_mono (Pi.lift (@Sigma.snd 𝒢 fun G => Y ⟶ (G : C)))).1 (limit.hom_ext fun j => ?_)
simpa using hh j.as.1.1 j.as.1.2 j.as.2
/-- An ingredient of the proof of the Special Adjoint Functor Theorem: a complete well-powered
category with a small coseparating set has an initial object.
In fact, it follows from the Special Adjoint Functor Theorem that `C` is already cocomplete,
see `hasColimits_of_hasLimits_of_isCoseparating`. -/
theorem hasInitial_of_isCoseparating [WellPowered C] [HasLimits C] {𝒢 : Set C} [Small.{v₁} 𝒢]
(h𝒢 : IsCoseparating 𝒢) : HasInitial C := by
haveI : HasProductsOfShape 𝒢 C := hasProductsOfShape_of_small C 𝒢
haveI := fun A => hasProductsOfShape_of_small.{v₁} C (ΣG : 𝒢, A ⟶ (G : C))
letI := completeLatticeOfCompleteSemilatticeInf (Subobject (piObj (Subtype.val : 𝒢 → C)))
suffices ∀ A : C, Unique (((⊥ : Subobject (piObj (Subtype.val : 𝒢 → C))) : C) ⟶ A) by
exact hasInitial_of_unique ((⊥ : Subobject (piObj (Subtype.val : 𝒢 → C))) : C)
refine fun A => ⟨⟨?_⟩, fun f => ?_⟩
· let s := Pi.lift fun f : ΣG : 𝒢, A ⟶ (G : C) => id (Pi.π (Subtype.val : 𝒢 → C)) f.1
let t := Pi.lift (@Sigma.snd 𝒢 fun G => A ⟶ (G : C))
haveI : Mono t := (isCoseparating_iff_mono 𝒢).1 h𝒢 A
exact Subobject.ofLEMk _ (pullback.fst _ _ : pullback s t ⟶ _) bot_le ≫ pullback.snd _ _
· suffices ∀ (g : Subobject.underlying.obj ⊥ ⟶ A), f = g by
apply this
intro g
suffices IsSplitEpi (equalizer.ι f g) by exact eq_of_epi_equalizer
exact IsSplitEpi.mk' ⟨Subobject.ofLEMk _ (equalizer.ι f g ≫ Subobject.arrow _) bot_le, by
ext
simp⟩
/-- An ingredient of the proof of the Special Adjoint Functor Theorem: a cocomplete well-copowered
category with a small separating set has a terminal object.
In fact, it follows from the Special Adjoint Functor Theorem that `C` is already complete, see
`hasLimits_of_hasColimits_of_isSeparating`. -/
theorem hasTerminal_of_isSeparating [WellPowered Cᵒᵖ] [HasColimits C] {𝒢 : Set C} [Small.{v₁} 𝒢]
(h𝒢 : IsSeparating 𝒢) : HasTerminal C := by
haveI : Small.{v₁} 𝒢.op := small_of_injective (Set.opEquiv_self 𝒢).injective
haveI : HasInitial Cᵒᵖ := hasInitial_of_isCoseparating ((isCoseparating_op_iff _).2 h𝒢)
exact hasTerminal_of_hasInitial_op
section WellPowered
namespace Subobject
theorem eq_of_le_of_isDetecting {𝒢 : Set C} (h𝒢 : IsDetecting 𝒢) {X : C} (P Q : Subobject X)
(h₁ : P ≤ Q) (h₂ : ∀ G ∈ 𝒢, ∀ {f : G ⟶ X}, Q.Factors f → P.Factors f) : P = Q := by
suffices IsIso (ofLE _ _ h₁) by exact le_antisymm h₁ (le_of_comm (inv (ofLE _ _ h₁)) (by simp))
refine h𝒢 _ fun G hG f => ?_
have : P.Factors (f ≫ Q.arrow) := h₂ _ hG ((factors_iff _ _).2 ⟨_, rfl⟩)
refine ⟨factorThru _ _ this, ?_, fun g (hg : g ≫ _ = f) => ?_⟩
· simp only [← cancel_mono Q.arrow, Category.assoc, ofLE_arrow, factorThru_arrow]
· simp only [← cancel_mono (Subobject.ofLE _ _ h₁), ← cancel_mono Q.arrow, hg, Category.assoc,
ofLE_arrow, factorThru_arrow]
theorem inf_eq_of_isDetecting [HasPullbacks C] {𝒢 : Set C} (h𝒢 : IsDetecting 𝒢) {X : C}
(P Q : Subobject X) (h : ∀ G ∈ 𝒢, ∀ {f : G ⟶ X}, P.Factors f → Q.Factors f) : P ⊓ Q = P :=
eq_of_le_of_isDetecting h𝒢 _ _ _root_.inf_le_left
fun _ hG _ hf => (inf_factors _).2 ⟨hf, h _ hG hf⟩
theorem eq_of_isDetecting [HasPullbacks C] {𝒢 : Set C} (h𝒢 : IsDetecting 𝒢) {X : C}
(P Q : Subobject X) (h : ∀ G ∈ 𝒢, ∀ {f : G ⟶ X}, P.Factors f ↔ Q.Factors f) : P = Q :=
calc
P = P ⊓ Q := Eq.symm <| inf_eq_of_isDetecting h𝒢 _ _ fun G hG _ hf => (h G hG).1 hf
_ = Q ⊓ P := inf_comm ..
_ = Q := inf_eq_of_isDetecting h𝒢 _ _ fun G hG _ hf => (h G hG).2 hf
end Subobject
/-- A category with pullbacks and a small detecting set is well-powered. -/
theorem wellPowered_of_isDetecting [HasPullbacks C] {𝒢 : Set C} [Small.{v₁} 𝒢]
(h𝒢 : IsDetecting 𝒢) : WellPowered C :=
⟨fun X =>
@small_of_injective _ _ _ (fun P : Subobject X => { f : ΣG : 𝒢, G.1 ⟶ X | P.Factors f.2 })
fun P Q h => Subobject.eq_of_isDetecting h𝒢 _ _ (by simpa [Set.ext_iff] using h)⟩
end WellPowered
namespace StructuredArrow
variable (S : D) (T : C ⥤ D)
theorem isCoseparating_proj_preimage {𝒢 : Set C} (h𝒢 : IsCoseparating 𝒢) :
IsCoseparating ((proj S T).obj ⁻¹' 𝒢) := by
refine fun X Y f g hfg => ext _ _ (h𝒢 _ _ fun G hG h => ?_)
exact congr_arg CommaMorphism.right (hfg (mk (Y.hom ≫ T.map h)) hG (homMk h rfl))
end StructuredArrow
namespace CostructuredArrow
variable (S : C ⥤ D) (T : D)
theorem isSeparating_proj_preimage {𝒢 : Set C} (h𝒢 : IsSeparating 𝒢) :
IsSeparating ((proj S T).obj ⁻¹' 𝒢) := by
refine fun X Y f g hfg => ext _ _ (h𝒢 _ _ fun G hG h => ?_)
exact congr_arg CommaMorphism.left (hfg (mk (S.map h ≫ X.hom)) hG (homMk h rfl))
end CostructuredArrow
/-- We say that `G` is a separator if the functor `C(G, -)` is faithful. -/
def IsSeparator (G : C) : Prop :=
IsSeparating ({G} : Set C)
/-- We say that `G` is a coseparator if the functor `C(-, G)` is faithful. -/
def IsCoseparator (G : C) : Prop :=
IsCoseparating ({G} : Set C)
/-- We say that `G` is a detector if the functor `C(G, -)` reflects isomorphisms. -/
def IsDetector (G : C) : Prop :=
IsDetecting ({G} : Set C)
/-- We say that `G` is a codetector if the functor `C(-, G)` reflects isomorphisms. -/
def IsCodetector (G : C) : Prop :=
IsCodetecting ({G} : Set C)
section Dual
theorem isSeparator_op_iff (G : C) : IsSeparator (op G) ↔ IsCoseparator G := by
rw [IsSeparator, IsCoseparator, ← isSeparating_op_iff, Set.singleton_op]
theorem isCoseparator_op_iff (G : C) : IsCoseparator (op G) ↔ IsSeparator G := by
rw [IsSeparator, IsCoseparator, ← isCoseparating_op_iff, Set.singleton_op]
theorem isCoseparator_unop_iff (G : Cᵒᵖ) : IsCoseparator (unop G) ↔ IsSeparator G := by
rw [IsSeparator, IsCoseparator, ← isCoseparating_unop_iff, Set.singleton_unop]
theorem isSeparator_unop_iff (G : Cᵒᵖ) : IsSeparator (unop G) ↔ IsCoseparator G := by
rw [IsSeparator, IsCoseparator, ← isSeparating_unop_iff, Set.singleton_unop]
theorem isDetector_op_iff (G : C) : IsDetector (op G) ↔ IsCodetector G := by
rw [IsDetector, IsCodetector, ← isDetecting_op_iff, Set.singleton_op]
theorem isCodetector_op_iff (G : C) : IsCodetector (op G) ↔ IsDetector G := by
rw [IsDetector, IsCodetector, ← isCodetecting_op_iff, Set.singleton_op]
theorem isCodetector_unop_iff (G : Cᵒᵖ) : IsCodetector (unop G) ↔ IsDetector G := by
rw [IsDetector, IsCodetector, ← isCodetecting_unop_iff, Set.singleton_unop]
theorem isDetector_unop_iff (G : Cᵒᵖ) : IsDetector (unop G) ↔ IsCodetector G := by
rw [IsDetector, IsCodetector, ← isDetecting_unop_iff, Set.singleton_unop]
end Dual
theorem IsDetector.isSeparator [HasEqualizers C] {G : C} : IsDetector G → IsSeparator G :=
IsDetecting.isSeparating
theorem IsCodetector.isCoseparator [HasCoequalizers C] {G : C} : IsCodetector G → IsCoseparator G :=
IsCodetecting.isCoseparating
theorem IsSeparator.isDetector [Balanced C] {G : C} : IsSeparator G → IsDetector G :=
IsSeparating.isDetecting
theorem IsCospearator.isCodetector [Balanced C] {G : C} : IsCoseparator G → IsCodetector G :=
IsCoseparating.isCodetecting
theorem isSeparator_def (G : C) :
IsSeparator G ↔ ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ h : G ⟶ X, h ≫ f = h ≫ g) → f = g :=
⟨fun hG X Y f g hfg =>
hG _ _ fun H hH h => by
obtain rfl := Set.mem_singleton_iff.1 hH
exact hfg h,
fun hG X Y f g hfg => hG _ _ fun h => hfg _ (Set.mem_singleton _) _⟩
theorem IsSeparator.def {G : C} :
IsSeparator G → ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ h : G ⟶ X, h ≫ f = h ≫ g) → f = g :=
(isSeparator_def _).1
theorem isCoseparator_def (G : C) :
IsCoseparator G ↔ ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ h : Y ⟶ G, f ≫ h = g ≫ h) → f = g :=
⟨fun hG X Y f g hfg =>
hG _ _ fun H hH h => by
obtain rfl := Set.mem_singleton_iff.1 hH
exact hfg h,
fun hG X Y f g hfg => hG _ _ fun h => hfg _ (Set.mem_singleton _) _⟩
theorem IsCoseparator.def {G : C} :
IsCoseparator G → ∀ ⦃X Y : C⦄ (f g : X ⟶ Y), (∀ h : Y ⟶ G, f ≫ h = g ≫ h) → f = g :=
(isCoseparator_def _).1
theorem isDetector_def (G : C) :
IsDetector G ↔ ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : G ⟶ Y, ∃! h', h' ≫ f = h) → IsIso f :=
⟨fun hG X Y f hf =>
hG _ fun H hH h => by
obtain rfl := Set.mem_singleton_iff.1 hH
exact hf h,
fun hG X Y f hf => hG _ fun h => hf _ (Set.mem_singleton _) _⟩
theorem IsDetector.def {G : C} :
IsDetector G → ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : G ⟶ Y, ∃! h', h' ≫ f = h) → IsIso f :=
(isDetector_def _).1
theorem isCodetector_def (G : C) :
IsCodetector G ↔ ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : X ⟶ G, ∃! h', f ≫ h' = h) → IsIso f :=
⟨fun hG X Y f hf =>
hG _ fun H hH h => by
obtain rfl := Set.mem_singleton_iff.1 hH
exact hf h,
fun hG X Y f hf => hG _ fun h => hf _ (Set.mem_singleton _) _⟩
theorem IsCodetector.def {G : C} :
IsCodetector G → ∀ ⦃X Y : C⦄ (f : X ⟶ Y), (∀ h : X ⟶ G, ∃! h', f ≫ h' = h) → IsIso f :=
(isCodetector_def _).1
theorem isSeparator_iff_faithful_coyoneda_obj (G : C) :
IsSeparator G ↔ (coyoneda.obj (op G)).Faithful :=
⟨fun hG => ⟨fun hfg => hG.def _ _ (congr_fun hfg)⟩, fun _ =>
(isSeparator_def _).2 fun _ _ _ _ hfg => (coyoneda.obj (op G)).map_injective (funext hfg)⟩
theorem isCoseparator_iff_faithful_yoneda_obj (G : C) : IsCoseparator G ↔ (yoneda.obj G).Faithful :=
⟨fun hG => ⟨fun hfg => Quiver.Hom.unop_inj (hG.def _ _ (congr_fun hfg))⟩, fun _ =>
(isCoseparator_def _).2 fun _ _ _ _ hfg =>
Quiver.Hom.op_inj <| (yoneda.obj G).map_injective (funext hfg)⟩
theorem isSeparator_iff_epi (G : C) [∀ A : C, HasCoproduct fun _ : G ⟶ A => G] :
IsSeparator G ↔ ∀ A : C, Epi (Sigma.desc fun f : G ⟶ A => f) := by
rw [isSeparator_def]
refine ⟨fun h A => ⟨fun u v huv => h _ _ fun i => ?_⟩, fun h X Y f g hh => ?_⟩
· simpa using Sigma.ι _ i ≫= huv
· haveI := h X
refine (cancel_epi (Sigma.desc fun f : G ⟶ X => f)).1 (colimit.hom_ext fun j => ?_)
simpa using hh j.as
theorem isCoseparator_iff_mono (G : C) [∀ A : C, HasProduct fun _ : A ⟶ G => G] :
IsCoseparator G ↔ ∀ A : C, Mono (Pi.lift fun f : A ⟶ G => f) := by
rw [isCoseparator_def]
refine ⟨fun h A => ⟨fun u v huv => h _ _ fun i => ?_⟩, fun h X Y f g hh => ?_⟩
· simpa using huv =≫ Pi.π _ i
· haveI := h Y
refine (cancel_mono (Pi.lift fun f : Y ⟶ G => f)).1 (limit.hom_ext fun j => ?_)
simpa using hh j.as
section ZeroMorphisms
variable [HasZeroMorphisms C]
theorem isSeparator_coprod (G H : C) [HasBinaryCoproduct G H] :
IsSeparator (G ⨿ H) ↔ IsSeparating ({G, H} : Set C) := by
refine
⟨fun h X Y u v huv => ?_, fun h =>
(isSeparator_def _).2 fun X Y u v huv => h _ _ fun Z hZ g => ?_⟩
· refine h.def _ _ fun g => coprod.hom_ext ?_ ?_
· simpa using huv G (by simp) (coprod.inl ≫ g)
· simpa using huv H (by simp) (coprod.inr ≫ g)
· simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at hZ
rcases hZ with (rfl | rfl)
· simpa using coprod.inl ≫= huv (coprod.desc g 0)
· simpa using coprod.inr ≫= huv (coprod.desc 0 g)
theorem isSeparator_coprod_of_isSeparator_left (G H : C) [HasBinaryCoproduct G H]
(hG : IsSeparator G) : IsSeparator (G ⨿ H) :=
(isSeparator_coprod _ _).2 <| IsSeparating.mono hG <| by simp
theorem isSeparator_coprod_of_isSeparator_right (G H : C) [HasBinaryCoproduct G H]
(hH : IsSeparator H) : IsSeparator (G ⨿ H) :=
(isSeparator_coprod _ _).2 <| IsSeparating.mono hH <| by simp
theorem isSeparator_sigma {β : Type w} (f : β → C) [HasCoproduct f] :
IsSeparator (∐ f) ↔ IsSeparating (Set.range f) := by
refine
⟨fun h X Y u v huv => ?_, fun h =>
(isSeparator_def _).2 fun X Y u v huv => h _ _ fun Z hZ g => ?_⟩
· refine h.def _ _ fun g => colimit.hom_ext fun b => ?_
simpa using huv (f b.as) (by simp) (colimit.ι (Discrete.functor f) _ ≫ g)
· obtain ⟨b, rfl⟩ := Set.mem_range.1 hZ
classical simpa using Sigma.ι f b ≫= huv (Sigma.desc (Pi.single b g))
theorem isSeparator_sigma_of_isSeparator {β : Type w} (f : β → C) [HasCoproduct f] (b : β)
(hb : IsSeparator (f b)) : IsSeparator (∐ f) :=
(isSeparator_sigma _).2 <| IsSeparating.mono hb <| by simp
theorem isCoseparator_prod (G H : C) [HasBinaryProduct G H] :
IsCoseparator (G ⨯ H) ↔ IsCoseparating ({G, H} : Set C) := by
refine
⟨fun h X Y u v huv => ?_, fun h =>
(isCoseparator_def _).2 fun X Y u v huv => h _ _ fun Z hZ g => ?_⟩
· refine h.def _ _ fun g => prod.hom_ext ?_ ?_
· simpa using huv G (by simp) (g ≫ Limits.prod.fst)
· simpa using huv H (by simp) (g ≫ Limits.prod.snd)
· simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at hZ
rcases hZ with (rfl | rfl)
· simpa using huv (prod.lift g 0) =≫ Limits.prod.fst
· simpa using huv (prod.lift 0 g) =≫ Limits.prod.snd
theorem isCoseparator_prod_of_isCoseparator_left (G H : C) [HasBinaryProduct G H]
(hG : IsCoseparator G) : IsCoseparator (G ⨯ H) :=
(isCoseparator_prod _ _).2 <| IsCoseparating.mono hG <| by simp
theorem isCoseparator_prod_of_isCoseparator_right (G H : C) [HasBinaryProduct G H]
(hH : IsCoseparator H) : IsCoseparator (G ⨯ H) :=
(isCoseparator_prod _ _).2 <| IsCoseparating.mono hH <| by simp
theorem isCoseparator_pi {β : Type w} (f : β → C) [HasProduct f] :
IsCoseparator (∏ᶜ f) ↔ IsCoseparating (Set.range f) := by
refine
⟨fun h X Y u v huv => ?_, fun h =>
(isCoseparator_def _).2 fun X Y u v huv => h _ _ fun Z hZ g => ?_⟩
· refine h.def _ _ fun g => limit.hom_ext fun b => ?_
simpa using huv (f b.as) (by simp) (g ≫ limit.π (Discrete.functor f) _)
· obtain ⟨b, rfl⟩ := Set.mem_range.1 hZ
classical simpa using huv (Pi.lift (Pi.single b g)) =≫ Pi.π f b
theorem isCoseparator_pi_of_isCoseparator {β : Type w} (f : β → C) [HasProduct f] (b : β)
(hb : IsCoseparator (f b)) : IsCoseparator (∏ᶜ f) :=
(isCoseparator_pi _).2 <| IsCoseparating.mono hb <| by simp
end ZeroMorphisms
theorem isDetector_iff_reflectsIsomorphisms_coyoneda_obj (G : C) :
IsDetector G ↔ (coyoneda.obj (op G)).ReflectsIsomorphisms := by
refine
⟨fun hG => ⟨fun f hf => hG.def _ fun h => ?_⟩, fun h =>
(isDetector_def _).2 fun X Y f hf => ?_⟩
· rw [isIso_iff_bijective, Function.bijective_iff_existsUnique] at hf
exact hf h
· suffices IsIso ((coyoneda.obj (op G)).map f) by
exact @isIso_of_reflects_iso _ _ _ _ _ _ _ (coyoneda.obj (op G)) _ h
rwa [isIso_iff_bijective, Function.bijective_iff_existsUnique]
theorem isCodetector_iff_reflectsIsomorphisms_yoneda_obj (G : C) :
IsCodetector G ↔ (yoneda.obj G).ReflectsIsomorphisms := by
refine ⟨fun hG => ⟨fun f hf => ?_⟩, fun h => (isCodetector_def _).2 fun X Y f hf => ?_⟩
· refine (isIso_unop_iff _).1 (hG.def _ ?_)
rwa [isIso_iff_bijective, Function.bijective_iff_existsUnique] at hf
· rw [← isIso_op_iff]
suffices IsIso ((yoneda.obj G).map f.op) by
exact @isIso_of_reflects_iso _ _ _ _ _ _ _ (yoneda.obj G) _ h
rwa [isIso_iff_bijective, Function.bijective_iff_existsUnique]
theorem wellPowered_of_isDetector [HasPullbacks C] (G : C) (hG : IsDetector G) : WellPowered C :=
-- Porting note: added the following `haveI` to prevent universe issues
haveI := small_subsingleton ({G} : Set C)
wellPowered_of_isDetecting hG
end CategoryTheory
|
CategoryTheory\GlueData.lean | /-
Copyright (c) 2021 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.Tactic.CategoryTheory.Elementwise
import Mathlib.CategoryTheory.Limits.Shapes.Multiequalizer
import Mathlib.CategoryTheory.Limits.Constructions.EpiMono
import Mathlib.CategoryTheory.Limits.Preserves.Limits
import Mathlib.CategoryTheory.Limits.Shapes.Types
/-!
# Gluing data
We define `GlueData` as a family of data needed to glue topological spaces, schemes, etc. We
provide the API to realize it as a multispan diagram, and also state lemmas about its
interaction with a functor that preserves certain pullbacks.
-/
noncomputable section
open CategoryTheory.Limits
namespace CategoryTheory
universe v u₁ u₂
variable (C : Type u₁) [Category.{v} C] {C' : Type u₂} [Category.{v} C']
/-- A gluing datum consists of
1. An index type `J`
2. An object `U i` for each `i : J`.
3. An object `V i j` for each `i j : J`.
4. A monomorphism `f i j : V i j ⟶ U i` for each `i j : J`.
5. A transition map `t i j : V i j ⟶ V j i` for each `i j : J`.
such that
6. `f i i` is an isomorphism.
7. `t i i` is the identity.
8. The pullback for `f i j` and `f i k` exists.
9. `V i j ×[U i] V i k ⟶ V i j ⟶ V j i` factors through `V j k ×[U j] V j i ⟶ V j i` via some
`t' : V i j ×[U i] V i k ⟶ V j k ×[U j] V j i`.
10. `t' i j k ≫ t' j k i ≫ t' k i j = 𝟙 _`.
-/
-- Porting note(#5171): linter not ported yet
-- @[nolint has_nonempty_instance]
structure GlueData where
J : Type v
U : J → C
V : J × J → C
f : ∀ i j, V (i, j) ⟶ U i
f_mono : ∀ i j, Mono (f i j) := by infer_instance
f_hasPullback : ∀ i j k, HasPullback (f i j) (f i k) := by infer_instance
f_id : ∀ i, IsIso (f i i) := by infer_instance
t : ∀ i j, V (i, j) ⟶ V (j, i)
t_id : ∀ i, t i i = 𝟙 _
t' : ∀ i j k, pullback (f i j) (f i k) ⟶ pullback (f j k) (f j i)
t_fac : ∀ i j k, t' i j k ≫ pullback.snd _ _ = pullback.fst _ _ ≫ t i j
cocycle : ∀ i j k, t' i j k ≫ t' j k i ≫ t' k i j = 𝟙 _
attribute [simp] GlueData.t_id
attribute [instance] GlueData.f_id GlueData.f_mono GlueData.f_hasPullback
attribute [reassoc] GlueData.t_fac GlueData.cocycle
namespace GlueData
variable {C}
variable (D : GlueData C)
@[simp]
theorem t'_iij (i j : D.J) : D.t' i i j = (pullbackSymmetry _ _).hom := by
have eq₁ := D.t_fac i i j
have eq₂ := (IsIso.eq_comp_inv (D.f i i)).mpr (@pullback.condition _ _ _ _ _ _ (D.f i j) _)
rw [D.t_id, Category.comp_id, eq₂] at eq₁
have eq₃ := (IsIso.eq_comp_inv (D.f i i)).mp eq₁
rw [Category.assoc, ← pullback.condition, ← Category.assoc] at eq₃
exact
Mono.right_cancellation _ _
((Mono.right_cancellation _ _ eq₃).trans (pullbackSymmetry_hom_comp_fst _ _).symm)
theorem t'_jii (i j : D.J) : D.t' j i i = pullback.fst _ _ ≫ D.t j i ≫ inv (pullback.snd _ _) := by
rw [← Category.assoc, ← D.t_fac]
simp
theorem t'_iji (i j : D.J) : D.t' i j i = pullback.fst _ _ ≫ D.t i j ≫ inv (pullback.snd _ _) := by
rw [← Category.assoc, ← D.t_fac]
simp
@[reassoc, elementwise (attr := simp)]
theorem t_inv (i j : D.J) : D.t i j ≫ D.t j i = 𝟙 _ := by
have eq : (pullbackSymmetry (D.f i i) (D.f i j)).hom =
pullback.snd _ _ ≫ inv (pullback.fst _ _) := by simp
have := D.cocycle i j i
rw [D.t'_iij, D.t'_jii, D.t'_iji, fst_eq_snd_of_mono_eq, eq] at this
simp only [Category.assoc, IsIso.inv_hom_id_assoc] at this
rw [← IsIso.eq_inv_comp, ← Category.assoc, IsIso.comp_inv_eq] at this
simpa using this
theorem t'_inv (i j k : D.J) :
D.t' i j k ≫ (pullbackSymmetry _ _).hom ≫ D.t' j i k ≫ (pullbackSymmetry _ _).hom = 𝟙 _ := by
rw [← cancel_mono (pullback.fst (D.f i j) (D.f i k))]
simp [t_fac, t_fac_assoc]
instance t_isIso (i j : D.J) : IsIso (D.t i j) :=
⟨⟨D.t j i, D.t_inv _ _, D.t_inv _ _⟩⟩
instance t'_isIso (i j k : D.J) : IsIso (D.t' i j k) :=
⟨⟨D.t' j k i ≫ D.t' k i j, D.cocycle _ _ _, by simpa using D.cocycle _ _ _⟩⟩
@[reassoc]
theorem t'_comp_eq_pullbackSymmetry (i j k : D.J) :
D.t' j k i ≫ D.t' k i j =
(pullbackSymmetry _ _).hom ≫ D.t' j i k ≫ (pullbackSymmetry _ _).hom := by
trans inv (D.t' i j k)
· exact IsIso.eq_inv_of_hom_inv_id (D.cocycle _ _ _)
· rw [← cancel_mono (pullback.fst (D.f i j) (D.f i k))]
simp [t_fac, t_fac_assoc]
/-- (Implementation) The disjoint union of `U i`. -/
def sigmaOpens [HasCoproduct D.U] : C :=
∐ D.U
/-- (Implementation) The diagram to take colimit of. -/
def diagram : MultispanIndex C where
L := D.J × D.J
R := D.J
fstFrom := _root_.Prod.fst
sndFrom := _root_.Prod.snd
left := D.V
right := D.U
fst := fun ⟨i, j⟩ => D.f i j
snd := fun ⟨i, j⟩ => D.t i j ≫ D.f j i
@[simp]
theorem diagram_l : D.diagram.L = (D.J × D.J) :=
rfl
@[simp]
theorem diagram_r : D.diagram.R = D.J :=
rfl
@[simp]
theorem diagram_fstFrom (i j : D.J) : D.diagram.fstFrom ⟨i, j⟩ = i :=
rfl
@[simp]
theorem diagram_sndFrom (i j : D.J) : D.diagram.sndFrom ⟨i, j⟩ = j :=
rfl
@[simp]
theorem diagram_fst (i j : D.J) : D.diagram.fst ⟨i, j⟩ = D.f i j :=
rfl
@[simp]
theorem diagram_snd (i j : D.J) : D.diagram.snd ⟨i, j⟩ = D.t i j ≫ D.f j i :=
rfl
@[simp]
theorem diagram_left : D.diagram.left = D.V :=
rfl
@[simp]
theorem diagram_right : D.diagram.right = D.U :=
rfl
section
variable [HasMulticoequalizer D.diagram]
/-- The glued object given a family of gluing data. -/
def glued : C :=
multicoequalizer D.diagram
/-- The map `D.U i ⟶ D.glued` for each `i`. -/
def ι (i : D.J) : D.U i ⟶ D.glued :=
Multicoequalizer.π D.diagram i
@[elementwise (attr := simp)]
theorem glue_condition (i j : D.J) : D.t i j ≫ D.f j i ≫ D.ι j = D.f i j ≫ D.ι i :=
(Category.assoc _ _ _).symm.trans (Multicoequalizer.condition D.diagram ⟨i, j⟩).symm
/-- The pullback cone spanned by `V i j ⟶ U i` and `V i j ⟶ U j`.
This will often be a pullback diagram. -/
def vPullbackCone (i j : D.J) : PullbackCone (D.ι i) (D.ι j) :=
PullbackCone.mk (D.f i j) (D.t i j ≫ D.f j i) (by simp)
variable [HasColimits C]
/-- The projection `∐ D.U ⟶ D.glued` given by the colimit. -/
def π : D.sigmaOpens ⟶ D.glued :=
Multicoequalizer.sigmaπ D.diagram
instance π_epi : Epi D.π := by
unfold π
infer_instance
end
theorem types_π_surjective (D : GlueData Type*) : Function.Surjective D.π :=
(epi_iff_surjective _).mp inferInstance
theorem types_ι_jointly_surjective (D : GlueData (Type v)) (x : D.glued) :
∃ (i : _) (y : D.U i), D.ι i y = x := by
delta CategoryTheory.GlueData.ι
simp_rw [← Multicoequalizer.ι_sigmaπ D.diagram]
rcases D.types_π_surjective x with ⟨x', rfl⟩
--have := colimit.isoColimitCocone (Types.coproductColimitCocone _)
rw [← show (colimit.isoColimitCocone (Types.coproductColimitCocone.{v, v} _)).inv _ = x' from
ConcreteCategory.congr_hom
(colimit.isoColimitCocone (Types.coproductColimitCocone _)).hom_inv_id x']
rcases (colimit.isoColimitCocone (Types.coproductColimitCocone _)).hom x' with ⟨i, y⟩
exact ⟨i, y, by
simp [← Multicoequalizer.ι_sigmaπ]
rfl ⟩
variable (F : C ⥤ C')
section
variable [∀ i j k, PreservesLimit (cospan (D.f i j) (D.f i k)) F]
instance (i j k : D.J) : HasPullback (F.map (D.f i j)) (F.map (D.f i k)) :=
⟨⟨⟨_, isLimitOfHasPullbackOfPreservesLimit F (D.f i j) (D.f i k)⟩⟩⟩
/-- A functor that preserves the pullbacks of `f i j` and `f i k` can map a family of glue data. -/
@[simps]
def mapGlueData : GlueData C' where
J := D.J
U i := F.obj (D.U i)
V i := F.obj (D.V i)
f i j := F.map (D.f i j)
f_mono i j := preserves_mono_of_preservesLimit _ _
f_id i := inferInstance
t i j := F.map (D.t i j)
t_id i := by
simp [D.t_id i]
t' i j k :=
(PreservesPullback.iso F (D.f i j) (D.f i k)).inv ≫
F.map (D.t' i j k) ≫ (PreservesPullback.iso F (D.f j k) (D.f j i)).hom
t_fac i j k := by simpa [Iso.inv_comp_eq] using congr_arg (fun f => F.map f) (D.t_fac i j k)
cocycle i j k := by
simp only [Category.assoc, Iso.hom_inv_id_assoc, ← Functor.map_comp_assoc, D.cocycle,
Iso.inv_hom_id, CategoryTheory.Functor.map_id, Category.id_comp]
/-- The diagram of the image of a `GlueData` under a functor `F` is naturally isomorphic to the
original diagram of the `GlueData` via `F`.
-/
def diagramIso : D.diagram.multispan ⋙ F ≅ (D.mapGlueData F).diagram.multispan :=
NatIso.ofComponents
(fun x =>
match x with
| WalkingMultispan.left a => Iso.refl _
| WalkingMultispan.right b => Iso.refl _)
(by
rintro (⟨_, _⟩ | _) _ (_ | _ | _)
· erw [Category.comp_id, Category.id_comp, Functor.map_id]
rfl
· erw [Category.comp_id, Category.id_comp]
rfl
· erw [Category.comp_id, Category.id_comp, Functor.map_comp]
rfl
· erw [Category.comp_id, Category.id_comp, Functor.map_id]
rfl)
@[simp]
theorem diagramIso_app_left (i : D.J × D.J) :
(D.diagramIso F).app (WalkingMultispan.left i) = Iso.refl _ :=
rfl
@[simp]
theorem diagramIso_app_right (i : D.J) :
(D.diagramIso F).app (WalkingMultispan.right i) = Iso.refl _ :=
rfl
@[simp]
theorem diagramIso_hom_app_left (i : D.J × D.J) :
(D.diagramIso F).hom.app (WalkingMultispan.left i) = 𝟙 _ :=
rfl
@[simp]
theorem diagramIso_hom_app_right (i : D.J) :
(D.diagramIso F).hom.app (WalkingMultispan.right i) = 𝟙 _ :=
rfl
@[simp]
theorem diagramIso_inv_app_left (i : D.J × D.J) :
(D.diagramIso F).inv.app (WalkingMultispan.left i) = 𝟙 _ :=
rfl
@[simp]
theorem diagramIso_inv_app_right (i : D.J) :
(D.diagramIso F).inv.app (WalkingMultispan.right i) = 𝟙 _ :=
rfl
end
variable [HasMulticoequalizer D.diagram] [PreservesColimit D.diagram.multispan F]
theorem hasColimit_multispan_comp : HasColimit (D.diagram.multispan ⋙ F) :=
⟨⟨⟨_, PreservesColimit.preserves (colimit.isColimit _)⟩⟩⟩
attribute [local instance] hasColimit_multispan_comp
variable [∀ i j k, PreservesLimit (cospan (D.f i j) (D.f i k)) F]
theorem hasColimit_mapGlueData_diagram : HasMulticoequalizer (D.mapGlueData F).diagram :=
hasColimitOfIso (D.diagramIso F).symm
attribute [local instance] hasColimit_mapGlueData_diagram
/-- If `F` preserves the gluing, we obtain an iso between the glued objects. -/
def gluedIso : F.obj D.glued ≅ (D.mapGlueData F).glued :=
haveI : HasColimit (MultispanIndex.multispan (diagram (mapGlueData D F))) := inferInstance
preservesColimitIso F D.diagram.multispan ≪≫ Limits.HasColimit.isoOfNatIso (D.diagramIso F)
@[reassoc (attr := simp)]
theorem ι_gluedIso_hom (i : D.J) : F.map (D.ι i) ≫ (D.gluedIso F).hom = (D.mapGlueData F).ι i := by
haveI : HasColimit (MultispanIndex.multispan (diagram (mapGlueData D F))) := inferInstance
erw [ι_preservesColimitsIso_hom_assoc]
rw [HasColimit.isoOfNatIso_ι_hom]
erw [Category.id_comp]
rfl
@[reassoc (attr := simp)]
theorem ι_gluedIso_inv (i : D.J) : (D.mapGlueData F).ι i ≫ (D.gluedIso F).inv = F.map (D.ι i) := by
rw [Iso.comp_inv_eq, ι_gluedIso_hom]
/-- If `F` preserves the gluing, and reflects the pullback of `U i ⟶ glued` and `U j ⟶ glued`,
then `F` reflects the fact that `V_pullback_cone` is a pullback. -/
def vPullbackConeIsLimitOfMap (i j : D.J) [ReflectsLimit (cospan (D.ι i) (D.ι j)) F]
(hc : IsLimit ((D.mapGlueData F).vPullbackCone i j)) : IsLimit (D.vPullbackCone i j) := by
apply isLimitOfReflects F
apply (isLimitMapConePullbackConeEquiv _ _).symm _
let e : cospan (F.map (D.ι i)) (F.map (D.ι j)) ≅
cospan ((D.mapGlueData F).ι i) ((D.mapGlueData F).ι j) :=
NatIso.ofComponents
(fun x => by
cases x
exacts [D.gluedIso F, Iso.refl _])
(by rintro (_ | _) (_ | _) (_ | _ | _) <;> simp)
apply IsLimit.postcomposeHomEquiv e _ _
apply hc.ofIsoLimit
refine Cones.ext (Iso.refl _) ?_
rintro (_ | _ | _)
all_goals simp [e]; rfl
/-- If there is a forgetful functor into `Type` that preserves enough (co)limits, then `D.ι` will
be jointly surjective. -/
theorem ι_jointly_surjective (F : C ⥤ Type v) [PreservesColimit D.diagram.multispan F]
[∀ i j k : D.J, PreservesLimit (cospan (D.f i j) (D.f i k)) F] (x : F.obj D.glued) :
∃ (i : _) (y : F.obj (D.U i)), F.map (D.ι i) y = x := by
let e := D.gluedIso F
obtain ⟨i, y, eq⟩ := (D.mapGlueData F).types_ι_jointly_surjective (e.hom x)
replace eq := congr_arg e.inv eq
change ((D.mapGlueData F).ι i ≫ e.inv) y = (e.hom ≫ e.inv) x at eq
rw [e.hom_inv_id, D.ι_gluedIso_inv] at eq
exact ⟨i, y, eq⟩
end GlueData
section GlueData'
/--
This is a variant of `GlueData` that only requires conditions on `V (i, j)` when `i ≠ j`.
See `GlueData.ofGlueData'`
-/
structure GlueData' where
/-- Indexing type of a glue data. -/
J : Type v
/-- Objects of a glue data to be glued. -/
U : J → C
/-- Objects representing the intersections. -/
V : ∀ (i j : J), i ≠ j → C
/-- The inclusion maps of the intersection into the object. -/
f : ∀ i j h, V i j h ⟶ U i
f_mono : ∀ i j h, Mono (f i j h) := by infer_instance
f_hasPullback : ∀ i j k hij hik, HasPullback (f i j hij) (f i k hik) := by infer_instance
/-- The transition maps between the intersections. -/
t : ∀ i j h, V i j h ⟶ V j i h.symm
/-- The transition maps between the intersection of intersections. -/
t' : ∀ i j k hij hik hjk,
pullback (f i j hij) (f i k hik) ⟶ pullback (f j k hjk) (f j i hij.symm)
t_fac : ∀ i j k hij hik hjk, t' i j k hij hik hjk ≫ pullback.snd _ _ =
pullback.fst _ _ ≫ t i j hij
t_inv : ∀ i j hij, t i j hij ≫ t j i hij.symm = 𝟙 _
cocycle : ∀ i j k hij hik hjk, t' i j k hij hik hjk ≫
t' j k i hjk hij.symm hik.symm ≫ t' k i j hik.symm hjk.symm hij = 𝟙 _
attribute [local instance] GlueData'.f_mono GlueData'.f_hasPullback mono_comp
attribute [reassoc (attr := simp)] GlueData'.t_inv GlueData'.cocycle
variable {C}
open scoped Classical
/-- (Implementation detail) the constructed `GlueData.f` from a `GlueData'`. -/
abbrev GlueData'.f' (D : GlueData' C) (i j : D.J) :
(if h : i = j then D.U i else D.V i j h) ⟶ D.U i :=
if h : i = j then eqToHom (dif_pos h) else eqToHom (dif_neg h) ≫ D.f i j h
instance (D : GlueData' C) (i j : D.J) :
Mono (D.f' i j) := by dsimp [GlueData'.f']; split_ifs <;> infer_instance
instance (D : GlueData' C) (i : D.J) :
IsIso (D.f' i i) := by simp only [GlueData'.f', ↓reduceDIte]; infer_instance
instance (D : GlueData' C) (i j k : D.J) :
HasPullback (D.f' i j) (D.f' i k) := by
if hij : i = j then
apply (config := { allowSynthFailures := true}) hasPullback_of_left_iso
simp only [GlueData'.f', dif_pos hij]
infer_instance
else if hik : i = k then
apply (config := { allowSynthFailures := true}) hasPullback_of_right_iso
simp only [GlueData'.f', dif_pos hik]
infer_instance
else
have {X Y Z : C} (f : X ⟶ Y) (e : Z = X) : HEq (eqToHom e ≫ f) f := by subst e; simp
convert D.f_hasPullback i j k hij hik <;> simp [GlueData'.f', hij, hik, this]
/-- (Implementation detail) the constructed `GlueData.t'` from a `GlueData'`. -/
def GlueData'.t'' (D : GlueData' C) (i j k : D.J) :
pullback (D.f' i j) (D.f' i k) ⟶ pullback (D.f' j k) (D.f' j i) :=
if hij : i = j then
(pullbackSymmetry _ _).hom ≫
pullback.map _ _ _ _ (eqToHom (by aesop)) (eqToHom (by aesop)) (eqToHom (by aesop))
(by aesop) (by aesop)
else if hik : i = k then
have : IsIso (pullback.snd (D.f' j k) (D.f' j i)) := by
subst hik; infer_instance
pullback.fst _ _ ≫ eqToHom (dif_neg hij) ≫ D.t _ _ _ ≫
eqToHom (dif_neg (Ne.symm hij)).symm ≫ inv (pullback.snd _ _)
else if hjk : j = k then
have : IsIso (pullback.snd (D.f' j k) (D.f' j i)) := by
apply (config := { allowSynthFailures := true}) pullback_snd_iso_of_left_iso
simp only [hjk, GlueData'.f', ↓reduceDIte]
infer_instance
pullback.fst _ _ ≫ eqToHom (dif_neg hij) ≫ D.t _ _ _ ≫
eqToHom (dif_neg (Ne.symm hij)).symm ≫ inv (pullback.snd _ _)
else
haveI := Ne.symm hij
pullback.map _ _ _ _ (eqToHom (by aesop)) (eqToHom (by rw [dif_neg hik]))
(eqToHom (by aesop)) (by aesop) (by delta f'; aesop) ≫
D.t' i j k hij hik hjk ≫
pullback.map _ _ _ _ (eqToHom (by aesop)) (eqToHom (by aesop)) (eqToHom (by aesop))
(by delta f'; aesop) (by delta f'; aesop)
/--
The constructed `GlueData` of a `GlueData'`, where `GlueData'` is a variant of `GlueData` that only
requires conditions on `V (i, j)` when `i ≠ j`.
-/
def GlueData.ofGlueData' (D : GlueData' C) : GlueData C where
J := D.J
U := D.U
V ij := if h : ij.1 = ij.2 then D.U ij.1 else D.V ij.1 ij.2 h
f i j := D.f' i j
f_id i := by simp only [↓reduceDIte, GlueData'.f']; infer_instance
t i j := if h : i = j then eqToHom (by simp [h]) else
eqToHom (dif_neg h) ≫ D.t i j h ≫ eqToHom (dif_neg (Ne.symm h)).symm
t_id i := by simp
t' := D.t''
t_fac i j k := by
delta GlueData'.t''
split_ifs
· simp [*]
· cases ‹i ≠ j› (‹i = k›.trans ‹j = k›.symm)
· simp [‹j ≠ k›.symm, *]
· simp [*]
· simp [*, reassoc_of% D.t_fac]
cocycle i j k := by
delta GlueData'.t''
if hij : i = j then
subst hij
if hik : i = k then
subst hik
ext <;> simp
else
simp [hik, Ne.symm hik, fst_eq_snd_of_mono_eq]
else if hik : i = k then
subst hik
ext <;> simp [hij, Ne.symm hij, fst_eq_snd_of_mono_eq, pullback.condition_assoc]
else if hjk : j = k then
subst hjk
ext <;> simp [hij, Ne.symm hij, fst_eq_snd_of_mono_eq, pullback.condition_assoc]
else
ext <;> simp [hij, Ne.symm hij, hik, Ne.symm hik, hjk, Ne.symm hjk,
pullback.map_comp_assoc]
end GlueData'
end CategoryTheory
|
CategoryTheory\GradedObject.lean | /-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Joël Riou
-/
import Mathlib.Algebra.Group.Int
import Mathlib.CategoryTheory.ConcreteCategory.Basic
import Mathlib.CategoryTheory.Shift.Basic
import Mathlib.Data.Set.Subsingleton
/-!
# The category of graded objects
For any type `β`, a `β`-graded object over some category `C` is just
a function `β → C` into the objects of `C`.
We put the "pointwise" category structure on these, as the non-dependent specialization of
`CategoryTheory.Pi`.
We describe the `comap` functors obtained by precomposing with functions `β → γ`.
As a consequence a fixed element (e.g. `1`) in an additive group `β` provides a shift
functor on `β`-graded objects
When `C` has coproducts we construct the `total` functor `GradedObject β C ⥤ C`,
show that it is faithful, and deduce that when `C` is concrete so is `GradedObject β C`.
A covariant functoriality of `GradedObject β C` with respect to the index set `β` is also
introduced: if `p : I → J` is a map such that `C` has coproducts indexed by `p ⁻¹' {j}`, we
have a functor `map : GradedObject I C ⥤ GradedObject J C`.
-/
namespace CategoryTheory
open Category Limits
universe w v u
/-- A type synonym for `β → C`, used for `β`-graded objects in a category `C`. -/
def GradedObject (β : Type w) (C : Type u) : Type max w u :=
β → C
-- Satisfying the inhabited linter...
instance inhabitedGradedObject (β : Type w) (C : Type u) [Inhabited C] :
Inhabited (GradedObject β C) :=
⟨fun _ => Inhabited.default⟩
-- `s` is here to distinguish type synonyms asking for different shifts
/-- A type synonym for `β → C`, used for `β`-graded objects in a category `C`
with a shift functor given by translation by `s`.
-/
@[nolint unusedArguments]
abbrev GradedObjectWithShift {β : Type w} [AddCommGroup β] (_ : β) (C : Type u) : Type max w u :=
GradedObject β C
namespace GradedObject
variable {C : Type u} [Category.{v} C]
@[simps!]
instance categoryOfGradedObjects (β : Type w) : Category.{max w v} (GradedObject β C) :=
CategoryTheory.pi fun _ => C
-- Porting note (#10688): added to ease automation
@[ext]
lemma hom_ext {β : Type*} {X Y : GradedObject β C} (f g : X ⟶ Y) (h : ∀ x, f x = g x) : f = g := by
funext
apply h
/-- The projection of a graded object to its `i`-th component. -/
@[simps]
def eval {β : Type w} (b : β) : GradedObject β C ⥤ C where
obj X := X b
map f := f b
section
variable {β : Type*} (X Y : GradedObject β C)
/-- Constructor for isomorphisms in `GradedObject` -/
@[simps]
def isoMk (e : ∀ i, X i ≅ Y i) : X ≅ Y where
hom i := (e i).hom
inv i := (e i).inv
variable {X Y}
-- this lemma is not an instance as it may create a loop with `isIso_apply_of_isIso`
lemma isIso_of_isIso_apply (f : X ⟶ Y) [hf : ∀ i, IsIso (f i)] :
IsIso f := by
change IsIso (isoMk X Y (fun i => asIso (f i))).hom
infer_instance
instance isIso_apply_of_isIso (f : X ⟶ Y) [IsIso f] (i : β) : IsIso (f i) := by
change IsIso ((eval i).map f)
infer_instance
end
end GradedObject
namespace Iso
variable {C D E J : Type*} [Category C] [Category D] [Category E]
{X Y : GradedObject J C}
@[reassoc (attr := simp)]
lemma hom_inv_id_eval (e : X ≅ Y) (j : J) :
e.hom j ≫ e.inv j = 𝟙 _ := by
rw [← GradedObject.categoryOfGradedObjects_comp, e.hom_inv_id,
GradedObject.categoryOfGradedObjects_id]
@[reassoc (attr := simp)]
lemma inv_hom_id_eval (e : X ≅ Y) (j : J) :
e.inv j ≫ e.hom j = 𝟙 _ := by
rw [← GradedObject.categoryOfGradedObjects_comp, e.inv_hom_id,
GradedObject.categoryOfGradedObjects_id]
@[reassoc (attr := simp)]
lemma map_hom_inv_id_eval (e : X ≅ Y) (F : C ⥤ D) (j : J) :
F.map (e.hom j) ≫ F.map (e.inv j) = 𝟙 _ := by
rw [← F.map_comp, ← GradedObject.categoryOfGradedObjects_comp, e.hom_inv_id,
GradedObject.categoryOfGradedObjects_id, Functor.map_id]
@[reassoc (attr := simp)]
lemma map_inv_hom_id_eval (e : X ≅ Y) (F : C ⥤ D) (j : J) :
F.map (e.inv j) ≫ F.map (e.hom j) = 𝟙 _ := by
rw [← F.map_comp, ← GradedObject.categoryOfGradedObjects_comp, e.inv_hom_id,
GradedObject.categoryOfGradedObjects_id, Functor.map_id]
@[reassoc (attr := simp)]
lemma map_hom_inv_id_eval_app (e : X ≅ Y) (F : C ⥤ D ⥤ E) (j : J) (Y : D) :
(F.map (e.hom j)).app Y ≫ (F.map (e.inv j)).app Y = 𝟙 _ := by
rw [← NatTrans.comp_app, ← F.map_comp, hom_inv_id_eval,
Functor.map_id, NatTrans.id_app]
@[reassoc (attr := simp)]
lemma map_inv_hom_id_eval_app (e : X ≅ Y) (F : C ⥤ D ⥤ E) (j : J) (Y : D) :
(F.map (e.inv j)).app Y ≫ (F.map (e.hom j)).app Y = 𝟙 _ := by
rw [← NatTrans.comp_app, ← F.map_comp, inv_hom_id_eval,
Functor.map_id, NatTrans.id_app]
end Iso
namespace GradedObject
variable {C : Type u} [Category.{v} C]
section
variable (C)
-- Porting note: added to ease the port
/-- Pull back an `I`-graded object in `C` to a `J`-graded object along a function `J → I`. -/
abbrev comap {I J : Type*} (h : J → I) : GradedObject I C ⥤ GradedObject J C :=
Pi.comap (fun _ => C) h
-- Porting note: added to ease the port, this is a special case of `Functor.eqToHom_proj`
@[simp]
theorem eqToHom_proj {I : Type*} {x x' : GradedObject I C} (h : x = x') (i : I) :
(eqToHom h : x ⟶ x') i = eqToHom (Function.funext_iff.mp h i) := by
subst h
rfl
/-- The natural isomorphism comparing between
pulling back along two propositionally equal functions.
-/
@[simps]
def comapEq {β γ : Type w} {f g : β → γ} (h : f = g) : comap C f ≅ comap C g where
hom := { app := fun X b => eqToHom (by dsimp; simp only [h]) }
inv := { app := fun X b => eqToHom (by dsimp; simp only [h]) }
theorem comapEq_symm {β γ : Type w} {f g : β → γ} (h : f = g) :
comapEq C h.symm = (comapEq C h).symm := by aesop_cat
theorem comapEq_trans {β γ : Type w} {f g h : β → γ} (k : f = g) (l : g = h) :
comapEq C (k.trans l) = comapEq C k ≪≫ comapEq C l := by aesop_cat
theorem eqToHom_apply {β : Type w} {X Y : β → C} (h : X = Y) (b : β) :
(eqToHom h : X ⟶ Y) b = eqToHom (by rw [h]) := by
subst h
rfl
/-- The equivalence between β-graded objects and γ-graded objects,
given an equivalence between β and γ.
-/
@[simps]
def comapEquiv {β γ : Type w} (e : β ≃ γ) : GradedObject β C ≌ GradedObject γ C where
functor := comap C (e.symm : γ → β)
inverse := comap C (e : β → γ)
counitIso :=
(Pi.comapComp (fun _ => C) _ _).trans (comapEq C (by ext; simp))
unitIso :=
(comapEq C (by ext; simp)).trans (Pi.comapComp _ _ _).symm
end
instance hasShift {β : Type*} [AddCommGroup β] (s : β) : HasShift (GradedObjectWithShift s C) ℤ :=
hasShiftMk _ _
{ F := fun n => comap C fun b : β => b + n • s
zero := comapEq C (by aesop_cat) ≪≫ Pi.comapId β fun _ => C
add := fun m n => comapEq C (by ext; dsimp; rw [add_comm m n, add_zsmul, add_assoc]) ≪≫
(Pi.comapComp _ _ _).symm }
@[simp]
theorem shiftFunctor_obj_apply {β : Type*} [AddCommGroup β] (s : β) (X : β → C) (t : β) (n : ℤ) :
(shiftFunctor (GradedObjectWithShift s C) n).obj X t = X (t + n • s) :=
rfl
@[simp]
theorem shiftFunctor_map_apply {β : Type*} [AddCommGroup β] (s : β)
{X Y : GradedObjectWithShift s C} (f : X ⟶ Y) (t : β) (n : ℤ) :
(shiftFunctor (GradedObjectWithShift s C) n).map f t = f (t + n • s) :=
rfl
instance [HasZeroMorphisms C] (β : Type w) (X Y : GradedObject β C) :
Zero (X ⟶ Y) := ⟨fun _ => 0⟩
#adaptation_note
/--
After https://github.com/leanprover/lean4/pull/4481
the `simpNF` linter incorrectly claims this lemma can't be applied by `simp`.
-/
@[simp, nolint simpNF]
theorem zero_apply [HasZeroMorphisms C] (β : Type w) (X Y : GradedObject β C) (b : β) :
(0 : X ⟶ Y) b = 0 :=
rfl
instance hasZeroMorphisms [HasZeroMorphisms C] (β : Type w) :
HasZeroMorphisms.{max w v} (GradedObject β C) where
section
open ZeroObject
instance hasZeroObject [HasZeroObject C] [HasZeroMorphisms C] (β : Type w) :
HasZeroObject.{max w v} (GradedObject β C) := by
refine ⟨⟨fun _ => 0, fun X => ⟨⟨⟨fun b => 0⟩, fun f => ?_⟩⟩, fun X =>
⟨⟨⟨fun b => 0⟩, fun f => ?_⟩⟩⟩⟩ <;> aesop_cat
end
end GradedObject
namespace GradedObject
-- The universes get a little hairy here, so we restrict the universe level for the grading to 0.
-- Since we're typically interested in grading by ℤ or a finite group, this should be okay.
-- If you're grading by things in higher universes, have fun!
variable (β : Type)
variable (C : Type u) [Category.{v} C]
variable [HasCoproducts.{0} C]
section
/-- The total object of a graded object is the coproduct of the graded components.
-/
noncomputable def total : GradedObject β C ⥤ C where
obj X := ∐ fun i : β => X i
map f := Limits.Sigma.map fun i => f i
end
variable [HasZeroMorphisms C]
/--
The `total` functor taking a graded object to the coproduct of its graded components is faithful.
To prove this, we need to know that the coprojections into the coproduct are monomorphisms,
which follows from the fact we have zero morphisms and decidable equality for the grading.
-/
instance : (total β C).Faithful where
map_injective {X Y} f g w := by
ext i
replace w := Sigma.ι (fun i : β => X i) i ≫= w
erw [colimit.ι_map, colimit.ι_map] at w
simp? at * says simp only [Discrete.functor_obj_eq_as, Discrete.natTrans_app] at *
exact Mono.right_cancellation _ _ w
end GradedObject
namespace GradedObject
noncomputable section
variable (β : Type)
variable (C : Type (u + 1)) [LargeCategory C] [ConcreteCategory C] [HasCoproducts.{0} C]
[HasZeroMorphisms C]
instance : ConcreteCategory (GradedObject β C) where forget := total β C ⋙ forget C
instance : HasForget₂ (GradedObject β C) C where forget₂ := total β C
end
end GradedObject
namespace GradedObject
variable {I J K : Type*} {C : Type*} [Category C]
(X Y Z : GradedObject I C) (φ : X ⟶ Y) (e : X ≅ Y) (ψ : Y ⟶ Z) (p : I → J)
/-- If `X : GradedObject I C` and `p : I → J`, `X.mapObjFun p j` is the family of objects `X i`
for `i : I` such that `p i = j`. -/
abbrev mapObjFun (j : J) (i : p ⁻¹' {j}) : C := X i
variable (j : J)
/-- Given `X : GradedObject I C` and `p : I → J`, `X.HasMap p` is the condition that
for all `j : J`, the coproduct of all `X i` such `p i = j` exists. -/
abbrev HasMap : Prop := ∀ (j : J), HasCoproduct (X.mapObjFun p j)
variable {X Y} in
lemma hasMap_of_iso (e : X ≅ Y) (p: I → J) [HasMap X p] : HasMap Y p := fun j => by
have α : Discrete.functor (X.mapObjFun p j) ≅ Discrete.functor (Y.mapObjFun p j) :=
Discrete.natIso (fun ⟨i, _⟩ => (GradedObject.eval i).mapIso e)
exact hasColimitOfIso α.symm
section
variable [X.HasMap p] [Y.HasMap p] [Z.HasMap p]
/-- Given `X : GradedObject I C` and `p : I → J`, `X.mapObj p` is the graded object by `J`
which in degree `j` consists of the coproduct of the `X i` such that `p i = j`. -/
noncomputable def mapObj : GradedObject J C := fun j => ∐ (X.mapObjFun p j)
/-- The canonical inclusion `X i ⟶ X.mapObj p j` when `i : I` and `j : J` are such
that `p i = j`. -/
noncomputable def ιMapObj (i : I) (j : J) (hij : p i = j) : X i ⟶ X.mapObj p j :=
Sigma.ι (X.mapObjFun p j) ⟨i, hij⟩
/-- Given `X : GradedObject I C`, `p : I → J` and `j : J`,
`CofanMapObjFun X p j` is the type `Cofan (X.mapObjFun p j)`. The point object of
such colimits cofans are isomorphic to `X.mapObj p j`, see `CofanMapObjFun.iso`. -/
abbrev CofanMapObjFun (j : J) : Type _ := Cofan (X.mapObjFun p j)
-- in order to use the cofan API, some definitions below
-- have a `simp` attribute rather than `simps`
/-- Constructor for `CofanMapObjFun X p j`. -/
@[simp]
def CofanMapObjFun.mk (j : J) (pt : C) (ι' : ∀ (i : I) (_ : p i = j), X i ⟶ pt) :
CofanMapObjFun X p j :=
Cofan.mk pt (fun ⟨i, hi⟩ => ι' i hi)
/-- The tautological cofan corresponding to the coproduct decomposition of `X.mapObj p j`. -/
@[simp]
noncomputable def cofanMapObj (j : J) : CofanMapObjFun X p j :=
CofanMapObjFun.mk X p j (X.mapObj p j) (fun i hi => X.ιMapObj p i j hi)
/-- Given `X : GradedObject I C`, `p : I → J` and `j : J`, `X.mapObj p j` satisfies
the universal property of the coproduct of those `X i` such that `p i = j`. -/
noncomputable def isColimitCofanMapObj (j : J) : IsColimit (X.cofanMapObj p j) :=
colimit.isColimit _
@[ext]
lemma mapObj_ext {A : C} {j : J} (f g : X.mapObj p j ⟶ A)
(hfg : ∀ (i : I) (hij : p i = j), X.ιMapObj p i j hij ≫ f = X.ιMapObj p i j hij ≫ g) :
f = g :=
Cofan.IsColimit.hom_ext (X.isColimitCofanMapObj p j) _ _ (fun ⟨i, hij⟩ => hfg i hij)
/-- This is the morphism `X.mapObj p j ⟶ A` constructed from a family of
morphisms `X i ⟶ A` for all `i : I` such that `p i = j`. -/
noncomputable def descMapObj {A : C} {j : J} (φ : ∀ (i : I) (_ : p i = j), X i ⟶ A) :
X.mapObj p j ⟶ A :=
Cofan.IsColimit.desc (X.isColimitCofanMapObj p j) (fun ⟨i, hi⟩ => φ i hi)
@[reassoc (attr := simp)]
lemma ι_descMapObj {A : C} {j : J}
(φ : ∀ (i : I) (_ : p i = j), X i ⟶ A) (i : I) (hi : p i = j) :
X.ιMapObj p i j hi ≫ X.descMapObj p φ = φ i hi := by
apply Cofan.IsColimit.fac
end
namespace CofanMapObjFun
lemma hasMap (c : ∀ j, CofanMapObjFun X p j) (hc : ∀ j, IsColimit (c j)) :
X.HasMap p := fun j => ⟨_, hc j⟩
variable {j X p}
variable [X.HasMap p]
variable {c : CofanMapObjFun X p j} (hc : IsColimit c)
/-- If `c : CofanMapObjFun X p j` is a colimit cofan, this is the induced
isomorphism `c.pt ≅ X.mapObj p j`. -/
noncomputable def iso : c.pt ≅ X.mapObj p j :=
IsColimit.coconePointUniqueUpToIso hc (X.isColimitCofanMapObj p j)
@[reassoc (attr := simp)]
lemma inj_iso_hom (i : I) (hi : p i = j) :
c.inj ⟨i, hi⟩ ≫ (c.iso hc).hom = X.ιMapObj p i j hi := by
apply IsColimit.comp_coconePointUniqueUpToIso_hom
@[reassoc (attr := simp)]
lemma ιMapObj_iso_inv (i : I) (hi : p i = j) :
X.ιMapObj p i j hi ≫ (c.iso hc).inv = c.inj ⟨i, hi⟩ := by
apply IsColimit.comp_coconePointUniqueUpToIso_inv
end CofanMapObjFun
variable {X Y}
variable [X.HasMap p] [Y.HasMap p]
/-- The canonical morphism of `J`-graded objects `X.mapObj p ⟶ Y.mapObj p` induced by
a morphism `X ⟶ Y` of `I`-graded objects and a map `p : I → J`. -/
noncomputable def mapMap : X.mapObj p ⟶ Y.mapObj p := fun j =>
X.descMapObj p (fun i hi => φ i ≫ Y.ιMapObj p i j hi)
@[reassoc (attr := simp)]
lemma ι_mapMap (i : I) (j : J) (hij : p i = j) :
X.ιMapObj p i j hij ≫ mapMap φ p j = φ i ≫ Y.ιMapObj p i j hij := by
simp only [mapMap, ι_descMapObj]
lemma congr_mapMap (φ₁ φ₂ : X ⟶ Y) (h : φ₁ = φ₂) : mapMap φ₁ p = mapMap φ₂ p := by
subst h
rfl
variable (X)
@[simp]
lemma mapMap_id : mapMap (𝟙 X) p = 𝟙 _ := by aesop_cat
variable {X Z}
@[simp, reassoc]
lemma mapMap_comp [Z.HasMap p] : mapMap (φ ≫ ψ) p = mapMap φ p ≫ mapMap ψ p := by aesop_cat
/-- The isomorphism of `J`-graded objects `X.mapObj p ≅ Y.mapObj p` induced by an
isomorphism `X ≅ Y` of graded objects and a map `p : I → J`. -/
@[simps]
noncomputable def mapIso : X.mapObj p ≅ Y.mapObj p where
hom := mapMap e.hom p
inv := mapMap e.inv p
variable (C)
/-- Given a map `p : I → J`, this is the functor `GradedObject I C ⥤ GradedObject J C` which
sends an `I`-object `X` to the graded object `X.mapObj p` which in degree `j : J` is given
by the coproduct of those `X i` such that `p i = j`. -/
@[simps]
noncomputable def map [∀ (j : J), HasColimitsOfShape (Discrete (p ⁻¹' {j})) C] :
GradedObject I C ⥤ GradedObject J C where
obj X := X.mapObj p
map φ := mapMap φ p
variable {C} (X Y)
variable (q : J → K) (r : I → K) (hpqr : ∀ i, q (p i) = r i)
section
variable (k : K) (c : ∀ (j : J), q j = k → X.CofanMapObjFun p j)
(hc : ∀ j hj, IsColimit (c j hj))
(c' : Cofan (fun (j : q ⁻¹' {k}) => (c j.1 j.2).pt)) (hc' : IsColimit c')
/-- Given maps `p : I → J`, `q : J → K` and `r : I → K` such that `q.comp p = r`,
`X : GradedObject I C`, `k : K`, the datum of cofans `X.CofanMapObjFun p j` for all
`j : J` and of a cofan for all the points of these cofans, this is a cofan of
type `X.CofanMapObjFun r k`, which is a colimit (see `isColimitCofanMapObjComp`) if the
given cofans are. -/
@[simp]
def cofanMapObjComp : X.CofanMapObjFun r k :=
CofanMapObjFun.mk _ _ _ c'.pt (fun i hi =>
(c (p i) (by rw [hpqr, hi])).inj ⟨i, rfl⟩ ≫ c'.inj (⟨p i, by
rw [Set.mem_preimage, Set.mem_singleton_iff, hpqr, hi]⟩))
/-- Given maps `p : I → J`, `q : J → K` and `r : I → K` such that `q.comp p = r`,
`X : GradedObject I C`, `k : K`, the cofan constructed by `cofanMapObjComp` is a colimit.
In other words, if we have, for all `j : J` such that `hj : q j = k`,
a colimit cofan `c j hj` which computes the coproduct of the `X i` such that `p i = j`,
and also a colimit cofan which computes the coproduct of the points of these `c j hj`, then
the point of this latter cofan computes the coproduct of the `X i` such that `r i = k`. -/
@[simp]
def isColimitCofanMapObjComp :
IsColimit (cofanMapObjComp X p q r hpqr k c c') :=
mkCofanColimit _
(fun s => Cofan.IsColimit.desc hc'
(fun ⟨j, (hj : q j = k)⟩ => Cofan.IsColimit.desc (hc j hj)
(fun ⟨i, (hi : p i = j)⟩ => s.inj ⟨i, by
simp only [Set.mem_preimage, Set.mem_singleton_iff, ← hpqr, hi, hj]⟩)))
(fun s ⟨i, (hi : r i = k)⟩ => by simp)
(fun s m hm => by
apply Cofan.IsColimit.hom_ext hc'
rintro ⟨j, rfl : q j = k⟩
apply Cofan.IsColimit.hom_ext (hc j rfl)
rintro ⟨i, rfl : p i = j⟩
dsimp
rw [Cofan.IsColimit.fac, Cofan.IsColimit.fac, ← hm]
dsimp
rw [assoc])
lemma hasMap_comp [(X.mapObj p).HasMap q] : X.HasMap r :=
fun k => ⟨_, isColimitCofanMapObjComp X p q r hpqr k _
(fun j _ => X.isColimitCofanMapObj p j) _ ((X.mapObj p).isColimitCofanMapObj q k)⟩
end
section HasZeroMorphisms
end HasZeroMorphisms
variable [HasZeroMorphisms C] [DecidableEq J] (i : I) (j : J)
/-- The canonical inclusion `X i ⟶ X.mapObj p j` when `p i = j`, the zero morphism otherwise. -/
noncomputable def ιMapObjOrZero : X i ⟶ X.mapObj p j :=
if h : p i = j
then X.ιMapObj p i j h
else 0
lemma ιMapObjOrZero_eq (h : p i = j) : X.ιMapObjOrZero p i j = X.ιMapObj p i j h := dif_pos h
lemma ιMapObjOrZero_eq_zero (h : p i ≠ j) : X.ιMapObjOrZero p i j = 0 := dif_neg h
variable {X Y} in
@[reassoc (attr := simp)]
lemma ιMapObjOrZero_mapMap :
X.ιMapObjOrZero p i j ≫ mapMap φ p j = φ i ≫ Y.ιMapObjOrZero p i j := by
by_cases h : p i = j
· simp only [ιMapObjOrZero_eq _ _ _ _ h, ι_mapMap]
· simp only [ιMapObjOrZero_eq_zero _ _ _ _ h, zero_comp, comp_zero]
end GradedObject
end CategoryTheory
|
CategoryTheory\Grothendieck.lean | /-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Sina Hazratpour
-/
import Mathlib.CategoryTheory.Category.Cat
import Mathlib.CategoryTheory.Elements
import Mathlib.CategoryTheory.Comma.Over
/-!
# The Grothendieck construction
Given a functor `F : C ⥤ Cat`, the objects of `Grothendieck F`
consist of dependent pairs `(b, f)`, where `b : C` and `f : F.obj c`,
and a morphism `(b, f) ⟶ (b', f')` is a pair `β : b ⟶ b'` in `C`, and
`φ : (F.map β).obj f ⟶ f'`
`Grothendieck.functor` makes the Grothendieck construction into a functor from the functor category
`C ⥤ Cat` to the over category `Over C` in the category of categories.
Categories such as `PresheafedSpace` are in fact examples of this construction,
and it may be interesting to try to generalize some of the development there.
## Implementation notes
Really we should treat `Cat` as a 2-category, and allow `F` to be a 2-functor.
There is also a closely related construction starting with `G : Cᵒᵖ ⥤ Cat`,
where morphisms consists again of `β : b ⟶ b'` and `φ : f ⟶ (F.map (op β)).obj f'`.
## References
See also `CategoryTheory.Functor.Elements` for the category of elements of functor `F : C ⥤ Type`.
* https://stacks.math.columbia.edu/tag/02XV
* https://ncatlab.org/nlab/show/Grothendieck+construction
-/
universe u
namespace CategoryTheory
variable {C D : Type*} [Category C] [Category D]
variable (F : C ⥤ Cat)
/--
The Grothendieck construction (often written as `∫ F` in mathematics) for a functor `F : C ⥤ Cat`
gives a category whose
* objects `X` consist of `X.base : C` and `X.fiber : F.obj base`
* morphisms `f : X ⟶ Y` consist of
`base : X.base ⟶ Y.base` and
`f.fiber : (F.map base).obj X.fiber ⟶ Y.fiber`
-/
-- Porting note(#5171): no such linter yet
-- @[nolint has_nonempty_instance]
structure Grothendieck where
/-- The underlying object in `C` -/
base : C
/-- The object in the fiber of the base object. -/
fiber : F.obj base
namespace Grothendieck
variable {F}
/-- A morphism in the Grothendieck category `F : C ⥤ Cat` consists of
`base : X.base ⟶ Y.base` and `f.fiber : (F.map base).obj X.fiber ⟶ Y.fiber`.
-/
structure Hom (X Y : Grothendieck F) where
/-- The morphism between base objects. -/
base : X.base ⟶ Y.base
/-- The morphism from the pushforward to the source fiber object to the target fiber object. -/
fiber : (F.map base).obj X.fiber ⟶ Y.fiber
@[ext (iff := false)]
theorem ext {X Y : Grothendieck F} (f g : Hom X Y) (w_base : f.base = g.base)
(w_fiber : eqToHom (by rw [w_base]) ≫ f.fiber = g.fiber) : f = g := by
cases f; cases g
congr
dsimp at w_base
aesop_cat
/-- The identity morphism in the Grothendieck category.
-/
@[simps]
def id (X : Grothendieck F) : Hom X X where
base := 𝟙 X.base
fiber := eqToHom (by erw [CategoryTheory.Functor.map_id, Functor.id_obj X.fiber])
instance (X : Grothendieck F) : Inhabited (Hom X X) :=
⟨id X⟩
/-- Composition of morphisms in the Grothendieck category.
-/
@[simps]
def comp {X Y Z : Grothendieck F} (f : Hom X Y) (g : Hom Y Z) : Hom X Z where
base := f.base ≫ g.base
fiber :=
eqToHom (by erw [Functor.map_comp, Functor.comp_obj]) ≫ (F.map g.base).map f.fiber ≫ g.fiber
attribute [local simp] eqToHom_map
instance : Category (Grothendieck F) where
Hom X Y := Grothendieck.Hom X Y
id X := Grothendieck.id X
comp := @fun X Y Z f g => Grothendieck.comp f g
comp_id := @fun X Y f => by
dsimp; ext
· simp
· dsimp
rw [← NatIso.naturality_2 (eqToIso (F.map_id Y.base)) f.fiber]
simp
id_comp := @fun X Y f => by dsimp; ext <;> simp
assoc := @fun W X Y Z f g h => by
dsimp; ext
· simp
· dsimp
rw [← NatIso.naturality_2 (eqToIso (F.map_comp _ _)) f.fiber]
simp
@[simp]
theorem id_fiber' (X : Grothendieck F) :
Hom.fiber (𝟙 X) = eqToHom (by erw [CategoryTheory.Functor.map_id, Functor.id_obj X.fiber]) :=
id_fiber X
@[simp]
theorem comp_fiber' {X Y Z : Grothendieck F} (f : X ⟶ Y) (g : Y ⟶ Z) :
Hom.fiber (f ≫ g) =
eqToHom (by erw [Functor.map_comp, Functor.comp_obj]) ≫
(F.map g.base).map f.fiber ≫ g.fiber :=
comp_fiber f g
theorem congr {X Y : Grothendieck F} {f g : X ⟶ Y} (h : f = g) :
f.fiber = eqToHom (by subst h; rfl) ≫ g.fiber := by
subst h
dsimp
simp
section
variable (F)
/-- The forgetful functor from `Grothendieck F` to the source category. -/
@[simps!]
def forget : Grothendieck F ⥤ C where
obj X := X.1
map := @fun X Y f => f.1
end
section
variable {G : C ⥤ Cat}
/-- The Grothendieck construction is functorial: a natural transformation `α : F ⟶ G` induces
a functor `Grothendieck.map : Grothendieck F ⥤ Grothendieck G`.
-/
@[simps!]
def map (α : F ⟶ G) : Grothendieck F ⥤ Grothendieck G where
obj X :=
{ base := X.base
fiber := (α.app X.base).obj X.fiber }
map {X Y} f :=
{ base := f.base
fiber := (eqToHom (α.naturality f.base).symm).app X.fiber ≫ (α.app Y.base).map f.fiber }
map_id X := by
simp only [Cat.comp_obj, id_fiber', eqToHom_map]
congr 1
rw [eqToHom_app, eqToHom_trans]
map_comp {X Y Z} f g := by
dsimp
congr 1
simp only [comp_fiber' f g, ← Category.assoc, Functor.map_comp, eqToHom_map]
congr 1
simp only [Cat.comp_obj, eqToHom_trans, eqToHom_map, Cat.comp_map, eqToHom_trans_assoc,
Category.assoc]
rw [eqToHom_app, eqToHom_app, eqToHom_app]
erw [Functor.congr_hom (α.naturality g.base).symm f.fiber]
simp
theorem map_obj {α : F ⟶ G} (X : Grothendieck F) :
(Grothendieck.map α).obj X = ⟨X.base, (α.app X.base).obj X.fiber⟩ := rfl
theorem map_map {α : F ⟶ G} {X Y : Grothendieck F} {f : X ⟶ Y} :
(Grothendieck.map α).map f =
⟨f.base, (eqToHom (α.naturality f.base).symm).app X.fiber ≫ (α.app Y.base).map f.fiber⟩ := rfl
/-- The functor `Grothendieck.map α : Grothendieck F ⥤ Grothendieck G` lies over `C`.-/
theorem functor_comp_forget {α : F ⟶ G} :
Grothendieck.map α ⋙ Grothendieck.forget G = Grothendieck.forget F := rfl
theorem map_id_eq : map (𝟙 F) = 𝟙 (Cat.of <| Grothendieck <| F) := by
fapply Functor.ext
· intro X
rfl
· intro X Y f
simp [map_map]
congr
rw [NatTrans.id_app]
simp
/-- Making the equality of functors into an isomorphism. Note: we should avoid equality of functors
if possible, and we should prefer `map_id_iso` to `map_id_eq` whenever we can. -/
def mapIdIso : map (𝟙 F) ≅ 𝟙 (Cat.of <| Grothendieck <| F) := eqToIso map_id_eq
variable {H : C ⥤ Cat}
theorem map_comp_eq (α : F ⟶ G) (β : G ⟶ H) :
map (α ≫ β) = map α ⋙ map β := by
fapply Functor.ext
· intro X
rfl
· intro X Y f
simp only [map_map, map_obj_base, NatTrans.comp_app, Cat.comp_obj, Cat.comp_map,
eqToHom_refl, Functor.comp_map, Functor.map_comp, Category.comp_id, Category.id_comp]
fapply Grothendieck.ext
· rfl
· simp only [eqToHom_refl, Category.id_comp]
erw [eqToHom_app, eqToHom_app, eqToHom_app, eqToHom_map]
simp only [Cat.comp_obj, eqToHom_trans_assoc]
/-- Making the equality of functors into an isomorphism. Note: we should avoid equality of functors
if possible, and we should prefer `map_comp_iso` to `map_comp_eq` whenever we can. -/
def mapCompIso (α : F ⟶ G) (β : G ⟶ H) : map (α ≫ β) ≅ map α ⋙ map β := eqToIso (map_comp_eq α β)
end
universe v
/-- The Grothendieck construction as a functor from the functor category `E ⥤ Cat` to the
over category `Over E`. -/
def functor {E : Cat.{v,u}} : (E ⥤ Cat.{v,u}) ⥤ Over (T := Cat.{v,u}) E where
obj F := Over.mk (X := E) (Y := Cat.of (Grothendieck F)) (Grothendieck.forget F)
map {F G} α := Over.homMk (X:= E) (Grothendieck.map α) Grothendieck.functor_comp_forget
map_id F := by
ext
exact Grothendieck.map_id_eq (F := F)
map_comp α β := by
simp [Grothendieck.map_comp_eq α β]
rfl
universe w
variable (G : C ⥤ Type w)
/-- Auxiliary definition for `grothendieckTypeToCat`, to speed up elaboration. -/
@[simps!]
def grothendieckTypeToCatFunctor : Grothendieck (G ⋙ typeToCat) ⥤ G.Elements where
obj X := ⟨X.1, X.2.as⟩
map f := ⟨f.1, f.2.1.1⟩
/-- Auxiliary definition for `grothendieckTypeToCat`, to speed up elaboration. -/
-- Porting note:
-- `simps` is incorrectly producing Prop-valued projections here,
-- so we manually specify which ones to produce.
-- See https://leanprover.zulipchat.com/#narrow/stream/144837-PR-reviews/topic/!4.233204.20simps.20bug.20.28Grothendieck.20construction.29
@[simps! obj_base obj_fiber_as map_base]
def grothendieckTypeToCatInverse : G.Elements ⥤ Grothendieck (G ⋙ typeToCat) where
obj X := ⟨X.1, ⟨X.2⟩⟩
map f := ⟨f.1, ⟨⟨f.2⟩⟩⟩
/-- The Grothendieck construction applied to a functor to `Type`
(thought of as a functor to `Cat` by realising a type as a discrete category)
is the same as the 'category of elements' construction.
-/
-- See porting note on grothendieckTypeToCatInverse.
-- We just want to turn off grothendieckTypeToCat_inverse_map_fiber_down_down,
-- so have to list the complement here for `@[simps]`.
@[simps! functor_obj_fst functor_obj_snd functor_map_coe inverse_obj_base inverse_obj_fiber_as
inverse_map_base unitIso_hom_app_base unitIso_hom_app_fiber unitIso_inv_app_base
unitIso_inv_app_fiber counitIso_hom_app_coe counitIso_inv_app_coe]
def grothendieckTypeToCat : Grothendieck (G ⋙ typeToCat) ≌ G.Elements where
functor := grothendieckTypeToCatFunctor G
inverse := grothendieckTypeToCatInverse G
unitIso :=
NatIso.ofComponents
(fun X => by
rcases X with ⟨_, ⟨⟩⟩
exact Iso.refl _)
(by
rintro ⟨_, ⟨⟩⟩ ⟨_, ⟨⟩⟩ ⟨base, ⟨⟨f⟩⟩⟩
dsimp at *
simp
rfl)
counitIso :=
NatIso.ofComponents
(fun X => by
cases X
exact Iso.refl _)
(by
rintro ⟨⟩ ⟨⟩ ⟨f, e⟩
dsimp at *
simp
rfl)
functor_unitIso_comp := by
rintro ⟨_, ⟨⟩⟩
dsimp
simp
rfl
end Grothendieck
end CategoryTheory
|
CategoryTheory\Groupoid.lean | /-
Copyright (c) 2018 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Scott Morrison, David Wärn
-/
import Mathlib.CategoryTheory.FullSubcategory
import Mathlib.CategoryTheory.Products.Basic
import Mathlib.CategoryTheory.Pi.Basic
import Mathlib.CategoryTheory.Category.Basic
import Mathlib.Combinatorics.Quiver.Symmetric
/-!
# Groupoids
We define `Groupoid` as a typeclass extending `Category`,
asserting that all morphisms have inverses.
The instance `IsIso.ofGroupoid (f : X ⟶ Y) : IsIso f` means that you can then write
`inv f` to access the inverse of any morphism `f`.
`Groupoid.isoEquivHom : (X ≅ Y) ≃ (X ⟶ Y)` provides the equivalence between
isomorphisms and morphisms in a groupoid.
We provide a (non-instance) constructor `Groupoid.ofIsIso` from an existing category
with `IsIso f` for every `f`.
## See also
See also `CategoryTheory.Core` for the groupoid of isomorphisms in a category.
-/
namespace CategoryTheory
universe v v₂ u u₂
-- morphism levels before object levels. See note [CategoryTheory universes].
/-- A `Groupoid` is a category such that all morphisms are isomorphisms. -/
class Groupoid (obj : Type u) extends Category.{v} obj : Type max u (v + 1) where
/-- The inverse morphism -/
inv : ∀ {X Y : obj}, (X ⟶ Y) → (Y ⟶ X)
/-- `inv f` composed `f` is the identity -/
inv_comp : ∀ {X Y : obj} (f : X ⟶ Y), comp (inv f) f = id Y := by aesop_cat
/-- `f` composed with `inv f` is the identity -/
comp_inv : ∀ {X Y : obj} (f : X ⟶ Y), comp f (inv f) = id X := by aesop_cat
initialize_simps_projections Groupoid (-Hom)
/-- A `LargeGroupoid` is a groupoid
where the objects live in `Type (u+1)` while the morphisms live in `Type u`.
-/
abbrev LargeGroupoid (C : Type (u + 1)) : Type (u + 1) :=
Groupoid.{u} C
/-- A `SmallGroupoid` is a groupoid
where the objects and morphisms live in the same universe.
-/
abbrev SmallGroupoid (C : Type u) : Type (u + 1) :=
Groupoid.{u} C
section
variable {C : Type u} [Groupoid.{v} C] {X Y : C}
-- see Note [lower instance priority]
instance (priority := 100) IsIso.of_groupoid (f : X ⟶ Y) : IsIso f :=
⟨⟨Groupoid.inv f, Groupoid.comp_inv f, Groupoid.inv_comp f⟩⟩
@[simp]
theorem Groupoid.inv_eq_inv (f : X ⟶ Y) : Groupoid.inv f = CategoryTheory.inv f :=
IsIso.eq_inv_of_hom_inv_id <| Groupoid.comp_inv f
/-- `Groupoid.inv` is involutive. -/
@[simps]
def Groupoid.invEquiv : (X ⟶ Y) ≃ (Y ⟶ X) :=
⟨Groupoid.inv, Groupoid.inv, fun f => by simp, fun f => by simp⟩
instance (priority := 100) groupoidHasInvolutiveReverse : Quiver.HasInvolutiveReverse C where
reverse' f := Groupoid.inv f
inv' f := by
dsimp [Quiver.reverse]
simp
@[simp]
theorem Groupoid.reverse_eq_inv (f : X ⟶ Y) : Quiver.reverse f = Groupoid.inv f :=
rfl
instance functorMapReverse {D : Type*} [Groupoid D] (F : C ⥤ D) : F.toPrefunctor.MapReverse where
map_reverse' f := by
simp only [Quiver.reverse, Quiver.HasReverse.reverse', Groupoid.inv_eq_inv,
Functor.map_inv]
variable (X Y)
/-- In a groupoid, isomorphisms are equivalent to morphisms. -/
def Groupoid.isoEquivHom : (X ≅ Y) ≃ (X ⟶ Y) where
toFun := Iso.hom
invFun f := ⟨f, Groupoid.inv f, (by aesop_cat), (by aesop_cat)⟩
left_inv i := Iso.ext rfl
right_inv f := rfl
variable (C)
/-- The functor from a groupoid `C` to its opposite sending every morphism to its inverse. -/
@[simps]
noncomputable def Groupoid.invFunctor : C ⥤ Cᵒᵖ where
obj := Opposite.op
map {X Y} f := (inv f).op
end
section
variable {C : Type u} [Category.{v} C]
/-- A category where every morphism `IsIso` is a groupoid. -/
noncomputable def Groupoid.ofIsIso (all_is_iso : ∀ {X Y : C} (f : X ⟶ Y), IsIso f) :
Groupoid.{v} C where
inv := fun f => CategoryTheory.inv f
inv_comp := fun f => Classical.choose_spec (all_is_iso f).out|>.right
/-- A category with a unique morphism between any two objects is a groupoid -/
def Groupoid.ofHomUnique (all_unique : ∀ {X Y : C}, Unique (X ⟶ Y)) : Groupoid.{v} C where
inv _ := all_unique.default
end
instance InducedCategory.groupoid {C : Type u} (D : Type u₂) [Groupoid.{v} D] (F : C → D) :
Groupoid.{v} (InducedCategory D F) :=
{ InducedCategory.category F with
inv := fun f => Groupoid.inv f
inv_comp := fun f => Groupoid.inv_comp f
comp_inv := fun f => Groupoid.comp_inv f }
section
instance groupoidPi {I : Type u} {J : I → Type u₂} [∀ i, Groupoid.{v} (J i)] :
Groupoid.{max u v} (∀ i : I, J i) where
inv f := fun i : I => Groupoid.inv (f i)
comp_inv := fun f => by funext i; apply Groupoid.comp_inv
inv_comp := fun f => by funext i; apply Groupoid.inv_comp
instance groupoidProd {α : Type u} {β : Type v} [Groupoid.{u₂} α] [Groupoid.{v₂} β] :
Groupoid.{max u₂ v₂} (α × β) where
inv f := (Groupoid.inv f.1, Groupoid.inv f.2)
end
end CategoryTheory
|
CategoryTheory\HomCongr.lean | /-
Copyright (c) 2019 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.CategoryTheory.Iso
/-!
# Conjugate morphisms by isomorphisms
We define
`CategoryTheory.Iso.homCongr : (X ≅ X₁) → (Y ≅ Y₁) → (X ⟶ Y) ≃ (X₁ ⟶ Y₁)`,
cf. `Equiv.arrowCongr`,
and `CategoryTheory.Iso.isoCongr : (f : X₁ ≅ X₂) → (g : Y₁ ≅ Y₂) → (X₁ ≅ Y₁) ≃ (X₂ ≅ Y₂)`.
As corollaries, an isomorphism `α : X ≅ Y` defines
- a monoid isomorphism
`CategoryTheory.Iso.conj : End X ≃* End Y` by `α.conj f = α.inv ≫ f ≫ α.hom`;
- a group isomorphism `CategoryTheory.Iso.conjAut : Aut X ≃* Aut Y` by
`α.conjAut f = α.symm ≪≫ f ≪≫ α`
which can be found in `CategoryTheory.Conj`.
-/
universe v u
namespace CategoryTheory
namespace Iso
variable {C : Type u} [Category.{v} C]
/-- If `X` is isomorphic to `X₁` and `Y` is isomorphic to `Y₁`, then
there is a natural bijection between `X ⟶ Y` and `X₁ ⟶ Y₁`. See also `Equiv.arrowCongr`. -/
@[simps]
def homCongr {X Y X₁ Y₁ : C} (α : X ≅ X₁) (β : Y ≅ Y₁) : (X ⟶ Y) ≃ (X₁ ⟶ Y₁) where
toFun f := α.inv ≫ f ≫ β.hom
invFun f := α.hom ≫ f ≫ β.inv
left_inv f :=
show α.hom ≫ (α.inv ≫ f ≫ β.hom) ≫ β.inv = f by
rw [Category.assoc, Category.assoc, β.hom_inv_id, α.hom_inv_id_assoc, Category.comp_id]
right_inv f :=
show α.inv ≫ (α.hom ≫ f ≫ β.inv) ≫ β.hom = f by
rw [Category.assoc, Category.assoc, β.inv_hom_id, α.inv_hom_id_assoc, Category.comp_id]
theorem homCongr_comp {X Y Z X₁ Y₁ Z₁ : C} (α : X ≅ X₁) (β : Y ≅ Y₁) (γ : Z ≅ Z₁) (f : X ⟶ Y)
(g : Y ⟶ Z) : α.homCongr γ (f ≫ g) = α.homCongr β f ≫ β.homCongr γ g := by simp
/- Porting note (#10618): removed `@[simp]`; simp can prove this -/
theorem homCongr_refl {X Y : C} (f : X ⟶ Y) : (Iso.refl X).homCongr (Iso.refl Y) f = f := by simp
/- Porting note (#10618): removed `@[simp]`; simp can prove this -/
theorem homCongr_trans {X₁ Y₁ X₂ Y₂ X₃ Y₃ : C} (α₁ : X₁ ≅ X₂) (β₁ : Y₁ ≅ Y₂) (α₂ : X₂ ≅ X₃)
(β₂ : Y₂ ≅ Y₃) (f : X₁ ⟶ Y₁) :
(α₁ ≪≫ α₂).homCongr (β₁ ≪≫ β₂) f = (α₁.homCongr β₁).trans (α₂.homCongr β₂) f := by simp
@[simp]
theorem homCongr_symm {X₁ Y₁ X₂ Y₂ : C} (α : X₁ ≅ X₂) (β : Y₁ ≅ Y₂) :
(α.homCongr β).symm = α.symm.homCongr β.symm :=
rfl
/-- If `X` is isomorphic to `X₁` and `Y` is isomorphic to `Y₁`, then
there is a bijection between `X ≅ Y` and `X₁ ≅ Y₁`. -/
@[simps]
def isoCongr {X₁ Y₁ X₂ Y₂ : C} (f : X₁ ≅ X₂) (g : Y₁ ≅ Y₂) : (X₁ ≅ Y₁) ≃ (X₂ ≅ Y₂) where
toFun h := f.symm.trans <| h.trans <| g
invFun h := f.trans <| h.trans <| g.symm
left_inv := by aesop_cat
right_inv := by aesop_cat
/-- If `X₁` is isomorphic to `X₂`, then there is a bijection between `X₁ ≅ Y` and `X₂ ≅ Y`. -/
def isoCongrLeft {X₁ X₂ Y : C} (f : X₁ ≅ X₂) : (X₁ ≅ Y) ≃ (X₂ ≅ Y) :=
isoCongr f (Iso.refl _)
/-- If `Y₁` is isomorphic to `Y₂`, then there is a bijection between `X ≅ Y₁` and `X ≅ Y₂`. -/
def isoCongrRight {X Y₁ Y₂ : C} (g : Y₁ ≅ Y₂) : (X ≅ Y₁) ≃ (X ≅ Y₂) :=
isoCongr (Iso.refl _) g
end Iso
namespace Functor
universe v₁ u₁
variable {C : Type u} [Category.{v} C] {D : Type u₁} [Category.{v₁} D] (F : C ⥤ D)
theorem map_homCongr {X Y X₁ Y₁ : C} (α : X ≅ X₁) (β : Y ≅ Y₁) (f : X ⟶ Y) :
F.map (Iso.homCongr α β f) = Iso.homCongr (F.mapIso α) (F.mapIso β) (F.map f) := by simp
theorem map_isoCongr {X Y X₁ Y₁ : C} (α : X ≅ X₁) (β : Y ≅ Y₁) (f : X ≅ Y) :
F.mapIso (Iso.isoCongr α β f) = Iso.isoCongr (F.mapIso α) (F.mapIso β) (F.mapIso f) := by
ext
simp
end Functor
end CategoryTheory
|
CategoryTheory\IsConnected.lean | /-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta, Jakob von Raumer
-/
import Mathlib.Data.List.Chain
import Mathlib.CategoryTheory.PUnit
import Mathlib.CategoryTheory.Groupoid
import Mathlib.CategoryTheory.Category.ULift
/-!
# Connected category
Define a connected category as a _nonempty_ category for which every functor
to a discrete category is isomorphic to the constant functor.
NB. Some authors include the empty category as connected, we do not.
We instead are interested in categories with exactly one 'connected
component'.
We give some equivalent definitions:
- A nonempty category for which every functor to a discrete category is
constant on objects.
See `any_functor_const_on_obj` and `Connected.of_any_functor_const_on_obj`.
- A nonempty category for which every function `F` for which the presence of a
morphism `f : j₁ ⟶ j₂` implies `F j₁ = F j₂` must be constant everywhere.
See `constant_of_preserves_morphisms` and `Connected.of_constant_of_preserves_morphisms`.
- A nonempty category for which any subset of its elements containing the
default and closed under morphisms is everything.
See `induct_on_objects` and `Connected.of_induct`.
- A nonempty category for which every object is related under the reflexive
transitive closure of the relation "there is a morphism in some direction
from `j₁` to `j₂`".
See `connected_zigzag` and `zigzag_connected`.
- A nonempty category for which for any two objects there is a sequence of
morphisms (some reversed) from one to the other.
See `exists_zigzag'` and `connected_of_zigzag`.
We also prove the result that the functor given by `(X × -)` preserves any
connected limit. That is, any limit of shape `J` where `J` is a connected
category is preserved by the functor `(X × -)`. This appears in `CategoryTheory.Limits.Connected`.
-/
universe v₁ v₂ u₁ u₂
noncomputable section
open CategoryTheory.Category
open Opposite
namespace CategoryTheory
/-- A possibly empty category for which every functor to a discrete category is constant.
-/
class IsPreconnected (J : Type u₁) [Category.{v₁} J] : Prop where
iso_constant :
∀ {α : Type u₁} (F : J ⥤ Discrete α) (j : J), Nonempty (F ≅ (Functor.const J).obj (F.obj j))
attribute [inherit_doc IsPreconnected] IsPreconnected.iso_constant
/-- We define a connected category as a _nonempty_ category for which every
functor to a discrete category is constant.
NB. Some authors include the empty category as connected, we do not.
We instead are interested in categories with exactly one 'connected
component'.
This allows us to show that the functor X ⨯ - preserves connected limits.
See <https://stacks.math.columbia.edu/tag/002S>
-/
class IsConnected (J : Type u₁) [Category.{v₁} J] extends IsPreconnected J : Prop where
[is_nonempty : Nonempty J]
attribute [instance 100] IsConnected.is_nonempty
variable {J : Type u₁} [Category.{v₁} J]
variable {K : Type u₂} [Category.{v₂} K]
namespace IsPreconnected.IsoConstantAux
/-- Implementation detail of `isoConstant`. -/
private def liftToDiscrete {α : Type u₂} (F : J ⥤ Discrete α) : J ⥤ Discrete J where
obj j := have := Nonempty.intro j
Discrete.mk (Function.invFun F.obj (F.obj j))
map {j _} f := have := Nonempty.intro j
⟨⟨congr_arg (Function.invFun F.obj) (Discrete.ext (Discrete.eq_of_hom (F.map f)))⟩⟩
/-- Implementation detail of `isoConstant`. -/
private def factorThroughDiscrete {α : Type u₂} (F : J ⥤ Discrete α) :
liftToDiscrete F ⋙ Discrete.functor F.obj ≅ F :=
NatIso.ofComponents (fun j => eqToIso Function.apply_invFun_apply) (by aesop_cat)
end IsPreconnected.IsoConstantAux
/-- If `J` is connected, any functor `F : J ⥤ Discrete α` is isomorphic to
the constant functor with value `F.obj j` (for any choice of `j`).
-/
def isoConstant [IsPreconnected J] {α : Type u₂} (F : J ⥤ Discrete α) (j : J) :
F ≅ (Functor.const J).obj (F.obj j) :=
(IsPreconnected.IsoConstantAux.factorThroughDiscrete F).symm
≪≫ isoWhiskerRight (IsPreconnected.iso_constant _ j).some _
≪≫ NatIso.ofComponents (fun j' => eqToIso Function.apply_invFun_apply) (by aesop_cat)
/-- If `J` is connected, any functor to a discrete category is constant on objects.
The converse is given in `IsConnected.of_any_functor_const_on_obj`.
-/
theorem any_functor_const_on_obj [IsPreconnected J] {α : Type u₂} (F : J ⥤ Discrete α) (j j' : J) :
F.obj j = F.obj j' := by
ext; exact ((isoConstant F j').hom.app j).down.1
/-- If any functor to a discrete category is constant on objects, J is connected.
The converse of `any_functor_const_on_obj`.
-/
theorem IsPreconnected.of_any_functor_const_on_obj
(h : ∀ {α : Type u₁} (F : J ⥤ Discrete α), ∀ j j' : J, F.obj j = F.obj j') :
IsPreconnected J where
iso_constant := fun F j' => ⟨NatIso.ofComponents fun j => eqToIso (h F j j')⟩
/-- If any functor to a discrete category is constant on objects, J is connected.
The converse of `any_functor_const_on_obj`.
-/
theorem IsConnected.of_any_functor_const_on_obj [Nonempty J]
(h : ∀ {α : Type u₁} (F : J ⥤ Discrete α), ∀ j j' : J, F.obj j = F.obj j') : IsConnected J :=
{ IsPreconnected.of_any_functor_const_on_obj h with }
/-- If `J` is connected, then given any function `F` such that the presence of a
morphism `j₁ ⟶ j₂` implies `F j₁ = F j₂`, we have that `F` is constant.
This can be thought of as a local-to-global property.
The converse is shown in `IsConnected.of_constant_of_preserves_morphisms`
-/
theorem constant_of_preserves_morphisms [IsPreconnected J] {α : Type u₂} (F : J → α)
(h : ∀ (j₁ j₂ : J) (_ : j₁ ⟶ j₂), F j₁ = F j₂) (j j' : J) : F j = F j' := by
simpa using
any_functor_const_on_obj
{ obj := Discrete.mk ∘ F
map := fun f => eqToHom (by ext; exact h _ _ f) }
j j'
/-- `J` is connected if: given any function `F : J → α` which is constant for any
`j₁, j₂` for which there is a morphism `j₁ ⟶ j₂`, then `F` is constant.
This can be thought of as a local-to-global property.
The converse of `constant_of_preserves_morphisms`.
-/
theorem IsPreconnected.of_constant_of_preserves_morphisms
(h : ∀ {α : Type u₁} (F : J → α),
(∀ {j₁ j₂ : J} (_ : j₁ ⟶ j₂), F j₁ = F j₂) → ∀ j j' : J, F j = F j') :
IsPreconnected J :=
IsPreconnected.of_any_functor_const_on_obj fun F =>
h F.obj fun f => by ext; exact Discrete.eq_of_hom (F.map f)
/-- `J` is connected if: given any function `F : J → α` which is constant for any
`j₁, j₂` for which there is a morphism `j₁ ⟶ j₂`, then `F` is constant.
This can be thought of as a local-to-global property.
The converse of `constant_of_preserves_morphisms`.
-/
theorem IsConnected.of_constant_of_preserves_morphisms [Nonempty J]
(h : ∀ {α : Type u₁} (F : J → α),
(∀ {j₁ j₂ : J} (_ : j₁ ⟶ j₂), F j₁ = F j₂) → ∀ j j' : J, F j = F j') :
IsConnected J :=
{ IsPreconnected.of_constant_of_preserves_morphisms h with }
/-- An inductive-like property for the objects of a connected category.
If the set `p` is nonempty, and `p` is closed under morphisms of `J`,
then `p` contains all of `J`.
The converse is given in `IsConnected.of_induct`.
-/
theorem induct_on_objects [IsPreconnected J] (p : Set J) {j₀ : J} (h0 : j₀ ∈ p)
(h1 : ∀ {j₁ j₂ : J} (_ : j₁ ⟶ j₂), j₁ ∈ p ↔ j₂ ∈ p) (j : J) : j ∈ p := by
let aux (j₁ j₂ : J) (f : j₁ ⟶ j₂) := congrArg ULift.up <| (h1 f).eq
injection constant_of_preserves_morphisms (fun k => ULift.up.{u₁} (k ∈ p)) aux j j₀ with i
rwa [i]
/--
If any maximal connected component containing some element j₀ of J is all of J, then J is connected.
The converse of `induct_on_objects`.
-/
theorem IsConnected.of_induct {j₀ : J}
(h : ∀ p : Set J, j₀ ∈ p → (∀ {j₁ j₂ : J} (_ : j₁ ⟶ j₂), j₁ ∈ p ↔ j₂ ∈ p) → ∀ j : J, j ∈ p) :
IsConnected J :=
have := Nonempty.intro j₀
IsConnected.of_constant_of_preserves_morphisms fun {α} F a => by
have w := h { j | F j = F j₀ } rfl (fun {j₁} {j₂} f => by
change F j₁ = F j₀ ↔ F j₂ = F j₀
simp [a f])
intro j j'
rw [w j, w j']
/-- Lifting the universe level of morphisms and objects preserves connectedness. -/
instance [hc : IsConnected J] : IsConnected (ULiftHom.{v₂} (ULift.{u₂} J)) := by
apply IsConnected.of_induct
· rintro p hj₀ h ⟨j⟩
let p' : Set J := {j : J | p ⟨j⟩}
have hj₀' : Classical.choice hc.is_nonempty ∈ p' := by
simp only [p', (eq_self p')]
exact hj₀
apply induct_on_objects p' hj₀' fun f => h ((ULiftHomULiftCategory.equiv J).functor.map f)
/-- Another induction principle for `IsPreconnected J`:
given a type family `Z : J → Sort*` and
a rule for transporting in *both* directions along a morphism in `J`,
we can transport an `x : Z j₀` to a point in `Z j` for any `j`.
-/
theorem isPreconnected_induction [IsPreconnected J] (Z : J → Sort*)
(h₁ : ∀ {j₁ j₂ : J} (_ : j₁ ⟶ j₂), Z j₁ → Z j₂) (h₂ : ∀ {j₁ j₂ : J} (_ : j₁ ⟶ j₂), Z j₂ → Z j₁)
{j₀ : J} (x : Z j₀) (j : J) : Nonempty (Z j) :=
(induct_on_objects { j | Nonempty (Z j) } ⟨x⟩
(fun f => ⟨by rintro ⟨y⟩; exact ⟨h₁ f y⟩, by rintro ⟨y⟩; exact ⟨h₂ f y⟩⟩)
j : _)
/-- If `J` and `K` are equivalent, then if `J` is preconnected then `K` is as well. -/
theorem isPreconnected_of_equivalent {K : Type u₂} [Category.{v₂} K] [IsPreconnected J]
(e : J ≌ K) : IsPreconnected K where
iso_constant F k :=
⟨calc
F ≅ e.inverse ⋙ e.functor ⋙ F := (e.invFunIdAssoc F).symm
_ ≅ e.inverse ⋙ (Functor.const J).obj ((e.functor ⋙ F).obj (e.inverse.obj k)) :=
isoWhiskerLeft e.inverse (isoConstant (e.functor ⋙ F) (e.inverse.obj k))
_ ≅ e.inverse ⋙ (Functor.const J).obj (F.obj k) :=
isoWhiskerLeft _ ((F ⋙ Functor.const J).mapIso (e.counitIso.app k))
_ ≅ (Functor.const K).obj (F.obj k) := NatIso.ofComponents fun X => Iso.refl _⟩
lemma isPreconnected_iff_of_equivalence {K : Type u₂} [Category.{v₂} K] (e : J ≌ K) :
IsPreconnected J ↔ IsPreconnected K :=
⟨fun _ => isPreconnected_of_equivalent e, fun _ => isPreconnected_of_equivalent e.symm⟩
/-- If `J` and `K` are equivalent, then if `J` is connected then `K` is as well. -/
theorem isConnected_of_equivalent {K : Type u₂} [Category.{v₂} K] (e : J ≌ K) [IsConnected J] :
IsConnected K :=
{ is_nonempty := Nonempty.map e.functor.obj (by infer_instance)
toIsPreconnected := isPreconnected_of_equivalent e }
lemma isConnected_iff_of_equivalence {K : Type u₂} [Category.{v₂} K] (e : J ≌ K) :
IsConnected J ↔ IsConnected K :=
⟨fun _ => isConnected_of_equivalent e, fun _ => isConnected_of_equivalent e.symm⟩
/-- If `J` is preconnected, then `Jᵒᵖ` is preconnected as well. -/
instance isPreconnected_op [IsPreconnected J] : IsPreconnected Jᵒᵖ where
iso_constant := fun {α} F X =>
⟨NatIso.ofComponents fun Y =>
eqToIso (Discrete.ext (Discrete.eq_of_hom ((Nonempty.some
(IsPreconnected.iso_constant (F.rightOp ⋙ (Discrete.opposite α).functor) (unop X))).app
(unop Y)).hom))⟩
/-- If `J` is connected, then `Jᵒᵖ` is connected as well. -/
instance isConnected_op [IsConnected J] : IsConnected Jᵒᵖ where
is_nonempty := Nonempty.intro (op (Classical.arbitrary J))
theorem isPreconnected_of_isPreconnected_op [IsPreconnected Jᵒᵖ] : IsPreconnected J :=
isPreconnected_of_equivalent (opOpEquivalence J)
theorem isConnected_of_isConnected_op [IsConnected Jᵒᵖ] : IsConnected J :=
isConnected_of_equivalent (opOpEquivalence J)
/-- j₁ and j₂ are related by `Zag` if there is a morphism between them. -/
def Zag (j₁ j₂ : J) : Prop :=
Nonempty (j₁ ⟶ j₂) ∨ Nonempty (j₂ ⟶ j₁)
theorem Zag.refl (X : J) : Zag X X := Or.inl ⟨𝟙 _⟩
theorem zag_symmetric : Symmetric (@Zag J _) := fun _ _ h => h.symm
theorem Zag.symm {j₁ j₂ : J} (h : Zag j₁ j₂) : Zag j₂ j₁ := zag_symmetric h
theorem Zag.of_hom {j₁ j₂ : J} (f : j₁ ⟶ j₂) : Zag j₁ j₂ := Or.inl ⟨f⟩
theorem Zag.of_inv {j₁ j₂ : J} (f : j₂ ⟶ j₁) : Zag j₁ j₂ := Or.inr ⟨f⟩
/-- `j₁` and `j₂` are related by `Zigzag` if there is a chain of
morphisms from `j₁` to `j₂`, with backward morphisms allowed.
-/
def Zigzag : J → J → Prop :=
Relation.ReflTransGen Zag
theorem zigzag_symmetric : Symmetric (@Zigzag J _) :=
Relation.ReflTransGen.symmetric zag_symmetric
theorem zigzag_equivalence : _root_.Equivalence (@Zigzag J _) :=
_root_.Equivalence.mk Relation.reflexive_reflTransGen (fun h => zigzag_symmetric h)
(fun h g => Relation.transitive_reflTransGen h g)
theorem Zigzag.refl (X : J) : Zigzag X X := zigzag_equivalence.refl _
theorem Zigzag.symm {j₁ j₂ : J} (h : Zigzag j₁ j₂) : Zigzag j₂ j₁ := zigzag_symmetric h
theorem Zigzag.trans {j₁ j₂ j₃ : J} (h₁ : Zigzag j₁ j₂) (h₂ : Zigzag j₂ j₃) : Zigzag j₁ j₃ :=
zigzag_equivalence.trans h₁ h₂
theorem Zigzag.of_zag {j₁ j₂ : J} (h : Zag j₁ j₂) : Zigzag j₁ j₂ :=
Relation.ReflTransGen.single h
theorem Zigzag.of_hom {j₁ j₂ : J} (f : j₁ ⟶ j₂) : Zigzag j₁ j₂ :=
of_zag (Zag.of_hom f)
theorem Zigzag.of_inv {j₁ j₂ : J} (f : j₂ ⟶ j₁) : Zigzag j₁ j₂ :=
of_zag (Zag.of_inv f)
theorem Zigzag.of_zag_trans {j₁ j₂ j₃ : J} (h₁ : Zag j₁ j₂) (h₂ : Zag j₂ j₃) : Zigzag j₁ j₃ :=
trans (of_zag h₁) (of_zag h₂)
theorem Zigzag.of_hom_hom {j₁ j₂ j₃ : J} (f₁₂ : j₁ ⟶ j₂) (f₂₃ : j₂ ⟶ j₃) : Zigzag j₁ j₃ :=
(of_hom f₁₂).trans (of_hom f₂₃)
theorem Zigzag.of_hom_inv {j₁ j₂ j₃ : J} (f₁₂ : j₁ ⟶ j₂) (f₃₂ : j₃ ⟶ j₂) : Zigzag j₁ j₃ :=
(of_hom f₁₂).trans (of_inv f₃₂)
theorem Zigzag.of_inv_hom {j₁ j₂ j₃ : J} (f₂₁ : j₂ ⟶ j₁) (f₂₃ : j₂ ⟶ j₃) : Zigzag j₁ j₃ :=
(of_inv f₂₁).trans (of_hom f₂₃)
theorem Zigzag.of_inv_inv {j₁ j₂ j₃ : J} (f₂₁ : j₂ ⟶ j₁) (f₃₂ : j₃ ⟶ j₂) : Zigzag j₁ j₃ :=
(of_inv f₂₁).trans (of_inv f₃₂)
/-- The setoid given by the equivalence relation `Zigzag`. A quotient for this
setoid is a connected component of the category.
-/
def Zigzag.setoid (J : Type u₂) [Category.{v₁} J] : Setoid J where
r := Zigzag
iseqv := zigzag_equivalence
/-- If there is a zigzag from `j₁` to `j₂`, then there is a zigzag from `F j₁` to
`F j₂` as long as `F` is a functor.
-/
theorem zigzag_obj_of_zigzag (F : J ⥤ K) {j₁ j₂ : J} (h : Zigzag j₁ j₂) :
Zigzag (F.obj j₁) (F.obj j₂) :=
h.lift _ fun _ _ => Or.imp (Nonempty.map fun f => F.map f) (Nonempty.map fun f => F.map f)
-- TODO: figure out the right way to generalise this to `Zigzag`.
theorem zag_of_zag_obj (F : J ⥤ K) [F.Full] {j₁ j₂ : J} (h : Zag (F.obj j₁) (F.obj j₂)) :
Zag j₁ j₂ :=
Or.imp (Nonempty.map F.preimage) (Nonempty.map F.preimage) h
/-- Any equivalence relation containing (⟶) holds for all pairs of a connected category. -/
theorem equiv_relation [IsPreconnected J] (r : J → J → Prop) (hr : _root_.Equivalence r)
(h : ∀ {j₁ j₂ : J} (_ : j₁ ⟶ j₂), r j₁ j₂) : ∀ j₁ j₂ : J, r j₁ j₂ := by
intros j₁ j₂
have z : ∀ j : J, r j₁ j :=
induct_on_objects {k | r j₁ k} (hr.1 j₁)
fun f => ⟨fun t => hr.3 t (h f), fun t => hr.3 t (hr.2 (h f))⟩
exact z j₂
/-- In a connected category, any two objects are related by `Zigzag`. -/
theorem isPreconnected_zigzag [IsPreconnected J] (j₁ j₂ : J) : Zigzag j₁ j₂ :=
equiv_relation _ zigzag_equivalence
(fun f => Relation.ReflTransGen.single (Or.inl (Nonempty.intro f))) _ _
@[deprecated (since := "2024-02-19")] alias isConnected_zigzag := isPreconnected_zigzag
theorem zigzag_isPreconnected (h : ∀ j₁ j₂ : J, Zigzag j₁ j₂) : IsPreconnected J := by
apply IsPreconnected.of_constant_of_preserves_morphisms
intro α F hF j j'
specialize h j j'
induction' h with j₁ j₂ _ hj ih
· rfl
· rw [ih]
rcases hj with (⟨⟨hj⟩⟩|⟨⟨hj⟩⟩)
exacts [hF hj, (hF hj).symm]
/-- If any two objects in a nonempty category are related by `Zigzag`, the category is connected.
-/
theorem zigzag_isConnected [Nonempty J] (h : ∀ j₁ j₂ : J, Zigzag j₁ j₂) : IsConnected J :=
{ zigzag_isPreconnected h with }
theorem exists_zigzag' [IsConnected J] (j₁ j₂ : J) :
∃ l, List.Chain Zag j₁ l ∧ List.getLast (j₁ :: l) (List.cons_ne_nil _ _) = j₂ :=
List.exists_chain_of_relationReflTransGen (isPreconnected_zigzag _ _)
/-- If any two objects in a nonempty category are linked by a sequence of (potentially reversed)
morphisms, then J is connected.
The converse of `exists_zigzag'`.
-/
theorem isPreconnected_of_zigzag (h : ∀ j₁ j₂ : J, ∃ l,
List.Chain Zag j₁ l ∧ List.getLast (j₁ :: l) (List.cons_ne_nil _ _) = j₂) :
IsPreconnected J := by
apply zigzag_isPreconnected
intro j₁ j₂
rcases h j₁ j₂ with ⟨l, hl₁, hl₂⟩
apply List.relationReflTransGen_of_exists_chain l hl₁ hl₂
/-- If any two objects in a nonempty category are linked by a sequence of (potentially reversed)
morphisms, then J is connected.
The converse of `exists_zigzag'`.
-/
theorem isConnected_of_zigzag [Nonempty J] (h : ∀ j₁ j₂ : J, ∃ l,
List.Chain Zag j₁ l ∧ List.getLast (j₁ :: l) (List.cons_ne_nil _ _) = j₂) :
IsConnected J :=
{ isPreconnected_of_zigzag h with }
/-- If `Discrete α` is connected, then `α` is (type-)equivalent to `PUnit`. -/
def discreteIsConnectedEquivPUnit {α : Type u₁} [IsConnected (Discrete α)] : α ≃ PUnit :=
Discrete.equivOfEquivalence.{u₁, u₁}
{ functor := Functor.star (Discrete α)
inverse := Discrete.functor fun _ => Classical.arbitrary _
unitIso := isoConstant _ (Classical.arbitrary _)
counitIso := Functor.punitExt _ _ }
variable {C : Type u₂} [Category.{u₁} C]
/-- For objects `X Y : C`, any natural transformation `α : const X ⟶ const Y` from a connected
category must be constant.
This is the key property of connected categories which we use to establish properties about limits.
-/
theorem nat_trans_from_is_connected [IsPreconnected J] {X Y : C}
(α : (Functor.const J).obj X ⟶ (Functor.const J).obj Y) :
∀ j j' : J, α.app j = (α.app j' : X ⟶ Y) :=
@constant_of_preserves_morphisms _ _ _ (X ⟶ Y) (fun j => α.app j) fun _ _ f => by
have := α.naturality f
erw [id_comp, comp_id] at this
exact this.symm
instance [IsConnected J] : (Functor.const J : C ⥤ J ⥤ C).Full where
map_surjective f := ⟨f.app (Classical.arbitrary J), by
ext j
apply nat_trans_from_is_connected f (Classical.arbitrary J) j⟩
theorem nonempty_hom_of_preconnected_groupoid {G} [Groupoid G] [IsPreconnected G] :
∀ x y : G, Nonempty (x ⟶ y) := by
refine equiv_relation _ ?_ fun {j₁ j₂} => Nonempty.intro
exact
⟨fun j => ⟨𝟙 _⟩,
fun {j₁ j₂} => Nonempty.map fun f => inv f,
fun {_ _ _} => Nonempty.map2 (· ≫ ·)⟩
attribute [instance] nonempty_hom_of_preconnected_groupoid
@[deprecated (since := "2024-02-19")]
alias nonempty_hom_of_connected_groupoid := nonempty_hom_of_preconnected_groupoid
end CategoryTheory
|
CategoryTheory\Iso.lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Tim Baumann, Stephen Morgan, Scott Morrison, Floris van Doorn
-/
import Mathlib.Tactic.CategoryTheory.Reassoc
/-!
# Isomorphisms
This file defines isomorphisms between objects of a category.
## Main definitions
- `structure Iso` : a bundled isomorphism between two objects of a category;
- `class IsIso` : an unbundled version of `iso`;
note that `IsIso f` is a `Prop`, and only asserts the existence of an inverse.
Of course, this inverse is unique, so it doesn't cost us much to use choice to retrieve it.
- `inv f`, for the inverse of a morphism with `[IsIso f]`
- `asIso` : convert from `IsIso` to `Iso` (noncomputable);
- `of_iso` : convert from `Iso` to `IsIso`;
- standard operations on isomorphisms (composition, inverse etc)
## Notations
- `X ≅ Y` : same as `Iso X Y`;
- `α ≪≫ β` : composition of two isomorphisms; it is called `Iso.trans`
## Tags
category, category theory, isomorphism
-/
universe v u
-- morphism levels before object levels. See note [CategoryTheory universes].
namespace CategoryTheory
open Category
/-- An isomorphism (a.k.a. an invertible morphism) between two objects of a category.
The inverse morphism is bundled.
See also `CategoryTheory.Core` for the category with the same objects and isomorphisms playing
the role of morphisms.
See <https://stacks.math.columbia.edu/tag/0017>.
-/
structure Iso {C : Type u} [Category.{v} C] (X Y : C) where
/-- The forward direction of an isomorphism. -/
hom : X ⟶ Y
/-- The backwards direction of an isomorphism. -/
inv : Y ⟶ X
/-- Composition of the two directions of an isomorphism is the identity on the source. -/
hom_inv_id : hom ≫ inv = 𝟙 X := by aesop_cat
/-- Composition of the two directions of an isomorphism in reverse order
is the identity on the target. -/
inv_hom_id : inv ≫ hom = 𝟙 Y := by aesop_cat
attribute [reassoc (attr := simp)] Iso.hom_inv_id Iso.inv_hom_id
/-- Notation for an isomorphism in a category. -/
infixr:10 " ≅ " => Iso -- type as \cong or \iso
variable {C : Type u} [Category.{v} C] {X Y Z : C}
namespace Iso
@[ext]
theorem ext ⦃α β : X ≅ Y⦄ (w : α.hom = β.hom) : α = β :=
suffices α.inv = β.inv by
cases α
cases β
cases w
cases this
rfl
calc
α.inv = α.inv ≫ β.hom ≫ β.inv := by rw [Iso.hom_inv_id, Category.comp_id]
_ = (α.inv ≫ α.hom) ≫ β.inv := by rw [Category.assoc, ← w]
_ = β.inv := by rw [Iso.inv_hom_id, Category.id_comp]
/-- Inverse isomorphism. -/
@[symm]
def symm (I : X ≅ Y) : Y ≅ X where
hom := I.inv
inv := I.hom
@[simp]
theorem symm_hom (α : X ≅ Y) : α.symm.hom = α.inv :=
rfl
@[simp]
theorem symm_inv (α : X ≅ Y) : α.symm.inv = α.hom :=
rfl
@[simp]
theorem symm_mk {X Y : C} (hom : X ⟶ Y) (inv : Y ⟶ X) (hom_inv_id) (inv_hom_id) :
Iso.symm { hom, inv, hom_inv_id := hom_inv_id, inv_hom_id := inv_hom_id } =
{ hom := inv, inv := hom, hom_inv_id := inv_hom_id, inv_hom_id := hom_inv_id } :=
rfl
@[simp]
theorem symm_symm_eq {X Y : C} (α : X ≅ Y) : α.symm.symm = α := by cases α; rfl
@[simp]
theorem symm_eq_iff {X Y : C} {α β : X ≅ Y} : α.symm = β.symm ↔ α = β :=
⟨fun h => symm_symm_eq α ▸ symm_symm_eq β ▸ congr_arg symm h, congr_arg symm⟩
theorem nonempty_iso_symm (X Y : C) : Nonempty (X ≅ Y) ↔ Nonempty (Y ≅ X) :=
⟨fun h => ⟨h.some.symm⟩, fun h => ⟨h.some.symm⟩⟩
/-- Identity isomorphism. -/
@[refl, simps]
def refl (X : C) : X ≅ X where
hom := 𝟙 X
inv := 𝟙 X
instance : Inhabited (X ≅ X) := ⟨Iso.refl X⟩
theorem nonempty_iso_refl (X : C) : Nonempty (X ≅ X) := ⟨default⟩
@[simp]
theorem refl_symm (X : C) : (Iso.refl X).symm = Iso.refl X := rfl
-- Porting note: It seems that the trans `trans` attribute isn't working properly
-- in this case, so we have to manually add a `Trans` instance (with a `simps` tag).
/-- Composition of two isomorphisms -/
@[trans, simps]
def trans (α : X ≅ Y) (β : Y ≅ Z) : X ≅ Z where
hom := α.hom ≫ β.hom
inv := β.inv ≫ α.inv
@[simps]
instance instTransIso : Trans (α := C) (· ≅ ·) (· ≅ ·) (· ≅ ·) where
trans := trans
/-- Notation for composition of isomorphisms. -/
infixr:80 " ≪≫ " => Iso.trans -- type as `\ll \gg`.
@[simp]
theorem trans_mk {X Y Z : C} (hom : X ⟶ Y) (inv : Y ⟶ X) (hom_inv_id) (inv_hom_id)
(hom' : Y ⟶ Z) (inv' : Z ⟶ Y) (hom_inv_id') (inv_hom_id') (hom_inv_id'') (inv_hom_id'') :
Iso.trans ⟨hom, inv, hom_inv_id, inv_hom_id⟩ ⟨hom', inv', hom_inv_id', inv_hom_id'⟩ =
⟨hom ≫ hom', inv' ≫ inv, hom_inv_id'', inv_hom_id''⟩ :=
rfl
@[simp]
theorem trans_symm (α : X ≅ Y) (β : Y ≅ Z) : (α ≪≫ β).symm = β.symm ≪≫ α.symm :=
rfl
@[simp]
theorem trans_assoc {Z' : C} (α : X ≅ Y) (β : Y ≅ Z) (γ : Z ≅ Z') :
(α ≪≫ β) ≪≫ γ = α ≪≫ β ≪≫ γ := by
ext; simp only [trans_hom, Category.assoc]
@[simp]
theorem refl_trans (α : X ≅ Y) : Iso.refl X ≪≫ α = α := by ext; apply Category.id_comp
@[simp]
theorem trans_refl (α : X ≅ Y) : α ≪≫ Iso.refl Y = α := by ext; apply Category.comp_id
@[simp]
theorem symm_self_id (α : X ≅ Y) : α.symm ≪≫ α = Iso.refl Y :=
ext α.inv_hom_id
@[simp]
theorem self_symm_id (α : X ≅ Y) : α ≪≫ α.symm = Iso.refl X :=
ext α.hom_inv_id
@[simp]
theorem symm_self_id_assoc (α : X ≅ Y) (β : Y ≅ Z) : α.symm ≪≫ α ≪≫ β = β := by
rw [← trans_assoc, symm_self_id, refl_trans]
@[simp]
theorem self_symm_id_assoc (α : X ≅ Y) (β : X ≅ Z) : α ≪≫ α.symm ≪≫ β = β := by
rw [← trans_assoc, self_symm_id, refl_trans]
theorem inv_comp_eq (α : X ≅ Y) {f : X ⟶ Z} {g : Y ⟶ Z} : α.inv ≫ f = g ↔ f = α.hom ≫ g :=
⟨fun H => by simp [H.symm], fun H => by simp [H]⟩
theorem eq_inv_comp (α : X ≅ Y) {f : X ⟶ Z} {g : Y ⟶ Z} : g = α.inv ≫ f ↔ α.hom ≫ g = f :=
(inv_comp_eq α.symm).symm
theorem comp_inv_eq (α : X ≅ Y) {f : Z ⟶ Y} {g : Z ⟶ X} : f ≫ α.inv = g ↔ f = g ≫ α.hom :=
⟨fun H => by simp [H.symm], fun H => by simp [H]⟩
theorem eq_comp_inv (α : X ≅ Y) {f : Z ⟶ Y} {g : Z ⟶ X} : g = f ≫ α.inv ↔ g ≫ α.hom = f :=
(comp_inv_eq α.symm).symm
theorem inv_eq_inv (f g : X ≅ Y) : f.inv = g.inv ↔ f.hom = g.hom :=
have : ∀ {X Y : C} (f g : X ≅ Y), f.hom = g.hom → f.inv = g.inv := fun f g h => by rw [ext h]
⟨this f.symm g.symm, this f g⟩
theorem hom_comp_eq_id (α : X ≅ Y) {f : Y ⟶ X} : α.hom ≫ f = 𝟙 X ↔ f = α.inv := by
rw [← eq_inv_comp, comp_id]
theorem comp_hom_eq_id (α : X ≅ Y) {f : Y ⟶ X} : f ≫ α.hom = 𝟙 Y ↔ f = α.inv := by
rw [← eq_comp_inv, id_comp]
theorem inv_comp_eq_id (α : X ≅ Y) {f : X ⟶ Y} : α.inv ≫ f = 𝟙 Y ↔ f = α.hom :=
hom_comp_eq_id α.symm
theorem comp_inv_eq_id (α : X ≅ Y) {f : X ⟶ Y} : f ≫ α.inv = 𝟙 X ↔ f = α.hom :=
comp_hom_eq_id α.symm
theorem hom_eq_inv (α : X ≅ Y) (β : Y ≅ X) : α.hom = β.inv ↔ β.hom = α.inv := by
erw [inv_eq_inv α.symm β, eq_comm]
rfl
/-- The bijection `(Z ⟶ X) ≃ (Z ⟶ Y)` induced by `α : X ≅ Y`. -/
@[simps]
def homToEquiv (α : X ≅ Y) {Z : C} : (Z ⟶ X) ≃ (Z ⟶ Y) where
toFun f := f ≫ α.hom
invFun g := g ≫ α.inv
left_inv := by aesop_cat
right_inv := by aesop_cat
/-- The bijection `(X ⟶ Z) ≃ (Y ⟶ Z)` induced by `α : X ≅ Y`. -/
@[simps]
def homFromEquiv (α : X ≅ Y) {Z : C} : (X ⟶ Z) ≃ (Y ⟶ Z) where
toFun f := α.inv ≫ f
invFun g := α.hom ≫ g
left_inv := by aesop_cat
right_inv := by aesop_cat
end Iso
/-- `IsIso` typeclass expressing that a morphism is invertible. -/
class IsIso (f : X ⟶ Y) : Prop where
/-- The existence of an inverse morphism. -/
out : ∃ inv : Y ⟶ X, f ≫ inv = 𝟙 X ∧ inv ≫ f = 𝟙 Y
/-- The inverse of a morphism `f` when we have `[IsIso f]`.
-/
noncomputable def inv (f : X ⟶ Y) [I : IsIso f] : Y ⟶ X :=
Classical.choose I.1
namespace IsIso
@[simp]
theorem hom_inv_id (f : X ⟶ Y) [I : IsIso f] : f ≫ inv f = 𝟙 X :=
(Classical.choose_spec I.1).left
@[simp]
theorem inv_hom_id (f : X ⟶ Y) [I : IsIso f] : inv f ≫ f = 𝟙 Y :=
(Classical.choose_spec I.1).right
-- FIXME putting @[reassoc] on the `hom_inv_id` above somehow unfolds `inv`
-- This happens even if we make `inv` irreducible!
-- I don't understand how this is happening: it is likely a bug.
-- attribute [reassoc] hom_inv_id inv_hom_id
-- #print hom_inv_id_assoc
-- theorem CategoryTheory.IsIso.hom_inv_id_assoc {X Y : C} (f : X ⟶ Y) [I : IsIso f]
-- {Z : C} (h : X ⟶ Z),
-- f ≫ Classical.choose (_ : Exists fun inv ↦ f ≫ inv = 𝟙 X ∧ inv ≫ f = 𝟙 Y) ≫ h = h := ...
@[simp]
theorem hom_inv_id_assoc (f : X ⟶ Y) [I : IsIso f] {Z} (g : X ⟶ Z) : f ≫ inv f ≫ g = g := by
simp [← Category.assoc]
@[simp]
theorem inv_hom_id_assoc (f : X ⟶ Y) [I : IsIso f] {Z} (g : Y ⟶ Z) : inv f ≫ f ≫ g = g := by
simp [← Category.assoc]
end IsIso
lemma Iso.isIso_hom (e : X ≅ Y) : IsIso e.hom :=
⟨e.inv, by simp, by simp⟩
lemma Iso.isIso_inv (e : X ≅ Y) : IsIso e.inv := e.symm.isIso_hom
attribute [instance] Iso.isIso_hom Iso.isIso_inv
open IsIso
/-- Reinterpret a morphism `f` with an `IsIso f` instance as an `Iso`. -/
noncomputable def asIso (f : X ⟶ Y) [IsIso f] : X ≅ Y :=
⟨f, inv f, hom_inv_id f, inv_hom_id f⟩
-- Porting note: the `IsIso f` argument had been instance implicit,
-- but we've changed it to implicit as a `rw` in `Mathlib.CategoryTheory.Closed.Functor`
-- was failing to generate it by typeclass search.
@[simp]
theorem asIso_hom (f : X ⟶ Y) {_ : IsIso f} : (asIso f).hom = f :=
rfl
-- Porting note: the `IsIso f` argument had been instance implicit,
-- but we've changed it to implicit as a `rw` in `Mathlib.CategoryTheory.Closed.Functor`
-- was failing to generate it by typeclass search.
@[simp]
theorem asIso_inv (f : X ⟶ Y) {_ : IsIso f} : (asIso f).inv = inv f :=
rfl
namespace IsIso
-- see Note [lower instance priority]
instance (priority := 100) epi_of_iso (f : X ⟶ Y) [IsIso f] : Epi f where
left_cancellation g h w := by
rw [← IsIso.inv_hom_id_assoc f g, w, IsIso.inv_hom_id_assoc f h]
-- see Note [lower instance priority]
instance (priority := 100) mono_of_iso (f : X ⟶ Y) [IsIso f] : Mono f where
right_cancellation g h w := by
rw [← Category.comp_id g, ← Category.comp_id h, ← IsIso.hom_inv_id f,
← Category.assoc, w, ← Category.assoc]
-- Porting note: `@[ext]` used to accept lemmas like this. Now we add an aesop rule
@[aesop apply safe (rule_sets := [CategoryTheory])]
theorem inv_eq_of_hom_inv_id {f : X ⟶ Y} [IsIso f] {g : Y ⟶ X} (hom_inv_id : f ≫ g = 𝟙 X) :
inv f = g := by
apply (cancel_epi f).mp
simp [hom_inv_id]
theorem inv_eq_of_inv_hom_id {f : X ⟶ Y} [IsIso f] {g : Y ⟶ X} (inv_hom_id : g ≫ f = 𝟙 Y) :
inv f = g := by
apply (cancel_mono f).mp
simp [inv_hom_id]
-- Porting note: `@[ext]` used to accept lemmas like this.
@[aesop apply safe (rule_sets := [CategoryTheory])]
theorem eq_inv_of_hom_inv_id {f : X ⟶ Y} [IsIso f] {g : Y ⟶ X} (hom_inv_id : f ≫ g = 𝟙 X) :
g = inv f :=
(inv_eq_of_hom_inv_id hom_inv_id).symm
theorem eq_inv_of_inv_hom_id {f : X ⟶ Y} [IsIso f] {g : Y ⟶ X} (inv_hom_id : g ≫ f = 𝟙 Y) :
g = inv f :=
(inv_eq_of_inv_hom_id inv_hom_id).symm
instance id (X : C) : IsIso (𝟙 X) := ⟨⟨𝟙 X, by simp⟩⟩
@[deprecated (since := "2024-05-15")] alias of_iso := CategoryTheory.Iso.isIso_hom
@[deprecated (since := "2024-05-15")] alias of_iso_inv := CategoryTheory.Iso.isIso_inv
variable {f g : X ⟶ Y} {h : Y ⟶ Z}
instance inv_isIso [IsIso f] : IsIso (inv f) :=
(asIso f).isIso_inv
/- The following instance has lower priority for the following reason:
Suppose we are given `f : X ≅ Y` with `X Y : Type u`.
Without the lower priority, typeclass inference cannot deduce `IsIso f.hom`
because `f.hom` is defeq to `(fun x ↦ x) ≫ f.hom`, triggering a loop. -/
instance (priority := 900) comp_isIso [IsIso f] [IsIso h] : IsIso (f ≫ h) :=
(asIso f ≪≫ asIso h).isIso_hom
@[simp]
theorem inv_id : inv (𝟙 X) = 𝟙 X := by
apply inv_eq_of_hom_inv_id
simp
@[simp]
theorem inv_comp [IsIso f] [IsIso h] : inv (f ≫ h) = inv h ≫ inv f := by
apply inv_eq_of_hom_inv_id
simp
@[simp]
theorem inv_inv [IsIso f] : inv (inv f) = f := by
apply inv_eq_of_hom_inv_id
simp
@[simp]
theorem Iso.inv_inv (f : X ≅ Y) : inv f.inv = f.hom := by
apply inv_eq_of_hom_inv_id
simp
@[simp]
theorem Iso.inv_hom (f : X ≅ Y) : inv f.hom = f.inv := by
apply inv_eq_of_hom_inv_id
simp
@[simp]
theorem inv_comp_eq (α : X ⟶ Y) [IsIso α] {f : X ⟶ Z} {g : Y ⟶ Z} : inv α ≫ f = g ↔ f = α ≫ g :=
(asIso α).inv_comp_eq
@[simp]
theorem eq_inv_comp (α : X ⟶ Y) [IsIso α] {f : X ⟶ Z} {g : Y ⟶ Z} : g = inv α ≫ f ↔ α ≫ g = f :=
(asIso α).eq_inv_comp
@[simp]
theorem comp_inv_eq (α : X ⟶ Y) [IsIso α] {f : Z ⟶ Y} {g : Z ⟶ X} : f ≫ inv α = g ↔ f = g ≫ α :=
(asIso α).comp_inv_eq
@[simp]
theorem eq_comp_inv (α : X ⟶ Y) [IsIso α] {f : Z ⟶ Y} {g : Z ⟶ X} : g = f ≫ inv α ↔ g ≫ α = f :=
(asIso α).eq_comp_inv
theorem of_isIso_comp_left {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [IsIso f] [IsIso (f ≫ g)] :
IsIso g := by
rw [← id_comp g, ← inv_hom_id f, assoc]
infer_instance
theorem of_isIso_comp_right {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) [IsIso g] [IsIso (f ≫ g)] :
IsIso f := by
rw [← comp_id f, ← hom_inv_id g, ← assoc]
infer_instance
theorem of_isIso_fac_left {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} {h : X ⟶ Z} [IsIso f]
[hh : IsIso h] (w : f ≫ g = h) : IsIso g := by
rw [← w] at hh
haveI := hh
exact of_isIso_comp_left f g
theorem of_isIso_fac_right {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} {h : X ⟶ Z} [IsIso g]
[hh : IsIso h] (w : f ≫ g = h) : IsIso f := by
rw [← w] at hh
haveI := hh
exact of_isIso_comp_right f g
end IsIso
open IsIso
theorem eq_of_inv_eq_inv {f g : X ⟶ Y} [IsIso f] [IsIso g] (p : inv f = inv g) : f = g := by
apply (cancel_epi (inv f)).1
erw [inv_hom_id, p, inv_hom_id]
theorem IsIso.inv_eq_inv {f g : X ⟶ Y} [IsIso f] [IsIso g] : inv f = inv g ↔ f = g :=
Iso.inv_eq_inv (asIso f) (asIso g)
theorem hom_comp_eq_id (g : X ⟶ Y) [IsIso g] {f : Y ⟶ X} : g ≫ f = 𝟙 X ↔ f = inv g :=
(asIso g).hom_comp_eq_id
theorem comp_hom_eq_id (g : X ⟶ Y) [IsIso g] {f : Y ⟶ X} : f ≫ g = 𝟙 Y ↔ f = inv g :=
(asIso g).comp_hom_eq_id
theorem inv_comp_eq_id (g : X ⟶ Y) [IsIso g] {f : X ⟶ Y} : inv g ≫ f = 𝟙 Y ↔ f = g :=
(asIso g).inv_comp_eq_id
theorem comp_inv_eq_id (g : X ⟶ Y) [IsIso g] {f : X ⟶ Y} : f ≫ inv g = 𝟙 X ↔ f = g :=
(asIso g).comp_inv_eq_id
theorem isIso_of_hom_comp_eq_id (g : X ⟶ Y) [IsIso g] {f : Y ⟶ X} (h : g ≫ f = 𝟙 X) : IsIso f := by
rw [(hom_comp_eq_id _).mp h]
infer_instance
theorem isIso_of_comp_hom_eq_id (g : X ⟶ Y) [IsIso g] {f : Y ⟶ X} (h : f ≫ g = 𝟙 Y) : IsIso f := by
rw [(comp_hom_eq_id _).mp h]
infer_instance
namespace Iso
-- Porting note: `@[ext]` used to accept lemmas like this.
@[aesop apply safe (rule_sets := [CategoryTheory])]
theorem inv_ext {f : X ≅ Y} {g : Y ⟶ X} (hom_inv_id : f.hom ≫ g = 𝟙 X) : f.inv = g :=
((hom_comp_eq_id f).1 hom_inv_id).symm
-- Porting note: `@[ext]` used to accept lemmas like this.
@[aesop apply safe (rule_sets := [CategoryTheory])]
theorem inv_ext' {f : X ≅ Y} {g : Y ⟶ X} (hom_inv_id : f.hom ≫ g = 𝟙 X) : g = f.inv :=
(hom_comp_eq_id f).1 hom_inv_id
/-!
All these cancellation lemmas can be solved by `simp [cancel_mono]` (or `simp [cancel_epi]`),
but with the current design `cancel_mono` is not a good `simp` lemma,
because it generates a typeclass search.
When we can see syntactically that a morphism is a `mono` or an `epi`
because it came from an isomorphism, it's fine to do the cancellation via `simp`.
In the longer term, it might be worth exploring making `mono` and `epi` structures,
rather than typeclasses, with coercions back to `X ⟶ Y`.
Presumably we could write `X ↪ Y` and `X ↠ Y`.
-/
@[simp]
theorem cancel_iso_hom_left {X Y Z : C} (f : X ≅ Y) (g g' : Y ⟶ Z) :
f.hom ≫ g = f.hom ≫ g' ↔ g = g' := by
simp only [cancel_epi]
@[simp]
theorem cancel_iso_inv_left {X Y Z : C} (f : Y ≅ X) (g g' : Y ⟶ Z) :
f.inv ≫ g = f.inv ≫ g' ↔ g = g' := by
simp only [cancel_epi]
@[simp]
theorem cancel_iso_hom_right {X Y Z : C} (f f' : X ⟶ Y) (g : Y ≅ Z) :
f ≫ g.hom = f' ≫ g.hom ↔ f = f' := by
simp only [cancel_mono]
@[simp]
theorem cancel_iso_inv_right {X Y Z : C} (f f' : X ⟶ Y) (g : Z ≅ Y) :
f ≫ g.inv = f' ≫ g.inv ↔ f = f' := by
simp only [cancel_mono]
/-
Unfortunately cancelling an isomorphism from the right of a chain of compositions is awkward.
We would need separate lemmas for each chain length (worse: for each pair of chain lengths).
We provide two more lemmas, for case of three morphisms, because this actually comes up in practice,
but then stop.
-/
@[simp]
theorem cancel_iso_hom_right_assoc {W X X' Y Z : C} (f : W ⟶ X) (g : X ⟶ Y) (f' : W ⟶ X')
(g' : X' ⟶ Y) (h : Y ≅ Z) : f ≫ g ≫ h.hom = f' ≫ g' ≫ h.hom ↔ f ≫ g = f' ≫ g' := by
simp only [← Category.assoc, cancel_mono]
@[simp]
theorem cancel_iso_inv_right_assoc {W X X' Y Z : C} (f : W ⟶ X) (g : X ⟶ Y) (f' : W ⟶ X')
(g' : X' ⟶ Y) (h : Z ≅ Y) : f ≫ g ≫ h.inv = f' ≫ g' ≫ h.inv ↔ f ≫ g = f' ≫ g' := by
simp only [← Category.assoc, cancel_mono]
section
variable {D E : Type*} [Category D] [Category E] {X Y : C} (e : X ≅ Y)
@[reassoc (attr := simp)]
lemma map_hom_inv_id (F : C ⥤ D) :
F.map e.hom ≫ F.map e.inv = 𝟙 _ := by
rw [← F.map_comp, e.hom_inv_id, F.map_id]
@[reassoc (attr := simp)]
lemma map_inv_hom_id (F : C ⥤ D) :
F.map e.inv ≫ F.map e.hom = 𝟙 _ := by
rw [← F.map_comp, e.inv_hom_id, F.map_id]
end
end Iso
namespace Functor
universe u₁ v₁ u₂ v₂
variable {D : Type u₂}
variable [Category.{v₂} D]
/-- A functor `F : C ⥤ D` sends isomorphisms `i : X ≅ Y` to isomorphisms `F.obj X ≅ F.obj Y` -/
@[simps]
def mapIso (F : C ⥤ D) {X Y : C} (i : X ≅ Y) : F.obj X ≅ F.obj Y where
hom := F.map i.hom
inv := F.map i.inv
@[simp]
theorem mapIso_symm (F : C ⥤ D) {X Y : C} (i : X ≅ Y) : F.mapIso i.symm = (F.mapIso i).symm :=
rfl
@[simp]
theorem mapIso_trans (F : C ⥤ D) {X Y Z : C} (i : X ≅ Y) (j : Y ≅ Z) :
F.mapIso (i ≪≫ j) = F.mapIso i ≪≫ F.mapIso j := by
ext; apply Functor.map_comp
@[simp]
theorem mapIso_refl (F : C ⥤ D) (X : C) : F.mapIso (Iso.refl X) = Iso.refl (F.obj X) :=
Iso.ext <| F.map_id X
instance map_isIso (F : C ⥤ D) (f : X ⟶ Y) [IsIso f] : IsIso (F.map f) :=
(F.mapIso (asIso f)).isIso_hom
@[simp]
theorem map_inv (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) [IsIso f] : F.map (inv f) = inv (F.map f) := by
apply eq_inv_of_hom_inv_id
simp [← F.map_comp]
@[reassoc]
theorem map_hom_inv (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) [IsIso f] :
F.map f ≫ F.map (inv f) = 𝟙 (F.obj X) := by simp
@[reassoc]
theorem map_inv_hom (F : C ⥤ D) {X Y : C} (f : X ⟶ Y) [IsIso f] :
F.map (inv f) ≫ F.map f = 𝟙 (F.obj Y) := by simp
end Functor
end CategoryTheory
|
CategoryTheory\IsomorphismClasses.lean | /-
Copyright (c) 2019 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.CategoryTheory.Category.Cat
import Mathlib.CategoryTheory.Groupoid
import Mathlib.CategoryTheory.Types
/-!
# Objects of a category up to an isomorphism
`IsIsomorphic X Y := Nonempty (X ≅ Y)` is an equivalence relation on the objects of a category.
The quotient with respect to this relation defines a functor from our category to `Type`.
-/
universe v u
namespace CategoryTheory
section Category
variable {C : Type u} [Category.{v} C]
/-- An object `X` is isomorphic to an object `Y`, if `X ≅ Y` is not empty. -/
def IsIsomorphic : C → C → Prop := fun X Y => Nonempty (X ≅ Y)
variable (C)
/-- `IsIsomorphic` defines a setoid. -/
def isIsomorphicSetoid : Setoid C where
r := IsIsomorphic
iseqv := ⟨fun X => ⟨Iso.refl X⟩, fun ⟨α⟩ => ⟨α.symm⟩, fun ⟨α⟩ ⟨β⟩ => ⟨α.trans β⟩⟩
end Category
/-- The functor that sends each category to the quotient space of its objects up to an isomorphism.
-/
def isomorphismClasses : Cat.{v, u} ⥤ Type u where
obj C := Quotient (isIsomorphicSetoid C.α)
map {C D} F := Quot.map F.obj fun X Y ⟨f⟩ => ⟨F.mapIso f⟩
map_id {C} := by -- Porting note: this used to be `tidy`
dsimp; apply funext; intro x
apply @Quot.recOn _ _ _ x
· intro _ _ p
simp only [types_id_apply]
· intro _
rfl
map_comp {C D E} f g := by -- Porting note(s): idem
dsimp; apply funext; intro x
apply @Quot.recOn _ _ _ x
· intro _ _ _
simp only [types_id_apply]
· intro _
rfl
theorem Groupoid.isIsomorphic_iff_nonempty_hom {C : Type u} [Groupoid.{v} C] {X Y : C} :
IsIsomorphic X Y ↔ Nonempty (X ⟶ Y) :=
(Groupoid.isoEquivHom X Y).nonempty_congr
end CategoryTheory
|
CategoryTheory\NatIso.lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Tim Baumann, Stephen Morgan, Scott Morrison, Floris van Doorn
-/
import Mathlib.CategoryTheory.Functor.Category
import Mathlib.CategoryTheory.Iso
/-!
# Natural isomorphisms
For the most part, natural isomorphisms are just another sort of isomorphism.
We provide some special support for extracting components:
* if `α : F ≅ G`, then `a.app X : F.obj X ≅ G.obj X`,
and building natural isomorphisms from components:
*
```
NatIso.ofComponents
(app : ∀ X : C, F.obj X ≅ G.obj X)
(naturality : ∀ {X Y : C} (f : X ⟶ Y), F.map f ≫ (app Y).hom = (app X).hom ≫ G.map f) :
F ≅ G
```
only needing to check naturality in one direction.
## Implementation
Note that `NatIso` is a namespace without a corresponding definition;
we put some declarations that are specifically about natural isomorphisms in the `Iso`
namespace so that they are available using dot notation.
-/
open CategoryTheory
-- declare the `v`'s first; see `CategoryTheory.Category` for an explanation
universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄
namespace CategoryTheory
open NatTrans
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] {E : Type u₃}
[Category.{v₃} E]
namespace Iso
/-- The application of a natural isomorphism to an object. We put this definition in a different
namespace, so that we can use `α.app` -/
@[simps]
def app {F G : C ⥤ D} (α : F ≅ G) (X : C) :
F.obj X ≅ G.obj X where
hom := α.hom.app X
inv := α.inv.app X
hom_inv_id := by rw [← comp_app, Iso.hom_inv_id]; rfl
inv_hom_id := by rw [← comp_app, Iso.inv_hom_id]; rfl
@[reassoc (attr := simp)]
theorem hom_inv_id_app {F G : C ⥤ D} (α : F ≅ G) (X : C) :
α.hom.app X ≫ α.inv.app X = 𝟙 (F.obj X) :=
congr_fun (congr_arg NatTrans.app α.hom_inv_id) X
@[reassoc (attr := simp)]
theorem inv_hom_id_app {F G : C ⥤ D} (α : F ≅ G) (X : C) :
α.inv.app X ≫ α.hom.app X = 𝟙 (G.obj X) :=
congr_fun (congr_arg NatTrans.app α.inv_hom_id) X
end Iso
namespace NatIso
open CategoryTheory.Category CategoryTheory.Functor
@[simp]
theorem trans_app {F G H : C ⥤ D} (α : F ≅ G) (β : G ≅ H) (X : C) :
(α ≪≫ β).app X = α.app X ≪≫ β.app X :=
rfl
theorem app_hom {F G : C ⥤ D} (α : F ≅ G) (X : C) : (α.app X).hom = α.hom.app X :=
rfl
theorem app_inv {F G : C ⥤ D} (α : F ≅ G) (X : C) : (α.app X).inv = α.inv.app X :=
rfl
variable {F G : C ⥤ D}
instance hom_app_isIso (α : F ≅ G) (X : C) : IsIso (α.hom.app X) :=
⟨⟨α.inv.app X,
⟨by rw [← comp_app, Iso.hom_inv_id, ← id_app], by rw [← comp_app, Iso.inv_hom_id, ← id_app]⟩⟩⟩
instance inv_app_isIso (α : F ≅ G) (X : C) : IsIso (α.inv.app X) :=
⟨⟨α.hom.app X,
⟨by rw [← comp_app, Iso.inv_hom_id, ← id_app], by rw [← comp_app, Iso.hom_inv_id, ← id_app]⟩⟩⟩
section
/-!
Unfortunately we need a separate set of cancellation lemmas for components of natural isomorphisms,
because the `simp` normal form is `α.hom.app X`, rather than `α.app.hom X`.
(With the later, the morphism would be visibly part of an isomorphism, so general lemmas about
isomorphisms would apply.)
In the future, we should consider a redesign that changes this simp norm form,
but for now it breaks too many proofs.
-/
variable (α : F ≅ G)
@[simp]
theorem cancel_natIso_hom_left {X : C} {Z : D} (g g' : G.obj X ⟶ Z) :
α.hom.app X ≫ g = α.hom.app X ≫ g' ↔ g = g' := by simp only [cancel_epi, refl]
@[simp]
theorem cancel_natIso_inv_left {X : C} {Z : D} (g g' : F.obj X ⟶ Z) :
α.inv.app X ≫ g = α.inv.app X ≫ g' ↔ g = g' := by simp only [cancel_epi, refl]
@[simp]
theorem cancel_natIso_hom_right {X : D} {Y : C} (f f' : X ⟶ F.obj Y) :
f ≫ α.hom.app Y = f' ≫ α.hom.app Y ↔ f = f' := by simp only [cancel_mono, refl]
@[simp]
theorem cancel_natIso_inv_right {X : D} {Y : C} (f f' : X ⟶ G.obj Y) :
f ≫ α.inv.app Y = f' ≫ α.inv.app Y ↔ f = f' := by simp only [cancel_mono, refl]
@[simp]
theorem cancel_natIso_hom_right_assoc {W X X' : D} {Y : C} (f : W ⟶ X) (g : X ⟶ F.obj Y)
(f' : W ⟶ X') (g' : X' ⟶ F.obj Y) :
f ≫ g ≫ α.hom.app Y = f' ≫ g' ≫ α.hom.app Y ↔ f ≫ g = f' ≫ g' := by
simp only [← Category.assoc, cancel_mono, refl]
@[simp]
theorem cancel_natIso_inv_right_assoc {W X X' : D} {Y : C} (f : W ⟶ X) (g : X ⟶ G.obj Y)
(f' : W ⟶ X') (g' : X' ⟶ G.obj Y) :
f ≫ g ≫ α.inv.app Y = f' ≫ g' ≫ α.inv.app Y ↔ f ≫ g = f' ≫ g' := by
simp only [← Category.assoc, cancel_mono, refl]
@[simp]
theorem inv_inv_app {F G : C ⥤ D} (e : F ≅ G) (X : C) : inv (e.inv.app X) = e.hom.app X := by
aesop_cat
end
variable {X Y : C}
theorem naturality_1 (α : F ≅ G) (f : X ⟶ Y) : α.inv.app X ≫ F.map f ≫ α.hom.app Y = G.map f := by
simp
theorem naturality_2 (α : F ≅ G) (f : X ⟶ Y) : α.hom.app X ≫ G.map f ≫ α.inv.app Y = F.map f := by
simp
theorem naturality_1' (α : F ⟶ G) (f : X ⟶ Y) {_ : IsIso (α.app X)} :
inv (α.app X) ≫ F.map f ≫ α.app Y = G.map f := by simp
@[reassoc (attr := simp)]
theorem naturality_2' (α : F ⟶ G) (f : X ⟶ Y) {_ : IsIso (α.app Y)} :
α.app X ≫ G.map f ≫ inv (α.app Y) = F.map f := by
rw [← Category.assoc, ← naturality, Category.assoc, IsIso.hom_inv_id, Category.comp_id]
/-- The components of a natural isomorphism are isomorphisms.
-/
instance isIso_app_of_isIso (α : F ⟶ G) [IsIso α] (X) : IsIso (α.app X) :=
⟨⟨(inv α).app X,
⟨congr_fun (congr_arg NatTrans.app (IsIso.hom_inv_id α)) X,
congr_fun (congr_arg NatTrans.app (IsIso.inv_hom_id α)) X⟩⟩⟩
@[simp]
theorem isIso_inv_app (α : F ⟶ G) {_ : IsIso α} (X) : (inv α).app X = inv (α.app X) := by
-- Porting note: the next lemma used to be in `ext`, but that is no longer allowed.
-- We've added an aesop apply rule;
-- it would be nice to have a hook to run those without aesop warning it didn't close the goal.
apply IsIso.eq_inv_of_hom_inv_id
rw [← NatTrans.comp_app]
simp
@[simp]
theorem inv_map_inv_app (F : C ⥤ D ⥤ E) {X Y : C} (e : X ≅ Y) (Z : D) :
inv ((F.map e.inv).app Z) = (F.map e.hom).app Z := by
aesop_cat
/-- Construct a natural isomorphism between functors by giving object level isomorphisms,
and checking naturality only in the forward direction.
-/
@[simps]
def ofComponents (app : ∀ X : C, F.obj X ≅ G.obj X)
(naturality : ∀ {X Y : C} (f : X ⟶ Y),
F.map f ≫ (app Y).hom = (app X).hom ≫ G.map f := by aesop_cat) :
F ≅ G where
hom := { app := fun X => (app X).hom }
inv :=
{ app := fun X => (app X).inv,
naturality := fun X Y f => by
have h := congr_arg (fun f => (app X).inv ≫ f ≫ (app Y).inv) (naturality f).symm
simp only [Iso.inv_hom_id_assoc, Iso.hom_inv_id, assoc, comp_id, cancel_mono] at h
exact h }
@[simp]
theorem ofComponents.app (app' : ∀ X : C, F.obj X ≅ G.obj X) (naturality) (X) :
(ofComponents app' naturality).app X = app' X := by aesop
-- Making this an instance would cause a typeclass inference loop with `isIso_app_of_isIso`.
/-- A natural transformation is an isomorphism if all its components are isomorphisms.
-/
theorem isIso_of_isIso_app (α : F ⟶ G) [∀ X : C, IsIso (α.app X)] : IsIso α :=
(ofComponents (fun X => asIso (α.app X)) (by aesop)).isIso_hom
/-- Horizontal composition of natural isomorphisms. -/
@[simps]
def hcomp {F G : C ⥤ D} {H I : D ⥤ E} (α : F ≅ G) (β : H ≅ I) : F ⋙ H ≅ G ⋙ I := by
refine ⟨α.hom ◫ β.hom, α.inv ◫ β.inv, ?_, ?_⟩
· ext
rw [← NatTrans.exchange]
simp
ext; rw [← NatTrans.exchange]; simp
theorem isIso_map_iff {F₁ F₂ : C ⥤ D} (e : F₁ ≅ F₂) {X Y : C} (f : X ⟶ Y) :
IsIso (F₁.map f) ↔ IsIso (F₂.map f) := by
revert F₁ F₂
suffices ∀ {F₁ F₂ : C ⥤ D} (_ : F₁ ≅ F₂) (_ : IsIso (F₁.map f)), IsIso (F₂.map f) by
exact fun F₁ F₂ e => ⟨this e, this e.symm⟩
intro F₁ F₂ e hf
refine IsIso.mk ⟨e.inv.app Y ≫ inv (F₁.map f) ≫ e.hom.app X, ?_, ?_⟩
· simp only [NatTrans.naturality_assoc, IsIso.hom_inv_id_assoc, Iso.inv_hom_id_app]
· simp only [assoc, ← e.hom.naturality, IsIso.inv_hom_id_assoc, Iso.inv_hom_id_app]
end NatIso
lemma NatTrans.isIso_iff_isIso_app {F G : C ⥤ D} (τ : F ⟶ G) :
IsIso τ ↔ ∀ X, IsIso (τ.app X) :=
⟨fun _ ↦ inferInstance, fun _ ↦ NatIso.isIso_of_isIso_app _⟩
namespace Functor
variable (F : C ⥤ D) (obj : C → D) (e : ∀ X, F.obj X ≅ obj X)
/-- Constructor for a functor that is isomorphic to a given functor `F : C ⥤ D`,
while being definitionally equal on objects to a given map `obj : C → D`
such that for all `X : C`, we have an isomorphism `F.obj X ≅ obj X`. -/
@[simps obj]
def copyObj : C ⥤ D where
obj := obj
map f := (e _).inv ≫ F.map f ≫ (e _).hom
/-- The functor constructed with `copyObj` is isomorphic to the given functor. -/
@[simps!]
def isoCopyObj : F ≅ F.copyObj obj e :=
NatIso.ofComponents e (by simp [Functor.copyObj])
end Functor
end CategoryTheory
|
CategoryTheory\NatTrans.lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Tim Baumann, Stephen Morgan, Scott Morrison, Floris van Doorn
-/
import Mathlib.Tactic.CategoryTheory.Reassoc
/-!
# Natural transformations
Defines natural transformations between functors.
A natural transformation `α : NatTrans F G` consists of morphisms `α.app X : F.obj X ⟶ G.obj X`,
and the naturality squares `α.naturality f : F.map f ≫ α.app Y = α.app X ≫ G.map f`,
where `f : X ⟶ Y`.
Note that we make `NatTrans.naturality` a simp lemma, with the preferred simp normal form
pushing components of natural transformations to the left.
See also `CategoryTheory.FunctorCat`, where we provide the category structure on
functors and natural transformations.
Introduces notations
* `τ.app X` for the components of natural transformations,
* `F ⟶ G` for the type of natural transformations between functors `F` and `G`
(this and the next require `CategoryTheory.FunctorCat`),
* `σ ≫ τ` for vertical compositions, and
* `σ ◫ τ` for horizontal compositions.
-/
namespace CategoryTheory
-- declare the `v`'s first; see note [CategoryTheory universes].
universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D]
/-- `NatTrans F G` represents a natural transformation between functors `F` and `G`.
The field `app` provides the components of the natural transformation.
Naturality is expressed by `α.naturality`.
-/
@[ext]
structure NatTrans (F G : C ⥤ D) : Type max u₁ v₂ where
/-- The component of a natural transformation. -/
app : ∀ X : C, F.obj X ⟶ G.obj X
/-- The naturality square for a given morphism. -/
naturality : ∀ ⦃X Y : C⦄ (f : X ⟶ Y), F.map f ≫ app Y = app X ≫ G.map f := by aesop_cat
-- Rather arbitrarily, we say that the 'simpler' form is
-- components of natural transformations moving earlier.
attribute [reassoc (attr := simp)] NatTrans.naturality
theorem congr_app {F G : C ⥤ D} {α β : NatTrans F G} (h : α = β) (X : C) : α.app X = β.app X := by
aesop_cat
namespace NatTrans
/-- `NatTrans.id F` is the identity natural transformation on a functor `F`. -/
protected def id (F : C ⥤ D) : NatTrans F F where app X := 𝟙 (F.obj X)
@[simp]
theorem id_app' (F : C ⥤ D) (X : C) : (NatTrans.id F).app X = 𝟙 (F.obj X) := rfl
instance (F : C ⥤ D) : Inhabited (NatTrans F F) := ⟨NatTrans.id F⟩
open Category
open CategoryTheory.Functor
section
variable {F G H I : C ⥤ D}
/-- `vcomp α β` is the vertical compositions of natural transformations. -/
def vcomp (α : NatTrans F G) (β : NatTrans G H) : NatTrans F H where
app X := α.app X ≫ β.app X
-- functor_category will rewrite (vcomp α β) to (α ≫ β), so this is not a
-- suitable simp lemma. We will declare the variant vcomp_app' there.
theorem vcomp_app (α : NatTrans F G) (β : NatTrans G H) (X : C) :
(vcomp α β).app X = α.app X ≫ β.app X := rfl
end
/-- The diagram
F(f) F(g) F(h)
F X ----> F Y ----> F U ----> F U
| | | |
| α(X) | α(Y) | α(U) | α(V)
v v v v
G X ----> G Y ----> G U ----> G V
G(f) G(g) G(h)
commutes.
-/
example {F G : C ⥤ D} (α : NatTrans F G) {X Y U V : C} (f : X ⟶ Y) (g : Y ⟶ U) (h : U ⟶ V) :
α.app X ≫ G.map f ≫ G.map g ≫ G.map h = F.map f ≫ F.map g ≫ F.map h ≫ α.app V := by
simp
end NatTrans
end CategoryTheory
|
CategoryTheory\Noetherian.lean | /-
Copyright (c) 2022 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.CategoryTheory.Subobject.Lattice
import Mathlib.CategoryTheory.EssentiallySmall
import Mathlib.CategoryTheory.Simple
/-!
# Artinian and noetherian categories
An artinian category is a category in which objects do not
have infinite decreasing sequences of subobjects.
A noetherian category is a category in which objects do not
have infinite increasing sequences of subobjects.
We show that any nonzero artinian object has a simple subobject.
## Future work
The Jordan-Hölder theorem, following https://stacks.math.columbia.edu/tag/0FCK.
-/
namespace CategoryTheory
open CategoryTheory.Limits
variable {C : Type*} [Category C]
/-- A noetherian object is an object
which does not have infinite increasing sequences of subobjects.
See https://stacks.math.columbia.edu/tag/0FCG
-/
class NoetherianObject (X : C) : Prop where
subobject_gt_wellFounded' : WellFounded ((· > ·) : Subobject X → Subobject X → Prop)
lemma NoetherianObject.subobject_gt_wellFounded (X : C) [NoetherianObject X] :
WellFounded ((· > ·) : Subobject X → Subobject X → Prop) :=
NoetherianObject.subobject_gt_wellFounded'
/-- An artinian object is an object
which does not have infinite decreasing sequences of subobjects.
See https://stacks.math.columbia.edu/tag/0FCF
-/
class ArtinianObject (X : C) : Prop where
subobject_lt_wellFounded' : WellFounded ((· < ·) : Subobject X → Subobject X → Prop)
lemma ArtinianObject.subobject_lt_wellFounded (X : C) [ArtinianObject X] :
WellFounded ((· < ·) : Subobject X → Subobject X → Prop) :=
ArtinianObject.subobject_lt_wellFounded'
variable (C)
/-- A category is noetherian if it is essentially small and all objects are noetherian. -/
class Noetherian extends EssentiallySmall C : Prop where
noetherianObject : ∀ X : C, NoetherianObject X
attribute [instance] Noetherian.noetherianObject
/-- A category is artinian if it is essentially small and all objects are artinian. -/
class Artinian extends EssentiallySmall C : Prop where
artinianObject : ∀ X : C, ArtinianObject X
attribute [instance] Artinian.artinianObject
variable {C}
open Subobject
variable [HasZeroMorphisms C] [HasZeroObject C]
theorem exists_simple_subobject {X : C} [ArtinianObject X] (h : ¬IsZero X) :
∃ Y : Subobject X, Simple (Y : C) := by
haveI : Nontrivial (Subobject X) := nontrivial_of_not_isZero h
haveI := isAtomic_of_orderBot_wellFounded_lt (ArtinianObject.subobject_lt_wellFounded X)
obtain ⟨Y, s⟩ := (IsAtomic.eq_bot_or_exists_atom_le (⊤ : Subobject X)).resolve_left top_ne_bot
exact ⟨Y, (subobject_simple_iff_isAtom _).mpr s.1⟩
/-- Choose an arbitrary simple subobject of a non-zero artinian object. -/
noncomputable def simpleSubobject {X : C} [ArtinianObject X] (h : ¬IsZero X) : C :=
(exists_simple_subobject h).choose
/-- The monomorphism from the arbitrary simple subobject of a non-zero artinian object. -/
noncomputable def simpleSubobjectArrow {X : C} [ArtinianObject X] (h : ¬IsZero X) :
simpleSubobject h ⟶ X :=
(exists_simple_subobject h).choose.arrow
instance mono_simpleSubobjectArrow {X : C} [ArtinianObject X] (h : ¬IsZero X) :
Mono (simpleSubobjectArrow h) := by
dsimp only [simpleSubobjectArrow]
infer_instance
instance {X : C} [ArtinianObject X] (h : ¬IsZero X) : Simple (simpleSubobject h) :=
(exists_simple_subobject h).choose_spec
end CategoryTheory
|
CategoryTheory\Opposites.lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Stephen Morgan, Scott Morrison
-/
import Mathlib.CategoryTheory.Equivalence
/-!
# Opposite categories
We provide a category instance on `Cᵒᵖ`.
The morphisms `X ⟶ Y` are defined to be the morphisms `unop Y ⟶ unop X` in `C`.
Here `Cᵒᵖ` is an irreducible typeclass synonym for `C`
(it is the same one used in the algebra library).
We also provide various mechanisms for constructing opposite morphisms, functors,
and natural transformations.
Unfortunately, because we do not have a definitional equality `op (op X) = X`,
there are quite a few variations that are needed in practice.
-/
universe v₁ v₂ u₁ u₂
-- morphism levels before object levels. See note [CategoryTheory universes].
open Opposite
variable {C : Type u₁}
section Quiver
variable [Quiver.{v₁} C]
theorem Quiver.Hom.op_inj {X Y : C} :
Function.Injective (Quiver.Hom.op : (X ⟶ Y) → (Opposite.op Y ⟶ Opposite.op X)) := fun _ _ H =>
congr_arg Quiver.Hom.unop H
theorem Quiver.Hom.unop_inj {X Y : Cᵒᵖ} :
Function.Injective (Quiver.Hom.unop : (X ⟶ Y) → (Opposite.unop Y ⟶ Opposite.unop X)) :=
fun _ _ H => congr_arg Quiver.Hom.op H
@[simp]
theorem Quiver.Hom.unop_op {X Y : C} (f : X ⟶ Y) : f.op.unop = f :=
rfl
@[simp]
theorem Quiver.Hom.unop_op' {X Y : Cᵒᵖ} {x} :
@Quiver.Hom.unop C _ X Y no_index (Opposite.op (unop := x)) = x := rfl
@[simp]
theorem Quiver.Hom.op_unop {X Y : Cᵒᵖ} (f : X ⟶ Y) : f.unop.op = f :=
rfl
@[simp] theorem Quiver.Hom.unop_mk {X Y : Cᵒᵖ} (f : X ⟶ Y) : Quiver.Hom.unop {unop := f} = f := rfl
end Quiver
namespace CategoryTheory
variable [Category.{v₁} C]
/-- The opposite category.
See <https://stacks.math.columbia.edu/tag/001M>.
-/
instance Category.opposite : Category.{v₁} Cᵒᵖ where
comp f g := (g.unop ≫ f.unop).op
id X := (𝟙 (unop X)).op
@[simp, reassoc]
theorem op_comp {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g).op = g.op ≫ f.op :=
rfl
@[simp]
theorem op_id {X : C} : (𝟙 X).op = 𝟙 (op X) :=
rfl
@[simp, reassoc]
theorem unop_comp {X Y Z : Cᵒᵖ} {f : X ⟶ Y} {g : Y ⟶ Z} : (f ≫ g).unop = g.unop ≫ f.unop :=
rfl
@[simp]
theorem unop_id {X : Cᵒᵖ} : (𝟙 X).unop = 𝟙 (unop X) :=
rfl
@[simp]
theorem unop_id_op {X : C} : (𝟙 (op X)).unop = 𝟙 X :=
rfl
@[simp]
theorem op_id_unop {X : Cᵒᵖ} : (𝟙 (unop X)).op = 𝟙 X :=
rfl
section
variable (C)
/-- The functor from the double-opposite of a category to the underlying category. -/
@[simps]
def unopUnop : Cᵒᵖᵒᵖ ⥤ C where
obj X := unop (unop X)
map f := f.unop.unop
/-- The functor from a category to its double-opposite. -/
@[simps]
def opOp : C ⥤ Cᵒᵖᵒᵖ where
obj X := op (op X)
map f := f.op.op
/-- The double opposite category is equivalent to the original. -/
@[simps]
def opOpEquivalence : Cᵒᵖᵒᵖ ≌ C where
functor := unopUnop C
inverse := opOp C
unitIso := Iso.refl (𝟭 Cᵒᵖᵒᵖ)
counitIso := Iso.refl (opOp C ⋙ unopUnop C)
end
/-- If `f` is an isomorphism, so is `f.op` -/
instance isIso_op {X Y : C} (f : X ⟶ Y) [IsIso f] : IsIso f.op :=
⟨⟨(inv f).op, ⟨Quiver.Hom.unop_inj (by aesop_cat), Quiver.Hom.unop_inj (by aesop_cat)⟩⟩⟩
/-- If `f.op` is an isomorphism `f` must be too.
(This cannot be an instance as it would immediately loop!)
-/
theorem isIso_of_op {X Y : C} (f : X ⟶ Y) [IsIso f.op] : IsIso f :=
⟨⟨(inv f.op).unop, ⟨Quiver.Hom.op_inj (by simp), Quiver.Hom.op_inj (by simp)⟩⟩⟩
theorem isIso_op_iff {X Y : C} (f : X ⟶ Y) : IsIso f.op ↔ IsIso f :=
⟨fun _ => isIso_of_op _, fun _ => inferInstance⟩
theorem isIso_unop_iff {X Y : Cᵒᵖ} (f : X ⟶ Y) : IsIso f.unop ↔ IsIso f := by
rw [← isIso_op_iff f.unop, Quiver.Hom.op_unop]
instance isIso_unop {X Y : Cᵒᵖ} (f : X ⟶ Y) [IsIso f] : IsIso f.unop :=
(isIso_unop_iff _).2 inferInstance
@[simp]
theorem op_inv {X Y : C} (f : X ⟶ Y) [IsIso f] : (inv f).op = inv f.op := by
apply IsIso.eq_inv_of_hom_inv_id
rw [← op_comp, IsIso.inv_hom_id, op_id]
@[simp]
theorem unop_inv {X Y : Cᵒᵖ} (f : X ⟶ Y) [IsIso f] : (inv f).unop = inv f.unop := by
apply IsIso.eq_inv_of_hom_inv_id
rw [← unop_comp, IsIso.inv_hom_id, unop_id]
namespace Functor
section
variable {D : Type u₂} [Category.{v₂} D]
/-- The opposite of a functor, i.e. considering a functor `F : C ⥤ D` as a functor `Cᵒᵖ ⥤ Dᵒᵖ`.
In informal mathematics no distinction is made between these. -/
@[simps]
protected def op (F : C ⥤ D) : Cᵒᵖ ⥤ Dᵒᵖ where
obj X := op (F.obj (unop X))
map f := (F.map f.unop).op
/-- Given a functor `F : Cᵒᵖ ⥤ Dᵒᵖ` we can take the "unopposite" functor `F : C ⥤ D`.
In informal mathematics no distinction is made between these.
-/
@[simps]
protected def unop (F : Cᵒᵖ ⥤ Dᵒᵖ) : C ⥤ D where
obj X := unop (F.obj (op X))
map f := (F.map f.op).unop
/-- The isomorphism between `F.op.unop` and `F`. -/
@[simps!]
def opUnopIso (F : C ⥤ D) : F.op.unop ≅ F :=
NatIso.ofComponents fun X => Iso.refl _
/-- The isomorphism between `F.unop.op` and `F`. -/
@[simps!]
def unopOpIso (F : Cᵒᵖ ⥤ Dᵒᵖ) : F.unop.op ≅ F :=
NatIso.ofComponents fun X => Iso.refl _
variable (C D)
/-- Taking the opposite of a functor is functorial.
-/
@[simps]
def opHom : (C ⥤ D)ᵒᵖ ⥤ Cᵒᵖ ⥤ Dᵒᵖ where
obj F := (unop F).op
map α :=
{ app := fun X => (α.unop.app (unop X)).op
naturality := fun X Y f => Quiver.Hom.unop_inj (α.unop.naturality f.unop).symm }
/-- Take the "unopposite" of a functor is functorial.
-/
@[simps]
def opInv : (Cᵒᵖ ⥤ Dᵒᵖ) ⥤ (C ⥤ D)ᵒᵖ where
obj F := op F.unop
map α :=
Quiver.Hom.op
{ app := fun X => (α.app (op X)).unop
naturality := fun X Y f => Quiver.Hom.op_inj <| (α.naturality f.op).symm }
variable {C D}
/--
Another variant of the opposite of functor, turning a functor `C ⥤ Dᵒᵖ` into a functor `Cᵒᵖ ⥤ D`.
In informal mathematics no distinction is made.
-/
@[simps]
protected def leftOp (F : C ⥤ Dᵒᵖ) : Cᵒᵖ ⥤ D where
obj X := unop (F.obj (unop X))
map f := (F.map f.unop).unop
/--
Another variant of the opposite of functor, turning a functor `Cᵒᵖ ⥤ D` into a functor `C ⥤ Dᵒᵖ`.
In informal mathematics no distinction is made.
-/
@[simps]
protected def rightOp (F : Cᵒᵖ ⥤ D) : C ⥤ Dᵒᵖ where
obj X := op (F.obj (op X))
map f := (F.map f.op).op
lemma rightOp_map_unop {F : Cᵒᵖ ⥤ D} {X Y} (f : X ⟶ Y) :
(F.rightOp.map f).unop = F.map f.op := rfl
instance {F : C ⥤ D} [Full F] : Full F.op where
map_surjective f := ⟨(F.preimage f.unop).op, by simp⟩
instance {F : C ⥤ D} [Faithful F] : Faithful F.op where
map_injective h := Quiver.Hom.unop_inj <| by simpa using map_injective F (Quiver.Hom.op_inj h)
/-- If F is faithful then the right_op of F is also faithful. -/
instance rightOp_faithful {F : Cᵒᵖ ⥤ D} [Faithful F] : Faithful F.rightOp where
map_injective h := Quiver.Hom.op_inj (map_injective F (Quiver.Hom.op_inj h))
/-- If F is faithful then the left_op of F is also faithful. -/
instance leftOp_faithful {F : C ⥤ Dᵒᵖ} [Faithful F] : Faithful F.leftOp where
map_injective h := Quiver.Hom.unop_inj (map_injective F (Quiver.Hom.unop_inj h))
instance rightOp_full {F : Cᵒᵖ ⥤ D} [Full F] : Full F.rightOp where
map_surjective f := ⟨(F.preimage f.unop).unop, by simp⟩
instance leftOp_full {F : C ⥤ Dᵒᵖ} [Full F] : Full F.leftOp where
map_surjective f := ⟨(F.preimage f.op).op, by simp⟩
/-- The isomorphism between `F.leftOp.rightOp` and `F`. -/
@[simps!]
def leftOpRightOpIso (F : C ⥤ Dᵒᵖ) : F.leftOp.rightOp ≅ F :=
NatIso.ofComponents fun X => Iso.refl _
/-- The isomorphism between `F.rightOp.leftOp` and `F`. -/
@[simps!]
def rightOpLeftOpIso (F : Cᵒᵖ ⥤ D) : F.rightOp.leftOp ≅ F :=
NatIso.ofComponents fun X => Iso.refl _
/-- Whenever possible, it is advisable to use the isomorphism `rightOpLeftOpIso`
instead of this equality of functors. -/
theorem rightOp_leftOp_eq (F : Cᵒᵖ ⥤ D) : F.rightOp.leftOp = F := by
cases F
rfl
end
end Functor
namespace NatTrans
variable {D : Type u₂} [Category.{v₂} D]
section
variable {F G : C ⥤ D}
/-- The opposite of a natural transformation. -/
@[simps]
protected def op (α : F ⟶ G) : G.op ⟶ F.op where
app X := (α.app (unop X)).op
naturality X Y f := Quiver.Hom.unop_inj (by simp)
@[simp]
theorem op_id (F : C ⥤ D) : NatTrans.op (𝟙 F) = 𝟙 F.op :=
rfl
/-- The "unopposite" of a natural transformation. -/
@[simps]
protected def unop {F G : Cᵒᵖ ⥤ Dᵒᵖ} (α : F ⟶ G) : G.unop ⟶ F.unop where
app X := (α.app (op X)).unop
naturality X Y f := Quiver.Hom.op_inj (by simp)
@[simp]
theorem unop_id (F : Cᵒᵖ ⥤ Dᵒᵖ) : NatTrans.unop (𝟙 F) = 𝟙 F.unop :=
rfl
/-- Given a natural transformation `α : F.op ⟶ G.op`,
we can take the "unopposite" of each component obtaining a natural transformation `G ⟶ F`.
-/
@[simps]
protected def removeOp (α : F.op ⟶ G.op) : G ⟶ F where
app X := (α.app (op X)).unop
naturality X Y f :=
Quiver.Hom.op_inj <| by simpa only [Functor.op_map] using (α.naturality f.op).symm
@[simp]
theorem removeOp_id (F : C ⥤ D) : NatTrans.removeOp (𝟙 F.op) = 𝟙 F :=
rfl
/-- Given a natural transformation `α : F.unop ⟶ G.unop`, we can take the opposite of each
component obtaining a natural transformation `G ⟶ F`. -/
@[simps]
protected def removeUnop {F G : Cᵒᵖ ⥤ Dᵒᵖ} (α : F.unop ⟶ G.unop) : G ⟶ F where
app X := (α.app (unop X)).op
naturality X Y f :=
Quiver.Hom.unop_inj <| by simpa only [Functor.unop_map] using (α.naturality f.unop).symm
@[simp]
theorem removeUnop_id (F : Cᵒᵖ ⥤ Dᵒᵖ) : NatTrans.removeUnop (𝟙 F.unop) = 𝟙 F :=
rfl
end
section
variable {F G H : C ⥤ Dᵒᵖ}
/-- Given a natural transformation `α : F ⟶ G`, for `F G : C ⥤ Dᵒᵖ`,
taking `unop` of each component gives a natural transformation `G.leftOp ⟶ F.leftOp`.
-/
@[simps]
protected def leftOp (α : F ⟶ G) : G.leftOp ⟶ F.leftOp where
app X := (α.app (unop X)).unop
naturality X Y f := Quiver.Hom.op_inj (by simp)
@[simp]
theorem leftOp_id : NatTrans.leftOp (𝟙 F : F ⟶ F) = 𝟙 F.leftOp :=
rfl
@[simp]
theorem leftOp_comp (α : F ⟶ G) (β : G ⟶ H) : NatTrans.leftOp (α ≫ β) =
NatTrans.leftOp β ≫ NatTrans.leftOp α :=
rfl
/-- Given a natural transformation `α : F.leftOp ⟶ G.leftOp`, for `F G : C ⥤ Dᵒᵖ`,
taking `op` of each component gives a natural transformation `G ⟶ F`.
-/
@[simps]
protected def removeLeftOp (α : F.leftOp ⟶ G.leftOp) : G ⟶ F where
app X := (α.app (op X)).op
naturality X Y f :=
Quiver.Hom.unop_inj <| by simpa only [Functor.leftOp_map] using (α.naturality f.op).symm
@[simp]
theorem removeLeftOp_id : NatTrans.removeLeftOp (𝟙 F.leftOp) = 𝟙 F :=
rfl
end
section
variable {F G H : Cᵒᵖ ⥤ D}
/-- Given a natural transformation `α : F ⟶ G`, for `F G : Cᵒᵖ ⥤ D`,
taking `op` of each component gives a natural transformation `G.rightOp ⟶ F.rightOp`.
-/
@[simps]
protected def rightOp (α : F ⟶ G) : G.rightOp ⟶ F.rightOp where
app X := (α.app _).op
naturality X Y f := Quiver.Hom.unop_inj (by simp)
@[simp]
theorem rightOp_id : NatTrans.rightOp (𝟙 F : F ⟶ F) = 𝟙 F.rightOp :=
rfl
@[simp]
theorem rightOp_comp (α : F ⟶ G) (β : G ⟶ H) : NatTrans.rightOp (α ≫ β) =
NatTrans.rightOp β ≫ NatTrans.rightOp α :=
rfl
/-- Given a natural transformation `α : F.rightOp ⟶ G.rightOp`, for `F G : Cᵒᵖ ⥤ D`,
taking `unop` of each component gives a natural transformation `G ⟶ F`.
-/
@[simps]
protected def removeRightOp (α : F.rightOp ⟶ G.rightOp) : G ⟶ F where
app X := (α.app X.unop).unop
naturality X Y f :=
Quiver.Hom.op_inj <| by simpa only [Functor.rightOp_map] using (α.naturality f.unop).symm
@[simp]
theorem removeRightOp_id : NatTrans.removeRightOp (𝟙 F.rightOp) = 𝟙 F :=
rfl
end
end NatTrans
namespace Iso
variable {X Y : C}
/-- The opposite isomorphism.
-/
@[simps]
protected def op (α : X ≅ Y) : op Y ≅ op X where
hom := α.hom.op
inv := α.inv.op
hom_inv_id := Quiver.Hom.unop_inj α.inv_hom_id
inv_hom_id := Quiver.Hom.unop_inj α.hom_inv_id
/-- The isomorphism obtained from an isomorphism in the opposite category. -/
@[simps]
def unop {X Y : Cᵒᵖ} (f : X ≅ Y) : Y.unop ≅ X.unop where
hom := f.hom.unop
inv := f.inv.unop
hom_inv_id := by simp only [← unop_comp, f.inv_hom_id, unop_id]
inv_hom_id := by simp only [← unop_comp, f.hom_inv_id, unop_id]
@[simp]
theorem unop_op {X Y : Cᵒᵖ} (f : X ≅ Y) : f.unop.op = f := by (ext; rfl)
@[simp]
theorem op_unop {X Y : C} (f : X ≅ Y) : f.op.unop = f := by (ext; rfl)
section
variable {D : Type*} [Category D] {F G : C ⥤ Dᵒᵖ} (e : F ≅ G) (X : C)
@[reassoc (attr := simp)]
lemma unop_hom_inv_id_app : (e.hom.app X).unop ≫ (e.inv.app X).unop = 𝟙 _ := by
rw [← unop_comp, inv_hom_id_app, unop_id]
@[reassoc (attr := simp)]
lemma unop_inv_hom_id_app : (e.inv.app X).unop ≫ (e.hom.app X).unop = 𝟙 _ := by
rw [← unop_comp, hom_inv_id_app, unop_id]
end
end Iso
namespace NatIso
variable {D : Type u₂} [Category.{v₂} D]
variable {F G : C ⥤ D}
/-- The natural isomorphism between opposite functors `G.op ≅ F.op` induced by a natural
isomorphism between the original functors `F ≅ G`. -/
@[simps]
protected def op (α : F ≅ G) : G.op ≅ F.op where
hom := NatTrans.op α.hom
inv := NatTrans.op α.inv
hom_inv_id := by ext; dsimp; rw [← op_comp]; rw [α.inv_hom_id_app]; rfl
inv_hom_id := by ext; dsimp; rw [← op_comp]; rw [α.hom_inv_id_app]; rfl
/-- The natural isomorphism between functors `G ≅ F` induced by a natural isomorphism
between the opposite functors `F.op ≅ G.op`. -/
@[simps]
protected def removeOp (α : F.op ≅ G.op) : G ≅ F where
hom := NatTrans.removeOp α.hom
inv := NatTrans.removeOp α.inv
/-- The natural isomorphism between functors `G.unop ≅ F.unop` induced by a natural isomorphism
between the original functors `F ≅ G`. -/
@[simps]
protected def unop {F G : Cᵒᵖ ⥤ Dᵒᵖ} (α : F ≅ G) : G.unop ≅ F.unop where
hom := NatTrans.unop α.hom
inv := NatTrans.unop α.inv
end NatIso
namespace Equivalence
variable {D : Type u₂} [Category.{v₂} D]
/-- An equivalence between categories gives an equivalence between the opposite categories.
-/
@[simps]
def op (e : C ≌ D) : Cᵒᵖ ≌ Dᵒᵖ where
functor := e.functor.op
inverse := e.inverse.op
unitIso := (NatIso.op e.unitIso).symm
counitIso := (NatIso.op e.counitIso).symm
functor_unitIso_comp X := by
apply Quiver.Hom.unop_inj
dsimp
simp
/-- An equivalence between opposite categories gives an equivalence between the original categories.
-/
@[simps]
def unop (e : Cᵒᵖ ≌ Dᵒᵖ) : C ≌ D where
functor := e.functor.unop
inverse := e.inverse.unop
unitIso := (NatIso.unop e.unitIso).symm
counitIso := (NatIso.unop e.counitIso).symm
functor_unitIso_comp X := by
apply Quiver.Hom.op_inj
dsimp
simp
end Equivalence
/-- The equivalence between arrows of the form `A ⟶ B` and `B.unop ⟶ A.unop`. Useful for building
adjunctions.
Note that this (definitionally) gives variants
```
def opEquiv' (A : C) (B : Cᵒᵖ) : (Opposite.op A ⟶ B) ≃ (B.unop ⟶ A) :=
opEquiv _ _
def opEquiv'' (A : Cᵒᵖ) (B : C) : (A ⟶ Opposite.op B) ≃ (B ⟶ A.unop) :=
opEquiv _ _
def opEquiv''' (A B : C) : (Opposite.op A ⟶ Opposite.op B) ≃ (B ⟶ A) :=
opEquiv _ _
```
-/
@[simps]
def opEquiv (A B : Cᵒᵖ) : (A ⟶ B) ≃ (B.unop ⟶ A.unop) where
toFun f := f.unop
invFun g := g.op
left_inv _ := rfl
right_inv _ := rfl
instance subsingleton_of_unop (A B : Cᵒᵖ) [Subsingleton (unop B ⟶ unop A)] : Subsingleton (A ⟶ B) :=
(opEquiv A B).subsingleton
instance decidableEqOfUnop (A B : Cᵒᵖ) [DecidableEq (unop B ⟶ unop A)] : DecidableEq (A ⟶ B) :=
(opEquiv A B).decidableEq
/-- The equivalence between isomorphisms of the form `A ≅ B` and `B.unop ≅ A.unop`.
Note this is definitionally the same as the other three variants:
* `(Opposite.op A ≅ B) ≃ (B.unop ≅ A)`
* `(A ≅ Opposite.op B) ≃ (B ≅ A.unop)`
* `(Opposite.op A ≅ Opposite.op B) ≃ (B ≅ A)`
-/
@[simps]
def isoOpEquiv (A B : Cᵒᵖ) : (A ≅ B) ≃ (B.unop ≅ A.unop) where
toFun f := f.unop
invFun g := g.op
left_inv _ := by
ext
rfl
right_inv _ := by
ext
rfl
namespace Functor
variable (C)
variable (D : Type u₂) [Category.{v₂} D]
/-- The equivalence of functor categories induced by `op` and `unop`.
-/
@[simps]
def opUnopEquiv : (C ⥤ D)ᵒᵖ ≌ Cᵒᵖ ⥤ Dᵒᵖ where
functor := opHom _ _
inverse := opInv _ _
unitIso :=
NatIso.ofComponents (fun F => F.unop.opUnopIso.op)
(by
intro F G f
dsimp [opUnopIso]
rw [show f = f.unop.op by simp, ← op_comp, ← op_comp]
congr 1
aesop_cat)
counitIso := NatIso.ofComponents fun F => F.unopOpIso
/-- The equivalence of functor categories induced by `leftOp` and `rightOp`.
-/
@[simps!]
def leftOpRightOpEquiv : (Cᵒᵖ ⥤ D)ᵒᵖ ≌ C ⥤ Dᵒᵖ where
functor :=
{ obj := fun F => F.unop.rightOp
map := fun η => NatTrans.rightOp η.unop }
inverse :=
{ obj := fun F => op F.leftOp
map := fun η => η.leftOp.op }
unitIso :=
NatIso.ofComponents (fun F => F.unop.rightOpLeftOpIso.op)
(by
intro F G η
dsimp
rw [show η = η.unop.op by simp, ← op_comp, ← op_comp]
congr 1
aesop_cat)
counitIso := NatIso.ofComponents fun F => F.leftOpRightOpIso
instance {F : C ⥤ D} [EssSurj F] : EssSurj F.op where
mem_essImage X := ⟨op _, ⟨(F.objObjPreimageIso X.unop).op.symm⟩⟩
instance {F : Cᵒᵖ ⥤ D} [EssSurj F] : EssSurj F.rightOp where
mem_essImage X := ⟨_, ⟨(F.objObjPreimageIso X.unop).op.symm⟩⟩
instance {F : C ⥤ Dᵒᵖ} [EssSurj F] : EssSurj F.leftOp where
mem_essImage X := ⟨op _, ⟨(F.objObjPreimageIso (op X)).unop.symm⟩⟩
instance {F : C ⥤ D} [IsEquivalence F] : IsEquivalence F.op where
instance {F : Cᵒᵖ ⥤ D} [IsEquivalence F] : IsEquivalence F.rightOp where
instance {F : C ⥤ Dᵒᵖ} [IsEquivalence F] : IsEquivalence F.leftOp where
end Functor
end CategoryTheory
|
CategoryTheory\PathCategory.lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.CategoryTheory.EqToHom
import Mathlib.CategoryTheory.Quotient
import Mathlib.Combinatorics.Quiver.Path
/-!
# The category paths on a quiver.
When `C` is a quiver, `paths C` is the category of paths.
## When the quiver is itself a category
We provide `path_composition : paths C ⥤ C`.
We check that the quotient of the path category of a category by the canonical relation
(paths are related if they compose to the same path) is equivalent to the original category.
-/
universe v₁ v₂ u₁ u₂
namespace CategoryTheory
section
/-- A type synonym for the category of paths in a quiver.
-/
def Paths (V : Type u₁) : Type u₁ := V
instance (V : Type u₁) [Inhabited V] : Inhabited (Paths V) := ⟨(default : V)⟩
variable (V : Type u₁) [Quiver.{v₁ + 1} V]
namespace Paths
instance categoryPaths : Category.{max u₁ v₁} (Paths V) where
Hom := fun X Y : V => Quiver.Path X Y
id X := Quiver.Path.nil
comp f g := Quiver.Path.comp f g
variable {V}
/-- The inclusion of a quiver `V` into its path category, as a prefunctor.
-/
@[simps]
def of : V ⥤q Paths V where
obj X := X
map f := f.toPath
attribute [local ext (iff := false)] Functor.ext
/-- Any prefunctor from `V` lifts to a functor from `paths V` -/
def lift {C} [Category C] (φ : V ⥤q C) : Paths V ⥤ C where
obj := φ.obj
map {X} {Y} f :=
@Quiver.Path.rec V _ X (fun Y _ => φ.obj X ⟶ φ.obj Y) (𝟙 <| φ.obj X)
(fun _ f ihp => ihp ≫ φ.map f) Y f
map_id X := rfl
map_comp f g := by
induction' g with _ _ g' p ih _ _ _
· rw [Category.comp_id]
rfl
· have : f ≫ Quiver.Path.cons g' p = (f ≫ g').cons p := by apply Quiver.Path.comp_cons
rw [this]
simp only at ih ⊢
rw [ih, Category.assoc]
@[simp]
theorem lift_nil {C} [Category C] (φ : V ⥤q C) (X : V) :
(lift φ).map Quiver.Path.nil = 𝟙 (φ.obj X) := rfl
@[simp]
theorem lift_cons {C} [Category C] (φ : V ⥤q C) {X Y Z : V} (p : Quiver.Path X Y) (f : Y ⟶ Z) :
(lift φ).map (p.cons f) = (lift φ).map p ≫ φ.map f := rfl
@[simp]
theorem lift_toPath {C} [Category C] (φ : V ⥤q C) {X Y : V} (f : X ⟶ Y) :
(lift φ).map f.toPath = φ.map f := by
dsimp [Quiver.Hom.toPath, lift]
simp
theorem lift_spec {C} [Category C] (φ : V ⥤q C) : of ⋙q (lift φ).toPrefunctor = φ := by
fapply Prefunctor.ext
· rintro X
rfl
· rintro X Y f
rcases φ with ⟨φo, φm⟩
dsimp [lift, Quiver.Hom.toPath]
simp only [Category.id_comp]
theorem lift_unique {C} [Category C] (φ : V ⥤q C) (Φ : Paths V ⥤ C)
(hΦ : of ⋙q Φ.toPrefunctor = φ) : Φ = lift φ := by
subst_vars
fapply Functor.ext
· rintro X
rfl
· rintro X Y f
dsimp [lift]
induction' f with _ _ p f' ih
· simp only [Category.comp_id]
apply Functor.map_id
· simp only [Category.comp_id, Category.id_comp] at ih ⊢
-- Porting note: Had to do substitute `p.cons f'` and `f'.toPath` by their fully qualified
-- versions in this `have` clause (elsewhere too).
have : Φ.map (Quiver.Path.cons p f') = Φ.map p ≫ Φ.map (Quiver.Hom.toPath f') := by
convert Functor.map_comp Φ p (Quiver.Hom.toPath f')
rw [this, ih]
/-- Two functors out of a path category are equal when they agree on singleton paths. -/
@[ext (iff := false)]
theorem ext_functor {C} [Category C] {F G : Paths V ⥤ C} (h_obj : F.obj = G.obj)
(h : ∀ (a b : V) (e : a ⟶ b), F.map e.toPath =
eqToHom (congr_fun h_obj a) ≫ G.map e.toPath ≫ eqToHom (congr_fun h_obj.symm b)) :
F = G := by
fapply Functor.ext
· intro X
rw [h_obj]
· intro X Y f
induction' f with Y' Z' g e ih
· erw [F.map_id, G.map_id, Category.id_comp, eqToHom_trans, eqToHom_refl]
· erw [F.map_comp g (Quiver.Hom.toPath e), G.map_comp g (Quiver.Hom.toPath e), ih, h]
simp only [Category.id_comp, eqToHom_refl, eqToHom_trans_assoc, Category.assoc]
end Paths
variable (W : Type u₂) [Quiver.{v₂ + 1} W]
-- A restatement of `Prefunctor.mapPath_comp` using `f ≫ g` instead of `f.comp g`.
@[simp]
theorem Prefunctor.mapPath_comp' (F : V ⥤q W) {X Y Z : Paths V} (f : X ⟶ Y) (g : Y ⟶ Z) :
F.mapPath (f ≫ g) = (F.mapPath f).comp (F.mapPath g) :=
Prefunctor.mapPath_comp _ _ _
end
section
variable {C : Type u₁} [Category.{v₁} C]
open Quiver
-- Porting note:
-- This def was originally marked `@[simp]`, but the meaning is different in lean4: lean4#2042
-- So, the `@[simp]` was removed, and the two equational lemmas below added instead.
/-- A path in a category can be composed to a single morphism. -/
def composePath {X : C} : ∀ {Y : C} (_ : Path X Y), X ⟶ Y
| _, .nil => 𝟙 X
| _, .cons p e => composePath p ≫ e
@[simp] lemma composePath_nil {X : C} : composePath (Path.nil : Path X X) = 𝟙 X := rfl
@[simp] lemma composePath_cons {X Y Z : C} (p : Path X Y) (e : Y ⟶ Z) :
composePath (p.cons e) = composePath p ≫ e := rfl
@[simp]
theorem composePath_toPath {X Y : C} (f : X ⟶ Y) : composePath f.toPath = f := Category.id_comp _
@[simp]
theorem composePath_comp {X Y Z : C} (f : Path X Y) (g : Path Y Z) :
composePath (f.comp g) = composePath f ≫ composePath g := by
induction' g with Y' Z' g e ih
· simp
· simp [ih]
@[simp]
-- Porting note (#11215): TODO get rid of `(id X : C)` somehow?
theorem composePath_id {X : Paths C} : composePath (𝟙 X) = 𝟙 (id X : C) := rfl
@[simp]
theorem composePath_comp' {X Y Z : Paths C} (f : X ⟶ Y) (g : Y ⟶ Z) :
composePath (f ≫ g) = composePath f ≫ composePath g :=
composePath_comp f g
variable (C)
/-- Composition of paths as functor from the path category of a category to the category. -/
@[simps]
def pathComposition : Paths C ⥤ C where
obj X := X
map f := composePath f
-- TODO: This, and what follows, should be generalized to
-- the `HomRel` for the kernel of any functor.
-- Indeed, this should be part of an equivalence between congruence relations on a category `C`
-- and full, essentially surjective functors out of `C`.
/-- The canonical relation on the path category of a category:
two paths are related if they compose to the same morphism. -/
@[simp]
def pathsHomRel : HomRel (Paths C) := fun _ _ p q =>
(pathComposition C).map p = (pathComposition C).map q
/-- The functor from a category to the canonical quotient of its path category. -/
@[simps]
def toQuotientPaths : C ⥤ Quotient (pathsHomRel C) where
obj X := Quotient.mk X
map f := Quot.mk _ f.toPath
map_id X := Quot.sound (Quotient.CompClosure.of _ _ _ (by simp))
map_comp f g := Quot.sound (Quotient.CompClosure.of _ _ _ (by simp))
/-- The functor from the canonical quotient of a path category of a category
to the original category. -/
@[simps!]
def quotientPathsTo : Quotient (pathsHomRel C) ⥤ C :=
Quotient.lift _ (pathComposition C) fun _ _ _ _ w => w
/-- The canonical quotient of the path category of a category
is equivalent to the original category. -/
def quotientPathsEquiv : Quotient (pathsHomRel C) ≌ C where
functor := quotientPathsTo C
inverse := toQuotientPaths C
unitIso :=
NatIso.ofComponents
(fun X => by cases X; rfl)
(Quot.ind fun f => by
apply Quot.sound
apply Quotient.CompClosure.of
simp [Category.comp_id, Category.id_comp, pathsHomRel])
counitIso := NatIso.ofComponents (fun X => Iso.refl _) (fun f => by simp [Quot.liftOn_mk])
functor_unitIso_comp X := by
cases X
simp only [pathsHomRel, pathComposition_obj, pathComposition_map, Functor.id_obj,
quotientPathsTo_obj, Functor.comp_obj, toQuotientPaths_obj_as,
NatIso.ofComponents_hom_app, Iso.refl_hom, quotientPathsTo_map, Category.comp_id]
rfl
end
end CategoryTheory
|
CategoryTheory\PEmpty.lean | /-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Bhavik Mehta
-/
import Mathlib.CategoryTheory.DiscreteCategory
/-!
# The empty category
Defines a category structure on `PEmpty`, and the unique functor `PEmpty ⥤ C` for any category `C`.
-/
universe w v v' u u'
-- morphism levels before object levels. See note [CategoryTheory universes].
namespace CategoryTheory
variable (C : Type u) [Category.{v} C] (D : Type u') [Category.{v'} D]
instance (α : Type*) [IsEmpty α] : IsEmpty (Discrete α) := Function.isEmpty Discrete.as
/-- The (unique) functor from an empty category. -/
def functorOfIsEmpty [IsEmpty C] : C ⥤ D where
obj := isEmptyElim
map := fun {X} ↦ isEmptyElim X
map_id := fun {X} ↦ isEmptyElim X
map_comp := fun {X} ↦ isEmptyElim X
variable {C D}
/-- Any two functors out of an empty category are isomorphic. -/
def Functor.isEmptyExt [IsEmpty C] (F G : C ⥤ D) : F ≅ G :=
NatIso.ofComponents isEmptyElim (fun {X} ↦ isEmptyElim X)
variable (C D)
/-- The equivalence between two empty categories. -/
def equivalenceOfIsEmpty [IsEmpty C] [IsEmpty D] : C ≌ D where
functor := functorOfIsEmpty C D
inverse := functorOfIsEmpty D C
unitIso := Functor.isEmptyExt _ _
counitIso := Functor.isEmptyExt _ _
functor_unitIso_comp := isEmptyElim
/-- Equivalence between two empty categories. -/
def emptyEquivalence : Discrete.{w} PEmpty ≌ Discrete.{v} PEmpty := equivalenceOfIsEmpty _ _
namespace Functor
/-- The canonical functor out of the empty category. -/
def empty : Discrete.{w} PEmpty ⥤ C :=
Discrete.functor PEmpty.elim
variable {C}
/-- Any two functors out of the empty category are isomorphic. -/
def emptyExt (F G : Discrete.{w} PEmpty ⥤ C) : F ≅ G :=
Discrete.natIso fun x => x.as.elim
/-- Any functor out of the empty category is isomorphic to the canonical functor from the empty
category.
-/
def uniqueFromEmpty (F : Discrete.{w} PEmpty ⥤ C) : F ≅ empty C :=
emptyExt _ _
/-- Any two functors out of the empty category are *equal*. You probably want to use
`emptyExt` instead of this.
-/
theorem empty_ext' (F G : Discrete.{w} PEmpty ⥤ C) : F = G :=
Functor.ext (fun x => x.as.elim) fun x _ _ => x.as.elim
end Functor
end CategoryTheory
|
CategoryTheory\PUnit.lean | /-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Bhavik Mehta
-/
import Mathlib.CategoryTheory.Functor.Const
import Mathlib.CategoryTheory.DiscreteCategory
/-!
# The category `Discrete PUnit`
We define `star : C ⥤ Discrete PUnit` sending everything to `PUnit.star`,
show that any two functors to `Discrete PUnit` are naturally isomorphic,
and construct the equivalence `(Discrete PUnit ⥤ C) ≌ C`.
-/
universe w v u
-- morphism levels before object levels. See note [CategoryTheory universes].
namespace CategoryTheory
variable (C : Type u) [Category.{v} C]
namespace Functor
/-- The constant functor sending everything to `PUnit.star`. -/
@[simps!]
def star : C ⥤ Discrete PUnit.{w + 1} :=
(Functor.const _).obj ⟨⟨⟩⟩
-- Porting note (#10618): simp can simplify this
attribute [nolint simpNF] star_map_down_down
variable {C}
/-- Any two functors to `Discrete PUnit` are isomorphic. -/
@[simps!]
def punitExt (F G : C ⥤ Discrete PUnit.{w + 1}) : F ≅ G :=
NatIso.ofComponents fun X => eqToIso (by simp only [eq_iff_true_of_subsingleton])
-- Porting note: simp does indeed fire for these despite the linter warning
attribute [nolint simpNF] punitExt_hom_app_down_down punitExt_inv_app_down_down
/-- Any two functors to `Discrete PUnit` are *equal*.
You probably want to use `punitExt` instead of this. -/
theorem punit_ext' (F G : C ⥤ Discrete PUnit.{w + 1}) : F = G :=
Functor.ext fun X => by simp only [eq_iff_true_of_subsingleton]
/-- The functor from `Discrete PUnit` sending everything to the given object. -/
abbrev fromPUnit (X : C) : Discrete PUnit.{w + 1} ⥤ C :=
(Functor.const _).obj X
/-- Functors from `Discrete PUnit` are equivalent to the category itself. -/
@[simps]
def equiv : Discrete PUnit.{w + 1} ⥤ C ≌ C where
functor :=
{ obj := fun F => F.obj ⟨⟨⟩⟩
map := fun θ => θ.app ⟨⟨⟩⟩ }
inverse := Functor.const _
unitIso := NatIso.ofComponents fun X => Discrete.natIso fun i => Iso.refl _
counitIso := NatIso.ofComponents Iso.refl
end Functor
/-- A category being equivalent to `PUnit` is equivalent to it having a unique morphism between
any two objects. (In fact, such a category is also a groupoid;
see `CategoryTheory.Groupoid.ofHomUnique`) -/
theorem equiv_punit_iff_unique :
Nonempty (C ≌ Discrete PUnit.{w + 1}) ↔ Nonempty C ∧ ∀ x y : C, Nonempty <| Unique (x ⟶ y) := by
constructor
· rintro ⟨h⟩
refine ⟨⟨h.inverse.obj ⟨⟨⟩⟩⟩, fun x y => Nonempty.intro ?_⟩
let f : x ⟶ y := by
have hx : x ⟶ h.inverse.obj ⟨⟨⟩⟩ := by convert h.unit.app x
have hy : h.inverse.obj ⟨⟨⟩⟩ ⟶ y := by convert h.unitInv.app y
exact hx ≫ hy
suffices sub : Subsingleton (x ⟶ y) from uniqueOfSubsingleton f
have : ∀ z, z = h.unit.app x ≫ (h.functor ⋙ h.inverse).map z ≫ h.unitInv.app y := by
intro z
simp [congrArg (· ≫ h.unitInv.app y) (h.unit.naturality z)]
apply Subsingleton.intro
intro a b
rw [this a, this b]
simp only [Functor.comp_map]
congr 3
apply ULift.ext
simp [eq_iff_true_of_subsingleton]
· rintro ⟨⟨p⟩, h⟩
haveI := fun x y => (h x y).some
refine
Nonempty.intro
(CategoryTheory.Equivalence.mk ((Functor.const _).obj ⟨⟨⟩⟩)
((@Functor.const <| Discrete PUnit).obj p) ?_ (by apply Functor.punitExt))
exact
NatIso.ofComponents fun _ =>
{ hom := default
inv := default }
end CategoryTheory
|
CategoryTheory\Quotient.lean | /-
Copyright (c) 2020 David Wärn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Wärn
-/
import Mathlib.CategoryTheory.NatIso
import Mathlib.CategoryTheory.EqToHom
/-!
# Quotient category
Constructs the quotient of a category by an arbitrary family of relations on its hom-sets,
by introducing a type synonym for the objects, and identifying homs as necessary.
This is analogous to 'the quotient of a group by the normal closure of a subset', rather
than 'the quotient of a group by a normal subgroup'. When taking the quotient by a congruence
relation, `functor_map_eq_iff` says that no unnecessary identifications have been made.
-/
/-- A `HomRel` on `C` consists of a relation on every hom-set. -/
def HomRel (C) [Quiver C] :=
∀ ⦃X Y : C⦄, (X ⟶ Y) → (X ⟶ Y) → Prop
-- Porting Note: `deriving Inhabited` was not able to deduce this typeclass
instance (C) [Quiver C] : Inhabited (HomRel C) where
default := fun _ _ _ _ ↦ PUnit
namespace CategoryTheory
variable {C : Type _} [Category C] (r : HomRel C)
/-- A `HomRel` is a congruence when it's an equivalence on every hom-set, and it can be composed
from left and right. -/
class Congruence : Prop where
/-- `r` is an equivalence on every hom-set. -/
equivalence : ∀ {X Y}, _root_.Equivalence (@r X Y)
/-- Precomposition with an arrow respects `r`. -/
compLeft : ∀ {X Y Z} (f : X ⟶ Y) {g g' : Y ⟶ Z}, r g g' → r (f ≫ g) (f ≫ g')
/-- Postcomposition with an arrow respects `r`. -/
compRight : ∀ {X Y Z} {f f' : X ⟶ Y} (g : Y ⟶ Z), r f f' → r (f ≫ g) (f' ≫ g)
/-- A type synonym for `C`, thought of as the objects of the quotient category. -/
@[ext]
structure Quotient (r : HomRel C) where
/-- The object of `C`. -/
as : C
instance [Inhabited C] : Inhabited (Quotient r) :=
⟨{ as := default }⟩
namespace Quotient
/-- Generates the closure of a family of relations w.r.t. composition from left and right. -/
inductive CompClosure (r : HomRel C) ⦃s t : C⦄ : (s ⟶ t) → (s ⟶ t) → Prop
| intro {a b : C} (f : s ⟶ a) (m₁ m₂ : a ⟶ b) (g : b ⟶ t) (h : r m₁ m₂) :
CompClosure r (f ≫ m₁ ≫ g) (f ≫ m₂ ≫ g)
theorem CompClosure.of {a b : C} (m₁ m₂ : a ⟶ b) (h : r m₁ m₂) : CompClosure r m₁ m₂ := by
simpa using CompClosure.intro (𝟙 _) m₁ m₂ (𝟙 _) h
theorem comp_left {a b c : C} (f : a ⟶ b) :
∀ (g₁ g₂ : b ⟶ c) (_ : CompClosure r g₁ g₂), CompClosure r (f ≫ g₁) (f ≫ g₂)
| _, _, ⟨x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro (f ≫ x) m₁ m₂ y h
theorem comp_right {a b c : C} (g : b ⟶ c) :
∀ (f₁ f₂ : a ⟶ b) (_ : CompClosure r f₁ f₂), CompClosure r (f₁ ≫ g) (f₂ ≫ g)
| _, _, ⟨x, m₁, m₂, y, h⟩ => by simpa using CompClosure.intro x m₁ m₂ (y ≫ g) h
/-- Hom-sets of the quotient category. -/
def Hom (s t : Quotient r) :=
Quot <| @CompClosure C _ r s.as t.as
instance (a : Quotient r) : Inhabited (Hom r a a) :=
⟨Quot.mk _ (𝟙 a.as)⟩
/-- Composition in the quotient category. -/
def comp ⦃a b c : Quotient r⦄ : Hom r a b → Hom r b c → Hom r a c := fun hf hg ↦
Quot.liftOn hf
(fun f ↦
Quot.liftOn hg (fun g ↦ Quot.mk _ (f ≫ g)) fun g₁ g₂ h ↦
Quot.sound <| comp_left r f g₁ g₂ h)
fun f₁ f₂ h ↦ Quot.inductionOn hg fun g ↦ Quot.sound <| comp_right r g f₁ f₂ h
@[simp]
theorem comp_mk {a b c : Quotient r} (f : a.as ⟶ b.as) (g : b.as ⟶ c.as) :
comp r (Quot.mk _ f) (Quot.mk _ g) = Quot.mk _ (f ≫ g) :=
rfl
-- Porting note: Had to manually add the proofs of `comp_id` `id_comp` and `assoc`
instance category : Category (Quotient r) where
Hom := Hom r
id a := Quot.mk _ (𝟙 a.as)
comp := @comp _ _ r
comp_id f := Quot.inductionOn f <| by simp
id_comp f := Quot.inductionOn f <| by simp
assoc f g h := Quot.inductionOn f <| Quot.inductionOn g <| Quot.inductionOn h <| by simp
/-- The functor from a category to its quotient. -/
def functor : C ⥤ Quotient r where
obj a := { as := a }
map := @fun _ _ f ↦ Quot.mk _ f
instance full_functor : (functor r).Full where
map_surjective f := ⟨Quot.out f, by simp [functor]⟩
instance essSurj_functor : (functor r).EssSurj where
mem_essImage Y :=
⟨Y.as, ⟨eqToIso (by
ext
rfl)⟩⟩
protected theorem induction {P : ∀ {a b : Quotient r}, (a ⟶ b) → Prop}
(h : ∀ {x y : C} (f : x ⟶ y), P ((functor r).map f)) :
∀ {a b : Quotient r} (f : a ⟶ b), P f := by
rintro ⟨x⟩ ⟨y⟩ ⟨f⟩
exact h f
protected theorem sound {a b : C} {f₁ f₂ : a ⟶ b} (h : r f₁ f₂) :
(functor r).map f₁ = (functor r).map f₂ := by
simpa using Quot.sound (CompClosure.intro (𝟙 a) f₁ f₂ (𝟙 b) h)
lemma compClosure_iff_self [h : Congruence r] {X Y : C} (f g : X ⟶ Y) :
CompClosure r f g ↔ r f g := by
constructor
· intro hfg
induction' hfg with m m' hm
exact Congruence.compLeft _ (Congruence.compRight _ (by assumption))
· exact CompClosure.of _ _ _
@[simp]
theorem compClosure_eq_self [h : Congruence r] :
CompClosure r = r := by
ext
simp only [compClosure_iff_self]
theorem functor_map_eq_iff [h : Congruence r] {X Y : C} (f f' : X ⟶ Y) :
(functor r).map f = (functor r).map f' ↔ r f f' := by
dsimp [functor]
rw [Equivalence.quot_mk_eq_iff, compClosure_eq_self r]
simpa only [compClosure_eq_self r] using h.equivalence
variable {D : Type _} [Category D] (F : C ⥤ D)
/-- The induced functor on the quotient category. -/
def lift (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂) : Quotient r ⥤ D where
obj a := F.obj a.as
map := @fun a b hf ↦
Quot.liftOn hf (fun f ↦ F.map f)
(by
rintro _ _ ⟨_, _, _, _, h⟩
simp [H _ _ _ _ h])
map_id a := F.map_id a.as
map_comp := by
rintro a b c ⟨f⟩ ⟨g⟩
exact F.map_comp f g
variable (H : ∀ (x y : C) (f₁ f₂ : x ⟶ y), r f₁ f₂ → F.map f₁ = F.map f₂)
theorem lift_spec : functor r ⋙ lift r F H = F := by
apply Functor.ext; rotate_left
· rintro X
rfl
· rintro X Y f
dsimp [lift, functor]
simp
theorem lift_unique (Φ : Quotient r ⥤ D) (hΦ : functor r ⋙ Φ = F) : Φ = lift r F H := by
subst_vars
fapply Functor.hext
· rintro X
dsimp [lift, Functor]
congr
· rintro _ _ f
dsimp [lift, Functor]
refine Quot.inductionOn f (fun _ ↦ ?_) -- Porting note: this line was originally an `apply`
simp only [Quot.liftOn_mk, Functor.comp_map]
congr
lemma lift_unique' (F₁ F₂ : Quotient r ⥤ D) (h : functor r ⋙ F₁ = functor r ⋙ F₂) :
F₁ = F₂ := by
rw [lift_unique r (functor r ⋙ F₂) _ F₂ rfl]; swap
· rintro X Y f g h
dsimp
rw [Quotient.sound r h]
apply lift_unique
rw [h]
/-- The original functor factors through the induced functor. -/
def lift.isLift : functor r ⋙ lift r F H ≅ F :=
NatIso.ofComponents fun X ↦ Iso.refl _
@[simp]
theorem lift.isLift_hom (X : C) : (lift.isLift r F H).hom.app X = 𝟙 (F.obj X) :=
rfl
@[simp]
theorem lift.isLift_inv (X : C) : (lift.isLift r F H).inv.app X = 𝟙 (F.obj X) :=
rfl
theorem lift_obj_functor_obj (X : C) :
(lift r F H).obj ((functor r).obj X) = F.obj X := rfl
theorem lift_map_functor_map {X Y : C} (f : X ⟶ Y) :
(lift r F H).map ((functor r).map f) = F.map f := by
rw [← NatIso.naturality_1 (lift.isLift r F H)]
dsimp [lift, functor]
simp
variable {r}
lemma natTrans_ext {F G : Quotient r ⥤ D} (τ₁ τ₂ : F ⟶ G)
(h : whiskerLeft (Quotient.functor r) τ₁ = whiskerLeft (Quotient.functor r) τ₂) : τ₁ = τ₂ :=
NatTrans.ext (by ext1 ⟨X⟩; exact NatTrans.congr_app h X)
variable (r)
/-- In order to define a natural transformation `F ⟶ G` with `F G : Quotient r ⥤ D`, it suffices
to do so after precomposing with `Quotient.functor r`. -/
def natTransLift {F G : Quotient r ⥤ D} (τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) :
F ⟶ G where
app := fun ⟨X⟩ => τ.app X
naturality := fun ⟨X⟩ ⟨Y⟩ => by
rintro ⟨f⟩
exact τ.naturality f
@[simp]
lemma natTransLift_app (F G : Quotient r ⥤ D)
(τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G) (X : C) :
(natTransLift r τ).app ((Quotient.functor r).obj X) = τ.app X := rfl
@[reassoc]
lemma comp_natTransLift {F G H : Quotient r ⥤ D}
(τ : Quotient.functor r ⋙ F ⟶ Quotient.functor r ⋙ G)
(τ' : Quotient.functor r ⋙ G ⟶ Quotient.functor r ⋙ H) :
natTransLift r τ ≫ natTransLift r τ' = natTransLift r (τ ≫ τ') := by aesop_cat
@[simp]
lemma natTransLift_id (F : Quotient r ⥤ D) :
natTransLift r (𝟙 (Quotient.functor r ⋙ F)) = 𝟙 _ := by aesop_cat
/-- In order to define a natural isomorphism `F ≅ G` with `F G : Quotient r ⥤ D`, it suffices
to do so after precomposing with `Quotient.functor r`. -/
@[simps]
def natIsoLift {F G : Quotient r ⥤ D} (τ : Quotient.functor r ⋙ F ≅ Quotient.functor r ⋙ G) :
F ≅ G where
hom := natTransLift _ τ.hom
inv := natTransLift _ τ.inv
hom_inv_id := by rw [comp_natTransLift, τ.hom_inv_id, natTransLift_id]
inv_hom_id := by rw [comp_natTransLift, τ.inv_hom_id, natTransLift_id]
variable (D)
instance full_whiskeringLeft_functor :
((whiskeringLeft C _ D).obj (functor r)).Full where
map_surjective f := ⟨natTransLift r f, by aesop_cat⟩
instance faithful_whiskeringLeft_functor :
((whiskeringLeft C _ D).obj (functor r)).Faithful := ⟨by apply natTrans_ext⟩
end Quotient
end CategoryTheory
|
CategoryTheory\Simple.lean | /-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel, Scott Morrison
-/
import Mathlib.CategoryTheory.Limits.Shapes.ZeroMorphisms
import Mathlib.CategoryTheory.Limits.Shapes.Kernels
import Mathlib.CategoryTheory.Abelian.Basic
import Mathlib.CategoryTheory.Subobject.Lattice
import Mathlib.Order.Atoms
/-!
# Simple objects
We define simple objects in any category with zero morphisms.
A simple object is an object `Y` such that any monomorphism `f : X ⟶ Y`
is either an isomorphism or zero (but not both).
This is formalized as a `Prop` valued typeclass `Simple X`.
In some contexts, especially representation theory, simple objects are called "irreducibles".
If a morphism `f` out of a simple object is nonzero and has a kernel, then that kernel is zero.
(We state this as `kernel.ι f = 0`, but should add `kernel f ≅ 0`.)
When the category is abelian, being simple is the same as being cosimple (although we do not
state a separate typeclass for this).
As a consequence, any nonzero epimorphism out of a simple object is an isomorphism,
and any nonzero morphism into a simple object has trivial cokernel.
We show that any simple object is indecomposable.
-/
noncomputable section
open CategoryTheory.Limits
namespace CategoryTheory
universe v u
variable {C : Type u} [Category.{v} C]
section
variable [HasZeroMorphisms C]
/-- An object is simple if monomorphisms into it are (exclusively) either isomorphisms or zero. -/
class Simple (X : C) : Prop where
mono_isIso_iff_nonzero : ∀ {Y : C} (f : Y ⟶ X) [Mono f], IsIso f ↔ f ≠ 0
/-- A nonzero monomorphism to a simple object is an isomorphism. -/
theorem isIso_of_mono_of_nonzero {X Y : C} [Simple Y] {f : X ⟶ Y} [Mono f] (w : f ≠ 0) : IsIso f :=
(Simple.mono_isIso_iff_nonzero f).mpr w
theorem Simple.of_iso {X Y : C} [Simple Y] (i : X ≅ Y) : Simple X :=
{ mono_isIso_iff_nonzero := fun f m => by
haveI : Mono (f ≫ i.hom) := mono_comp _ _
constructor
· intro h w
have j : IsIso (f ≫ i.hom) := by infer_instance
rw [Simple.mono_isIso_iff_nonzero] at j
subst w
simp at j
· intro h
have j : IsIso (f ≫ i.hom) := by
apply isIso_of_mono_of_nonzero
intro w
apply h
simpa using (cancel_mono i.inv).2 w
rw [← Category.comp_id f, ← i.hom_inv_id, ← Category.assoc]
infer_instance }
theorem Simple.iff_of_iso {X Y : C} (i : X ≅ Y) : Simple X ↔ Simple Y :=
⟨fun _ => Simple.of_iso i.symm, fun _ => Simple.of_iso i⟩
theorem kernel_zero_of_nonzero_from_simple {X Y : C} [Simple X] {f : X ⟶ Y} [HasKernel f]
(w : f ≠ 0) : kernel.ι f = 0 := by
classical
by_contra h
haveI := isIso_of_mono_of_nonzero h
exact w (eq_zero_of_epi_kernel f)
-- See also `mono_of_nonzero_from_simple`, which requires `Preadditive C`.
/-- A nonzero morphism `f` to a simple object is an epimorphism
(assuming `f` has an image, and `C` has equalizers).
-/
theorem epi_of_nonzero_to_simple [HasEqualizers C] {X Y : C} [Simple Y] {f : X ⟶ Y} [HasImage f]
(w : f ≠ 0) : Epi f := by
rw [← image.fac f]
haveI : IsIso (image.ι f) := isIso_of_mono_of_nonzero fun h => w (eq_zero_of_image_eq_zero h)
apply epi_comp
theorem mono_to_simple_zero_of_not_iso {X Y : C} [Simple Y] {f : X ⟶ Y} [Mono f]
(w : IsIso f → False) : f = 0 := by
classical
by_contra h
exact w (isIso_of_mono_of_nonzero h)
theorem id_nonzero (X : C) [Simple.{v} X] : 𝟙 X ≠ 0 :=
(Simple.mono_isIso_iff_nonzero (𝟙 X)).mp (by infer_instance)
instance (X : C) [Simple.{v} X] : Nontrivial (End X) :=
nontrivial_of_ne 1 _ (id_nonzero X)
section
theorem Simple.not_isZero (X : C) [Simple X] : ¬IsZero X := by
simpa [Limits.IsZero.iff_id_eq_zero] using id_nonzero X
variable [HasZeroObject C]
open ZeroObject
variable (C)
/-- We don't want the definition of 'simple' to include the zero object, so we check that here. -/
theorem zero_not_simple [Simple (0 : C)] : False :=
(Simple.mono_isIso_iff_nonzero (0 : (0 : C) ⟶ (0 : C))).mp ⟨⟨0, by aesop_cat⟩⟩ rfl
end
end
-- We next make the dual arguments, but for this we must be in an abelian category.
section Abelian
variable [Abelian C]
/-- In an abelian category, an object satisfying the dual of the definition of a simple object is
simple. -/
theorem simple_of_cosimple (X : C) (h : ∀ {Z : C} (f : X ⟶ Z) [Epi f], IsIso f ↔ f ≠ 0) :
Simple X :=
⟨fun {Y} f I => by
classical
fconstructor
· intros
have hx := cokernel.π_of_epi f
by_contra h
subst h
exact (h _).mp (cokernel.π_of_zero _ _) hx
· intro hf
suffices Epi f by exact isIso_of_mono_of_epi _
apply Preadditive.epi_of_cokernel_zero
by_contra h'
exact cokernel_not_iso_of_nonzero hf ((h _).mpr h')⟩
/-- A nonzero epimorphism from a simple object is an isomorphism. -/
theorem isIso_of_epi_of_nonzero {X Y : C} [Simple X] {f : X ⟶ Y} [Epi f] (w : f ≠ 0) : IsIso f :=
-- `f ≠ 0` means that `kernel.ι f` is not an iso, and hence zero, and hence `f` is a mono.
haveI : Mono f :=
Preadditive.mono_of_kernel_zero (mono_to_simple_zero_of_not_iso (kernel_not_iso_of_nonzero w))
isIso_of_mono_of_epi f
theorem cokernel_zero_of_nonzero_to_simple {X Y : C} [Simple Y] {f : X ⟶ Y} (w : f ≠ 0) :
cokernel.π f = 0 := by
classical
by_contra h
haveI := isIso_of_epi_of_nonzero h
exact w (eq_zero_of_mono_cokernel f)
theorem epi_from_simple_zero_of_not_iso {X Y : C} [Simple X] {f : X ⟶ Y} [Epi f]
(w : IsIso f → False) : f = 0 := by
classical
by_contra h
exact w (isIso_of_epi_of_nonzero h)
end Abelian
section Indecomposable
variable [Preadditive C] [HasBinaryBiproducts C]
-- There are another three potential variations of this lemma,
-- but as any one suffices to prove `indecomposable_of_simple` we will not give them all.
theorem Biprod.isIso_inl_iff_isZero (X Y : C) : IsIso (biprod.inl : X ⟶ X ⊞ Y) ↔ IsZero Y := by
rw [biprod.isIso_inl_iff_id_eq_fst_comp_inl, ← biprod.total, add_right_eq_self]
constructor
· intro h
replace h := h =≫ biprod.snd
simpa [← IsZero.iff_isSplitEpi_eq_zero (biprod.snd : X ⊞ Y ⟶ Y)] using h
· intro h
rw [IsZero.iff_isSplitEpi_eq_zero (biprod.snd : X ⊞ Y ⟶ Y)] at h
rw [h, zero_comp]
/-- Any simple object in a preadditive category is indecomposable. -/
theorem indecomposable_of_simple (X : C) [Simple X] : Indecomposable X :=
⟨Simple.not_isZero X, fun Y Z i => by
refine or_iff_not_imp_left.mpr fun h => ?_
rw [IsZero.iff_isSplitMono_eq_zero (biprod.inl : Y ⟶ Y ⊞ Z)] at h
change biprod.inl ≠ 0 at h
have : Simple (Y ⊞ Z) := Simple.of_iso i.symm -- Porting note: this instance is needed
rw [← Simple.mono_isIso_iff_nonzero biprod.inl] at h
rwa [Biprod.isIso_inl_iff_isZero] at h⟩
end Indecomposable
section Subobject
variable [HasZeroMorphisms C] [HasZeroObject C]
open ZeroObject
open Subobject
instance {X : C} [Simple X] : Nontrivial (Subobject X) :=
nontrivial_of_not_isZero (Simple.not_isZero X)
instance {X : C} [Simple X] : IsSimpleOrder (Subobject X) where
eq_bot_or_eq_top := by
rintro ⟨⟨⟨Y : C, ⟨⟨⟩⟩, f : Y ⟶ X⟩, m : Mono f⟩⟩
change mk f = ⊥ ∨ mk f = ⊤
by_cases h : f = 0
· exact Or.inl (mk_eq_bot_iff_zero.mpr h)
· refine Or.inr ((isIso_iff_mk_eq_top _).mp ((Simple.mono_isIso_iff_nonzero f).mpr h))
/-- If `X` has subobject lattice `{⊥, ⊤}`, then `X` is simple. -/
theorem simple_of_isSimpleOrder_subobject (X : C) [IsSimpleOrder (Subobject X)] : Simple X := by
constructor; intros Y f hf; constructor
· intro i
rw [Subobject.isIso_iff_mk_eq_top] at i
intro w
rw [← Subobject.mk_eq_bot_iff_zero] at w
exact IsSimpleOrder.bot_ne_top (w.symm.trans i)
· intro i
rcases IsSimpleOrder.eq_bot_or_eq_top (Subobject.mk f) with (h | h)
· rw [Subobject.mk_eq_bot_iff_zero] at h
exact False.elim (i h)
· exact (Subobject.isIso_iff_mk_eq_top _).mpr h
/-- `X` is simple iff it has subobject lattice `{⊥, ⊤}`. -/
theorem simple_iff_subobject_isSimpleOrder (X : C) : Simple X ↔ IsSimpleOrder (Subobject X) :=
⟨by
intro h
infer_instance, by
intro h
exact simple_of_isSimpleOrder_subobject X⟩
/-- A subobject is simple iff it is an atom in the subobject lattice. -/
theorem subobject_simple_iff_isAtom {X : C} (Y : Subobject X) : Simple (Y : C) ↔ IsAtom Y :=
(simple_iff_subobject_isSimpleOrder _).trans
((OrderIso.isSimpleOrder_iff (subobjectOrderIso Y)).trans Set.isSimpleOrder_Iic_iff_isAtom)
end Subobject
end CategoryTheory
|
CategoryTheory\SingleObj.lean | /-
Copyright (c) 2019 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.CategoryTheory.Endomorphism
import Mathlib.CategoryTheory.FinCategory.Basic
import Mathlib.CategoryTheory.Category.Cat
import Mathlib.Algebra.Category.MonCat.Basic
import Mathlib.Combinatorics.Quiver.SingleObj
import Mathlib.Algebra.Group.Units.Equiv
/-!
# Single-object category
Single object category with a given monoid of endomorphisms.
It is defined to facilitate transferring some definitions and lemmas (e.g., conjugacy etc.)
from category theory to monoids and groups.
## Main definitions
Given a type `M` with a monoid structure, `SingleObj M` is `Unit` type with `Category` structure
such that `End (SingleObj M).star` is the monoid `M`. This can be extended to a functor
`MonCat ⥤ Cat`.
If `M` is a group, then `SingleObj M` is a groupoid.
An element `x : M` can be reinterpreted as an element of `End (SingleObj.star M)` using
`SingleObj.toEnd`.
## Implementation notes
- `categoryStruct.comp` on `End (SingleObj.star M)` is `flip (*)`, not `(*)`. This way
multiplication on `End` agrees with the multiplication on `M`.
- By default, Lean puts instances into `CategoryTheory` namespace instead of
`CategoryTheory.SingleObj`, so we give all names explicitly.
-/
universe u v w
namespace CategoryTheory
/-- Abbreviation that allows writing `CategoryTheory.SingleObj` rather than `Quiver.SingleObj`.
-/
abbrev SingleObj :=
Quiver.SingleObj
namespace SingleObj
variable (M G : Type u)
/-- One and `flip (*)` become `id` and `comp` for morphisms of the single object category. -/
instance categoryStruct [One M] [Mul M] : CategoryStruct (SingleObj M) where
Hom _ _ := M
comp x y := y * x
id _ := 1
variable [Monoid M] [Group G]
/-- Monoid laws become category laws for the single object category. -/
instance category : Category (SingleObj M) where
comp_id := one_mul
id_comp := mul_one
assoc x y z := (mul_assoc z y x).symm
theorem id_as_one (x : SingleObj M) : 𝟙 x = 1 :=
rfl
theorem comp_as_mul {x y z : SingleObj M} (f : x ⟶ y) (g : y ⟶ z) : f ≫ g = g * f :=
rfl
/-- If `M` is finite and in universe zero, then `SingleObj M` is a `FinCategory`. -/
instance finCategoryOfFintype (M : Type) [Fintype M] [Monoid M] : FinCategory (SingleObj M) where
/-- Groupoid structure on `SingleObj M`.
See <https://stacks.math.columbia.edu/tag/0019>.
-/
instance groupoid : Groupoid (SingleObj G) where
inv x := x⁻¹
inv_comp := mul_right_inv
comp_inv := mul_left_inv
theorem inv_as_inv {x y : SingleObj G} (f : x ⟶ y) : inv f = f⁻¹ := by
apply IsIso.inv_eq_of_hom_inv_id
rw [comp_as_mul, inv_mul_self, id_as_one]
/-- Abbreviation that allows writing `CategoryTheory.SingleObj.star` rather than
`Quiver.SingleObj.star`.
-/
abbrev star : SingleObj M :=
Quiver.SingleObj.star M
/-- The endomorphisms monoid of the only object in `SingleObj M` is equivalent to the original
monoid M. -/
def toEnd : M ≃* End (SingleObj.star M) :=
{ Equiv.refl M with map_mul' := fun _ _ => rfl }
theorem toEnd_def (x : M) : toEnd M x = x :=
rfl
variable (N : Type v) [Monoid N]
/-- There is a 1-1 correspondence between monoid homomorphisms `M → N` and functors between the
corresponding single-object categories. It means that `SingleObj` is a fully faithful
functor.
See <https://stacks.math.columbia.edu/tag/001F> --
although we do not characterize when the functor is full or faithful.
-/
def mapHom : (M →* N) ≃ SingleObj M ⥤ SingleObj N where
toFun f :=
{ obj := id
map := ⇑f
map_id := fun _ => f.map_one
map_comp := fun x y => f.map_mul y x }
invFun f :=
{ toFun := fun x => f.map ((toEnd M) x)
map_one' := f.map_id _
map_mul' := fun x y => f.map_comp y x }
left_inv := by aesop_cat
right_inv := by aesop_cat
theorem mapHom_id : mapHom M M (MonoidHom.id M) = 𝟭 _ :=
rfl
variable {M N G}
theorem mapHom_comp (f : M →* N) {P : Type w} [Monoid P] (g : N →* P) :
mapHom M P (g.comp f) = mapHom M N f ⋙ mapHom N P g :=
rfl
variable {C : Type v} [Category.{w} C]
/-- Given a function `f : C → G` from a category to a group, we get a functor
`C ⥤ G` sending any morphism `x ⟶ y` to `f y * (f x)⁻¹`. -/
@[simps]
def differenceFunctor (f : C → G) : C ⥤ SingleObj G where
obj _ := ()
map {x y} _ := f y * (f x)⁻¹
map_id := by
intro
simp only [SingleObj.id_as_one, mul_right_inv]
map_comp := by
intros
dsimp
rw [SingleObj.comp_as_mul, ← mul_assoc, mul_left_inj, mul_assoc, inv_mul_self, mul_one]
/-- A monoid homomorphism `f: M → End X` into the endomorphisms of an object `X` of a category `C`
induces a functor `SingleObj M ⥤ C`. -/
@[simps]
def functor {X : C} (f : M →* End X) : SingleObj M ⥤ C where
obj _ := X
map a := f a
map_id _ := MonoidHom.map_one f
map_comp a b := MonoidHom.map_mul f b a
/-- Construct a natural transformation between functors `SingleObj M ⥤ C` by
giving a compatible morphism `SingleObj.star M`. -/
@[simps]
def natTrans {F G : SingleObj M ⥤ C} (u : F.obj (SingleObj.star M) ⟶ G.obj (SingleObj.star M))
(h : ∀ a : M, F.map a ≫ u = u ≫ G.map a) : F ⟶ G where
app _ := u
naturality _ _ a := h a
end SingleObj
end CategoryTheory
open CategoryTheory
namespace MonoidHom
variable {M : Type u} {N : Type v} [Monoid M] [Monoid N]
/-- Reinterpret a monoid homomorphism `f : M → N` as a functor `(single_obj M) ⥤ (single_obj N)`.
See also `CategoryTheory.SingleObj.mapHom` for an equivalence between these types. -/
abbrev toFunctor (f : M →* N) : SingleObj M ⥤ SingleObj N :=
SingleObj.mapHom M N f
@[simp]
theorem comp_toFunctor (f : M →* N) {P : Type w} [Monoid P] (g : N →* P) :
(g.comp f).toFunctor = f.toFunctor ⋙ g.toFunctor :=
rfl
variable (M)
@[simp]
theorem id_toFunctor : (id M).toFunctor = 𝟭 _ :=
rfl
end MonoidHom
namespace MulEquiv
variable {M : Type u} {N : Type v} [Monoid M] [Monoid N]
/-- Reinterpret a monoid isomorphism `f : M ≃* N` as an equivalence `SingleObj M ≌ SingleObj N`. -/
@[simps!]
def toSingleObjEquiv (e : M ≃* N) : SingleObj M ≌ SingleObj N where
functor := e.toMonoidHom.toFunctor
inverse := e.symm.toMonoidHom.toFunctor
unitIso := eqToIso (by
rw [← MonoidHom.comp_toFunctor, ← MonoidHom.id_toFunctor]
congr 1
aesop_cat)
counitIso := eqToIso (by
rw [← MonoidHom.comp_toFunctor, ← MonoidHom.id_toFunctor]
congr 1
aesop_cat)
end MulEquiv
namespace Units
variable (M : Type u) [Monoid M]
/-- The units in a monoid are (multiplicatively) equivalent to
the automorphisms of `star` when we think of the monoid as a single-object category. -/
def toAut : Mˣ ≃* Aut (SingleObj.star M) :=
MulEquiv.trans (Units.mapEquiv (SingleObj.toEnd M))
(Aut.unitsEndEquivAut (SingleObj.star M))
@[simp]
theorem toAut_hom (x : Mˣ) : (toAut M x).hom = SingleObj.toEnd M x :=
rfl
@[simp]
theorem toAut_inv (x : Mˣ) : (toAut M x).inv = SingleObj.toEnd M (x⁻¹ : Mˣ) :=
rfl
end Units
namespace MonCat
open CategoryTheory
/-- The fully faithful functor from `MonCat` to `Cat`. -/
def toCat : MonCat ⥤ Cat where
obj x := Cat.of (SingleObj x)
map {x y} f := SingleObj.mapHom x y f
instance toCat_full : toCat.Full where
map_surjective := (SingleObj.mapHom _ _).surjective
instance toCat_faithful : toCat.Faithful where
map_injective h := by rwa [toCat, (SingleObj.mapHom _ _).apply_eq_iff_eq] at h
end MonCat
|
CategoryTheory\Skeletal.lean | /-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import Mathlib.CategoryTheory.Adjunction.Basic
import Mathlib.CategoryTheory.Category.Preorder
import Mathlib.CategoryTheory.IsomorphismClasses
import Mathlib.CategoryTheory.Thin
/-!
# Skeleton of a category
Define skeletal categories as categories in which any two isomorphic objects are equal.
Construct the skeleton of an arbitrary category by taking isomorphism classes, and show it is a
skeleton of the original category.
In addition, construct the skeleton of a thin category as a partial ordering, and (noncomputably)
show it is a skeleton of the original category. The advantage of this special case being handled
separately is that lemmas and definitions about orderings can be used directly, for example for the
subobject lattice. In addition, some of the commutative diagrams about the functors commute
definitionally on the nose which is convenient in practice.
-/
universe v₁ v₂ v₃ u₁ u₂ u₃
namespace CategoryTheory
open Category
variable (C : Type u₁) [Category.{v₁} C]
variable (D : Type u₂) [Category.{v₂} D]
variable {E : Type u₃} [Category.{v₃} E]
/-- A category is skeletal if isomorphic objects are equal. -/
def Skeletal : Prop :=
∀ ⦃X Y : C⦄, IsIsomorphic X Y → X = Y
/-- `IsSkeletonOf C D F` says that `F : D ⥤ C` exhibits `D` as a skeletal full subcategory of `C`,
in particular `F` is a (strong) equivalence and `D` is skeletal.
-/
structure IsSkeletonOf (F : D ⥤ C) : Prop where
/-- The category `D` has isomorphic objects equal -/
skel : Skeletal D
/-- The functor `F` is an equivalence -/
eqv : F.IsEquivalence := by infer_instance
attribute [local instance] isIsomorphicSetoid
variable {C D}
/-- If `C` is thin and skeletal, then any naturally isomorphic functors to `C` are equal. -/
theorem Functor.eq_of_iso {F₁ F₂ : D ⥤ C} [Quiver.IsThin C] (hC : Skeletal C) (hF : F₁ ≅ F₂) :
F₁ = F₂ :=
Functor.ext (fun X => hC ⟨hF.app X⟩) fun _ _ _ => Subsingleton.elim _ _
/-- If `C` is thin and skeletal, `D ⥤ C` is skeletal.
`CategoryTheory.functor_thin` shows it is thin also.
-/
theorem functor_skeletal [Quiver.IsThin C] (hC : Skeletal C) : Skeletal (D ⥤ C) := fun _ _ h =>
h.elim (Functor.eq_of_iso hC)
variable (C D)
/-- Construct the skeleton category as the induced category on the isomorphism classes, and derive
its category structure.
-/
def Skeleton : Type u₁ := InducedCategory C Quotient.out
instance [Inhabited C] : Inhabited (Skeleton C) :=
⟨⟦default⟧⟩
-- Porting note: previously `Skeleton` used `deriving Category`
noncomputable instance : Category (Skeleton C) := by
apply InducedCategory.category
/-- The functor from the skeleton of `C` to `C`. -/
@[simps!]
noncomputable def fromSkeleton : Skeleton C ⥤ C :=
inducedFunctor _
-- Porting note: previously `fromSkeleton` used `deriving Faithful, Full`
noncomputable instance : (fromSkeleton C).Full := by
apply InducedCategory.full
noncomputable instance : (fromSkeleton C).Faithful := by
apply InducedCategory.faithful
instance : (fromSkeleton C).EssSurj where mem_essImage X := ⟨Quotient.mk' X, Quotient.mk_out X⟩
-- Porting note: named this instance
noncomputable instance fromSkeleton.isEquivalence : (fromSkeleton C).IsEquivalence where
/-- The equivalence between the skeleton and the category itself. -/
noncomputable def skeletonEquivalence : Skeleton C ≌ C :=
(fromSkeleton C).asEquivalence
theorem skeleton_skeletal : Skeletal (Skeleton C) := by
rintro X Y ⟨h⟩
have : X.out ≈ Y.out := ⟨(fromSkeleton C).mapIso h⟩
simpa using Quotient.sound this
/-- The `skeleton` of `C` given by choice is a skeleton of `C`. -/
lemma skeleton_isSkeleton : IsSkeletonOf C (Skeleton C) (fromSkeleton C) where
skel := skeleton_skeletal C
eqv := fromSkeleton.isEquivalence C
section
variable {C D}
/-- Two categories which are categorically equivalent have skeletons with equivalent objects.
-/
noncomputable def Equivalence.skeletonEquiv (e : C ≌ D) : Skeleton C ≃ Skeleton D :=
let f := ((skeletonEquivalence C).trans e).trans (skeletonEquivalence D).symm
{ toFun := f.functor.obj
invFun := f.inverse.obj
left_inv := fun X => skeleton_skeletal C ⟨(f.unitIso.app X).symm⟩
right_inv := fun Y => skeleton_skeletal D ⟨f.counitIso.app Y⟩ }
end
/-- Construct the skeleton category by taking the quotient of objects. This construction gives a
preorder with nice definitional properties, but is only really appropriate for thin categories.
If your original category is not thin, you probably want to be using `skeleton` instead of this.
-/
def ThinSkeleton : Type u₁ :=
Quotient (isIsomorphicSetoid C)
instance inhabitedThinSkeleton [Inhabited C] : Inhabited (ThinSkeleton C) :=
⟨@Quotient.mk' C (isIsomorphicSetoid C) default⟩
instance ThinSkeleton.preorder : Preorder (ThinSkeleton C) where
le :=
@Quotient.lift₂ C C _ (isIsomorphicSetoid C) (isIsomorphicSetoid C)
(fun X Y => Nonempty (X ⟶ Y))
(by
rintro _ _ _ _ ⟨i₁⟩ ⟨i₂⟩
exact
propext
⟨Nonempty.map fun f => i₁.inv ≫ f ≫ i₂.hom,
Nonempty.map fun f => i₁.hom ≫ f ≫ i₂.inv⟩)
le_refl := by
refine Quotient.ind fun a => ?_
exact ⟨𝟙 _⟩
le_trans a b c := Quotient.inductionOn₃ a b c fun A B C => Nonempty.map2 (· ≫ ·)
/-- The functor from a category to its thin skeleton. -/
@[simps]
def toThinSkeleton : C ⥤ ThinSkeleton C where
obj := @Quotient.mk' C _
map f := homOfLE (Nonempty.intro f)
/-!
The constructions here are intended to be used when the category `C` is thin, even though
some of the statements can be shown without this assumption.
-/
namespace ThinSkeleton
/-- The thin skeleton is thin. -/
instance thin : Quiver.IsThin (ThinSkeleton C) := fun _ _ =>
⟨by
rintro ⟨⟨f₁⟩⟩ ⟨⟨_⟩⟩
rfl⟩
variable {C} {D}
/-- A functor `C ⥤ D` computably lowers to a functor `ThinSkeleton C ⥤ ThinSkeleton D`. -/
@[simps]
def map (F : C ⥤ D) : ThinSkeleton C ⥤ ThinSkeleton D where
obj := Quotient.map F.obj fun X₁ X₂ ⟨hX⟩ => ⟨F.mapIso hX⟩
map {X} {Y} := Quotient.recOnSubsingleton₂ X Y fun x y k => homOfLE (k.le.elim fun t => ⟨F.map t⟩)
theorem comp_toThinSkeleton (F : C ⥤ D) : F ⋙ toThinSkeleton D = toThinSkeleton C ⋙ map F :=
rfl
/-- Given a natural transformation `F₁ ⟶ F₂`, induce a natural transformation `map F₁ ⟶ map F₂`. -/
def mapNatTrans {F₁ F₂ : C ⥤ D} (k : F₁ ⟶ F₂) : map F₁ ⟶ map F₂ where
app X := Quotient.recOnSubsingleton X fun x => ⟨⟨⟨k.app x⟩⟩⟩
/- Porting note: `map₂ObjMap`, `map₂Functor`, and `map₂NatTrans` were all extracted
from the original `map₂` proof. Lean needed an extensive amount explicit type
annotations to figure things out. This also translated into repeated deterministic
timeouts. The extracted defs allow for explicit motives for the multiple
descents to the quotients.
It would be better to prove that
`ThinSkeleton (C × D) ≌ ThinSkeleton C × ThinSkeleton D`
which is more immediate from comparing the preorders. Then one could get
`map₂` by currying.
-/
/-- Given a bifunctor, we descend to a function on objects of `ThinSkeleton` -/
def map₂ObjMap (F : C ⥤ D ⥤ E) : ThinSkeleton C → ThinSkeleton D → ThinSkeleton E :=
fun x y =>
@Quotient.map₂ C D (isIsomorphicSetoid C) (isIsomorphicSetoid D) E (isIsomorphicSetoid E)
(fun X Y => (F.obj X).obj Y)
(fun X₁ _ ⟨hX⟩ _ Y₂ ⟨hY⟩ => ⟨(F.obj X₁).mapIso hY ≪≫ (F.mapIso hX).app Y₂⟩) x y
/-- For each `x : ThinSkeleton C`, we promote `map₂ObjMap F x` to a functor -/
def map₂Functor (F : C ⥤ D ⥤ E) : ThinSkeleton C → ThinSkeleton D ⥤ ThinSkeleton E :=
fun x =>
{ obj := fun y => map₂ObjMap F x y
map := fun {y₁} {y₂} => @Quotient.recOnSubsingleton C (isIsomorphicSetoid C)
(fun x => (y₁ ⟶ y₂) → (map₂ObjMap F x y₁ ⟶ map₂ObjMap F x y₂)) _ x fun X
=> Quotient.recOnSubsingleton₂ y₁ y₂ fun Y₁ Y₂ hY =>
homOfLE (hY.le.elim fun g => ⟨(F.obj X).map g⟩) }
/-- This provides natural transformations `map₂Functor F x₁ ⟶ map₂Functor F x₂` given
`x₁ ⟶ x₂` -/
def map₂NatTrans (F : C ⥤ D ⥤ E) : {x₁ x₂ : ThinSkeleton C} → (x₁ ⟶ x₂) →
(map₂Functor F x₁ ⟶ map₂Functor F x₂) := fun {x₁} {x₂} =>
@Quotient.recOnSubsingleton₂ C C (isIsomorphicSetoid C) (isIsomorphicSetoid C)
(fun x x' : ThinSkeleton C => (x ⟶ x') → (map₂Functor F x ⟶ map₂Functor F x')) _ x₁ x₂
(fun X₁ X₂ f => { app := fun y =>
Quotient.recOnSubsingleton y fun Y => homOfLE (f.le.elim fun f' => ⟨(F.map f').app Y⟩) })
-- TODO: state the lemmas about what happens when you compose with `toThinSkeleton`
/-- A functor `C ⥤ D ⥤ E` computably lowers to a functor
`ThinSkeleton C ⥤ ThinSkeleton D ⥤ ThinSkeleton E` -/
@[simps]
def map₂ (F : C ⥤ D ⥤ E) : ThinSkeleton C ⥤ ThinSkeleton D ⥤ ThinSkeleton E where
obj := map₂Functor F
map := map₂NatTrans F
variable (C)
section
variable [Quiver.IsThin C]
instance toThinSkeleton_faithful : (toThinSkeleton C).Faithful where
/-- Use `Quotient.out` to create a functor out of the thin skeleton. -/
@[simps]
noncomputable def fromThinSkeleton : ThinSkeleton C ⥤ C where
obj := Quotient.out
map {x} {y} :=
Quotient.recOnSubsingleton₂ x y fun X Y f =>
(Nonempty.some (Quotient.mk_out X)).hom ≫ f.le.some ≫ (Nonempty.some (Quotient.mk_out Y)).inv
/-- The equivalence between the thin skeleton and the category itself. -/
noncomputable def equivalence : ThinSkeleton C ≌ C where
functor := fromThinSkeleton C
inverse := toThinSkeleton C
counitIso := NatIso.ofComponents fun X => Nonempty.some (Quotient.mk_out X)
unitIso := NatIso.ofComponents fun x => Quotient.recOnSubsingleton x fun X =>
eqToIso (Quotient.sound ⟨(Nonempty.some (Quotient.mk_out X)).symm⟩)
noncomputable instance fromThinSkeleton_isEquivalence : (fromThinSkeleton C).IsEquivalence :=
(equivalence C).isEquivalence_functor
variable {C}
theorem equiv_of_both_ways {X Y : C} (f : X ⟶ Y) (g : Y ⟶ X) : X ≈ Y :=
⟨iso_of_both_ways f g⟩
instance thinSkeletonPartialOrder : PartialOrder (ThinSkeleton C) :=
{ CategoryTheory.ThinSkeleton.preorder C with
le_antisymm :=
Quotient.ind₂
(by
rintro _ _ ⟨f⟩ ⟨g⟩
apply Quotient.sound (equiv_of_both_ways f g)) }
theorem skeletal : Skeletal (ThinSkeleton C) := fun X Y =>
Quotient.inductionOn₂ X Y fun _ _ h => h.elim fun i => i.1.le.antisymm i.2.le
theorem map_comp_eq (F : E ⥤ D) (G : D ⥤ C) : map (F ⋙ G) = map F ⋙ map G :=
Functor.eq_of_iso skeletal <|
NatIso.ofComponents fun X => Quotient.recOnSubsingleton X fun x => Iso.refl _
theorem map_id_eq : map (𝟭 C) = 𝟭 (ThinSkeleton C) :=
Functor.eq_of_iso skeletal <|
NatIso.ofComponents fun X => Quotient.recOnSubsingleton X fun x => Iso.refl _
theorem map_iso_eq {F₁ F₂ : D ⥤ C} (h : F₁ ≅ F₂) : map F₁ = map F₂ :=
Functor.eq_of_iso skeletal
{ hom := mapNatTrans h.hom
inv := mapNatTrans h.inv }
/-- `fromThinSkeleton C` exhibits the thin skeleton as a skeleton. -/
lemma thinSkeleton_isSkeleton : IsSkeletonOf C (ThinSkeleton C) (fromThinSkeleton C) where
skel := skeletal
instance isSkeletonOfInhabited :
Inhabited (IsSkeletonOf C (ThinSkeleton C) (fromThinSkeleton C)) :=
⟨thinSkeleton_isSkeleton⟩
end
variable {C}
/-- An adjunction between thin categories gives an adjunction between their thin skeletons. -/
def lowerAdjunction (R : D ⥤ C) (L : C ⥤ D) (h : L ⊣ R) : ThinSkeleton.map L ⊣ ThinSkeleton.map R :=
Adjunction.mkOfUnitCounit
{ unit :=
{
app := fun X => by
letI := isIsomorphicSetoid C
exact Quotient.recOnSubsingleton X fun x => homOfLE ⟨h.unit.app x⟩ }
-- TODO: make quotient.rec_on_subsingleton' so the letI isn't needed
counit :=
{
app := fun X => by
letI := isIsomorphicSetoid D
exact Quotient.recOnSubsingleton X fun x => homOfLE ⟨h.counit.app x⟩ } }
end ThinSkeleton
open ThinSkeleton
section
variable {C} {α : Type*} [PartialOrder α]
/--
When `e : C ≌ α` is a categorical equivalence from a thin category `C` to some partial order `α`,
the `ThinSkeleton C` is order isomorphic to `α`.
-/
noncomputable def Equivalence.thinSkeletonOrderIso [Quiver.IsThin C] (e : C ≌ α) :
ThinSkeleton C ≃o α :=
((ThinSkeleton.equivalence C).trans e).toOrderIso
end
end CategoryTheory
|
CategoryTheory\Square.lean | /-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.CategoryTheory.Comma.Arrow
import Mathlib.CategoryTheory.CommSq
/-!
# The category of commutative squares
In this file, we define a bundled version of `CommSq`
which allows to consider commutative squares as
objects in a category `Square C`.
The four objects in a commutative square are
numbered as follows:
```
X₁ --> X₂
| |
v v
X₃ --> X₄
```
We define the flip functor, and two equivalences with
the category `Arrow (Arrow C)`, depending on whether
we consider a commutative square as a horizontal
morphism between two vertical maps (`arrowArrowEquivalence`)
or a vertical morphism betwen two horizontal
maps (`arrowArrowEquivalence'`).
-/
universe v v' u u'
namespace CategoryTheory
open Category
variable (C : Type u) [Category.{v} C] {D : Type u'} [Category.{v'} D]
/-- The category of commutative squares in a category. -/
structure Square where
/-- the top-left object -/
{X₁ : C}
/-- the top-right object -/
{X₂ : C}
/-- the bottom-left object -/
{X₃ : C}
/-- the bottom-right object -/
{X₄ : C}
/-- the top morphism -/
f₁₂ : X₁ ⟶ X₂
/-- the left morphism -/
f₁₃ : X₁ ⟶ X₃
/-- the right morphism -/
f₂₄ : X₂ ⟶ X₄
/-- the bottom morphism -/
f₃₄ : X₃ ⟶ X₄
fac : f₁₂ ≫ f₂₄ = f₁₃ ≫ f₃₄
namespace Square
variable {C}
lemma commSq (sq : Square C) : CommSq sq.f₁₂ sq.f₁₃ sq.f₂₄ sq.f₃₄ where
w := sq.fac
/-- A morphism between two commutative squares consists of 4 morphisms
which extend these two squares into a commuting cube. -/
@[ext]
structure Hom (sq₁ sq₂ : Square C) where
/-- the top-left morphism -/
τ₁ : sq₁.X₁ ⟶ sq₂.X₁
/-- the top-right morphism -/
τ₂ : sq₁.X₂ ⟶ sq₂.X₂
/-- the bottom-left morphism -/
τ₃ : sq₁.X₃ ⟶ sq₂.X₃
/-- the bottom-right morphism -/
τ₄ : sq₁.X₄ ⟶ sq₂.X₄
comm₁₂ : sq₁.f₁₂ ≫ τ₂ = τ₁ ≫ sq₂.f₁₂ := by aesop_cat
comm₁₃ : sq₁.f₁₃ ≫ τ₃ = τ₁ ≫ sq₂.f₁₃ := by aesop_cat
comm₂₄ : sq₁.f₂₄ ≫ τ₄ = τ₂ ≫ sq₂.f₂₄ := by aesop_cat
comm₃₄ : sq₁.f₃₄ ≫ τ₄ = τ₃ ≫ sq₂.f₃₄ := by aesop_cat
namespace Hom
attribute [reassoc (attr := simp)] comm₁₂ comm₁₃ comm₂₄ comm₃₄
/-- The identity of a commutative square. -/
@[simps]
def id (sq : Square C) : Hom sq sq where
τ₁ := 𝟙 _
τ₂ := 𝟙 _
τ₃ := 𝟙 _
τ₄ := 𝟙 _
/-- The composition of morphisms of squares. -/
@[simps]
def comp {sq₁ sq₂ sq₃ : Square C} (f : Hom sq₁ sq₂) (g : Hom sq₂ sq₃) : Hom sq₁ sq₃ where
τ₁ := f.τ₁ ≫ g.τ₁
τ₂ := f.τ₂ ≫ g.τ₂
τ₃ := f.τ₃ ≫ g.τ₃
τ₄ := f.τ₄ ≫ g.τ₄
end Hom
@[simps!]
instance category : Category (Square C) where
Hom := Hom
id := Hom.id
comp := Hom.comp
@[ext]
lemma hom_ext {sq₁ sq₂ : Square C} {f g : sq₁ ⟶ sq₂}
(h₁ : f.τ₁ = g.τ₁) (h₂ : f.τ₂ = g.τ₂)
(h₃ : f.τ₃ = g.τ₃) (h₄ : f.τ₄ = g.τ₄) : f = g :=
Hom.ext h₁ h₂ h₃ h₄
/-- Constructor for isomorphisms in `Square c` -/
def isoMk {sq₁ sq₂ : Square C} (e₁ : sq₁.X₁ ≅ sq₂.X₁) (e₂ : sq₁.X₂ ≅ sq₂.X₂)
(e₃ : sq₁.X₃ ≅ sq₂.X₃) (e₄ : sq₁.X₄ ≅ sq₂.X₄)
(comm₁₂ : sq₁.f₁₂ ≫ e₂.hom = e₁.hom ≫ sq₂.f₁₂)
(comm₁₃ : sq₁.f₁₃ ≫ e₃.hom = e₁.hom ≫ sq₂.f₁₃)
(comm₂₄ : sq₁.f₂₄ ≫ e₄.hom = e₂.hom ≫ sq₂.f₂₄)
(comm₃₄ : sq₁.f₃₄ ≫ e₄.hom = e₃.hom ≫ sq₂.f₃₄) :
sq₁ ≅ sq₂ where
hom :=
{ τ₁ := e₁.hom
τ₂ := e₂.hom
τ₃ := e₃.hom
τ₄ := e₄.hom }
inv :=
{ τ₁ := e₁.inv
τ₂ := e₂.inv
τ₃ := e₃.inv
τ₄ := e₄.inv
comm₁₂ := by simp only [← cancel_mono e₂.hom, assoc, Iso.inv_hom_id,
comp_id, comm₁₂, Iso.inv_hom_id_assoc]
comm₁₃ := by simp only [← cancel_mono e₃.hom, assoc, Iso.inv_hom_id,
comp_id, comm₁₃, Iso.inv_hom_id_assoc]
comm₂₄ := by simp only [← cancel_mono e₄.hom, assoc, Iso.inv_hom_id,
comp_id, comm₂₄, Iso.inv_hom_id_assoc]
comm₃₄ := by simp only [← cancel_mono e₄.hom, assoc, Iso.inv_hom_id,
comp_id, comm₃₄, Iso.inv_hom_id_assoc] }
/-- Flipping a square by switching the top-right and the bottom-left objects. -/
@[simps]
def flip (sq : Square C) : Square C where
fac := sq.fac.symm
/-- The functor which flips commutative squares. -/
@[simps]
def flipFunctor : Square C ⥤ Square C where
obj := flip
map φ :=
{ τ₁ := φ.τ₁
τ₂ := φ.τ₃
τ₃ := φ.τ₂
τ₄ := φ.τ₄ }
/-- Flipping commutative squares is an auto-equivalence. -/
@[simps]
def flipEquivalence : Square C ≌ Square C where
functor := flipFunctor
inverse := flipFunctor
unitIso := Iso.refl _
counitIso := Iso.refl _
/-- The functor `Square C ⥤ Arrow (Arrow C)` which sends a
commutative square `sq` to the obvious arrow from the left morphism of `sq`
to the right morphism of `sq`. -/
@[simps!]
def toArrowArrowFunctor : Square C ⥤ Arrow (Arrow C) where
obj sq := Arrow.mk (Arrow.homMk sq.fac : Arrow.mk sq.f₁₃ ⟶ Arrow.mk sq.f₂₄)
map φ := Arrow.homMk (u := Arrow.homMk φ.comm₁₃.symm)
(v := Arrow.homMk φ.comm₂₄.symm) (by aesop_cat)
/-- The functor `Arrow (Arrow C) ⥤ Square C` which sends
a morphism `Arrow.mk f ⟶ Arrow.mk g` to the commutative square
with `f` on the left side and `g` on the right side. -/
@[simps!]
def fromArrowArrowFunctor : Arrow (Arrow C) ⥤ Square C where
obj f := { fac := f.hom.w }
map φ :=
{ τ₁ := φ.left.left
τ₂ := φ.right.left
τ₃ := φ.left.right
τ₄ := φ.right.right
comm₁₂ := Arrow.leftFunc.congr_map φ.w.symm
comm₁₃ := φ.left.w.symm
comm₂₄ := φ.right.w.symm
comm₃₄ := Arrow.rightFunc.congr_map φ.w.symm }
/-- The equivalence `Square C ≌ Arrow (Arrow C)` which sends a
commutative square `sq` to the obvious arrow from the left morphism of `sq`
to the right morphism of `sq`. -/
@[simps]
def arrowArrowEquivalence : Square C ≌ Arrow (Arrow C) where
functor := toArrowArrowFunctor
inverse := fromArrowArrowFunctor
unitIso := Iso.refl _
counitIso := Iso.refl _
/-- The functor `Square C ⥤ Arrow (Arrow C)` which sends a
commutative square `sq` to the obvious arrow from the top morphism of `sq`
to the bottom morphism of `sq`. -/
@[simps!]
def toArrowArrowFunctor' : Square C ⥤ Arrow (Arrow C) where
obj sq := Arrow.mk (Arrow.homMk sq.fac.symm : Arrow.mk sq.f₁₂ ⟶ Arrow.mk sq.f₃₄)
map φ := Arrow.homMk (u := Arrow.homMk φ.comm₁₂.symm)
(v := Arrow.homMk φ.comm₃₄.symm) (by aesop_cat)
/-- The functor `Arrow (Arrow C) ⥤ Square C` which sends
a morphism `Arrow.mk f ⟶ Arrow.mk g` to the commutative square
with `f` on the top side and `g` on the bottom side. -/
@[simps!]
def fromArrowArrowFunctor' : Arrow (Arrow C) ⥤ Square C where
obj f := { fac := f.hom.w.symm }
map φ :=
{ τ₁ := φ.left.left
τ₂ := φ.left.right
τ₃ := φ.right.left
τ₄ := φ.right.right
comm₁₂ := φ.left.w.symm
comm₁₃ := Arrow.leftFunc.congr_map φ.w.symm
comm₂₄ := Arrow.rightFunc.congr_map φ.w.symm
comm₃₄ := φ.right.w.symm }
/-- The equivalence `Square C ≌ Arrow (Arrow C)` which sends a
commutative square `sq` to the obvious arrow from the top morphism of `sq`
to the bottom morphism of `sq`. -/
@[simps]
def arrowArrowEquivalence' : Square C ≌ Arrow (Arrow C) where
functor := toArrowArrowFunctor'
inverse := fromArrowArrowFunctor'
unitIso := Iso.refl _
counitIso := Iso.refl _
/-- The top-left evaluation `Square C ⥤ C`. -/
@[simps]
def evaluation₁ : Square C ⥤ C where
obj sq := sq.X₁
map φ := φ.τ₁
/-- The top-right evaluation `Square C ⥤ C`. -/
@[simps]
def evaluation₂ : Square C ⥤ C where
obj sq := sq.X₂
map φ := φ.τ₂
/-- The bottom-left evaluation `Square C ⥤ C`. -/
@[simps]
def evaluation₃ : Square C ⥤ C where
obj sq := sq.X₃
map φ := φ.τ₃
/-- The bottom-right evaluation `Square C ⥤ C`. -/
@[simps]
def evaluation₄ : Square C ⥤ C where
obj sq := sq.X₄
map φ := φ.τ₄
/-- The map `Square C → Square Cᵒᵖ` which switches `X₁` and `X₃`, but
does not move `X₂` and `X₃`. -/
@[simps]
protected def op (sq : Square C) : Square Cᵒᵖ where
f₁₂ := sq.f₂₄.op
f₁₃ := sq.f₃₄.op
f₂₄ := sq.f₁₂.op
f₃₄ := sq.f₁₃.op
fac := Quiver.Hom.unop_inj sq.fac
/-- The map `Square Cᵒᵖ → Square C` which switches `X₁` and `X₃`, but
does not move `X₂` and `X₃`. -/
@[simps]
protected def unop (sq : Square Cᵒᵖ) : Square C where
f₁₂ := sq.f₂₄.unop
f₁₃ := sq.f₃₄.unop
f₂₄ := sq.f₁₂.unop
f₃₄ := sq.f₁₃.unop
fac := Quiver.Hom.op_inj sq.fac
/-- The functor `(Square C)ᵒᵖ ⥤ Square Cᵒᵖ`. -/
@[simps]
def opFunctor : (Square C)ᵒᵖ ⥤ Square Cᵒᵖ where
obj sq := sq.unop.op
map φ :=
{ τ₁ := φ.unop.τ₄.op
τ₂ := φ.unop.τ₂.op
τ₃ := φ.unop.τ₃.op
τ₄ := φ.unop.τ₁.op
comm₁₂ := Quiver.Hom.unop_inj (by simp)
comm₁₃ := Quiver.Hom.unop_inj (by simp)
comm₂₄ := Quiver.Hom.unop_inj (by simp)
comm₃₄ := Quiver.Hom.unop_inj (by simp) }
/-- The functor `(Square Cᵒᵖ)ᵒᵖ ⥤ Square Cᵒᵖ`. -/
def unopFunctor : (Square Cᵒᵖ)ᵒᵖ ⥤ Square C where
obj sq := sq.unop.unop
map φ :=
{ τ₁ := φ.unop.τ₄.unop
τ₂ := φ.unop.τ₂.unop
τ₃ := φ.unop.τ₃.unop
τ₄ := φ.unop.τ₁.unop
comm₁₂ := Quiver.Hom.op_inj (by simp)
comm₁₃ := Quiver.Hom.op_inj (by simp)
comm₂₄ := Quiver.Hom.op_inj (by simp)
comm₃₄ := Quiver.Hom.op_inj (by simp) }
/-- The equivalence `(Square C)ᵒᵖ ≌ Square Cᵒᵖ`. -/
def opEquivalence : (Square C)ᵒᵖ ≌ Square Cᵒᵖ where
functor := opFunctor
inverse := unopFunctor.rightOp
unitIso := Iso.refl _
counitIso := Iso.refl _
/-- The image of a commutative square by a functor. -/
@[simps]
def map (sq : Square C) (F : C ⥤ D) : Square D where
f₁₂ := F.map sq.f₁₂
f₁₃ := F.map sq.f₁₃
f₂₄ := F.map sq.f₂₄
f₃₄ := F.map sq.f₃₄
fac := by simpa using F.congr_map sq.fac
end Square
namespace Functor
/-- The functor `Square C ⥤ Square D` induced by a functor `C ⥤ D`. -/
@[simps]
def mapSquare (F : C ⥤ D) : Square C ⥤ Square D where
obj sq := sq.map F
map φ :=
{ τ₁ := F.map φ.τ₁
τ₂ := F.map φ.τ₂
τ₃ := F.map φ.τ₃
τ₄ := F.map φ.τ₄
comm₁₂ := by simpa only [Functor.map_comp] using F.congr_map φ.comm₁₂
comm₁₃ := by simpa only [Functor.map_comp] using F.congr_map φ.comm₁₃
comm₂₄ := by simpa only [Functor.map_comp] using F.congr_map φ.comm₂₄
comm₃₄ := by simpa only [Functor.map_comp] using F.congr_map φ.comm₃₄ }
end Functor
end CategoryTheory
|
CategoryTheory\Subterminal.lean | /-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts
import Mathlib.CategoryTheory.Limits.Shapes.Terminal
import Mathlib.CategoryTheory.Subobject.MonoOver
/-!
# Subterminal objects
Subterminal objects are the objects which can be thought of as subobjects of the terminal object.
In fact, the definition can be constructed to not require a terminal object, by defining `A` to be
subterminal iff for any `Z`, there is at most one morphism `Z ⟶ A`.
An alternate definition is that the diagonal morphism `A ⟶ A ⨯ A` is an isomorphism.
In this file we define subterminal objects and show the equivalence of these three definitions.
We also construct the subcategory of subterminal objects.
## TODO
* Define exponential ideals, and show this subcategory is an exponential ideal.
* Use the above to show that in a locally cartesian closed category, every subobject lattice
is cartesian closed (equivalently, a Heyting algebra).
-/
universe v₁ v₂ u₁ u₂
noncomputable section
namespace CategoryTheory
open Limits Category
variable {C : Type u₁} [Category.{v₁} C] {A : C}
/-- An object `A` is subterminal iff for any `Z`, there is at most one morphism `Z ⟶ A`. -/
def IsSubterminal (A : C) : Prop :=
∀ ⦃Z : C⦄ (f g : Z ⟶ A), f = g
theorem IsSubterminal.def : IsSubterminal A ↔ ∀ ⦃Z : C⦄ (f g : Z ⟶ A), f = g :=
Iff.rfl
/-- If `A` is subterminal, the unique morphism from it to a terminal object is a monomorphism.
The converse of `isSubterminal_of_mono_isTerminal_from`.
-/
theorem IsSubterminal.mono_isTerminal_from (hA : IsSubterminal A) {T : C} (hT : IsTerminal T) :
Mono (hT.from A) :=
{ right_cancellation := fun _ _ _ => hA _ _ }
/-- If `A` is subterminal, the unique morphism from it to the terminal object is a monomorphism.
The converse of `isSubterminal_of_mono_terminal_from`.
-/
theorem IsSubterminal.mono_terminal_from [HasTerminal C] (hA : IsSubterminal A) :
Mono (terminal.from A) :=
hA.mono_isTerminal_from terminalIsTerminal
/-- If the unique morphism from `A` to a terminal object is a monomorphism, `A` is subterminal.
The converse of `IsSubterminal.mono_isTerminal_from`.
-/
theorem isSubterminal_of_mono_isTerminal_from {T : C} (hT : IsTerminal T) [Mono (hT.from A)] :
IsSubterminal A := fun Z f g => by
rw [← cancel_mono (hT.from A)]
apply hT.hom_ext
/-- If the unique morphism from `A` to the terminal object is a monomorphism, `A` is subterminal.
The converse of `IsSubterminal.mono_terminal_from`.
-/
theorem isSubterminal_of_mono_terminal_from [HasTerminal C] [Mono (terminal.from A)] :
IsSubterminal A := fun Z f g => by
rw [← cancel_mono (terminal.from A)]
subsingleton
theorem isSubterminal_of_isTerminal {T : C} (hT : IsTerminal T) : IsSubterminal T := fun _ _ _ =>
hT.hom_ext _ _
theorem isSubterminal_of_terminal [HasTerminal C] : IsSubterminal (⊤_ C) := fun _ _ _ => by
subsingleton
/-- If `A` is subterminal, its diagonal morphism is an isomorphism.
The converse of `isSubterminal_of_isIso_diag`.
-/
theorem IsSubterminal.isIso_diag (hA : IsSubterminal A) [HasBinaryProduct A A] : IsIso (diag A) :=
⟨⟨Limits.prod.fst,
⟨by simp, by
rw [IsSubterminal.def] at hA
aesop_cat⟩⟩⟩
/-- If the diagonal morphism of `A` is an isomorphism, then it is subterminal.
The converse of `isSubterminal.isIso_diag`.
-/
theorem isSubterminal_of_isIso_diag [HasBinaryProduct A A] [IsIso (diag A)] : IsSubterminal A :=
fun Z f g => by
have : (Limits.prod.fst : A ⨯ A ⟶ _) = Limits.prod.snd := by simp [← cancel_epi (diag A)]
rw [← prod.lift_fst f g, this, prod.lift_snd]
/-- If `A` is subterminal, it is isomorphic to `A ⨯ A`. -/
@[simps!]
def IsSubterminal.isoDiag (hA : IsSubterminal A) [HasBinaryProduct A A] : A ⨯ A ≅ A := by
letI := IsSubterminal.isIso_diag hA
apply (asIso (diag A)).symm
variable (C)
/-- The (full sub)category of subterminal objects.
TODO: If `C` is the category of sheaves on a topological space `X`, this category is equivalent
to the lattice of open subsets of `X`. More generally, if `C` is a topos, this is the lattice of
"external truth values".
-/
def Subterminals (C : Type u₁) [Category.{v₁} C] :=
FullSubcategory fun A : C => IsSubterminal A
instance (C : Type u₁) [Category.{v₁} C] :
Category (Subterminals C) := FullSubcategory.category _
instance [HasTerminal C] : Inhabited (Subterminals C) :=
⟨⟨⊤_ C, isSubterminal_of_terminal⟩⟩
/-- The inclusion of the subterminal objects into the original category. -/
@[simps!]
def subterminalInclusion : Subterminals C ⥤ C :=
fullSubcategoryInclusion _
instance (C : Type u₁) [Category.{v₁} C] : (subterminalInclusion C).Full :=
FullSubcategory.full _
instance (C : Type u₁) [Category.{v₁} C] : (subterminalInclusion C).Faithful :=
FullSubcategory.faithful _
instance subterminals_thin (X Y : Subterminals C) : Subsingleton (X ⟶ Y) :=
⟨fun f g => Y.2 f g⟩
/--
The category of subterminal objects is equivalent to the category of monomorphisms to the terminal
object (which is in turn equivalent to the subobjects of the terminal object).
-/
@[simps]
def subterminalsEquivMonoOverTerminal [HasTerminal C] : Subterminals C ≌ MonoOver (⊤_ C) where
functor :=
{ obj := fun X => ⟨Over.mk (terminal.from X.1), X.2.mono_terminal_from⟩
map := fun f => MonoOver.homMk f (by ext1 ⟨⟨⟩⟩)
map_id := fun X => rfl
map_comp := fun f g => rfl }
inverse :=
{ obj := fun X =>
⟨X.obj.left, fun Z f g => by
rw [← cancel_mono X.arrow]
subsingleton⟩
map := fun f => f.1
map_id := fun X => rfl
map_comp := fun f g => rfl }
-- Porting note: the original definition was triggering a timeout, using `NatIso.ofComponents`
-- in the definition of the natural isomorphisms makes the situation slightly better
unitIso := NatIso.ofComponents (fun X => Iso.refl X) (by subsingleton)
counitIso := NatIso.ofComponents (fun X => MonoOver.isoMk (Iso.refl _)) (by subsingleton)
functor_unitIso_comp := by subsingleton
-- With `aesop` filling the auto-params this was taking 20s or so
@[simp]
theorem subterminals_to_monoOver_terminal_comp_forget [HasTerminal C] :
(subterminalsEquivMonoOverTerminal C).functor ⋙ MonoOver.forget _ ⋙ Over.forget _ =
subterminalInclusion C :=
rfl
@[simp]
theorem monoOver_terminal_to_subterminals_comp [HasTerminal C] :
(subterminalsEquivMonoOverTerminal C).inverse ⋙ subterminalInclusion C =
MonoOver.forget _ ⋙ Over.forget _ :=
rfl
end CategoryTheory
|
CategoryTheory\Thin.lean | /-
Copyright (c) 2019 Scott Morrison, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Bhavik Mehta
-/
import Mathlib.CategoryTheory.Functor.Category
import Mathlib.CategoryTheory.Iso
/-!
# Thin categories
A thin category (also known as a sparse category) is a category with at most one morphism between
each pair of objects.
Examples include posets, but also some indexing categories (diagrams) for special shapes of
(co)limits.
To construct a category instance one only needs to specify the `category_struct` part,
as the axioms hold for free.
If `C` is thin, then the category of functors to `C` is also thin.
Further, to show two objects are isomorphic in a thin category, it suffices only to give a morphism
in each direction.
-/
universe v₁ v₂ u₁ u₂
namespace CategoryTheory
variable {C : Type u₁}
section
variable [CategoryStruct.{v₁} C] [Quiver.IsThin C]
/-- Construct a category instance from a category_struct, using the fact that
hom spaces are subsingletons to prove the axioms. -/
def thin_category : Category C where
end
-- We don't assume anything about where the category instance on `C` came from.
-- In particular this allows `C` to be a preorder, with the category instance inherited from the
-- preorder structure.
variable [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D]
variable [Quiver.IsThin C]
/-- If `C` is a thin category, then `D ⥤ C` is a thin category. -/
instance functor_thin : Quiver.IsThin (D ⥤ C) := fun _ _ =>
⟨fun α β => NatTrans.ext (by subsingleton)⟩
/-- To show `X ≅ Y` in a thin category, it suffices to just give any morphism in each direction. -/
def iso_of_both_ways {X Y : C} (f : X ⟶ Y) (g : Y ⟶ X) :
X ≅ Y where
hom := f
inv := g
instance subsingleton_iso {X Y : C} : Subsingleton (X ≅ Y) :=
⟨by
intro i₁ i₂
ext1
subsingleton⟩
end CategoryTheory
|
CategoryTheory\Types.lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Stephen Morgan, Scott Morrison, Johannes Hölzl
-/
import Mathlib.CategoryTheory.EpiMono
import Mathlib.CategoryTheory.Functor.FullyFaithful
import Mathlib.Tactic.PPWithUniv
import Mathlib.Data.Set.Defs
/-!
# The category `Type`.
In this section we set up the theory so that Lean's types and functions between them
can be viewed as a `LargeCategory` in our framework.
Lean can not transparently view a function as a morphism in this category, and needs a hint in
order to be able to type check. We provide the abbreviation `asHom f` to guide type checking,
as well as a corresponding notation `↾ f`. (Entered as `\upr `.)
We provide various simplification lemmas for functors and natural transformations valued in `Type`.
We define `uliftFunctor`, from `Type u` to `Type (max u v)`, and show that it is fully faithful
(but not, of course, essentially surjective).
We prove some basic facts about the category `Type`:
* epimorphisms are surjections and monomorphisms are injections,
* `Iso` is both `Iso` and `Equiv` to `Equiv` (at least within a fixed universe),
* every type level `IsLawfulFunctor` gives a categorical functor `Type ⥤ Type`
(the corresponding fact about monads is in `Mathlib/CategoryTheory/Monad/Types.lean`).
-/
namespace CategoryTheory
-- morphism levels before object levels. See note [CategoryTheory universes].
universe v v' w u u'
/- The `@[to_additive]` attribute is just a hint that expressions involving this instance can
still be additivized. -/
@[to_additive existing CategoryTheory.types]
instance types : LargeCategory (Type u) where
Hom a b := a → b
id a := id
comp f g := g ∘ f
theorem types_hom {α β : Type u} : (α ⟶ β) = (α → β) :=
rfl
-- porting note (#10688): this lemma was not here in Lean 3. Lean 3 `ext` would solve this goal
-- because of its "if all else fails, apply all `ext` lemmas" policy,
-- which apparently we want to move away from.
@[ext] theorem types_ext {α β : Type u} (f g : α ⟶ β) (h : ∀ a : α, f a = g a) : f = g := by
funext x
exact h x
theorem types_id (X : Type u) : 𝟙 X = id :=
rfl
theorem types_comp {X Y Z : Type u} (f : X ⟶ Y) (g : Y ⟶ Z) : f ≫ g = g ∘ f :=
rfl
@[simp]
theorem types_id_apply (X : Type u) (x : X) : (𝟙 X : X → X) x = x :=
rfl
@[simp]
theorem types_comp_apply {X Y Z : Type u} (f : X ⟶ Y) (g : Y ⟶ Z) (x : X) : (f ≫ g) x = g (f x) :=
rfl
@[simp]
theorem hom_inv_id_apply {X Y : Type u} (f : X ≅ Y) (x : X) : f.inv (f.hom x) = x :=
congr_fun f.hom_inv_id x
@[simp]
theorem inv_hom_id_apply {X Y : Type u} (f : X ≅ Y) (y : Y) : f.hom (f.inv y) = y :=
congr_fun f.inv_hom_id y
-- Unfortunately without this wrapper we can't use `CategoryTheory` idioms, such as `IsIso f`.
/-- `asHom f` helps Lean type check a function as a morphism in the category `Type`. -/
abbrev asHom {α β : Type u} (f : α → β) : α ⟶ β :=
f
@[inherit_doc]
scoped notation "↾" f:200 => CategoryTheory.asHom f
section
-- We verify the expected type checking behaviour of `asHom`
variable (α β γ : Type u) (f : α → β) (g : β → γ)
example : α → γ :=
↾f ≫ ↾g
example [IsIso (↾f)] : Mono (↾f) := by infer_instance
example [IsIso (↾f)] : ↾f ≫ inv (↾f) = 𝟙 α := by simp
end
namespace Functor
variable {J : Type u} [Category.{v} J]
/-- The sections of a functor `F : J ⥤ Type` are
the choices of a point `u j : F.obj j` for each `j`,
such that `F.map f (u j) = u j'` for every morphism `f : j ⟶ j'`.
We later use these to define limits in `Type` and in many concrete categories.
-/
def sections (F : J ⥤ Type w) : Set (∀ j, F.obj j) :=
{ u | ∀ {j j'} (f : j ⟶ j'), F.map f (u j) = u j' }
@[simp]
lemma sections_property {F : J ⥤ Type w} (s : (F.sections : Type _))
{j j' : J} (f : j ⟶ j') : F.map f (s.val j) = s.val j' :=
s.property f
lemma sections_ext_iff {F : J ⥤ Type w} {x y : F.sections} : x = y ↔ ∀ j, x.val j = y.val j :=
Subtype.ext_iff.trans Function.funext_iff
variable (J)
/-- The functor which sends a functor to types to its sections. -/
@[simps]
def sectionsFunctor : (J ⥤ Type w) ⥤ Type max u w where
obj F := F.sections
map {F G} φ x := ⟨fun j => φ.app j (x.1 j), fun {j j'} f =>
(congr_fun (φ.naturality f) (x.1 j)).symm.trans (by simp [x.2 f])⟩
end Functor
namespace FunctorToTypes
variable {C : Type u} [Category.{v} C] (F G H : C ⥤ Type w) {X Y Z : C}
variable (σ : F ⟶ G) (τ : G ⟶ H)
@[simp]
theorem map_comp_apply (f : X ⟶ Y) (g : Y ⟶ Z) (a : F.obj X) :
(F.map (f ≫ g)) a = (F.map g) ((F.map f) a) := by simp [types_comp]
@[simp]
theorem map_id_apply (a : F.obj X) : (F.map (𝟙 X)) a = a := by simp [types_id]
theorem naturality (f : X ⟶ Y) (x : F.obj X) : σ.app Y ((F.map f) x) = (G.map f) (σ.app X x) :=
congr_fun (σ.naturality f) x
@[simp]
theorem comp (x : F.obj X) : (σ ≫ τ).app X x = τ.app X (σ.app X x) :=
rfl
@[simp]
theorem eqToHom_map_comp_apply (p : X = Y) (q : Y = Z) (x : F.obj X) :
F.map (eqToHom q) (F.map (eqToHom p) x) = F.map (eqToHom <| p.trans q) x := by
aesop_cat
variable {D : Type u'} [𝒟 : Category.{u'} D] (I J : D ⥤ C) (ρ : I ⟶ J) {W : D}
@[simp]
theorem hcomp (x : (I ⋙ F).obj W) : (ρ ◫ σ).app W x = (G.map (ρ.app W)) (σ.app (I.obj W) x) :=
rfl
@[simp]
theorem map_inv_map_hom_apply (f : X ≅ Y) (x : F.obj X) : F.map f.inv (F.map f.hom x) = x :=
congr_fun (F.mapIso f).hom_inv_id x
@[simp]
theorem map_hom_map_inv_apply (f : X ≅ Y) (y : F.obj Y) : F.map f.hom (F.map f.inv y) = y :=
congr_fun (F.mapIso f).inv_hom_id y
@[simp]
theorem hom_inv_id_app_apply (α : F ≅ G) (X) (x) : α.inv.app X (α.hom.app X x) = x :=
congr_fun (α.hom_inv_id_app X) x
@[simp]
theorem inv_hom_id_app_apply (α : F ≅ G) (X) (x) : α.hom.app X (α.inv.app X x) = x :=
congr_fun (α.inv_hom_id_app X) x
end FunctorToTypes
/-- The isomorphism between a `Type` which has been `ULift`ed to the same universe,
and the original type.
-/
def uliftTrivial (V : Type u) : ULift.{u} V ≅ V where
hom a := a.1
inv a := .up a
/-- The functor embedding `Type u` into `Type (max u v)`.
Write this as `uliftFunctor.{5, 2}` to get `Type 2 ⥤ Type 5`.
-/
@[pp_with_univ]
def uliftFunctor : Type u ⥤ Type max u v where
obj X := ULift.{v} X
map {X} {Y} f := fun x : ULift.{v} X => ULift.up (f x.down)
@[simp]
theorem uliftFunctor_obj {X : Type u} : uliftFunctor.obj.{v} X = ULift.{v} X :=
rfl
@[simp]
theorem uliftFunctor_map {X Y : Type u} (f : X ⟶ Y) (x : ULift.{v} X) :
uliftFunctor.map f x = ULift.up (f x.down) :=
rfl
instance uliftFunctor_full : Functor.Full.{u} uliftFunctor where
map_surjective f := ⟨fun x => (f (ULift.up x)).down, rfl⟩
instance uliftFunctor_faithful : uliftFunctor.Faithful where
map_injective {_X} {_Y} f g p :=
funext fun x =>
congr_arg ULift.down (congr_fun p (ULift.up x) : ULift.up (f x) = ULift.up (g x))
/-- The functor embedding `Type u` into `Type u` via `ULift` is isomorphic to the identity functor.
-/
def uliftFunctorTrivial : uliftFunctor.{u, u} ≅ 𝟭 _ :=
NatIso.ofComponents uliftTrivial
-- TODO We should connect this to a general story about concrete categories
-- whose forgetful functor is representable.
/-- Any term `x` of a type `X` corresponds to a morphism `PUnit ⟶ X`. -/
def homOfElement {X : Type u} (x : X) : PUnit ⟶ X := fun _ => x
theorem homOfElement_eq_iff {X : Type u} (x y : X) : homOfElement x = homOfElement y ↔ x = y :=
⟨fun H => congr_fun H PUnit.unit, by aesop⟩
/-- A morphism in `Type` is a monomorphism if and only if it is injective.
See <https://stacks.math.columbia.edu/tag/003C>.
-/
theorem mono_iff_injective {X Y : Type u} (f : X ⟶ Y) : Mono f ↔ Function.Injective f := by
constructor
· intro H x x' h
rw [← homOfElement_eq_iff] at h ⊢
exact (cancel_mono f).mp h
· exact fun H => ⟨fun g g' h => H.comp_left h⟩
theorem injective_of_mono {X Y : Type u} (f : X ⟶ Y) [hf : Mono f] : Function.Injective f :=
(mono_iff_injective f).1 hf
/-- A morphism in `Type` is an epimorphism if and only if it is surjective.
See <https://stacks.math.columbia.edu/tag/003C>.
-/
theorem epi_iff_surjective {X Y : Type u} (f : X ⟶ Y) : Epi f ↔ Function.Surjective f := by
constructor
· rintro ⟨H⟩
refine Function.surjective_of_right_cancellable_Prop fun g₁ g₂ hg => ?_
rw [← Equiv.ulift.symm.injective.comp_left.eq_iff]
apply H
change ULift.up ∘ g₁ ∘ f = ULift.up ∘ g₂ ∘ f
rw [hg]
· exact fun H => ⟨fun g g' h => H.injective_comp_right h⟩
theorem surjective_of_epi {X Y : Type u} (f : X ⟶ Y) [hf : Epi f] : Function.Surjective f :=
(epi_iff_surjective f).1 hf
section
/-- `ofTypeFunctor m` converts from Lean's `Type`-based `Category` to `CategoryTheory`. This
allows us to use these functors in category theory. -/
def ofTypeFunctor (m : Type u → Type v) [_root_.Functor m] [LawfulFunctor m] : Type u ⥤ Type v where
obj := m
map f := Functor.map f
map_id := fun α => by funext X; apply id_map /- Porting note: original proof is via
`fun α => _root_.Functor.map_id` but I cannot get Lean to find this. Reproduced its
original proof -/
map_comp f g := funext fun a => LawfulFunctor.comp_map f g _
variable (m : Type u → Type v) [_root_.Functor m] [LawfulFunctor m]
@[simp]
theorem ofTypeFunctor_obj : (ofTypeFunctor m).obj = m :=
rfl
@[simp]
theorem ofTypeFunctor_map {α β} (f : α → β) :
(ofTypeFunctor m).map f = (Functor.map f : m α → m β) :=
rfl
end
end CategoryTheory
-- Isomorphisms in Type and equivalences.
namespace Equiv
universe u
variable {X Y : Type u}
/-- Any equivalence between types in the same universe gives
a categorical isomorphism between those types.
-/
def toIso (e : X ≃ Y) : X ≅ Y where
hom := e.toFun
inv := e.invFun
hom_inv_id := funext e.left_inv
inv_hom_id := funext e.right_inv
@[simp]
theorem toIso_hom {e : X ≃ Y} : e.toIso.hom = e :=
rfl
@[simp]
theorem toIso_inv {e : X ≃ Y} : e.toIso.inv = e.symm :=
rfl
end Equiv
universe u
namespace CategoryTheory.Iso
open CategoryTheory
variable {X Y : Type u}
/-- Any isomorphism between types gives an equivalence. -/
def toEquiv (i : X ≅ Y) : X ≃ Y where
toFun := i.hom
invFun := i.inv
left_inv x := congr_fun i.hom_inv_id x
right_inv y := congr_fun i.inv_hom_id y
@[simp]
theorem toEquiv_fun (i : X ≅ Y) : (i.toEquiv : X → Y) = i.hom :=
rfl
@[simp]
theorem toEquiv_symm_fun (i : X ≅ Y) : (i.toEquiv.symm : Y → X) = i.inv :=
rfl
@[simp]
theorem toEquiv_id (X : Type u) : (Iso.refl X).toEquiv = Equiv.refl X :=
rfl
@[simp]
theorem toEquiv_comp {X Y Z : Type u} (f : X ≅ Y) (g : Y ≅ Z) :
(f ≪≫ g).toEquiv = f.toEquiv.trans g.toEquiv :=
rfl
end CategoryTheory.Iso
namespace CategoryTheory
/-- A morphism in `Type u` is an isomorphism if and only if it is bijective. -/
theorem isIso_iff_bijective {X Y : Type u} (f : X ⟶ Y) : IsIso f ↔ Function.Bijective f :=
Iff.intro (fun _ => (asIso f : X ≅ Y).toEquiv.bijective) fun b =>
(Equiv.ofBijective f b).toIso.isIso_hom
instance : SplitEpiCategory (Type u) where
isSplitEpi_of_epi f hf :=
IsSplitEpi.mk' <|
{ section_ := Function.surjInv <| (epi_iff_surjective f).1 hf
id := funext <| Function.rightInverse_surjInv <| (epi_iff_surjective f).1 hf }
end CategoryTheory
-- We prove `equivIsoIso` and then use that to sneakily construct `equivEquivIso`.
-- (In this order the proofs are handled by `aesop_cat`.)
/-- Equivalences (between types in the same universe) are the same as (isomorphic to) isomorphisms
of types. -/
@[simps]
def equivIsoIso {X Y : Type u} : X ≃ Y ≅ X ≅ Y where
hom e := e.toIso
inv i := i.toEquiv
/-- Equivalences (between types in the same universe) are the same as (equivalent to) isomorphisms
of types. -/
def equivEquivIso {X Y : Type u} : X ≃ Y ≃ (X ≅ Y) :=
equivIsoIso.toEquiv
@[simp]
theorem equivEquivIso_hom {X Y : Type u} (e : X ≃ Y) : equivEquivIso e = e.toIso :=
rfl
@[simp]
theorem equivEquivIso_inv {X Y : Type u} (e : X ≅ Y) : equivEquivIso.symm e = e.toEquiv :=
rfl
|
CategoryTheory\UnivLE.lean | /-
Copyright (c) 2023 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.Logic.UnivLE
import Mathlib.CategoryTheory.EssentialImage
import Mathlib.CategoryTheory.Types
/-!
# Universe inequalities and essential surjectivity of `uliftFunctor`.
We show `UnivLE.{max u v, v} ↔ EssSurj (uliftFunctor.{u, v} : Type v ⥤ Type max u v)`.
-/
open CategoryTheory
universe u v
noncomputable section
theorem UnivLE.ofEssSurj (w : (uliftFunctor.{u, v} : Type v ⥤ Type max u v).EssSurj) :
UnivLE.{max u v, v} :=
fun α ↦ by
obtain ⟨a', ⟨m⟩⟩ := w.mem_essImage α
exact ⟨a', ⟨(Iso.toEquiv m).symm.trans Equiv.ulift⟩⟩
instance EssSurj.ofUnivLE [UnivLE.{max u v, v}] :
(uliftFunctor.{u, v} : Type v ⥤ Type max u v).EssSurj where
mem_essImage α :=
⟨Shrink α, ⟨Equiv.toIso (Equiv.ulift.trans (equivShrink α).symm)⟩⟩
theorem UnivLE_iff_essSurj :
UnivLE.{max u v, v} ↔ (uliftFunctor.{u, v} : Type v ⥤ Type max u v).EssSurj :=
⟨fun _ => inferInstance, fun w => UnivLE.ofEssSurj w⟩
instance [UnivLE.{max u v, v}] : uliftFunctor.{u, v}.IsEquivalence where
def UnivLE.witness [UnivLE.{max u v, v}] : Type u ⥤ Type v :=
uliftFunctor.{v, u} ⋙ (uliftFunctor.{u, v}).inv
instance [UnivLE.{max u v, v}] : UnivLE.witness.{u, v}.Faithful :=
inferInstanceAs <| Functor.Faithful (_ ⋙ _)
instance [UnivLE.{max u v, v}] : UnivLE.witness.{u, v}.Full :=
inferInstanceAs <| Functor.Full (_ ⋙ _)
|
CategoryTheory\Whiskering.lean | /-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.CategoryTheory.Iso
import Mathlib.CategoryTheory.Functor.Category
import Mathlib.CategoryTheory.Functor.FullyFaithful
/-!
# Whiskering
Given a functor `F : C ⥤ D` and functors `G H : D ⥤ E` and a natural transformation `α : G ⟶ H`,
we can construct a new natural transformation `F ⋙ G ⟶ F ⋙ H`,
called `whiskerLeft F α`. This is the same as the horizontal composition of `𝟙 F` with `α`.
This operation is functorial in `F`, and we package this as `whiskeringLeft`. Here
`(whiskeringLeft.obj F).obj G` is `F ⋙ G`, and
`(whiskeringLeft.obj F).map α` is `whiskerLeft F α`.
(That is, we might have alternatively named this as the "left composition functor".)
We also provide analogues for composition on the right, and for these operations on isomorphisms.
At the end of the file, we provide the left and right unitors, and the associator,
for functor composition.
(In fact functor composition is definitionally associative, but very often relying on this causes
extremely slow elaboration, so it is better to insert it explicitly.)
We also show these natural isomorphisms satisfy the triangle and pentagon identities.
-/
namespace CategoryTheory
universe u₁ v₁ u₂ v₂ u₃ v₃ u₄ v₄
section
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D] {E : Type u₃}
[Category.{v₃} E]
/-- If `α : G ⟶ H` then
`whiskerLeft F α : (F ⋙ G) ⟶ (F ⋙ H)` has components `α.app (F.obj X)`.
-/
@[simps]
def whiskerLeft (F : C ⥤ D) {G H : D ⥤ E} (α : G ⟶ H) :
F ⋙ G ⟶ F ⋙ H where
app X := α.app (F.obj X)
naturality X Y f := by rw [Functor.comp_map, Functor.comp_map, α.naturality]
/-- If `α : G ⟶ H` then
`whisker_right α F : (G ⋙ F) ⟶ (G ⋙ F)` has components `F.map (α.app X)`.
-/
@[simps]
def whiskerRight {G H : C ⥤ D} (α : G ⟶ H) (F : D ⥤ E) :
G ⋙ F ⟶ H ⋙ F where
app X := F.map (α.app X)
naturality X Y f := by
rw [Functor.comp_map, Functor.comp_map, ← F.map_comp, ← F.map_comp, α.naturality]
variable (C D E)
/-- Left-composition gives a functor `(C ⥤ D) ⥤ ((D ⥤ E) ⥤ (C ⥤ E))`.
`(whiskeringLeft.obj F).obj G` is `F ⋙ G`, and
`(whiskeringLeft.obj F).map α` is `whiskerLeft F α`.
-/
@[simps]
def whiskeringLeft : (C ⥤ D) ⥤ (D ⥤ E) ⥤ C ⥤ E where
obj F :=
{ obj := fun G => F ⋙ G
map := fun α => whiskerLeft F α }
map τ :=
{ app := fun H =>
{ app := fun c => H.map (τ.app c)
naturality := fun X Y f => by dsimp; rw [← H.map_comp, ← H.map_comp, ← τ.naturality] }
naturality := fun X Y f => by ext; dsimp; rw [f.naturality] }
/-- Right-composition gives a functor `(D ⥤ E) ⥤ ((C ⥤ D) ⥤ (C ⥤ E))`.
`(whiskeringRight.obj H).obj F` is `F ⋙ H`, and
`(whiskeringRight.obj H).map α` is `whiskerRight α H`.
-/
@[simps]
def whiskeringRight : (D ⥤ E) ⥤ (C ⥤ D) ⥤ C ⥤ E where
obj H :=
{ obj := fun F => F ⋙ H
map := fun α => whiskerRight α H }
map τ :=
{ app := fun F =>
{ app := fun c => τ.app (F.obj c)
naturality := fun X Y f => by dsimp; rw [τ.naturality] }
naturality := fun X Y f => by ext; dsimp; rw [← NatTrans.naturality] }
variable {C} {D} {E}
instance faithful_whiskeringRight_obj {F : D ⥤ E} [F.Faithful] :
((whiskeringRight C D E).obj F).Faithful where
map_injective hαβ := by
ext X
exact F.map_injective <| congr_fun (congr_arg NatTrans.app hαβ) X
/-- If `F : D ⥤ E` is fully faithful, then so is
`(whiskeringRight C D E).obj F : (C ⥤ D) ⥤ C ⥤ E`. -/
@[simps]
def Functor.FullyFaithful.whiskeringRight {F : D ⥤ E} (hF : F.FullyFaithful)
(C : Type*) [Category C] :
((whiskeringRight C D E).obj F).FullyFaithful where
preimage f :=
{ app := fun X => hF.preimage (f.app X)
naturality := fun _ _ g => by
apply hF.map_injective
dsimp
simp only [map_comp, map_preimage]
apply f.naturality }
instance full_whiskeringRight_obj {F : D ⥤ E} [F.Faithful] [F.Full] :
((whiskeringRight C D E).obj F).Full :=
((Functor.FullyFaithful.ofFullyFaithful F).whiskeringRight C).full
@[simp]
theorem whiskerLeft_id (F : C ⥤ D) {G : D ⥤ E} :
whiskerLeft F (NatTrans.id G) = NatTrans.id (F.comp G) :=
rfl
@[simp]
theorem whiskerLeft_id' (F : C ⥤ D) {G : D ⥤ E} : whiskerLeft F (𝟙 G) = 𝟙 (F.comp G) :=
rfl
@[simp]
theorem whiskerRight_id {G : C ⥤ D} (F : D ⥤ E) :
whiskerRight (NatTrans.id G) F = NatTrans.id (G.comp F) :=
((whiskeringRight C D E).obj F).map_id _
@[simp]
theorem whiskerRight_id' {G : C ⥤ D} (F : D ⥤ E) : whiskerRight (𝟙 G) F = 𝟙 (G.comp F) :=
((whiskeringRight C D E).obj F).map_id _
@[simp, reassoc]
theorem whiskerLeft_comp (F : C ⥤ D) {G H K : D ⥤ E} (α : G ⟶ H) (β : H ⟶ K) :
whiskerLeft F (α ≫ β) = whiskerLeft F α ≫ whiskerLeft F β :=
rfl
@[simp, reassoc]
theorem whiskerRight_comp {G H K : C ⥤ D} (α : G ⟶ H) (β : H ⟶ K) (F : D ⥤ E) :
whiskerRight (α ≫ β) F = whiskerRight α F ≫ whiskerRight β F :=
((whiskeringRight C D E).obj F).map_comp α β
/-- If `α : G ≅ H` is a natural isomorphism then
`iso_whisker_left F α : (F ⋙ G) ≅ (F ⋙ H)` has components `α.app (F.obj X)`.
-/
def isoWhiskerLeft (F : C ⥤ D) {G H : D ⥤ E} (α : G ≅ H) : F ⋙ G ≅ F ⋙ H :=
((whiskeringLeft C D E).obj F).mapIso α
@[simp]
theorem isoWhiskerLeft_hom (F : C ⥤ D) {G H : D ⥤ E} (α : G ≅ H) :
(isoWhiskerLeft F α).hom = whiskerLeft F α.hom :=
rfl
@[simp]
theorem isoWhiskerLeft_inv (F : C ⥤ D) {G H : D ⥤ E} (α : G ≅ H) :
(isoWhiskerLeft F α).inv = whiskerLeft F α.inv :=
rfl
/-- If `α : G ≅ H` then
`iso_whisker_right α F : (G ⋙ F) ≅ (H ⋙ F)` has components `F.map_iso (α.app X)`.
-/
def isoWhiskerRight {G H : C ⥤ D} (α : G ≅ H) (F : D ⥤ E) : G ⋙ F ≅ H ⋙ F :=
((whiskeringRight C D E).obj F).mapIso α
@[simp]
theorem isoWhiskerRight_hom {G H : C ⥤ D} (α : G ≅ H) (F : D ⥤ E) :
(isoWhiskerRight α F).hom = whiskerRight α.hom F :=
rfl
@[simp]
theorem isoWhiskerRight_inv {G H : C ⥤ D} (α : G ≅ H) (F : D ⥤ E) :
(isoWhiskerRight α F).inv = whiskerRight α.inv F :=
rfl
instance isIso_whiskerLeft (F : C ⥤ D) {G H : D ⥤ E} (α : G ⟶ H) [IsIso α] :
IsIso (whiskerLeft F α) :=
(isoWhiskerLeft F (asIso α)).isIso_hom
instance isIso_whiskerRight {G H : C ⥤ D} (α : G ⟶ H) (F : D ⥤ E) [IsIso α] :
IsIso (whiskerRight α F) :=
(isoWhiskerRight (asIso α) F).isIso_hom
variable {B : Type u₄} [Category.{v₄} B]
-- Porting note: it was `attribute [local elab_without_expected_type]`,
-- but now `elab_without_expected-type` must be global
attribute [elab_without_expected_type] whiskerLeft whiskerRight
@[simp]
theorem whiskerLeft_twice (F : B ⥤ C) (G : C ⥤ D) {H K : D ⥤ E} (α : H ⟶ K) :
whiskerLeft F (whiskerLeft G α) = whiskerLeft (F ⋙ G) α :=
rfl
@[simp]
theorem whiskerRight_twice {H K : B ⥤ C} (F : C ⥤ D) (G : D ⥤ E) (α : H ⟶ K) :
whiskerRight (whiskerRight α F) G = whiskerRight α (F ⋙ G) :=
rfl
theorem whiskerRight_left (F : B ⥤ C) {G H : C ⥤ D} (α : G ⟶ H) (K : D ⥤ E) :
whiskerRight (whiskerLeft F α) K = whiskerLeft F (whiskerRight α K) :=
rfl
end
namespace Functor
universe u₅ v₅
variable {A : Type u₁} [Category.{v₁} A]
variable {B : Type u₂} [Category.{v₂} B]
/-- The left unitor, a natural isomorphism `((𝟭 _) ⋙ F) ≅ F`.
-/
@[simps]
def leftUnitor (F : A ⥤ B) :
𝟭 A ⋙ F ≅ F where
hom := { app := fun X => 𝟙 (F.obj X) }
inv := { app := fun X => 𝟙 (F.obj X) }
/-- The right unitor, a natural isomorphism `(F ⋙ (𝟭 B)) ≅ F`.
-/
@[simps]
def rightUnitor (F : A ⥤ B) :
F ⋙ 𝟭 B ≅ F where
hom := { app := fun X => 𝟙 (F.obj X) }
inv := { app := fun X => 𝟙 (F.obj X) }
variable {C : Type u₃} [Category.{v₃} C]
variable {D : Type u₄} [Category.{v₄} D]
/-- The associator for functors, a natural isomorphism `((F ⋙ G) ⋙ H) ≅ (F ⋙ (G ⋙ H))`.
(In fact, `iso.refl _` will work here, but it tends to make Lean slow later,
and it's usually best to insert explicit associators.)
-/
@[simps]
def associator (F : A ⥤ B) (G : B ⥤ C) (H : C ⥤ D) :
(F ⋙ G) ⋙ H ≅ F ⋙ G ⋙ H where
hom := { app := fun _ => 𝟙 _ }
inv := { app := fun _ => 𝟙 _ }
protected theorem assoc (F : A ⥤ B) (G : B ⥤ C) (H : C ⥤ D) : (F ⋙ G) ⋙ H = F ⋙ G ⋙ H :=
rfl
theorem triangle (F : A ⥤ B) (G : B ⥤ C) :
(associator F (𝟭 B) G).hom ≫ whiskerLeft F (leftUnitor G).hom =
whiskerRight (rightUnitor F).hom G := by aesop_cat
-- See note [dsimp, simp].
variable {E : Type u₅} [Category.{v₅} E]
variable (F : A ⥤ B) (G : B ⥤ C) (H : C ⥤ D) (K : D ⥤ E)
theorem pentagon :
whiskerRight (associator F G H).hom K ≫
(associator F (G ⋙ H) K).hom ≫ whiskerLeft F (associator G H K).hom =
(associator (F ⋙ G) H K).hom ≫ (associator F G (H ⋙ K)).hom := by aesop_cat
end Functor
end CategoryTheory
|
CategoryTheory\Widesubcategory.lean | /-
Copyright (c) 2024 Sina Hazratpour. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sina Hazratpour
-/
import Mathlib.CategoryTheory.Functor.FullyFaithful
import Mathlib.CategoryTheory.MorphismProperty.Composition
/-!
# Wide subcategories
A wide subcategory of a category `C` is a subcategory containing all the objects of `C`.
## Main declarations
Given a category `D`, a function `F : C → D` from a type `C` to the objects of `D`,
and a morphism property `P` on `D` which contains identities and is stable under
composition, the type class `InducedWideCategory D F P` is a typeclass
synonym for `C` which comes equipped with a category structure whose morphisms `X ⟶ Y` are the
morphisms in `D` which have the property `P`.
The instance `WideSubcategory.category` provides a category structure on `WideSubcategory P`
whose objects are the objects of `C` and morphisms are the morphisms in `C` which have the
property `P`.
-/
namespace CategoryTheory
universe v₁ v₂ u₁ u₂
open MorphismProperty
section Induced
variable {C : Type u₁} (D : Type u₂) [Category.{v₁} D]
variable (F : C → D) (P : MorphismProperty D) [IsMultiplicative P]
/-- `InducedWideCategory D F P`, where `F : C → D`, is a typeclass synonym for `C`,
which provides a category structure so that the morphisms `X ⟶ Y` are the morphisms
in `D` from `F X` to `F Y` which satisfy a property `P : MorphismProperty D` that is multiplicative.
-/
-- Porting note(#5171): removed @[nolint has_nonempty_instance]
@[nolint unusedArguments]
def InducedWideCategory (_F : C → D) (_P : MorphismProperty D) [IsMultiplicative _P] :=
C
variable {D}
instance InducedWideCategory.hasCoeToSort {α : Sort*} [CoeSort D α] :
CoeSort (InducedWideCategory D F P) α :=
⟨fun c => F c⟩
@[simps!]
instance InducedWideCategory.category :
Category (InducedWideCategory D F P) where
Hom X Y := {f : F X ⟶ F Y | P f}
id X := ⟨𝟙 (F X), P.id_mem (F X)⟩
comp {X Y Z} f g := ⟨f.1 ≫ g.1, P.comp_mem _ _ f.2 g.2⟩
/-- The forgetful functor from an induced wide category to the original category. -/
@[simps]
def wideInducedFunctor : InducedWideCategory D F P ⥤ D where
obj := F
map {X Y} f := f.1
/-- The induced functor `wideInducedFunctor F P : InducedWideCategory D F P ⥤ D`
is faithful. -/
instance InducedWideCategory.faithful : (wideInducedFunctor F P).Faithful where
map_injective {X Y} f g eq := by
cases f
cases g
aesop
end Induced
section WideSubcategory
variable {C : Type u₁} [Category.{v₁} C]
variable (P : MorphismProperty C) [IsMultiplicative P]
/--
Structure for wide subcategories. Objects ignore the morphism property.
-/
@[ext, nolint unusedArguments]
structure WideSubcategory (_P : MorphismProperty C) [IsMultiplicative _P] where
/-- The category of which this is a wide subcategory-/
obj : C
instance WideSubcategory.category : Category.{v₁} (WideSubcategory P) :=
InducedWideCategory.category WideSubcategory.obj P
@[simp]
lemma WideSubcategory.id_def (X : WideSubcategory P) : (CategoryStruct.id X).1 = 𝟙 X.obj := rfl
@[simp]
lemma WideSubcategory.comp_def {X Y Z : WideSubcategory P} (f : X ⟶ Y) (g : Y ⟶ Z) :
(f ≫ g).1 = (f.1 ≫ g.1 : X.obj ⟶ Z.obj) := rfl
/-- The forgetful functor from a wide subcategory into the original category
("forgetting" the condition).
-/
def wideSubcategoryInclusion : WideSubcategory P ⥤ C :=
wideInducedFunctor WideSubcategory.obj P
@[simp]
theorem wideSubcategoryInclusion.obj (X) : (wideSubcategoryInclusion P).obj X = X.obj :=
rfl
@[simp]
theorem wideSubcategoryInclusion.map {X Y} {f : X ⟶ Y} :
(wideSubcategoryInclusion P).map f = f.1 :=
rfl
/-- The inclusion of a wide subcategory is faithful. -/
instance wideSubcategory.faithful : (wideSubcategoryInclusion P).Faithful :=
inferInstanceAs (wideInducedFunctor WideSubcategory.obj P).Faithful
end WideSubcategory
end CategoryTheory
|
CategoryTheory\WithTerminal.lean | /-
Copyright (c) 2021 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Tooby-Smith, Adam Topaz
-/
import Mathlib.CategoryTheory.Limits.Shapes.Terminal
import Mathlib.CategoryTheory.Bicategory.Functor.Pseudofunctor
/-!
# `WithInitial` and `WithTerminal`
Given a category `C`, this file constructs two objects:
1. `WithTerminal C`, the category built from `C` by formally adjoining a terminal object.
2. `WithInitial C`, the category built from `C` by formally adjoining an initial object.
The terminal resp. initial object is `WithTerminal.star` resp. `WithInitial.star`, and
the proofs that these are terminal resp. initial are in `WithTerminal.star_terminal`
and `WithInitial.star_initial`.
The inclusion from `C` into `WithTerminal C` resp. `WithInitial C` is denoted
`WithTerminal.incl` resp. `WithInitial.incl`.
The relevant constructions needed for the universal properties of these constructions are:
1. `lift`, which lifts `F : C ⥤ D` to a functor from `WithTerminal C` resp. `WithInitial C` in
the case where an object `Z : D` is provided satisfying some additional conditions.
2. `inclLift` shows that the composition of `lift` with `incl` is isomorphic to the
functor which was lifted.
3. `liftUnique` provides the uniqueness property of `lift`.
In addition to this, we provide `WithTerminal.map` and `WithInitial.map` providing the
functoriality of these constructions with respect to functors on the base categories.
We define corresponding pseudofunctors `WithTerminal.pseudofunctor` and `WithInitial.pseudofunctor`
from `Cat` to `Cat`.
-/
namespace CategoryTheory
universe v u
variable (C : Type u) [Category.{v} C]
/-- Formally adjoin a terminal object to a category. -/
inductive WithTerminal : Type u
| of : C → WithTerminal
| star : WithTerminal
deriving Inhabited
attribute [local aesop safe cases (rule_sets := [CategoryTheory])] WithTerminal
/-- Formally adjoin an initial object to a category. -/
inductive WithInitial : Type u
| of : C → WithInitial
| star : WithInitial
deriving Inhabited
attribute [local aesop safe cases (rule_sets := [CategoryTheory])] WithInitial
namespace WithTerminal
variable {C}
/-- Morphisms for `WithTerminal C`. -/
-- Porting note(#5171): removed `nolint has_nonempty_instance`
@[simp]
def Hom : WithTerminal C → WithTerminal C → Type v
| of X, of Y => X ⟶ Y
| star, of _ => PEmpty
| _, star => PUnit
/-- Identity morphisms for `WithTerminal C`. -/
@[simp]
def id : ∀ X : WithTerminal C, Hom X X
| of _ => 𝟙 _
| star => PUnit.unit
/-- Composition of morphisms for `WithTerminal C`. -/
@[simp]
def comp : ∀ {X Y Z : WithTerminal C}, Hom X Y → Hom Y Z → Hom X Z
| of _X, of _Y, of _Z => fun f g => f ≫ g
| of _X, _, star => fun _f _g => PUnit.unit
| star, of _X, _ => fun f _g => PEmpty.elim f
| _, star, of _Y => fun _f g => PEmpty.elim g
| star, star, star => fun _ _ => PUnit.unit
instance : Category.{v} (WithTerminal C) where
Hom X Y := Hom X Y
id X := id _
comp := comp
assoc {a b c d} f g h := by
-- Porting note: it would be nice to automate this away as well.
-- I tried splitting this into separate `Quiver` and `Category` instances,
-- so the `false_of_from_star` destruct rule below can be used here.
-- That works, but causes mysterious failures of `aesop_cat` in `map`.
cases a <;> cases b <;> cases c <;> cases d <;> try aesop_cat
· exact (h : PEmpty).elim
· exact (g : PEmpty).elim
· exact (h : PEmpty).elim
/-- Helper function for typechecking. -/
def down {X Y : C} (f : of X ⟶ of Y) : X ⟶ Y := f
@[simp] lemma down_id {X : C} : down (𝟙 (of X)) = 𝟙 X := rfl
@[simp] lemma down_comp {X Y Z : C} (f : of X ⟶ of Y) (g : of Y ⟶ of Z) :
down (f ≫ g) = down f ≫ down g :=
rfl
@[aesop safe destruct (rule_sets := [CategoryTheory])]
lemma false_of_from_star {X : C} (f : star ⟶ of X) : False := (f : PEmpty).elim
/-- The inclusion from `C` into `WithTerminal C`. -/
def incl : C ⥤ WithTerminal C where
obj := of
map f := f
instance : (incl : C ⥤ _).Full where
map_surjective f := ⟨f, rfl⟩
instance : (incl : C ⥤ _).Faithful where
/-- Map `WithTerminal` with respect to a functor `F : C ⥤ D`. -/
@[simps]
def map {D : Type*} [Category D] (F : C ⥤ D) : WithTerminal C ⥤ WithTerminal D where
obj X :=
match X with
| of x => of <| F.obj x
| star => star
map {X Y} f :=
match X, Y, f with
| of x, of y, f => F.map (down f)
| of _, star, _ => PUnit.unit
| star, star, _ => PUnit.unit
/-- A natural isomorphism between the functor `map (𝟭 C)` and `𝟭 (WithTerminal C)`. -/
@[simps!]
def mapId (C : Type*) [Category C] : map (𝟭 C) ≅ 𝟭 (WithTerminal C) :=
NatIso.ofComponents (fun X => match X with
| of x => Iso.refl _
| star => Iso.refl _) (by aesop_cat)
/-- A natural isomorphism between the functor `map (F ⋙ G) ` and `map F ⋙ map G `. -/
@[simps!]
def mapComp {D E : Type*} [Category D] [Category E] (F : C ⥤ D) (G : D ⥤ E) :
map (F ⋙ G) ≅ map F ⋙ map G :=
NatIso.ofComponents (fun X => match X with
| of x => Iso.refl _
| star => Iso.refl _) (by aesop_cat)
/-- From a natural transformation of functors `C ⥤ D`, the induced natural transformation
of functors `WithTerminal C ⥤ WithTerminal D`. -/
@[simps]
def map₂ {D : Type*} [Category D] {F G : C ⥤ D} (η : F ⟶ G) : map F ⟶ map G where
app := fun X => match X with
| of x => η.app x
| star => 𝟙 star
naturality := by
intro X Y f
match X, Y, f with
| of x, of y, f => exact η.naturality f
| of x, star, _ => rfl
| star, star, _ => rfl
-- Note: ...
/-- The prelax functor from `Cat` to `Cat` defined with `WithTerminal`. -/
@[simps]
def prelaxfunctor : PrelaxFunctor Cat Cat where
obj C := Cat.of (WithTerminal C)
map := map
map₂ := map₂
map₂_id := by
intros
apply NatTrans.ext
funext X
cases X <;> rfl
map₂_comp := by
intros
apply NatTrans.ext
funext X
cases X <;> rfl
/-- The pseudofunctor from `Cat` to `Cat` defined with `WithTerminal`. -/
@[simps]
def pseudofunctor : Pseudofunctor Cat Cat where
toPrelaxFunctor := prelaxfunctor
mapId C := mapId C
mapComp := mapComp
map₂_whisker_left := by
intros
apply NatTrans.ext
funext X
cases X
· rw [NatTrans.comp_app, NatTrans.comp_app]
simp only [prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_obj,
prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_map, map_obj, Cat.comp_obj,
prelaxfunctor_toPrelaxFunctorStruct_map₂, map₂_app, Cat.whiskerLeft_app, mapComp_hom_app,
Iso.refl_hom, mapComp_inv_app, Iso.refl_inv, Category.comp_id, Category.id_comp]
· rfl
map₂_whisker_right := by
intros
apply NatTrans.ext
funext X
cases X
· rw [NatTrans.comp_app, NatTrans.comp_app]
simp only [prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_obj,
prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_map, map_obj, Cat.comp_obj,
prelaxfunctor_toPrelaxFunctorStruct_map₂, map₂_app, Cat.whiskerRight_app, mapComp_hom_app,
Iso.refl_hom, map_map, mapComp_inv_app, Iso.refl_inv, Category.comp_id, Category.id_comp]
rfl
· rfl
map₂_associator := by
intros
dsimp
apply NatTrans.ext
funext X
cases X
· rw [NatTrans.comp_app,NatTrans.comp_app,NatTrans.comp_app,NatTrans.comp_app]
simp only [prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_obj,
prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_map, map_obj, Cat.comp_obj,
Bicategory.Strict.associator_eqToIso, eqToIso_refl, Iso.refl_hom,
prelaxfunctor_toPrelaxFunctorStruct_map₂, map₂_app, mapComp_hom_app, Cat.whiskerRight_app,
map_map, down_id, Functor.map_id, Cat.whiskerLeft_app, mapComp_inv_app, Iso.refl_inv,
Category.comp_id, Category.id_comp]
rw [NatTrans.id_app, NatTrans.id_app]
simp only [Cat.comp_obj, Bicategory.whiskerRight, whiskerRight_app, map_obj, mapComp_hom_app,
Iso.refl_hom, map_map, down_id, Functor.map_id, Bicategory.whiskerLeft, whiskerLeft_app,
mapComp_inv_app, Iso.refl_inv, Category.comp_id]
· rfl
map₂_left_unitor := by
intros
apply NatTrans.ext
funext X
cases X
· rw [NatTrans.comp_app, NatTrans.comp_app]
simp only [prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_obj,
prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_map, map_obj, Cat.comp_obj,
Bicategory.Strict.leftUnitor_eqToIso, eqToIso_refl, Iso.refl_hom,
prelaxfunctor_toPrelaxFunctorStruct_map₂, map₂_app, mapComp_hom_app, Cat.whiskerRight_app,
mapId_hom_app, map_map, Category.id_comp]
rw [NatTrans.id_app, NatTrans.id_app]
simp only [Cat.comp_obj, map_obj, Category.comp_id]
rw [← Functor.map_id]
rfl
· rfl
map₂_right_unitor := by
intros
apply NatTrans.ext
funext X
cases X
· rw [NatTrans.comp_app, NatTrans.comp_app]
simp only [prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_obj,
prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_map, map_obj, Cat.comp_obj,
Bicategory.Strict.rightUnitor_eqToIso, eqToIso_refl, Iso.refl_hom,
prelaxfunctor_toPrelaxFunctorStruct_map₂, map₂_app, mapComp_hom_app, Cat.whiskerLeft_app,
mapId_hom_app, Category.id_comp]
rw [NatTrans.id_app, NatTrans.id_app]
simp only [Cat.comp_obj, map_obj, Category.comp_id]
rw [← Functor.map_id]
rfl
· rfl
instance {X : WithTerminal C} : Unique (X ⟶ star) where
default :=
match X with
| of _ => PUnit.unit
| star => PUnit.unit
uniq := by aesop_cat
/-- `WithTerminal.star` is terminal. -/
def starTerminal : Limits.IsTerminal (star : WithTerminal C) :=
Limits.IsTerminal.ofUnique _
/-- Lift a functor `F : C ⥤ D` to `WithTerminal C ⥤ D`. -/
@[simps]
def lift {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (M : ∀ x : C, F.obj x ⟶ Z)
(hM : ∀ (x y : C) (f : x ⟶ y), F.map f ≫ M y = M x) : WithTerminal C ⥤ D where
obj X :=
match X with
| of x => F.obj x
| star => Z
map {X Y} f :=
match X, Y, f with
| of x, of y, f => F.map (down f)
| of x, star, _ => M x
| star, star, _ => 𝟙 Z
/-- The isomorphism between `incl ⋙ lift F _ _` with `F`. -/
@[simps!]
def inclLift {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (M : ∀ x : C, F.obj x ⟶ Z)
(hM : ∀ (x y : C) (f : x ⟶ y), F.map f ≫ M y = M x) : incl ⋙ lift F M hM ≅ F where
hom := { app := fun X => 𝟙 _ }
inv := { app := fun X => 𝟙 _ }
/-- The isomorphism between `(lift F _ _).obj WithTerminal.star` with `Z`. -/
@[simps!]
def liftStar {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (M : ∀ x : C, F.obj x ⟶ Z)
(hM : ∀ (x y : C) (f : x ⟶ y), F.map f ≫ M y = M x) : (lift F M hM).obj star ≅ Z :=
eqToIso rfl
theorem lift_map_liftStar {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (M : ∀ x : C, F.obj x ⟶ Z)
(hM : ∀ (x y : C) (f : x ⟶ y), F.map f ≫ M y = M x) (x : C) :
(lift F M hM).map (starTerminal.from (incl.obj x)) ≫ (liftStar F M hM).hom =
(inclLift F M hM).hom.app x ≫ M x := by
erw [Category.id_comp, Category.comp_id]
rfl
/-- The uniqueness of `lift`. -/
@[simp]
def liftUnique {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (M : ∀ x : C, F.obj x ⟶ Z)
(hM : ∀ (x y : C) (f : x ⟶ y), F.map f ≫ M y = M x)
(G : WithTerminal C ⥤ D) (h : incl ⋙ G ≅ F)
(hG : G.obj star ≅ Z)
(hh : ∀ x : C, G.map (starTerminal.from (incl.obj x)) ≫ hG.hom = h.hom.app x ≫ M x) :
G ≅ lift F M hM :=
NatIso.ofComponents
(fun X =>
match X with
| of x => h.app x
| star => hG)
(by
rintro (X | X) (Y | Y) f
· apply h.hom.naturality
· cases f
exact hh _
· cases f
· cases f
change G.map (𝟙 _) ≫ hG.hom = hG.hom ≫ 𝟙 _
simp)
/-- A variant of `lift` with `Z` a terminal object. -/
@[simps!]
def liftToTerminal {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (hZ : Limits.IsTerminal Z) :
WithTerminal C ⥤ D :=
lift F (fun _x => hZ.from _) fun _x _y _f => hZ.hom_ext _ _
/-- A variant of `incl_lift` with `Z` a terminal object. -/
@[simps!]
def inclLiftToTerminal {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (hZ : Limits.IsTerminal Z) :
incl ⋙ liftToTerminal F hZ ≅ F :=
inclLift _ _ _
/-- A variant of `lift_unique` with `Z` a terminal object. -/
@[simps!]
def liftToTerminalUnique {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (hZ : Limits.IsTerminal Z)
(G : WithTerminal C ⥤ D) (h : incl ⋙ G ≅ F) (hG : G.obj star ≅ Z) : G ≅ liftToTerminal F hZ :=
liftUnique F (fun _z => hZ.from _) (fun _x _y _f => hZ.hom_ext _ _) G h hG fun _x =>
hZ.hom_ext _ _
/-- Constructs a morphism to `star` from `of X`. -/
@[simp]
def homFrom (X : C) : incl.obj X ⟶ star :=
starTerminal.from _
instance isIso_of_from_star {X : WithTerminal C} (f : star ⟶ X) : IsIso f :=
match X with
| of _X => f.elim
| star => ⟨f, rfl, rfl⟩
end WithTerminal
namespace WithInitial
variable {C}
/-- Morphisms for `WithInitial C`. -/
-- Porting note(#5171): removed `nolint has_nonempty_instance`
@[simp]
def Hom : WithInitial C → WithInitial C → Type v
| of X, of Y => X ⟶ Y
| of _, _ => PEmpty
| star, _ => PUnit
/-- Identity morphisms for `WithInitial C`. -/
@[simp]
def id : ∀ X : WithInitial C, Hom X X
| of _ => 𝟙 _
| star => PUnit.unit
/-- Composition of morphisms for `WithInitial C`. -/
@[simp]
def comp : ∀ {X Y Z : WithInitial C}, Hom X Y → Hom Y Z → Hom X Z
| of _X, of _Y, of _Z => fun f g => f ≫ g
| star, _, of _X => fun _f _g => PUnit.unit
| _, of _X, star => fun _f g => PEmpty.elim g
| of _Y, star, _ => fun f _g => PEmpty.elim f
| star, star, star => fun _ _ => PUnit.unit
instance : Category.{v} (WithInitial C) where
Hom X Y := Hom X Y
id X := id X
comp f g := comp f g
assoc {a b c d} f g h := by
-- Porting note: it would be nice to automate this away as well.
-- See the note on `Category (WithTerminal C)`
cases a <;> cases b <;> cases c <;> cases d <;> try aesop_cat
· exact (g : PEmpty).elim
· exact (f : PEmpty).elim
· exact (f : PEmpty).elim
/-- Helper function for typechecking. -/
def down {X Y : C} (f : of X ⟶ of Y) : X ⟶ Y := f
@[simp] lemma down_id {X : C} : down (𝟙 (of X)) = 𝟙 X := rfl
@[simp] lemma down_comp {X Y Z : C} (f : of X ⟶ of Y) (g : of Y ⟶ of Z) :
down (f ≫ g) = down f ≫ down g :=
rfl
@[aesop safe destruct (rule_sets := [CategoryTheory])]
lemma false_of_to_star {X : C} (f : of X ⟶ star) : False := (f : PEmpty).elim
/-- The inclusion of `C` into `WithInitial C`. -/
def incl : C ⥤ WithInitial C where
obj := of
map f := f
instance : (incl : C ⥤ _).Full where
map_surjective f := ⟨f, rfl⟩
instance : (incl : C ⥤ _).Faithful where
/-- Map `WithInitial` with respect to a functor `F : C ⥤ D`. -/
@[simps]
def map {D : Type*} [Category D] (F : C ⥤ D) : WithInitial C ⥤ WithInitial D where
obj X :=
match X with
| of x => of <| F.obj x
| star => star
map {X Y} f :=
match X, Y, f with
| of x, of y, f => F.map (down f)
| star, of _, _ => PUnit.unit
| star, star, _ => PUnit.unit
/-- A natural isomorphism between the functor `map (𝟭 C)` and `𝟭 (WithInitial C)`. -/
@[simps!]
def mapId (C : Type*) [Category C] : map (𝟭 C) ≅ 𝟭 (WithInitial C) :=
NatIso.ofComponents (fun X => match X with
| of x => Iso.refl _
| star => Iso.refl _) (by aesop_cat)
/-- A natural isomorphism between the functor `map (F ⋙ G) ` and `map F ⋙ map G `. -/
@[simps!]
def mapComp {D E : Type*} [Category D] [Category E] (F : C ⥤ D) (G : D ⥤ E) :
map (F ⋙ G) ≅ map F ⋙ map G :=
NatIso.ofComponents (fun X => match X with
| of x => Iso.refl _
| star => Iso.refl _) (by aesop_cat)
/-- From a natrual transformation of functors `C ⥤ D`, the induced natural transformation
of functors `WithInitial C ⥤ WithInitial D`. -/
@[simps]
def map₂ {D : Type*} [Category D] {F G : C ⥤ D} (η : F ⟶ G) : map F ⟶ map G where
app := fun X => match X with
| of x => η.app x
| star => 𝟙 star
naturality := by
intro X Y f
match X, Y, f with
| of x, of y, f => exact η.naturality f
| star, of x, _ => rfl
| star, star, _ => rfl
/-- The prelax functor from `Cat` to `Cat` defined with `WithInitial`. -/
@[simps]
def prelaxfunctor : PrelaxFunctor Cat Cat where
obj C := Cat.of (WithInitial C)
map := map
map₂ := map₂
map₂_id := by
intros
apply NatTrans.ext
funext X
cases X <;> rfl
map₂_comp := by
intros
apply NatTrans.ext
funext X
cases X <;> rfl
/-- The pseudofunctor from `Cat` to `Cat` defined with `WithInitial`. -/
@[simps]
def pseudofunctor : Pseudofunctor Cat Cat where
toPrelaxFunctor := prelaxfunctor
mapId C := mapId C
mapComp := mapComp
map₂_whisker_left := by
intros
apply NatTrans.ext
funext X
cases X
· rw [NatTrans.comp_app, NatTrans.comp_app]
simp only [prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_obj,
prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_map, map_obj, Cat.comp_obj,
prelaxfunctor_toPrelaxFunctorStruct_map₂, map₂_app, Cat.whiskerLeft_app, mapComp_hom_app,
Iso.refl_hom, mapComp_inv_app, Iso.refl_inv, Category.comp_id, Category.id_comp]
· rfl
map₂_whisker_right := by
intros
apply NatTrans.ext
funext X
cases X
· rw [NatTrans.comp_app, NatTrans.comp_app]
simp only [prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_obj,
prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_map, map_obj, Cat.comp_obj,
prelaxfunctor_toPrelaxFunctorStruct_map₂, map₂_app, Cat.whiskerRight_app, mapComp_hom_app,
Iso.refl_hom, map_map, mapComp_inv_app, Iso.refl_inv, Category.comp_id, Category.id_comp]
rfl
· rfl
map₂_associator := by
intros
apply NatTrans.ext
funext X
cases X
· rw [NatTrans.comp_app,NatTrans.comp_app,NatTrans.comp_app,NatTrans.comp_app]
simp only [prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_obj,
prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_map, map_obj, Cat.comp_obj,
Bicategory.Strict.associator_eqToIso, eqToIso_refl, Iso.refl_hom,
prelaxfunctor_toPrelaxFunctorStruct_map₂, map₂_app, mapComp_hom_app, Cat.whiskerRight_app,
map_map, down_id, Functor.map_id, Cat.whiskerLeft_app, mapComp_inv_app, Iso.refl_inv,
Category.comp_id, Category.id_comp]
rw [NatTrans.id_app, NatTrans.id_app]
simp only [Cat.comp_obj, map_obj, Category.comp_id]
· rfl
map₂_left_unitor := by
intros
apply NatTrans.ext
funext X
cases X
· rw [NatTrans.comp_app, NatTrans.comp_app]
simp only [prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_obj,
prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_map, map_obj, Cat.comp_obj,
Bicategory.Strict.leftUnitor_eqToIso, eqToIso_refl, Iso.refl_hom,
prelaxfunctor_toPrelaxFunctorStruct_map₂, map₂_app, mapComp_hom_app, Cat.whiskerRight_app,
mapId_hom_app, map_map, Category.id_comp]
rw [NatTrans.id_app, NatTrans.id_app]
simp only [Cat.comp_obj, map_obj, Category.comp_id]
rw [← Functor.map_id]
rfl
· rfl
map₂_right_unitor := by
intros
apply NatTrans.ext
funext X
cases X
· rw [NatTrans.comp_app, NatTrans.comp_app]
simp only [prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_obj,
prelaxfunctor_toPrelaxFunctorStruct_toPrefunctor_map, map_obj, Cat.comp_obj,
Bicategory.Strict.rightUnitor_eqToIso, eqToIso_refl, Iso.refl_hom,
prelaxfunctor_toPrelaxFunctorStruct_map₂, map₂_app, mapComp_hom_app, Cat.whiskerLeft_app,
mapId_hom_app, Category.id_comp]
rw [NatTrans.id_app, NatTrans.id_app]
simp only [Cat.comp_obj, map_obj, Category.comp_id]
rw [← Functor.map_id, Cat.id_map]
rfl
· rfl
instance {X : WithInitial C} : Unique (star ⟶ X) where
default :=
match X with
| of _x => PUnit.unit
| star => PUnit.unit
uniq := by aesop_cat
/-- `WithInitial.star` is initial. -/
def starInitial : Limits.IsInitial (star : WithInitial C) :=
Limits.IsInitial.ofUnique _
/-- Lift a functor `F : C ⥤ D` to `WithInitial C ⥤ D`. -/
@[simps]
def lift {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (M : ∀ x : C, Z ⟶ F.obj x)
(hM : ∀ (x y : C) (f : x ⟶ y), M x ≫ F.map f = M y) : WithInitial C ⥤ D where
obj X :=
match X with
| of x => F.obj x
| star => Z
map {X Y} f :=
match X, Y, f with
| of x, of y, f => F.map (down f)
| star, of x, _ => M _
| star, star, _ => 𝟙 _
/-- The isomorphism between `incl ⋙ lift F _ _` with `F`. -/
@[simps!]
def inclLift {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (M : ∀ x : C, Z ⟶ F.obj x)
(hM : ∀ (x y : C) (f : x ⟶ y), M x ≫ F.map f = M y) : incl ⋙ lift F M hM ≅ F where
hom := { app := fun X => 𝟙 _ }
inv := { app := fun X => 𝟙 _ }
/-- The isomorphism between `(lift F _ _).obj WithInitial.star` with `Z`. -/
@[simps!]
def liftStar {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (M : ∀ x : C, Z ⟶ F.obj x)
(hM : ∀ (x y : C) (f : x ⟶ y), M x ≫ F.map f = M y) : (lift F M hM).obj star ≅ Z :=
eqToIso rfl
theorem liftStar_lift_map {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (M : ∀ x : C, Z ⟶ F.obj x)
(hM : ∀ (x y : C) (f : x ⟶ y), M x ≫ F.map f = M y) (x : C) :
(liftStar F M hM).hom ≫ (lift F M hM).map (starInitial.to (incl.obj x)) =
M x ≫ (inclLift F M hM).hom.app x := by
erw [Category.id_comp, Category.comp_id]
rfl
/-- The uniqueness of `lift`. -/
@[simp]
def liftUnique {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (M : ∀ x : C, Z ⟶ F.obj x)
(hM : ∀ (x y : C) (f : x ⟶ y), M x ≫ F.map f = M y)
(G : WithInitial C ⥤ D) (h : incl ⋙ G ≅ F)
(hG : G.obj star ≅ Z)
(hh : ∀ x : C, hG.symm.hom ≫ G.map (starInitial.to (incl.obj x)) = M x ≫ h.symm.hom.app x) :
G ≅ lift F M hM :=
NatIso.ofComponents
(fun X =>
match X with
| of x => h.app x
| star => hG)
(by
rintro (X | X) (Y | Y) f
· apply h.hom.naturality
· cases f
· cases f
change G.map _ ≫ h.hom.app _ = hG.hom ≫ _
symm
erw [← Iso.eq_inv_comp, ← Category.assoc, hh]
simp
· cases f
change G.map (𝟙 _) ≫ hG.hom = hG.hom ≫ 𝟙 _
simp)
/-- A variant of `lift` with `Z` an initial object. -/
@[simps!]
def liftToInitial {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (hZ : Limits.IsInitial Z) :
WithInitial C ⥤ D :=
lift F (fun _x => hZ.to _) fun _x _y _f => hZ.hom_ext _ _
/-- A variant of `incl_lift` with `Z` an initial object. -/
@[simps!]
def inclLiftToInitial {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (hZ : Limits.IsInitial Z) :
incl ⋙ liftToInitial F hZ ≅ F :=
inclLift _ _ _
/-- A variant of `lift_unique` with `Z` an initial object. -/
@[simps!]
def liftToInitialUnique {D : Type*} [Category D] {Z : D} (F : C ⥤ D) (hZ : Limits.IsInitial Z)
(G : WithInitial C ⥤ D) (h : incl ⋙ G ≅ F) (hG : G.obj star ≅ Z) : G ≅ liftToInitial F hZ :=
liftUnique F (fun _z => hZ.to _) (fun _x _y _f => hZ.hom_ext _ _) G h hG fun _x => hZ.hom_ext _ _
/-- Constructs a morphism from `star` to `of X`. -/
@[simp]
def homTo (X : C) : star ⟶ incl.obj X :=
starInitial.to _
-- Porting note: need to do cases analysis
instance isIso_of_to_star {X : WithInitial C} (f : X ⟶ star) : IsIso f :=
match X with
| of _X => f.elim
| star => ⟨f, rfl, rfl⟩
end WithInitial
end CategoryTheory
|
CategoryTheory\Yoneda.lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.CategoryTheory.Functor.Hom
import Mathlib.CategoryTheory.Products.Basic
import Mathlib.Data.ULift
import Mathlib.Logic.Function.ULift
/-!
# The Yoneda embedding
The Yoneda embedding as a functor `yoneda : C ⥤ (Cᵒᵖ ⥤ Type v₁)`,
along with an instance that it is `FullyFaithful`.
Also the Yoneda lemma, `yonedaLemma : (yoneda_pairing C) ≅ (yoneda_evaluation C)`.
## References
* [Stacks: Opposite Categories and the Yoneda Lemma](https://stacks.math.columbia.edu/tag/001L)
-/
namespace CategoryTheory
open Opposite
universe v₁ u₁ u₂
-- morphism levels before object levels. See note [CategoryTheory universes].
variable {C : Type u₁} [Category.{v₁} C]
/-- The Yoneda embedding, as a functor from `C` into presheaves on `C`.
See <https://stacks.math.columbia.edu/tag/001O>.
-/
@[simps]
def yoneda : C ⥤ Cᵒᵖ ⥤ Type v₁ where
obj X :=
{ obj := fun Y => unop Y ⟶ X
map := fun f g => f.unop ≫ g }
map f :=
{ app := fun Y g => g ≫ f }
/-- The co-Yoneda embedding, as a functor from `Cᵒᵖ` into co-presheaves on `C`.
-/
@[simps]
def coyoneda : Cᵒᵖ ⥤ C ⥤ Type v₁ where
obj X :=
{ obj := fun Y => unop X ⟶ Y
map := fun f g => g ≫ f }
map f :=
{ app := fun Y g => f.unop ≫ g }
namespace Yoneda
theorem obj_map_id {X Y : C} (f : op X ⟶ op Y) :
(yoneda.obj X).map f (𝟙 X) = (yoneda.map f.unop).app (op Y) (𝟙 Y) := by
dsimp
simp
@[simp]
theorem naturality {X Y : C} (α : yoneda.obj X ⟶ yoneda.obj Y) {Z Z' : C} (f : Z ⟶ Z')
(h : Z' ⟶ X) : f ≫ α.app (op Z') h = α.app (op Z) (f ≫ h) :=
(FunctorToTypes.naturality _ _ α f.op h).symm
/-- The Yoneda embedding is fully faithful. -/
def fullyFaithful : (yoneda (C := C)).FullyFaithful where
preimage f := f.app _ (𝟙 _)
lemma fullyFaithful_preimage {X Y : C} (f : yoneda.obj X ⟶ yoneda.obj Y) :
fullyFaithful.preimage f = f.app (op X) (𝟙 X) := rfl
/-- The Yoneda embedding is full.
See <https://stacks.math.columbia.edu/tag/001P>.
-/
instance yoneda_full : (yoneda : C ⥤ Cᵒᵖ ⥤ Type v₁).Full :=
fullyFaithful.full
/-- The Yoneda embedding is faithful.
See <https://stacks.math.columbia.edu/tag/001P>.
-/
instance yoneda_faithful : (yoneda : C ⥤ Cᵒᵖ ⥤ Type v₁).Faithful :=
fullyFaithful.faithful
/-- Extensionality via Yoneda. The typical usage would be
```
-- Goal is `X ≅ Y`
apply yoneda.ext,
-- Goals are now functions `(Z ⟶ X) → (Z ⟶ Y)`, `(Z ⟶ Y) → (Z ⟶ X)`, and the fact that these
-- functions are inverses and natural in `Z`.
```
-/
def ext (X Y : C) (p : ∀ {Z : C}, (Z ⟶ X) → (Z ⟶ Y))
(q : ∀ {Z : C}, (Z ⟶ Y) → (Z ⟶ X))
(h₁ : ∀ {Z : C} (f : Z ⟶ X), q (p f) = f) (h₂ : ∀ {Z : C} (f : Z ⟶ Y), p (q f) = f)
(n : ∀ {Z Z' : C} (f : Z' ⟶ Z) (g : Z ⟶ X), p (f ≫ g) = f ≫ p g) : X ≅ Y :=
fullyFaithful.preimageIso
(NatIso.ofComponents fun Z =>
{ hom := p
inv := q })
/-- If `yoneda.map f` is an isomorphism, so was `f`.
-/
theorem isIso {X Y : C} (f : X ⟶ Y) [IsIso (yoneda.map f)] : IsIso f :=
isIso_of_fully_faithful yoneda f
end Yoneda
namespace Coyoneda
@[simp]
theorem naturality {X Y : Cᵒᵖ} (α : coyoneda.obj X ⟶ coyoneda.obj Y) {Z Z' : C} (f : Z' ⟶ Z)
(h : unop X ⟶ Z') : α.app Z' h ≫ f = α.app Z (h ≫ f) :=
(FunctorToTypes.naturality _ _ α f h).symm
/-- The co-Yoneda embedding is fully faithful. -/
def fullyFaithful : (coyoneda (C := C)).FullyFaithful where
preimage f := (f.app _ (𝟙 _)).op
lemma fullyFaithful_preimage {X Y : Cᵒᵖ} (f : coyoneda.obj X ⟶ coyoneda.obj Y) :
fullyFaithful.preimage f = (f.app X.unop (𝟙 X.unop)).op := rfl
/-- The morphism `X ⟶ Y` corresponding to a natural transformation
`coyoneda.obj X ⟶ coyoneda.obj Y`. -/
def preimage {X Y : Cᵒᵖ} (f : coyoneda.obj X ⟶ coyoneda.obj Y) : X ⟶ Y :=
(f.app _ (𝟙 X.unop)).op
instance coyoneda_full : (coyoneda : Cᵒᵖ ⥤ C ⥤ Type v₁).Full :=
fullyFaithful.full
instance coyoneda_faithful : (coyoneda : Cᵒᵖ ⥤ C ⥤ Type v₁).Faithful :=
fullyFaithful.faithful
/-- If `coyoneda.map f` is an isomorphism, so was `f`.
-/
theorem isIso {X Y : Cᵒᵖ} (f : X ⟶ Y) [IsIso (coyoneda.map f)] : IsIso f :=
isIso_of_fully_faithful coyoneda f
/-- The identity functor on `Type` is isomorphic to the coyoneda functor coming from `PUnit`. -/
def punitIso : coyoneda.obj (Opposite.op PUnit) ≅ 𝟭 (Type v₁) :=
NatIso.ofComponents fun X =>
{ hom := fun f => f ⟨⟩
inv := fun x _ => x }
/-- Taking the `unop` of morphisms is a natural isomorphism. -/
@[simps!]
def objOpOp (X : C) : coyoneda.obj (op (op X)) ≅ yoneda.obj X :=
NatIso.ofComponents fun _ => (opEquiv _ _).toIso
end Coyoneda
namespace Functor
/-- A functor `F : Cᵒᵖ ⥤ Type v₁` is representable if there is object `X` so `F ≅ yoneda.obj X`.
See <https://stacks.math.columbia.edu/tag/001Q>.
-/
class Representable (F : Cᵒᵖ ⥤ Type v₁) : Prop where
/-- `Hom(-,X) ≅ F` via `f` -/
has_representation : ∃ (X : _), Nonempty (yoneda.obj X ≅ F)
instance {X : C} : Representable (yoneda.obj X) where has_representation := ⟨X, ⟨Iso.refl _⟩⟩
/-- A functor `F : C ⥤ Type v₁` is corepresentable if there is object `X` so `F ≅ coyoneda.obj X`.
See <https://stacks.math.columbia.edu/tag/001Q>.
-/
class Corepresentable (F : C ⥤ Type v₁) : Prop where
/-- `Hom(X,-) ≅ F` via `f` -/
has_corepresentation : ∃ (X : _), Nonempty (coyoneda.obj X ≅ F)
instance {X : Cᵒᵖ} : Corepresentable (coyoneda.obj X) where
has_corepresentation := ⟨X, ⟨Iso.refl _⟩⟩
-- instance : corepresentable (𝟭 (Type v₁)) :=
-- corepresentable_of_nat_iso (op punit) coyoneda.punit_iso
section Representable
variable (F : Cᵒᵖ ⥤ Type v₁)
variable [hF : F.Representable]
/-- The representing object for the representable functor `F`. -/
noncomputable def reprX : C := hF.has_representation.choose
/-- An isomorphism between a representable `F` and a functor of the
form `C(-, F.reprX)`. Note the components `F.reprW.app X`
definitionally have type `(X.unop ⟶ F.repr_X) ≅ F.obj X`.
-/
noncomputable def reprW : yoneda.obj F.reprX ≅ F :=
Representable.has_representation.choose_spec.some
/-- The representing element for the representable functor `F`, sometimes called the universal
element of the functor.
-/
noncomputable def reprx : F.obj (op F.reprX) :=
F.reprW.hom.app (op F.reprX) (𝟙 F.reprX)
theorem reprW_app_hom (X : Cᵒᵖ) (f : unop X ⟶ F.reprX) :
(F.reprW.app X).hom f = F.map f.op F.reprx := by
simp only [yoneda_obj_obj, Iso.app_hom, op_unop, reprx, ← FunctorToTypes.naturality,
yoneda_obj_map, unop_op, Quiver.Hom.unop_op, Category.comp_id]
end Representable
section Corepresentable
variable (F : C ⥤ Type v₁)
variable [hF : F.Corepresentable]
/-- The representing object for the corepresentable functor `F`. -/
noncomputable def coreprX : C :=
hF.has_corepresentation.choose.unop
/-- An isomorphism between a corepresnetable `F` and a functor of the form
`C(F.corepr X, -)`. Note the components `F.coreprW.app X`
definitionally have type `F.corepr_X ⟶ X ≅ F.obj X`.
-/
noncomputable def coreprW : coyoneda.obj (op F.coreprX) ≅ F :=
hF.has_corepresentation.choose_spec.some
/-- The representing element for the corepresentable functor `F`, sometimes called the universal
element of the functor.
-/
noncomputable def coreprx : F.obj F.coreprX :=
F.coreprW.hom.app F.coreprX (𝟙 F.coreprX)
theorem coreprW_app_hom (X : C) (f : F.coreprX ⟶ X) :
(F.coreprW.app X).hom f = F.map f F.coreprx := by
simp only [coyoneda_obj_obj, unop_op, Iso.app_hom, coreprx, ← FunctorToTypes.naturality,
coyoneda_obj_map, Category.id_comp]
end Corepresentable
end Functor
theorem representable_of_natIso (F : Cᵒᵖ ⥤ Type v₁) {G} (i : F ≅ G) [F.Representable] :
G.Representable :=
{ has_representation := ⟨F.reprX, ⟨F.reprW ≪≫ i⟩⟩ }
theorem corepresentable_of_natIso (F : C ⥤ Type v₁) {G} (i : F ≅ G) [F.Corepresentable] :
G.Corepresentable :=
{ has_corepresentation := ⟨op F.coreprX, ⟨F.coreprW ≪≫ i⟩⟩ }
instance : Functor.Corepresentable (𝟭 (Type v₁)) :=
corepresentable_of_natIso (coyoneda.obj (op PUnit)) Coyoneda.punitIso
open Opposite
variable (C)
-- We need to help typeclass inference with some awkward universe levels here.
instance prodCategoryInstance1 : Category ((Cᵒᵖ ⥤ Type v₁) × Cᵒᵖ) :=
CategoryTheory.prod.{max u₁ v₁, v₁} (Cᵒᵖ ⥤ Type v₁) Cᵒᵖ
instance prodCategoryInstance2 : Category (Cᵒᵖ × (Cᵒᵖ ⥤ Type v₁)) :=
CategoryTheory.prod.{v₁, max u₁ v₁} Cᵒᵖ (Cᵒᵖ ⥤ Type v₁)
open Yoneda
section YonedaLemma
variable {C}
/-- We have a type-level equivalence between natural transformations from the yoneda embedding
and elements of `F.obj X`, without any universe switching.
-/
def yonedaEquiv {X : C} {F : Cᵒᵖ ⥤ Type v₁} : (yoneda.obj X ⟶ F) ≃ F.obj (op X) where
toFun η := η.app (op X) (𝟙 X)
invFun ξ := { app := fun Y f ↦ F.map f.op ξ }
left_inv := by
intro η
ext Y f
dsimp
rw [← FunctorToTypes.naturality]
simp
right_inv := by intro ξ; simp
theorem yonedaEquiv_apply {X : C} {F : Cᵒᵖ ⥤ Type v₁} (f : yoneda.obj X ⟶ F) :
yonedaEquiv f = f.app (op X) (𝟙 X) :=
rfl
@[simp]
theorem yonedaEquiv_symm_app_apply {X : C} {F : Cᵒᵖ ⥤ Type v₁} (x : F.obj (op X)) (Y : Cᵒᵖ)
(f : Y.unop ⟶ X) : (yonedaEquiv.symm x).app Y f = F.map f.op x :=
rfl
lemma yonedaEquiv_naturality {X Y : C} {F : Cᵒᵖ ⥤ Type v₁} (f : yoneda.obj X ⟶ F)
(g : Y ⟶ X) : F.map g.op (yonedaEquiv f) = yonedaEquiv (yoneda.map g ≫ f) := by
change (f.app (op X) ≫ F.map g.op) (𝟙 X) = f.app (op Y) (𝟙 Y ≫ g)
rw [← f.naturality]
dsimp
simp
lemma yonedaEquiv_naturality' {X Y : Cᵒᵖ} {F : Cᵒᵖ ⥤ Type v₁} (f : yoneda.obj (unop X) ⟶ F)
(g : X ⟶ Y) : F.map g (yonedaEquiv f) = yonedaEquiv (yoneda.map g.unop ≫ f) :=
yonedaEquiv_naturality _ _
lemma yonedaEquiv_comp {X : C} {F G : Cᵒᵖ ⥤ Type v₁} (α : yoneda.obj X ⟶ F) (β : F ⟶ G) :
yonedaEquiv (α ≫ β) = β.app _ (yonedaEquiv α) :=
rfl
lemma yonedaEquiv_yoneda_map {X Y : C} (f : X ⟶ Y) : yonedaEquiv (yoneda.map f) = f := by
rw [yonedaEquiv_apply]
simp
lemma yonedaEquiv_symm_map {X Y : Cᵒᵖ} (f : X ⟶ Y) {F : Cᵒᵖ ⥤ Type v₁} (t : F.obj X) :
yonedaEquiv.symm (F.map f t) = yoneda.map f.unop ≫ yonedaEquiv.symm t := by
obtain ⟨u, rfl⟩ := yonedaEquiv.surjective t
rw [yonedaEquiv_naturality', Equiv.symm_apply_apply, Equiv.symm_apply_apply]
/-- Two morphisms of presheaves of types `P ⟶ Q` coincide if the precompositions
with morphisms `yoneda.obj X ⟶ P` agree. -/
lemma hom_ext_yoneda {P Q : Cᵒᵖ ⥤ Type v₁} {f g : P ⟶ Q}
(h : ∀ (X : C) (p : yoneda.obj X ⟶ P), p ≫ f = p ≫ g) :
f = g := by
ext X x
simpa only [yonedaEquiv_comp, Equiv.apply_symm_apply]
using congr_arg (yonedaEquiv) (h _ (yonedaEquiv.symm x))
variable (C)
/-- The "Yoneda evaluation" functor, which sends `X : Cᵒᵖ` and `F : Cᵒᵖ ⥤ Type`
to `F.obj X`, functorially in both `X` and `F`.
-/
def yonedaEvaluation : Cᵒᵖ × (Cᵒᵖ ⥤ Type v₁) ⥤ Type max u₁ v₁ :=
evaluationUncurried Cᵒᵖ (Type v₁) ⋙ uliftFunctor
@[simp]
theorem yonedaEvaluation_map_down (P Q : Cᵒᵖ × (Cᵒᵖ ⥤ Type v₁)) (α : P ⟶ Q)
(x : (yonedaEvaluation C).obj P) :
((yonedaEvaluation C).map α x).down = α.2.app Q.1 (P.2.map α.1 x.down) :=
rfl
/-- The "Yoneda pairing" functor, which sends `X : Cᵒᵖ` and `F : Cᵒᵖ ⥤ Type`
to `yoneda.op.obj X ⟶ F`, functorially in both `X` and `F`.
-/
def yonedaPairing : Cᵒᵖ × (Cᵒᵖ ⥤ Type v₁) ⥤ Type max u₁ v₁ :=
Functor.prod yoneda.op (𝟭 (Cᵒᵖ ⥤ Type v₁)) ⋙ Functor.hom (Cᵒᵖ ⥤ Type v₁)
-- Porting note (#5229): we need to provide this `@[ext]` lemma separately,
-- as `ext` will not look through the definition.
@[ext]
lemma yonedaPairingExt {X : Cᵒᵖ × (Cᵒᵖ ⥤ Type v₁)} {x y : (yonedaPairing C).obj X}
(w : ∀ Y, x.app Y = y.app Y) : x = y :=
NatTrans.ext (funext w)
@[simp]
theorem yonedaPairing_map (P Q : Cᵒᵖ × (Cᵒᵖ ⥤ Type v₁)) (α : P ⟶ Q) (β : (yonedaPairing C).obj P) :
(yonedaPairing C).map α β = yoneda.map α.1.unop ≫ β ≫ α.2 :=
rfl
universe w in
variable {C} in
/-- A bijection `(yoneda.obj X ⋙ uliftFunctor ⟶ F) ≃ F.obj (op X)` which is a variant
of `yonedaEquiv` with heterogeneous universes. -/
def yonedaCompUliftFunctorEquiv (F : Cᵒᵖ ⥤ Type max v₁ w) (X : C) :
(yoneda.obj X ⋙ uliftFunctor ⟶ F) ≃ F.obj (op X) where
toFun φ := φ.app (op X) (ULift.up (𝟙 _))
invFun f :=
{ app := fun Y x => F.map (ULift.down x).op f }
left_inv φ := by
ext Y f
dsimp
rw [← FunctorToTypes.naturality]
dsimp
rw [Category.comp_id]
rfl
right_inv f := by aesop_cat
/-- The Yoneda lemma asserts that the Yoneda pairing
`(X : Cᵒᵖ, F : Cᵒᵖ ⥤ Type) ↦ (yoneda.obj (unop X) ⟶ F)`
is naturally isomorphic to the evaluation `(X, F) ↦ F.obj X`.
See <https://stacks.math.columbia.edu/tag/001P>.
-/
def yonedaLemma : yonedaPairing C ≅ yonedaEvaluation C :=
NatIso.ofComponents
(fun X ↦ Equiv.toIso (yonedaEquiv.trans Equiv.ulift.symm))
(by intro (X, F) (Y, G) f
ext (a : yoneda.obj X.unop ⟶ F)
apply ULift.ext
simp only [Functor.prod_obj, Functor.id_obj, types_comp_apply, yonedaEvaluation_map_down]
erw [Equiv.ulift_symm_down, Equiv.ulift_symm_down]
dsimp [yonedaEquiv]
simp [← FunctorToTypes.naturality])
variable {C}
/- Porting note: this used to be two calls to `tidy` -/
/-- The curried version of yoneda lemma when `C` is small. -/
def curriedYonedaLemma {C : Type u₁} [SmallCategory C] :
(yoneda.op ⋙ coyoneda : Cᵒᵖ ⥤ (Cᵒᵖ ⥤ Type u₁) ⥤ Type u₁) ≅ evaluation Cᵒᵖ (Type u₁) :=
NatIso.ofComponents (fun X ↦ NatIso.ofComponents (fun F ↦ Equiv.toIso yonedaEquiv)) (by
intro X Y f
ext a b
dsimp [yonedaEquiv]
simp [← FunctorToTypes.naturality])
/-- The curried version of the Yoneda lemma. -/
def largeCurriedYonedaLemma {C : Type u₁} [Category.{v₁} C] :
yoneda.op ⋙ coyoneda ≅
evaluation Cᵒᵖ (Type v₁) ⋙ (whiskeringRight _ _ _).obj uliftFunctor.{u₁} :=
NatIso.ofComponents
(fun X => NatIso.ofComponents
(fun Y => Equiv.toIso <| yonedaEquiv.trans Equiv.ulift.symm)
(by
intros Y Z f
ext g
rw [← ULift.down_inj]
simpa using yonedaEquiv_comp _ _))
(by
intros Y Z f
ext F g
rw [← ULift.down_inj]
simpa using (yonedaEquiv_naturality _ _).symm)
/-- Version of the Yoneda lemma where the presheaf is fixed but the argument varies. -/
def yonedaOpCompYonedaObj {C : Type u₁} [Category.{v₁} C] (P : Cᵒᵖ ⥤ Type v₁) :
yoneda.op ⋙ yoneda.obj P ≅ P ⋙ uliftFunctor.{u₁} :=
isoWhiskerRight largeCurriedYonedaLemma ((evaluation _ _).obj P)
/-- The curried version of yoneda lemma when `C` is small. -/
def curriedYonedaLemma' {C : Type u₁} [SmallCategory C] :
yoneda ⋙ (whiskeringLeft Cᵒᵖ (Cᵒᵖ ⥤ Type u₁)ᵒᵖ (Type u₁)).obj yoneda.op
≅ 𝟭 (Cᵒᵖ ⥤ Type u₁) :=
NatIso.ofComponents (fun F ↦ NatIso.ofComponents (fun X ↦ Equiv.toIso yonedaEquiv) (by
intro X Y f
ext a
dsimp [yonedaEquiv]
simp [← FunctorToTypes.naturality]))
lemma isIso_of_yoneda_map_bijective {X Y : C} (f : X ⟶ Y)
(hf : ∀ (T : C), Function.Bijective (fun (x : T ⟶ X) => x ≫ f)) :
IsIso f := by
obtain ⟨g, hg : g ≫ f = 𝟙 Y⟩ := (hf Y).2 (𝟙 Y)
exact ⟨g, (hf _).1 (by aesop_cat), hg⟩
end YonedaLemma
section CoyonedaLemma
variable {C}
/-- We have a type-level equivalence between natural transformations from the coyoneda embedding
and elements of `F.obj X.unop`, without any universe switching.
-/
def coyonedaEquiv {X : C} {F : C ⥤ Type v₁} : (coyoneda.obj (op X) ⟶ F) ≃ F.obj X where
toFun η := η.app X (𝟙 X)
invFun ξ := { app := fun Y x ↦ F.map x ξ }
left_inv := fun η ↦ by
ext Y (x : X ⟶ Y)
dsimp
rw [← FunctorToTypes.naturality]
simp
right_inv := by intro ξ; simp
theorem coyonedaEquiv_apply {X : C} {F : C ⥤ Type v₁} (f : coyoneda.obj (op X) ⟶ F) :
coyonedaEquiv f = f.app X (𝟙 X) :=
rfl
@[simp]
theorem coyonedaEquiv_symm_app_apply {X : C} {F : C ⥤ Type v₁} (x : F.obj X) (Y : C)
(f : X ⟶ Y) : (coyonedaEquiv.symm x).app Y f = F.map f x :=
rfl
lemma coyonedaEquiv_naturality {X Y : C} {F : C ⥤ Type v₁} (f : coyoneda.obj (op X) ⟶ F)
(g : X ⟶ Y) : F.map g (coyonedaEquiv f) = coyonedaEquiv (coyoneda.map g.op ≫ f) := by
change (f.app X ≫ F.map g) (𝟙 X) = f.app Y (g ≫ 𝟙 Y)
rw [← f.naturality]
dsimp
simp
lemma coyonedaEquiv_comp {X : C} {F G : C ⥤ Type v₁} (α : coyoneda.obj (op X) ⟶ F) (β : F ⟶ G) :
coyonedaEquiv (α ≫ β) = β.app _ (coyonedaEquiv α) := by
rfl
lemma coyonedaEquiv_coyoneda_map {X Y : C} (f : X ⟶ Y) :
coyonedaEquiv (coyoneda.map f.op) = f := by
rw [coyonedaEquiv_apply]
simp
lemma coyonedaEquiv_symm_map {X Y : C} (f : X ⟶ Y) {F : C ⥤ Type v₁} (t : F.obj X) :
coyonedaEquiv.symm (F.map f t) = coyoneda.map f.op ≫ coyonedaEquiv.symm t := by
obtain ⟨u, rfl⟩ := coyonedaEquiv.surjective t
simp [coyonedaEquiv_naturality u f]
variable (C)
/-- The "Coyoneda evaluation" functor, which sends `X : C` and `F : C ⥤ Type`
to `F.obj X`, functorially in both `X` and `F`.
-/
def coyonedaEvaluation : C × (C ⥤ Type v₁) ⥤ Type max u₁ v₁ :=
evaluationUncurried C (Type v₁) ⋙ uliftFunctor
@[simp]
theorem coyonedaEvaluation_map_down (P Q : C × (C ⥤ Type v₁)) (α : P ⟶ Q)
(x : (coyonedaEvaluation C).obj P) :
((coyonedaEvaluation C).map α x).down = α.2.app Q.1 (P.2.map α.1 x.down) :=
rfl
/-- The "Coyoneda pairing" functor, which sends `X : C` and `F : C ⥤ Type`
to `coyoneda.rightOp.obj X ⟶ F`, functorially in both `X` and `F`.
-/
def coyonedaPairing : C × (C ⥤ Type v₁) ⥤ Type max u₁ v₁ :=
Functor.prod coyoneda.rightOp (𝟭 (C ⥤ Type v₁)) ⋙ Functor.hom (C ⥤ Type v₁)
-- Porting note (#5229): we need to provide this `@[ext]` lemma separately,
-- as `ext` will not look through the definition.
@[ext]
lemma coyonedaPairingExt {X : C × (C ⥤ Type v₁)} {x y : (coyonedaPairing C).obj X}
(w : ∀ Y, x.app Y = y.app Y) : x = y :=
NatTrans.ext (funext w)
@[simp]
theorem coyonedaPairing_map (P Q : C × (C ⥤ Type v₁)) (α : P ⟶ Q) (β : (coyonedaPairing C).obj P) :
(coyonedaPairing C).map α β = coyoneda.map α.1.op ≫ β ≫ α.2 :=
rfl
universe w in
variable {C} in
/-- A bijection `(coyoneda.obj X ⋙ uliftFunctor ⟶ F) ≃ F.obj (unop X)` which is a variant
of `coyonedaEquiv` with heterogeneous universes. -/
def coyonedaCompUliftFunctorEquiv (F : C ⥤ Type max v₁ w) (X : Cᵒᵖ) :
(coyoneda.obj X ⋙ uliftFunctor ⟶ F) ≃ F.obj X.unop where
toFun φ := φ.app X.unop (ULift.up (𝟙 _))
invFun f :=
{ app := fun Y x => F.map (ULift.down x) f }
left_inv φ := by
ext Y f
dsimp
rw [← FunctorToTypes.naturality]
dsimp
rw [Category.id_comp]
rfl
right_inv f := by aesop_cat
/-- The Coyoneda lemma asserts that the Coyoneda pairing
`(X : C, F : C ⥤ Type) ↦ (coyoneda.obj X ⟶ F)`
is naturally isomorphic to the evaluation `(X, F) ↦ F.obj X`.
See <https://stacks.math.columbia.edu/tag/001P>.
-/
def coyonedaLemma : coyonedaPairing C ≅ coyonedaEvaluation C :=
NatIso.ofComponents
(fun X ↦ Equiv.toIso (coyonedaEquiv.trans Equiv.ulift.symm))
(by intro (X, F) (Y, G) f
ext (a : coyoneda.obj (op X) ⟶ F)
apply ULift.ext
simp only [Functor.prod_obj, Functor.id_obj, types_comp_apply, coyonedaEvaluation_map_down]
erw [Equiv.ulift_symm_down, Equiv.ulift_symm_down]
simp [coyonedaEquiv, ← FunctorToTypes.naturality])
variable {C}
/- Porting note: this used to be two calls to `tidy` -/
/-- The curried version of coyoneda lemma when `C` is small. -/
def curriedCoyonedaLemma {C : Type u₁} [SmallCategory C] :
coyoneda.rightOp ⋙ coyoneda ≅ evaluation C (Type u₁) :=
NatIso.ofComponents (fun X ↦ NatIso.ofComponents (fun F ↦ Equiv.toIso coyonedaEquiv)) (by
intro X Y f
ext a b
simp [coyonedaEquiv, ← FunctorToTypes.naturality])
/-- The curried version of the Coyoneda lemma. -/
def largeCurriedCoyonedaLemma {C : Type u₁} [Category.{v₁} C] :
(coyoneda.rightOp ⋙ coyoneda) ≅
evaluation C (Type v₁) ⋙ (whiskeringRight _ _ _).obj uliftFunctor.{u₁} :=
NatIso.ofComponents
(fun X => NatIso.ofComponents
(fun Y => Equiv.toIso <| coyonedaEquiv.trans Equiv.ulift.symm)
(by
intros Y Z f
ext g
rw [← ULift.down_inj]
simpa using coyonedaEquiv_comp _ _))
(by
intro Y Z f
ext F g
rw [← ULift.down_inj]
simpa using (coyonedaEquiv_naturality _ _).symm)
/-- Version of the Coyoneda lemma where the presheaf is fixed but the argument varies. -/
def coyonedaCompYonedaObj {C : Type u₁} [Category.{v₁} C] (P : C ⥤ Type v₁) :
coyoneda.rightOp ⋙ yoneda.obj P ≅ P ⋙ uliftFunctor.{u₁} :=
isoWhiskerRight largeCurriedCoyonedaLemma ((evaluation _ _).obj P)
/-- The curried version of coyoneda lemma when `C` is small. -/
def curriedCoyonedaLemma' {C : Type u₁} [SmallCategory C] :
yoneda ⋙ (whiskeringLeft C (C ⥤ Type u₁)ᵒᵖ (Type u₁)).obj coyoneda.rightOp
≅ 𝟭 (C ⥤ Type u₁) :=
NatIso.ofComponents (fun F ↦ NatIso.ofComponents (fun X ↦ Equiv.toIso coyonedaEquiv) (by
intro X Y f
ext a
simp [coyonedaEquiv, ← FunctorToTypes.naturality]))
lemma isIso_of_coyoneda_map_bijective {X Y : C} (f : X ⟶ Y)
(hf : ∀ (T : C), Function.Bijective (fun (x : Y ⟶ T) => f ≫ x)) :
IsIso f := by
obtain ⟨g, hg : f ≫ g = 𝟙 X⟩ := (hf X).2 (𝟙 X)
refine ⟨g, hg, (hf _).1 ?_⟩
simp only [Category.comp_id, ← Category.assoc, hg, Category.id_comp]
end CoyonedaLemma
section
variable {C}
variable {D : Type*} [Category.{v₁} D] (F : C ⥤ D)
/-- The natural transformation `yoneda.obj X ⟶ F.op ⋙ yoneda.obj (F.obj X)`
when `F : C ⥤ D` and `X : C`. -/
def yonedaMap (X : C) : yoneda.obj X ⟶ F.op ⋙ yoneda.obj (F.obj X) where
app X f := F.map f
@[simp]
lemma yonedaMap_app_apply {Y : C} {X : Cᵒᵖ} (f : X.unop ⟶ Y) :
(yonedaMap F Y).app X f = F.map f := rfl
end
end CategoryTheory
|
CategoryTheory\Abelian\Basic.lean | /-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel, Johan Commelin, Scott Morrison
-/
import Mathlib.CategoryTheory.Limits.Constructions.Pullbacks
import Mathlib.CategoryTheory.Preadditive.Biproducts
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Kernels
import Mathlib.CategoryTheory.Limits.Shapes.Images
import Mathlib.CategoryTheory.Limits.Constructions.LimitsOfProductsAndEqualizers
import Mathlib.CategoryTheory.Abelian.NonPreadditive
/-!
# Abelian categories
This file contains the definition and basic properties of abelian categories.
There are many definitions of abelian category. Our definition is as follows:
A category is called abelian if it is preadditive,
has a finite products, kernels and cokernels,
and if every monomorphism and epimorphism is normal.
It should be noted that if we also assume coproducts, then preadditivity is
actually a consequence of the other properties, as we show in
`NonPreadditiveAbelian.lean`. However, this fact is of little practical
relevance, since essentially all interesting abelian categories come with a
preadditive structure. In this way, by requiring preadditivity, we allow the
user to pass in the "native" preadditive structure for the specific category they are
working with.
## Main definitions
* `Abelian` is the type class indicating that a category is abelian. It extends `Preadditive`.
* `Abelian.image f` is `kernel (cokernel.π f)`, and
* `Abelian.coimage f` is `cokernel (kernel.ι f)`.
## Main results
* In an abelian category, mono + epi = iso.
* If `f : X ⟶ Y`, then the map `factorThruImage f : X ⟶ image f` is an epimorphism, and the map
`factorThruCoimage f : coimage f ⟶ Y` is a monomorphism.
* Factoring through the image and coimage is a strong epi-mono factorisation. This means that
* every abelian category has images. We provide the isomorphism
`imageIsoImage : abelian.image f ≅ limits.image f`.
* the canonical morphism `coimageImageComparison : coimage f ⟶ image f`
is an isomorphism.
* We provide the alternate characterisation of an abelian category as a category with
(co)kernels and finite products, and in which the canonical coimage-image comparison morphism
is always an isomorphism.
* Every epimorphism is a cokernel of its kernel. Every monomorphism is a kernel of its cokernel.
* The pullback of an epimorphism is an epimorphism. The pushout of a monomorphism is a monomorphism.
(This is not to be confused with the fact that the pullback of a monomorphism is a monomorphism,
which is true in any category).
## Implementation notes
The typeclass `Abelian` does not extend `NonPreadditiveAbelian`,
to avoid having to deal with comparing the two `HasZeroMorphisms` instances
(one from `Preadditive` in `Abelian`, and the other a field of `NonPreadditiveAbelian`).
As a consequence, at the beginning of this file we trivially build
a `NonPreadditiveAbelian` instance from an `Abelian` instance,
and use this to restate a number of theorems,
in each case just reusing the proof from `NonPreadditiveAbelian.lean`.
We don't show this yet, but abelian categories are finitely complete and finitely cocomplete.
However, the limits we can construct at this level of generality will most likely be less nice than
the ones that can be created in specific applications. For this reason, we adopt the following
convention:
* If the statement of a theorem involves limits, the existence of these limits should be made an
explicit typeclass parameter.
* If a limit only appears in a proof, but not in the statement of a theorem, the limit should not
be a typeclass parameter, but instead be created using `Abelian.hasPullbacks` or a similar
definition.
## References
* [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2]
* [P. Aluffi, *Algebra: Chapter 0*][aluffi2016]
-/
noncomputable section
open CategoryTheory
open CategoryTheory.Preadditive
open CategoryTheory.Limits
universe v u
namespace CategoryTheory
variable {C : Type u} [Category.{v} C]
variable (C)
/-- A (preadditive) category `C` is called abelian if it has all finite products,
all kernels and cokernels, and if every monomorphism is the kernel of some morphism
and every epimorphism is the cokernel of some morphism.
(This definition implies the existence of zero objects:
finite products give a terminal object, and in a preadditive category
any terminal object is a zero object.)
-/
class Abelian extends Preadditive C, NormalMonoCategory C, NormalEpiCategory C where
[has_finite_products : HasFiniteProducts C]
[has_kernels : HasKernels C]
[has_cokernels : HasCokernels C]
attribute [instance 100] Abelian.has_finite_products
attribute [instance 90] Abelian.has_kernels Abelian.has_cokernels
end CategoryTheory
open CategoryTheory
/-!
We begin by providing an alternative constructor:
a preadditive category with kernels, cokernels, and finite products,
in which the coimage-image comparison morphism is always an isomorphism,
is an abelian category.
-/
namespace CategoryTheory.Abelian
variable {C : Type u} [Category.{v} C] [Preadditive C]
variable [Limits.HasKernels C] [Limits.HasCokernels C]
namespace OfCoimageImageComparisonIsIso
/-- The factorisation of a morphism through its abelian image. -/
@[simps]
def imageMonoFactorisation {X Y : C} (f : X ⟶ Y) : MonoFactorisation f where
I := Abelian.image f
m := kernel.ι _
m_mono := inferInstance
e := kernel.lift _ f (cokernel.condition _)
fac := kernel.lift_ι _ _ _
theorem imageMonoFactorisation_e' {X Y : C} (f : X ⟶ Y) :
(imageMonoFactorisation f).e = cokernel.π _ ≫ Abelian.coimageImageComparison f := by
dsimp
ext
simp only [Abelian.coimageImageComparison, imageMonoFactorisation_e, Category.assoc,
cokernel.π_desc_assoc]
/-- If the coimage-image comparison morphism for a morphism `f` is an isomorphism,
we obtain an image factorisation of `f`. -/
def imageFactorisation {X Y : C} (f : X ⟶ Y) [IsIso (Abelian.coimageImageComparison f)] :
ImageFactorisation f where
F := imageMonoFactorisation f
isImage :=
{ lift := fun F => inv (Abelian.coimageImageComparison f) ≫ cokernel.desc _ F.e F.kernel_ι_comp
lift_fac := fun F => by
rw [imageMonoFactorisation_m]
simp only [Category.assoc]
rw [IsIso.inv_comp_eq]
ext
simp }
instance [HasZeroObject C] {X Y : C} (f : X ⟶ Y) [Mono f]
[IsIso (Abelian.coimageImageComparison f)] : IsIso (imageMonoFactorisation f).e := by
rw [imageMonoFactorisation_e']
exact IsIso.comp_isIso
instance [HasZeroObject C] {X Y : C} (f : X ⟶ Y) [Epi f] : IsIso (imageMonoFactorisation f).m := by
dsimp
infer_instance
variable [∀ {X Y : C} (f : X ⟶ Y), IsIso (Abelian.coimageImageComparison f)]
/-- A category in which coimage-image comparisons are all isomorphisms has images. -/
theorem hasImages : HasImages C :=
{ has_image := fun {_} {_} f => { exists_image := ⟨imageFactorisation f⟩ } }
variable [Limits.HasFiniteProducts C]
attribute [local instance] Limits.HasFiniteBiproducts.of_hasFiniteProducts
/-- A category with finite products in which coimage-image comparisons are all isomorphisms
is a normal mono category.
-/
def normalMonoCategory : NormalMonoCategory C where
normalMonoOfMono f m :=
{ Z := _
g := cokernel.π f
w := by simp
isLimit := by
haveI : Limits.HasImages C := hasImages
haveI : HasEqualizers C := Preadditive.hasEqualizers_of_hasKernels
haveI : HasZeroObject C := Limits.hasZeroObject_of_hasFiniteBiproducts _
have aux : ∀ (s : KernelFork (cokernel.π f)), (limit.lift (parallelPair (cokernel.π f) 0) s
≫ inv (imageMonoFactorisation f).e) ≫ Fork.ι (KernelFork.ofι f (by simp))
= Fork.ι s := ?_
· refine isLimitAux _ (fun A => limit.lift _ _ ≫ inv (imageMonoFactorisation f).e) aux ?_
intro A g hg
rw [KernelFork.ι_ofι] at hg
rw [← cancel_mono f, hg, ← aux, KernelFork.ι_ofι]
· intro A
simp only [KernelFork.ι_ofι, Category.assoc]
convert limit.lift_π A WalkingParallelPair.zero using 2
rw [IsIso.inv_comp_eq, eq_comm]
exact (imageMonoFactorisation f).fac }
/-- A category with finite products in which coimage-image comparisons are all isomorphisms
is a normal epi category.
-/
def normalEpiCategory : NormalEpiCategory C where
normalEpiOfEpi f m :=
{ W := kernel f
g := kernel.ι _
w := kernel.condition _
isColimit := by
haveI : Limits.HasImages C := hasImages
haveI : HasEqualizers C := Preadditive.hasEqualizers_of_hasKernels
haveI : HasZeroObject C := Limits.hasZeroObject_of_hasFiniteBiproducts _
have aux : ∀ (s : CokernelCofork (kernel.ι f)), Cofork.π (CokernelCofork.ofπ f (by simp)) ≫
inv (imageMonoFactorisation f).m ≫ inv (Abelian.coimageImageComparison f) ≫
colimit.desc (parallelPair (kernel.ι f) 0) s = Cofork.π s := ?_
· refine isColimitAux _ (fun A => inv (imageMonoFactorisation f).m ≫
inv (Abelian.coimageImageComparison f) ≫ colimit.desc _ _) aux ?_
intro A g hg
rw [CokernelCofork.π_ofπ] at hg
rw [← cancel_epi f, hg, ← aux, CokernelCofork.π_ofπ]
· intro A
simp only [CokernelCofork.π_ofπ, ← Category.assoc]
convert colimit.ι_desc A WalkingParallelPair.one using 2
rw [IsIso.comp_inv_eq, IsIso.comp_inv_eq, eq_comm, ← imageMonoFactorisation_e']
exact (imageMonoFactorisation f).fac }
end OfCoimageImageComparisonIsIso
variable [∀ {X Y : C} (f : X ⟶ Y), IsIso (Abelian.coimageImageComparison f)]
[Limits.HasFiniteProducts C]
attribute [local instance] OfCoimageImageComparisonIsIso.normalMonoCategory
attribute [local instance] OfCoimageImageComparisonIsIso.normalEpiCategory
/-- A preadditive category with kernels, cokernels, and finite products,
in which the coimage-image comparison morphism is always an isomorphism,
is an abelian category.
The Stacks project uses this characterisation at the definition of an abelian category.
See <https://stacks.math.columbia.edu/tag/0109>.
-/
def ofCoimageImageComparisonIsIso : Abelian C where
end CategoryTheory.Abelian
namespace CategoryTheory.Abelian
variable {C : Type u} [Category.{v} C] [Abelian C]
-- Porting note: the below porting note is from mathlib3!
-- Porting note: this should be an instance,
-- but triggers https://github.com/leanprover/lean4/issues/2055
-- We set it as a local instance instead.
-- instance (priority := 100)
/-- An abelian category has finite biproducts. -/
theorem hasFiniteBiproducts : HasFiniteBiproducts C :=
Limits.HasFiniteBiproducts.of_hasFiniteProducts
attribute [local instance] hasFiniteBiproducts
instance (priority := 100) hasBinaryBiproducts : HasBinaryBiproducts C :=
Limits.hasBinaryBiproducts_of_finite_biproducts _
instance (priority := 100) hasZeroObject : HasZeroObject C :=
hasZeroObject_of_hasInitial_object
section ToNonPreadditiveAbelian
/-- Every abelian category is, in particular, `NonPreadditiveAbelian`. -/
def nonPreadditiveAbelian : NonPreadditiveAbelian C :=
{ ‹Abelian C› with }
end ToNonPreadditiveAbelian
section
/-! We now promote some instances that were constructed using `non_preadditive_abelian`. -/
attribute [local instance] nonPreadditiveAbelian
variable {P Q : C} (f : P ⟶ Q)
/-- The map `p : P ⟶ image f` is an epimorphism -/
instance : Epi (Abelian.factorThruImage f) := by infer_instance
instance isIso_factorThruImage [Mono f] : IsIso (Abelian.factorThruImage f) := by infer_instance
/-- The canonical morphism `i : coimage f ⟶ Q` is a monomorphism -/
instance : Mono (Abelian.factorThruCoimage f) := by infer_instance
instance isIso_factorThruCoimage [Epi f] : IsIso (Abelian.factorThruCoimage f) := by infer_instance
end
section Factor
attribute [local instance] nonPreadditiveAbelian
variable {P Q : C} (f : P ⟶ Q)
section
theorem mono_of_kernel_ι_eq_zero (h : kernel.ι f = 0) : Mono f :=
mono_of_kernel_zero h
theorem epi_of_cokernel_π_eq_zero (h : cokernel.π f = 0) : Epi f := by
apply NormalMonoCategory.epi_of_zero_cokernel _ (cokernel f)
simp_rw [← h]
exact IsColimit.ofIsoColimit (colimit.isColimit (parallelPair f 0)) (isoOfπ _)
end
section
variable {f}
theorem image_ι_comp_eq_zero {R : C} {g : Q ⟶ R} (h : f ≫ g = 0) : Abelian.image.ι f ≫ g = 0 :=
zero_of_epi_comp (Abelian.factorThruImage f) <| by simp [h]
theorem comp_coimage_π_eq_zero {R : C} {g : Q ⟶ R} (h : f ≫ g = 0) : f ≫ Abelian.coimage.π g = 0 :=
zero_of_comp_mono (Abelian.factorThruCoimage g) <| by simp [h]
end
/-- Factoring through the image is a strong epi-mono factorisation. -/
@[simps]
def imageStrongEpiMonoFactorisation : StrongEpiMonoFactorisation f where
I := Abelian.image f
m := image.ι f
m_mono := by infer_instance
e := Abelian.factorThruImage f
e_strong_epi := strongEpi_of_epi _
/-- Factoring through the coimage is a strong epi-mono factorisation. -/
@[simps]
def coimageStrongEpiMonoFactorisation : StrongEpiMonoFactorisation f where
I := Abelian.coimage f
m := Abelian.factorThruCoimage f
m_mono := by infer_instance
e := coimage.π f
e_strong_epi := strongEpi_of_epi _
end Factor
section HasStrongEpiMonoFactorisations
/-- An abelian category has strong epi-mono factorisations. -/
instance (priority := 100) : HasStrongEpiMonoFactorisations C :=
HasStrongEpiMonoFactorisations.mk fun f => imageStrongEpiMonoFactorisation f
-- In particular, this means that it has well-behaved images.
example : HasImages C := by infer_instance
example : HasImageMaps C := by infer_instance
end HasStrongEpiMonoFactorisations
section Images
variable {X Y : C} (f : X ⟶ Y)
/-- The coimage-image comparison morphism is always an isomorphism in an abelian category.
See `CategoryTheory.Abelian.ofCoimageImageComparisonIsIso` for the converse.
-/
instance : IsIso (coimageImageComparison f) := by
convert
Iso.isIso_hom
(IsImage.isoExt (coimageStrongEpiMonoFactorisation f).toMonoIsImage
(imageStrongEpiMonoFactorisation f).toMonoIsImage)
ext
change _ = _ ≫ (imageStrongEpiMonoFactorisation f).m
simp [-imageStrongEpiMonoFactorisation_m]
/-- There is a canonical isomorphism between the abelian coimage and the abelian image of a
morphism. -/
abbrev coimageIsoImage : Abelian.coimage f ≅ Abelian.image f :=
asIso (coimageImageComparison f)
/-- There is a canonical isomorphism between the abelian coimage and the categorical image of a
morphism. -/
abbrev coimageIsoImage' : Abelian.coimage f ≅ image f :=
IsImage.isoExt (coimageStrongEpiMonoFactorisation f).toMonoIsImage (Image.isImage f)
theorem coimageIsoImage'_hom :
(coimageIsoImage' f).hom =
cokernel.desc _ (factorThruImage f) (by simp [← cancel_mono (Limits.image.ι f)]) := by
ext
simp only [← cancel_mono (Limits.image.ι f), IsImage.isoExt_hom, cokernel.π_desc,
Category.assoc, IsImage.lift_ι, coimageStrongEpiMonoFactorisation_m,
Limits.image.fac]
theorem factorThruImage_comp_coimageIsoImage'_inv :
factorThruImage f ≫ (coimageIsoImage' f).inv = cokernel.π _ := by
simp only [IsImage.isoExt_inv, image.isImage_lift, image.fac_lift,
coimageStrongEpiMonoFactorisation_e]
/-- There is a canonical isomorphism between the abelian image and the categorical image of a
morphism. -/
abbrev imageIsoImage : Abelian.image f ≅ image f :=
IsImage.isoExt (imageStrongEpiMonoFactorisation f).toMonoIsImage (Image.isImage f)
theorem imageIsoImage_hom_comp_image_ι : (imageIsoImage f).hom ≫ Limits.image.ι _ = kernel.ι _ := by
simp only [IsImage.isoExt_hom, IsImage.lift_ι, imageStrongEpiMonoFactorisation_m]
theorem imageIsoImage_inv :
(imageIsoImage f).inv =
kernel.lift _ (Limits.image.ι f) (by simp [← cancel_epi (factorThruImage f)]) := by
ext
rw [IsImage.isoExt_inv, image.isImage_lift, Limits.image.fac_lift,
imageStrongEpiMonoFactorisation_e, Category.assoc, kernel.lift_ι, equalizer_as_kernel,
kernel.lift_ι, Limits.image.fac]
end Images
section CokernelOfKernel
variable {X Y : C} {f : X ⟶ Y}
attribute [local instance] nonPreadditiveAbelian
/-- In an abelian category, an epi is the cokernel of its kernel. More precisely:
If `f` is an epimorphism and `s` is some limit kernel cone on `f`, then `f` is a cokernel
of `fork.ι s`. -/
def epiIsCokernelOfKernel [Epi f] (s : Fork f 0) (h : IsLimit s) :
IsColimit (CokernelCofork.ofπ f (KernelFork.condition s)) :=
NonPreadditiveAbelian.epiIsCokernelOfKernel s h
/-- In an abelian category, a mono is the kernel of its cokernel. More precisely:
If `f` is a monomorphism and `s` is some colimit cokernel cocone on `f`, then `f` is a kernel
of `cofork.π s`. -/
def monoIsKernelOfCokernel [Mono f] (s : Cofork f 0) (h : IsColimit s) :
IsLimit (KernelFork.ofι f (CokernelCofork.condition s)) :=
NonPreadditiveAbelian.monoIsKernelOfCokernel s h
variable (f)
/-- In an abelian category, any morphism that turns to zero when precomposed with the kernel of an
epimorphism factors through that epimorphism. -/
def epiDesc [Epi f] {T : C} (g : X ⟶ T) (hg : kernel.ι f ≫ g = 0) : Y ⟶ T :=
(epiIsCokernelOfKernel _ (limit.isLimit _)).desc (CokernelCofork.ofπ _ hg)
@[reassoc (attr := simp)]
theorem comp_epiDesc [Epi f] {T : C} (g : X ⟶ T) (hg : kernel.ι f ≫ g = 0) :
f ≫ epiDesc f g hg = g :=
(epiIsCokernelOfKernel _ (limit.isLimit _)).fac (CokernelCofork.ofπ _ hg) WalkingParallelPair.one
/-- In an abelian category, any morphism that turns to zero when postcomposed with the cokernel of a
monomorphism factors through that monomorphism. -/
def monoLift [Mono f] {T : C} (g : T ⟶ Y) (hg : g ≫ cokernel.π f = 0) : T ⟶ X :=
(monoIsKernelOfCokernel _ (colimit.isColimit _)).lift (KernelFork.ofι _ hg)
@[reassoc (attr := simp)]
theorem monoLift_comp [Mono f] {T : C} (g : T ⟶ Y) (hg : g ≫ cokernel.π f = 0) :
monoLift f g hg ≫ f = g :=
(monoIsKernelOfCokernel _ (colimit.isColimit _)).fac (KernelFork.ofι _ hg)
WalkingParallelPair.zero
section
variable {D : Type*} [Category D] [HasZeroMorphisms D]
/-- If `F : D ⥤ C` is a functor to an abelian category, `i : X ⟶ Y` is a morphism
admitting a cokernel such that `F` preserves this cokernel and `F.map i` is a mono,
then `F.map X` identifies to the kernel of `F.map (cokernel.π i)`. -/
noncomputable def isLimitMapConeOfKernelForkOfι
{X Y : D} (i : X ⟶ Y) [HasCokernel i] (F : D ⥤ C)
[F.PreservesZeroMorphisms] [Mono (F.map i)]
[PreservesColimit (parallelPair i 0) F] :
IsLimit (F.mapCone (KernelFork.ofι i (cokernel.condition i))) := by
let e : parallelPair (cokernel.π (F.map i)) 0 ≅ parallelPair (cokernel.π i) 0 ⋙ F :=
parallelPair.ext (Iso.refl _) (asIso (cokernelComparison i F)) (by simp) (by simp)
refine IsLimit.postcomposeInvEquiv e _ ?_
let hi := Abelian.monoIsKernelOfCokernel _ (cokernelIsCokernel (F.map i))
refine IsLimit.ofIsoLimit hi (Fork.ext (Iso.refl _) ?_)
change 𝟙 _ ≫ F.map i ≫ 𝟙 _ = F.map i
rw [Category.comp_id, Category.id_comp]
/-- If `F : D ⥤ C` is a functor to an abelian category, `p : X ⟶ Y` is a morphisms
admitting a kernel such that `F` preserves this kernel and `F.map p` is an epi,
then `F.map Y` identifies to the cokernel of `F.map (kernel.ι p)`. -/
noncomputable def isColimitMapCoconeOfCokernelCoforkOfπ
{X Y : D} (p : X ⟶ Y) [HasKernel p] (F : D ⥤ C)
[F.PreservesZeroMorphisms] [Epi (F.map p)]
[PreservesLimit (parallelPair p 0) F] :
IsColimit (F.mapCocone (CokernelCofork.ofπ p (kernel.condition p))) := by
let e : parallelPair (kernel.ι p) 0 ⋙ F ≅ parallelPair (kernel.ι (F.map p)) 0 :=
parallelPair.ext (asIso (kernelComparison p F)) (Iso.refl _) (by simp) (by simp)
refine IsColimit.precomposeInvEquiv e _ ?_
let hp := Abelian.epiIsCokernelOfKernel _ (kernelIsKernel (F.map p))
refine IsColimit.ofIsoColimit hp (Cofork.ext (Iso.refl _) ?_)
change F.map p ≫ 𝟙 _ = 𝟙 _ ≫ F.map p
rw [Category.comp_id, Category.id_comp]
end
end CokernelOfKernel
section
instance (priority := 100) hasEqualizers : HasEqualizers C :=
Preadditive.hasEqualizers_of_hasKernels
/-- Any abelian category has pullbacks -/
instance (priority := 100) hasPullbacks : HasPullbacks C :=
hasPullbacks_of_hasBinaryProducts_of_hasEqualizers C
end
section
instance (priority := 100) hasCoequalizers : HasCoequalizers C :=
Preadditive.hasCoequalizers_of_hasCokernels
/-- Any abelian category has pushouts -/
instance (priority := 100) hasPushouts : HasPushouts C :=
hasPushouts_of_hasBinaryCoproducts_of_hasCoequalizers C
instance (priority := 100) hasFiniteLimits : HasFiniteLimits C :=
Limits.hasFiniteLimits_of_hasEqualizers_and_finite_products
instance (priority := 100) hasFiniteColimits : HasFiniteColimits C :=
Limits.hasFiniteColimits_of_hasCoequalizers_and_finite_coproducts
end
namespace PullbackToBiproductIsKernel
variable [Limits.HasPullbacks C] {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z)
/-! This section contains a slightly technical result about pullbacks and biproducts.
We will need it in the proof that the pullback of an epimorphism is an epimorphism. -/
/-- The canonical map `pullback f g ⟶ X ⊞ Y` -/
abbrev pullbackToBiproduct : pullback f g ⟶ X ⊞ Y :=
biprod.lift (pullback.fst f g) (pullback.snd f g)
/-- The canonical map `pullback f g ⟶ X ⊞ Y` induces a kernel cone on the map
`biproduct X Y ⟶ Z` induced by `f` and `g`. A slightly more intuitive way to think of
this may be that it induces an equalizer fork on the maps induced by `(f, 0)` and
`(0, g)`. -/
abbrev pullbackToBiproductFork : KernelFork (biprod.desc f (-g)) :=
KernelFork.ofι (pullbackToBiproduct f g) <| by
rw [biprod.lift_desc, comp_neg, pullback.condition, add_right_neg]
/-- The canonical map `pullback f g ⟶ X ⊞ Y` is a kernel of the map induced by
`(f, -g)`. -/
def isLimitPullbackToBiproduct : IsLimit (pullbackToBiproductFork f g) :=
Fork.IsLimit.mk _
(fun s =>
pullback.lift (Fork.ι s ≫ biprod.fst) (Fork.ι s ≫ biprod.snd) <|
sub_eq_zero.1 <| by
rw [Category.assoc, Category.assoc, ← comp_sub, sub_eq_add_neg, ← comp_neg, ←
biprod.desc_eq, KernelFork.condition s])
(fun s => by
apply biprod.hom_ext <;> rw [Fork.ι_ofι, Category.assoc]
· rw [biprod.lift_fst, pullback.lift_fst]
· rw [biprod.lift_snd, pullback.lift_snd])
fun s m h => by apply pullback.hom_ext <;> simp [← h]
end PullbackToBiproductIsKernel
namespace BiproductToPushoutIsCokernel
variable [Limits.HasPushouts C] {W X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z)
/-- The canonical map `Y ⊞ Z ⟶ pushout f g` -/
abbrev biproductToPushout : Y ⊞ Z ⟶ pushout f g :=
biprod.desc (pushout.inl _ _) (pushout.inr _ _)
/-- The canonical map `Y ⊞ Z ⟶ pushout f g` induces a cokernel cofork on the map
`X ⟶ Y ⊞ Z` induced by `f` and `-g`. -/
abbrev biproductToPushoutCofork : CokernelCofork (biprod.lift f (-g)) :=
CokernelCofork.ofπ (biproductToPushout f g) <| by
rw [biprod.lift_desc, neg_comp, pushout.condition, add_right_neg]
/-- The cofork induced by the canonical map `Y ⊞ Z ⟶ pushout f g` is in fact a colimit cokernel
cofork. -/
def isColimitBiproductToPushout : IsColimit (biproductToPushoutCofork f g) :=
Cofork.IsColimit.mk _
(fun s =>
pushout.desc (biprod.inl ≫ Cofork.π s) (biprod.inr ≫ Cofork.π s) <|
sub_eq_zero.1 <| by
rw [← Category.assoc, ← Category.assoc, ← sub_comp, sub_eq_add_neg, ← neg_comp, ←
biprod.lift_eq, Cofork.condition s, zero_comp])
(fun s => by apply biprod.hom_ext' <;> simp)
fun s m h => by apply pushout.hom_ext <;> simp [← h]
end BiproductToPushoutIsCokernel
section EpiPullback
variable [Limits.HasPullbacks C] {W X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z)
/-- In an abelian category, the pullback of an epimorphism is an epimorphism.
Proof from [aluffi2016, IX.2.3], cf. [borceux-vol2, 1.7.6] -/
instance epi_pullback_of_epi_f [Epi f] : Epi (pullback.snd f g) :=
-- It will suffice to consider some morphism e : Y ⟶ R such that
-- pullback.snd f g ≫ e = 0 and show that e = 0.
epi_of_cancel_zero _ fun {R} e h => by
-- Consider the morphism u := (0, e) : X ⊞ Y⟶ R.
let u := biprod.desc (0 : X ⟶ R) e
-- The composite pullback f g ⟶ X ⊞ Y ⟶ R is zero by assumption.
have hu : PullbackToBiproductIsKernel.pullbackToBiproduct f g ≫ u = 0 := by simpa [u]
-- pullbackToBiproduct f g is a kernel of (f, -g), so (f, -g) is a
-- cokernel of pullbackToBiproduct f g
have :=
epiIsCokernelOfKernel _
(PullbackToBiproductIsKernel.isLimitPullbackToBiproduct f g)
-- We use this fact to obtain a factorization of u through (f, -g) via some d : Z ⟶ R.
obtain ⟨d, hd⟩ := CokernelCofork.IsColimit.desc' this u hu
dsimp at d; dsimp [u] at hd
-- But then f ≫ d = 0:
have : f ≫ d = 0 := calc
f ≫ d = (biprod.inl ≫ biprod.desc f (-g)) ≫ d := by rw [biprod.inl_desc]
_ = biprod.inl ≫ u := by rw [Category.assoc, hd]
_ = 0 := biprod.inl_desc _ _
-- But f is an epimorphism, so d = 0...
have : d = 0 := (cancel_epi f).1 (by simpa)
-- ...or, in other words, e = 0.
calc
e = biprod.inr ≫ biprod.desc (0 : X ⟶ R) e := by rw [biprod.inr_desc]
_ = biprod.inr ≫ biprod.desc f (-g) ≫ d := by rw [← hd]
_ = biprod.inr ≫ biprod.desc f (-g) ≫ 0 := by rw [this]
_ = (biprod.inr ≫ biprod.desc f (-g)) ≫ 0 := by rw [← Category.assoc]
_ = 0 := HasZeroMorphisms.comp_zero _ _
/-- In an abelian category, the pullback of an epimorphism is an epimorphism. -/
instance epi_pullback_of_epi_g [Epi g] : Epi (pullback.fst f g) :=
-- It will suffice to consider some morphism e : X ⟶ R such that
-- pullback.fst f g ≫ e = 0 and show that e = 0.
epi_of_cancel_zero _ fun {R} e h => by
-- Consider the morphism u := (e, 0) : X ⊞ Y ⟶ R.
let u := biprod.desc e (0 : Y ⟶ R)
-- The composite pullback f g ⟶ X ⊞ Y ⟶ R is zero by assumption.
have hu : PullbackToBiproductIsKernel.pullbackToBiproduct f g ≫ u = 0 := by simpa [u]
-- pullbackToBiproduct f g is a kernel of (f, -g), so (f, -g) is a
-- cokernel of pullbackToBiproduct f g
have :=
epiIsCokernelOfKernel _
(PullbackToBiproductIsKernel.isLimitPullbackToBiproduct f g)
-- We use this fact to obtain a factorization of u through (f, -g) via some d : Z ⟶ R.
obtain ⟨d, hd⟩ := CokernelCofork.IsColimit.desc' this u hu
dsimp at d; dsimp [u] at hd
-- But then (-g) ≫ d = 0:
have : (-g) ≫ d = 0 := calc
(-g) ≫ d = (biprod.inr ≫ biprod.desc f (-g)) ≫ d := by rw [biprod.inr_desc]
_ = biprod.inr ≫ u := by rw [Category.assoc, hd]
_ = 0 := biprod.inr_desc _ _
-- But g is an epimorphism, thus so is -g, so d = 0...
have : d = 0 := (cancel_epi (-g)).1 (by simpa)
-- ...or, in other words, e = 0.
calc
e = biprod.inl ≫ biprod.desc e (0 : Y ⟶ R) := by rw [biprod.inl_desc]
_ = biprod.inl ≫ biprod.desc f (-g) ≫ d := by rw [← hd]
_ = biprod.inl ≫ biprod.desc f (-g) ≫ 0 := by rw [this]
_ = (biprod.inl ≫ biprod.desc f (-g)) ≫ 0 := by rw [← Category.assoc]
_ = 0 := HasZeroMorphisms.comp_zero _ _
theorem epi_snd_of_isLimit [Epi f] {s : PullbackCone f g} (hs : IsLimit s) : Epi s.snd := by
haveI : Epi (NatTrans.app (limit.cone (cospan f g)).π WalkingCospan.right) :=
Abelian.epi_pullback_of_epi_f f g
apply epi_of_epi_fac (IsLimit.conePointUniqueUpToIso_hom_comp (limit.isLimit _) hs _)
theorem epi_fst_of_isLimit [Epi g] {s : PullbackCone f g} (hs : IsLimit s) : Epi s.fst := by
haveI : Epi (NatTrans.app (limit.cone (cospan f g)).π WalkingCospan.left) :=
Abelian.epi_pullback_of_epi_g f g
apply epi_of_epi_fac (IsLimit.conePointUniqueUpToIso_hom_comp (limit.isLimit _) hs _)
/-- Suppose `f` and `g` are two morphisms with a common codomain and suppose we have written `g` as
an epimorphism followed by a monomorphism. If `f` factors through the mono part of this
factorization, then any pullback of `g` along `f` is an epimorphism. -/
theorem epi_fst_of_factor_thru_epi_mono_factorization (g₁ : Y ⟶ W) [Epi g₁] (g₂ : W ⟶ Z) [Mono g₂]
(hg : g₁ ≫ g₂ = g) (f' : X ⟶ W) (hf : f' ≫ g₂ = f) (t : PullbackCone f g) (ht : IsLimit t) :
Epi t.fst := by
apply epi_fst_of_isLimit _ _ (PullbackCone.isLimitOfFactors f g g₂ f' g₁ hf hg t ht)
end EpiPullback
section MonoPushout
variable [Limits.HasPushouts C] {W X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z)
instance mono_pushout_of_mono_f [Mono f] : Mono (pushout.inr _ _ : Z ⟶ pushout f g) :=
mono_of_cancel_zero _ fun {R} e h => by
let u := biprod.lift (0 : R ⟶ Y) e
have hu : u ≫ BiproductToPushoutIsCokernel.biproductToPushout f g = 0 := by simpa [u]
have :=
monoIsKernelOfCokernel _
(BiproductToPushoutIsCokernel.isColimitBiproductToPushout f g)
obtain ⟨d, hd⟩ := KernelFork.IsLimit.lift' this u hu
dsimp at d
dsimp [u] at hd
have : d ≫ f = 0 := calc
d ≫ f = d ≫ biprod.lift f (-g) ≫ biprod.fst := by rw [biprod.lift_fst]
_ = u ≫ biprod.fst := by rw [← Category.assoc, hd]
_ = 0 := biprod.lift_fst _ _
have : d = 0 := (cancel_mono f).1 (by simpa)
calc
e = biprod.lift (0 : R ⟶ Y) e ≫ biprod.snd := by rw [biprod.lift_snd]
_ = (d ≫ biprod.lift f (-g)) ≫ biprod.snd := by rw [← hd]
_ = (0 ≫ biprod.lift f (-g)) ≫ biprod.snd := by rw [this]
_ = 0 ≫ biprod.lift f (-g) ≫ biprod.snd := by rw [Category.assoc]
_ = 0 := zero_comp
instance mono_pushout_of_mono_g [Mono g] : Mono (pushout.inl f g) :=
mono_of_cancel_zero _ fun {R} e h => by
let u := biprod.lift e (0 : R ⟶ Z)
have hu : u ≫ BiproductToPushoutIsCokernel.biproductToPushout f g = 0 := by simpa [u]
have :=
monoIsKernelOfCokernel _
(BiproductToPushoutIsCokernel.isColimitBiproductToPushout f g)
obtain ⟨d, hd⟩ := KernelFork.IsLimit.lift' this u hu
dsimp at d
dsimp [u] at hd
have : d ≫ (-g) = 0 := calc
d ≫ (-g) = d ≫ biprod.lift f (-g) ≫ biprod.snd := by rw [biprod.lift_snd]
_ = biprod.lift e (0 : R ⟶ Z) ≫ biprod.snd := by rw [← Category.assoc, hd]
_ = 0 := biprod.lift_snd _ _
have : d = 0 := (cancel_mono (-g)).1 (by simpa)
calc
e = biprod.lift e (0 : R ⟶ Z) ≫ biprod.fst := by rw [biprod.lift_fst]
_ = (d ≫ biprod.lift f (-g)) ≫ biprod.fst := by rw [← hd]
_ = (0 ≫ biprod.lift f (-g)) ≫ biprod.fst := by rw [this]
_ = 0 ≫ biprod.lift f (-g) ≫ biprod.fst := by rw [Category.assoc]
_ = 0 := zero_comp
theorem mono_inr_of_isColimit [Mono f] {s : PushoutCocone f g} (hs : IsColimit s) : Mono s.inr := by
haveI : Mono (NatTrans.app (colimit.cocone (span f g)).ι WalkingCospan.right) :=
Abelian.mono_pushout_of_mono_f f g
apply
mono_of_mono_fac (IsColimit.comp_coconePointUniqueUpToIso_hom hs (colimit.isColimit _) _)
theorem mono_inl_of_isColimit [Mono g] {s : PushoutCocone f g} (hs : IsColimit s) : Mono s.inl := by
haveI : Mono (NatTrans.app (colimit.cocone (span f g)).ι WalkingCospan.left) :=
Abelian.mono_pushout_of_mono_g f g
apply
mono_of_mono_fac (IsColimit.comp_coconePointUniqueUpToIso_hom hs (colimit.isColimit _) _)
/-- Suppose `f` and `g` are two morphisms with a common domain and suppose we have written `g` as
an epimorphism followed by a monomorphism. If `f` factors through the epi part of this
factorization, then any pushout of `g` along `f` is a monomorphism. -/
theorem mono_inl_of_factor_thru_epi_mono_factorization (f : X ⟶ Y) (g : X ⟶ Z) (g₁ : X ⟶ W) [Epi g₁]
(g₂ : W ⟶ Z) [Mono g₂] (hg : g₁ ≫ g₂ = g) (f' : W ⟶ Y) (hf : g₁ ≫ f' = f)
(t : PushoutCocone f g) (ht : IsColimit t) : Mono t.inl := by
apply mono_inl_of_isColimit _ _ (PushoutCocone.isColimitOfFactors _ _ _ _ _ hf hg t ht)
end MonoPushout
end CategoryTheory.Abelian
namespace CategoryTheory.NonPreadditiveAbelian
variable (C : Type u) [Category.{v} C] [NonPreadditiveAbelian C]
/-- Every NonPreadditiveAbelian category can be promoted to an abelian category. -/
def abelian : Abelian C :=
{/- We need the `convert`s here because the instances we have are slightly different from the
instances we need: `HasKernels` depends on an instance of `HasZeroMorphisms`. In the
case of `NonPreadditiveAbelian`, this instance is an explicit argument. However, in the case
of `abelian`, the `HasZeroMorphisms` instance is derived from `Preadditive`. So we need to
transform an instance of "has kernels with NonPreadditiveAbelian.HasZeroMorphisms" to an
instance of "has kernels with NonPreadditiveAbelian.Preadditive.HasZeroMorphisms".
Luckily, we have a `subsingleton` instance for `HasZeroMorphisms`, so `convert` can
immediately close the goal it creates for the two instances of `HasZeroMorphisms`,
and the proof is complete. -/
NonPreadditiveAbelian.preadditive with
has_finite_products := by infer_instance
has_kernels := by convert (by infer_instance : Limits.HasKernels C)
has_cokernels := by convert (by infer_instance : Limits.HasCokernels C)
normalMonoOfMono := by
intro _ _ f _
convert normalMonoOfMono f
normalEpiOfEpi := by
intro _ _ f _
convert normalEpiOfEpi f }
end CategoryTheory.NonPreadditiveAbelian
|
CategoryTheory\Abelian\EpiWithInjectiveKernel.lean | /-
Copyright (c) 2024 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Algebra.Homology.ShortComplex.ShortExact
import Mathlib.CategoryTheory.MorphismProperty.Composition
/-!
# Epimorphisms with an injective kernel
In this file, we define the class of morphisms `epiWithInjectiveKernel` in an
abelian category. We show that this property of morphisms is multiplicative.
This shall be used in the file `Mathlib.Algebra.Homology.Factorizations.Basic` in
order to define morphisms of cochain complexes which satisfy this property
degreewise.
-/
namespace CategoryTheory
open Category Limits ZeroObject Preadditive
variable {C : Type*} [Category C] [Abelian C]
namespace Abelian
/-- The class of morphisms in an abelian category that are epimorphisms
and have an injective kernel. -/
def epiWithInjectiveKernel : MorphismProperty C :=
fun _ _ f => Epi f ∧ Injective (kernel f)
/-- A morphism `g : X ⟶ Y` is epi with an injective kernel iff there exists a morphism
`f : I ⟶ X` with `I` injective such that `f ≫ g = 0` and
the short complex `I ⟶ X ⟶ Y` has a splitting. -/
lemma epiWithInjectiveKernel_iff {X Y : C} (g : X ⟶ Y) :
epiWithInjectiveKernel g ↔ ∃ (I : C) (_ : Injective I) (f : I ⟶ X) (w : f ≫ g = 0),
Nonempty (ShortComplex.mk f g w).Splitting := by
constructor
· rintro ⟨_, _⟩
let S := ShortComplex.mk (kernel.ι g) g (by simp)
exact ⟨_, inferInstance, _, S.zero,
⟨ShortComplex.Splitting.ofExactOfRetraction S
(S.exact_of_f_is_kernel (kernelIsKernel g)) (Injective.factorThru (𝟙 _) (kernel.ι g))
(by simp) inferInstance⟩⟩
· rintro ⟨I, _, f, w, ⟨σ⟩⟩
have : IsSplitEpi g := ⟨σ.s, σ.s_g⟩
let e : I ≅ kernel g :=
IsLimit.conePointUniqueUpToIso σ.shortExact.fIsKernel (limit.isLimit _)
exact ⟨inferInstance, Injective.of_iso e inferInstance⟩
lemma epiWithInjectiveKernel_of_iso {X Y : C} (f : X ⟶ Y) [IsIso f] :
epiWithInjectiveKernel f := by
rw [epiWithInjectiveKernel_iff]
exact ⟨0, inferInstance, 0, by simp,
⟨ShortComplex.Splitting.ofIsZeroOfIsIso _ (isZero_zero C) (by dsimp; infer_instance)⟩⟩
instance : (epiWithInjectiveKernel : MorphismProperty C).IsMultiplicative where
id_mem _ := epiWithInjectiveKernel_of_iso _
comp_mem {X Y Z} g₁ g₂ hg₁ hg₂ := by
rw [epiWithInjectiveKernel_iff] at hg₁ hg₂ ⊢
obtain ⟨I₁, _, f₁, w₁, ⟨σ₁⟩⟩ := hg₁
obtain ⟨I₂, _, f₂, w₂, ⟨σ₂⟩⟩ := hg₂
refine ⟨I₁ ⊞ I₂, inferInstance, biprod.fst ≫ f₁ + biprod.snd ≫ f₂ ≫ σ₁.s, ?_, ⟨?_⟩⟩
· ext
· simp [reassoc_of% w₁]
· simp [reassoc_of% σ₁.s_g, w₂]
· exact
{ r := σ₁.r ≫ biprod.inl + g₁ ≫ σ₂.r ≫ biprod.inr
s := σ₂.s ≫ σ₁.s
f_r := by
ext
· simp [σ₁.f_r]
· simp [reassoc_of% w₁]
· simp
· simp [reassoc_of% σ₁.s_g, σ₂.f_r]
s_g := by simp [reassoc_of% σ₁.s_g, σ₂.s_g]
id := by
dsimp
have h := g₁ ≫= σ₂.id =≫ σ₁.s
simp only [add_comp, assoc, comp_add, id_comp] at h
rw [← σ₁.id, ← h]
simp only [comp_add, add_comp, assoc, BinaryBicone.inl_fst_assoc,
BinaryBicone.inr_fst_assoc, zero_comp, comp_zero, add_zero,
BinaryBicone.inl_snd_assoc, BinaryBicone.inr_snd_assoc, zero_add]
abel }
end Abelian
end CategoryTheory
|
CategoryTheory\Abelian\Exact.lean | /-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel, Adam Topaz, Johan Commelin, Jakob von Raumer
-/
import Mathlib.Algebra.Homology.ImageToKernel
import Mathlib.Algebra.Homology.ShortComplex.Exact
import Mathlib.CategoryTheory.Abelian.Opposite
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Zero
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Kernels
import Mathlib.CategoryTheory.Adjunction.Limits
import Mathlib.Tactic.TFAE
/-!
# Exact sequences in abelian categories
In an abelian category, we get several interesting results related to exactness which are not
true in more general settings.
## Main results
* A short complex `S` is exact iff `imageSubobject S.f = kernelSubobject S.g`.
* If `(f, g)` is exact, then `image.ι f` has the universal property of the kernel of `g`.
* `f` is a monomorphism iff `kernel.ι f = 0` iff `Exact 0 f`, and `f` is an epimorphism iff
`cokernel.π = 0` iff `Exact f 0`.
* A faithful functor between abelian categories that preserves zero morphisms reflects exact
sequences.
* `X ⟶ Y ⟶ Z ⟶ 0` is exact if and only if the second map is a cokernel of the first, and
`0 ⟶ X ⟶ Y ⟶ Z` is exact if and only if the first map is a kernel of the second.
* A functor `F` such that for all `S`, we have `S.Exact → (S.map F).Exact` preserves both
finite limits and colimits.
-/
universe v₁ v₂ u₁ u₂
noncomputable section
open CategoryTheory Limits Preadditive
variable {C : Type u₁} [Category.{v₁} C] [Abelian C]
namespace CategoryTheory
namespace ShortComplex
variable (S : ShortComplex C)
attribute [local instance] hasEqualizers_of_hasKernels
theorem exact_iff_epi_imageToKernel' : S.Exact ↔ Epi (imageToKernel' S.f S.g S.zero) := by
rw [S.exact_iff_epi_kernel_lift]
have : factorThruImage S.f ≫ imageToKernel' S.f S.g S.zero = kernel.lift S.g S.f S.zero := by
simp only [← cancel_mono (kernel.ι _), kernel.lift_ι, imageToKernel',
Category.assoc, image.fac]
constructor
· intro
exact epi_of_epi_fac this
· intro
rw [← this]
apply epi_comp
theorem exact_iff_epi_imageToKernel : S.Exact ↔ Epi (imageToKernel S.f S.g S.zero) := by
rw [S.exact_iff_epi_imageToKernel']
apply (MorphismProperty.epimorphisms C).arrow_mk_iso_iff
exact Arrow.isoMk (imageSubobjectIso S.f).symm (kernelSubobjectIso S.g).symm
theorem exact_iff_isIso_imageToKernel : S.Exact ↔ IsIso (imageToKernel S.f S.g S.zero) := by
rw [S.exact_iff_epi_imageToKernel]
constructor
· intro
apply isIso_of_mono_of_epi
· intro
infer_instance
/-- In an abelian category, a short complex `S` is exact
iff `imageSubobject S.f = kernelSubobject S.g`.
-/
theorem exact_iff_image_eq_kernel : S.Exact ↔ imageSubobject S.f = kernelSubobject S.g := by
rw [exact_iff_isIso_imageToKernel]
constructor
· intro
exact Subobject.eq_of_comm (asIso (imageToKernel _ _ S.zero)) (by simp)
· intro h
exact ⟨Subobject.ofLE _ _ h.ge, by ext; simp, by ext; simp⟩
theorem exact_iff_of_forks {cg : KernelFork S.g} (hg : IsLimit cg) {cf : CokernelCofork S.f}
(hf : IsColimit cf) : S.Exact ↔ cg.ι ≫ cf.π = 0 := by
rw [exact_iff_kernel_ι_comp_cokernel_π_zero]
let e₁ := IsLimit.conePointUniqueUpToIso (kernelIsKernel S.g) hg
let e₂ := IsColimit.coconePointUniqueUpToIso (cokernelIsCokernel S.f) hf
have : cg.ι ≫ cf.π = e₁.inv ≫ kernel.ι S.g ≫ cokernel.π S.f ≫ e₂.hom := by
have eq₁ := IsLimit.conePointUniqueUpToIso_inv_comp (kernelIsKernel S.g) hg (.zero)
have eq₂ := IsColimit.comp_coconePointUniqueUpToIso_hom (cokernelIsCokernel S.f) hf (.one)
dsimp at eq₁ eq₂
rw [← eq₁, ← eq₂, Category.assoc]
rw [this, IsIso.comp_left_eq_zero e₁.inv, ← Category.assoc,
IsIso.comp_right_eq_zero _ e₂.hom]
variable {S}
/-- If `(f, g)` is exact, then `Abelian.image.ι S.f` is a kernel of `S.g`. -/
def Exact.isLimitImage (h : S.Exact) :
IsLimit (KernelFork.ofι (Abelian.image.ι S.f)
(Abelian.image_ι_comp_eq_zero S.zero) : KernelFork S.g) := by
rw [exact_iff_kernel_ι_comp_cokernel_π_zero] at h
exact KernelFork.IsLimit.ofι _ _
(fun u hu ↦ kernel.lift (cokernel.π S.f) u
(by rw [← kernel.lift_ι S.g u hu, Category.assoc, h, comp_zero])) (by aesop_cat)
(fun _ _ _ hm => by rw [← cancel_mono (Abelian.image.ι S.f), hm, kernel.lift_ι])
/-- If `(f, g)` is exact, then `image.ι f` is a kernel of `g`. -/
def Exact.isLimitImage' (h : S.Exact) :
IsLimit (KernelFork.ofι (Limits.image.ι S.f)
(image_ι_comp_eq_zero S.zero) : KernelFork S.g) :=
IsKernel.isoKernel _ _ h.isLimitImage (Abelian.imageIsoImage S.f).symm <| IsImage.lift_fac _ _
/-- If `(f, g)` is exact, then `Abelian.coimage.π g` is a cokernel of `f`. -/
def Exact.isColimitCoimage (h : S.Exact) :
IsColimit
(CokernelCofork.ofπ (Abelian.coimage.π S.g) (Abelian.comp_coimage_π_eq_zero S.zero) :
CokernelCofork S.f) := by
rw [exact_iff_kernel_ι_comp_cokernel_π_zero] at h
refine CokernelCofork.IsColimit.ofπ _ _
(fun u hu => cokernel.desc (kernel.ι S.g) u
(by rw [← cokernel.π_desc S.f u hu, ← Category.assoc, h, zero_comp]))
(by aesop_cat) ?_
intros _ _ _ _ hm
ext
rw [hm, cokernel.π_desc]
/-- If `(f, g)` is exact, then `factorThruImage g` is a cokernel of `f`. -/
def Exact.isColimitImage (h : S.Exact) :
IsColimit (CokernelCofork.ofπ (Limits.factorThruImage S.g)
(comp_factorThruImage_eq_zero S.zero)) :=
IsCokernel.cokernelIso _ _ h.isColimitCoimage (Abelian.coimageIsoImage' S.g) <|
(cancel_mono (Limits.image.ι S.g)).1 <| by simp
theorem exact_kernel {X Y : C} (f : X ⟶ Y) :
(ShortComplex.mk (kernel.ι f) f (by simp)).Exact :=
exact_of_f_is_kernel _ (kernelIsKernel f)
theorem exact_cokernel {X Y : C} (f : X ⟶ Y) :
(ShortComplex.mk f (cokernel.π f) (by simp)).Exact :=
exact_of_g_is_cokernel _ (cokernelIsCokernel f)
variable (S)
theorem exact_iff_exact_image_ι :
S.Exact ↔ (ShortComplex.mk (Abelian.image.ι S.f) S.g
(Abelian.image_ι_comp_eq_zero S.zero)).Exact :=
ShortComplex.exact_iff_of_epi_of_isIso_of_mono
{ τ₁ := Abelian.factorThruImage S.f
τ₂ := 𝟙 _
τ₃ := 𝟙 _ }
theorem exact_iff_exact_coimage_π :
S.Exact ↔ (ShortComplex.mk S.f (Abelian.coimage.π S.g)
(Abelian.comp_coimage_π_eq_zero S.zero)).Exact := by
symm
exact ShortComplex.exact_iff_of_epi_of_isIso_of_mono
{ τ₁ := 𝟙 _
τ₂ := 𝟙 _
τ₃ := Abelian.factorThruCoimage S.g }
end ShortComplex
section
open List in
theorem Abelian.tfae_mono {X Y : C} (f : X ⟶ Y) (Z : C) :
TFAE [Mono f, kernel.ι f = 0, (ShortComplex.mk (0 : Z ⟶ X) f zero_comp).Exact] := by
tfae_have 2 → 1
· exact mono_of_kernel_ι_eq_zero _
tfae_have 1 → 2
· intro
rw [← cancel_mono f, kernel.condition, zero_comp]
tfae_have 3 ↔ 1
· exact ShortComplex.exact_iff_mono _ (by simp)
tfae_finish
open List in
theorem Abelian.tfae_epi {X Y : C} (f : X ⟶ Y) (Z : C ) :
TFAE [Epi f, cokernel.π f = 0, (ShortComplex.mk f (0 : Y ⟶ Z) comp_zero).Exact] := by
tfae_have 2 → 1
· exact epi_of_cokernel_π_eq_zero _
tfae_have 1 → 2
· intro
rw [← cancel_epi f, cokernel.condition, comp_zero]
tfae_have 3 ↔ 1
· exact ShortComplex.exact_iff_epi _ (by simp)
tfae_finish
end
namespace Functor
section
variable {D : Type u₂} [Category.{v₂} D] [Abelian D]
variable (F : C ⥤ D) [PreservesZeroMorphisms F]
lemma reflects_exact_of_faithful [F.Faithful] (S : ShortComplex C) (hS : (S.map F).Exact) :
S.Exact := by
rw [ShortComplex.exact_iff_kernel_ι_comp_cokernel_π_zero] at hS ⊢
dsimp at hS
apply F.zero_of_map_zero
obtain ⟨k, hk⟩ :=
kernel.lift' (F.map S.g) (F.map (kernel.ι S.g))
(by simp only [← F.map_comp, kernel.condition, CategoryTheory.Functor.map_zero])
obtain ⟨l, hl⟩ :=
cokernel.desc' (F.map S.f) (F.map (cokernel.π S.f))
(by simp only [← F.map_comp, cokernel.condition, CategoryTheory.Functor.map_zero])
rw [F.map_comp, ← hl, ← hk, Category.assoc, reassoc_of% hS, zero_comp, comp_zero]
end
end Functor
namespace Functor
@[deprecated (since := "2024-07-09")] alias CategoryTheory.Functor.map_exact :=
ShortComplex.Exact.map
open Limits Abelian
variable {A : Type u₁} {B : Type u₂} [Category.{v₁} A] [Category.{v₂} B]
variable [Abelian A] [Abelian B]
variable (L : A ⥤ B)
section
variable [L.PreservesZeroMorphisms]
variable (hL : ∀ (S : ShortComplex A), S.Exact → (S.map L).Exact)
open ZeroObject
/-- A functor which preserves exactness preserves monomorphisms. -/
theorem preservesMonomorphisms_of_map_exact : L.PreservesMonomorphisms where
preserves f hf := by
apply ((Abelian.tfae_mono (L.map f) (L.obj 0)).out 2 0).mp
refine ShortComplex.exact_of_iso ?_ (hL _ (((tfae_mono f 0).out 0 2).mp hf))
exact ShortComplex.isoMk (Iso.refl _) (Iso.refl _) (Iso.refl _)
/-- A functor which preserves exactness preserves epimorphisms. -/
theorem preservesEpimorphisms_of_map_exact : L.PreservesEpimorphisms where
preserves f hf := by
apply ((Abelian.tfae_epi (L.map f) (L.obj 0)).out 2 0).mp
refine ShortComplex.exact_of_iso ?_ (hL _ (((tfae_epi f 0).out 0 2).mp hf))
exact ShortComplex.isoMk (Iso.refl _) (Iso.refl _) (Iso.refl _)
/-- A functor which preserves the exactness of short complexes preserves homology. -/
def preservesHomologyOfMapExact : L.PreservesHomology where
preservesCokernels X Y f := by
have := preservesEpimorphisms_of_map_exact _ hL
apply preservesColimitOfPreservesColimitCocone (cokernelIsCokernel f)
apply (CokernelCofork.isColimitMapCoconeEquiv _ L).2
have : Epi ((ShortComplex.mk _ _ (cokernel.condition f)).map L).g := by
dsimp
infer_instance
exact (hL (ShortComplex.mk _ _ (cokernel.condition f))
(ShortComplex.exact_of_g_is_cokernel _ (cokernelIsCokernel f))).gIsCokernel
preservesKernels X Y f := by
have := preservesMonomorphisms_of_map_exact _ hL
apply preservesLimitOfPreservesLimitCone (kernelIsKernel f)
apply (KernelFork.isLimitMapConeEquiv _ L).2
have : Mono ((ShortComplex.mk _ _ (kernel.condition f)).map L).f := by
dsimp
infer_instance
exact (hL (ShortComplex.mk _ _ (kernel.condition f))
(ShortComplex.exact_of_f_is_kernel _ (kernelIsKernel f))).fIsKernel
@[deprecated (since := "2024-07-09")] alias preservesKernelsOfMapExact :=
PreservesHomology.preservesKernels
@[deprecated (since := "2024-07-09")] alias preservesCokernelsOfMapExact :=
PreservesHomology.preservesCokernels
end
section
/-- A functor preserving zero morphisms, monos, and cokernels preserves homology. -/
def preservesHomologyOfPreservesMonosAndCokernels [PreservesZeroMorphisms L]
[PreservesMonomorphisms L] [∀ {X Y} (f : X ⟶ Y), PreservesColimit (parallelPair f 0) L] :
PreservesHomology L := by
apply preservesHomologyOfMapExact
intro S hS
let φ : (ShortComplex.mk _ _ (Abelian.comp_coimage_π_eq_zero S.zero)).map L ⟶ S.map L :=
{ τ₁ := 𝟙 _
τ₂ := 𝟙 _
τ₃ := L.map (Abelian.factorThruCoimage S.g)
comm₂₃ := by
dsimp
rw [Category.id_comp, ← L.map_comp, cokernel.π_desc] }
apply (ShortComplex.exact_iff_of_epi_of_isIso_of_mono φ).1
apply ShortComplex.exact_of_g_is_cokernel
exact CokernelCofork.mapIsColimit _ ((S.exact_iff_exact_coimage_π).1 hS).gIsCokernel L
/-- A functor preserving zero morphisms, epis, and kernels preserves homology. -/
def preservesHomologyOfPreservesEpisAndKernels [PreservesZeroMorphisms L]
[PreservesEpimorphisms L] [∀ {X Y} (f : X ⟶ Y), PreservesLimit (parallelPair f 0) L] :
PreservesHomology L := by
apply preservesHomologyOfMapExact
intro S hS
let φ : S.map L ⟶ (ShortComplex.mk _ _ (Abelian.image_ι_comp_eq_zero S.zero)).map L :=
{ τ₁ := L.map (Abelian.factorThruImage S.f)
τ₂ := 𝟙 _
τ₃ := 𝟙 _
comm₁₂ := by
dsimp
rw [Category.comp_id, ← L.map_comp, kernel.lift_ι] }
apply (ShortComplex.exact_iff_of_epi_of_isIso_of_mono φ).2
apply ShortComplex.exact_of_f_is_kernel
exact KernelFork.mapIsLimit _ ((S.exact_iff_exact_image_ι).1 hS).fIsKernel L
end
end Functor
end CategoryTheory
|
CategoryTheory\Abelian\Ext.lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Adam Topaz
-/
import Mathlib.Algebra.Category.ModuleCat.Abelian
import Mathlib.Algebra.Homology.Opposite
import Mathlib.CategoryTheory.Abelian.LeftDerived
import Mathlib.CategoryTheory.Abelian.Opposite
import Mathlib.CategoryTheory.Abelian.ProjectiveResolution
import Mathlib.CategoryTheory.Linear.Yoneda
/-!
# Ext
We define `Ext R C n : Cᵒᵖ ⥤ C ⥤ Module R` for any `R`-linear abelian category `C`
by (left) deriving in the first argument of the bifunctor `(X, Y) ↦ ModuleCat.of R (unop X ⟶ Y)`.
## Implementation
TODO (@joelriou): When the derived category enters mathlib, the Ext groups shall be
redefined using morphisms in the derived category, and then it will be possible to
compute `Ext` using both projective or injective resolutions.
-/
noncomputable section
open CategoryTheory Limits
variable (R : Type*) [Ring R] (C : Type*) [Category C] [Abelian C] [Linear R C]
[EnoughProjectives C]
/-- `Ext R C n` is defined by deriving in
the first argument of `(X, Y) ↦ ModuleCat.of R (unop X ⟶ Y)`
(which is the second argument of `linearYoneda`).
-/
-- Porting note: the lemmas `Ext_obj` and `Ext_map` generated by `@[simps]` were
-- being rejected by the type-checking linter; it's unclear exactly why.
-- In any case, these lemmas were not actually used downstream in mathlib3,
-- and seem unlikely to be directly useful (rather than lemmas in terms of resolutions),
-- and so have been removed during porting:
-- @[simps! obj map]
-- Porting note: the mathlib3 proofs of `map_id` and `map_comp` were timing out,
-- but `aesop_cat` is fast if we leave them out.
def Ext (n : ℕ) : Cᵒᵖ ⥤ C ⥤ ModuleCat R :=
Functor.flip
{ obj := fun Y => (((linearYoneda R C).obj Y).rightOp.leftDerived n).leftOp
-- Porting note: if we use dot notation for any of
-- `NatTrans.leftOp` / `NatTrans.rightOp` / `NatTrans.leftDerived`
-- then `aesop_cat` can not discharge the `map_id` and `map_comp` goals.
-- This should be investigated further.
map := fun f =>
NatTrans.leftOp (NatTrans.leftDerived (NatTrans.rightOp ((linearYoneda R C).map f)) n) }
open ZeroObject
variable {R C}
/-- Given a chain complex `X` and an object `Y`, this is the cochain complex
which in degree `i` consists of the module of morphisms `X.X i ⟶ Y`. -/
@[simps! X d]
def ChainComplex.linearYonedaObj {α : Type*} [AddRightCancelSemigroup α] [One α]
(X : ChainComplex C α) (A : Type*) [Ring A] [Linear A C] (Y : C) :
CochainComplex (ModuleCat A) α :=
((((linearYoneda A C).obj Y).rightOp.mapHomologicalComplex _).obj X).unop
namespace CategoryTheory
namespace ProjectiveResolution
variable {X : C} (P : ProjectiveResolution X)
/-- `Ext` can be computed using a projective resolution. -/
def isoExt (n : ℕ) (Y : C) : ((Ext R C n).obj (Opposite.op X)).obj Y ≅
(P.complex.linearYonedaObj R Y).homology n :=
(P.isoLeftDerivedObj ((linearYoneda R C).obj Y).rightOp n).unop.symm ≪≫
(HomologicalComplex.homologyUnop _ _).symm
end ProjectiveResolution
end CategoryTheory
/-- If `X : C` is projective and `n : ℕ`, then `Ext^(n + 1) X Y ≅ 0` for any `Y`. -/
lemma isZero_Ext_succ_of_projective (X Y : C) [Projective X] (n : ℕ) :
IsZero (((Ext R C (n + 1)).obj (Opposite.op X)).obj Y) := by
refine IsZero.of_iso ?_ ((ProjectiveResolution.self X).isoExt (n + 1) Y)
rw [← HomologicalComplex.exactAt_iff_isZero_homology, HomologicalComplex.exactAt_iff]
refine ShortComplex.exact_of_isZero_X₂ _ ?_
dsimp
rw [IsZero.iff_id_eq_zero]
ext (x : _ ⟶ _)
obtain rfl : x = 0 := (HomologicalComplex.isZero_single_obj_X
(ComplexShape.down ℕ) 0 X (n + 1) (by simp)).eq_of_src _ _
rfl
|
CategoryTheory\Abelian\FunctorCategory.lean | /-
Copyright (c) 2022 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.CategoryTheory.Abelian.Basic
import Mathlib.CategoryTheory.Preadditive.FunctorCategory
import Mathlib.CategoryTheory.Limits.Shapes.FunctorCategory
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Kernels
/-!
# If `D` is abelian, then the functor category `C ⥤ D` is also abelian.
-/
noncomputable section
namespace CategoryTheory
open CategoryTheory.Limits
namespace Abelian
section
universe z w v u
-- Porting note: removed restrictions on universes
variable {C : Type u} [Category.{v} C]
variable {D : Type w} [Category.{z} D] [Abelian D]
namespace FunctorCategory
variable {F G : C ⥤ D} (α : F ⟶ G) (X : C)
/-- The abelian coimage in a functor category can be calculated componentwise. -/
@[simps!]
def coimageObjIso : (Abelian.coimage α).obj X ≅ Abelian.coimage (α.app X) :=
PreservesCokernel.iso ((evaluation C D).obj X) _ ≪≫
cokernel.mapIso _ _ (PreservesKernel.iso ((evaluation C D).obj X) _) (Iso.refl _)
(by
dsimp
simp only [Category.comp_id, PreservesKernel.iso_hom]
exact (kernelComparison_comp_ι _ ((evaluation C D).obj X)).symm)
/-- The abelian image in a functor category can be calculated componentwise. -/
@[simps!]
def imageObjIso : (Abelian.image α).obj X ≅ Abelian.image (α.app X) :=
PreservesKernel.iso ((evaluation C D).obj X) _ ≪≫
kernel.mapIso _ _ (Iso.refl _) (PreservesCokernel.iso ((evaluation C D).obj X) _)
(by
apply (cancel_mono (PreservesCokernel.iso ((evaluation C D).obj X) α).inv).1
simp only [Category.assoc, Iso.hom_inv_id]
dsimp
simp only [PreservesCokernel.iso_inv, Category.id_comp, Category.comp_id]
exact (π_comp_cokernelComparison _ ((evaluation C D).obj X)).symm)
theorem coimageImageComparison_app :
coimageImageComparison (α.app X) =
(coimageObjIso α X).inv ≫ (coimageImageComparison α).app X ≫ (imageObjIso α X).hom := by
ext
dsimp
dsimp [imageObjIso, coimageObjIso, cokernel.map]
simp only [coimage_image_factorisation, PreservesKernel.iso_hom, Category.assoc,
kernel.lift_ι, Category.comp_id, PreservesCokernel.iso_inv,
cokernel.π_desc_assoc, Category.id_comp]
erw [kernelComparison_comp_ι _ ((evaluation C D).obj X),
π_comp_cokernelComparison_assoc _ ((evaluation C D).obj X)]
conv_lhs => rw [← coimage_image_factorisation α]
rfl
theorem coimageImageComparison_app' :
(coimageImageComparison α).app X =
(coimageObjIso α X).hom ≫ coimageImageComparison (α.app X) ≫ (imageObjIso α X).inv := by
simp only [coimageImageComparison_app, Iso.hom_inv_id_assoc, Iso.hom_inv_id, Category.assoc,
Category.comp_id]
instance functor_category_isIso_coimageImageComparison :
IsIso (Abelian.coimageImageComparison α) := by
have : ∀ X : C, IsIso ((Abelian.coimageImageComparison α).app X) := by
intros
rw [coimageImageComparison_app']
infer_instance
apply NatIso.isIso_of_isIso_app
end FunctorCategory
noncomputable instance functorCategoryAbelian : Abelian (C ⥤ D) :=
let _ : HasKernels (C ⥤ D) := inferInstance
let _ : HasCokernels (C ⥤ D) := inferInstance
Abelian.ofCoimageImageComparisonIsIso
end
-- Porting note: the following section should be unnecessary because there are no longer
--any universe restrictions for `functorCategoryAbelian`
--
--section
--
--universe u
--
--variable {C : Type u} [SmallCategory C]
--
--variable {D : Type (u + 1)} [LargeCategory D] [Abelian D]
--
--/-- A variant with specialized universes for a common case. -/
--noncomputable instance functorCategoryAbelian' : Abelian (C ⥤ D) :=
-- Abelian.functorCategoryAbelian.{u, u + 1, u, u}
--
--end
end Abelian
end CategoryTheory
|
CategoryTheory\Abelian\Generator.lean | /-
Copyright (c) 2022 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.CategoryTheory.Abelian.Subobject
import Mathlib.CategoryTheory.Limits.EssentiallySmall
import Mathlib.CategoryTheory.Preadditive.Injective
import Mathlib.CategoryTheory.Preadditive.Generator
import Mathlib.CategoryTheory.Abelian.Opposite
/-!
# A complete abelian category with enough injectives and a separator has an injective coseparator
## Future work
* Once we know that Grothendieck categories have enough injectives, we can use this to conclude
that Grothendieck categories have an injective coseparator.
## References
* [Peter J Freyd, *Abelian Categories* (Theorem 3.37)][freyd1964abelian]
-/
open CategoryTheory CategoryTheory.Limits Opposite
universe v u
namespace CategoryTheory.Abelian
variable {C : Type u} [Category.{v} C] [Abelian C]
theorem has_injective_coseparator [HasLimits C] [EnoughInjectives C] (G : C) (hG : IsSeparator G) :
∃ G : C, Injective G ∧ IsCoseparator G := by
haveI : WellPowered C := wellPowered_of_isDetector G hG.isDetector
haveI : HasProductsOfShape (Subobject (op G)) C := hasProductsOfShape_of_small _ _
let T : C := Injective.under (piObj fun P : Subobject (op G) => unop P)
refine ⟨T, inferInstance, (Preadditive.isCoseparator_iff _).2 fun X Y f hf => ?_⟩
refine (Preadditive.isSeparator_iff _).1 hG _ fun h => ?_
suffices hh : factorThruImage (h ≫ f) = 0 by
rw [← Limits.image.fac (h ≫ f), hh, zero_comp]
let R := Subobject.mk (factorThruImage (h ≫ f)).op
let q₁ : image (h ≫ f) ⟶ unop R :=
(Subobject.underlyingIso (factorThruImage (h ≫ f)).op).unop.hom
let q₂ : unop (R : Cᵒᵖ) ⟶ piObj fun P : Subobject (op G) => unop P :=
section_ (Pi.π (fun P : Subobject (op G) => (unop P : C)) R)
let q : image (h ≫ f) ⟶ T := q₁ ≫ q₂ ≫ Injective.ι _
exact zero_of_comp_mono q
(by rw [← Injective.comp_factorThru q (Limits.image.ι (h ≫ f)), Limits.image.fac_assoc,
Category.assoc, hf, comp_zero])
theorem has_projective_separator [HasColimits C] [EnoughProjectives C] (G : C)
(hG : IsCoseparator G) : ∃ G : C, Projective G ∧ IsSeparator G := by
obtain ⟨T, hT₁, hT₂⟩ := has_injective_coseparator (op G) ((isSeparator_op_iff _).2 hG)
exact ⟨unop T, inferInstance, (isSeparator_unop_iff _).2 hT₂⟩
end CategoryTheory.Abelian
|
CategoryTheory\Abelian\Images.lean | /-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel, Scott Morrison
-/
import Mathlib.CategoryTheory.Limits.Shapes.Kernels
/-!
# The abelian image and coimage.
In an abelian category we usually want the image of a morphism `f` to be defined as
`kernel (cokernel.π f)`, and the coimage to be defined as `cokernel (kernel.ι f)`.
We make these definitions here, as `Abelian.image f` and `Abelian.coimage f`
(without assuming the category is actually abelian),
and later relate these to the usual categorical notions when in an abelian category.
There is a canonical morphism `coimageImageComparison : Abelian.coimage f ⟶ Abelian.image f`.
Later we show that this is always an isomorphism in an abelian category,
and conversely a category with (co)kernels and finite products in which this morphism
is always an isomorphism is an abelian category.
-/
noncomputable section
universe v u
open CategoryTheory
open CategoryTheory.Limits
namespace CategoryTheory.Abelian
variable {C : Type u} [Category.{v} C] [HasZeroMorphisms C] [HasKernels C] [HasCokernels C]
variable {P Q : C} (f : P ⟶ Q)
section Image
/-- The kernel of the cokernel of `f` is called the (abelian) image of `f`. -/
protected abbrev image : C :=
kernel (cokernel.π f)
/-- The inclusion of the image into the codomain. -/
protected abbrev image.ι : Abelian.image f ⟶ Q :=
kernel.ι (cokernel.π f)
/-- There is a canonical epimorphism `p : P ⟶ image f` for every `f`. -/
protected abbrev factorThruImage : P ⟶ Abelian.image f :=
kernel.lift (cokernel.π f) f <| cokernel.condition f
-- Porting note (#10618): simp can prove this and reassoc version, removed tags
/-- `f` factors through its image via the canonical morphism `p`. -/
protected theorem image.fac : Abelian.factorThruImage f ≫ image.ι f = f :=
kernel.lift_ι _ _ _
instance mono_factorThruImage [Mono f] : Mono (Abelian.factorThruImage f) :=
mono_of_mono_fac <| image.fac f
end Image
section Coimage
/-- The cokernel of the kernel of `f` is called the (abelian) coimage of `f`. -/
protected abbrev coimage : C :=
cokernel (kernel.ι f)
/-- The projection onto the coimage. -/
protected abbrev coimage.π : P ⟶ Abelian.coimage f :=
cokernel.π (kernel.ι f)
/-- There is a canonical monomorphism `i : coimage f ⟶ Q`. -/
protected abbrev factorThruCoimage : Abelian.coimage f ⟶ Q :=
cokernel.desc (kernel.ι f) f <| kernel.condition f
/-- `f` factors through its coimage via the canonical morphism `p`. -/
protected theorem coimage.fac : coimage.π f ≫ Abelian.factorThruCoimage f = f :=
cokernel.π_desc _ _ _
instance epi_factorThruCoimage [Epi f] : Epi (Abelian.factorThruCoimage f) :=
epi_of_epi_fac <| coimage.fac f
end Coimage
/-- The canonical map from the abelian coimage to the abelian image.
In any abelian category this is an isomorphism.
Conversely, any additive category with kernels and cokernels and
in which this is always an isomorphism, is abelian.
See <https://stacks.math.columbia.edu/tag/0107>
-/
def coimageImageComparison : Abelian.coimage f ⟶ Abelian.image f :=
cokernel.desc (kernel.ι f) (kernel.lift (cokernel.π f) f (by simp)) (by ext; simp)
/-- An alternative formulation of the canonical map from the abelian coimage to the abelian image.
-/
def coimageImageComparison' : Abelian.coimage f ⟶ Abelian.image f :=
kernel.lift (cokernel.π f) (cokernel.desc (kernel.ι f) f (by simp)) (by ext; simp)
theorem coimageImageComparison_eq_coimageImageComparison' :
coimageImageComparison f = coimageImageComparison' f := by
ext
simp [coimageImageComparison, coimageImageComparison']
@[reassoc (attr := simp)]
theorem coimage_image_factorisation : coimage.π f ≫ coimageImageComparison f ≫ image.ι f = f := by
simp [coimageImageComparison]
end CategoryTheory.Abelian
|
CategoryTheory\Abelian\Injective.lean | /-
Copyright (c) 2022 Jakob von Raumer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jakob von Raumer
-/
import Mathlib.CategoryTheory.Abelian.Exact
import Mathlib.CategoryTheory.Preadditive.Injective
import Mathlib.CategoryTheory.Preadditive.Yoneda.Limits
import Mathlib.CategoryTheory.Preadditive.Yoneda.Injective
import Mathlib.Algebra.Homology.ShortComplex.ExactFunctor
/-!
# Injective objects in abelian categories
* Objects in an abelian categories are injective if and only if the preadditive Yoneda functor
on them preserves finite colimits.
-/
noncomputable section
open CategoryTheory Limits Injective Opposite
universe v u
namespace CategoryTheory
variable {C : Type u} [Category.{v} C] [Abelian C]
/-- The preadditive Yoneda functor on `J` preserves homology if `J` is injective. -/
instance preservesHomologyPreadditiveYonedaObjOfInjective (J : C) [hJ : Injective J] :
(preadditiveYonedaObj J).PreservesHomology := by
letI := (injective_iff_preservesEpimorphisms_preadditive_yoneda_obj' J).mp hJ
apply Functor.preservesHomologyOfPreservesEpisAndKernels
/-- The preadditive Yoneda functor on `J` preserves colimits if `J` is injective. -/
instance preservesFiniteColimitsPreadditiveYonedaObjOfInjective (J : C) [hP : Injective J] :
PreservesFiniteColimits (preadditiveYonedaObj J) := by
apply Functor.preservesFiniteColimitsOfPreservesHomology
/-- An object is injective if its preadditive Yoneda functor preserves finite colimits. -/
theorem injective_of_preservesFiniteColimits_preadditiveYonedaObj (J : C)
[hP : PreservesFiniteColimits (preadditiveYonedaObj J)] : Injective J := by
rw [injective_iff_preservesEpimorphisms_preadditive_yoneda_obj']
have := Functor.preservesHomologyOfExact (preadditiveYonedaObj J)
infer_instance
end CategoryTheory
|
CategoryTheory\Abelian\InjectiveResolution.lean | /-
Copyright (c) 2022 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang, Scott Morrison
-/
import Mathlib.CategoryTheory.Preadditive.InjectiveResolution
import Mathlib.Algebra.Homology.HomotopyCategory
import Mathlib.Data.Set.Subsingleton
import Mathlib.Tactic.AdaptationNote
/-!
# Abelian categories with enough injectives have injective resolutions
## Main results
When the underlying category is abelian:
* `CategoryTheory.InjectiveResolution.desc`: Given `I : InjectiveResolution X` and
`J : InjectiveResolution Y`, any morphism `X ⟶ Y` admits a descent to a chain map
`J.cocomplex ⟶ I.cocomplex`. It is a descent in the sense that `I.ι` intertwines the descent and
the original morphism, see `CategoryTheory.InjectiveResolution.desc_commutes`.
* `CategoryTheory.InjectiveResolution.descHomotopy`: Any two such descents are homotopic.
* `CategoryTheory.InjectiveResolution.homotopyEquiv`: Any two injective resolutions of the same
object are homotopy equivalent.
* `CategoryTheory.injectiveResolutions`: If every object admits an injective resolution, we can
construct a functor `injectiveResolutions C : C ⥤ HomotopyCategory C`.
* `CategoryTheory.exact_f_d`: `f` and `Injective.d f` are exact.
* `CategoryTheory.InjectiveResolution.of`: Hence, starting from a monomorphism `X ⟶ J`, where `J`
is injective, we can apply `Injective.d` repeatedly to obtain an injective resolution of `X`.
-/
noncomputable section
open CategoryTheory Category Limits
universe v u
namespace CategoryTheory
variable {C : Type u} [Category.{v} C]
open Injective
namespace InjectiveResolution
section
variable [HasZeroObject C] [HasZeroMorphisms C]
/-- Auxiliary construction for `desc`. -/
def descFZero {Y Z : C} (f : Z ⟶ Y) (I : InjectiveResolution Y) (J : InjectiveResolution Z) :
J.cocomplex.X 0 ⟶ I.cocomplex.X 0 :=
factorThru (f ≫ I.ι.f 0) (J.ι.f 0)
end
section Abelian
variable [Abelian C]
lemma exact₀ {Z : C} (I : InjectiveResolution Z) :
(ShortComplex.mk _ _ I.ι_f_zero_comp_complex_d).Exact :=
ShortComplex.exact_of_f_is_kernel _ I.isLimitKernelFork
/-- Auxiliary construction for `desc`. -/
def descFOne {Y Z : C} (f : Z ⟶ Y) (I : InjectiveResolution Y) (J : InjectiveResolution Z) :
J.cocomplex.X 1 ⟶ I.cocomplex.X 1 :=
J.exact₀.descToInjective (descFZero f I J ≫ I.cocomplex.d 0 1)
(by dsimp; simp [← assoc, assoc, descFZero])
@[simp]
theorem descFOne_zero_comm {Y Z : C} (f : Z ⟶ Y) (I : InjectiveResolution Y)
(J : InjectiveResolution Z) :
J.cocomplex.d 0 1 ≫ descFOne f I J = descFZero f I J ≫ I.cocomplex.d 0 1 := by
apply J.exact₀.comp_descToInjective
/-- Auxiliary construction for `desc`. -/
def descFSucc {Y Z : C} (I : InjectiveResolution Y) (J : InjectiveResolution Z) (n : ℕ)
(g : J.cocomplex.X n ⟶ I.cocomplex.X n) (g' : J.cocomplex.X (n + 1) ⟶ I.cocomplex.X (n + 1))
(w : J.cocomplex.d n (n + 1) ≫ g' = g ≫ I.cocomplex.d n (n + 1)) :
Σ'g'' : J.cocomplex.X (n + 2) ⟶ I.cocomplex.X (n + 2),
J.cocomplex.d (n + 1) (n + 2) ≫ g'' = g' ≫ I.cocomplex.d (n + 1) (n + 2) :=
⟨(J.exact_succ n).descToInjective
(g' ≫ I.cocomplex.d (n + 1) (n + 2)) (by simp [reassoc_of% w]),
(J.exact_succ n).comp_descToInjective _ _⟩
/-- A morphism in `C` descends to a chain map between injective resolutions. -/
def desc {Y Z : C} (f : Z ⟶ Y) (I : InjectiveResolution Y) (J : InjectiveResolution Z) :
J.cocomplex ⟶ I.cocomplex :=
CochainComplex.mkHom _ _ (descFZero f _ _) (descFOne f _ _) (descFOne_zero_comm f I J).symm
fun n ⟨g, g', w⟩ => ⟨(descFSucc I J n g g' w.symm).1, (descFSucc I J n g g' w.symm).2.symm⟩
/-- The resolution maps intertwine the descent of a morphism and that morphism. -/
@[reassoc (attr := simp)]
theorem desc_commutes {Y Z : C} (f : Z ⟶ Y) (I : InjectiveResolution Y)
(J : InjectiveResolution Z) : J.ι ≫ desc f I J = (CochainComplex.single₀ C).map f ≫ I.ι := by
ext
simp [desc, descFOne, descFZero]
@[reassoc (attr := simp)]
lemma desc_commutes_zero {Y Z : C} (f : Z ⟶ Y)
(I : InjectiveResolution Y) (J : InjectiveResolution Z) :
J.ι.f 0 ≫ (desc f I J).f 0 = f ≫ I.ι.f 0 :=
(HomologicalComplex.congr_hom (desc_commutes f I J) 0).trans (by simp)
-- Now that we've checked this property of the descent, we can seal away the actual definition.
/-- An auxiliary definition for `descHomotopyZero`. -/
def descHomotopyZeroZero {Y Z : C} {I : InjectiveResolution Y} {J : InjectiveResolution Z}
(f : I.cocomplex ⟶ J.cocomplex) (comm : I.ι ≫ f = 0) : I.cocomplex.X 1 ⟶ J.cocomplex.X 0 :=
I.exact₀.descToInjective (f.f 0) (congr_fun (congr_arg HomologicalComplex.Hom.f comm) 0)
@[reassoc (attr := simp)]
lemma comp_descHomotopyZeroZero {Y Z : C} {I : InjectiveResolution Y} {J : InjectiveResolution Z}
(f : I.cocomplex ⟶ J.cocomplex) (comm : I.ι ≫ f = 0) :
I.cocomplex.d 0 1 ≫ descHomotopyZeroZero f comm = f.f 0 :=
I.exact₀.comp_descToInjective _ _
/-- An auxiliary definition for `descHomotopyZero`. -/
def descHomotopyZeroOne {Y Z : C} {I : InjectiveResolution Y} {J : InjectiveResolution Z}
(f : I.cocomplex ⟶ J.cocomplex) (comm : I.ι ≫ f = (0 : _ ⟶ J.cocomplex)) :
I.cocomplex.X 2 ⟶ J.cocomplex.X 1 :=
(I.exact_succ 0).descToInjective (f.f 1 - descHomotopyZeroZero f comm ≫ J.cocomplex.d 0 1)
(by rw [Preadditive.comp_sub, comp_descHomotopyZeroZero_assoc f comm,
HomologicalComplex.Hom.comm, sub_self])
@[reassoc (attr := simp)]
lemma comp_descHomotopyZeroOne {Y Z : C} {I : InjectiveResolution Y} {J : InjectiveResolution Z}
(f : I.cocomplex ⟶ J.cocomplex) (comm : I.ι ≫ f = (0 : _ ⟶ J.cocomplex)) :
I.cocomplex.d 1 2 ≫ descHomotopyZeroOne f comm =
f.f 1 - descHomotopyZeroZero f comm ≫ J.cocomplex.d 0 1 :=
(I.exact_succ 0).comp_descToInjective _ _
/-- An auxiliary definition for `descHomotopyZero`. -/
def descHomotopyZeroSucc {Y Z : C} {I : InjectiveResolution Y} {J : InjectiveResolution Z}
(f : I.cocomplex ⟶ J.cocomplex) (n : ℕ) (g : I.cocomplex.X (n + 1) ⟶ J.cocomplex.X n)
(g' : I.cocomplex.X (n + 2) ⟶ J.cocomplex.X (n + 1))
(w : f.f (n + 1) = I.cocomplex.d (n + 1) (n + 2) ≫ g' + g ≫ J.cocomplex.d n (n + 1)) :
I.cocomplex.X (n + 3) ⟶ J.cocomplex.X (n + 2) :=
(I.exact_succ (n + 1)).descToInjective (f.f (n + 2) - g' ≫ J.cocomplex.d _ _) (by
dsimp
rw [Preadditive.comp_sub, ← HomologicalComplex.Hom.comm, w, Preadditive.add_comp,
Category.assoc, Category.assoc, HomologicalComplex.d_comp_d, comp_zero,
add_zero, sub_self])
@[reassoc (attr := simp)]
lemma comp_descHomotopyZeroSucc {Y Z : C} {I : InjectiveResolution Y} {J : InjectiveResolution Z}
(f : I.cocomplex ⟶ J.cocomplex) (n : ℕ) (g : I.cocomplex.X (n + 1) ⟶ J.cocomplex.X n)
(g' : I.cocomplex.X (n + 2) ⟶ J.cocomplex.X (n + 1))
(w : f.f (n + 1) = I.cocomplex.d (n + 1) (n + 2) ≫ g' + g ≫ J.cocomplex.d n (n + 1)) :
I.cocomplex.d (n+2) (n+3) ≫ descHomotopyZeroSucc f n g g' w =
f.f (n + 2) - g' ≫ J.cocomplex.d _ _ :=
(I.exact_succ (n+1)).comp_descToInjective _ _
/-- Any descent of the zero morphism is homotopic to zero. -/
def descHomotopyZero {Y Z : C} {I : InjectiveResolution Y} {J : InjectiveResolution Z}
(f : I.cocomplex ⟶ J.cocomplex) (comm : I.ι ≫ f = 0) : Homotopy f 0 :=
Homotopy.mkCoinductive _ (descHomotopyZeroZero f comm) (by simp)
(descHomotopyZeroOne f comm) (by simp) (fun n ⟨g, g', w⟩ =>
⟨descHomotopyZeroSucc f n g g' (by simp only [w, add_comm]), by simp⟩)
/-- Two descents of the same morphism are homotopic. -/
def descHomotopy {Y Z : C} (f : Y ⟶ Z) {I : InjectiveResolution Y} {J : InjectiveResolution Z}
(g h : I.cocomplex ⟶ J.cocomplex) (g_comm : I.ι ≫ g = (CochainComplex.single₀ C).map f ≫ J.ι)
(h_comm : I.ι ≫ h = (CochainComplex.single₀ C).map f ≫ J.ι) : Homotopy g h :=
Homotopy.equivSubZero.invFun (descHomotopyZero _ (by simp [g_comm, h_comm]))
/-- The descent of the identity morphism is homotopic to the identity cochain map. -/
def descIdHomotopy (X : C) (I : InjectiveResolution X) :
Homotopy (desc (𝟙 X) I I) (𝟙 I.cocomplex) := by
apply descHomotopy (𝟙 X) <;> simp
/-- The descent of a composition is homotopic to the composition of the descents. -/
def descCompHomotopy {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (I : InjectiveResolution X)
(J : InjectiveResolution Y) (K : InjectiveResolution Z) :
Homotopy (desc (f ≫ g) K I) (desc f J I ≫ desc g K J) := by
apply descHomotopy (f ≫ g) <;> simp
-- We don't care about the actual definitions of these homotopies.
/-- Any two injective resolutions are homotopy equivalent. -/
def homotopyEquiv {X : C} (I J : InjectiveResolution X) :
HomotopyEquiv I.cocomplex J.cocomplex where
hom := desc (𝟙 X) J I
inv := desc (𝟙 X) I J
homotopyHomInvId := (descCompHomotopy (𝟙 X) (𝟙 X) I J I).symm.trans <| by
simpa [id_comp] using descIdHomotopy _ _
homotopyInvHomId := (descCompHomotopy (𝟙 X) (𝟙 X) J I J).symm.trans <| by
simpa [id_comp] using descIdHomotopy _ _
@[reassoc (attr := simp)]
theorem homotopyEquiv_hom_ι {X : C} (I J : InjectiveResolution X) :
I.ι ≫ (homotopyEquiv I J).hom = J.ι := by simp [homotopyEquiv]
@[reassoc (attr := simp)]
theorem homotopyEquiv_inv_ι {X : C} (I J : InjectiveResolution X) :
J.ι ≫ (homotopyEquiv I J).inv = I.ι := by simp [homotopyEquiv]
end Abelian
end InjectiveResolution
section
variable [Abelian C]
/-- An arbitrarily chosen injective resolution of an object. -/
abbrev injectiveResolution (Z : C) [HasInjectiveResolution Z] : InjectiveResolution Z :=
(HasInjectiveResolution.out (Z := Z)).some
variable (C)
variable [HasInjectiveResolutions C]
/-- Taking injective resolutions is functorial,
if considered with target the homotopy category
(`ℕ`-indexed cochain complexes and chain maps up to homotopy).
-/
def injectiveResolutions : C ⥤ HomotopyCategory C (ComplexShape.up ℕ) where
obj X := (HomotopyCategory.quotient _ _).obj (injectiveResolution X).cocomplex
map f := (HomotopyCategory.quotient _ _).map (InjectiveResolution.desc f _ _)
map_id X := by
rw [← (HomotopyCategory.quotient _ _).map_id]
apply HomotopyCategory.eq_of_homotopy
apply InjectiveResolution.descIdHomotopy
map_comp f g := by
rw [← (HomotopyCategory.quotient _ _).map_comp]
apply HomotopyCategory.eq_of_homotopy
apply InjectiveResolution.descCompHomotopy
variable {C}
/-- If `I : InjectiveResolution X`, then the chosen `(injectiveResolutions C).obj X`
is isomorphic (in the homotopy category) to `I.cocomplex`. -/
def InjectiveResolution.iso {X : C} (I : InjectiveResolution X) :
(injectiveResolutions C).obj X ≅
(HomotopyCategory.quotient _ _).obj I.cocomplex :=
HomotopyCategory.isoOfHomotopyEquiv (homotopyEquiv _ _)
@[reassoc]
lemma InjectiveResolution.iso_hom_naturality {X Y : C} (f : X ⟶ Y)
(I : InjectiveResolution X) (J : InjectiveResolution Y)
(φ : I.cocomplex ⟶ J.cocomplex) (comm : I.ι.f 0 ≫ φ.f 0 = f ≫ J.ι.f 0) :
(injectiveResolutions C).map f ≫ J.iso.hom =
I.iso.hom ≫ (HomotopyCategory.quotient _ _).map φ := by
apply HomotopyCategory.eq_of_homotopy
apply descHomotopy f
all_goals aesop_cat
@[reassoc]
lemma InjectiveResolution.iso_inv_naturality {X Y : C} (f : X ⟶ Y)
(I : InjectiveResolution X) (J : InjectiveResolution Y)
(φ : I.cocomplex ⟶ J.cocomplex) (comm : I.ι.f 0 ≫ φ.f 0 = f ≫ J.ι.f 0) :
I.iso.inv ≫ (injectiveResolutions C).map f =
(HomotopyCategory.quotient _ _).map φ ≫ J.iso.inv := by
rw [← cancel_mono (J.iso).hom, Category.assoc, iso_hom_naturality f I J φ comm,
Iso.inv_hom_id_assoc, Category.assoc, Iso.inv_hom_id, Category.comp_id]
end
section
variable [Abelian C] [EnoughInjectives C]
theorem exact_f_d {X Y : C} (f : X ⟶ Y) :
(ShortComplex.mk f (d f) (by simp)).Exact := by
let α : ShortComplex.mk f (cokernel.π f) (by simp) ⟶ ShortComplex.mk f (d f) (by simp) :=
{ τ₁ := 𝟙 _
τ₂ := 𝟙 _
τ₃ := Injective.ι _ }
have : Epi α.τ₁ := by dsimp; infer_instance
have : IsIso α.τ₂ := by dsimp; infer_instance
have : Mono α.τ₃ := by dsimp; infer_instance
rw [← ShortComplex.exact_iff_of_epi_of_isIso_of_mono α]
apply ShortComplex.exact_of_g_is_cokernel
apply cokernelIsCokernel
end
namespace InjectiveResolution
/-!
Our goal is to define `InjectiveResolution.of Z : InjectiveResolution Z`.
The `0`-th object in this resolution will just be `Injective.under Z`,
i.e. an arbitrarily chosen injective object with a map from `Z`.
After that, we build the `n+1`-st object as `Injective.syzygies`
applied to the previously constructed morphism,
and the map from the `n`-th object as `Injective.d`.
-/
variable [Abelian C] [EnoughInjectives C] (Z : C)
-- The construction of the injective resolution `of` would be very, very slow
-- if it were not broken into separate definitions and lemmas
/-- Auxiliary definition for `InjectiveResolution.of`. -/
def ofCocomplex : CochainComplex C ℕ :=
CochainComplex.mk' (Injective.under Z) (Injective.syzygies (Injective.ι Z))
(Injective.d (Injective.ι Z)) fun f => ⟨_, Injective.d f, by simp⟩
lemma ofCocomplex_d_0_1 :
(ofCocomplex Z).d 0 1 = d (Injective.ι Z) := by
simp [ofCocomplex]
#adaptation_note /-- Since nightly-2024-03-11, this takes forever now -/
lemma ofCocomplex_exactAt_succ (n : ℕ) :
(ofCocomplex Z).ExactAt (n + 1) := by
rw [HomologicalComplex.exactAt_iff' _ n (n + 1) (n + 1 + 1) (by simp) (by simp)]
dsimp [ofCocomplex, CochainComplex.mk', CochainComplex.mk, HomologicalComplex.sc',
HomologicalComplex.shortComplexFunctor']
simp only [CochainComplex.of_d]
match n with
| 0 => apply exact_f_d ((CochainComplex.mkAux _ _ _
(d (Injective.ι Z)) (d (d (Injective.ι Z))) _ _ 0).f)
| n+1 => apply exact_f_d ((CochainComplex.mkAux _ _ _
(d (Injective.ι Z)) (d (d (Injective.ι Z))) _ _ (n+1)).f)
instance (n : ℕ) : Injective ((ofCocomplex Z).X n) := by
obtain (_ | _ | _ | n) := n <;> apply Injective.injective_under
/-- In any abelian category with enough injectives,
`InjectiveResolution.of Z` constructs an injective resolution of the object `Z`.
-/
irreducible_def of : InjectiveResolution Z where
cocomplex := ofCocomplex Z
ι := (CochainComplex.fromSingle₀Equiv _ _).symm ⟨Injective.ι Z,
by rw [ofCocomplex_d_0_1, cokernel.condition_assoc, zero_comp]⟩
quasiIso := ⟨fun n => by
cases n
· rw [CochainComplex.quasiIsoAt₀_iff, ShortComplex.quasiIso_iff_of_zeros]
· refine (ShortComplex.exact_and_mono_f_iff_of_iso ?_).2
⟨exact_f_d (Injective.ι Z), by dsimp; infer_instance⟩
exact ShortComplex.isoMk (Iso.refl _) (Iso.refl _) (Iso.refl _) (by simp)
(by simp [ofCocomplex])
all_goals rfl
· rw [quasiIsoAt_iff_exactAt]
· apply ofCocomplex_exactAt_succ
· apply CochainComplex.exactAt_succ_single_obj⟩
instance (priority := 100) (Z : C) : HasInjectiveResolution Z where out := ⟨of Z⟩
instance (priority := 100) : HasInjectiveResolutions C where out _ := inferInstance
end InjectiveResolution
end CategoryTheory
|
CategoryTheory\Abelian\LeftDerived.lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Riccardo Brasca, Adam Topaz, Jujian Zhang, Joël Riou
-/
import Mathlib.Algebra.Homology.Additive
import Mathlib.CategoryTheory.Abelian.ProjectiveResolution
/-!
# Left-derived functors
We define the left-derived functors `F.leftDerived n : C ⥤ D` for any additive functor `F`
out of a category with projective resolutions.
We first define a functor
`F.leftDerivedToHomotopyCategory : C ⥤ HomotopyCategory D (ComplexShape.down ℕ)` which is
`projectiveResolutions C ⋙ F.mapHomotopyCategory _`. We show that if `X : C` and
`P : ProjectiveResolution X`, then `F.leftDerivedToHomotopyCategory.obj X` identifies
to the image in the homotopy category of the functor `F` applied objectwise to `P.complex`
(this isomorphism is `P.isoLeftDerivedToHomotopyCategoryObj F`).
Then, the left-derived functors `F.leftDerived n : C ⥤ D` are obtained by composing
`F.leftDerivedToHomotopyCategory` with the homology functors on the homotopy category.
Similarly we define natural transformations between left-derived functors coming from
natural transformations between the original additive functors,
and show how to compute the components.
## Main results
* `Functor.isZero_leftDerived_obj_projective_succ`: projective objects have no higher
left derived functor.
* `NatTrans.leftDerived`: the natural isomorphism between left derived functors
induced by natural transformation.
* `Functor.fromLeftDerivedZero`: the natural transformation `F.leftDerived 0 ⟶ F`,
which is an isomorphism when `F` is right exact (i.e. preserves finite colimits),
see also `Functor.leftDerivedZeroIsoSelf`.
## TODO
* refactor `Functor.leftDerived` (and `Functor.rightDerived`) when the necessary
material enters mathlib: derived categories, injective/projective derivability
structures, existence of derived functors from derivability structures.
Eventually, we shall get a right derived functor
`F.leftDerivedFunctorMinus : DerivedCategory.Minus C ⥤ DerivedCategory.Minus D`,
and `F.leftDerived` shall be redefined using `F.leftDerivedFunctorMinus`.
-/
universe v u
namespace CategoryTheory
open Category Limits
variable {C : Type u} [Category.{v} C] {D : Type*} [Category D]
[Abelian C] [HasProjectiveResolutions C] [Abelian D]
/-- When `F : C ⥤ D` is an additive functor, this is
the functor `C ⥤ HomotopyCategory D (ComplexShape.down ℕ)` which
sends `X : C` to `F` applied to a projective resolution of `X`. -/
noncomputable def Functor.leftDerivedToHomotopyCategory (F : C ⥤ D) [F.Additive] :
C ⥤ HomotopyCategory D (ComplexShape.down ℕ) :=
projectiveResolutions C ⋙ F.mapHomotopyCategory _
/-- If `P : ProjectiveResolution Z` and `F : C ⥤ D` is an additive functor, this is
an isomorphism between `F.leftDerivedToHomotopyCategory.obj X` and the complex
obtained by applying `F` to `P.complex`. -/
noncomputable def ProjectiveResolution.isoLeftDerivedToHomotopyCategoryObj {X : C}
(P : ProjectiveResolution X) (F : C ⥤ D) [F.Additive] :
F.leftDerivedToHomotopyCategory.obj X ≅
(F.mapHomologicalComplex _ ⋙ HomotopyCategory.quotient _ _).obj P.complex :=
(F.mapHomotopyCategory _).mapIso P.iso ≪≫
(F.mapHomotopyCategoryFactors _).app P.complex
@[reassoc]
lemma ProjectiveResolution.isoLeftDerivedToHomotopyCategoryObj_inv_naturality
{X Y : C} (f : X ⟶ Y) (P : ProjectiveResolution X) (Q : ProjectiveResolution Y)
(φ : P.complex ⟶ Q.complex) (comm : φ.f 0 ≫ Q.π.f 0 = P.π.f 0 ≫ f)
(F : C ⥤ D) [F.Additive] :
(P.isoLeftDerivedToHomotopyCategoryObj F).inv ≫ F.leftDerivedToHomotopyCategory.map f =
(F.mapHomologicalComplex _ ⋙ HomotopyCategory.quotient _ _).map φ ≫
(Q.isoLeftDerivedToHomotopyCategoryObj F).inv := by
dsimp [Functor.leftDerivedToHomotopyCategory, isoLeftDerivedToHomotopyCategoryObj]
rw [assoc, ← Functor.map_comp, iso_inv_naturality f P Q φ comm, Functor.map_comp]
erw [(F.mapHomotopyCategoryFactors (ComplexShape.down ℕ)).inv.naturality_assoc]
rfl
@[reassoc]
lemma ProjectiveResolution.isoLeftDerivedToHomotopyCategoryObj_hom_naturality
{X Y : C} (f : X ⟶ Y) (P : ProjectiveResolution X) (Q : ProjectiveResolution Y)
(φ : P.complex ⟶ Q.complex) (comm : φ.f 0 ≫ Q.π.f 0 = P.π.f 0 ≫ f)
(F : C ⥤ D) [F.Additive] :
F.leftDerivedToHomotopyCategory.map f ≫ (Q.isoLeftDerivedToHomotopyCategoryObj F).hom =
(P.isoLeftDerivedToHomotopyCategoryObj F).hom ≫
(F.mapHomologicalComplex _ ⋙ HomotopyCategory.quotient _ _).map φ := by
dsimp
rw [← cancel_epi (P.isoLeftDerivedToHomotopyCategoryObj F).inv, Iso.inv_hom_id_assoc,
isoLeftDerivedToHomotopyCategoryObj_inv_naturality_assoc f P Q φ comm F,
Iso.inv_hom_id, comp_id]
/-- The left derived functors of an additive functor. -/
noncomputable def Functor.leftDerived (F : C ⥤ D) [F.Additive] (n : ℕ) : C ⥤ D :=
F.leftDerivedToHomotopyCategory ⋙ HomotopyCategory.homologyFunctor D _ n
/-- We can compute a left derived functor using a chosen projective resolution. -/
noncomputable def ProjectiveResolution.isoLeftDerivedObj {X : C} (P : ProjectiveResolution X)
(F : C ⥤ D) [F.Additive] (n : ℕ) :
(F.leftDerived n).obj X ≅
(HomologicalComplex.homologyFunctor D _ n).obj
((F.mapHomologicalComplex _).obj P.complex) :=
(HomotopyCategory.homologyFunctor D _ n).mapIso
(P.isoLeftDerivedToHomotopyCategoryObj F) ≪≫
(HomotopyCategory.homologyFunctorFactors D (ComplexShape.down ℕ) n).app _
@[reassoc]
lemma ProjectiveResolution.isoLeftDerivedObj_hom_naturality
{X Y : C} (f : X ⟶ Y) (P : ProjectiveResolution X) (Q : ProjectiveResolution Y)
(φ : P.complex ⟶ Q.complex) (comm : φ.f 0 ≫ Q.π.f 0 = P.π.f 0 ≫ f)
(F : C ⥤ D) [F.Additive] (n : ℕ) :
(F.leftDerived n).map f ≫ (Q.isoLeftDerivedObj F n).hom =
(P.isoLeftDerivedObj F n).hom ≫
(F.mapHomologicalComplex _ ⋙ HomologicalComplex.homologyFunctor _ _ n).map φ := by
dsimp [isoLeftDerivedObj, Functor.leftDerived]
rw [assoc, ← Functor.map_comp_assoc,
ProjectiveResolution.isoLeftDerivedToHomotopyCategoryObj_hom_naturality f P Q φ comm F,
Functor.map_comp, assoc]
erw [(HomotopyCategory.homologyFunctorFactors D (ComplexShape.down ℕ) n).hom.naturality]
rfl
@[reassoc]
lemma ProjectiveResolution.isoLeftDerivedObj_inv_naturality
{X Y : C} (f : X ⟶ Y) (P : ProjectiveResolution X) (Q : ProjectiveResolution Y)
(φ : P.complex ⟶ Q.complex) (comm : φ.f 0 ≫ Q.π.f 0 = P.π.f 0 ≫ f)
(F : C ⥤ D) [F.Additive] (n : ℕ) :
(P.isoLeftDerivedObj F n).inv ≫ (F.leftDerived n).map f =
(F.mapHomologicalComplex _ ⋙ HomologicalComplex.homologyFunctor _ _ n).map φ ≫
(Q.isoLeftDerivedObj F n).inv := by
rw [← cancel_mono (Q.isoLeftDerivedObj F n).hom, assoc, assoc,
ProjectiveResolution.isoLeftDerivedObj_hom_naturality f P Q φ comm F n,
Iso.inv_hom_id_assoc, Iso.inv_hom_id, comp_id]
/-- The higher derived functors vanish on projective objects. -/
lemma Functor.isZero_leftDerived_obj_projective_succ
(F : C ⥤ D) [F.Additive] (n : ℕ) (X : C) [Projective X] :
IsZero ((F.leftDerived (n + 1)).obj X) := by
refine IsZero.of_iso ?_ ((ProjectiveResolution.self X).isoLeftDerivedObj F (n + 1))
erw [← HomologicalComplex.exactAt_iff_isZero_homology]
exact ShortComplex.exact_of_isZero_X₂ _ (F.map_isZero (by apply isZero_zero))
/-- We can compute a left derived functor on a morphism using a descent of that morphism
to a chain map between chosen projective resolutions.
-/
theorem Functor.leftDerived_map_eq (F : C ⥤ D) [F.Additive] (n : ℕ) {X Y : C} (f : X ⟶ Y)
{P : ProjectiveResolution X} {Q : ProjectiveResolution Y} (g : P.complex ⟶ Q.complex)
(w : g ≫ Q.π = P.π ≫ (ChainComplex.single₀ C).map f) :
(F.leftDerived n).map f =
(P.isoLeftDerivedObj F n).hom ≫
(F.mapHomologicalComplex _ ⋙ HomologicalComplex.homologyFunctor _ _ n).map g ≫
(Q.isoLeftDerivedObj F n).inv := by
rw [← cancel_mono (Q.isoLeftDerivedObj F n).hom,
ProjectiveResolution.isoLeftDerivedObj_hom_naturality f P Q g _ F n,
assoc, assoc, Iso.inv_hom_id, comp_id]
rw [← HomologicalComplex.comp_f, w, HomologicalComplex.comp_f,
ChainComplex.single₀_map_f_zero]
/-- The natural transformation
`F.leftDerivedToHomotopyCategory ⟶ G.leftDerivedToHomotopyCategory` induced by
a natural transformation `F ⟶ G` between additive functors. -/
noncomputable def NatTrans.leftDerivedToHomotopyCategory
{F G : C ⥤ D} [F.Additive] [G.Additive] (α : F ⟶ G) :
F.leftDerivedToHomotopyCategory ⟶ G.leftDerivedToHomotopyCategory :=
whiskerLeft _ (NatTrans.mapHomotopyCategory α (ComplexShape.down ℕ))
lemma ProjectiveResolution.leftDerivedToHomotopyCategory_app_eq
{F G : C ⥤ D} [F.Additive] [G.Additive] (α : F ⟶ G) {X : C} (P : ProjectiveResolution X) :
(NatTrans.leftDerivedToHomotopyCategory α).app X =
(P.isoLeftDerivedToHomotopyCategoryObj F).hom ≫
(HomotopyCategory.quotient _ _).map
((NatTrans.mapHomologicalComplex α _).app P.complex) ≫
(P.isoLeftDerivedToHomotopyCategoryObj G).inv := by
rw [← cancel_mono (P.isoLeftDerivedToHomotopyCategoryObj G).hom, assoc, assoc,
Iso.inv_hom_id, comp_id]
dsimp [isoLeftDerivedToHomotopyCategoryObj, Functor.mapHomotopyCategoryFactors,
NatTrans.leftDerivedToHomotopyCategory]
rw [assoc]
erw [id_comp, comp_id]
obtain ⟨β, hβ⟩ := (HomotopyCategory.quotient _ _).map_surjective (iso P).hom
rw [← hβ]
dsimp
simp only [← Functor.map_comp, NatTrans.mapHomologicalComplex_naturality]
rfl
@[simp]
lemma NatTrans.leftDerivedToHomotopyCategory_id (F : C ⥤ D) [F.Additive] :
NatTrans.leftDerivedToHomotopyCategory (𝟙 F) = 𝟙 _ := rfl
@[simp, reassoc]
lemma NatTrans.leftDerivedToHomotopyCategory_comp {F G H : C ⥤ D} (α : F ⟶ G) (β : G ⟶ H)
[F.Additive] [G.Additive] [H.Additive] :
NatTrans.leftDerivedToHomotopyCategory (α ≫ β) =
NatTrans.leftDerivedToHomotopyCategory α ≫
NatTrans.leftDerivedToHomotopyCategory β := rfl
/-- The natural transformation between left-derived functors induced by a natural transformation. -/
noncomputable def NatTrans.leftDerived
{F G : C ⥤ D} [F.Additive] [G.Additive] (α : F ⟶ G) (n : ℕ) :
F.leftDerived n ⟶ G.leftDerived n :=
whiskerRight (NatTrans.leftDerivedToHomotopyCategory α) _
@[simp]
theorem NatTrans.leftDerived_id (F : C ⥤ D) [F.Additive] (n : ℕ) :
NatTrans.leftDerived (𝟙 F) n = 𝟙 (F.leftDerived n) := by
dsimp only [leftDerived]
simp only [leftDerivedToHomotopyCategory_id, whiskerRight_id']
rfl
@[simp, reassoc]
theorem NatTrans.leftDerived_comp {F G H : C ⥤ D} [F.Additive] [G.Additive] [H.Additive]
(α : F ⟶ G) (β : G ⟶ H) (n : ℕ) :
NatTrans.leftDerived (α ≫ β) n = NatTrans.leftDerived α n ≫ NatTrans.leftDerived β n := by
simp [NatTrans.leftDerived]
namespace ProjectiveResolution
/-- A component of the natural transformation between left-derived functors can be computed
using a chosen projective resolution. -/
lemma leftDerived_app_eq
{F G : C ⥤ D} [F.Additive] [G.Additive] (α : F ⟶ G) {X : C} (P : ProjectiveResolution X)
(n : ℕ) : (NatTrans.leftDerived α n).app X =
(P.isoLeftDerivedObj F n).hom ≫
(HomologicalComplex.homologyFunctor D (ComplexShape.down ℕ) n).map
((NatTrans.mapHomologicalComplex α _).app P.complex) ≫
(P.isoLeftDerivedObj G n).inv := by
dsimp [NatTrans.leftDerived, isoLeftDerivedObj]
rw [ProjectiveResolution.leftDerivedToHomotopyCategory_app_eq α P,
Functor.map_comp, Functor.map_comp, assoc]
erw [← (HomotopyCategory.homologyFunctorFactors D (ComplexShape.down ℕ) n).hom.naturality_assoc
((NatTrans.mapHomologicalComplex α (ComplexShape.down ℕ)).app P.complex)]
simp only [Functor.comp_map, Iso.hom_inv_id_app_assoc]
/-- If `P : ProjectiveResolution X` and `F` is an additive functor, this is
the canonical morphism from the opcycles in degree `0` of
`(F.mapHomologicalComplex _).obj P.complex` to `F.obj X`. -/
noncomputable def fromLeftDerivedZero' {X : C}
(P : ProjectiveResolution X) (F : C ⥤ D) [F.Additive] :
((F.mapHomologicalComplex _).obj P.complex).opcycles 0 ⟶ F.obj X :=
HomologicalComplex.descOpcycles _ (F.map (P.π.f 0)) 1 (by simp) (by
dsimp
rw [← F.map_comp, complex_d_comp_π_f_zero, F.map_zero])
@[reassoc (attr := simp)]
lemma pOpcycles_comp_fromLeftDerivedZero' {C} [Category C] [Abelian C] {X : C}
(P : ProjectiveResolution X) (F : C ⥤ D) [F.Additive] :
HomologicalComplex.pOpcycles _ _ ≫ P.fromLeftDerivedZero' F = F.map (P.π.f 0) := by
simp [fromLeftDerivedZero']
@[reassoc]
lemma fromLeftDerivedZero'_naturality {C} [Category C] [Abelian C] {X Y : C} (f : X ⟶ Y)
(P : ProjectiveResolution X) (Q : ProjectiveResolution Y)
(φ : P.complex ⟶ Q.complex) (comm : φ.f 0 ≫ Q.π.f 0 = P.π.f 0 ≫ f)
(F : C ⥤ D) [F.Additive] :
HomologicalComplex.opcyclesMap ((F.mapHomologicalComplex _).map φ) 0 ≫
Q.fromLeftDerivedZero' F = P.fromLeftDerivedZero' F ≫ F.map f := by
simp only [← cancel_epi (HomologicalComplex.pOpcycles _ _), ← F.map_comp, comm,
HomologicalComplex.p_opcyclesMap_assoc, Functor.mapHomologicalComplex_map_f,
pOpcycles_comp_fromLeftDerivedZero', pOpcycles_comp_fromLeftDerivedZero'_assoc]
instance (F : C ⥤ D) [F.Additive] (X : C) [Projective X] :
IsIso ((ProjectiveResolution.self X).fromLeftDerivedZero' F) := by
dsimp [ProjectiveResolution.fromLeftDerivedZero']
rw [ChainComplex.isIso_descOpcycles_iff]
refine ⟨ShortComplex.Splitting.exact ?_, inferInstance⟩
exact
{ r := 0
s := 𝟙 _
f_r := (F.map_isZero (isZero_zero _)).eq_of_src _ _ }
end ProjectiveResolution
/-- The natural transformation `F.leftDerived 0 ⟶ F`. -/
noncomputable def Functor.fromLeftDerivedZero (F : C ⥤ D) [F.Additive] :
F.leftDerived 0 ⟶ F where
app X := (HomotopyCategory.homologyFunctorFactors D (ComplexShape.down ℕ) 0).hom.app _ ≫
(ChainComplex.isoHomologyι₀ _).hom ≫ (projectiveResolution X).fromLeftDerivedZero' F
naturality {X Y} f := by
dsimp [leftDerived]
rw [assoc, assoc, ← ProjectiveResolution.fromLeftDerivedZero'_naturality f
(projectiveResolution X) (projectiveResolution Y)
(ProjectiveResolution.lift f _ _) (by simp),
← HomologicalComplex.homologyι_naturality_assoc]
erw [← NatTrans.naturality_assoc]
rfl
lemma ProjectiveResolution.fromLeftDerivedZero_eq
{X : C} (P : ProjectiveResolution X) (F : C ⥤ D) [F.Additive] :
F.fromLeftDerivedZero.app X = (P.isoLeftDerivedObj F 0).hom ≫
(ChainComplex.isoHomologyι₀ _).hom ≫
P.fromLeftDerivedZero' F := by
dsimp [Functor.fromLeftDerivedZero, isoLeftDerivedObj]
have h₁ := ProjectiveResolution.fromLeftDerivedZero'_naturality
(𝟙 X) P (projectiveResolution X) (lift (𝟙 X) _ _) (by simp) F
have h₂ : (P.isoLeftDerivedToHomotopyCategoryObj F).inv =
(F.mapHomologicalComplex _ ⋙ HomotopyCategory.quotient _ _).map (lift (𝟙 X) _ _) :=
id_comp _
simp only [Functor.map_id, comp_id] at h₁
rw [assoc, ← cancel_epi ((HomotopyCategory.homologyFunctor _ _ 0).map
(P.isoLeftDerivedToHomotopyCategoryObj F).inv), ← Functor.map_comp_assoc,
Iso.inv_hom_id, Functor.map_id, id_comp, ← h₁, h₂,
← HomologicalComplex.homologyι_naturality_assoc]
erw [← NatTrans.naturality_assoc]
rfl
instance (F : C ⥤ D) [F.Additive] (X : C) [Projective X] :
IsIso (F.fromLeftDerivedZero.app X) := by
rw [(ProjectiveResolution.self X).fromLeftDerivedZero_eq F]
infer_instance
section
variable (F : C ⥤ D) [F.Additive] [PreservesFiniteColimits F]
instance {X : C} (P : ProjectiveResolution X) :
IsIso (P.fromLeftDerivedZero' F) := by
dsimp [ProjectiveResolution.fromLeftDerivedZero']
rw [ChainComplex.isIso_descOpcycles_iff, ShortComplex.exact_and_epi_g_iff_g_is_cokernel]
exact ⟨CokernelCofork.mapIsColimit _ (P.isColimitCokernelCofork) F⟩
instance (X : C) : IsIso (F.fromLeftDerivedZero.app X) := by
dsimp [Functor.fromLeftDerivedZero]
infer_instance
instance : IsIso F.fromLeftDerivedZero :=
NatIso.isIso_of_isIso_app _
namespace Functor
/-- The canonical isomorphism `F.leftDerived 0 ≅ F` when `F` is right exact
(i.e. preserves finite colimits). -/
@[simps! hom]
noncomputable def leftDerivedZeroIsoSelf : F.leftDerived 0 ≅ F :=
(asIso F.fromLeftDerivedZero)
@[reassoc (attr := simp)]
lemma leftDerivedZeroIsoSelf_hom_inv_id :
F.fromLeftDerivedZero ≫ F.leftDerivedZeroIsoSelf.inv = 𝟙 _ :=
F.leftDerivedZeroIsoSelf.hom_inv_id
@[reassoc (attr := simp)]
lemma leftDerivedZeroIsoSelf_inv_hom_id :
F.leftDerivedZeroIsoSelf.inv ≫ F.fromLeftDerivedZero = 𝟙 _ :=
F.leftDerivedZeroIsoSelf.inv_hom_id
@[reassoc (attr := simp)]
lemma leftDerivedZeroIsoSelf_hom_inv_id_app (X : C) :
F.fromLeftDerivedZero.app X ≫ F.leftDerivedZeroIsoSelf.inv.app X = 𝟙 _ :=
F.leftDerivedZeroIsoSelf.hom_inv_id_app X
@[reassoc (attr := simp)]
lemma leftDerivedZeroIsoSelf_inv_hom_id_app (X : C) :
F.leftDerivedZeroIsoSelf.inv.app X ≫ F.fromLeftDerivedZero.app X = 𝟙 _ :=
F.leftDerivedZeroIsoSelf.inv_hom_id_app X
end Functor
end
end CategoryTheory
|
CategoryTheory\Abelian\NonPreadditive.lean | /-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.CategoryTheory.Limits.Shapes.FiniteProducts
import Mathlib.CategoryTheory.Limits.Shapes.Kernels
import Mathlib.CategoryTheory.Limits.Shapes.NormalMono.Equalizers
import Mathlib.CategoryTheory.Abelian.Images
import Mathlib.CategoryTheory.Preadditive.Basic
/-!
# Every NonPreadditiveAbelian category is preadditive
In mathlib, we define an abelian category as a preadditive category with a zero object,
kernels and cokernels, products and coproducts and in which every monomorphism and epimorphism is
normal.
While virtually every interesting abelian category has a natural preadditive structure (which is why
it is included in the definition), preadditivity is not actually needed: Every category that has
all of the other properties appearing in the definition of an abelian category admits a preadditive
structure. This is the construction we carry out in this file.
The proof proceeds in roughly five steps:
1. Prove some results (for example that all equalizers exist) that would be trivial if we already
had the preadditive structure but are a bit of work without it.
2. Develop images and coimages to show that every monomorphism is the kernel of its cokernel.
The results of the first two steps are also useful for the "normal" development of abelian
categories, and will be used there.
3. For every object `A`, define a "subtraction" morphism `σ : A ⨯ A ⟶ A` and use it to define
subtraction on morphisms as `f - g := prod.lift f g ≫ σ`.
4. Prove a small number of identities about this subtraction from the definition of `σ`.
5. From these identities, prove a large number of other identities that imply that defining
`f + g := f - (0 - g)` indeed gives an abelian group structure on morphisms such that composition
is bilinear.
The construction is non-trivial and it is quite remarkable that this abelian group structure can
be constructed purely from the existence of a few limits and colimits. Even more remarkably,
since abelian categories admit exactly one preadditive structure (see
`subsingletonPreadditiveOfHasBinaryBiproducts`), the construction manages to exactly
reconstruct any natural preadditive structure the category may have.
## References
* [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2]
-/
noncomputable section
open CategoryTheory
open CategoryTheory.Limits
namespace CategoryTheory
section
universe v u
variable (C : Type u) [Category.{v} C]
/-- We call a category `NonPreadditiveAbelian` if it has a zero object, kernels, cokernels, binary
products and coproducts, and every monomorphism and every epimorphism is normal. -/
class NonPreadditiveAbelian extends HasZeroMorphisms C, NormalMonoCategory C,
NormalEpiCategory C where
[has_zero_object : HasZeroObject C]
[has_kernels : HasKernels C]
[has_cokernels : HasCokernels C]
[has_finite_products : HasFiniteProducts C]
[has_finite_coproducts : HasFiniteCoproducts C]
attribute [instance] NonPreadditiveAbelian.has_zero_object
attribute [instance] NonPreadditiveAbelian.has_kernels
attribute [instance] NonPreadditiveAbelian.has_cokernels
attribute [instance] NonPreadditiveAbelian.has_finite_products
attribute [instance] NonPreadditiveAbelian.has_finite_coproducts
end
end CategoryTheory
open CategoryTheory
universe v u
variable {C : Type u} [Category.{v} C] [NonPreadditiveAbelian C]
namespace CategoryTheory.NonPreadditiveAbelian
section Factor
variable {P Q : C} (f : P ⟶ Q)
/-- The map `p : P ⟶ image f` is an epimorphism -/
instance : Epi (Abelian.factorThruImage f) :=
let I := Abelian.image f
let p := Abelian.factorThruImage f
let i := kernel.ι (cokernel.π f)
-- It will suffice to consider some g : I ⟶ R such that p ≫ g = 0 and show that g = 0.
NormalMonoCategory.epi_of_zero_cancel
_ fun R (g : I ⟶ R) (hpg : p ≫ g = 0) => by
-- Since C is abelian, u := ker g ≫ i is the kernel of some morphism h.
let u := kernel.ι g ≫ i
haveI : Mono u := mono_comp _ _
haveI hu := normalMonoOfMono u
let h := hu.g
-- By hypothesis, p factors through the kernel of g via some t.
obtain ⟨t, ht⟩ := kernel.lift' g p hpg
have fh : f ≫ h = 0 :=
calc
f ≫ h = (p ≫ i) ≫ h := (Abelian.image.fac f).symm ▸ rfl
_ = ((t ≫ kernel.ι g) ≫ i) ≫ h := ht ▸ rfl
_ = t ≫ u ≫ h := by simp only [u, Category.assoc]
_ = t ≫ 0 := hu.w ▸ rfl
_ = 0 := HasZeroMorphisms.comp_zero _ _
-- h factors through the cokernel of f via some l.
obtain ⟨l, hl⟩ := cokernel.desc' f h fh
have hih : i ≫ h = 0 :=
calc
i ≫ h = i ≫ cokernel.π f ≫ l := hl ▸ rfl
_ = 0 ≫ l := by rw [← Category.assoc, kernel.condition]
_ = 0 := zero_comp
-- i factors through u = ker h via some s.
obtain ⟨s, hs⟩ := NormalMono.lift' u i hih
have hs' : (s ≫ kernel.ι g) ≫ i = 𝟙 I ≫ i := by rw [Category.assoc, hs, Category.id_comp]
haveI : Epi (kernel.ι g) := epi_of_epi_fac ((cancel_mono _).1 hs')
-- ker g is an epimorphism, but ker g ≫ g = 0 = ker g ≫ 0, so g = 0 as required.
exact zero_of_epi_comp _ (kernel.condition g)
instance isIso_factorThruImage [Mono f] : IsIso (Abelian.factorThruImage f) :=
isIso_of_mono_of_epi <| Abelian.factorThruImage f
/-- The canonical morphism `i : coimage f ⟶ Q` is a monomorphism -/
instance : Mono (Abelian.factorThruCoimage f) :=
let I := Abelian.coimage f
let i := Abelian.factorThruCoimage f
let p := cokernel.π (kernel.ι f)
NormalEpiCategory.mono_of_cancel_zero _ fun R (g : R ⟶ I) (hgi : g ≫ i = 0) => by
-- Since C is abelian, u := p ≫ coker g is the cokernel of some morphism h.
let u := p ≫ cokernel.π g
haveI : Epi u := epi_comp _ _
haveI hu := normalEpiOfEpi u
let h := hu.g
-- By hypothesis, i factors through the cokernel of g via some t.
obtain ⟨t, ht⟩ := cokernel.desc' g i hgi
have hf : h ≫ f = 0 :=
calc
h ≫ f = h ≫ p ≫ i := (Abelian.coimage.fac f).symm ▸ rfl
_ = h ≫ p ≫ cokernel.π g ≫ t := ht ▸ rfl
_ = h ≫ u ≫ t := by simp only [u, Category.assoc]
_ = 0 ≫ t := by rw [← Category.assoc, hu.w]
_ = 0 := zero_comp
-- h factors through the kernel of f via some l.
obtain ⟨l, hl⟩ := kernel.lift' f h hf
have hhp : h ≫ p = 0 :=
calc
h ≫ p = (l ≫ kernel.ι f) ≫ p := hl ▸ rfl
_ = l ≫ 0 := by rw [Category.assoc, cokernel.condition]
_ = 0 := comp_zero
-- p factors through u = coker h via some s.
obtain ⟨s, hs⟩ := NormalEpi.desc' u p hhp
have hs' : p ≫ cokernel.π g ≫ s = p ≫ 𝟙 I := by rw [← Category.assoc, hs, Category.comp_id]
haveI : Mono (cokernel.π g) := mono_of_mono_fac ((cancel_epi _).1 hs')
-- coker g is a monomorphism, but g ≫ coker g = 0 = 0 ≫ coker g, so g = 0 as required.
exact zero_of_comp_mono _ (cokernel.condition g)
instance isIso_factorThruCoimage [Epi f] : IsIso (Abelian.factorThruCoimage f) :=
isIso_of_mono_of_epi _
end Factor
section CokernelOfKernel
variable {X Y : C} {f : X ⟶ Y}
/-- In a `NonPreadditiveAbelian` category, an epi is the cokernel of its kernel. More precisely:
If `f` is an epimorphism and `s` is some limit kernel cone on `f`, then `f` is a cokernel
of `Fork.ι s`. -/
def epiIsCokernelOfKernel [Epi f] (s : Fork f 0) (h : IsLimit s) :
IsColimit (CokernelCofork.ofπ f (KernelFork.condition s)) :=
IsCokernel.cokernelIso _ _
(cokernel.ofIsoComp _ _ (Limits.IsLimit.conePointUniqueUpToIso (limit.isLimit _) h)
(ConeMorphism.w (Limits.IsLimit.uniqueUpToIso (limit.isLimit _) h).hom _))
(asIso <| Abelian.factorThruCoimage f) (Abelian.coimage.fac f)
/-- In a `NonPreadditiveAbelian` category, a mono is the kernel of its cokernel. More precisely:
If `f` is a monomorphism and `s` is some colimit cokernel cocone on `f`, then `f` is a kernel
of `Cofork.π s`. -/
def monoIsKernelOfCokernel [Mono f] (s : Cofork f 0) (h : IsColimit s) :
IsLimit (KernelFork.ofι f (CokernelCofork.condition s)) :=
IsKernel.isoKernel _ _
(kernel.ofCompIso _ _ (Limits.IsColimit.coconePointUniqueUpToIso h (colimit.isColimit _))
(CoconeMorphism.w (Limits.IsColimit.uniqueUpToIso h <| colimit.isColimit _).hom _))
(asIso <| Abelian.factorThruImage f) (Abelian.image.fac f)
end CokernelOfKernel
section
/-- The composite `A ⟶ A ⨯ A ⟶ cokernel (Δ A)`, where the first map is `(𝟙 A, 0)` and the second map
is the canonical projection into the cokernel. -/
abbrev r (A : C) : A ⟶ cokernel (diag A) :=
prod.lift (𝟙 A) 0 ≫ cokernel.π (diag A)
instance mono_Δ {A : C} : Mono (diag A) :=
mono_of_mono_fac <| prod.lift_fst _ _
instance mono_r {A : C} : Mono (r A) := by
let hl : IsLimit (KernelFork.ofι (diag A) (cokernel.condition (diag A))) :=
monoIsKernelOfCokernel _ (colimit.isColimit _)
apply NormalEpiCategory.mono_of_cancel_zero
intro Z x hx
have hxx : (x ≫ prod.lift (𝟙 A) (0 : A ⟶ A)) ≫ cokernel.π (diag A) = 0 := by
rw [Category.assoc, hx]
obtain ⟨y, hy⟩ := KernelFork.IsLimit.lift' hl _ hxx
rw [KernelFork.ι_ofι] at hy
have hyy : y = 0 := by
erw [← Category.comp_id y, ← Limits.prod.lift_snd (𝟙 A) (𝟙 A), ← Category.assoc, hy,
Category.assoc, prod.lift_snd, HasZeroMorphisms.comp_zero]
haveI : Mono (prod.lift (𝟙 A) (0 : A ⟶ A)) := mono_of_mono_fac (prod.lift_fst _ _)
apply (cancel_mono (prod.lift (𝟙 A) (0 : A ⟶ A))).1
rw [← hy, hyy, zero_comp, zero_comp]
instance epi_r {A : C} : Epi (r A) := by
have hlp : prod.lift (𝟙 A) (0 : A ⟶ A) ≫ Limits.prod.snd = 0 := prod.lift_snd _ _
let hp1 : IsLimit (KernelFork.ofι (prod.lift (𝟙 A) (0 : A ⟶ A)) hlp) := by
refine Fork.IsLimit.mk _ (fun s => Fork.ι s ≫ Limits.prod.fst) ?_ ?_
· intro s
apply prod.hom_ext <;> simp
· intro s m h
haveI : Mono (prod.lift (𝟙 A) (0 : A ⟶ A)) := mono_of_mono_fac (prod.lift_fst _ _)
apply (cancel_mono (prod.lift (𝟙 A) (0 : A ⟶ A))).1
convert h
apply prod.hom_ext <;> simp
let hp2 : IsColimit (CokernelCofork.ofπ (Limits.prod.snd : A ⨯ A ⟶ A) hlp) :=
epiIsCokernelOfKernel _ hp1
apply NormalMonoCategory.epi_of_zero_cancel
intro Z z hz
have h : prod.lift (𝟙 A) (0 : A ⟶ A) ≫ cokernel.π (diag A) ≫ z = 0 := by rw [← Category.assoc, hz]
obtain ⟨t, ht⟩ := CokernelCofork.IsColimit.desc' hp2 _ h
rw [CokernelCofork.π_ofπ] at ht
have htt : t = 0 := by
rw [← Category.id_comp t]
change 𝟙 A ≫ t = 0
rw [← Limits.prod.lift_snd (𝟙 A) (𝟙 A), Category.assoc, ht, ← Category.assoc,
cokernel.condition, zero_comp]
apply (cancel_epi (cokernel.π (diag A))).1
rw [← ht, htt, comp_zero, comp_zero]
instance isIso_r {A : C} : IsIso (r A) :=
isIso_of_mono_of_epi _
/-- The composite `A ⨯ A ⟶ cokernel (diag A) ⟶ A` given by the natural projection into the cokernel
followed by the inverse of `r`. In the category of modules, using the normal kernels and
cokernels, this map is equal to the map `(a, b) ↦ a - b`, hence the name `σ` for
"subtraction". -/
abbrev σ {A : C} : A ⨯ A ⟶ A :=
cokernel.π (diag A) ≫ inv (r A)
end
-- Porting note (#10618): simp can prove these
@[reassoc]
theorem diag_σ {X : C} : diag X ≫ σ = 0 := by rw [cokernel.condition_assoc, zero_comp]
@[reassoc (attr := simp)]
theorem lift_σ {X : C} : prod.lift (𝟙 X) 0 ≫ σ = 𝟙 X := by rw [← Category.assoc, IsIso.hom_inv_id]
@[reassoc]
theorem lift_map {X Y : C} (f : X ⟶ Y) :
prod.lift (𝟙 X) 0 ≫ Limits.prod.map f f = f ≫ prod.lift (𝟙 Y) 0 := by simp
/-- σ is a cokernel of Δ X. -/
def isColimitσ {X : C} : IsColimit (CokernelCofork.ofπ (σ : X ⨯ X ⟶ X) diag_σ) :=
cokernel.cokernelIso _ σ (asIso (r X)).symm (by rw [Iso.symm_hom, asIso_inv])
/-- This is the key identity satisfied by `σ`. -/
theorem σ_comp {X Y : C} (f : X ⟶ Y) : σ ≫ f = Limits.prod.map f f ≫ σ := by
obtain ⟨g, hg⟩ :=
CokernelCofork.IsColimit.desc' isColimitσ (Limits.prod.map f f ≫ σ) (by
rw [prod.diag_map_assoc, diag_σ, comp_zero])
suffices hfg : f = g by rw [← hg, Cofork.π_ofπ, hfg]
calc
f = f ≫ prod.lift (𝟙 Y) 0 ≫ σ := by rw [lift_σ, Category.comp_id]
_ = prod.lift (𝟙 X) 0 ≫ Limits.prod.map f f ≫ σ := by rw [lift_map_assoc]
_ = prod.lift (𝟙 X) 0 ≫ σ ≫ g := by rw [← hg, CokernelCofork.π_ofπ]
_ = g := by rw [← Category.assoc, lift_σ, Category.id_comp]
section
-- We write `f - g` for `prod.lift f g ≫ σ`.
/-- Subtraction of morphisms in a `NonPreadditiveAbelian` category. -/
def hasSub {X Y : C} : Sub (X ⟶ Y) :=
⟨fun f g => prod.lift f g ≫ σ⟩
attribute [local instance] hasSub
-- We write `-f` for `0 - f`.
/-- Negation of morphisms in a `NonPreadditiveAbelian` category. -/
def hasNeg {X Y : C} : Neg (X ⟶ Y) where
neg := fun f => 0 - f
attribute [local instance] hasNeg
-- We write `f + g` for `f - (-g)`.
/-- Addition of morphisms in a `NonPreadditiveAbelian` category. -/
def hasAdd {X Y : C} : Add (X ⟶ Y) :=
⟨fun f g => f - -g⟩
attribute [local instance] hasAdd
theorem sub_def {X Y : C} (a b : X ⟶ Y) : a - b = prod.lift a b ≫ σ := rfl
theorem add_def {X Y : C} (a b : X ⟶ Y) : a + b = a - -b := rfl
theorem neg_def {X Y : C} (a : X ⟶ Y) : -a = 0 - a := rfl
theorem sub_zero {X Y : C} (a : X ⟶ Y) : a - 0 = a := by
rw [sub_def]
conv_lhs =>
congr; congr; rw [← Category.comp_id a]
case a.g => rw [show 0 = a ≫ (0 : Y ⟶ Y) by simp]
rw [← prod.comp_lift, Category.assoc, lift_σ, Category.comp_id]
theorem sub_self {X Y : C} (a : X ⟶ Y) : a - a = 0 := by
rw [sub_def, ← Category.comp_id a, ← prod.comp_lift, Category.assoc, diag_σ, comp_zero]
theorem lift_sub_lift {X Y : C} (a b c d : X ⟶ Y) :
prod.lift a b - prod.lift c d = prod.lift (a - c) (b - d) := by
simp only [sub_def]
ext
· rw [Category.assoc, σ_comp, prod.lift_map_assoc, prod.lift_fst, prod.lift_fst, prod.lift_fst]
· rw [Category.assoc, σ_comp, prod.lift_map_assoc, prod.lift_snd, prod.lift_snd, prod.lift_snd]
theorem sub_sub_sub {X Y : C} (a b c d : X ⟶ Y) : a - c - (b - d) = a - b - (c - d) := by
rw [sub_def, ← lift_sub_lift, sub_def, Category.assoc, σ_comp, prod.lift_map_assoc]; rfl
theorem neg_sub {X Y : C} (a b : X ⟶ Y) : -a - b = -b - a := by
conv_lhs => rw [neg_def, ← sub_zero b, sub_sub_sub, sub_zero, ← neg_def]
theorem neg_neg {X Y : C} (a : X ⟶ Y) : - -a = a := by
rw [neg_def, neg_def]
conv_lhs =>
congr; rw [← sub_self a]
rw [sub_sub_sub, sub_zero, sub_self, sub_zero]
theorem add_comm {X Y : C} (a b : X ⟶ Y) : a + b = b + a := by
rw [add_def]
conv_lhs => rw [← neg_neg a]
rw [neg_def, neg_def, neg_def, sub_sub_sub]
conv_lhs =>
congr
next => skip
rw [← neg_def, neg_sub]
rw [sub_sub_sub, add_def, ← neg_def, neg_neg b, neg_def]
theorem add_neg {X Y : C} (a b : X ⟶ Y) : a + -b = a - b := by rw [add_def, neg_neg]
theorem add_neg_self {X Y : C} (a : X ⟶ Y) : a + -a = 0 := by rw [add_neg, sub_self]
theorem neg_add_self {X Y : C} (a : X ⟶ Y) : -a + a = 0 := by rw [add_comm, add_neg_self]
theorem neg_sub' {X Y : C} (a b : X ⟶ Y) : -(a - b) = -a + b := by
rw [neg_def, neg_def]
conv_lhs => rw [← sub_self (0 : X ⟶ Y)]
rw [sub_sub_sub, add_def, neg_def]
theorem neg_add {X Y : C} (a b : X ⟶ Y) : -(a + b) = -a - b := by rw [add_def, neg_sub', add_neg]
theorem sub_add {X Y : C} (a b c : X ⟶ Y) : a - b + c = a - (b - c) := by
rw [add_def, neg_def, sub_sub_sub, sub_zero]
theorem add_assoc {X Y : C} (a b c : X ⟶ Y) : a + b + c = a + (b + c) := by
conv_lhs =>
congr; rw [add_def]
rw [sub_add, ← add_neg, neg_sub', neg_neg]
theorem add_zero {X Y : C} (a : X ⟶ Y) : a + 0 = a := by rw [add_def, neg_def, sub_self, sub_zero]
theorem comp_sub {X Y Z : C} (f : X ⟶ Y) (g h : Y ⟶ Z) : f ≫ (g - h) = f ≫ g - f ≫ h := by
rw [sub_def, ← Category.assoc, prod.comp_lift, sub_def]
theorem sub_comp {X Y Z : C} (f g : X ⟶ Y) (h : Y ⟶ Z) : (f - g) ≫ h = f ≫ h - g ≫ h := by
rw [sub_def, Category.assoc, σ_comp, ← Category.assoc, prod.lift_map, sub_def]
theorem comp_add (X Y Z : C) (f : X ⟶ Y) (g h : Y ⟶ Z) : f ≫ (g + h) = f ≫ g + f ≫ h := by
rw [add_def, comp_sub, neg_def, comp_sub, comp_zero, add_def, neg_def]
theorem add_comp (X Y Z : C) (f g : X ⟶ Y) (h : Y ⟶ Z) : (f + g) ≫ h = f ≫ h + g ≫ h := by
rw [add_def, sub_comp, neg_def, sub_comp, zero_comp, add_def, neg_def]
/-- Every `NonPreadditiveAbelian` category is preadditive. -/
def preadditive : Preadditive C where
homGroup X Y :=
{ add := (· + ·)
add_assoc := add_assoc
zero := 0
zero_add := neg_neg
add_zero := add_zero
neg := fun f => -f
add_left_neg := neg_add_self
sub_eq_add_neg := fun f g => (add_neg f g).symm -- Porting note: autoParam failed
add_comm := add_comm
nsmul := nsmulRec
zsmul := zsmulRec }
add_comp := add_comp
comp_add := comp_add
end
end CategoryTheory.NonPreadditiveAbelian
|
CategoryTheory\Abelian\Opposite.lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.CategoryTheory.Abelian.Basic
import Mathlib.CategoryTheory.Preadditive.Opposite
import Mathlib.CategoryTheory.Limits.Opposites
/-!
# The opposite of an abelian category is abelian.
-/
noncomputable section
namespace CategoryTheory
open CategoryTheory.Limits
variable (C : Type*) [Category C] [Abelian C]
-- Porting note: these local instances do not seem to be necessary
--attribute [local instance]
-- hasFiniteLimits_of_hasEqualizers_and_finite_products
-- hasFiniteColimits_of_hasCoequalizers_and_finite_coproducts
-- Abelian.hasFiniteBiproducts
instance : Abelian Cᵒᵖ := by
-- Porting note: priorities of `Abelian.has_kernels` and `Abelian.has_cokernels` have
-- been set to 90 in `Abelian.Basic` in order to prevent a timeout here
exact {
normalMonoOfMono := fun f => normalMonoOfNormalEpiUnop _ (normalEpiOfEpi f.unop)
normalEpiOfEpi := fun f => normalEpiOfNormalMonoUnop _ (normalMonoOfMono f.unop) }
section
variable {C}
variable {X Y : C} (f : X ⟶ Y) {A B : Cᵒᵖ} (g : A ⟶ B)
-- TODO: Generalize (this will work whenever f has a cokernel)
-- (The abelian case is probably sufficient for most applications.)
/-- The kernel of `f.op` is the opposite of `cokernel f`. -/
@[simps]
def kernelOpUnop : (kernel f.op).unop ≅ cokernel f where
hom := (kernel.lift f.op (cokernel.π f).op <| by simp [← op_comp]).unop
inv :=
cokernel.desc f (kernel.ι f.op).unop <| by
rw [← f.unop_op, ← unop_comp, f.unop_op]
simp
hom_inv_id := by
rw [← unop_id, ← (cokernel.desc f _ _).unop_op, ← unop_comp]
congr 1
ext
simp [← op_comp]
inv_hom_id := by
ext
simp [← unop_comp]
-- TODO: Generalize (this will work whenever f has a kernel)
-- (The abelian case is probably sufficient for most applications.)
/-- The cokernel of `f.op` is the opposite of `kernel f`. -/
@[simps]
def cokernelOpUnop : (cokernel f.op).unop ≅ kernel f where
hom :=
kernel.lift f (cokernel.π f.op).unop <| by
rw [← f.unop_op, ← unop_comp, f.unop_op]
simp
inv := (cokernel.desc f.op (kernel.ι f).op <| by simp [← op_comp]).unop
hom_inv_id := by
rw [← unop_id, ← (kernel.lift f _ _).unop_op, ← unop_comp]
congr 1
ext
simp [← op_comp]
inv_hom_id := by
ext
simp [← unop_comp]
/-- The kernel of `g.unop` is the opposite of `cokernel g`. -/
@[simps!]
def kernelUnopOp : Opposite.op (kernel g.unop) ≅ cokernel g :=
(cokernelOpUnop g.unop).op
/-- The cokernel of `g.unop` is the opposite of `kernel g`. -/
@[simps!]
def cokernelUnopOp : Opposite.op (cokernel g.unop) ≅ kernel g :=
(kernelOpUnop g.unop).op
theorem cokernel.π_op :
(cokernel.π f.op).unop =
(cokernelOpUnop f).hom ≫ kernel.ι f ≫ eqToHom (Opposite.unop_op _).symm := by
simp [cokernelOpUnop]
theorem kernel.ι_op :
(kernel.ι f.op).unop = eqToHom (Opposite.unop_op _) ≫ cokernel.π f ≫ (kernelOpUnop f).inv := by
simp [kernelOpUnop]
/-- The kernel of `f.op` is the opposite of `cokernel f`. -/
@[simps!]
def kernelOpOp : kernel f.op ≅ Opposite.op (cokernel f) :=
(kernelOpUnop f).op.symm
/-- The cokernel of `f.op` is the opposite of `kernel f`. -/
@[simps!]
def cokernelOpOp : cokernel f.op ≅ Opposite.op (kernel f) :=
(cokernelOpUnop f).op.symm
/-- The kernel of `g.unop` is the opposite of `cokernel g`. -/
@[simps!]
def kernelUnopUnop : kernel g.unop ≅ (cokernel g).unop :=
(kernelUnopOp g).unop.symm
theorem kernel.ι_unop :
(kernel.ι g.unop).op = eqToHom (Opposite.op_unop _) ≫ cokernel.π g ≫ (kernelUnopOp g).inv := by
simp
theorem cokernel.π_unop :
(cokernel.π g.unop).op =
(cokernelUnopOp g).hom ≫ kernel.ι g ≫ eqToHom (Opposite.op_unop _).symm := by
simp
/-- The cokernel of `g.unop` is the opposite of `kernel g`. -/
@[simps!]
def cokernelUnopUnop : cokernel g.unop ≅ (kernel g).unop :=
(cokernelUnopOp g).unop.symm
/-- The opposite of the image of `g.unop` is the image of `g.` -/
def imageUnopOp : Opposite.op (image g.unop) ≅ image g :=
(Abelian.imageIsoImage _).op ≪≫
(cokernelOpOp _).symm ≪≫
cokernelIsoOfEq (cokernel.π_unop _) ≪≫
cokernelEpiComp _ _ ≪≫ cokernelCompIsIso _ _ ≪≫ Abelian.coimageIsoImage' _
/-- The opposite of the image of `f` is the image of `f.op`. -/
def imageOpOp : Opposite.op (image f) ≅ image f.op :=
imageUnopOp f.op
/-- The image of `f.op` is the opposite of the image of `f`. -/
def imageOpUnop : (image f.op).unop ≅ image f :=
(imageUnopOp f.op).unop
/-- The image of `g` is the opposite of the image of `g.unop.` -/
def imageUnopUnop : (image g).unop ≅ image g.unop :=
(imageUnopOp g).unop
theorem image_ι_op_comp_imageUnopOp_hom :
(image.ι g.unop).op ≫ (imageUnopOp g).hom = factorThruImage g := by
simp only [imageUnopOp, Iso.trans, Iso.symm, Iso.op, cokernelOpOp_inv, cokernelEpiComp_hom,
cokernelCompIsIso_hom, Abelian.coimageIsoImage'_hom, ← Category.assoc, ← op_comp]
simp only [Category.assoc, Abelian.imageIsoImage_hom_comp_image_ι, kernel.lift_ι,
Quiver.Hom.op_unop, cokernelIsoOfEq_hom_comp_desc_assoc, cokernel.π_desc_assoc,
cokernel.π_desc]
simp only [eqToHom_refl]
erw [IsIso.inv_id, Category.id_comp]
theorem imageUnopOp_hom_comp_image_ι :
(imageUnopOp g).hom ≫ image.ι g = (factorThruImage g.unop).op := by
simp only [← cancel_epi (image.ι g.unop).op, ← Category.assoc, image_ι_op_comp_imageUnopOp_hom,
← op_comp, image.fac, Quiver.Hom.op_unop]
theorem factorThruImage_comp_imageUnopOp_inv :
factorThruImage g ≫ (imageUnopOp g).inv = (image.ι g.unop).op := by
rw [Iso.comp_inv_eq, image_ι_op_comp_imageUnopOp_hom]
theorem imageUnopOp_inv_comp_op_factorThruImage :
(imageUnopOp g).inv ≫ (factorThruImage g.unop).op = image.ι g := by
rw [Iso.inv_comp_eq, imageUnopOp_hom_comp_image_ι]
end
end CategoryTheory
end
|
CategoryTheory\Abelian\Projective.lean | /-
Copyright (c) 2022 Jakob von Raumer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jakob von Raumer
-/
import Mathlib.CategoryTheory.Abelian.Exact
import Mathlib.CategoryTheory.Preadditive.Yoneda.Projective
import Mathlib.CategoryTheory.Preadditive.Yoneda.Limits
import Mathlib.Algebra.Category.ModuleCat.EpiMono
import Mathlib.Algebra.Homology.ShortComplex.ExactFunctor
/-!
# Projective objects in abelian categories
In an abelian category, an object `P` is projective iff the functor
`preadditiveCoyonedaObj (op P)` preserves finite colimits.
-/
universe v u
namespace CategoryTheory
open Limits Projective Opposite
variable {C : Type u} [Category.{v} C] [Abelian C]
/-- The preadditive Co-Yoneda functor on `P` preserves homology if `P` is projective. -/
noncomputable instance preservesHomologyPreadditiveCoyonedaObjOfProjective
(P : C) [hP : Projective P] :
(preadditiveCoyonedaObj (op P)).PreservesHomology := by
haveI := (projective_iff_preservesEpimorphisms_preadditiveCoyoneda_obj' P).mp hP
haveI := @Functor.preservesEpimorphisms_of_preserves_of_reflects _ _ _ _ _ _ _ _ this _
apply Functor.preservesHomologyOfPreservesEpisAndKernels
/-- The preadditive Co-Yoneda functor on `P` preserves finite colimits if `P` is projective. -/
noncomputable instance preservesFiniteColimitsPreadditiveCoyonedaObjOfProjective
(P : C) [hP : Projective P] :
PreservesFiniteColimits (preadditiveCoyonedaObj (op P)) := by
apply Functor.preservesFiniteColimitsOfPreservesHomology
/-- An object is projective if its preadditive Co-Yoneda functor preserves finite colimits. -/
theorem projective_of_preservesFiniteColimits_preadditiveCoyonedaObj (P : C)
[hP : PreservesFiniteColimits (preadditiveCoyonedaObj (op P))] : Projective P := by
rw [projective_iff_preservesEpimorphisms_preadditiveCoyoneda_obj']
dsimp
have := Functor.preservesHomologyOfExact (preadditiveCoyonedaObj (op P))
infer_instance
end CategoryTheory
|
CategoryTheory\Abelian\ProjectiveResolution.lean | /-
Copyright (c) 2022 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel, Scott Morrison, Jakob von Raumer, Joël Riou
-/
import Mathlib.CategoryTheory.Preadditive.ProjectiveResolution
import Mathlib.Algebra.Homology.HomotopyCategory
import Mathlib.Tactic.SuppressCompilation
/-!
# Abelian categories with enough projectives have projective resolutions
## Main results
When the underlying category is abelian:
* `CategoryTheory.ProjectiveResolution.lift`: Given `P : ProjectiveResolution X` and
`Q : ProjectiveResolution Y`, any morphism `X ⟶ Y` admits a lifting to a chain map
`P.complex ⟶ Q.complex`. It is a lifting in the sense that `P.ι` intertwines the lift and
the original morphism, see `CategoryTheory.ProjectiveResolution.lift_commutes`.
* `CategoryTheory.ProjectiveResolution.liftHomotopy`: Any two such descents are homotopic.
* `CategoryTheory.ProjectiveResolution.homotopyEquiv`: Any two projective resolutions of the same
object are homotopy equivalent.
* `CategoryTheory.projectiveResolutions`: If every object admits a projective resolution, we can
construct a functor `projectiveResolutions C : C ⥤ HomotopyCategory C (ComplexShape.down ℕ)`.
* `CategoryTheory.exact_d_f`: `Projective.d f` and `f` are exact.
* `CategoryTheory.ProjectiveResolution.of`: Hence, starting from an epimorphism `P ⟶ X`, where `P`
is projective, we can apply `Projective.d` repeatedly to obtain a projective resolution of `X`.
-/
suppress_compilation
noncomputable section
universe v u
namespace CategoryTheory
variable {C : Type u} [Category.{v} C]
open Category Limits Projective
namespace ProjectiveResolution
section
variable [HasZeroObject C] [HasZeroMorphisms C]
/-- Auxiliary construction for `lift`. -/
def liftFZero {Y Z : C} (f : Y ⟶ Z) (P : ProjectiveResolution Y) (Q : ProjectiveResolution Z) :
P.complex.X 0 ⟶ Q.complex.X 0 :=
Projective.factorThru (P.π.f 0 ≫ f) (Q.π.f 0)
end
section Abelian
variable [Abelian C]
lemma exact₀ {Z : C} (P : ProjectiveResolution Z) :
(ShortComplex.mk _ _ P.complex_d_comp_π_f_zero).Exact :=
ShortComplex.exact_of_g_is_cokernel _ P.isColimitCokernelCofork
/-- Auxiliary construction for `lift`. -/
def liftFOne {Y Z : C} (f : Y ⟶ Z) (P : ProjectiveResolution Y) (Q : ProjectiveResolution Z) :
P.complex.X 1 ⟶ Q.complex.X 1 :=
Q.exact₀.liftFromProjective (P.complex.d 1 0 ≫ liftFZero f P Q) (by simp [liftFZero])
@[simp]
theorem liftFOne_zero_comm {Y Z : C} (f : Y ⟶ Z) (P : ProjectiveResolution Y)
(Q : ProjectiveResolution Z) :
liftFOne f P Q ≫ Q.complex.d 1 0 = P.complex.d 1 0 ≫ liftFZero f P Q := by
apply Q.exact₀.liftFromProjective_comp
/-- Auxiliary construction for `lift`. -/
def liftFSucc {Y Z : C} (P : ProjectiveResolution Y) (Q : ProjectiveResolution Z) (n : ℕ)
(g : P.complex.X n ⟶ Q.complex.X n) (g' : P.complex.X (n + 1) ⟶ Q.complex.X (n + 1))
(w : g' ≫ Q.complex.d (n + 1) n = P.complex.d (n + 1) n ≫ g) :
Σ'g'' : P.complex.X (n + 2) ⟶ Q.complex.X (n + 2),
g'' ≫ Q.complex.d (n + 2) (n + 1) = P.complex.d (n + 2) (n + 1) ≫ g' :=
⟨(Q.exact_succ n).liftFromProjective
(P.complex.d (n + 2) (n + 1) ≫ g') (by simp [w]),
(Q.exact_succ n).liftFromProjective_comp _ _⟩
/-- A morphism in `C` lift to a chain map between projective resolutions. -/
def lift {Y Z : C} (f : Y ⟶ Z) (P : ProjectiveResolution Y) (Q : ProjectiveResolution Z) :
P.complex ⟶ Q.complex :=
ChainComplex.mkHom _ _ (liftFZero f _ _) (liftFOne f _ _) (liftFOne_zero_comm f P Q)
fun n ⟨g, g', w⟩ => ⟨(liftFSucc P Q n g g' w).1, (liftFSucc P Q n g g' w).2⟩
/-- The resolution maps intertwine the lift of a morphism and that morphism. -/
@[reassoc (attr := simp)]
theorem lift_commutes {Y Z : C} (f : Y ⟶ Z) (P : ProjectiveResolution Y)
(Q : ProjectiveResolution Z) : lift f P Q ≫ Q.π = P.π ≫ (ChainComplex.single₀ C).map f := by
ext
simp [lift, liftFZero, liftFOne]
@[reassoc (attr := simp)]
lemma lift_commutes_zero {Y Z : C} (f : Y ⟶ Z)
(P : ProjectiveResolution Y) (Q : ProjectiveResolution Z) :
(lift f P Q).f 0 ≫ Q.π.f 0 = P.π.f 0 ≫ f :=
(HomologicalComplex.congr_hom (lift_commutes f P Q) 0).trans (by simp)
/-- An auxiliary definition for `liftHomotopyZero`. -/
def liftHomotopyZeroZero {Y Z : C} {P : ProjectiveResolution Y} {Q : ProjectiveResolution Z}
(f : P.complex ⟶ Q.complex) (comm : f ≫ Q.π = 0) : P.complex.X 0 ⟶ Q.complex.X 1 :=
Q.exact₀.liftFromProjective (f.f 0) (congr_fun (congr_arg HomologicalComplex.Hom.f comm) 0)
@[reassoc (attr := simp)]
lemma liftHomotopyZeroZero_comp {Y Z : C} {P : ProjectiveResolution Y} {Q : ProjectiveResolution Z}
(f : P.complex ⟶ Q.complex) (comm : f ≫ Q.π = 0) :
liftHomotopyZeroZero f comm ≫ Q.complex.d 1 0 = f.f 0 :=
Q.exact₀.liftFromProjective_comp _ _
/-- An auxiliary definition for `liftHomotopyZero`. -/
def liftHomotopyZeroOne {Y Z : C} {P : ProjectiveResolution Y} {Q : ProjectiveResolution Z}
(f : P.complex ⟶ Q.complex) (comm : f ≫ Q.π = 0) :
P.complex.X 1 ⟶ Q.complex.X 2 :=
(Q.exact_succ 0).liftFromProjective (f.f 1 - P.complex.d 1 0 ≫ liftHomotopyZeroZero f comm)
(by rw [Preadditive.sub_comp, assoc, HomologicalComplex.Hom.comm,
liftHomotopyZeroZero_comp, sub_self])
@[reassoc (attr := simp)]
lemma liftHomotopyZeroOne_comp {Y Z : C} {P : ProjectiveResolution Y} {Q : ProjectiveResolution Z}
(f : P.complex ⟶ Q.complex) (comm : f ≫ Q.π = 0) :
liftHomotopyZeroOne f comm ≫ Q.complex.d 2 1 =
f.f 1 - P.complex.d 1 0 ≫ liftHomotopyZeroZero f comm :=
(Q.exact_succ 0).liftFromProjective_comp _ _
/-- An auxiliary definition for `liftHomotopyZero`. -/
def liftHomotopyZeroSucc {Y Z : C} {P : ProjectiveResolution Y} {Q : ProjectiveResolution Z}
(f : P.complex ⟶ Q.complex) (n : ℕ) (g : P.complex.X n ⟶ Q.complex.X (n + 1))
(g' : P.complex.X (n + 1) ⟶ Q.complex.X (n + 2))
(w : f.f (n + 1) = P.complex.d (n + 1) n ≫ g + g' ≫ Q.complex.d (n + 2) (n + 1)) :
P.complex.X (n + 2) ⟶ Q.complex.X (n + 3) :=
(Q.exact_succ (n + 1)).liftFromProjective (f.f (n + 2) - P.complex.d _ _ ≫ g') (by simp [w])
@[reassoc (attr := simp)]
lemma liftHomotopyZeroSucc_comp {Y Z : C} {P : ProjectiveResolution Y} {Q : ProjectiveResolution Z}
(f : P.complex ⟶ Q.complex) (n : ℕ) (g : P.complex.X n ⟶ Q.complex.X (n + 1))
(g' : P.complex.X (n + 1) ⟶ Q.complex.X (n + 2))
(w : f.f (n + 1) = P.complex.d (n + 1) n ≫ g + g' ≫ Q.complex.d (n + 2) (n + 1)) :
liftHomotopyZeroSucc f n g g' w ≫ Q.complex.d (n + 3) (n + 2) =
f.f (n + 2) - P.complex.d _ _ ≫ g' :=
(Q.exact_succ (n+1)).liftFromProjective_comp _ _
/-- Any lift of the zero morphism is homotopic to zero. -/
def liftHomotopyZero {Y Z : C} {P : ProjectiveResolution Y} {Q : ProjectiveResolution Z}
(f : P.complex ⟶ Q.complex) (comm : f ≫ Q.π = 0) : Homotopy f 0 :=
Homotopy.mkInductive _ (liftHomotopyZeroZero f comm) (by simp )
(liftHomotopyZeroOne f comm) (by simp) fun n ⟨g, g', w⟩ =>
⟨liftHomotopyZeroSucc f n g g' w, by simp⟩
/-- Two lifts of the same morphism are homotopic. -/
def liftHomotopy {Y Z : C} (f : Y ⟶ Z) {P : ProjectiveResolution Y} {Q : ProjectiveResolution Z}
(g h : P.complex ⟶ Q.complex) (g_comm : g ≫ Q.π = P.π ≫ (ChainComplex.single₀ C).map f)
(h_comm : h ≫ Q.π = P.π ≫ (ChainComplex.single₀ C).map f) : Homotopy g h :=
Homotopy.equivSubZero.invFun (liftHomotopyZero _ (by simp [g_comm, h_comm]))
/-- The lift of the identity morphism is homotopic to the identity chain map. -/
def liftIdHomotopy (X : C) (P : ProjectiveResolution X) :
Homotopy (lift (𝟙 X) P P) (𝟙 P.complex) := by
apply liftHomotopy (𝟙 X) <;> simp
/-- The lift of a composition is homotopic to the composition of the lifts. -/
def liftCompHomotopy {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z) (P : ProjectiveResolution X)
(Q : ProjectiveResolution Y) (R : ProjectiveResolution Z) :
Homotopy (lift (f ≫ g) P R) (lift f P Q ≫ lift g Q R) := by
apply liftHomotopy (f ≫ g) <;> simp
-- We don't care about the actual definitions of these homotopies.
/-- Any two projective resolutions are homotopy equivalent. -/
def homotopyEquiv {X : C} (P Q : ProjectiveResolution X) :
HomotopyEquiv P.complex Q.complex where
hom := lift (𝟙 X) P Q
inv := lift (𝟙 X) Q P
homotopyHomInvId := (liftCompHomotopy (𝟙 X) (𝟙 X) P Q P).symm.trans <| by
simpa [id_comp] using liftIdHomotopy _ _
homotopyInvHomId := (liftCompHomotopy (𝟙 X) (𝟙 X) Q P Q).symm.trans <| by
simpa [id_comp] using liftIdHomotopy _ _
@[reassoc (attr := simp)]
theorem homotopyEquiv_hom_π {X : C} (P Q : ProjectiveResolution X) :
(homotopyEquiv P Q).hom ≫ Q.π = P.π := by simp [homotopyEquiv]
@[reassoc (attr := simp)]
theorem homotopyEquiv_inv_π {X : C} (P Q : ProjectiveResolution X) :
(homotopyEquiv P Q).inv ≫ P.π = Q.π := by simp [homotopyEquiv]
end Abelian
end ProjectiveResolution
/-- An arbitrarily chosen projective resolution of an object. -/
abbrev projectiveResolution (Z : C) [HasZeroObject C]
[HasZeroMorphisms C] [HasProjectiveResolution Z] :
ProjectiveResolution Z :=
(HasProjectiveResolution.out (Z := Z)).some
variable [Abelian C]
section
variable [HasProjectiveResolutions C]
variable (C) in
/-- Taking projective resolutions is functorial,
if considered with target the homotopy category
(`ℕ`-indexed chain complexes and chain maps up to homotopy).
-/
def projectiveResolutions : C ⥤ HomotopyCategory C (ComplexShape.down ℕ) where
obj X := (HomotopyCategory.quotient _ _).obj (projectiveResolution X).complex
map f := (HomotopyCategory.quotient _ _).map (ProjectiveResolution.lift f _ _)
map_id X := by
rw [← (HomotopyCategory.quotient _ _).map_id]
apply HomotopyCategory.eq_of_homotopy
apply ProjectiveResolution.liftIdHomotopy
map_comp f g := by
rw [← (HomotopyCategory.quotient _ _).map_comp]
apply HomotopyCategory.eq_of_homotopy
apply ProjectiveResolution.liftCompHomotopy
/-- If `P : ProjectiveResolution X`, then the chosen `(projectiveResolutions C).obj X`
is isomorphic (in the homotopy category) to `P.complex`. -/
def ProjectiveResolution.iso {X : C} (P : ProjectiveResolution X) :
(projectiveResolutions C).obj X ≅
(HomotopyCategory.quotient _ _).obj P.complex :=
HomotopyCategory.isoOfHomotopyEquiv (homotopyEquiv _ _)
@[reassoc]
lemma ProjectiveResolution.iso_inv_naturality {X Y : C} (f : X ⟶ Y)
(P : ProjectiveResolution X) (Q : ProjectiveResolution Y)
(φ : P.complex ⟶ Q.complex) (comm : φ.f 0 ≫ Q.π.f 0 = P.π.f 0 ≫ f) :
P.iso.inv ≫ (projectiveResolutions C).map f =
(HomotopyCategory.quotient _ _).map φ ≫ Q.iso.inv := by
apply HomotopyCategory.eq_of_homotopy
apply liftHomotopy f
all_goals
aesop_cat
@[reassoc]
lemma ProjectiveResolution.iso_hom_naturality {X Y : C} (f : X ⟶ Y)
(P : ProjectiveResolution X) (Q : ProjectiveResolution Y)
(φ : P.complex ⟶ Q.complex) (comm : φ.f 0 ≫ Q.π.f 0 = P.π.f 0 ≫ f) :
(projectiveResolutions C).map f ≫ Q.iso.hom =
P.iso.hom ≫ (HomotopyCategory.quotient _ _).map φ := by
rw [← cancel_epi (P.iso).inv, iso_inv_naturality_assoc f P Q φ comm,
Iso.inv_hom_id_assoc, Iso.inv_hom_id, comp_id]
end
variable [EnoughProjectives C]
theorem exact_d_f {X Y : C} (f : X ⟶ Y) :
(ShortComplex.mk (d f) f (by simp)).Exact := by
let α : ShortComplex.mk (d f) f (by simp) ⟶ ShortComplex.mk (kernel.ι f) f (by simp) :=
{ τ₁ := Projective.π _
τ₂ := 𝟙 _
τ₃ := 𝟙 _ }
have : Epi α.τ₁ := by dsimp; infer_instance
have : IsIso α.τ₂ := by dsimp; infer_instance
have : Mono α.τ₃ := by dsimp; infer_instance
rw [ShortComplex.exact_iff_of_epi_of_isIso_of_mono α]
apply ShortComplex.exact_of_f_is_kernel
apply kernelIsKernel
namespace ProjectiveResolution
/-!
Our goal is to define `ProjectiveResolution.of Z : ProjectiveResolution Z`.
The `0`-th object in this resolution will just be `Projective.over Z`,
i.e. an arbitrarily chosen projective object with a map to `Z`.
After that, we build the `n+1`-st object as `Projective.syzygies`
applied to the previously constructed morphism,
and the map from the `n`-th object as `Projective.d`.
-/
variable (Z : C)
-- The construction of the projective resolution `of` would be very, very slow
-- if it were not broken into separate definitions and lemmas
/-- Auxiliary definition for `ProjectiveResolution.of`. -/
def ofComplex : ChainComplex C ℕ :=
ChainComplex.mk' (Projective.over Z) (Projective.syzygies (Projective.π Z))
(Projective.d (Projective.π Z)) (fun f => ⟨_, Projective.d f, by simp⟩)
lemma ofComplex_d_1_0 :
(ofComplex Z).d 1 0 = d (Projective.π Z) := by
simp [ofComplex]
lemma ofComplex_exactAt_succ (n : ℕ) :
(ofComplex Z).ExactAt (n + 1) := by
rw [HomologicalComplex.exactAt_iff' _ (n + 1 + 1) (n + 1) n (by simp) (by simp)]
dsimp [ofComplex, HomologicalComplex.sc', HomologicalComplex.shortComplexFunctor',
ChainComplex.mk', ChainComplex.mk]
simp only [ChainComplex.of_d]
-- TODO: this should just be apply exact_d_f so something is missing
match n with
| 0 =>
apply exact_d_f ((ChainComplex.mkAux _ _ _ (d (Projective.π Z)) (d (d (Projective.π Z))) _ _
0).g)
| n+1 =>
apply exact_d_f ((ChainComplex.mkAux _ _ _ (d (Projective.π Z)) (d (d (Projective.π Z))) _ _
(n+1)).g)
instance (n : ℕ) : Projective ((ofComplex Z).X n) := by
obtain (_ | _ | _ | n) := n <;> apply Projective.projective_over
/-- In any abelian category with enough projectives,
`ProjectiveResolution.of Z` constructs an projective resolution of the object `Z`.
-/
irreducible_def of : ProjectiveResolution Z where
complex := ofComplex Z
π := (ChainComplex.toSingle₀Equiv _ _).symm ⟨Projective.π Z, by
rw [ofComplex_d_1_0, assoc, kernel.condition, comp_zero]⟩
quasiIso := ⟨fun n => by
cases n
· rw [ChainComplex.quasiIsoAt₀_iff, ShortComplex.quasiIso_iff_of_zeros']
· dsimp
refine (ShortComplex.exact_and_epi_g_iff_of_iso ?_).2
⟨exact_d_f (Projective.π Z), by dsimp; infer_instance⟩
exact ShortComplex.isoMk (Iso.refl _) (Iso.refl _) (Iso.refl _)
(by simp [ofComplex]) (by simp)
all_goals rfl
· rw [quasiIsoAt_iff_exactAt']
· apply ofComplex_exactAt_succ
· apply ChainComplex.exactAt_succ_single_obj⟩
instance (priority := 100) (Z : C) : HasProjectiveResolution Z where out := ⟨of Z⟩
instance (priority := 100) : HasProjectiveResolutions C where out _ := inferInstance
end ProjectiveResolution
end CategoryTheory
|
CategoryTheory\Abelian\Pseudoelements.lean | /-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.CategoryTheory.Abelian.Exact
import Mathlib.CategoryTheory.Comma.Over
import Mathlib.Algebra.Category.ModuleCat.EpiMono
/-!
# Pseudoelements in abelian categories
A *pseudoelement* of an object `X` in an abelian category `C` is an equivalence class of arrows
ending in `X`, where two arrows are considered equivalent if we can find two epimorphisms with a
common domain making a commutative square with the two arrows. While the construction shows that
pseudoelements are actually subobjects of `X` rather than "elements", it is possible to chase these
pseudoelements through commutative diagrams in an abelian category to prove exactness properties.
This is done using some "diagram-chasing metatheorems" proved in this file. In many cases, a proof
in the category of abelian groups can more or less directly be converted into a proof using
pseudoelements.
A classic application of pseudoelements are diagram lemmas like the four lemma or the snake lemma.
Pseudoelements are in some ways weaker than actual elements in a concrete category. The most
important limitation is that there is no extensionality principle: If `f g : X ⟶ Y`, then
`∀ x ∈ X, f x = g x` does not necessarily imply that `f = g` (however, if `f = 0` or `g = 0`,
it does). A corollary of this is that we can not define arrows in abelian categories by dictating
their action on pseudoelements. Thus, a usual style of proofs in abelian categories is this:
First, we construct some morphism using universal properties, and then we use diagram chasing
of pseudoelements to verify that is has some desirable property such as exactness.
It should be noted that the Freyd-Mitchell embedding theorem gives a vastly stronger notion of
pseudoelement (in particular one that gives extensionality). However, this theorem is quite
difficult to prove and probably out of reach for a formal proof for the time being.
## Main results
We define the type of pseudoelements of an object and, in particular, the zero pseudoelement.
We prove that every morphism maps the zero pseudoelement to the zero pseudoelement (`apply_zero`)
and that a zero morphism maps every pseudoelement to the zero pseudoelement (`zero_apply`).
Here are the metatheorems we provide:
* A morphism `f` is zero if and only if it is the zero function on pseudoelements.
* A morphism `f` is an epimorphism if and only if it is surjective on pseudoelements.
* A morphism `f` is a monomorphism if and only if it is injective on pseudoelements
if and only if `∀ a, f a = 0 → f = 0`.
* A sequence `f, g` of morphisms is exact if and only if
`∀ a, g (f a) = 0` and `∀ b, g b = 0 → ∃ a, f a = b`.
* If `f` is a morphism and `a, a'` are such that `f a = f a'`, then there is some
pseudoelement `a''` such that `f a'' = 0` and for every `g` we have
`g a' = 0 → g a = g a''`. We can think of `a''` as `a - a'`, but don't get too carried away
by that: pseudoelements of an object do not form an abelian group.
## Notations
We introduce coercions from an object of an abelian category to the set of its pseudoelements
and from a morphism to the function it induces on pseudoelements.
These coercions must be explicitly enabled via local instances:
`attribute [local instance] objectToSort homToFun`
## Implementation notes
It appears that sometimes the coercion from morphisms to functions does not work, i.e.,
writing `g a` raises a "function expected" error. This error can be fixed by writing
`(g : X ⟶ Y) a`.
## References
* [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2]
-/
open CategoryTheory
open CategoryTheory.Limits
open CategoryTheory.Abelian
open CategoryTheory.Preadditive
universe v u
namespace CategoryTheory.Abelian
variable {C : Type u} [Category.{v} C]
attribute [local instance] Over.coeFromHom
/-- This is just composition of morphisms in `C`. Another way to express this would be
`(Over.map f).obj a`, but our definition has nicer definitional properties. -/
def app {P Q : C} (f : P ⟶ Q) (a : Over P) : Over Q :=
a.hom ≫ f
@[simp]
theorem app_hom {P Q : C} (f : P ⟶ Q) (a : Over P) : (app f a).hom = a.hom ≫ f := rfl
/-- Two arrows `f : X ⟶ P` and `g : Y ⟶ P` are called pseudo-equal if there is some object
`R` and epimorphisms `p : R ⟶ X` and `q : R ⟶ Y` such that `p ≫ f = q ≫ g`. -/
def PseudoEqual (P : C) (f g : Over P) : Prop :=
∃ (R : C) (p : R ⟶ f.1) (q : R ⟶ g.1) (_ : Epi p) (_ : Epi q), p ≫ f.hom = q ≫ g.hom
theorem pseudoEqual_refl {P : C} : Reflexive (PseudoEqual P) :=
fun f => ⟨f.1, 𝟙 f.1, 𝟙 f.1, inferInstance, inferInstance, by simp⟩
theorem pseudoEqual_symm {P : C} : Symmetric (PseudoEqual P) :=
fun _ _ ⟨R, p, q, ep, Eq, comm⟩ => ⟨R, q, p, Eq, ep, comm.symm⟩
variable [Abelian.{v} C]
section
/-- Pseudoequality is transitive: Just take the pullback. The pullback morphisms will
be epimorphisms since in an abelian category, pullbacks of epimorphisms are epimorphisms. -/
theorem pseudoEqual_trans {P : C} : Transitive (PseudoEqual P) := by
intro f g h ⟨R, p, q, ep, Eq, comm⟩ ⟨R', p', q', ep', eq', comm'⟩
refine ⟨pullback q p', pullback.fst _ _ ≫ p, pullback.snd _ _ ≫ q',
epi_comp _ _, epi_comp _ _, ?_⟩
rw [Category.assoc, comm, ← Category.assoc, pullback.condition, Category.assoc, comm',
Category.assoc]
end
/-- The arrows with codomain `P` equipped with the equivalence relation of being pseudo-equal. -/
def Pseudoelement.setoid (P : C) : Setoid (Over P) :=
⟨_, ⟨pseudoEqual_refl, @pseudoEqual_symm _ _ _, @pseudoEqual_trans _ _ _ _⟩⟩
attribute [local instance] Pseudoelement.setoid
/-- A `Pseudoelement` of `P` is just an equivalence class of arrows ending in `P` by being
pseudo-equal. -/
def Pseudoelement (P : C) : Type max u v :=
Quotient (Pseudoelement.setoid P)
namespace Pseudoelement
/-- A coercion from an object of an abelian category to its pseudoelements. -/
def objectToSort : CoeSort C (Type max u v) :=
⟨fun P => Pseudoelement P⟩
attribute [local instance] objectToSort
scoped[Pseudoelement] attribute [instance] CategoryTheory.Abelian.Pseudoelement.objectToSort
/-- A coercion from an arrow with codomain `P` to its associated pseudoelement. -/
def overToSort {P : C} : Coe (Over P) (Pseudoelement P) :=
⟨Quot.mk (PseudoEqual P)⟩
attribute [local instance] overToSort
theorem over_coe_def {P Q : C} (a : Q ⟶ P) : (a : Pseudoelement P) = ⟦↑a⟧ := rfl
/-- If two elements are pseudo-equal, then their composition with a morphism is, too. -/
theorem pseudoApply_aux {P Q : C} (f : P ⟶ Q) (a b : Over P) : a ≈ b → app f a ≈ app f b :=
fun ⟨R, p, q, ep, Eq, comm⟩ =>
⟨R, p, q, ep, Eq, show p ≫ a.hom ≫ f = q ≫ b.hom ≫ f by rw [reassoc_of% comm]⟩
/-- A morphism `f` induces a function `pseudoApply f` on pseudoelements. -/
def pseudoApply {P Q : C} (f : P ⟶ Q) : P → Q :=
Quotient.map (fun g : Over P => app f g) (pseudoApply_aux f)
/-- A coercion from morphisms to functions on pseudoelements. -/
def homToFun {P Q : C} : CoeFun (P ⟶ Q) fun _ => P → Q :=
⟨pseudoApply⟩
attribute [local instance] homToFun
scoped[Pseudoelement] attribute [instance] CategoryTheory.Abelian.Pseudoelement.homToFun
theorem pseudoApply_mk' {P Q : C} (f : P ⟶ Q) (a : Over P) : f ⟦a⟧ = ⟦↑(a.hom ≫ f)⟧ := rfl
/-- Applying a pseudoelement to a composition of morphisms is the same as composing
with each morphism. Sadly, this is not a definitional equality, but at least it is
true. -/
theorem comp_apply {P Q R : C} (f : P ⟶ Q) (g : Q ⟶ R) (a : P) : (f ≫ g) a = g (f a) :=
Quotient.inductionOn a fun x =>
Quotient.sound <| by
simp only [app]
rw [← Category.assoc, Over.coe_hom]
/-- Composition of functions on pseudoelements is composition of morphisms. -/
theorem comp_comp {P Q R : C} (f : P ⟶ Q) (g : Q ⟶ R) : g ∘ f = f ≫ g :=
funext fun _ => (comp_apply _ _ _).symm
section Zero
/-!
In this section we prove that for every `P` there is an equivalence class that contains
precisely all the zero morphisms ending in `P` and use this to define *the* zero
pseudoelement.
-/
section
attribute [local instance] HasBinaryBiproducts.of_hasBinaryProducts
/-- The arrows pseudo-equal to a zero morphism are precisely the zero morphisms. -/
theorem pseudoZero_aux {P : C} (Q : C) (f : Over P) : f ≈ (0 : Q ⟶ P) ↔ f.hom = 0 :=
⟨fun ⟨R, p, q, ep, _, comm⟩ => zero_of_epi_comp p (by simp [comm]), fun hf =>
⟨biprod f.1 Q, biprod.fst, biprod.snd, inferInstance, inferInstance, by
rw [hf, Over.coe_hom, HasZeroMorphisms.comp_zero, HasZeroMorphisms.comp_zero]⟩⟩
end
theorem zero_eq_zero' {P Q R : C} :
(⟦((0 : Q ⟶ P) : Over P)⟧ : Pseudoelement P) = ⟦((0 : R ⟶ P) : Over P)⟧ :=
Quotient.sound <| (pseudoZero_aux R _).2 rfl
/-- The zero pseudoelement is the class of a zero morphism. -/
def pseudoZero {P : C} : P :=
⟦(0 : P ⟶ P)⟧
-- Porting note: in mathlib3, we couldn't make this an instance
-- as it would have fired on `coe_sort`.
-- However now that coercions are treated differently, this is a structural instance triggered by
-- the appearance of `Pseudoelement`.
instance hasZero {P : C} : Zero P :=
⟨pseudoZero⟩
instance {P : C} : Inhabited P :=
⟨0⟩
theorem pseudoZero_def {P : C} : (0 : Pseudoelement P) = ⟦↑(0 : P ⟶ P)⟧ := rfl
@[simp]
theorem zero_eq_zero {P Q : C} : ⟦((0 : Q ⟶ P) : Over P)⟧ = (0 : Pseudoelement P) :=
zero_eq_zero'
/-- The pseudoelement induced by an arrow is zero precisely when that arrow is zero. -/
theorem pseudoZero_iff {P : C} (a : Over P) : a = (0 : P) ↔ a.hom = 0 := by
rw [← pseudoZero_aux P a]
exact Quotient.eq'
end Zero
open Pseudoelement
/-- Morphisms map the zero pseudoelement to the zero pseudoelement. -/
@[simp]
theorem apply_zero {P Q : C} (f : P ⟶ Q) : f 0 = 0 := by
rw [pseudoZero_def, pseudoApply_mk']
simp
/-- The zero morphism maps every pseudoelement to 0. -/
@[simp]
theorem zero_apply {P : C} (Q : C) (a : P) : (0 : P ⟶ Q) a = 0 :=
Quotient.inductionOn a fun a' => by
rw [pseudoZero_def, pseudoApply_mk']
simp
/-- An extensionality lemma for being the zero arrow. -/
theorem zero_morphism_ext {P Q : C} (f : P ⟶ Q) : (∀ a, f a = 0) → f = 0 := fun h => by
rw [← Category.id_comp f]
exact (pseudoZero_iff (𝟙 P ≫ f : Over Q)).1 (h (𝟙 P))
theorem zero_morphism_ext' {P Q : C} (f : P ⟶ Q) : (∀ a, f a = 0) → 0 = f :=
Eq.symm ∘ zero_morphism_ext f
-- Porting note: these are no longer valid as `ext` lemmas.
-- scoped[Pseudoelement]
-- attribute [ext]
-- CategoryTheory.Abelian.Pseudoelement.zero_morphism_ext
-- CategoryTheory.Abelian.Pseudoelement.zero_morphism_ext'
theorem eq_zero_iff {P Q : C} (f : P ⟶ Q) : f = 0 ↔ ∀ a, f a = 0 :=
⟨fun h a => by simp [h], zero_morphism_ext _⟩
/-- A monomorphism is injective on pseudoelements. -/
theorem pseudo_injective_of_mono {P Q : C} (f : P ⟶ Q) [Mono f] : Function.Injective f := by
intro abar abar'
refine Quotient.inductionOn₂ abar abar' fun a a' ha => ?_
apply Quotient.sound
have : (⟦(a.hom ≫ f : Over Q)⟧ : Quotient (setoid Q)) = ⟦↑(a'.hom ≫ f)⟧ := by convert ha
have ⟨R, p, q, ep, Eq, comm⟩ := Quotient.exact this
exact ⟨R, p, q, ep, Eq, (cancel_mono f).1 <| by
simp only [Category.assoc]
exact comm⟩
/-- A morphism that is injective on pseudoelements only maps the zero element to zero. -/
theorem zero_of_map_zero {P Q : C} (f : P ⟶ Q) : Function.Injective f → ∀ a, f a = 0 → a = 0 :=
fun h a ha => by
rw [← apply_zero f] at ha
exact h ha
/-- A morphism that only maps the zero pseudoelement to zero is a monomorphism. -/
theorem mono_of_zero_of_map_zero {P Q : C} (f : P ⟶ Q) : (∀ a, f a = 0 → a = 0) → Mono f :=
fun h => (mono_iff_cancel_zero _).2 fun _ g hg =>
(pseudoZero_iff (g : Over P)).1 <|
h _ <| show f g = 0 from (pseudoZero_iff (g ≫ f : Over Q)).2 hg
section
/-- An epimorphism is surjective on pseudoelements. -/
theorem pseudo_surjective_of_epi {P Q : C} (f : P ⟶ Q) [Epi f] : Function.Surjective f :=
fun qbar =>
Quotient.inductionOn qbar fun q =>
⟨(pullback.fst f q.hom : Over P),
Quotient.sound <|
⟨pullback f q.hom, 𝟙 (pullback f q.hom), pullback.snd _ _, inferInstance, inferInstance, by
rw [Category.id_comp, ← pullback.condition, app_hom, Over.coe_hom]⟩⟩
end
/-- A morphism that is surjective on pseudoelements is an epimorphism. -/
theorem epi_of_pseudo_surjective {P Q : C} (f : P ⟶ Q) : Function.Surjective f → Epi f := by
intro h
have ⟨pbar, hpbar⟩ := h (𝟙 Q)
have ⟨p, hp⟩ := Quotient.exists_rep pbar
have : (⟦(p.hom ≫ f : Over Q)⟧ : Quotient (setoid Q)) = ⟦↑(𝟙 Q)⟧ := by
rw [← hp] at hpbar
exact hpbar
have ⟨R, x, y, _, ey, comm⟩ := Quotient.exact this
apply @epi_of_epi_fac _ _ _ _ _ (x ≫ p.hom) f y ey
dsimp at comm
rw [Category.assoc, comm]
apply Category.comp_id
section
/-- Two morphisms in an exact sequence are exact on pseudoelements. -/
theorem pseudo_exact_of_exact {S : ShortComplex C} (hS : S.Exact) :
∀ b, S.g b = 0 → ∃ a, S.f a = b :=
fun b' =>
Quotient.inductionOn b' fun b hb => by
have hb' : b.hom ≫ S.g = 0 := (pseudoZero_iff _).1 hb
-- By exactness, `b` factors through `im f = ker g` via some `c`.
obtain ⟨c, hc⟩ := KernelFork.IsLimit.lift' hS.isLimitImage _ hb'
-- We compute the pullback of the map into the image and `c`.
-- The pseudoelement induced by the first pullback map will be our preimage.
use pullback.fst (Abelian.factorThruImage S.f) c
-- It remains to show that the image of this element under `f` is pseudo-equal to `b`.
apply Quotient.sound
refine ⟨pullback (Abelian.factorThruImage S.f) c, 𝟙 _,
pullback.snd _ _, inferInstance, inferInstance, ?_⟩
-- Now we can verify that the diagram commutes.
calc
𝟙 (pullback (Abelian.factorThruImage S.f) c) ≫ pullback.fst _ _ ≫ S.f =
pullback.fst _ _ ≫ S.f :=
Category.id_comp _
_ = pullback.fst _ _ ≫ Abelian.factorThruImage S.f ≫ kernel.ι (cokernel.π S.f) := by
rw [Abelian.image.fac]
_ = (pullback.snd _ _ ≫ c) ≫ kernel.ι (cokernel.π S.f) := by
rw [← Category.assoc, pullback.condition]
_ = pullback.snd _ _ ≫ b.hom := by
rw [Category.assoc]
congr
end
theorem apply_eq_zero_of_comp_eq_zero {P Q R : C} (f : Q ⟶ R) (a : P ⟶ Q) : a ≫ f = 0 → f a = 0 :=
fun h => by simp [over_coe_def, pseudoApply_mk', Over.coe_hom, h]
section
/-- If two morphisms are exact on pseudoelements, they are exact. -/
theorem exact_of_pseudo_exact (S : ShortComplex C)
(hS : ∀ b, S.g b = 0 → ∃ a, S.f a = b) : S.Exact :=
(S.exact_iff_kernel_ι_comp_cokernel_π_zero).2 (by
-- If we apply `g` to the pseudoelement induced by its kernel, we get 0 (of course!).
have : S.g (kernel.ι S.g) = 0 := apply_eq_zero_of_comp_eq_zero _ _ (kernel.condition _)
-- By pseudo-exactness, we get a preimage.
obtain ⟨a', ha⟩ := hS _ this
obtain ⟨a, ha'⟩ := Quotient.exists_rep a'
rw [← ha'] at ha
obtain ⟨Z, r, q, _, eq, comm⟩ := Quotient.exact ha
-- Consider the pullback of `kernel.ι (cokernel.π f)` and `kernel.ι g`.
-- The commutative diagram given by the pseudo-equality `f a = b` induces
-- a cone over this pullback, so we get a factorization `z`.
obtain ⟨z, _, hz₂⟩ := @pullback.lift' _ _ _ _ _ _ (kernel.ι (cokernel.π S.f))
(kernel.ι S.g) _ (r ≫ a.hom ≫ Abelian.factorThruImage S.f) q (by
simp only [Category.assoc, Abelian.image.fac]
exact comm)
-- Let's give a name to the second pullback morphism.
let j : pullback (kernel.ι (cokernel.π S.f)) (kernel.ι S.g) ⟶ kernel S.g := pullback.snd _ _
-- Since `q` is an epimorphism, in particular this means that `j` is an epimorphism.
haveI pe : Epi j := epi_of_epi_fac hz₂
-- But it is also a monomorphism, because `kernel.ι (cokernel.π f)` is: A kernel is
-- always a monomorphism and the pullback of a monomorphism is a monomorphism.
-- But mono + epi = iso, so `j` is an isomorphism.
haveI : IsIso j := isIso_of_mono_of_epi _
-- But then `kernel.ι g` can be expressed using all of the maps of the pullback square, and we
-- are done.
rw [(Iso.eq_inv_comp (asIso j)).2 pullback.condition.symm]
simp only [Category.assoc, kernel.condition, HasZeroMorphisms.comp_zero])
end
/-- If two pseudoelements `x` and `y` have the same image under some morphism `f`, then we can form
their "difference" `z`. This pseudoelement has the properties that `f z = 0` and for all
morphisms `g`, if `g y = 0` then `g z = g x`. -/
theorem sub_of_eq_image {P Q : C} (f : P ⟶ Q) (x y : P) :
f x = f y → ∃ z, f z = 0 ∧ ∀ (R : C) (g : P ⟶ R), (g : P ⟶ R) y = 0 → g z = g x :=
Quotient.inductionOn₂ x y fun a a' h =>
match Quotient.exact h with
| ⟨R, p, q, ep, _, comm⟩ =>
let a'' : R ⟶ P := ↑(p ≫ a.hom) - ↑(q ≫ a'.hom)
⟨a'',
⟨show ⟦(a'' ≫ f : Over Q)⟧ = ⟦↑(0 : Q ⟶ Q)⟧ by
dsimp at comm
simp [a'', sub_eq_zero.2 comm],
fun Z g hh => by
obtain ⟨X, p', q', ep', _, comm'⟩ := Quotient.exact hh
have : a'.hom ≫ g = 0 := by
apply (epi_iff_cancel_zero _).1 ep' _ (a'.hom ≫ g)
simpa using comm'
apply Quotient.sound
-- Can we prevent quotient.sound from giving us this weird `coe_b` thingy?
change app g (a'' : Over P) ≈ app g a
exact ⟨R, 𝟙 R, p, inferInstance, ep, by simp [a'', sub_eq_add_neg, this]⟩⟩⟩
variable [Limits.HasPullbacks C]
/-- If `f : P ⟶ R` and `g : Q ⟶ R` are morphisms and `p : P` and `q : Q` are pseudoelements such
that `f p = g q`, then there is some `s : pullback f g` such that `fst s = p` and `snd s = q`.
Remark: Borceux claims that `s` is unique, but this is false. See
`Counterexamples/Pseudoelement.lean` for details. -/
theorem pseudo_pullback {P Q R : C} {f : P ⟶ R} {g : Q ⟶ R} {p : P} {q : Q} :
f p = g q →
∃ s, pullback.fst f g s = p ∧ pullback.snd f g s = q :=
Quotient.inductionOn₂ p q fun x y h => by
obtain ⟨Z, a, b, ea, eb, comm⟩ := Quotient.exact h
obtain ⟨l, hl₁, hl₂⟩ := @pullback.lift' _ _ _ _ _ _ f g _ (a ≫ x.hom) (b ≫ y.hom) (by
simp only [Category.assoc]
exact comm)
exact ⟨l, ⟨Quotient.sound ⟨Z, 𝟙 Z, a, inferInstance, ea, by rwa [Category.id_comp]⟩,
Quotient.sound ⟨Z, 𝟙 Z, b, inferInstance, eb, by rwa [Category.id_comp]⟩⟩⟩
section Module
/-- In the category `Module R`, if `x` and `y` are pseudoequal, then the range of the associated
morphisms is the same. -/
theorem ModuleCat.eq_range_of_pseudoequal {R : Type*} [CommRing R] {G : ModuleCat R} {x y : Over G}
(h : PseudoEqual G x y) : LinearMap.range x.hom = LinearMap.range y.hom := by
obtain ⟨P, p, q, hp, hq, H⟩ := h
refine Submodule.ext fun a => ⟨fun ha => ?_, fun ha => ?_⟩
· obtain ⟨a', ha'⟩ := ha
obtain ⟨a'', ha''⟩ := (ModuleCat.epi_iff_surjective p).1 hp a'
refine ⟨q a'', ?_⟩
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [← LinearMap.comp_apply, ← ModuleCat.comp_def, ← H,
ModuleCat.comp_def, LinearMap.comp_apply, ha'', ha']
· obtain ⟨a', ha'⟩ := ha
obtain ⟨a'', ha''⟩ := (ModuleCat.epi_iff_surjective q).1 hq a'
refine ⟨p a'', ?_⟩
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [← LinearMap.comp_apply, ← ModuleCat.comp_def, H, ModuleCat.comp_def, LinearMap.comp_apply,
ha'', ha']
end Module
end Pseudoelement
end CategoryTheory.Abelian
|
CategoryTheory\Abelian\Refinements.lean | /-
Copyright (c) 2023 Joël Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joël Riou
-/
import Mathlib.Algebra.Homology.ShortComplex.Exact
/-!
# Refinements
In order to prove injectivity/surjectivity/exactness properties for diagrams
in the category of abelian groups, we often need to do diagram chases.
Some of these can be carried out in more general abelian categories:
for example, a morphism `X ⟶ Y` in an abelian category `C` is a
monomorphism if and only if for all `A : C`, the induced map
`(A ⟶ X) → (A ⟶ Y)` of abelian groups is a monomorphism, i.e. injective.
Alternatively, the yoneda presheaf functor which sends `X` to the
presheaf of maps `A ⟶ X` for all `A : C` preserves and reflects
monomorphisms.
However, if `p : X ⟶ Y` is an epimorphism in `C` and `A : C`,
`(A ⟶ X) → (A ⟶ Y)` may fail to be surjective (unless `p` is a split
epimorphism).
In this file, the basic result is `epi_iff_surjective_up_to_refinements`
which states that `f : X ⟶ Y` is a morphism in an abelian category,
then it is an epimorphism if and only if for all `y : A ⟶ Y`,
there exists an epimorphism `π : A' ⟶ A` and `x : A' ⟶ X` such
that `π ≫ y = x ≫ f`. In order words, if we allow a precomposition
with an epimorphism, we may lift a morphism to `Y` to a morphism to `X`.
Following unpublished notes by George Bergman, we shall say that the
precomposition by an epimorphism `π ≫ y` is a refinement of `y`. Then,
we get that an epimorphism is a morphism that is "surjective up to refinements".
(This result is similar to the fact that a morphism of sheaves on
a topological space or a site is epi iff sections can be lifted
locally. Then, arguing "up to refinements" is very similar to
arguing locally for a Grothendieck topology (TODO: indeed,
show that it corresponds to the "refinements" topology on an
abelian category `C` that is defined by saying that
a sieve is covering if it contains an epimorphism).
Similarly, it is possible to show that a short complex in an abelian
category is exact if and only if it is exact up to refinements
(see `ShortComplex.exact_iff_exact_up_to_refinements`).
As it is outlined in the documentation of the file
`CategoryTheory.Abelian.Pseudoelements`, the Freyd-Mitchell
embedding theorem implies the existence of a faithful and exact functor `ι`
from an abelian category `C` to the category of abelian groups. If we
define a pseudo-element of `X : C` to be an element in `ι.obj X`, one
may do diagram chases in any abelian category using these pseudo-elements.
However, using this approach would require proving this embedding theorem!
Currently, mathlib contains a weaker notion of pseudo-elements
`CategoryTheory.Abelian.Pseudoelements`. Some theorems can be obtained
using this notion, but there is the issue that for this notion
of pseudo-elements a morphism `X ⟶ Y` in `C` is not determined by
its action on pseudo-elements (see also `Counterexamples/Pseudoelement`).
On the contrary, the approach consisting of working up to refinements
does not require the introduction of other types: we only need to work
with morphisms `A ⟶ X` in `C` which we may consider as being
"sort of elements of `X`". One may carry diagram-chasing by tracking
these morphisms and sometimes introducing an auxiliary epimorphism `A' ⟶ A`.
## References
* George Bergman, A note on abelian categories – translating element-chasing proofs,
and exact embedding in abelian groups (1974)
http://math.berkeley.edu/~gbergman/papers/unpub/elem-chase.pdf
-/
namespace CategoryTheory
open Category Limits
variable {C : Type _} [Category C] [Abelian C] {X Y : C} (S : ShortComplex C)
{S₁ S₂ : ShortComplex C}
lemma epi_iff_surjective_up_to_refinements (f : X ⟶ Y) :
Epi f ↔ ∀ ⦃A : C⦄ (y : A ⟶ Y),
∃ (A' : C) (π : A' ⟶ A) (_ : Epi π) (x : A' ⟶ X), π ≫ y = x ≫ f := by
constructor
· intro _ A a
exact ⟨pullback a f, pullback.fst a f, inferInstance, pullback.snd a f, pullback.condition⟩
· intro hf
obtain ⟨A, π, hπ, a', fac⟩ := hf (𝟙 Y)
rw [comp_id] at fac
exact epi_of_epi_fac fac.symm
lemma surjective_up_to_refinements_of_epi (f : X ⟶ Y) [Epi f] {A : C} (y : A ⟶ Y) :
∃ (A' : C) (π : A' ⟶ A) (_ : Epi π) (x : A' ⟶ X), π ≫ y = x ≫ f :=
(epi_iff_surjective_up_to_refinements f).1 inferInstance y
lemma ShortComplex.exact_iff_exact_up_to_refinements :
S.Exact ↔ ∀ ⦃A : C⦄ (x₂ : A ⟶ S.X₂) (_ : x₂ ≫ S.g = 0),
∃ (A' : C) (π : A' ⟶ A) (_ : Epi π) (x₁ : A' ⟶ S.X₁), π ≫ x₂ = x₁ ≫ S.f := by
rw [S.exact_iff_epi_toCycles, epi_iff_surjective_up_to_refinements]
constructor
· intro hS A a ha
obtain ⟨A', π, hπ, x₁, fac⟩ := hS (S.liftCycles a ha)
exact ⟨A', π, hπ, x₁, by simpa only [assoc, liftCycles_i, toCycles_i] using fac =≫ S.iCycles⟩
· intro hS A a
obtain ⟨A', π, hπ, x₁, fac⟩ := hS (a ≫ S.iCycles) (by simp)
exact ⟨A', π, hπ, x₁, by simp only [← cancel_mono S.iCycles, assoc, toCycles_i, fac]⟩
variable {S}
lemma ShortComplex.Exact.exact_up_to_refinements
(hS : S.Exact) {A : C} (x₂ : A ⟶ S.X₂) (hx₂ : x₂ ≫ S.g = 0) :
∃ (A' : C) (π : A' ⟶ A) (_ : Epi π) (x₁ : A' ⟶ S.X₁), π ≫ x₂ = x₁ ≫ S.f := by
rw [ShortComplex.exact_iff_exact_up_to_refinements] at hS
exact hS x₂ hx₂
lemma ShortComplex.eq_liftCycles_homologyπ_up_to_refinements {A : C} (γ : A ⟶ S.homology) :
∃ (A' : C) (π : A' ⟶ A) (_ : Epi π) (z : A' ⟶ S.X₂) (hz : z ≫ S.g = 0),
π ≫ γ = S.liftCycles z hz ≫ S.homologyπ := by
obtain ⟨A', π, hπ, z, hz⟩ := surjective_up_to_refinements_of_epi S.homologyπ γ
refine ⟨A', π, hπ, z ≫ S.iCycles, by simp, ?_⟩
rw [hz]
congr 1
rw [← cancel_mono S.iCycles, liftCycles_i]
end CategoryTheory
|
CategoryTheory\Abelian\RightDerived.lean | /-
Copyright (c) 2022 Jujian Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jujian Zhang, Scott Morrison, Joël Riou
-/
import Mathlib.Algebra.Homology.Additive
import Mathlib.CategoryTheory.Abelian.InjectiveResolution
/-!
# Right-derived functors
We define the right-derived functors `F.rightDerived n : C ⥤ D` for any additive functor `F`
out of a category with injective resolutions.
We first define a functor
`F.rightDerivedToHomotopyCategory : C ⥤ HomotopyCategory D (ComplexShape.up ℕ)` which is
`injectiveResolutions C ⋙ F.mapHomotopyCategory _`. We show that if `X : C` and
`I : InjectiveResolution X`, then `F.rightDerivedToHomotopyCategory.obj X` identifies
to the image in the homotopy category of the functor `F` applied objectwise to `I.cocomplex`
(this isomorphism is `I.isoRightDerivedToHomotopyCategoryObj F`).
Then, the right-derived functors `F.rightDerived n : C ⥤ D` are obtained by composing
`F.rightDerivedToHomotopyCategory` with the homology functors on the homotopy category.
Similarly we define natural transformations between right-derived functors coming from
natural transformations between the original additive functors,
and show how to compute the components.
## Main results
* `Functor.isZero_rightDerived_obj_injective_succ`: injective objects have no higher
right derived functor.
* `NatTrans.rightDerived`: the natural isomorphism between right derived functors
induced by natural transformation.
* `Functor.toRightDerivedZero`: the natural transformation `F ⟶ F.rightDerived 0`,
which is an isomorphism when `F` is left exact (i.e. preserves finite limits),
see also `Functor.rightDerivedZeroIsoSelf`.
## TODO
* refactor `Functor.rightDerived` (and `Functor.leftDerived`) when the necessary
material enters mathlib: derived categories, injective/projective derivability
structures, existence of derived functors from derivability structures.
Eventually, we shall get a right derived functor
`F.rightDerivedFunctorPlus : DerivedCategory.Plus C ⥤ DerivedCategory.Plus D`,
and `F.rightDerived` shall be redefined using `F.rightDerivedFunctorPlus`.
-/
universe v u
namespace CategoryTheory
open Category Limits
variable {C : Type u} [Category.{v} C] {D : Type*} [Category D]
[Abelian C] [HasInjectiveResolutions C] [Abelian D]
/-- When `F : C ⥤ D` is an additive functor, this is
the functor `C ⥤ HomotopyCategory D (ComplexShape.up ℕ)` which
sends `X : C` to `F` applied to an injective resolution of `X`. -/
noncomputable def Functor.rightDerivedToHomotopyCategory (F : C ⥤ D) [F.Additive] :
C ⥤ HomotopyCategory D (ComplexShape.up ℕ) :=
injectiveResolutions C ⋙ F.mapHomotopyCategory _
/-- If `I : InjectiveResolution Z` and `F : C ⥤ D` is an additive functor, this is
an isomorphism between `F.rightDerivedToHomotopyCategory.obj X` and the complex
obtained by applying `F` to `I.cocomplex`. -/
noncomputable def InjectiveResolution.isoRightDerivedToHomotopyCategoryObj {X : C}
(I : InjectiveResolution X) (F : C ⥤ D) [F.Additive] :
F.rightDerivedToHomotopyCategory.obj X ≅
(F.mapHomologicalComplex _ ⋙ HomotopyCategory.quotient _ _).obj I.cocomplex :=
(F.mapHomotopyCategory _).mapIso I.iso ≪≫
(F.mapHomotopyCategoryFactors _).app I.cocomplex
@[reassoc]
lemma InjectiveResolution.isoRightDerivedToHomotopyCategoryObj_hom_naturality
{X Y : C} (f : X ⟶ Y) (I : InjectiveResolution X) (J : InjectiveResolution Y)
(φ : I.cocomplex ⟶ J.cocomplex) (comm : I.ι.f 0 ≫ φ.f 0 = f ≫ J.ι.f 0)
(F : C ⥤ D) [F.Additive] :
F.rightDerivedToHomotopyCategory.map f ≫ (J.isoRightDerivedToHomotopyCategoryObj F).hom =
(I.isoRightDerivedToHomotopyCategoryObj F).hom ≫
(F.mapHomologicalComplex _ ⋙ HomotopyCategory.quotient _ _).map φ := by
dsimp [Functor.rightDerivedToHomotopyCategory, isoRightDerivedToHomotopyCategoryObj]
rw [← Functor.map_comp_assoc, iso_hom_naturality f I J φ comm, Functor.map_comp,
assoc, assoc]
erw [(F.mapHomotopyCategoryFactors (ComplexShape.up ℕ)).hom.naturality]
rfl
@[reassoc]
lemma InjectiveResolution.isoRightDerivedToHomotopyCategoryObj_inv_naturality
{X Y : C} (f : X ⟶ Y) (I : InjectiveResolution X) (J : InjectiveResolution Y)
(φ : I.cocomplex ⟶ J.cocomplex) (comm : I.ι.f 0 ≫ φ.f 0 = f ≫ J.ι.f 0)
(F : C ⥤ D) [F.Additive] :
(I.isoRightDerivedToHomotopyCategoryObj F).inv ≫ F.rightDerivedToHomotopyCategory.map f =
(F.mapHomologicalComplex _ ⋙ HomotopyCategory.quotient _ _).map φ ≫
(J.isoRightDerivedToHomotopyCategoryObj F).inv := by
rw [← cancel_epi (I.isoRightDerivedToHomotopyCategoryObj F).hom, Iso.hom_inv_id_assoc]
dsimp
rw [← isoRightDerivedToHomotopyCategoryObj_hom_naturality_assoc f I J φ comm F,
Iso.hom_inv_id, comp_id]
/-- The right derived functors of an additive functor. -/
noncomputable def Functor.rightDerived (F : C ⥤ D) [F.Additive] (n : ℕ) : C ⥤ D :=
F.rightDerivedToHomotopyCategory ⋙ HomotopyCategory.homologyFunctor D _ n
/-- We can compute a right derived functor using a chosen injective resolution. -/
noncomputable def InjectiveResolution.isoRightDerivedObj {X : C} (I : InjectiveResolution X)
(F : C ⥤ D) [F.Additive] (n : ℕ) :
(F.rightDerived n).obj X ≅
(HomologicalComplex.homologyFunctor D _ n).obj
((F.mapHomologicalComplex _).obj I.cocomplex) :=
(HomotopyCategory.homologyFunctor D _ n).mapIso
(I.isoRightDerivedToHomotopyCategoryObj F) ≪≫
(HomotopyCategory.homologyFunctorFactors D (ComplexShape.up ℕ) n).app _
@[reassoc]
lemma InjectiveResolution.isoRightDerivedObj_hom_naturality
{X Y : C} (f : X ⟶ Y) (I : InjectiveResolution X) (J : InjectiveResolution Y)
(φ : I.cocomplex ⟶ J.cocomplex) (comm : I.ι.f 0 ≫ φ.f 0 = f ≫ J.ι.f 0)
(F : C ⥤ D) [F.Additive] (n : ℕ) :
(F.rightDerived n).map f ≫ (J.isoRightDerivedObj F n).hom =
(I.isoRightDerivedObj F n).hom ≫
(F.mapHomologicalComplex _ ⋙ HomologicalComplex.homologyFunctor _ _ n).map φ := by
dsimp [isoRightDerivedObj, Functor.rightDerived]
rw [assoc, ← Functor.map_comp_assoc,
InjectiveResolution.isoRightDerivedToHomotopyCategoryObj_hom_naturality f I J φ comm F,
Functor.map_comp, assoc]
erw [(HomotopyCategory.homologyFunctorFactors D (ComplexShape.up ℕ) n).hom.naturality]
rfl
@[reassoc]
lemma InjectiveResolution.isoRightDerivedObj_inv_naturality
{X Y : C} (f : X ⟶ Y) (I : InjectiveResolution X) (J : InjectiveResolution Y)
(φ : I.cocomplex ⟶ J.cocomplex) (comm : I.ι.f 0 ≫ φ.f 0 = f ≫ J.ι.f 0)
(F : C ⥤ D) [F.Additive] (n : ℕ) :
(I.isoRightDerivedObj F n).inv ≫ (F.rightDerived n).map f =
(F.mapHomologicalComplex _ ⋙ HomologicalComplex.homologyFunctor _ _ n).map φ ≫
(J.isoRightDerivedObj F n).inv := by
rw [← cancel_mono (J.isoRightDerivedObj F n).hom, assoc, assoc,
InjectiveResolution.isoRightDerivedObj_hom_naturality f I J φ comm F n,
Iso.inv_hom_id_assoc, Iso.inv_hom_id, comp_id]
/-- The higher derived functors vanish on injective objects. -/
lemma Functor.isZero_rightDerived_obj_injective_succ
(F : C ⥤ D) [F.Additive] (n : ℕ) (X : C) [Injective X] :
IsZero ((F.rightDerived (n+1)).obj X) := by
refine IsZero.of_iso ?_ ((InjectiveResolution.self X).isoRightDerivedObj F (n + 1))
erw [← HomologicalComplex.exactAt_iff_isZero_homology]
exact ShortComplex.exact_of_isZero_X₂ _ (F.map_isZero (by apply isZero_zero))
/-- We can compute a right derived functor on a morphism using a descent of that morphism
to a cochain map between chosen injective resolutions.
-/
theorem Functor.rightDerived_map_eq (F : C ⥤ D) [F.Additive] (n : ℕ) {X Y : C} (f : X ⟶ Y)
{P : InjectiveResolution X} {Q : InjectiveResolution Y} (g : P.cocomplex ⟶ Q.cocomplex)
(w : P.ι ≫ g = (CochainComplex.single₀ C).map f ≫ Q.ι) :
(F.rightDerived n).map f =
(P.isoRightDerivedObj F n).hom ≫
(F.mapHomologicalComplex _ ⋙ HomologicalComplex.homologyFunctor _ _ n).map g ≫
(Q.isoRightDerivedObj F n).inv := by
rw [← cancel_mono (Q.isoRightDerivedObj F n).hom,
InjectiveResolution.isoRightDerivedObj_hom_naturality f P Q g _ F n,
assoc, assoc, Iso.inv_hom_id, comp_id]
rw [← HomologicalComplex.comp_f, w, HomologicalComplex.comp_f,
CochainComplex.single₀_map_f_zero]
/-- The natural transformation
`F.rightDerivedToHomotopyCategory ⟶ G.rightDerivedToHomotopyCategory` induced by
a natural transformation `F ⟶ G` between additive functors. -/
noncomputable def NatTrans.rightDerivedToHomotopyCategory
{F G : C ⥤ D} [F.Additive] [G.Additive] (α : F ⟶ G) :
F.rightDerivedToHomotopyCategory ⟶ G.rightDerivedToHomotopyCategory :=
whiskerLeft _ (NatTrans.mapHomotopyCategory α (ComplexShape.up ℕ))
lemma InjectiveResolution.rightDerivedToHomotopyCategory_app_eq
{F G : C ⥤ D} [F.Additive] [G.Additive] (α : F ⟶ G) {X : C} (P : InjectiveResolution X) :
(NatTrans.rightDerivedToHomotopyCategory α).app X =
(P.isoRightDerivedToHomotopyCategoryObj F).hom ≫
(HomotopyCategory.quotient _ _).map
((NatTrans.mapHomologicalComplex α _).app P.cocomplex) ≫
(P.isoRightDerivedToHomotopyCategoryObj G).inv := by
rw [← cancel_mono (P.isoRightDerivedToHomotopyCategoryObj G).hom, assoc, assoc,
Iso.inv_hom_id, comp_id]
dsimp [isoRightDerivedToHomotopyCategoryObj, Functor.mapHomotopyCategoryFactors,
NatTrans.rightDerivedToHomotopyCategory]
rw [assoc]
erw [id_comp, comp_id]
obtain ⟨β, hβ⟩ := (HomotopyCategory.quotient _ _).map_surjective (iso P).hom
rw [← hβ]
dsimp
simp only [← Functor.map_comp, NatTrans.mapHomologicalComplex_naturality]
rfl
@[simp]
lemma NatTrans.rightDerivedToHomotopyCategory_id (F : C ⥤ D) [F.Additive] :
NatTrans.rightDerivedToHomotopyCategory (𝟙 F) = 𝟙 _ := rfl
@[simp, reassoc]
lemma NatTrans.rightDerivedToHomotopyCategory_comp {F G H : C ⥤ D} (α : F ⟶ G) (β : G ⟶ H)
[F.Additive] [G.Additive] [H.Additive] :
NatTrans.rightDerivedToHomotopyCategory (α ≫ β) =
NatTrans.rightDerivedToHomotopyCategory α ≫
NatTrans.rightDerivedToHomotopyCategory β := rfl
/-- The natural transformation between right-derived functors
induced by a natural transformation. -/
noncomputable def NatTrans.rightDerived
{F G : C ⥤ D} [F.Additive] [G.Additive] (α : F ⟶ G) (n : ℕ) :
F.rightDerived n ⟶ G.rightDerived n :=
whiskerRight (NatTrans.rightDerivedToHomotopyCategory α) _
@[simp]
theorem NatTrans.rightDerived_id (F : C ⥤ D) [F.Additive] (n : ℕ) :
NatTrans.rightDerived (𝟙 F) n = 𝟙 (F.rightDerived n) := by
dsimp only [rightDerived]
simp only [rightDerivedToHomotopyCategory_id, whiskerRight_id']
rfl
@[simp, reassoc]
theorem NatTrans.rightDerived_comp {F G H : C ⥤ D} [F.Additive] [G.Additive] [H.Additive]
(α : F ⟶ G) (β : G ⟶ H) (n : ℕ) :
NatTrans.rightDerived (α ≫ β) n = NatTrans.rightDerived α n ≫ NatTrans.rightDerived β n := by
simp [NatTrans.rightDerived]
namespace InjectiveResolution
/-- A component of the natural transformation between right-derived functors can be computed
using a chosen injective resolution. -/
lemma rightDerived_app_eq
{F G : C ⥤ D} [F.Additive] [G.Additive] (α : F ⟶ G) {X : C} (P : InjectiveResolution X)
(n : ℕ) : (NatTrans.rightDerived α n).app X =
(P.isoRightDerivedObj F n).hom ≫
(HomologicalComplex.homologyFunctor D (ComplexShape.up ℕ) n).map
((NatTrans.mapHomologicalComplex α _).app P.cocomplex) ≫
(P.isoRightDerivedObj G n).inv := by
dsimp [NatTrans.rightDerived, isoRightDerivedObj]
rw [InjectiveResolution.rightDerivedToHomotopyCategory_app_eq α P,
Functor.map_comp, Functor.map_comp, assoc]
erw [← (HomotopyCategory.homologyFunctorFactors D (ComplexShape.up ℕ) n).hom.naturality_assoc
((NatTrans.mapHomologicalComplex α (ComplexShape.up ℕ)).app P.cocomplex)]
simp only [Functor.comp_map, Iso.hom_inv_id_app_assoc]
/-- If `P : InjectiveResolution X` and `F` is an additive functor, this is
the canonical morphism from `F.obj X` to the cycles in degree `0` of
`(F.mapHomologicalComplex _).obj P.cocomplex`. -/
noncomputable def toRightDerivedZero' {X : C}
(P : InjectiveResolution X) (F : C ⥤ D) [F.Additive] :
F.obj X ⟶ ((F.mapHomologicalComplex _).obj P.cocomplex).cycles 0 :=
HomologicalComplex.liftCycles _ (F.map (P.ι.f 0)) 1 (by simp) (by
dsimp
rw [← F.map_comp, HomologicalComplex.Hom.comm, HomologicalComplex.single_obj_d,
zero_comp, F.map_zero])
@[reassoc (attr := simp)]
lemma toRightDerivedZero'_comp_iCycles {C} [Category C] [Abelian C] {X : C}
(P : InjectiveResolution X) (F : C ⥤ D) [F.Additive] :
P.toRightDerivedZero' F ≫
HomologicalComplex.iCycles _ _ = F.map (P.ι.f 0) := by
simp [toRightDerivedZero']
@[reassoc]
lemma toRightDerivedZero'_naturality {C} [Category C] [Abelian C] {X Y : C} (f : X ⟶ Y)
(P : InjectiveResolution X) (Q : InjectiveResolution Y)
(φ : P.cocomplex ⟶ Q.cocomplex) (comm : P.ι.f 0 ≫ φ.f 0 = f ≫ Q.ι.f 0)
(F : C ⥤ D) [F.Additive] :
F.map f ≫ Q.toRightDerivedZero' F =
P.toRightDerivedZero' F ≫
HomologicalComplex.cyclesMap ((F.mapHomologicalComplex _).map φ) 0 := by
simp only [← cancel_mono (HomologicalComplex.iCycles _ _),
Functor.mapHomologicalComplex_obj_X, assoc, toRightDerivedZero'_comp_iCycles,
CochainComplex.single₀_obj_zero, HomologicalComplex.cyclesMap_i,
Functor.mapHomologicalComplex_map_f, toRightDerivedZero'_comp_iCycles_assoc,
← F.map_comp, comm]
instance (F : C ⥤ D) [F.Additive] (X : C) [Injective X] :
IsIso ((InjectiveResolution.self X).toRightDerivedZero' F) := by
dsimp [InjectiveResolution.toRightDerivedZero']
rw [CochainComplex.isIso_liftCycles_iff]
refine ⟨ShortComplex.Splitting.exact ?_, inferInstance⟩
exact
{ r := 𝟙 _
s := 0
s_g := (F.map_isZero (isZero_zero _)).eq_of_src _ _ }
end InjectiveResolution
/-- The natural transformation `F ⟶ F.rightDerived 0`. -/
noncomputable def Functor.toRightDerivedZero (F : C ⥤ D) [F.Additive] :
F ⟶ F.rightDerived 0 where
app X := (injectiveResolution X).toRightDerivedZero' F ≫
(CochainComplex.isoHomologyπ₀ _).hom ≫
(HomotopyCategory.homologyFunctorFactors D (ComplexShape.up ℕ) 0).inv.app _
naturality {X Y} f := by
dsimp [rightDerived]
rw [assoc, assoc, InjectiveResolution.toRightDerivedZero'_naturality_assoc f
(injectiveResolution X) (injectiveResolution Y)
(InjectiveResolution.desc f _ _) (by simp),
← HomologicalComplex.homologyπ_naturality_assoc]
erw [← NatTrans.naturality]
rfl
lemma InjectiveResolution.toRightDerivedZero_eq
{X : C} (I : InjectiveResolution X) (F : C ⥤ D) [F.Additive] :
F.toRightDerivedZero.app X = I.toRightDerivedZero' F ≫
(CochainComplex.isoHomologyπ₀ _).hom ≫ (I.isoRightDerivedObj F 0).inv := by
dsimp [Functor.toRightDerivedZero, isoRightDerivedObj]
have h₁ := InjectiveResolution.toRightDerivedZero'_naturality
(𝟙 X) (injectiveResolution X) I (desc (𝟙 X) _ _) (by simp) F
simp only [Functor.map_id, id_comp] at h₁
have h₂ : (I.isoRightDerivedToHomotopyCategoryObj F).hom =
(F.mapHomologicalComplex _ ⋙ HomotopyCategory.quotient _ _).map (desc (𝟙 X) _ _) :=
comp_id _
rw [← cancel_mono ((HomotopyCategory.homologyFunctor _ _ 0).map
(I.isoRightDerivedToHomotopyCategoryObj F).hom),
assoc, assoc, assoc, assoc, assoc, ← Functor.map_comp,
Iso.inv_hom_id, Functor.map_id, comp_id,
reassoc_of% h₁, h₂, ← HomologicalComplex.homologyπ_naturality_assoc]
erw [← NatTrans.naturality]
rfl
instance (F : C ⥤ D) [F.Additive] (X : C) [Injective X] :
IsIso (F.toRightDerivedZero.app X) := by
rw [(InjectiveResolution.self X).toRightDerivedZero_eq F]
infer_instance
section
variable (F : C ⥤ D) [F.Additive] [PreservesFiniteLimits F]
instance {X : C} (P : InjectiveResolution X) :
IsIso (P.toRightDerivedZero' F) := by
dsimp [InjectiveResolution.toRightDerivedZero']
rw [CochainComplex.isIso_liftCycles_iff, ShortComplex.exact_and_mono_f_iff_f_is_kernel]
exact ⟨KernelFork.mapIsLimit _ (P.isLimitKernelFork) F⟩
instance (X : C) : IsIso (F.toRightDerivedZero.app X) := by
dsimp [Functor.toRightDerivedZero]
infer_instance
instance : IsIso F.toRightDerivedZero :=
NatIso.isIso_of_isIso_app _
namespace Functor
/-- The canonical isomorphism `F.rightDerived 0 ≅ F` when `F` is left exact
(i.e. preserves finite limits). -/
@[simps! inv]
noncomputable def rightDerivedZeroIsoSelf : F.rightDerived 0 ≅ F :=
(asIso F.toRightDerivedZero).symm
@[reassoc (attr := simp)]
lemma rightDerivedZeroIsoSelf_hom_inv_id :
F.rightDerivedZeroIsoSelf.hom ≫ F.toRightDerivedZero = 𝟙 _ :=
F.rightDerivedZeroIsoSelf.hom_inv_id
@[reassoc (attr := simp)]
lemma rightDerivedZeroIsoSelf_inv_hom_id :
F.toRightDerivedZero ≫ F.rightDerivedZeroIsoSelf.hom = 𝟙 _ :=
F.rightDerivedZeroIsoSelf.inv_hom_id
@[reassoc (attr := simp)]
lemma rightDerivedZeroIsoSelf_hom_inv_id_app (X : C) :
F.rightDerivedZeroIsoSelf.hom.app X ≫ F.toRightDerivedZero.app X = 𝟙 _ :=
F.rightDerivedZeroIsoSelf.hom_inv_id_app X
@[reassoc (attr := simp)]
lemma rightDerivedZeroIsoSelf_inv_hom_id_app (X : C) :
F.toRightDerivedZero.app X ≫ F.rightDerivedZeroIsoSelf.hom.app X = 𝟙 _ :=
F.rightDerivedZeroIsoSelf.inv_hom_id_app X
end Functor
end
end CategoryTheory
|
CategoryTheory\Abelian\Subobject.lean | /-
Copyright (c) 2022 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.CategoryTheory.Subobject.Limits
import Mathlib.CategoryTheory.Abelian.Basic
/-!
# Equivalence between subobjects and quotients in an abelian category
-/
open CategoryTheory CategoryTheory.Limits Opposite
universe v u
noncomputable section
namespace CategoryTheory.Abelian
variable {C : Type u} [Category.{v} C]
/-- In an abelian category, the subobjects and quotient objects of an object `X` are
order-isomorphic via taking kernels and cokernels.
Implemented here using subobjects in the opposite category,
since mathlib does not have a notion of quotient objects at the time of writing. -/
@[simps!]
def subobjectIsoSubobjectOp [Abelian C] (X : C) : Subobject X ≃o (Subobject (op X))ᵒᵈ := by
refine OrderIso.ofHomInv (cokernelOrderHom X) (kernelOrderHom X) ?_ ?_
· change (cokernelOrderHom X).comp (kernelOrderHom X) = _
refine OrderHom.ext _ _ (funext (Subobject.ind _ ?_))
intro A f hf
dsimp only [OrderHom.comp_coe, Function.comp_apply, kernelOrderHom_coe, Subobject.lift_mk,
cokernelOrderHom_coe, OrderHom.id_coe, id]
refine Subobject.mk_eq_mk_of_comm _ _
⟨?_, ?_, Quiver.Hom.unop_inj ?_, Quiver.Hom.unop_inj ?_⟩ ?_
· exact (Abelian.epiDesc f.unop _ (cokernel.condition (kernel.ι f.unop))).op
· exact (cokernel.desc _ _ (kernel.condition f.unop)).op
· rw [← cancel_epi (cokernel.π (kernel.ι f.unop))]
simp only [unop_comp, Quiver.Hom.unop_op, unop_id_op, cokernel.π_desc_assoc,
comp_epiDesc, Category.comp_id]
· simp only [← cancel_epi f.unop, unop_comp, Quiver.Hom.unop_op, unop_id, comp_epiDesc_assoc,
cokernel.π_desc, Category.comp_id]
· exact Quiver.Hom.unop_inj (by simp only [unop_comp, Quiver.Hom.unop_op, comp_epiDesc])
· change (kernelOrderHom X).comp (cokernelOrderHom X) = _
refine OrderHom.ext _ _ (funext (Subobject.ind _ ?_))
intro A f hf
dsimp only [OrderHom.comp_coe, Function.comp_apply, cokernelOrderHom_coe, Subobject.lift_mk,
kernelOrderHom_coe, OrderHom.id_coe, id, unop_op, Quiver.Hom.unop_op]
refine Subobject.mk_eq_mk_of_comm _ _ ⟨?_, ?_, ?_, ?_⟩ ?_
· exact Abelian.monoLift f _ (kernel.condition (cokernel.π f))
· exact kernel.lift _ _ (cokernel.condition f)
· simp only [← cancel_mono (kernel.ι (cokernel.π f)), Category.assoc, image.fac, monoLift_comp,
Category.id_comp]
· simp only [← cancel_mono f, Category.assoc, monoLift_comp, image.fac, Category.id_comp]
· simp only [monoLift_comp]
/-- A well-powered abelian category is also well-copowered. -/
instance wellPowered_opposite [Abelian C] [WellPowered C] : WellPowered Cᵒᵖ where
subobject_small X :=
(small_congr (subobjectIsoSubobjectOp (unop X)).toEquiv).1 inferInstance
end CategoryTheory.Abelian
|
CategoryTheory\Abelian\Transfer.lean | /-
Copyright (c) 2022 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.CategoryTheory.Abelian.Basic
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Kernels
import Mathlib.CategoryTheory.Adjunction.Limits
/-!
# Transferring "abelian-ness" across a functor
If `C` is an additive category, `D` is an abelian category,
we have `F : C ⥤ D` `G : D ⥤ C` (both preserving zero morphisms),
`G` is left exact (that is, preserves finite limits),
and further we have `adj : G ⊣ F` and `i : F ⋙ G ≅ 𝟭 C`,
then `C` is also abelian.
See <https://stacks.math.columbia.edu/tag/03A3>
## Notes
The hypotheses, following the statement from the Stacks project,
may appear surprising: we don't ask that the counit of the adjunction is an isomorphism,
but just that we have some potentially unrelated isomorphism `i : F ⋙ G ≅ 𝟭 C`.
However Lemma A1.1.1 from [Elephant] shows that in this situation the counit itself
must be an isomorphism, and thus that `C` is a reflective subcategory of `D`.
Someone may like to formalize that lemma, and restate this theorem in terms of `Reflective`.
(That lemma has a nice string diagrammatic proof that holds in any bicategory.)
-/
noncomputable section
namespace CategoryTheory
open Limits
universe v u₁ u₂
namespace AbelianOfAdjunction
variable {C : Type u₁} [Category.{v} C] [Preadditive C]
variable {D : Type u₂} [Category.{v} D] [Abelian D]
variable (F : C ⥤ D)
variable (G : D ⥤ C) [Functor.PreservesZeroMorphisms G]
/-- No point making this an instance, as it requires `i`. -/
theorem hasKernels [PreservesFiniteLimits G] (i : F ⋙ G ≅ 𝟭 C) : HasKernels C :=
{ has_limit := fun f => by
have := NatIso.naturality_1 i f
simp? at this says
simp only [Functor.id_obj, Functor.comp_obj, Functor.comp_map, Functor.id_map] at this
rw [← this]
haveI : HasKernel (G.map (F.map f) ≫ i.hom.app _) := Limits.hasKernel_comp_mono _ _
apply Limits.hasKernel_iso_comp }
/-- No point making this an instance, as it requires `i` and `adj`. -/
theorem hasCokernels (i : F ⋙ G ≅ 𝟭 C) (adj : G ⊣ F) : HasCokernels C :=
{ has_colimit := fun f => by
have : PreservesColimits G := adj.leftAdjointPreservesColimits
have := NatIso.naturality_1 i f
simp? at this says
simp only [Functor.id_obj, Functor.comp_obj, Functor.comp_map, Functor.id_map] at this
rw [← this]
haveI : HasCokernel (G.map (F.map f) ≫ i.hom.app _) := Limits.hasCokernel_comp_iso _ _
apply Limits.hasCokernel_epi_comp }
variable [Limits.HasCokernels C]
/-- Auxiliary construction for `coimageIsoImage` -/
def cokernelIso (i : F ⋙ G ≅ 𝟭 C) (adj : G ⊣ F) {X Y : C} (f : X ⟶ Y) :
G.obj (cokernel (F.map f)) ≅ cokernel f := by
-- We have to write an explicit `PreservesColimits` type here,
-- as `leftAdjointPreservesColimits` has universe variables.
have : PreservesColimits G := adj.leftAdjointPreservesColimits
calc
G.obj (cokernel (F.map f)) ≅ cokernel (G.map (F.map f)) :=
(asIso (cokernelComparison _ G)).symm
_ ≅ cokernel (i.hom.app X ≫ f ≫ i.inv.app Y) := cokernelIsoOfEq (NatIso.naturality_2 i f).symm
_ ≅ cokernel (f ≫ i.inv.app Y) := cokernelEpiComp (i.hom.app X) (f ≫ i.inv.app Y)
_ ≅ cokernel f := cokernelCompIsIso f (i.inv.app Y)
variable [Limits.HasKernels C] [PreservesFiniteLimits G]
/-- Auxiliary construction for `coimageIsoImage` -/
def coimageIsoImageAux (i : F ⋙ G ≅ 𝟭 C) (adj : G ⊣ F) {X Y : C} (f : X ⟶ Y) :
kernel (G.map (cokernel.π (F.map f))) ≅ kernel (cokernel.π f) := by
have : PreservesColimits G := adj.leftAdjointPreservesColimits
calc
kernel (G.map (cokernel.π (F.map f))) ≅
kernel (cokernel.π (G.map (F.map f)) ≫ cokernelComparison (F.map f) G) :=
kernelIsoOfEq (π_comp_cokernelComparison _ _).symm
_ ≅ kernel (cokernel.π (G.map (F.map f))) := kernelCompMono _ _
_ ≅ kernel (cokernel.π (_ ≫ f ≫ _) ≫ (cokernelIsoOfEq _).hom) :=
(kernelIsoOfEq (π_comp_cokernelIsoOfEq_hom (NatIso.naturality_2 i f)).symm)
_ ≅ kernel (cokernel.π (_ ≫ f ≫ _)) := kernelCompMono _ _
_ ≅ kernel (cokernel.π (f ≫ i.inv.app Y) ≫ (cokernelEpiComp (i.hom.app X) _).inv) :=
(kernelIsoOfEq (by simp only [cokernel.π_desc, cokernelEpiComp_inv]))
_ ≅ kernel (cokernel.π (f ≫ _)) := kernelCompMono _ _
_ ≅ kernel (inv (i.inv.app Y) ≫ cokernel.π f ≫ (cokernelCompIsIso f (i.inv.app Y)).inv) :=
(kernelIsoOfEq
(by simp only [cokernel.π_desc, cokernelCompIsIso_inv, Iso.hom_inv_id_app_assoc,
NatIso.inv_inv_app]))
_ ≅ kernel (cokernel.π f ≫ _) := kernelIsIsoComp _ _
_ ≅ kernel (cokernel.π f) := kernelCompMono _ _
variable [Functor.PreservesZeroMorphisms F]
/-- Auxiliary definition: the abelian coimage and abelian image agree.
We still need to check that this agrees with the canonical morphism.
-/
def coimageIsoImage (i : F ⋙ G ≅ 𝟭 C) (adj : G ⊣ F) {X Y : C} (f : X ⟶ Y) :
Abelian.coimage f ≅ Abelian.image f := by
have : PreservesLimits F := adj.rightAdjointPreservesLimits
calc
Abelian.coimage f ≅ cokernel (kernel.ι f) := Iso.refl _
_ ≅ G.obj (cokernel (F.map (kernel.ι f))) := (cokernelIso _ _ i adj _).symm
_ ≅ G.obj (cokernel (kernelComparison f F ≫ kernel.ι (F.map f))) :=
(G.mapIso (cokernelIsoOfEq (by simp)))
_ ≅ G.obj (cokernel (kernel.ι (F.map f))) := G.mapIso (cokernelEpiComp _ _)
_ ≅ G.obj (Abelian.coimage (F.map f)) := Iso.refl _
_ ≅ G.obj (Abelian.image (F.map f)) := G.mapIso (Abelian.coimageIsoImage _)
_ ≅ G.obj (kernel (cokernel.π (F.map f))) := Iso.refl _
_ ≅ kernel (G.map (cokernel.π (F.map f))) := PreservesKernel.iso _ _
_ ≅ kernel (cokernel.π f) := coimageIsoImageAux F G i adj f
_ ≅ Abelian.image f := Iso.refl _
-- The account of this proof in the Stacks project omits this calculation.
theorem coimageIsoImage_hom (i : F ⋙ G ≅ 𝟭 C) (adj : G ⊣ F) {X Y : C} (f : X ⟶ Y) :
(coimageIsoImage F G i adj f).hom = Abelian.coimageImageComparison f := by
dsimp [coimageIsoImage, cokernelIso, cokernelEpiComp, cokernelCompIsIso_inv,
coimageIsoImageAux, kernelCompMono]
simpa only [← cancel_mono (Abelian.image.ι f), ← cancel_epi (Abelian.coimage.π f),
Category.assoc, Category.id_comp, cokernel.π_desc_assoc,
π_comp_cokernelIsoOfEq_inv_assoc, PreservesKernel.iso_hom,
π_comp_cokernelComparison_assoc, ← G.map_comp_assoc, kernel.lift_ι,
Abelian.coimage_image_factorisation, lift_comp_kernelIsoOfEq_hom_assoc,
kernelIsIsoComp_hom, kernel.lift_ι_assoc, kernelIsoOfEq_hom_comp_ι_assoc,
kernelComparison_comp_ι_assoc, π_comp_cokernelIsoOfEq_hom_assoc,
asIso_hom, NatIso.inv_inv_app] using NatIso.naturality_1 i f
end AbelianOfAdjunction
open AbelianOfAdjunction
/-- If `C` is an additive category, `D` is an abelian category,
we have `F : C ⥤ D` `G : D ⥤ C` (both preserving zero morphisms),
`G` is left exact (that is, preserves finite limits),
and further we have `adj : G ⊣ F` and `i : F ⋙ G ≅ 𝟭 C`,
then `C` is also abelian.
See <https://stacks.math.columbia.edu/tag/03A3>
-/
def abelianOfAdjunction {C : Type u₁} [Category.{v} C] [Preadditive C] [HasFiniteProducts C]
{D : Type u₂} [Category.{v} D] [Abelian D] (F : C ⥤ D) [Functor.PreservesZeroMorphisms F]
(G : D ⥤ C) [Functor.PreservesZeroMorphisms G] [PreservesFiniteLimits G] (i : F ⋙ G ≅ 𝟭 C)
(adj : G ⊣ F) : Abelian C := by
haveI := hasKernels F G i
haveI := hasCokernels F G i adj
have : ∀ {X Y : C} (f : X ⟶ Y), IsIso (Abelian.coimageImageComparison f) := by
intro X Y f
rw [← coimageIsoImage_hom F G i adj f]
infer_instance
apply Abelian.ofCoimageImageComparisonIsIso
/-- If `C` is an additive category equivalent to an abelian category `D`
via a functor that preserves zero morphisms,
then `C` is also abelian.
-/
def abelianOfEquivalence {C : Type u₁} [Category.{v} C] [Preadditive C] [HasFiniteProducts C]
{D : Type u₂} [Category.{v} D] [Abelian D] (F : C ⥤ D) [Functor.PreservesZeroMorphisms F]
[F.IsEquivalence] : Abelian C :=
abelianOfAdjunction F F.inv F.asEquivalence.unitIso.symm F.asEquivalence.symm.toAdjunction
end CategoryTheory
|
CategoryTheory\Abelian\DiagramLemmas\Four.lean | /-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel, Joël Riou
-/
import Mathlib.Algebra.Homology.ExactSequence
import Mathlib.CategoryTheory.Abelian.Refinements
/-!
# The four and five lemmas
Consider the following commutative diagram with exact rows in an abelian category `C`:
```
A ---f--> B ---g--> C ---h--> D ---i--> E
| | | | |
α β γ δ ε
| | | | |
v v v v v
A' --f'-> B' --g'-> C' --h'-> D' --i'-> E'
```
We show:
- the "mono" version of the four lemma: if `α` is an epimorphism and `β` and `δ` are monomorphisms,
then `γ` is a monomorphism,
- the "epi" version of the four lemma: if `β` and `δ` are epimorphisms and `ε` is a monomorphism,
then `γ` is an epimorphism,
- the five lemma: if `α`, `β`, `δ` and `ε` are isomorphisms, then `γ` is an isomorphism.
## Implementation details
The diagram of the five lemmas is given by a morphism in the category `ComposableArrows C 4`
between two objects which satisfy `ComposableArrows.Exact`. Similarly, the two versions of the
four lemma are stated in terms of the category `ComposableArrows C 3`.
The five lemmas is deduced from the two versions of the four lemma. Both of these versions
are proved separately. It would be easy to deduce the epi version from the mono version
using duality, but this would require lengthy API developments for `ComposableArrows` (TODO).
## Tags
four lemma, five lemma, diagram lemma, diagram chase
-/
namespace CategoryTheory
open Category Limits Preadditive
namespace Abelian
variable {C : Type*} [Category C] [Abelian C]
open ComposableArrows
section Four
variable {R₁ R₂ : ComposableArrows C 3} (φ : R₁ ⟶ R₂)
theorem mono_of_epi_of_mono_of_mono' (hR₁ : R₁.map' 0 2 = 0)
(hR₁' : (mk₂ (R₁.map' 1 2) (R₁.map' 2 3)).Exact)
(hR₂ : (mk₂ (R₂.map' 0 1) (R₂.map' 1 2)).Exact)
(h₀ : Epi (app' φ 0)) (h₁ : Mono (app' φ 1)) (h₃ : Mono (app' φ 3)) :
Mono (app' φ 2) := by
apply mono_of_cancel_zero
intro A f₂ h₁
have h₂ : f₂ ≫ R₁.map' 2 3 = 0 := by
rw [← cancel_mono (app' φ 3 _), assoc, NatTrans.naturality, reassoc_of% h₁,
zero_comp, zero_comp]
obtain ⟨A₁, π₁, _, f₁, hf₁⟩ := (hR₁'.exact 0).exact_up_to_refinements f₂ h₂
dsimp at hf₁
have h₃ : (f₁ ≫ app' φ 1) ≫ R₂.map' 1 2 = 0 := by
rw [assoc, ← NatTrans.naturality, ← reassoc_of% hf₁, h₁, comp_zero]
obtain ⟨A₂, π₂, _, g₀, hg₀⟩ := (hR₂.exact 0).exact_up_to_refinements _ h₃
obtain ⟨A₃, π₃, _, f₀, hf₀⟩ := surjective_up_to_refinements_of_epi (app' φ 0 _) g₀
have h₄ : f₀ ≫ R₁.map' 0 1 = π₃ ≫ π₂ ≫ f₁ := by
rw [← cancel_mono (app' φ 1 _), assoc, assoc, assoc, NatTrans.naturality,
← reassoc_of% hf₀, hg₀]
rfl
rw [← cancel_epi π₁, comp_zero, hf₁, ← cancel_epi π₂, ← cancel_epi π₃, comp_zero,
comp_zero, ← reassoc_of% h₄, ← R₁.map'_comp 0 1 2, hR₁, comp_zero]
theorem mono_of_epi_of_mono_of_mono (hR₁ : R₁.Exact) (hR₂ : R₂.Exact)
(h₀ : Epi (app' φ 0)) (h₁ : Mono (app' φ 1)) (h₃ : Mono (app' φ 3)) :
Mono (app' φ 2) :=
mono_of_epi_of_mono_of_mono' φ
(by simpa only [R₁.map'_comp 0 1 2] using hR₁.toIsComplex.zero 0)
(hR₁.exact 1).exact_toComposableArrows (hR₂.exact 0).exact_toComposableArrows h₀ h₁ h₃
attribute [local instance] epi_comp
theorem epi_of_epi_of_epi_of_mono'
(hR₁ : (mk₂ (R₁.map' 1 2) (R₁.map' 2 3)).Exact)
(hR₂ : (mk₂ (R₂.map' 0 1) (R₂.map' 1 2)).Exact) (hR₂' : R₂.map' 1 3 = 0)
(h₀ : Epi (app' φ 0)) (h₂ : Epi (app' φ 2)) (h₃ : Mono (app' φ 3)) :
Epi (app' φ 1) := by
rw [epi_iff_surjective_up_to_refinements]
intro A g₁
obtain ⟨A₁, π₁, _, f₂, h₁⟩ :=
surjective_up_to_refinements_of_epi (app' φ 2 _) (g₁ ≫ R₂.map' 1 2)
have h₂ : f₂ ≫ R₁.map' 2 3 = 0 := by
rw [← cancel_mono (app' φ 3 _), assoc, zero_comp, NatTrans.naturality, ← reassoc_of% h₁,
← R₂.map'_comp 1 2 3, hR₂', comp_zero, comp_zero]
obtain ⟨A₂, π₂, _, f₁, h₃⟩ := (hR₁.exact 0).exact_up_to_refinements _ h₂
dsimp at f₁ h₃
have h₄ : (π₂ ≫ π₁ ≫ g₁ - f₁ ≫ app' φ 1 _) ≫ R₂.map' 1 2 = 0 := by
rw [sub_comp, assoc, assoc, assoc, ← NatTrans.naturality, ← reassoc_of% h₃, h₁, sub_self]
obtain ⟨A₃, π₃, _, g₀, h₅⟩ := (hR₂.exact 0).exact_up_to_refinements _ h₄
dsimp at g₀ h₅
rw [comp_sub] at h₅
obtain ⟨A₄, π₄, _, f₀, h₆⟩ := surjective_up_to_refinements_of_epi (app' φ 0 _) g₀
refine ⟨A₄, π₄ ≫ π₃ ≫ π₂ ≫ π₁, inferInstance,
π₄ ≫ π₃ ≫ f₁ + f₀ ≫ (by exact R₁.map' 0 1), ?_⟩
rw [assoc, assoc, assoc, add_comp, assoc, assoc, assoc, NatTrans.naturality,
← reassoc_of% h₆, ← h₅, comp_sub]
dsimp
rw [add_sub_cancel]
theorem epi_of_epi_of_epi_of_mono (hR₁ : R₁.Exact) (hR₂ : R₂.Exact)
(h₀ : Epi (app' φ 0)) (h₂ : Epi (app' φ 2)) (h₃ : Mono (app' φ 3)) :
Epi (app' φ 1) :=
epi_of_epi_of_epi_of_mono' φ (hR₁.exact 1).exact_toComposableArrows
(hR₂.exact 0).exact_toComposableArrows
(by simpa only [R₂.map'_comp 1 2 3] using hR₂.toIsComplex.zero 1) h₀ h₂ h₃
end Four
section Five
variable {R₁ R₂ : ComposableArrows C 4} (hR₁ : R₁.Exact) (hR₂ : R₂.Exact) (φ : R₁ ⟶ R₂)
#adaptation_note /-- nightly-2024-03-11
We turn off simprocs here.
Ideally someone will investigate whether `simp` lemmas can be rearranged
so that this works without the `set_option`,
*or* come up with a proposal regarding finer control of disabling simprocs. -/
set_option simprocs false in
/-- The five lemma. -/
theorem isIso_of_epi_of_isIso_of_isIso_of_mono (h₀ : Epi (app' φ 0)) (h₁ : IsIso (app' φ 1))
(h₂ : IsIso (app' φ 3)) (h₃ : Mono (app' φ 4)) : IsIso (app' φ 2) := by
dsimp at h₀ h₁ h₂ h₃
have : Mono (app' φ 2) := by
apply mono_of_epi_of_mono_of_mono (δlastFunctor.map φ) (R₁.exact_iff_δlast.1 hR₁).1
(R₂.exact_iff_δlast.1 hR₂).1 <;> dsimp <;> infer_instance
have : Epi (app' φ 2) := by
apply epi_of_epi_of_epi_of_mono (δ₀Functor.map φ) (R₁.exact_iff_δ₀.1 hR₁).2
(R₂.exact_iff_δ₀.1 hR₂).2 <;> dsimp <;> infer_instance
apply isIso_of_mono_of_epi
end Five
/-! The following "three lemmas" for morphisms in `ComposableArrows C 2` are
special cases of "four lemmas" applied to diagrams where some of the
leftmost or rightmost maps (or objects) are zero. -/
section Three
variable {R₁ R₂ : ComposableArrows C 2} (φ : R₁ ⟶ R₂)
attribute [local simp] Precomp.map
theorem mono_of_epi_of_epi_mono' (hR₁ : R₁.map' 0 2 = 0) (hR₁' : Epi (R₁.map' 1 2))
(hR₂ : R₂.Exact) (h₀ : Epi (app' φ 0)) (h₁ : Mono (app' φ 1)) :
Mono (app' φ 2) := by
let ψ : mk₃ (R₁.map' 0 1) (R₁.map' 1 2) (0 : _ ⟶ R₁.obj' 0) ⟶
mk₃ (R₂.map' 0 1) (R₂.map' 1 2) (0 : _ ⟶ R₁.obj' 0) := homMk₃ (app' φ 0) (app' φ 1)
(app' φ 2) (𝟙 _) (naturality' φ 0 1) (naturality' φ 1 2) (by simp)
refine mono_of_epi_of_mono_of_mono' ψ ?_ (exact₂_mk _ (by simp) ?_)
(hR₂.exact 0).exact_toComposableArrows h₀ h₁ (by dsimp [ψ]; infer_instance)
· dsimp
rw [← Functor.map_comp]
exact hR₁
· rw [ShortComplex.exact_iff_epi _ (by simp)]
exact hR₁'
theorem mono_of_epi_of_epi_of_mono (hR₁ : R₁.Exact) (hR₂ : R₂.Exact)
(hR₁' : Epi (R₁.map' 1 2)) (h₀ : Epi (app' φ 0)) (h₁ : Mono (app' φ 1)) :
Mono (app' φ 2) :=
mono_of_epi_of_epi_mono' φ (by simpa only [map'_comp R₁ 0 1 2] using hR₁.toIsComplex.zero 0)
hR₁' hR₂ h₀ h₁
theorem epi_of_mono_of_epi_of_mono' (hR₁ : R₁.Exact) (hR₂ : R₂.map' 0 2 = 0)
(hR₂' : Mono (R₂.map' 0 1)) (h₀ : Epi (app' φ 1)) (h₁ : Mono (app' φ 2)) :
Epi (app' φ 0) := by
let ψ : mk₃ (0 : R₁.obj' 0 ⟶ _) (R₁.map' 0 1) (R₁.map' 1 2) ⟶
mk₃ (0 : R₁.obj' 0 ⟶ _) (R₂.map' 0 1) (R₂.map' 1 2) := homMk₃ (𝟙 _) (app' φ 0) (app' φ 1)
(app' φ 2) (by simp) (naturality' φ 0 1) (naturality' φ 1 2)
refine epi_of_epi_of_epi_of_mono' ψ (hR₁.exact 0).exact_toComposableArrows
(exact₂_mk _ (by simp) ?_) ?_ (by dsimp [ψ]; infer_instance) h₀ h₁
· rw [ShortComplex.exact_iff_mono _ (by simp)]
exact hR₂'
· dsimp
rw [← Functor.map_comp]
exact hR₂
theorem epi_of_mono_of_epi_of_mono (hR₁ : R₁.Exact) (hR₂ : R₂.Exact)
(hR₂' : Mono (R₂.map' 0 1)) (h₀ : Epi (app' φ 1)) (h₁ : Mono (app' φ 2)) :
Epi (app' φ 0) :=
epi_of_mono_of_epi_of_mono' φ hR₁
(by simpa only [map'_comp R₂ 0 1 2] using hR₂.toIsComplex.zero 0) hR₂' h₀ h₁
theorem mono_of_mono_of_mono_of_mono (hR₁ : R₁.Exact)
(hR₂' : Mono (R₂.map' 0 1))
(h₀ : Mono (app' φ 0))
(h₁ : Mono (app' φ 2)) :
Mono (app' φ 1) := by
let ψ : mk₃ (0 : R₁.obj' 0 ⟶ _) (R₁.map' 0 1) (R₁.map' 1 2) ⟶
mk₃ (0 : R₁.obj' 0 ⟶ _) (R₂.map' 0 1) (R₂.map' 1 2) := homMk₃ (𝟙 _) (app' φ 0) (app' φ 1)
(app' φ 2) (by simp) (naturality' φ 0 1) (naturality' φ 1 2)
refine mono_of_epi_of_mono_of_mono' ψ (by simp)
(hR₁.exact 0).exact_toComposableArrows
(exact₂_mk _ (by simp) ?_) (by dsimp [ψ]; infer_instance) h₀ h₁
rw [ShortComplex.exact_iff_mono _ (by simp)]
exact hR₂'
theorem epi_of_epi_of_epi_of_epi (hR₂ : R₂.Exact) (hR₁' : Epi (R₁.map' 1 2))
(h₀ : Epi (app' φ 0)) (h₁ : Epi (app' φ 2)) :
Epi (app' φ 1) := by
let ψ : mk₃ (R₁.map' 0 1) (R₁.map' 1 2) (0 : _ ⟶ R₁.obj' 0) ⟶
mk₃ (R₂.map' 0 1) (R₂.map' 1 2) (0 : _ ⟶ R₁.obj' 0) := homMk₃ (app' φ 0) (app' φ 1)
(app' φ 2) (𝟙 _) (naturality' φ 0 1) (naturality' φ 1 2) (by simp)
refine epi_of_epi_of_epi_of_mono' ψ (exact₂_mk _ (by simp) ?_)
(hR₂.exact 0).exact_toComposableArrows (by simp)
h₀ h₁ (by dsimp [ψ]; infer_instance)
rw [ShortComplex.exact_iff_epi _ (by simp)]
exact hR₁'
end Three
end Abelian
end CategoryTheory
|
CategoryTheory\Adjunction\AdjointFunctorTheorems.lean | /-
Copyright (c) 2021 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import Mathlib.CategoryTheory.Generator
import Mathlib.CategoryTheory.Limits.ConeCategory
import Mathlib.CategoryTheory.Limits.Constructions.WeaklyInitial
import Mathlib.CategoryTheory.Limits.FunctorCategory
import Mathlib.CategoryTheory.Subobject.Comma
/-!
# Adjoint functor theorem
This file proves the (general) adjoint functor theorem, in the form:
* If `G : D ⥤ C` preserves limits and `D` has limits, and satisfies the solution set condition,
then it has a left adjoint: `isRightAdjointOfPreservesLimitsOfIsCoseparating`.
We show that the converse holds, i.e. that if `G` has a left adjoint then it satisfies the solution
set condition, see `solutionSetCondition_of_isRightAdjoint`
(the file `CategoryTheory/Adjunction/Limits` already shows it preserves limits).
We define the *solution set condition* for the functor `G : D ⥤ C` to mean, for every object
`A : C`, there is a set-indexed family ${f_i : A ⟶ G (B_i)}$ such that any morphism `A ⟶ G X`
factors through one of the `f_i`.
This file also proves the special adjoint functor theorem, in the form:
* If `G : D ⥤ C` preserves limits and `D` is complete, well-powered and has a small coseparating
set, then `G` has a left adjoint: `isRightAdjointOfPreservesLimitsOfIsCoseparating`
Finally, we prove the following corollary of the special adjoint functor theorem:
* If `C` is complete, well-powered and has a small coseparating set, then it is cocomplete:
`hasColimits_of_hasLimits_of_isCoseparating`
-/
universe v u u'
namespace CategoryTheory
open Limits
variable {J : Type v}
variable {C : Type u} [Category.{v} C]
/-- The functor `G : D ⥤ C` satisfies the *solution set condition* if for every `A : C`, there is a
family of morphisms `{f_i : A ⟶ G (B_i) // i ∈ ι}` such that given any morphism `h : A ⟶ G X`,
there is some `i ∈ ι` such that `h` factors through `f_i`.
The key part of this definition is that the indexing set `ι` lives in `Type v`, where `v` is the
universe of morphisms of the category: this is the "smallness" condition which allows the general
adjoint functor theorem to go through.
-/
def SolutionSetCondition {D : Type u} [Category.{v} D] (G : D ⥤ C) : Prop :=
∀ A : C,
∃ (ι : Type v) (B : ι → D) (f : ∀ i : ι, A ⟶ G.obj (B i)),
∀ (X) (h : A ⟶ G.obj X), ∃ (i : ι) (g : B i ⟶ X), f i ≫ G.map g = h
section GeneralAdjointFunctorTheorem
variable {D : Type u} [Category.{v} D]
variable (G : D ⥤ C)
/-- If `G : D ⥤ C` is a right adjoint it satisfies the solution set condition. -/
theorem solutionSetCondition_of_isRightAdjoint [G.IsRightAdjoint] : SolutionSetCondition G := by
intro A
refine
⟨PUnit, fun _ => G.leftAdjoint.obj A, fun _ => (Adjunction.ofIsRightAdjoint G).unit.app A, ?_⟩
intro B h
refine ⟨PUnit.unit, ((Adjunction.ofIsRightAdjoint G).homEquiv _ _).symm h, ?_⟩
rw [← Adjunction.homEquiv_unit, Equiv.apply_symm_apply]
/-- The general adjoint functor theorem says that if `G : D ⥤ C` preserves limits and `D` has them,
if `G` satisfies the solution set condition then `G` is a right adjoint.
-/
lemma isRightAdjoint_of_preservesLimits_of_solutionSetCondition [HasLimits D]
[PreservesLimits G] (hG : SolutionSetCondition G) : G.IsRightAdjoint := by
refine @isRightAdjointOfStructuredArrowInitials _ _ _ _ G ?_
intro A
specialize hG A
choose ι B f g using hG
let B' : ι → StructuredArrow A G := fun i => StructuredArrow.mk (f i)
have hB' : ∀ A' : StructuredArrow A G, ∃ i, Nonempty (B' i ⟶ A') := by
intro A'
obtain ⟨i, _, t⟩ := g _ A'.hom
exact ⟨i, ⟨StructuredArrow.homMk _ t⟩⟩
obtain ⟨T, hT⟩ := has_weakly_initial_of_weakly_initial_set_and_hasProducts hB'
apply hasInitial_of_weakly_initial_and_hasWideEqualizers hT
end GeneralAdjointFunctorTheorem
section SpecialAdjointFunctorTheorem
variable {D : Type u'} [Category.{v} D]
/-- The special adjoint functor theorem: if `G : D ⥤ C` preserves limits and `D` is complete,
well-powered and has a small coseparating set, then `G` has a left adjoint.
-/
lemma isRightAdjoint_of_preservesLimits_of_isCoseparating [HasLimits D] [WellPowered D]
{𝒢 : Set D} [Small.{v} 𝒢] (h𝒢 : IsCoseparating 𝒢) (G : D ⥤ C) [PreservesLimits G] :
G.IsRightAdjoint :=
have : ∀ A, HasInitial (StructuredArrow A G) := fun A =>
hasInitial_of_isCoseparating (StructuredArrow.isCoseparating_proj_preimage A G h𝒢)
isRightAdjointOfStructuredArrowInitials _
/-- The special adjoint functor theorem: if `F : C ⥤ D` preserves colimits and `C` is cocomplete,
well-copowered and has a small separating set, then `F` has a right adjoint.
-/
lemma isLeftAdjoint_of_preservesColimits_of_isSeparating [HasColimits C] [WellPowered Cᵒᵖ]
{𝒢 : Set C} [Small.{v} 𝒢] (h𝒢 : IsSeparating 𝒢) (F : C ⥤ D) [PreservesColimits F] :
F.IsLeftAdjoint :=
have : ∀ A, HasTerminal (CostructuredArrow F A) := fun A =>
hasTerminal_of_isSeparating (CostructuredArrow.isSeparating_proj_preimage F A h𝒢)
isLeftAdjoint_of_costructuredArrowTerminals _
end SpecialAdjointFunctorTheorem
namespace Limits
/-- A consequence of the special adjoint functor theorem: if `C` is complete, well-powered and
has a small coseparating set, then it is cocomplete. -/
theorem hasColimits_of_hasLimits_of_isCoseparating [HasLimits C] [WellPowered C] {𝒢 : Set C}
[Small.{v} 𝒢] (h𝒢 : IsCoseparating 𝒢) : HasColimits C :=
{ has_colimits_of_shape := fun _ _ =>
hasColimitsOfShape_iff_isRightAdjoint_const.2
(isRightAdjoint_of_preservesLimits_of_isCoseparating h𝒢 _) }
/-- A consequence of the special adjoint functor theorem: if `C` is cocomplete, well-copowered and
has a small separating set, then it is complete. -/
theorem hasLimits_of_hasColimits_of_isSeparating [HasColimits C] [WellPowered Cᵒᵖ] {𝒢 : Set C}
[Small.{v} 𝒢] (h𝒢 : IsSeparating 𝒢) : HasLimits C :=
{ has_limits_of_shape := fun _ _ =>
hasLimitsOfShape_iff_isLeftAdjoint_const.2
(isLeftAdjoint_of_preservesColimits_of_isSeparating h𝒢 _) }
end Limits
end CategoryTheory
|
CategoryTheory\Adjunction\Basic.lean | /-
Copyright (c) 2019 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Johan Commelin, Bhavik Mehta
-/
import Mathlib.CategoryTheory.Equivalence
/-!
# Adjunctions between functors
`F ⊣ G` represents the data of an adjunction between two functors
`F : C ⥤ D` and `G : D ⥤ C`. `F` is the left adjoint and `G` is the right adjoint.
We provide various useful constructors:
* `mkOfHomEquiv`
* `mkOfUnitCounit`
* `leftAdjointOfEquiv` / `rightAdjointOfEquiv`
construct a left/right adjoint of a given functor given the action on objects and
the relevant equivalence of morphism spaces.
* `adjunctionOfEquivLeft` / `adjunctionOfEquivRight` witness that these constructions
give adjunctions.
There are also typeclasses `IsLeftAdjoint` / `IsRightAdjoint`, which asserts the
existence of a adjoint functor. Given `[F.IsLeftAdjoint]`, a chosen right
adjoint can be obtained as `F.rightAdjoint`.
`Adjunction.comp` composes adjunctions.
`toEquivalence` upgrades an adjunction to an equivalence,
given witnesses that the unit and counit are pointwise isomorphisms.
Conversely `Equivalence.toAdjunction` recovers the underlying adjunction from an equivalence.
-/
namespace CategoryTheory
open Category
-- declare the `v`'s first; see `CategoryTheory.Category` for an explanation
universe v₁ v₂ v₃ u₁ u₂ u₃
-- Porting Note: `elab_without_expected_type` cannot be a local attribute
-- attribute [local elab_without_expected_type] whiskerLeft whiskerRight
variable {C : Type u₁} [Category.{v₁} C] {D : Type u₂} [Category.{v₂} D]
/-- `F ⊣ G` represents the data of an adjunction between two functors
`F : C ⥤ D` and `G : D ⥤ C`. `F` is the left adjoint and `G` is the right adjoint.
To construct an `adjunction` between two functors, it's often easier to instead use the
constructors `mkOfHomEquiv` or `mkOfUnitCounit`. To construct a left adjoint,
there are also constructors `leftAdjointOfEquiv` and `adjunctionOfEquivLeft` (as
well as their duals) which can be simpler in practice.
Uniqueness of adjoints is shown in `CategoryTheory.Adjunction.Opposites`.
See <https://stacks.math.columbia.edu/tag/0037>.
-/
structure Adjunction (F : C ⥤ D) (G : D ⥤ C) where
/-- The equivalence between `Hom (F X) Y` and `Hom X (G Y)` coming from an adjunction -/
homEquiv : ∀ X Y, (F.obj X ⟶ Y) ≃ (X ⟶ G.obj Y)
/-- The unit of an adjunction -/
unit : 𝟭 C ⟶ F.comp G
/-- The counit of an adjunction -/
counit : G.comp F ⟶ 𝟭 D
-- Porting note: It's strange that this `Prop` is being flagged by the `docBlame` linter
/-- Naturality of the unit of an adjunction -/
homEquiv_unit : ∀ {X Y f}, (homEquiv X Y) f = (unit : _ ⟶ _).app X ≫ G.map f := by aesop_cat
-- Porting note: It's strange that this `Prop` is being flagged by the `docBlame` linter
/-- Naturality of the counit of an adjunction -/
homEquiv_counit : ∀ {X Y g}, (homEquiv X Y).symm g = F.map g ≫ counit.app Y := by aesop_cat
/-- The notation `F ⊣ G` stands for `Adjunction F G` representing that `F` is left adjoint to `G` -/
infixl:15 " ⊣ " => Adjunction
namespace Functor
/-- A class asserting the existence of a right adjoint. -/
class IsLeftAdjoint (left : C ⥤ D) : Prop where
exists_rightAdjoint : ∃ (right : D ⥤ C), Nonempty (left ⊣ right)
/-- A class asserting the existence of a left adjoint. -/
class IsRightAdjoint (right : D ⥤ C) : Prop where
exists_leftAdjoint : ∃ (left : C ⥤ D), Nonempty (left ⊣ right)
/-- A chosen left adjoint to a functor that is a right adjoint. -/
noncomputable def leftAdjoint (R : D ⥤ C) [IsRightAdjoint R] : C ⥤ D :=
(IsRightAdjoint.exists_leftAdjoint (right := R)).choose
/-- A chosen right adjoint to a functor that is a left adjoint. -/
noncomputable def rightAdjoint (L : C ⥤ D) [IsLeftAdjoint L] : D ⥤ C :=
(IsLeftAdjoint.exists_rightAdjoint (left := L)).choose
end Functor
/-- The adjunction associated to a functor known to be a left adjoint. -/
noncomputable def Adjunction.ofIsLeftAdjoint (left : C ⥤ D) [left.IsLeftAdjoint] :
left ⊣ left.rightAdjoint :=
Functor.IsLeftAdjoint.exists_rightAdjoint.choose_spec.some
/-- The adjunction associated to a functor known to be a right adjoint. -/
noncomputable def Adjunction.ofIsRightAdjoint (right : C ⥤ D) [right.IsRightAdjoint] :
right.leftAdjoint ⊣ right :=
Functor.IsRightAdjoint.exists_leftAdjoint.choose_spec.some
namespace Adjunction
-- Porting note: Workaround not needed in Lean 4
-- restate_axiom homEquiv_unit'
-- restate_axiom homEquiv_counit'
attribute [simp] homEquiv_unit homEquiv_counit
section
variable {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G)
lemma isLeftAdjoint (adj : F ⊣ G) : F.IsLeftAdjoint := ⟨_, ⟨adj⟩⟩
lemma isRightAdjoint (adj : F ⊣ G) : G.IsRightAdjoint := ⟨_, ⟨adj⟩⟩
instance (R : D ⥤ C) [R.IsRightAdjoint] : R.leftAdjoint.IsLeftAdjoint :=
(ofIsRightAdjoint R).isLeftAdjoint
instance (L : C ⥤ D) [L.IsLeftAdjoint] : L.rightAdjoint.IsRightAdjoint :=
(ofIsLeftAdjoint L).isRightAdjoint
variable {X' X : C} {Y Y' : D}
theorem homEquiv_id (X : C) : adj.homEquiv X _ (𝟙 _) = adj.unit.app X := by simp
theorem homEquiv_symm_id (X : D) : (adj.homEquiv _ X).symm (𝟙 _) = adj.counit.app X := by simp
/-
Porting note: `nolint simpNF` as the linter was complaining that this was provable using `simp`
but it is in fact not. Also the `docBlame` linter expects a docstring even though this is `Prop`
valued
-/
@[simp, nolint simpNF]
theorem homEquiv_naturality_left_symm (f : X' ⟶ X) (g : X ⟶ G.obj Y) :
(adj.homEquiv X' Y).symm (f ≫ g) = F.map f ≫ (adj.homEquiv X Y).symm g := by
rw [homEquiv_counit, F.map_comp, assoc, adj.homEquiv_counit.symm]
-- Porting note: Same as above
@[simp, nolint simpNF]
theorem homEquiv_naturality_left (f : X' ⟶ X) (g : F.obj X ⟶ Y) :
(adj.homEquiv X' Y) (F.map f ≫ g) = f ≫ (adj.homEquiv X Y) g := by
rw [← Equiv.eq_symm_apply]
simp only [Equiv.symm_apply_apply,eq_self_iff_true,homEquiv_naturality_left_symm]
-- Porting note: Same as above
@[simp, nolint simpNF]
theorem homEquiv_naturality_right (f : F.obj X ⟶ Y) (g : Y ⟶ Y') :
(adj.homEquiv X Y') (f ≫ g) = (adj.homEquiv X Y) f ≫ G.map g := by
rw [homEquiv_unit, G.map_comp, ← assoc, ← homEquiv_unit]
-- Porting note: Same as above
@[simp, nolint simpNF]
theorem homEquiv_naturality_right_symm (f : X ⟶ G.obj Y) (g : Y ⟶ Y') :
(adj.homEquiv X Y').symm (f ≫ G.map g) = (adj.homEquiv X Y).symm f ≫ g := by
rw [Equiv.symm_apply_eq]
simp only [homEquiv_naturality_right,eq_self_iff_true,Equiv.apply_symm_apply]
@[reassoc]
theorem homEquiv_naturality_left_square (f : X' ⟶ X) (g : F.obj X ⟶ Y')
(h : F.obj X' ⟶ Y) (k : Y ⟶ Y') (w : F.map f ≫ g = h ≫ k) :
f ≫ (adj.homEquiv X Y') g = (adj.homEquiv X' Y) h ≫ G.map k := by
rw [← homEquiv_naturality_left, ← homEquiv_naturality_right, w]
@[reassoc]
theorem homEquiv_naturality_right_square (f : X' ⟶ X) (g : X ⟶ G.obj Y')
(h : X' ⟶ G.obj Y) (k : Y ⟶ Y') (w : f ≫ g = h ≫ G.map k) :
F.map f ≫ (adj.homEquiv X Y').symm g = (adj.homEquiv X' Y).symm h ≫ k := by
rw [← homEquiv_naturality_left_symm, ← homEquiv_naturality_right_symm, w]
theorem homEquiv_naturality_left_square_iff (f : X' ⟶ X) (g : F.obj X ⟶ Y')
(h : F.obj X' ⟶ Y) (k : Y ⟶ Y') :
(f ≫ (adj.homEquiv X Y') g = (adj.homEquiv X' Y) h ≫ G.map k) ↔
(F.map f ≫ g = h ≫ k) :=
⟨fun w ↦ by simpa only [Equiv.symm_apply_apply]
using homEquiv_naturality_right_square adj _ _ _ _ w,
homEquiv_naturality_left_square adj f g h k⟩
theorem homEquiv_naturality_right_square_iff (f : X' ⟶ X) (g : X ⟶ G.obj Y')
(h : X' ⟶ G.obj Y) (k : Y ⟶ Y') :
(F.map f ≫ (adj.homEquiv X Y').symm g = (adj.homEquiv X' Y).symm h ≫ k) ↔
(f ≫ g = h ≫ G.map k) :=
⟨fun w ↦ by simpa only [Equiv.apply_symm_apply]
using homEquiv_naturality_left_square adj _ _ _ _ w,
homEquiv_naturality_right_square adj f g h k⟩
@[simp]
theorem left_triangle : whiskerRight adj.unit F ≫ whiskerLeft F adj.counit = 𝟙 _ := by
ext; dsimp
erw [← adj.homEquiv_counit, Equiv.symm_apply_eq, adj.homEquiv_unit]
simp
@[simp]
theorem right_triangle : whiskerLeft G adj.unit ≫ whiskerRight adj.counit G = 𝟙 _ := by
ext; dsimp
erw [← adj.homEquiv_unit, ← Equiv.eq_symm_apply, adj.homEquiv_counit]
simp
variable (X Y)
@[reassoc (attr := simp)]
theorem left_triangle_components :
F.map (adj.unit.app X) ≫ adj.counit.app (F.obj X) = 𝟙 (F.obj X) :=
congr_arg (fun t : NatTrans _ (𝟭 C ⋙ F) => t.app X) adj.left_triangle
@[reassoc (attr := simp)]
theorem right_triangle_components :
adj.unit.app (G.obj Y) ≫ G.map (adj.counit.app Y) = 𝟙 (G.obj Y) :=
congr_arg (fun t : NatTrans _ (G ⋙ 𝟭 C) => t.app Y) adj.right_triangle
variable {X Y}
@[reassoc (attr := simp)]
theorem counit_naturality {X Y : D} (f : X ⟶ Y) :
F.map (G.map f) ≫ adj.counit.app Y = adj.counit.app X ≫ f :=
adj.counit.naturality f
@[reassoc (attr := simp)]
theorem unit_naturality {X Y : C} (f : X ⟶ Y) :
adj.unit.app X ≫ G.map (F.map f) = f ≫ adj.unit.app Y :=
(adj.unit.naturality f).symm
theorem homEquiv_apply_eq {A : C} {B : D} (f : F.obj A ⟶ B) (g : A ⟶ G.obj B) :
adj.homEquiv A B f = g ↔ f = (adj.homEquiv A B).symm g :=
⟨fun h => by
cases h
simp, fun h => by
cases h
simp⟩
theorem eq_homEquiv_apply {A : C} {B : D} (f : F.obj A ⟶ B) (g : A ⟶ G.obj B) :
g = adj.homEquiv A B f ↔ (adj.homEquiv A B).symm g = f :=
⟨fun h => by
cases h
simp, fun h => by
cases h
simp⟩
end
end Adjunction
namespace Adjunction
/-- This is an auxiliary data structure useful for constructing adjunctions.
See `Adjunction.mkOfHomEquiv`.
This structure won't typically be used anywhere else.
-/
-- Porting note(#5171): `has_nonempty_instance` linter not ported yet
-- @[nolint has_nonempty_instance]
structure CoreHomEquiv (F : C ⥤ D) (G : D ⥤ C) where
/-- The equivalence between `Hom (F X) Y` and `Hom X (G Y)` -/
homEquiv : ∀ X Y, (F.obj X ⟶ Y) ≃ (X ⟶ G.obj Y)
/-- The property that describes how `homEquiv.symm` transforms compositions `X' ⟶ X ⟶ G Y` -/
homEquiv_naturality_left_symm :
∀ {X' X Y} (f : X' ⟶ X) (g : X ⟶ G.obj Y),
(homEquiv X' Y).symm (f ≫ g) = F.map f ≫ (homEquiv X Y).symm g := by
aesop_cat
/-- The property that describes how `homEquiv` transforms compositions `F X ⟶ Y ⟶ Y'` -/
homEquiv_naturality_right :
∀ {X Y Y'} (f : F.obj X ⟶ Y) (g : Y ⟶ Y'),
(homEquiv X Y') (f ≫ g) = (homEquiv X Y) f ≫ G.map g := by
aesop_cat
namespace CoreHomEquiv
-- Porting note: Workaround not needed in Lean 4.
-- restate_axiom homEquiv_naturality_left_symm'
-- restate_axiom homEquiv_naturality_right'
attribute [simp] homEquiv_naturality_left_symm homEquiv_naturality_right
variable {F : C ⥤ D} {G : D ⥤ C} (adj : CoreHomEquiv F G) {X' X : C} {Y Y' : D}
@[simp]
theorem homEquiv_naturality_left_aux (f : X' ⟶ X) (g : F.obj X ⟶ Y) :
(adj.homEquiv X' (F.obj X)) (F.map f) ≫ G.map g = f ≫ (adj.homEquiv X Y) g := by
rw [← homEquiv_naturality_right, ← Equiv.eq_symm_apply]; simp
-- @[simp] -- Porting note: LHS simplifies, added aux lemma above
theorem homEquiv_naturality_left (f : X' ⟶ X) (g : F.obj X ⟶ Y) :
(adj.homEquiv X' Y) (F.map f ≫ g) = f ≫ (adj.homEquiv X Y) g := by
rw [← Equiv.eq_symm_apply]; simp
@[simp]
theorem homEquiv_naturality_right_symm_aux (f : X ⟶ G.obj Y) (g : Y ⟶ Y') :
F.map f ≫ (adj.homEquiv (G.obj Y) Y').symm (G.map g) = (adj.homEquiv X Y).symm f ≫ g := by
rw [← homEquiv_naturality_left_symm, Equiv.symm_apply_eq]; simp
-- @[simp] -- Porting note: LHS simplifies, added aux lemma above
theorem homEquiv_naturality_right_symm (f : X ⟶ G.obj Y) (g : Y ⟶ Y') :
(adj.homEquiv X Y').symm (f ≫ G.map g) = (adj.homEquiv X Y).symm f ≫ g := by
rw [Equiv.symm_apply_eq]; simp
end CoreHomEquiv
/-- This is an auxiliary data structure useful for constructing adjunctions.
See `Adjunction.mkOfUnitCounit`.
This structure won't typically be used anywhere else.
-/
-- Porting note(#5171): `has_nonempty_instance` linter not ported yet
-- @[nolint has_nonempty_instance]
structure CoreUnitCounit (F : C ⥤ D) (G : D ⥤ C) where
/-- The unit of an adjunction between `F` and `G` -/
unit : 𝟭 C ⟶ F.comp G
/-- The counit of an adjunction between `F` and `G`s -/
counit : G.comp F ⟶ 𝟭 D
/-- Equality of the composition of the unit, associator, and counit with the identity
`F ⟶ (F G) F ⟶ F (G F) ⟶ F = NatTrans.id F` -/
left_triangle :
whiskerRight unit F ≫ (Functor.associator F G F).hom ≫ whiskerLeft F counit =
NatTrans.id (𝟭 C ⋙ F) := by
aesop_cat
/-- Equality of the composition of the unit, associator, and counit with the identity
`G ⟶ G (F G) ⟶ (F G) F ⟶ G = NatTrans.id G` -/
right_triangle :
whiskerLeft G unit ≫ (Functor.associator G F G).inv ≫ whiskerRight counit G =
NatTrans.id (G ⋙ 𝟭 C) := by
aesop_cat
namespace CoreUnitCounit
attribute [simp] left_triangle right_triangle
end CoreUnitCounit
variable {F : C ⥤ D} {G : D ⥤ C}
/-- Construct an adjunction between `F` and `G` out of a natural bijection between each
`F.obj X ⟶ Y` and `X ⟶ G.obj Y`. -/
@[simps]
def mkOfHomEquiv (adj : CoreHomEquiv F G) : F ⊣ G :=
-- See note [dsimp, simp].
{ adj with
unit :=
{ app := fun X => (adj.homEquiv X (F.obj X)) (𝟙 (F.obj X))
naturality := by
intros
erw [← adj.homEquiv_naturality_left, ← adj.homEquiv_naturality_right]
dsimp; simp }
counit :=
{ app := fun Y => (adj.homEquiv _ _).invFun (𝟙 (G.obj Y))
naturality := by
intros
erw [← adj.homEquiv_naturality_left_symm, ← adj.homEquiv_naturality_right_symm]
dsimp; simp }
homEquiv_unit := @fun X Y f => by erw [← adj.homEquiv_naturality_right]; simp
homEquiv_counit := @fun X Y f => by erw [← adj.homEquiv_naturality_left_symm]; simp
}
/-- Construct an adjunction between functors `F` and `G` given a unit and counit for the adjunction
satisfying the triangle identities. -/
@[simps!]
def mkOfUnitCounit (adj : CoreUnitCounit F G) : F ⊣ G :=
{ adj with
homEquiv := fun X Y =>
{ toFun := fun f => adj.unit.app X ≫ G.map f
invFun := fun g => F.map g ≫ adj.counit.app Y
left_inv := fun f => by
change F.map (_ ≫ _) ≫ _ = _
rw [F.map_comp, assoc, ← Functor.comp_map, adj.counit.naturality, ← assoc]
convert id_comp f
have t := congrArg (fun (s : NatTrans (𝟭 C ⋙ F) (F ⋙ 𝟭 D)) => s.app X) adj.left_triangle
dsimp at t
simp only [id_comp] at t
exact t
right_inv := fun g => by
change _ ≫ G.map (_ ≫ _) = _
rw [G.map_comp, ← assoc, ← Functor.comp_map, ← adj.unit.naturality, assoc]
convert comp_id g
have t := congrArg (fun t : NatTrans (G ⋙ 𝟭 C) (𝟭 D ⋙ G) => t.app Y) adj.right_triangle
dsimp at t
simp only [id_comp] at t
exact t } }
/- Porting note: simpNF linter claims these are solved by simp but that
is not true -/
attribute [nolint simpNF] CategoryTheory.Adjunction.mkOfUnitCounit_homEquiv_symm_apply
attribute [nolint simpNF] CategoryTheory.Adjunction.mkOfUnitCounit_homEquiv_apply
/-- The adjunction between the identity functor on a category and itself. -/
def id : 𝟭 C ⊣ 𝟭 C where
homEquiv X Y := Equiv.refl _
unit := 𝟙 _
counit := 𝟙 _
-- Satisfy the inhabited linter.
instance : Inhabited (Adjunction (𝟭 C) (𝟭 C)) :=
⟨id⟩
/-- If F and G are naturally isomorphic functors, establish an equivalence of hom-sets. -/
@[simps]
def equivHomsetLeftOfNatIso {F F' : C ⥤ D} (iso : F ≅ F') {X : C} {Y : D} :
(F.obj X ⟶ Y) ≃ (F'.obj X ⟶ Y) where
toFun f := iso.inv.app _ ≫ f
invFun g := iso.hom.app _ ≫ g
left_inv f := by simp
right_inv g := by simp
/-- If G and H are naturally isomorphic functors, establish an equivalence of hom-sets. -/
@[simps]
def equivHomsetRightOfNatIso {G G' : D ⥤ C} (iso : G ≅ G') {X : C} {Y : D} :
(X ⟶ G.obj Y) ≃ (X ⟶ G'.obj Y) where
toFun f := f ≫ iso.hom.app _
invFun g := g ≫ iso.inv.app _
left_inv f := by simp
right_inv g := by simp
/-- Transport an adjunction along a natural isomorphism on the left. -/
def ofNatIsoLeft {F G : C ⥤ D} {H : D ⥤ C} (adj : F ⊣ H) (iso : F ≅ G) : G ⊣ H :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun X Y => (equivHomsetLeftOfNatIso iso.symm).trans (adj.homEquiv X Y) }
/-- Transport an adjunction along a natural isomorphism on the right. -/
def ofNatIsoRight {F : C ⥤ D} {G H : D ⥤ C} (adj : F ⊣ G) (iso : G ≅ H) : F ⊣ H :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun X Y => (adj.homEquiv X Y).trans (equivHomsetRightOfNatIso iso) }
section
variable {E : Type u₃} [ℰ : Category.{v₃} E] {H : D ⥤ E} {I : E ⥤ D}
(adj₁ : F ⊣ G) (adj₂ : H ⊣ I)
/-- Composition of adjunctions.
See <https://stacks.math.columbia.edu/tag/0DV0>.
-/
def comp : F ⋙ H ⊣ I ⋙ G where
homEquiv X Z := Equiv.trans (adj₂.homEquiv _ _) (adj₁.homEquiv _ _)
unit := adj₁.unit ≫ (whiskerLeft F <| whiskerRight adj₂.unit G) ≫ (Functor.associator _ _ _).inv
counit :=
(Functor.associator _ _ _).hom ≫ (whiskerLeft I <| whiskerRight adj₁.counit H) ≫ adj₂.counit
@[simp, reassoc]
lemma comp_unit_app (X : C) :
(adj₁.comp adj₂).unit.app X = adj₁.unit.app X ≫ G.map (adj₂.unit.app (F.obj X)) := by
simp [Adjunction.comp]
@[simp, reassoc]
lemma comp_counit_app (X : E) :
(adj₁.comp adj₂).counit.app X = H.map (adj₁.counit.app (I.obj X)) ≫ adj₂.counit.app X := by
simp [Adjunction.comp]
end
section ConstructLeft
-- Construction of a left adjoint. In order to construct a left
-- adjoint to a functor G : D → C, it suffices to give the object part
-- of a functor F : C → D together with isomorphisms Hom(FX, Y) ≃
-- Hom(X, GY) natural in Y. The action of F on morphisms can be
-- constructed from this data.
variable {F_obj : C → D}
variable (e : ∀ X Y, (F_obj X ⟶ Y) ≃ (X ⟶ G.obj Y))
/-- Construct a left adjoint functor to `G`, given the functor's value on objects `F_obj` and
a bijection `e` between `F_obj X ⟶ Y` and `X ⟶ G.obj Y` satisfying a naturality law
`he : ∀ X Y Y' g h, e X Y' (h ≫ g) = e X Y h ≫ G.map g`.
Dual to `rightAdjointOfEquiv`. -/
@[simps!]
def leftAdjointOfEquiv (he : ∀ X Y Y' g h, e X Y' (h ≫ g) = e X Y h ≫ G.map g) : C ⥤ D where
obj := F_obj
map {X} {X'} f := (e X (F_obj X')).symm (f ≫ e X' (F_obj X') (𝟙 _))
map_comp := fun f f' => by
rw [Equiv.symm_apply_eq, he, Equiv.apply_symm_apply]
conv =>
rhs
rw [assoc, ← he, id_comp, Equiv.apply_symm_apply]
simp
variable (he : ∀ X Y Y' g h, e X Y' (h ≫ g) = e X Y h ≫ G.map g)
/-- Show that the functor given by `leftAdjointOfEquiv` is indeed left adjoint to `G`. Dual
to `adjunctionOfRightEquiv`. -/
@[simps!]
def adjunctionOfEquivLeft : leftAdjointOfEquiv e he ⊣ G :=
mkOfHomEquiv
{ homEquiv := e
homEquiv_naturality_left_symm := fun {X'} {X} {Y} f g => by
have {X : C} {Y Y' : D} (f : X ⟶ G.obj Y) (g : Y ⟶ Y') :
(e X Y').symm (f ≫ G.map g) = (e X Y).symm f ≫ g := by
rw [Equiv.symm_apply_eq, he]; simp
erw [← this, ← Equiv.apply_eq_iff_eq (e X' Y)]
simp only [leftAdjointOfEquiv_obj, Equiv.apply_symm_apply, assoc]
congr
rw [← he]
simp
}
end ConstructLeft
section ConstructRight
-- Construction of a right adjoint, analogous to the above.
variable {G_obj : D → C}
variable (e : ∀ X Y, (F.obj X ⟶ Y) ≃ (X ⟶ G_obj Y))
private theorem he'' (he : ∀ X' X Y f g, e X' Y (F.map f ≫ g) = f ≫ e X Y g)
{X' X Y} (f g) : F.map f ≫ (e X Y).symm g = (e X' Y).symm (f ≫ g) := by
rw [Equiv.eq_symm_apply, he]; simp
/-- Construct a right adjoint functor to `F`, given the functor's value on objects `G_obj` and
a bijection `e` between `F.obj X ⟶ Y` and `X ⟶ G_obj Y` satisfying a naturality law
`he : ∀ X Y Y' g h, e X' Y (F.map f ≫ g) = f ≫ e X Y g`.
Dual to `leftAdjointOfEquiv`. -/
@[simps!]
def rightAdjointOfEquiv (he : ∀ X' X Y f g, e X' Y (F.map f ≫ g) = f ≫ e X Y g) : D ⥤ C where
obj := G_obj
map {Y} {Y'} g := (e (G_obj Y) Y') ((e (G_obj Y) Y).symm (𝟙 _) ≫ g)
map_comp := fun {Y} {Y'} {Y''} g g' => by
rw [← Equiv.eq_symm_apply, ← he'' e he, Equiv.symm_apply_apply]
conv =>
rhs
rw [← assoc, he'' e he, comp_id, Equiv.symm_apply_apply]
simp
/-- Show that the functor given by `rightAdjointOfEquiv` is indeed right adjoint to `F`. Dual
to `adjunctionOfEquivRight`. -/
@[simps!]
def adjunctionOfEquivRight (he : ∀ X' X Y f g, e X' Y (F.map f ≫ g) = f ≫ e X Y g) :
F ⊣ (rightAdjointOfEquiv e he) :=
mkOfHomEquiv
{ homEquiv := e
homEquiv_naturality_left_symm := by
intro X X' Y f g; rw [Equiv.symm_apply_eq]; dsimp; rw [he]; simp
homEquiv_naturality_right := by
intro X Y Y' g h
erw [← he, Equiv.apply_eq_iff_eq, ← assoc, he'' e he, comp_id, Equiv.symm_apply_apply] }
end ConstructRight
/--
If the unit and counit of a given adjunction are (pointwise) isomorphisms, then we can upgrade the
adjunction to an equivalence.
-/
@[simps!]
noncomputable def toEquivalence (adj : F ⊣ G) [∀ X, IsIso (adj.unit.app X)]
[∀ Y, IsIso (adj.counit.app Y)] : C ≌ D where
functor := F
inverse := G
unitIso := NatIso.ofComponents fun X => asIso (adj.unit.app X)
counitIso := NatIso.ofComponents fun Y => asIso (adj.counit.app Y)
end Adjunction
open Adjunction
/--
If the unit and counit for the adjunction corresponding to a right adjoint functor are (pointwise)
isomorphisms, then the functor is an equivalence of categories.
-/
lemma Functor.isEquivalence_of_isRightAdjoint (G : C ⥤ D) [IsRightAdjoint G]
[∀ X, IsIso ((Adjunction.ofIsRightAdjoint G).unit.app X)]
[∀ Y, IsIso ((Adjunction.ofIsRightAdjoint G).counit.app Y)] : G.IsEquivalence :=
(Adjunction.ofIsRightAdjoint G).toEquivalence.isEquivalence_inverse
namespace Equivalence
variable (e : C ≌ D)
/-- The adjunction given by an equivalence of categories. (To obtain the opposite adjunction,
simply use `e.symm.toAdjunction`. -/
@[simps! unit counit]
def toAdjunction : e.functor ⊣ e.inverse :=
mkOfUnitCounit
⟨e.unit, e.counit, by
ext
dsimp
simp only [id_comp]
exact e.functor_unit_comp _, by
ext
dsimp
simp only [id_comp]
exact e.unit_inverse_comp _⟩
lemma isLeftAdjoint_functor : e.functor.IsLeftAdjoint where
exists_rightAdjoint := ⟨_, ⟨e.toAdjunction⟩⟩
lemma isRightAdjoint_inverse : e.inverse.IsRightAdjoint where
exists_leftAdjoint := ⟨_, ⟨e.toAdjunction⟩⟩
lemma isLeftAdjoint_inverse : e.inverse.IsLeftAdjoint :=
e.symm.isLeftAdjoint_functor
lemma isRightAdjoint_functor : e.functor.IsRightAdjoint :=
e.symm.isRightAdjoint_inverse
end Equivalence
namespace Functor
/-- If `F` and `G` are left adjoints then `F ⋙ G` is a left adjoint too. -/
instance isLeftAdjoint_comp {E : Type u₃} [Category.{v₃} E] (F : C ⥤ D) (G : D ⥤ E)
[F.IsLeftAdjoint] [G.IsLeftAdjoint] : (F ⋙ G).IsLeftAdjoint where
exists_rightAdjoint :=
⟨_, ⟨(Adjunction.ofIsLeftAdjoint F).comp (Adjunction.ofIsLeftAdjoint G)⟩⟩
/-- If `F` and `G` are right adjoints then `F ⋙ G` is a right adjoint too. -/
instance isRightAdjoint_comp {E : Type u₃} [Category.{v₃} E] {F : C ⥤ D} {G : D ⥤ E}
[IsRightAdjoint F] [IsRightAdjoint G] : IsRightAdjoint (F ⋙ G) where
exists_leftAdjoint :=
⟨_, ⟨(Adjunction.ofIsRightAdjoint G).comp (Adjunction.ofIsRightAdjoint F)⟩⟩
/-- Transport being a right adjoint along a natural isomorphism. -/
lemma isRightAdjoint_of_iso {F G : C ⥤ D} (h : F ≅ G) [F.IsRightAdjoint] :
IsRightAdjoint G where
exists_leftAdjoint := ⟨_, ⟨(Adjunction.ofIsRightAdjoint F).ofNatIsoRight h⟩⟩
/-- Transport being a left adjoint along a natural isomorphism. -/
lemma isLeftAdjoint_of_iso {F G : C ⥤ D} (h : F ≅ G) [IsLeftAdjoint F] :
IsLeftAdjoint G where
exists_rightAdjoint := ⟨_, ⟨(Adjunction.ofIsLeftAdjoint F).ofNatIsoLeft h⟩⟩
/-- An equivalence `E` is left adjoint to its inverse. -/
noncomputable def adjunction (E : C ⥤ D) [IsEquivalence E] : E ⊣ E.inv :=
E.asEquivalence.toAdjunction
/-- If `F` is an equivalence, it's a left adjoint. -/
instance (priority := 10) isLeftAdjoint_of_isEquivalence {F : C ⥤ D} [F.IsEquivalence] :
IsLeftAdjoint F :=
F.asEquivalence.isLeftAdjoint_functor
/-- If `F` is an equivalence, it's a right adjoint. -/
instance (priority := 10) isRightAdjoint_of_isEquivalence {F : C ⥤ D} [F.IsEquivalence] :
IsRightAdjoint F :=
F.asEquivalence.isRightAdjoint_functor
end Functor
end CategoryTheory
|
CategoryTheory\Adjunction\Comma.lean | /-
Copyright (c) 2021 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import Mathlib.CategoryTheory.Adjunction.Basic
import Mathlib.CategoryTheory.Comma.StructuredArrow
import Mathlib.CategoryTheory.PUnit
/-!
# Properties of comma categories relating to adjunctions
This file shows that for a functor `G : D ⥤ C` the data of an initial object in each
`StructuredArrow` category on `G` is equivalent to a left adjoint to `G`, as well as the dual.
Specifically, `adjunctionOfStructuredArrowInitials` gives the left adjoint assuming the
appropriate initial objects exist, and `mkInitialOfLeftAdjoint` constructs the initial objects
provided a left adjoint.
The duals are also shown.
-/
universe v₁ v₂ u₁ u₂
noncomputable section
namespace CategoryTheory
open Limits
variable {C : Type u₁} {D : Type u₂} [Category.{v₁} C] [Category.{v₂} D] (G : D ⥤ C)
section OfInitials
variable [∀ A, HasInitial (StructuredArrow A G)]
attribute [local simp] eq_iff_true_of_subsingleton in
/-- Implementation: If each structured arrow category on `G` has an initial object, an equivalence
which is helpful for constructing a left adjoint to `G`.
-/
@[simps]
def leftAdjointOfStructuredArrowInitialsAux (A : C) (B : D) :
((⊥_ StructuredArrow A G).right ⟶ B) ≃ (A ⟶ G.obj B) where
toFun g := (⊥_ StructuredArrow A G).hom ≫ G.map g
invFun f := CommaMorphism.right (initial.to (StructuredArrow.mk f))
left_inv g := by
let B' : StructuredArrow A G := StructuredArrow.mk ((⊥_ StructuredArrow A G).hom ≫ G.map g)
let g' : ⊥_ StructuredArrow A G ⟶ B' := StructuredArrow.homMk g rfl
have : initial.to _ = g' := by aesop_cat
change CommaMorphism.right (initial.to B') = _
rw [this]
rfl
right_inv f := by
let B' : StructuredArrow A G := StructuredArrow.mk f
apply (CommaMorphism.w (initial.to B')).symm.trans (Category.id_comp _)
/--
If each structured arrow category on `G` has an initial object, construct a left adjoint to `G`. It
is shown that it is a left adjoint in `adjunctionOfStructuredArrowInitials`.
-/
def leftAdjointOfStructuredArrowInitials : C ⥤ D :=
Adjunction.leftAdjointOfEquiv (leftAdjointOfStructuredArrowInitialsAux G) fun _ _ => by simp
/--
If each structured arrow category on `G` has an initial object, we have a constructed left adjoint
to `G`.
-/
def adjunctionOfStructuredArrowInitials : leftAdjointOfStructuredArrowInitials G ⊣ G :=
Adjunction.adjunctionOfEquivLeft _ _
/-- If each structured arrow category on `G` has an initial object, `G` is a right adjoint. -/
lemma isRightAdjointOfStructuredArrowInitials : G.IsRightAdjoint where
exists_leftAdjoint := ⟨_, ⟨adjunctionOfStructuredArrowInitials G⟩⟩
end OfInitials
section OfTerminals
variable [∀ A, HasTerminal (CostructuredArrow G A)]
attribute [local simp] eq_iff_true_of_subsingleton in
/-- Implementation: If each costructured arrow category on `G` has a terminal object, an equivalence
which is helpful for constructing a right adjoint to `G`.
-/
@[simps]
def rightAdjointOfCostructuredArrowTerminalsAux (B : D) (A : C) :
(G.obj B ⟶ A) ≃ (B ⟶ (⊤_ CostructuredArrow G A).left) where
toFun g := CommaMorphism.left (terminal.from (CostructuredArrow.mk g))
invFun g := G.map g ≫ (⊤_ CostructuredArrow G A).hom
left_inv := by aesop_cat
right_inv g := by
let B' : CostructuredArrow G A :=
CostructuredArrow.mk (G.map g ≫ (⊤_ CostructuredArrow G A).hom)
let g' : B' ⟶ ⊤_ CostructuredArrow G A := CostructuredArrow.homMk g rfl
have : terminal.from _ = g' := by aesop_cat
change CommaMorphism.left (terminal.from B') = _
rw [this]
rfl
/--
If each costructured arrow category on `G` has a terminal object, construct a right adjoint to `G`.
It is shown that it is a right adjoint in `adjunctionOfStructuredArrowInitials`.
-/
def rightAdjointOfCostructuredArrowTerminals : C ⥤ D :=
Adjunction.rightAdjointOfEquiv (rightAdjointOfCostructuredArrowTerminalsAux G)
fun B₁ B₂ A f g => by
rw [← Equiv.eq_symm_apply]
simp
/-- If each costructured arrow category on `G` has a terminal object, we have a constructed right
adjoint to `G`.
-/
def adjunctionOfCostructuredArrowTerminals : G ⊣ rightAdjointOfCostructuredArrowTerminals G :=
Adjunction.adjunctionOfEquivRight _ _
/-- If each costructured arrow category on `G` has a terminal object, `G` is a left adjoint. -/
lemma isLeftAdjoint_of_costructuredArrowTerminals : G.IsLeftAdjoint where
exists_rightAdjoint :=
⟨rightAdjointOfCostructuredArrowTerminals G, ⟨Adjunction.adjunctionOfEquivRight _ _⟩⟩
end OfTerminals
section
variable {F : C ⥤ D}
/-- Given a left adjoint to `G`, we can construct an initial object in each structured arrow
category on `G`. -/
def mkInitialOfLeftAdjoint (h : F ⊣ G) (A : C) :
IsInitial (StructuredArrow.mk (h.unit.app A) : StructuredArrow A G) where
desc B := StructuredArrow.homMk ((h.homEquiv _ _).symm B.pt.hom)
uniq s m _ := by
apply StructuredArrow.ext
dsimp
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [Equiv.eq_symm_apply, Adjunction.homEquiv_unit]
apply StructuredArrow.w m
/-- Given a right adjoint to `F`, we can construct a terminal object in each costructured arrow
category on `F`. -/
def mkTerminalOfRightAdjoint (h : F ⊣ G) (A : D) :
IsTerminal (CostructuredArrow.mk (h.counit.app A) : CostructuredArrow F A) where
lift B := CostructuredArrow.homMk (h.homEquiv _ _ B.pt.hom)
uniq s m _ := by
apply CostructuredArrow.ext
dsimp
rw [h.eq_homEquiv_apply, Adjunction.homEquiv_counit]
exact CostructuredArrow.w m
end
theorem isRightAdjoint_iff_hasInitial_structuredArrow {G : D ⥤ C} :
G.IsRightAdjoint ↔ ∀ A, HasInitial (StructuredArrow A G) :=
⟨fun _ A => (mkInitialOfLeftAdjoint _ (Adjunction.ofIsRightAdjoint G) A).hasInitial,
fun _ => isRightAdjointOfStructuredArrowInitials _⟩
theorem isLeftAdjoint_iff_hasTerminal_costructuredArrow {F : C ⥤ D} :
F.IsLeftAdjoint ↔ ∀ A, HasTerminal (CostructuredArrow F A) :=
⟨fun _ A => (mkTerminalOfRightAdjoint _ (Adjunction.ofIsLeftAdjoint F) A).hasTerminal,
fun _ => isLeftAdjoint_of_costructuredArrowTerminals _⟩
end CategoryTheory
|
CategoryTheory\Adjunction\Evaluation.lean | /-
Copyright (c) 2021 Adam Topaz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz
-/
import Mathlib.CategoryTheory.Limits.Shapes.Products
import Mathlib.CategoryTheory.Functor.EpiMono
/-!
# Adjunctions involving evaluation
We show that evaluation of functors have adjoints, given the existence of (co)products.
-/
namespace CategoryTheory
open CategoryTheory.Limits
universe v₁ v₂ u₁ u₂
variable {C : Type u₁} [Category.{v₁} C] (D : Type u₂) [Category.{v₂} D]
noncomputable section
section
variable [∀ a b : C, HasCoproductsOfShape (a ⟶ b) D]
/-- The left adjoint of evaluation. -/
@[simps]
def evaluationLeftAdjoint (c : C) : D ⥤ C ⥤ D where
obj d :=
{ obj := fun t => ∐ fun _ : c ⟶ t => d
map := fun f => Sigma.desc fun g => (Sigma.ι fun _ => d) <| g ≫ f}
map {_ d₂} f :=
{ app := fun e => Sigma.desc fun h => f ≫ Sigma.ι (fun _ => d₂) h
naturality := by
intros
dsimp
ext
simp }
/-- The adjunction showing that evaluation is a right adjoint. -/
@[simps! unit_app counit_app_app]
def evaluationAdjunctionRight (c : C) : evaluationLeftAdjoint D c ⊣ (evaluation _ _).obj c :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun d F =>
{ toFun := fun f => Sigma.ι (fun _ => d) (𝟙 _) ≫ f.app c
invFun := fun f =>
{ app := fun e => Sigma.desc fun h => f ≫ F.map h
naturality := by
intros
dsimp
ext
simp }
left_inv := by
intro f
ext x
dsimp
ext g
simp only [colimit.ι_desc, Cofan.mk_ι_app, Category.assoc, ← f.naturality,
evaluationLeftAdjoint_obj_map, colimit.ι_desc_assoc,
Discrete.functor_obj, Cofan.mk_pt, Discrete.natTrans_app, Category.id_comp]
right_inv := fun f => by
dsimp
simp }
-- This used to be automatic before leanprover/lean4#2644
homEquiv_naturality_right := by intros; dsimp; simp }
instance evaluationIsRightAdjoint (c : C) : ((evaluation _ D).obj c).IsRightAdjoint :=
⟨_, ⟨evaluationAdjunctionRight _ _⟩⟩
theorem NatTrans.mono_iff_mono_app {F G : C ⥤ D} (η : F ⟶ G) : Mono η ↔ ∀ c, Mono (η.app c) := by
constructor
· intro h c
exact (inferInstance : Mono (((evaluation _ _).obj c).map η))
· intro _
apply NatTrans.mono_of_mono_app
end
section
variable [∀ a b : C, HasProductsOfShape (a ⟶ b) D]
/-- The right adjoint of evaluation. -/
@[simps]
def evaluationRightAdjoint (c : C) : D ⥤ C ⥤ D where
obj d :=
{ obj := fun t => ∏ᶜ fun _ : t ⟶ c => d
map := fun f => Pi.lift fun g => Pi.π _ <| f ≫ g }
map f :=
{ app := fun t => Pi.lift fun g => Pi.π _ g ≫ f
naturality := by
intros
dsimp
ext
simp }
/-- The adjunction showing that evaluation is a left adjoint. -/
@[simps! unit_app_app counit_app]
def evaluationAdjunctionLeft (c : C) : (evaluation _ _).obj c ⊣ evaluationRightAdjoint D c :=
Adjunction.mkOfHomEquiv
{ homEquiv := fun F d =>
{ toFun := fun f =>
{ app := fun t => Pi.lift fun g => F.map g ≫ f
naturality := by
intros
dsimp
ext
simp }
invFun := fun f => f.app _ ≫ Pi.π _ (𝟙 _)
left_inv := fun f => by
dsimp
simp
right_inv := by
intro f
ext x
dsimp
ext g
simp only [Discrete.functor_obj, NatTrans.naturality_assoc,
evaluationRightAdjoint_obj_obj, evaluationRightAdjoint_obj_map, limit.lift_π,
Fan.mk_pt, Fan.mk_π_app, Discrete.natTrans_app, Category.comp_id] } }
instance evaluationIsLeftAdjoint (c : C) : ((evaluation _ D).obj c).IsLeftAdjoint :=
⟨_, ⟨evaluationAdjunctionLeft _ _⟩⟩
theorem NatTrans.epi_iff_epi_app {F G : C ⥤ D} (η : F ⟶ G) : Epi η ↔ ∀ c, Epi (η.app c) := by
constructor
· intro h c
exact (inferInstance : Epi (((evaluation _ _).obj c).map η))
· intros
apply NatTrans.epi_of_epi_app
end
end
end CategoryTheory
|
CategoryTheory\Adjunction\FullyFaithful.lean | /-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Dagur Asgeirsson
-/
import Mathlib.CategoryTheory.Adjunction.Basic
import Mathlib.CategoryTheory.MorphismProperty.Basic
import Mathlib.CategoryTheory.EpiMono
/-!
# Adjoints of fully faithful functors
A left adjoint is
* faithful, if and only if the unit is a monomorphism
* full, if and only if the unit is a split epimorphism
* fully faithful, if and only if the unit is an isomorphism
A right adjoint is
* faithful, if and only if the counit is an epimorphism
* full, if and only if the counit is a split monomorphism
* fully faithful, if and only if the counit is an isomorphism
This is Lemma 4.5.13 in Riehl's *Category Theory in Context* [riehl2017].
See also https://stacks.math.columbia.edu/tag/07RB for the statements about fully faithful functors.
In the file `Mathlib.CategoryTheory.Monad.Adjunction`, we prove that in fact, if there exists an
isomorphism `L ⋙ R ≅ 𝟭 C`, then the unit is an isomorphism, and similarly for the counit.
See `CategoryTheory.Adjunction.isIso_unit_of_iso` and
`CategoryTheory.Adjunction.isIso_counit_of_iso`.
-/
open CategoryTheory
namespace CategoryTheory.Adjunction
universe v₁ v₂ u₁ u₂
open Category
open Opposite
variable {C : Type u₁} [Category.{v₁} C]
variable {D : Type u₂} [Category.{v₂} D]
variable {L : C ⥤ D} {R : D ⥤ C} (h : L ⊣ R)
/-- If the left adjoint is faithful, then each component of the unit is an monomorphism. -/
instance unit_mono_of_L_faithful [L.Faithful] (X : C) : Mono (h.unit.app X) where
right_cancellation {Y} f g hfg :=
L.map_injective <| (h.homEquiv Y (L.obj X)).injective <| by simpa using hfg
/-- If the left adjoint is full, then each component of the unit is a split epimorphism.-/
noncomputable def unitSplitEpiOfLFull [L.Full] (X : C) : SplitEpi (h.unit.app X) where
section_ := L.preimage (h.counit.app (L.obj X))
id := by simp [← h.unit_naturality (L.preimage (h.counit.app (L.obj X)))]
/-- If the right adjoint is full, then each component of the counit is a split monomorphism. -/
instance unit_isSplitEpi_of_L_full [L.Full] (X : C) : IsSplitEpi (h.unit.app X) :=
⟨⟨h.unitSplitEpiOfLFull X⟩⟩
instance [L.Full] [L.Faithful] (X : C) : IsIso (h.unit.app X) :=
isIso_of_mono_of_isSplitEpi _
/-- If the left adjoint is fully faithful, then the unit is an isomorphism. -/
instance unit_isIso_of_L_fully_faithful [L.Full] [L.Faithful] : IsIso (Adjunction.unit h) :=
NatIso.isIso_of_isIso_app _
/-- If the right adjoint is faithful, then each component of the counit is an epimorphism.-/
instance counit_epi_of_R_faithful [R.Faithful] (X : D) : Epi (h.counit.app X) where
left_cancellation {Y} f g hfg :=
R.map_injective <| (h.homEquiv (R.obj X) Y).symm.injective <| by simpa using hfg
/-- If the right adjoint is full, then each component of the counit is a split monomorphism. -/
noncomputable def counitSplitMonoOfRFull [R.Full] (X : D) : SplitMono (h.counit.app X) where
retraction := R.preimage (h.unit.app (R.obj X))
id := by simp [← h.counit_naturality (R.preimage (h.unit.app (R.obj X)))]
/-- If the right adjoint is full, then each component of the counit is a split monomorphism. -/
instance counit_isSplitMono_of_R_full [R.Full] (X : D) : IsSplitMono (h.counit.app X) :=
⟨⟨h.counitSplitMonoOfRFull X⟩⟩
instance [R.Full] [R.Faithful] (X : D) : IsIso (h.counit.app X) :=
isIso_of_epi_of_isSplitMono _
/-- If the right adjoint is fully faithful, then the counit is an isomorphism. -/
instance counit_isIso_of_R_fully_faithful [R.Full] [R.Faithful] : IsIso (Adjunction.counit h) :=
NatIso.isIso_of_isIso_app _
/-- If the unit of an adjunction is an isomorphism, then its inverse on the image of L is given
by L whiskered with the counit. -/
@[simp]
theorem inv_map_unit {X : C} [IsIso (h.unit.app X)] :
inv (L.map (h.unit.app X)) = h.counit.app (L.obj X) :=
IsIso.inv_eq_of_hom_inv_id (h.left_triangle_components X)
/-- If the unit is an isomorphism, bundle one has an isomorphism `L ⋙ R ⋙ L ≅ L`. -/
@[simps!]
noncomputable def whiskerLeftLCounitIsoOfIsIsoUnit [IsIso h.unit] : L ⋙ R ⋙ L ≅ L :=
(L.associator R L).symm ≪≫ isoWhiskerRight (asIso h.unit).symm L ≪≫ Functor.leftUnitor _
/-- If the counit of an adjunction is an isomorphism, then its inverse on the image of R is given
by R whiskered with the unit. -/
@[simp]
theorem inv_counit_map {X : D} [IsIso (h.counit.app X)] :
inv (R.map (h.counit.app X)) = h.unit.app (R.obj X) :=
IsIso.inv_eq_of_inv_hom_id (h.right_triangle_components X)
/-- If the counit of an is an isomorphism, one has an isomorphism `(R ⋙ L ⋙ R) ≅ R`. -/
@[simps!]
noncomputable def whiskerLeftRUnitIsoOfIsIsoCounit [IsIso h.counit] : R ⋙ L ⋙ R ≅ R :=
(R.associator L R).symm ≪≫ isoWhiskerRight (asIso h.counit) R ≪≫ Functor.leftUnitor _
/-- If each component of the unit is a monomorphism, then the left adjoint is faithful. -/
lemma faithful_L_of_mono_unit_app [∀ X, Mono (h.unit.app X)] : L.Faithful where
map_injective {X Y f g} hfg := by
apply Mono.right_cancellation (f := h.unit.app Y)
apply (h.homEquiv X (L.obj Y)).symm.injective
simpa using hfg
/-- If each component of the unit is a split epimorphism, then the left adjoint is full. -/
lemma full_L_of_isSplitEpi_unit_app [∀ X, IsSplitEpi (h.unit.app X)] : L.Full where
map_surjective {X Y} f := by
use ((h.homEquiv X (L.obj Y)) f ≫ section_ (h.unit.app Y))
suffices L.map (section_ (h.unit.app Y)) = h.counit.app (L.obj Y) by simp [this]
rw [← comp_id (L.map (section_ (h.unit.app Y)))]
simp only [Functor.comp_obj, Functor.id_obj, comp_id, ← h.left_triangle_components Y,
← assoc, ← Functor.map_comp, IsSplitEpi.id, Functor.map_id, id_comp]
/-- If the unit is an isomorphism, then the left adjoint is fully faithful. -/
noncomputable def fullyFaithfulLOfIsIsoUnit [IsIso h.unit] : L.FullyFaithful where
preimage {X Y} f := h.homEquiv _ (L.obj Y) f ≫ inv (h.unit.app Y)
/-- If each component of the counit is an epimorphism, then the right adjoint is faithful. -/
lemma faithful_R_of_epi_counit_app [∀ X, Epi (h.counit.app X)] : R.Faithful where
map_injective {X Y f g} hfg := by
apply Epi.left_cancellation (f := h.counit.app X)
apply (h.homEquiv (R.obj X) Y).injective
simpa using hfg
/-- If each component of the counit is a split monomorphism, then the right adjoint is full. -/
lemma full_R_of_isSplitMono_counit_app [∀ X, IsSplitMono (h.counit.app X)] : R.Full where
map_surjective {X Y} f := by
use (retraction (h.counit.app X) ≫ (h.homEquiv (R.obj X) Y).symm f)
suffices R.map (retraction (h.counit.app X)) = h.unit.app (R.obj X) by simp [this]
rw [← id_comp (R.map (retraction (h.counit.app X)))]
simp only [Functor.id_obj, Functor.comp_obj, id_comp, ← h.right_triangle_components X,
assoc, ← Functor.map_comp, IsSplitMono.id, Functor.map_id, comp_id]
/-- If the counit is an isomorphism, then the right adjoint is fully faithful. -/
noncomputable def fullyFaithfulROfIsIsoCounit [IsIso h.counit] : R.FullyFaithful where
preimage {X Y} f := inv (h.counit.app X) ≫ (h.homEquiv (R.obj X) Y).symm f
instance whiskerLeft_counit_iso_of_L_fully_faithful [L.Full] [L.Faithful] :
IsIso (whiskerLeft L h.counit) := by
have := h.left_triangle
rw [← IsIso.eq_inv_comp] at this
rw [this]
infer_instance
instance whiskerRight_counit_iso_of_L_fully_faithful [L.Full] [L.Faithful] :
IsIso (whiskerRight h.counit R) := by
have := h.right_triangle
rw [← IsIso.eq_inv_comp] at this
rw [this]
infer_instance
instance whiskerLeft_unit_iso_of_R_fully_faithful [R.Full] [R.Faithful] :
IsIso (whiskerLeft R h.unit) := by
have := h.right_triangle
rw [← IsIso.eq_comp_inv] at this
rw [this]
infer_instance
instance whiskerRight_unit_iso_of_R_fully_faithful [R.Full] [R.Faithful] :
IsIso (whiskerRight h.unit L) := by
have := h.left_triangle
rw [← IsIso.eq_comp_inv] at this
rw [this]
infer_instance
instance [L.Faithful] [L.Full] {Y : C} : IsIso (h.counit.app (L.obj Y)) :=
isIso_of_hom_comp_eq_id _ (h.left_triangle_components Y)
instance [L.Faithful] [L.Full] {Y : D} : IsIso (R.map (h.counit.app Y)) :=
isIso_of_hom_comp_eq_id _ (h.right_triangle_components Y)
lemma isIso_counit_app_iff_mem_essImage [L.Faithful] [L.Full] {X : D} :
IsIso (h.counit.app X) ↔ X ∈ L.essImage := by
constructor
· intro
exact ⟨R.obj X, ⟨asIso (h.counit.app X)⟩⟩
· rintro ⟨_, ⟨i⟩⟩
rw [NatTrans.isIso_app_iff_of_iso _ i.symm]
infer_instance
lemma mem_essImage_of_counit_isIso (A : D)
[IsIso (h.counit.app A)] : A ∈ L.essImage :=
⟨R.obj A, ⟨asIso (h.counit.app A)⟩⟩
lemma isIso_counit_app_of_iso [L.Faithful] [L.Full] {X : D} {Y : C} (e : X ≅ L.obj Y) :
IsIso (h.counit.app X) :=
(isIso_counit_app_iff_mem_essImage h).mpr ⟨Y, ⟨e.symm⟩⟩
instance [R.Faithful] [R.Full] {Y : D} : IsIso (h.unit.app (R.obj Y)) :=
isIso_of_comp_hom_eq_id _ (h.right_triangle_components Y)
instance [R.Faithful] [R.Full] {X : C} : IsIso (L.map (h.unit.app X)) :=
isIso_of_comp_hom_eq_id _ (h.left_triangle_components X)
lemma isIso_unit_app_iff_mem_essImage [R.Faithful] [R.Full] {Y : C} :
IsIso (h.unit.app Y) ↔ Y ∈ R.essImage := by
constructor
· intro
exact ⟨L.obj Y, ⟨(asIso (h.unit.app Y)).symm⟩⟩
· rintro ⟨_, ⟨i⟩⟩
rw [NatTrans.isIso_app_iff_of_iso _ i.symm]
infer_instance
/-- If `η_A` is an isomorphism, then `A` is in the essential image of `i`. -/
theorem mem_essImage_of_unit_isIso (A : C)
[IsIso (h.unit.app A)] : A ∈ R.essImage :=
⟨L.obj A, ⟨(asIso (h.unit.app A)).symm⟩⟩
@[deprecated (since := "2024-06-19")] alias _root_.CategoryTheory.mem_essImage_of_unit_isIso :=
mem_essImage_of_unit_isIso
lemma isIso_unit_app_of_iso [R.Faithful] [R.Full] {X : D} {Y : C} (e : Y ≅ R.obj X) :
IsIso (h.unit.app Y) :=
(isIso_unit_app_iff_mem_essImage h).mpr ⟨X, ⟨e.symm⟩⟩
instance [R.IsEquivalence] : IsIso h.unit := by
have := fun Y => isIso_unit_app_of_iso h (R.objObjPreimageIso Y).symm
apply NatIso.isIso_of_isIso_app
instance [L.IsEquivalence] : IsIso h.counit := by
have := fun X => isIso_counit_app_of_iso h (L.objObjPreimageIso X).symm
apply NatIso.isIso_of_isIso_app
lemma isEquivalence_left_of_isEquivalence_right (h : L ⊣ R) [R.IsEquivalence] : L.IsEquivalence :=
h.toEquivalence.isEquivalence_functor
lemma isEquivalence_right_of_isEquivalence_left (h : L ⊣ R) [L.IsEquivalence] : R.IsEquivalence :=
h.toEquivalence.isEquivalence_inverse
instance [L.IsEquivalence] : IsIso h.unit := by
have := h.isEquivalence_right_of_isEquivalence_left
infer_instance
instance [R.IsEquivalence] : IsIso h.counit := by
have := h.isEquivalence_left_of_isEquivalence_right
infer_instance
end CategoryTheory.Adjunction
|
CategoryTheory\Adjunction\Lifting.lean | /-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import Mathlib.CategoryTheory.Limits.Shapes.Equalizers
import Mathlib.CategoryTheory.Limits.Shapes.Reflexive
import Mathlib.CategoryTheory.Monad.Adjunction
import Mathlib.CategoryTheory.Monad.Coequalizer
/-!
# Adjoint lifting
This file gives two constructions for building left adjoints: the adjoint triangle theorem and the
adjoint lifting theorem.
The adjoint triangle theorem concerns a functor `U : B ⥤ C` with a left adjoint `F` such
that `ε_X : FUX ⟶ X` is a regular epi. Then for any category `A` with coequalizers of reflexive
pairs, a functor `R : A ⥤ B` has a left adjoint if (and only if) the composite `R ⋙ U` does.
Note that the condition on `U` regarding `ε_X` is automatically satisfied in the case when `U` is
a monadic functor, giving the corollary: `monadicAdjointTriangleLift`, i.e. if `U` is monadic,
`A` has reflexive coequalizers then `R : A ⥤ B` has a left adjoint provided `R ⋙ U` does.
The adjoint lifting theorem says that given a commutative square of functors (up to isomorphism):
Q
A → B
U ↓ ↓ V
C → D
R
where `U` and `V` are monadic and `A` has reflexive coequalizers, then if `R` has a left adjoint
then `Q` has a left adjoint.
## Implementation
It is more convenient to prove this theorem by assuming we are given the explicit adjunction rather
than just a functor known to be a right adjoint. In docstrings, we write `(η, ε)` for the unit
and counit of the adjunction `adj₁ : F ⊣ U` and `(ι, δ)` for the unit and counit of the adjunction
`adj₂ : F' ⊣ R ⋙ U`.
## TODO
Dualise to lift right adjoints through comonads (by reversing 1-cells) and dualise to lift right
adjoints through monads (by reversing 2-cells), and the combination.
## References
* https://ncatlab.org/nlab/show/adjoint+triangle+theorem
* https://ncatlab.org/nlab/show/adjoint+lifting+theorem
* Adjoint Lifting Theorems for Categories of Algebras (PT Johnstone, 1975)
* A unified approach to the lifting of adjoints (AJ Power, 1988)
-/
namespace CategoryTheory
open Category Limits
universe v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄
variable {A : Type u₁} {B : Type u₂} {C : Type u₃}
variable [Category.{v₁} A] [Category.{v₂} B] [Category.{v₃} C]
-- Hide implementation details in this namespace
namespace LiftAdjoint
variable {U : B ⥤ C} {F : C ⥤ B} (R : A ⥤ B) (F' : C ⥤ A)
variable (adj₁ : F ⊣ U) (adj₂ : F' ⊣ R ⋙ U)
/-- To show that `ε_X` is a coequalizer for `(FUε_X, ε_FUX)`, it suffices to assume it's always a
coequalizer of something (i.e. a regular epi).
-/
def counitCoequalises [∀ X : B, RegularEpi (adj₁.counit.app X)] (X : B) :
IsColimit (Cofork.ofπ (adj₁.counit.app X) (adj₁.counit_naturality _)) :=
Cofork.IsColimit.mk' _ fun s => by
refine ⟨(RegularEpi.desc' (adj₁.counit.app X) s.π ?_).1, ?_, ?_⟩
· rw [← cancel_epi (adj₁.counit.app (RegularEpi.W (adj₁.counit.app X)))]
rw [← adj₁.counit_naturality_assoc RegularEpi.left]
dsimp only [Functor.comp_obj]
rw [← s.condition, ← F.map_comp_assoc, ← U.map_comp, RegularEpi.w, U.map_comp,
F.map_comp_assoc, s.condition, ← adj₁.counit_naturality_assoc RegularEpi.right]
· apply (RegularEpi.desc' (adj₁.counit.app X) s.π _).2
· intro m hm
rw [← cancel_epi (adj₁.counit.app X)]
apply hm.trans (RegularEpi.desc' (adj₁.counit.app X) s.π _).2.symm
/-- (Implementation)
To construct the left adjoint, we use the coequalizer of `F' U ε_Y` with the composite
`F' U F U X ⟶ F' U F U R F U' X ⟶ F' U R F' U X ⟶ F' U X`
where the first morphism is `F' U F ι_UX`, the second is `F' U ε_RF'UX`, and the third is `δ_F'UX`.
We will show that this coequalizer exists and that it forms the object map for a left adjoint to
`R`.
-/
def otherMap (X) : F'.obj (U.obj (F.obj (U.obj X))) ⟶ F'.obj (U.obj X) :=
F'.map (U.map (F.map (adj₂.unit.app _) ≫ adj₁.counit.app _)) ≫ adj₂.counit.app _
/-- `(F'Uε_X, otherMap X)` is a reflexive pair: in particular if `A` has reflexive coequalizers then
it has a coequalizer.
-/
instance (X : B) :
IsReflexivePair (F'.map (U.map (adj₁.counit.app X))) (otherMap _ _ adj₁ adj₂ X) :=
IsReflexivePair.mk' (F'.map (adj₁.unit.app (U.obj X)))
(by
rw [← F'.map_comp, adj₁.right_triangle_components]
apply F'.map_id)
(by
dsimp [otherMap]
rw [← F'.map_comp_assoc, U.map_comp, adj₁.unit_naturality_assoc,
adj₁.right_triangle_components, comp_id, adj₂.left_triangle_components])
variable [HasReflexiveCoequalizers A]
/-- Construct the object part of the desired left adjoint as the coequalizer of `F'Uε_Y` with
`otherMap`.
-/
noncomputable def constructLeftAdjointObj (Y : B) : A :=
coequalizer (F'.map (U.map (adj₁.counit.app Y))) (otherMap _ _ adj₁ adj₂ Y)
/-- The homset equivalence which helps show that `R` is a right adjoint. -/
@[simps!] -- Porting note: Originally `@[simps (config := { rhsMd := semireducible })]`
noncomputable def constructLeftAdjointEquiv [∀ X : B, RegularEpi (adj₁.counit.app X)] (Y : A)
(X : B) : (constructLeftAdjointObj _ _ adj₁ adj₂ X ⟶ Y) ≃ (X ⟶ R.obj Y) :=
calc
(constructLeftAdjointObj _ _ adj₁ adj₂ X ⟶ Y) ≃
{ f : F'.obj (U.obj X) ⟶ Y //
F'.map (U.map (adj₁.counit.app X)) ≫ f = otherMap _ _ adj₁ adj₂ _ ≫ f } :=
Cofork.IsColimit.homIso (colimit.isColimit _) _
_ ≃ { g : U.obj X ⟶ U.obj (R.obj Y) //
U.map (F.map g ≫ adj₁.counit.app _) = U.map (adj₁.counit.app _) ≫ g } := by
apply (adj₂.homEquiv _ _).subtypeEquiv _
intro f
rw [← (adj₂.homEquiv _ _).injective.eq_iff, eq_comm, adj₂.homEquiv_naturality_left,
otherMap, assoc, adj₂.homEquiv_naturality_left, ← adj₂.counit_naturality,
adj₂.homEquiv_naturality_left, adj₂.homEquiv_unit, adj₂.right_triangle_components,
comp_id, Functor.comp_map, ← U.map_comp, assoc, ← adj₁.counit_naturality,
adj₂.homEquiv_unit, adj₂.homEquiv_unit, F.map_comp, assoc]
rfl
_ ≃ { z : F.obj (U.obj X) ⟶ R.obj Y // _ } := by
apply (adj₁.homEquiv _ _).symm.subtypeEquiv
intro g
rw [← (adj₁.homEquiv _ _).symm.injective.eq_iff, adj₁.homEquiv_counit,
adj₁.homEquiv_counit, adj₁.homEquiv_counit, F.map_comp, assoc, U.map_comp, F.map_comp,
assoc, adj₁.counit_naturality, adj₁.counit_naturality_assoc]
apply eq_comm
_ ≃ (X ⟶ R.obj Y) := (Cofork.IsColimit.homIso (counitCoequalises adj₁ X) _).symm
/-- Construct the left adjoint to `R`, with object map `constructLeftAdjointObj`. -/
noncomputable def constructLeftAdjoint [∀ X : B, RegularEpi (adj₁.counit.app X)] : B ⥤ A := by
refine Adjunction.leftAdjointOfEquiv (fun X Y => constructLeftAdjointEquiv R _ adj₁ adj₂ Y X) ?_
intro X Y Y' g h
rw [constructLeftAdjointEquiv_apply, constructLeftAdjointEquiv_apply,
Equiv.symm_apply_eq, Subtype.ext_iff]
dsimp
-- This used to be `rw`, but we need `erw` after leanprover/lean4#2644
erw [Cofork.IsColimit.homIso_natural, Cofork.IsColimit.homIso_natural]
erw [adj₂.homEquiv_naturality_right]
simp_rw [Functor.comp_map]
-- This used to be `simp`, but we need `aesop_cat` after leanprover/lean4#2644
aesop_cat
end LiftAdjoint
/-- The adjoint triangle theorem: Suppose `U : B ⥤ C` has a left adjoint `F` such that each counit
`ε_X : FUX ⟶ X` is a regular epimorphism. Then if a category `A` has coequalizers of reflexive
pairs, then a functor `R : A ⥤ B` has a left adjoint if the composite `R ⋙ U` does.
Note the converse is true (with weaker assumptions), by `Adjunction.comp`.
See https://ncatlab.org/nlab/show/adjoint+triangle+theorem
-/
lemma adjointTriangleLift {U : B ⥤ C} {F : C ⥤ B} (R : A ⥤ B) (adj₁ : F ⊣ U)
[∀ X : B, RegularEpi (adj₁.counit.app X)] [HasReflexiveCoequalizers A]
[(R ⋙ U).IsRightAdjoint ] : R.IsRightAdjoint where
exists_leftAdjoint :=
⟨LiftAdjoint.constructLeftAdjoint R _ adj₁ (Adjunction.ofIsRightAdjoint _),
⟨Adjunction.adjunctionOfEquivLeft _ _⟩⟩
/-- If `R ⋙ U` has a left adjoint, the domain of `R` has reflexive coequalizers and `U` is a monadic
functor, then `R` has a left adjoint.
This is a special case of `adjointTriangleLift` which is often more useful in practice.
-/
lemma monadicAdjointTriangleLift (U : B ⥤ C) [MonadicRightAdjoint U] {R : A ⥤ B}
[HasReflexiveCoequalizers A] [(R ⋙ U).IsRightAdjoint] : R.IsRightAdjoint := by
let R' : A ⥤ _ := R ⋙ Monad.comparison (monadicAdjunction U)
rsuffices : R'.IsRightAdjoint
· let this : (R' ⋙ (Monad.comparison (monadicAdjunction U)).inv).IsRightAdjoint := by
infer_instance
refine ((Adjunction.ofIsRightAdjoint
(R' ⋙ (Monad.comparison (monadicAdjunction U)).inv)).ofNatIsoRight ?_).isRightAdjoint
exact isoWhiskerLeft R (Monad.comparison _).asEquivalence.unitIso.symm ≪≫ R.rightUnitor
let this : (R' ⋙ Monad.forget (monadicAdjunction U).toMonad).IsRightAdjoint := by
refine ((Adjunction.ofIsRightAdjoint (R ⋙ U)).ofNatIsoRight ?_).isRightAdjoint
exact isoWhiskerLeft R (Monad.comparisonForget (monadicAdjunction U)).symm
let this : ∀ X, RegularEpi ((Monad.adj (monadicAdjunction U).toMonad).counit.app X) := by
intro X
simp only [Monad.adj_counit]
exact ⟨_, _, _, _, Monad.beckAlgebraCoequalizer X⟩
exact adjointTriangleLift R' (Monad.adj _)
variable {D : Type u₄}
variable [Category.{v₄} D]
/-- Suppose we have a commutative square of functors
Q
A → B
U ↓ ↓ V
C → D
R
where `U` has a left adjoint, `A` has reflexive coequalizers and `V` has a left adjoint such that
each component of the counit is a regular epi.
Then `Q` has a left adjoint if `R` has a left adjoint.
See https://ncatlab.org/nlab/show/adjoint+lifting+theorem
-/
lemma adjointSquareLift (Q : A ⥤ B) (V : B ⥤ D) (U : A ⥤ C) (R : C ⥤ D)
(comm : U ⋙ R ≅ Q ⋙ V) [U.IsRightAdjoint] [V.IsRightAdjoint] [R.IsRightAdjoint]
[∀ X, RegularEpi ((Adjunction.ofIsRightAdjoint V).counit.app X)] [HasReflexiveCoequalizers A] :
Q.IsRightAdjoint :=
have := ((Adjunction.ofIsRightAdjoint (U ⋙ R)).ofNatIsoRight comm).isRightAdjoint
adjointTriangleLift Q (Adjunction.ofIsRightAdjoint V)
/-- Suppose we have a commutative square of functors
Q
A → B
U ↓ ↓ V
C → D
R
where `U` has a left adjoint, `A` has reflexive coequalizers and `V` is monadic.
Then `Q` has a left adjoint if `R` has a left adjoint.
See https://ncatlab.org/nlab/show/adjoint+lifting+theorem
-/
lemma monadicAdjointSquareLift (Q : A ⥤ B) (V : B ⥤ D) (U : A ⥤ C) (R : C ⥤ D)
(comm : U ⋙ R ≅ Q ⋙ V) [U.IsRightAdjoint] [MonadicRightAdjoint V] [R.IsRightAdjoint]
[HasReflexiveCoequalizers A] : Q.IsRightAdjoint :=
have := ((Adjunction.ofIsRightAdjoint (U ⋙ R)).ofNatIsoRight comm).isRightAdjoint
monadicAdjointTriangleLift V
end CategoryTheory
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.