├── .gitignore ├── .project ├── .travis.yml ├── README.md ├── files ├── Screenshot 2018-08-19 01.55.54.png ├── equivalence_full_further.png └── equivalence_full_further2.png ├── interesting-rewrites ├── leanpkg.toml ├── log ├── profile ├── profile.out ├── rewrite_search_examples ├── schemes_roadmap.md ├── src └── category_theory │ ├── abelian │ ├── abelian.lean │ └── monic.lean │ ├── concrete.lean │ ├── enriched.lean │ ├── examples │ ├── categories.lean │ └── graphs.lean │ ├── filtered.lean │ ├── follow_your_nose.lean │ ├── functor │ ├── functorial.lean │ └── isomorphism.lean │ ├── graph_category.lean │ ├── graphs │ ├── category.lean │ └── default.lean │ ├── homological_algebra │ └── chain_complex.lean │ ├── idempotent_completion.lean │ ├── limits │ ├── filtered_limits.lean │ └── obviously.lean │ ├── path_category.lean │ ├── presheaves │ ├── locally_ringed.lean │ ├── map.lean │ ├── sheaves.lean │ └── sheaves_of_types.lean │ ├── projectives │ └── default.lean │ ├── sigma_category.lean │ ├── simplicial_sets │ └── default.lean │ ├── small.lean │ ├── tactics │ └── obviously.lean │ ├── types │ └── functor.lean │ ├── universal │ ├── kernels.lean │ ├── monic.lean │ ├── products.lean │ ├── strongly_concrete.lean │ └── zero.lean │ ├── universe_lifting.lean │ ├── yoneda_comparisons.lean │ └── yoneda_terse.lean └── travis_long.sh /.gitignore: -------------------------------------------------------------------------------- 1 | *.olean 2 | /_target 3 | /leanpkg.path 4 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kim-em/lean-category-theory/1f2bff331a6b1e79fa51df7a843b7ae5383c4160/.project -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | sudo: false 3 | os: 4 | - linux 5 | 6 | cache: 7 | directories: 8 | - $TRAVIS_BUILD_DIR/*/ 9 | - $HOME/.elan 10 | 11 | install: 12 | - | 13 | if [ ! -d "$HOME/.elan/toolchains/" ]; then 14 | curl https://raw.githubusercontent.com/Kha/elan/master/elan-init.sh -sSf | sh -s -- --default-toolchain none -y 15 | fi 16 | - source ~/.elan/env 17 | - mkdir $HOME/scripts || echo "" 18 | - export PATH="$HOME/scripts:$PATH" 19 | - cp travis_long.sh $HOME/scripts/travis_long 20 | - chmod +x $HOME/scripts/travis_long 21 | - (git status | grep -e "Changes not staged for commit:"); RESULT=$? 22 | - if [ $RESULT -eq 0 ]; then git checkout -f HEAD ; fi 23 | - rm `git status | grep "\.lean" | sed "s/\.lean/.olean/"` || true 24 | - rm `git status | grep "\.lean"` || true 25 | - rm mathlib.txt || true 26 | 27 | jobs: 28 | include: 29 | - stage: Pre-build-1 30 | script: 31 | - travis_long "timeout 2400 leanpkg test" | awk 'BEGIN{e=0;c=-1}c&&--c;/error/{if (!e) {c=30;e=1}};{if (!c) {exit 1}}' 32 | 33 | - stage: Pre-build-2 34 | script: 35 | - travis_long "timeout 2400 leanpkg test" | awk 'BEGIN{e=0;c=-1}c&&--c;/error/{if (!e) {c=30;e=1}};{if (!c) {exit 1}}' 36 | 37 | - stage: Pre-build-3 38 | script: 39 | - travis_long "timeout 2400 leanpkg test" | awk 'BEGIN{e=0;c=-1}c&&--c;/error/{if (!e) {c=30;e=1}};{if (!c) {exit 1}}' 40 | 41 | - stage: Pre-build-4 42 | script: 43 | - travis_long "timeout 2400 leanpkg test" | awk 'BEGIN{e=0;c=-1}c&&--c;/error/{if (!e) {c=30;e=1}};{if (!c) {exit 1}}' 44 | 45 | - stage: Test 46 | script: 47 | - leanpkg test 48 | 49 | notifications: 50 | webhooks: 51 | - https://leanprover.zulipchat.com/api/v1/external/travis?stream=travis&topic=build-status&api_key=SwF1QzwUWol76dCxsYgwHbI6giN3cxGn 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Archived, this repository is obsolete! 2 | 3 | The entire contents have long ago become part of [Mathlib](https://github.com/leanprover-community/mathlib4). 4 | 5 | --- 6 | 7 | [![Build Status](https://travis-ci.org/semorrison/lean-category-theory.svg?branch=master)](https://travis-ci.org/semorrison/lean-category-theory) 8 | 9 | This repository develops the basics of category theory in Lean. 10 | 11 | Some parts of this library have already been PR'd into mathlib, under [`category_theory`](https://github.com/leanprover/mathlib/blob/master/docs/theories/categories.md), and hopefully more will come across soon. 12 | 13 | Please note that our goal is _not_ to produce a beautiful category theory library for Lean. Lean probably isn't ready for someone to try to write one! 14 | Instead, this is an experiment to discover how plausible it is that "working mathematicians" should be interested in the current state of interactive theorem proving. As such, we're trying to set a high bar for: 15 | * consistency with the way mathematicians think, 16 | * automation of everything so straightforward that a human mathematician wouldn't want to have to think about ("could an undergraduate do it?") 17 | * concise expression (e.g. no boilerplate or excessive redundancy) 18 | 19 | We define 20 | * Category, functors, and natural transformations. 21 | * The category of functors between a pair of categories. 22 | * Isomorphisms, and equivalences of categories. 23 | 24 | For now we only do a little of the usual development of "1-category theory", defining 25 | * Comma, slice, and coslice categories. 26 | * Limits ands colimits. 27 | Notably we haven't even mentioned adjunctions! 28 | 29 | Instead our current primary interest is developing the theory of monoidal categories. (**Note: for now all the material on monoidal categories is in https://github.com/semorrison/lean-monoidal-categories/.**) We define 30 | * Cartesian products of categories, functors, and natural transformations. 31 | * A monoidal category, axiomatized as a category C, along with a functor C x C \to C, and an associator natural transformation satisfying the pentagon equation, which is an isomorphism. 32 | * A braided monoidal category, and a symmetric monoidal category. 33 | 34 | As examples, we construct 35 | * The symmetric monoidal category of semigroups. (Note: the current implementation is extremely slow to compile!) 36 | * The symmetric monoidal category of types. (Note: also slow!) 37 | 38 | Work in progress: 39 | * The Drinfeld centre of a monoidal category. 40 | * Internal objects (e.g. semigroups and monoids, and their modules) in monoidal categories. 41 | * Enriched categories. 42 | 43 | 44 | As notational conventions, we denote 45 | * Categories by capital latin letters near the begining of the alphabet (C, D, E, and then A, B when needed), 46 | * Objects of categories by capital latin letters near the end of the alphabet, 47 | * Morphisms by lower case latin letters, 48 | * Functors by capital latin letters starting at F, 49 | * Natural transformations by greek letters. 50 | 51 | -------------------------------------------------------------------------------- /files/Screenshot 2018-08-19 01.55.54.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kim-em/lean-category-theory/1f2bff331a6b1e79fa51df7a843b7ae5383c4160/files/Screenshot 2018-08-19 01.55.54.png -------------------------------------------------------------------------------- /files/equivalence_full_further.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kim-em/lean-category-theory/1f2bff331a6b1e79fa51df7a843b7ae5383c4160/files/equivalence_full_further.png -------------------------------------------------------------------------------- /files/equivalence_full_further2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kim-em/lean-category-theory/1f2bff331a6b1e79fa51df7a843b7ae5383c4160/files/equivalence_full_further2.png -------------------------------------------------------------------------------- /interesting-rewrites: -------------------------------------------------------------------------------- 1 | rewrite_search (saw/visited/used) 16/4/4 expressions during proof of category_theory.adjunctions.Adjunction_to_HomAdjunction_morphism 2 | rewrite_search (saw/visited/used) 26/11/6 expressions during proof of category_theory.uncurry 3 | rewrite_search (saw/visited/used) 10/5/5 expressions during proof of category_theory.adjunctions.Adjunction_to_HomAdjunction 4 | rewrite_search (saw/visited/used) 15/6/5 expressions during proof of category_theory.uncurry 5 | rewrite_search (saw/visited/used) 11/7/6 expressions during proof of category_theory.adjunctions.Adjunction_to_HomAdjunction 6 | rewrite_search (saw/visited/used) 5/5/5 expressions during proof of category_theory.universal.functorial_Colimit 7 | rewrite_search (saw/visited/used) 10/7/5 expressions during proof of category_theory.comma.CommaCategory 8 | rewrite_search (saw/visited/used) 16/3/2 expressions during proof of category_theory.IdempotentCompletion.extend_Functor_to_completion 9 | rewrite_search (saw/visited/used) 10/3/3 expressions during proof of category_theory.adjunctions.unit_from_HomAdjunction 10 | rewrite_search (saw/visited/used) 172/53/20 expressions during proof of category_theory.equivalence.Equivalences_are_Full 11 | rewrite_search (saw/visited/used) 7/4/4 expressions during proof of category_theory.universal.lemmas.cones_in_functor_categories.cone_commutativity_in_FunctorCategory_assoc 12 | rewrite_search (saw/visited/used) 11/5/5 expressions during proof of category_theory.universal.lemmas.cones_in_functor_categories.cone_in_functor_category 13 | rewrite_search (saw/visited/used) 4/4/4 expressions during proof of category_theory.universal.Limits_from_Products_and_Equalizers 14 | rewrite_search (saw/visited/used) 4/4/4 expressions during proof of category_theory.universal.Limits_from_Products_and_Equalizers 15 | rewrite_search (saw/visited/used) 16/9/7 expressions during proof of category_theory.currying 16 | rewrite_search (saw/visited/used) 12/7/5 expressions during proof of category_theory.currying 17 | rewrite_search (saw/visited/used) 18/9/7 expressions during proof of category_theory.equivalence.Fully_Faithful_EssentiallySurjective_Functor_is_Equivalence 18 | rewrite_search (saw/visited/used) 6/4/4 expressions during proof of category_theory.yoneda.yoneda_lemma 19 | rewrite_search (saw/visited/used) 9/6/6 expressions during proof of category_theory.equivalence.Fully_Faithful_EssentiallySurjective_Functor_is_Equivalence 20 | rewrite_search (saw/visited/used) 15/8/6 expressions during proof of category_theory.currying 21 | rewrite_search (saw/visited/used) 16/9/7 expressions during proof of category_theory.currying 22 | rewrite_search (saw/visited/used) 17/7/7 expressions during proof of category_theory.yoneda.yoneda_lemma 23 | rewrite_search (saw/visited/used) 15/13/8 expressions during proof of category_theory.currying 24 | rewrite_search (saw/visited/used) 15/13/8 expressions during proof of category_theory.currying 25 | -------------------------------------------------------------------------------- /leanpkg.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "lean-category-theory" 3 | version = "0.1" 4 | lean_version = "3.4.2" 5 | path = "src" 6 | 7 | [dependencies] 8 | mathlib = {git = "https://github.com/leanprover-community/mathlib", rev = "4263b2be91c453051aa5790d10fb454a9785fe35"} 9 | lean-rewrite-search = {git = "https://github.com/semorrison/lean-rewrite-search", branch = "old-working-version", rev = "4221c65ed7cc2d96cb9fd7278b9f8746a8843aac"} 10 | lean-tidy = {git = "https://github.com/semorrison/lean-tidy", branch = "master", rev = "6c1d46de6cff05e1c2c4c9692af812bca3e13b6c"} 11 | -------------------------------------------------------------------------------- /log: -------------------------------------------------------------------------------- 1 | rewrite_search (saw/visited/used) 16/4/4 expressions during proof of category_theory.adjunctions.Adjunction_to_HomAdjunction_morphism 2 | rewrite_search (saw/visited/used) 26/11/6 expressions during proof of category_theory.uncurry 3 | rewrite_search (saw/visited/used) 10/5/5 expressions during proof of category_theory.adjunctions.Adjunction_to_HomAdjunction 4 | rewrite_search (saw/visited/used) 15/6/5 expressions during proof of category_theory.uncurry 5 | rewrite_search (saw/visited/used) 11/7/6 expressions during proof of category_theory.adjunctions.Adjunction_to_HomAdjunction 6 | rewrite_search (saw/visited/used) 5/5/5 expressions during proof of category_theory.universal.functorial_Colimit 7 | rewrite_search (saw/visited/used) 10/7/5 expressions during proof of category_theory.comma.CommaCategory 8 | rewrite_search (saw/visited/used) 16/3/2 expressions during proof of category_theory.IdempotentCompletion.extend_Functor_to_completion 9 | rewrite_search (saw/visited/used) 10/3/3 expressions during proof of category_theory.adjunctions.unit_from_HomAdjunction 10 | rewrite_search (saw/visited/used) 172/53/20 expressions during proof of category_theory.equivalence.Equivalences_are_Full 11 | rewrite_search (saw/visited/used) 7/4/4 expressions during proof of category_theory.universal.lemmas.cones_in_functor_categories.cone_commutativity_in_FunctorCategory_assoc 12 | rewrite_search (saw/visited/used) 11/5/5 expressions during proof of category_theory.universal.lemmas.cones_in_functor_categories.cone_in_functor_category 13 | rewrite_search (saw/visited/used) 4/4/4 expressions during proof of category_theory.universal.Limits_from_Products_and_Equalizers 14 | rewrite_search (saw/visited/used) 4/4/4 expressions during proof of category_theory.universal.Limits_from_Products_and_Equalizers 15 | rewrite_search (saw/visited/used) 16/9/7 expressions during proof of category_theory.currying 16 | rewrite_search (saw/visited/used) 12/7/5 expressions during proof of category_theory.currying 17 | rewrite_search (saw/visited/used) 18/9/7 expressions during proof of category_theory.equivalence.Fully_Faithful_EssentiallySurjective_Functor_is_Equivalence 18 | rewrite_search (saw/visited/used) 6/4/4 expressions during proof of category_theory.yoneda.yoneda_lemma 19 | rewrite_search (saw/visited/used) 9/6/6 expressions during proof of category_theory.equivalence.Fully_Faithful_EssentiallySurjective_Functor_is_Equivalence 20 | rewrite_search (saw/visited/used) 15/8/6 expressions during proof of category_theory.currying 21 | rewrite_search (saw/visited/used) 16/9/7 expressions during proof of category_theory.currying 22 | rewrite_search (saw/visited/used) 17/7/7 expressions during proof of category_theory.yoneda.yoneda_lemma 23 | rewrite_search (saw/visited/used) 15/13/8 expressions during proof of category_theory.currying 24 | rewrite_search (saw/visited/used) 15/13/8 expressions during proof of category_theory.currying 25 | -------------------------------------------------------------------------------- /profile: -------------------------------------------------------------------------------- 1 | date | tee -a profile.out 2 | echo Repository at `git log --format=format:%H -n 1` | tee -a profile.out 3 | # find . -name "*.olean" -type f -delete 4 | rm src/categories/currying/*.olean 5 | for file in products/bifunctors.lean currying/currying_1.lean currying/currying_2.lean currying/currying_3.lean currying/currying_4.lean 6 | do 7 | printf "Compiling %-40s " $file | tee -a profile.out 8 | (time lean --make src/categories/$file) 2>&1 > /dev/null | grep real | awk '{print $2}' | tee -a profile.out 9 | done 10 | -------------------------------------------------------------------------------- /profile.out: -------------------------------------------------------------------------------- 1 | Repository at 109798ad22b1e34ca1705f033f5b1a927d00cbbe 2 | Compiling natural_transformation.lean 0m8.522s 3 | Compiling products/default.lean 0m11.250s 4 | Compiling universal/default.lean 0m0.023s 5 | Compiling currying/currying_3.lean 0m20.892s 6 | Sat 23 Jun 2018 07:59:45 AEST 7 | Repository at ec63f62d4b19e78887ee2acbaa18a5fd9379b2e9 8 | Compiling currying/currying_3.lean 6m21.206s 9 | Sat 23 Jun 2018 08:15:00 AEST 10 | Repository at ec63f62d4b19e78887ee2acbaa18a5fd9379b2e9 11 | Compiling products/bifunctors.lean 5m48.618s 12 | Compiling currying/currying_1.lean 0m20.496s 13 | Compiling currying/currying_2.lean 0m30.530s 14 | Compiling currying/currying_3.lean 0m26.103s 15 | Sat 23 Jun 2018 08:22:50 AEST 16 | Repository at ec63f62d4b19e78887ee2acbaa18a5fd9379b2e9 17 | Compiling products/bifunctors.lean 0m1.068s 18 | Compiling currying/currying_1.lean 0m13.100s 19 | Compiling currying/currying_2.lean 0m30.755s 20 | Compiling currying/currying_3.lean 0m11.048s 21 | -- Now without making declarations 22 | Sat 23 Jun 2018 08:25:34 AEST 23 | Repository at ec63f62d4b19e78887ee2acbaa18a5fd9379b2e9 24 | Compiling products/bifunctors.lean 0m19.490s 25 | Compiling currying/currying_1.lean 0m19.481s 26 | Compiling currying/currying_2.lean 0m41.126s 27 | Compiling currying/currying_3.lean 0m25.243s 28 | Sat 23 Jun 2018 08:27:22 AEST 29 | Repository at ec63f62d4b19e78887ee2acbaa18a5fd9379b2e9 30 | Compiling products/bifunctors.lean 0m1.031s 31 | Compiling currying/currying_1.lean 0m13.204s 32 | Compiling currying/currying_2.lean 0m36.138s 33 | Compiling currying/currying_3.lean 0m10.776s 34 | Sat 23 Jun 2018 08:28:31 AEST 35 | Repository at ec63f62d4b19e78887ee2acbaa18a5fd9379b2e9 36 | Compiling products/bifunctors.lean 0m1.085s 37 | Compiling currying/currying_1.lean 0m12.683s 38 | Compiling currying/currying_2.lean 0m36.822s 39 | Compiling currying/currying_3.lean 0m10.741s 40 | Sat 23 Jun 2018 08:29:59 AEST 41 | Repository at ec63f62d4b19e78887ee2acbaa18a5fd9379b2e9 42 | Compiling products/bifunctors.lean 5m55.087s 43 | Compiling currying/currying_1.lean 0m20.869s 44 | Compiling currying/currying_2.lean 0m42.264s 45 | Compiling currying/currying_3.lean 0m32.083s 46 | Sat 23 Jun 2018 08:40:43 AEST 47 | Repository at ec63f62d4b19e78887ee2acbaa18a5fd9379b2e9 48 | Compiling products/bifunctors.lean 0m1.135s 49 | Compiling currying/currying_1.lean 0m13.873s 50 | Compiling currying/currying_2.lean 0m41.246s 51 | Compiling currying/currying_3.lean 0m11.998s 52 | Compiling currying/currying_4.lean 2m6.647s 53 | Sat 23 Jun 2018 08:44:13 AEST 54 | Repository at ec63f62d4b19e78887ee2acbaa18a5fd9379b2e9 55 | Compiling products/bifunctors.lean 0m1.041s 56 | Compiling currying/currying_1.lean 0m14.105s 57 | Compiling currying/currying_2.lean 0m40.145s 58 | Compiling currying/currying_3.lean 0m11.333s 59 | Compiling currying/currying_4.lean 2m0.226s 60 | -- Turning declarations back on 61 | Sat 23 Jun 2018 08:48:46 AEST 62 | Repository at ec63f62d4b19e78887ee2acbaa18a5fd9379b2e9 63 | Compiling products/bifunctors.lean 0m17.817s 64 | Compiling currying/currying_1.lean 0m20.357s 65 | Compiling currying/currying_2.lean 0m49.910s 66 | Compiling currying/currying_3.lean 0m11.560s 67 | Compiling currying/currying_4.lean 1m27.124s 68 | -------------------------------------------------------------------------------- /rewrite_search_examples: -------------------------------------------------------------------------------- 1 | during elaboration of categories.functor_categories.whiskering_on_left, rewrite_search considered 21 expressions, and found a chain of 5 rewrites 2 | during elaboration of categories.functor_categories.whiskering_on_left, rewrite_search considered 3 expressions, and found a chain of 3 rewrites 3 | during elaboration of categories.arrows.Arrows, rewrite_search considered 8 expressions, and found a chain of 4 rewrites 4 | during elaboration of categories.equivalence.Fully_Faithful_EssentiallySurjective_Functor_is_Equivalence, rewrite_search considered 12 expressions, and found a chain of 7 rewrites 5 | during elaboration of categories.functor_categories.whiskering_on_left, rewrite_search considered 504 expressions, and found a chain of 13 rewrites 6 | -------------------------------------------------------------------------------- /schemes_roadmap.md: -------------------------------------------------------------------------------- 1 | = Roadmap to an example of an affine scheme in mathlib 2 | 3 | * Functions from a type to a (commutative) ring form a (commutative) ring. 4 | * Continuous maps between topological spaces form a topological space. 5 | * Continuous maps into a topological ring form a topological ring. 6 | 7 | * Open subsets of a topological space can be thought of as topological spaces themselves. 8 | 9 | * Now it's trivial to define the presheaf of continuous functions on a topological space. 10 | 11 | * Products, equalizers, filtered colimits. 12 | * There should be a PR for these soon, in the meantime: 13 | * https://github.com/semorrison/lean-category-theory/blob/master/src/category_theory/universal/limits.lean 14 | * https://github.com/semorrison/lean-category-theory/blob/master/src/category_theory/universal/colimits.lean 15 | * https://github.com/semorrison/lean-category-theory/blob/master/src/category_theory/universal/limits/limits.lean 16 | 17 | * The category of (topological) (commutative) rings has products. 18 | * `instance : has_products CommRing := ...` 19 | * For non-topological rings, most of the machinery already there, via `pi_instances`, but we'll 20 | need to verify that the universal properties can be proved effortlessly. 21 | * Later, one wants to show that the forgetful functors to `Type u` are monadic, and hence 22 | create limits, and one dreams that this even gives limits which are defeq to the "by hand" 23 | versions. 24 | 25 | * (Topological) (commutative) rings have filtered colimits. 26 | * Directed colimits is enough at first, but filtered colimits will be needed eventually when 27 | someone wants sheaves on sites. 28 | * The filtered colimit of the presheaf of continuous functions along the poset of neighbourhoods of 29 | a point looks like germs at that point. 30 | 31 | * The germ of continuous functions to `ℂ` at a point `x` is a local ring. 32 | 33 | * The forgetful functor `CommRing ⥤ (Type u)` reflects isomorphisms. 34 | * The forgetful functor `CommRing ⥤ (Type u)` preserves limits. 35 | * We can do this by hand, or better, show that it is represented by `ℤ[x]`, and hence that it 36 | preserves limits. (Either directly, or because more generally right adjoints preserve limits.) 37 | 38 | * In order to verify a presheaf of rings is a sheaf, it's now enough to look at the underlying 39 | presheaf of types, because one should be able to prove: 40 | * ```` 41 | variables {α : Type u} [topological_space α] 42 | variables {V : Type (u+1)} [𝒱 : large_category V] [has_products.{u+1 u} V] (ℱ : V ⥤ (Type u)) 43 | [faithful ℱ] [preserves_limits ℱ] [reflects_isos ℱ] 44 | include 𝒱 45 | 46 | def sheaf.of_sheaf_of_types 47 | (presheaf : presheaf (open_set α) V) 48 | (underlying_is_sheaf : is_sheaf (presheaf ⋙ ℱ)) : is_sheaf presheaf := sorry 49 | ```` 50 | * On the other hand, this doesn't help for presheaves of topological rings, so: 51 | * Show that the presheaf of topological rings given by continuous functions to `ℂ` satisfies the 52 | sheaf condition. 53 | 54 | * Almost trivial: write down the definition of a locally ringed space 55 | ```` 56 | variables (α : Type v) [topological_space α] 57 | 58 | def structure_sheaf := sheaf.{v+1 v} α CommRing 59 | 60 | structure ringed_space := 61 | (𝒪 : structure_sheaf α) 62 | 63 | structure locally_ringed_space extends ringed_space α := 64 | (locality : ∀ x : α, is_local_ring (stalk_at.{v+1 v} 𝒪 x).1) 65 | ```` 66 | and observe we've got all the ingredients to make an example out of continuous functions to `ℂ`. 67 | * Although consider the alternative description of locality, which doesn't require computing stalks: 68 | https://ncatlab.org/nlab/show/locally+ringed+topological+space#on_the_locality_condition 69 | How generally does this work? 70 | 71 | * Define the category of locally_ringed_spaces, as tuples `(f, f', w)`, `f` a continuous map, `f'` a 72 | natural transformation `Y.𝒪 ⟹ f_* X.𝒪`, and `w` some information about preserving maximal ideals 73 | of stalks. 74 | 75 | * Define `Spec R` as a `locally_ringed_space` for `R` a commutative ring, and morever `TopSpec R` 76 | as a `topological_locally_ringed_space` for `R` a topological commutative ring, and verify that 77 | the example above is isomorphic to `TopSpec (continuous_map X ℂ)`. -------------------------------------------------------------------------------- /src/category_theory/abelian/abelian.lean: -------------------------------------------------------------------------------- 1 | -- -- Copyright (c) 2017 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.abelian.monic 6 | -- import category_theory.universal.monic 7 | -- import category_theory.universal.kernels 8 | 9 | -- open category_theory 10 | -- open category_theory.limits 11 | -- open category_theory.universal.monic 12 | 13 | -- namespace category_theory.abelian 14 | 15 | -- -- This is the def of abelian from Etingof's "Tensor categories" 16 | 17 | -- universes u v 18 | 19 | -- -- structure KernelImageCokernelDecomposition 20 | -- -- {C : Type u} [category.{u v} C] [has_zero_object.{u v} C] [has_kernels.{u v} C] [has_cokernels.{u v} C] 21 | -- -- {X Y : C} (f : X ⟶ Y) := 22 | -- -- (image_well_defined : cokernel (kernel.map f) ≅ kernel (cokernel.map f)) 23 | -- -- (composition_is_morphism : (cokernel (kernel.map f)).map ≫ image_well_defined.hom ≫ (kernel (cokernel.map f)).map = f) 24 | 25 | -- -- class Abelian {C : Type u} [category.{u v} C] [has_zero_object.{u v} C] [has_kernels.{u v} C] [has_cokernels.{u v} C] := 26 | -- -- (decomposition : ∀ {X Y : C} (f : X ⟶ Y), KernelImageCokernelDecomposition f) 27 | 28 | -- -- This is the usual definition 29 | 30 | -- class Abelian' {C : Type u} [category.{u v} C] [has_zero_object.{u v} C] := 31 | -- (monics_are_regular : ∀ {X Y : C} {f : X ⟶ Y} (m : mono f), regular_mono f) 32 | -- (epics_are_regular : ∀ {X Y : C} {f : X ⟶ Y} (m : epi f ), regular_epi f) 33 | 34 | -- -- PROJECT show these definitions are equivalent 35 | 36 | -- -- PROJECT define short and long exact sequences, cohomology? 37 | 38 | -- end category_theory.abelian -------------------------------------------------------------------------------- /src/category_theory/abelian/monic.lean: -------------------------------------------------------------------------------- 1 | -- Copyright (c) 2017 Scott Morrison. All rights reserved. 2 | -- Released under Apache 2.0 license as described in the file LICENSE. 3 | -- Authors: Stephen Morgan, Scott Morrison 4 | 5 | import category_theory.isomorphism 6 | import category_theory.tactics.obviously 7 | 8 | namespace category_theory 9 | 10 | universe u 11 | variable {C : Type (u+1)} 12 | variable [large_category C] 13 | variables {X Y Z : C} 14 | 15 | structure split_mono (f : Y ⟶ Z) := 16 | (right_inverse : Z ⟶ Y) 17 | (evidence' : f ≫ right_inverse = 𝟙 Y . obviously) 18 | 19 | restate_axiom split_mono.evidence' 20 | attribute [simp,search] split_mono.evidence 21 | 22 | def mono.of_split_mono {f : Y ⟶ Z} (m : split_mono f) : mono f := 23 | { right_cancellation := λ _ a b p, begin 24 | have e := congr_arg (λ g, g ≫ m.right_inverse) p, 25 | obviously, 26 | end } 27 | 28 | -- PROJECT split_epi 29 | 30 | end category_theory -------------------------------------------------------------------------------- /src/category_theory/concrete.lean: -------------------------------------------------------------------------------- 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.equivalence 6 | import category_theory.types 7 | 8 | namespace category_theory 9 | 10 | universes u v 11 | 12 | class concrete (C : Type u) [category.{v} C] := 13 | (fibre_functor : C ⥤ Sort v) 14 | (faithfulness : faithful fibre_functor . obviously) 15 | 16 | instance : concrete (Type u) := 17 | { fibre_functor := functor.id _ } 18 | 19 | end category_theory -------------------------------------------------------------------------------- /src/category_theory/enriched.lean: -------------------------------------------------------------------------------- 1 | -- import category_theory.limits.limits 2 | -- import category_theory.limits.preserves 3 | -- import category_theory.limits.types 4 | -- import category_theory.fully_faithful 5 | 6 | -- open category_theory.limits 7 | 8 | -- universes v u 9 | 10 | -- namespace category_theory 11 | 12 | -- variables {C : Type u} [𝒞 : category.{v} C] 13 | -- variables (V : Type (v+1)) [𝒱 : large_category V] 14 | -- [has_terminal.{v+1 v} V] [has_binary_products.{v+1 v} V] 15 | -- (ℱ : V ⥤ Type v) [faithful ℱ] [preserves_limits ℱ] 16 | 17 | -- include 𝒞 𝒱 18 | 19 | -- class enriched_over := 20 | -- (enriched_hom : C → C → V) 21 | -- (enriched_id : Π {X : C}, terminal V ⟶ enriched_hom X X) 22 | -- (enriched_comp : Π {X Y Z : C}, limits.prod (enriched_hom X Y) (enriched_hom Y Z) ⟶ enriched_hom X Z) 23 | -- (fibre_hom : Π {X Y : C}, ℱ.obj (enriched_hom X Y) ≅ (X ⟶ Y)) 24 | -- /- to state compatibility between enriched_comp and comp, we need that the fibre functor preserves limits -/ 25 | 26 | -- -- TODO simple examples 27 | 28 | -- /- The category of types is enriched over itself. -/ 29 | -- -- instance : enriched_over.{u v} (Type v) (functor.id _) := 30 | -- -- { enriched_hom := λ X Y, X ⟶ Y, 31 | -- -- enriched_id := λ (X : C) _, 𝟙 X, 32 | -- -- enriched_comp := λ X Y Z, begin dsimp, exact λ p, p.1 ≫ p.2, end, 33 | -- -- fibre_hom := by obviously } 34 | 35 | -- end category_theory -------------------------------------------------------------------------------- /src/category_theory/examples/categories.lean: -------------------------------------------------------------------------------- 1 | import category_theory.functor 2 | 3 | universes v u 4 | 5 | namespace category_theory 6 | 7 | structure Category : Type (max (u+1) (v+1)) := 8 | (C : Type u) 9 | [𝒞 : category.{v} C] 10 | 11 | instance category_of_Category (𝒞 : Category) : category (𝒞.C) := 𝒞.𝒞 12 | 13 | instance CAT : category.{(max (u+1) v)} Category.{v u} := 14 | { hom := λ 𝒞 𝒟, 𝒞.C ⥤ 𝒟.C, 15 | id := λ 𝒞, (functor.id 𝒞.C), 16 | comp := λ _ _ _ F G, F ⋙ G, 17 | id_comp' := begin tidy, cases f, dsimp [functor.comp], refl end, 18 | comp_id' := begin tidy, cases f, dsimp [functor.comp], refl end, 19 | assoc' := begin tidy, end } 20 | 21 | end category_theory -------------------------------------------------------------------------------- /src/category_theory/examples/graphs.lean: -------------------------------------------------------------------------------- 1 | -- Copyright (c) 2017 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.category 6 | import category_theory.graphs 7 | 8 | open category_theory 9 | open category_theory.graphs 10 | 11 | namespace category_theory.examples.graphs 12 | 13 | universe u₁ 14 | 15 | def Graph := Σ α : Type u₁, graph.{u₁} α 16 | 17 | instance graph_from_Graph (G : Graph) : graph G.1 := G.2 18 | 19 | structure Graph_hom (G H : Graph.{u₁}) : Type u₁ := 20 | (map : @graph_hom G.1 G.2 H.1 H.2) 21 | 22 | @[extensionality] lemma graph_homomorphisms_pointwise_equal 23 | {G H : Graph.{u₁}} 24 | {p q : Graph_hom G H} 25 | (vertexWitness : ∀ X : G.1, p.map.onVertices X = q.map.onVertices X) 26 | (edgeWitness : ∀ X Y : G.1, ∀ f : edges X Y, ⟬ p.map.onEdges f ⟭ = q.map.onEdges f ) : p = q := 27 | begin 28 | induction p, 29 | induction q, 30 | tidy, 31 | end 32 | 33 | instance CategoryOfGraphs : large_category Graph := 34 | { hom := Graph_hom, 35 | id := λ G, 36 | ⟨{ onVertices := id, 37 | onEdges := λ _ _ f, f }⟩, 38 | comp := λ G H K f g, 39 | ⟨{ onVertices := λ v, g.map.onVertices (f.map.onVertices v), 40 | onEdges := λ v w e, g.map.onEdges (f.map.onEdges e) }⟩ } 41 | 42 | end category_theory.examples.graphs -------------------------------------------------------------------------------- /src/category_theory/filtered.lean: -------------------------------------------------------------------------------- 1 | import category_theory.limits.limits 2 | import order.filter 3 | 4 | open category_theory.limits 5 | 6 | namespace category_theory 7 | 8 | universes u₁ v₁ 9 | 10 | variables α : Type u₁ 11 | 12 | class directed [preorder α] := 13 | (bound (x₁ x₂ : α) : α) 14 | (i₁ (x₁ x₂ : α) : x₁ ≤ bound x₁ x₂) 15 | (i₂ (x₁ x₂ : α) : x₂ ≤ bound x₁ x₂) 16 | 17 | variables (C : Type u₁) [𝒞 : category.{v₁} C] 18 | include 𝒞 19 | 20 | -- class filtered := 21 | -- (default : C) 22 | -- (obj_bound (X Y : C) : cone (two.map X Y)) 23 | -- (hom_bound {X Y : C} (f g : X ⟶ Y) : cofork f g) 24 | 25 | -- instance [inhabited α] [preorder α] [directed α] : filtered.{u₁ u₁} α := 26 | -- { default := default α, 27 | -- obj_bound := λ x y, { X := directed.bound x y, ι₁ := ⟨ ⟨ directed.i₁ x y ⟩ ⟩, ι₂ := ⟨ ⟨ directed.i₂ x y ⟩ ⟩ }, 28 | -- hom_bound := λ _ y f g, { X := y, π := 𝟙 y, w' := begin cases f, cases f, cases g, cases g, simp end } } 29 | 30 | end category_theory -------------------------------------------------------------------------------- /src/category_theory/follow_your_nose.lean: -------------------------------------------------------------------------------- 1 | import category_theory.natural_transformation 2 | import category_theory.opposites 3 | import category_theory.types 4 | 5 | import category_theory.tactics.obviously 6 | 7 | universes v₁ u₁ 8 | 9 | open tactic 10 | open opposite 11 | 12 | def fyn_names := 13 | [ `category_theory.category_struct.id, 14 | `category_theory.functor.map, 15 | `category_theory.nat_trans.app, 16 | `category_theory.has_hom.hom.unop, 17 | `category_theory.category_struct.comp, 18 | `prod.mk ] 19 | 20 | meta def construct_morphism : tactic unit := 21 | do ctx ← local_context, 22 | extra ← fyn_names.mmap (λ n, mk_const n), 23 | solve_by_elim { assumptions := return (ctx ++ extra), max_rep := 5 } 24 | 25 | meta def fyn := tidy { tactics := tactic.tidy.default_tactics ++ [construct_morphism >> pure "construct_morphism"] } 26 | 27 | attribute [tidy] construct_morphism 28 | 29 | notation `ƛ` binders `, ` r:(scoped f, { category_theory.functor . obj := f, map := by obviously }) := r 30 | 31 | open category_theory 32 | 33 | variables (C : Type u₁) [𝒞 : category.{v₁+1} C] 34 | include 𝒞 35 | 36 | def yoneda : C ⥤ ((Cᵒᵖ) ⥤ Sort (v₁+1)) := ƛ X, ƛ Y, (unop Y) ⟶ X. 37 | 38 | variables (D : Type u₁) [𝒟 : category.{v₁+1} D] 39 | include 𝒟 40 | 41 | def curry_id : C ⥤ (D ⥤ (C × D)) := ƛ X, ƛ Y, (X, Y) 42 | -------------------------------------------------------------------------------- /src/category_theory/functor/functorial.lean: -------------------------------------------------------------------------------- 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 | 6 | import category_theory.functor 7 | import category_theory.tactics.obviously 8 | 9 | namespace category_theory 10 | 11 | universes u₁ u₂ 12 | 13 | variable {C : Type (u₁+1)} 14 | variable [large_category C] 15 | variable {D : Type (u₂+1)} 16 | variable [large_category D] 17 | 18 | -- TODO this is WIP 19 | class functorial (f : C → D) := 20 | (map : Π {X Y : C}, (X ⟶ Y) → ((f X) ⟶ (f Y))) 21 | (map_id' : ∀ (X : C), map (𝟙 X) = 𝟙 (f X) . obviously) 22 | (map_comp' : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z), map (f ≫ g) = (map f) ≫ (map g) . obviously) 23 | 24 | restate_axiom functorial.map_id' 25 | restate_axiom functorial.map_comp' 26 | attribute [simp,search] functorial.map_comp functorial.map_id 27 | 28 | -- instance (F : C ⥤ D) : functorial (F.obj) := 29 | -- { map := F.map' } 30 | 31 | -- TODO notations? 32 | end category_theory -------------------------------------------------------------------------------- /src/category_theory/functor/isomorphism.lean: -------------------------------------------------------------------------------- 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.fully_faithful 6 | 7 | open category_theory 8 | 9 | namespace category_theory 10 | 11 | universes v₁ v₂ u₁ u₂ 12 | 13 | variables {C : Type u₁} [𝓒 : category.{v₁} C] {D : Type u₂} [𝓓 : category.{v₂} D] 14 | include 𝓒 𝓓 15 | 16 | class reflects_isos (F : C ⥤ D) := 17 | (reflects : Π {X Y : C} (f : X ⟶ Y) (w : is_iso (F.map f)), is_iso f) 18 | 19 | instance (F : C ⥤ D) [fully_faithful F] : reflects_isos F := 20 | { reflects := λ X Y f, 21 | by introI w; exact 22 | { inv := F.preimage (inv (F.map f)), 23 | hom_inv_id' := begin apply F.injectivity, simp, end, 24 | inv_hom_id' := begin apply F.injectivity, simp, end }} 25 | 26 | -- TODO define reflects_epis, reflects_monos, and deduce these from faithful 27 | 28 | end category_theory -------------------------------------------------------------------------------- /src/category_theory/graph_category.lean: -------------------------------------------------------------------------------- 1 | -- import category_theory.path_category 2 | -- import tactic.linarith 3 | 4 | -- open category_theory.graphs 5 | 6 | -- universes v₁ u₁ 7 | 8 | -- namespace category_theory 9 | 10 | -- def finite_graph {n k : ℕ} (e : vector (fin n × fin n) k) := ulift.{v₁} (fin n) 11 | 12 | -- instance finite_graph_category {n k : ℕ} (e : vector (fin n × fin n) k) : graph.{v₁+1} (finite_graph e) := 13 | -- { edges := λ x y, ulift { a : fin k // e.nth a = (x.down, y.down) } } 14 | 15 | -- def parallel_pair : vector (fin 2 × fin 2) 2 := ⟨ [(0, 1), (0, 1)], by refl ⟩ 16 | 17 | -- -- Verify typeclass inference is hooked up correctly: 18 | -- example : category.{v₁+1} (paths (finite_graph parallel_pair)) := by apply_instance. 19 | 20 | -- variables {C : Type u₁} [𝒞 : category.{v₁} C] 21 | -- include 𝒞 22 | 23 | -- @[simp] def graph_functor {n k : ℕ} {e : vector (fin n × fin n) k} 24 | -- (objs : vector C n) (homs : Π m : fin k, objs.nth (e.nth m).1 ⟶ objs.nth (e.nth m).2) : 25 | -- paths (finite_graph.{v₁} e) ⥤ C := 26 | -- functor.of_graph_hom 27 | -- { onVertices := λ x, objs.nth x.down, 28 | -- onEdges := λ x y f, 29 | -- begin 30 | -- have p := homs f.down.val, 31 | -- refine (eq_to_hom _) ≫ p ≫ (eq_to_hom _), -- TODO this needs a name, e.g. `convert_hom` 32 | -- rw f.down.property, 33 | -- rw f.down.property, 34 | -- end} 35 | 36 | 37 | -- def parallel_pair_functor' {X Y : C} (f g : X ⟶ Y) : paths.{v₁} (finite_graph parallel_pair) ⥤ C := 38 | -- graph_functor ⟨ [X, Y], by refl ⟩ 39 | -- (λ m, match m with 40 | -- | ⟨ 0, _ ⟩ := f 41 | -- | ⟨ 1, _ ⟩ := g 42 | -- | ⟨ n+2, _ ⟩ := by exfalso; linarith 43 | -- end) 44 | 45 | -- end category_theory 46 | -------------------------------------------------------------------------------- /src/category_theory/graphs/category.lean: -------------------------------------------------------------------------------- 1 | -- Copyright (c) 2017 Scott Morrison. All rights reserved. 2 | -- Released under Apache 2.0 license as described in the file LICENSE. 3 | -- Authors: Stephen Morgan and Scott Morrison 4 | 5 | import category_theory.category 6 | import category_theory.graphs 7 | 8 | namespace category_theory 9 | 10 | open category_theory.graphs 11 | 12 | universes u v 13 | variable {C : Type u} 14 | 15 | instance category.graph [𝒞 : category.{v} C] : graph C := 16 | { edges := 𝒞.hom } 17 | 18 | variable [small_category C] 19 | 20 | inductive morphism_path : C → C → Type (u+1) 21 | | nil : Π (h : C), morphism_path h h 22 | | cons : Π {h s t : C} (e : h ⟶ s) (l : morphism_path s t), morphism_path h t 23 | 24 | notation a :: b := morphism_path.cons a b 25 | notation `c[` l:(foldr `, ` (h t, morphism_path.cons h t) morphism_path.nil _ `]`) := l 26 | 27 | def concatenate_paths : Π {x y z : C}, morphism_path x y → morphism_path y z → morphism_path x z 28 | | ._ ._ _ (morphism_path.nil _) q := q 29 | | ._ ._ _ (@morphism_path.cons ._ _ _ _ _ e p') q := morphism_path.cons e (concatenate_paths p' q) 30 | 31 | def category.compose_path : Π {X Y : C}, morphism_path X Y → (X ⟶ Y) 32 | | X ._ (morphism_path.nil ._) := 𝟙 X 33 | | _ _ (@morphism_path.cons ._ ._ _ _ ._ e p) := e ≫ (category.compose_path p) 34 | 35 | end category_theory -------------------------------------------------------------------------------- /src/category_theory/graphs/default.lean: -------------------------------------------------------------------------------- 1 | -- Copyright (c) 2017 Scott Morrison. All rights reserved. 2 | -- Released under Apache 2.0 license as described in the file LICENSE. 3 | -- Authors: Stephen Morgan and Scott Morrison 4 | 5 | import category_theory.tactics.obviously 6 | import tidy.auto_cast 7 | 8 | namespace category_theory.graphs 9 | 10 | universes v₁ v₂ u₁ u₂ 11 | 12 | class graph (vertices : Type u₁) := 13 | (edges : vertices → vertices → Sort v₁) 14 | 15 | variable {C : Type u₁} 16 | variables {W X Y Z : C} 17 | variable [𝒞 : graph.{v₁} C] 18 | 19 | def edges : C → C → Sort v₁ := @graph.edges.{v₁} C 𝒞 20 | 21 | structure graph_hom (G : Type u₁) [graph.{v₁} G] (H : Type u₂) [graph.{v₂} H] := 22 | (onVertices : G → H) 23 | (onEdges : ∀ {X Y : G}, edges X Y → edges (onVertices X) (onVertices Y)) 24 | 25 | section 26 | variables {G : Type u₁} [𝒢 : graph.{v₁} G] {H : Type u₂} [ℋ : graph.{v₂} H] 27 | include 𝒢 ℋ 28 | 29 | @[extensionality] lemma graph_hom_pointwise_equal 30 | {p q : graph_hom G H} 31 | (vertexWitness : ∀ X : G, p.onVertices X = q.onVertices X) 32 | (edgeWitness : ∀ X Y : G, ∀ f : edges X Y, ⟬ p.onEdges f ⟭ = q.onEdges f) : p = q := 33 | begin 34 | induction p with p_onVertices p_onEdges, 35 | induction q with q_onVertices q_onEdges, 36 | have h_vertices : p_onVertices = q_onVertices, exact funext vertexWitness, 37 | subst h_vertices, 38 | have h_edges : @p_onEdges = @q_onEdges, 39 | apply funext, intro X, apply funext, intro Y, apply funext, intro f, 40 | exact edgeWitness X Y f, 41 | subst h_edges 42 | end 43 | end 44 | 45 | variables {G : Type u₁} [𝒢 : graph.{v₁} G] 46 | include 𝒢 47 | 48 | inductive path : G → G → Type (max u₁ v₁) 49 | | nil : Π (h : G), path h h 50 | | cons : Π {h s t : G} (e : edges h s) (l : path s t), path h t 51 | 52 | def path.length : Π {s t : G}, path s t → ℕ 53 | | _ _ (path.nil _) := 0 54 | | _ _ (@path.cons _ _ _ _ _ e l) := path.length l 55 | 56 | notation a :: b := path.cons a b 57 | notation `p[` l:(foldr `, ` (h t, path.cons h t) path.nil _ `]`) := l 58 | 59 | inductive path_of_paths : G → G → Type (max u₁ v₁) 60 | | nil : Π (h : G), path_of_paths h h 61 | | cons : Π {h s t : G} (e : path h s) (l : path_of_paths s t), path_of_paths h t 62 | 63 | notation a :: b := path_of_paths.cons a b 64 | notation `pp[` l:(foldr `, ` (h t, path_of_paths.cons h t) path_of_paths.nil _ `]`) := l 65 | 66 | -- The pattern matching trick used here was explained by Jeremy Avigad at https://groups.google.com/d/msg/lean-user/JqaI12tdk3g/F9MZDxkFDAAJ 67 | def concatenate_paths : Π {x y z : G}, path x y → path y z → path x z 68 | | ._ ._ _ (path.nil _) q := q 69 | | ._ ._ _ (@path.cons ._ _ _ _ _ e p') q := path.cons e (concatenate_paths p' q) 70 | 71 | @[simp] lemma concatenate_paths' {x' x y z : G} (e : edges x' x) (p : path x y) (q : path y z) : concatenate_paths (e :: p) q = e :: (concatenate_paths p q) := rfl 72 | 73 | def concatenate_path_of_paths : Π {x y : G}, path_of_paths x y → path x y 74 | | ._ ._ (path_of_paths.nil X) := path.nil X 75 | | ._ ._ (@path_of_paths.cons ._ _ _ _ _ e p') := concatenate_paths e (concatenate_path_of_paths p') 76 | 77 | end category_theory.graphs 78 | -------------------------------------------------------------------------------- /src/category_theory/homological_algebra/chain_complex.lean: -------------------------------------------------------------------------------- 1 | -- /- Attempting to "live-formalise", from the PhD students reading group meeting on June 24 2018, starting at the beginning of homological algebra. -/ 2 | 3 | -- import category_theory.category 4 | -- import category_theory.universal.zero 5 | -- import category_theory.limits.products 6 | 7 | -- universes u₁ v₁ u₂ v₂ 8 | 9 | -- open category_theory 10 | -- open category_theory.limits 11 | 12 | -- class Ab_category (C: Type u₁) extends category.{u₁ v₁} C := --- we really need to setup enriched categories 13 | -- (hom_groups : Π X Y : C, comm_group (X ⟶ Y)) 14 | -- (compose_is_homomorphism : Π X Y Z : C, 15 | -- begin 16 | -- haveI : comm_group (X ⟶ Y) := by apply_instance, -- we can get these, but not the product automatically? 17 | -- haveI : comm_group ((X ⟶ Y) × (Y ⟶ Z)) := by sorry, -- surely this should just appear magically. 18 | -- exact is_group_hom (λ p : (X ⟶ Y) × (Y ⟶ Z), p.1 ≫ p.2) 19 | -- end) 20 | 21 | 22 | -- -- variables (C : Type u₁) [𝒞 : Ab_category.{u₁ v₁} C] (D : Type u₂) [𝒟 : Ab_category.{u₂ v₂} D] 23 | 24 | -- -- def additive_functor extends Functor C D := sorry 25 | -- -- TODO should be has_finite_products, but that doesn't exist yet 26 | -- class additive_category (C : Type u₁) extends (Ab_category.{u₁ v₁} C), (has_zero_object.{u₁ v₁} C), (has_products.{u₁ v₁} C) 27 | 28 | -- /- Examples -/ 29 | -- /- Field is not additve, it doesn't have a zero object, or all products. -/ 30 | -- /- Abelian groups = Z-mod is an additive category. -/ 31 | -- /- mod-R, Vec_F, even dimensional vector spaces, are all additive categories -/ 32 | 33 | -- structure chain_complex (C : Type u₁) [additive_category.{u₁ v₁} C] : Type (max u₁ v₁) := 34 | -- (chain_objects : ℤ → C) 35 | -- (differentials : Π n : ℤ, (chain_objects n) ⟶ (chain_objects (n+1))) 36 | -- -- squares to zero! 37 | 38 | -- structure chain_map {C : Type u₁} [additive_category C] (M N : chain_complex C) := 39 | -- (component : Π n : ℤ, M.chain_objects n ⟶ N.chain_objects n) 40 | -- (commutes : Π n : ℤ, component n ≫ N.differentials n = M.differentials n ≫ component (n+1)) 41 | 42 | -- class abelian_category (C : Type u₁) extends (additive_category.{u₁ v₁} C)/-, (has_Equalizers.{u₁ u₂} C), (has_Coequalizers.{u₁ u₂} C)-/ . 43 | -- -- TODO: monics are regular 44 | 45 | -- instance category_of_chain_complexes {C : Type u₁} [additive_category.{u₁ v₁} C] : category.{(max u₁ v₁)} (chain_complex C) := 46 | -- { hom := λ M N, chain_map M N, 47 | -- comp := sorry, 48 | -- id := sorry, 49 | -- id_comp' := sorry, comp_id' := sorry, assoc' := sorry 50 | -- } 51 | 52 | -- instance chain_complexes_are_abelian_too (C : Type u₁) [abelian_category.{u₁ v₁} C] : abelian_category (chain_complex C) := sorry 53 | -- -- mostly, work componentwise 54 | 55 | 56 | -- -- cycles, boundaries, homology, quasi-isomorphism 57 | -- -- Example: singular chains in a topological space 58 | -------------------------------------------------------------------------------- /src/category_theory/idempotent_completion.lean: -------------------------------------------------------------------------------- 1 | -- Copyright (c) 2017 Scott Morrison. All rights reserved. 2 | -- Released under Apache 2.0 license as described in the file LICENSE. 3 | -- Authors: Stephen Morgan, Scott Morrison 4 | import category_theory.tactics.obviously 5 | import category_theory.equivalence 6 | 7 | namespace category_theory 8 | 9 | universes v₁ v₂ u₁ u₂ 10 | 11 | structure idempotent (C : Sort u₁) [category.{v₁+1} C] := 12 | (X : C) 13 | (idem : X ⟶ X) 14 | (w' : idem ≫ idem = idem . obviously) 15 | 16 | restate_axiom idempotent.w' 17 | attribute [simp] idempotent.w -- search 18 | 19 | variables {C : Sort u₁} [𝒞 : category.{v₁+1} C] 20 | include 𝒞 21 | 22 | namespace idempotent 23 | 24 | structure morphism (P Q : idempotent.{v₁} C) := 25 | (hom : P.X ⟶ Q.X) 26 | (left' : P.idem ≫ hom = hom . obviously) 27 | (right' : hom ≫ Q.idem = hom . obviously) 28 | 29 | restate_axiom morphism.left' 30 | restate_axiom morphism.right' 31 | attribute [simp] morphism.left morphism.right -- search 32 | 33 | @[extensionality] lemma ext {P Q : idempotent C} (f g : morphism P Q) (w : f.hom = g.hom) : f = g := 34 | begin 35 | induction f, 36 | induction g, 37 | tidy 38 | end 39 | 40 | end idempotent 41 | 42 | instance idempotent_completion : category.{v₁+1} (idempotent C) := 43 | { hom := idempotent.morphism, 44 | id := λ P, ⟨ P.idem ⟩, 45 | comp := λ _ _ _ f g, 46 | { hom := f.hom ≫ g.hom, 47 | left' := by rw [←category.assoc, idempotent.morphism.left], 48 | right' := by rw [category.assoc, idempotent.morphism.right] } } 49 | 50 | namespace idempotent_completion 51 | 52 | @[simp] lemma id_hom (P : idempotent C) : ((𝟙 P) : idempotent.morphism P P).hom = P.idem := rfl 53 | @[simp] lemma comp_hom {P Q R : idempotent C} (f : P ⟶ Q) (g : Q ⟶ R) : (f ≫ g).hom = f.hom ≫ g.hom := rfl 54 | 55 | def to_completion (C : Type u₁) [𝒞 : category.{v₁+1} C] : C ⥤ (idempotent.{v₁} C) := 56 | { obj := λ P, { X := P, idem := 𝟙 P }, 57 | map := λ _ _ f, { hom := f } } 58 | 59 | @[simp] private lemma double_idempotent_morphism_left (P Q : idempotent (idempotent C)) (f : P ⟶ Q) 60 | : (P.idem).hom ≫ (f.hom).hom = (f.hom).hom := congr_arg idempotent.morphism.hom f.left 61 | @[simp] private lemma double_idempotent_morphism_right (P Q : idempotent (idempotent C)) (f : P ⟶ Q) 62 | : (f.hom).hom ≫ (Q.idem).hom = (f.hom).hom := congr_arg idempotent.morphism.hom f.right 63 | 64 | @[simp] private def idempotent_functor : (idempotent (idempotent C)) ⥤ (idempotent C) := 65 | { obj := λ P, ⟨ P.X.X, P.idem.hom, congr_arg idempotent.morphism.hom P.w ⟩, 66 | map := λ _ _ f, ⟨ f.hom.hom, by obviously ⟩ }. 67 | @[simp] private def idempotent_inverse : (idempotent C) ⥤ (idempotent (idempotent C)) := 68 | { obj := λ P, ⟨ P, ⟨ P.idem, by obviously ⟩, by obviously ⟩, 69 | map := λ _ _ f, ⟨ f, by obviously ⟩ }. 70 | 71 | @[simp] lemma idem_hom_idempotent (X : idempotent (idempotent C)) : X.idem.hom ≫ X.idem.hom = X.idem.hom := 72 | begin 73 | rw ←comp_hom, 74 | simp, 75 | end 76 | 77 | lemma idempotent_idempotent : 78 | equivalence (idempotent (idempotent C)) (idempotent C) := 79 | equivalence.mk idempotent_functor idempotent_inverse 80 | { hom := { app := λ X, { hom := { hom := X.idem.hom } } }, 81 | inv := { app := λ X, { hom := { hom := X.idem.hom } } } } 82 | { hom := { app := λ X, { hom := X.idem } }, 83 | inv := { app := λ X, { hom := X.idem } } } 84 | 85 | variable {D : Type u₂} 86 | variable [𝒟 : category.{v₂+1} D] 87 | include 𝒟 88 | 89 | attribute [search] idempotent.w idempotent.morphism.left idempotent.morphism.right 90 | idem_hom_idempotent comp_hom id_hom 91 | 92 | def extend_to_completion (F : C ⥤ (idempotent D)) : (idempotent C) ⥤ (idempotent D) := 93 | { obj := λ P, 94 | { X := (F.obj P.X).X, 95 | idem := (F.map P.idem).hom, 96 | w' := begin rw [←comp_hom, ←functor.map_comp, idempotent.w], end }, 97 | map := λ X Y f, { hom := (F.map f.hom).hom } } 98 | 99 | end idempotent_completion 100 | end category_theory 101 | -------------------------------------------------------------------------------- /src/category_theory/limits/filtered_limits.lean: -------------------------------------------------------------------------------- 1 | -- import category_theory.filtered 2 | 3 | -- class has_filtered_limits := 4 | -- (limit : Π {J : Type v} [𝒥 : small_category J] [filtered.{v v} J] (F : J ⥤ C), cone F) 5 | -- (is_limit : Π {J : Type v} [𝒥 : small_category J] [filtered.{v v} J] (F : J ⥤ C), is_limit (limit F) . obviously) 6 | 7 | -- class has_filtered_colimits := 8 | -- (colimit : Π {J : Type v} [𝒥 : small_category J] [filtered.{v v} J] (F : J ⥤ C), cocone F) 9 | -- (is_colimit : Π {J : Type v} [𝒥 : small_category J] [filtered.{v v} J] (F : J ⥤ C), is_colimit (colimit F) . obviously) 10 | -------------------------------------------------------------------------------- /src/category_theory/limits/obviously.lean: -------------------------------------------------------------------------------- 1 | import category_theory.limits.limits 2 | import category_theory.limits.shapes.binary_products 3 | import category_theory.limits.shapes.products 4 | import category_theory.limits.shapes.pullbacks 5 | import category_theory.limits.shapes.equalizers 6 | import category_theory.tactics.obviously 7 | 8 | open category_theory.limits 9 | 10 | attribute [search] fork.condition cofork.condition pullback_cone.condition pushout_cocone.condition cone.w cocone.w 11 | 12 | attribute [search] is_limit.fac 13 | attribute [search,elim] is_limit.uniq 14 | attribute [search] is_colimit.fac 15 | attribute [search,elim] is_colimit.uniq 16 | 17 | attribute [search] limit.pre_π limit.post_π colimit.ι_pre colimit.ι_post 18 | 19 | -- attribute [search] is_binary_product.fac₁ is_binary_product.fac₂ 20 | -- attribute [search,elim] is_binary_product.uniq 21 | 22 | -- attribute [search] prod.lift_π₁ prod.lift_π₂ prod.map_π₁ prod.map_π₂ prod.swap_π₁ prod.swap_π₂ 23 | -- attribute [search] coprod.ι₁_desc coprod.ι₂_desc coprod.ι₁_map coprod.ι₂_map coprod.ι₁_swap coprod.ι₂_swap 24 | 25 | -- attribute [search] prod.swap_swap prod.lift_swap prod.swap_map prod.map_map 26 | -- attribute [search] coprod.swap_swap coprod.swap_desc coprod.swap_map coprod.map_map 27 | 28 | -- attribute [search] is_product.fac is_coproduct.fac 29 | -- attribute [search,elim] is_product.uniq is_coproduct.uniq 30 | 31 | -- attribute [search] pi.lift_π pi.map_π pi.pre_π pi.post_π 32 | -- attribute [search] sigma.ι_desc sigma.ι_map sigma.ι_pre sigma.ι_post 33 | 34 | -- attribute [search] is_pullback.fac₁ is_pullback.fac₂ 35 | -- attribute [search,elim] is_pullback.uniq 36 | -- attribute [search] is_pushout.fac₁ is_pushout.fac₂ 37 | -- attribute [search,elim] is_pushout.uniq 38 | 39 | -- attribute [search] is_equalizer.fac 40 | -- attribute [search,elim] is_equalizer.uniq 41 | -- attribute [search] is_coequalizer.fac 42 | -- attribute [search,elim] is_coequalizer.uniq 43 | -------------------------------------------------------------------------------- /src/category_theory/path_category.lean: -------------------------------------------------------------------------------- 1 | -- Copyright (c) 2017 Scott Morrison. All rights reserved. 2 | -- Released under Apache 2.0 license as described in the file LICENSE. 3 | -- Authors: Stephen Morgan and Scott Morrison 4 | 5 | import category_theory.graphs.category 6 | 7 | -- FIXME why do we need this here? 8 | @[obviously] meta def obviously_4 := tactic.tidy { tactics := extended_tidy_tactics } 9 | 10 | open category_theory 11 | open category_theory.graphs 12 | 13 | universes v₁ v₂ u₁ u₂ 14 | 15 | namespace category_theory.graphs 16 | 17 | def paths (C : Type u₂) := C 18 | 19 | instance paths_category (C : Type u₁) [graph.{v₁} C] : category.{(max u₁ v₁)+1} (paths C) := 20 | { hom := λ x y : C, path x y, 21 | id := λ x, path.nil x, 22 | comp := λ _ _ _ f g, concatenate_paths f g, 23 | comp_id' := begin 24 | tidy, 25 | induction f, -- PROJECT think about how to automate an inductive step. When can you be sure it's a good idea? 26 | obviously, 27 | end, 28 | assoc' := begin 29 | tidy, 30 | induction f, 31 | obviously, 32 | end }. 33 | 34 | instance paths_small_category (C : Type u₁) [graph.{u₁ u₁} C] : small_category (paths C) := graphs.paths_category C 35 | 36 | variables {C : Type u₂} [𝒞 : category.{v₂} C] {G : Type u₁} [𝒢 : graph.{v₁} G] 37 | include 𝒢 𝒞 38 | 39 | @[simp] def path_to_morphism 40 | (H : graph_hom G C) 41 | : Π {X Y : G}, path X Y → ((H.onVertices X) ⟶ (H.onVertices Y)) 42 | | ._ ._ (path.nil Z) := 𝟙 (H.onVertices Z) 43 | | ._ ._ (@path.cons ._ _ _ _ _ e p) := (H.onEdges e) ≫ (path_to_morphism p) 44 | 45 | @[simp] lemma path_to_morphism.comp (H : graph_hom G C) {X Y Z : paths G} (f : X ⟶ Y) (g : Y ⟶ Z) : path_to_morphism H (f ≫ g) = path_to_morphism H f ≫ path_to_morphism H g := 46 | begin 47 | induction f, 48 | obviously, 49 | end 50 | 51 | end category_theory.graphs 52 | 53 | namespace category_theory.functor 54 | 55 | open category_theory.graphs 56 | 57 | variables {C : Type u₂} [𝒞 : category.{v₂} C] {G : Type u₁} [𝒢 : graph.{v₁} G] 58 | include 𝒢 𝒞 59 | 60 | -- PROJECT obtain this as the left adjoint to the forgetful functor. 61 | @[simp] def of_graph_hom (H : graph_hom G C) : (paths G) ⥤ C := 62 | { obj := λ X, (H.onVertices X), 63 | map := λ _ _ f, (path_to_morphism H f) } 64 | 65 | end category_theory.functor -------------------------------------------------------------------------------- /src/category_theory/presheaves/locally_ringed.lean: -------------------------------------------------------------------------------- 1 | -- import category_theory.presheaves.sheaves 2 | -- import topology.Top.stalks 3 | -- import algebra.CommRing.limits 4 | -- import ring_theory.ideals 5 | 6 | -- universes v 7 | 8 | -- open category_theory.examples 9 | -- open category_theory.presheaves 10 | -- open category_theory.limits 11 | 12 | -- variables (X : Top.{v}) 13 | 14 | -- instance : has_colimits.{v+1 v} CommRing := sorry 15 | 16 | -- def structure_sheaf := sheaf.{v+1 v} X CommRing 17 | 18 | -- structure ringed_space := 19 | -- (𝒪 : structure_sheaf X) 20 | 21 | -- structure locally_ringed_space extends ringed_space X := 22 | -- (locality : ∀ x : X, is_local_ring (stalk_at.{v+1 v} 𝒪.presheaf x).1) -- coercion from sheaf to presheaf? 23 | 24 | -- def ringed_space.of_topological_space : ringed_space X := 25 | -- { 𝒪 := { presheaf := { obj := λ U, sorry /- ring of continuous functions U → ℂ -/, 26 | -- map := sorry, 27 | -- map_id' := sorry, 28 | -- map_comp' := sorry }, 29 | -- sheaf_condition := sorry, 30 | -- } } -------------------------------------------------------------------------------- /src/category_theory/presheaves/map.lean: -------------------------------------------------------------------------------- 1 | -- import topology.Top.presheaf 2 | -- import category_theory.tactics.obviously 3 | 4 | -- open category_theory 5 | -- open category_theory.examples 6 | 7 | -- universes u v 8 | 9 | -- open category_theory.presheaves 10 | -- open topological_space 11 | 12 | -- namespace category_theory 13 | 14 | -- /- `Presheaf` is a 2-functor CAT ⥤₂ CAT, but we're not going to prove all of that yet. -/ 15 | 16 | -- attribute [simp] set.preimage_id -- mathlib?? 17 | 18 | -- section 19 | -- variables {C : Type u} [𝒞 : category.{u v} C] {D : Type u} [𝒟 : category.{u v} D] 20 | -- include 𝒞 𝒟 21 | 22 | -- set_option trace.tidy true 23 | 24 | -- def functor.map_presheaf (F : C ⥤ D) : Presheaf.{u v} C ⥤ Presheaf.{u v} D := 25 | -- { obj := λ X, { X := X.X, 𝒪 := X.𝒪 ⋙ F }, 26 | -- map := λ X Y f, { f := f.f, c := whisker_right f.c F }, 27 | -- map_id' := 28 | -- begin 29 | -- intros X, 30 | -- ext1, 31 | -- swap, 32 | -- refl, 33 | -- ext1, -- check the equality of natural transformations componentwise 34 | -- dsimp at *, 35 | -- erw functor.map_id, 36 | -- erw functor.map_id, 37 | -- simp, 38 | -- end, 39 | -- map_comp' := 40 | -- begin 41 | -- intros X Y Z f g, 42 | -- ext1, 43 | -- swap, 44 | -- refl, 45 | -- tidy, 46 | -- dsimp [opens.map_iso, nat_iso.of_components, opens.map], 47 | -- erw functor.map_id, 48 | -- erw functor.map_id, 49 | -- simp, 50 | -- end }. 51 | 52 | -- def nat_trans.map_presheaf {F G : C ⥤ D} (α : F ⟹ G) : (G.map_presheaf) ⟹ (F.map_presheaf) := 53 | -- { app := λ ℱ, 54 | -- { f := 𝟙 ℱ.X, 55 | -- c := { app := λ U, (α.app _) ≫ G.map (ℱ.𝒪.map ((opens.map_id ℱ.X).hom.app U)), 56 | -- naturality' := sorry } 57 | -- }, 58 | -- naturality' := sorry } 59 | 60 | -- lemma map₂_id {F : C ⥤ D} : (nat_trans.id F).map_presheaf = nat_trans.id (F.map_presheaf) := 61 | -- sorry 62 | -- lemma map₂_vcomp {F G H : C ⥤ D} (α : F ⟹ G) (β : G ⟹ H) : β.map_presheaf ⊟ α.map_presheaf = 63 | -- (α ⊟ β).map_presheaf := sorry 64 | -- end 65 | 66 | -- section 67 | -- variables (C : Type u) [𝒞 : category.{u v} C] 68 | -- include 𝒞 69 | -- def presheaves.map_presheaf_id : ((functor.id C).map_presheaf) ≅ functor.id (Presheaf.{u v} C) := 70 | -- sorry 71 | -- end 72 | 73 | -- section 74 | -- variables {C : Type u} [𝒞 : category.{u v} C] 75 | -- {D : Type u} [𝒟 : category.{u v} D] 76 | -- {E : Type u} [ℰ : category.{u v} E] 77 | -- include 𝒞 𝒟 ℰ 78 | -- def presheaves.map_presheaf_comp (F : C ⥤ D) (G : D ⥤ E) : 79 | -- (F.map_presheaf) ⋙ (G.map_presheaf) ≅ (F ⋙ G).map_presheaf := 80 | -- { hom := sorry, 81 | -- inv := sorry, 82 | -- hom_inv_id' := sorry, 83 | -- inv_hom_id' := sorry } 84 | 85 | -- lemma nat_trans.map_presheaf_hcomp {F G : C ⥤ D} {H K : D ⥤ E} (α : F ⟹ G) (β : H ⟹ K) : 86 | -- ((α.map_presheaf ◫ β.map_presheaf) ⊟ (presheaves.map_presheaf_comp F H).hom) = 87 | -- ((presheaves.map_presheaf_comp G K).hom ⊟ ((α ◫ β).map_presheaf)) := 88 | -- sorry 89 | -- end 90 | 91 | 92 | -- end category_theory -------------------------------------------------------------------------------- /src/category_theory/presheaves/sheaves.lean: -------------------------------------------------------------------------------- 1 | -- import category_theory.opposites 2 | -- import category_theory.full_subcategory 3 | -- import category_theory.limits.types 4 | -- import topology.Top.basic 5 | -- import category_theory.limits.obviously 6 | 7 | 8 | -- open category_theory 9 | -- open category_theory.limits 10 | -- open topological_space 11 | 12 | -- universes u v u₁ v₁ u₂ v₂ 13 | 14 | -- variable (X : Top.{v}) 15 | 16 | -- local attribute [back] topological_space.is_open_inter 17 | -- -- local attribute [back] opens.property 18 | 19 | -- instance has_inter_open_set : has_inter (opens X) := 20 | -- { inter := λ U V, ⟨ U.val ∩ V.val, by obviously ⟩ } 21 | 22 | -- instance has_inter_open_set_op : has_inter ((opens X)ᵒᵖ) := sorry -- has_inter_open_set X 23 | 24 | -- -- def cover_intersections_index (I : Type v) : grothendieck_category (ParallelPair_functor (@prod.fst I I) (@prod.snd I I)) 25 | -- -- def cover_intersections (c : cover X) : (cover_intersections_index c.I) ⥤ open_set X := 26 | -- -- { obj := λ p, match p.1 with 27 | -- -- | _1 := c.U p.2.1 ∩ c.U p.2.2 28 | -- -- | _2 := c.U p.2 29 | -- -- end, 30 | -- -- map := λ p q f, sorry 31 | -- -- } 32 | 33 | -- -- @[tidy] meta def sbe := `[solve_by_elim [sum.inl, sum.inr, ulift.up, plift.up, trivial] {max_rep := 5}] 34 | 35 | -- -- instance (I : Type v) : category (I × I ⊕ I) := 36 | -- -- { hom := λ X Y, match (X, Y) with 37 | -- -- | (sum.inl (i, j), sum.inr k) := ulift (plift (i = k)) ⊕ ulift (plift (j = k)) 38 | -- -- | (sum.inl (i, j), sum.inl (i', j')) := ulift (plift (i = i' ∧ j = j')) 39 | -- -- | (sum.inr k, sum.inr k') := ulift (plift (k = k')) 40 | -- -- | (sum.inr k, sum.inl (i, j)) := pempty 41 | -- -- end, 42 | -- -- id := by tidy, 43 | -- -- comp := by tidy, 44 | -- -- } 45 | 46 | -- structure cover := 47 | -- (I : Type v) 48 | -- (U : I → (opens X)) 49 | 50 | -- variables {X} 51 | 52 | -- def cover.union (c : cover X) : opens X := 53 | -- ⟨ set.Union (λ i : c.I, (c.U i).1), 54 | -- begin 55 | -- apply topological_space.is_open_sUnion, 56 | -- tidy, 57 | -- subst H_h, 58 | -- exact (c.U H_w).2 59 | -- end ⟩ 60 | 61 | -- def cover.sub (c : cover X) (i : c.I) : c.U i ⟶ c.union := sorry 62 | 63 | -- definition cover.left (c : cover X) (i j : c.I) : (c.U i ∩ c.U j) ⟶ (c.U i) := by obviously 64 | -- definition cover.right (c : cover X) (i j : c.I) : (c.U i ∩ c.U j) ⟶ (c.U j) := by obviously 65 | 66 | -- section 67 | -- variables {D : Type u₂} [𝒟 : category.{u₂ v₂} D] 68 | -- variables {c : cover X} (i j : c.I) (F : (opens X)ᵒᵖ ⥤ D) 69 | -- include 𝒟 70 | 71 | -- definition res_left : (F.obj (c.U i)) ⟶ (F.obj ((c.U i) ∩ (c.U j))) := 72 | -- F.map (c.left i j) 73 | 74 | -- definition res_right := 75 | -- F.map (c.right i j) 76 | 77 | -- definition res_union : (F.obj (c.union)) ⟶ (F.obj ((c.U i))) := 78 | -- F.map (c.sub i) 79 | 80 | -- @[simp] lemma res_left_right : res_union i F ≫ res_left i j F = res_union j F ≫ res_right i j F := 81 | -- begin 82 | -- dsimp [res_union, res_left, res_right], 83 | -- rw ← functor.map_comp, 84 | -- rw ← functor.map_comp, 85 | -- refl, 86 | -- end 87 | -- end 88 | 89 | -- section 90 | -- variables {V : Type u} [𝒱 : category.{u v} V] [has_products.{u v} V] 91 | -- include 𝒱 92 | 93 | -- variables (c : cover X) (F : (opens X)ᵒᵖ ⥤ V) 94 | 95 | -- def sections : V := 96 | -- limits.pi.{u v} (λ i : c.I, F.obj (c.U i)) 97 | 98 | -- def overlaps : V := 99 | -- limits.pi.{u v} (λ p : c.I × c.I, F.obj (c.U p.1 ∩ c.U p.2)) 100 | 101 | -- def left : (sections c F) ⟶ (overlaps c F) := 102 | -- pi.pre _ (λ p : c.I × c.I, p.1) ≫ pi.map (λ p, res_left p.1 p.2 F) 103 | 104 | -- def right : (sections c F) ⟶ (overlaps c F) := 105 | -- pi.pre _ (λ p : c.I × c.I, p.2) ≫ pi.map (λ p, res_right p.1 p.2 F) 106 | 107 | -- def res : F.obj (c.union) ⟶ (sections c F) := 108 | -- pi.lift (λ i, res_union i F) 109 | 110 | -- @[simp] lemma res_left_right' : res c F ≫ left c F = res c F ≫ right c F := 111 | -- begin 112 | -- dsimp [left, right, res], 113 | -- rw ← category.assoc, 114 | -- simp, 115 | -- rw ← category.assoc, 116 | -- simp, 117 | -- end 118 | 119 | -- def cover_fork : fork (left c F) (right c F) := 120 | -- fork.of_ι (res c F) (by tidy) 121 | 122 | -- class is_sheaf (presheaf : (opens X)ᵒᵖ ⥤ V) := 123 | -- (sheaf_condition : Π (c : cover X), is_equalizer (cover_fork c presheaf)) 124 | 125 | -- variables (X V) 126 | 127 | -- structure sheaf := 128 | -- (presheaf : (opens X)ᵒᵖ ⥤ V) 129 | -- (sheaf_condition : is_sheaf presheaf) 130 | 131 | -- end 132 | -------------------------------------------------------------------------------- /src/category_theory/presheaves/sheaves_of_types.lean: -------------------------------------------------------------------------------- 1 | -- import category_theory.presheaves.sheaves 2 | -- import category_theory.limits.preserves 3 | -- import category_theory.functor.isomorphism 4 | 5 | -- universes u v 6 | 7 | -- open category_theory 8 | -- open category_theory.limits 9 | -- open category_theory.examples 10 | -- open topological_space 11 | 12 | -- -- We now provide an alternative 'pointwise' constructor for sheaves of types. 13 | 14 | -- -- This should eventually be generalised to sheaves of categories with a 15 | -- -- fibre functor with reflects iso and preserves limits. 16 | -- section 17 | -- variables {X : Top.{v}} 18 | 19 | -- structure compatible_sections (c : cover X) (F : (opens X)ᵒᵖ ⥤ (Type u)) := 20 | -- (sections : Π i : c.I, F.obj (c.U i)) 21 | -- (compatibility : Π i j : c.I, res_left i j F (sections i) = res_right i j F (sections j)) 22 | 23 | -- structure gluing {c : cover X} {F : (opens X)ᵒᵖ ⥤ (Type u)} (s : compatible_sections c F) := 24 | -- («section» : F.obj c.union) 25 | -- (restrictions : ∀ i : c.I, (F.map (c.sub i)) «section» = s.sections i) 26 | -- (uniqueness : ∀ (Γ : F.obj c.union) (w : ∀ i : c.I, (F.map (c.sub i)) Γ = s.sections i), Γ = «section») 27 | 28 | -- -- definition sheaf.of_types 29 | -- -- (presheaf : (opens X)ᵒᵖ ⥤ (Type v)) 30 | -- -- (sheaf_condition : Π (c : cover X) 31 | -- -- (s : compatible_sections c presheaf), gluing s) : 32 | -- -- sheaf.{v+1 v} X (Type v) := 33 | -- -- { presheaf := presheaf, 34 | -- -- sheaf_condition := ⟨ λ c, 35 | -- -- let σ : Π s : fork (left c presheaf) (right c presheaf), s.X → compatible_sections c presheaf := 36 | -- -- λ s x, { sections := λ i, pi.π (λ i : c.I, presheaf.obj (c.U i)) i (s.ι x), 37 | -- -- compatibility := λ i j, congr_fun (congr_fun s.w x) (i,j), } in 38 | -- -- { lift := λ s x, (sheaf_condition c (σ s x)).«section», 39 | -- -- fac' := λ s, funext $ λ x, funext $ λ i, (sheaf_condition c (σ s x)).restrictions i, 40 | -- -- uniq' := λ s m w, funext $ λ x, (sheaf_condition c (σ s x)).uniqueness (m x) (λ i, congr_fun (congr_fun w x) i), 41 | -- -- } ⟩ } 42 | -- end 43 | 44 | -- section 45 | -- variables {X : Top.{u}} 46 | 47 | -- variables {V : Type (u+1)} [𝒱 : large_category V] [has_products.{u+1 u} V] (ℱ : V ⥤ (Type u)) 48 | -- [faithful ℱ] [category_theory.limits.preserves_limits ℱ] [reflects_isos ℱ] 49 | -- include 𝒱 50 | 51 | -- -- This is a good project! 52 | -- def sheaf.of_sheaf_of_types 53 | -- (presheaf : (opens X)ᵒᵖ ⥤ V) 54 | -- (underlying_is_sheaf : is_sheaf (presheaf ⋙ ℱ)) : is_sheaf presheaf := sorry 55 | 56 | -- end 57 | -------------------------------------------------------------------------------- /src/category_theory/projectives/default.lean: -------------------------------------------------------------------------------- 1 | -- import ..abelian.abelian 2 | -- import category_theory.universal.zero 3 | 4 | 5 | -- open category_theory 6 | -- open category_theory.limits 7 | 8 | -- universes u v 9 | 10 | -- class projective {C : Type u} [category.{u v} C] (P : C) := 11 | -- (lift : Π M N : C, Π f : M ⟶ N, Π w : epi f, Π g : P ⟶ N, P ⟶ M) 12 | -- (factorisation : Π M N : C, Π f : M ⟶ N, Π w : epi f, Π g : P ⟶ N, (lift M N f w g) ≫ f = g) 13 | 14 | -- structure projective_cover {C : Type u} [category.{u v} C] (X : C) := 15 | -- (cover : C) 16 | -- (map : cover ⟶ X) 17 | -- (projectivity: projective cover) 18 | -- (surjectivity: epi map) 19 | 20 | -- class enough_projectives (C : Type u) [category.{u v} C] := 21 | -- (cover : Π X : C, projective_cover X) 22 | 23 | -- structure chain_complex (C : Type u) [category.{u v} C] [has_zero_object.{u v} C] := 24 | -- (objects : ℤ → C) 25 | -- (d : Π i : ℤ, objects i ⟶ objects (i + 1)) 26 | -- (d_squared : Π i, (d i) ≫ (d (i+1)) = zero_morphism _ _) 27 | 28 | -- structure projective_resolution {C : Type u} [category.{u v} C] [has_zero_object.{u v} C] (X : C) := 29 | -- (complex : chain_complex C) 30 | -- (projectivity : Π i : ℤ, i < 0 → projective (complex.objects i)) 31 | -- (of : complex.objects 0 = X) 32 | -- (nothing : Π i : ℤ, i > 0 → complex.objects i = zero_object.{u v} C) -- it's zero 33 | 34 | -- -- TODO find out why we don't also need universe annotations on `enough_projectives`? 35 | -- -- TODO this needs the category to be abelian! 36 | -- def construct_injective_resolution {C : Type u} [category.{u v} C] [has_zero_object.{u v} C] [enough_projectives C] (X : C) : projective_resolution X := sorry 37 | -- -- we define the complex inductively, taking the cover of X, then the cover of its kernel, and so on 38 | 39 | -- /- 40 | -- Baer's criterion: 41 | -- A (right) R-module E is injective iff for every right ideal J ⊂ R, every map J → E extends to a map R → E 42 | 43 | -- The forward direction is immediate from the definition. The reverse direction is harder, and uses Zorn. 44 | -- -/ 45 | 46 | -- -- Corollary: If R is a PID, then an R-module A is injective iff it is 'divisible': ∀ r ∈ R, r ≠ 0, ∀ a ∈ A, ∃ b ∈ A so a = b * r. 47 | 48 | -- /- Lemmas: 49 | 50 | -- M is projective iff Hom_A(M ⟶ -) is exact 51 | -- M is projective in A iff M is injective in Aᵒᵖ 52 | -- M is injective iff Hom_A(- ⟶ M) is exact 53 | -- -/ 54 | 55 | -- -- Comparision theorem: a map lifts to a chain map between resolutions, which is unique up to homotopy 56 | 57 | -- -- If R : D → C is additive, L : C → D is exact, and L ⊣ R, then R preserves injectives. 58 | 59 | -------------------------------------------------------------------------------- /src/category_theory/sigma_category.lean: -------------------------------------------------------------------------------- 1 | -- Copyright (c) 2017 Scott Morrison. All rights reserved. 2 | -- Released under Apache 2.0 license as described in the file LICENSE. 3 | -- Authors: Scott Morrison 4 | import category_theory.fully_faithful 5 | 6 | /- This is exactly analogous to the full_subcategory definition for a subtype, but 7 | for a sigma type instead. -/ 8 | 9 | namespace category_theory 10 | 11 | universes v u w 12 | 13 | section 14 | variables {C : Type u} [𝒞 : category.{v} C] 15 | include 𝒞 16 | 17 | instance sigma_category (Z : C → Type w) : category.{v} (Σ X : C, Z X) := 18 | { hom := λ X Y, X.1 ⟶ Y.1, 19 | id := λ X, 𝟙 X.1, 20 | comp := λ _ _ _ f g, f ≫ g } 21 | 22 | def sigma_category_embedding (Z : C → Type w) : (Σ X : C, Z X) ⥤ C := 23 | { obj := λ X, X.1, 24 | map := λ _ _ f, f } 25 | 26 | instance sigma_category_full (Z : C → Type w) : full (sigma_category_embedding Z) := by obviously 27 | instance sigma_category_faithful (Z : C → Type w) : faithful (sigma_category_embedding Z) := by obviously 28 | end 29 | 30 | end category_theory -------------------------------------------------------------------------------- /src/category_theory/simplicial_sets/default.lean: -------------------------------------------------------------------------------- 1 | import category_theory.category 2 | import category_theory.tactics.obviously 3 | 4 | open category_theory 5 | 6 | def simplicial_operator (n m : ℕ) := { f : fin n → fin m // ∀ i < n - 1, f ⟨ i, sorry ⟩ ≤ f ⟨ i + 1, sorry ⟩ } 7 | 8 | def Δ : category ℕ := 9 | { hom := λ n m, simplicial_operator n m, 10 | comp := λ _ _ _ f g, ⟨ g.1 ∘ f.1, sorry ⟩, 11 | id := λ n, ⟨ id, sorry ⟩, } 12 | 13 | -- def SimplicialSet := Presheaf Δ -------------------------------------------------------------------------------- /src/category_theory/small.lean: -------------------------------------------------------------------------------- 1 | /- Categories which are small relative to a cardinal κ. 2 | κ-filtered categories. 3 | Normally we care about these concepts for categories which are 4 | used to index (co)limits, so we work with small_categories. -/ 5 | 6 | import category_theory.category 7 | import category_theory.functor 8 | import category_theory.limits.cones 9 | import set_theory.cardinal 10 | 11 | universe u 12 | 13 | namespace category_theory 14 | 15 | variables (κ : cardinal.{u}) 16 | 17 | def is_kappa_small (I : Type u) [small_category I] : Prop := 18 | cardinal.mk (Σ (a b : I), a ⟶ b) < κ 19 | 20 | structure kappa_filtered (C : Type u) [small_category C] : Prop := 21 | (has_cocones : ∀ (I : Type u) [small_category I] (hI : is_kappa_small κ I) (F : I ⥤ C), 22 | nonempty (limits.cocone F)) 23 | 24 | end category_theory 25 | -------------------------------------------------------------------------------- /src/category_theory/tactics/obviously.lean: -------------------------------------------------------------------------------- 1 | import category_theory.natural_isomorphism 2 | import category_theory.products 3 | import category_theory.types 4 | import category_theory.fully_faithful 5 | import category_theory.yoneda 6 | import category_theory.limits.cones 7 | import category_theory.equivalence 8 | 9 | import tactic.tidy 10 | import tactic.rewrite_search 11 | import tidy.forwards_reasoning 12 | import tidy.backwards_reasoning 13 | import tidy.tidy 14 | 15 | open category_theory 16 | 17 | @[suggest] def use_category_theory := `category_theory 18 | 19 | attribute [elim] full.preimage 20 | attribute [forward] faithful.injectivity 21 | 22 | attribute [search] category.comp_id category.id_comp category.assoc 23 | attribute [search] category_theory.functor.map_comp category_theory.functor.map_id 24 | attribute [search] nat_trans.naturality 25 | attribute [search] iso.hom_inv_id iso.inv_hom_id 26 | attribute [search] nat_iso.naturality_1 nat_iso.naturality_2 27 | 28 | attribute [search] yoneda.obj_map_id 29 | 30 | attribute [search] equivalence.fun_inv_map equivalence.inv_fun_map 31 | is_equivalence.fun_inv_map is_equivalence.inv_fun_map 32 | 33 | -- attribute [search] cone_morphism.w cocone_morphism.w 34 | -------------------------------------------------------------------------------- /src/category_theory/types/functor.lean: -------------------------------------------------------------------------------- 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.types 6 | -- import category_theory.tactics.obviously 7 | 8 | -- open category_theory 9 | 10 | -- universes u v 11 | 12 | -- instance functor_of_functor (F : (Type u) ⥤ (Type v)) : _root_.functor F.obj := 13 | -- { map := λ _ _ f, F.map f } 14 | 15 | -- -- local attribute [tidy] dsimp' 16 | 17 | -- -- TODO yuck, automate 18 | -- instance lawful_functor_of_Functor (F : (Type u) ⥤ (Type v)) : is_lawful_functor (F.obj) := 19 | -- { id_map := begin obviously, end, 20 | -- comp_map := begin 21 | -- tidy, 22 | -- calc (F.map (λ (x : α), h (g x))) x = (F.map (g ≫ h)) x : by obviously 23 | -- ... = (F.map h) ((F.map g) x) : by obviously 24 | -- end 25 | -- } 26 | 27 | -- attribute [search] is_lawful_functor.comp_map 28 | 29 | -- def functor_of_functor' (g : Type u → Type v) [functor g] [is_lawful_functor g] : (Type u) ⥤ (Type v) := 30 | -- { obj := g, 31 | -- map' := λ X Y f z, f <$> z } -------------------------------------------------------------------------------- /src/category_theory/universal/kernels.lean: -------------------------------------------------------------------------------- 1 | -- import category_theory.universal.zero 2 | -- import category_theory.limits.equalizers 3 | -- import category_theory.over 4 | 5 | -- open category_theory 6 | 7 | -- universes u v 8 | 9 | -- namespace category_theory.limits 10 | 11 | -- variables {C : Type u} [𝒞 : category.{u v} C] [has_zero_object.{u v} C] 12 | -- include 𝒞 13 | -- variables {X Y Z : C} 14 | 15 | -- structure is_kernel (f : Y ⟶ Z) (ι : X ⟶ Y) := 16 | -- (w' : ι ≫ f = zero_morphism _ _) 17 | -- (lift : Π {X' : C} {ι' : X' ⟶ Y} (w : ι' ≫ f = zero_morphism X' Z), X' ⟶ X) 18 | -- (fac' : Π {X' : C} {ι' : X' ⟶ Y} (w : ι' ≫ f = zero_morphism X' Z), (lift w) ≫ ι = ι' . obviously) 19 | -- (uniq' : Π {X' : C} {ι' : X' ⟶ Y} (w : ι' ≫ f = zero_morphism X' Z) {m : X' ⟶ X} (h : m ≫ ι = ι'), m = lift w . obviously) 20 | 21 | -- restate_axiom is_kernel.w' 22 | -- attribute [search] is_kernel.w 23 | -- restate_axiom is_kernel.fac' 24 | -- attribute [simp,search] is_kernel.fac 25 | -- restate_axiom is_kernel.uniq' 26 | -- attribute [search,elim] is_kernel.uniq 27 | 28 | -- @[extensionality] lemma is_kernel.ext {f : Y ⟶ Z} {ι : X ⟶ Y} (P Q : is_kernel f ι) : P = Q := 29 | -- begin cases P, cases Q, obviously end 30 | 31 | -- -- TODO should be marked [search]? 32 | -- lemma kernel.w {f : Y ⟶ Z} {X : C} (ι : X ⟶ Y) (k : is_kernel f ι) : ι ≫ f = zero_morphism _ _ := by rw k.w 33 | 34 | -- variable (C) 35 | 36 | -- class has_kernels := 37 | -- (kernel : Π {Y Z : C} (f : Y ⟶ Z), C) 38 | -- (ι : Π {Y Z : C} (f : Y ⟶ Z), kernel f ⟶ Y) 39 | -- (is : Π {Y Z : C} (f : Y ⟶ Z), is_kernel f (ι f)) 40 | 41 | -- variable {C} 42 | 43 | -- variable [has_kernels.{u v} C] 44 | 45 | -- def kernel (f : Y ⟶ Z) : C := has_kernels.kernel.{u v} f 46 | -- def kernel.ι (f : Y ⟶ Z) : kernel f ⟶ Y := has_kernels.ι.{u v} f 47 | -- def kernel.subobject (f : Y ⟶ Z) : over Y := ⟨ kernel f, kernel.ι f ⟩ 48 | 49 | -- def kernel_of_equalizer {f : Y ⟶ Z} {t : fork f (zero_morphism _ _)} (e : is_equalizer t) : is_kernel f t.ι := 50 | -- { w' := begin have p := t.w, simp at p, exact p end, 51 | -- lift := λ X' ι' w, e.lift { X := X', ι := ι' }, 52 | -- uniq' := λ X' ι' w m h, begin tidy, apply e.uniq { X := X', ι := m ≫ t.ι }, tidy end } 53 | 54 | -- -- def equalizer_of_kernel {f : Y ⟶ Z} {t : fork f (zero_morphism _ _)} (k : is_kernel f t.ι) : is_equalizer t := 55 | -- -- { lift := λ s, begin have e := s.w, tidy, exact k.lift e, end, 56 | -- -- uniq := sorry, } 57 | 58 | -- -- def kernels_are_equalizers {f : Y ⟶ Z} (t : fork f (zero_morphism _ _)) : equiv (is_kernel f t.ι) (is_equalizer t) := 59 | -- -- { to_fun := equalizer_of_kernel, 60 | -- -- inv_fun := kernel_of_equalizer, 61 | -- -- left_inv := sorry, 62 | -- -- right_inv := sorry } 63 | 64 | -- end category_theory.limits 65 | 66 | -------------------------------------------------------------------------------- /src/category_theory/universal/monic.lean: -------------------------------------------------------------------------------- 1 | -- -- Copyright (c) 2017 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.equalizers 6 | -- import category_theory.abelian.monic 7 | 8 | -- open category_theory 9 | -- open category_theory.limits 10 | 11 | -- namespace category_theory.universal.monic 12 | 13 | -- universes u v 14 | -- variables {C : Type u} [category.{u v} C] {X Y Z : C} 15 | 16 | -- structure regular_mono (f : X ⟶ Y) := 17 | -- (Z : C) 18 | -- (a b : Y ⟶ Z) 19 | -- (w : f ≫ a = f ≫ b) 20 | -- (e : is_equalizer ⟨ ⟨ X ⟩, f, w ⟩) 21 | 22 | -- -- EXERCISE 23 | -- -- def SplitMonic_implies_RegularMonic 24 | -- -- {f : Hom X Y} 25 | -- -- (s : SplitMonic f) : RegularMonic f := sorry 26 | 27 | -- -- EXERCISE 28 | -- -- def RegularMonic_implies_Monic 29 | -- -- {f : Hom X Y} 30 | -- -- (s : RegularMonic f) : Monic f := sorry 31 | 32 | -- structure regular_epi (f : Y ⟶ Z) := 33 | -- (X : C) 34 | -- (a b : X ⟶ Y) 35 | -- (w : a ≫ f = b ≫ f) 36 | -- (c : is_coequalizer ⟨ ⟨ Z ⟩, f, w ⟩) 37 | 38 | -- end category_theory.universal.monic -------------------------------------------------------------------------------- /src/category_theory/universal/products.lean: -------------------------------------------------------------------------------- 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, Reid Barton, Mario Carneiro 4 | 5 | -- import category_theory.limits.binary_products 6 | 7 | -- open category_theory 8 | 9 | -- universes u v 10 | 11 | -- namespace category_theory.limits 12 | 13 | -- variables {C : Type u} [𝒞 : category.{u v} C] [has_binary_products.{u v} C] 14 | -- include 𝒞 15 | 16 | -- def binary_product.braiding (P Q : C) : prod P Q ≅ prod Q P := 17 | -- { hom := prod.lift (prod.π₂ _ _) (prod.π₁ _ _), 18 | -- inv := prod.lift (prod.π₂ _ _) (prod.π₁ _ _) } 19 | 20 | -- def binary_product.symmetry (P Q : C) : (binary_product.braiding P Q).hom ≫ (binary_product.braiding Q P).hom = 𝟙 _ := 21 | -- begin 22 | -- dunfold binary_product.braiding, 23 | -- obviously, 24 | -- end 25 | 26 | -- def binary_product.associativity (P Q R : C) : (prod (prod P Q) R) ≅ (prod P (prod Q R)) := 27 | -- { hom := prod.lift (prod.π₁ _ _ ≫ prod.π₁ _ _) (prod.lift (prod.π₁ _ _ ≫ prod.π₂ _ _) (prod.π₂ _ _)), 28 | -- inv := prod.lift (prod.lift (prod.π₁ _ _) (prod.π₂ _ _ ≫ prod.π₁ _ _)) (prod.π₂ _ _ ≫ prod.π₂ _ _), 29 | -- hom_inv_id' := begin ext; simp; rw ← category.assoc; simp, end, 30 | -- inv_hom_id' := begin ext; simp; rw ← category.assoc; simp, end } 31 | 32 | -- -- TODO binary_coproduct 33 | 34 | -- -- TODO verify the pentagon? 35 | 36 | -- end category_theory.limits -------------------------------------------------------------------------------- /src/category_theory/universal/strongly_concrete.lean: -------------------------------------------------------------------------------- 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.universal.continuous 6 | -- import category_theory.concrete 7 | -- import category_theory.functor.isomorphism 8 | 9 | -- open category_theory 10 | 11 | -- namespace category_theory 12 | 13 | -- universes u 14 | -- variable (C : Type (u+1)) 15 | -- variable [large_category C] 16 | 17 | -- class strongly_concrete [concrete C] := 18 | -- (reflects_isos : reflects_isos (concrete.fibre_functor C)) 19 | -- (preserves_limits : continuous (concrete.fibre_functor C)) 20 | 21 | -- -- PROJECT 22 | -- instance type_strongly_concrete : strongly_concrete (Type u) := { 23 | -- reflects_isos := sorry, 24 | -- preserves_limits := sorry 25 | -- } 26 | 27 | -- end category_theory -------------------------------------------------------------------------------- /src/category_theory/universal/zero.lean: -------------------------------------------------------------------------------- 1 | -- import category_theory.limits.terminal 2 | -- import category_theory.tactics.obviously 3 | 4 | -- open category_theory 5 | 6 | -- universes u v 7 | 8 | -- namespace category_theory.limits 9 | 10 | -- variables {C : Type u} [𝒞 : category.{u v} C] 11 | -- include 𝒞 12 | 13 | -- structure is_zero (t : C) := 14 | -- (lift : ∀ (s : C), s ⟶ t) 15 | -- (uniq_lift' : ∀ (s : C) (m : s ⟶ t), m = lift s . obviously) 16 | -- (desc : ∀ (s : C), t ⟶ s) 17 | -- (uniq_desc' : ∀ (s : C) (m : t ⟶ s), m = desc s . obviously) 18 | 19 | -- namespace is_zero 20 | -- def to_is_initial {t : C} (Z : is_zero.{u v} t) : is_initial.{u v} t := { desc := Z.desc, uniq' := Z.uniq_desc' } 21 | -- def to_is_terminal {t : C} (Z : is_zero.{u v} t) : is_terminal.{u v} t := { lift := Z.lift, uniq' := Z.uniq_lift' } 22 | -- end is_zero 23 | 24 | 25 | -- restate_axiom is_zero.uniq_lift' 26 | -- restate_axiom is_zero.uniq_desc' 27 | -- attribute [search,elim] is_zero.uniq_lift is_zero.uniq_desc 28 | 29 | -- @[extensionality] lemma is_zero.ext {X : C} (P Q : is_zero.{u v} X) : P = Q := 30 | -- begin tactic.unfreeze_local_instances, cases P, cases Q, congr, obviously, end 31 | 32 | -- instance hom_to_zero_subsingleton (X Z : C) (B : is_zero.{u v} Z) : subsingleton (X ⟶ Z) := 33 | -- limits.hom_to_terminal_subsingleton X Z B.to_is_terminal 34 | -- instance hom_from_zero_subsingleton (Z X : C) (B : is_zero.{u v} Z) : subsingleton (Z ⟶ X) := 35 | -- limits.hom_from_initial_subsingleton Z X B.to_is_initial 36 | 37 | -- variable (C) 38 | 39 | -- class has_zero_object := 40 | -- (zero : C) 41 | -- (is_zero : is_zero.{u v} zero) 42 | 43 | -- end category_theory.limits 44 | 45 | -- namespace category_theory.limits 46 | 47 | -- def zero_object := has_zero_object.zero.{u v} 48 | 49 | -- variables {C : Type u} [𝒞 : category.{u v} C] 50 | -- include 𝒞 51 | 52 | -- variables [has_zero_object.{u v} C] 53 | 54 | -- def zero_is_zero : is_zero.{u v} (zero_object.{u v} C) := has_zero_object.is_zero C 55 | 56 | -- instance has_initial_object_of_has_zero : has_initial_object.{u v} C := 57 | -- { initial := zero_object.{u v} C, 58 | -- is_initial := zero_is_zero.to_is_initial } 59 | 60 | -- instance has_terminal_object_of_has_zero: has_terminal_object.{u v} C := 61 | -- { terminal := zero_object.{u v} C, 62 | -- is_terminal := zero_is_zero.to_is_terminal } 63 | 64 | -- def zero_morphism (X Y : C) : X ⟶ Y := (zero_is_zero.lift.{u v} X) ≫ (zero_is_zero.desc.{u v} Y) 65 | 66 | -- instance hom_has_zero (X Y : C) : _root_.has_zero (X ⟶ Y) := { zero := zero_morphism X Y } 67 | 68 | -- @[extensionality] lemma ext.out (Y : C) (f g : zero_object.{u v} C ⟶ Y) : f = g := 69 | -- begin 70 | -- rw (initial.universal_property).uniq _ f, 71 | -- rw (initial.universal_property).uniq _ g, 72 | -- end 73 | -- @[extensionality] lemma ext.in (Y : C) (f g : Y ⟶ zero_object.{u v} C) : f = g := 74 | -- begin 75 | -- rw (terminal.universal_property).uniq _ f, 76 | -- rw (terminal.universal_property).uniq _ g, 77 | -- end 78 | 79 | -- @[simp] lemma zero_morphism_left {X Y Z : C} (f : Y ⟶ Z) : (zero_morphism X Y) ≫ f = zero_morphism X Z := 80 | -- begin 81 | -- unfold zero_morphism, 82 | -- rw category.assoc, 83 | -- congr, 84 | -- tidy, 85 | -- end 86 | -- @[simp] lemma zero_morphism_right {X Y Z : C} (f : X ⟶ Y) : f ≫ (zero_morphism Y Z) = zero_morphism X Z := 87 | -- begin 88 | -- unfold zero_morphism, 89 | -- rw ← category.assoc, 90 | -- congr, 91 | -- tidy, 92 | -- end 93 | 94 | -- end category_theory.limits 95 | 96 | -------------------------------------------------------------------------------- /src/category_theory/universe_lifting.lean: -------------------------------------------------------------------------------- 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.equivalence 6 | import tidy.backwards_reasoning 7 | import category_theory.tactics.obviously 8 | 9 | namespace category_theory 10 | 11 | universes u₁ 12 | 13 | variable (C : Type u₁) 14 | variable [small_category C] 15 | 16 | local attribute [back] category_struct.id 17 | 18 | def universe_lift.equivalence : equivalence C (ulift.{(u₁+1)} C) := by obviously 19 | 20 | end category_theory -------------------------------------------------------------------------------- /src/category_theory/yoneda_comparisons.lean: -------------------------------------------------------------------------------- 1 | import category_theory.yoneda 2 | import category_theory.follow_your_nose 3 | 4 | universes v₁ u₁ 5 | 6 | open category_theory 7 | open opposite 8 | 9 | -- Unimath, Coq 10 | -- https://github.com/UniMath/UniMath/blob/master/UniMath/CategoryTheory/yoneda.v 11 | -- Greg O'Keefe, Isabelle 12 | -- https://www.isa-afp.org/browser_info/current/AFP/Category/document.pdf 13 | -- Alexander Katovsky, Isabelle 14 | -- https://www.isa-afp.org/browser_info/current/AFP/Category2/document.pdf 15 | -- Gross, Chlipala, Spivak, Coq 16 | -- https://arxiv.org/src/1401.7694v2/anc/HoTT/theories/categories/Yoneda.v 17 | 18 | variables (C : Type u₁) [𝒞 : category.{v₁+1} C] 19 | include 𝒞 20 | 21 | def yoneda_0 : C ⥤ ((Cᵒᵖ) ⥤ Type v₁) := 22 | { obj := λ X, 23 | { obj := λ Y, (unop Y) ⟶ X, 24 | map := λ Y Y' f g, f.unop ≫ g, 25 | map_comp' := begin intros, ext1, dsimp, erw [category.assoc] end, 26 | map_id' := begin intros, ext1, dsimp, erw [category.id_comp] end }, 27 | map := λ X X' f, 28 | { app := λ Y g, g ≫ f, 29 | naturality' := begin intros, ext1, dsimp, simp end }, 30 | map_comp' := begin intros, ext1, ext1, dsimp, simp end, 31 | map_id' := begin intros, ext1, ext1, dsimp, simp end }. 32 | 33 | def yoneda_1 : C ⥤ ((Cᵒᵖ) ⥤ Type v₁) := 34 | { obj := λ X, 35 | { obj := λ Y, (unop Y) ⟶ X, 36 | map := λ Y Y' f g, f.unop ≫ g, 37 | map_comp' := begin intros, ext1, dsimp, erw [category.assoc] end, 38 | map_id' := begin intros, ext1, dsimp, erw [category.id_comp] end }, 39 | map := λ X X' f, { app := λ Y g, g ≫ f } }. 40 | 41 | def yoneda_2 : C ⥤ ((Cᵒᵖ) ⥤ Type v₁) := 42 | { obj := λ X, 43 | { obj := λ Y, (unop Y) ⟶ X, 44 | map := λ Y Y' f g, f.unop ≫ g }, 45 | map := λ X X' f, { app := λ Y g, g ≫ f } }. 46 | 47 | def yoneda_3 : C ⥤ ((Cᵒᵖ) ⥤ Type v₁) := ƛ X, ƛ Y, (unop Y) ⟶ X. 48 | 49 | def yoneda_lemma' : (yoneda_pairing C) ≅ (yoneda_evaluation C) := 50 | { hom := { app := λ F x, ulift.up ((x.app F.1) (𝟙 (unop F.1))) }, 51 | inv := { app := λ F x, { app := λ X a, (F.2.map a.op) x.down } } }. 52 | -------------------------------------------------------------------------------- /src/category_theory/yoneda_terse.lean: -------------------------------------------------------------------------------- 1 | import category_theory.follow_your_nose 2 | 3 | universes u₁ v₁ 4 | 5 | open category_theory 6 | open opposite 7 | 8 | namespace terse 9 | 10 | variables (C : Type u₁) [𝒞 : category.{v₁+1} C] 11 | include 𝒞 12 | 13 | def yoneda : C ⥤ ((Cᵒᵖ) ⥤ Type v₁) := ƛ X, ƛ Y, (unop Y) ⟶ X. 14 | 15 | def yoneda_evaluation : ((Cᵒᵖ) × ((Cᵒᵖ) ⥤ (Type v₁))) ⥤ (Type (max u₁ v₁)) := 16 | (evaluation_uncurried (Cᵒᵖ) (Type v₁)) ⋙ ulift_functor.{u₁} 17 | 18 | @[simp] lemma yoneda_evaluation_map_down 19 | (P Q : (Cᵒᵖ) × (Cᵒᵖ ⥤ Type v₁)) (α : P ⟶ Q) (x : (yoneda_evaluation C).obj P) : 20 | ((yoneda_evaluation C).map α x).down = (α.2).app (Q.1) ((P.2).map (α.1) (x.down)) := rfl 21 | 22 | def yoneda_pairing : ((Cᵒᵖ) × ((Cᵒᵖ) ⥤ (Type v₁))) ⥤ (Type (max u₁ v₁)) := 23 | (functor.prod ((yoneda C).op) (functor.id ((Cᵒᵖ) ⥤ (Type v₁)))) ⋙ (functor.hom ((Cᵒᵖ) ⥤ (Type v₁))) 24 | 25 | @[simp] lemma yoneda_pairing_map 26 | (P Q : (Cᵒᵖ) × (Cᵒᵖ ⥤ Type v₁)) (α : P ⟶ Q) (β : (yoneda_pairing C).obj P) : 27 | (yoneda_pairing C).map α β = (yoneda C).map (α.1.unop) ≫ β ≫ α.2 := rfl 28 | 29 | def yoneda_lemma : (yoneda_pairing C) ≅ (yoneda_evaluation C) := 30 | { hom := { app := λ F x, ulift.up ((x.app F.1) (𝟙 (unop F.1))) }, 31 | inv := { app := λ F x, { app := λ X a, (F.2.map a.op) x.down } } }. 32 | 33 | end terse -------------------------------------------------------------------------------- /travis_long.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | 4 | # 5 | # This script is taken from: 6 | # 7 | # https://docs.haskellstack.org/en/stable/travis_ci/ 8 | # https://github.com/futurice/fum2github/blob/master/travis_long 9 | 10 | # The following explains the 50min hard timeout on macs 11 | # https://github.com/travis-ci/travis-ci/issues/3810 12 | 13 | $* & 14 | pidA=$! 15 | minutes=0 16 | 17 | while true; do sleep 60; ((minutes++)); echo -e "\033[0;32m$minutes minute(s) elapsed.\033[0m"; done & 18 | pidB=$! 19 | 20 | wait $pidA 21 | exitCode=$? 22 | 23 | echo -e "\033[0;32m$* finished.\033[0m" 24 | 25 | kill -9 $pidB 26 | exit $exitCode 27 | --------------------------------------------------------------------------------