Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(category_theory): basic definitions #152

Merged
merged 40 commits into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
933f4a0
feat(category_theory): basic definitions
Jun 4, 2018
46e694c
fixing formatting in documentation
Jun 4, 2018
88dd1f0
corrections from review
semorrison Jun 4, 2018
4341b14
removing second ematch attribute on associativity_lemma
semorrison Jun 4, 2018
26dde34
being slightly more careful about variables
semorrison Jun 4, 2018
062d55f
fix(notation): transformation components
semorrison Jun 15, 2018
456594a
fix(notation): more conventional notation for composition
semorrison Jun 15, 2018
eb4dc51
Merge branch 'master' into category_theory
semorrison Jun 20, 2018
efe51ee
adjusting namespaces, capitalisation, and headers
semorrison Jul 2, 2018
fff0238
move functor/default.lean to functor.lean
Jul 27, 2018
ce7194d
oops
Jul 27, 2018
c46e78b
fixing indentation
Jul 27, 2018
0205498
namespace for instances
Jul 27, 2018
e2d0ca4
removing unnecessary `@>` notation for natural transformations
Jul 27, 2018
a949270
Merge commit 'a7b749f0a743ab467e1cb7d688e4a8a0f7a82874' into category…
semorrison Aug 3, 2018
10d77a8
renaming, namespacing, and removing a spurious attribute
Aug 6, 2018
7d3cadd
better naming, namespaces, and coercions
Aug 6, 2018
176a12f
updating documentation
Aug 6, 2018
3eb8c2a
Merge branch 'category_theory' of github.com:semorrison/mathlib into …
semorrison Aug 6, 2018
0e3229d
Merge branch 'master' into category_theory
semorrison Aug 6, 2018
3a49fea
renaming id
Aug 7, 2018
14117a0
reordering definitions
Aug 7, 2018
c030b8d
Merge branch 'category_theory' of github.com:semorrison/mathlib into …
Aug 7, 2018
2b4621d
rfl lemmas for has_one
Aug 7, 2018
433aae7
formatting
Aug 7, 2018
52ed9b7
formatting
Aug 7, 2018
ac4b311
renaming: snake_case
Aug 7, 2018
c3984f0
renaming coe rfl lemmas
Aug 7, 2018
b68bc6e
functoriality -> map_comp
Aug 7, 2018
8f59e1a
rfl lemmas for identity C and identity F (reducing both to `1`)
Aug 7, 2018
d23e348
renaming ext lemma to `ext`
Aug 7, 2018
e29fda0
rename `natural_transformation` to `nat_trans`
Aug 7, 2018
b832f05
rename `make_lemma` to `restate_axiom`
Aug 7, 2018
cb93d51
renaming nat_trans.components to nat_trans.app
Aug 7, 2018
eaac4c0
oops, fix import
Aug 7, 2018
1ce8b0a
adding doc_comments, and `protected`
Aug 7, 2018
14ba452
formatting
Aug 7, 2018
18db512
removing `has_one` instances, per zulip chat, and adding a `vcomp.ass…
Aug 7, 2018
3aa69cb
removing the attribute that `restate_axiom` used to add
semorrison Aug 7, 2018
569241e
fixing names
semorrison Aug 7, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions category_theory/category.lean
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ local notation f ` ⊚ `:80 g:80 := category.comp g f -- type as \oo
```
-/

import tactic.make_lemma
import tactic.restate_axiom
import tactic.interactive

namespace category_theory
Expand Down Expand Up @@ -43,9 +43,9 @@ infixr ` ≫ `:80 := category.comp -- type as \gg
infixr ` ⟶ `:10 := category.Hom -- type as \h

-- make_lemma is a command that creates a lemma from a structure field, discarding all auto_param wrappers from the type.
make_lemma category.id_comp
make_lemma category.comp_id
make_lemma category.assoc
restate_axiom category.id_comp
restate_axiom category.comp_id
restate_axiom category.assoc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed a spot (make_lemma)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

-- We tag some lemmas with the attribute `@[ematch]`, for later automation. (I'd be happy to change this to e.g. `@[search]`.)
attribute [simp,ematch] category.id_comp_lemma category.comp_id_lemma category.assoc_lemma

Expand Down
8 changes: 4 additions & 4 deletions category_theory/functor.lean
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ structure functor (C : Type u₁) [category.{u₁ v₁} C] (D : Type u₂) [cate
(map_id : ∀ (X : C), map (𝟙 X) = 𝟙 (obj X) . obviously)
(map_comp : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z), map (f ≫ g) = (map f) ≫ (map g) . obviously)

make_lemma functor.map_id
make_lemma functor.map_comp
restate_axiom functor.map_id
restate_axiom functor.map_comp
attribute [simp,ematch] functor.map_id_lemma functor.map_comp_lemma

infixr ` ↝ `:70 := functor -- type as \lea --
Expand Down Expand Up @@ -60,8 +60,8 @@ instance has_one : has_one (C ↝ C) :=

variable {C}

@[simp] lemma identity.on_objects (X : C) : (identity C) X = X := rfl
@[simp] lemma identity.on_morphisms {X Y : C} (f : X ⟶ Y) : (identity C).map f = f := rfl
@[simp] lemma identity_to_has_one : (identity C) = 1 := rfl

@[simp] lemma has_one.on_objects (X : C) : (1 : C ↝ C) X = X := rfl
@[simp] lemma has_one.on_morphisms {X Y : C} (f : X ⟶ Y) : (1 : C ↝ C).map f = f := rfl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need both of these? I would prefer to have identity simplify to 1 so that we only need the second set of lemmas. Unless you are having similar problems as with simp under coe, but I don't think this should happen.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My inclination is to actually remove entirely the has_one instances. I think they're more cosmetic than useful. What do you think?

What is the relation between this identity and the \b1 symbol? I would like to have some kind of symbol for this which is one-like. But it doesn't hurt to have a has_one instance as well; just pick one or the other to be the "idiomatic" one and use it in all your statements, and have a simp lemma from any alternative ways to write it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I missed this comment. identity is an "outside" identity, that is C.identity is the identity functor from C to itself. id (and the \b1 symbol) are for the identities "inside" a category, e.g. category.id X is a morphism from the object X to itself.

I agree it would be nice to be clearer here. Suggestions for renamings very welcome!

Copy link
Member

@digama0 digama0 Aug 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about functor.id (protected)? I can live with C.id as a notation, does that work for you?

Edit: oh wait, C is a category not a functor. I can still live with functor.id C, unless there is a good reason to further abbreviate it.


Expand Down
39 changes: 20 additions & 19 deletions category_theory/natural_transformation.lean
Original file line number Diff line number Diff line change
Expand Up @@ -21,39 +21,40 @@ universes u₁ v₁ u₂ v₂ u₃ v₃
variables {C : Type u₁} [𝒞 : category.{u₁ v₁} C] {D : Type u₂} [𝒟 : category.{u₂ v₂} D]
include 𝒞 𝒟

structure natural_transformation (F G : C ↝ D) : Type (max u₁ v₂) :=
(components : Π X : C, (F X) ⟶ (G X))
(naturality : ∀ {X Y : C} (f : X ⟶ Y), (F.map f) ≫ (components Y) = (components X) ≫ (G.map f) . obviously)
structure nat_trans (F G : C ↝ D) : Type (max u₁ v₂) :=
(app : Π X : C, (F X) ⟶ (G X))
(naturality : ∀ {X Y : C} (f : X ⟶ Y), (F.map f) ≫ (app Y) = (app X) ≫ (G.map f) . obviously)

make_lemma natural_transformation.naturality
attribute [ematch] natural_transformation.naturality_lemma
restate_axiom nat_trans.naturality
attribute [ematch] nat_trans.naturality_lemma

infixr ` ⟹ `:50 := natural_transformation -- type as \==> or ⟹
infixr ` ⟹ `:50 := nat_trans -- type as \==> or ⟹

namespace natural_transformation
namespace nat_trans

instance {F G : C ↝ D} : has_coe_to_fun (F ⟹ G) :=
{ F := λ α, Π X : C, (F X) ⟶ (G X),
coe := λ α, α.components }
coe := λ α, α.app }

@[simp] lemma coe_def {F G : C ↝ D} (α : F ⟹ G) (X : C) : α X = α.components X := rfl
@[simp] lemma coe_def {F G : C ↝ D} (α : F ⟹ G) (X : C) : α X = α.app X := rfl

end natural_transformation
end nat_trans

namespace functor
definition identity (F : C ↝ D) : F ⟹ F :=
{ components := λ X, 𝟙 (F X),
{ app := λ X, 𝟙 (F X),
naturality := begin /- `obviously'` says: -/ intros, dsimp, simp end }

instance has_one (F : C ↝ D) : has_one (F ⟹ F) :=
{ one := identity F }

@[simp] lemma identity.components (F : C ↝ D) (X : C) : (identity F) X = 𝟙 (F X) := rfl
@[simp] lemma has_one.components (F : C ↝ D) (X : C) : (1 : F ⟹ F) X = 𝟙 (F X) := rfl
@[simp] lemma identity_to_has_one (F : C ↝ D) : identity F = 1 := rfl

@[simp] lemma has_one.app (F : C ↝ D) (X : C) : (1 : F ⟹ F) X = 𝟙 (F X) := rfl

end functor

namespace natural_transformation
namespace nat_trans

open category
open category_theory.functor
Expand All @@ -62,7 +63,7 @@ section
variables {F G H : C ↝ D}

-- We'll want to be able to prove that two natural transformations are equal if they are componentwise equal.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this is an intermezzo between vertical and horizontal composition of natural transformations. Is that on purpose?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it wasn't on purpose; I've rearranged now.

@[extensionality] lemma componentwise_equal (α β : F ⟹ G) (w : ∀ X : C, α X = β X) : α = β :=
@[extensionality] lemma ext (α β : F ⟹ G) (w : ∀ X : C, α X = β X) : α = β :=
begin
induction α with α_components α_naturality,
induction β with β_components β_naturality,
Expand All @@ -71,7 +72,7 @@ begin
end

definition vcomp (α : F ⟹ G) (β : G ⟹ H) : F ⟹ H :=
{ components := λ X, (α X) ≫ (β X),
{ app := λ X, (α X) ≫ (β X),
naturality := begin /- `obviously'` says: -/ intros, simp, rw [←assoc_lemma, naturality_lemma, assoc_lemma, ←naturality_lemma], end }

notation α `⊟` β:80 := vcomp α β
Expand All @@ -84,7 +85,7 @@ variable [ℰ : category.{u₃ v₃} E]
include ℰ

definition hcomp {F G : C ↝ D} {H I : D ↝ E} (α : F ⟹ G) (β : H ⟹ I) : (F ⋙ H) ⟹ (G ⋙ I) :=
{ components := λ X : C, (β (F X)) ≫ (I.map (α X)),
{ app := λ X : C, (β (F X)) ≫ (I.map (α X)),
naturality := begin
/- `obviously'` says: -/
intros,
Expand All @@ -102,13 +103,13 @@ notation α `◫` β:80 := hcomp α β
@[ematch] lemma exchange {F G H : C ↝ D} {I J K : D ↝ E} (α : F ⟹ G) (β : G ⟹ H) (γ : I ⟹ J) (δ : J ⟹ K) : ((α ⊟ β) ◫ (γ ⊟ δ)) = ((α ◫ γ) ⊟ (β ◫ δ)) :=
begin
-- `obviously'` says:
apply componentwise_equal,
ext,
intros,
dsimp,
simp,
-- again, this isn't actually what obviously says, but it achieves the same effect.
conv { to_lhs, congr, skip, rw [←assoc_lemma, ←naturality_lemma, assoc_lemma] }
end

end natural_transformation
end nat_trans
end category_theory
11 changes: 5 additions & 6 deletions tactic/make_lemma.lean → tactic/restate_axiom.lean
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ import data.buffer.parser
open lean.parser tactic interactive parser

@[user_attribute] meta def field_lemma_attr : user_attribute :=
{ name := `field_lemma, descr := "This definition was automatically generated from a structure field by `make_lemma`." }

{ name := `field_lemma, descr := "This definition was automatically generated from a structure field by `restate_axiom`." }

/- Make lemma takes a structure field, and makes a new, definitionally simplified copy of it, appending `_lemma` to the name.
The main application is to provide clean versions of structure fields that have been tagged with an auto_param. -/
meta def make_lemma (d : declaration) (new_name : name) : tactic unit :=
meta def restate_axiom (d : declaration) (new_name : name) : tactic unit :=
do (levels, type, value, reducibility, trusted) ← pure (match d.to_definition with
| declaration.defn name levels type value reducibility trusted :=
(levels, type, value, reducibility, trusted)
Expand All @@ -31,13 +30,13 @@ match n.components.reverse with
| nil := undefined
end

@[user_command] meta def make_lemma_cmd (meta_info : decl_meta_info)
(_ : parse $ tk "make_lemma") : lean.parser unit :=
@[user_command] meta def restate_axiom_cmd (meta_info : decl_meta_info)
(_ : parse $ tk "restate_axiom") : lean.parser unit :=
do from_lemma ← ident,
from_lemma_fully_qualified ← resolve_constant from_lemma,
d ← get_decl from_lemma_fully_qualified <|>
fail ("declaration " ++ to_string from_lemma ++ " not found"),
do {
make_lemma d (name_lemma from_lemma_fully_qualified)
restate_axiom d (name_lemma from_lemma_fully_qualified)
}.