Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit f5060c4

Browse files
authored
feat(category_theory/limits): support for special shapes of (co)limits (#938)
feat(category_theory/limits): support for special shapes of (co)limits
1 parent 219cb1a commit f5060c4

10 files changed

Lines changed: 586 additions & 2 deletions

File tree

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import category_theory.instances.Top.limits
2+
import category_theory.limits.shapes
3+
import topology.instances.real
4+
5+
/- This file contains some demos of using the (co)limits API to do topology. -/
6+
7+
noncomputable theory
8+
9+
open category_theory
10+
open category_theory.instances
11+
open category_theory.limits
12+
13+
def R : Top := Top.of ℝ
14+
def I : Top := Top.of (set.Icc 0 1 : set ℝ)
15+
def pt : Top := Top.of unit
16+
17+
section MappingCylinder
18+
-- Let's construct the mapping cylinder.
19+
def to_pt (X : Top) : X ⟶ pt :=
20+
{ val := λ _, unit.star, property := continuous_const }
21+
def I_0 : pt ⟶ I :=
22+
{ val := λ _, ⟨(0 : ℝ), begin rw [set.left_mem_Icc], norm_num, end⟩,
23+
property := continuous_const }
24+
def I_1 : pt ⟶ I :=
25+
{ val := λ _, ⟨(1 : ℝ), begin rw [set.right_mem_Icc], norm_num, end⟩,
26+
property := continuous_const }
27+
28+
def cylinder (X : Top) : Top := limit (pair X I)
29+
-- To define a map to the cylinder, we give a map to each factor.
30+
-- `binary_fan.mk` is a helper method for constructing a `cone` over `pair X Y`.
31+
def cylinder_0 (X : Top) : X ⟶ cylinder X :=
32+
limit.lift (pair X I) (binary_fan.mk (𝟙 X) (to_pt X ≫ I_0))
33+
def cylinder_1 (X : Top) : X ⟶ cylinder X :=
34+
limit.lift (pair X I) (binary_fan.mk (𝟙 X) (to_pt X ≫ I_1))
35+
36+
-- The mapping cylinder is the colimit of the diagram
37+
-- X
38+
-- ↙ ↘
39+
-- Y (X x I)
40+
def mapping_cylinder {X Y : Top} (f : X ⟶ Y) : Top := colimit (span f (cylinder_1 X))
41+
42+
-- The mapping cone is the colimit of the diagram
43+
-- X X
44+
-- ↙ ↘ ↙ ↘
45+
-- Y (X x I) pt
46+
-- Here we'll calculate it as an iterated colimit, as the colimit of
47+
-- X
48+
-- ↙ ↘
49+
-- (Cyl f) pt
50+
51+
def mapping_cylinder_0 {X Y : Top} (f : X ⟶ Y) : X ⟶ mapping_cylinder f :=
52+
cylinder_0 X ≫ colimit.ι (span f (cylinder_1 X)) walking_span.right
53+
54+
def mapping_cone {X Y : Top} (f : X ⟶ Y) : Top := colimit (span (mapping_cylinder_0 f) (to_pt X))
55+
56+
-- TODO Hopefully someone will write a nice tactic for generating diagrams quickly,
57+
-- and we'll be able to verify that this iterated construction is the same as the colimit
58+
-- over a single diagram.
59+
end MappingCylinder
60+
61+
section Gluing
62+
63+
-- Here's two copies of the real line glued together at a point.
64+
def f : pt ⟶ R := { val := λ _, (0 : ℝ), property := continuous_const }
65+
def X : Top := colimit (span f f)
66+
67+
-- To define a map out of it, we define maps out of each copy of the line,
68+
-- and check the maps agree at 0.
69+
-- `pushout_cocone.mk` is a helper method for constructing cocones over a span.
70+
def g : X ⟶ R :=
71+
colimit.desc (span f f) (pushout_cocone.mk (𝟙 _) (𝟙 _) rfl).
72+
73+
end Gluing
74+
75+
universes v u w
76+
77+
section Products
78+
79+
def d : discrete ℕ ⥤ Top := functor.of_function (λ n : ℕ, R)
80+
81+
def Y : Top := limit d
82+
83+
def w : cone d := fan.mk (λ (n : ℕ), ⟨λ (_ : pt), (n : ℝ), continuous_const⟩)
84+
85+
def q : pt ⟶ Y :=
86+
limit.lift d w
87+
88+
example : (q.val ()).val (57 : ℕ) = ((57 : ℕ) : ℝ) := rfl
89+
90+
end Products

src/category_theory/discrete_category.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ def lift {α : Type u₁} {β : Type u₂} (f : α → β) : (discrete α) ⥤ (
4848
functor.of_function f
4949

5050
include 𝒞
51-
variables (J : Type v₂)
51+
variables {J : Type v₁}
5252

5353
@[simp] lemma functor_map_id
54-
(F : discrete J ⥤ C) (j : discrete J) (f : j ⟶ j) : F.map f = 𝟙 (F.obj j) :=
54+
(F : discrete J ⥤ C) {j : discrete J} (f : j ⟶ j) : F.map f = 𝟙 (F.obj j) :=
5555
begin
5656
have h : f = 𝟙 j, cases f, cases f, ext,
5757
rw h,

src/category_theory/instances/Top/basic.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ instance topological_space_unbundled (x : Top) : topological_space x := x.str
2020
namespace Top
2121
instance concrete_category_continuous : concrete_category @continuous := ⟨@continuous_id, @continuous.comp⟩
2222

23+
def of (X : Type u) [topological_space X] : Top := ⟨X, by apply_instance⟩
24+
2325
def discrete : Type u ⥤ Top.{u} :=
2426
{ obj := λ X, ⟨X, ⊤⟩,
2527
map := λ X Y f, ⟨f, continuous_top⟩ }
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
-- Copyright (c) 2018 Scott Morrison. All rights reserved.
2+
-- Released under Apache 2.0 license as described in the file LICENSE.
3+
-- Authors: Scott Morrison
4+
5+
import category_theory.limits.cones
6+
import category_theory.discrete_category
7+
8+
universes v u
9+
10+
open category_theory
11+
12+
namespace category_theory.limits
13+
14+
@[derive decidable_eq] inductive walking_pair : Type v
15+
| left | right
16+
17+
def pair_function {C : Sort u} (X Y : C) : walking_pair → C
18+
| walking_pair.left := X
19+
| walking_pair.right := Y
20+
21+
variables {C : Sort u} [𝒞 : category.{v+1} C]
22+
include 𝒞
23+
24+
def pair (X Y : C) : discrete walking_pair ⥤ C :=
25+
functor.of_function (pair_function X Y)
26+
27+
abbreviation binary_fan (X Y : C) := cone (pair X Y)
28+
abbreviation binary_cofan (X Y : C) := cocone (pair X Y)
29+
30+
variables {X Y : C}
31+
32+
def binary_fan.mk {P : C} (π₁ : P ⟶ X) (π₂ : P ⟶ Y) : binary_fan X Y :=
33+
{ X := P,
34+
π := { app := λ j, walking_pair.cases_on j π₁ π₂ }}
35+
def binary_cofan.mk {P : C} (ι₁ : X ⟶ P) (ι₂ : Y ⟶ P) : binary_cofan X Y :=
36+
{ X := P,
37+
ι := { app := λ j, walking_pair.cases_on j ι₁ ι₂ }}
38+
39+
end category_theory.limits
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- Copyright (c) 2019 Scott Morrison. All rights reserved.
2+
-- Released under Apache 2.0 license as described in the file LICENSE.
3+
-- Authors: Scott Morrison
4+
5+
import category_theory.limits.shapes.binary_products
6+
import category_theory.limits.shapes.products
7+
import category_theory.limits.shapes.equalizers
8+
import category_theory.limits.shapes.pullbacks
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
-- Copyright (c) 2018 Scott Morrison. All rights reserved.
2+
-- Released under Apache 2.0 license as described in the file LICENSE.
3+
-- Authors: Scott Morrison
4+
5+
import category_theory.eq_to_hom
6+
import category_theory.limits.cones
7+
8+
open category_theory
9+
10+
namespace category_theory.limits
11+
12+
local attribute [tidy] tactic.case_bash
13+
14+
universes v u
15+
16+
@[derive decidable_eq] inductive walking_parallel_pair : Type v
17+
| zero | one
18+
19+
open walking_parallel_pair
20+
21+
inductive walking_parallel_pair_hom : walking_parallel_pair → walking_parallel_pair → Type v
22+
| left : walking_parallel_pair_hom zero one
23+
| right : walking_parallel_pair_hom zero one
24+
| id : Π X : walking_parallel_pair.{v}, walking_parallel_pair_hom X X
25+
26+
open walking_parallel_pair_hom
27+
28+
def walking_parallel_pair_hom.comp :
29+
Π (X Y Z : walking_parallel_pair)
30+
(f : walking_parallel_pair_hom X Y) (g : walking_parallel_pair_hom Y Z),
31+
walking_parallel_pair_hom X Z
32+
| _ _ _ (id _) h := h
33+
| _ _ _ left (id one) := left
34+
| _ _ _ right (id one) := right
35+
.
36+
37+
instance walking_parallel_pair_hom_category : small_category.{v+1} walking_parallel_pair :=
38+
{ hom := walking_parallel_pair_hom,
39+
id := walking_parallel_pair_hom.id,
40+
comp := walking_parallel_pair_hom.comp }
41+
42+
lemma walking_parallel_pair_hom_id (X : walking_parallel_pair.{v}) :
43+
walking_parallel_pair_hom.id X = 𝟙 X :=
44+
rfl
45+
46+
variables {C : Sort u} [𝒞 : category.{v+1} C]
47+
include 𝒞
48+
variables {X Y : C}
49+
50+
def parallel_pair (f g : X ⟶ Y) : walking_parallel_pair.{v} ⥤ C :=
51+
{ obj := λ x, match x with
52+
| zero := X
53+
| one := Y
54+
end,
55+
map := λ x y h, match x, y, h with
56+
| _, _, (id _) := 𝟙 _
57+
| _, _, left := f
58+
| _, _, right := g
59+
end }.
60+
61+
@[simp] lemma parallel_pair_map_left (f g : X ⟶ Y) : (parallel_pair f g).map left = f := rfl
62+
@[simp] lemma parallel_pair_map_right (f g : X ⟶ Y) : (parallel_pair f g).map right = g := rfl
63+
64+
@[simp] lemma parallel_pair_functor_obj
65+
{F : walking_parallel_pair.{v} ⥤ C} (j : walking_parallel_pair.{v}) :
66+
(parallel_pair (F.map left) (F.map right)).obj j = F.obj j :=
67+
begin
68+
cases j; refl
69+
end
70+
71+
abbreviation fork (f g : X ⟶ Y) := cone (parallel_pair f g)
72+
abbreviation cofork (f g : X ⟶ Y) := cocone (parallel_pair f g)
73+
74+
variables {f g : X ⟶ Y}
75+
76+
attribute [simp] walking_parallel_pair_hom_id
77+
78+
def fork.of_ι {P : C} (ι : P ⟶ X) (w : ι ≫ f = ι ≫ g) : fork f g :=
79+
{ X := P,
80+
π :=
81+
{ app := λ X, begin cases X, exact ι, exact ι ≫ f, end,
82+
naturality' := λ X Y f,
83+
begin
84+
cases X; cases Y; cases f; dsimp; simp,
85+
exact w
86+
end }}
87+
def cofork.of_π {P : C} (π : Y ⟶ P) (w : f ≫ π = g ≫ π) : cofork f g :=
88+
{ X := P,
89+
ι :=
90+
{ app := λ X, begin cases X, exact f ≫ π, exact π, end,
91+
naturality' := λ X Y f,
92+
begin
93+
cases X; cases Y; cases f; dsimp; simp,
94+
exact eq.symm w
95+
end }}
96+
97+
@[simp] lemma fork.of_ι_app_zero {P : C} (ι : P ⟶ X) (w : ι ≫ f = ι ≫ g) :
98+
(fork.of_ι ι w).π.app zero = ι := rfl
99+
@[simp] lemma fork.of_ι_app_one {P : C} (ι : P ⟶ X) (w : ι ≫ f = ι ≫ g) :
100+
(fork.of_ι ι w).π.app one = ι ≫ f := rfl
101+
102+
def fork.ι (t : fork f g) := t.π.app zero
103+
def cofork.π (t : cofork f g) := t.ι.app one
104+
def fork.condition (t : fork f g) : (fork.ι t) ≫ f = (fork.ι t) ≫ g :=
105+
begin
106+
erw [t.w left, ← t.w right], refl
107+
end
108+
def cofork.condition (t : cofork f g) : f ≫ (cofork.π t) = g ≫ (cofork.π t) :=
109+
begin
110+
erw [t.w left, ← t.w right], refl
111+
end
112+
113+
def cone.of_fork
114+
{F : walking_parallel_pair.{v} ⥤ C} (t : fork (F.map left) (F.map right)) : cone F :=
115+
{ X := t.X,
116+
π :=
117+
{ app := λ X, t.π.app X ≫ eq_to_hom (by tidy),
118+
naturality' := λ j j' g,
119+
begin
120+
cases j; cases j'; cases g; dsimp; simp,
121+
erw ← t.w left, refl,
122+
erw ← t.w right, refl,
123+
end } }.
124+
def cocone.of_cofork
125+
{F : walking_parallel_pair.{v} ⥤ C} (t : cofork (F.map left) (F.map right)) : cocone F :=
126+
{ X := t.X,
127+
ι :=
128+
{ app := λ X, eq_to_hom (by tidy) ≫ t.ι.app X,
129+
naturality' := λ j j' g,
130+
begin
131+
cases j; cases j'; cases g; dsimp; simp,
132+
erw ← t.w left, refl,
133+
erw ← t.w right, refl,
134+
end } }.
135+
136+
@[simp] lemma cone.of_fork_π
137+
{F : walking_parallel_pair.{v} ⥤ C} (t : fork (F.map left) (F.map right)) (j):
138+
(cone.of_fork t).π.app j = t.π.app j ≫ eq_to_hom (by tidy) := rfl
139+
140+
@[simp] lemma cocone.of_cofork_ι
141+
{F : walking_parallel_pair.{v} ⥤ C} (t : cofork (F.map left) (F.map right)) (j):
142+
(cocone.of_cofork t).ι.app j = eq_to_hom (by tidy) ≫ t.ι.app j := rfl
143+
144+
def fork.of_cone
145+
{F : walking_parallel_pair.{v} ⥤ C} (t : cone F) : fork (F.map left) (F.map right) :=
146+
{ X := t.X,
147+
π := { app := λ X, t.π.app X ≫ eq_to_hom (by tidy) } }
148+
def cofork.of_cocone
149+
{F : walking_parallel_pair.{v} ⥤ C} (t : cocone F) : cofork (F.map left) (F.map right) :=
150+
{ X := t.X,
151+
ι := { app := λ X, eq_to_hom (by tidy) ≫ t.ι.app X } }
152+
153+
@[simp] lemma fork.of_cone_π {F : walking_parallel_pair.{v} ⥤ C} (t : cone F) (j) :
154+
(fork.of_cone t).π.app j = t.π.app j ≫ eq_to_hom (by tidy) := rfl
155+
@[simp] lemma cofork.of_cocone_ι {F : walking_parallel_pair.{v} ⥤ C} (t : cocone F) (j) :
156+
(cofork.of_cocone t).ι.app j = eq_to_hom (by tidy) ≫ t.ι.app j := rfl
157+
158+
end category_theory.limits
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
-- Copyright (c) 2018 Scott Morrison. All rights reserved.
2+
-- Released under Apache 2.0 license as described in the file LICENSE.
3+
-- Authors: Scott Morrison
4+
5+
import category_theory.limits.cones
6+
import category_theory.discrete_category
7+
8+
universes v u
9+
10+
open category_theory
11+
12+
namespace category_theory.limits
13+
14+
variables {β : Type v}
15+
variables {C : Sort u} [𝒞 : category.{v+1} C]
16+
include 𝒞
17+
18+
-- We don't need an analogue of `pair` (for binary products), `parallel_pair` (for equalizers),
19+
-- or `(co)span`, since we already have `functor.of_function`.
20+
21+
abbreviation fan (f : β → C) := cone (functor.of_function f)
22+
abbreviation cofan (f : β → C) := cocone (functor.of_function f)
23+
24+
def fan.mk {f : β → C} {P : C} (p : Π b, P ⟶ f b) : fan f :=
25+
{ X := P,
26+
π := { app := p } }
27+
28+
def cofan.mk {f : β → C} {P : C} (p : Π b, f b ⟶ P) : cofan f :=
29+
{ X := P,
30+
ι := { app := p } }
31+
32+
end category_theory.limits

0 commit comments

Comments
 (0)