├── .dir-locals.el ├── .github └── workflows │ └── ci.yml ├── .gitignore ├── .gitmodules ├── .mailmap ├── CREDITS.txt ├── INSTALL.md ├── LICENSE.txt ├── Makefile ├── Makefile.coq.local ├── Makefile.coq.local-early ├── README.md ├── STYLE.md ├── UNICODE.txt ├── contrib ├── HoTTBook.v ├── HoTTBookExercises.v ├── SetoidRewrite.v └── dune ├── coq-hott.opam ├── dune ├── dune-project ├── etc ├── Book.py ├── DepsToDot.hs ├── coqccount.sh ├── coqcreplace.py ├── coqcstriprequires.py ├── emacs │ └── run-etags.sh ├── generate_coqproject.sh ├── homotopy.css └── time2html ├── flake.lock ├── flake.nix ├── test ├── Algebra │ ├── Groups │ │ ├── Expressions.v │ │ ├── Group.v │ │ └── Presentation.v │ └── Rings │ │ ├── Expressions.v │ │ ├── Matrix.v │ │ └── Ring.v ├── Classes │ └── ring_tac.v ├── Idempotents.v ├── Metatheory │ ├── FunextVarieties.v │ └── UnivalenceImpliesFunext.v ├── Pointed │ └── Core.v ├── README.md ├── Spaces │ └── List.v ├── Tactics │ ├── napply.v │ └── transport_paths.v ├── WildCat │ └── Opposite.v ├── bugs │ ├── github1358.v │ ├── github1382.v │ ├── github1758.v │ ├── github1759.v │ ├── github1791.v │ ├── github1794.v │ ├── github370.v │ ├── github390.v │ ├── github726.v │ ├── github754.v │ └── github973.v └── dune └── theories ├── Algebra ├── AbGroups.v ├── AbGroups │ ├── AbHom.v │ ├── AbProjective.v │ ├── AbPullback.v │ ├── AbPushout.v │ ├── AbelianGroup.v │ ├── Abelianization.v │ ├── Biproduct.v │ ├── Centralizer.v │ ├── Cyclic.v │ ├── FiniteSum.v │ ├── FreeAbelianGroup.v │ ├── TensorProduct.v │ └── Z.v ├── AbSES.v ├── AbSES │ ├── BaerSum.v │ ├── Core.v │ ├── DirectSum.v │ ├── Ext.v │ ├── Pullback.v │ ├── PullbackFiberSequence.v │ ├── Pushout.v │ └── SixTerm.v ├── Aut.v ├── Categorical │ └── MonoidObject.v ├── Congruence.v ├── Groups.v ├── Groups │ ├── Commutator.v │ ├── Finite.v │ ├── FreeGroup.v │ ├── FreeProduct.v │ ├── Group.v │ ├── GroupCoeq.v │ ├── GrpPullback.v │ ├── Presentation.v │ ├── QuotientGroup.v │ ├── ShortExactSequence.v │ └── Subgroup.v ├── Monoids │ └── Monoid.v ├── Rings.v ├── Rings │ ├── CRing.v │ ├── ChineseRemainder.v │ ├── Ideal.v │ ├── Idempotent.v │ ├── KroneckerDelta.v │ ├── Localization.v │ ├── Matrix.v │ ├── Module.v │ ├── QuotientRing.v │ ├── Ring.v │ ├── Vector.v │ └── Z.v ├── Universal │ ├── Algebra.v │ ├── Congruence.v │ ├── Homomorphism.v │ ├── Operation.v │ └── TermAlgebra.v ├── ooAction.v └── ooGroup.v ├── Analysis └── Locator.v ├── Axioms ├── Funext.v ├── PropResizing.v └── Univalence.v ├── Basics.v ├── Basics ├── Classes.v ├── Contractible.v ├── Decidable.v ├── Equivalences.v ├── Iff.v ├── Nat.v ├── Notations.v ├── Numeral.v ├── Numerals │ ├── Decimal.v │ └── Hexadecimal.v ├── Overture.v ├── PathGroupoids.v ├── Settings.v ├── Tactics.v ├── Trunc.v └── Utf8.v ├── Categories.v ├── Categories ├── Adjoint.v ├── Adjoint │ ├── Composition.v │ ├── Composition │ │ ├── AssociativityLaw.v │ │ ├── Core.v │ │ ├── IdentityLaws.v │ │ └── LawsTactic.v │ ├── Core.v │ ├── Dual.v │ ├── Functorial.v │ ├── Functorial │ │ ├── Core.v │ │ ├── Laws.v │ │ └── Parts.v │ ├── Hom.v │ ├── HomCoercions.v │ ├── Identity.v │ ├── Notations.v │ ├── Paths.v │ ├── Pointwise.v │ ├── UnitCounit.v │ ├── UnitCounitCoercions.v │ ├── UniversalMorphisms.v │ ├── UniversalMorphisms │ │ └── Core.v │ └── Utf8.v ├── Cat.v ├── Cat │ ├── Core.v │ └── Morphisms.v ├── Category.v ├── Category │ ├── Core.v │ ├── Dual.v │ ├── Morphisms.v │ ├── Notations.v │ ├── Objects.v │ ├── Paths.v │ ├── Pi.v │ ├── Prod.v │ ├── Sigma.v │ ├── Sigma │ │ ├── Core.v │ │ ├── OnMorphisms.v │ │ ├── OnObjects.v │ │ └── Univalent.v │ ├── Strict.v │ ├── Subcategory.v │ ├── Subcategory │ │ ├── Full.v │ │ └── Wide.v │ ├── Sum.v │ ├── Univalent.v │ └── Utf8.v ├── CategoryOfGroupoids.v ├── CategoryOfSections.v ├── CategoryOfSections │ └── Core.v ├── ChainCategory.v ├── Comma.v ├── Comma │ ├── Core.v │ ├── Dual.v │ ├── Functorial.v │ ├── InducedFunctors.v │ ├── Notations.v │ ├── Projection.v │ ├── ProjectionFunctors.v │ └── Utf8.v ├── DependentProduct.v ├── DiscreteCategory.v ├── DualFunctor.v ├── ExponentialLaws.v ├── ExponentialLaws │ ├── Law0.v │ ├── Law1.v │ ├── Law1 │ │ ├── Functors.v │ │ └── Law.v │ ├── Law2.v │ ├── Law2 │ │ ├── Functors.v │ │ └── Law.v │ ├── Law3.v │ ├── Law3 │ │ ├── Functors.v │ │ └── Law.v │ ├── Law4.v │ ├── Law4 │ │ ├── Functors.v │ │ └── Law.v │ └── Tactics.v ├── Functor.v ├── Functor │ ├── Attributes.v │ ├── Composition.v │ ├── Composition │ │ ├── Core.v │ │ ├── Functorial.v │ │ ├── Functorial │ │ │ ├── Attributes.v │ │ │ └── Core.v │ │ └── Laws.v │ ├── Core.v │ ├── Dual.v │ ├── Identity.v │ ├── Notations.v │ ├── Paths.v │ ├── Pointwise.v │ ├── Pointwise │ │ ├── Core.v │ │ └── Properties.v │ ├── Prod.v │ ├── Prod │ │ ├── Core.v │ │ ├── Functorial.v │ │ └── Universal.v │ ├── Sum.v │ └── Utf8.v ├── FunctorCategory.v ├── FunctorCategory │ ├── Core.v │ ├── Dual.v │ ├── Functorial.v │ ├── Morphisms.v │ ├── Notations.v │ └── Utf8.v ├── FundamentalPreGroupoidCategory.v ├── Grothendieck.v ├── Grothendieck │ ├── PseudofunctorToCat.v │ ├── ToCat.v │ ├── ToSet.v │ └── ToSet │ │ ├── Core.v │ │ ├── Morphisms.v │ │ └── Univalent.v ├── GroupoidCategory.v ├── GroupoidCategory │ ├── Core.v │ ├── Dual.v │ └── Morphisms.v ├── HomFunctor.v ├── HomotopyPreCategory.v ├── IndiscreteCategory.v ├── InitialTerminalCategory.v ├── InitialTerminalCategory │ ├── Core.v │ ├── Functors.v │ ├── NaturalTransformations.v │ ├── Notations.v │ └── Pseudofunctors.v ├── KanExtensions.v ├── KanExtensions │ ├── Core.v │ └── Functors.v ├── LaxComma.v ├── LaxComma │ ├── Core.v │ ├── CoreLaws.v │ ├── CoreParts.v │ ├── Notations.v │ └── Utf8.v ├── Limits.v ├── Limits │ ├── Core.v │ └── Functors.v ├── Monoidal │ └── MonoidalCategory.v ├── NatCategory.v ├── NaturalTransformation.v ├── NaturalTransformation │ ├── Composition.v │ ├── Composition │ │ ├── Core.v │ │ ├── Functorial.v │ │ └── Laws.v │ ├── Core.v │ ├── Dual.v │ ├── Identity.v │ ├── Isomorphisms.v │ ├── Notations.v │ ├── Paths.v │ ├── Pointwise.v │ ├── Prod.v │ ├── Sum.v │ └── Utf8.v ├── Notations.v ├── ProductLaws.v ├── Profunctor.v ├── Profunctor │ ├── Core.v │ ├── Identity.v │ ├── Notations.v │ ├── Representable.v │ └── Utf8.v ├── Pseudofunctor.v ├── Pseudofunctor │ ├── Core.v │ ├── FromFunctor.v │ ├── Identity.v │ └── RewriteLaws.v ├── PseudonaturalTransformation.v ├── PseudonaturalTransformation │ └── Core.v ├── SemiSimplicialSets.v ├── SetCategory.v ├── SetCategory │ ├── Core.v │ ├── Functors.v │ ├── Functors │ │ └── SetProp.v │ └── Morphisms.v ├── SimplicialSets.v ├── Structure.v ├── Structure │ ├── Core.v │ ├── IdentityPrinciple.v │ ├── Notations.v │ └── Utf8.v ├── UniversalProperties.v ├── Utf8.v └── Yoneda.v ├── Classes ├── categories │ └── ua_category.v ├── implementations │ ├── assume_rationals.v │ ├── binary_naturals.v │ ├── bool.v │ ├── family_prod.v │ ├── field_of_fractions.v │ ├── hprop_lattice.v │ ├── natpair_integers.v │ ├── ne_list.v │ ├── peano_naturals.v │ └── pointwise.v ├── interfaces │ ├── abstract_algebra.v │ ├── archimedean.v │ ├── canonical_names.v │ ├── cauchy.v │ ├── integers.v │ ├── monad.v │ ├── naturals.v │ ├── orders.v │ ├── rationals.v │ ├── round.v │ ├── ua_algebra.v │ ├── ua_congruence.v │ └── ua_setalgebra.v ├── isomorphisms │ └── rings.v ├── orders │ ├── archimedean.v │ ├── dec_fields.v │ ├── fields.v │ ├── integers.v │ ├── lattices.v │ ├── maps.v │ ├── nat_int.v │ ├── naturals.v │ ├── orders.v │ ├── rings.v │ ├── semirings.v │ └── sum.v ├── tactics │ ├── ring_pol.v │ ├── ring_quote.v │ └── ring_tac.v └── theory │ ├── additional_operations.v │ ├── apartness.v │ ├── dec_fields.v │ ├── fields.v │ ├── groups.v │ ├── int_abs.v │ ├── integers.v │ ├── lattices.v │ ├── nat_distance.v │ ├── naturals.v │ ├── premetric.v │ ├── rationals.v │ ├── rings.v │ ├── ua_first_isomorphism.v │ ├── ua_homomorphism.v │ ├── ua_isomorphic.v │ ├── ua_prod_algebra.v │ ├── ua_quotient_algebra.v │ ├── ua_second_isomorphism.v │ ├── ua_subalgebra.v │ └── ua_third_isomorphism.v ├── Colimits ├── Coeq.v ├── CoeqUnivProp.v ├── Colimit.v ├── Colimit_Coequalizer.v ├── Colimit_Flattening.v ├── Colimit_Prod.v ├── Colimit_Pushout.v ├── Colimit_Pushout_Flattening.v ├── Colimit_Sigma.v ├── GraphQuotient.v ├── MappingCylinder.v ├── Pushout.v ├── Quotient.v ├── Quotient │ └── Choice.v ├── Sequential.v └── SpanPushout.v ├── Cubical ├── DPath.v ├── DPathCube.v ├── DPathSquare.v ├── PathCube.v └── PathSquare.v ├── Diagrams ├── Cocone.v ├── CommutativeSquares.v ├── Cone.v ├── ConstantDiagram.v ├── DDiagram.v ├── Diagram.v ├── Graph.v ├── ParallelPair.v ├── Sequence.v └── Span.v ├── Equiv ├── BiInv.v ├── PathSplit.v └── Relational.v ├── EquivGroupoids.v ├── ExcludedMiddle.v ├── Extensions.v ├── Factorization.v ├── Functorish.v ├── HFiber.v ├── HIT ├── Flattening.v ├── FreeIntQuotient.v ├── Interval.v ├── README.txt ├── SetCone.v ├── V.v ├── epi.v ├── iso.v ├── quotient.v └── unique_choice.v ├── HoTT.v ├── Homotopy ├── BlakersMassey.v ├── Bouquet.v ├── CayleyDickson.v ├── ClassifyingSpace.v ├── Cofiber.v ├── Cover.v ├── EMSpace.v ├── EncodeDecode.v ├── EvaluationFibration.v ├── ExactSequence.v ├── HSpace.v ├── HSpace │ ├── Coherent.v │ ├── Core.v │ ├── Moduli.v │ └── Pointwise.v ├── HSpaceS1.v ├── HomotopyGroup.v ├── Hopf.v ├── IdentitySystems.v ├── InjectiveTypes │ ├── InjectiveSigma.v │ ├── InjectiveTypes.v │ └── TypeFamKanExt.v ├── Join.v ├── Join │ ├── Core.v │ ├── JoinAssoc.v │ ├── JoinSusp.v │ └── TriJoin.v ├── NullHomotopy.v ├── PinSn.v ├── Smash.v ├── SuccessorStructure.v ├── Suspension.v ├── Syllepsis.v ├── Wedge.v └── WhiteheadsPrinciple.v ├── Idempotents.v ├── Limits ├── Equalizer.v ├── Limit.v └── Pullback.v ├── Metatheory ├── Core.v ├── FunextVarieties.v ├── ImpredicativeTruncation.v ├── IntervalImpliesFunext.v ├── Nat.v ├── PropTrunc.v ├── TruncImpliesFunext.v ├── UnivalenceImpliesFunext.v └── UnivalenceVarieties.v ├── Misc ├── BarInduction.v ├── BoundedSearch.v ├── FanTheorem.v └── UStructures.v ├── Modalities ├── Accessible.v ├── Closed.v ├── CoreflectiveSubuniverse.v ├── Descent.v ├── Fracture.v ├── Identity.v ├── Lex.v ├── Localization.v ├── Meet.v ├── Modality.v ├── Notnot.v ├── Nullification.v ├── Open.v ├── ReflectiveSubuniverse.v ├── Separated.v └── Topological.v ├── Pointed.v ├── Pointed ├── Core.v ├── Loops.v ├── pEquiv.v ├── pFiber.v ├── pMap.v ├── pModality.v ├── pSect.v ├── pSusp.v └── pTrunc.v ├── Projective.v ├── Sets ├── AC.v ├── GCH.v ├── GCHtoAC.v ├── Hartogs.v ├── Ordinals.v └── Powers.v ├── Spaces ├── BAut │ ├── Bool.v │ ├── Bool │ │ └── IncoherentIdempotent.v │ └── Cantor.v ├── BinInt.v ├── BinInt │ ├── Core.v │ ├── Equiv.v │ ├── LoopExp.v │ └── Spec.v ├── Cantor.v ├── Card.v ├── Circle.v ├── Finite.v ├── Finite │ ├── Fin.v │ ├── FinInduction.v │ ├── FinNat.v │ ├── FinSeq.v │ ├── Finite.v │ └── Tactics.v ├── FreeInt.v ├── Int.v ├── List │ ├── Core.v │ ├── Paths.v │ └── Theory.v ├── Nat.v ├── Nat │ ├── Arithmetic.v │ ├── Binomial.v │ ├── Core.v │ ├── Division.v │ ├── Factorial.v │ └── Paths.v ├── NatSeq │ ├── Core.v │ └── UStructure.v ├── No.v ├── No │ ├── Addition.v │ ├── Core.v │ └── Negation.v ├── Pos.v ├── Pos │ ├── Core.v │ └── Spec.v ├── Spheres.v ├── Torus │ ├── Torus.v │ ├── TorusEquivCircles.v │ └── TorusHomotopy.v └── TwoSphere.v ├── Spectra └── Spectrum.v ├── Tactics.v ├── Tactics ├── BinderApply.v ├── EquivalenceInduction.v ├── EvalIn.v ├── Nameless.v └── RewriteModuloAssociativity.v ├── Truncations.v ├── Truncations ├── Connectedness.v ├── Constant.v ├── Core.v └── SeparatedTrunc.v ├── Types.v ├── Types ├── Arrow.v ├── Bool.v ├── Empty.v ├── Equiv.v ├── Forall.v ├── IWType.v ├── Option.v ├── Paths.v ├── Prod.v ├── Sigma.v ├── Sum.v ├── Unit.v ├── Universe.v └── WType.v ├── Universes ├── Automorphisms.v ├── BAut.v ├── DProp.v ├── HProp.v ├── HSet.v ├── ObjectClassifier.v ├── Rigid.v ├── Smallness.v ├── TruncType.v └── UniverseLevel.v ├── Utf8.v ├── Utf8Minimal.v ├── WildCat.v ├── WildCat ├── Adjoint.v ├── Bifunctor.v ├── Category.v ├── Coproducts.v ├── Core.v ├── Displayed.v ├── DisplayedEquiv.v ├── EmptyCat.v ├── Equiv.v ├── EquivGpd.v ├── Forall.v ├── FunctorCat.v ├── Graph.v ├── Induced.v ├── Monoidal.v ├── MonoidalTwistConstruction.v ├── NatTrans.v ├── Opposite.v ├── Paths.v ├── PointedCat.v ├── Prod.v ├── Products.v ├── Sigma.v ├── Square.v ├── Sum.v ├── TwoOneCat.v ├── UnitCat.v ├── Universe.v ├── Yoneda.v └── ZeroGroupoid.v └── dune /.dir-locals.el: -------------------------------------------------------------------------------- 1 | ((nil . ((mode . visual-line)))) 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore Emacs backup files 2 | *~ 3 | # Ignore Emacs temp files 4 | *#*# 5 | 6 | # Ignore the .DS_Store file generated on a Mac 7 | .DS_Store 8 | 9 | # Ignore files generated by the Coq compiler 10 | .*.aux 11 | .*.d 12 | *.a 13 | *.cma 14 | *.cmi 15 | *.cmo 16 | *.cmx 17 | *.cmxa 18 | *.cmxs 19 | *.glob 20 | *.ml.d 21 | *.ml4.d 22 | *.mlg.d 23 | *.mli.d 24 | *.mllib.d 25 | *.mlpack.d 26 | *.native 27 | *.o 28 | *.v.d 29 | *.vio 30 | *.vo 31 | *.vok 32 | *.vos 33 | .coq-native 34 | .csdp.cache 35 | .lia.cache 36 | .nia.cache 37 | .nlia.cache 38 | .nra.cache 39 | csdp.cache 40 | lia.cache 41 | nia.cache 42 | nlia.cache 43 | nra.cache 44 | native_compute_profile_*.data 45 | 46 | # generated timing files 47 | *.timing.diff 48 | *.v.after-timing 49 | *.v.before-timing 50 | *.v.timing 51 | time-of-build-after.log 52 | time-of-build-before.log 53 | time-of-build-both.log 54 | time-of-build-pretty.log 55 | 56 | *.vo 57 | *.vos 58 | *.vok 59 | *.glob 60 | *.v.d 61 | *.native 62 | *.ml4.d 63 | *.mli.d 64 | *.mllib.d 65 | *.timing 66 | 67 | # Ignore makefiles generated by coq_makefile 68 | /Makefile.coq 69 | /Makefile.coq.conf 70 | 71 | html/ 72 | file-dep-graphs/ 73 | alectryon-html/ 74 | alectryon-cache/ 75 | 76 | HoTT.deps 77 | HoTT.dot 78 | 79 | # Ignore files generated by LaTeX 80 | *.aux 81 | *.log 82 | *.out 83 | 84 | # Ignore stuff from autobuild 85 | configure 86 | 87 | html-done.timestamp 88 | alectryon-html-done.timestamp 89 | 90 | # generated dependency files: 91 | TAGS 92 | 93 | # ignore compiled python files 94 | *.pyc 95 | 96 | # ignore backup files generated by etc/Book.py 97 | contrib/*.bak.* 98 | 99 | # ignore backup files generated by etc/coqcstriprequires.py 100 | *.bak 101 | 102 | *.crashcoqide 103 | .vscode/ 104 | 105 | # ignore dune _build directory 106 | _build/ 107 | 108 | # ignore _CoqProject since we autogenerate it 109 | _CoqProject 110 | 111 | # ignore nix profiles 112 | nix/profiles/ 113 | 114 | # Ignore the file to bench 115 | file_to_bench 116 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "etc/coq-scripts"] 2 | path = etc/coq-scripts 3 | url = https://github.com/JasonGross/coq-scripts.git 4 | [submodule "etc/alectryon"] 5 | path = etc/alectryon 6 | url = https://github.com/JasonGross/alectryon.git 7 | -------------------------------------------------------------------------------- /CREDITS.txt: -------------------------------------------------------------------------------- 1 | THE HoTT DEVELOPMENT TEAM 2 | ========================= 3 | 4 | The HoTT library was jointly developed by the following people, 5 | listed in alphabetical order: 6 | 7 | * Andrej Bauer, University of Ljubljana 8 | * Jason Gross, Massachusetts Institute of Technology 9 | * Peter LeFanu Lumsdaine, Institute for Advanced Study 10 | * Michael Shulman, University of San Diego 11 | * Bas Spitters, Radboud University Nijmegen 12 | 13 | For a complete list of all contributors, please see the git commit logs, 14 | available at https://github.com/HoTT/HoTT. 15 | 16 | 17 | INSTITUTIONAL SUPPORT 18 | ===================== 19 | 20 | We acknowledge the support of the following instutitions and funding agencies, 21 | listed in alphabetical order: 22 | 23 | * Institute for Advanced Study, Princeton, USA (http://www.ias.edu/) 24 | * Institute for Mathematics, Physics and Mechanics, Ljubljana, Slovenia (http://www.imfm.si/) 25 | * Faculty of Mathematics and Physics, University of Ljubljana, Slovenia (http://www.fmf.uni-lj.si/) 26 | * Slovenian Research Agency (http://www.arrs.gov.si/), grant P1-0294 27 | * European Science Foundation project GReGAS (http://www.gregas.eu) 28 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | PREAMBLE 2 | ======== 3 | 4 | The HoTT library is distributed under the BSD 2-clause licence, included below, except for 5 | files which contain a specific copyright notice and licencing information. The members of 6 | the HoTT development team and their contributions are described in the file CREDITS.txt. 7 | 8 | LICENSE 9 | ======= 10 | 11 | Copyright (c) 2012, the HoTT development team 12 | All rights reserved. 13 | 14 | Redistribution and use in source and binary forms, with or without modification, are 15 | permitted provided that the following conditions are met: 16 | 17 | * Redistributions of source code must retain the above copyright notice, this list of 18 | conditions and the following disclaimer. 19 | 20 | * Redistributions in binary form must reproduce the above copyright notice, this list 21 | of conditions and the following disclaimer in the documentation and/or other materials 22 | provided with the distribution. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 25 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 27 | COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 31 | TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # KNOWNTARGETS will not be passed along to Makefile.coq 2 | KNOWNTARGETS := Makefile.coq 3 | # KNOWNFILES will not get implicit targets from the final rule, and so 4 | # depending on them won't invoke the submake 5 | # Warning: These files get declared as PHONY, so any targets depending 6 | # on them always get rebuilt 7 | KNOWNFILES := Makefile _CoqProject 8 | 9 | .DEFAULT_GOAL := invoke-coqmakefile 10 | 11 | Makefile.coq: Makefile _CoqProject 12 | # Generate _CoqProject file 13 | bash etc/generate_coqproject.sh 14 | # Generate Makefile 15 | $(COQBIN)coq_makefile -f _CoqProject -o Makefile.coq 16 | 17 | # We replace the html target with real-html, because we want to make 18 | # the timestamp file. We use patsubst rather than subst to do this so 19 | # that we only replace entire words. 20 | invoke-coqmakefile: Makefile.coq 21 | $(MAKE) --no-print-directory -f Makefile.coq $(patsubst html,real-html,$(filter-out $(KNOWNTARGETS),$(MAKECMDGOALS))) 22 | 23 | .PHONY: invoke-coqmakefile $(KNOWNFILES) 24 | 25 | #################################################################### 26 | ## Your targets here ## 27 | #################################################################### 28 | 29 | # This should be the last rule, to handle any targets not declared above 30 | %: invoke-coqmakefile 31 | @true 32 | -------------------------------------------------------------------------------- /Makefile.coq.local-early: -------------------------------------------------------------------------------- 1 | # Once https://github.com/coq/coq/pull/12411 is merged and we bump the 2 | # minimum version to a version including that PR, this file should 3 | # become Makefile.coq.local, and we should rename Makefile.coq.local 4 | # to Makefile.coq.local-late; Makefile.coq.local-early contains code 5 | # that overrides the relevant variables in Makefile.coq, while 6 | # Makefile.coq.local currently contains additional targets that need 7 | # access to the variables in Makefile.coq 8 | COQDOCEXTRAFLAGS?= 9 | COQDOCFLAGS?=--interpolate --utf8 --no-externals --parse-comments $(COQDOCEXTRAFLAGS) 10 | -------------------------------------------------------------------------------- /UNICODE.txt: -------------------------------------------------------------------------------- 1 | To insert unicode characters into emacs, you can set the TeX input 2 | method by typing `C-u C-\` (or `M-x set-input-method RET`), typing 3 | `TeX`, and pressing RETURN. You can then insert characters as you 4 | would in TeX, such as `•` by typing `\bullet`. There are other 5 | unicode input methods, as well. For example, if you have Agda 6 | installed, you can enter `Agda` as the input method, and then you can 7 | enter `•` by typing `\bu`. 8 | 9 | Emacs can tell you how to enter a pre-existing character: place the 10 | cursor right before the character, and type `C-u C-x =` (or `M-x 11 | describe-char RET`). 12 | 13 | To default to TeX input method when editing Coq files, add the 14 | following to your ~/.emacs: 15 | 16 | (defun my-coq-hook () 17 | (set-input-method "TeX")) 18 | 19 | (add-hook 'coq-mode-hook 'my-coq-hook) 20 | 21 | 22 | Instructions for entering unicode into CoqIDE are documented in the 23 | Coq Reference Manual (http://coq.inria.fr/refman/toc.html). You can 24 | find the v8.4 documentation about unicode input at 25 | http://coq.inria.fr/distrib/8.4pl4/refman/Reference-Manual018.html#sec628. 26 | -------------------------------------------------------------------------------- /contrib/dune: -------------------------------------------------------------------------------- 1 | (coq.theory 2 | (name HoTT.Contrib) 3 | (package coq-hott) 4 | (theories HoTT)) 5 | -------------------------------------------------------------------------------- /coq-hott.opam: -------------------------------------------------------------------------------- 1 | # This file is generated by dune, edit dune-project instead 2 | opam-version: "2.0" 3 | synopsis: "The Homotopy Type Theory library" 4 | description: """ 5 | To use the HoTT library, the following flags must be passed to coqc: 6 | -noinit -indices-matter 7 | To use the HoTT library in a project, add the following to _CoqProject: 8 | -arg -noinit 9 | -arg -indices-matter 10 | """ 11 | maintainer: [ 12 | "Jason Gross " "Ali Caglayan " 13 | ] 14 | authors: ["The HoTT Library Development Team"] 15 | license: "BSD-2-Clause" 16 | homepage: "http://homotopytypetheory.org/" 17 | bug-reports: "https://github.com/HoTT/HoTT/issues" 18 | depends: [ 19 | "dune" {>= "3.13"} 20 | "coq" {>= "8.19.0"} 21 | "odoc" {with-doc} 22 | ] 23 | build: [ 24 | ["dune" "subst"] {dev} 25 | [ 26 | "dune" 27 | "build" 28 | "-p" 29 | name 30 | "-j" 31 | jobs 32 | "@install" 33 | "@runtest" {with-test} 34 | "@doc" {with-doc} 35 | ] 36 | ] 37 | dev-repo: "git+https://github.com/HoTT/HoTT.git" 38 | -------------------------------------------------------------------------------- /dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 3.13) 2 | 3 | (using coq 0.8) 4 | 5 | (name coq-hott) 6 | 7 | (generate_opam_files true) 8 | 9 | (source 10 | (github HoTT/HoTT)) 11 | 12 | (homepage "http://homotopytypetheory.org/") 13 | 14 | (license BSD-2-Clause) 15 | 16 | (authors "The HoTT Library Development Team") 17 | 18 | (maintainers 19 | "Jason Gross " 20 | "Ali Caglayan ") 21 | 22 | (package 23 | (name coq-hott) 24 | (synopsis "The Homotopy Type Theory library") 25 | (description 26 | "To use the HoTT library, the following flags must be passed to coqc:\n -noinit -indices-matter\nTo use the HoTT library in a project, add the following to _CoqProject:\n -arg -noinit\n -arg -indices-matter\n") 27 | (depends 28 | (coq 29 | (>= 8.19.0)))) 30 | -------------------------------------------------------------------------------- /etc/emacs/run-etags.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | etags --language=none -r '/^[ \t]*\(\(Local\|Global\|Cumulative\|NonCumulative\|Monomorphic\|Polymorphic\|Private\)[ \t]+\)*\(Axiom\|Theorem\|Class\|Instance\|Let\|Ltac\|Definition\|Lemma\|Record\|Remark\|Structure\|Fixpoint\|Fact\|Corollary\|Inductive\|CoInductive\|Proposition\|Notation\)[ \t]+\([a-zA-Z0-9_'\'']+\)/\4/' -r '/^[ \t]*\([a-zA-Z0-9_'\'']+\)[ \t]*:/\1/' "$@" 3 | -------------------------------------------------------------------------------- /etc/generate_coqproject.sh: -------------------------------------------------------------------------------- 1 | ## List tracked .v files 2 | if [ -e .git ]; then 3 | TRACKED_V_FILES="$(git ls-files "*.v")" 4 | else 5 | # This is expected when building using dune, so don't print the warning in that case: 6 | if [ "$GENERATE_COQPROJECT_FOR_DUNE" != "true" ]; then 7 | echo "Warning: Not a git clone, using find instead" >&2 8 | fi 9 | TRACKED_V_FILES="$(find theories contrib test -type f -name "*.v")" 10 | fi 11 | 12 | ## List untracked .v files 13 | #UNTRACKED_V_FILES=$(git ls-files --others --exclude-standard "*.v") 14 | 15 | ## Combine untracked and tracked .v files 16 | printf -v UNSORTED_V_FILES '%s\n%s' "$TRACKED_V_FILES" "$UNTRACKED_V_FILES" 17 | 18 | ## Sort combined .v files, and remove duplicates that can arise during a merge. 19 | SORTED_V_FILES=$(echo "$UNSORTED_V_FILES" | sort -u) 20 | 21 | ## _CoqProject header 22 | COQPROJECT_HEADER=\ 23 | "############################################################################### 24 | # WARNING: This file is autogenerated by the generate_coqproject.sh script 25 | # found in etc/. It is set to be untracked by git. 26 | ############################################################################### 27 | -R theories HoTT 28 | -Q contrib HoTT.Contrib 29 | -Q test HoTT.Tests 30 | 31 | -arg -noinit 32 | -arg -indices-matter 33 | -arg -native-compiler -arg no 34 | " 35 | 36 | ## Add additional lines when building with dune 37 | if [ "$GENERATE_COQPROJECT_FOR_DUNE" == "true" ]; then 38 | COQPROJECT_HEADER="$COQPROJECT_HEADER 39 | # Dune compatibility 40 | -R _build/default/theories HoTT 41 | -Q _build/default/contrib HoTT.Contrib 42 | -Q _build/default/test HoTT.Tests 43 | " 44 | fi 45 | 46 | ## Store new _CoqProject in a variable 47 | printf -v NEW_COQPROJECT '%s\n%s' "$COQPROJECT_HEADER" "$SORTED_V_FILES" 48 | 49 | ## Look for existing _CoqProject 50 | if test -f "_CoqProject"; then 51 | OLD_COQPROJECT=$(cat _CoqProject) 52 | ## If it is the same don't overwrite 53 | if [ "$NEW_COQPROJECT" == "$OLD_COQPROJECT" ]; then 54 | exit 0 55 | fi 56 | fi 57 | 58 | ## Overwrite _CoqProject 59 | echo "$NEW_COQPROJECT" > _CoqProject 60 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "flake-utils": { 4 | "inputs": { 5 | "systems": "systems" 6 | }, 7 | "locked": { 8 | "lastModified": 1726560853, 9 | "narHash": "sha256-X6rJYSESBVr3hBoH0WbKE5KvhPU5bloyZ2L4K60/fPQ=", 10 | "owner": "numtide", 11 | "repo": "flake-utils", 12 | "rev": "c1dfcf08411b08f6b8615f7d8971a2bfa81d5e8a", 13 | "type": "github" 14 | }, 15 | "original": { 16 | "owner": "numtide", 17 | "repo": "flake-utils", 18 | "type": "github" 19 | } 20 | }, 21 | "nixpkgs": { 22 | "locked": { 23 | "lastModified": 1728336163, 24 | "narHash": "sha256-rISnMC117SHUI19jwOyoBpeH1lg0JkNUwDS2khhEXzc=", 25 | "owner": "NixOS", 26 | "repo": "nixpkgs", 27 | "rev": "df8a060c473cf49d3d3b0480f892ffcbea7bba41", 28 | "type": "github" 29 | }, 30 | "original": { 31 | "owner": "NixOS", 32 | "ref": "master", 33 | "repo": "nixpkgs", 34 | "type": "github" 35 | } 36 | }, 37 | "root": { 38 | "inputs": { 39 | "flake-utils": "flake-utils", 40 | "nixpkgs": "nixpkgs" 41 | } 42 | }, 43 | "systems": { 44 | "locked": { 45 | "lastModified": 1681028828, 46 | "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", 47 | "owner": "nix-systems", 48 | "repo": "default", 49 | "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", 50 | "type": "github" 51 | }, 52 | "original": { 53 | "owner": "nix-systems", 54 | "repo": "default", 55 | "type": "github" 56 | } 57 | } 58 | }, 59 | "root": "root", 60 | "version": 7 61 | } 62 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "A Coq library for Homotopy Type Theory"; 3 | 4 | inputs = { 5 | nixpkgs.url = "github:NixOS/nixpkgs/master"; 6 | 7 | flake-utils.url = "github:numtide/flake-utils"; 8 | }; 9 | 10 | outputs = { self, nixpkgs, flake-utils }: 11 | flake-utils.lib.eachDefaultSystem (system: 12 | let 13 | pkgs = nixpkgs.legacyPackages.${system}; 14 | makeDevShell = { coq ? pkgs.coq }: 15 | let 16 | coqPackages = pkgs.mkCoqPackages coq // { 17 | __attrsFailEvaluation = true; 18 | }; 19 | in 20 | { extraPackages ? [ coqPackages.coq-lsp ] }: 21 | pkgs.mkShell { 22 | buildInputs = 23 | [ pkgs.dune_3 pkgs.ocaml ] ++ extraPackages ++ [ coq ]; 24 | }; 25 | in 26 | { 27 | packages.default = pkgs.coqPackages.mkCoqDerivation { 28 | pname = "hott"; 29 | version = "8.20"; 30 | src = self; 31 | useDune = true; 32 | }; 33 | 34 | devShells.default = 35 | makeDevShell 36 | { coq = pkgs.coq_8_20; } 37 | { }; 38 | 39 | devShells.coq_8_19 = 40 | makeDevShell 41 | { coq = pkgs.coq_8_19; } 42 | { }; 43 | 44 | # To use, pass --impure to nix develop 45 | devShells.coq_master = 46 | makeDevShell 47 | { coq = pkgs.coq.override { version = "master"; }; } 48 | { extraPackages = [ ]; }; 49 | 50 | formatter = pkgs.nixpkgs-fmt; 51 | }); 52 | } 53 | -------------------------------------------------------------------------------- /test/Algebra/Groups/Group.v: -------------------------------------------------------------------------------- 1 | From HoTT Require Import Basics.Overture Algebra.Groups.Group. 2 | 3 | (** Test that opposite groups are definitionally involutive. *) 4 | Succeed Definition test1 (G : Group) : G = (grp_op (grp_op G)) :> Group := 1. 5 | -------------------------------------------------------------------------------- /test/Algebra/Groups/Presentation.v: -------------------------------------------------------------------------------- 1 | From HoTT Require Import Basics Spaces.Finite.Fin Spaces.Finite.FinSeq. 2 | From HoTT.Algebra.Groups Require Import Group Presentation FreeGroup. 3 | 4 | Local Open Scope mc_scope. 5 | Local Open Scope mc_mult_scope. 6 | 7 | Check ⟨ x | x * x * x , x^ ⟩. 8 | Check ⟨ x , y | x * y , x * y * x , x * y^ * x * x * x⟩. 9 | Check ⟨ x , y , z | x * y * z , x * z^ , x * y⟩. 10 | -------------------------------------------------------------------------------- /test/Algebra/Rings/Expressions.v: -------------------------------------------------------------------------------- 1 | From HoTT Require Import Basics.Overture Algebra.Rings.Ring. 2 | 3 | Set Universe Minimization ToSet. 4 | 5 | (** In this file, we test various aspects of writing group expressions. These kinds of expressions appear throughout the library, but since mathclasses is quite sensitive to subtle changes, we keep this file to document and enforce certain behaviours. 6 | 7 | We use the [Type] vernacular command which is like [Check] but doesn't allow for evars. *) 8 | 9 | Section Rings. 10 | 11 | Context {R : Ring@{Set}} (x y : R). 12 | 13 | (** [mc_scope] is appropriate for rings. *) 14 | 15 | Local Open Scope mc_scope. 16 | 17 | Succeed Type (x + y : R). 18 | Succeed Type (x - y : R). 19 | Succeed Type (x * y * x - x * y : R). 20 | Succeed Type (x - y : R). 21 | Succeed Type (x - y : R). 22 | 23 | Local Close Scope mc_scope. 24 | End Rings. 25 | -------------------------------------------------------------------------------- /test/Algebra/Rings/Ring.v: -------------------------------------------------------------------------------- 1 | From HoTT Require Import Basics.Overture Algebra.Rings.Ring Algebra.Rings.CRing. 2 | From HoTT.Algebra Require Import Groups.Group AbGroups.AbelianGroup. 3 | From HoTT Require Import abstract_algebra. 4 | 5 | Local Open Scope path_scope. 6 | 7 | (** Test that opposite rings are definitionally involutive. *) 8 | Definition test1 (R : Ring) : R = (rng_op (rng_op R)) :> Ring := 1. 9 | 10 | (** This may look funny, but you will see that Coq discards the [rng_op] during elaboration meaning that we only have [R = R] at the end. The reason this works is that [rng_op] takes in only a [Ring]. Afterwards, Coq is able to see that [rng_op (rng_op R)] should be a [CRing] and the coercion from [Ring] to [CRing] is reversible, therefore Coq tries to unify it with the original commutative ring. This behaviour is a bit surprising but is harmless so we just document it here. *) 11 | Definition test2 (R : CRing) : R = (rng_op (rng_op R)) :> CRing := 1. 12 | -------------------------------------------------------------------------------- /test/Classes/ring_tac.v: -------------------------------------------------------------------------------- 1 | From HoTT Require Import 2 | Classes.interfaces.abstract_algebra 3 | Classes.implementations.peano_naturals 4 | Classes.orders.sum 5 | Classes.tactics.ring_tac 6 | Classes.tactics.ring_quote. 7 | 8 | Import Quoting.Instances. 9 | Generalizable Variables R. 10 | 11 | Lemma test1 `{IsSemiCRing R} 12 | : forall x y : R, x + (y * x) = x * (y + 1). 13 | Proof. 14 | intros. 15 | ring_with_nat. 16 | Qed. 17 | 18 | Require Import 19 | HoTT.Classes.interfaces.naturals. 20 | 21 | Lemma test2 `{IsSemiCRing R} 22 | : forall x y : R, x + (y * x) = x * (y + 1). 23 | Proof. 24 | intros. 25 | apply (by_quoting (naturals_to_semiring nat R)). 26 | compute. reflexivity. 27 | Qed. 28 | 29 | Lemma test3 `{IsSemiCRing R} 30 | (pa pb pc : R) : 31 | pa * (pb * pc) 32 | = pa * pb * pc. 33 | Proof. 34 | intros. 35 | apply (by_quoting (naturals_to_semiring nat R)). compute. 36 | reflexivity. 37 | Qed. 38 | 39 | Lemma test4 `{IsSemiCRing R} 40 | (a b : R) 41 | : a * b = b * a. 42 | Proof. 43 | apply (ring_quote.Quoting.eval_eqquote R). 44 | apply (prove_prequoted (naturals_to_semiring nat R)). 45 | reflexivity. 46 | Qed. 47 | 48 | Lemma test5 : forall x y : nat, x + (y * x) = x * (y + 1). 49 | Proof. 50 | intros;ring_with_nat. 51 | Qed. 52 | 53 | -------------------------------------------------------------------------------- /test/Idempotents.v: -------------------------------------------------------------------------------- 1 | From HoTT Require Import Idempotents. 2 | 3 | (** Note that [Idempotent X], unlike [RetractOf X], lives in the same universe as [X], even if we demand that it contain the identity. *) 4 | Check (fun (X:Type@{i}) => (idem_idmap X : (Idempotent X : Type@{i}))). 5 | 6 | (** By contrast, [RetractOf X] does not live in the same universe as [X] if it is required to contain the identity retraction. *) 7 | Fail Check (fun (X:Type@{i}) => (idmap_retractof X : (RetractOf X : Type@{i}))). 8 | 9 | -------------------------------------------------------------------------------- /test/Metatheory/FunextVarieties.v: -------------------------------------------------------------------------------- 1 | From HoTT.Metatheory Require Import FunextVarieties. 2 | 3 | (** Checking the universes of FunextVarieties.v *) 4 | 5 | Check NaiveFunext@{i j max}. 6 | Check NaiveNondepFunext@{i j max}. 7 | Check WeakFunext@{i j max}. 8 | -------------------------------------------------------------------------------- /test/Metatheory/UnivalenceImpliesFunext.v: -------------------------------------------------------------------------------- 1 | From HoTT Require Import Basics. 2 | From HoTT.Metatheory Require Import Core FunextVarieties UnivalenceImpliesFunext. 3 | 4 | (** Note that only the codomain universe of [NaiveNondepFunext] is required to be univalent. *) 5 | Check @Univalence_implies_FunextNondep@{j jplusone i max j max} 6 | : Univalence_type@{j jplusone} -> NaiveNondepFunext@{i j max}. 7 | -------------------------------------------------------------------------------- /test/Pointed/Core.v: -------------------------------------------------------------------------------- 1 | From HoTT Require Import Basics.Overture Pointed.Core. 2 | 3 | (** Test pelim tactic. *) 4 | 5 | Open Scope pointed_scope. 6 | 7 | (** Check that it works for types with explicit base points. *) 8 | Definition test1 {X Y : Type} {x : X} {y : Y} (f : [X,x] ->* [Y,y]) : (f x = y) * (point_eq f = point_eq f). 9 | Proof. 10 | pelim f. 11 | split; reflexivity. 12 | Defined. 13 | 14 | (** Check that it works for pointed equivalences. *) 15 | Definition test2 {X Y : pType} (f : X <~>* Y) : (f pt = pt) * (point_eq f = point_eq f). 16 | Proof. 17 | pelim f. 18 | split; reflexivity. 19 | Defined. 20 | -------------------------------------------------------------------------------- /test/README.md: -------------------------------------------------------------------------------- 1 | # Tests 2 | 3 | Sometimes there are properties of the library that we would like to test 4 | without polluting it with examples and noisy output. Such tests are collected 5 | here. 6 | 7 | We also collect regression tests from various issues and PRs in a 8 | subdirectory called `bugs/`. 9 | 10 | ## Adding a test 11 | 12 | To add a test, create a new .v file in a subdirectory of this directory. 13 | 14 | When testing properties of the library, use the same directory 15 | structure. For instance, tests about suspensions should be in 16 | `test/Homotopy/Suspension.v`. 17 | 18 | Place regression tests in the subdirectory `bugs`, using file name `github.v` or `github.v`. For example, if you are adding a test for 20 | issue #123, the file name should be `test/bugs/github123.v`. 21 | 22 | ## Running tests 23 | 24 | To run the tests, simply run 25 | ``` 26 | dune test 27 | ``` 28 | -------------------------------------------------------------------------------- /test/Tactics/napply.v: -------------------------------------------------------------------------------- 1 | From HoTT Require Import Basics.Overture Basics.Tactics. 2 | From HoTT Require Import Spaces.Nat.Core. 3 | 4 | Local Open Scope nat_scope. 5 | 6 | (** Testing the different [apply] tacitcs in the library. *) 7 | 8 | Definition test1_type := {n : nat & n < 3}. 9 | Fail Definition test1 : test1_type := ltac:(apply exist). 10 | Fail Definition test1 : test1_type := ltac:(rapply exist). 11 | Fail Definition test1 : test1_type := ltac:(napply exist). 12 | Fail Definition test1 : test1_type := ltac:(tapply exist). 13 | Succeed Definition test1 : test1_type := ltac:(napply exist; exact _). 14 | 15 | (** Testing deprecated tactics *) 16 | Fail #[warnings="+deprecated-tactic-notation-since-2025-03-11"] 17 | Definition test1 : test1_type := ltac:(nrapply exist). 18 | Fail #[warnings="+deprecated-tactic-notation-since-2025-03-11"] 19 | Definition test1 : test1_type := ltac:(snrapply exist). 20 | -------------------------------------------------------------------------------- /test/bugs/github1358.v: -------------------------------------------------------------------------------- 1 | From HoTT Require Import Basics. 2 | 3 | Axiom A@{i} : Type@{i}. 4 | 5 | Axiom foo@{i} : A@{i} <~> A@{i}. 6 | 7 | Definition bar@{i} : A@{i} <~> A@{i}. 8 | Proof. 9 | reflexivity. 10 | Defined. 11 | 12 | Definition bar'@{i} : A@{i} <~> A@{i}. 13 | Proof. 14 | exact equiv_idmap. 15 | Defined. 16 | 17 | -------------------------------------------------------------------------------- /test/bugs/github1382.v: -------------------------------------------------------------------------------- 1 | From HoTT Require Import Basics Types. 2 | 3 | (* Tests for discriminate tactic *) 4 | 5 | Goal O = S O -> Empty. 6 | discriminate 1. 7 | Qed. 8 | 9 | Goal forall H : O = S O, H = H. 10 | discriminate H. 11 | Qed. 12 | 13 | Goal O = S O -> Unit. 14 | intros H. discriminate H. Qed. 15 | Goal O = S O -> Unit. 16 | intros H. Ltac g x := discriminate x. g H. Qed. 17 | 18 | Goal (forall x y : nat, x = y -> x = S y) -> Unit. 19 | intros. 20 | try discriminate (H O) || exact tt. 21 | Qed. 22 | 23 | Goal (forall x y : nat, x = y -> x = S y) -> Unit. 24 | intros H. ediscriminate (H O). instantiate (1:=O). Abort. 25 | 26 | (* Check discriminate on types with local definitions *) 27 | 28 | Inductive A : Type0 := B (T := Unit) (x y : Bool) (z := x). 29 | Goal forall x y, B x true = B y false -> Empty. 30 | discriminate. 31 | Qed. 32 | 33 | -------------------------------------------------------------------------------- /test/bugs/github1758.v: -------------------------------------------------------------------------------- 1 | From HoTT Require Import Basics.Overture HIT.Interval HIT.Flattening Colimits.GraphQuotient 2 | Spaces.Torus.Torus Cubical.DPath. 3 | 4 | (* Test that various higher inductive types are defined correctly. If they are defined in the most naive way, two uses of the induction principle that are definitionally equal on the point constructors will be considered definitionally equal, which is inconsistent. There is an idiom that must be used in order to force Coq to regard the supplementary data as being required as well. See, for example, Colimits/GraphQuotient.v for the idiom. *) 5 | 6 | Fail Definition test_interval (P : interval -> Type) (a : P zero) (b : P one) 7 | (p p' : seg # a = b) : 8 | interval_ind P a b p = interval_ind P a b p' 9 | := 1. 10 | 11 | Fail Definition test_wtil {A B f g C D} (Q : Wtil A B f g C D -> Type) 12 | (cct' : forall a x, Q (cct a x)) 13 | (ppt' : forall b y, (ppt b y) # (cct' (f b) y) = cct' (g b) (D b y)) 14 | (ppt'' : forall b y, (ppt b y) # (cct' (f b) y) = cct' (g b) (D b y)) 15 | : Wtil_ind Q cct' ppt' = Wtil_ind Q cct' ppt'' 16 | := 1. 17 | 18 | Section GraphQuotient_bug. 19 | Local Definition R : Unit -> Unit -> Type := fun x y => Unit. 20 | 21 | (* This should be the circle. *) 22 | Local Definition Q := GraphQuotient R. 23 | 24 | (* This is the identity map. *) 25 | Local Definition id : Q -> Q := GraphQuotient_rec gq (fun a b r => gqglue r). 26 | 27 | (* This is the constant map. *) 28 | Local Definition cst : Q -> Q. 29 | Proof. 30 | refine (GraphQuotient_rec gq _). 31 | intros [] [] r. 32 | reflexivity. 33 | Defined. 34 | 35 | Fail Definition test_graphquotient : id = cst := 1. 36 | End GraphQuotient_bug. 37 | 38 | Fail Definition test_torus (P : Torus -> Type) (pb : P tbase) 39 | (pla pla' : DPath P loop_a pb pb) 40 | (plb : DPath P loop_b pb pb) 41 | (ps : DPathSquare P surf pla pla plb plb) 42 | (ps' : DPathSquare P surf pla' pla' plb plb) 43 | : Torus_ind P pb pla plb ps = Torus_ind P pb pla' plb ps' 44 | := 1. 45 | -------------------------------------------------------------------------------- /test/bugs/github1791.v: -------------------------------------------------------------------------------- 1 | From HoTT Require Import WildCat Join. 2 | 3 | (** PR #1791 reduced the number of universe variables for several definitions. These tests ensure that they remain reduced. *) 4 | 5 | (** WildCat/Square.v: *) 6 | 7 | Check is0functor_idmap@{u1 u2}. 8 | Check vinverse@{u1 u2 u3 u4 u5}. 9 | Check transpose@{u1 u2 u3}. 10 | 11 | (** WildCat/Yoneda.v: *) 12 | 13 | Check opyon_equiv_0gpd@{u1 u2 u3 u4 u5 u6 u7 u8 u9}. 14 | 15 | (** Join/Core.v: *) 16 | 17 | Check equiv_join_sym@{u1 u2 u3 u4}. 18 | 19 | (** Join/JoinAssoc.v: *) 20 | 21 | Check join_assoc@{u1 u2 u3 u4 u5 u6 u7 u8}. 22 | -------------------------------------------------------------------------------- /test/bugs/github1794.v: -------------------------------------------------------------------------------- 1 | From HoTT Require Import Basics.Overture. 2 | 3 | (** When [rewrite] is first used, it defines helper lemmas. If the first use is in a Section that has universe variables, then these lemmas get unnecessary universe variables. Overture uses [rewrite] outside of a section to ensure that they have the expected number of universe variables, and we test that here. *) 4 | 5 | Check internal_paths_rew@{u1 u2}. 6 | Check internal_paths_rew_r@{u1 u2}. 7 | -------------------------------------------------------------------------------- /test/bugs/github370.v: -------------------------------------------------------------------------------- 1 | From HoTT Require Import Basics Homotopy.Suspension. 2 | 3 | Fail Check (fun (P : interval -> Type) (a : P Interval.zero) (b : P Interval.one) 4 | (p p' : seg # a = b) 5 | => idpath : interval_ind P a b p = interval_rect P a b p'). 6 | 7 | Fail Check Type0 : Type0. 8 | Check Susp nat : Type0. 9 | Fail Check Susp Type0 : Type0. 10 | -------------------------------------------------------------------------------- /test/bugs/github390.v: -------------------------------------------------------------------------------- 1 | From HoTT Require Import Basics Pointed Homotopy.Suspension. 2 | 3 | (** Check that [ispointed_susp] doesn't require just a [Set] *) 4 | Check (fun A : Type => _ : IsPointed (Susp A)). 5 | Check (@ispointed_susp Type). 6 | Check (@ispointed_susp Set). 7 | 8 | -------------------------------------------------------------------------------- /test/bugs/github726.v: -------------------------------------------------------------------------------- 1 | From HoTT Require Import Basics Types. 2 | 3 | (** Check that nested sigma-type notation didn't get clobbered by surreal cuts *) 4 | Check ({ l : Unit & { n : Unit & Unit }}). 5 | -------------------------------------------------------------------------------- /test/bugs/github754.v: -------------------------------------------------------------------------------- 1 | From HoTT Require Import Basics Types Universes.DProp Tactics.EquivalenceInduction. 2 | 3 | Local Open Scope nat_scope. 4 | 5 | (** Test 1 from issue #754 *) 6 | Inductive nat@{i | Set < i} : Type@{i} := 7 | | O : nat 8 | | S : nat -> nat. 9 | Fixpoint code_nat (m n : nat) {struct m} : DProp.DHProp := 10 | match m with 11 | | O => match n with 12 | | O => DProp.True 13 | | S _ => DProp.False 14 | end 15 | | S m' => match n with 16 | | O => DProp.False 17 | | S n' => code_nat m' n' 18 | end 19 | end. 20 | 21 | Local Set Warnings "-notation-overridden". 22 | Notation "x =n y" := (code_nat x y) : nat_scope. 23 | Local Set Warnings "notation-overridden". 24 | Bind Scope nat_scope with nat. 25 | Axiom equiv_path_nat : 26 | forall n m : nat, 27 | Trunc.trunctype_type (DProp.dhprop_hprop (n =n m)) <~> n = m. 28 | 29 | Definition nat_discr `{Funext} {n: nat}: O <> S n. 30 | Proof. 31 | intro H'. 32 | equiv_induction (@equiv_path_nat O (S n)). 33 | assumption. 34 | Qed. 35 | -------------------------------------------------------------------------------- /test/bugs/github973.v: -------------------------------------------------------------------------------- 1 | From HoTT Require Import Basics. 2 | 3 | Inductive vec (A : Type) : nat -> Type := 4 | | nil : vec A 0 5 | | cons : forall n : nat, A -> vec A n -> vec A (S n). 6 | 7 | Definition hd (A : Type) (n : nat) (v : vec A (S n)) : A := 8 | match v in (vec _ (S n)) return A with 9 | | cons _ h _ => h 10 | end. 11 | 12 | -------------------------------------------------------------------------------- /test/dune: -------------------------------------------------------------------------------- 1 | (coq.theory 2 | (name HoTT.Tests) 3 | (theories HoTT)) 4 | 5 | (include_subdirs qualified) 6 | 7 | (alias 8 | (name runtest) 9 | (deps 10 | (glob_files_rec ./*.vo))) 11 | -------------------------------------------------------------------------------- /theories/Algebra/AbGroups.v: -------------------------------------------------------------------------------- 1 | (** Theory *) 2 | 3 | Require Export HoTT.Algebra.Groups. 4 | 5 | Require Export HoTT.Algebra.AbGroups.AbelianGroup. 6 | Require Export HoTT.Algebra.AbGroups.Abelianization. 7 | Require Export HoTT.Algebra.AbGroups.AbPullback. 8 | Require Export HoTT.Algebra.AbGroups.AbPushout. 9 | Require Export HoTT.Algebra.AbGroups.Biproduct. 10 | Require Export HoTT.Algebra.AbGroups.AbHom. 11 | Require Export HoTT.Algebra.AbGroups.Cyclic. 12 | Require Export HoTT.Algebra.AbGroups.Centralizer. 13 | Require Export HoTT.Algebra.AbGroups.FiniteSum. 14 | 15 | (* The theory of Ext groups of abelian groups is in HoTT.Algebra.AbSES. *) 16 | 17 | (** Examples *) 18 | 19 | Require Export HoTT.Algebra.AbGroups.Z. 20 | -------------------------------------------------------------------------------- /theories/Algebra/AbGroups/AbProjective.v: -------------------------------------------------------------------------------- 1 | Require Import Basics Types AbelianGroup AbPullback 2 | WildCat.Core Limits.Pullback ReflectiveSubuniverse Truncations.Core. 3 | 4 | (** * Projective abelian groups *) 5 | 6 | (** We define projective abelian groups and show that [P] is projective if and only if every epimorphism [A -> P] merely splits. *) 7 | 8 | (** An abelian group [P] is projective if for any map [P -> B] and epimorphism [A -> B], there merely exists a lift [P -> A] making the following triangle commute: 9 | 10 | A 11 | ^ | 12 | l / | 13 | | e 14 | / | 15 | V 16 | P ---> B 17 | f 18 | *) 19 | Class IsAbProjective@{u +} (P : AbGroup@{u}) : Type := 20 | isabprojective : forall (A B : AbGroup@{u}), forall (e : A $-> B), 21 | forall (f : P $-> B), IsSurjection e -> merely (exists l : P $-> A, e $o l == f). 22 | 23 | (** An abelian group is projective iff epis into it merely split. *) 24 | Proposition iff_isabprojective_surjections_split (P : AbGroup) 25 | : IsAbProjective P 26 | <-> (forall A, forall p : A $-> P, IsSurjection p -> 27 | merely (exists s : P $-> A, p $o s == grp_homo_id)). 28 | Proof. 29 | split. 30 | - intros H A B. 31 | apply H. 32 | - intros H A B e f H1. 33 | pose proof (s := H (ab_pullback f e) (grp_pullback_pr1 f e) 34 | (conn_map_pullback _ f e)). 35 | strip_truncations. 36 | destruct s as [s h]. 37 | refine (tr ((grp_pullback_pr2 f e) $o s; _)); intro x. 38 | refine ((pullback_commsq f e _)^ @ _). 39 | exact (ap f (h x)). 40 | Defined. 41 | -------------------------------------------------------------------------------- /theories/Algebra/AbGroups/AbPullback.v: -------------------------------------------------------------------------------- 1 | Require Import Basics. 2 | Require Import Limits.Pullback Cubical.PathSquare. 3 | Require Export Algebra.Groups.GrpPullback. 4 | Require Import Algebra.AbGroups.AbelianGroup. 5 | Require Import WildCat.Core. 6 | 7 | Local Open Scope mc_add_scope. 8 | 9 | (** * Pullbacks of abelian groups *) 10 | 11 | Section AbPullback. 12 | (* Variables are named to correspond with Limits.Pullback. *) 13 | Context {A B C : AbGroup} (f : B $-> A) (g : C $-> A). 14 | 15 | #[export] Instance ab_pullback_commutative 16 | : Commutative (@group_sgop (grp_pullback f g)). 17 | Proof. 18 | unfold Commutative. 19 | intros [b [c p]] [d [e q]]. 20 | apply equiv_path_pullback; simpl. 21 | refine (commutativity _ _; commutativity _ _; _). 22 | apply equiv_sq_path. 23 | apply path_ishprop. 24 | Defined. 25 | 26 | Definition ab_pullback : AbGroup := Build_AbGroup (grp_pullback f g) _. 27 | 28 | (** The corecursion principle is inherited from [Group]; use [grp_pullback_corec] and friends from Groups/GrpPullback.v. *) 29 | 30 | End AbPullback. 31 | -------------------------------------------------------------------------------- /theories/Algebra/AbGroups/Cyclic.v: -------------------------------------------------------------------------------- 1 | Require Import Basics.Overture Basics.Tactics WildCat.Core AbelianGroup 2 | AbGroups.Z Spaces.Int Groups.QuotientGroup. 3 | 4 | (** * Cyclic groups *) 5 | 6 | (** The [n]-th cyclic group is the cokernel of [ab_mul n]. *) 7 | Definition cyclic (n : nat) : AbGroup 8 | := ab_cokernel (ab_mul (A:=abgroup_Z) n). 9 | 10 | Definition cyclic_in (n : nat) : abgroup_Z $-> cyclic n 11 | := grp_quotient_map. 12 | 13 | Definition ab_mul_cyclic_in (n : nat) (x y : abgroup_Z) 14 | : ab_mul y (cyclic_in n x) = cyclic_in n (y * x)%int. 15 | Proof. 16 | lhs_V napply ab_mul_natural. 17 | apply ap, abgroup_Z_ab_mul. 18 | Defined. 19 | -------------------------------------------------------------------------------- /theories/Algebra/AbGroups/Z.v: -------------------------------------------------------------------------------- 1 | Require Import Basics. 2 | Require Import Spaces.Pos.Core Spaces.Int. 3 | Require Import Algebra.AbGroups.AbelianGroup. 4 | 5 | Local Set Universe Minimization ToSet. 6 | 7 | Local Open Scope int_scope. 8 | Local Open Scope mc_add_scope. 9 | 10 | (** * The group of integers *) 11 | 12 | (** See also Cyclic.v for a definition of the integers as the free group on one generator. *) 13 | 14 | Definition abgroup_Z@{} : AbGroup@{Set}. 15 | Proof. 16 | snapply Build_AbGroup'. 17 | - exact Int. 18 | - exact 0%int. 19 | - exact int_neg. 20 | - exact int_add. 21 | - exact _. 22 | - exact int_add_comm. 23 | - exact int_add_assoc. 24 | - exact int_add_0_l. 25 | - exact int_add_neg_l. 26 | Defined. 27 | 28 | (** For every group [G] and element [g : G], the map sending an integer to that power of [g] is a homomorphism. See [ab_mul] for the homomorphism [G -> G] when [G] is abelian. *) 29 | Definition grp_pow_homo {G : Group} (g : G) 30 | : GroupHomomorphism abgroup_Z G. 31 | Proof. 32 | snapply Build_GroupHomomorphism. 33 | 1: exact (grp_pow g). 34 | intros m n; apply grp_pow_add. 35 | Defined. 36 | 37 | (** [ab_mul] (and [grp_pow]) give multiplication in [abgroup_Z]. *) 38 | Definition abgroup_Z_ab_mul (z z' : Int) 39 | : ab_mul (A:=abgroup_Z) z z' = z * z'. 40 | Proof. 41 | induction z. 42 | - reflexivity. 43 | - cbn. 44 | lhs napply (grp_pow_succ (G:=abgroup_Z)). 45 | rhs napply int_mul_succ_l. 46 | f_ap. 47 | - cbn. 48 | lhs napply (grp_pow_pred (G:=abgroup_Z)). 49 | rhs napply int_mul_pred_l. 50 | f_ap. 51 | Defined. 52 | -------------------------------------------------------------------------------- /theories/Algebra/AbSES.v: -------------------------------------------------------------------------------- 1 | Require Export AbSES.Core. 2 | Require Export AbSES.Ext. 3 | Require Export AbSES.Pullback. 4 | Require Export AbSES.PullbackFiberSequence. 5 | Require Export AbSES.Pushout. 6 | Require Export AbSES.BaerSum. 7 | Require Export AbSES.DirectSum. 8 | Require Export AbSES.SixTerm. 9 | -------------------------------------------------------------------------------- /theories/Algebra/Aut.v: -------------------------------------------------------------------------------- 1 | Require Import Basics. 2 | Require Import Truncations. 3 | Require Import Algebra.ooGroup. 4 | Require Import Universes.BAut. 5 | Require Import Pointed.Core. 6 | 7 | Local Open Scope pointed_scope. 8 | 9 | (** * Automorphism oo-Groups *) 10 | 11 | (** We define [Aut X] using the pointed, connected type [BAut X]. *) 12 | Definition Aut (X : Type) : ooGroup 13 | := Build_ooGroup [BAut X, _] _. 14 | -------------------------------------------------------------------------------- /theories/Algebra/Congruence.v: -------------------------------------------------------------------------------- 1 | Require Import Classes.interfaces.canonical_names. 2 | 3 | (* We say that a relation is a congruence if it respects the operation. 4 | This is technically incorrect since we are not enforcing the relation to be an equivalence relation. 5 | *) 6 | 7 | Local Open Scope mc_mult_scope. 8 | 9 | Class IsCongruence {G} `{SgOp G} (R : Relation G) := { 10 | iscong {x x' y y'} : R x x' -> R y y' -> R (x * y) (x' * y'); 11 | }. 12 | -------------------------------------------------------------------------------- /theories/Algebra/Groups.v: -------------------------------------------------------------------------------- 1 | (** Theory *) 2 | 3 | Require Export HoTT.Algebra.Groups.Group. 4 | Require Export HoTT.Algebra.Groups.Subgroup. 5 | 6 | Require Export HoTT.Algebra.Groups.QuotientGroup. 7 | Require Export HoTT.Algebra.Groups.GrpPullback. 8 | Require Export HoTT.Algebra.Groups.GroupCoeq. 9 | Require Export HoTT.Algebra.Groups.FreeGroup. 10 | Require Export HoTT.Algebra.Groups.FreeProduct. 11 | 12 | Require Export HoTT.Algebra.Groups.Presentation. 13 | Require Export HoTT.Algebra.Groups.ShortExactSequence. 14 | Require Export HoTT.Algebra.Groups.Finite. 15 | 16 | (** Examples *) 17 | 18 | 19 | -------------------------------------------------------------------------------- /theories/Algebra/Rings.v: -------------------------------------------------------------------------------- 1 | (** Basic theory *) 2 | 3 | Require Export HoTT.Algebra.Rings.Ring. 4 | Require Export HoTT.Algebra.Rings.CRing. 5 | Require Export HoTT.Algebra.Rings.Ideal. 6 | Require Export HoTT.Algebra.Rings.Module. 7 | Require Export HoTT.Algebra.Rings.QuotientRing. 8 | Require Export HoTT.Algebra.Rings.Localization. 9 | Require Export HoTT.Algebra.Rings.ChineseRemainder. 10 | Require Export HoTT.Algebra.Rings.KroneckerDelta. 11 | Require Export HoTT.Algebra.Rings.Idempotent. 12 | 13 | (** Examples *) 14 | 15 | Require Export HoTT.Algebra.Rings.Z. 16 | Require Export HoTT.Algebra.Rings.Vector. 17 | Require Export HoTT.Algebra.Rings.Matrix. 18 | -------------------------------------------------------------------------------- /theories/Algebra/ooAction.v: -------------------------------------------------------------------------------- 1 | Require Import Basics. 2 | Require Import Algebra.ooGroup. 3 | 4 | Local Open Scope path_scope. 5 | 6 | (** * Actions of oo-Groups *) 7 | 8 | Definition ooAction (G : ooGroup) 9 | := classifying_space G -> Type. 10 | 11 | Definition action_space {G} : ooAction G -> Type 12 | := fun X => X (point _). 13 | 14 | Coercion action_space : ooAction >-> Sortclass. 15 | -------------------------------------------------------------------------------- /theories/Axioms/Funext.v: -------------------------------------------------------------------------------- 1 | Require Import Basics.Overture. 2 | 3 | (** To assume the Funext axiom outright, import this file. (Doing this instead of simply positing Funext directly avoids creating multiple witnesses for the axiom in different developments.) *) 4 | 5 | Axiom funext_axiom : Funext. 6 | Existing Instance funext_axiom. 7 | -------------------------------------------------------------------------------- /theories/Axioms/PropResizing.v: -------------------------------------------------------------------------------- 1 | Require Import Basics.Overture. 2 | 3 | (** To assume the [PropResizing] axiom outright, import this file. (Doing this instead of simply positing [PropResizing] directly avoids creating multiple witnesses for the axiom in different developments.) *) 4 | 5 | Axiom propresizing_axiom : PropResizing. 6 | Existing Instance propresizing_axiom. 7 | -------------------------------------------------------------------------------- /theories/Axioms/Univalence.v: -------------------------------------------------------------------------------- 1 | Require Import Types.Universe. 2 | 3 | (** To assume the Univalence axiom outright, import this file. (Doing this instead of simply positing Univalence directly avoids creating multiple witnesses for the axiom in different developments.) *) 4 | 5 | Axiom univalence_axiom : Univalence. 6 | Existing Instance univalence_axiom. 7 | -------------------------------------------------------------------------------- /theories/Basics.v: -------------------------------------------------------------------------------- 1 | Require Export Basics.Overture. 2 | Require Export Basics.PathGroupoids. 3 | Require Export Basics.Contractible. 4 | Require Export Basics.Equivalences. 5 | Require Export Basics.Trunc. 6 | Require Export Basics.Decidable. 7 | Require Export Basics.Utf8. 8 | Require Export Basics.Notations. 9 | Require Export Basics.Tactics. 10 | Require Export Basics.Classes. 11 | Require Export Basics.Iff. 12 | 13 | Require Export Basics.Nat. 14 | Require Export Basics.Numeral. 15 | -------------------------------------------------------------------------------- /theories/Basics/Classes.v: -------------------------------------------------------------------------------- 1 | Require Import Basics.Overture Basics.Tactics. 2 | 3 | (** * Classes *) 4 | 5 | (** ** Injective Functions *) 6 | 7 | Class IsInjective {A B : Type} (f : A -> B) 8 | := injective : forall x y, f x = f y -> x = y. 9 | Arguments injective {A B} f {_} _ _. 10 | 11 | Definition neq_isinj {A B : Type} (f : A -> B) `{!IsInjective f} 12 | : forall x y, x <> y -> f x <> f y. 13 | Proof. 14 | intros x y np q. 15 | apply np, (injective f). 16 | exact q. 17 | Defined. 18 | 19 | Instance isinj_idmap A : @IsInjective A A idmap 20 | := fun x y => idmap. 21 | 22 | #[export] Hint Unfold IsInjective : typeclass_instances. 23 | 24 | Definition isinj_compose {A B C f g} `{IsInjective B C g} `{IsInjective A B f} 25 | : IsInjective (g o f). 26 | Proof. 27 | intros x y p. 28 | by apply (injective f), (injective g). 29 | Defined. 30 | #[export] Hint Immediate isinj_compose : typeclass_instances. 31 | 32 | Definition isinj_cancelL {A B C : Type} (f : A -> B) (g : B -> C) 33 | `{!IsInjective (g o f)} 34 | : IsInjective f. 35 | Proof. 36 | intros x y p. 37 | apply (injective (g o f)). 38 | exact (ap g p). 39 | Defined. 40 | 41 | (** ** Antisymmetric Relations *) 42 | 43 | Class AntiSymmetric {A : Type} (R : A -> A -> Type) : Type 44 | := antisymmetry : forall x y, R x y -> R y x -> x = y. 45 | Arguments antisymmetry {A} R {AntiSymmetric} x y _ _. 46 | -------------------------------------------------------------------------------- /theories/Basics/Iff.v: -------------------------------------------------------------------------------- 1 | Require Import Basics.Overture Basics.Tactics. 2 | 3 | Local Set Universe Minimization ToSet. 4 | 5 | (** * If and only if *) 6 | 7 | (** ** Definition *) 8 | 9 | (** [iff A B], written [A <-> B], expresses the logical equivalence of [A] and [B] *) 10 | Definition iff (A B : Type) := prod (A -> B) (B -> A). 11 | 12 | Notation "A <-> B" := (iff A B) : type_scope. 13 | 14 | (** ** Basic Properties *) 15 | 16 | (** Everything is logically equivalent to itself. *) 17 | Definition iff_refl {A} : A <-> A 18 | := (idmap , idmap). 19 | 20 | (** [iff] is a reflexive relation. *) 21 | Instance iff_reflexive : Reflexive iff | 1 22 | := @iff_refl. 23 | 24 | (** Logical equivalences can be inverted. *) 25 | Definition iff_inverse {A B} : (A <-> B) -> (B <-> A) 26 | := fun f => (snd f , fst f). 27 | 28 | (** [iff] is a symmetric relation. *) 29 | Instance symmetric_iff : Symmetric iff | 1 30 | := @iff_inverse. 31 | 32 | (** Logical equivalences can be composed. *) 33 | Definition iff_compose {A B C} (f : A <-> B) (g : B <-> C) : A <-> C 34 | := (fst g o fst f , snd f o snd g). 35 | 36 | (** [iff] is a transitive relation. *) 37 | Instance transitive_iff : Transitive iff | 1 38 | := @iff_compose. 39 | 40 | (** Any equivalence can be considered a logical equivalence by discarding everything but the maps. We make this a coercion so that equivalences can be used in place of logical equivalences. *) 41 | Coercion iff_equiv {A B : Type} (f : A <~> B) 42 | : A <-> B := (equiv_fun f, f^-1). 43 | 44 | (** ** Logical Laws *) 45 | 46 | (** One of De Morgan's Laws. The dual statement about negating a product appears in Decidable.v due to decidability requirements. *) 47 | Definition iff_not_sum A B : ~ (A + B) <-> ~ A * ~ B. 48 | Proof. 49 | split. 50 | - intros ns. 51 | exact (ns o inl, ns o inr). 52 | - by intros []; snapply sum_ind. 53 | Defined. 54 | 55 | Definition iff_contradiction A : A * ~A <-> Empty. 56 | Proof. 57 | split. 58 | - intros [a na]; exact (na a). 59 | - intros e; exact (Empty_rec _ e). 60 | Defined. 61 | -------------------------------------------------------------------------------- /theories/Basics/Numeral.v: -------------------------------------------------------------------------------- 1 | Require Import Basics.Overture Basics.Numerals.Decimal Basics.Numerals.Hexadecimal. 2 | 3 | (** * Decimal or Hexadecimal numbers *) 4 | 5 | Variant uint : Type0 := UIntDec (u:Decimal.uint) | UIntHex (u:Hexadecimal.uint). 6 | 7 | Variant int : Type0 := IntDec (i:Decimal.int) | IntHex (i:Hexadecimal.int). 8 | 9 | Variant numeral : Type0 := Dec (d:Decimal.decimal) | Hex (h:Hexadecimal.hexadecimal). 10 | 11 | Register uint as num.num_uint.type. 12 | Register int as num.num_int.type. 13 | Register numeral as num.numeral.type. 14 | Register numeral as num.number.type. 15 | 16 | (** Pseudo-conversion functions used when declaring 17 | Numeral Notations on [uint] and [int]. *) 18 | 19 | Definition uint_of_uint (i:uint) := i. 20 | Definition int_of_int (i:int) := i. 21 | 22 | (* Parsing / printing of decimal numbers *) 23 | Number Notation uint uint_of_uint uint_of_uint : dec_uint_scope. 24 | Number Notation int int_of_int int_of_int : dec_int_scope. 25 | -------------------------------------------------------------------------------- /theories/Categories/Adjoint.v: -------------------------------------------------------------------------------- 1 | (** * Adjunctions *) 2 | (** ** Definitions *) 3 | Require Adjoint.Core. 4 | (** *** unit+UMP *) 5 | (** *** counit+UMP *) 6 | (** *** unit+counit+zig+zag *) 7 | Require Adjoint.UnitCounit. 8 | (** *** universal morphisms *) 9 | Require Adjoint.UniversalMorphisms. 10 | (** *** hom-set isomorphism *) 11 | Require Adjoint.Hom. 12 | (** ** Coercions between various definitions *) 13 | Require Adjoint.UnitCounitCoercions. 14 | Require Adjoint.HomCoercions. 15 | (** ** Opposite adjunctions *) 16 | Require Adjoint.Dual. 17 | (** ** Path spaces of adjunctions *) 18 | Require Adjoint.Paths. 19 | (** ** Composition *) 20 | Require Adjoint.Composition. 21 | (** ** Pointwise adjunctions *) 22 | Require Adjoint.Pointwise. 23 | (** ** Functoriality of any adjoint construction *) 24 | Require Adjoint.Functorial. 25 | 26 | Include Adjoint.Core. 27 | Include Adjoint.UnitCounit. 28 | Include Adjoint.UniversalMorphisms.Core. 29 | Include Adjoint.Hom. 30 | Include Adjoint.UnitCounitCoercions. 31 | Include Adjoint.HomCoercions. 32 | Include Adjoint.Dual. 33 | Include Adjoint.Paths. 34 | Include Adjoint.Composition. 35 | Include Adjoint.Pointwise. 36 | Include Adjoint.Functorial.Core. 37 | 38 | Require Export Adjoint.Notations. 39 | -------------------------------------------------------------------------------- /theories/Categories/Adjoint/Composition.v: -------------------------------------------------------------------------------- 1 | (** * Adjunction composition *) 2 | (** ** Definition *) 3 | Require Adjoint.Composition.Core. 4 | (** ** Associativity *) 5 | Require Adjoint.Composition.AssociativityLaw. 6 | (** * Left and right identity laws *) 7 | Require Adjoint.Composition.IdentityLaws. 8 | 9 | Include Adjoint.Composition.Core. 10 | Include Adjoint.Composition.AssociativityLaw. 11 | Include Adjoint.Composition.IdentityLaws. 12 | 13 | Module Export AdjointCompositionNotations. 14 | Include AdjointCompositionCoreNotations. 15 | End AdjointCompositionNotations. 16 | -------------------------------------------------------------------------------- /theories/Categories/Adjoint/Composition/AssociativityLaw.v: -------------------------------------------------------------------------------- 1 | (** * Associativity of adjunction composition *) 2 | Require Import Category.Core Functor.Core. 3 | Require Import Adjoint.Composition.Core Adjoint.Core. 4 | Require Adjoint.Composition.LawsTactic. 5 | Require Import Types.Sigma Types.Prod. 6 | 7 | Set Universe Polymorphism. 8 | Set Implicit Arguments. 9 | Generalizable All Variables. 10 | Set Asymmetric Patterns. 11 | 12 | Local Open Scope adjunction_scope. 13 | Local Open Scope morphism_scope. 14 | 15 | Section composition_lemmas. 16 | Local Notation AdjunctionWithFunctors C D := 17 | { fg : Functor C D * Functor D C 18 | | fst fg -| snd fg }. 19 | 20 | Context `{H0 : Funext}. 21 | 22 | Variables B C D E : PreCategory. 23 | 24 | Variable F : Functor B C. 25 | Variable F' : Functor C B. 26 | Variable G : Functor C D. 27 | Variable G' : Functor D C. 28 | Variable H : Functor D E. 29 | Variable H' : Functor E D. 30 | 31 | Variable AF : F -| F'. 32 | Variable AG : G -| G'. 33 | Variable AH : H -| H'. 34 | 35 | Local Open Scope adjunction_scope. 36 | 37 | Lemma associativity 38 | : ((_, _); (AH o AG) o AF) = ((_, _); AH o (AG o AF)) :> AdjunctionWithFunctors B E. 39 | Proof. 40 | apply path_sigma_uncurried; simpl. 41 | (exists (path_prod' 42 | (Functor.Composition.Laws.associativity _ _ _) 43 | (symmetry _ _ (Functor.Composition.Laws.associativity _ _ _)))); 44 | Adjoint.Composition.LawsTactic.law_t. 45 | Qed. 46 | End composition_lemmas. 47 | 48 | #[export] 49 | Hint Resolve associativity : category. 50 | -------------------------------------------------------------------------------- /theories/Categories/Adjoint/Composition/IdentityLaws.v: -------------------------------------------------------------------------------- 1 | (** * Left and right identity laws of adjunction composition *) 2 | Require Import Category.Core Functor.Core. 3 | Require Import Adjoint.Composition.Core Adjoint.Core Adjoint.Identity. 4 | Require Adjoint.Composition.LawsTactic. 5 | Require Import Types.Sigma Types.Prod. 6 | 7 | Set Universe Polymorphism. 8 | Set Implicit Arguments. 9 | Generalizable All Variables. 10 | Set Asymmetric Patterns. 11 | 12 | Local Open Scope adjunction_scope. 13 | Local Open Scope morphism_scope. 14 | 15 | Section identity_lemmas. 16 | Local Notation AdjunctionWithFunctors C D := 17 | { fg : Functor C D * Functor D C 18 | | fst fg -| snd fg }. 19 | 20 | Context `{Funext}. 21 | 22 | Variables C D : PreCategory. 23 | 24 | Variable F : Functor C D. 25 | Variable G : Functor D C. 26 | 27 | Variable A : F -| G. 28 | 29 | Local Open Scope adjunction_scope. 30 | 31 | Lemma left_identity 32 | : ((_, _); 1 o A) = ((_, _); A) :> AdjunctionWithFunctors C D. 33 | Proof. 34 | apply path_sigma_uncurried; simpl. 35 | (exists (path_prod' 36 | (Functor.Composition.Laws.left_identity _) 37 | (Functor.Composition.Laws.right_identity _))). 38 | Adjoint.Composition.LawsTactic.law_t. 39 | Qed. 40 | 41 | Lemma right_identity 42 | : ((_, _); A o 1) = ((_, _); A) :> AdjunctionWithFunctors C D. 43 | Proof. 44 | apply path_sigma_uncurried; simpl. 45 | (exists (path_prod' 46 | (Functor.Composition.Laws.right_identity _) 47 | (Functor.Composition.Laws.left_identity _))). 48 | Adjoint.Composition.LawsTactic.law_t. 49 | Qed. 50 | End identity_lemmas. 51 | 52 | #[export] 53 | Hint Rewrite @left_identity @right_identity : category. 54 | #[export] 55 | Hint Immediate left_identity right_identity : category. 56 | -------------------------------------------------------------------------------- /theories/Categories/Adjoint/Core.v: -------------------------------------------------------------------------------- 1 | (** * Adjunctions *) 2 | Require Import Adjoint.UnitCounit. 3 | Require Import Basics.Notations. 4 | 5 | Notation Adjunction := AdjunctionUnitCounit. 6 | 7 | Module Export AdjointCoreNotations. 8 | Infix "-|" := Adjunction : type_scope. 9 | End AdjointCoreNotations. 10 | -------------------------------------------------------------------------------- /theories/Categories/Adjoint/Dual.v: -------------------------------------------------------------------------------- 1 | (** * Opposite adjunction [F ⊣ G → Gᵒᵖ ⊣ Fᵒᵖ] *) 2 | Require Import Category.Core Functor.Core. 3 | Require Import Functor.Dual NaturalTransformation.Dual. 4 | Require Import Adjoint.UnitCounit Adjoint.Core. 5 | 6 | Set Universe Polymorphism. 7 | Set Implicit Arguments. 8 | Generalizable All Variables. 9 | Set Asymmetric Patterns. 10 | 11 | Local Open Scope category_scope. 12 | 13 | (** ** Definition of [Aᵒᵖ] *) 14 | Definition opposite 15 | C D 16 | (F : Functor C D) 17 | (G : Functor D C) 18 | (A : F -| G) 19 | : G^op -| F^op 20 | := @Build_AdjunctionUnitCounit 21 | _ _ (G^op) (F^op) 22 | ((counit A)^op) 23 | ((unit A)^op) 24 | (unit_counit_equation_2 A) 25 | (unit_counit_equation_1 A). 26 | 27 | Local Notation "A ^op" := (opposite A) : adjunction_scope. 28 | 29 | Local Open Scope adjunction_scope. 30 | 31 | (** ** [ᵒᵖ] is judgmentally involutive *) 32 | Definition opposite_involutive C D (F : Functor C D) (G : Functor D C) (A : F -| G) 33 | : (A^op)^op = A 34 | := idpath. 35 | 36 | Module Export AdjointDualNotations. 37 | Notation "A ^op" := (opposite A) : adjunction_scope. 38 | End AdjointDualNotations. 39 | -------------------------------------------------------------------------------- /theories/Categories/Adjoint/Functorial.v: -------------------------------------------------------------------------------- 1 | (** * Functoriality of the construction of adjunctions *) 2 | (** ** Computational components *) 3 | Require Adjoint.Functorial.Parts. 4 | (** ** Functor laws *) 5 | Require Adjoint.Functorial.Laws. 6 | (** ** Adjunction functor *) 7 | Require Adjoint.Functorial.Core. 8 | -------------------------------------------------------------------------------- /theories/Categories/Adjoint/Identity.v: -------------------------------------------------------------------------------- 1 | (** * Identity adjunction [1 ⊣ 1] *) 2 | Require Import Category.Core. 3 | Require Import Functor.Identity NaturalTransformation.Identity. 4 | Require Import Adjoint.UnitCounit Adjoint.Core. 5 | 6 | Set Universe Polymorphism. 7 | Set Implicit Arguments. 8 | Generalizable All Variables. 9 | Set Asymmetric Patterns. 10 | 11 | Section identity. 12 | (** There is an identity adjunction. It does the obvious thing. *) 13 | 14 | Definition identity C : @Adjunction C C 1 1 15 | := @Build_AdjunctionUnitCounit 16 | C C 1 1 17 | 1 18 | 1 19 | (fun _ => identity_identity _ _) 20 | (fun _ => identity_identity _ _). 21 | End identity. 22 | 23 | Module Export AdjointIdentityNotations. 24 | Notation "1" := (identity _) : adjunction_scope. 25 | End AdjointIdentityNotations. 26 | -------------------------------------------------------------------------------- /theories/Categories/Adjoint/Notations.v: -------------------------------------------------------------------------------- 1 | Require Adjoint.Composition. 2 | Require Adjoint.Core. 3 | Require Adjoint.Dual. 4 | Require Adjoint.Identity. 5 | 6 | Include Adjoint.Composition.AdjointCompositionNotations. 7 | Include Adjoint.Core.AdjointCoreNotations. 8 | Include Adjoint.Dual.AdjointDualNotations. 9 | Include Adjoint.Identity.AdjointIdentityNotations. 10 | -------------------------------------------------------------------------------- /theories/Categories/Adjoint/UniversalMorphisms.v: -------------------------------------------------------------------------------- 1 | (** * Adjunctions as universal morphisms *) 2 | (** ** Definitions *) 3 | Require Adjoint.UniversalMorphisms.Core. 4 | 5 | Include Adjoint.UniversalMorphisms.Core. 6 | -------------------------------------------------------------------------------- /theories/Categories/Adjoint/Utf8.v: -------------------------------------------------------------------------------- 1 | Require Import Adjoint.Core Adjoint.Dual Adjoint.Composition.Core. 2 | Require Export Adjoint.Notations. 3 | Require Import Basics.Utf8. 4 | 5 | Infix "⊣" := Adjunction : type_scope. 6 | 7 | Infix "∘" := compose : adjunction_scope. 8 | 9 | (** It would be nice to put [, format "A 'ᵒᵖ'"] here, but that would 10 | make this notation unparseable. *) 11 | Notation "A 'ᵒᵖ'" := (opposite A) : adjunction_scope. 12 | -------------------------------------------------------------------------------- /theories/Categories/Cat.v: -------------------------------------------------------------------------------- 1 | (** * Cat, precategories of precategories *) 2 | (** ** Definitions *) 3 | Require Cat.Core. 4 | (** ** Morphisms in cat *) 5 | Require Cat.Morphisms. 6 | 7 | Include Cat.Core. 8 | Include Cat.Morphisms. 9 | -------------------------------------------------------------------------------- /theories/Categories/Cat/Morphisms.v: -------------------------------------------------------------------------------- 1 | (** * Morphisms in cat *) 2 | Require Import Category.Core Functor.Core FunctorCategory.Core NaturalTransformation.Core. 3 | Require Import Category.Morphisms. 4 | 5 | Set Universe Polymorphism. 6 | Set Implicit Arguments. 7 | Generalizable All Variables. 8 | Set Asymmetric Patterns. 9 | 10 | Local Open Scope category_scope. 11 | Local Open Scope morphism_scope. 12 | 13 | (** ** Lemmas relationship between transporting the action of functors on objects, and [idtoiso] *) 14 | Section iso_lemmas. 15 | Context `{Funext}. 16 | 17 | Variable C : PreCategory. 18 | 19 | Variables s d : C. 20 | Variables m1 m2 : morphism C s d. 21 | Variable p : m1 = m2. 22 | 23 | Variables Fs Fd : PreCategory. 24 | Variable Fm : morphism C s d -> Functor Fs Fd. 25 | 26 | Lemma transport_Fc_to_idtoiso 27 | s' d' u 28 | : @transport _ (fun m => morphism _ (Fm m s') d') _ _ p u 29 | = u o components_of (Category.Morphisms.idtoiso (_ -> _) (ap Fm p) : morphism _ _ _)^-1 s'. 30 | Proof. 31 | case p; clear p; simpl; autorewrite with morphism; reflexivity. 32 | Qed. 33 | 34 | Lemma transport_cF_to_idtoiso 35 | s' d' u 36 | : @transport _ (fun m => morphism _ s' (Fm m d')) _ _ p u 37 | = components_of (Category.Morphisms.idtoiso (_ -> _) (ap Fm p) : morphism _ _ _) d' o u. 38 | Proof. 39 | case p; clear p; simpl; autorewrite with morphism; reflexivity. 40 | Qed. 41 | End iso_lemmas. 42 | -------------------------------------------------------------------------------- /theories/Categories/Category.v: -------------------------------------------------------------------------------- 1 | (** * Categories *) 2 | (** We collect here all of the files about categories. *) 3 | (** Since there are only notations in [Category.Notations], we can just export those. *) 4 | Require Export Category.Notations. 5 | 6 | (** ** Definition of precategories *) 7 | Require Category.Core. 8 | (** ** Opposite precategories *) 9 | Require Category.Dual. 10 | (** ** Morphisms in precategories *) 11 | Require Category.Morphisms. 12 | (** ** Classification of path space *) 13 | Require Category.Paths. 14 | (** ** Universal objects *) 15 | Require Category.Objects. 16 | (** ** Product precategories *) 17 | Require Category.Prod. 18 | (** ** Dependent product precategories *) 19 | Require Category.Pi. 20 | (** ** ∑-precategories *) 21 | Require Category.Sigma. 22 | (** ** Strict categories *) 23 | Require Category.Strict. 24 | (** ** Coproduct precategories *) 25 | Require Category.Sum. 26 | (** ** Categories (univalent or saturated) *) 27 | Require Category.Univalent. 28 | 29 | Local Set Warnings "-notation-overridden". 30 | Include Category.Core. 31 | Include Category.Dual. 32 | Include Category.Morphisms. 33 | Include Category.Paths. 34 | Include Category.Objects. 35 | Include Category.Prod. 36 | Include Category.Pi. 37 | (** We use the [Sigma] folder only to allow us to split up the various files and group conceptually similar lemmas, but not for namespacing. So we include the main file in it. *) 38 | Include Category.Sigma. 39 | Include Category.Strict. 40 | Include Category.Sum. 41 | Include Category.Univalent. 42 | (** We don't want to make UTF-8 notations the default, so we don't export them. *) 43 | 44 | (** ** Subcategories *) 45 | (** For the subfolders, we need to re-create the module structure. Alas, namespacing in Coq is kind-of broken (see, e.g., https://coq.inria.fr/bugs/show_bug.cgi?id=3676), so we don't get the ability to rename subfolders by [Including] into other modules. *) 46 | Require Category.Subcategory. 47 | -------------------------------------------------------------------------------- /theories/Categories/Category/Dual.v: -------------------------------------------------------------------------------- 1 | (** * Opposite Category *) 2 | Require Import Category.Core Category.Objects. 3 | 4 | Set Universe Polymorphism. 5 | Set Implicit Arguments. 6 | Generalizable All Variables. 7 | Set Asymmetric Patterns. 8 | 9 | 10 | Local Open Scope morphism_scope. 11 | Local Open Scope category_scope. 12 | 13 | (** ** Definition of [Cᵒᵖ] *) 14 | Definition opposite (C : PreCategory) : PreCategory 15 | := @Build_PreCategory' 16 | C 17 | (fun s d => morphism C d s) 18 | (identity (C := C)) 19 | (fun _ _ _ m1 m2 => m2 o m1) 20 | (fun _ _ _ _ _ _ _ => @associativity_sym _ _ _ _ _ _ _ _) 21 | (fun _ _ _ _ _ _ _ => @associativity _ _ _ _ _ _ _ _) 22 | (fun _ _ => @right_identity _ _ _) 23 | (fun _ _ => @left_identity _ _ _) 24 | (@identity_identity C) 25 | _. 26 | 27 | Local Notation "C ^op" := (opposite C) : category_scope. 28 | 29 | (** ** [ᵒᵖ] is judgmentally involutive *) 30 | Definition opposite_involutive C : (C^op)^op = C := idpath. 31 | 32 | (** ** Initial objects are opposite terminal objects, and vice versa *) 33 | Section DualObjects. 34 | Variable C : PreCategory. 35 | 36 | Definition terminal_opposite_initial (x : C) 37 | `(H : IsTerminalObject C x) 38 | : IsInitialObject (C^op) x 39 | := fun x' => H x'. 40 | 41 | Definition initial_opposite_terminal (x : C) 42 | `(H : IsInitialObject C x) 43 | : IsTerminalObject (C^op) x 44 | := fun x' => H x'. 45 | End DualObjects. 46 | 47 | Module Export CategoryDualNotations. 48 | Notation "C ^op" := (opposite C) : category_scope. 49 | End CategoryDualNotations. 50 | -------------------------------------------------------------------------------- /theories/Categories/Category/Notations.v: -------------------------------------------------------------------------------- 1 | (** * Notations for categories *) 2 | Require Category.Core. 3 | Require Category.Dual. 4 | Require Category.Morphisms. 5 | Require Category.Pi. 6 | Require Category.Prod. 7 | Require Category.Sum. 8 | Require Category.Sigma. 9 | 10 | Include Category.Core.CategoryCoreNotations. 11 | Include Category.Dual.CategoryDualNotations. 12 | Include Category.Morphisms.CategoryMorphismsNotations. 13 | Include Category.Pi.CategoryPiNotations. 14 | Include Category.Prod.CategoryProdNotations. 15 | Include Category.Sum.CategorySumNotations. 16 | Include Category.Sigma.CategorySigmaNotations. 17 | -------------------------------------------------------------------------------- /theories/Categories/Category/Pi.v: -------------------------------------------------------------------------------- 1 | (** * Dependent Product Category *) 2 | Require Import Category.Strict. 3 | Require Import Basics.Trunc. 4 | 5 | Set Universe Polymorphism. 6 | Set Implicit Arguments. 7 | Generalizable All Variables. 8 | Set Asymmetric Patterns. 9 | 10 | Local Open Scope category_scope. 11 | Local Open Scope morphism_scope. 12 | 13 | (** ** Definition of [∀], or [∏], for categories *) 14 | Section pi. 15 | Context `{Funext}. 16 | Variable A : Type. 17 | Variable P : A -> PreCategory. 18 | 19 | Definition pi : PreCategory. 20 | refine (@Build_PreCategory 21 | (forall a : A, P a) 22 | (fun s d => forall a : A, morphism (P a) (s a) (d a)) 23 | (fun x => fun a => identity (x a)) 24 | (fun s d d' m2 m1 => fun a => m2 a o m1 a) 25 | _ 26 | _ 27 | _ 28 | _); 29 | abstract ( 30 | repeat (intro || apply path_forall); 31 | auto with morphism 32 | ). 33 | Defined. 34 | End pi. 35 | 36 | Local Notation "'forall' x .. y , P" := (forall x, .. (forall y, P) ..) : type_scope. 37 | Local Notation "'forall' x .. y , P" := (pi (fun x => .. (pi (fun y => P)) .. )) : category_scope. 38 | 39 | (** ** The product of strict categories is strict *) 40 | Instance isstrict_category_pi 41 | `{Funext} 42 | `{forall a : A, IsStrictCategory (P a)} 43 | : IsStrictCategory (forall a, P a). 44 | Proof. 45 | typeclasses eauto. 46 | Qed. 47 | 48 | Local Set Warnings "-notation-overridden". 49 | Module Export CategoryPiNotations. 50 | Notation "'forall' x .. y , P" := (forall x, .. (forall y, P) ..)%type : type_scope. 51 | Notation "'forall' x .. y , P" := (pi (fun x => .. (pi (fun y => P)) .. )) : category_scope. 52 | End CategoryPiNotations. 53 | -------------------------------------------------------------------------------- /theories/Categories/Category/Prod.v: -------------------------------------------------------------------------------- 1 | (** * Product Category *) 2 | Require Import Basics.Tactics. 3 | Require Import Category.Strict. 4 | Require Import Types.Prod. 5 | 6 | Set Universe Polymorphism. 7 | Set Implicit Arguments. 8 | Generalizable All Variables. 9 | Set Asymmetric Patterns. 10 | 11 | Local Open Scope category_scope. 12 | Local Open Scope morphism_scope. 13 | 14 | (** ** Definition of [*] for categories *) 15 | Section prod. 16 | Variables C D : PreCategory. 17 | 18 | Definition prod : PreCategory. 19 | refine (@Build_PreCategory 20 | (C * D) 21 | (fun s d => morphism C (fst s) (fst d) 22 | * morphism D (snd s) (snd d)) 23 | (fun x => (identity (fst x), identity (snd x))) 24 | (fun s d d' m2 m1 => (fst m2 o fst m1, snd m2 o snd m1)) 25 | _ 26 | _ 27 | _ 28 | _); 29 | abstract ( 30 | repeat (simpl || intros [] || intro); 31 | try f_ap; auto with morphism 32 | ). 33 | Defined. 34 | End prod. 35 | 36 | Local Infix "*" := prod : category_scope. 37 | 38 | (** ** The product of strict categories is strict *) 39 | Instance isstrict_category_product 40 | `{IsStrictCategory C, IsStrictCategory D} 41 | : IsStrictCategory (C * D). 42 | Proof. 43 | typeclasses eauto. 44 | Qed. 45 | 46 | Module Export CategoryProdNotations. 47 | Infix "*" := prod : category_scope. 48 | End CategoryProdNotations. 49 | -------------------------------------------------------------------------------- /theories/Categories/Category/Sigma.v: -------------------------------------------------------------------------------- 1 | (** * ∑-precategories *) 2 | (** These are a generalization of subcategories in the direction of the Grothendieck construction *) 3 | Require Category.Sigma.Core. 4 | Require Category.Sigma.OnMorphisms. 5 | Require Category.Sigma.OnObjects. 6 | Require Category.Sigma.Univalent. 7 | 8 | Include Category.Sigma.Core. 9 | Include Category.Sigma.OnMorphisms. 10 | Include Category.Sigma.OnObjects. 11 | Include Category.Sigma.Univalent. 12 | 13 | Module CategorySigmaNotations. 14 | Include Category.Sigma.OnObjects.CategorySigmaOnObjectsNotations. 15 | End CategorySigmaNotations. 16 | -------------------------------------------------------------------------------- /theories/Categories/Category/Strict.v: -------------------------------------------------------------------------------- 1 | (** * Definition of a strict category *) 2 | Require Export Category.Core. 3 | 4 | Set Universe Polymorphism. 5 | Set Implicit Arguments. 6 | Generalizable All Variables. 7 | Set Asymmetric Patterns. 8 | 9 | Local Open Scope morphism_scope. 10 | 11 | (** Quoting the HoTT Book: *) 12 | (** Definition. A _strict category_ is a precategory whose type of 13 | objects is a set. *) 14 | 15 | Notation IsStrictCategory C := (IsHSet (object C)). 16 | 17 | Record StrictCategory := 18 | { 19 | precategory_strict :> PreCategory; 20 | isstrict_StrictCategory :> IsStrictCategory precategory_strict 21 | }. 22 | 23 | Existing Instance isstrict_StrictCategory. 24 | -------------------------------------------------------------------------------- /theories/Categories/Category/Subcategory.v: -------------------------------------------------------------------------------- 1 | (** * Subcategories *) 2 | (** ** Full *) 3 | Require Subcategory.Full. 4 | (** ** Wide *) 5 | Require Subcategory.Wide. 6 | 7 | Include Subcategory.Full. 8 | Include Subcategory.Wide. 9 | -------------------------------------------------------------------------------- /theories/Categories/Category/Subcategory/Full.v: -------------------------------------------------------------------------------- 1 | (** * Full Subcategories *) 2 | (** We reuse the generalization given by ∑-precategories; a full subcategory has a sigma type as its objects. *) 3 | Require Import Category.Sigma.OnObjects. 4 | 5 | Notation full := sig_obj. 6 | 7 | Notation "{ x : A | P }" := (full A (fun x => P)) : category_scope. 8 | -------------------------------------------------------------------------------- /theories/Categories/Category/Subcategory/Wide.v: -------------------------------------------------------------------------------- 1 | (** * Wide subcategories *) 2 | (** We reuse ∑-precategories; a wide subcategory has the same objects, and a ∑ type as its morphisms. We make use of the fact that the extra component should be an hProp to not require as many proofs. *) 3 | Require Import Category.Sigma.OnMorphisms. 4 | 5 | Notation wide := sig_mor. 6 | -------------------------------------------------------------------------------- /theories/Categories/Category/Sum.v: -------------------------------------------------------------------------------- 1 | (** * The coproduct of categories *) 2 | Require Export Category.Core. 3 | 4 | Set Universe Polymorphism. 5 | Set Implicit Arguments. 6 | Generalizable All Variables. 7 | Set Asymmetric Patterns. 8 | 9 | (** ** Definition of [+] for categories *) 10 | Section internals. 11 | Variables C D : PreCategory. 12 | 13 | Definition sum_morphism (s d : C + D) : Type 14 | := match s, d with 15 | | inl s, inl d => morphism C s d 16 | | inr s, inr d => morphism D s d 17 | | _, _ => Empty 18 | end. 19 | 20 | Global Arguments sum_morphism _ _ / . 21 | 22 | Definition sum_identity (x : C + D) : sum_morphism x x 23 | := match x with 24 | | inl x => identity x 25 | | inr x => identity x 26 | end. 27 | 28 | Global Arguments sum_identity _ / . 29 | 30 | Definition sum_compose (s d d' : C + D) 31 | (m1 : sum_morphism d d') (m2 : sum_morphism s d) 32 | : sum_morphism s d'. 33 | Proof. 34 | case s, d, d'; simpl in *; 35 | solve [ case m1 36 | | case m2 37 | | eapply compose; eassumption ]. 38 | Defined. 39 | 40 | Global Arguments sum_compose [_ _ _] _ _ / . 41 | End internals. 42 | 43 | Definition sum (C D : PreCategory) : PreCategory. 44 | Proof. 45 | refine (@Build_PreCategory 46 | (C + D) 47 | (sum_morphism C D) 48 | (sum_identity C D) 49 | (sum_compose C D) 50 | _ 51 | _ 52 | _ 53 | _); 54 | abstract ( 55 | repeat (simpl || apply istrunc_S || intros [] || intro); 56 | auto with morphism; 57 | typeclasses eauto 58 | ). 59 | Defined. 60 | 61 | Module Export CategorySumNotations. 62 | Infix "+" := sum : category_scope. 63 | End CategorySumNotations. 64 | -------------------------------------------------------------------------------- /theories/Categories/Category/Univalent.v: -------------------------------------------------------------------------------- 1 | (** * Definition of a univalent/saturated precategory, or just "category" *) 2 | Require Import Category.Core Category.Morphisms. 3 | Require Import HoTT.Basics HoTT.Tactics. 4 | 5 | Set Universe Polymorphism. 6 | Set Implicit Arguments. 7 | Generalizable All Variables. 8 | Set Asymmetric Patterns. 9 | 10 | Local Open Scope morphism_scope. 11 | 12 | (** A category is a precategory for which [idtoiso] is an equivalence. *) 13 | 14 | Notation IsCategory C := (forall s d : object C, IsEquiv (@idtoiso C s d)). 15 | 16 | Notation isotoid C s d := (@equiv_inv _ _ (@idtoiso C s d) _). 17 | 18 | (** *** The objects of a category are a 1-type *) 19 | 20 | Instance trunc_category `{IsCategory C} : IsTrunc 1 C | 10000. 21 | Proof. 22 | apply istrunc_S. 23 | intros ? ?. 24 | eapply istrunc_equiv_istrunc; 25 | [ symmetry; 26 | esplit; 27 | apply_hyp 28 | | ]. 29 | typeclasses eauto. 30 | Qed. 31 | 32 | Record Category := 33 | { 34 | precategory_of_category :> PreCategory; 35 | iscategory_precategory_of_category :> IsCategory precategory_of_category 36 | }. 37 | 38 | Existing Instance iscategory_precategory_of_category. 39 | -------------------------------------------------------------------------------- /theories/Categories/Category/Utf8.v: -------------------------------------------------------------------------------- 1 | (** * Unicode notations for categories *) 2 | Require Import Category.Morphisms Category.Dual Category.Sum Category.Pi. 3 | Local Set Warnings "-notation-overridden". 4 | Require Export Category.Notations. 5 | Local Set Warnings "notation-overridden". 6 | Require Import Basics.Utf8. 7 | 8 | Infix "∘" := compose : morphism_scope. 9 | Notation "m ⁻¹" := (morphism_inverse m) : morphism_scope. 10 | Infix "≅" := Isomorphic : category_scope. 11 | Notation "x ↠ y" := (Epimorphism x y). 12 | Notation "x ↪ y" := (Monomorphism x y). 13 | 14 | (** It would be nice to put [, format "C 'ᵒᵖ'"] here, but that makes 15 | this notation unparseable. *) 16 | Notation "C 'ᵒᵖ'" := (opposite C) : category_scope. 17 | 18 | Notation "∀ x .. y , P" := (forall x, .. (forall y, P) ..). 19 | Notation "∀ x .. y , P" := (forall x, .. (forall y, P) ..) : type_scope. 20 | Notation "∀ x .. y , P" := (pi (fun x => .. (pi (fun y => P)) .. )) : category_scope. 21 | -------------------------------------------------------------------------------- /theories/Categories/CategoryOfGroupoids.v: -------------------------------------------------------------------------------- 1 | (** * Groupoid, the precategory of strict groupoid categories *) 2 | Require Import Functor.Core Category.Strict. 3 | Require Import Cat.Core. 4 | Require Import GroupoidCategory.Core. 5 | Require Import Functor.Paths. 6 | 7 | Set Universe Polymorphism. 8 | Set Implicit Arguments. 9 | Generalizable All Variables. 10 | Set Asymmetric Patterns. 11 | 12 | Local Open Scope functor_scope. 13 | 14 | Section groupoid_cat. 15 | Context `{Funext}. 16 | 17 | Let P : PreCategory -> Type 18 | := fun C => IsGroupoid C /\ IsStrictCategory C. 19 | Let HF : forall C D, P C -> P D -> IsHSet (Functor C D) 20 | := fun C D HC HD => @trunc_functor _ C D _ (snd HD) _. 21 | 22 | (** There is a full precategory of [cat] which is the strict groupoid precategories *) 23 | 24 | Definition groupoid_cat : PreCategory 25 | := @sub_pre_cat _ P HF. 26 | End groupoid_cat. 27 | -------------------------------------------------------------------------------- /theories/Categories/CategoryOfSections.v: -------------------------------------------------------------------------------- 1 | (** * Category of sections of a functor *) 2 | Require CategoryOfSections.Core. 3 | 4 | Include CategoryOfSections.Core. 5 | -------------------------------------------------------------------------------- /theories/Categories/Comma.v: -------------------------------------------------------------------------------- 1 | (** * Comma Categories *) 2 | (** Since there are only notations in [Comma.Notations], we can just export those. *) 3 | Local Set Warnings "-notation-overridden". 4 | Require Import Basics.Notations. 5 | Require Export Comma.Notations. 6 | 7 | (** ** Definitions *) 8 | Require Comma.Core. 9 | (** ** Duals *) 10 | Require Comma.Dual. 11 | (** ** Projection functors *) 12 | Require Comma.Projection. 13 | Require Comma.InducedFunctors. 14 | (** ** Functoriality *) 15 | Require Comma.ProjectionFunctors. 16 | Require Comma.Functorial. 17 | 18 | Include Comma.Core. 19 | Include Comma.Dual. 20 | Include Comma.Projection. 21 | Include Comma.InducedFunctors. 22 | Include Comma.ProjectionFunctors. 23 | Include Comma.Functorial. 24 | (** We don't want to make UTF-8 notations the default, so we don't export them. *) 25 | -------------------------------------------------------------------------------- /theories/Categories/Comma/Dual.v: -------------------------------------------------------------------------------- 1 | (** * Opposite comma categories *) 2 | Require Import Category.Core Functor.Core. 3 | Require Import Category.Dual Functor.Dual. 4 | Require Import Functor.Composition.Core Functor.Identity. 5 | Require Comma.Core. 6 | Local Set Warnings "-notation-overridden". (* work around bug #5567, https://coq.inria.fr/bugs/show_bug.cgi?id=5567, notation-overridden,parsing should not trigger for only printing notations *) 7 | Import Comma.Core. 8 | Local Set Warnings "notation-overridden". 9 | 10 | Set Universe Polymorphism. 11 | Set Implicit Arguments. 12 | Generalizable All Variables. 13 | Set Asymmetric Patterns. 14 | 15 | Local Open Scope path_scope. 16 | Local Open Scope morphism_scope. 17 | Local Open Scope category_scope. 18 | Local Open Scope functor_scope. 19 | 20 | (** ** The dual functors [(S / T) ↔ ((Tᵒᵖ / Sᵒᵖ)ᵒᵖ)] *) 21 | Section opposite. 22 | Section op. 23 | Variables A B C : PreCategory. 24 | 25 | Variable S : Functor A C. 26 | Variable T : Functor B C. 27 | 28 | Local Notation obj_of x 29 | := (CommaCategory.Build_object (T^op) (S^op) _ _ (CommaCategory.f x) 30 | : object ((T^op / S^op)^op)). 31 | 32 | Local Notation mor_of s d m 33 | := (CommaCategory.Build_morphism' 34 | (obj_of d) (obj_of s) 35 | (CommaCategory.h m%morphism) 36 | (CommaCategory.g m%morphism) 37 | (CommaCategory.p_sym m%morphism) 38 | (CommaCategory.p m%morphism) 39 | : morphism ((T^op / S^op)^op) (obj_of s) (obj_of d)). 40 | 41 | Definition dual_functor : Functor (S / T) ((T^op / S^op)^op) 42 | := Build_Functor 43 | (S / T) ((T^op / S^op)^op) 44 | (fun x => obj_of x) 45 | (fun s d m => mor_of s d m) 46 | (fun _ _ _ _ _ => 1%path) 47 | (fun _ => 1%path). 48 | End op. 49 | 50 | Definition dual_functor_involutive A B C (S : Functor A C) (T : Functor B C) 51 | : dual_functor S T o (dual_functor T^op S^op)^op = 1 52 | /\ (dual_functor T^op S^op)^op o dual_functor S T = 1 53 | := (idpath, idpath)%core. 54 | End opposite. 55 | -------------------------------------------------------------------------------- /theories/Categories/Comma/Notations.v: -------------------------------------------------------------------------------- 1 | (** * Notations for comma categories *) 2 | Require Import Basics.Notations. 3 | Require Comma.Core. 4 | 5 | Local Set Warnings "-notation-overridden". (* work around bug #5567, https://coq.inria.fr/bugs/show_bug.cgi?id=5567, notation-overridden,parsing should not trigger for only printing notations *) 6 | Include Comma.Core.CommaCoreNotations. 7 | -------------------------------------------------------------------------------- /theories/Categories/Comma/Utf8.v: -------------------------------------------------------------------------------- 1 | (** * Unicode notations for comma categories *) 2 | Local Set Warnings "-notation-overridden". 3 | Require Import Basics.Notations. 4 | Require Import Comma.Core. 5 | Require Export Comma.Notations. 6 | Require Import Basics.Utf8. 7 | 8 | (** Set some notations for printing *) 9 | Notation "C ↓ a" := (@slice_category_over C a) (only printing) : category_scope. 10 | Notation "a ↓ C" := (@coslice_category_over C a) (only printing) : category_scope. 11 | Notation "x ↓ F" := (coslice_category x F) (only printing) : category_scope. 12 | Notation "F ↓ x" := (slice_category x F) (only printing) : category_scope. 13 | Notation "S ↓ T" := (comma_category S T) (only printing) : category_scope. 14 | (** Set the notation for parsing; coercions will automatically decide which of the arguments are functors and which are objects, i.e., functors from the terminal category. *) 15 | Notation "S ↓ T" := (comma_category (S : CC_Functor' _ _) 16 | (T : CC_Functor' _ _)) : category_scope. 17 | (*Set Printing All. 18 | Check (fun (C : PreCategory)(D : PreCategory)(E : PreCategory)(S : Functor C D) (T : Functor E D) => (S ↓ T)%category). 19 | Check (fun (D : PreCategory)(E : PreCategory)(S : Functor E D) (x : D) => (x ↓ S)%category). 20 | Check (fun (D : PreCategory)(E : PreCategory)(S : Functor E D) (x : D) => (S ↓ x)%category).*) 21 | -------------------------------------------------------------------------------- /theories/Categories/DependentProduct.v: -------------------------------------------------------------------------------- 1 | (** * Dependent Product; oplax limit of a functor to Cat *) 2 | Require Import Category.Core Functor.Core. 3 | Require Import Cat.Core. 4 | Require Grothendieck.ToCat. 5 | Require Import CategoryOfSections.Core. 6 | 7 | Set Universe Polymorphism. 8 | Set Implicit Arguments. 9 | Generalizable All Variables. 10 | Set Asymmetric Patterns. 11 | 12 | Local Open Scope functor_scope. 13 | 14 | Section dependent_product. 15 | Context `{Funext}. 16 | Variable C : PreCategory. 17 | Variable P : PreCategory -> Type. 18 | (*Context `{forall C, IsHProp (P C)}.*) 19 | Context `{HF : forall C D, P C -> P D -> IsHSet (Functor C D)}. 20 | 21 | Local Notation cat := (@sub_pre_cat _ P HF). 22 | 23 | Variable F : Functor C cat. 24 | 25 | (** Quoting http://mathoverflow.net/questions/137689/explicit-description-of-the-oplax-limit-of-a-functor-to-cat: 26 | 27 | The oplax limit is the category of sections for the functor from 28 | the Grothendieck construction to the base category. 29 | 30 | The strong limit is the category of cartesian sections 31 | (every arrow in the base category gets mapped to a cartesian 32 | one). 33 | 34 | Notice how this goes along very well with the interpretation as 35 | dependent product and as ∀: The set theoretic product is just 36 | the set of sections into the disjoint union. 37 | 38 | Given a strong functor [F : X → Cat] we denote the Grothendieck 39 | construction by [Gr F]. 40 | 41 | There is a canonical functor [π : Gr F → X]. Sections of this 42 | functor are functors [s : X → Gr F] such that [s ∘ π = id]. *) 43 | 44 | Definition dependent_product : PreCategory 45 | := category_of_sections (Grothendieck.ToCat.pr1 F). 46 | End dependent_product. 47 | 48 | Notation Pi := dependent_product. 49 | -------------------------------------------------------------------------------- /theories/Categories/DiscreteCategory.v: -------------------------------------------------------------------------------- 1 | (** * Discrete category *) 2 | Require Import HoTT.Basics GroupoidCategory.Core. 3 | 4 | Set Universe Polymorphism. 5 | Set Implicit Arguments. 6 | Generalizable All Variables. 7 | Set Asymmetric Patterns. 8 | 9 | (** A discrete category is a groupoid which is a 0-type *) 10 | Module Export Core. 11 | Definition discrete_category X `{IsHSet X} := groupoid_category X. 12 | 13 | Arguments discrete_category X {_} / . 14 | End Core. 15 | -------------------------------------------------------------------------------- /theories/Categories/ExponentialLaws.v: -------------------------------------------------------------------------------- 1 | (** * Exponential Laws *) 2 | (** We want to have the following as subdirectories/modules, not at top level. Unfortunately, namespacing in Coq is kind-of broken (see, e.g., https://coq.inria.fr/bugs/show_bug.cgi?id=3676), so we don't get the ability to rename subfolders by [Including] into other modules. *) 3 | (** ** Laws about the initial category *) 4 | (** *** [x⁰ ≅ 1] *) 5 | (** *** [0ˣ ≅ 0] if [x ≠ 0] *) 6 | Require ExponentialLaws.Law0. 7 | 8 | (** ** Laws about the terminal category *) 9 | (** *** [x¹ ≅ x] *) 10 | (** *** [1ˣ ≅ 1] *) 11 | Require ExponentialLaws.Law1. 12 | 13 | (** ** The law that a sum in an exponent is a product *) 14 | (** *** [yⁿ⁺ᵐ ≅ yⁿ × yᵐ] *) 15 | Require ExponentialLaws.Law2. 16 | 17 | (** ** The law that exponentiation distributes over product *) 18 | (** *** [(y × z)ⁿ ≅ yⁿ × zⁿ] *) 19 | Require ExponentialLaws.Law3. 20 | 21 | (** ** Currying *) 22 | (** *** [(yⁿ)ᵐ ≅ yⁿᵐ] *) 23 | Require ExponentialLaws.Law4. 24 | 25 | 26 | Require ExponentialLaws.Tactics. 27 | Include ExponentialLaws.Tactics. 28 | -------------------------------------------------------------------------------- /theories/Categories/ExponentialLaws/Law1.v: -------------------------------------------------------------------------------- 1 | (** * Laws about the terminal category *) 2 | (** ** [x¹ ≅ x] *) 3 | (** ** [1ˣ ≅ 1] *) 4 | Require ExponentialLaws.Law1.Functors. 5 | Require ExponentialLaws.Law1.Law. 6 | 7 | Include ExponentialLaws.Law1.Functors. 8 | Include ExponentialLaws.Law1.Law. 9 | -------------------------------------------------------------------------------- /theories/Categories/ExponentialLaws/Law1/Law.v: -------------------------------------------------------------------------------- 1 | (** * Exponential laws about the terminal category *) 2 | Require Import Category.Core Functor.Core Functor.Identity Functor.Paths ExponentialLaws.Law1.Functors Functor.Composition.Core. 3 | Require Import InitialTerminalCategory.Core. 4 | Require Import Basics.Trunc ExponentialLaws.Tactics. 5 | Require Import Basics.Tactics. 6 | 7 | Set Universe Polymorphism. 8 | Set Implicit Arguments. 9 | Generalizable All Variables. 10 | Set Asymmetric Patterns. 11 | 12 | Local Open Scope functor_scope. 13 | 14 | (** ** [C¹ ≅ C] *) 15 | Section law1. 16 | Context `{Funext}. 17 | Context `{IsInitialCategory zero}. 18 | Context `{IsTerminalCategory one}. 19 | Local Notation "0" := zero : category_scope. 20 | Local Notation "1" := one : category_scope. 21 | 22 | Variable C : PreCategory. 23 | 24 | Definition helper (c : Functor 1 C) 25 | : Functors.from_terminal C (c (center _)) = c. 26 | Proof. 27 | path_functor. 28 | exists (path_forall _ _ (fun x => ap (object_of c) (contr _))). 29 | abstract ( 30 | exp_laws_t; 31 | simpl; 32 | rewrite <- identity_of; 33 | f_ap; 34 | symmetry; 35 | apply contr 36 | ). 37 | Defined. 38 | 39 | Lemma law 40 | : @functor _ one _ C o inverse C = 1 41 | /\ inverse C o @functor _ one _ C = 1. 42 | Proof. 43 | split; 44 | path_functor. 45 | exists (path_forall _ _ helper). 46 | unfold helper. 47 | exp_laws_t. 48 | Qed. 49 | End law1. 50 | -------------------------------------------------------------------------------- /theories/Categories/ExponentialLaws/Law2.v: -------------------------------------------------------------------------------- 1 | (** * The law that a sum in an exponent is a product *) 2 | (** ** [yⁿ⁺ᵐ ≅ yⁿ × yᵐ] *) 3 | Require ExponentialLaws.Law2.Functors. 4 | Require ExponentialLaws.Law2.Law. 5 | 6 | Include ExponentialLaws.Law2.Functors. 7 | Include ExponentialLaws.Law2.Law. 8 | -------------------------------------------------------------------------------- /theories/Categories/ExponentialLaws/Law2/Functors.v: -------------------------------------------------------------------------------- 1 | (** * Exponential functors between products and sums in exponents *) 2 | Require Import Functor.Core FunctorCategory.Core Functor.Identity NaturalTransformation.Core Category.Sum Category.Prod Functor.Sum Functor.Prod.Core NaturalTransformation.Sum Functor.Pointwise.Core NaturalTransformation.Paths. 3 | 4 | Set Universe Polymorphism. 5 | Set Implicit Arguments. 6 | Generalizable All Variables. 7 | Set Asymmetric Patterns. 8 | 9 | Local Open Scope functor_scope. 10 | 11 | Local Notation fst_type := Basics.Overture.fst. 12 | Local Notation snd_type := Basics.Overture.snd. 13 | Local Notation pair_type := Basics.Overture.pair. 14 | 15 | Section law2. 16 | Context `{Funext}. 17 | Variables D C1 C2 : PreCategory. 18 | 19 | (** ** [yⁿ⁺ᵐ → yⁿ × yᵐ] *) 20 | Definition functor 21 | : Functor (C1 + C2 -> D) ((C1 -> D) * (C2 -> D)) 22 | := pointwise (inl C1 C2) 1 23 | * pointwise (inr C1 C2) 1. 24 | 25 | (** ** [yⁿ × yᵐ → yⁿ⁺ᵐ] *) 26 | Definition inverse 27 | : Functor ((C1 -> D) * (C2 -> D)) (C1 + C2 -> D). 28 | Proof. 29 | refine (Build_Functor 30 | ((C1 -> D) * (C2 -> D)) (C1 + C2 -> D) 31 | (fun FG => fst FG + snd FG)%functor 32 | (fun _ _ m => fst_type m + snd_type m)%natural_transformation 33 | _ 34 | _); 35 | simpl in *; 36 | abstract ( 37 | repeat (intros [?|?] || intros [? ?]); 38 | simpl in *; 39 | apply path_natural_transformation; intros [?|?]; 40 | reflexivity 41 | ). 42 | Defined. 43 | End law2. 44 | -------------------------------------------------------------------------------- /theories/Categories/ExponentialLaws/Law2/Law.v: -------------------------------------------------------------------------------- 1 | (** * Exponential laws about products and sums in exponents *) 2 | Require Import Functor.Core. 3 | Require Import Category.Sum Functor.Sum. 4 | Require Import Functor.Paths. 5 | Require Import Functor.Identity Functor.Composition.Core. 6 | Require Import Types.Prod ExponentialLaws.Tactics. 7 | Require Import ExponentialLaws.Law2.Functors. 8 | 9 | Set Universe Polymorphism. 10 | Set Implicit Arguments. 11 | Generalizable All Variables. 12 | Set Asymmetric Patterns. 13 | 14 | Local Open Scope functor_scope. 15 | 16 | (** ** [yⁿ⁺ᵐ ≅ yⁿ × yᵐ] *) 17 | Section Law2. 18 | Context `{Funext}. 19 | Variables D C1 C2 : PreCategory. 20 | 21 | 22 | 23 | Lemma helper1 (c : Functor C1 D * Functor C2 D) 24 | : ((1 o (Basics.Overture.fst c + Basics.Overture.snd c) o inl C1 C2)%functor, 25 | (1 o (Basics.Overture.fst c + Basics.Overture.snd c) o inr C1 C2)%functor)%core = c. 26 | Proof. 27 | apply path_prod; simpl; 28 | path_functor. 29 | Defined. 30 | 31 | Lemma helper2_helper (c : Functor (C1 + C2) D) x 32 | : (1 o c o inl C1 C2 + 1 o c o inr C1 C2) x = c x. 33 | Proof. 34 | destruct x; reflexivity. 35 | Defined. 36 | 37 | Lemma helper2 (c : Functor (C1 + C2) D) 38 | : 1 o c o inl C1 C2 + 1 o c o inr C1 C2 = c. 39 | Proof. 40 | path_functor. 41 | (exists (path_forall _ _ (@helper2_helper c))). 42 | abstract exp_laws_t. 43 | Defined. 44 | 45 | Lemma law 46 | : functor D C1 C2 o inverse D C1 C2 = 1 47 | /\ inverse D C1 C2 o functor D C1 C2 = 1. 48 | Proof. 49 | split; 50 | path_functor; 51 | [ (exists (path_forall _ _ helper1)) 52 | | (exists (path_forall _ _ helper2)) ]; 53 | exp_laws_t; 54 | unfold helper1, helper2; 55 | exp_laws_t. 56 | Qed. 57 | End Law2. 58 | -------------------------------------------------------------------------------- /theories/Categories/ExponentialLaws/Law3.v: -------------------------------------------------------------------------------- 1 | (** * The law that exponentiation distributes over product *) 2 | (** ** [(y × z)ⁿ ≅ yⁿ × zⁿ] *) 3 | Require ExponentialLaws.Law3.Functors. 4 | Require ExponentialLaws.Law3.Law. 5 | 6 | Include ExponentialLaws.Law3.Functors. 7 | Include ExponentialLaws.Law3.Law. 8 | -------------------------------------------------------------------------------- /theories/Categories/ExponentialLaws/Law3/Functors.v: -------------------------------------------------------------------------------- 1 | (** * Functors between an exponential of a product and a product of exponentials *) 2 | Require Import Category.Core Functor.Core FunctorCategory.Core Category.Prod. 3 | Require Import Functor.Prod Functor.Composition.Core NaturalTransformation.Composition.Laws NaturalTransformation.Composition.Core. 4 | Require Import Types.Prod. 5 | 6 | Set Universe Polymorphism. 7 | Set Implicit Arguments. 8 | Generalizable All Variables. 9 | Set Asymmetric Patterns. 10 | 11 | Local Open Scope natural_transformation_scope. 12 | Local Open Scope functor_scope. 13 | 14 | Local Notation fst_type := Basics.Overture.fst. 15 | Local Notation snd_type := Basics.Overture.snd. 16 | Local Notation pair_type := Basics.Overture.pair. 17 | 18 | Section law3. 19 | Context `{Funext}. 20 | Variables C1 C2 D : PreCategory. 21 | 22 | (** ** [(y × z)ⁿ → yⁿ × zⁿ] *) 23 | Definition functor 24 | : Functor (D -> C1 * C2) ((D -> C1) * (D -> C2)) 25 | := Build_Functor 26 | (D -> C1 * C2) ((D -> C1) * (D -> C2)) 27 | (fun H => (fst o H, snd o H)%core) 28 | (fun s d m => (fst oL m, snd oL m)%core) 29 | (fun _ _ _ _ _ => path_prod' (composition_of_whisker_l _ _ _) 30 | (composition_of_whisker_l _ _ _)) 31 | (fun _ => path_prod' (whisker_l_right_identity _ _) 32 | (whisker_l_right_identity _ _)). 33 | 34 | (** ** [yⁿ × zⁿ → (y × z)ⁿ] *) 35 | (** If we had [Require Functor.Functor.], we could just say [Functor.Prod.functor] here. *) 36 | Definition inverse 37 | : Functor ((D -> C1) * (D -> C2)) (D -> C1 * C2) 38 | := Functor.Prod.Functorial.functor _ _ _. 39 | End law3. 40 | -------------------------------------------------------------------------------- /theories/Categories/ExponentialLaws/Law3/Law.v: -------------------------------------------------------------------------------- 1 | (** * Laws about an exponential of a product and a product of exponentials *) 2 | Require Import Category.Core Functor.Core. 3 | Require Import Functor.Prod. 4 | Require Import Functor.Paths. 5 | Require Import Functor.Identity Functor.Composition.Core. 6 | Require Import ExponentialLaws.Law3.Functors. 7 | Require Import Types.Prod ExponentialLaws.Tactics. 8 | 9 | Set Universe Polymorphism. 10 | Set Implicit Arguments. 11 | Generalizable All Variables. 12 | Set Asymmetric Patterns. 13 | 14 | Local Open Scope functor_scope. 15 | 16 | (** ** [(y × z)ⁿ ≅ yⁿ × zⁿ] *) 17 | Section Law3. 18 | Context `{Funext}. 19 | Variables C1 C2 D : PreCategory. 20 | 21 | Lemma helper (c : Functor D C1 * Functor D C2) 22 | : ((fst o (Basics.Overture.fst c * Basics.Overture.snd c))%functor, 23 | (snd o (Basics.Overture.fst c * Basics.Overture.snd c))%functor)%core = c. 24 | Proof. 25 | apply path_prod; 26 | [ apply compose_fst_prod 27 | | apply compose_snd_prod ]. 28 | Defined. 29 | 30 | Lemma Law 31 | : functor C1 C2 D o inverse C1 C2 D = 1 32 | /\ inverse C1 C2 D o functor C1 C2 D = 1. 33 | Proof. 34 | split; path_functor; 35 | [ (exists (path_forall _ _ helper)) 36 | | (exists (path_forall _ _ (fun _ => Functor.Prod.Universal.unique idpath idpath))) ]; 37 | exp_laws_t; 38 | unfold helper, compose_fst_prod, compose_snd_prod, Functor.Prod.Universal.unique, Functor.Prod.Universal.unique_helper; 39 | exp_laws_t. 40 | Qed. 41 | End Law3. 42 | -------------------------------------------------------------------------------- /theories/Categories/ExponentialLaws/Law4.v: -------------------------------------------------------------------------------- 1 | (** * Currying *) 2 | (** ** [(yⁿ)ᵐ ≅ yⁿᵐ] *) 3 | Require ExponentialLaws.Law4.Functors. 4 | Require ExponentialLaws.Law4.Law. 5 | 6 | Include ExponentialLaws.Law4.Functors. 7 | Include ExponentialLaws.Law4.Law. 8 | -------------------------------------------------------------------------------- /theories/Categories/ExponentialLaws/Law4/Law.v: -------------------------------------------------------------------------------- 1 | (** * Law about currying *) 2 | Require Import Category.Core Functor.Core. 3 | Require Import Functor.Paths. 4 | Require Import Functor.Identity Functor.Composition.Core. 5 | Require Import ExponentialLaws.Law4.Functors. 6 | Require Import ExponentialLaws.Tactics. 7 | 8 | Set Universe Polymorphism. 9 | Set Implicit Arguments. 10 | Generalizable All Variables. 11 | Set Asymmetric Patterns. 12 | 13 | Local Open Scope functor_scope. 14 | 15 | (** ** [(C₁ × C₂ → D) ≅ (C₁ → (C₂ → D))] *) 16 | Section Law4. 17 | Context `{Funext}. 18 | Variables C1 C2 D : PreCategory. 19 | 20 | Lemma helper1 c 21 | : functor C1 C2 D (inverse C1 C2 D c) = c. 22 | Proof. 23 | path_functor. 24 | abstract ( 25 | exp_laws_t; 26 | rewrite <- composition_of; 27 | exp_laws_t 28 | ). 29 | Defined. 30 | 31 | Lemma helper2_helper c x 32 | : inverse C1 C2 D (functor C1 C2 D c) x = c x. 33 | Proof. 34 | path_functor. 35 | abstract exp_laws_t. 36 | Defined. 37 | 38 | Lemma helper2 c 39 | : inverse C1 C2 D (functor C1 C2 D c) = c. 40 | Proof. 41 | path_functor. 42 | exists (path_forall _ _ (helper2_helper c)). 43 | abstract (unfold helper2_helper; exp_laws_t). 44 | Defined. 45 | 46 | Lemma law 47 | : functor C1 C2 D o inverse C1 C2 D = 1 48 | /\ inverse C1 C2 D o functor C1 C2 D = 1. 49 | Proof. 50 | split; 51 | path_functor; 52 | [ (exists (path_forall _ _ helper1)) 53 | | (exists (path_forall _ _ helper2)) ]; 54 | unfold helper1, helper2, helper2_helper; 55 | exp_laws_t. 56 | Qed. 57 | End Law4. 58 | -------------------------------------------------------------------------------- /theories/Categories/Functor.v: -------------------------------------------------------------------------------- 1 | (** * Functors *) 2 | (** Since there are only notations in [Functor.Notations], we can just export those. *) 3 | Require Export Functor.Notations. 4 | 5 | (** ** Definition *) 6 | Require Functor.Core. 7 | (** ** Composition *) 8 | Require Functor.Composition.Core. 9 | (** ** Duals *) 10 | Require Functor.Dual. 11 | (** ** Identity *) 12 | Require Functor.Identity. 13 | (** ** Classification of path space *) 14 | Require Functor.Paths. 15 | (** ** Product functors *) 16 | Require Functor.Prod.Core. 17 | (** ** Coproduct functors *) 18 | Require Functor.Sum. 19 | (** ** Full, Faithful, Fully Faithful *) 20 | Require Functor.Attributes. 21 | (** ** Pointwise functors (functoriality of functor category construction) *) 22 | Require Functor.Pointwise.Core. 23 | 24 | Include Functor.Composition.Core. 25 | Include Functor.Core. 26 | Include Functor.Dual. 27 | Include Functor.Identity. 28 | Include Functor.Paths. 29 | Include Functor.Prod.Core. 30 | Include Functor.Sum. 31 | Include Functor.Attributes. 32 | Include Functor.Pointwise.Core. 33 | 34 | (** We want to have the following as subdirectories/modules, not at top level. Unfortunately, namespacing in Coq is kind-of broken (see, e.g., https://coq.inria.fr/bugs/show_bug.cgi?id=3676), so we don't get the ability to rename subfolders by [Including] into other modules. *) 35 | Require Functor.Pointwise. 36 | 37 | (** We don't want to make UTF-8 notations the default, so we don't export them. *) 38 | -------------------------------------------------------------------------------- /theories/Categories/Functor/Composition.v: -------------------------------------------------------------------------------- 1 | (** * Composition of functors *) 2 | (** ** Definition of composition *) 3 | Require Functor.Composition.Core. 4 | (** ** Functoriality of composition *) 5 | Require Functor.Composition.Functorial. 6 | (** ** Laws about functor composition *) 7 | Require Functor.Composition.Laws. 8 | 9 | Include Functor.Composition.Core. 10 | Include Functor.Composition.Functorial. 11 | Include Functor.Composition.Laws. 12 | 13 | Module Export FunctorCompositionNotations. 14 | Include Functor.Composition.Core.FunctorCompositionCoreNotations. 15 | End FunctorCompositionNotations. 16 | -------------------------------------------------------------------------------- /theories/Categories/Functor/Composition/Core.v: -------------------------------------------------------------------------------- 1 | (** * Composition of functors *) 2 | Require Import Category.Core Functor.Core. 3 | 4 | Set Universe Polymorphism. 5 | Set Implicit Arguments. 6 | Generalizable All Variables. 7 | Set Asymmetric Patterns. 8 | 9 | Local Open Scope morphism_scope. 10 | 11 | Section composition. 12 | Variables B C D E : PreCategory. 13 | Variable G : Functor D E. 14 | Variable F : Functor C D. 15 | 16 | (** We usually don't want to see the proofs of composition in functors, because the proofs are hProps, and so we don't care about them. But occasionally, we want to be able to reduce the proofs. Having the proofs transparent allows the composition of the identity functor with itself to be judgementally the identity. Since the only way to hide something from within a proof is [abstract], and that makes the definitions opaque, we need to define the laws separately. *) 17 | 18 | Local Notation c_object_of c := (G (F c)) (only parsing). 19 | Local Notation c_morphism_of m := (G _1 (F _1 m)) (only parsing). 20 | Definition compose_composition_of s d d' 21 | (m1 : morphism C s d) (m2 : morphism C d d') 22 | : c_morphism_of (m2 o m1) = c_morphism_of m2 o c_morphism_of m1 23 | := transport (@paths _ (c_morphism_of (m2 o m1))) 24 | (composition_of G _ _ _ _ _) 25 | (ap (fun m => G _1 m) (composition_of F _ _ _ m1 m2)). 26 | 27 | Definition compose_identity_of x 28 | : c_morphism_of (identity x) = identity (c_object_of x) 29 | := transport (@paths _ _) 30 | (identity_of G _) 31 | (ap (fun m => G _1 m) (identity_of F x)). 32 | 33 | Definition compose : Functor C E 34 | := Build_Functor 35 | C E 36 | (fun c => G (F c)) 37 | (fun _ _ m => G _1 (F _1 m)) 38 | compose_composition_of 39 | compose_identity_of. 40 | End composition. 41 | 42 | Global Arguments compose_composition_of / . 43 | Global Arguments compose_identity_of / . 44 | 45 | Module Export FunctorCompositionCoreNotations. 46 | Infix "o" := compose : functor_scope. 47 | End FunctorCompositionCoreNotations. 48 | -------------------------------------------------------------------------------- /theories/Categories/Functor/Composition/Functorial.v: -------------------------------------------------------------------------------- 1 | Require Functor.Composition.Functorial.Core. 2 | Require Functor.Composition.Functorial.Attributes. 3 | 4 | Include Functor.Composition.Functorial.Core. 5 | Include Functor.Composition.Functorial.Attributes. 6 | -------------------------------------------------------------------------------- /theories/Categories/Functor/Composition/Functorial/Core.v: -------------------------------------------------------------------------------- 1 | (** * Functoriality of functor composition *) 2 | Require Import Category.Core Functor.Core NaturalTransformation.Core. 3 | Require Import Functor.Composition.Core NaturalTransformation.Composition.Core. 4 | Require Import Category.Prod FunctorCategory.Core NaturalTransformation.Composition.Functorial NaturalTransformation.Composition.Laws ExponentialLaws.Law4.Functors. 5 | Require Import NaturalTransformation.Paths. 6 | Require ProductLaws. 7 | 8 | Set Universe Polymorphism. 9 | Set Implicit Arguments. 10 | Generalizable All Variables. 11 | Set Asymmetric Patterns. 12 | 13 | (** Construction of the functor [_∘_ : (C → D) × (D → E) → (C → E)] and its curried variant *) 14 | Section functorial_composition. 15 | Context `{Funext}. 16 | Variables C D E : PreCategory. 17 | 18 | Local Open Scope natural_transformation_scope. 19 | 20 | Definition compose_functor_morphism_of 21 | s d (m : morphism (C -> D) s d) 22 | : morphism ((D -> E) -> (C -> E)) 23 | (whiskerR_functor _ s) 24 | (whiskerR_functor _ d) 25 | := Build_NaturalTransformation 26 | (whiskerR_functor E s) 27 | (whiskerR_functor E d) 28 | (fun x => x oL m) 29 | (fun _ _ _ => exchange_whisker _ _). 30 | 31 | Definition compose_functor : object ((C -> D) -> ((D -> E) -> (C -> E))). 32 | Proof. 33 | refine (Build_Functor 34 | (C -> D) ((D -> E) -> (C -> E)) 35 | (@whiskerR_functor _ _ _ _) 36 | compose_functor_morphism_of 37 | _ 38 | _); 39 | abstract ( 40 | path_natural_transformation; 41 | rewrite ?composition_of, ?identity_of; 42 | reflexivity 43 | ). 44 | Defined. 45 | 46 | Definition compose_functor_uncurried 47 | : object ((C -> D) * (D -> E) -> (C -> E)) 48 | := ExponentialLaws.Law4.Functors.functor _ _ _ compose_functor. 49 | 50 | Definition compose_functor' : object ((D -> E) -> ((C -> D) -> (C -> E))) 51 | := ExponentialLaws.Law4.Functors.inverse 52 | _ _ _ (compose_functor_uncurried o ProductLaws.Swap.functor _ _)%functor. 53 | End functorial_composition. 54 | -------------------------------------------------------------------------------- /theories/Categories/Functor/Dual.v: -------------------------------------------------------------------------------- 1 | (** * Opposite functors *) 2 | Require Category.Dual. 3 | Import Category.Dual.CategoryDualNotations. 4 | Require Import Category.Core Functor.Core. 5 | 6 | Set Universe Polymorphism. 7 | Set Implicit Arguments. 8 | Generalizable All Variables. 9 | Set Asymmetric Patterns. 10 | 11 | Local Open Scope category_scope. 12 | 13 | (** ** Definition of [Fᵒᵖ] *) 14 | Definition opposite C D (F : Functor C D) : Functor C^op D^op 15 | := Build_Functor (C^op) (D^op) 16 | (object_of F) 17 | (fun s d (m : morphism C^op s d) => (F _1 m)%morphism) 18 | (fun d' d s m1 m2 => composition_of F s d d' m2 m1) 19 | (identity_of F). 20 | 21 | Local Notation "F ^op" := (opposite F) : functor_scope. 22 | 23 | Local Open Scope functor_scope. 24 | 25 | (** ** [ᵒᵖ] is judgmentally involutive *) 26 | Definition opposite_involutive C D (F : Functor C D) : (F^op)^op = F 27 | := idpath. 28 | 29 | Module Export FunctorDualNotations. 30 | Notation "F ^op" := (opposite F) : functor_scope. 31 | End FunctorDualNotations. 32 | -------------------------------------------------------------------------------- /theories/Categories/Functor/Identity.v: -------------------------------------------------------------------------------- 1 | (** * Identity functor *) 2 | Require Import Category.Core Functor.Core. 3 | 4 | Set Universe Polymorphism. 5 | Set Implicit Arguments. 6 | Generalizable All Variables. 7 | Set Asymmetric Patterns. 8 | 9 | Section identity. 10 | (** There is an identity functor. It does the obvious thing. *) 11 | Definition identity C : Functor C C 12 | := Build_Functor C C 13 | (fun x => x) 14 | (fun _ _ x => x) 15 | (fun _ _ _ _ _ => idpath) 16 | (fun _ => idpath). 17 | End identity. 18 | 19 | Module Export FunctorIdentityNotations. 20 | Notation "1" := (identity _) : functor_scope. 21 | End FunctorIdentityNotations. 22 | -------------------------------------------------------------------------------- /theories/Categories/Functor/Notations.v: -------------------------------------------------------------------------------- 1 | (** * Notations for functors *) 2 | Require Import Basics.Notations. 3 | Require Functor.Composition. 4 | Require Functor.Core. 5 | Require Functor.Dual. 6 | Require Functor.Identity. 7 | Require Functor.Prod. 8 | Require Functor.Sum. 9 | 10 | Include Functor.Composition.FunctorCompositionNotations. 11 | Include Functor.Core.FunctorCoreNotations. 12 | Include Functor.Dual.FunctorDualNotations. 13 | Include Functor.Identity.FunctorIdentityNotations. 14 | Include Functor.Prod.FunctorProdNotations. 15 | Include Functor.Sum.FunctorSumNotations. 16 | -------------------------------------------------------------------------------- /theories/Categories/Functor/Pointwise.v: -------------------------------------------------------------------------------- 1 | (** * Pointwise functors (functoriality of the functor category construction) *) 2 | Require Functor.Pointwise.Core. 3 | Require Functor.Pointwise.Properties. 4 | 5 | Include Functor.Pointwise.Core. 6 | Include Functor.Pointwise.Properties. 7 | -------------------------------------------------------------------------------- /theories/Categories/Functor/Prod.v: -------------------------------------------------------------------------------- 1 | (** * Functors involving product categories, and their properties *) 2 | (** ** Definitions of various functors *) 3 | Require Functor.Prod.Core. 4 | (** ** Universal property *) 5 | Require Functor.Prod.Universal. 6 | (** ** Functoriality *) 7 | Require Functor.Prod.Functorial. 8 | 9 | Include Functor.Prod.Core. 10 | Include Functor.Prod.Universal. 11 | Include Functor.Prod.Functorial. 12 | 13 | Module Export FunctorProdNotations. 14 | Include Functor.Prod.Core.FunctorProdCoreNotations. 15 | End FunctorProdNotations. 16 | -------------------------------------------------------------------------------- /theories/Categories/Functor/Prod/Functorial.v: -------------------------------------------------------------------------------- 1 | (** * Functoriality of product of functors *) 2 | Require Import Category.Core Functor.Core Functor.Prod.Core FunctorCategory.Core Category.Prod NaturalTransformation.Prod NaturalTransformation.Composition.Core. 3 | Require Import NaturalTransformation.Paths. 4 | 5 | Set Universe Polymorphism. 6 | Set Implicit Arguments. 7 | Generalizable All Variables. 8 | Set Asymmetric Patterns. 9 | 10 | Local Open Scope natural_transformation_scope. 11 | 12 | Local Notation fst_type := Basics.Overture.fst. 13 | Local Notation snd_type := Basics.Overture.snd. 14 | Local Notation pair_type := Basics.Overture.pair. 15 | 16 | (** ** Construction of product of functors as a functor - [_×_ : (C → D) × (C → D') → (C → D × D')] *) 17 | Section functorial. 18 | Context `{Funext}. 19 | 20 | Variables C D D' : PreCategory. 21 | 22 | Definition functor_morphism_of 23 | s d 24 | (m : morphism ((C -> D) * (C -> D')) s d) 25 | : morphism (_ -> _) (fst s * snd s)%functor (fst d * snd d)%functor 26 | := fst_type m * snd_type m. 27 | 28 | Definition functor_composition_of 29 | s d d' 30 | (m1 : morphism ((C -> D) * (C -> D')) s d) 31 | (m2 : morphism ((C -> D) * (C -> D')) d d') 32 | : functor_morphism_of (m2 o m1) 33 | = functor_morphism_of m2 o functor_morphism_of m1. 34 | Proof. 35 | path_natural_transformation; reflexivity. 36 | Qed. 37 | 38 | Definition functor_identity_of 39 | (x : object ((C -> D) * (C -> D'))) 40 | : functor_morphism_of (identity x) = identity _. 41 | Proof. 42 | path_natural_transformation; reflexivity. 43 | Qed. 44 | 45 | Definition functor 46 | : object ((C -> D) * (C -> D') -> (C -> D * D')) 47 | := Build_Functor 48 | ((C -> D) * (C -> D')) (C -> D * D') 49 | _ 50 | functor_morphism_of 51 | functor_composition_of 52 | functor_identity_of. 53 | End functorial. 54 | -------------------------------------------------------------------------------- /theories/Categories/Functor/Utf8.v: -------------------------------------------------------------------------------- 1 | (** * Unicode notations for functors *) 2 | Require Export Category.Notations Category.Utf8 Functor.Notations. 3 | Require Import Functor.Core Functor.Composition.Core Functor.Dual. 4 | Require Import Basics.Utf8. 5 | 6 | Infix "∘" := compose : functor_scope. 7 | 8 | Notation "F ₀ x" := (object_of F x) : object_scope. 9 | Notation "F ₁ m" := (morphism_of F m) : morphism_scope. 10 | Notation "F 'ᵒᵖ'" := (opposite F) : functor_scope. 11 | -------------------------------------------------------------------------------- /theories/Categories/FunctorCategory.v: -------------------------------------------------------------------------------- 1 | (** * Functor category *) 2 | (** Since there are only notations in [FunctorCategory.Notations], we can just export those. *) 3 | Require Export FunctorCategory.Notations. 4 | 5 | (** ** Definition *) 6 | Require FunctorCategory.Core. 7 | (** ** Morphisms in a functor category *) 8 | Require FunctorCategory.Morphisms. 9 | (** ** Functoriality of [(_ → _)] *) 10 | Require FunctorCategory.Functorial. 11 | (** ** Opposite functor [(C → D) → (Cᵒᵖ → Dᵒᵖ)ᵒᵖ] *) 12 | Require FunctorCategory.Dual. 13 | 14 | Include FunctorCategory.Core. 15 | Include FunctorCategory.Morphisms. 16 | Include FunctorCategory.Functorial. 17 | Include FunctorCategory.Dual. 18 | (** We don't want to make UTF-8 notations the default, so we don't export them. *) 19 | -------------------------------------------------------------------------------- /theories/Categories/FunctorCategory/Core.v: -------------------------------------------------------------------------------- 1 | (** * Functor category [D → C] (also [Cᴰ] and [[D, C]]) *) 2 | Require Import Category.Strict Functor.Core NaturalTransformation.Core Functor.Paths. 3 | (** These must come last, so that [identity], [compose], etc., refer to natural transformations. *) 4 | Require Import NaturalTransformation.Composition.Core NaturalTransformation.Identity NaturalTransformation.Composition.Laws NaturalTransformation.Paths. 5 | 6 | Set Universe Polymorphism. 7 | Set Implicit Arguments. 8 | Generalizable All Variables. 9 | Set Asymmetric Patterns. 10 | 11 | (** ** Definition of [C → D] *) 12 | Section functor_category. 13 | Context `{Funext}. 14 | 15 | Variables C D : PreCategory. 16 | 17 | (** There is a category Fun(C, D) of functors from [C] to [D]. *) 18 | Definition functor_category : PreCategory 19 | := @Build_PreCategory (Functor C D) 20 | (@NaturalTransformation C D) 21 | (@identity C D) 22 | (@compose C D) 23 | (@associativity _ C D) 24 | (@left_identity _ C D) 25 | (@right_identity _ C D) 26 | _. 27 | End functor_category. 28 | 29 | Local Notation "C -> D" := (functor_category C D) : category_scope. 30 | 31 | (** ** [C → D] is a strict category if [D] is *) 32 | Lemma isstrict_functor_category `{Funext} C `{IsStrictCategory D} 33 | : IsStrictCategory (C -> D). 34 | Proof. 35 | typeclasses eauto. 36 | Defined. 37 | 38 | Module Export FunctorCategoryCoreNotations. 39 | (*Notation "C ^ D" := (functor_category D C) : category_scope. 40 | Notation "[ C , D ]" := (functor_category C D) : category_scope.*) 41 | Notation "C -> D" := (functor_category C D) : category_scope. 42 | End FunctorCategoryCoreNotations. 43 | -------------------------------------------------------------------------------- /theories/Categories/FunctorCategory/Dual.v: -------------------------------------------------------------------------------- 1 | (** * Dual functor categories *) 2 | Require Import Category.Core Functor.Core NaturalTransformation.Core. 3 | Require Import Category.Dual Functor.Dual NaturalTransformation.Dual. 4 | Require Import Functor.Identity. 5 | Require Import FunctorCategory.Core. 6 | Require Import Functor.Paths. 7 | Require Import HoTT.Tactics. 8 | 9 | Set Universe Polymorphism. 10 | Set Implicit Arguments. 11 | Generalizable All Variables. 12 | Set Asymmetric Patterns. 13 | 14 | Local Open Scope functor_scope. 15 | 16 | Section opposite. 17 | Context `{Funext}. 18 | 19 | (** ** Functors [(C → D) ↔ (Cᵒᵖ → Dᵒᵖ)ᵒᵖ] *) 20 | Definition opposite_functor (C D : PreCategory) : Functor (C -> D) (C^op -> D^op)^op 21 | := Build_Functor 22 | (C -> D) ((C^op -> D^op)^op) 23 | (fun F => F^op)%functor 24 | (fun _ _ T => T^op)%natural_transformation 25 | (fun _ _ _ _ _ => idpath) 26 | (fun _ => idpath). 27 | 28 | Local Ltac op_t C D := 29 | split; 30 | path_functor; 31 | repeat (apply path_forall; intro); 32 | simpl; 33 | destruct_head NaturalTransformation; 34 | exact idpath. 35 | 36 | (** ** The above functors are isomorphisms *) 37 | Definition opposite_functor_law C D 38 | : opposite_functor C D o (opposite_functor C^op D^op)^op = 1 39 | /\ (opposite_functor C^op D^op)^op o opposite_functor C D = 1. 40 | Proof. 41 | op_t C D. 42 | Qed. 43 | End opposite. 44 | -------------------------------------------------------------------------------- /theories/Categories/FunctorCategory/Functorial.v: -------------------------------------------------------------------------------- 1 | (** * Functoriality of functor category construction *) 2 | Require Import Category.Core Functor.Core FunctorCategory.Core Functor.Pointwise.Core Functor.Pointwise.Properties Category.Dual Category.Prod Cat.Core ExponentialLaws.Law4.Functors. 3 | 4 | Set Universe Polymorphism. 5 | Set Implicit Arguments. 6 | Generalizable All Variables. 7 | Set Asymmetric Patterns. 8 | 9 | Local Open Scope category_scope. 10 | Local Open Scope type_scope. 11 | 12 | (** ** [(_ → _)] is a functor [catᵒᵖ × cat → cat] *) 13 | Section functor. 14 | Context `{Funext}. 15 | 16 | Variable P : PreCategory -> Type. 17 | Context `{forall C, IsHProp (P C)}. 18 | Context `{HF : forall C D, P C -> P D -> IsHSet (Functor C D)}. 19 | 20 | Local Notation cat := (sub_pre_cat P HF). 21 | 22 | Hypothesis has_functor_categories : forall C D : cat, P (C.1 -> D.1). 23 | 24 | Local Open Scope category_scope. 25 | 26 | Definition functor_uncurried 27 | : object ((cat^op * cat) -> cat) 28 | := Eval cbv zeta in 29 | let object_of := (fun CD => (((fst CD).1 -> (snd CD).1); 30 | has_functor_categories (fst CD) (snd CD))) 31 | in Build_Functor 32 | (cat^op * cat) cat 33 | object_of 34 | (fun CD C'D' FG => pointwise (fst FG) (snd FG)) 35 | (fun _ _ _ _ _ => Functor.Pointwise.Properties.composition_of _ _ _ _) 36 | (fun _ => Functor.Pointwise.Properties.identity_of _ _). 37 | 38 | Definition functor : object (cat^op -> (cat -> cat)) 39 | := ExponentialLaws.Law4.Functors.inverse _ _ _ functor_uncurried. 40 | End functor. 41 | -------------------------------------------------------------------------------- /theories/Categories/FunctorCategory/Notations.v: -------------------------------------------------------------------------------- 1 | (** * Notations for functor categories *) 2 | Require FunctorCategory.Core. 3 | Require FunctorCategory.Morphisms. 4 | 5 | Include FunctorCategory.Core.FunctorCategoryCoreNotations. 6 | Include FunctorCategory.Morphisms.FunctorCategoryMorphismsNotations. 7 | -------------------------------------------------------------------------------- /theories/Categories/FunctorCategory/Utf8.v: -------------------------------------------------------------------------------- 1 | (** * Unicode notations for functor categories *) 2 | Require Export Category.Utf8 Functor.Utf8 NaturalTransformation.Utf8. 3 | Require Import FunctorCategory.Core FunctorCategory.Morphisms. 4 | Require Import Basics.Utf8. 5 | 6 | Notation "C → D" := (functor_category C D) : category_scope. 7 | Infix "≅" := NaturalIsomorphism : natural_transformation_scope. 8 | -------------------------------------------------------------------------------- /theories/Categories/Grothendieck.v: -------------------------------------------------------------------------------- 1 | (** * Grothendieck Construction *) 2 | (** We want to have the following as subdirectories/modules, not at top level. Unfortunately, namespacing in Coq is kind-of broken (see, e.g., https://coq.inria.fr/bugs/show_bug.cgi?id=3676), so we don't get the ability to rename subfolders by [Including] into other modules. *) 3 | (** ** of a functor to Set *) 4 | Require Grothendieck.ToSet. 5 | 6 | (** ** of a pseudofunctor to Cat *) 7 | Require Grothendieck.PseudofunctorToCat. 8 | 9 | (** ** of a functor to Cat *) 10 | Require Grothendieck.ToCat. 11 | -------------------------------------------------------------------------------- /theories/Categories/Grothendieck/ToCat.v: -------------------------------------------------------------------------------- 1 | (** * Grothendieck Construction of a functor to Cat *) 2 | Require Import Category.Core Functor.Core. 3 | Require Import Pseudofunctor.FromFunctor. 4 | Require Import Cat.Core. 5 | Require Import Grothendieck.PseudofunctorToCat. 6 | 7 | Set Universe Polymorphism. 8 | Set Implicit Arguments. 9 | Generalizable All Variables. 10 | Set Asymmetric Patterns. 11 | 12 | Local Open Scope morphism_scope. 13 | 14 | Section Grothendieck. 15 | Context `{Funext}. 16 | 17 | Variable P : PreCategory -> Type. 18 | (*Context `{forall C, IsHProp (P C)}.*) 19 | Context `{HF : forall C D, P C -> P D -> IsHSet (Functor C D)}. 20 | 21 | Local Notation cat := (@sub_pre_cat _ P HF). 22 | 23 | Variable C : PreCategory. 24 | Variable F : Functor C cat. 25 | 26 | (** ** Category of elements *) 27 | Definition category : PreCategory 28 | := category (pseudofunctor_of_functor_to_cat F). 29 | 30 | (** ** First projection functor *) 31 | Definition pr1 : Functor category C 32 | := pr1 (pseudofunctor_of_functor_to_cat F). 33 | End Grothendieck. 34 | -------------------------------------------------------------------------------- /theories/Categories/Grothendieck/ToSet.v: -------------------------------------------------------------------------------- 1 | (** * Grothendieck Construction of a functor to Set *) 2 | (** We want to have the following as subdirectories/modules, not at top level. Unfortunately, namespacing in Coq is kind-of broken (see, e.g., https://coq.inria.fr/bugs/show_bug.cgi?id=3676), so we don't get the ability to rename subfolders by [Including] into other modules. *) 3 | (** ** construction *) 4 | Require Grothendieck.ToSet.Core. 5 | 6 | (** ** classification of morphisms *) 7 | Require Grothendieck.ToSet.Morphisms. 8 | 9 | (** ** preservation of saturation *) 10 | Require Grothendieck.ToSet.Univalent. 11 | 12 | Include Grothendieck.ToSet.Core. 13 | -------------------------------------------------------------------------------- /theories/Categories/Grothendieck/ToSet/Morphisms.v: -------------------------------------------------------------------------------- 1 | (** * Classification of morphisms of the Grothendieck Construction of a functor to Set *) 2 | Require Import Category.Core Functor.Core. 3 | Require Import Category.Morphisms. 4 | Require Import SetCategory.Core. 5 | Require Import Grothendieck.ToSet.Core. 6 | Require Import HoTT.Basics HoTT.Types. 7 | 8 | Set Universe Polymorphism. 9 | Set Implicit Arguments. 10 | Generalizable All Variables. 11 | Set Asymmetric Patterns. 12 | 13 | Local Open Scope morphism_scope. 14 | 15 | Section Grothendieck. 16 | Context `{Funext}. 17 | Context {C : PreCategory} 18 | {F : Functor C set_cat}. 19 | 20 | Definition isequiv_sigma_category_isomorphism {s d : category F} 21 | : (s <~=~> d)%category <~> { e : (s.(c) <~=~> d.(c))%category | (F _1 e s.(x) = d.(x))%category }. 22 | Proof. 23 | simple refine (equiv_adjointify _ _ _ _). 24 | { intro m. 25 | simple refine (_; _). 26 | { exists (m : morphism _ _ _).1. 27 | exists (m^-1).1. 28 | { exact (ap proj1 (@left_inverse _ _ _ m _)). } 29 | { exact (ap proj1 (@right_inverse _ _ _ m _)). } } 30 | { exact (m : morphism _ _ _).2. } } 31 | { intro m. 32 | exists (m.1 : morphism _ _ _ ; m.2). 33 | eexists (m.1^-1; 34 | ((ap (F _1 (m.1)^-1) m.2)^) 35 | @ (ap10 ((((composition_of F _ _ _ _ _)^) 36 | @ (ap (fun m => F _1 m) (@left_inverse _ _ _ m.1 _)) 37 | @ (identity_of F _)) 38 | : (F _1 (m.1 : morphism _ _ _)^-1) o F _1 m.1 = idmap) s.(x))); 39 | apply path_sigma_hprop. 40 | - exact left_inverse. 41 | - exact right_inverse. } 42 | { intro x; apply path_sigma_hprop; apply path_isomorphic. 43 | reflexivity. } 44 | { intro x; apply path_isomorphic; reflexivity. } 45 | Defined. 46 | End Grothendieck. 47 | -------------------------------------------------------------------------------- /theories/Categories/Grothendieck/ToSet/Univalent.v: -------------------------------------------------------------------------------- 1 | (** * Saturation of the Grothendieck Construction of a functor to Set *) 2 | Require Import Category.Core Functor.Core. 3 | Require Import Category.Univalent. 4 | Require Import Category.Morphisms. 5 | Require Import SetCategory.Core. 6 | Require Import Grothendieck.ToSet.Core Grothendieck.ToSet.Morphisms. 7 | Require Import HoTT.Basics.Equivalences HoTT.Basics.Trunc. 8 | Require Import HoTT.Types.Universe HoTT.Types.Sigma. 9 | 10 | Set Universe Polymorphism. 11 | Set Implicit Arguments. 12 | Generalizable All Variables. 13 | Set Asymmetric Patterns. 14 | 15 | Local Open Scope morphism_scope. 16 | 17 | Section Grothendieck. 18 | Context `{Funext}. 19 | 20 | Variable C : PreCategory. 21 | Context `{IsCategory C}. 22 | Variable F : Functor C set_cat. 23 | 24 | Definition category_isotoid_helper {s d} (a : c s = c d) 25 | : (transport (fun c : C => F c) a (x s) = x d) 26 | <~> (F _1 (idtoiso C a)) (x s) = x d. 27 | Proof. 28 | apply equiv_path. 29 | apply ap10, ap. 30 | destruct a; simpl. 31 | exact (ap10 (identity_of F _)^ _). 32 | Defined. 33 | 34 | Arguments category_isotoid_helper : simpl never. 35 | 36 | Definition category_isotoid {s d : category F} 37 | : s = d <~> (s <~=~> d)%category. 38 | Proof. 39 | refine (isequiv_sigma_category_isomorphism^-1 oE _ oE (equiv_ap' (issig_pair F)^-1 s d)). 40 | refine (_ oE (equiv_path_sigma _ _ _)^-1). 41 | simpl. 42 | simple refine (equiv_functor_sigma' _ _). 43 | { exists (@idtoiso C _ _). 44 | exact _. } 45 | { exact category_isotoid_helper. } 46 | Defined. 47 | 48 | #[export] Instance preservation : IsCategory (category F). 49 | Proof. 50 | intros s d. 51 | refine (@isequiv_homotopic _ _ category_isotoid (idtoiso (category F) (x:=s) (y:=d)) _ _). 52 | intro x. 53 | destruct x; apply path_isomorphic, path_sigma_hprop. 54 | reflexivity. 55 | Defined. 56 | End Grothendieck. 57 | -------------------------------------------------------------------------------- /theories/Categories/GroupoidCategory.v: -------------------------------------------------------------------------------- 1 | (** * Groupoids *) 2 | (** ** Definition *) 3 | Require GroupoidCategory.Core. 4 | (** ** Morphisms in a groupoid *) 5 | Require GroupoidCategory.Morphisms. 6 | (** ** Propositional self-duality *) 7 | Require GroupoidCategory.Dual. 8 | 9 | Include GroupoidCategory.Core. 10 | Include GroupoidCategory.Core.GroupoidCategoryInternals. 11 | Include GroupoidCategory.Morphisms. 12 | Include GroupoidCategory.Dual. 13 | -------------------------------------------------------------------------------- /theories/Categories/GroupoidCategory/Dual.v: -------------------------------------------------------------------------------- 1 | (** * Propositional self-duality of groupoid categories *) 2 | Require Import Category.Core GroupoidCategory.Core Category.Paths Category.Dual. 3 | Require Import HoTT.Types. 4 | Require Import Basics.Trunc Basics.Tactics. 5 | 6 | Set Universe Polymorphism. 7 | Set Implicit Arguments. 8 | Generalizable All Variables. 9 | Set Asymmetric Patterns. 10 | 11 | Local Open Scope category_scope. 12 | 13 | Lemma path_groupoid_dual `{Univalence} `{IsTrunc 1 X} 14 | : (groupoid_category X)^op = groupoid_category X. 15 | Proof. 16 | repeat match goal with 17 | | _ => intro 18 | | _ => progress cbn 19 | | _ => reflexivity 20 | | _ => apply path_forall 21 | | _ => apply (path_universe (symmetry _ _)) 22 | | _ => exact (center _) 23 | | _ => progress rewrite ?transport_path_universe, ?transport_path_universe_V 24 | | _ => progress path_category 25 | | _ => progress path_induction 26 | end. 27 | Qed. 28 | -------------------------------------------------------------------------------- /theories/Categories/GroupoidCategory/Morphisms.v: -------------------------------------------------------------------------------- 1 | (** * Morphisms in a groupoid *) 2 | Require Import Category.Core Category.Morphisms Category.Univalent GroupoidCategory.Core. 3 | Require Import Trunc Equivalences HoTT.Tactics. 4 | 5 | Set Universe Polymorphism. 6 | Set Implicit Arguments. 7 | Generalizable All Variables. 8 | Set Asymmetric Patterns. 9 | 10 | 11 | Local Open Scope category_scope. 12 | 13 | Section groupoid_category. 14 | Variable X : Type. 15 | Context `{IsTrunc 1 X}. 16 | 17 | Definition isotoid (s d : groupoid_category X) 18 | : s <~=~> d -> s = d 19 | := fun f => f : morphism _ _ _. 20 | 21 | (** ** All groupoids are categories *) 22 | #[export] Instance iscategory_groupoid_category 23 | : IsCategory (groupoid_category X). 24 | Proof. 25 | repeat intro. 26 | apply (isequiv_adjointify (@idtoiso (groupoid_category X) _ _) 27 | (@isotoid _ _)); 28 | repeat intro; 29 | destruct_head @Isomorphic; 30 | destruct_head @IsIsomorphism; 31 | compute in *; 32 | path_induction_hammer. 33 | Qed. 34 | End groupoid_category. 35 | -------------------------------------------------------------------------------- /theories/Categories/InitialTerminalCategory.v: -------------------------------------------------------------------------------- 1 | (** * Initial and terminal categories *) 2 | (** ** Definitions *) 3 | Require InitialTerminalCategory.Core. 4 | Include InitialTerminalCategory.Core. 5 | 6 | (** We want to have the following as subdirectories/modules, not at top level. Unfortunately, namespacing in Coq is kind-of broken (see, e.g., https://coq.inria.fr/bugs/show_bug.cgi?id=3676), so we don't get the ability to rename subfolders by [Including] into other modules. *) 7 | (** ** Functors to and from initial and terminal categories *) 8 | Require InitialTerminalCategory.Functors. 9 | (** ** Natural transformations between functors from initial categories and to terminal categories *) 10 | Require InitialTerminalCategory.NaturalTransformations. 11 | (** ** Pseudofunctors from initial and terminal categories *) 12 | Require InitialTerminalCategory.Pseudofunctors. 13 | 14 | 15 | Require Export InitialTerminalCategory.Notations. 16 | -------------------------------------------------------------------------------- /theories/Categories/InitialTerminalCategory/Core.v: -------------------------------------------------------------------------------- 1 | (** * Initial and terminal category definitions *) 2 | Require Import HoTT.Basics HoTT.Types. 3 | Require Import Category.Core. 4 | Require Import NatCategory. 5 | 6 | Set Universe Polymorphism. 7 | Set Implicit Arguments. 8 | Generalizable All Variables. 9 | Set Asymmetric Patterns. 10 | Local Unset Primitive Projections. (* suppress a warning about [IsTerminalCategory] *) 11 | 12 | Notation initial_category := (nat_category 0) (only parsing). 13 | Notation terminal_category := (nat_category 1) (only parsing). 14 | 15 | (** ** Terminal categories *) 16 | (** A precategory is terminal if its objects and morphisms are contractible types. *) 17 | Class IsTerminalCategory (C : PreCategory) 18 | `{Contr (object C)} 19 | `{forall s d, Contr (morphism C s d)} 20 | : Type0 := {}. 21 | 22 | (** ** Initial categories *) 23 | (** An initial precategory is one whose objects have the recursion principle of the empty type *) 24 | Class IsInitialCategory (C : PreCategory) 25 | := initial_category_ind : forall P : Type, C -> P. 26 | 27 | Instance trunc_initial_category `{IsInitialCategory C} 28 | : IsHProp C 29 | := istrunc_S _ (fun x y => initial_category_ind _ x). 30 | Instance trunc_initial_category_mor `{IsInitialCategory C} x y 31 | : Contr (morphism C x y) 32 | := initial_category_ind _ x. 33 | 34 | (** ** Default initial ([0]) and terminal ([1]) precategories. *) 35 | Instance is_initial_category_0 : IsInitialCategory 0 := (fun T => @Empty_ind (fun _ => T)). 36 | Instance: IsTerminalCategory 1 | 0 := {}. 37 | Instance: Contr (object 1) | 0 := _. 38 | Instance : `{Contr (morphism 1 x y)} | 0 := fun x y => _. 39 | Instance default_terminal C {H H1} : @IsTerminalCategory C H H1 | 10 := {}. 40 | 41 | Arguments initial_category_ind / . 42 | Arguments is_initial_category_0 / . 43 | -------------------------------------------------------------------------------- /theories/Categories/InitialTerminalCategory/Notations.v: -------------------------------------------------------------------------------- 1 | (** * Initial and terminal category notations *) 2 | Require InitialTerminalCategory.Functors. 3 | Require InitialTerminalCategory.Pseudofunctors. 4 | 5 | Export InitialTerminalCategory.Functors.InitialTerminalCategoryFunctorsNotations. 6 | Export InitialTerminalCategory.Pseudofunctors.InitialTerminalCategoryPseudofunctorsNotations. 7 | -------------------------------------------------------------------------------- /theories/Categories/KanExtensions.v: -------------------------------------------------------------------------------- 1 | (** * Kan Extensions *) 2 | (** ** Definitions *) 3 | Require KanExtensions.Core. 4 | (** ** Kan Extensions assemble into functors *) 5 | Require KanExtensions.Functors. 6 | 7 | Include KanExtensions.Core. 8 | Include KanExtensions.Functors. 9 | -------------------------------------------------------------------------------- /theories/Categories/KanExtensions/Functors.v: -------------------------------------------------------------------------------- 1 | (** * Kan extensions assemble into functors *) 2 | Require Import Category.Core Functor.Core. 3 | Require Import KanExtensions.Core. 4 | Require Import Adjoint.UniversalMorphisms.Core. 5 | Require Import FunctorCategory.Core. 6 | Require Import Adjoint.Core. 7 | 8 | Set Universe Polymorphism. 9 | Set Implicit Arguments. 10 | Generalizable All Variables. 11 | Set Asymmetric Patterns. 12 | 13 | Section kan_extension_functors. 14 | Context `{Funext}. 15 | Variables C C' D : PreCategory. 16 | Variable p : object (C -> C'). 17 | 18 | (** ** Left Kan extension functor *) 19 | Section lan. 20 | Context `(has_left_kan_extensions 21 | : forall h : object (C -> D), 22 | @IsLeftKanExtensionAlong _ _ _ _ p h (left_kan_extensions h)). 23 | 24 | Definition left_kan_extension_functor 25 | : Functor (C -> D) (C' -> D) 26 | := functor__of__initial_morphism has_left_kan_extensions. 27 | 28 | Definition left_kan_extension_adjunction 29 | : left_kan_extension_functor -| pullback_along D p 30 | := adjunction__of__initial_morphism has_left_kan_extensions. 31 | End lan. 32 | 33 | 34 | (** ** Right Kan extension functor *) 35 | Section ran. 36 | Context `(has_right_kan_extensions 37 | : forall h : object (C -> D), 38 | @IsRightKanExtensionAlong _ _ _ _ p h (right_kan_extensions h)). 39 | 40 | Definition right_kan_extension_functor 41 | : Functor (C -> D) (C' -> D) 42 | := functor__of__terminal_morphism has_right_kan_extensions. 43 | 44 | Definition right_kan_extension_adjunction 45 | : pullback_along D p -| right_kan_extension_functor 46 | := adjunction__of__terminal_morphism has_right_kan_extensions. 47 | End ran. 48 | End kan_extension_functors. 49 | -------------------------------------------------------------------------------- /theories/Categories/LaxComma.v: -------------------------------------------------------------------------------- 1 | (** * Lax Comma Categories *) 2 | (** Since there are only notations in [LaxComma.Notations], we can just export those. *) 3 | Local Set Warnings "-notation-overridden". 4 | Require Export LaxComma.Notations. 5 | 6 | (** ** Definitions *) 7 | Require LaxComma.Core. 8 | 9 | Include LaxComma.Core. 10 | (** We don't want to make UTF-8 notations the default, so we don't export them. *) 11 | -------------------------------------------------------------------------------- /theories/Categories/LaxComma/Notations.v: -------------------------------------------------------------------------------- 1 | (** * Notations for lax comma categories *) 2 | Require LaxComma.Core. 3 | 4 | Local Set Warnings "-notation-overridden". (* work around bug #5567, https://coq.inria.fr/bugs/show_bug.cgi?id=5567, notation-overridden,parsing should not trigger for only printing notations *) 5 | Include LaxComma.Core.LaxCommaCoreNotations. 6 | -------------------------------------------------------------------------------- /theories/Categories/LaxComma/Utf8.v: -------------------------------------------------------------------------------- 1 | (** * Unicode notations for comma categories *) 2 | Local Set Warnings "-notation-overridden". 3 | Require Import LaxComma.Core. 4 | Require Export LaxComma.Notations. 5 | Require Import Basics.Utf8. 6 | 7 | (** Set some notations for printing *) 8 | Notation "'CAT' ⇓ a" := (@lax_slice_category_over _ _ _ a _) : category_scope. 9 | Notation "a ⇓ 'CAT'" := (@lax_coslice_category_over _ _ _ a _) : category_scope. 10 | Notation "x ⇓ F" := (lax_coslice_category x F) (only printing) : category_scope. 11 | Notation "F ⇓ x" := (lax_slice_category x F) (only printing) : category_scope. 12 | Notation "S ⇓ T" := (lax_comma_category S T) (only printing) : category_scope. 13 | (** Set the notation for parsing; typeclasses will automatically decide which of the arguments are functors and which are objects, i.e., functors from the terminal category. *) 14 | Notation "S ⇓ T" := (get_LCC S T) : category_scope. 15 | 16 | Notation "'CAT' ⇑ a" := (@oplax_slice_category_over _ _ _ a _) : category_scope. 17 | Notation "a ⇑ 'CAT'" := (@oplax_coslice_category_over _ _ _ a _) : category_scope. 18 | Notation "x ⇑ F" := (oplax_coslice_category x F) (only printing) : category_scope. 19 | Notation "F ⇑ x" := (oplax_slice_category x F) (only printing) : category_scope. 20 | Notation "S ⇑ T" := (oplax_comma_category S T) (only printing) : category_scope. 21 | (** Set the notation for parsing; typeclasses will automatically decide which of the arguments are functors and which are objects, i.e., functors from the terminal category. *) 22 | Notation "S ⇑ T" := (get_OLCC S T) : category_scope. 23 | -------------------------------------------------------------------------------- /theories/Categories/Limits.v: -------------------------------------------------------------------------------- 1 | (** * Limits and Colimits *) 2 | (** ** Definitions *) 3 | Require Limits.Core. 4 | (** ** (co)limits assemble into functors *) 5 | (** *** which are adjoints to Δ *) 6 | Require Limits.Functors. 7 | 8 | Include Limits.Core. 9 | Include Limits.Functors. 10 | -------------------------------------------------------------------------------- /theories/Categories/NaturalTransformation.v: -------------------------------------------------------------------------------- 1 | (** * Natural Transformations *) 2 | (** Since there are only notations in [NaturalTransformation.Notations], we can just export those. *) 3 | Require Export NaturalTransformation.Notations. 4 | 5 | (** ** Definition of natural transformation *) 6 | Require NaturalTransformation.Core. 7 | (** ** Composition of natural transformations *) 8 | Require NaturalTransformation.Composition.Core. 9 | (** ** Dual natural transformations *) 10 | Require NaturalTransformation.Dual. 11 | (** ** Identity natural transformation *) 12 | Require NaturalTransformation.Identity. 13 | (** ** Natural isomorphisms *) 14 | Require NaturalTransformation.Isomorphisms. 15 | (** ** Path space of natural transformation type *) 16 | Require NaturalTransformation.Paths. 17 | (** ** Pointwise natural transformations *) 18 | Require NaturalTransformation.Pointwise. 19 | (** ** Sums of natural transformations *) 20 | Require NaturalTransformation.Sum. 21 | (** ** Products of natural transformations *) 22 | Require NaturalTransformation.Prod. 23 | 24 | Include NaturalTransformation.Core. 25 | Include NaturalTransformation.Composition.Core. 26 | Include NaturalTransformation.Dual. 27 | Include NaturalTransformation.Identity. 28 | Include NaturalTransformation.Isomorphisms. 29 | Include NaturalTransformation.Paths. 30 | Include NaturalTransformation.Pointwise. 31 | Include NaturalTransformation.Sum. 32 | Include NaturalTransformation.Prod. 33 | (** We don't want to make UTF-8 notations the default, so we don't export them. *) 34 | 35 | (** Since [Composition] is a separate sub-directory, we need to re-create the module structure *) 36 | (** We want to have the following as subdirectories/modules, not at top level. Unfortunately, namespacing in Coq is kind-of broken (see, e.g., https://coq.inria.fr/bugs/show_bug.cgi?id=3676), so we don't get the ability to rename subfolders by [Including] into other modules. *) 37 | Require NaturalTransformation.Composition. 38 | -------------------------------------------------------------------------------- /theories/Categories/NaturalTransformation/Composition.v: -------------------------------------------------------------------------------- 1 | (** * Composition of natural transformations *) 2 | (** ** Composition *) 3 | Require NaturalTransformation.Composition.Core. 4 | (** ** Functoriality *) 5 | Require NaturalTransformation.Composition.Functorial. 6 | (** ** Laws about composition *) 7 | Require NaturalTransformation.Composition.Laws. 8 | 9 | Include NaturalTransformation.Composition.Core. 10 | Include NaturalTransformation.Composition.Functorial. 11 | Include NaturalTransformation.Composition.Laws. 12 | 13 | Module Export NaturalTransformationCompositionNotations. 14 | Include NaturalTransformation.Composition.Core.NaturalTransformationCompositionCoreNotations. 15 | End NaturalTransformationCompositionNotations. 16 | -------------------------------------------------------------------------------- /theories/Categories/NaturalTransformation/Composition/Functorial.v: -------------------------------------------------------------------------------- 1 | (** * Functoriality of composition of natural transformations *) 2 | Require Import Category.Core Functor.Core. 3 | Require Import FunctorCategory.Core Functor.Composition.Core NaturalTransformation.Composition.Core NaturalTransformation.Composition.Laws. 4 | 5 | Set Universe Polymorphism. 6 | Set Implicit Arguments. 7 | Generalizable All Variables. 8 | Set Asymmetric Patterns. 9 | 10 | Local Open Scope functor_scope. 11 | 12 | Section functorial_composition. 13 | Context `{Funext}. 14 | Variables C D E : PreCategory. 15 | 16 | Local Open Scope natural_transformation_scope. 17 | 18 | (** ** whiskering on the left is a functor *) 19 | Definition whiskerL_functor (F : (D -> E)%category) 20 | : ((C -> D) -> (C -> E))%category 21 | := Build_Functor 22 | (C -> D) (C -> E) 23 | (fun G => F o G)%functor 24 | (fun _ _ T => F oL T) 25 | (fun _ _ _ _ _ => composition_of_whisker_l _ _ _) 26 | (fun _ => whisker_l_right_identity _ _). 27 | 28 | (** ** whiskering on the right is a functor *) 29 | Definition whiskerR_functor (G : (C -> D)%category) 30 | : ((D -> E) -> (C -> E))%category 31 | := Build_Functor 32 | (D -> E) (C -> E) 33 | (fun F => F o G)%functor 34 | (fun _ _ T => T oR G) 35 | (fun _ _ _ _ _ => composition_of_whisker_r _ _ _) 36 | (fun _ => whisker_r_left_identity _ _). 37 | End functorial_composition. 38 | -------------------------------------------------------------------------------- /theories/Categories/NaturalTransformation/Dual.v: -------------------------------------------------------------------------------- 1 | (** * Opposite natural transformations *) 2 | Require Category.Dual Functor.Dual. 3 | Import Category.Dual.CategoryDualNotations Functor.Dual.FunctorDualNotations. 4 | Require Import Category.Core Functor.Core NaturalTransformation.Core. 5 | 6 | Set Universe Polymorphism. 7 | Set Implicit Arguments. 8 | Generalizable All Variables. 9 | Set Asymmetric Patterns. 10 | 11 | Local Open Scope category_scope. 12 | 13 | (** ** Definition of [Tᵒᵖ] *) 14 | Definition opposite 15 | C D 16 | (F G : Functor C D) 17 | (T : NaturalTransformation F G) 18 | : NaturalTransformation G^op F^op 19 | := Build_NaturalTransformation' (G^op) (F^op) 20 | (components_of T) 21 | (fun s d => commutes_sym T d s) 22 | (fun s d => commutes T d s). 23 | 24 | Local Notation "T ^op" := (opposite T) : natural_transformation_scope. 25 | 26 | (** ** [ᵒᵖ] is judgmentally involutive *) 27 | Local Open Scope natural_transformation_scope. 28 | 29 | Definition opposite_involutive C D (F G : Functor C D) (T : NaturalTransformation F G) 30 | : (T^op)^op = T 31 | := idpath. 32 | 33 | Module Export NaturalTransformationDualNotations. 34 | Notation "T ^op" := (opposite T) : natural_transformation_scope. 35 | End NaturalTransformationDualNotations. 36 | -------------------------------------------------------------------------------- /theories/Categories/NaturalTransformation/Notations.v: -------------------------------------------------------------------------------- 1 | (** * Notations for natural transformations *) 2 | Require NaturalTransformation.Composition. 3 | Require NaturalTransformation.Dual. 4 | Require NaturalTransformation.Identity. 5 | Require NaturalTransformation.Prod. 6 | Require NaturalTransformation.Sum. 7 | 8 | Include NaturalTransformation.Composition.NaturalTransformationCompositionNotations. 9 | Include NaturalTransformation.Dual.NaturalTransformationDualNotations. 10 | Include NaturalTransformation.Identity.NaturalTransformationIdentityNotations. 11 | Include NaturalTransformation.Prod.NaturalTransformationProdNotations. 12 | Include NaturalTransformation.Sum.NaturalTransformationSumNotations. 13 | -------------------------------------------------------------------------------- /theories/Categories/NaturalTransformation/Sum.v: -------------------------------------------------------------------------------- 1 | (** * Coproduct of natural transformations *) 2 | Require Import Category.Sum Functor.Sum NaturalTransformation.Core. 3 | 4 | Set Universe Polymorphism. 5 | Set Implicit Arguments. 6 | Generalizable All Variables. 7 | Set Asymmetric Patterns. 8 | 9 | Section sum. 10 | Definition sum 11 | C C' D F G F' G' 12 | (T : @NaturalTransformation C D F G) 13 | (T' : @NaturalTransformation C' D F' G') 14 | : NaturalTransformation (F + F') (G + G'). 15 | Proof. 16 | refine (Build_NaturalTransformation 17 | (F + F') (G + G') 18 | (fun x => match x with 19 | | Basics.Overture.inl c => T c 20 | | Basics.Overture.inr c' => T' c' 21 | end) 22 | _). 23 | abstract ( 24 | repeat (intros [] || intro); simpl; 25 | auto with natural_transformation 26 | ). 27 | Defined. 28 | End sum. 29 | 30 | Module Export NaturalTransformationSumNotations. 31 | Notation "T + U" := (sum T U) : natural_transformation_scope. 32 | End NaturalTransformationSumNotations. 33 | -------------------------------------------------------------------------------- /theories/Categories/NaturalTransformation/Utf8.v: -------------------------------------------------------------------------------- 1 | (** * Unicode notations for natural transformations *) 2 | Require Export Category.Utf8 Functor.Utf8. 3 | Require Import NaturalTransformation.Composition.Core NaturalTransformation.Dual. 4 | Require Import Basics.Utf8. 5 | 6 | Infix "∘" := compose : natural_transformation_scope. 7 | Infix "∘ˡ" := whisker_l : natural_transformation_scope. 8 | Infix "∘ʳ" := whisker_r : natural_transformation_scope. 9 | Notation "T 'ᵒᵖ'" := (opposite T) : natural_transformation_scope. 10 | -------------------------------------------------------------------------------- /theories/Categories/Notations.v: -------------------------------------------------------------------------------- 1 | (** * Notations for categories *) 2 | Require Import Basics.Notations. 3 | Require Export Category.Notations. 4 | Require Export Functor.Notations. 5 | Require Export NaturalTransformation.Notations. 6 | Require Export FunctorCategory.Notations. 7 | Require NatCategory. 8 | Export NatCategory.Notations. 9 | Require Export InitialTerminalCategory.Notations. 10 | Require Export Profunctor.Notations. 11 | Local Set Warnings "-notation-overridden". 12 | Require Export Comma.Notations. 13 | Require Export Adjoint.Notations. 14 | Require Export Structure.Notations. 15 | 16 | Require ChainCategory. 17 | Export ChainCategory.Notations. 18 | -------------------------------------------------------------------------------- /theories/Categories/Profunctor.v: -------------------------------------------------------------------------------- 1 | (** * Profunctors *) 2 | Require Export Profunctor.Notations. 3 | 4 | (** ** Definition *) 5 | Require Profunctor.Core. 6 | (** ** Identity Profunctor *) 7 | Require Profunctor.Identity. 8 | (** ** Representable Profunctors *) 9 | Require Profunctor.Representable. 10 | 11 | Include Profunctor.Core. 12 | Include Profunctor.Representable. 13 | Include Profunctor.Identity. 14 | -------------------------------------------------------------------------------- /theories/Categories/Profunctor/Identity.v: -------------------------------------------------------------------------------- 1 | (** * Identity profunctor *) 2 | Require Import Category.Core Profunctor.Core HomFunctor. 3 | 4 | Set Universe Polymorphism. 5 | Set Implicit Arguments. 6 | Generalizable All Variables. 7 | Set Asymmetric Patterns. 8 | 9 | Local Open Scope profunctor_scope. 10 | 11 | Section identity. 12 | (** Quoting nLab: 13 | 14 | In particular the identity profunctor [Id : C ⇸ C] is represented by the identity functor and hence is given by the hom-functor [C(−,−) : Cᵒᵖ × C → Set]. *) 15 | 16 | Definition identity `{Funext} (C : PreCategory) : C -|-> C 17 | := hom_functor C. 18 | End identity. 19 | 20 | Module Export ProfunctorIdentityNotations. 21 | Notation "1" := (identity _) : profunctor_scope. 22 | End ProfunctorIdentityNotations. 23 | -------------------------------------------------------------------------------- /theories/Categories/Profunctor/Notations.v: -------------------------------------------------------------------------------- 1 | (** * Notations for profunctors *) 2 | Require Profunctor.Core. 3 | Require Profunctor.Identity. 4 | 5 | Include Profunctor.Core.ProfunctorCoreNotations. 6 | Include Profunctor.Identity.ProfunctorIdentityNotations. 7 | -------------------------------------------------------------------------------- /theories/Categories/Profunctor/Representable.v: -------------------------------------------------------------------------------- 1 | (** * Representable profunctors *) 2 | Require Import Category.Core Functor.Core Functor.Prod.Core Profunctor.Core Functor.Dual Profunctor.Identity Functor.Composition.Core Functor.Identity. 3 | 4 | Set Universe Polymorphism. 5 | Set Implicit Arguments. 6 | Generalizable All Variables. 7 | Set Asymmetric Patterns. 8 | 9 | Local Open Scope functor_scope. 10 | Local Open Scope profunctor_scope. 11 | 12 | Section representable. 13 | (** Quoting nLab on profunctors: 14 | 15 | Every functor [f : C → D] induces two profunctors [D(1, f) : C ⇸ D] and [D(f, 1) : D ⇸ C], defined by [D(1, f)(d, c) = D(d, f(c))] and [D(f, 1)(c, d) = D(f(c), d)]. These profunctors are called representable (or sometimes one of them is corepresentable). *) 16 | 17 | Context `{Funext}. 18 | 19 | Definition representable C D (F : Functor C D) : C -|-> D 20 | := 1%profunctor o (1, F). 21 | 22 | (** TODO: Is there a define this so that we get proofs by duality about representable functors? If we had judgemental eta expansion, maybe we could do it as [swap o (representable F^op)^op]? *) 23 | Definition corepresentable C D (F : Functor C D) : D -|-> C 24 | := 1%profunctor o (F^op, 1). 25 | End representable. 26 | -------------------------------------------------------------------------------- /theories/Categories/Profunctor/Utf8.v: -------------------------------------------------------------------------------- 1 | (** * Unicode notations for profunctors *) 2 | Require Import Profunctor.Core. 3 | Require Export Profunctor.Notations. 4 | Require Import Basics.Utf8. 5 | 6 | Notation "x ⇸ y" := (Profunctor x y) : type_scope. 7 | -------------------------------------------------------------------------------- /theories/Categories/Pseudofunctor.v: -------------------------------------------------------------------------------- 1 | (** * Pseudofunctors *) 2 | (** ** Definition *) 3 | Require Pseudofunctor.Core. 4 | (** ** Helper lemmas for rewriting *) 5 | Require Pseudofunctor.RewriteLaws. 6 | (** ** Construction from a functor to cat *) 7 | Require Pseudofunctor.FromFunctor. 8 | (** ** Identity pseudofunctor *) 9 | Require Pseudofunctor.Identity. 10 | 11 | Include Pseudofunctor.Core. 12 | Include Pseudofunctor.RewriteLaws. 13 | Include Pseudofunctor.FromFunctor. 14 | Include Pseudofunctor.Identity. 15 | -------------------------------------------------------------------------------- /theories/Categories/PseudonaturalTransformation.v: -------------------------------------------------------------------------------- 1 | (** * Pseudonatural Transformations *) 2 | 3 | (** ** Definition of pseudonatural transformations *) 4 | Require PseudonaturalTransformation.Core. 5 | 6 | Include PseudonaturalTransformation.Core. 7 | -------------------------------------------------------------------------------- /theories/Categories/SemiSimplicialSets.v: -------------------------------------------------------------------------------- 1 | (** * The category of semisimplicial sets *) 2 | Require Import Types Basics.Trunc. 3 | Require Import Category.Core Functor.Core. 4 | Require Import Category.Morphisms. 5 | Require Import Category.Dual FunctorCategory.Core. 6 | Require Import SetCategory.Core. 7 | Require Import SimplicialSets. 8 | Require Import Category.Sigma.OnMorphisms Category.Subcategory.Wide. 9 | 10 | Set Universe Polymorphism. 11 | Set Implicit Arguments. 12 | Generalizable All Variables. 13 | Set Asymmetric Patterns. 14 | 15 | Local Open Scope category_scope. 16 | 17 | Module Export Core. 18 | Section semisimplicial_sets. 19 | Context `{Funext}. 20 | (** Quoting David Spivak: 21 | 22 | Consider the subcategory of [Δ] with the same objects (wide) 23 | but only injective morphisms. If we call that [Γ] (which is 24 | nonstandard), then semi-simplicial sets (also a non-standard 25 | term) (sic) are [Fun(Γᵒᵖ, Set)]. Define the obvious inclusion 26 | [Γ -> Δ], which we will use to make simplicial sets without 27 | having to worry about "degeneracies". *) 28 | 29 | Definition semisimplex_category : PreCategory 30 | := wide simplex_category 31 | (@IsMonomorphism _) 32 | _ _ _. 33 | 34 | Definition semisimplicial_inclusion_functor : semisimplex_category -> simplex_category 35 | := pr1_mor. 36 | 37 | Definition semisimplicial_category (C : PreCategory) : PreCategory 38 | := semisimplex_category^op -> C. 39 | 40 | Definition semisimplicial_set := semisimplicial_category set_cat. 41 | Definition semisimplicial_prop := semisimplicial_category prop_cat. 42 | End semisimplicial_sets. 43 | 44 | Notation semisimplicial_of obj := (semisimplicial_category (cat_of obj)). 45 | End Core. 46 | -------------------------------------------------------------------------------- /theories/Categories/SetCategory.v: -------------------------------------------------------------------------------- 1 | (** * Category of sets *) 2 | (** ** Definitions of [set_cat] and [prop_cat] *) 3 | Require SetCategory.Core. 4 | (** ** Morphisms in the category of sets *) 5 | Require SetCategory.Morphisms. 6 | (** If there were a [SetCategory.Functors.Core], we'd [Include] it here. *) 7 | 8 | Include SetCategory.Core. 9 | Include SetCategory.Morphisms. 10 | 11 | (** ** Functors to/from the category of sets *) 12 | (** Since [Functors] is a separate sub-directory, we need to re-create the module structure. Alas, namespacing in Coq is kind-of broken (see, e.g., https://coq.inria.fr/bugs/show_bug.cgi?id=3676), so we don't get the ability to rename subfolders by [Including] into other modules. *) 13 | Require SetCategory.Functors. 14 | -------------------------------------------------------------------------------- /theories/Categories/SetCategory/Core.v: -------------------------------------------------------------------------------- 1 | (** * Precategories [set_cat] and [prop_cat] *) 2 | Require Import Category.Strict. 3 | Require Import HoTT.Basics HoTT.Types TruncType. 4 | 5 | Set Universe Polymorphism. 6 | Set Implicit Arguments. 7 | Generalizable All Variables. 8 | Set Asymmetric Patterns. 9 | 10 | Notation cat_of obj := 11 | (@Build_PreCategory obj 12 | (fun x y => x -> y) 13 | (fun _ x => x) 14 | (fun _ _ _ f g => f o g)%core 15 | (fun _ _ _ _ _ _ _ => idpath) 16 | (fun _ _ _ => idpath) 17 | (fun _ _ _ => idpath) 18 | _). 19 | 20 | (** There is a category [Set], where the objects are sets and the 21 | morphisms are set morphisms *) 22 | 23 | Definition prop_cat `{Funext} : PreCategory := cat_of HProp. 24 | Definition set_cat `{Funext} : PreCategory := cat_of HSet. 25 | 26 | (** ** [Prop] is a strict category *) 27 | Instance isstrict_prop_cat `{Univalence} 28 | : IsStrictCategory prop_cat 29 | := _. 30 | 31 | (** Because, e.g., [@identity set_cat x ≡ x], and we want [rewrite] to 32 | notice this, we must inform it that it can try treating [identity] 33 | as [idmap]. *) 34 | Declare Equivalent Keys identity idmap. 35 | -------------------------------------------------------------------------------- /theories/Categories/SetCategory/Functors.v: -------------------------------------------------------------------------------- 1 | (** * Functors between [set_cat] and [prop_cat] *) 2 | Require SetCategory.Functors.SetProp. 3 | 4 | Include SetCategory.Functors.SetProp. 5 | -------------------------------------------------------------------------------- /theories/Categories/SimplicialSets.v: -------------------------------------------------------------------------------- 1 | (** * The simplex category Δ, and the precategory of simplicial sets, [Δᵒᵖ → set] *) 2 | Require Import Basics Types Spaces.Nat.Core. 3 | Require Import Category.Core Functor.Core Functor.Paths. 4 | Require Import SetCategory.Core. 5 | Require Import ChainCategory FunctorCategory.Core. 6 | Require Import Category.Dual. 7 | Require Import Functor.Identity Functor.Composition.Core Functor.Composition.Laws. 8 | 9 | Set Universe Polymorphism. 10 | Set Implicit Arguments. 11 | Generalizable All Variables. 12 | Set Asymmetric Patterns. 13 | 14 | Local Open Scope functor_scope. 15 | Local Open Scope category_scope. 16 | 17 | (** We define the precategory Δ of simplices, or finite non-empty linear 18 | orders *) 19 | 20 | Module Export Core. 21 | Section simplicial_sets. 22 | Context `{Funext}. 23 | 24 | (** We say that the objects of Δ are natural numbers, where a 25 | number [n] is morally considered as the canonical [n]-simplex, 26 | a finite linear order on [n + 1] elements. By declaring 27 | [chain] to be a local coercion from [nat] to [PreCategory], we 28 | can rely on on-the-fly eta-expansion to make this moral 29 | consideration a reality, telling Coq that it can unify, for 30 | example, [nat -> nat -> Type] with [PreCategory -> PreCategory 31 | -> Type] by silently inserting [chain]. *) 32 | 33 | Local Coercion chain : nat >-> PreCategory. 34 | 35 | Definition simplex_category 36 | := @Build_PreCategory 37 | nat 38 | Functor 39 | identity 40 | compose 41 | associativity 42 | left_identity 43 | right_identity 44 | _. 45 | 46 | Definition simplicial_category (C : PreCategory) : PreCategory 47 | := simplex_category^op -> C. 48 | 49 | Definition simplicial_set := simplicial_category set_cat. 50 | Definition simplicial_prop := simplicial_category prop_cat. 51 | End simplicial_sets. 52 | 53 | Notation simplicial_of obj := (simplicial_category (cat_of obj)). 54 | End Core. 55 | 56 | Module Utf8. 57 | Notation Δ := simplex_category. 58 | End Utf8. 59 | -------------------------------------------------------------------------------- /theories/Categories/Structure.v: -------------------------------------------------------------------------------- 1 | (** Since there are only notations in [Structure.Notations], we can just export those. *) 2 | Require Export Structure.Notations. 3 | 4 | Require Structure.Core. 5 | Require Structure.IdentityPrinciple. 6 | 7 | Include Structure.Core. 8 | Include Structure.IdentityPrinciple. 9 | (** We don't want to make UTF-8 notations the default, so we don't export them. *) 10 | -------------------------------------------------------------------------------- /theories/Categories/Structure/Notations.v: -------------------------------------------------------------------------------- 1 | (** * Notations for structures *) 2 | Require Structure.Core. 3 | 4 | Include Structure.Core.StructureCoreNotations. 5 | -------------------------------------------------------------------------------- /theories/Categories/Structure/Utf8.v: -------------------------------------------------------------------------------- 1 | Require Import Structure.Core. 2 | Require Export Structure.Notations. 3 | Require Import Basics.Utf8. 4 | 5 | Notation "a ≤_{ x } b" := (a <=_{ x } b)%long_structure : long_structure_scope. 6 | Notation "a ≤ b" := (a <= b)%structure : structure_scope. 7 | -------------------------------------------------------------------------------- /theories/Categories/Utf8.v: -------------------------------------------------------------------------------- 1 | (** * Unicode notations for categories *) 2 | Local Set Warnings "-notation-overridden". 3 | Require Export HoTT.Categories.Notations. 4 | Require Export Category.Utf8 Functor.Utf8 NaturalTransformation.Utf8. 5 | Require Export Comma.Utf8. 6 | Require Export Adjoint.Utf8. 7 | Require Export FunctorCategory.Utf8. 8 | Require Export Profunctor.Utf8. 9 | Require Export Structure.Utf8. 10 | 11 | Require ChainCategory. 12 | Export ChainCategory.Utf8. 13 | Require SimplicialSets. 14 | Export SimplicialSets.Utf8. 15 | -------------------------------------------------------------------------------- /theories/Classes/implementations/assume_rationals.v: -------------------------------------------------------------------------------- 1 | From HoTT.Classes Require Import 2 | interfaces.canonical_names 3 | interfaces.orders 4 | interfaces.rationals 5 | theory.rationals. 6 | 7 | Monomorphic Universe UQ. 8 | Parameters (Q : Type@{UQ}) (Qap : Apart@{UQ UQ} Q) 9 | (Qplus : Plus Q) (Qmult : Mult Q) 10 | (Qzero : Zero Q) (Qone : One Q) (Qneg : Negate Q) (Qrecip : DecRecip Q) 11 | (Qle : Le@{UQ UQ} Q) (Qlt : Lt@{UQ UQ} Q) 12 | (QtoField : RationalsToField@{UQ UQ UQ UQ} Q) 13 | (Qrats : Rationals@{UQ UQ UQ UQ UQ UQ UQ UQ UQ UQ} Q) 14 | (Qtrivialapart : TrivialApart Q) (Qdec : DecidablePaths Q) 15 | (Qmeet : Meet Q) (Qjoin : Join Q) (Qlattice : LatticeOrder Qle) 16 | (Qle_total : TotalRelation (@le Q _)) 17 | (Qabs : Abs Q). 18 | (* I don't even want to know why this is necessary. *) 19 | Parameter Qenum : Enumerable Q. 20 | Notation "Q+" := (Qpos Q). 21 | 22 | Existing Instances Qap Qplus Qmult Qzero Qone Qneg Qrecip 23 | Qle Qlt QtoField Qrats Qtrivialapart Qdec 24 | Qmeet Qjoin Qlattice Qle_total Qabs Qenum. 25 | -------------------------------------------------------------------------------- /theories/Classes/implementations/bool.v: -------------------------------------------------------------------------------- 1 | Require Import 2 | HoTT.Classes.interfaces.abstract_algebra. 3 | 4 | Instance join_bool : Join Bool := orb. 5 | Instance meet_bool : Meet Bool := andb. 6 | Instance bottom_bool : Bottom Bool := false. 7 | Instance top_bool : Top Bool := true. 8 | 9 | Section contents. 10 | Local Ltac solve_bool := 11 | repeat (intros [|]); compute; (contradiction || auto). 12 | 13 | #[export] Instance lattice_bool : IsBoundedLattice Bool. 14 | Proof. repeat split; (apply _ || solve_bool). Defined. 15 | 16 | End contents. 17 | -------------------------------------------------------------------------------- /theories/Classes/interfaces/archimedean.v: -------------------------------------------------------------------------------- 1 | From HoTT.Classes Require Import 2 | interfaces.abstract_algebra 3 | interfaces.rationals 4 | interfaces.orders. 5 | 6 | Section property. 7 | Context (Q : Type). 8 | Context `{Qrats : Rationals Q}. 9 | Context (F : Type). 10 | Context `{Aorderedfield : OrderedField F}. 11 | (* We are assuming `A` to be of characteristic 0 because this is 12 | what `rationals_to_field` requires. But this requirement should 13 | eventually simply be implemented by the fact that F is an ordered 14 | field. *) 15 | Context {Achar : FieldCharacteristic F 0}. 16 | 17 | Definition qinc : Cast Q F := rationals_to_field Q F. 18 | Existing Instance qinc. 19 | 20 | Class ArchimedeanProperty := archimedean_property 21 | : forall x y, x < y -> hexists (fun q => x < ' q < y). 22 | 23 | End property. 24 | -------------------------------------------------------------------------------- /theories/Classes/interfaces/integers.v: -------------------------------------------------------------------------------- 1 | Require Import 2 | HoTT.Classes.interfaces.abstract_algebra 3 | HoTT.Classes.interfaces.orders 4 | HoTT.Classes.interfaces.naturals 5 | HoTT.Classes.theory.rings (* for Ring -> SemiRing *). 6 | 7 | Class IntegersToRing@{i j} (A:Type@{i}) 8 | := integers_to_ring: forall (R:Type@{j}) `{IsCRing R}, A -> R. 9 | Arguments integers_to_ring A {_} R {_ _ _ _ _ _} _. 10 | 11 | Class Integers A {Aap:Apart A} {Aplus Amult Azero Aone Anegate Ale Alt} 12 | `{U : IntegersToRing A} := 13 | { integers_ring :: @IsCRing A Aplus Amult Azero Aone Anegate 14 | ; integers_order :: FullPseudoSemiRingOrder Ale Alt 15 | ; integers_to_ring_mor :: forall {B} `{IsCRing B}, IsSemiRingPreserving (integers_to_ring A B) 16 | ; integers_initial: forall {B} `{IsCRing B} {h : A -> B} `{!IsSemiRingPreserving h} x, 17 | integers_to_ring A B x = h x}. 18 | 19 | Section specializable. 20 | Context (Z N : Type) `{Integers Z} `{Naturals N}. 21 | 22 | Class IntAbs := int_abs_sig : forall x, 23 | { n : N | naturals_to_semiring N Z n = x } |_| 24 | { n : N | naturals_to_semiring N Z n = -x }. 25 | 26 | Definition int_abs `{ia : IntAbs} (x : Z) : N := 27 | match int_abs_sig x with 28 | | inl (n;_) => n 29 | | inr (n;_) => n 30 | end. 31 | 32 | Definition int_to_nat `{Zero N} `{ia : IntAbs} (x : Z) : N := 33 | match int_abs_sig x with 34 | | inl (n;_) => n 35 | | inr (n;_) => 0 36 | end. 37 | End specializable. 38 | -------------------------------------------------------------------------------- /theories/Classes/interfaces/monad.v: -------------------------------------------------------------------------------- 1 | Require Export 2 | HoTT.Classes.interfaces.canonical_names. 3 | 4 | Class Monad (M : Type -> Type) {Mret : Return M} {Mbind : Bind M} := 5 | { monad_ret_bind : forall {A B} a (f : A -> M B), bind (ret a) f = f a 6 | ; monad_bind_ret : forall {A} (x : M A), bind x ret = x 7 | ; monad_bind_assoc : forall {A B C} x (f : A -> M B) (g : B -> M C), 8 | bind (bind x f) g = bind x (fun a => bind (f a) g) }. 9 | 10 | -------------------------------------------------------------------------------- /theories/Classes/interfaces/naturals.v: -------------------------------------------------------------------------------- 1 | Require Import 2 | HoTT.Classes.interfaces.abstract_algebra 3 | HoTT.Classes.interfaces.orders. 4 | 5 | Class NaturalsToSemiRing@{i j} (A : Type@{i}) := 6 | naturals_to_semiring: forall (B : Type@{j}) `{IsSemiCRing B}, A -> B. 7 | 8 | Arguments naturals_to_semiring A {_} B {_ _ _ _ _} _. 9 | 10 | Class Naturals A {Aap:Apart A} {Aplus Amult Azero Aone Ale Alt} 11 | `{U: NaturalsToSemiRing A} := 12 | { naturals_ring :: @IsSemiCRing A Aplus Amult Azero Aone 13 | ; naturals_order :: FullPseudoSemiRingOrder Ale Alt 14 | ; naturals_to_semiring_mor :: forall {B} `{IsSemiCRing B}, 15 | IsSemiRingPreserving (naturals_to_semiring A B) 16 | ; naturals_initial: forall {B} `{IsSemiCRing B} {h : A -> B} `{!IsSemiRingPreserving h} x, 17 | naturals_to_semiring A B x = h x }. 18 | 19 | (* Specializable operations: *) 20 | Class NatDistance N `{Plus N} 21 | := nat_distance_sig : forall x y : N, { z : N | x + z = y } |_| 22 | { z : N | y + z = x }. 23 | Definition nat_distance {N} `{nd : NatDistance N} (x y : N) := 24 | match nat_distance_sig x y with 25 | | inl (n;_) => n 26 | | inr (n;_) => n 27 | end. 28 | -------------------------------------------------------------------------------- /theories/Classes/interfaces/rationals.v: -------------------------------------------------------------------------------- 1 | Require Import 2 | HoTT.Classes.interfaces.abstract_algebra 3 | HoTT.Classes.interfaces.orders. 4 | 5 | (* Universes: 6 | - i universe of origin type 7 | - j universe of target types 8 | - k universe of applied apart of target types 9 | - l universe of Field property of target types 10 | *) 11 | Class RationalsToField@{i j k l} (A : Type@{i}) := 12 | rationals_to_field : forall (B : Type@{j}) `{IsField@{j l k} B} 13 | `{!FieldCharacteristic B 0}, A -> B. 14 | 15 | Arguments rationals_to_field A {_} B {_ _ _ _ _ _ _ _ _} _. 16 | 17 | 18 | (* The Rationals are the initial field of characteristic 0. *) 19 | 20 | Class Rationals A {Aap : Apart A} {Aplus Amult Azero Aone Aneg Arecip Ale Alt} 21 | `{U : !RationalsToField A} := 22 | { rationals_field :: @IsDecField A Aplus Amult Azero Aone Aneg Arecip 23 | ; rationals_order :: FullPseudoSemiRingOrder Ale Alt 24 | ; rationals_to_field_mor :: forall {B} `{IsField B} `{!FieldCharacteristic B 0}, 25 | IsSemiRingPreserving (rationals_to_field A B) 26 | ; rationals_initial : forall {B} `{IsField B} `{!FieldCharacteristic B 0} 27 | {h : A -> B} `{!IsSemiRingPreserving h} x, 28 | rationals_to_field A B x = h x }. 29 | -------------------------------------------------------------------------------- /theories/Classes/interfaces/round.v: -------------------------------------------------------------------------------- 1 | Require Import 2 | HoTT.Classes.interfaces.abstract_algebra 3 | HoTT.Classes.interfaces.orders 4 | HoTT.Classes.interfaces.naturals 5 | HoTT.Classes.implementations.peano_naturals. 6 | 7 | Section round_up. 8 | 9 | Class RoundUpStrict A `{IsSemiCRing A} `{StrictSemiRingOrder A} 10 | := round_up_strict : forall a : A, {n : nat & a < naturals_to_semiring nat A n}. 11 | Global Arguments round_up_strict A {_ _ _ _ _ _ _ _ _ _ _ _} _. 12 | 13 | End round_up. 14 | -------------------------------------------------------------------------------- /theories/Classes/interfaces/ua_setalgebra.v: -------------------------------------------------------------------------------- 1 | (** This file defines [SetAlgebra], a specialized [Algebra] where 2 | the carriers are always sets. *) 3 | 4 | Require Export HoTT.Classes.interfaces.ua_algebra. 5 | 6 | 7 | Record SetAlgebra {σ : Signature} : Type := BuildSetAlgebra 8 | { algebra_setalgebra : Algebra σ 9 | ; is_hset_algebra_setalgebra :: IsHSetAlgebra algebra_setalgebra }. 10 | 11 | Arguments SetAlgebra : clear implicits. 12 | 13 | Global Coercion algebra_setalgebra : SetAlgebra >-> Algebra. 14 | 15 | (** To find a path [A = B] between set algebras [A B : SetAlgebra σ], 16 | it is enough to find a path between the defining algebras, 17 | [algebra_setalgebra A = algebra_setalgebra B]. *) 18 | 19 | Lemma path_setalgebra `{Funext} {σ} (A B : SetAlgebra σ) 20 | (p : algebra_setalgebra A = algebra_setalgebra B) 21 | : A = B. 22 | Proof. 23 | destruct A as [A AH], B as [B BH]. cbn in *. 24 | transparent assert (a : (p#AH = BH)) by apply path_ishprop. 25 | by path_induction. 26 | Defined. 27 | 28 | (** The id path is mapped to the id path by [path_setalgebra]. *) 29 | 30 | Lemma path_setalgebra_1 `{Funext} {σ} (A : SetAlgebra σ) 31 | : path_setalgebra A A idpath = idpath. 32 | Proof. 33 | transparent assert (p : 34 | (∀ I : IsHSetAlgebra A, path_ishprop I I = idpath)). 35 | - intros. apply path_ishprop. 36 | - unfold path_setalgebra. by rewrite p. 37 | Qed. 38 | 39 | (** The function [path_setalgebra A B] is an equivalence with inverse 40 | [ap algebra_setalgebra]. *) 41 | 42 | Instance isequiv_path_setalgebra `{Funext} {σ : Signature} 43 | (A B : SetAlgebra σ) 44 | : IsEquiv (path_setalgebra A B). 45 | Proof. 46 | refine (isequiv_adjointify 47 | (path_setalgebra A B) (ap algebra_setalgebra) _ _). 48 | - abstract (intro p; induction p; by rewrite path_setalgebra_1). 49 | - abstract ( 50 | intro e; destruct A as [A AH], B as [B BH]; 51 | cbn in e; destruct e; 52 | unfold path_setalgebra; by destruct path_ishprop). 53 | Defined. 54 | -------------------------------------------------------------------------------- /theories/Classes/orders/sum.v: -------------------------------------------------------------------------------- 1 | Require Import 2 | HoTT.Classes.interfaces.abstract_algebra. 3 | 4 | Generalizable Variables A B. 5 | 6 | Instance Empty_lt : Lt@{Set Set} Empty. 7 | Proof. intros []. Defined. 8 | 9 | Instance Unit_lt : Lt@{Set Set} Unit := fun _ _ => Empty. 10 | 11 | Instance empty_tricho : Trichotomy@{Set Set Set} (_:Lt Empty). 12 | Proof. 13 | intros []. 14 | Qed. 15 | 16 | Instance unit_tricho : Trichotomy@{Set Set Set} (_:Lt Unit). 17 | Proof. 18 | intros [] [];auto. 19 | Defined. 20 | 21 | Section contents. 22 | 23 | Context `{Alt : Lt@{Set Set} A} `{Blt : Lt@{Set Set} B}. 24 | 25 | #[export] Instance sum_lt : Lt@{Set Set} (A |_| B) | 2 26 | := fun s1 s2 => 27 | match s1, s2 with 28 | | inl a1, inl a2 => a1 < a2 29 | | inr b1, inr b2 => b1 < b2 30 | | inl _, inr _ => Unit 31 | | inr _, inl _ => Empty 32 | end. 33 | 34 | #[export] Instance sum_tricho `{!Trichotomy@{Set Set Set} Alt} `{!Trichotomy@{Set Set Set} Blt} 35 | : Trichotomy@{Set Set Set} sum_lt. 36 | Proof. 37 | hnf. intros [a1|b1] [a2|b2];simpl. 38 | - destruct (trichotomy _ a1 a2) as [?|[?|?]];auto. 39 | - auto. 40 | - auto. 41 | - destruct (trichotomy _ b1 b2) as [?|[?|?]];auto. 42 | Defined. 43 | 44 | End contents. 45 | -------------------------------------------------------------------------------- /theories/Colimits/Colimit_Prod.v: -------------------------------------------------------------------------------- 1 | Require Import Basics. 2 | Require Import Types. 3 | Require Import Diagrams.Diagram. 4 | Require Import Colimits.Colimit. 5 | Require Import Colimits.Colimit_Sigma. 6 | Require Import Diagrams.Graph. 7 | 8 | (** * Colimit of product by a constant type *) 9 | 10 | (** Given a diagram [D], one of his colimits [Q] and a type [A], one can consider the diagram of the products of the types of [D] and [A]. Then, a colimit of such a diagram is [A * Q]. *) 11 | 12 | (** This is the constant case of the file [Colimit_Sigma] and we reuse its results. *) 13 | 14 | Section ColimitProd. 15 | 16 | Context `{Funext} {G : Graph} (D : Diagram G) (A : Type). 17 | 18 | Definition prod_diagram : Diagram G. 19 | Proof. 20 | srapply Build_Diagram. 21 | - exact (fun i => A * (D i)). 22 | - simpl; intros i j f x. 23 | exact (fst x, D _f f (snd x)). 24 | Defined. 25 | 26 | Definition diagram_equiv_prod_sigma 27 | : sigma_diagram (fun _ : A => D) ~d~ prod_diagram. 28 | Proof. 29 | unshelve econstructor. 30 | - srapply Build_DiagramMap; cbn. 31 | + intro i; apply equiv_sigma_prod0. 32 | + reflexivity. 33 | - intro i; cbn. 34 | apply equiv_sigma_prod0. 35 | Defined. 36 | 37 | Lemma iscolimit_prod {Q : Type} (HQ : IsColimit D Q) 38 | : IsColimit prod_diagram (A * Q). 39 | Proof. 40 | eapply iscolimit_postcompose_equiv. 41 | - apply equiv_sigma_prod0. 42 | - eapply iscolimit_precompose_equiv. 43 | + symmetry; exact diagram_equiv_prod_sigma. 44 | + by apply iscolimit_sigma. 45 | Defined. 46 | 47 | End ColimitProd. 48 | -------------------------------------------------------------------------------- /theories/Diagrams/DDiagram.v: -------------------------------------------------------------------------------- 1 | Require Import Basics. 2 | Require Import Diagrams.Graph. 3 | Require Import Diagrams.Diagram. 4 | 5 | (** We define here the Graph ∫D, also denoted G·D *) 6 | 7 | Definition integral {G : Graph} (D : Diagram G) : Graph. 8 | Proof. 9 | srapply Build_Graph. 10 | + exact {i : G & D i}. 11 | + intros i j. 12 | exact {g : G i.1 j.1 & D _f g i.2 = j.2}. 13 | Defined. 14 | 15 | (** Then, a dependent diagram E over D is just a diagram over ∫D. *) 16 | 17 | Definition DDiagram {G : Graph} (D : Diagram G) 18 | := Diagram (integral D). 19 | 20 | (** Given a dependent diagram, we c.an recover a diagram over G by considering the Σ types. *) 21 | 22 | Definition diagram_sigma {G : Graph} {D : Diagram G} (E : DDiagram D) 23 | : Diagram G. 24 | Proof. 25 | srapply Build_Diagram. 26 | - intro i. 27 | exact {x : D i & E (i; x)}. 28 | - intros i j g x. simpl in *. 29 | exists (D _f g x.1). 30 | exact (@arr _ E (i; x.1) (j; D _f g x.1) (g; idpath) x.2). 31 | Defined. 32 | 33 | (** A dependent diagram is said equifibered if all its fibers are equivalences. *) 34 | 35 | Class Equifibered {G : Graph} {D : Diagram G} (E : DDiagram D) := { 36 | isequifibered i j (g : G i j) (x : D i) 37 | :: IsEquiv (@arr _ E (i; x) (j; D _f g x) (g; idpath)); 38 | }. 39 | -------------------------------------------------------------------------------- /theories/Diagrams/Graph.v: -------------------------------------------------------------------------------- 1 | Require Import Basics.Overture. 2 | 3 | (** * Graphs *) 4 | 5 | (** A [Graph] is a type [graph0] of points together with a type [graph1] of arrows between each points. *) 6 | 7 | Record Graph := { 8 | graph0 : Type; 9 | graph1 : graph0 -> graph0 -> Type; 10 | }. 11 | 12 | Coercion graph0 : Graph >-> Sortclass. 13 | Coercion graph1 : Graph >-> Funclass. 14 | -------------------------------------------------------------------------------- /theories/Diagrams/ParallelPair.v: -------------------------------------------------------------------------------- 1 | Require Import Basics. 2 | Require Import Types. 3 | Require Import Diagrams.Graph. 4 | Require Import Diagrams.Diagram. 5 | Require Import Diagrams.Cocone. 6 | 7 | (** Parallel pairs *) 8 | 9 | Definition parallel_pair_graph : Graph. 10 | Proof. 11 | srapply (Build_Graph Bool). 12 | intros i j. 13 | exact (if i then if j then Empty else Bool else Empty). 14 | Defined. 15 | 16 | (** Parallel pair diagram *) 17 | 18 | Definition parallel_pair {A B : Type} (f g : A -> B) 19 | : Diagram parallel_pair_graph. 20 | Proof. 21 | srapply Build_Diagram. 22 | 1: intros []; [exact A | exact B]. 23 | intros [] [] []; [exact f | exact g]. 24 | Defined. 25 | 26 | (** Cones on [parallel_pair]s *) 27 | 28 | Definition Build_parallel_pair_cocone {A B Q} {f g : B -> A} 29 | `(q: A -> Q) (Hq: q o g == q o f) 30 | : Cocone (parallel_pair f g) Q. 31 | Proof. 32 | srapply Build_Cocone. 33 | 1: intros []; [exact (q o f) | exact q]. 34 | intros [] [] []; [reflexivity | exact Hq]. 35 | Defined. -------------------------------------------------------------------------------- /theories/Diagrams/Sequence.v: -------------------------------------------------------------------------------- 1 | Require Import Basics. 2 | Require Import Diagrams.Graph. 3 | Require Import Diagrams.Diagram. 4 | 5 | Local Open Scope nat_scope. 6 | Local Open Scope path_scope. 7 | 8 | (** * Sequence *) 9 | 10 | (** A Sequence is a sequence of maps from [X(n)] to [X(n+1)]. *) 11 | 12 | Definition sequence_graph : Graph. 13 | Proof. 14 | srapply (Build_Graph nat). 15 | intros n m; exact (S n = m). 16 | Defined. 17 | 18 | Definition Sequence := Diagram sequence_graph. 19 | 20 | Definition Build_Sequence 21 | (X : nat -> Type) 22 | (f : forall n, X n -> X n.+1) 23 | : Sequence. 24 | Proof. 25 | srapply Build_Diagram. 26 | 1: exact X. 27 | intros ? ? p. 28 | destruct p. 29 | apply f. 30 | Defined. 31 | 32 | (** A useful lemma to show than two sequences are equivalent. *) 33 | 34 | Definition equiv_sequence (D1 D2 : Sequence) 35 | (H0 : (D1 0) <~> (D2 0)) 36 | (Hn: forall n (e: (D1 n) <~> (D2 n)), 37 | {e' : (D1 n.+1) <~> (D2 n.+1) & (D2 _f 1) o e == e' o (D1 _f 1)}) 38 | : D1 ~d~ D2. 39 | Proof. 40 | srapply (Build_diagram_equiv (Build_DiagramMap _ _)); intro n; simpl. 41 | - apply equiv_fun. 42 | induction n. 43 | + exact H0. 44 | + exact (Hn n IHn).1. 45 | - intros m q; destruct q. 46 | induction n; simpl. 47 | + exact (Hn 0 H0).2. 48 | + simple refine (Hn n.+1 _).2. 49 | - induction n; simpl. 50 | + apply H0. 51 | + apply (Hn n _ ).1. 52 | Defined. 53 | -------------------------------------------------------------------------------- /theories/Diagrams/Span.v: -------------------------------------------------------------------------------- 1 | Require Import Basics. 2 | Require Import Types. 3 | Require Import Diagrams.Graph. 4 | Require Import Diagrams.Diagram. 5 | 6 | (** The underlying graph of a span. *) 7 | 8 | Definition span_graph : Graph. 9 | Proof. 10 | srapply (Build_Graph (Unit + Bool)). 11 | intros [i|i] [j|j]. 12 | 2: exact Unit. 13 | all: exact Empty. 14 | Defined. 15 | 16 | Section Span. 17 | 18 | Context {A B C : Type}. 19 | 20 | (** A span is a diagram: 21 | f g 22 | B <-- A --> C *) 23 | 24 | Definition span (f : A -> B) (g : A -> C) : Diagram span_graph. 25 | Proof. 26 | srapply Build_Diagram. 27 | - intros [i|i]. 28 | + exact A. 29 | + exact (if i then B else C). 30 | - intros [i|i] [j|j] u; cbn; try contradiction. 31 | destruct j. 32 | + exact f. 33 | + exact g. 34 | Defined. 35 | 36 | End Span. -------------------------------------------------------------------------------- /theories/Equiv/BiInv.v: -------------------------------------------------------------------------------- 1 | Require Import Basics Types.Prod Types.Equiv. 2 | 3 | Local Open Scope path_scope. 4 | Generalizable Variables A B f. 5 | 6 | (** * Bi-invertible maps *) 7 | 8 | (** A map is "bi-invertible" if it has both a section and a retraction, not necessarily the same. This definition of equivalence was proposed by Andre Joyal. *) 9 | 10 | Definition BiInv `(f : A -> B) : Type 11 | := {g : B -> A & g o f == idmap} * {h : B -> A & f o h == idmap}. 12 | 13 | (** It seems that the easiest way to show that bi-invertibility is equivalent to being an equivalence is also to show that both are h-props and that they are logically equivalent. *) 14 | 15 | Definition isequiv_biinv `(f : A -> B) 16 | : BiInv f -> IsEquiv f. 17 | Proof. 18 | intros [[g s] [h r]]. 19 | exact (isequiv_adjointify f g 20 | (fun x => ap f (ap g (r x)^ @ s (h x)) @ r x) 21 | s). 22 | Defined. 23 | 24 | Definition biinv_isequiv `(f : A -> B) 25 | : IsEquiv f -> BiInv f. 26 | Proof. 27 | intros [g s r adj]. 28 | exact ((g; r), (g; s)). 29 | Defined. 30 | 31 | Definition iff_biinv_isequiv `(f : A -> B) 32 | : BiInv f <-> IsEquiv f. 33 | Proof. 34 | split. 35 | - apply isequiv_biinv. 36 | - apply biinv_isequiv. 37 | Defined. 38 | 39 | Instance ishprop_biinv `{Funext} `(f : A -> B) : IsHProp (BiInv f) | 0. 40 | Proof. 41 | apply hprop_inhabited_contr. 42 | intros bif; pose (fe := isequiv_biinv f bif). 43 | apply @contr_prod. 44 | (* For this, we've done all the work already. *) 45 | - by apply contr_retr_equiv. 46 | - by apply contr_sect_equiv. 47 | Defined. 48 | 49 | Definition equiv_biinv_isequiv `{Funext} `(f : A -> B) 50 | : BiInv f <~> IsEquiv f. 51 | Proof. 52 | apply equiv_iff_hprop_uncurried, iff_biinv_isequiv. 53 | Defined. 54 | -------------------------------------------------------------------------------- /theories/ExcludedMiddle.v: -------------------------------------------------------------------------------- 1 | Require Import HoTT.Basics HoTT.Types. 2 | 3 | (** * The law of excluded middle *) 4 | 5 | Monomorphic Axiom ExcludedMiddle : Type0. 6 | Existing Class ExcludedMiddle. 7 | 8 | (** Mark this axiom as a "global axiom", which some of our tactics will automatically handle. *) 9 | Instance is_global_axiom_excludedmiddle : IsGlobalAxiom ExcludedMiddle := {}. 10 | 11 | Axiom LEM : forall `{ExcludedMiddle} (P : Type), IsHProp P -> P + ~P. 12 | 13 | Definition ExcludedMiddle_type := forall (P : Type), IsHProp P -> P + ~P. 14 | 15 | (** ** LEM means that all propositions are decidable *) 16 | 17 | Instance decidable_lem `{ExcludedMiddle} (P : Type) `{IsHProp P} : Decidable P 18 | := LEM P _. 19 | 20 | (** ** Double-negation elimination *) 21 | 22 | Definition DNE_type := forall P, IsHProp P -> ~~P -> P. 23 | 24 | Definition LEM_to_DNE : ExcludedMiddle -> DNE_type. 25 | Proof. 26 | intros lem P hp nnp. 27 | case (LEM P _). 28 | - auto. 29 | - intros np; elim (nnp np). 30 | Defined. 31 | 32 | (** This direction requires Funext. *) 33 | Definition DNE_to_LEM `{Funext} : 34 | DNE_type -> ExcludedMiddle_type. 35 | Proof. 36 | intros dn P hp. 37 | refine (dn (P + ~P) _ _). 38 | - apply ishprop_sum. 39 | + exact _. 40 | + exact _. 41 | + intros p np; exact (np p). 42 | - intros nlem. 43 | apply nlem. 44 | apply inr. 45 | intros p. 46 | apply nlem. 47 | apply inl. 48 | exact p. 49 | Defined. 50 | 51 | (** DNE is equivalent to "every proposition is a negation". *) 52 | Definition allneg_from_DNE (H : DNE_type) (P : Type) `{IsHProp P} 53 | : {Q : Type & P <-> ~Q}. 54 | Proof. 55 | exists (~P); split. 56 | - intros p np; exact (np p). 57 | - apply H; exact _. 58 | Defined. 59 | 60 | Definition DNE_from_allneg (H : forall P, IsHProp P -> {Q : Type & P <-> ~Q}) 61 | : DNE_type. 62 | Proof. 63 | intros P ? nnp. 64 | destruct (H P _) as [Q e]. 65 | apply e. 66 | intros q. 67 | apply nnp. 68 | intros p. 69 | exact (fst e p q). 70 | Defined. 71 | -------------------------------------------------------------------------------- /theories/Functorish.v: -------------------------------------------------------------------------------- 1 | Require Import HoTT.Basics Types.Universe. 2 | 3 | Local Open Scope path_scope. 4 | 5 | Section Functorish. 6 | Context `{Univalence}. 7 | (* We do not need composition to be preserved. *) 8 | Class Functorish (F : Type -> Type) := { 9 | fmap {A B} (f : A -> B) : F A -> F B ; 10 | fmap_idmap (A:Type) : fmap (idmap : A -> A) = idmap 11 | }. 12 | 13 | Global Arguments fmap F {FF} {A B} f _ : rename. 14 | Global Arguments fmap_idmap F {FF A} : rename. 15 | 16 | Context (F : Type -> Type). 17 | Context {FF : Functorish F}. 18 | 19 | Proposition isequiv_fmap {A B} (f : A -> B) `{IsEquiv _ _ f} 20 | : IsEquiv (fmap F f). 21 | Proof. 22 | refine (equiv_induction (fun A' e => IsEquiv (fmap F e)) _ _ (Build_Equiv _ _ f _)). 23 | exact (transport _ (fmap_idmap F)^ _). 24 | Defined. 25 | 26 | Proposition fmap_agrees_with_univalence {A B} (f : A -> B) `{IsEquiv _ _ f} 27 | : fmap F f = equiv_path _ _ (ap F (path_universe f)). 28 | Proof. 29 | refine (equiv_induction 30 | (fun A' e => fmap F e = equiv_path _ _ (ap F (path_universe e))) 31 | _ _ (Build_Equiv _ _ f _)). 32 | transitivity (idmap : F A -> F A). 33 | - apply fmap_idmap. 34 | - change (equiv_idmap A) with (equiv_path A A 1). 35 | rewrite (@eta_path_universe _ A A 1). exact 1. 36 | Defined. 37 | 38 | End Functorish. 39 | -------------------------------------------------------------------------------- /theories/HIT/Interval.v: -------------------------------------------------------------------------------- 1 | (** * Theorems about the homotopical interval. *) 2 | 3 | Require Import Basics.Overture Basics.PathGroupoids. 4 | Require Import Types.Paths. 5 | 6 | Local Open Scope path_scope. 7 | 8 | 9 | Module Export Interval. 10 | 11 | Private Inductive interval : Type0 := 12 | | zero : interval 13 | | one : interval. 14 | 15 | Axiom seg : zero = one. 16 | 17 | Definition interval_ind (P : interval -> Type) 18 | (a : P zero) (b : P one) (p : seg # a = b) 19 | : forall x:interval, P x 20 | := fun x => (match x return _ -> P x with 21 | | zero => fun _ => a 22 | | one => fun _ => b 23 | end) p. 24 | 25 | Axiom interval_ind_beta_seg : forall (P : interval -> Type) 26 | (a : P zero) (b : P one) (p : seg # a = b), 27 | apD (interval_ind P a b p) seg = p. 28 | 29 | End Interval. 30 | 31 | Definition interval_rec (P : Type) (a b : P) (p : a = b) 32 | : interval -> P 33 | := interval_ind (fun _ => P) a b (transport_const _ _ @ p). 34 | 35 | Definition interval_rec_beta_seg (P : Type) (a b : P) (p : a = b) 36 | : ap (interval_rec P a b p) seg = p. 37 | Proof. 38 | refine (cancelL (transport_const seg a) _ _ _). 39 | refine ((apD_const (interval_ind (fun _ => P) a b _) seg)^ @ _). 40 | exact (interval_ind_beta_seg (fun _ => P) _ _ _). 41 | Defined. 42 | 43 | (** ** The interval is contractible. *) 44 | 45 | Instance contr_interval : Contr interval | 0. 46 | Proof. 47 | apply (Build_Contr _ zero). 48 | refine (interval_ind _ 1 seg _). 49 | exact (transport_paths_r _ _ @ concat_1p _). 50 | Defined. 51 | -------------------------------------------------------------------------------- /theories/HIT/README.txt: -------------------------------------------------------------------------------- 1 | The files in this directory use "private inductive types" in order to 2 | implement higher inductive types (HITs). 3 | 4 | Many of the files which use HITs are currently segregated into this 5 | directory, but they can also be found in other directories. 6 | -------------------------------------------------------------------------------- /theories/HIT/SetCone.v: -------------------------------------------------------------------------------- 1 | Require Import HoTT.Basics Types.Unit. 2 | Require Import Colimits.Pushout. 3 | Require Import Truncations.Core. 4 | 5 | (** * Cones of HSets *) 6 | 7 | Section SetCone. 8 | Context {A B : HSet} (f : A -> B). 9 | 10 | Definition setcone := Trunc 0 (Pushout@{_ _ Set _} f (const_tt A)). 11 | 12 | #[export] Instance istrunc_setcone : IsHSet setcone := _. 13 | 14 | Definition setcone_point : setcone := tr (push (inr tt)). 15 | End SetCone. 16 | -------------------------------------------------------------------------------- /theories/HIT/iso.v: -------------------------------------------------------------------------------- 1 | Require Import HoTT.Basics. 2 | Require Import Types.Universe. 3 | Require Import HSet. 4 | Require Import HIT.epi HIT.unique_choice. 5 | 6 | Local Open Scope path_scope. 7 | 8 | (** We prove that [epi + mono <-> IsEquiv] *) 9 | Section iso. 10 | Context `{Univalence}. 11 | Variables X Y : HSet. 12 | Variable f : X -> Y. 13 | 14 | Lemma atmost1P_isinj (injf : IsInjective f) 15 | : forall y : Y, atmost1P (fun x => f x = y). 16 | Proof. 17 | intros y x x' p q. 18 | apply (injective f). 19 | exact (p @ q^). 20 | Defined. 21 | 22 | Definition isequiv_isepi_ismono (epif : isepi f) (monof : ismono f) 23 | : IsEquiv f. 24 | Proof. 25 | pose proof (@isepi_issurj _ _ _ f epif) as surjf. 26 | pose proof (isinj_ismono _ monof) as injf. 27 | pose proof (unique_choice 28 | (fun y x => f x = y) 29 | _ 30 | (fun y => (@center _ (surjf y), atmost1P_isinj injf y))) 31 | as H_unique_choice. 32 | apply (isequiv_adjointify _ H_unique_choice.1). 33 | - intro. 34 | apply H_unique_choice.2. 35 | - intro. 36 | apply injf. 37 | apply H_unique_choice.2. 38 | Defined. 39 | End iso. 40 | -------------------------------------------------------------------------------- /theories/HIT/unique_choice.v: -------------------------------------------------------------------------------- 1 | Require Import HoTT.Basics HoTT.Truncations.Core. 2 | 3 | Definition atmost1 X:=(forall x1 x2:X, (x1 = x2)). 4 | Definition atmost1P {X} (P:X->Type):= 5 | (forall x1 x2:X, P x1 -> P x2 -> (x1 = x2)). 6 | Definition hunique {X} (P:X->Type):=(hexists P) * (atmost1P P). 7 | 8 | Lemma atmost {X} {P : X -> Type}: 9 | (forall x, IsHProp (P x)) -> (atmost1P P) -> atmost1 (sig P). 10 | intros H H0 [x p] [y q]. 11 | specialize (H0 x y p q). 12 | induction H0. 13 | assert (H0: (p =q)) by apply path_ishprop. 14 | by induction H0. 15 | Qed. 16 | 17 | Lemma iota {X} (P:X-> Type): 18 | (forall x, IsHProp (P x)) -> (hunique P) -> sig P. 19 | Proof. 20 | intros H1 [H H0]. 21 | apply (@Trunc_rec (-1) (sig P) );auto. 22 | by apply hprop_allpath, atmost. 23 | Qed. 24 | 25 | Lemma unique_choice {X Y} (R:X->Y->Type) : 26 | (forall x y, IsHProp (R x y)) -> (forall x, (hunique (R x))) 27 | -> {f : X -> Y & forall x, (R x (f x))}. 28 | intros X0 X1. 29 | exists (fun x:X => (pr1 (iota _ (X0 x) (X1 x)))). 30 | intro x. exact (pr2 (iota _ (X0 x) (X1 x))). 31 | Qed. 32 | -------------------------------------------------------------------------------- /theories/Homotopy/EvaluationFibration.v: -------------------------------------------------------------------------------- 1 | From HoTT Require Import Basics Types Truncations.Core Pointed.Core Homotopy.Cover. 2 | 3 | Local Open Scope pointed_scope. 4 | Local Open Scope trunc_scope. 5 | 6 | (** * Evaluation fibrations and self-maps *) 7 | 8 | (** The type of unpointed self maps of A, pointed at the identity map. *) 9 | Definition selfmaps (A : Type) : pType := [A -> A, idmap]. 10 | 11 | (** The unrestricted evaluation map. *) 12 | Definition ev (A : pType) : selfmaps A ->* A 13 | := Build_pMap (fun f : selfmaps A => f pt) idpath. 14 | 15 | (** The evaluation fibration of an unpointed map [X -> A]. *) 16 | Definition evfib {X : pType} {A : Type} (f : X -> A) : comp (X -> A) (tr f) -> A 17 | := fun g => g.1 pt. 18 | 19 | (** If [f] is pointed, then the evaluation fibration of [f] is too. *) 20 | Definition pevfib {A X : pType} (f : X ->* A) : pcomp (X -> A) f ->* A 21 | := Build_pMap (fun g : pcomp (X -> A) f => g.1 pt) (point_eq f). 22 | 23 | (** The evaluation map of the identity. *) 24 | Definition ev1 (A : pType) := pevfib (A:=A) pmap_idmap. 25 | -------------------------------------------------------------------------------- /theories/Homotopy/HSpace.v: -------------------------------------------------------------------------------- 1 | Require Export HSpace.Core. 2 | Require Export HSpace.Coherent. 3 | Require Export HSpace.Pointwise. 4 | Require Export HSpace.Moduli. 5 | -------------------------------------------------------------------------------- /theories/Homotopy/HSpace/Coherent.v: -------------------------------------------------------------------------------- 1 | Require Import Basics HSpace.Core Pointed.Core Pointed.Loops. 2 | 3 | Local Open Scope mc_mult_scope. 4 | Local Open Scope pointed_scope. 5 | 6 | (** ** Coherent H-space structures *) 7 | 8 | (** An H-space is coherent when the left and right identities agree at the base point. *) 9 | 10 | Class IsCoherent (X : pType) `{IsHSpace X} := 11 | iscoherent : left_identity pt = right_identity pt. 12 | 13 | Record IsCohHSpace (A : pType) := { 14 | ishspace_cohhspace :: IsHSpace A; 15 | iscoherent_cohhspace :: IsCoherent A; 16 | }. 17 | 18 | Definition issig_iscohhspace (A : pType) 19 | : { hspace_op : SgOp A 20 | & { hspace_left_identity : LeftIdentity hspace_op pt 21 | & { hspace_right_identity : RightIdentity hspace_op pt 22 | & hspace_left_identity pt = hspace_right_identity pt } } } 23 | <~> IsCohHSpace A 24 | := ltac:(make_equiv). 25 | 26 | (** A type equivalent to a coherent H-space is a coherent H-space. *) 27 | Definition iscohhspace_equiv_cohhspace {X Y : pType} `{IsCohHSpace Y} (f : X <~>* Y) 28 | : IsCohHSpace X. 29 | Proof. 30 | snapply Build_IsCohHSpace. 31 | - rapply (ishspace_equiv_hspace f). 32 | apply ishspace_cohhspace; assumption. 33 | - unfold IsCoherent; cbn. 34 | refine (_ @@ 1). 35 | refine (ap (ap f^-1) _). 36 | pelim f. 37 | refine (1 @@ _). 38 | exact iscoherent. 39 | Defined. 40 | 41 | (** Every loop space is a coherent H-space. *) 42 | Definition iscohhspace_loops {X : pType} : IsCohHSpace (loops X). 43 | Proof. 44 | srapply Build_IsCohHSpace. 45 | - exact ishspace_loops. 46 | - reflexivity. 47 | Defined. 48 | -------------------------------------------------------------------------------- /theories/Homotopy/Join.v: -------------------------------------------------------------------------------- 1 | Require Export Join.Core. 2 | Require Export Join.TriJoin. 3 | Require Export Join.JoinAssoc. 4 | Require Export Join.JoinSusp. 5 | -------------------------------------------------------------------------------- /theories/Limits/Equalizer.v: -------------------------------------------------------------------------------- 1 | Require Import Basics Types.Sigma Types.Paths. 2 | 3 | (** Equalizers *) 4 | 5 | Definition Equalizer {A B} (f g : A -> B) 6 | := {x : A & f x = g x}. 7 | 8 | Definition functor_equalizer {A B A' B'} (f g : A -> B) 9 | (f' g' : A' -> B') 10 | (h : B -> B') (k : A -> A') 11 | (p : h o f == f' o k) (q : h o g == g' o k) 12 | : Equalizer f g -> Equalizer f' g'. 13 | Proof. 14 | intros [x r]. 15 | exists (k x). 16 | exact ((p x)^ @ (ap h r) @ (q x)). 17 | Defined. 18 | 19 | Definition equiv_functor_equalizer {A B A' B'} (f g : A -> B) 20 | (f' g' : A' -> B') 21 | (h : B <~> B') (k : A <~> A') 22 | (p : h o f == f' o k) (q : h o g == g' o k) 23 | : Equalizer f g <~> Equalizer f' g'. 24 | Proof. 25 | unfold Equalizer. 26 | srapply (equiv_functor_sigma' k). 27 | - intro a; cbn. 28 | refine (_ oE _). 29 | 2: rapply (equiv_ap h). 30 | exact (equiv_concat_r (q a) _ oE equiv_concat_l (p a)^ _). 31 | Defined. 32 | 33 | -------------------------------------------------------------------------------- /theories/Metatheory/Core.v: -------------------------------------------------------------------------------- 1 | Require Import HoTT.Basics HoTT.Types. 2 | 3 | (** * Metatheory *) 4 | 5 | (** This directory contains files that prove important metatheoretic results about HoTT, but that are not important for internal development of mathematics in HoTT. Thus, no files in this directory should ever need to be imported by files outside of this directory. *) 6 | 7 | (** Many of these results are about ways to prove univalence and function extensionality (which in the main library we simply assert as axioms, though we track their usage with dummy typeclasses). For convenience, here we define the types of these two statements. *) 8 | 9 | Definition Funext_type@{i j max} := 10 | forall (A : Type@{i}) (P : A -> Type@{j}) f g, 11 | IsEquiv (@apD10@{i j max} A P f g). 12 | 13 | (** Univalence is a property of a single universe; its statement lives in a higher universe *) 14 | Definition Univalence_type@{i iplusone} : Type@{iplusone} := 15 | forall (A B : Type@{i}), IsEquiv (equiv_path@{i iplusone} A B). 16 | -------------------------------------------------------------------------------- /theories/Metatheory/IntervalImpliesFunext.v: -------------------------------------------------------------------------------- 1 | (** * An interval type implies function extensionality *) 2 | 3 | Require Import HoTT.Basics. 4 | Require Import HIT.Interval. 5 | Require Import Metatheory.Core Metatheory.FunextVarieties. 6 | 7 | (** From an interval type with definitional computation rules on the end points, we can prove function extensionality. *) 8 | 9 | Definition funext_type_from_interval : Funext_type 10 | := WeakFunext_implies_Funext (NaiveFunext_implies_WeakFunext 11 | (fun A P f g p => 12 | let h := fun (x:interval) (a:A) => 13 | interval_rec _ (f a) (g a) (p a) x 14 | in ap h seg)). 15 | 16 | (** Note that the converse is also true: function extensionality implies that an interval type exists, with definitional computation rules. This is illustrated in TruncImpliesFunext.v. *) 17 | -------------------------------------------------------------------------------- /theories/Metatheory/PropTrunc.v: -------------------------------------------------------------------------------- 1 | Require Import Basics Types. 2 | Require Import Diagrams.Sequence. 3 | Require Import Homotopy.Join.Core. 4 | Require Import Colimits.Colimit Colimits.Sequential. 5 | 6 | Local Open Scope nat_scope. 7 | 8 | (** * Propositional truncation as a colimit. *) 9 | 10 | (** In this file we give an alternative construction of the propositional truncation using colimits. This can serve as a metatheoretic justification that propositional truncations exist. *) 11 | 12 | (** The sequence of increasing joins. *) 13 | Definition Join_seq (A : Type) : Sequence. 14 | Proof. 15 | srapply Build_Sequence. 16 | 1: exact (iterated_join A). 17 | intros n. 18 | exact joinr. 19 | Defined. 20 | 21 | (** Propositional truncation can be defined as the colimit of this sequence. *) 22 | Definition PropTrunc A : Type := Colimit (Join_seq A). 23 | 24 | (** The constructor is given by the colimit constructor. *) 25 | Definition ptr_in {A} : A -> PropTrunc A := colim (D:=Join_seq A) 0. 26 | 27 | (** The sequential colimit of this sequence is the propositional truncation. *) 28 | 29 | (** Universal property of propositional truncation. *) 30 | Lemma equiv_PropTrunc_rec `{Funext} (A P : Type) `{IsHProp P} 31 | : (PropTrunc A -> P) <~> (A -> P). 32 | Proof. 33 | refine (_ oE equiv_colim_seq_rec _ P). 34 | srapply equiv_iff_hprop. 35 | { intros h. 36 | exact (h 0). } 37 | intros f. 38 | induction n. 39 | - exact f. 40 | - cbn. 41 | srapply Join_rec. 42 | 1,2: assumption. 43 | intros a b. 44 | rapply path_ishprop. 45 | Defined. 46 | 47 | (** The propositional truncation is a hprop. *) 48 | Instance ishprop_proptrunc `{Funext} (A : Type) 49 | : IsHProp (PropTrunc A). 50 | Proof. 51 | rapply hprop_inhabited_contr. 52 | rapply (equiv_PropTrunc_rec _ _)^-1. 53 | intros x. 54 | srapply contr_colim_seq_into_prop. 55 | - intros n. 56 | destruct n. 57 | 1: exact x. 58 | exact (joinl x). 59 | - intros n. 60 | rapply jglue. 61 | Defined. 62 | -------------------------------------------------------------------------------- /theories/Modalities/Identity.v: -------------------------------------------------------------------------------- 1 | Require Import HoTT.Basics HoTT.Types. 2 | Require Import Modality Accessible. 3 | 4 | Local Open Scope path_scope. 5 | 6 | 7 | (** * The identity modality *) 8 | 9 | (** Everything to say here is fairly trivial. *) 10 | 11 | Definition purely : Modality. 12 | Proof. 13 | srapply (Build_Modality (fun _ => Unit) _ _ idmap). 14 | 1-2,6:intros; exact tt. 15 | - intros; assumption. 16 | - intros ? ? ? f z; exact (f z). 17 | - intros; reflexivity. 18 | Defined. 19 | 20 | Instance accmodality_purely : IsAccModality purely. 21 | Proof. 22 | unshelve econstructor. 23 | - econstructor. 24 | exact (@Empty_rec Type). 25 | - intros X; split. 26 | + intros _ []. 27 | + intros; exact tt. 28 | Defined. 29 | -------------------------------------------------------------------------------- /theories/Modalities/Notnot.v: -------------------------------------------------------------------------------- 1 | Require Import HoTT.Basics HoTT.Types Universes.HProp. 2 | Require Import Modality. 3 | 4 | Local Open Scope path_scope. 5 | 6 | (** * The double negation modality *) 7 | 8 | (** The operation sending [X] to [~~X] is a modality. This is Exercise 7.12 in the book. Note that it is (apparently) *not* accessible unless we assume propositional resizing. *) 9 | Definition NotNot `{Funext} : Modality. 10 | Proof. 11 | snapply easy_modality. 12 | - intros X; exact (~~X). 13 | - exact @not_not_unit. 14 | - cbn beta; intros A B f z nBz. 15 | apply z; intros a. 16 | exact (f a (transport (fun x => ~ (B x)) 17 | (path_ishprop _ _) 18 | nBz)). 19 | - cbn beta; intros A B f a. 20 | apply path_ishprop. 21 | - cbn beta; intros A z z'. 22 | refine (isequiv_iff_hprop _ _). 23 | intros; apply path_ishprop. 24 | Defined. 25 | 26 | (** By definition, the local types for this modality are the types such that [not_not_unit : P -> ~~P] is an equivalence. These are exactly the stable propositions, i.e. those propositions [P] such that [~~P -> P]. *) 27 | Definition inO_notnot `{Funext} (P : Type) 28 | : In NotNot P <~> (Stable P * IsHProp P) 29 | := equiv_isequiv_not_not_unit_stable_hprop P. 30 | -------------------------------------------------------------------------------- /theories/Pointed.v: -------------------------------------------------------------------------------- 1 | Require Export Pointed.Core. 2 | Require Export Pointed.Loops. 3 | Require Export Pointed.pMap. 4 | Require Export Pointed.pFiber. 5 | Require Export Pointed.pEquiv. 6 | Require Export Pointed.pTrunc. 7 | Require Export Pointed.pModality. 8 | Require Export Pointed.pSusp. 9 | Require Export Pointed.pSect. 10 | -------------------------------------------------------------------------------- /theories/Spaces/BinInt.v: -------------------------------------------------------------------------------- 1 | Require Export HoTT.Spaces.BinInt.Core. 2 | Require Export HoTT.Spaces.BinInt.Spec. 3 | Require Export HoTT.Spaces.BinInt.Equiv. 4 | Require Export HoTT.Spaces.BinInt.LoopExp. 5 | -------------------------------------------------------------------------------- /theories/Spaces/Cantor.v: -------------------------------------------------------------------------------- 1 | Require Import HoTT.Basics HoTT.Types. 2 | 3 | Local Open Scope nat_scope. 4 | Local Open Scope path_scope. 5 | 6 | (** * Cantor space 2^N *) 7 | 8 | Definition Cantor : Type := nat -> Bool. 9 | 10 | Definition cantor_fold : Cantor + Cantor -> Cantor. 11 | Proof. 12 | intros [c|c]; intros n. 13 | - destruct n as [|n]. 14 | + exact true. 15 | + exact (c n). 16 | - destruct n as [|n]. 17 | + exact false. 18 | + exact (c n). 19 | Defined. 20 | 21 | Definition cantor_unfold : Cantor -> Cantor + Cantor. 22 | Proof. 23 | intros c. 24 | case (c 0). 25 | - exact (inl (fun n => c n.+1)). 26 | - exact (inr (fun n => c n.+1)). 27 | Defined. 28 | 29 | Instance isequiv_cantor_fold `{Funext} : IsEquiv cantor_fold. 30 | Proof. 31 | refine (isequiv_adjointify _ cantor_unfold _ _). 32 | - intros c; apply path_arrow; intros n. 33 | induction n as [|n IH]. 34 | + unfold cantor_unfold. 35 | case (c 0); reflexivity. 36 | + unfold cantor_unfold. 37 | case (c 0); reflexivity. 38 | - intros [c|c]; apply path_sum; reflexivity. 39 | Defined. 40 | 41 | Definition equiv_cantor_fold `{Funext} : Cantor + Cantor <~> Cantor 42 | := Build_Equiv _ _ cantor_fold _. 43 | 44 | Definition equiv_cantor_unfold `{Funext} : Cantor <~> Cantor + Cantor 45 | := Build_Equiv _ _ cantor_unfold (isequiv_inverse equiv_cantor_fold). 46 | -------------------------------------------------------------------------------- /theories/Spaces/Finite.v: -------------------------------------------------------------------------------- 1 | Require Export Finite.Fin. 2 | Require Export Finite.FinNat. 3 | Require Export Finite.FinInduction. 4 | Require Export Finite.Finite. 5 | Require Export Finite.FinSeq. 6 | Require Export Finite.Tactics. 7 | -------------------------------------------------------------------------------- /theories/Spaces/Finite/Tactics.v: -------------------------------------------------------------------------------- 1 | Require Import HoTT.Basics Fin. 2 | 3 | (** ** Tactics *) 4 | 5 | Ltac FinIndOn X := repeat 6 | match type of X with 7 | | Fin 0 => destruct X 8 | | Empty => destruct X 9 | | Unit => destruct X 10 | | Fin ?n => destruct X as [X|X] 11 | | ?L + Unit => destruct X as [X|X] 12 | end. 13 | 14 | (** This tactic can be used to generate n cases from a goal like forall (x : Fin n), _ *) 15 | Ltac FinInd := let X := fresh "X" in intro X; FinIndOn X. 16 | -------------------------------------------------------------------------------- /theories/Spaces/Nat.v: -------------------------------------------------------------------------------- 1 | (** Nat.Paths has many dependencies, so if you do not need it, it is better to explicitly require only those files that you need. *) 2 | 3 | Require Export Nat.Core. 4 | Require Export Nat.Arithmetic. 5 | Require Export Nat.Division. 6 | Require Export Nat.Paths. 7 | Require Export Nat.Factorial. 8 | -------------------------------------------------------------------------------- /theories/Spaces/Nat/Paths.v: -------------------------------------------------------------------------------- 1 | Require Import Basics. 2 | Require Export Basics.Nat. 3 | Require Export HoTT.Universes.DProp. 4 | 5 | (** * Characterization of the path types of [nat] *) 6 | 7 | (** We characterize the path types of [nat]. We put this in its own file because it uses [DProp], which has a lot of dependencies. *) 8 | 9 | Local Set Universe Minimization ToSet. 10 | 11 | Local Close Scope trunc_scope. 12 | Local Open Scope nat_scope. 13 | 14 | Fixpoint code_nat (m n : nat) {struct m} : DHProp@{Set} := 15 | match m, n with 16 | | 0, 0 => True 17 | | m'.+1, n'.+1 => code_nat m' n' 18 | | _, _ => False 19 | end. 20 | 21 | Infix "=n" := code_nat : nat_scope. 22 | 23 | Fixpoint idcode_nat {n} : (n =n n) := 24 | match n as n return (n =n n) with 25 | | 0 => tt 26 | | S n' => @idcode_nat n' 27 | end. 28 | 29 | Fixpoint path_nat {n m} : (n =n m) -> (n = m) := 30 | match m as m, n as n return (n =n m) -> (n = m) with 31 | | 0, 0 => fun _ => idpath 32 | | m'.+1, n'.+1 => fun H : (n' =n m') => ap S (path_nat H) 33 | | _, _ => fun H => match H with end 34 | end. 35 | 36 | Instance isequiv_path_nat {n m} : IsEquiv (@path_nat n m). 37 | Proof. 38 | refine (isequiv_adjointify 39 | (@path_nat n m) 40 | (fun H => transport (fun m' => (n =n m')) H idcode_nat) 41 | _ _). 42 | { intros []; simpl. 43 | induction n; simpl; trivial. 44 | by destruct (IHn^)%path. } 45 | { intro. apply path_ishprop. } 46 | Defined. 47 | 48 | Definition equiv_path_nat {n m} : (n =n m) <~> (n = m) 49 | := Build_Equiv _ _ (@path_nat n m) _. 50 | -------------------------------------------------------------------------------- /theories/Spaces/No.v: -------------------------------------------------------------------------------- 1 | Require Export HoTT.Spaces.No.Core. 2 | Require Export HoTT.Spaces.No.Negation. 3 | Require Export HoTT.Spaces.No.Addition. 4 | -------------------------------------------------------------------------------- /theories/Spaces/Pos.v: -------------------------------------------------------------------------------- 1 | Require Export HoTT.Spaces.Pos.Core. 2 | Require Export HoTT.Spaces.Pos.Spec. -------------------------------------------------------------------------------- /theories/Spaces/Torus/TorusHomotopy.v: -------------------------------------------------------------------------------- 1 | Require Import Basics Types. 2 | Require Import Pointed WildCat. 3 | Require Import Modalities.ReflectiveSubuniverse Truncations.Core. 4 | Require Import Algebra.AbGroups. 5 | Require Import Homotopy.HomotopyGroup. 6 | Require Import Homotopy.PinSn. 7 | Require Import Spaces.Int Spaces.Circle. 8 | 9 | Require Import Spaces.Torus.Torus. 10 | Require Import Spaces.Torus.TorusEquivCircles. 11 | 12 | Local Open Scope trunc_scope. 13 | Local Open Scope pointed_scope. 14 | 15 | (** ** Fundamental group of the torus .*) 16 | 17 | (** The torus is 1-truncated *) 18 | 19 | Instance is1type_torus `{Univalence} : IsTrunc 1 Torus. 20 | Proof. 21 | exact (istrunc_equiv_istrunc _ equiv_torus_prod_Circle^-1). 22 | Qed. 23 | 24 | (** The torus is 0-connected *) 25 | 26 | Instance isconnected_torus `{Univalence} : IsConnected 0 Torus. 27 | Proof. 28 | srapply (isconnected_equiv' _ _ equiv_torus_prod_Circle^-1). 29 | srapply (isconnected_equiv' _ _ (equiv_sigma_prod0 _ _)). 30 | Qed. 31 | 32 | (** We give these notations for the pointed versions. *) 33 | Local Notation T := ([Torus, _]). 34 | Local Notation S1 := ([Circle, _]). 35 | 36 | (** A pointed version of the equivalence from TorusEquivCircles.v. *) 37 | (** TODO: If [Funext] is removed from there, remove it from here as well. *) 38 | Lemma pequiv_torus_prod_circles `{Funext} : T <~>* S1 * S1. 39 | Proof. 40 | srapply Build_pEquiv'. 41 | 1: exact equiv_torus_prod_Circle. 42 | reflexivity. 43 | Defined. 44 | 45 | (** Fundamental group of torus *) 46 | Theorem pi1_torus `{Univalence} 47 | : GroupIsomorphism (Pi 1 T) (grp_prod abgroup_Z abgroup_Z). 48 | Proof. 49 | etransitivity. 50 | 1: exact (emap (Pi 1) pequiv_torus_prod_circles). 51 | etransitivity. 52 | 1: apply grp_iso_pi_prod. 53 | apply grp_iso_prod. 54 | 1,2: exact pi1_circle. 55 | Defined. 56 | 57 | (** Loop space of torus *) 58 | Theorem loops_torus `{Univalence} : loops T <~>* Int * Int. 59 | Proof. 60 | (* Since [T] is 1-truncated, [loops T] is 0-truncated, and is therefore equivalent to its 0-truncation. *) 61 | refine (_ o*E pequiv_ptr (n:=0)). 62 | exact pi1_torus. 63 | Defined. 64 | -------------------------------------------------------------------------------- /theories/Spectra/Spectrum.v: -------------------------------------------------------------------------------- 1 | (** * Spectra *) 2 | 3 | Require Import HoTT.Basics HoTT.Types. 4 | Require Import Pointed. 5 | 6 | Local Open Scope nat_scope. 7 | Local Open Scope path_scope. 8 | Local Open Scope equiv_scope. 9 | Local Open Scope pointed_scope. 10 | 11 | (** ** Basic Definitions of Spectra *) 12 | 13 | Record Prespectrum := 14 | { deloop :> nat -> pType 15 | ; glue : forall n, deloop n ->* loops (deloop (n .+1)) }. 16 | 17 | Class IsSpectrum (E : Prespectrum) := 18 | is_equiv_glue :: forall n, IsEquiv (glue E n). 19 | 20 | Definition equiv_glue (E : Prespectrum) `{IsSpectrum E} 21 | : forall n, E n <~>* loops (E n.+1) 22 | := fun n => Build_pEquiv (glue E n) _. 23 | 24 | Record Spectrum := 25 | { to_prespectrum :> Prespectrum 26 | ; to_is_spectrum :: IsSpectrum to_prespectrum }. 27 | 28 | (** ** Truncations of spectra *) 29 | 30 | Definition strunc `{Univalence} (k : trunc_index) (E : Spectrum) : Spectrum. 31 | Proof. 32 | simple refine (Build_Spectrum (Build_Prespectrum (fun n => pTr (trunc_index_inc k n) (E n)) _) _). 33 | - intros n. 34 | exact ((ptr_loops _ (E n.+1)) o*E (pequiv_ptr_functor _ (equiv_glue E n))). 35 | - intros n. unfold glue. 36 | rapply isequiv_compose. 37 | Defined. 38 | -------------------------------------------------------------------------------- /theories/Tactics/Nameless.v: -------------------------------------------------------------------------------- 1 | Require Import Basics.Overture. 2 | (** * Building blocks for a globally nameless style of tactic reasoning *) 3 | 4 | (** ** [hyp] returns any hypothesis, with subsequent failures backtracking through all hypotheses *) 5 | Ltac hyp := multimatch goal with H : _ |- _ => constr:(H) end. 6 | 7 | (** ** [enforce foo] ensures that [foo] is well-typed *) 8 | Tactic Notation "enforce" open_constr(term) := idtac. 9 | 10 | (** ** [syntax_enforce [ H := body ]] ensures that [H] has a body which is syntactically equal to [body] *) 11 | Tactic Notation "syntax_enforce" "[" constr(H) ":=" open_constr(body) "]" := let H' := (eval unfold H in H) in constr_eq H' body. 12 | 13 | (** ** [enforce [ x = y ]] ensures that two terms, possibly containing holes, are judgmentally equal *) 14 | Tactic Notation "enforce" "[" open_constr(x) "=" open_constr(y) "]" := unify x y. 15 | 16 | (** An example *) 17 | Goal Empty -> let X0 := tt in Empty -> Unit. 18 | Proof. 19 | intros. 20 | let H := hyp in 21 | enforce (H : Unit); 22 | syntax_enforce [ H := tt ]; 23 | enforce [ H = _ ]; 24 | enforce [ _ = H ]; 25 | enforce [ H = tt ]. 26 | Abort. 27 | -------------------------------------------------------------------------------- /theories/Truncations.v: -------------------------------------------------------------------------------- 1 | Require Export HoTT.Truncations.Core. 2 | Require Export HoTT.Truncations.SeparatedTrunc. 3 | Require Export HoTT.Truncations.Connectedness. 4 | Require Export HoTT.Truncations.Constant. 5 | -------------------------------------------------------------------------------- /theories/Truncations/SeparatedTrunc.v: -------------------------------------------------------------------------------- 1 | Require Import Basics Types. 2 | Require Import TruncType. 3 | Require Import Truncations.Core Modalities.Modality Modalities.Descent. 4 | 5 | (** ** Separatedness and path-spaces of truncations *) 6 | 7 | Section SeparatedTrunc. 8 | 9 | Local Open Scope subuniverse_scope. 10 | 11 | (** The [n.+1]-truncation modality consists of the separated types for the [n]-truncation modality. *) 12 | #[export] Instance O_eq_Tr (n : trunc_index) 13 | : Tr n.+1 <=> Sep (Tr n). 14 | Proof. 15 | split; intros A A_inO. 16 | - intros x y; exact _. 17 | - rapply istrunc_S. 18 | Defined. 19 | 20 | (** It follows that [Tr n <<< Tr n.+1]. However, it is easier to prove this directly than to go through separatedness. *) 21 | #[export] Instance O_leq_Tr (n : trunc_index) 22 | : Tr n <= Tr n.+1. 23 | Proof. 24 | intros A ?; exact _. 25 | Defined. 26 | 27 | #[export] Instance O_strong_leq_Tr (n : trunc_index) 28 | : Tr n << Tr n.+1. 29 | Proof. 30 | srapply O_strong_leq_trans_l. 31 | Defined. 32 | 33 | (** For some reason, this causes typeclass search to spin. *) 34 | Local Instance O_lex_leq_Tr `{Univalence} (n : trunc_index) 35 | : Tr n <<< Tr n.+1. 36 | Proof. 37 | intros A; unshelve econstructor; intros P' P_inO; 38 | pose (P := fun x => Build_TruncType n (P' x)). 39 | - exact (Trunc_rec P). 40 | - intros; simpl; exact _. 41 | - intros; cbn. reflexivity. 42 | Defined. 43 | 44 | Definition path_Tr {n A} {x y : A} 45 | : Tr n (x = y) -> (tr x = tr y :> Tr n.+1 A) 46 | := path_OO (Tr n.+1) (Tr n) x y. 47 | 48 | Definition equiv_path_Tr `{Univalence} {n} {A : Type} (x y : A) 49 | : Tr n (x = y) <~> (tr x = tr y :> Tr n.+1 A) 50 | := equiv_path_OO (Tr n.+1) (Tr n) x y. 51 | 52 | End SeparatedTrunc. 53 | 54 | -------------------------------------------------------------------------------- /theories/Types.v: -------------------------------------------------------------------------------- 1 | Require Export Types.Unit. 2 | Require Export Types.Empty. 3 | Require Export Types.Paths. 4 | Require Export Types.Prod. 5 | Require Export Types.Forall. 6 | Require Export Types.Arrow. 7 | Require Export Types.Sigma. 8 | Require Export Types.Equiv. 9 | Require Export Types.Universe. 10 | Require Export Types.Bool. 11 | Require Export Types.Sum. 12 | Require Export Types.WType. 13 | Require Export Types.IWType. 14 | -------------------------------------------------------------------------------- /theories/Types/Option.v: -------------------------------------------------------------------------------- 1 | Require Import Basics.Overture. 2 | 3 | (** * Option types *) 4 | 5 | (** Option types are a simple way to represent a value that may or may not be present. They are also known as the Maybe monad in functional programming. *) 6 | 7 | (** [option] is functorial. *) 8 | Definition functor_option {A B} (f : A -> B) (x : option A) : option B := 9 | match x with 10 | | None => None 11 | | Some a => Some (f a) 12 | end. 13 | 14 | (** The [Some] constructor is injective. *) 15 | Definition isinj_some {A} {x y : A} (p : Some x = Some y) 16 | : x = y. 17 | Proof. 18 | injection p. 19 | exact idmap. 20 | Defined. 21 | -------------------------------------------------------------------------------- /theories/Types/WType.v: -------------------------------------------------------------------------------- 1 | Require Import HoTT.Basics. 2 | Require Import Types.Forall Types.Sigma. 3 | 4 | (** * Theorems about W-types (well-founded trees) *) 5 | 6 | Inductive W (A : Type) (B : A -> Type) : Type := 7 | w_sup (x : A) : (B x -> W A B) -> W A B. 8 | 9 | Definition w_label {A B} (w : W A B) : A := 10 | match w with 11 | | w_sup x y => x 12 | end. 13 | 14 | Definition w_arg {A B} (w : W A B) : B (w_label w) -> W A B := 15 | match w with 16 | | w_sup x y => y 17 | end. 18 | 19 | Definition issig_W (A : Type) (B : A -> Type) 20 | : _ <~> W A B := ltac:(issig). 21 | 22 | (** ** Paths *) 23 | 24 | Definition equiv_path_wtype {A B} (z z' : W A B) 25 | : (w_label z;w_arg z) = (w_label z';w_arg z') :> {a : _ & B a -> W A B} <~> z = z' 26 | := (equiv_ap' (issig_W A B)^-1%equiv z z')^-1%equiv. 27 | 28 | Definition equiv_path_wtype' {A B} (z z' : W A B) 29 | : {p : w_label z = w_label z' & w_arg z = w_arg z' o transport B p} 30 | <~> z = z'. 31 | Proof. 32 | refine (equiv_path_wtype _ _ oE equiv_path_sigma _ _ _ oE _). 33 | apply equiv_functor_sigma_id. 34 | destruct z as [z1 z2], z' as [z1' z2']. 35 | cbn; intros p. 36 | destruct p. 37 | reflexivity. 38 | Defined. 39 | 40 | (** ** W-types preserve truncation *) 41 | 42 | Instance istrunc_wtype `{Funext} 43 | {A B} {n : trunc_index} `{IsTrunc n.+1 A} 44 | : IsTrunc n.+1 (W A B) | 100. 45 | Proof. 46 | apply istrunc_S. 47 | intros z; induction z as [a w]. 48 | intro y; destruct y as [a0 w0]. 49 | nrefine (istrunc_equiv_istrunc _ (equiv_path_wtype' _ _)). 50 | rapply istrunc_sigma. 51 | cbn; intro p. 52 | destruct p. 53 | exact (istrunc_equiv_istrunc _ (equiv_path_forall _ _)). 54 | Defined. 55 | -------------------------------------------------------------------------------- /theories/Utf8Minimal.v: -------------------------------------------------------------------------------- 1 | Require Export Basics.Utf8 Basics.Overture Basics.Iff. 2 | 3 | (** * Just enough UTF8/Unicode for the Classes library to build, without depending on everything that HoTT.Utf8 depends on. *) 4 | 5 | (* Logic *) 6 | Notation "∀ x .. y , P" := (forall x, .. (forall y, P) ..) : type_scope. 7 | Notation "∃ x .. y , P" := (exists x, .. (exists y, P) ..) : type_scope. 8 | 9 | Notation "x ∧ y" := (x /\ y) : type_scope. 10 | Notation "x → y" := (x -> y) : type_scope. 11 | 12 | Notation "x ↔ y" := (x <-> y) : type_scope. 13 | (*Notation "¬ x" := (not x) : type_scope.*) 14 | (*Notation "x ≠ y" := (x <> y) : type_scope.*) 15 | 16 | (* Abstraction *) 17 | Notation "'λ' x .. y , t" := (fun x => .. (fun y => t) ..). 18 | -------------------------------------------------------------------------------- /theories/WildCat.v: -------------------------------------------------------------------------------- 1 | (* Theory *) 2 | Require Export WildCat.Adjoint. 3 | Require Export WildCat.Core. 4 | Require Export WildCat.Equiv. 5 | Require Export WildCat.Opposite. 6 | Require Export WildCat.Induced. 7 | Require Export WildCat.EquivGpd. 8 | Require Export WildCat.FunctorCat. 9 | Require Export WildCat.NatTrans. 10 | Require Export WildCat.Yoneda. 11 | Require Export WildCat.Square. 12 | Require Export WildCat.PointedCat. 13 | Require Export WildCat.Bifunctor. 14 | Require Export WildCat.Monoidal. 15 | Require Export WildCat.MonoidalTwistConstruction. 16 | Require Export WildCat.Products. 17 | Require Export WildCat.Coproducts. 18 | Require Export WildCat.Displayed. 19 | Require Export WildCat.DisplayedEquiv. 20 | 21 | (* See also contrib/SetoidRewrite.v for tools that can be used for rewriting in wild categories. *) 22 | 23 | (* Examples *) 24 | Require Export WildCat.Universe. 25 | Require Export WildCat.Paths. 26 | Require Export WildCat.UnitCat. 27 | Require Export WildCat.EmptyCat. 28 | Require Export WildCat.Prod. 29 | Require Export WildCat.Sum. 30 | Require Export WildCat.Forall. 31 | Require Export WildCat.Sigma. 32 | Require Export WildCat.Graph. 33 | Require Export WildCat.Category. 34 | Require Export WildCat.ZeroGroupoid. 35 | 36 | (* Higher categories *) 37 | Require Export WildCat.TwoOneCat. 38 | -------------------------------------------------------------------------------- /theories/WildCat/Category.v: -------------------------------------------------------------------------------- 1 | Require Import Basics.Overture. 2 | Require Import WildCat.Core WildCat.NatTrans WildCat.FunctorCat. 3 | 4 | (** * Category of categories *) 5 | 6 | (** TODO: make into a bicategory *) 7 | 8 | (** ** Definition *) 9 | 10 | (** A category is a [Type] together with a proof that it is a 1-category. *) 11 | Record Category := { 12 | category_carrier :> Type; 13 | isgraph_category_carrier :: IsGraph category_carrier; 14 | is01cat_category_carrier :: Is01Cat category_carrier; 15 | is2graph_category_carrier :: Is2Graph category_carrier; 16 | is1cat_category_carrier :: Is1Cat category_carrier 17 | }. 18 | 19 | (** Morphisms of categories are given by functors. *) 20 | Instance isgraph_cat : IsGraph Category 21 | := { Hom A B := Fun11 A B }. 22 | 23 | (** 2-morphisms of categories are given by natural transformations. *) 24 | Instance is2graph_cat : Is2Graph Category 25 | := fun A B => _. 26 | 27 | (** 3-morphisms of categories are given by "wild modifications" - the underlying data of a modification, subject to no coherence conditions. *) 28 | Instance is3graph_cat : Is3Graph Category 29 | := fun A B => _. 30 | -------------------------------------------------------------------------------- /theories/WildCat/EmptyCat.v: -------------------------------------------------------------------------------- 1 | Require Import Basics.Overture Basics.Tactics. 2 | Require Import WildCat.Core. 3 | 4 | (** Empty category *) 5 | 6 | Instance isgraph_empty : IsGraph Empty. 7 | Proof. 8 | by apply Build_IsGraph. 9 | Defined. 10 | 11 | Instance is01cat_empty : Is01Cat Empty. 12 | Proof. 13 | srapply Build_Is01Cat; intros []. 14 | Defined. 15 | 16 | Instance is0gpd_empty : Is0Gpd Empty. 17 | Proof. 18 | constructor; intros []. 19 | Defined. 20 | 21 | Instance is2graph_empty : Is2Graph Empty. 22 | Proof. 23 | intros f g. 24 | by apply Build_IsGraph. 25 | Defined. 26 | 27 | Instance is1cat_empty : Is1Cat Empty. 28 | Proof. 29 | snapply Build_Is1Cat; intros []. 30 | Defined. 31 | -------------------------------------------------------------------------------- /theories/WildCat/Forall.v: -------------------------------------------------------------------------------- 1 | Require Import Basics.Overture Basics.Tactics. 2 | Require Import WildCat.Core. 3 | 4 | (** ** Indexed product of categories *) 5 | 6 | Instance isgraph_forall (A : Type) (B : A -> Type) 7 | `{forall a, IsGraph (B a)} 8 | : IsGraph (forall a, B a). 9 | Proof. 10 | srapply Build_IsGraph. 11 | intros x y; exact (forall (a : A), x a $-> y a). 12 | Defined. 13 | 14 | Instance is01cat_forall (A : Type) (B : A -> Type) 15 | `{forall a, IsGraph (B a)} `{forall a, Is01Cat (B a)} 16 | : Is01Cat (forall a, B a). 17 | Proof. 18 | srapply Build_Is01Cat. 19 | + intros x a; exact (Id (x a)). 20 | + intros x y z f g a; exact (f a $o g a). 21 | Defined. 22 | 23 | Instance is0gpd_forall (A : Type) (B : A -> Type) 24 | (* Apparently when there's a [forall] there, Coq can't automatically add the [Is01Cat] instance from the [Is0Gpd] instance. *) 25 | `{forall a, IsGraph (B a)} `{forall a, Is01Cat (B a)} `{forall a, Is0Gpd (B a)} 26 | : Is0Gpd (forall a, B a). 27 | Proof. 28 | constructor. 29 | intros f g p a; exact ((p a)^$). 30 | Defined. 31 | 32 | Instance is2graph_forall (A : Type) (B : A -> Type) 33 | `{forall a, IsGraph (B a)} `{forall a, Is2Graph (B a)} 34 | : Is2Graph (forall a, B a). 35 | Proof. 36 | intros x y; srapply Build_IsGraph. 37 | intros f g; exact (forall a, f a $-> g a). 38 | Defined. 39 | 40 | Instance is1cat_forall (A : Type) (B : A -> Type) 41 | `{forall a, IsGraph (B a)} `{forall a, Is01Cat (B a)} 42 | `{forall a, Is2Graph (B a)} `{forall a, Is1Cat (B a)} 43 | : Is1Cat (forall a, B a). 44 | Proof. 45 | srapply Build_Is1Cat. 46 | + intros x y z h; srapply Build_Is0Functor. 47 | intros f g p a. 48 | exact (h a $@L p a). 49 | + intros x y z h; srapply Build_Is0Functor. 50 | intros f g p a. 51 | exact (p a $@R h a). 52 | + intros w x y z f g h a; apply cat_assoc. 53 | + intros w x y z f g h a; apply cat_assoc_opp. 54 | + intros x y f a; apply cat_idl. 55 | + intros x y f a; apply cat_idr. 56 | Defined. 57 | -------------------------------------------------------------------------------- /theories/WildCat/Graph.v: -------------------------------------------------------------------------------- 1 | Require Import Basics.Overture Basics.Tactics. 2 | Require Import WildCat.Core WildCat.NatTrans WildCat.FunctorCat. 3 | 4 | (** * Category of graphs *) 5 | 6 | (** ** Definition *) 7 | 8 | (** A graph is a [Type] together with a relation [$->]. *) 9 | Record Graph := { 10 | graph_carrier :> Type; 11 | isgraph_graph_carrier :: IsGraph graph_carrier 12 | }. 13 | 14 | (** ** Category of graphs *) 15 | 16 | (** Morphisms of graphs are 0-coherent 1-functors, i.e., maps between the underlying types of the graphs together with an [fmap] functorial map taking arrows to appropriate arrows. This is known as a graph homomorphism. *) 17 | Instance isgraph_graph : IsGraph Graph 18 | := { Hom A B := Fun01 A B }. 19 | 20 | (** A 2-cell between graph homomorphisms [F G : A $-> B] is a wild [Transformation], i.e., a family of 1-cells [forall x, F x $-> G x] subject to no coherence conditions. When [A] and [B] have more structure (e.g., they are 1-categories or bicategories) a stronger notion of 2-cell is appropriate, such as a (possibly lax or oplax) natural transformation.*) 21 | Instance is2graph_graph : Is2Graph Graph 22 | := fun A B => {| Hom F G := Transformation (fun01_F F) (fun01_F G) |}. 23 | 24 | (** We have identity graph homomorphisms together with compositions of graph homomorphisms. *) 25 | Instance is01cat_graph : Is01Cat Graph := { 26 | Id A := fun01_id; 27 | cat_comp A B C G F := fun01_compose G F 28 | }. 29 | -------------------------------------------------------------------------------- /theories/WildCat/Sigma.v: -------------------------------------------------------------------------------- 1 | Require Import Basics.Overture Basics.Tactics. 2 | Require Import WildCat.Core. 3 | 4 | (** ** Indexed sum of categories *) 5 | 6 | Section Sigma. 7 | 8 | Context (A : Type) (B : A -> Type) 9 | `{forall a, IsGraph (B a)} 10 | `{forall a, Is01Cat (B a)} 11 | `{forall a, Is0Gpd (B a)}. 12 | 13 | #[export] Instance isgraph_sigma : IsGraph (sig B). 14 | Proof. 15 | srapply Build_IsGraph. 16 | intros [x u] [y v]. 17 | exact {p : x = y & p # u $-> v}. 18 | Defined. 19 | 20 | #[export] Instance is01cat_sigma : Is01Cat (sig B). 21 | Proof. 22 | srapply Build_Is01Cat. 23 | + intros [x u]. 24 | exists idpath. exact (Id u). 25 | + intros [x u] [y v] [z w] [q g] [p f]. 26 | exists (p @ q). 27 | destruct p, q; cbn in *. 28 | exact (g $o f). 29 | Defined. 30 | 31 | #[export] Instance is0gpd_sigma : Is0Gpd (sig B). 32 | Proof. 33 | constructor. 34 | intros [x u] [y v] [p f]. 35 | exists (p^). 36 | destruct p; cbn in *. 37 | exact (f^$). 38 | Defined. 39 | 40 | End Sigma. 41 | 42 | Instance is0functor_sigma {A : Type} (B C : A -> Type) 43 | `{forall a, IsGraph (B a)} `{forall a, IsGraph (C a)} 44 | `{forall a, Is01Cat (B a)} `{forall a, Is01Cat (C a)} 45 | (F : forall a, B a -> C a) {ff : forall a, Is0Functor (F a)} 46 | : Is0Functor (fun (x:sig B) => (x.1 ; F x.1 x.2)). 47 | Proof. 48 | constructor; intros [a1 b1] [a2 b2] [p f]; cbn. 49 | exists p. 50 | destruct p; cbn in *. 51 | exact (fmap (F a1) f). 52 | Defined. 53 | -------------------------------------------------------------------------------- /theories/WildCat/UnitCat.v: -------------------------------------------------------------------------------- 1 | Require Import Basics.Overture Basics.Tactics. 2 | Require Import WildCat.Core. 3 | 4 | (** Unit category *) 5 | 6 | Instance isgraph_unit : IsGraph Unit. 7 | Proof. 8 | apply Build_IsGraph. 9 | intros; exact Unit. 10 | Defined. 11 | 12 | Instance is01cat_unit : Is01Cat Unit. 13 | Proof. 14 | srapply Build_Is01Cat. 15 | all: intros; exact tt. 16 | Defined. 17 | 18 | Instance is0gpd_unit : Is0Gpd Unit. 19 | Proof. 20 | constructor; intros; exact tt. 21 | Defined. 22 | 23 | Instance is2graph_unit : Is2Graph Unit 24 | := fun f g => isgraph_unit. 25 | 26 | Instance is1cat_unit : Is1Cat Unit. 27 | Proof. 28 | econstructor. 29 | 1,2:econstructor. 30 | all:intros; exact tt. 31 | Defined. 32 | -------------------------------------------------------------------------------- /theories/dune: -------------------------------------------------------------------------------- 1 | ; Tell dune to look through subdirectories 2 | 3 | (include_subdirs qualified) 4 | 5 | ; Main theory stanza telling dune how the HoTT library is compiled 6 | 7 | (coq.theory 8 | (name HoTT) 9 | (package coq-hott)) 10 | --------------------------------------------------------------------------------