From 567cee2d9c39b6e95d88eb00ada63713d5058654 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Tue, 1 Aug 2023 14:33:34 +0200 Subject: [PATCH 001/147] [refactor] separate add-mixin and make-mixin-canonical --- HB/instance.elpi | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/HB/instance.elpi b/HB/instance.elpi index 2eec1d08b..397e0482e 100644 --- a/HB/instance.elpi +++ b/HB/instance.elpi @@ -274,11 +274,11 @@ declare-instance Factory T F Clauses CSL :- (Clauses2 = []), std.append Clauses1 Clauses2 Clauses. -% [add-mixin T F _ M Cl] adds a constant being the mixin instance for M on type +% [add-mixin T F M Cl] adds a constant being the mixin instance for M on type % T built from factory F -pred add-mixin i:term, i:factoryname, i:bool, i:mixinname, - o:list prop, o:list (pair id constant). -add-mixin T FGR MakeCanon MissingMixin [MixinSrcCl, BuilderDeclCl] CSL :- std.do! [ +pred add-mixin i:term, i:factoryname, i:mixinname, + o:prop, o:prop, o:constant. +add-mixin T FGR MissingMixin MixinSrcCl BuilderDeclCl C :- std.do! [ new_int N, % timestamp synthesis.assert!-infer-mixin T MissingMixin Bo, @@ -297,23 +297,15 @@ add-mixin T FGR MakeCanon MissingMixin [MixinSrcCl, BuilderDeclCl] CSL :- std.do (Name is {gref->modname FGR 2 "_"} ^"__to__" ^ {gref->modname MixinName 2 "_"}, if-verbose (coq.say {header} "declare mixin instance" Name), log.coq.env.add-const-noimplicits Name Bo Ty @transparent! C), - if (MakeCanon = tt, whd (global (const C)) [] (global (indc _)) _) - (std.do! [ - if-verbose (coq.say {header} "declare canonical mixin instance" C), - with-locality (log.coq.CS.declare-instance C), - CSL = [pr "_" C] - ]) (CSL = []), ]. -pred add-all-mixins i:term, i:factoryname, i:list mixinname, i:bool, - o:list prop, o:list (pair id constant). -add-all-mixins T FGR ML MakeCanon Clauses CSL :- std.do! [ - std.map ML (m\ o\ sigma ClL CSL\ - add-mixin T FGR MakeCanon m ClL CSL, o = pr ClL CSL) ClLxCSL_L, - std.unzip ClLxCSL_L ClLL CSLL, - std.flatten ClLL Clauses, - std.flatten CSLL CSL -]. +pred add-all-mixins i:term, i:factoryname, i:list mixinname, + o:list prop, o:list constant. +add-all-mixins _T _FGR [] [] []. +add-all-mixins T FGR [M|ML] [MixinSrcCL,BuilderDeclCL | CL] [C|CC] :- std.do! [ + add-mixin T FGR M MixinSrcCL BuilderDeclCL C, + add-all-mixins T FGR ML CL CC, +]. % [postulate-arity A Acc T TS] postulates section variables % corresponding to parameters in arity A. TS is T applied @@ -342,12 +334,18 @@ pred declare-canonical-instances-from-factory-and-local-builders declare-canonical-instances-from-factory-and-local-builders Factory T F _TheFactory FGR Clauses CSL :- std.do! [ synthesis.under-new-mixin-src-from-factory.do! T F (NewMixins\ std.do! [ - add-all-mixins T FGR NewMixins ff Clauses MCSL, + add-all-mixins T FGR NewMixins Clauses _TheMixins, ]), list-w-params_list {factory-provides Factory} ML, - Clauses => declare-all T {findall-classes-for ML} CCSL, - std.append MCSL CCSL CSL + Clauses => instance.declare-all T {findall-classes-for ML} CSL, +]. + +pred make-mixin-canonical i:constant, o:option (pair id constant). +make-mixin-canonical C (some (pr "_" C)) :- whd (global (const C)) [] (global (indc _)) _, !, std.do! [ + if-verbose (coq.say {header} "declare canonical mixin instance" C), + with-locality (log.coq.CS.declare-instance C), ]. +make-mixin-canonical _ none. % [declare-canonical-instances-from-factory T F] given a factory F % it uses all known builders to declare canonical instances of structures @@ -362,11 +360,13 @@ declare-canonical-instances-from-factory Factory T F ClausesHas CSL :- std.do! [ synthesis.under-mixin-src-from-factory.do! T F [ synthesis.under-local-canonical-mixins-of.do! T [ list-w-params_list {factory-provides Factory} ML, - add-all-mixins T Factory ML tt Clauses MCSL, + add-all-mixins T Factory ML Clauses TheMixins, std.map-filter Clauses (mixin-src->has-mixin-instance ) ClausesHas, - ClausesHas => declare-all T {findall-classes-for ML} CCSL, % declare-all-on-type-constructor doesn't work here + ClausesHas => instance.declare-all T {findall-classes-for ML} CCSL, ] ], + std.map TheMixins make-mixin-canonical TheCanonicalMixins, + std.map-filter TheCanonicalMixins (x\r\x = some r) MCSL, std.append MCSL CCSL CSL ]. From 64525c72afd7d0eddc54912da57c938ce22d6672 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Wed, 2 Aug 2023 15:14:27 +0200 Subject: [PATCH 002/147] [instance] declare-instance -> declare-mixins-from-factory + declare-structure-instance-from-mixins NOTE: synthesis.under-local-canonical-mixins-of.do! is called twice now --- HB/common/synthesis.elpi | 10 +++++ HB/instance.elpi | 94 +++++++++++++++++++++++++++++++++++++--- tests/about.v | 2 +- tests/hnf.v | 18 -------- 4 files changed, 98 insertions(+), 26 deletions(-) delete mode 100644 tests/hnf.v diff --git a/HB/common/synthesis.elpi b/HB/common/synthesis.elpi index c596fc5c4..f6c105113 100644 --- a/HB/common/synthesis.elpi +++ b/HB/common/synthesis.elpi @@ -103,6 +103,16 @@ under-mixin-src-from-factory.do! TheType TheFactory LP :- std.do! [ MLClauses => std.do! LP ]. + +% Given TheType makes the provided list of mixins and instances +% available for inference. +pred under-these-mixin-src.do! i:term, i:list mixinname, i:list constant, i:list prop. +under-these-mixin-src.do! TheType ML TheMixins LP :- std.do! [ + std.map2 ML TheMixins (m\mi\c\ c = mixin-src TheType m (global (const mi))) MLClauses, + MLClauses => std.do! LP +]. + + % Given TheType and a factory instance (on it), builds all the *new* mixins % provided by the factory available for and passes them to the given % continuation diff --git a/HB/instance.elpi b/HB/instance.elpi index 397e0482e..0a0161c8d 100644 --- a/HB/instance.elpi +++ b/HB/instance.elpi @@ -66,13 +66,50 @@ declare-const Name BodySkel TyWPSkel CSL :- std.do! [ private.check-non-forgetful-inheritance TheType Factory, - private.declare-instance Factory TheType TheFactory Clauses CSL, - - % handle parameters via a section -- end - if (TyWP = arity _) true ( - if-verbose (coq.say {header} "closing instance section"), - log.coq.env.end-section-name SectionName - ), + if (current-mode (builder-from TheType TheFactoryForBuilderSection FGR _)) + % instance in a builder section %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + (std.do![ + if (get-option "local" tt) + (coq.error "HB: declare-instance: cannot make builders local. If you want temporary instances, make an alias, e.g. with let T' := T") true, + + private.declare-canonical-instances-from-factory-and-local-builders + Factory TheType TheFactory TheFactoryForBuilderSection FGR Clauses CSL, + + private.close-section-if-has-params TyWP SectionName, + ]) + % regular instance + (std.do![ + + % derive all mixins the factory provides + private.declare-mixins-from-factory Factory TheType TheFactory ML TheMixins, + + if true + % regular subject %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + (std.do![ + private.declare-structure-instance-from-mixins TheType ML TheMixins CCSL, + + % ?? should we do this also in the wrapper case, if so it lands below ?? + % 4 cyril: what are canonical-mixins? Why we want to export them? + std.map TheMixins private.make-mixin-canonical TheCanonicalMixins, + std.map-filter TheCanonicalMixins (x\r\x = some r) MCSL, + std.append MCSL CCSL CSL, + if (get-option "export" tt) + (coq.env.current-library File, + std.map CSL (x\r\ sigma i c\ x = pr i c, r = instance-to-export File i c) Clauses) + (Clauses = []), + + private.close-section-if-has-params TyWP SectionName, + ]) + % wrapper %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + (std.do![ + private.close-section-if-has-params TyWP SectionName, + private.wrap-mixins TheType ML TheMixins TheNewType WML TheWrappedMixins, + private.declare-structure-instance-from-mixins TheNewType WML TheWrappedMixins CSL, + Clauses = [] + ]), + + % ?? lands here ?? + ]), % we accumulate clauses now that the section is over acc-clauses current Clauses @@ -370,6 +407,49 @@ declare-canonical-instances-from-factory Factory T F ClausesHas CSL :- std.do! [ std.append MCSL CCSL CSL ]. +% [declare-mixins-from-factory T F] given a factory F +% it uses all known builders to declare canonical instances of structures +% on T +pred declare-mixins-from-factory + i:factoryname, i:term, i:term, o:list mixinname, o:list constant. +declare-mixins-from-factory Factory T F ML TheMixins :- std.do! [ + % The order of the following two "under...do!" is crucial, + % priority must be given to canonical mixins + % as they are the ones which guarantee forgetful inheritance + % hence we add these clauses last. + synthesis.under-mixin-src-from-factory.do! T F [ + synthesis.under-local-canonical-mixins-of.do! T [ + list-w-params_list {factory-provides Factory} ML, + add-all-mixins T Factory ML _ TheMixins, + ] + ], +]. + +pred wrap-mixins i:term, i:list mixinname, i:list constant, o:term, o:list mixinname, o:list constant. +wrap-mixins TheType ML TheMixins TheNewType WML TheWrappedMixins :- + coq.say TheType ML TheMixins TheNewType WML TheWrappedMixins. + +% [declare-structure-instance-from-mixins T ML MLI] given mixins ML and +% their implementation MLI declares all structure instances for T +pred declare-structure-instance-from-mixins i:term, i:list mixinname, i:list constant, o:list (pair id constant). +declare-structure-instance-from-mixins T ML TheMixins CL :- std.do! [ + % The order of the following two "under...do!" is crucial, + % priority must be given to canonical mixins + % as they are the ones which guarantee forgetful inheritance + % hence we add these clauses last. + synthesis.under-these-mixin-src.do! T ML TheMixins [ + synthesis.under-local-canonical-mixins-of.do! T [ + instance.declare-all T {findall-classes-for ML} CL, + ] + ], +]. + +pred close-section-if-has-params i:arity, i:id. +close-section-if-has-params (arity _) _ :- !. +close-section-if-has-params _ SectionName :- + if-verbose (coq.say {header} "closing instance section"), + log.coq.env.end-section-name SectionName. + % If you don't mention the factory in a builder, then Coq won't make % a lambda for it at section closing time. pred hack-section-discharging i:term, o:term. diff --git a/tests/about.v b/tests/about.v index a8971ab2b..0e114d234 100644 --- a/tests/about.v +++ b/tests/about.v @@ -46,7 +46,7 @@ HB.about hierarchy_5_Ring_class__to__hierarchy_5_SemiRing_class. HB.about hierarchy_5_Ring__to__hierarchy_5_SemiRing. (* builder *) -HB.about Builders_40.hierarchy_5_Ring_of_AddAG__to__hierarchy_5_BiNearRing_of_AddMonoid. +HB.about Builders_36.hierarchy_5_Ring_of_AddAG__to__hierarchy_5_BiNearRing_of_AddMonoid. HB.locate BinNums_Z__canonical__hierarchy_5_AddAG. diff --git a/tests/hnf.v b/tests/hnf.v deleted file mode 100644 index b219a6a82..000000000 --- a/tests/hnf.v +++ /dev/null @@ -1,18 +0,0 @@ -From HB Require Import structures. - -HB.mixin Record M A := { x: nat }. -HB.structure Definition S := { X of M X}. - -HB.factory Record f A := { y : nat }. -HB.builders Context T of f T. -HB.instance Definition _ := M.Build T (y + 1). -HB.end. - -#[hnf] HB.instance Definition _ := f.Build nat (3 + 2). -Print Datatypes_nat__canonical__hnf_S. -Print HB_unnamed_mixin_8. - -HB.instance Definition _ := f.Build bool (3 + 2). -Print Datatypes_bool__canonical__hnf_S. -Print HB_unnamed_mixin_12. - From e0f78951c337223841791e6211678b8174a7aa85 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Wed, 2 Aug 2023 15:23:06 +0200 Subject: [PATCH 003/147] document exported-op --- structures.v | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/structures.v b/structures.v index 027c14427..6c9891155 100644 --- a/structures.v +++ b/structures.v @@ -171,7 +171,9 @@ pred mixin-mem i:term, o:gref. % that contains the mixin M pred mixin-first-class o:mixinname, o:classname. -% memory of exported operations (TODO: document fiels) +% memory of exported operations. +% [exported-op Mixin MixinProjection Operation], where Operation is a +% structure projection. pred exported-op o:mixinname, o:constant, o:constant. % memory of factory sort coercion From 8c4071ca14d8b5fcfe9ce1e77eacbf9bf3401efe Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Wed, 2 Aug 2023 15:25:40 +0200 Subject: [PATCH 004/147] [instance] test for structure op as subject --- HB/instance.elpi | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/HB/instance.elpi b/HB/instance.elpi index 0a0161c8d..28fc5afcc 100644 --- a/HB/instance.elpi +++ b/HB/instance.elpi @@ -83,7 +83,7 @@ declare-const Name BodySkel TyWPSkel CSL :- std.do! [ % derive all mixins the factory provides private.declare-mixins-from-factory Factory TheType TheFactory ML TheMixins, - if true + if (not(private.is-structure-op TheType)) % regular subject %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% (std.do![ private.declare-structure-instance-from-mixins TheType ML TheMixins CCSL, @@ -450,6 +450,10 @@ close-section-if-has-params _ SectionName :- if-verbose (coq.say {header} "closing instance section"), log.coq.env.end-section-name SectionName. +pred is-structure-op i:term. +is-structure-op (global (const C)) :- exported-op _ _ C. +is-structure-op (app[global (const C)|_]) :- exported-op _ _ C. + % If you don't mention the factory in a builder, then Coq won't make % a lambda for it at section closing time. pred hack-section-discharging i:term, o:term. From 6128f447882a205e135d400cca8fcf69a3307b48 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Wed, 2 Aug 2023 15:29:47 +0200 Subject: [PATCH 005/147] comment --- HB/instance.elpi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/HB/instance.elpi b/HB/instance.elpi index 28fc5afcc..415e85b8e 100644 --- a/HB/instance.elpi +++ b/HB/instance.elpi @@ -105,6 +105,8 @@ declare-const Name BodySkel TyWPSkel CSL :- std.do! [ private.close-section-if-has-params TyWP SectionName, private.wrap-mixins TheType ML TheMixins TheNewType WML TheWrappedMixins, private.declare-structure-instance-from-mixins TheNewType WML TheWrappedMixins CSL, + + % 4 cyril Clauses = [] ]), From 1f8ca636a334f87dafe65e9847b64a9455438806 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Thu, 3 Aug 2023 10:28:38 +0200 Subject: [PATCH 006/147] add comment --- HB/instance.elpi | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/HB/instance.elpi b/HB/instance.elpi index 415e85b8e..86d734d8a 100644 --- a/HB/instance.elpi +++ b/HB/instance.elpi @@ -88,11 +88,13 @@ declare-const Name BodySkel TyWPSkel CSL :- std.do! [ (std.do![ private.declare-structure-instance-from-mixins TheType ML TheMixins CCSL, - % ?? should we do this also in the wrapper case, if so it lands below ?? - % 4 cyril: what are canonical-mixins? Why we want to export them? + % TODO: share between the two cases and put just after declare-mixins-from-factory + % since it talks about the unwrapped mixins std.map TheMixins private.make-mixin-canonical TheCanonicalMixins, std.map-filter TheCanonicalMixins (x\r\x = some r) MCSL, std.append MCSL CCSL CSL, + + % TODO: share to both branches, put below if (get-option "export" tt) (coq.env.current-library File, std.map CSL (x\r\ sigma i c\ x = pr i c, r = instance-to-export File i c) Clauses) From 2ce532bc210c02344f001e07b815fc0015f5b424 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Thu, 3 Aug 2023 11:06:58 +0200 Subject: [PATCH 007/147] wip-wrapping --- HB/common/utils-synterp.elpi | 1 + HB/factory.elpi | 51 +++++- HB/instance.elpi | 79 ++++++++- HB/structure.elpi | 28 +++ _CoqProject.test-suite | 1 + structures.v | 7 + tests/monoid_enriched_cat.v | 320 +++++++++++++++++++++++++++++++++++ 7 files changed, 480 insertions(+), 7 deletions(-) create mode 100644 tests/monoid_enriched_cat.v diff --git a/HB/common/utils-synterp.elpi b/HB/common/utils-synterp.elpi index 73932c1a4..7ce05ed31 100644 --- a/HB/common/utils-synterp.elpi +++ b/HB/common/utils-synterp.elpi @@ -24,6 +24,7 @@ with-attributes P :- att "primitive" bool, att "non_forgetful_inheritance" bool, att "hnf" bool, + att "wrapper" bool, ] Opts, !, Opts => (save-docstring, P). diff --git a/HB/factory.elpi b/HB/factory.elpi index 8ff726654..5e0005dab 100644 --- a/HB/factory.elpi +++ b/HB/factory.elpi @@ -219,6 +219,49 @@ declare-asset Arg AssetKind :- std.do! [ ) ]. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%% auxiliary code for wrapper-mixin + +pred extract_from_record_decl i: (term -> gref -> prop), i:indt-decl, o:gref. +extract_from_record_decl P (parameter ID _ _ R) Out :- + pi p\ + extract_from_record_decl P (R p) Out. +extract_from_record_decl P (record ID _ KID (field _ _ Ty (x\end-record))) GR0 :- + P Ty GR0. + +pred extract_from_rtty i: (term -> gref -> prop), i: term, o:gref. +extract_from_rtty P (prod _ _ TF) Out1 :- + pi p\ + extract_from_rtty P (TF p) Out1. +extract_from_rtty P Ty Gr :- P Ty Gr. + +pred xtr_fst_op i:term, o:gref. +xtr_fst_op Ty Gr1 :- + Ty = (app [global Gr0| _]), + factory-alias->gref Gr0 Gr1. + +pred xtr_snd_op i:term, o:gref. +xtr_snd_op Ty Gr :- + Ty = (app [global _, app [global Gr| _]]). + +pred extract_wrapped i:indt-decl, o:gref. +extract_wrapped In Out :- + extract_from_record_decl (extract_from_rtty xtr_fst_op) In Out. + +pred extract_subject i:indt-decl, o:gref. +extract_subject In Out :- + extract_from_record_decl (extract_from_rtty xtr_snd_op) In Out. + +pred wrapper_mixin_aux i:gref, o:gref, o:gref. +wrapper_mixin_aux XX Gr1 Gr2 :- + XX = (indt I), + coq.env.indt-decl I D, + extract_subject D Gr1, + extract_wrapped D Gr2. + +%%% end auxiliary code for wrapper-mixin +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + pred declare-mixin-or-factory i:list prop, i:list constant, i:list term, i:term, i:term, i:record-decl, i:list-w-params factoryname, i:id, i:asset. declare-mixin-or-factory MixinSrcClauses SectionCanonicalInstance @@ -255,6 +298,12 @@ declare-mixin-or-factory MixinSrcClauses SectionCanonicalInstance % TODO: should this be in the Exports module? + % if the wrapper option is on, build the wrapper clause + if (get-option "wrapper" tt) + ((wrapper_mixin_aux (indt R) NSbj WMxn), + (WrapperClauses = [wrapper-mixin (indt R) NSbj WMxn])) + (WrapperClauses = []), + if-verbose (coq.say {header} "declare notation Build"), GRDepsClauses => phant.of-gref ff GRK [] PhGRK, @@ -271,7 +320,7 @@ declare-mixin-or-factory MixinSrcClauses SectionCanonicalInstance if-verbose (coq.say {header} "start module Exports"), log.coq.env.begin-module "Exports" none, - std.flatten [Clauses, GRDepsClauses, [ + std.flatten [Clauses, GRDepsClauses, WrapperClauses, [ factory-constructor (indt R) GRK, factory-nparams (indt R) NParams, factory-builder-nparams BuildConst NParams, diff --git a/HB/instance.elpi b/HB/instance.elpi index 86d734d8a..8c1a129c5 100644 --- a/HB/instance.elpi +++ b/HB/instance.elpi @@ -105,8 +105,9 @@ declare-const Name BodySkel TyWPSkel CSL :- std.do! [ % wrapper %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% (std.do![ private.close-section-if-has-params TyWP SectionName, - private.wrap-mixins TheType ML TheMixins TheNewType WML TheWrappedMixins, - private.declare-structure-instance-from-mixins TheNewType WML TheWrappedMixins CSL, + coq.say "HERE" TheType, + std.spy(private.wrap-mixins TheType ML TheMixins TheNewType WML TheWrappedMixins), + std.spy(private.declare-structure-instance-from-mixins TheNewType WML TheWrappedMixins CSL), % 4 cyril Clauses = [] @@ -429,10 +430,6 @@ declare-mixins-from-factory Factory T F ML TheMixins :- std.do! [ ], ]. -pred wrap-mixins i:term, i:list mixinname, i:list constant, o:term, o:list mixinname, o:list constant. -wrap-mixins TheType ML TheMixins TheNewType WML TheWrappedMixins :- - coq.say TheType ML TheMixins TheNewType WML TheWrappedMixins. - % [declare-structure-instance-from-mixins T ML MLI] given mixins ML and % their implementation MLI declares all structure instances for T pred declare-structure-instance-from-mixins i:term, i:list mixinname, i:list constant, o:list (pair id constant). @@ -458,6 +455,76 @@ pred is-structure-op i:term. is-structure-op (global (const C)) :- exported-op _ _ C. is-structure-op (app[global (const C)|_]) :- exported-op _ _ C. + +pred derive-wrapper-instances i:term, i:prop, o:term, o:constant. +derive-wrapper-instances Instance (wrapper-mixin WrapperMixin Subject Mixin) + WrapperSubject C :- std.do! [ + + % K is the mixin constructor (Build) for WrapperMixin + factory-constructor WrapperMixin K, + factory-nparams WrapperMixin NParams, + std.assert! (NParams = 0) "TODO support parameters", + + % We are only interested in the last parameter of the constructor + % type, which is the current instance + % (which is a Mixin instance on the new Subject). + % In monoid_enriched_cat.v, we are targeting the code + % + % HB.instance Definition funQ_hom_isMon := + % hom_isMon.Axioms_ _ _ funQ_isMon. + % which Coq can compute to stand for + % hom_isMon.Axioms_ Type funQ funQ_isMon. + % + % We compute the number of the underscores and we pass + % them as arguments followed by Instance. + coq.env.typeof K KTy, + coq.count-prods KTy KN, + KN0 = KN - 1, + coq.mk-n-holes KN0 Holes, + + std.append Holes [Instance] Args, + + % the body of the new wrapper instance + NewInstance = app[global K| Args], + + std.assert-ok! (coq.typecheck NewInstance Ty) "declare-instances: mixin illtyped", + + if (Dgn = error S) + (coq.say "DWI! error in NewInstance" NewInstance "xxxx" S) + (coq.count-prods Ty N0, + coq.safe-dest-app Ty _Factory FArgs, + std.nth NParams FArgs WrapperSubject + ), + + Name is "wrapped__" ^ {std.any->string {new_int}}, + + log.coq.env.add-const-noimplicits Name NewInstance Ty @transparent! C + ]. + +pred wrap-a-mixin i:gref, i:mixinname, i:constant, o:term, o:mixinname, o:constant. +wrap-a-mixin TheTypeKeyGR M TheMixin TheNewType WM TheWrappedMixin :- + std.do! [ + std.findall (wrapper-mixin _ TheTypeKeyGR M) Wrappers, + if (Wrappers = [W|_]) + (W = wrapper-mixin WM TheTypeKeyGR M, + private.derive-wrapper-instances (global (const TheMixin)) W TheNewType TheWrappedMixin) + (coq.say "problem in wrap-a-mixin"), + ]. + +pred wrap-mixins i:term, i:list mixinname, i:list constant, + o:term, o:list mixinname, o:list constant. +wrap-mixins TheType [M | ML] [ TheMixin | TheMixins ] TheNewType [ WM | WML ] + [ TheWrappedMixin | TheWrappedMixins ] :- + coq.say TheType ML TheMixins TheNewType WML TheWrappedMixins, + coq.safe-dest-app TheType TheTypeKey _, + if (TheTypeKey = global TheTypeKeyGR) + (wrap-a-mixin TheTypeKeyGR M TheMixin TheNewType1 WM TheWrapperMixin, + std.assert! (TheNewType = TheNewType1) "wrapping to different subjects", + wrap-mixins TheType ML TheMixins TheNewType WML TheWrappedMixins) + (coq.say "problem in wrap-mixins"). +wrap-mixins _ [] [] _ [] []. + + % If you don't mention the factory in a builder, then Coq won't make % a lambda for it at section closing time. pred hack-section-discharging i:term, o:term. diff --git a/HB/structure.elpi b/HB/structure.elpi index be549496a..f6c5a8515 100644 --- a/HB/structure.elpi +++ b/HB/structure.elpi @@ -176,6 +176,11 @@ declare Module BSkel Sort :- std.do! [ log.coq.env.end-module-name ElpiOperationModName ElpiOperations, export.module ElpiOperationModName ElpiOperations, + % we need to filter the wrappers out of ML + std.filter ML (x\ wrapper-mixin x _ _) WrapperML, + % we need to assert locally the clauses in EX + EX => std.forall WrapperML private.reexport-wrapper-as-instance, + if-verbose (coq.say {header} "abbreviation factory-by-classname"), NewClauses => factory.declare-abbrev Module (factory.by-classname ClassName), @@ -631,4 +636,27 @@ sigT->list-w-params {{ lib:@hb.sigT _ lp:{{ fun N Ty B }} }} L C :- @pi-decl N Ty t\ product->triples (B t) (Rest t) C. +% M is the gref of the wrapper mixin. +% C gets now instantiated to the projection, i.e. hom_isMon_private. +% we need to count the parameters, we can get that from the type. +% we then can construct the instance, using +% instance.declare-const (notably used in the API, i.e. in structures.v, +% HB.instance) +pred reexport-wrapper-as-instance i:mixinname. +reexport-wrapper-as-instance M :- std.do! [ + + % need the body of the wrapper projection type + exported-op M _ C, + B = (global (const C)), + coq.env.typeof (const C) Ty, + coq.count-prods Ty N0, + coq.term->arity Ty N0 Arity, + + % need a recognisable valid idenfier for the derived instance + Str0 is "op_isMx" ^ "__" ^ {std.any->string {new_int}}, + std.string.concat "__" [Str0, "ELIM"] Str, + + instance.declare-const Str B Arity _ + ]. + }} diff --git a/_CoqProject.test-suite b/_CoqProject.test-suite index d60c9bb6c..12326e2fe 100644 --- a/_CoqProject.test-suite +++ b/_CoqProject.test-suite @@ -94,6 +94,7 @@ tests/unit/mk_src_map.v tests/unit/close_hole_term.v tests/unit/struct.v tests/factory_when_notation.v +tests/monoid_enriched_cat.v -R tests HB.tests -R examples HB.examples diff --git a/structures.v b/structures.v index 6c9891155..51cd4c501 100644 --- a/structures.v +++ b/structures.v @@ -160,6 +160,13 @@ pred join o:classname, o:classname, o:classname. % in order to discover two mixins are the same) pred mixin-mem i:term, o:gref. +% [wrapper-mixin Wrapper NewSubject WrappedMixin] +% #[wrapper] HB.mixin Record hom_isMon T of Quiver T := +% { private : forall A B, isMon (@hom T A B) }. +% --> +% wrapper-mixin (indt "hom_isMon") (const "hom") (indt "isMon"). +pred wrapper-mixin o:mixinname, o:gref, o:mixinname. + %%%%%% Memory of exported mixins (HB.structure) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Operations (named mixin fields) need to be exported exactly once, % but the same mixin can be used in many structure, hence this memory diff --git a/tests/monoid_enriched_cat.v b/tests/monoid_enriched_cat.v new file mode 100644 index 000000000..b10b6f6f6 --- /dev/null +++ b/tests/monoid_enriched_cat.v @@ -0,0 +1,320 @@ +From HB Require Import structures. +From Coq Require Import ssreflect ssrfun. + +HB.mixin Record isQuiver Obj := { hom : Obj -> Obj -> Type }. + +HB.structure Definition Quiver := { Obj of isQuiver Obj }. + +HB.mixin Record isMon A := { + zero : A; + add : A -> A -> A; + addrA : associative add; + add0r : left_id zero add; + addr0 : right_id zero add; + }. + +HB.structure + Definition Monoid := { A of isMon A }. + +(* This is expected to fail, as it isn't a mixin *) +Fail HB.structure + Definition Monoid_enriched_quiver := + { Obj of isQuiver Obj & + (forall A B : Obj, isMon (@hom (Quiver.clone Obj _) A B)) }. + +(* About zero. + Print zero. +*) +(* Step 0: define a wrapper predicate in coq-elpi *) +(* 5 lines of documentation + 1 line of elpi code in structure.v + `pred wrapper-mixin o:mixinname, o:gref, o:mixinname` +*) +(* Step 1: add a wrapper attribute to declare wrappers, + they should index: + - the wrapped mixin (`isMon`) + - the wrapper mixin (`hom_isMon`) + - the new subject (`hom`) + This attribute will add an entry in the `wrapper-mixin` database. + As an addition substep, we should check that the wrapper has + exactly one field, which is the wrapped mixin. + *) +(* added wrapper attribute in utils.elpi. + added pred wrapper-mixin in structures.v. + added conditional rule for wrapper-mixin in factory.elpi. +*) +#[wrapper] +HB.mixin Record hom_isMon T of Quiver T := + { hom_isMon_private : forall A B, isMon (@hom T A B) }. + +(* Print Canonical Projections. *) +(* About hom_isMon.hom_isMon_private. *) +(* About hom_isMon_private. *) + +(* Step 2: at structure declaration, export the main and only projection + of each declared wrapper as an instance of the wrapped structure on + its subject *) +#[verbose] HB.structure + Definition Monoid_enriched_quiver := + { Obj of isQuiver Obj & hom_isMon Obj }. + +(* About hom_isMon.hom_isMon_private. *) +(* About hom_isMon_private. *) + +(* as expected from step 2, now this instance declaration is no more necessay *) +(* + HB.instance Definition _ (T : Monoid_enriched_quiver.type) (A B : T) : isMon (@hom T A B) := + @hom_isMon_private T A B. +*) +(* each instance of isMon should be tried as an instance of hom_isMon *) +(* + (* Step 3: for each instance of a wrapped mixin on a subject known + to be wrapped, automatically produce an instance of the wrapper mixin too. *) + HB.instance Definition _ := isQuiver.Build Type (fun A B => A -> B). + Fail HB.instance Definition homTypeMon (A B : Quiver.type) := isMon.Build (hom A B) (* ... *). + (* This last command should create a `Monoid_enriched_quiver`, in order to do so it should + automatically instanciate the wrapper `hom_isMon`: + HB.instance Definition _ := hom_isMon.Build Type homTypeMon. + *) +*) + +(* Essentially, step 2 is the elimination rule for the wrapper, step 3 is the introduction one *) + +(* quiver instance (simply typed functions between two types) *) +(* Elpi Trace Browser. *) + +HB.instance Definition funQ := isQuiver.Build Type + (fun A B => A -> option B). + +(* Print Canonical Projections. *) + +(* prove that for every two types the quiver is a monoid *) + +Require Import FunctionalExtensionality. + +Definition funQ_comp {A B} (f g: A -> option B) (x: A) : option B := + match f x with + | Some _ => f x + | _ => g x end. + + (* + Program Definition funQ_isMonF_alt (A B: Type) : isMon (hom A B) := + isMon.Build (A -> option B) (fun (_:A) => None) funQ_comp _ _ _. + Obligations. + Obligation 1. + unfold associative; intros. + eapply functional_extensionality; intro a. + unfold funQ_comp. + destruct (x a) eqn:K1. + simpl; auto. + destruct (y a); auto. + Qed. + Obligation 2. + unfold left_id; intros. + unfold funQ_comp; auto. + Qed. + Obligation 3. + unfold right_id; intros. + eapply functional_extensionality; intro a. + unfold funQ_comp. + destruct (x a); auto. + Qed. +*) + +Program Definition funQ_isMonF (A B: Type) : isMon (A -> option B) := + isMon.Build (A -> option B) (fun (_:A) => None) funQ_comp _ _ _. +(* Obligations. *) +Obligation 1. +unfold associative; intros. +eapply functional_extensionality; intro a. +unfold funQ_comp. +destruct (x a) eqn:K1. +simpl; auto. +destruct (y a); auto. +Qed. +Obligation 2. +unfold left_id; intros. +unfold funQ_comp; auto. +Qed. +Obligation 3. +unfold right_id; intros. +eapply functional_extensionality; intro a. +unfold funQ_comp. +destruct (x a); auto. +Qed. + +(* +Print Canonical Projections. +*) + +(* +Fail Check (nat -> option nat) : Monoid.type. + +Check 1. + +Print Canonical Projections. + +Check 2. +Set Printing All. +*) + +(* use the lemma to instantiate isMon. Notice the genericity of the type. + In principle this instance should be derivable from the wrapper instance. + But since we haven't introduced the wrapper instance yet, we use this + HB command to actually introduce it. *) + +Check Type : Quiver.type. +Fail Check Type : Monoid_enriched_quiver.type. + +HB.instance Definition funQ_isMon (A B: Type) : isMon (hom A B) := + funQ_isMonF A B. + +Check Type : Monoid_enriched_quiver.type. + + + +(* Check (fun A B : Type => hom A B : Monoid.type). *) + +(* instantiate hom_isMon by using the generic isMon instance to define 'private' *) +(* HB.instance Definition funQ_hom_isMon := + hom_isMon.Build Type funQ_isMonF. + *) + +(* Print Canonical Projections. *) + +(* Check (fun A B : Type => hom A B : Monoid.type). *) + +(* HB.about private. *) +(* Print Canonical Projections. *) +(* this has to be changed, it should be something like (hom nat nat): + Check (nat -> option nat) : Monoid.type. *) +(* +HB.about funQ_isMonF. +Fail HB.about funQ_hom_isMon. +About funQ_hom_isMon. +*) + +Elpi Print HB.structure. + + +(**************************************************************) +(* Elpi code moved to factory.elpi *) +(* +Elpi Command x. +Elpi Accumulate File "HB/common/stdpp.elpi". +Elpi Accumulate File "HB/common/database.elpi". +Elpi Accumulate File "HB/common/utils.elpi". +Elpi Accumulate File "HB/status.elpi". +Elpi Accumulate Db hb.db. + +(* extracts isMon *) +Elpi Accumulate lp:{{ + +pred extract_ret_type_name i:term, o:gref. +extract_ret_type_name (prod _ _ TF) Out1 :- + pi p\ + extract_ret_type_name (TF p) Out1. +extract_ret_type_name Ty GR1 :- + Ty = app [global GR0| _], + factory-alias->gref GR0 GR1. + +pred extract_wrapped1 i:indt-decl, o:gref. +extract_wrapped1 (parameter ID _ _ R) Out :- + pi p\ + extract_wrapped1 (R p) Out. +extract_wrapped1 (record ID _ KID (field _ _ Ty (x\end-record))) GR0 :- + extract_ret_type_name Ty GR0. + +}}. +Elpi Typecheck. + +(* extracts hom *) +Elpi Accumulate lp:{{ + +pred extract_inner_type_name i:term, o:gref. +extract_inner_type_name (prod _ _ TF) Out1 :- + pi p\ + extract_inner_type_name (TF p) Out1. +extract_inner_type_name Ty Gr :- + Ty = (app [global _, app [global Gr| _]]). + +pred extract_subject1 i:indt-decl, o:gref. +extract_subject1 (parameter ID _ _ R) Out :- + pi p\ + extract_subject1 (R p) Out. +extract_subject1 (record ID _ KID (field _ _ Ty (x\end-record))) GR0 :- + extract_inner_type_name Ty GR0. + +}}. +Elpi Typecheck. + +(* better version, with predicate parameters *) +Elpi Accumulate lp:{{ + +pred extract_from_record_decl i: (term -> gref -> prop), i:indt-decl, o:gref. +extract_from_record_decl P (parameter ID _ _ R) Out :- + pi p\ + extract_from_record_decl P (R p) Out. +extract_from_record_decl P (record ID _ KID (field _ _ Ty (x\end-record))) GR0 :- + P Ty GR0. + +pred extract_from_rtty i: (term -> gref -> prop), i: term, o:gref. +extract_from_rtty P (prod _ _ TF) Out1 :- + pi p\ + extract_from_rtty P (TF p) Out1. +extract_from_rtty P Ty Gr :- P Ty Gr. + +pred xtr_fst_op i:term, o:gref. +xtr_fst_op Ty Gr1 :- + Ty = (app [global Gr0| _]), + factory-alias->gref Gr0 Gr1. + +pred xtr_snd_op i:term, o:gref. +xtr_snd_op Ty Gr :- + Ty = (app [global _, app [global Gr| _]]). + +pred extract_wrapped i:indt-decl, o:gref. +extract_wrapped In Out :- + extract_from_record_decl (extract_from_rtty xtr_fst_op) In Out. + +pred extract_subject i:indt-decl, o:gref. +extract_subject In Out :- + extract_from_record_decl (extract_from_rtty xtr_snd_op) In Out. + +pred wrapper_mixin_aux i:gref, o:gref, o:gref. +wrapper_mixin_aux XX Gr1 Gr2 :- + XX = (indt I), + coq.env.indt-decl I D, + extract_subject D Gr1, + extract_wrapped D Gr2. + +}}. +Elpi Typecheck. + +(*for debugging - check /tmp/traced.tmp.json with Elpi Tracer *) +(* Elpi Trace Browser. *) +(* Elpi Bound Steps 1000. *) + +(* OK *) +Elpi Query lp:{{ + + coq.locate "hom_isMon.axioms_" XX, + wrapper_mixin_aux XX Gr1 Gr2. + +}}. + +(* also OK *) +Elpi Query lp:{{ + + coq.locate "hom_isMon.axioms_" XX, + XX = (indt I), + coq.env.indt-decl I D, + extract_wrapped1 D GR11, + extract_subject1 D GR12. + +}}. + +Elpi Print HB.structure. + +stop. +*) + From f12d772276de63f480908911311b6c386948f045 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Thu, 3 Aug 2023 16:55:30 +0200 Subject: [PATCH 008/147] minor changes --- HB/instance.elpi | 50 +++++++++++++++++++++++++---------------------- HB/structure.elpi | 2 +- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/HB/instance.elpi b/HB/instance.elpi index 8c1a129c5..1bcd55e04 100644 --- a/HB/instance.elpi +++ b/HB/instance.elpi @@ -3,6 +3,7 @@ namespace instance { +% DEPRECATED % [declare-existing T F] equips T with all the canonical structures that can be % built using factory instance F pred declare-existing i:argument, i:argument. @@ -93,12 +94,6 @@ declare-const Name BodySkel TyWPSkel CSL :- std.do! [ std.map TheMixins private.make-mixin-canonical TheCanonicalMixins, std.map-filter TheCanonicalMixins (x\r\x = some r) MCSL, std.append MCSL CCSL CSL, - - % TODO: share to both branches, put below - if (get-option "export" tt) - (coq.env.current-library File, - std.map CSL (x\r\ sigma i c\ x = pr i c, r = instance-to-export File i c) Clauses) - (Clauses = []), private.close-section-if-has-params TyWP SectionName, ]) @@ -106,20 +101,27 @@ declare-const Name BodySkel TyWPSkel CSL :- std.do! [ (std.do![ private.close-section-if-has-params TyWP SectionName, coq.say "HERE" TheType, - std.spy(private.wrap-mixins TheType ML TheMixins TheNewType WML TheWrappedMixins), - std.spy(private.declare-structure-instance-from-mixins TheNewType WML TheWrappedMixins CSL), - - % 4 cyril - Clauses = [] + coq.safe-dest-app TheType TheTypeKey _, + if (TheTypeKey = global TheTypeKeyGR) + (std.spy(private.wrap-mixins TheTypeKeyGR ML TheMixins TheNewType WML TheWrappedMixins), + std.spy(private.declare-structure-instance-from-mixins TheNewType WML TheWrappedMixins CSL)) + (coq.say "problem in wrap-mixins"), ]), - % ?? lands here ?? + % DONE (?): shared to both branches, moved it below + if (get-option "export" tt) + (coq.env.current-library File, + std.map CSL (x\r\ sigma i c\ x = pr i c, r = instance-to-export File i c) Clauses) + (Clauses = []), + % 4 cyril + % Clauses = [], ]), % we accumulate clauses now that the section is over - acc-clauses current Clauses + acc-clauses current Clauses ]. + % [declare-all T CL MCSTL] given a type T and a list of class definition % CL in topological order (from least dep to most) looks for classes % for which all the dependencies (mixins) were postulated so far and skips the @@ -298,6 +300,7 @@ namespace private { shorten coq.{ term->gref, subst-fun, safe-dest-app, mk-app, mk-eta, subst-prod }. +% DEPRECATED pred declare-instance i:factoryname, i:term, i:term, o:list prop, o:list (pair id constant). declare-instance Factory T F Clauses CSL :- @@ -507,21 +510,22 @@ wrap-a-mixin TheTypeKeyGR M TheMixin TheNewType WM TheWrappedMixin :- std.findall (wrapper-mixin _ TheTypeKeyGR M) Wrappers, if (Wrappers = [W|_]) (W = wrapper-mixin WM TheTypeKeyGR M, - private.derive-wrapper-instances (global (const TheMixin)) W TheNewType TheWrappedMixin) + TM = global (const TheMixin), + private.derive-wrapper-instances TM W TheNewType TheWrappedMixin) (coq.say "problem in wrap-a-mixin"), ]. -pred wrap-mixins i:term, i:list mixinname, i:list constant, +pred wrap-mixins i:gref, i:list mixinname, i:list constant, o:term, o:list mixinname, o:list constant. -wrap-mixins TheType [M | ML] [ TheMixin | TheMixins ] TheNewType [ WM | WML ] +wrap-mixins TheTypeKeyGR [M | ML] [ TheMixin | TheMixins ] TheNewType [ WM | WML ] [ TheWrappedMixin | TheWrappedMixins ] :- - coq.say TheType ML TheMixins TheNewType WML TheWrappedMixins, - coq.safe-dest-app TheType TheTypeKey _, - if (TheTypeKey = global TheTypeKeyGR) - (wrap-a-mixin TheTypeKeyGR M TheMixin TheNewType1 WM TheWrapperMixin, - std.assert! (TheNewType = TheNewType1) "wrapping to different subjects", - wrap-mixins TheType ML TheMixins TheNewType WML TheWrappedMixins) - (coq.say "problem in wrap-mixins"). + coq.say TheTypeKeyGR M ML TheMixin TheMixins TheNewType WM WML TheWrappedMixin TheWrappedMixins, +% coq.safe-dest-app TheType TheTypeKey _, +% if (TheTypeKey = global TheTypeKeyGR) + wrap-a-mixin TheTypeKeyGR M TheMixin TheNewType1 WM TheWrapperMixin, + std.assert! (TheNewType = TheNewType1) "wrapping to different subjects", + wrap-mixins TheType ML TheMixins TheNewType WML TheWrappedMixins. +% (coq.say "problem in wrap-mixins"). wrap-mixins _ [] [] _ [] []. diff --git a/HB/structure.elpi b/HB/structure.elpi index f6c5a8515..92c893591 100644 --- a/HB/structure.elpi +++ b/HB/structure.elpi @@ -653,7 +653,7 @@ reexport-wrapper-as-instance M :- std.do! [ coq.term->arity Ty N0 Arity, % need a recognisable valid idenfier for the derived instance - Str0 is "op_isMx" ^ "__" ^ {std.any->string {new_int}}, + Str0 is "Op_isMx" ^ "__" ^ {std.any->string {new_int}}, std.string.concat "__" [Str0, "ELIM"] Str, instance.declare-const Str B Arity _ From d3273a4382f4be2b81c7e601418be7bcd403e5e2 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Thu, 3 Aug 2023 17:46:26 +0200 Subject: [PATCH 009/147] minor changes in instance.elpi --- HB/instance.elpi | 50 +++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/HB/instance.elpi b/HB/instance.elpi index 1bcd55e04..a302932b3 100644 --- a/HB/instance.elpi +++ b/HB/instance.elpi @@ -86,27 +86,9 @@ declare-const Name BodySkel TyWPSkel CSL :- std.do! [ if (not(private.is-structure-op TheType)) % regular subject %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - (std.do![ - private.declare-structure-instance-from-mixins TheType ML TheMixins CCSL, - - % TODO: share between the two cases and put just after declare-mixins-from-factory - % since it talks about the unwrapped mixins - std.map TheMixins private.make-mixin-canonical TheCanonicalMixins, - std.map-filter TheCanonicalMixins (x\r\x = some r) MCSL, - std.append MCSL CCSL CSL, - - private.close-section-if-has-params TyWP SectionName, - ]) + (private.declare-regular-inst TheType ML TheMixins TyWP SectionName CSL) % wrapper %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - (std.do![ - private.close-section-if-has-params TyWP SectionName, - coq.say "HERE" TheType, - coq.safe-dest-app TheType TheTypeKey _, - if (TheTypeKey = global TheTypeKeyGR) - (std.spy(private.wrap-mixins TheTypeKeyGR ML TheMixins TheNewType WML TheWrappedMixins), - std.spy(private.declare-structure-instance-from-mixins TheNewType WML TheWrappedMixins CSL)) - (coq.say "problem in wrap-mixins"), - ]), + (private.declare-wrapper-inst TheType ML TheMixins TyWP SectionName CSL), % DONE (?): shared to both branches, moved it below if (get-option "export" tt) @@ -121,7 +103,6 @@ declare-const Name BodySkel TyWPSkel CSL :- std.do! [ acc-clauses current Clauses ]. - % [declare-all T CL MCSTL] given a type T and a list of class definition % CL in topological order (from least dep to most) looks for classes % for which all the dependencies (mixins) were postulated so far and skips the @@ -454,11 +435,36 @@ close-section-if-has-params _ SectionName :- if-verbose (coq.say {header} "closing instance section"), log.coq.env.end-section-name SectionName. +pred declare-regular-inst i:term, i:list mixinname, i:list constant, i:arity, i:id, + o:list (pair id constant). +declare-regular-inst TheType ML TheMixins TyWP SectionName CSL :- std.do![ + private.declare-structure-instance-from-mixins TheType ML TheMixins CCSL, + + % TODO: share between the two cases and put just after declare-mixins-from-factory + % since it talks about the unwrapped mixins + std.map TheMixins private.make-mixin-canonical TheCanonicalMixins, + std.map-filter TheCanonicalMixins (x\r\x = some r) MCSL, + std.append MCSL CCSL CSL, + + private.close-section-if-has-params TyWP SectionName, +]. + +pred declare-wrapper-inst i:term, i:list mixinname, i:list constant, i:arity, i:id, + o:list (pair id constant). +declare-wrapper-inst TheType ML TheMixins TyWP SectionName CSL :- std.do![ + private.close-section-if-has-params TyWP SectionName, + coq.say "HERE" TheType, + coq.safe-dest-app TheType TheTypeKey _, + if (TheTypeKey = global TheTypeKeyGR) + (std.spy(private.wrap-mixins TheTypeKeyGR ML TheMixins TheNewType WML TheWrappedMixins), + std.spy(private.declare-structure-instance-from-mixins TheNewType WML TheWrappedMixins CSL)) + (coq.say "problem in wrap-mixins") +]. + pred is-structure-op i:term. is-structure-op (global (const C)) :- exported-op _ _ C. is-structure-op (app[global (const C)|_]) :- exported-op _ _ C. - pred derive-wrapper-instances i:term, i:prop, o:term, o:constant. derive-wrapper-instances Instance (wrapper-mixin WrapperMixin Subject Mixin) WrapperSubject C :- std.do! [ From 894aff0691054024533956977c67062277aa03ad Mon Sep 17 00:00:00 2001 From: ptorrx Date: Thu, 3 Aug 2023 18:18:00 +0200 Subject: [PATCH 010/147] introduced derived instance check in instance.elpi (as a hack); still not working --- HB/instance.elpi | 24 ++++++++++++++---------- HB/structure.elpi | 6 ++++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/HB/instance.elpi b/HB/instance.elpi index a302932b3..af9dd1060 100644 --- a/HB/instance.elpi +++ b/HB/instance.elpi @@ -84,20 +84,24 @@ declare-const Name BodySkel TyWPSkel CSL :- std.do! [ % derive all mixins the factory provides private.declare-mixins-from-factory Factory TheType TheFactory ML TheMixins, - if (not(private.is-structure-op TheType)) - % regular subject %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + if (RealName = "wrapper__ELIM") % meant to rule out generated instances + % if (rex.match "*__ELIM" RealName) % meant to rule out generated instances (private.declare-regular-inst TheType ML TheMixins TyWP SectionName CSL) - % wrapper %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - (private.declare-wrapper-inst TheType ML TheMixins TyWP SectionName CSL), - - % DONE (?): shared to both branches, moved it below - if (get-option "export" tt) - (coq.env.current-library File, + (if (not(private.is-structure-op TheType)) + % regular subject %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + (private.declare-regular-inst TheType ML TheMixins TyWP SectionName CSL) + % wrapper %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + (private.declare-wrapper-inst TheType ML TheMixins TyWP SectionName CSL) + ), + + % DONE (?): shared to both branches, moved it below + if (get-option "export" tt) + (coq.env.current-library File, std.map CSL (x\r\ sigma i c\ x = pr i c, r = instance-to-export File i c) Clauses) - (Clauses = []), + (Clauses = []), % 4 cyril % Clauses = [], - ]), + ]), % we accumulate clauses now that the section is over acc-clauses current Clauses diff --git a/HB/structure.elpi b/HB/structure.elpi index 92c893591..6a809c5f1 100644 --- a/HB/structure.elpi +++ b/HB/structure.elpi @@ -653,9 +653,11 @@ reexport-wrapper-as-instance M :- std.do! [ coq.term->arity Ty N0 Arity, % need a recognisable valid idenfier for the derived instance - Str0 is "Op_isMx" ^ "__" ^ {std.any->string {new_int}}, - std.string.concat "__" [Str0, "ELIM"] Str, + % Str0 is "Op_isMx" ^ "__" ^ {std.any->string {new_int}}, + % std.string.concat "__" [Str0, "ELIM"] Str, + std.string.concat "__" ["wrapper", "ELIM"] Str, + instance.declare-const Str B Arity _ ]. From 1ecb63402dffd2145a488e88b8f526984cd6d5a4 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Fri, 4 Aug 2023 10:35:12 +0200 Subject: [PATCH 011/147] fixed bugs in instance.elpi, compiles --- HB/instance.elpi | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/HB/instance.elpi b/HB/instance.elpi index af9dd1060..6e460c190 100644 --- a/HB/instance.elpi +++ b/HB/instance.elpi @@ -33,7 +33,7 @@ declare-const Name BodySkel TyWPSkel CSL :- std.do! [ % Do not open a section when it is not necessary (no parameters) % A side effect of opening a section is loosing meta data associated % with instances, in particular builder tags are lost - if-verbose (coq.say "HB: skipping section opening"), + if-verbose (coq.say "HB!: skipping section opening"), SectionBody = Body ) ( std.assert! (coq.next-synterp-action (begin-section SectionName)) "synterp code did not open section", @@ -84,8 +84,8 @@ declare-const Name BodySkel TyWPSkel CSL :- std.do! [ % derive all mixins the factory provides private.declare-mixins-from-factory Factory TheType TheFactory ML TheMixins, - if (RealName = "wrapper__ELIM") % meant to rule out generated instances - % if (rex.match "*__ELIM" RealName) % meant to rule out generated instances + % if (RealName = "wrapper__ELIM") % meant to rule out generated instances + if (rex.match ".*__ELIM" RealName) % meant to rule out generated instances (private.declare-regular-inst TheType ML TheMixins TyWP SectionName CSL) (if (not(private.is-structure-op TheType)) % regular subject %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -457,7 +457,7 @@ pred declare-wrapper-inst i:term, i:list mixinname, i:list constant, i:arity, i: o:list (pair id constant). declare-wrapper-inst TheType ML TheMixins TyWP SectionName CSL :- std.do![ private.close-section-if-has-params TyWP SectionName, - coq.say "HERE" TheType, + coq.say "HERE!" TheType, coq.safe-dest-app TheType TheTypeKey _, if (TheTypeKey = global TheTypeKeyGR) (std.spy(private.wrap-mixins TheTypeKeyGR ML TheMixins TheNewType WML TheWrappedMixins), @@ -470,7 +470,7 @@ is-structure-op (global (const C)) :- exported-op _ _ C. is-structure-op (app[global (const C)|_]) :- exported-op _ _ C. pred derive-wrapper-instances i:term, i:prop, o:term, o:constant. -derive-wrapper-instances Instance (wrapper-mixin WrapperMixin Subject Mixin) +derive-wrapper-instances Instance (wrapper-mixin WrapperMixin _Subject _Mixin) WrapperSubject C :- std.do! [ % K is the mixin constructor (Build) for WrapperMixin @@ -500,7 +500,7 @@ derive-wrapper-instances Instance (wrapper-mixin WrapperMixin Subject Mixin) % the body of the new wrapper instance NewInstance = app[global K| Args], - std.assert-ok! (coq.typecheck NewInstance Ty) "declare-instances: mixin illtyped", + coq.typecheck NewInstance Ty Dgn, if (Dgn = error S) (coq.say "DWI! error in NewInstance" NewInstance "xxxx" S) @@ -532,9 +532,9 @@ wrap-mixins TheTypeKeyGR [M | ML] [ TheMixin | TheMixins ] TheNewType [ WM | WML coq.say TheTypeKeyGR M ML TheMixin TheMixins TheNewType WM WML TheWrappedMixin TheWrappedMixins, % coq.safe-dest-app TheType TheTypeKey _, % if (TheTypeKey = global TheTypeKeyGR) - wrap-a-mixin TheTypeKeyGR M TheMixin TheNewType1 WM TheWrapperMixin, + wrap-a-mixin TheTypeKeyGR M TheMixin TheNewType1 WM TheWrappedMixin, std.assert! (TheNewType = TheNewType1) "wrapping to different subjects", - wrap-mixins TheType ML TheMixins TheNewType WML TheWrappedMixins. + wrap-mixins TheTypeKeyGR ML TheMixins TheNewType WML TheWrappedMixins. % (coq.say "problem in wrap-mixins"). wrap-mixins _ [] [] _ [] []. @@ -589,7 +589,7 @@ check-non-forgetful-inheritance T Factory :- std.do! [ if (coq.safe-dest-app T (global (const HdSym)) _, structure-key HdSym _ Super) ( coq.warning "HB" "HB.non-forgetful-inheritance" "non forgetful inheritance detected.\n" - "You have two solutions:" + "You have two solutions: " "1. (Best practice) Reorganize your hierarchy to make" {nice-gref->string Factory} "depend on" From cb3d53ae6c69d3ee0a79bb75e6c9a3d8d2474a1c Mon Sep 17 00:00:00 2001 From: ptorrx Date: Fri, 4 Aug 2023 13:35:34 +0200 Subject: [PATCH 012/147] minor changes --- HB/instance.elpi | 13 ++++++------- HB/structure.elpi | 6 ++---- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/HB/instance.elpi b/HB/instance.elpi index 6e460c190..5d24f3cd7 100644 --- a/HB/instance.elpi +++ b/HB/instance.elpi @@ -78,15 +78,16 @@ declare-const Name BodySkel TyWPSkel CSL :- std.do! [ private.close-section-if-has-params TyWP SectionName, ]) - % regular instance + % instance in regular section %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% (std.do![ % derive all mixins the factory provides private.declare-mixins-from-factory Factory TheType TheFactory ML TheMixins, - % if (RealName = "wrapper__ELIM") % meant to rule out generated instances - if (rex.match ".*__ELIM" RealName) % meant to rule out generated instances - (private.declare-regular-inst TheType ML TheMixins TyWP SectionName CSL) + if (rex.match ".*__ELIM" RealName) + % derived instance %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + (private.declare-regular-inst TheType ML TheMixins TyWP SectionName CSL) + % regular instance %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% (if (not(private.is-structure-op TheType)) % regular subject %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% (private.declare-regular-inst TheType ML TheMixins TyWP SectionName CSL) @@ -94,13 +95,11 @@ declare-const Name BodySkel TyWPSkel CSL :- std.do! [ (private.declare-wrapper-inst TheType ML TheMixins TyWP SectionName CSL) ), - % DONE (?): shared to both branches, moved it below + % shared to all branches if (get-option "export" tt) (coq.env.current-library File, std.map CSL (x\r\ sigma i c\ x = pr i c, r = instance-to-export File i c) Clauses) (Clauses = []), - % 4 cyril - % Clauses = [], ]), % we accumulate clauses now that the section is over diff --git a/HB/structure.elpi b/HB/structure.elpi index 6a809c5f1..1bcf78440 100644 --- a/HB/structure.elpi +++ b/HB/structure.elpi @@ -653,10 +653,8 @@ reexport-wrapper-as-instance M :- std.do! [ coq.term->arity Ty N0 Arity, % need a recognisable valid idenfier for the derived instance - % Str0 is "Op_isMx" ^ "__" ^ {std.any->string {new_int}}, - % std.string.concat "__" [Str0, "ELIM"] Str, - - std.string.concat "__" ["wrapper", "ELIM"] Str, + Str0 is "Op_isMx" ^ "__" ^ {std.any->string {new_int}}, + std.string.concat "__" [Str0, "ELIM"] Str, instance.declare-const Str B Arity _ ]. From 2fc666232aa65b4f8a71966e6800be41a0435618 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Thu, 10 Aug 2023 14:38:20 +0200 Subject: [PATCH 013/147] added and updated cmon_enriched_cat.v - this file contains three examples; there's an unsolved compilation glitch (it will compile the 2nd and 3rd examples separately but not together, depending on which we put first) --- tests/cmonoid_enriched_cat.v | 634 +++++++++++++++++++++++++++++++++++ 1 file changed, 634 insertions(+) create mode 100644 tests/cmonoid_enriched_cat.v diff --git a/tests/cmonoid_enriched_cat.v b/tests/cmonoid_enriched_cat.v new file mode 100644 index 000000000..a9325fc60 --- /dev/null +++ b/tests/cmonoid_enriched_cat.v @@ -0,0 +1,634 @@ +From HB Require Import structures. +From Coq Require Import ssreflect ssrfun. + +(** Quiver *) + +HB.mixin Record isQuiver Obj := { hom : Obj -> Obj -> Type }. + +HB.structure Definition Quiver := { Obj of isQuiver Obj }. + +(** Ohter base mixins *) + +HB.mixin Record isMon A := { + zero : A; + add : A -> A -> A; + addrA : associative add; + add0r : left_id zero add; + addr0 : right_id zero add; + }. + +HB.mixin Record isIAlg A := { + iadd : A -> A -> A; + iaddI : idempotent iadd; + }. + +HB.mixin Record isCAlg A := { + cadd : A -> A -> A; + caddrC : commutative cadd; + }. + +(** Base structures *) + +HB.structure Definition Monoid := { A of isMon A }. + +HB.structure Definition CAlgebra := { A of isCAlg A }. + +HB.structure Definition IAlgebra := { A of isIAlg A }. + +(** Complex mixins *) + +(*******************************************************************) +(********** Combining mixins ***************************************) + +(***** Vanilla Coq (no HB) *) + +Record isMon0 A := { + zero0 : A; + add0 : A -> A -> A; + addrA0 : associative add0; + add0r0 : left_id zero0 add0; + addr00 : right_id zero0 add0; + }. + +Record isIAlg0 A := { + iadd0 : A -> A -> A; + iaddI0 : idempotent iadd0; + }. + +Record isIMon0 A := { is_mon0 : isMon0 A; + is_ialg0 : isIAlg0 A; + mon_ialg_ch0 : add0 _ is_mon0 = iadd0 _ is_ialg0 ; + }. + + +(***** The analogous of vanilla does not work in HB *) + +Fail HB.mixin Record isIMonM A := { is_mon : isMon A; + is_ialg : isIAlg A; + mon_ialg_ch : add _ is_mon = iadd _ is_ialg ; + }. + +Fail HB.mixin Record isIMonS A := { is_mon : Monoid A; + is_ialg : IAlgebra A; + mon_ialg_ch : add _ is_mon = iadd _ is_ialg ; + }. + +(***** Basic approach (can be cumbersome) *) + +HB.mixin Record isIMonB A := { + zero : A; + add : A -> A -> A; + addrA : associative add; + add0r : left_id zero add; + addr0 : right_id zero add; + addI : idempotent add; +}. + +HB.mixin Record isCMonB A := { + zero : A; + add : A -> A -> A; + addrA : associative add; + add0r : left_id zero add; + addr0 : right_id zero add; + addC : commutative add; +}. + + +(***** Operator mixins *) + +(**** single dependent pair parameter *) + +HB.mixin Record isOpMon1 (S: sigT (fun A => A -> A -> A)) := { + zero : projT1 S; + addrA : associative (projT2 S); + add0r : left_id zero (projT2 S); + addr0 : right_id zero (projT2 S); + }. + +HB.structure Definition OpMonoid1 := { C of isOpMon1 C }. + +HB.mixin Record isOpIAlg1 (S: sigT (fun A => A -> A -> A)) := { + addI : idempotent (projT2 S); + }. + +HB.structure Definition OpIAlgebra1 := { C of isOpIAlg1 C }. + +HB.mixin Record isOpIMon1 A of OpMonoid1 A & OpIAlgebra1 A. + + +(**** two parameters (subject is Add) *) + +(**) +HB.mixin Record isOpAAlg2 A (Add: A -> A -> A) := { + addA : associative Add; + }. + +HB.mixin Record isOpAAlgebra2 A := { add: A -> A -> A; + is_op_aalg : isOpAAlg2 A add }. + +HB.structure Definition OpAAlgebra2 := { A of isOpAAlgebra2 A }. + +(**) +HB.mixin Record isOpZAlg2 A (Add: A -> A -> A) (Zero: A) := { + add0r : left_id Zero Add; + addr0 : right_id Zero Add; + }. + +HB.mixin Record isOpZAlgebra2 A := { add: A -> A -> A; + zero: A; + is_op_zalg : isOpZAlg2 A add zero }. + +HB.structure Definition OpZAlgebra2 := { A of isOpZAlgebra2 A }. + +(**) +HB.mixin Record isOpMon2 A (Add: A -> A -> A) (Zero: A) := { + is_op_zalg : isOpZAlg2 A Add Zero ; + is_op_aalg : isOpAAlg2 A Add ; + }. + +HB.mixin Record isOpMonoid2 A := { add: A -> A -> A; + zero: A; + is_op_mon : isOpMon2 A add zero }. + +HB.structure Definition OpMonoid2 := { A of isOpMonoid2 A }. + +(**) +HB.mixin Record isOpIAlg2 A (Add: A -> A -> A) := { + addI : idempotent Add; + }. + +HB.mixin Record isOpIAlgebra2 A := { add: A -> A -> A; + is_op_ialg : isOpIAlg2 A add }. + +HB.structure Definition OpIAlgebra2 := { A of isOpIAlgebra2 A }. + +(**) +HB.mixin Record isOpCAlg2 A (Add: A -> A -> A) := { + addC : commutative Add; + }. + +HB.mixin Record isOpCAlgebra2 A := { add: A -> A -> A; + is_op_calg : isOpCAlg2 A add }. + +HB.structure Definition OpCAlgebra2 := { A of isOpCAlgebra2 A }. + +(**) +HB.mixin Record isOpIMon2 A (Add: A -> A -> A) (Zero: A) := { + is_op_mon : isOpMon2 A Add Zero ; + is_op_ialg : isOpIAlg2 A Add ; + }. + +HB.mixin Record isOpIMonoid2 A := { add: A -> A -> A; + zero: A; + is_op_imon : isOpIMon2 A add zero }. + +HB.structure Definition OpIMonoid2 := { A of isOpIMonoid2 A }. + +(**) +HB.mixin Record isOpCMon2 A (Add: A -> A -> A) (Zero: A) := { + is_op_mon : isOpMon2 A Add Zero ; + is_op_calg : isOpCAlg2 A Add ; + }. + +HB.mixin Record isOpCMonoid2 A := { add: A -> A -> A; + zero: A; + is_op_imon : isOpCMon2 A add zero }. + +HB.structure Definition OpCMonoid2 := { A of isOpCMonoid2 A }. + +(**) +HB.mixin Record isOpCIAlg2 A (Add: A -> A -> A) := { + is_op_ialg : isOpIAlg2 A Add ; + is_op_calg : isOpCAlg2 A Add ; + }. + +HB.mixin Record isOpCIAlgebra2 A := { add: A -> A -> A; + is_op_cialg : isOpCIAlg2 A add }. + +HB.structure Definition OpCIAlgebra2 := { A of isOpCIAlgebra2 A }. + +(**) +HB.mixin Record isOpICAlg2 A (Add: A -> A -> A) := { + is_op_calg : isOpCAlg2 A Add ; + is_op_ialg : isOpIAlg2 A Add ; + }. + +HB.mixin Record isOpICAlgebra2 A := { add: A -> A -> A; + is_op_calg : isOpICAlg2 A add }. + +HB.structure Definition OpICAlgebra2 := { A of isOpICAlgebra2 A }. + +(**) +HB.mixin Record isOpACIAlg2 A (Add: A -> A -> A) := { + is_op_ialg : isOpIAlg2 A Add ; + is_op_calg : isOpCAlg2 A Add ; + is_op_aalg : isOpAAlg2 A Add ; + }. + +HB.mixin Record isOpACIAlgebra2 A := { add: A -> A -> A; + is_op_acialg : isOpACIAlg2 A add }. + +HB.structure Definition OpACIAlgebra2 := { A of isOpACIAlgebra2 A }. + +(**) +HB.mixin Record isOpCIMon2 A (Add: A -> A -> A) (Zero: A) := { + is_op_mon : isOpIMon2 A Add Zero ; + is_op_calg : isOpCAlg2 A Add ; + }. + +HB.mixin Record isOpCIMonoid2 A := { add: A -> A -> A; + zero: A; + is_op_cimon : isOpCIMon2 A add zero }. + +HB.structure Definition OpCIMonoid2 := { A of isOpCIMonoid2 A }. + +(**) +HB.mixin Record isOpICMon2 A (Add: A -> A -> A) (Zero: A) := { + is_op_mon : isOpCMon2 A Add Zero ; + is_op_calg : isOpIAlg2 A Add ; + }. + +HB.mixin Record isOpICMonoid2 A := { add: A -> A -> A; + zero: A; + is_op_cimon : isOpICMon2 A add zero }. + +HB.structure Definition OpICMonoid2 := { A of isOpICMonoid2 A }. + + +(*******************************************************************) + +(** Wrapper mixins *) + +#[wrapper] +HB.mixin Record hom_isAAlg T of Quiver T := + { hom_isAAlg_private : forall A B, isOpAAlgebra2 (@hom T A B) }. + +#[wrapper] +HB.mixin Record hom_isZAlg T of Quiver T := + { hom_isZAlg_private : forall A B, isOpZAlgebra2 (@hom T A B) }. + +#[wrapper] +HB.mixin Record hom_isMon T of Quiver T := + { hom_isMon_private : forall A B, isOpMonoid2 (@hom T A B) }. + +#[wrapper] +HB.mixin Record hom_isIAlg T of Quiver T := + { hom_isIAlg_private : forall A B, isOpIAlgebra2 (@hom T A B) }. + +#[wrapper] +HB.mixin Record hom_isCAlg T of Quiver T := + { hom_isCAlg_private : forall A B, isOpCAlgebra2 (@hom T A B) }. + +#[wrapper] +HB.mixin Record hom_isIMon T of Quiver T := + { hom_isIMon_private : forall A B, isOpIMonoid2 (@hom T A B) }. + +#[wrapper] +HB.mixin Record hom_isCMon T of Quiver T := + { hom_isCMon_private : forall A B, isOpCMonoid2 (@hom T A B) }. + +#[wrapper] +HB.mixin Record hom_isCIAlg T of Quiver T := + { hom_isCIAlg_private : forall A B, isOpCIAlgebra2 (@hom T A B) }. + +#[wrapper] +HB.mixin Record hom_isICAlg T of Quiver T := + { hom_isICAlg_private : forall A B, isOpICAlgebra2 (@hom T A B) }. + +#[wrapper] +HB.mixin Record hom_isACIAlg T of Quiver T := + { hom_isACIAlg_private : forall A B, isOpACIAlgebra2 (@hom T A B) }. + +#[wrapper] +HB.mixin Record hom_isCIMon T of Quiver T := + { hom_isCIMon_private : forall A B, isOpCIMonoid2 (@hom T A B) }. + +#[wrapper] +HB.mixin Record hom_isICMon T of Quiver T := + { hom_isICMon_private : forall A B, isOpICMonoid2 (@hom T A B) }. + + +(** Base enriched structures *) + +HB.structure + Definition Monoid_enriched_quiver := + { Obj of isQuiver Obj & hom_isMon Obj }. + +HB.structure + Definition IAlgebra_enriched_quiver := + { Obj of isQuiver Obj & hom_isIAlg Obj }. + +HB.structure + Definition CAlgebra_enriched_quiver := + { Obj of isQuiver Obj & hom_isCAlg Obj }. + +(** Complex enriched structures *) + +HB.structure + Definition IMonoid_enriched_quiver := + { Obj of isQuiver Obj & hom_isMon Obj & hom_isIAlg Obj}. + +HB.structure + Definition CIAlgebra_enriched_quiver := + { Obj of isQuiver Obj & hom_isIAlg Obj & hom_isCAlg Obj}. + +HB.structure + Definition ACIAlgebra_enriched_quiver := + { Obj of isQuiver Obj & hom_isIAlg Obj & hom_isCAlg Obj & hom_isAAlg Obj}. + +HB.structure + Definition CIMonoid_enriched_quiver := + { Obj of isQuiver Obj & hom_isMon Obj & hom_isIAlg Obj & hom_isCAlg Obj}. + + +(********* INSTANCES *****************************) + +Require Import FunctionalExtensionality. + +(** SAMPLE INSTANCE 1 *) + +HB.instance Definition funQ := isQuiver.Build Type + (fun A B => A -> option B). + +Definition funQ_comp {A B: Type} (f g: hom A B) : hom A B := + fun x => + match f x with + | Some _ => f x + | _ => g x end. + +Program Definition funQ_isMon (A B: Type) : + isOpMon2 (hom A B) funQ_comp (fun (_:A) => None) := + isOpMon2.Build _ _ (fun (_:A) => None) _ _. +Obligation 1. +econstructor. +{- unfold left_id; intros. + unfold funQ_comp; auto. +} +{- unfold right_id; intros. + eapply functional_extensionality; intro a. + unfold funQ_comp. + destruct (x a); auto. +} +Qed. +Obligation 2. +econstructor. +{- unfold associative; intros. + eapply functional_extensionality; intro a. + unfold funQ_comp. + destruct (x a) eqn:K1. + simpl; auto. + destruct (y a); auto. +} +Qed. + +Program Definition funQ_isIAlg (A B: Type) : + isOpIAlg2 (hom A B) funQ_comp := + isOpIAlg2.Build _ _ _. +Obligation 1. +unfold idempotent; intros. +eapply functional_extensionality; intro a. +unfold funQ_comp. +destruct (x a); auto. +Qed. + +Program Definition funQ_isIMon (A B: Type) : + isOpIMon2 (hom A B) funQ_comp (fun (_:A) => None) := + isOpIMon2.Build (hom A B) _ _ _ _. +Obligation 1. +eapply funQ_isMon. +Qed. +Obligation 2. +eapply funQ_isIAlg. +Qed. + +HB.instance Definition funQ_isMonoid (A B: Type) : + isOpMonoid2 (hom A B) := + isOpMonoid2.Build (hom A B) funQ_comp (fun (_:A) => None) (funQ_isMon A B). + +HB.instance Definition funQ_isIAlgebra (A B: Type) : + isOpIAlgebra2 (hom A B) := + isOpIAlgebra2.Build (hom A B) funQ_comp (funQ_isIAlg A B). + +HB.instance Definition funQ_isIMonoid (A B: Type) : + isOpIMonoid2 (hom A B) := + isOpIMonoid2.Build (hom A B) funQ_comp (fun (_:A) => None) + (funQ_isIMon A B). + +Elpi Print HB.structure. + + + +(** SAMPLE INSTANCE 3 *) + +HB.instance Definition cimfunQ := + isQuiver.Build (sigT (fun A => A -> A -> A)) + (fun X Y => isOpACIAlg2 (projT1 X) (projT2 X) -> + isOpACIAlg2 (projT1 Y) (projT2 Y) -> + (projT1 X) -> option (projT1 Y)). + +Definition cimfunQ_comp {A B: sigT (fun A => A -> A -> A)} + (f g: hom A B) : hom A B := + fun (ca: isOpACIAlg2 (projT1 A) (projT2 A)) + (cb: isOpACIAlg2 (projT1 B) (projT2 B)) a => + match (f ca cb a, g ca cb a) with + | (Some b1, Some b2) => Some (projT2 B b1 b2) + | (Some b, None) => Some b + | (None, Some b) => Some b + | _ => None end. + +Definition cimfunQ_zero {A B: sigT (fun A => A -> A -> A)} : hom A B := + fun _ _ _ => None. + +Program Definition cimfunQ_isCIMon (A B: sigT (fun A => A -> A -> A)) : + isOpCIMon2 (hom A B) cimfunQ_comp cimfunQ_zero := + isOpCIMon2.Build _ _ cimfunQ_zero _ _. +Obligation 1. +econstructor. +econstructor. +econstructor. +{- unfold left_id; intros. + unfold cimfunQ_comp; simpl. + eapply functional_extensionality; intro ca. + eapply functional_extensionality; intro cb. + eapply functional_extensionality; intro v. + destruct (x ca cb v); auto. +} +{- unfold right_id; intros. + unfold cimfunQ_comp; simpl. + eapply functional_extensionality; intro ca. + eapply functional_extensionality; intro cb. + eapply functional_extensionality; intro v. + destruct (x ca cb v); auto. +} +econstructor. +{- unfold associative; intros. + unfold cimfunQ_comp; simpl. + eapply functional_extensionality; intro ca. + eapply functional_extensionality; intro cb. + eapply functional_extensionality; intro v. + remember cb as cb1. + destruct cb. + destruct is_op_aalg0. + simpl in addA. + unfold associative in addA. + destruct (x ca cb1 v); simpl; eauto. + {+ destruct (y ca cb1 v); simpl; eauto. + destruct (z ca cb1 v); simpl; eauto. + rewrite addA; auto. + destruct (z ca cb1 v); simpl; eauto. + } + {+ destruct (y ca cb1 v); simpl; eauto. + destruct (z ca cb1 v); simpl; eauto. + destruct (z ca cb1 v); simpl; eauto. + } +} +econstructor. +{- unfold idempotent; intros. + unfold cimfunQ_comp; simpl. + eapply functional_extensionality; intro ca. + eapply functional_extensionality; intro cb. + eapply functional_extensionality; intro v. + remember cb as cb1. + destruct cb. + destruct is_op_ialg0. + unfold idempotent in addI0. + simpl in addI0. + destruct (x ca cb1 v) eqn:K1. + rewrite addI0; auto. + auto. +} +Qed. +Obligation 2. +econstructor. +unfold commutative; intros. +unfold cimfunQ_comp; simpl. +eapply functional_extensionality; intro ca. +eapply functional_extensionality; intro cb. +eapply functional_extensionality; intro v. +remember cb as cb1. +destruct cb. +destruct is_op_calg0. +unfold commutative in addC. +simpl in addC. +destruct (x ca cb1 v); simpl; eauto. +destruct (y ca cb1 v); simpl; eauto. +rewrite addC; auto. +Qed. + +HB.instance Definition cimfunQ_isCIMonoid + (A B: sigT (fun A => A -> A -> A)) : + isOpCIMonoid2 (hom A B) := + isOpCIMonoid2.Build (hom A B) cimfunQ_comp cimfunQ_zero + (cimfunQ_isCIMon A B). + +Elpi Print HB.structure. + + +(** SAMPLE INSTANCE 2 *) + +Lemma zero_unique {B} (X: B -> B -> B) (zz0 zz1:B) : + left_id zz0 X -> right_id zz0 X -> left_id zz1 X -> right_id zz1 X -> + zz0 = zz1. + unfold left_id, right_id. + intros. + specialize (H0 zz1). + specialize (H1 zz0). + rewrite H1 in H0. + auto. +Qed. + +Open Scope type. + +HB.instance Definition cmfunQ := + isQuiver.Build (sigT (fun A => (A -> A -> A) * A)) + (fun X Y => isOpCMon2 (projT1 X) (fst (projT2 X)) (snd (projT2 X)) -> + isOpCMon2 (projT1 Y) (fst (projT2 Y)) (snd (projT2 Y)) -> + (projT1 X) -> (projT1 Y)). + +Definition cmfunQ_comp {A B: sigT (fun A => (A -> A -> A) * A)} + (f g: @hom _ A B) : hom A B := + fun (ca: isOpCMon2 (projT1 A) (fst (projT2 A)) (snd (projT2 A))) + (cb: isOpCMon2 (projT1 B) (fst (projT2 B)) (snd (projT2 B))) a => + match (f ca cb a, g ca cb a) with + | (b1, b2) => (fst (projT2 B)) b1 b2 end. + +Program Definition cmfunQ_zero {A B: sigT (fun A => (A -> A -> A) * A)} : + hom A B. +Proof. + unfold hom; intros. + unfold isQuiver.hom. + unfold Quiver.cmonoid_enriched_cat_isQuiver_mixin. + unfold Quiver.class. + simpl; intros. + destruct B as [X [f x1]]; simpl. + exact x1. +Defined. + +Program Definition cmfunQ_isCMon (A B: sigT (fun A => (A -> A -> A) * A)) : + isOpCMon2 (hom A B) cmfunQ_comp cmfunQ_zero := + isOpCMon2.Build (hom A B) cmfunQ_comp _ _ _. +Obligation 1. +unfold cmfunQ_comp; simpl. +econstructor. +econstructor. +{- unfold left_id; intros. + eapply functional_extensionality; intro CMa. + eapply functional_extensionality; intro CMb. + eapply functional_extensionality; intro v. + remember CMb as CMb1. + destruct CMb. + destruct is_op_mon0. + destruct is_op_zalg0. + unfold left_id in add0r1. + simpl in add0r1. + unfold cmfunQ_zero. + eapply add0r1. +} +{- unfold right_id; intros. + eapply functional_extensionality; intro CMa. + eapply functional_extensionality; intro CMb. + eapply functional_extensionality; intro v. + remember CMb as CMb1. + destruct CMb. + destruct is_op_mon0. + destruct is_op_zalg0. + unfold right_id in addr1. + simpl in addr1. + unfold cmfunQ_zero. + eapply addr1. +} +econstructor. +{- unfold associative; intros. + eapply functional_extensionality; intro CMa. + eapply functional_extensionality; intro CMb. + eapply functional_extensionality; intro v. + remember CMb as CMb1. + destruct CMb. + destruct is_op_mon0. + destruct is_op_aalg0. + unfold associative in addA. + simpl in addA. + eapply addA. +} +Qed. +Obligation 2. + econstructor. + unfold cmfunQ_comp. + unfold commutative; simpl; intros. + eapply functional_extensionality; intro CMa. + eapply functional_extensionality; intro CMb. + eapply functional_extensionality; intro v. + remember CMb as CMb1. + destruct CMb. + destruct is_op_calg0. + simpl in addC. + eapply addC. +Qed. + +HB.instance Definition cmfunQ_isCMonoid + (A B: sigT (fun A => (A -> A -> A) * A)) : + isOpCMonoid2 (hom A B) := + isOpCMonoid2.Build (hom A B) cmfunQ_comp cmfunQ_zero (cmfunQ_isCMon A B). + +Elpi Print HB.structure. + From c002312fd8469e8855930956b30c67c066a356a2 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Thu, 24 Aug 2023 22:45:53 +0200 Subject: [PATCH 014/147] fixed bug in cmonoid_enriched_cat.v --- tests/cmonoid_enriched_cat.v | 216 ++++++++++++++++++----------------- 1 file changed, 109 insertions(+), 107 deletions(-) diff --git a/tests/cmonoid_enriched_cat.v b/tests/cmonoid_enriched_cat.v index a9325fc60..66b55e6b7 100644 --- a/tests/cmonoid_enriched_cat.v +++ b/tests/cmonoid_enriched_cat.v @@ -417,113 +417,6 @@ HB.instance Definition funQ_isIMonoid (A B: Type) : Elpi Print HB.structure. - -(** SAMPLE INSTANCE 3 *) - -HB.instance Definition cimfunQ := - isQuiver.Build (sigT (fun A => A -> A -> A)) - (fun X Y => isOpACIAlg2 (projT1 X) (projT2 X) -> - isOpACIAlg2 (projT1 Y) (projT2 Y) -> - (projT1 X) -> option (projT1 Y)). - -Definition cimfunQ_comp {A B: sigT (fun A => A -> A -> A)} - (f g: hom A B) : hom A B := - fun (ca: isOpACIAlg2 (projT1 A) (projT2 A)) - (cb: isOpACIAlg2 (projT1 B) (projT2 B)) a => - match (f ca cb a, g ca cb a) with - | (Some b1, Some b2) => Some (projT2 B b1 b2) - | (Some b, None) => Some b - | (None, Some b) => Some b - | _ => None end. - -Definition cimfunQ_zero {A B: sigT (fun A => A -> A -> A)} : hom A B := - fun _ _ _ => None. - -Program Definition cimfunQ_isCIMon (A B: sigT (fun A => A -> A -> A)) : - isOpCIMon2 (hom A B) cimfunQ_comp cimfunQ_zero := - isOpCIMon2.Build _ _ cimfunQ_zero _ _. -Obligation 1. -econstructor. -econstructor. -econstructor. -{- unfold left_id; intros. - unfold cimfunQ_comp; simpl. - eapply functional_extensionality; intro ca. - eapply functional_extensionality; intro cb. - eapply functional_extensionality; intro v. - destruct (x ca cb v); auto. -} -{- unfold right_id; intros. - unfold cimfunQ_comp; simpl. - eapply functional_extensionality; intro ca. - eapply functional_extensionality; intro cb. - eapply functional_extensionality; intro v. - destruct (x ca cb v); auto. -} -econstructor. -{- unfold associative; intros. - unfold cimfunQ_comp; simpl. - eapply functional_extensionality; intro ca. - eapply functional_extensionality; intro cb. - eapply functional_extensionality; intro v. - remember cb as cb1. - destruct cb. - destruct is_op_aalg0. - simpl in addA. - unfold associative in addA. - destruct (x ca cb1 v); simpl; eauto. - {+ destruct (y ca cb1 v); simpl; eauto. - destruct (z ca cb1 v); simpl; eauto. - rewrite addA; auto. - destruct (z ca cb1 v); simpl; eauto. - } - {+ destruct (y ca cb1 v); simpl; eauto. - destruct (z ca cb1 v); simpl; eauto. - destruct (z ca cb1 v); simpl; eauto. - } -} -econstructor. -{- unfold idempotent; intros. - unfold cimfunQ_comp; simpl. - eapply functional_extensionality; intro ca. - eapply functional_extensionality; intro cb. - eapply functional_extensionality; intro v. - remember cb as cb1. - destruct cb. - destruct is_op_ialg0. - unfold idempotent in addI0. - simpl in addI0. - destruct (x ca cb1 v) eqn:K1. - rewrite addI0; auto. - auto. -} -Qed. -Obligation 2. -econstructor. -unfold commutative; intros. -unfold cimfunQ_comp; simpl. -eapply functional_extensionality; intro ca. -eapply functional_extensionality; intro cb. -eapply functional_extensionality; intro v. -remember cb as cb1. -destruct cb. -destruct is_op_calg0. -unfold commutative in addC. -simpl in addC. -destruct (x ca cb1 v); simpl; eauto. -destruct (y ca cb1 v); simpl; eauto. -rewrite addC; auto. -Qed. - -HB.instance Definition cimfunQ_isCIMonoid - (A B: sigT (fun A => A -> A -> A)) : - isOpCIMonoid2 (hom A B) := - isOpCIMonoid2.Build (hom A B) cimfunQ_comp cimfunQ_zero - (cimfunQ_isCIMon A B). - -Elpi Print HB.structure. - - (** SAMPLE INSTANCE 2 *) Lemma zero_unique {B} (X: B -> B -> B) (zz0 zz1:B) : @@ -539,6 +432,7 @@ Qed. Open Scope type. +#[verbose] HB.instance Definition cmfunQ := isQuiver.Build (sigT (fun A => (A -> A -> A) * A)) (fun X Y => isOpCMon2 (projT1 X) (fst (projT2 X)) (snd (projT2 X)) -> @@ -632,3 +526,111 @@ HB.instance Definition cmfunQ_isCMonoid Elpi Print HB.structure. + +(** SAMPLE INSTANCE 3 *) + +Definition sigTa1 := sigT (fun A => A -> A -> A). + +HB.instance Definition cimfunQ := + isQuiver.Build (sigTa1) + (fun X Y => isOpACIAlg2 (projT1 X) (projT2 X) -> + isOpACIAlg2 (projT1 Y) (projT2 Y) -> + (projT1 X) -> option (projT1 Y)). + +Definition cimfunQ_comp {A B: sigTa1} + (f g: hom A B) : hom A B := + fun (ca: isOpACIAlg2 (projT1 A) (projT2 A)) + (cb: isOpACIAlg2 (projT1 B) (projT2 B)) a => + match (f ca cb a, g ca cb a) with + | (Some b1, Some b2) => Some (projT2 B b1 b2) + | (Some b, None) => Some b + | (None, Some b) => Some b + | _ => None end. + +Definition cimfunQ_zero {A B: sigTa1} : hom A B := + fun _ _ _ => None. + +Program Definition cimfunQ_isCIMon (A B: sigTa1) : + isOpCIMon2 (hom A B) cimfunQ_comp cimfunQ_zero := + isOpCIMon2.Build _ _ cimfunQ_zero _ _. +Obligation 1. +econstructor. +econstructor. +econstructor. +{- unfold left_id; intros. + unfold cimfunQ_comp; simpl. + eapply functional_extensionality; intro ca. + eapply functional_extensionality; intro cb. + eapply functional_extensionality; intro v. + destruct (x ca cb v); auto. +} +{- unfold right_id; intros. + unfold cimfunQ_comp; simpl. + eapply functional_extensionality; intro ca. + eapply functional_extensionality; intro cb. + eapply functional_extensionality; intro v. + destruct (x ca cb v); auto. +} +econstructor. +{- unfold associative; intros. + unfold cimfunQ_comp; simpl. + eapply functional_extensionality; intro ca. + eapply functional_extensionality; intro cb. + eapply functional_extensionality; intro v. + remember cb as cb1. + destruct cb. + destruct is_op_aalg0. + simpl in addA. + unfold associative in addA. + destruct (x ca cb1 v); simpl; eauto. + {+ destruct (y ca cb1 v); simpl; eauto. + destruct (z ca cb1 v); simpl; eauto. + rewrite addA; auto. + destruct (z ca cb1 v); simpl; eauto. + } + {+ destruct (y ca cb1 v); simpl; eauto. + destruct (z ca cb1 v); simpl; eauto. + destruct (z ca cb1 v); simpl; eauto. + } +} +econstructor. +{- unfold idempotent; intros. + unfold cimfunQ_comp; simpl. + eapply functional_extensionality; intro ca. + eapply functional_extensionality; intro cb. + eapply functional_extensionality; intro v. + remember cb as cb1. + destruct cb. + destruct is_op_ialg0. + unfold idempotent in addI0. + simpl in addI0. + destruct (x ca cb1 v) eqn:K1. + rewrite addI0; auto. + auto. +} +Qed. +Obligation 2. +econstructor. +unfold commutative; intros. +unfold cimfunQ_comp; simpl. +eapply functional_extensionality; intro ca. +eapply functional_extensionality; intro cb. +eapply functional_extensionality; intro v. +remember cb as cb1. +destruct cb. +destruct is_op_calg0. +unfold commutative in addC. +simpl in addC. +destruct (x ca cb1 v); simpl; eauto. +destruct (y ca cb1 v); simpl; eauto. +rewrite addC; auto. +Qed. + +HB.instance Definition cimfunQ_isCIMonoid + (A B: sigTa1) : + isOpCIMonoid2 (hom A B) := + isOpCIMonoid2.Build (hom A B) cimfunQ_comp cimfunQ_zero + (cimfunQ_isCIMon A B). + +Elpi Print HB.structure. + From 46d59321a84eacfa0f84c82e8d23efc92d30d56a Mon Sep 17 00:00:00 2001 From: ptorrx Date: Mon, 28 Aug 2023 15:47:25 +0200 Subject: [PATCH 015/147] revised tests/cmonoid_enriched_cat.v --- tests/cmonoid_enriched_cat.v | 282 +++++++++++++++++++++-------------- 1 file changed, 172 insertions(+), 110 deletions(-) diff --git a/tests/cmonoid_enriched_cat.v b/tests/cmonoid_enriched_cat.v index 66b55e6b7..fa18b328e 100644 --- a/tests/cmonoid_enriched_cat.v +++ b/tests/cmonoid_enriched_cat.v @@ -7,8 +7,11 @@ HB.mixin Record isQuiver Obj := { hom : Obj -> Obj -> Type }. HB.structure Definition Quiver := { Obj of isQuiver Obj }. -(** Ohter base mixins *) +(*************************************** OTHER MIXINS *************) +(******************************* Exploring different alternatives *) + +(************* 1) Monolithic definition; not used *) HB.mixin Record isMon A := { zero : A; add : A -> A -> A; @@ -17,6 +20,30 @@ HB.mixin Record isMon A := { addr0 : right_id zero add; }. +(***** using the monolithic approach to extend monoids with + idempotence and commutativity can be cumbersome *) + +HB.mixin Record isIMonB A := { + zero : A; + add : A -> A -> A; + addrA : associative add; + add0r : left_id zero add; + addr0 : right_id zero add; + addI : idempotent add; +}. + +HB.mixin Record isCMonB A := { + zero : A; + add : A -> A -> A; + addrA : associative add; + add0r : left_id zero add; + addr0 : right_id zero add; + addC : commutative add; +}. + + +(**************** 2) Small mixins (problem with sharing); not used *) + HB.mixin Record isIAlg A := { iadd : A -> A -> A; iaddI : idempotent iadd; @@ -27,20 +54,8 @@ HB.mixin Record isCAlg A := { caddrC : commutative cadd; }. -(** Base structures *) - -HB.structure Definition Monoid := { A of isMon A }. - -HB.structure Definition CAlgebra := { A of isCAlg A }. - -HB.structure Definition IAlgebra := { A of isIAlg A }. - -(** Complex mixins *) -(*******************************************************************) -(********** Combining mixins ***************************************) - -(***** Vanilla Coq (no HB) *) +(***************** 3) Sharing my equalities: vanilla Coq (no HB) *) Record isMon0 A := { zero0 : A; @@ -55,13 +70,13 @@ Record isIAlg0 A := { iaddI0 : idempotent iadd0; }. +(* this would require additional support *) Record isIMon0 A := { is_mon0 : isMon0 A; is_ialg0 : isIAlg0 A; mon_ialg_ch0 : add0 _ is_mon0 = iadd0 _ is_ialg0 ; }. - -(***** The analogous of vanilla does not work in HB *) +(*** The analogous of vanilla does not work in HB *) Fail HB.mixin Record isIMonM A := { is_mon : isMon A; is_ialg : isIAlg A; @@ -73,30 +88,11 @@ Fail HB.mixin Record isIMonS A := { is_mon : Monoid A; mon_ialg_ch : add _ is_mon = iadd _ is_ialg ; }. -(***** Basic approach (can be cumbersome) *) - -HB.mixin Record isIMonB A := { - zero : A; - add : A -> A -> A; - addrA : associative add; - add0r : left_id zero add; - addr0 : right_id zero add; - addI : idempotent add; -}. - -HB.mixin Record isCMonB A := { - zero : A; - add : A -> A -> A; - addrA : associative add; - add0r : left_id zero add; - addr0 : right_id zero add; - addC : commutative add; -}. - -(***** Operator mixins *) +(************************* 4) Operator-sharing small mixins *) -(**** single dependent pair parameter *) +(*********** 4.1) mixins with single dependent pair parameter, using + sigma types; complicates things; not used *) HB.mixin Record isOpMon1 (S: sigT (fun A => A -> A -> A)) := { zero : projT1 S; @@ -105,20 +101,19 @@ HB.mixin Record isOpMon1 (S: sigT (fun A => A -> A -> A)) := { addr0 : right_id zero (projT2 S); }. -HB.structure Definition OpMonoid1 := { C of isOpMon1 C }. - HB.mixin Record isOpIAlg1 (S: sigT (fun A => A -> A -> A)) := { addI : idempotent (projT2 S); }. -HB.structure Definition OpIAlgebra1 := { C of isOpIAlg1 C }. - -HB.mixin Record isOpIMon1 A of OpMonoid1 A & OpIAlgebra1 A. +(*********** 4.2) USED: mixins with multiple parameters instead of a + single dependent pair; possibly less general, but works well + with the running example (notice that the subject here could be + an operator, i.e. Add) *) -(**** two parameters (subject is Add) *) +(**** Base Mixins *) -(**) +(* associative algebra *) HB.mixin Record isOpAAlg2 A (Add: A -> A -> A) := { addA : associative Add; }. @@ -126,9 +121,7 @@ HB.mixin Record isOpAAlg2 A (Add: A -> A -> A) := { HB.mixin Record isOpAAlgebra2 A := { add: A -> A -> A; is_op_aalg : isOpAAlg2 A add }. -HB.structure Definition OpAAlgebra2 := { A of isOpAAlgebra2 A }. - -(**) +(* algebra with zero *) HB.mixin Record isOpZAlg2 A (Add: A -> A -> A) (Zero: A) := { add0r : left_id Zero Add; addr0 : right_id Zero Add; @@ -138,21 +131,7 @@ HB.mixin Record isOpZAlgebra2 A := { add: A -> A -> A; zero: A; is_op_zalg : isOpZAlg2 A add zero }. -HB.structure Definition OpZAlgebra2 := { A of isOpZAlgebra2 A }. - -(**) -HB.mixin Record isOpMon2 A (Add: A -> A -> A) (Zero: A) := { - is_op_zalg : isOpZAlg2 A Add Zero ; - is_op_aalg : isOpAAlg2 A Add ; - }. - -HB.mixin Record isOpMonoid2 A := { add: A -> A -> A; - zero: A; - is_op_mon : isOpMon2 A add zero }. - -HB.structure Definition OpMonoid2 := { A of isOpMonoid2 A }. - -(**) +(* idempotent algebra *) HB.mixin Record isOpIAlg2 A (Add: A -> A -> A) := { addI : idempotent Add; }. @@ -160,9 +139,7 @@ HB.mixin Record isOpIAlg2 A (Add: A -> A -> A) := { HB.mixin Record isOpIAlgebra2 A := { add: A -> A -> A; is_op_ialg : isOpIAlg2 A add }. -HB.structure Definition OpIAlgebra2 := { A of isOpIAlgebra2 A }. - -(**) +(* commutative algebra *) HB.mixin Record isOpCAlg2 A (Add: A -> A -> A) := { addC : commutative Add; }. @@ -170,9 +147,19 @@ HB.mixin Record isOpCAlg2 A (Add: A -> A -> A) := { HB.mixin Record isOpCAlgebra2 A := { add: A -> A -> A; is_op_calg : isOpCAlg2 A add }. -HB.structure Definition OpCAlgebra2 := { A of isOpCAlgebra2 A }. +(**** Complex Mixins *) + +(* monoid *) +HB.mixin Record isOpMon2 A (Add: A -> A -> A) (Zero: A) := { + is_op_zalg : isOpZAlg2 A Add Zero ; + is_op_aalg : isOpAAlg2 A Add ; + }. + +HB.mixin Record isOpMonoid2 A := { add: A -> A -> A; + zero: A; + is_op_mon : isOpMon2 A add zero }. -(**) +(* idempotent monoid *) HB.mixin Record isOpIMon2 A (Add: A -> A -> A) (Zero: A) := { is_op_mon : isOpMon2 A Add Zero ; is_op_ialg : isOpIAlg2 A Add ; @@ -182,9 +169,7 @@ HB.mixin Record isOpIMonoid2 A := { add: A -> A -> A; zero: A; is_op_imon : isOpIMon2 A add zero }. -HB.structure Definition OpIMonoid2 := { A of isOpIMonoid2 A }. - -(**) +(* commutative monoid *) HB.mixin Record isOpCMon2 A (Add: A -> A -> A) (Zero: A) := { is_op_mon : isOpMon2 A Add Zero ; is_op_calg : isOpCAlg2 A Add ; @@ -194,9 +179,7 @@ HB.mixin Record isOpCMonoid2 A := { add: A -> A -> A; zero: A; is_op_imon : isOpCMon2 A add zero }. -HB.structure Definition OpCMonoid2 := { A of isOpCMonoid2 A }. - -(**) +(* commutative idempotent algebra *) HB.mixin Record isOpCIAlg2 A (Add: A -> A -> A) := { is_op_ialg : isOpIAlg2 A Add ; is_op_calg : isOpCAlg2 A Add ; @@ -205,9 +188,7 @@ HB.mixin Record isOpCIAlg2 A (Add: A -> A -> A) := { HB.mixin Record isOpCIAlgebra2 A := { add: A -> A -> A; is_op_cialg : isOpCIAlg2 A add }. -HB.structure Definition OpCIAlgebra2 := { A of isOpCIAlgebra2 A }. - -(**) +(* idempotent commutative algebra *) HB.mixin Record isOpICAlg2 A (Add: A -> A -> A) := { is_op_calg : isOpCAlg2 A Add ; is_op_ialg : isOpIAlg2 A Add ; @@ -216,9 +197,7 @@ HB.mixin Record isOpICAlg2 A (Add: A -> A -> A) := { HB.mixin Record isOpICAlgebra2 A := { add: A -> A -> A; is_op_calg : isOpICAlg2 A add }. -HB.structure Definition OpICAlgebra2 := { A of isOpICAlgebra2 A }. - -(**) +(* associative commutative idempotent algebra *) HB.mixin Record isOpACIAlg2 A (Add: A -> A -> A) := { is_op_ialg : isOpIAlg2 A Add ; is_op_calg : isOpCAlg2 A Add ; @@ -228,9 +207,7 @@ HB.mixin Record isOpACIAlg2 A (Add: A -> A -> A) := { HB.mixin Record isOpACIAlgebra2 A := { add: A -> A -> A; is_op_acialg : isOpACIAlg2 A add }. -HB.structure Definition OpACIAlgebra2 := { A of isOpACIAlgebra2 A }. - -(**) +(* commutative idempotent monoid *) HB.mixin Record isOpCIMon2 A (Add: A -> A -> A) (Zero: A) := { is_op_mon : isOpIMon2 A Add Zero ; is_op_calg : isOpCAlg2 A Add ; @@ -240,9 +217,7 @@ HB.mixin Record isOpCIMonoid2 A := { add: A -> A -> A; zero: A; is_op_cimon : isOpCIMon2 A add zero }. -HB.structure Definition OpCIMonoid2 := { A of isOpCIMonoid2 A }. - -(**) +(* idempotent commutative monoid *) HB.mixin Record isOpICMon2 A (Add: A -> A -> A) (Zero: A) := { is_op_mon : isOpCMon2 A Add Zero ; is_op_calg : isOpIAlg2 A Add ; @@ -252,12 +227,64 @@ HB.mixin Record isOpICMonoid2 A := { add: A -> A -> A; zero: A; is_op_cimon : isOpICMon2 A add zero }. -HB.structure Definition OpICMonoid2 := { A of isOpICMonoid2 A }. +(************************************** STRUCTURES ***********************) + +(********************* NOT USED *) + +(** Base structures *) + +HB.structure Definition Monoid := { A of isMon A }. + +HB.structure Definition CAlgebra := { A of isCAlg A }. + +HB.structure Definition IAlgebra := { A of isIAlg A }. + +(** Complex structures *) + +HB.structure Definition OpMonoid1 := { C of isOpMon1 C }. + +HB.structure Definition OpIAlgebra1 := { C of isOpIAlg1 C }. + +HB.mixin Record isOpIMon1 A of OpMonoid1 A & OpIAlgebra1 A. (*******************************************************************) -(** Wrapper mixins *) +(********************** USED: based on operator-sharing, + simple-parameters mixins *) + +(** Base structures *) + +HB.structure Definition OpAAlgebra2 := { A of isOpAAlgebra2 A }. + +HB.structure Definition OpZAlgebra2 := { A of isOpZAlgebra2 A }. + +HB.structure Definition OpIAlgebra2 := { A of isOpIAlgebra2 A }. + +HB.structure Definition OpCAlgebra2 := { A of isOpCAlgebra2 A }. + +(** Complex structures *) + +HB.structure Definition OpMonoid2 := { A of isOpMonoid2 A }. + +HB.structure Definition OpIMonoid2 := { A of isOpIMonoid2 A }. + +HB.structure Definition OpCMonoid2 := { A of isOpCMonoid2 A }. + +HB.structure Definition OpCIAlgebra2 := { A of isOpCIAlgebra2 A }. + +HB.structure Definition OpICAlgebra2 := { A of isOpICAlgebra2 A }. + +HB.structure Definition OpACIAlgebra2 := { A of isOpACIAlgebra2 A }. + +HB.structure Definition OpCIMonoid2 := { A of isOpCIMonoid2 A }. + +HB.structure Definition OpICMonoid2 := { A of isOpICMonoid2 A }. + + +(******************************************** WRAPPERS *******) + +(** Base wrappers *) #[wrapper] HB.mixin Record hom_isAAlg T of Quiver T := @@ -267,10 +294,6 @@ HB.mixin Record hom_isAAlg T of Quiver T := HB.mixin Record hom_isZAlg T of Quiver T := { hom_isZAlg_private : forall A B, isOpZAlgebra2 (@hom T A B) }. -#[wrapper] -HB.mixin Record hom_isMon T of Quiver T := - { hom_isMon_private : forall A B, isOpMonoid2 (@hom T A B) }. - #[wrapper] HB.mixin Record hom_isIAlg T of Quiver T := { hom_isIAlg_private : forall A B, isOpIAlgebra2 (@hom T A B) }. @@ -279,6 +302,13 @@ HB.mixin Record hom_isIAlg T of Quiver T := HB.mixin Record hom_isCAlg T of Quiver T := { hom_isCAlg_private : forall A B, isOpCAlgebra2 (@hom T A B) }. + +(** Complex wrappers *) + +#[wrapper] +HB.mixin Record hom_isMon T of Quiver T := + { hom_isMon_private : forall A B, isOpMonoid2 (@hom T A B) }. + #[wrapper] HB.mixin Record hom_isIMon T of Quiver T := { hom_isIMon_private : forall A B, isOpIMonoid2 (@hom T A B) }. @@ -308,11 +338,11 @@ HB.mixin Record hom_isICMon T of Quiver T := { hom_isICMon_private : forall A B, isOpICMonoid2 (@hom T A B) }. -(** Base enriched structures *) +(**************************************** ENRICHED STRUCTURES *******) -HB.structure - Definition Monoid_enriched_quiver := - { Obj of isQuiver Obj & hom_isMon Obj }. +(*** USED *) + +(** Base enriched structures *) HB.structure Definition IAlgebra_enriched_quiver := @@ -322,8 +352,21 @@ HB.structure Definition CAlgebra_enriched_quiver := { Obj of isQuiver Obj & hom_isCAlg Obj }. +HB.structure + Definition ZAlgebra_enriched_quiver := + { Obj of isQuiver Obj & hom_isZAlg Obj }. + +HB.structure + Definition AAlgebra_enriched_quiver := + { Obj of isQuiver Obj & hom_isAAlg Obj }. + + (** Complex enriched structures *) +HB.structure + Definition Monoid_enriched_quiver := + { Obj of isQuiver Obj & hom_isMon Obj }. + HB.structure Definition IMonoid_enriched_quiver := { Obj of isQuiver Obj & hom_isMon Obj & hom_isIAlg Obj}. @@ -341,11 +384,29 @@ HB.structure { Obj of isQuiver Obj & hom_isMon Obj & hom_isIAlg Obj & hom_isCAlg Obj}. -(********* INSTANCES *****************************) +(*************************** LEMMA *****************************) + +Lemma zero_unique {B} (X: B -> B -> B) (zz0 zz1:B) : + left_id zz0 X -> right_id zz0 X -> left_id zz1 X -> right_id zz1 X -> + zz0 = zz1. + unfold left_id, right_id. + intros. + specialize (H0 zz1). + specialize (H1 zz0). + rewrite H1 in H0. + auto. +Qed. + +(*************************** INSTANCES *****************************) Require Import FunctionalExtensionality. -(** SAMPLE INSTANCE 1 *) +(** INSTANCE 1 + +Object: Type, +Morphism: A -> option B +Structure: Monoid (from isOpMon2) +*) HB.instance Definition funQ := isQuiver.Build Type (fun A B => A -> option B). @@ -417,18 +478,12 @@ HB.instance Definition funQ_isIMonoid (A B: Type) : Elpi Print HB.structure. -(** SAMPLE INSTANCE 2 *) +(** INSTANCE 2 -Lemma zero_unique {B} (X: B -> B -> B) (zz0 zz1:B) : - left_id zz0 X -> right_id zz0 X -> left_id zz1 X -> right_id zz1 X -> - zz0 = zz1. - unfold left_id, right_id. - intros. - specialize (H0 zz1). - specialize (H1 zz0). - rewrite H1 in H0. - auto. -Qed. +Object: commutative monoid (by sigma type and isOpCMon2) +Morphism: (projT1 X) -> (projT1 Y) +Structure: commutative monoid (by isOpCMon2) +*) Open Scope type. @@ -527,8 +582,15 @@ HB.instance Definition cmfunQ_isCMonoid Elpi Print HB.structure. -(** SAMPLE INSTANCE 3 *) +(** INSTANCE 3 + +Object: associative commutative idempotent algebra + (by sigma type and isOpACIAlg2) +Morphism: (projT1 X) -> option (projT1 Y) +Structure: commutative idempotent monoid (by isOpCImon2) +*) +(* hack *) Definition sigTa1 := sigT (fun A => A -> A -> A). HB.instance Definition cimfunQ := From ed74a828d7266e98d2934e460b51dcca05ac90d9 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Mon, 25 Sep 2023 15:07:13 +0200 Subject: [PATCH 016/147] cleanup --- HB/factory.elpi | 13 +++++----- HB/instance.elpi | 52 ++++++++++++++++--------------------- tests/monoid_enriched_cat.v | 11 ++------ 3 files changed, 32 insertions(+), 44 deletions(-) diff --git a/HB/factory.elpi b/HB/factory.elpi index 5e0005dab..da7d183f1 100644 --- a/HB/factory.elpi +++ b/HB/factory.elpi @@ -223,15 +223,15 @@ declare-asset Arg AssetKind :- std.do! [ %%% auxiliary code for wrapper-mixin pred extract_from_record_decl i: (term -> gref -> prop), i:indt-decl, o:gref. -extract_from_record_decl P (parameter ID _ _ R) Out :- - pi p\ +extract_from_record_decl P (parameter ID _ Ty R) Out :- + @pi-parameter ID Ty p\ extract_from_record_decl P (R p) Out. -extract_from_record_decl P (record ID _ KID (field _ _ Ty (x\end-record))) GR0 :- +extract_from_record_decl P (record _ _ _ (field _ _ Ty (x\end-record))) GR0 :- P Ty GR0. pred extract_from_rtty i: (term -> gref -> prop), i: term, o:gref. -extract_from_rtty P (prod _ _ TF) Out1 :- - pi p\ +extract_from_rtty P (prod N Ty TF) Out1 :- + @pi-decl N Ty p\ extract_from_rtty P (TF p) Out1. extract_from_rtty P Ty Gr :- P Ty Gr. @@ -242,7 +242,8 @@ xtr_fst_op Ty Gr1 :- pred xtr_snd_op i:term, o:gref. xtr_snd_op Ty Gr :- - Ty = (app [global _, app [global Gr| _]]). + Ty = (app [global _| Args]), + std.last Args (app [global Gr| _]). pred extract_wrapped i:indt-decl, o:gref. extract_wrapped In Out :- diff --git a/HB/instance.elpi b/HB/instance.elpi index 5d24f3cd7..2bae5a431 100644 --- a/HB/instance.elpi +++ b/HB/instance.elpi @@ -455,22 +455,19 @@ declare-regular-inst TheType ML TheMixins TyWP SectionName CSL :- std.do![ pred declare-wrapper-inst i:term, i:list mixinname, i:list constant, i:arity, i:id, o:list (pair id constant). declare-wrapper-inst TheType ML TheMixins TyWP SectionName CSL :- std.do![ - private.close-section-if-has-params TyWP SectionName, - coq.say "HERE!" TheType, coq.safe-dest-app TheType TheTypeKey _, - if (TheTypeKey = global TheTypeKeyGR) - (std.spy(private.wrap-mixins TheTypeKeyGR ML TheMixins TheNewType WML TheWrappedMixins), - std.spy(private.declare-structure-instance-from-mixins TheNewType WML TheWrappedMixins CSL)) - (coq.say "problem in wrap-mixins") + std.assert! (TheTypeKey = global TheTypeKeyGR) "The subject to be wrapped has no key", + private.close-section-if-has-params TyWP SectionName, + private.wrap-mixins TheTypeKeyGR ML TheMixins TheNewType WML TheWrappedMixins, + private.declare-structure-instance-from-mixins TheNewType WML TheWrappedMixins CSL, ]. pred is-structure-op i:term. is-structure-op (global (const C)) :- exported-op _ _ C. is-structure-op (app[global (const C)|_]) :- exported-op _ _ C. -pred derive-wrapper-instances i:term, i:prop, o:term, o:constant. -derive-wrapper-instances Instance (wrapper-mixin WrapperMixin _Subject _Mixin) - WrapperSubject C :- std.do! [ +pred derive-wrapper-instances i:term, i:mixinname, o:term, o:constant. +derive-wrapper-instances Instance WrapperMixin WrapperSubject C :- std.do! [ % K is the mixin constructor (Build) for WrapperMixin factory-constructor WrapperMixin K, @@ -491,7 +488,7 @@ derive-wrapper-instances Instance (wrapper-mixin WrapperMixin _Subject _Mixin) % them as arguments followed by Instance. coq.env.typeof K KTy, coq.count-prods KTy KN, - KN0 = KN - 1, + KN0 is KN - 1, coq.mk-n-holes KN0 Holes, std.append Holes [Instance] Args, @@ -501,10 +498,12 @@ derive-wrapper-instances Instance (wrapper-mixin WrapperMixin _Subject _Mixin) coq.typecheck NewInstance Ty Dgn, + coq.say "NewInstance" {coq.term->string NewInstance}, + coq.say "NewInstanceTy" {coq.term->string Ty}, + if (Dgn = error S) (coq.say "DWI! error in NewInstance" NewInstance "xxxx" S) - (coq.count-prods Ty N0, - coq.safe-dest-app Ty _Factory FArgs, + (coq.safe-dest-app Ty _Factory FArgs, std.nth NParams FArgs WrapperSubject ), @@ -514,27 +513,22 @@ derive-wrapper-instances Instance (wrapper-mixin WrapperMixin _Subject _Mixin) ]. pred wrap-a-mixin i:gref, i:mixinname, i:constant, o:term, o:mixinname, o:constant. -wrap-a-mixin TheTypeKeyGR M TheMixin TheNewType WM TheWrappedMixin :- - std.do! [ - std.findall (wrapper-mixin _ TheTypeKeyGR M) Wrappers, - if (Wrappers = [W|_]) - (W = wrapper-mixin WM TheTypeKeyGR M, - TM = global (const TheMixin), - private.derive-wrapper-instances TM W TheNewType TheWrappedMixin) - (coq.say "problem in wrap-a-mixin"), - ]. +wrap-a-mixin TheTypeKeyGR M TheMixin TheNewType WM TheWrappedMixin :- std.do! [ + std.findall (wrapper-mixin _ TheTypeKeyGR M) Wrappers, + std.assert! (not(Wrappers = [])) "wrap-a-mixin: no wrapper found", + if (Wrappers = [wrapper-mixin WM TheTypeKeyGR M]) + (TM = global (const TheMixin), + private.derive-wrapper-instances TM WM TheNewType TheWrappedMixin) + (coq.error "wrap-a-mixin: more than one way to wrap" TheTypeKeyGR "for" M), +]. pred wrap-mixins i:gref, i:list mixinname, i:list constant, o:term, o:list mixinname, o:list constant. -wrap-mixins TheTypeKeyGR [M | ML] [ TheMixin | TheMixins ] TheNewType [ WM | WML ] - [ TheWrappedMixin | TheWrappedMixins ] :- - coq.say TheTypeKeyGR M ML TheMixin TheMixins TheNewType WM WML TheWrappedMixin TheWrappedMixins, -% coq.safe-dest-app TheType TheTypeKey _, -% if (TheTypeKey = global TheTypeKeyGR) - wrap-a-mixin TheTypeKeyGR M TheMixin TheNewType1 WM TheWrappedMixin, - std.assert! (TheNewType = TheNewType1) "wrapping to different subjects", +wrap-mixins TheTypeKeyGR [ M | ML ] [ TheMixinInstance | TheMixins ] + TheNewType [ WM | WML ] [ TheWrappedMixin | TheWrappedMixins ] :- + wrap-a-mixin TheTypeKeyGR M TheMixinInstance TheNewType1 WM TheWrappedMixin, + std.assert! (TheNewType = TheNewType1) "wrapping leads to different subjects", wrap-mixins TheTypeKeyGR ML TheMixins TheNewType WML TheWrappedMixins. -% (coq.say "problem in wrap-mixins"). wrap-mixins _ [] [] _ [] []. diff --git a/tests/monoid_enriched_cat.v b/tests/monoid_enriched_cat.v index b10b6f6f6..6412f6b92 100644 --- a/tests/monoid_enriched_cat.v +++ b/tests/monoid_enriched_cat.v @@ -146,16 +146,9 @@ Qed. Print Canonical Projections. *) -(* -Fail Check (nat -> option nat) : Monoid.type. - -Check 1. -Print Canonical Projections. +Fail Check (nat -> option nat) : Monoid.type. -Check 2. -Set Printing All. -*) (* use the lemma to instantiate isMon. Notice the genericity of the type. In principle this instance should be derivable from the wrapper instance. @@ -165,7 +158,7 @@ Set Printing All. Check Type : Quiver.type. Fail Check Type : Monoid_enriched_quiver.type. -HB.instance Definition funQ_isMon (A B: Type) : isMon (hom A B) := +#[verbose] HB.instance Definition funQ_isMon (A B: Type) : isMon (hom A B) := funQ_isMonF A B. Check Type : Monoid_enriched_quiver.type. From 3e040b497b018bb13efe15115a822acdf10e39da Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Mon, 25 Sep 2023 16:28:00 +0200 Subject: [PATCH 017/147] eta expand wrapped mixing in context --- HB/context.elpi | 46 +++++++++++++++++++++++++++++++++++-- tests/monoid_enriched_cat.v | 29 +++++++++++++++++++++++ 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/HB/context.elpi b/HB/context.elpi index 4b04e5f0b..627106066 100644 --- a/HB/context.elpi +++ b/HB/context.elpi @@ -57,6 +57,38 @@ namespace private { % to the corresponding mixin using mixin-for pred postulate-mixin i:term, i:w-args mixinname, i:triple (list constant) (list prop) (list (w-args mixinname)), o:triple (list constant) (list prop) (list (w-args mixinname)). +postulate-mixin TheType (triple M Ps T) (triple CL MSL MLwP) (triple OutCL [MC|MSL] [NewMwP|MLwP]) :- wrapper-mixin M _ _, !, MSL => std.do! [ + NameVar is "local_mixin_private_" ^ {gref->modname M 2 "_"}, + NameMixin is "local_mixin_" ^ {gref->modname M 2 "_"}, + + if-verbose (coq.say "HB: postulate and wrap" NameVar "on" {coq.term->string T}), + + synthesis.infer-all-gref-deps Ps T M TySkel, + % was synthesis.infer-all-mixin-args Ps T M TySkel, + % if-verbose (coq.say "HB: postulate-mixin checking" TySkel), + % std.assert-ok! (coq.typecheck Ty _) "postulate-mixin: Ty illtyped", + std.assert-ok! (coq.elaborate-ty-skeleton TySkel _ Ty) + "postulate-mixin: Ty illtyped", + + Ty = app[global M|Args], + factory-constructor M K, + coq.mk-app (global K) Args KArgs, + std.assert-ok! (coq.typecheck KArgs {{ lp:VarTy -> _ }}) "brrr", + + log.coq.env.add-section-variable-noimplicits NameVar VarTy V, + + coq.mk-app KArgs [global (const V)] TheMixin, + + log.coq.env.add-const-noimplicits NameMixin TheMixin Ty @transparent! C, + + factory? Ty NewMwP, + + declare-instances-from-postulated-mixin TheType M T C MC NewCL, + + std.append CL NewCL OutCL, + +]. + postulate-mixin TheType (triple M Ps T) (triple CL MSL MLwP) (triple OutCL [MC|MSL] [NewMwP|MLwP]) :- MSL => std.do! [ Name is "local_mixin_" ^ {gref->modname M 2 "_"}, @@ -69,12 +101,22 @@ postulate-mixin TheType (triple M Ps T) (triple CL MSL MLwP) (triple OutCL [MC|M std.assert-ok! (coq.elaborate-ty-skeleton TySkel _ Ty) "postulate-mixin: Ty illtyped", log.coq.env.add-section-variable-noimplicits Name Ty C, + factory? Ty NewMwP, + declare-instances-from-postulated-mixin TheType M T C MC NewCL, + + std.append CL NewCL OutCL, + + ]. + +pred declare-instances-from-postulated-mixin i:term, i:mixinname, i:term, i:constant, o:prop, o:(list constant). +declare-instances-from-postulated-mixin TheType M T C MC NewCL :- std.do! [ + MC = mixin-src T M (global (const C)), MC => get-option "local" tt => instance.declare-all TheType {findall-classes-for [M]} NewCSL, std.map NewCSL snd NewCL, - std.append CL NewCL OutCL - ]. +]. + }} diff --git a/tests/monoid_enriched_cat.v b/tests/monoid_enriched_cat.v index 6412f6b92..6f4759cf7 100644 --- a/tests/monoid_enriched_cat.v +++ b/tests/monoid_enriched_cat.v @@ -163,7 +163,36 @@ Fail Check Type : Monoid_enriched_quiver.type. Check Type : Monoid_enriched_quiver.type. +Section A0. +#[verbose, log] +HB.declare Context T of Monoid_enriched_quiver T. +Goal forall A B : T, isMon (hom A B). +assumption. +Qed. + +End A0. + +(* BUG + +HB.mixin Record isNE T := { def: T }. +HB.structure Definition NE := { T of isNE T }. + +HB.factory Record dummy T of Monoid_enriched_quiver T := { x : T }. + +HB.builders Context T (f : dummy T). + +Goal forall A B : T, isMon (hom A B). +assumption. +Qed. + +HB.instance Definition _ := isNE.Build T x. + +HB.end. +About wrapped__20. +#[verbose] HB.instance +Definition x := dummy.Build Type nat. +*) (* Check (fun A B : Type => hom A B : Monoid.type). *) From 19fd228546b400ef69bb55b009ea3442a5a20993 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Tue, 26 Sep 2023 15:05:53 +0200 Subject: [PATCH 018/147] minimal test for parameters --- HB/instance.elpi | 17 ++--- tests/monoid_enriched_cat.v | 122 +++++++++++++++++++++++++++++++++++- 2 files changed, 126 insertions(+), 13 deletions(-) diff --git a/HB/instance.elpi b/HB/instance.elpi index 2bae5a431..aa1158de9 100644 --- a/HB/instance.elpi +++ b/HB/instance.elpi @@ -472,8 +472,7 @@ derive-wrapper-instances Instance WrapperMixin WrapperSubject C :- std.do! [ % K is the mixin constructor (Build) for WrapperMixin factory-constructor WrapperMixin K, factory-nparams WrapperMixin NParams, - std.assert! (NParams = 0) "TODO support parameters", - + % We are only interested in the last parameter of the constructor % type, which is the current instance % (which is a Mixin instance on the new Subject). @@ -496,20 +495,14 @@ derive-wrapper-instances Instance WrapperMixin WrapperSubject C :- std.do! [ % the body of the new wrapper instance NewInstance = app[global K| Args], - coq.typecheck NewInstance Ty Dgn, + std.assert-ok! (coq.typecheck NewInstance Ty) "cannot wrap", - coq.say "NewInstance" {coq.term->string NewInstance}, - coq.say "NewInstanceTy" {coq.term->string Ty}, - - if (Dgn = error S) - (coq.say "DWI! error in NewInstance" NewInstance "xxxx" S) - (coq.safe-dest-app Ty _Factory FArgs, - std.nth NParams FArgs WrapperSubject - ), + coq.safe-dest-app Ty _Factory FArgs, + std.nth NParams FArgs WrapperSubject, Name is "wrapped__" ^ {std.any->string {new_int}}, - log.coq.env.add-const-noimplicits Name NewInstance Ty @transparent! C + std.spy(log.coq.env.add-const-noimplicits Name NewInstance Ty @transparent! C), ]. pred wrap-a-mixin i:gref, i:mixinname, i:constant, o:term, o:mixinname, o:constant. diff --git a/tests/monoid_enriched_cat.v b/tests/monoid_enriched_cat.v index 6f4759cf7..1fb4c0206 100644 --- a/tests/monoid_enriched_cat.v +++ b/tests/monoid_enriched_cat.v @@ -1,6 +1,11 @@ From HB Require Import structures. From Coq Require Import ssreflect ssrfun. + +Require Import FunctionalExtensionality. + +Module NoParams. + HB.mixin Record isQuiver Obj := { hom : Obj -> Obj -> Type }. HB.structure Definition Quiver := { Obj of isQuiver Obj }. @@ -89,7 +94,6 @@ HB.instance Definition funQ := isQuiver.Build Type (* prove that for every two types the quiver is a monoid *) -Require Import FunctionalExtensionality. Definition funQ_comp {A B} (f g: A -> option B) (x: A) : option B := match f x with @@ -172,6 +176,118 @@ assumption. Qed. End A0. + +End NoParams. + + +(******************* PARAMETERS ***********************) + +Module WithParams. + + + +HB.mixin Record isQuiver P Obj := { hom : Obj -> Obj -> Type; embed : P -> Obj; }. + +HB.structure Definition Quiver P := { Obj of isQuiver P Obj }. + +HB.mixin Record isMon S A := { + zero : A; + add : A -> A -> A; + scale : S -> A -> A; + addrA : associative add; + add0r : left_id zero add; + addr0 : right_id zero add; + }. + +HB.structure + Definition Monoid S := { A of isMon S A }. + +(* This is expected to fail, as it isn't a mixin *) +Fail HB.structure + Definition Monoid_enriched_quiver P S := + { Obj of isQuiver P Obj & + (forall A B : Obj, isMon S (@hom (Quiver.clone Obj _) A B)) }. + +#[wrapper] +HB.mixin Record hom_isMon P S T of Quiver P T := + { hom_isMon_private : forall A B, isMon S (@hom P T A B) }. + +#[verbose] HB.structure + Definition Monoid_enriched_quiver P S := + { Obj of isQuiver P Obj & hom_isMon P S Obj }. + +HB.instance Definition funQ := isQuiver.Build nat Type + (fun A B => A -> option B) (fun x => match x with O => nat | S _ => bool end). + +Definition funQ_comp {A B} (f g: A -> option B) (x: A) : option B := + match f x with + | Some _ => f x + | _ => g x end. + +Program Definition funQ_isMonF S (A B: Type) : isMon S (A -> option B) := + isMon.Build S (A -> option B) (fun (_:A) => None) funQ_comp (fun _ x => x) _ _ _. +(* Obligations. *) +Obligation 1. +unfold associative; intros. +eapply functional_extensionality; intro a. +unfold funQ_comp. +destruct (x a) eqn:K1. +simpl; auto. +destruct (y a); auto. +Qed. +Obligation 2. +unfold left_id; intros. +unfold funQ_comp; auto. +Qed. +Obligation 3. +unfold right_id; intros. +eapply functional_extensionality; intro a. +unfold funQ_comp. +destruct (x a); auto. +Qed. + +Fail Check (nat -> option nat) : Monoid.type _. + + +(* use the lemma to instantiate isMon. Notice the genericity of the type. + In principle this instance should be derivable from the wrapper instance. + But since we haven't introduced the wrapper instance yet, we use this + HB command to actually introduce it. *) + +Check Type : Quiver.type _. +Fail Check Type : Monoid_enriched_quiver.type _ _. + +(* What should we do *) +Fail #[verbose] HB.instance Definition funQ_isMon S (A B: Type) : isMon S (hom A B) := + funQ_isMonF S A B. + +#[verbose] HB.instance Definition funQ_isMon (A B: Type) : isMon bool (hom A B) := + funQ_isMonF bool A B. + +Check Type : Monoid_enriched_quiver.type _ _. + + +End WithParams. + + + + + + + + + + + + + + + + + + + + (* BUG @@ -189,6 +305,10 @@ Qed. HB.instance Definition _ := isNE.Build T x. HB.end. + +This builder is not a legit one!!!!! +About Builders_25.local_mixin_monoid_enriched_cat_hom_isMon. + About wrapped__20. #[verbose] HB.instance Definition x := dummy.Build Type nat. From 2d94c60ea89de4e29fbab409d40bdad6dc4c4f90 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Tue, 26 Sep 2023 16:04:24 +0200 Subject: [PATCH 019/147] plan for auto wrapping --- HB/structure.elpi | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/HB/structure.elpi b/HB/structure.elpi index 1bcf78440..0110b6f11 100644 --- a/HB/structure.elpi +++ b/HB/structure.elpi @@ -11,8 +11,11 @@ declare Module BSkel Sort :- std.do! [ disable-id-phant BSkel BSkelNoId, std.assert-ok! (coq.elaborate-skeleton BSkelNoId _ BNoId) "illtyped structure definition", re-enable-id-phant BNoId B, - private.sigT->list-w-params B GRFSwP ClosureCheck, + private.sigT->list-w-params B GRFSwP_or_ThingtoBeWrapped ClosureCheck, + % do some work to go back to + GRFSwP_or_ThingtoBeWrapped = GRFSwP, + factories-provide GRFSwP PMLwP, list-w-params.flatten-map GRFSwP gref-deps RMLwP, % TODO: extract code from factories-provide @@ -615,6 +618,18 @@ if-coverage-not-good-error.one MS M :- mixin-first-class M C, !, "which contains at most" {std.map {coq.gref.set.elements {coq.gref.set.inter CMS MS}} nice-gref->string}). if-coverage-not-good-error.one _ _. % new class is the first covering M +% 1. write a predicate to recognize factory applied to op, maybe under a forall prefix +% factory-on-some-structure-op? +% 2. change the type of product->triples and sigT->list-w-params to +% return a list-w-params of either a factoryname or a thing-to-be-wrapper +% (eg mixin to be wrapped, operation) +% 3. the caller of sigT->list-w-params has to pre-process the list +% and generate wrapper mixins for each thing-to-be-wrapper and replace +% in the list the thing-to-be-wrapper with the wrapper mixin +% - one needs to find to which structure the operation belongs and +% use that structure to synthesize the type of the wrapper, eg +% hom belongs to Quiver, hence hom_isMon takes a "T of Quiver T" + pred product->triples i:term, o:list (w-args factoryname), o:bool. product->triples {{ lib:hb.prod lp:A lp:B }} L ClosureCheck :- !, product->triples B GRB ClosureCheck, @@ -623,6 +638,7 @@ product->triples {{ lib:hb.prod lp:A lp:B }} L ClosureCheck :- !, product->triples {{ True }} [] tt :- !. product->triples {{ False }} [] ff :- !. product->triples A [GR] tt :- std.assert! (factory? A GR) "A structure can only mention known factories". +% product->triples A [GR] tt :- factory-on-some-structure-op? A GR. pred sigT->list-w-params i:term, o:list-w-params factoryname, o:bool. sigT->list-w-params (fun N T B) L C :- From df1d86579a9c659277f8603254f60d0211d46881 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Tue, 3 Oct 2023 11:09:46 +0200 Subject: [PATCH 020/147] added enriched_cat_case1.v - problematic --- tests/enriched_cat_case1.v | 101 +++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 tests/enriched_cat_case1.v diff --git a/tests/enriched_cat_case1.v b/tests/enriched_cat_case1.v new file mode 100644 index 000000000..902afa6d8 --- /dev/null +++ b/tests/enriched_cat_case1.v @@ -0,0 +1,101 @@ +From HB Require Import structures. +From Coq Require Import ssreflect ssrfun. + +(** Quiver *) + +HB.mixin Record isQuiver Obj := { hom : Obj -> Obj -> Type }. + +HB.structure Definition Quiver := { Obj of isQuiver Obj }. + + +(*************************************** OTHER MIXINS *************) +Require Import Coq.Program.Equality. +Require Import FunctionalExtensionality. + +HB.mixin Record isMon T := { + munit : T; + mop : T -> T -> T; + massoc : associative mop; + mlid : left_id munit mop; + mrid : right_id munit mop; + }. +#[verbose] +HB.structure Definition Mon := { T of isMon T }. + +HB.mixin Record isICAlg T := { + aop : T -> T -> T; + acomm : commutative aop; + aidem : idempotent aop; + }. +#[verbose] +HB.structure Definition ICAlg := { T of isICAlg T }. + +HB.mixin Record isICMon T of ICAlg T := { + maunit : T; + maop : T -> T -> T; + maassoc : associative maop; + malid : left_id maunit maop; + marid : right_id maunit maop; + macomm : commutative maop; + maidem : idempotent maop; + }. +#[verbose] +HB.structure Definition ICMon := { T of isICMon T }. + +(* +#[wrapper] +HB.mixin Record hom_isICAlg T of Quiver T := + { hom_isICAlg_private : forall A B, isICAlg (@hom T A B) }. + +#[wrapper] +HB.mixin Record hom_isMon T of Quiver T := + { hom_isMon_private : forall A B, isMon (@hom T A B) }. + +HB.structure + Definition Mon_enriched_quiver := + { Obj of isQuiver Obj & hom_isMon Obj }. + +HB.structure + Definition ICAlg_enriched_quiver := + { Obj of isQuiver Obj & hom_isICAlg Obj }. +*) + +Fail #[wrapper] +HB.mixin Record hom_isICMon T of Quiver T := + { hom_isICMon_private : forall A B, isICMon (@hom T A B) }. +Fail #[verbose] +HB.structure + Definition ICMon_enriched_quiver := + { Obj of isQuiver Obj & hom_isICMon Obj }. + + +HB.factory Record isMICAlg T of Mon T := { + amop : T -> T -> T; + ameq : forall x y, amop x y = mop x y; + amcomm : commutative amop; + amidem : idempotent amop; + }. + +HB.builders Context T (f : isMICAlg T). + + Lemma amop_mop_eq : amop = mop. + destruct f; simpl. + eapply functional_extensionality; intro. + eapply functional_extensionality; intro. + auto. + Qed. + + Definition dum_comm := + @eq_rect (T -> T -> T) amop (@commutative T T) amcomm mop amop_mop_eq. + + Definition dum_idem := + @eq_rect (T -> T -> T) amop (@idempotent T) amidem mop amop_mop_eq. + + HB.instance Definition b_A : isICAlg T := + isICAlg.Build T mop dum_comm dum_idem. + + HB.instance Definition b_M : isICMon T := + isICMon.Build T munit mop massoc mlid mrid dum_comm dum_idem. + +HB.end. + From ffce0b98642ec83a56f899ead1e5e4ce602dac09 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Tue, 3 Oct 2023 11:44:10 +0200 Subject: [PATCH 021/147] added enriched_cat_case2.v - which works, but wraps without depencies; and enriched_cat_case3.v which fails, as expected (sadly) --- tests/enriched_cat_case2.v | 113 +++++++++++++++++++++++++++++++++++++ tests/enriched_cat_case3.v | 94 ++++++++++++++++++++++++++++++ 2 files changed, 207 insertions(+) create mode 100644 tests/enriched_cat_case2.v create mode 100644 tests/enriched_cat_case3.v diff --git a/tests/enriched_cat_case2.v b/tests/enriched_cat_case2.v new file mode 100644 index 000000000..2502943fc --- /dev/null +++ b/tests/enriched_cat_case2.v @@ -0,0 +1,113 @@ +From HB Require Import structures. +From Coq Require Import ssreflect ssrfun. + +(** Quiver *) + +HB.mixin Record isQuiver Obj := { hom : Obj -> Obj -> Type }. + +HB.structure Definition Quiver := { Obj of isQuiver Obj }. + + +(*************************************** OTHER MIXINS *************) +Require Import Coq.Program.Equality. +Require Import FunctionalExtensionality. + +HB.mixin Record isMon T := { + munit : T; + mop : T -> T -> T; + massoc : associative mop; + mlid : left_id munit mop; + mrid : right_id munit mop; + }. +#[verbose] +HB.structure Definition Mon := { T of isMon T }. + +HB.mixin Record isICAlg T := { + aop : T -> T -> T; + acomm : commutative aop; + aidem : idempotent aop; + }. +#[verbose] +HB.structure Definition ICAlg := { T of isICAlg T }. + +HB.mixin Record isICMon T := { + maunit : T; + maop : T -> T -> T; + maassoc : associative maop; + malid : left_id maunit maop; + marid : right_id maunit maop; + macomm : commutative maop; + maidem : idempotent maop; + }. +#[verbose] +HB.structure Definition ICMon := { T of isICMon T }. + +Lemma isICMon2isMon T : isICMon T -> isMon T. + intro X. + destruct X. + econstructor; eauto. +Qed. + +Lemma isICMon2isICAlg T : isICMon T -> isICAlg T. + intro X. + destruct X. + econstructor; eauto. +Qed. + +(* +#[wrapper] +HB.mixin Record hom_isICAlg T of Quiver T := + { hom_isICAlg_private : forall A B, isICAlg (@hom T A B) }. + +#[wrapper] +HB.mixin Record hom_isMon T of Quiver T := + { hom_isMon_private : forall A B, isMon (@hom T A B) }. + +HB.structure + Definition Mon_enriched_quiver := + { Obj of isQuiver Obj & hom_isMon Obj }. + +HB.structure + Definition ICAlg_enriched_quiver := + { Obj of isQuiver Obj & hom_isICAlg Obj }. +*) + +#[wrapper] +HB.mixin Record hom_isICMon T of Quiver T := + { hom_isICMon_private : forall A B, isICMon (@hom T A B) }. +#[verbose] +HB.structure + Definition ICMon_enriched_quiver := + { Obj of isQuiver Obj & hom_isICMon Obj }. + + +HB.factory Record isMICAlg T of Mon T := { + amop : T -> T -> T; + ameq : forall x y, amop x y = mop x y; + amcomm : commutative amop; + amidem : idempotent amop; + }. + +HB.builders Context T (f : isMICAlg T). + + Lemma amop_mop_eq : amop = mop. + destruct f; simpl. + eapply functional_extensionality; intro. + eapply functional_extensionality; intro. + auto. + Qed. + + Definition dum_comm := + @eq_rect (T -> T -> T) amop (@commutative T T) amcomm mop amop_mop_eq. + + Definition dum_idem := + @eq_rect (T -> T -> T) amop (@idempotent T) amidem mop amop_mop_eq. + + HB.instance Definition b_A : isICAlg T := + isICAlg.Build T mop dum_comm dum_idem. + + HB.instance Definition b_M : isICMon T := + isICMon.Build T munit mop massoc mlid mrid dum_comm dum_idem. + +HB.end. + diff --git a/tests/enriched_cat_case3.v b/tests/enriched_cat_case3.v new file mode 100644 index 000000000..6185fc7f1 --- /dev/null +++ b/tests/enriched_cat_case3.v @@ -0,0 +1,94 @@ +From HB Require Import structures. +From Coq Require Import ssreflect ssrfun. + +(** Quiver *) + +HB.mixin Record isQuiver Obj := { hom : Obj -> Obj -> Type }. + +HB.structure Definition Quiver := { Obj of isQuiver Obj }. + + +(*************************************** OTHER MIXINS *************) +Require Import Coq.Program.Equality. +Require Import FunctionalExtensionality. + +HB.mixin Record isMon T := { + munit : T; + mop : T -> T -> T; + massoc : associative mop; + mlid : left_id munit mop; + mrid : right_id munit mop; + }. +HB.structure Definition Mon := { T of isMon T }. + +HB.mixin Record isICAlg T := { + aop : T -> T -> T; + acomm : commutative aop; + aidem : idempotent aop; + }. +HB.structure Definition ICAlg := { T of isICAlg T }. + +HB.mixin Record isICMon T of ICAlg T := { + maunit : T; + maop : T -> T -> T; + maeq : forall x y, maop x y = aop x y; + maassoc : associative maop; + malid : left_id maunit maop; + marid : right_id maunit maop; + }. +HB.structure Definition ICMon := { T of isICMon T & isICAlg T }. + +#[wrapper] +HB.mixin Record hom_isMon T of Quiver T := + { hom_isMon_private : forall A B, isMon (@hom T A B) }. + +#[wrapper] +HB.mixin Record hom_isICAlg T of Quiver T := + { hom_isICAlg_private : forall A B, isICAlg (@hom T A B) }. + +HB.structure + Definition Mon_enriched_quiver := + { Obj of isQuiver Obj & hom_isMon Obj }. + +HB.structure + Definition ICAlg_enriched_quiver := + { Obj of isQuiver Obj & hom_isICAlg Obj }. + +Fail #[wrapper] +HB.mixin Record hom_isICMon T of Quiver T := + { hom_isICMon_private : forall A B, isICMon (@hom T A B) }. + +HB.factory Record isMICAlg T of Mon T := { + amop : T -> T -> T; + ameq : forall x y, amop x y = mop x y; + amcomm : commutative amop; + amidem : idempotent amop; + }. + +HB.builders Context T (f : isMICAlg T). + + Lemma amop_mop_eq : amop = mop. + destruct f; simpl. + eapply functional_extensionality; intro. + eapply functional_extensionality; intro. + auto. + Qed. + + Definition dum_comm := + @eq_rect (T -> T -> T) amop (@commutative T T) amcomm mop amop_mop_eq. + + Definition dum_idem := + @eq_rect (T -> T -> T) amop (@idempotent T) amidem mop amop_mop_eq. + + HB.instance Definition b_A : isICAlg T := + isICAlg.Build T mop dum_comm dum_idem. + + Lemma mop_aop_eq (x y: T) : mop x y = aop x y. + destruct f; auto. + Qed. + + HB.instance Definition b_M : isICMon T := + isICMon.Build T munit mop mop_aop_eq massoc mlid mrid. + +HB.end. + From f6e44589fc3aa28f8e138aaa0fc105b8e4330b1a Mon Sep 17 00:00:00 2001 From: ptorrx Date: Tue, 3 Oct 2023 13:36:42 +0200 Subject: [PATCH 022/147] added enriched_cat_case4.v --- tests/enriched_cat_case2.v | 4 +- tests/enriched_cat_case4.v | 111 +++++++++++++++++++++++++++++++++++++ 2 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 tests/enriched_cat_case4.v diff --git a/tests/enriched_cat_case2.v b/tests/enriched_cat_case2.v index 2502943fc..a9817e46d 100644 --- a/tests/enriched_cat_case2.v +++ b/tests/enriched_cat_case2.v @@ -40,8 +40,9 @@ HB.mixin Record isICMon T := { maidem : idempotent maop; }. #[verbose] -HB.structure Definition ICMon := { T of isICMon T }. +HB.structure Definition ICMon := { T of isICMon T & Mon T & ICAlg T }. +(* Lemma isICMon2isMon T : isICMon T -> isMon T. intro X. destruct X. @@ -53,6 +54,7 @@ Lemma isICMon2isICAlg T : isICMon T -> isICAlg T. destruct X. econstructor; eauto. Qed. + *) (* #[wrapper] diff --git a/tests/enriched_cat_case4.v b/tests/enriched_cat_case4.v new file mode 100644 index 000000000..6e5951aba --- /dev/null +++ b/tests/enriched_cat_case4.v @@ -0,0 +1,111 @@ +From HB Require Import structures. +From Coq Require Import ssreflect ssrfun. + +(** Quiver *) + +HB.mixin Record isQuiver Obj := { hom : Obj -> Obj -> Type }. + +HB.structure Definition Quiver := { Obj of isQuiver Obj }. + + +(*************************************** OTHER MIXINS *************) +Require Import Coq.Program.Equality. +Require Import FunctionalExtensionality. + +HB.mixin Record isM T (munit: T) (mop: T -> T -> T) := { + massoc : associative mop; + mlid : left_id munit mop; + mrid : right_id munit mop; + }. + +HB.mixin Record isMon T := { + munit : T; + mop : T -> T -> T; + mism : isM T munit mop; + }. +#[verbose] +HB.structure Definition Mon := { T of isMon T }. + +HB.mixin Record isIC T (aop: T -> T -> T) := { + comm : commutative aop; + idem : idempotent aop; + }. + +HB.mixin Record isICAlg T := { + aop : T -> T -> T; + ica : isIC T aop ; + }. +#[verbose] +HB.structure Definition ICAlg := { T of isICAlg T }. + +HB.mixin Record isICMon T := { + maunit : T; + maop : T -> T -> T; + mica : isIC T maop; + mon : isM T maunit maop; + }. +HB.structure Definition ICMon := { T of isICMon T & Mon T & ICAlg T }. + +#[wrapper] +HB.mixin Record hom_isMon T of Quiver T := + { hom_isMon_private : forall A B, isMon (@hom T A B) }. +#[verbose] +HB.structure Definition Mon_enriched_quiver := + { Obj of isQuiver Obj & hom_isMon Obj }. + +#[wrapper] +HB.mixin Record hom_isICAlg T of Quiver T := + { hom_isICAlg_private : forall A B, isICAlg (@hom T A B) }. +#[verbose] +HB.structure Definition ICAlg_enriched_quiver := + { Obj of isQuiver Obj & hom_isICAlg Obj }. + +#[wrapper] +HB.mixin Record hom_isICMon T of Quiver T := + { hom_isICMon_private : forall A B, isICMon (@hom T A B) }. +#[verbose] +HB.structure Definition ICMon_enriched_quiver := + { Obj of isQuiver Obj & hom_isICMon Obj }. + +HB.factory Record isMICAlg T of Mon T := { + amop : T -> T -> T; + ameq : forall x y, amop x y = mop x y; + amcomm : commutative amop; + amidem : idempotent amop; + }. + +HB.builders Context T (f : isMICAlg T). + + Lemma amop_mop_eq : amop = mop. + destruct f; simpl. + eapply functional_extensionality; intro. + eapply functional_extensionality; intro. + auto. + Qed. + + Definition dum_comm := + @eq_rect (T -> T -> T) amop (@commutative T T) amcomm mop amop_mop_eq. + + Definition dum_idem := + @eq_rect (T -> T -> T) amop (@idempotent T) amidem mop amop_mop_eq. + + Definition b_A : isIC T mop := + isIC.Build T mop dum_comm dum_idem. + + HB.instance Definition bb_A : isICAlg T := + isICAlg.Build T mop b_A. + + Lemma mop_aop_eq (x y: T) : mop x y = aop x y. + destruct f; auto. + Qed. + + Lemma b_M : isM T munit mop. + destruct f. + exact mism. + Qed. + + HB.instance Definition bb_M : isICMon T := + isICMon.Build T munit mop b_A b_M. + +HB.end. + From 9aebc2b9e864db1317cc81eef94d7039a0d4a6d8 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Tue, 3 Oct 2023 15:25:44 +0200 Subject: [PATCH 023/147] updated examples --- tests/enriched_cat_case1.v | 50 +++++++++++++++++++++----------------- tests/enriched_cat_case2.v | 12 ++++----- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/tests/enriched_cat_case1.v b/tests/enriched_cat_case1.v index 902afa6d8..91c0c01cd 100644 --- a/tests/enriched_cat_case1.v +++ b/tests/enriched_cat_case1.v @@ -12,32 +12,30 @@ HB.structure Definition Quiver := { Obj of isQuiver Obj }. Require Import Coq.Program.Equality. Require Import FunctionalExtensionality. -HB.mixin Record isMon T := { - munit : T; +HB.mixin Record isMagma T := { mop : T -> T -> T; - massoc : associative mop; +}. +HB.structure Definition Magma := { T of isMagma T }. + +HB.mixin Record isMon T of isMagma T := { + munit : T; + massoc : associative (mop : T -> T -> T); mlid : left_id munit mop; mrid : right_id munit mop; }. #[verbose] HB.structure Definition Mon := { T of isMon T }. -HB.mixin Record isICAlg T := { - aop : T -> T -> T; - acomm : commutative aop; - aidem : idempotent aop; +HB.mixin Record isICAlg T of isMagma T := { + acomm : commutative (mop : T -> T -> T); + aidem : idempotent (mop : T -> T -> T); }. #[verbose] HB.structure Definition ICAlg := { T of isICAlg T }. -HB.mixin Record isICMon T of ICAlg T := { - maunit : T; - maop : T -> T -> T; - maassoc : associative maop; - malid : left_id maunit maop; - marid : right_id maunit maop; - macomm : commutative maop; - maidem : idempotent maop; +HB.mixin Record isICMon T of isMagma T := { + ica: isICAlg T ; + mon: isMon T; }. #[verbose] HB.structure Definition ICMon := { T of isICMon T }. @@ -60,15 +58,14 @@ HB.structure { Obj of isQuiver Obj & hom_isICAlg Obj }. *) -Fail #[wrapper] +#[wrapper] HB.mixin Record hom_isICMon T of Quiver T := - { hom_isICMon_private : forall A B, isICMon (@hom T A B) }. -Fail #[verbose] + { hom_isICMon_private : forall A B, ICMon (@hom T A B) }. +#[verbose] HB.structure Definition ICMon_enriched_quiver := { Obj of isQuiver Obj & hom_isICMon Obj }. - HB.factory Record isMICAlg T of Mon T := { amop : T -> T -> T; ameq : forall x y, amop x y = mop x y; @@ -91,11 +88,20 @@ HB.builders Context T (f : isMICAlg T). Definition dum_idem := @eq_rect (T -> T -> T) amop (@idempotent T) amidem mop amop_mop_eq. - HB.instance Definition b_A : isICAlg T := - isICAlg.Build T mop dum_comm dum_idem. + HB.instance Definition b_Mg : isMagma T := + isMagma.Build T mop. + HB.instance Definition b_IC : isICAlg T := + isICAlg.Build T dum_comm dum_idem. + + Lemma M : isMon T. + destruct f; auto. + Qed. + HB.instance Definition b_M : isICMon T := - isICMon.Build T munit mop massoc mlid mrid dum_comm dum_idem. + isICMon.Build T b_IC M. HB.end. +(*******************************************************************) + diff --git a/tests/enriched_cat_case2.v b/tests/enriched_cat_case2.v index a9817e46d..8f9fb062a 100644 --- a/tests/enriched_cat_case2.v +++ b/tests/enriched_cat_case2.v @@ -32,12 +32,12 @@ HB.structure Definition ICAlg := { T of isICAlg T }. HB.mixin Record isICMon T := { maunit : T; - maop : T -> T -> T; - maassoc : associative maop; - malid : left_id maunit maop; - marid : right_id maunit maop; - macomm : commutative maop; - maidem : idempotent maop; + aop : T -> T -> T; + maassoc : associative aop; + malid : left_id maunit aop; + marid : right_id maunit aop; + macomm : commutative aop; + maidem : idempotent aop; }. #[verbose] HB.structure Definition ICMon := { T of isICMon T & Mon T & ICAlg T }. From 3ef5a1f06e2f2020d55fe1c12e7850d26e981152 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Tue, 3 Oct 2023 19:53:39 +0200 Subject: [PATCH 024/147] updated enriched_cat_case1.v, there are still problems --- tests/enriched_cat_case1.v | 184 +++++++++++++++++++++++++++++++++++-- 1 file changed, 177 insertions(+), 7 deletions(-) diff --git a/tests/enriched_cat_case1.v b/tests/enriched_cat_case1.v index 91c0c01cd..4a0104ca1 100644 --- a/tests/enriched_cat_case1.v +++ b/tests/enriched_cat_case1.v @@ -40,32 +40,47 @@ HB.mixin Record isICMon T of isMagma T := { #[verbose] HB.structure Definition ICMon := { T of isICMon T }. -(* + +(***** wrapping ****************************************************) + #[wrapper] -HB.mixin Record hom_isICAlg T of Quiver T := - { hom_isICAlg_private : forall A B, isICAlg (@hom T A B) }. +HB.mixin Record hom_isMagma T of Quiver T := + { hom_isMagma_private : forall A B, isMagma (@hom T A B) }. +HB.structure + Definition Magma_enriched_quiver := + { Obj of isQuiver Obj & hom_isMagma Obj }. +(* #[wrapper] HB.mixin Record hom_isMon T of Quiver T := + { hom_isMon_private : forall A B, Mon (@hom T A B) }. +*) +(* need to add explicitly Magma_enriched_quiver, otherwise switch + from mixin to structure *) +#[wrapper] +HB.mixin Record hom_isMon T of Quiver T & Magma_enriched_quiver T := { hom_isMon_private : forall A B, isMon (@hom T A B) }. - HB.structure Definition Mon_enriched_quiver := { Obj of isQuiver Obj & hom_isMon Obj }. +#[wrapper] +HB.mixin Record hom_isICAlg T of Quiver T & Magma_enriched_quiver T := + { hom_isICAlg_private : forall A B, isICAlg (@hom T A B) }. HB.structure Definition ICAlg_enriched_quiver := { Obj of isQuiver Obj & hom_isICAlg Obj }. -*) #[wrapper] -HB.mixin Record hom_isICMon T of Quiver T := - { hom_isICMon_private : forall A B, ICMon (@hom T A B) }. +HB.mixin Record hom_isICMon T of Quiver T & Magma_enriched_quiver T := + { hom_isICMon_private : forall A B, isICMon (@hom T A B) }. #[verbose] HB.structure Definition ICMon_enriched_quiver := { Obj of isQuiver Obj & hom_isICMon Obj }. +(*** factory ********************************************************) + HB.factory Record isMICAlg T of Mon T := { amop : T -> T -> T; ameq : forall x y, amop x y = mop x y; @@ -105,3 +120,158 @@ HB.end. (*******************************************************************) +(** INSTANCE 1 *********************************************** + +Object: Type, +Morphism: A -> option B +Structure: Monoid (from isMon) +*) + +HB.instance Definition funQ := isQuiver.Build Type + (fun A B => A -> option B). + +Definition funQ_comp {A B: Type} (f g: hom A B) : hom A B := + fun x => + match f x with + | Some _ => f x + | _ => g x end. + +Definition funQ_zero {A B: Type} : hom A B := + fun (_:A) => None. + +(* does not work without declaring the Magma wrapper *) +HB.instance Definition funQ_isMagma (A B: Type) : + isMagma (hom A B) := isMagma.Build _ funQ_comp. + +Program Definition funQ_isMon (A B: Type) : isMon (hom A B) := + isMon.Build _ funQ_zero _ _ _. +Obligation 1. + unfold associative; intros. + eapply functional_extensionality; intro a. + unfold mop; simpl. + unfold funQ_comp. + destruct (x a) eqn:K1. + simpl; auto. + destruct (y a); auto. +Qed. +Obligation 2. + unfold left_id; intros. + unfold funQ_comp; auto. +Qed. +Obligation 3. + unfold right_id, mop; simpl; intros. + unfold funQ_zero, funQ_comp; simpl. + eapply functional_extensionality; intro a. + destruct (x a); auto. +Qed. + +Fail HB.instance Definition funQ_Monoid (A B: Type) : + isMon (hom A B) := funQ_isMon A B. + + +(** INSTANCE 2 ********************************************** + +Object: ICMon.type +Morphism: ICMon.sort A -> ICMon.sort B +Structure: idempotent commutative monoid (by ICMon) +*) + +#[verbose] +HB.instance Definition icmfunQ := + isQuiver.Build ICMon.type + (fun A B => (ICMon.sort A) -> (ICMon.sort B)). + +Definition icmfunQ_comp {A B: ICMon.type} (f g: hom A B) : hom A B := + fun x => mop (f x) (g x). + +Definition icmfunQ_zero {A B: ICMon.type} : hom A B. + destruct B. + unfold hom; simpl; intro. + destruct class. + destruct enriched_cat_case1_isICMon_mixin. + destruct mon0. + exact munit0. +Defined. + +(* does not work without declaring the Magma wrapper *) +HB.instance Definition icmfunQ_isMagma (A B: ICMon.type) : + isMagma (hom A B) := isMagma.Build _ icmfunQ_comp. + +(* does not type-check without the Magma instance *) +Program Definition icmfunQ_isMon (A B: ICMon.type) : + isMon (hom A B) := isMon.Build (hom A B) icmfunQ_zero _ _ _. +Obligation 1. +unfold associative, mop; simpl; intros. +unfold icmfunQ_comp; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isICMon_mixin. +simpl in *. +destruct mon0. +eapply massoc0; auto. +Qed. +Obligation 2. +unfold left_id, mop; simpl; intros. +unfold icmfunQ_comp, icmfunQ_zero; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isICMon_mixin. +destruct mon0. +auto. +Qed. +Obligation 3. +unfold right_id, mop; simpl; intros. +unfold icmfunQ_comp, icmfunQ_zero; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isICMon_mixin. +destruct mon0. +auto. +Qed. + +Program Definition icmfunQ_isICAlg (A B: ICMon.type) : + isICAlg (hom A B) := isICAlg.Build (hom A B) _ _. +Obligation 1. +unfold commutative, mop; simpl; intros. +unfold icmfunQ_comp; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isICMon_mixin. +simpl in *. +destruct ica0. +eapply acomm0; auto. +Qed. +Obligation 2. +unfold idempotent, mop; simpl; intros. +unfold icmfunQ_comp; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isICMon_mixin. +simpl in *. +destruct ica0. +eapply aidem0; auto. +Qed. + +Program Definition icmfunQ_isICMon (A B: ICMon.type) : + isICMon (hom A B) := isICMon.Build (hom A B) _ _. +Obligation 1. +eapply icmfunQ_isICAlg. +Qed. +Obligation 2. +eapply icmfunQ_isMon. +Qed. + +Fail HB.instance Definition icmfunQ_isMonoid (A B: ICMon.type) : + isMon (hom A B) := icmfunQ_isMon A B. + +Fail HB.instance Definition icmfunQ_isICAlgebra (A B: ICMon.type) : + isICAlg (hom A B) := icmfunQ_isICAlg A B. + +Fail HB.instance Definition icmfunQ_isICMonoid (A B: ICMon.type) : + isICMon (hom A B) := icmfunQ_isICMon A B. + From 96a6113e6f6b31f5c73a8eb5ef4a99cd4a5588c3 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Tue, 3 Oct 2023 21:36:36 +0200 Subject: [PATCH 025/147] updated enriched_cat_case4.v, not finished but less problematic --- tests/enriched_cat_case1.v | 2 +- tests/enriched_cat_case4.v | 168 +++++++++++++++++++++++++++++++++++++ 2 files changed, 169 insertions(+), 1 deletion(-) diff --git a/tests/enriched_cat_case1.v b/tests/enriched_cat_case1.v index 4a0104ca1..8f7b55739 100644 --- a/tests/enriched_cat_case1.v +++ b/tests/enriched_cat_case1.v @@ -182,7 +182,7 @@ HB.instance Definition icmfunQ := (fun A B => (ICMon.sort A) -> (ICMon.sort B)). Definition icmfunQ_comp {A B: ICMon.type} (f g: hom A B) : hom A B := - fun x => mop (f x) (g x). + fun x => @mop B (f x) (g x). Definition icmfunQ_zero {A B: ICMon.type} : hom A B. destruct B. diff --git a/tests/enriched_cat_case4.v b/tests/enriched_cat_case4.v index 6e5951aba..6d294b78d 100644 --- a/tests/enriched_cat_case4.v +++ b/tests/enriched_cat_case4.v @@ -46,6 +46,9 @@ HB.mixin Record isICMon T := { }. HB.structure Definition ICMon := { T of isICMon T & Mon T & ICAlg T }. + +(*** wrapping ******************************************************) + #[wrapper] HB.mixin Record hom_isMon T of Quiver T := { hom_isMon_private : forall A B, isMon (@hom T A B) }. @@ -67,6 +70,8 @@ HB.mixin Record hom_isICMon T of Quiver T := HB.structure Definition ICMon_enriched_quiver := { Obj of isQuiver Obj & hom_isICMon Obj }. +(*** factory ********************************************************) + HB.factory Record isMICAlg T of Mon T := { amop : T -> T -> T; ameq : forall x y, amop x y = mop x y; @@ -109,3 +114,166 @@ HB.builders Context T (f : isMICAlg T). HB.end. +(**********************************************************************) + +(** INSTANCE 1 ********************************************************* + +Object: Type, +Morphism: A -> option B +Structure: Monoid (from isMon) +*) + +HB.instance Definition funQ := isQuiver.Build Type + (fun A B => A -> option B). + +Definition funQ_comp {A B: Type} (f g: hom A B) : hom A B := + fun x => + match f x with + | Some _ => f x + | _ => g x end. + +Definition funQ_zero {A B: Type} : hom A B := + fun (_:A) => None. + +Program Definition funQ_isM (A B: Type) : + isM (hom A B) funQ_zero funQ_comp := + isM.Build _ funQ_zero funQ_comp _ _ _. +Obligation 1. + unfold associative; intros. + unfold funQ_comp. + eapply functional_extensionality; intro a; simpl. + destruct (x a) eqn:K1. + simpl; auto. + destruct (y a); auto. +Qed. +Obligation 2. + unfold left_id; intros. + unfold funQ_comp; auto. +Qed. +Obligation 3. + unfold right_id; simpl; intros. + unfold funQ_zero, funQ_comp; simpl. + eapply functional_extensionality; intro a. + destruct (x a); auto. +Qed. + +HB.instance Definition funQ_isMonoid (A B: Type) : + isMon (hom A B) := + isMon.Build (hom A B) funQ_zero funQ_comp (funQ_isM A B). + + +(** INSTANCE 2 ********************************************** + +Object: ICMon.type +Morphism: ICMon.sort A -> ICMon.sort B +Structure: idempotent commutative monoid (by ICMon) +*) + +#[verbose] +HB.instance Definition icmfunQ := + isQuiver.Build ICMon.type + (fun A B => (ICMon.sort A) -> (ICMon.sort B)). + +Definition icmfunQ_comp {A B: ICMon.type} (f g: hom A B) : hom A B := + fun x => @maop B (f x) (g x). + +Definition icmfunQ_zero {A B: ICMon.type} : hom A B := fun _ => @maunit B. + +(* does not type-check without the Magma instance *) +Program Definition icmfunQ_isM (A B: ICMon.type) : + isM (hom A B) (@icmfunQ_zero A B) (@icmfunQ_comp A B) := + isM.Build (hom A B) icmfunQ_zero icmfunQ_comp _ _ _. +Obligation 1. +unfold associative; simpl; intros. +unfold icmfunQ_comp; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B eqn:B1. +destruct class eqn:class1. +destruct enriched_cat_case4_isMon_mixin eqn:C1. +simpl in *. +unfold maop; simpl. +unfold isICMon.maop; simpl. +destruct enriched_cat_case4_isICMon_mixin eqn:D1. +destruct mon0. +eapply massoc. +Qed. +Obligation 2. +unfold left_id; simpl; intros. +unfold icmfunQ_comp, icmfunQ_zero; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B eqn: B1. +destruct class eqn: class1. +destruct enriched_cat_case4_isMon_mixin eqn:C1; simpl in *. +destruct mism0 eqn:mism1. +destruct enriched_cat_case4_isICMon_mixin eqn:D1; simpl in *. +destruct mon0 eqn:mon1; simpl in *. +unfold maop; simpl. +eapply mlid0. +Qed. +Obligation 3. +unfold right_id; simpl; intros. +unfold icmfunQ_comp, icmfunQ_zero; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B eqn: B1. +destruct class eqn: class1. +destruct enriched_cat_case4_isMon_mixin eqn:C1; simpl in *. +destruct mism0 eqn:mism1. +destruct enriched_cat_case4_isICMon_mixin eqn:D1; simpl in *. +destruct mon0 eqn:mon1; simpl in *. +unfold maop; simpl. +eapply mrid0. +Qed. + +HB.instance Definition icmfunQ_isMonoid (A B: ICMon.type) : + isMon (hom A B) := + isMon.Build (hom A B) icmfunQ_zero icmfunQ_comp (icmfunQ_isM A B). + + + +Program Definition icmfunQ_isICAlg (A B: ICMon.type) : + isIC (hom A B) icmfunQ_comp := isIC.Build (hom A B) icmfunQ_comp _ _. +Obligation 1. +unfold commutative; simpl; intros. +unfold icmfunQ_comp; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case4_isICAlg_mixin. +unfold mop; simpl. +destruct enriched_cat_case4_isMon_mixin. +simpl. +simpl in x. +simpl in *. +destruct ica0. +eapply comm; auto. +Qed. +Obligation 2. +unfold idempotent, mop; simpl; intros. +unfold icmfunQ_comp; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isICMon_mixin. +simpl in *. +destruct ica0. +eapply aidem0; auto. +Qed. + +Program Definition icmfunQ_isICMon (A B: ICMon.type) : + isICMon (hom A B) := isICMon.Build (hom A B) _ _. +Obligation 1. +eapply icmfunQ_isICAlg. +Qed. +Obligation 2. +eapply icmfunQ_isMon. +Qed. + +Fail HB.instance Definition icmfunQ_isMonoid (A B: ICMon.type) : + isMon (hom A B) := icmfunQ_isMon A B. + +Fail HB.instance Definition icmfunQ_isICAlgebra (A B: ICMon.type) : + isICAlg (hom A B) := icmfunQ_isICAlg A B. + +Fail HB.instance Definition icmfunQ_isICMonoid (A B: ICMon.type) : + isICMon (hom A B) := icmfunQ_isICMon A B. + From 1292d1e78616067981dd7fbaa80450db47062ee5 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Wed, 4 Oct 2023 08:13:30 +0200 Subject: [PATCH 026/147] fix generation of wrapper-mixin when the mixin has deps --- HB/factory.elpi | 6 ++++-- tests/enriched_cat_case1.v | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/HB/factory.elpi b/HB/factory.elpi index da7d183f1..d6f537f04 100644 --- a/HB/factory.elpi +++ b/HB/factory.elpi @@ -242,8 +242,10 @@ xtr_fst_op Ty Gr1 :- pred xtr_snd_op i:term, o:gref. xtr_snd_op Ty Gr :- - Ty = (app [global _| Args]), - std.last Args (app [global Gr| _]). + Ty = (app [global Gr0| Args]), + factory-alias->gref Gr0 Gr1, + factory-nparams Gr1 N, + std.nth N Args (app [global Gr| _]). pred extract_wrapped i:indt-decl, o:gref. extract_wrapped In Out :- diff --git a/tests/enriched_cat_case1.v b/tests/enriched_cat_case1.v index 8f7b55739..cc456c7ad 100644 --- a/tests/enriched_cat_case1.v +++ b/tests/enriched_cat_case1.v @@ -165,7 +165,7 @@ Obligation 3. destruct (x a); auto. Qed. -Fail HB.instance Definition funQ_Monoid (A B: Type) : +HB.instance Definition funQ_Monoid (A B: Type) : isMon (hom A B) := funQ_isMon A B. From 457817c811043ffc9653c25342c6fdde386b406b Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Wed, 4 Oct 2023 08:26:39 +0200 Subject: [PATCH 027/147] add more tests --- tests/enriched_cat_case1.v | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/enriched_cat_case1.v b/tests/enriched_cat_case1.v index cc456c7ad..9ab4a8b52 100644 --- a/tests/enriched_cat_case1.v +++ b/tests/enriched_cat_case1.v @@ -130,6 +130,8 @@ Structure: Monoid (from isMon) HB.instance Definition funQ := isQuiver.Build Type (fun A B => A -> option B). +Check Type : Quiver.type. + Definition funQ_comp {A B: Type} (f g: hom A B) : hom A B := fun x => match f x with @@ -168,7 +170,8 @@ Qed. HB.instance Definition funQ_Monoid (A B: Type) : isMon (hom A B) := funQ_isMon A B. - +Check Type : Mon_enriched_quiver.type. + (** INSTANCE 2 ********************************************** Object: ICMon.type @@ -266,12 +269,13 @@ Obligation 2. eapply icmfunQ_isMon. Qed. -Fail HB.instance Definition icmfunQ_isMonoid (A B: ICMon.type) : +HB.instance Definition icmfunQ_isMonoid (A B: ICMon.type) : isMon (hom A B) := icmfunQ_isMon A B. -Fail HB.instance Definition icmfunQ_isICAlgebra (A B: ICMon.type) : +HB.instance Definition icmfunQ_isICAlgebra (A B: ICMon.type) : isICAlg (hom A B) := icmfunQ_isICAlg A B. -Fail HB.instance Definition icmfunQ_isICMonoid (A B: ICMon.type) : +HB.instance Definition icmfunQ_isICMonoid (A B: ICMon.type) : isICMon (hom A B) := icmfunQ_isICMon A B. +Check ICMon.type : ICAlg_enriched_quiver.type. From 66eb897434c9cb53ad450387063c656710b1244b Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Wed, 4 Oct 2023 08:46:09 +0200 Subject: [PATCH 028/147] cleanup --- tests/enriched_cat_case1.v | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/enriched_cat_case1.v b/tests/enriched_cat_case1.v index 9ab4a8b52..528cce395 100644 --- a/tests/enriched_cat_case1.v +++ b/tests/enriched_cat_case1.v @@ -58,21 +58,21 @@ HB.mixin Record hom_isMon T of Quiver T := (* need to add explicitly Magma_enriched_quiver, otherwise switch from mixin to structure *) #[wrapper] -HB.mixin Record hom_isMon T of Quiver T & Magma_enriched_quiver T := +HB.mixin Record hom_isMon T of Magma_enriched_quiver T := { hom_isMon_private : forall A B, isMon (@hom T A B) }. HB.structure Definition Mon_enriched_quiver := { Obj of isQuiver Obj & hom_isMon Obj }. #[wrapper] -HB.mixin Record hom_isICAlg T of Quiver T & Magma_enriched_quiver T := +HB.mixin Record hom_isICAlg T of Magma_enriched_quiver T := { hom_isICAlg_private : forall A B, isICAlg (@hom T A B) }. HB.structure Definition ICAlg_enriched_quiver := { Obj of isQuiver Obj & hom_isICAlg Obj }. #[wrapper] -HB.mixin Record hom_isICMon T of Quiver T & Magma_enriched_quiver T := +HB.mixin Record hom_isICMon T of Magma_enriched_quiver T := { hom_isICMon_private : forall A B, isICMon (@hom T A B) }. #[verbose] HB.structure @@ -103,9 +103,11 @@ HB.builders Context T (f : isMICAlg T). Definition dum_idem := @eq_rect (T -> T -> T) amop (@idempotent T) amidem mop amop_mop_eq. - HB.instance Definition b_Mg : isMagma T := - isMagma.Build T mop. - + (* Expected failure: + HB.instance Definition b_IC : isICAlg T := + isICAlg.Build T amcomm amidem. + *) + HB.instance Definition b_IC : isICAlg T := isICAlg.Build T dum_comm dum_idem. @@ -126,7 +128,6 @@ Object: Type, Morphism: A -> option B Structure: Monoid (from isMon) *) - HB.instance Definition funQ := isQuiver.Build Type (fun A B => A -> option B). From 41da96ed9390dc07b7818f682625cd8eff9f7073 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Wed, 4 Oct 2023 10:20:22 +0200 Subject: [PATCH 029/147] added enriched_cat_case5.v with more cases --- tests/enriched_cat_case5.v | 562 +++++++++++++++++++++++++++++++++++++ 1 file changed, 562 insertions(+) create mode 100644 tests/enriched_cat_case5.v diff --git a/tests/enriched_cat_case5.v b/tests/enriched_cat_case5.v new file mode 100644 index 000000000..2bbfee99b --- /dev/null +++ b/tests/enriched_cat_case5.v @@ -0,0 +1,562 @@ +From HB Require Import structures. +From Coq Require Import ssreflect ssrfun. + +(** Quiver *) + +HB.mixin Record isQuiver Obj := { hom : Obj -> Obj -> Type }. + +HB.structure Definition Quiver := { Obj of isQuiver Obj }. + + +(*************************************** OTHER MIXINS *************) +Require Import Coq.Program.Equality. +Require Import FunctionalExtensionality. + +HB.mixin Record isMagma T := { + mop : T -> T -> T; +}. +HB.structure Definition Magma := { T of isMagma T }. + +HB.mixin Record isMon T of isMagma T := { + munit : T; + massoc : associative (mop : T -> T -> T); + mlid : left_id munit mop; + mrid : right_id munit mop; + }. +#[verbose] +HB.structure Definition Mon := { T of isMon T }. + +HB.mixin Record isCAlg T of isMagma T := { + acomm : commutative (mop : T -> T -> T); + }. +#[verbose] +HB.structure Definition CAlg := { T of isCAlg T }. + +HB.mixin Record isIAlg T of isMagma T := { + aidem : idempotent (mop : T -> T -> T); + }. +#[verbose] +HB.structure Definition IAlg := { T of isIAlg T }. + +HB.mixin Record isICAlg T of isMagma T := { + isca : isCAlg T; + isia : isIAlg T; + }. +#[verbose] +HB.structure Definition ICAlg := { T of isICAlg T }. + +HB.mixin Record isCMon T of isMagma T := { + cca: isCAlg T ; + cmon: isMon T; + }. +#[verbose] +HB.structure Definition CMon := { T of isCMon T }. + +HB.mixin Record isIMon T of isMagma T := { + iia: isIAlg T ; + imon: isMon T; + }. +#[verbose] +HB.structure Definition IMon := { T of isIMon T }. + +HB.mixin Record isICMon T of isMagma T := { + ica: isICAlg T ; + mon: isMon T; + }. +#[verbose] +HB.structure Definition ICMon := { T of isICMon T }. + + +(***** wrapping ****************************************************) + +#[wrapper] +HB.mixin Record hom_isMagma T of Quiver T := + { hom_isMagma_private : forall A B, isMagma (@hom T A B) }. +HB.structure + Definition Magma_enriched_quiver := + { Obj of isQuiver Obj & hom_isMagma Obj }. + +(* +#[wrapper] +HB.mixin Record hom_isMon T of Quiver T := + { hom_isMon_private : forall A B, Mon (@hom T A B) }. +*) +(* need to add explicitly Magma_enriched_quiver, otherwise switch + from mixin to structure *) +#[wrapper] +HB.mixin Record hom_isMon T of Magma_enriched_quiver T := + { hom_isMon_private : forall A B, isMon (@hom T A B) }. +HB.structure + Definition Mon_enriched_quiver := + { Obj of isQuiver Obj & hom_isMon Obj }. + +#[wrapper] +HB.mixin Record hom_isCAlg T of Magma_enriched_quiver T := + { hom_isCAlg_private : forall A B, isCAlg (@hom T A B) }. +HB.structure + Definition CAlg_enriched_quiver := + { Obj of isQuiver Obj & hom_isCAlg Obj }. + +#[wrapper] +HB.mixin Record hom_isIAlg T of Magma_enriched_quiver T := + { hom_isIAlg_private : forall A B, isIAlg (@hom T A B) }. +HB.structure + Definition IAlg_enriched_quiver := + { Obj of isQuiver Obj & hom_isIAlg Obj }. + +#[wrapper] +HB.mixin Record hom_isICAlg T of Magma_enriched_quiver T := + { hom_isICAlg_private : forall A B, isICAlg (@hom T A B) }. +HB.structure + Definition ICAlg_enriched_quiver := + { Obj of isQuiver Obj & hom_isICAlg Obj }. + +#[wrapper] +HB.mixin Record hom_isCMon T of Magma_enriched_quiver T := + { hom_isCMon_private : forall A B, isCMon (@hom T A B) }. +#[verbose] +HB.structure + Definition CMon_enriched_quiver := + { Obj of isQuiver Obj & hom_isCMon Obj }. + +#[wrapper] +HB.mixin Record hom_isIMon T of Magma_enriched_quiver T := + { hom_isIMon_private : forall A B, isIMon (@hom T A B) }. +#[verbose] +HB.structure + Definition IMon_enriched_quiver := + { Obj of isQuiver Obj & hom_isIMon Obj }. + +#[wrapper] +HB.mixin Record hom_isICMon T of Magma_enriched_quiver T := + { hom_isICMon_private : forall A B, isICMon (@hom T A B) }. +#[verbose] +HB.structure + Definition ICMon_enriched_quiver := + { Obj of isQuiver Obj & hom_isICMon Obj }. + +(*** factory ********************************************************) + +HB.factory Record isMICAlg T of Mon T := { + amop : T -> T -> T; + ameq : forall x y, amop x y = mop x y; + amcomm : commutative amop; + amidem : idempotent amop; + }. + +HB.builders Context T (f : isMICAlg T). + + Lemma amop_mop_eq : amop = mop. + destruct f; simpl. + eapply functional_extensionality; intro. + eapply functional_extensionality; intro. + auto. + Qed. + + Definition dum_comm := + @eq_rect (T -> T -> T) amop (@commutative T T) amcomm mop amop_mop_eq. + + Definition dum_idem := + @eq_rect (T -> T -> T) amop (@idempotent T) amidem mop amop_mop_eq. + + HB.instance Definition b_C : isCAlg T := + isCAlg.Build T dum_comm. + + HB.instance Definition b_I : isIAlg T := + isIAlg.Build T dum_idem. + + HB.instance Definition b_IC : isICAlg T := + isICAlg.Build T b_C b_I. + + Lemma M : isMon T. + destruct f; auto. + Qed. + + HB.instance Definition b_M : isICMon T := + isICMon.Build T b_IC M. + +HB.end. + +(*******************************************************************) + +(** INSTANCE 1 *********************************************** + +Object: Type, +Morphism: A -> option B +Structure: Monoid (from isMon) +*) + +HB.instance Definition funQ := isQuiver.Build Type + (fun A B => A -> option B). + +Check Type : Quiver.type. + +Definition funQ_comp {A B: Type} (f g: hom A B) : hom A B := + fun x => + match f x with + | Some _ => f x + | _ => g x end. + +Definition funQ_zero {A B: Type} : hom A B := + fun (_:A) => None. + +(* does not work without declaring the Magma wrapper *) +HB.instance Definition funQ_isMagma (A B: Type) : + isMagma (hom A B) := isMagma.Build _ funQ_comp. + +Program Definition funQ_isMon (A B: Type) : isMon (hom A B) := + isMon.Build _ funQ_zero _ _ _. +Obligation 1. + unfold associative; intros. + eapply functional_extensionality; intro a. + unfold mop; simpl. + unfold funQ_comp. + destruct (x a) eqn:K1. + simpl; auto. + destruct (y a); auto. +Qed. +Obligation 2. + unfold left_id; intros. + unfold funQ_comp; auto. +Qed. +Obligation 3. + unfold right_id, mop; simpl; intros. + unfold funQ_zero, funQ_comp; simpl. + eapply functional_extensionality; intro a. + destruct (x a); auto. +Qed. + +Program Definition funQ_isIAlg (A B: Type) : + isIAlg (hom A B) := isIAlg.Build _ _. +Obligation 1. +unfold idempotent; intros. +eapply functional_extensionality; intro a. +unfold mop; simpl. +unfold funQ_comp; simpl. +destruct (x a); auto. +Qed. + +Program Definition funQ_isIMon (A B: Type) : + isIMon (hom A B) := isIMon.Build (hom A B) _ _. +Obligation 1. +eapply funQ_isIAlg. +Qed. +Obligation 2. +eapply funQ_isMon. +Qed. + +HB.instance Definition funQ_IAlgebra (A B: Type) : + isIAlg (hom A B) := funQ_isIAlg A B. + +HB.instance Definition funQ_IMonoid (A B: Type) : + isIMon (hom A B) := funQ_isIMon A B. + +Check Type : IMon_enriched_quiver.type. + + +(** INSTANCE 2 ********************************************** + +Object: CMon.type +Morphism: CMon.sort A -> CMon.sort B +Structure: commutative monoid (by CMon) +*) + +#[verbose] +HB.instance Definition cmfunQ := + isQuiver.Build CMon.type + (fun A B => (CMon.sort A) -> (CMon.sort B)). + +Definition cmfunQ_comp {A B: CMon.type} (f g: hom A B) : hom A B := + fun x => @mop B (f x) (g x). + +Definition cmfunQ_zero {A B: CMon.type} : hom A B. + destruct B. + unfold hom; simpl; intro. + destruct class. + destruct enriched_cat_case1_isCMon_mixin. + destruct cmon0. + exact munit0. +Defined. + +(* does not work without declaring the Magma wrapper *) +HB.instance Definition cmfunQ_isMagma (A B: CMon.type) : + isMagma (hom A B) := isMagma.Build _ cmfunQ_comp. + +(* does not type-check without the Magma instance *) +Program Definition cmfunQ_isMon (A B: CMon.type) : + isMon (hom A B) := isMon.Build (hom A B) cmfunQ_zero _ _ _. +Obligation 1. +unfold associative, mop; simpl; intros. +unfold cmfunQ_comp; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isCMon_mixin. +simpl in *. +destruct cmon0. +eapply massoc0; auto. +Qed. +Obligation 2. +unfold left_id, mop; simpl; intros. +unfold cmfunQ_comp, cmfunQ_zero; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isCMon_mixin. +destruct cmon0. +auto. +Qed. +Obligation 3. +unfold right_id, mop; simpl; intros. +unfold cmfunQ_comp, cmfunQ_zero; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isCMon_mixin. +destruct cmon0. +auto. +Qed. + +Program Definition cmfunQ_isCAlg (A B: CMon.type) : + isCAlg (hom A B) := isCAlg.Build (hom A B) _. +Obligation 1. +unfold commutative, mop; simpl; intros. +unfold cmfunQ_comp; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isCMon_mixin. +simpl in *. +destruct cca0. +eapply acomm0; auto. +Qed. + +Program Definition cmfunQ_isCMon (A B: CMon.type) : + isCMon (hom A B) := isCMon.Build (hom A B) _ _. +Obligation 1. +eapply cmfunQ_isCAlg. +Qed. +Obligation 2. +eapply cmfunQ_isMon. +Qed. + +HB.instance Definition cmfunQ_isMonoid (A B: CMon.type) : + isMon (hom A B) := cmfunQ_isMon A B. + +HB.instance Definition cmfunQ_isICAlgebra (A B: CMon.type) : + isCAlg (hom A B) := cmfunQ_isCAlg A B. + +HB.instance Definition icmfunQ_isCMonoid (A B: CMon.type) : + isCMon (hom A B) := cmfunQ_isCMon A B. + +Check CMon.type : CAlg_enriched_quiver.type. + +(*********************************************************) + +(* +Object: IMon.type +Morphism: IMon.sort A -> IMon.sort B +Structure: idempotent monoid (by IMon) +*) + +#[verbose] +HB.instance Definition imfunQ := + isQuiver.Build IMon.type + (fun A B => (IMon.sort A) -> (IMon.sort B)). + +Definition imfunQ_comp {A B: IMon.type} (f g: hom A B) : hom A B := + fun x => @mop B (f x) (g x). + +Definition imfunQ_zero {A B: IMon.type} : hom A B. + destruct B. + unfold hom; simpl; intro. + destruct class. + destruct enriched_cat_case1_isIMon_mixin. + destruct imon0. + exact munit0. +Defined. + +(* does not work without declaring the Magma wrapper *) +HB.instance Definition imfunQ_isMagma (A B: IMon.type) : + isMagma (hom A B) := isMagma.Build _ imfunQ_comp. + +(* does not type-check without the Magma instance *) +Program Definition imfunQ_isMon (A B: IMon.type) : + isMon (hom A B) := isMon.Build (hom A B) imfunQ_zero _ _ _. +Obligation 1. +unfold associative, mop; simpl; intros. +unfold imfunQ_comp; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isIMon_mixin. +simpl in *. +destruct imon0. +eapply massoc0; auto. +Qed. +Obligation 2. +unfold left_id, mop; simpl; intros. +unfold imfunQ_comp, imfunQ_zero; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isIMon_mixin. +destruct imon0. +auto. +Qed. +Obligation 3. +unfold right_id, mop; simpl; intros. +unfold imfunQ_comp, imfunQ_zero; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isIMon_mixin. +destruct imon0. +auto. +Qed. + +Program Definition imfunQ_isIAlg (A B: IMon.type) : + isIAlg (hom A B) := isIAlg.Build (hom A B) _. +Obligation 1. +unfold idempotent, mop; simpl; intros. +unfold imfunQ_comp; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isIMon_mixin. +simpl in *. +destruct iia0; auto. +Qed. + +Program Definition imfunQ_isIMon (A B: IMon.type) : + isIMon (hom A B) := isIMon.Build (hom A B) _ _. +Obligation 1. +eapply imfunQ_isIAlg. +Qed. +Obligation 2. +eapply imfunQ_isMon. +Qed. + +HB.instance Definition imfunQ_isMonoid (A B: IMon.type) : + isMon (hom A B) := imfunQ_isMon A B. + +HB.instance Definition imfunQ_isIAlgebra (A B: IMon.type) : + isIAlg (hom A B) := imfunQ_isIAlg A B. + +HB.instance Definition imfunQ_isIMonoid (A B: IMon.type) : + isIMon (hom A B) := imfunQ_isIMon A B. + +Check IMon.type : IAlg_enriched_quiver.type. + +(*********************************************************) +(* +Object: ICMon.type +Morphism: ICMon.sort A -> ICMon.sort B +Structure: idempotent commutative monoid (by ICMon) +*) + +#[verbose] +HB.instance Definition icmfunQ := + isQuiver.Build ICMon.type + (fun A B => (ICMon.sort A) -> (ICMon.sort B)). + +Definition icmfunQ_comp {A B: ICMon.type} (f g: hom A B) : hom A B := + fun x => @mop B (f x) (g x). + +Definition icmfunQ_zero {A B: ICMon.type} : hom A B. + destruct B. + unfold hom; simpl; intro. + destruct class. + destruct enriched_cat_case1_isICMon_mixin. + destruct mon0. + exact munit0. +Defined. + +(* does not work without declaring the Magma wrapper *) +HB.instance Definition icmfunQ_isMagma (A B: ICMon.type) : + isMagma (hom A B) := isMagma.Build _ icmfunQ_comp. + +(* does not type-check without the Magma instance *) +Program Definition icmfunQ_isMon (A B: ICMon.type) : + isMon (hom A B) := isMon.Build (hom A B) icmfunQ_zero _ _ _. +Obligation 1. +unfold associative, mop; simpl; intros. +unfold icmfunQ_comp; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isICMon_mixin. +simpl in *. +destruct mon0. +eapply massoc0; auto. +Qed. +Obligation 2. +unfold left_id, mop; simpl; intros. +unfold icmfunQ_comp, icmfunQ_zero; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isICMon_mixin. +destruct mon0. +auto. +Qed. +Obligation 3. +unfold right_id, mop; simpl; intros. +unfold icmfunQ_comp, icmfunQ_zero; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isICMon_mixin. +destruct mon0. +auto. +Qed. + + +Program Definition icmfunQ_isICAlg (A B: ICMon.type) : + isICAlg (hom A B) := isICAlg.Build (hom A B) _ _. +Obligation 1. +econstructor. +unfold commutative, mop; simpl; intros. +unfold icmfunQ_comp; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isICMon_mixin. +simpl in *. +destruct ica0. +destruct isca0. +eapply acomm0; auto. +Qed. +Obligation 2. +econstructor. +unfold idempotent, mop; simpl; intros. +unfold icmfunQ_comp; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isICMon_mixin. +simpl in *. +destruct ica0. +destruct isia0. +eapply aidem0; auto. +Qed. + +Program Definition icmfunQ_isICMon (A B: ICMon.type) : + isICMon (hom A B) := isICMon.Build (hom A B) _ _. +Obligation 1. +eapply icmfunQ_isICAlg. +Qed. +Obligation 2. +eapply icmfunQ_isMon. +Qed. + +HB.instance Definition icmfunQ_isMonoid (A B: ICMon.type) : + isMon (hom A B) := icmfunQ_isMon A B. + +HB.instance Definition icmfunQ_isICAlgebra (A B: ICMon.type) : + isICAlg (hom A B) := icmfunQ_isICAlg A B. + +HB.instance Definition icmfunQ_isICMonoid (A B: ICMon.type) : + isICMon (hom A B) := icmfunQ_isICMon A B. + +Check ICMon.type : ICAlg_enriched_quiver.type. From 30debed988de33859a2a505462b2290b692068d9 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Wed, 4 Oct 2023 10:47:57 +0200 Subject: [PATCH 030/147] completed enriched_cat_case4.v --- tests/enriched_cat_case4.v | 59 +++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/tests/enriched_cat_case4.v b/tests/enriched_cat_case4.v index 6d294b78d..92479861f 100644 --- a/tests/enriched_cat_case4.v +++ b/tests/enriched_cat_case4.v @@ -224,56 +224,55 @@ unfold maop; simpl. eapply mrid0. Qed. -HB.instance Definition icmfunQ_isMonoid (A B: ICMon.type) : - isMon (hom A B) := - isMon.Build (hom A B) icmfunQ_zero icmfunQ_comp (icmfunQ_isM A B). - - - -Program Definition icmfunQ_isICAlg (A B: ICMon.type) : +Program Definition icmfunQ_isIC (A B: ICMon.type) : isIC (hom A B) icmfunQ_comp := isIC.Build (hom A B) icmfunQ_comp _ _. Obligation 1. unfold commutative; simpl; intros. unfold icmfunQ_comp; simpl; intros. eapply functional_extensionality; intro x0. -destruct B. -destruct class. -destruct enriched_cat_case4_isICAlg_mixin. -unfold mop; simpl. -destruct enriched_cat_case4_isMon_mixin. +unfold maop. +unfold isICMon.maop; simpl. +destruct B eqn:B1. +destruct class eqn:class1. +destruct enriched_cat_case4_isICMon_mixin eqn:D1. simpl. -simpl in x. -simpl in *. -destruct ica0. -eapply comm; auto. +destruct mica0. +eapply comm. Qed. Obligation 2. unfold idempotent, mop; simpl; intros. unfold icmfunQ_comp; simpl; intros. eapply functional_extensionality; intro x0. -destruct B. -destruct class. -destruct enriched_cat_case1_isICMon_mixin. -simpl in *. -destruct ica0. -eapply aidem0; auto. +unfold maop. +unfold isICMon.maop; simpl. +destruct B eqn:B1. +destruct class eqn:class1. +destruct enriched_cat_case4_isICMon_mixin eqn:D1. +simpl. +destruct mica0. +eapply idem. Qed. Program Definition icmfunQ_isICMon (A B: ICMon.type) : - isICMon (hom A B) := isICMon.Build (hom A B) _ _. + isICMon (hom A B) := isICMon.Build (hom A B) icmfunQ_zero icmfunQ_comp _ _. Obligation 1. -eapply icmfunQ_isICAlg. +eapply icmfunQ_isIC. Qed. Obligation 2. -eapply icmfunQ_isMon. +eapply icmfunQ_isM. Qed. -Fail HB.instance Definition icmfunQ_isMonoid (A B: ICMon.type) : - isMon (hom A B) := icmfunQ_isMon A B. +HB.instance Definition icmfunQ_isMonoid (A B: ICMon.type) : + isMon (hom A B) := + isMon.Build (hom A B) icmfunQ_zero icmfunQ_comp (icmfunQ_isM A B). -Fail HB.instance Definition icmfunQ_isICAlgebra (A B: ICMon.type) : - isICAlg (hom A B) := icmfunQ_isICAlg A B. +HB.instance Definition icmfunQ_isICAlgebra (A B: ICMon.type) : + isICAlg (hom A B) := + isICAlg.Build (hom A B) icmfunQ_comp (icmfunQ_isIC A B). -Fail HB.instance Definition icmfunQ_isICMonoid (A B: ICMon.type) : +HB.instance Definition icmfunQ_isICMonoid (A B: ICMon.type) : isICMon (hom A B) := icmfunQ_isICMon A B. + + + From 7d113d0b12daaead61697199cec1dc6cbab69fd6 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Wed, 4 Oct 2023 10:03:20 +0200 Subject: [PATCH 031/147] note --- HB/factory.elpi | 1 + 1 file changed, 1 insertion(+) diff --git a/HB/factory.elpi b/HB/factory.elpi index d6f537f04..d63c54a3c 100644 --- a/HB/factory.elpi +++ b/HB/factory.elpi @@ -242,6 +242,7 @@ xtr_fst_op Ty Gr1 :- pred xtr_snd_op i:term, o:gref. xtr_snd_op Ty Gr :- + % TODO: use factory? from database.elpi Ty = (app [global Gr0| Args]), factory-alias->gref Gr0 Gr1, factory-nparams Gr1 N, From d3dce627f34caeaedb70217c964c21ffd2e5157a Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Wed, 4 Oct 2023 10:04:23 +0200 Subject: [PATCH 032/147] validate structure declaration and wrap is the wrapper already exists --- HB/structure.elpi | 65 +++++++++++++++++++++++++++++-------- tests/monoid_enriched_cat.v | 22 +++++++++++-- 2 files changed, 72 insertions(+), 15 deletions(-) diff --git a/HB/structure.elpi b/HB/structure.elpi index 0110b6f11..d0a2976c5 100644 --- a/HB/structure.elpi +++ b/HB/structure.elpi @@ -13,8 +13,8 @@ declare Module BSkel Sort :- std.do! [ re-enable-id-phant BNoId B, private.sigT->list-w-params B GRFSwP_or_ThingtoBeWrapped ClosureCheck, - % do some work to go back to - GRFSwP_or_ThingtoBeWrapped = GRFSwP, + % do some work to go back to factories on a single subject + private.lift-to-the-subject GRFSwP_or_ThingtoBeWrapped GRFSwP, factories-provide GRFSwP PMLwP, @@ -630,17 +630,35 @@ if-coverage-not-good-error.one _ _. % new class is the first covering M % use that structure to synthesize the type of the wrapper, eg % hom belongs to Quiver, hence hom_isMon takes a "T of Quiver T" -pred product->triples i:term, o:list (w-args factoryname), o:bool. -product->triples {{ lib:hb.prod lp:A lp:B }} L ClosureCheck :- !, - product->triples B GRB ClosureCheck, - product->triples A GRA _, +% checks if the term is forall A B C, Factory ... (Op A B C) ... +pred factory-on-some-structure-op? i:term, i:list term, o:gref, o:constant. +factory-on-some-structure-op? (prod N Ty Bo) VS F OP :- + @pi-decl N Ty x\ + factory-on-some-structure-op? (Bo x) [x|VS] F OP. +factory-on-some-structure-op? T VS F OP :- + factory? T (triple F _ Subject), + coq.safe-dest-app Subject (global (const OP)) Args, + exported-op _ _ OP, + std.appendR _ {std.rev VS} Args. + +kind factory-on-subject type. +type factory-on-the-type w-args factoryname -> factory-on-subject. +type factory-on-structure-op term -> factoryname -> constant -> factory-on-subject. + +pred product->triples i:term, i:term, o:list factory-on-subject, o:bool. +product->triples {{ lib:hb.prod lp:A lp:B }} T L ClosureCheck :- !, + product->triples B T GRB ClosureCheck, + product->triples A T GRA _, std.append GRA GRB L. -product->triples {{ True }} [] tt :- !. -product->triples {{ False }} [] ff :- !. -product->triples A [GR] tt :- std.assert! (factory? A GR) "A structure can only mention known factories". -% product->triples A [GR] tt :- factory-on-some-structure-op? A GR. - -pred sigT->list-w-params i:term, o:list-w-params factoryname, o:bool. +product->triples {{ True }} _ [] tt :- !. +product->triples {{ False }} _ [] ff :- !. +product->triples A T [factory-on-the-type F] tt :- factory? A F, F = triple _ _ T, !. +product->triples A _ [factory-on-structure-op A F OP] tt :- factory-on-some-structure-op? A [] F OP, !. +product->triples A T _ _ :- + coq.error "HB: expecting a factory on" {coq.term->string T} + "or a factory on a structure operation. Got:" {coq.term->string A}. + +pred sigT->list-w-params i:term, o:w-params (list factory-on-subject), o:bool. sigT->list-w-params (fun N T B) L C :- coq.name->id N ID, % TODO: we should read the ID from the definition type which is an arity containing ids L = w-params.cons ID T Rest, @@ -650,7 +668,28 @@ sigT->list-w-params {{ lib:@hb.sigT _ lp:{{ fun N Ty B }} }} L C :- coq.name->id N ID, % TODO: we should read the ID from the definition type which is an arity containing ids L = w-params.nil ID Ty Rest, @pi-decl N Ty t\ - product->triples (B t) (Rest t) C. + product->triples (B t) t (Rest t) C. + +pred lift-to-the-subject i:w-params (list factory-on-subject), o:list-w-params factoryname. +lift-to-the-subject (w-params.cons ID T Rest) (w-params.cons ID T Rest1) :- + @pi-parameter ID T x\ + lift-to-the-subject (Rest x) (Rest1 x). +lift-to-the-subject (w-params.nil ID T Rest) (w-params.nil ID T Rest1) :- + @pi-parameter ID T x\ + lift-to-the-subject.aux (Rest x) x (Rest1 x). +lift-to-the-subject.aux [] _ []. +lift-to-the-subject.aux [factory-on-the-type F|Rest] T [F|Rest1] :- + lift-to-the-subject.aux Rest T Rest1. +lift-to-the-subject.aux [factory-on-structure-op Expr F OP|Rest] T [WF|Rest1] :- + wrapper-mixin Wrapper (const OP) F, !, + factory-nparams Wrapper NParams, + coq.mk-app {coq.env.global Wrapper} {std.append {coq.mk-n-holes NParams} [T]} W, + factory? W WF, + coq.say Expr "->" WF, + lift-to-the-subject.aux Rest T Rest1. +lift-to-the-subject.aux [factory-on-structure-op Expr _ _|_] _ _ :- + coq.error "NYI: automatic wrapping for" {coq.term->string Expr}. + % M is the gref of the wrapper mixin. % C gets now instantiated to the projection, i.e. hom_isMon_private. diff --git a/tests/monoid_enriched_cat.v b/tests/monoid_enriched_cat.v index 1fb4c0206..aa707c529 100644 --- a/tests/monoid_enriched_cat.v +++ b/tests/monoid_enriched_cat.v @@ -51,17 +51,35 @@ Fail HB.structure HB.mixin Record hom_isMon T of Quiver T := { hom_isMon_private : forall A B, isMon (@hom T A B) }. + +Fail HB.structure + Definition Monoid_enriched_quiver := + { Obj of isQuiver Obj & + (forall A B : Obj, isMon (hom A B)) }. + +(* which one is best? *) +Succeed HB.structure + Definition Monoid_enriched_quiver := + { Obj of isQuiver Obj & + (forall A B : Obj, isMon (@hom (Quiver.clone Obj _) A B)) }. +HB.structure + Definition Monoid_enriched_quiver := + { Obj of isQuiver Obj & + (forall A B (* : Quiver.sort _ *), isMon (hom A B)) }. + + (* Print Canonical Projections. *) (* About hom_isMon.hom_isMon_private. *) (* About hom_isMon_private. *) (* Step 2: at structure declaration, export the main and only projection of each declared wrapper as an instance of the wrapped structure on - its subject *) + its subject #[verbose] HB.structure Definition Monoid_enriched_quiver := { Obj of isQuiver Obj & hom_isMon Obj }. - + *) + (* About hom_isMon.hom_isMon_private. *) (* About hom_isMon_private. *) From cad4f2099c268b8d5409e2ed1992fa948ce7a558 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Wed, 4 Oct 2023 10:51:19 +0200 Subject: [PATCH 033/147] a bit unsure about this, it looks too smart in some cases we should juggle with the section or infer by hand... --- HB/common/utils.elpi | 19 +++++++++++++++++++ HB/structure.elpi | 5 ++++- tests/monoid_enriched_cat.v | 9 +++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/HB/common/utils.elpi b/HB/common/utils.elpi index de87dc33f..a5b4d64ba 100644 --- a/HB/common/utils.elpi +++ b/HB/common/utils.elpi @@ -315,6 +315,25 @@ re-enable-id-phant T T1 :- (pi f1 f2 t v\ copy {{lib:@hb.ignore_disabled lp:t lp:f1 lp:v lp:f2}} {{lib:@hb.ignore lp:t lp:v}} :- !) => copy T T1. +pred failsafe-structure-inference i:term, o:term. +failsafe-structure-inference T T1 :- + (pi OP Args Args1\ + copy (app [global (const OP)|Args]) (app [global (const OP)| Args1]) :- + exported-op _ _ OP, !, eta-structure-record OP Args Args1) => + copy T T1. + +pred eta-structure-record i:constant, i:list term, o:list term. +eta-structure-record OP L L1 :- + exported-op M _ OP, mixin-first-class M Class, factory-nparams Class NP, + std.split-at NP L Params [S|Rest], + var S, + class-def (class Class Structure _), + get-constructor Structure K, + std.map Params copy Params1, + std.map Rest copy Rest1, + coq.mk-app {coq.env.global K} {std.append Params1 [_,_]} EtaS, + std.append Params1 [EtaS|Rest1] L1. + pred prod-last i:term, o:term. prod-last (prod N S X) Y :- !, @pi-decl N S x\ prod-last (X x) Y. prod-last X X :- !. diff --git a/HB/structure.elpi b/HB/structure.elpi index d0a2976c5..e80b771f6 100644 --- a/HB/structure.elpi +++ b/HB/structure.elpi @@ -9,8 +9,11 @@ pred declare i:string, i:term, i:sort. pred declare i:string, i:term, i:universe. declare Module BSkel Sort :- std.do! [ disable-id-phant BSkel BSkelNoId, - std.assert-ok! (coq.elaborate-skeleton BSkelNoId _ BNoId) "illtyped structure definition", + failsafe-structure-inference BSkelNoId BSkelNoIdX, + coq.say BSkelNoIdX, + std.assert-ok! (coq.elaborate-skeleton BSkelNoIdX _ BNoId) "illtyped structure definition", re-enable-id-phant BNoId B, + private.sigT->list-w-params B GRFSwP_or_ThingtoBeWrapped ClosureCheck, % do some work to go back to factories on a single subject diff --git a/tests/monoid_enriched_cat.v b/tests/monoid_enriched_cat.v index aa707c529..a0a795288 100644 --- a/tests/monoid_enriched_cat.v +++ b/tests/monoid_enriched_cat.v @@ -52,12 +52,17 @@ HB.mixin Record hom_isMon T of Quiver T := { hom_isMon_private : forall A B, isMon (@hom T A B) }. -Fail HB.structure +Succeed HB.structure Definition Monoid_enriched_quiver := { Obj of isQuiver Obj & (forall A B : Obj, isMon (hom A B)) }. -(* which one is best? *) +Succeed HB.structure + Definition Monoid_enriched_quiver := + { Obj of (*isQuiver Obj & once we wrap we pull this in as a dep! *) + (forall A B : Obj, isMon (hom A B)) }. + + (* which one is best? *) Succeed HB.structure Definition Monoid_enriched_quiver := { Obj of isQuiver Obj & From 4e80affb44b1d143645bcc7d9e4787321f07e191 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Wed, 4 Oct 2023 20:27:10 +0200 Subject: [PATCH 034/147] added enriched_cat_case6.v --- tests/enriched_cat_case1.v | 10 + tests/enriched_cat_case5.v | 6 +- tests/enriched_cat_case6.v | 600 +++++++++++++++++++++++++++++++++++++ 3 files changed, 613 insertions(+), 3 deletions(-) create mode 100644 tests/enriched_cat_case6.v diff --git a/tests/enriched_cat_case1.v b/tests/enriched_cat_case1.v index 528cce395..845c62fc6 100644 --- a/tests/enriched_cat_case1.v +++ b/tests/enriched_cat_case1.v @@ -43,6 +43,7 @@ HB.structure Definition ICMon := { T of isICMon T }. (***** wrapping ****************************************************) + #[wrapper] HB.mixin Record hom_isMagma T of Quiver T := { hom_isMagma_private : forall A B, isMagma (@hom T A B) }. @@ -54,6 +55,10 @@ HB.structure #[wrapper] HB.mixin Record hom_isMon T of Quiver T := { hom_isMon_private : forall A B, Mon (@hom T A B) }. +#[verbose] +HB.structure + Definition Mon_enriched_quiver := + { Obj of isQuiver Obj & hom_isMon Obj }. *) (* need to add explicitly Magma_enriched_quiver, otherwise switch from mixin to structure *) @@ -168,10 +173,15 @@ Obligation 3. destruct (x a); auto. Qed. +Fail Check Type : Mon_enriched_quiver.type. +Fail Check hom (nat:Type) nat: Mon.type. + HB.instance Definition funQ_Monoid (A B: Type) : isMon (hom A B) := funQ_isMon A B. Check Type : Mon_enriched_quiver.type. +Check hom (nat:Type) nat: Mon.type. + (** INSTANCE 2 ********************************************** diff --git a/tests/enriched_cat_case5.v b/tests/enriched_cat_case5.v index 2bbfee99b..f27137dd5 100644 --- a/tests/enriched_cat_case5.v +++ b/tests/enriched_cat_case5.v @@ -144,13 +144,13 @@ HB.factory Record isMICAlg T of Mon T := { amidem : idempotent amop; }. -HB.builders Context T (f : isMICAlg T). +HB.builders Context T (_ : isMICAlg T). Lemma amop_mop_eq : amop = mop. - destruct f; simpl. + (* destruct f; simpl. *) eapply functional_extensionality; intro. eapply functional_extensionality; intro. - auto. + apply ameq. Qed. Definition dum_comm := diff --git a/tests/enriched_cat_case6.v b/tests/enriched_cat_case6.v new file mode 100644 index 000000000..e9df748d1 --- /dev/null +++ b/tests/enriched_cat_case6.v @@ -0,0 +1,600 @@ +From HB Require Import structures. +From Coq Require Import ssreflect ssrfun. + +(** Quiver *) + +HB.mixin Record isQuiver Obj := { hom : Obj -> Obj -> Type }. + +HB.structure Definition Quiver := { Obj of isQuiver Obj }. + + +(*************************************** OTHER MIXINS *************) +Require Import Coq.Program.Equality. +Require Import FunctionalExtensionality. + +HB.mixin Record isMagma T := { + mop : T -> T -> T; +}. +HB.structure Definition Magma := { T of isMagma T }. + +HB.mixin Record isMon T of isMagma T := { + munit : T; + massoc : associative (mop : T -> T -> T); + mlid : left_id munit mop; + mrid : right_id munit mop; + }. +#[verbose] +HB.structure Definition Mon := { T of isMon T }. + +HB.mixin Record isCAlg T of isMagma T := { + acomm : commutative (mop : T -> T -> T); + }. +#[verbose] +HB.structure Definition CAlg := { T of isCAlg T }. + +HB.mixin Record isIAlg T of isMagma T := { + aidem : idempotent (mop : T -> T -> T); + }. +#[verbose] +HB.structure Definition IAlg := { T of isIAlg T }. + +(* HB.mixin Record isICAlg T of isMagma T & IAlg T & CAlg T := { + }. *) +#[verbose] +HB.structure Definition ICAlg := { T of CAlg T & IAlg T }. + +(* HB.mixin Record isCMon T of isMagma T := { + cca: isCAlg T ; + cmon: isMon T; + }. *) +#[verbose] +HB.structure Definition CMon := { T of Mon T & CAlg T }. + +(* +HB.mixin Record isIMon T of isMagma T := { + iia: isIAlg T ; + imon: isMon T; + }. *) +#[verbose] +HB.structure Definition IMon := { T of Mon T & IAlg T }. + +(* +HB.mixin Record isICMon T of isMagma T := { + ica: isICAlg T ; + mon: isMon T; + }. +*) +#[verbose] +HB.structure Definition ICMon := { T of IMon T & CMon T }. + + +(***** wrapping ****************************************************) + +#[wrapper] +HB.mixin Record hom_isMagma T of Quiver T := + { hom_isMagma_private : forall A B, isMagma (@hom T A B) }. +HB.structure + Definition Magma_enriched_quiver := + { Obj of isQuiver Obj & hom_isMagma Obj }. + +(* +#[wrapper] +HB.mixin Record hom_isMon T of Quiver T := + { hom_isMon_private : forall A B, Mon (@hom T A B) }. +*) +(* need to add explicitly Magma_enriched_quiver, otherwise switch + from mixin to structure *) +#[wrapper] +HB.mixin Record hom_isMon T of Magma_enriched_quiver T := + { hom_isMon_private : forall A B, isMon (@hom T A B) }. +HB.structure + Definition Mon_enriched_quiver := + { Obj of isQuiver Obj & hom_isMon Obj }. + +#[wrapper] +HB.mixin Record hom_isCAlg T of Magma_enriched_quiver T := + { hom_isCAlg_private : forall A B, isCAlg (@hom T A B) }. +HB.structure + Definition CAlg_enriched_quiver := + { Obj of isQuiver Obj & hom_isCAlg Obj }. + +#[wrapper] +HB.mixin Record hom_isIAlg T of Magma_enriched_quiver T := + { hom_isIAlg_private : forall A B, isIAlg (@hom T A B) }. +HB.structure + Definition IAlg_enriched_quiver := + { Obj of isQuiver Obj & hom_isIAlg Obj }. + +(* +#[wrapper] +HB.mixin Record hom_isICAlg T of Magma_enriched_quiver T := + { hom_isICAlg_private : forall A B, isICAlg (@hom T A B) }. +HB.structure + Definition ICAlg_enriched_quiver := + { Obj of isQuiver Obj & hom_isICAlg Obj }. + +#[wrapper] +HB.mixin Record hom_isCMon T of Magma_enriched_quiver T := + { hom_isCMon_private : forall A B, isCMon (@hom T A B) }. +#[verbose] +HB.structure + Definition CMon_enriched_quiver := + { Obj of isQuiver Obj & hom_isCMon Obj }. + +#[wrapper] +HB.mixin Record hom_isIMon T of Magma_enriched_quiver T := + { hom_isIMon_private : forall A B, isIMon (@hom T A B) }. +*) +#[verbose] +HB.structure + Definition IMon_enriched_quiver := + { Obj of Mon_enriched_quiver Obj & IAlg_enriched_quiver Obj }. + +(* workaround *) +Definition Ifoo (T : IMon_enriched_quiver.type) (A B : T) : IMon.type. +Proof. +refine (HB.pack (hom A B)). +Defined. +Canonical Ifoo. + +(****) + +#[verbose] +HB.structure + Definition CMon_enriched_quiver := + { Obj of Mon_enriched_quiver Obj & CAlg_enriched_quiver Obj }. + +(* workaround *) +Definition Cfoo (T : CMon_enriched_quiver.type) (A B : T) : CMon.type. +Proof. +refine (HB.pack (hom A B)). +Defined. +Canonical Cfoo. + + +(* { Obj of isQuiver Obj & hom_isMon Obj & hom_isIAlg Obj }. *) + +(* +#[wrapper] +HB.mixin Record hom_isICMon T of Magma_enriched_quiver T := + { hom_isICMon_private : forall A B, isICMon (@hom T A B) }. +#[verbose] +HB.structure + Definition ICMon_enriched_quiver := + { Obj of isQuiver Obj & hom_isICMon Obj }. +*) + +(*** factory ********************************************************) + +HB.factory Record isMICAlg T of Mon T := { + amop : T -> T -> T; + ameq : forall x y, amop x y = mop x y; + amcomm : commutative amop; + amidem : idempotent amop; + }. + +HB.builders Context T (_ : isMICAlg T). + + Lemma amop_mop_eq : amop = mop. + (* destruct f; simpl. *) + eapply functional_extensionality; intro. + eapply functional_extensionality; intro. + apply ameq. + Qed. + + Definition dum_comm := + @eq_rect (T -> T -> T) amop (@commutative T T) amcomm mop amop_mop_eq. + + Definition dum_idem := + @eq_rect (T -> T -> T) amop (@idempotent T) amidem mop amop_mop_eq. + + HB.instance Definition b_C : isCAlg T := + isCAlg.Build T dum_comm. + + HB.instance Definition b_I : isIAlg T := + isIAlg.Build T dum_idem. + + (* + HB.instance Definition b_IC : isICAlg T := + isICAlg.Build T b_C b_I. + *) +(* + Lemma M : isMon T. + auto. + Qed. +*) + (* + HB.instance Definition b_M : isICMon T := + isICMon.Build T b_IC M. + *) + +HB.end. + +(*******************************************************************) + +(** INSTANCE 1 *********************************************** + +Object: Type, +Morphism: A -> option B +Structure: Monoid (from isMon) +*) + +HB.instance Definition funQ := isQuiver.Build Type + (fun A B => A -> option B). + +Check Type : Quiver.type. + +Definition funQ_comp {A B: Type} (f g: hom A B) : hom A B := + fun x => + match f x with + | Some _ => f x + | _ => g x end. + +Definition funQ_zero {A B: Type} : hom A B := + fun (_:A) => None. + +(* does not work without declaring the Magma wrapper *) +HB.instance Definition funQ_isMagma (A B: Type) : + isMagma (hom A B) := isMagma.Build _ funQ_comp. + +Program Definition funQ_isMon (A B: Type) : isMon (hom A B) := + isMon.Build _ funQ_zero _ _ _. +Obligation 1. + unfold associative; intros. + eapply functional_extensionality; intro a. + unfold mop; simpl. + unfold funQ_comp. + destruct (x a) eqn:K1. + simpl; auto. + destruct (y a); auto. +Qed. +Obligation 2. + unfold left_id; intros. + unfold funQ_comp; auto. +Qed. +Obligation 3. + unfold right_id, mop; simpl; intros. + unfold funQ_zero, funQ_comp; simpl. + eapply functional_extensionality; intro a. + destruct (x a); auto. +Qed. + +Program Definition funQ_isIAlg (A B: Type) : + isIAlg (hom A B) := isIAlg.Build _ _. +Obligation 1. +unfold idempotent; intros. +eapply functional_extensionality; intro a. +unfold mop; simpl. +unfold funQ_comp; simpl. +destruct (x a); auto. +Qed. + +(* +Program Definition funQ_isIMon (A B: Type) : + isIMon (hom A B) := isIMon.Build (hom A B) _ _. +Obligation 1. +eapply funQ_isIAlg. +Qed. +Obligation 2. +eapply funQ_isMon. +Qed. +*) + +#[verbose] +HB.instance Definition funQ_IAlgebra (A B: Type) : + isIAlg (hom A B) := funQ_isIAlg A B. + +#[verbose] +HB.instance Definition funQ_Monoid (A B: Type) : + isMon (hom A B) := funQ_isMon A B. + +Check hom (nat:Type) nat : IMon.type. + +(***) + +HB.graph "foo.dot". + +Definition hom' (A B: Type) := hom A B. + +HB.instance Definition _ (A B: Type) := Mon.on (hom' A B). +HB.instance Definition _ (A B: Type) := IAlg.on (hom' A B). + +Check hom' (nat:Type) nat : IMon.type. + +HB.instance Definition _ (A B: Type) := Mon.on (hom' A B). + + +(** INSTANCE 2 ********************************************** + +Object: CMon.type +Morphism: CMon.sort A -> CMon.sort B +Structure: commutative monoid (by CMon) +*) + +#[verbose] +HB.instance Definition cmfunQ := + isQuiver.Build CMon.type + (fun A B => (CMon.sort A) -> (CMon.sort B)). + +Definition cmfunQ_comp {A B: CMon.type} (f g: hom A B) : hom A B := + fun x => @mop B (f x) (g x). + +Definition cmfunQ_zero {A B: CMon.type} : hom A B. + destruct B. + unfold hom; simpl; intro. + destruct class. + destruct enriched_cat_case5_isMon_mixin. + exact munit0. +Defined. + +(* does not work without declaring the Magma wrapper *) +HB.instance Definition cmfunQ_isMagma (A B: CMon.type) : + isMagma (hom A B) := isMagma.Build _ cmfunQ_comp. + +(* does not type-check without the Magma instance *) +Program Definition cmfunQ_isMon (A B: CMon.type) : + isMon (hom A B) := isMon.Build (hom A B) cmfunQ_zero _ _ _. +Obligation 1. +unfold associative, mop; simpl; intros. +unfold cmfunQ_comp; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case5_isMon_mixin. +simpl in *. +eapply massoc0; auto. +Qed. +Obligation 2. +unfold left_id, mop; simpl; intros. +unfold cmfunQ_comp, cmfunQ_zero; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case5_isMon_mixin. +auto. +Qed. +Obligation 3. +unfold right_id, mop; simpl; intros. +unfold cmfunQ_comp, cmfunQ_zero; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case5_isMon_mixin. +auto. +Qed. + +Program Definition cmfunQ_isCAlg (A B: CMon.type) : + isCAlg (hom A B) := isCAlg.Build (hom A B) _. +Obligation 1. +unfold commutative, mop; simpl; intros. +unfold cmfunQ_comp; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case5_isCAlg_mixin. +simpl in *. +eapply acomm0; auto. +Qed. + +HB.instance Definition cmfunQ_isMonoid (A B: CMon.type) : + isMon (hom A B) := cmfunQ_isMon A B. + +HB.instance Definition cmfunQ_isICAlgebra (A B: CMon.type) : + isCAlg (hom A B) := cmfunQ_isCAlg A B. + +(* +HB.instance Definition icmfunQ_isCMonoid (A B: CMon.type) : + isCMon (hom A B) := cmfunQ_isCMon A B. + +Check CMon.type : CAlg_enriched_quiver.type. +*) + +(*********************************************************) + +(* +Object: IMon.type +Morphism: IMon.sort A -> IMon.sort B +Structure: idempotent monoid (by IMon) +*) + +#[verbose] +HB.instance Definition imfunQ := + isQuiver.Build IMon.type + (fun A B => (IMon.sort A) -> (IMon.sort B)). + +Definition imfunQ_comp {A B: IMon.type} (f g: hom A B) : hom A B := + fun x => @mop B (f x) (g x). + +Definition imfunQ_zero {A B: IMon.type} : hom A B. + destruct B. + unfold hom; simpl; intro. + destruct class. + destruct enriched_cat_case1_isIMon_mixin. + destruct imon0. + exact munit0. +Defined. + +(* does not work without declaring the Magma wrapper *) +HB.instance Definition imfunQ_isMagma (A B: IMon.type) : + isMagma (hom A B) := isMagma.Build _ imfunQ_comp. + +(* does not type-check without the Magma instance *) +Program Definition imfunQ_isMon (A B: IMon.type) : + isMon (hom A B) := isMon.Build (hom A B) imfunQ_zero _ _ _. +Obligation 1. +unfold associative, mop; simpl; intros. +unfold imfunQ_comp; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isIMon_mixin. +simpl in *. +destruct imon0. +eapply massoc0; auto. +Qed. +Obligation 2. +unfold left_id, mop; simpl; intros. +unfold imfunQ_comp, imfunQ_zero; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isIMon_mixin. +destruct imon0. +auto. +Qed. +Obligation 3. +unfold right_id, mop; simpl; intros. +unfold imfunQ_comp, imfunQ_zero; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isIMon_mixin. +destruct imon0. +auto. +Qed. + +Program Definition imfunQ_isIAlg (A B: IMon.type) : + isIAlg (hom A B) := isIAlg.Build (hom A B) _. +Obligation 1. +unfold idempotent, mop; simpl; intros. +unfold imfunQ_comp; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isIMon_mixin. +simpl in *. +destruct iia0; auto. +Qed. + +Program Definition imfunQ_isIMon (A B: IMon.type) : + isIMon (hom A B) := isIMon.Build (hom A B) _ _. +Obligation 1. +eapply imfunQ_isIAlg. +Qed. +Obligation 2. +eapply imfunQ_isMon. +Qed. + +HB.instance Definition imfunQ_isMonoid (A B: IMon.type) : + isMon (hom A B) := imfunQ_isMon A B. + +HB.instance Definition imfunQ_isIAlgebra (A B: IMon.type) : + isIAlg (hom A B) := imfunQ_isIAlg A B. + +HB.instance Definition imfunQ_isIMonoid (A B: IMon.type) : + isIMon (hom A B) := imfunQ_isIMon A B. + +Check IMon.type : IAlg_enriched_quiver.type. + +(*********************************************************) +(* +Object: ICMon.type +Morphism: ICMon.sort A -> ICMon.sort B +Structure: idempotent commutative monoid (by ICMon) +*) + +#[verbose] +HB.instance Definition icmfunQ := + isQuiver.Build ICMon.type + (fun A B => (ICMon.sort A) -> (ICMon.sort B)). + +Definition icmfunQ_comp {A B: ICMon.type} (f g: hom A B) : hom A B := + fun x => @mop B (f x) (g x). + +Definition icmfunQ_zero {A B: ICMon.type} : hom A B. + destruct B. + unfold hom; simpl; intro. + destruct class. + destruct enriched_cat_case1_isICMon_mixin. + destruct mon0. + exact munit0. +Defined. + +(* does not work without declaring the Magma wrapper *) +HB.instance Definition icmfunQ_isMagma (A B: ICMon.type) : + isMagma (hom A B) := isMagma.Build _ icmfunQ_comp. + +(* does not type-check without the Magma instance *) +Program Definition icmfunQ_isMon (A B: ICMon.type) : + isMon (hom A B) := isMon.Build (hom A B) icmfunQ_zero _ _ _. +Obligation 1. +unfold associative, mop; simpl; intros. +unfold icmfunQ_comp; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isICMon_mixin. +simpl in *. +destruct mon0. +eapply massoc0; auto. +Qed. +Obligation 2. +unfold left_id, mop; simpl; intros. +unfold icmfunQ_comp, icmfunQ_zero; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isICMon_mixin. +destruct mon0. +auto. +Qed. +Obligation 3. +unfold right_id, mop; simpl; intros. +unfold icmfunQ_comp, icmfunQ_zero; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isICMon_mixin. +destruct mon0. +auto. +Qed. + + +Program Definition icmfunQ_isICAlg (A B: ICMon.type) : + isICAlg (hom A B) := isICAlg.Build (hom A B) _ _. +Obligation 1. +econstructor. +unfold commutative, mop; simpl; intros. +unfold icmfunQ_comp; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isICMon_mixin. +simpl in *. +destruct ica0. +destruct isca0. +eapply acomm0; auto. +Qed. +Obligation 2. +econstructor. +unfold idempotent, mop; simpl; intros. +unfold icmfunQ_comp; simpl; intros. +eapply functional_extensionality; intro x0. +destruct B. +destruct class. +destruct enriched_cat_case1_isICMon_mixin. +simpl in *. +destruct ica0. +destruct isia0. +eapply aidem0; auto. +Qed. + +Program Definition icmfunQ_isICMon (A B: ICMon.type) : + isICMon (hom A B) := isICMon.Build (hom A B) _ _. +Obligation 1. +eapply icmfunQ_isICAlg. +Qed. +Obligation 2. +eapply icmfunQ_isMon. +Qed. + +HB.instance Definition icmfunQ_isMonoid (A B: ICMon.type) : + isMon (hom A B) := icmfunQ_isMon A B. + +HB.instance Definition icmfunQ_isICAlgebra (A B: ICMon.type) : + isICAlg (hom A B) := icmfunQ_isICAlg A B. + +HB.instance Definition icmfunQ_isICMonoid (A B: ICMon.type) : + isICMon (hom A B) := icmfunQ_isICMon A B. + +Check ICMon.type : ICAlg_enriched_quiver.type. From 353b3fdbf19212e58f0c8b91dc07426ecc3ca53c Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Wed, 4 Oct 2023 20:17:47 +0200 Subject: [PATCH 035/147] wip --- HB/factory.elpi | 2 ++ tests/monoid_enriched_cat.v | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/HB/factory.elpi b/HB/factory.elpi index d63c54a3c..08835b367 100644 --- a/HB/factory.elpi +++ b/HB/factory.elpi @@ -276,6 +276,8 @@ declare-mixin-or-factory MixinSrcClauses SectionCanonicalInstance RDeclSkel = record "axioms_" Sort1 Kname Fields, std.assert-ok! (coq.elaborate-indt-decl-skeleton RDeclSkel RDecl) "record declaration illtyped", + % scheck-no-mixin-or-factory-occurs RDecl, + abstract-over-section TheParams TheType MixinSrcClauses SectionCanonicalInstance coq.abstract-indt-decl RDecl RDeclClosed _, diff --git a/tests/monoid_enriched_cat.v b/tests/monoid_enriched_cat.v index a0a795288..06cd75114 100644 --- a/tests/monoid_enriched_cat.v +++ b/tests/monoid_enriched_cat.v @@ -51,11 +51,10 @@ Fail HB.structure HB.mixin Record hom_isMon T of Quiver T := { hom_isMon_private : forall A B, isMon (@hom T A B) }. - Succeed HB.structure Definition Monoid_enriched_quiver := - { Obj of isQuiver Obj & - (forall A B : Obj, isMon (hom A B)) }. + { Obj of isQuiver Obj & + (forall A B : Obj, isMon (@hom _ A B)) }. Succeed HB.structure Definition Monoid_enriched_quiver := @@ -63,10 +62,11 @@ Succeed HB.structure (forall A B : Obj, isMon (hom A B)) }. (* which one is best? *) -Succeed HB.structure +Fail HB.structure Definition Monoid_enriched_quiver := { Obj of isQuiver Obj & (forall A B : Obj, isMon (@hom (Quiver.clone Obj _) A B)) }. + HB.structure Definition Monoid_enriched_quiver := { Obj of isQuiver Obj & From d3433168b39e541cc75064f5c7c8fcefd6eeb85c Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Thu, 5 Oct 2023 21:46:32 +0200 Subject: [PATCH 036/147] fix rebase --- _CoqProject.test-suite | 2 +- tests/hnf.v | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/hnf.v diff --git a/_CoqProject.test-suite b/_CoqProject.test-suite index 12326e2fe..138337f6a 100644 --- a/_CoqProject.test-suite +++ b/_CoqProject.test-suite @@ -53,7 +53,7 @@ examples/Coq2020_material/CoqWS_abstract.v examples/Coq2020_material/CoqWS_expansion/withHB.v examples/Coq2020_material/CoqWS_expansion/withoutHB.v -# examples/cat/cat.v +examples/cat/cat.v tests/type_of_exported_ops.v tests/duplicate_structure.v diff --git a/tests/hnf.v b/tests/hnf.v new file mode 100644 index 000000000..b219a6a82 --- /dev/null +++ b/tests/hnf.v @@ -0,0 +1,18 @@ +From HB Require Import structures. + +HB.mixin Record M A := { x: nat }. +HB.structure Definition S := { X of M X}. + +HB.factory Record f A := { y : nat }. +HB.builders Context T of f T. +HB.instance Definition _ := M.Build T (y + 1). +HB.end. + +#[hnf] HB.instance Definition _ := f.Build nat (3 + 2). +Print Datatypes_nat__canonical__hnf_S. +Print HB_unnamed_mixin_8. + +HB.instance Definition _ := f.Build bool (3 + 2). +Print Datatypes_bool__canonical__hnf_S. +Print HB_unnamed_mixin_12. + From 063ffc3811b2124ed87a0dca1dc3ac393ede0c5f Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Thu, 5 Oct 2023 21:47:04 +0200 Subject: [PATCH 037/147] fix failsafe structure inference --- HB/common/utils.elpi | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/HB/common/utils.elpi b/HB/common/utils.elpi index a5b4d64ba..f71a6c187 100644 --- a/HB/common/utils.elpi +++ b/HB/common/utils.elpi @@ -317,16 +317,18 @@ re-enable-id-phant T T1 :- pred failsafe-structure-inference i:term, o:term. failsafe-structure-inference T T1 :- - (pi OP Args Args1\ + (pi OP Args Args1 M Class NP S\ copy (app [global (const OP)|Args]) (app [global (const OP)| Args1]) :- - exported-op _ _ OP, !, eta-structure-record OP Args Args1) => + exported-op M _ OP, mixin-first-class M Class, factory-nparams Class NP, + std.nth NP Args S, + var S, + !, + eta-structure-record NP Class Args Args1) => copy T T1. -pred eta-structure-record i:constant, i:list term, o:list term. -eta-structure-record OP L L1 :- - exported-op M _ OP, mixin-first-class M Class, factory-nparams Class NP, - std.split-at NP L Params [S|Rest], - var S, +pred eta-structure-record i:int, i:classname, i:list term, o:list term. +eta-structure-record NP Class L L1 :- + std.split-at NP L Params [_|Rest], class-def (class Class Structure _), get-constructor Structure K, std.map Params copy Params1, From 1d189794aa9aed1d72e5745fc38ec608bf9b1406 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Thu, 5 Oct 2023 21:47:30 +0200 Subject: [PATCH 038/147] fix test for wrapping --- HB/instance.elpi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/HB/instance.elpi b/HB/instance.elpi index aa1158de9..f7d1195b6 100644 --- a/HB/instance.elpi +++ b/HB/instance.elpi @@ -88,7 +88,7 @@ declare-const Name BodySkel TyWPSkel CSL :- std.do! [ % derived instance %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% (private.declare-regular-inst TheType ML TheMixins TyWP SectionName CSL) % regular instance %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - (if (not(private.is-structure-op TheType)) + (if (not(private.is-structure-op-w-wrapper TheType)) % regular subject %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% (private.declare-regular-inst TheType ML TheMixins TyWP SectionName CSL) % wrapper %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -462,9 +462,9 @@ declare-wrapper-inst TheType ML TheMixins TyWP SectionName CSL :- std.do![ private.declare-structure-instance-from-mixins TheNewType WML TheWrappedMixins CSL, ]. -pred is-structure-op i:term. -is-structure-op (global (const C)) :- exported-op _ _ C. -is-structure-op (app[global (const C)|_]) :- exported-op _ _ C. +pred is-structure-op-w-wrapper i:term. +is-structure-op-w-wrapper (global (const C)) :- exported-op _ _ C, wrapper-mixin _ (const C) _. +is-structure-op-w-wrapper (app[global (const C)|_]) :- std.spy(exported-op _ _ C), wrapper-mixin _ (const C) _. pred derive-wrapper-instances i:term, i:mixinname, o:term, o:constant. derive-wrapper-instances Instance WrapperMixin WrapperSubject C :- std.do! [ From 8f2d47df9778ce7a527014ba8d93e169334ec44d Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Thu, 5 Oct 2023 21:47:45 +0200 Subject: [PATCH 039/147] cleanup --- HB/structure.elpi | 1 - 1 file changed, 1 deletion(-) diff --git a/HB/structure.elpi b/HB/structure.elpi index e80b771f6..d035d9428 100644 --- a/HB/structure.elpi +++ b/HB/structure.elpi @@ -10,7 +10,6 @@ pred declare i:string, i:term, i:universe. declare Module BSkel Sort :- std.do! [ disable-id-phant BSkel BSkelNoId, failsafe-structure-inference BSkelNoId BSkelNoIdX, - coq.say BSkelNoIdX, std.assert-ok! (coq.elaborate-skeleton BSkelNoIdX _ BNoId) "illtyped structure definition", re-enable-id-phant BNoId B, From 7e413469b677c6473bb9365a07e027837574975c Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Thu, 5 Oct 2023 21:54:50 +0200 Subject: [PATCH 040/147] cleanup --- HB/instance.elpi | 4 ++-- tests/monoid_enriched_cat.v | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/HB/instance.elpi b/HB/instance.elpi index f7d1195b6..fcae033b1 100644 --- a/HB/instance.elpi +++ b/HB/instance.elpi @@ -464,7 +464,7 @@ declare-wrapper-inst TheType ML TheMixins TyWP SectionName CSL :- std.do![ pred is-structure-op-w-wrapper i:term. is-structure-op-w-wrapper (global (const C)) :- exported-op _ _ C, wrapper-mixin _ (const C) _. -is-structure-op-w-wrapper (app[global (const C)|_]) :- std.spy(exported-op _ _ C), wrapper-mixin _ (const C) _. +is-structure-op-w-wrapper (app[global (const C)|_]) :- exported-op _ _ C, wrapper-mixin _ (const C) _. pred derive-wrapper-instances i:term, i:mixinname, o:term, o:constant. derive-wrapper-instances Instance WrapperMixin WrapperSubject C :- std.do! [ @@ -502,7 +502,7 @@ derive-wrapper-instances Instance WrapperMixin WrapperSubject C :- std.do! [ Name is "wrapped__" ^ {std.any->string {new_int}}, - std.spy(log.coq.env.add-const-noimplicits Name NewInstance Ty @transparent! C), + log.coq.env.add-const-noimplicits Name NewInstance Ty @transparent! C, ]. pred wrap-a-mixin i:gref, i:mixinname, i:constant, o:term, o:mixinname, o:constant. diff --git a/tests/monoid_enriched_cat.v b/tests/monoid_enriched_cat.v index 06cd75114..95b935089 100644 --- a/tests/monoid_enriched_cat.v +++ b/tests/monoid_enriched_cat.v @@ -62,7 +62,7 @@ Succeed HB.structure (forall A B : Obj, isMon (hom A B)) }. (* which one is best? *) -Fail HB.structure +Succeed HB.structure Definition Monoid_enriched_quiver := { Obj of isQuiver Obj & (forall A B : Obj, isMon (@hom (Quiver.clone Obj _) A B)) }. From fb93fbe9876eacb209408bd344b9cb8902d0755e Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Fri, 6 Oct 2023 11:00:54 +0200 Subject: [PATCH 041/147] option wrapper=off to instance --- HB/instance.elpi | 2 +- tests/enriched_cat_case6.v | 18 ++++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/HB/instance.elpi b/HB/instance.elpi index fcae033b1..d17784042 100644 --- a/HB/instance.elpi +++ b/HB/instance.elpi @@ -88,7 +88,7 @@ declare-const Name BodySkel TyWPSkel CSL :- std.do! [ % derived instance %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% (private.declare-regular-inst TheType ML TheMixins TyWP SectionName CSL) % regular instance %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - (if (not(private.is-structure-op-w-wrapper TheType)) + (if (get-option "wrapper" ff ; not(private.is-structure-op-w-wrapper TheType)) % regular subject %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% (private.declare-regular-inst TheType ML TheMixins TyWP SectionName CSL) % wrapper %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/tests/enriched_cat_case6.v b/tests/enriched_cat_case6.v index e9df748d1..592309fc2 100644 --- a/tests/enriched_cat_case6.v +++ b/tests/enriched_cat_case6.v @@ -130,12 +130,9 @@ HB.structure Definition IMon_enriched_quiver := { Obj of Mon_enriched_quiver Obj & IAlg_enriched_quiver Obj }. -(* workaround *) -Definition Ifoo (T : IMon_enriched_quiver.type) (A B : T) : IMon.type. -Proof. -refine (HB.pack (hom A B)). -Defined. -Canonical Ifoo. +#[wrapper=false] +HB.instance Definition _ (T : IMon_enriched_quiver.type) A B : isMon (@hom T A B) := + Mon.on (@hom T A B). (****) @@ -144,13 +141,10 @@ HB.structure Definition CMon_enriched_quiver := { Obj of Mon_enriched_quiver Obj & CAlg_enriched_quiver Obj }. -(* workaround *) -Definition Cfoo (T : CMon_enriched_quiver.type) (A B : T) : CMon.type. -Proof. -refine (HB.pack (hom A B)). -Defined. -Canonical Cfoo. +#[wrapper=false] +HB.instance Definition _ (T : CMon_enriched_quiver.type) A B := + Mon.on (@hom T A B). (* { Obj of isQuiver Obj & hom_isMon Obj & hom_isIAlg Obj }. *) From 4c2742c0a2fba25c805c4190cd301e32c455d58b Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Wed, 4 Oct 2023 22:38:54 +0200 Subject: [PATCH 042/147] demo should not break abstractions --- tests/enriched_cat_case6.v | 104 +++++-------------------------------- 1 file changed, 14 insertions(+), 90 deletions(-) diff --git a/tests/enriched_cat_case6.v b/tests/enriched_cat_case6.v index 592309fc2..89dc78b26 100644 --- a/tests/enriched_cat_case6.v +++ b/tests/enriched_cat_case6.v @@ -313,13 +313,7 @@ HB.instance Definition cmfunQ := Definition cmfunQ_comp {A B: CMon.type} (f g: hom A B) : hom A B := fun x => @mop B (f x) (g x). -Definition cmfunQ_zero {A B: CMon.type} : hom A B. - destruct B. - unfold hom; simpl; intro. - destruct class. - destruct enriched_cat_case5_isMon_mixin. - exact munit0. -Defined. +Definition cmfunQ_zero {A B: CMon.type} : hom A B := fun a : A => munit. (* does not work without declaring the Magma wrapper *) HB.instance Definition cmfunQ_isMagma (A B: CMon.type) : @@ -332,29 +326,19 @@ Obligation 1. unfold associative, mop; simpl; intros. unfold cmfunQ_comp; simpl; intros. eapply functional_extensionality; intro x0. -destruct B. -destruct class. -destruct enriched_cat_case5_isMon_mixin. -simpl in *. -eapply massoc0; auto. +refine (massoc _ _ _). Qed. Obligation 2. unfold left_id, mop; simpl; intros. unfold cmfunQ_comp, cmfunQ_zero; simpl; intros. eapply functional_extensionality; intro x0. -destruct B. -destruct class. -destruct enriched_cat_case5_isMon_mixin. -auto. +refine (mlid _). Qed. Obligation 3. unfold right_id, mop; simpl; intros. unfold cmfunQ_comp, cmfunQ_zero; simpl; intros. eapply functional_extensionality; intro x0. -destruct B. -destruct class. -destruct enriched_cat_case5_isMon_mixin. -auto. +refine (mrid _). Qed. Program Definition cmfunQ_isCAlg (A B: CMon.type) : @@ -363,11 +347,7 @@ Obligation 1. unfold commutative, mop; simpl; intros. unfold cmfunQ_comp; simpl; intros. eapply functional_extensionality; intro x0. -destruct B. -destruct class. -destruct enriched_cat_case5_isCAlg_mixin. -simpl in *. -eapply acomm0; auto. +refine (acomm _ _). Qed. HB.instance Definition cmfunQ_isMonoid (A B: CMon.type) : @@ -399,14 +379,7 @@ HB.instance Definition imfunQ := Definition imfunQ_comp {A B: IMon.type} (f g: hom A B) : hom A B := fun x => @mop B (f x) (g x). -Definition imfunQ_zero {A B: IMon.type} : hom A B. - destruct B. - unfold hom; simpl; intro. - destruct class. - destruct enriched_cat_case1_isIMon_mixin. - destruct imon0. - exact munit0. -Defined. +Definition imfunQ_zero {A B: IMon.type} : hom A B := fun a : A => munit. (* does not work without declaring the Magma wrapper *) HB.instance Definition imfunQ_isMagma (A B: IMon.type) : @@ -419,32 +392,19 @@ Obligation 1. unfold associative, mop; simpl; intros. unfold imfunQ_comp; simpl; intros. eapply functional_extensionality; intro x0. -destruct B. -destruct class. -destruct enriched_cat_case1_isIMon_mixin. -simpl in *. -destruct imon0. -eapply massoc0; auto. +refine (massoc _ _ _). Qed. Obligation 2. unfold left_id, mop; simpl; intros. unfold imfunQ_comp, imfunQ_zero; simpl; intros. eapply functional_extensionality; intro x0. -destruct B. -destruct class. -destruct enriched_cat_case1_isIMon_mixin. -destruct imon0. -auto. +refine (mlid _). Qed. Obligation 3. unfold right_id, mop; simpl; intros. unfold imfunQ_comp, imfunQ_zero; simpl; intros. eapply functional_extensionality; intro x0. -destruct B. -destruct class. -destruct enriched_cat_case1_isIMon_mixin. -destruct imon0. -auto. +refine (mrid _). Qed. Program Definition imfunQ_isIAlg (A B: IMon.type) : @@ -453,20 +413,7 @@ Obligation 1. unfold idempotent, mop; simpl; intros. unfold imfunQ_comp; simpl; intros. eapply functional_extensionality; intro x0. -destruct B. -destruct class. -destruct enriched_cat_case1_isIMon_mixin. -simpl in *. -destruct iia0; auto. -Qed. - -Program Definition imfunQ_isIMon (A B: IMon.type) : - isIMon (hom A B) := isIMon.Build (hom A B) _ _. -Obligation 1. -eapply imfunQ_isIAlg. -Qed. -Obligation 2. -eapply imfunQ_isMon. +refine (aidem _). Qed. HB.instance Definition imfunQ_isMonoid (A B: IMon.type) : @@ -475,9 +422,6 @@ HB.instance Definition imfunQ_isMonoid (A B: IMon.type) : HB.instance Definition imfunQ_isIAlgebra (A B: IMon.type) : isIAlg (hom A B) := imfunQ_isIAlg A B. -HB.instance Definition imfunQ_isIMonoid (A B: IMon.type) : - isIMon (hom A B) := imfunQ_isIMon A B. - Check IMon.type : IAlg_enriched_quiver.type. (*********************************************************) @@ -495,14 +439,7 @@ HB.instance Definition icmfunQ := Definition icmfunQ_comp {A B: ICMon.type} (f g: hom A B) : hom A B := fun x => @mop B (f x) (g x). -Definition icmfunQ_zero {A B: ICMon.type} : hom A B. - destruct B. - unfold hom; simpl; intro. - destruct class. - destruct enriched_cat_case1_isICMon_mixin. - destruct mon0. - exact munit0. -Defined. +Definition icmfunQ_zero {A B: ICMon.type} : hom A B := fun a : A => munit. (* does not work without declaring the Magma wrapper *) HB.instance Definition icmfunQ_isMagma (A B: ICMon.type) : @@ -515,32 +452,19 @@ Obligation 1. unfold associative, mop; simpl; intros. unfold icmfunQ_comp; simpl; intros. eapply functional_extensionality; intro x0. -destruct B. -destruct class. -destruct enriched_cat_case1_isICMon_mixin. -simpl in *. -destruct mon0. -eapply massoc0; auto. +refine (massoc _ _ _). Qed. Obligation 2. unfold left_id, mop; simpl; intros. unfold icmfunQ_comp, icmfunQ_zero; simpl; intros. eapply functional_extensionality; intro x0. -destruct B. -destruct class. -destruct enriched_cat_case1_isICMon_mixin. -destruct mon0. -auto. +refine (mlid _). Qed. Obligation 3. unfold right_id, mop; simpl; intros. unfold icmfunQ_comp, icmfunQ_zero; simpl; intros. eapply functional_extensionality; intro x0. -destruct B. -destruct class. -destruct enriched_cat_case1_isICMon_mixin. -destruct mon0. -auto. +refine (mrid _). Qed. From bd83789a333f6bdead2fa9e641eff9e9dc556b1b Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Fri, 6 Oct 2023 13:15:01 +0200 Subject: [PATCH 043/147] test --- _CoqProject.test-suite | 1 + tests/enriched_cat_case6.v | 1 + 2 files changed, 2 insertions(+) diff --git a/_CoqProject.test-suite b/_CoqProject.test-suite index 138337f6a..39f69e06c 100644 --- a/_CoqProject.test-suite +++ b/_CoqProject.test-suite @@ -54,6 +54,7 @@ examples/Coq2020_material/CoqWS_expansion/withHB.v examples/Coq2020_material/CoqWS_expansion/withoutHB.v examples/cat/cat.v +tests/enriched_cat_case6.v tests/type_of_exported_ops.v tests/duplicate_structure.v diff --git a/tests/enriched_cat_case6.v b/tests/enriched_cat_case6.v index 89dc78b26..dd9c0e951 100644 --- a/tests/enriched_cat_case6.v +++ b/tests/enriched_cat_case6.v @@ -467,6 +467,7 @@ eapply functional_extensionality; intro x0. refine (mrid _). Qed. +stop Program Definition icmfunQ_isICAlg (A B: ICMon.type) : isICAlg (hom A B) := isICAlg.Build (hom A B) _ _. From d1c8070d8740d3fe19dea69ca4d47bf8e0b124ef Mon Sep 17 00:00:00 2001 From: Cyril Cohen Date: Fri, 6 Oct 2023 10:39:20 +0200 Subject: [PATCH 044/147] moving category theory to theories --- theories/algebra.v | 120 +++++++++++++++++++++++++++++++ {examples/cat => theories}/cat.v | 109 ---------------------------- 2 files changed, 120 insertions(+), 109 deletions(-) create mode 100644 theories/algebra.v rename {examples/cat => theories}/cat.v (89%) diff --git a/theories/algebra.v b/theories/algebra.v new file mode 100644 index 000000000..d37bdd952 --- /dev/null +++ b/theories/algebra.v @@ -0,0 +1,120 @@ +Require Import ssreflect ssrfun. +From HB Require Import structures cat. + +Set Implicit Arguments. +Unset Strict Implicit. +Unset Printing Implicit Defensive. +Add Search Blacklist "__canonical__". + +Local Open Scope algebra_scope. +Local Open Scope cat_scope. + +HB.mixin Record IsRing A := { + zero : A; + one : A; + add : A -> A -> A; + opp : A -> A; + mul : A -> A -> A; + addrA : associative add; + addrC : commutative add; + add0r : left_id zero add; + addNr : left_inverse zero opp add; + mulrA : associative mul; + mul1r : left_id one mul; + mulr1 : right_id one mul; + mulrDl : left_distributive mul add; + mulrDr : right_distributive mul add; +}. + +#[short(type="ring")] +HB.structure Definition Ring := { A of IsRing A }. + +Bind Scope algebra_scope with Ring.sort. +Notation "0" := zero : algebra_scope. +Notation "1" := one : algebra_scope. +Infix "+" := (@add _) : algebra_scope. +Notation "- x" := (@opp _ x) : algebra_scope. +Infix "*" := (@mul _) : algebra_scope. +Notation "x - y" := (x + - y) : algebra_scope. + +Lemma addr0 (R : ring) : right_id (@zero R) add. +Proof. by move=> x; rewrite addrC add0r. Qed. + +Lemma addrN (R : ring) : right_inverse (@zero R) opp add. +Proof. by move=> x; rewrite addrC addNr. Qed. + +Lemma addKr (R : ring) (x : R) : cancel (add x) (add (- x)). +Proof. by move=> y; rewrite addrA addNr add0r. Qed. + +Lemma addrI (R : ring) (x : R) : injective (add x). +Proof. exact: can_inj (addKr _). Qed. + +Lemma opprK (R : ring) : involutive (@opp R). +Proof. by move=> x; apply: (@addrI _ (- x)); rewrite addNr addrN. Qed. + +HB.mixin Record IsRingHom (A B : ring) (f : A -> B) := { + hom1_subproof : f 1%A = 1%A; + homB_subproof : {morph f : x y / x - y}; + homM_subproof : {morph f : x y / (x * y)%A}; +}. + +HB.structure Definition RingHom A B := { f of IsRingHom A B f }. + +Lemma id_IsRingHom A : IsRingHom A A idfun. Proof. by []. Defined. +HB.instance Definition _ A := id_IsRingHom A. + +Lemma comp_IsRingHom (A B C : ring) + (f : RingHom.type A B) (g : RingHom.type B C) : + IsRingHom A C (f \; g :> U). +Proof. +by constructor => [|x y|x y]; +rewrite /comp/= ?hom1_subproof ?homB_subproof ?homM_subproof. +Qed. +HB.instance Definition _ A B C f g := @comp_IsRingHom A B C f g. + +HB.instance Definition _ := IsQuiver.Build ring RingHom.type. +HB.instance Definition _ := + Quiver_IsPreCat.Build ring (fun _ => idfun) (fun _ _ _ f g => f \; g :> U). +HB.instance Definition _ := Quiver_IsPreConcrete.Build ring (fun _ _ => id). +Lemma ring_precat : PreConcrete_IsConcrete ring. +Proof. +constructor => A B [f cf] [g cg]//=; rewrite -[_ = _]/(f = g) => fg. +case: _ / fg in cg *; congr {|RingHom.sort := _ ; RingHom.class := _|}. +case: cf cg => [[? ? ?]] [[? ? ?]]. +by congr RingHom.Class; congr IsRingHom.phant_Build => //=; apply: Prop_irrelevance. +Qed. +HB.instance Definition _ := ring_precat. + +Lemma ring_IsCat : PreCat_IsCat ring. +Proof. +by constructor=> [A B f|A B f|A B C D f g h]; exact: concrete_fun_inj. +Qed. +HB.instance Definition _ := ring_IsCat. + +Lemma hom1 (R S : ring) (f : R ~> S) : f 1%A = 1%A. +Proof. exact: hom1_subproof. Qed. +Lemma homB (R S : ring) (f : R ~> S) : {morph f : x y / x - y}. +Proof. exact: homB_subproof. Qed. +Lemma homM (R S : ring) (f : R ~> S) : {morph f : x y / (x * y)%A}. +Proof. exact: homM_subproof. Qed. +Lemma hom0 (R S : ring) (f : R ~> S) : f 0%A = 0%A. +Proof. by rewrite -(addrN 1%A) homB addrN. Qed. +Lemma homN (R S : ring) (f : R ~> S) : {morph f : x / - x}. +Proof. by move=> x; rewrite -[- x]add0r homB hom0 add0r. Qed. +Lemma homD (R S : ring) (f : R ~> S) : {morph f : x y / x + y}. +Proof. by move=> x y; rewrite -[y]opprK !homB !homN. Qed. + +HB.mixin Record IsIdeal (R : ring) (I : R -> Prop) := { + ideal0 : I 0; + idealD : forall x y, I x -> I y -> I (x + y); + idealM : forall x y, I y -> I (x * y)%A; +}. +HB.structure Definition Ideal (R : ring) := { I of IsIdeal R I }. + +HB.mixin Record Ideal_IsPrime (R : ring) (I : R -> Prop) of IsIdeal R I := { + ideal_prime : forall x y : R, I (x * y)%A -> I x \/ I y +}. +#[short(type="spectrum")] +HB.structure Definition PrimeIdeal (R : ring) := + { I of Ideal_IsPrime R I & Ideal R I }. + diff --git a/examples/cat/cat.v b/theories/cat.v similarity index 89% rename from examples/cat/cat.v rename to theories/cat.v index f340cd457..1932da9e4 100644 --- a/examples/cat/cat.v +++ b/theories/cat.v @@ -881,113 +881,4 @@ HB.structure Definition Monoidal : Set := { C of PreMonoidal_IsMonoidal C & PreMonoidal C }. Set Universe Checking. -HB.mixin Record IsRing A := { - zero : A; - one : A; - add : A -> A -> A; - opp : A -> A; - mul : A -> A -> A; - addrA : associative add; - addrC : commutative add; - add0r : left_id zero add; - addNr : left_inverse zero opp add; - mulrA : associative mul; - mul1r : left_id one mul; - mulr1 : right_id one mul; - mulrDl : left_distributive mul add; - mulrDr : right_distributive mul add; -}. - -#[short(type="ring")] -HB.structure Definition Ring := { A of IsRing A }. - -Bind Scope algebra_scope with Ring.sort. -Notation "0" := zero : algebra_scope. -Notation "1" := one : algebra_scope. -Infix "+" := (@add _) : algebra_scope. -Notation "- x" := (@opp _ x) : algebra_scope. -Infix "*" := (@mul _) : algebra_scope. -Notation "x - y" := (x + - y) : algebra_scope. - -Lemma addr0 (R : ring) : right_id (@zero R) add. -Proof. by move=> x; rewrite addrC add0r. Qed. - -Lemma addrN (R : ring) : right_inverse (@zero R) opp add. -Proof. by move=> x; rewrite addrC addNr. Qed. - -Lemma addKr (R : ring) (x : R) : cancel (add x) (add (- x)). -Proof. by move=> y; rewrite addrA addNr add0r. Qed. - -Lemma addrI (R : ring) (x : R) : injective (add x). -Proof. exact: can_inj (addKr _). Qed. - -Lemma opprK (R : ring) : involutive (@opp R). -Proof. by move=> x; apply: (@addrI _ (- x)); rewrite addNr addrN. Qed. - -HB.mixin Record IsRingHom (A B : ring) (f : A -> B) := { - hom1_subproof : f 1%A = 1%A; - homB_subproof : {morph f : x y / x - y}; - homM_subproof : {morph f : x y / (x * y)%A}; -}. - -HB.structure Definition RingHom A B := { f of IsRingHom A B f }. - -Lemma id_IsRingHom A : IsRingHom A A idfun. Proof. by []. Defined. -HB.instance Definition _ A := id_IsRingHom A. - -Lemma comp_IsRingHom (A B C : ring) - (f : RingHom.type A B) (g : RingHom.type B C) : - IsRingHom A C (f \; g :> U). -Proof. -by constructor => [|x y|x y]; -rewrite /comp/= ?hom1_subproof ?homB_subproof ?homM_subproof. -Qed. -HB.instance Definition _ A B C f g := @comp_IsRingHom A B C f g. - -HB.instance Definition _ := IsQuiver.Build ring RingHom.type. -HB.instance Definition _ := - Quiver_IsPreCat.Build ring (fun _ => idfun) (fun _ _ _ f g => f \; g :> U). -HB.instance Definition _ := Quiver_IsPreConcrete.Build ring (fun _ _ => id). -Lemma ring_precat : PreConcrete_IsConcrete ring. -Proof. -constructor => A B [f cf] [g cg]//=; rewrite -[_ = _]/(f = g) => fg. -case: _ / fg in cg *; congr {|RingHom.sort := _ ; RingHom.class := _|}. -case: cf cg => [[? ? ?]] [[? ? ?]]. -by congr RingHom.Class; congr IsRingHom.phant_Build => //=; apply: Prop_irrelevance. -Qed. -HB.instance Definition _ := ring_precat. - -Lemma ring_IsCat : PreCat_IsCat ring. -Proof. -by constructor=> [A B f|A B f|A B C D f g h]; exact: concrete_fun_inj. -Qed. -HB.instance Definition _ := ring_IsCat. - -Lemma hom1 (R S : ring) (f : R ~> S) : f 1%A = 1%A. -Proof. exact: hom1_subproof. Qed. -Lemma homB (R S : ring) (f : R ~> S) : {morph f : x y / x - y}. -Proof. exact: homB_subproof. Qed. -Lemma homM (R S : ring) (f : R ~> S) : {morph f : x y / (x * y)%A}. -Proof. exact: homM_subproof. Qed. -Lemma hom0 (R S : ring) (f : R ~> S) : f 0%A = 0%A. -Proof. by rewrite -(addrN 1%A) homB addrN. Qed. -Lemma homN (R S : ring) (f : R ~> S) : {morph f : x / - x}. -Proof. by move=> x; rewrite -[- x]add0r homB hom0 add0r. Qed. -Lemma homD (R S : ring) (f : R ~> S) : {morph f : x y / x + y}. -Proof. by move=> x y; rewrite -[y]opprK !homB !homN. Qed. - -HB.mixin Record IsIdeal (R : ring) (I : R -> Prop) := { - ideal0 : I 0; - idealD : forall x y, I x -> I y -> I (x + y); - idealM : forall x y, I y -> I (x * y)%A; -}. -HB.structure Definition Ideal (R : ring) := { I of IsIdeal R I }. - -HB.mixin Record Ideal_IsPrime (R : ring) (I : R -> Prop) of IsIdeal R I := { - ideal_prime : forall x y : R, I (x * y)%A -> I x \/ I y -}. -#[short(type="spectrum")] -HB.structure Definition PrimeIdeal (R : ring) := - { I of Ideal_IsPrime R I & Ideal R I }. - From b73828cb5835e8d5d75603df71cf647a0986e7f4 Mon Sep 17 00:00:00 2001 From: Cyril Cohen Date: Fri, 6 Oct 2023 14:09:25 +0200 Subject: [PATCH 045/147] defining pullbacks --- _CoqProject | 5 +- theories/algebra.v | 2 + theories/cat.v | 189 ++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 177 insertions(+), 19 deletions(-) diff --git a/_CoqProject b/_CoqProject index 057e90014..9ea90d11e 100644 --- a/_CoqProject +++ b/_CoqProject @@ -1,7 +1,10 @@ structures.v +theories/cat.v +theories/algebra.v -arg -w -arg -elpi.accumulate-syntax -arg -w -arg +elpi.typecheck -Q . HB -R tests HB.tests --R examples HB.examples \ No newline at end of file +-R examples HB.examples +-R theories HB diff --git a/theories/algebra.v b/theories/algebra.v index d37bdd952..9eada670d 100644 --- a/theories/algebra.v +++ b/theories/algebra.v @@ -1,5 +1,7 @@ Require Import ssreflect ssrfun. +Unset Universe Checking. From HB Require Import structures cat. +Set Universe Checking. Set Implicit Arguments. Unset Strict Implicit. diff --git a/theories/cat.v b/theories/cat.v index 1932da9e4..c8fb9f7a2 100644 --- a/theories/cat.v +++ b/theories/cat.v @@ -317,9 +317,10 @@ HB.instance Definition _ {C D : cat} (c : C) := (* opposite category *) Definition catop (C : U) : U := C. -Notation "C ^op" := (catop C) (at level 10, format "C ^op") : cat_scope. +Notation "C ^op" := (catop C) + (at level 2, format "C ^op") : cat_scope. HB.instance Definition _ (C : quiver) := - IsQuiver.Build (C^op) (fun a b => hom b a). + IsQuiver.Build C^op (fun a b => hom b a). HB.instance Definition _ (C : precat) := Quiver_IsPreCat.Build (C^op) (fun=> idmap) (fun _ _ _ f g => g \; f). HB.instance Definition _ (C : cat) := PreCat_IsCat.Build (C^op) @@ -737,23 +738,23 @@ Notation "F `/ b" := (F `/` cst unit b) (at level 40, b at level 40, format "F `/ b") : cat_scope. Notation "a / b" := (cst unit a `/ b) : cat_scope. -(* (* Not working yet *) *) -(* HB.mixin Record IsInitial {C : quiver} (i : C) := { *) -(* to : forall c, i ~> c; *) -(* to_unique : forall c (f : i ~> c), f = to c *) -(* }. *) -(* #[short(type="initial")] *) -(* HB.structure Definition Initial {C : quiver} := {i of IsInitial C i}. *) +Definition obj (C : quiver) : Type := C. +HB.mixin Record IsInitial {C : quiver} (i : obj C) := { + to : forall c, i ~> c; + to_unique : forall c (f : i ~> c), f = to c +}. +#[short(type="initial")] +HB.structure Definition Initial {C : quiver} := {i of IsInitial C i}. -(* HB.mixin Record IsTerminal {C : quiver} (t : C) := { *) -(* from : forall c, c ~> t; *) -(* from_unique : forall c (f : c ~> t), f = from c *) -(* }. *) -(* #[short(type="terminal")] *) -(* HB.structure Definition Terminal {C : quiver} := {t of IsTerminal C t}. *) -(* #[short(type="universal")] *) -(* HB.structure Definition Universal {C : quiver} := *) -(* {u of Initial C u & Terminal C u}. *) +HB.mixin Record IsTerminal {C : quiver} (t : obj C) := { + from : forall c, c ~> t; + from_unique : forall c (f : c ~> t), f = from c +}. +#[short(type="terminal")] +HB.structure Definition Terminal {C : quiver} := {t of IsTerminal C t}. +#[short(type="universal")] +HB.structure Definition Universal {C : quiver} := + {u of Initial C u & Terminal C u}. (* Definition hom' {C : precat} (a b : C) := a ~> b. *) (* (* Bug *) *) @@ -802,6 +803,7 @@ Arguments L_ {_ _}. Arguments phi {D C s} {c d}. Arguments psy {D C s} {c d}. + HB.mixin Record PreCat_IsMonoidal C of PreCat C := { onec : C; prod : (C * C)%type ~>_precat C; @@ -882,3 +884,154 @@ HB.structure Definition Monoidal : Set := Set Universe Checking. +Record cospan (Q : quiver) (A B : Q) := Cospan { + top : Q; + left2top : A ~> top; + right2top : B ~> top +}. + +Section cospans. +Variables (Q : precat) (A B : Q). +Record cospan_map (c c' : cospan A B) := CospanMap { + top_map : top c ~> top c'; + left2top_map : left2top c \; top_map = left2top c'; + right2top_map : right2top c \; top_map = right2top c'; +}. +HB.instance Definition _ := IsQuiver.Build (cospan A B) cospan_map. + +Lemma cospan_mapP (c c' : cospan A B) (f g : c ~> c') : + top_map f = top_map g <-> f = g. +Admitted. +End cospans. + +Section cospans_in_cat. +Variables (Q : cat) (A B : Q). +Definition cospan_idmap (c : cospan A B) := + @CospanMap Q A B c c idmap (compo1 _) (compo1 _). +Program Definition cospan_comp (c1 c2 c3 : cospan A B) + (f12 : c1 ~> c2) (f23 : c2 ~> c3) := + @CospanMap Q A B c1 c3 (top_map f12 \; top_map f23) _ _. +Next Obligation. by rewrite compoA !left2top_map. Qed. +Next Obligation. by rewrite compoA !right2top_map. Qed. +HB.instance Definition _ := IsPreCat.Build (cospan A B) cospan_idmap cospan_comp. + +Lemma cospan_are_cats : PreCat_IsCat (cospan A B). +Proof. +constructor=> [a b f|a b f|a b c d f g h]. +- by apply/cospan_mapP => /=; rewrite comp1o. +- by apply/cospan_mapP => /=; rewrite compo1. +- by apply/cospan_mapP => /=; rewrite compoA. +Qed. +HB.instance Definition _ := cospan_are_cats. +End cospans_in_cat. + +Section spans_and_co. +Variables (Q : quiver) (A B : Q). +Definition span := @cospan Q^op A B. +Definition bot (s : span) : Q := top s. +Definition bot2left (s : span) : bot s ~>_Q A := left2top s. +Definition bot2right (s : span) : bot s ~>_Q B := right2top s. +Definition Span (C : Q) (f : C ~> A) (g : C ~> B) : span := + @Cospan Q^op A B C f g. +End spans_and_co. + +HB.instance Definition _ (Q : precat) (A B : Q) := + Quiver.copy (span A B) (@cospan Q^op A B)^op. +HB.instance Definition _ (Q : cat) (A B : Q) := + Cat.copy (span A B) (@cospan Q^op A B)^op. + +Section bot_map. +Variables (C : cat) (A B : C) (s s' : span A B) (f : s ~> s'). +Definition bot_map : bot s ~> bot s' := top_map f. +Lemma bot2left_map : bot_map \; bot2left s' = bot2left s. +Proof. exact: left2top_map f. Qed. +Lemma bot2right_map : bot_map \; bot2right s' = bot2right s. +Proof. exact: right2top_map f. Qed. +End bot_map. + +HB.mixin Record isPrePullback (Q : precat) (A B : Q) + (c : cospan A B) (s : span A B) := { + is_square : bot2left s \; left2top c = bot2right s \; right2top c; +}. +#[short(type=prepullback)] +HB.structure Definition PrePullback Q A B (c : cospan A B) := + {s of isPrePullback Q A B c s}. +Arguments prepullback {Q A B} c. + +Section prepullback. +Variables (Q : precat) (A B : Q) (c : cospan A B). +HB.instance Definition _ := + IsQuiver.Build (prepullback c) + (fun a b => (a : span A B) ~>_(span A B) (b : span A B)). +Lemma eq_prepullbackP (p q : prepullback c) : + p = q :> span _ _ <-> p = q. +Admitted. +End prepullback. +Section prepullback. +Variables (Q : cat) (A B : Q) (csp : cospan A B). +(* TODO: why can't we do that? *) +(* HB.instance Definition _ := Cat.on (prepullback csp). *) +HB.instance Definition _ := + Quiver_IsPreCat.Build (prepullback csp) + (fun a => \idmap_(a : span A B)) + (* TODO: study how to make this coercion trigger + even when the target is not reduced to span *) + (fun a b c f g => f \; g). +Lemma prepullback_is_cat : PreCat_IsCat (prepullback csp). +Proof. (* should be copied from the cat on span *) +constructor=> [a b f|a b f|a b c d f g h]; + [exact: comp1o|exact: compo1|exact: compoA]. +Qed. +End prepullback. + +Definition pb_terminal (Q : precat) + (A B : Q) (c : cospan A B) (s : prepullback c) : + obj (prepullback c) := s. +#[wrapper] +HB.mixin Record prepullback_isTerminal (Q : precat) + (A B : Q) (c : cospan A B) + (s : span A B) of isPrePullback Q A B c s := { + prepullback_terminal : + IsTerminal (prepullback c) (pb_terminal s) +}. +#[short(type="pullback")] +HB.structure Definition Pullback (Q : precat) + (A B : Q) (c : cospan A B) := + {s of isPrePullback Q A B c s + & prepullback_isTerminal Q A B c s }. + +Notation pbsquare u v f g := + (Pullback _ (Cospan f g) (Span u v)). + +Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). + +Section th_of_pb. +Variables (Q : cat) (A B C D E F : Q). +Variables (f : A ~> D) (g : B ~> D) (h : C ~> A). +Variables (u : E ~> A) (v : E ~> B) (w : F ~> C) (z : F ~> E). +Variable (uvfg : pbsquare u v f g). + +Set Printing Width 50. +Theorem pbsquarec_compP : + pbsquare w z h u <=> pbsquare w (z \; v) (h \; f) g. +Proof. +split=> [] sq. + have p : pullback (Cospan h u) := HB.pack (Span w z) sq. + +Admitted. + +End th_of_pb. + + +Module test. + +Section test. +Variables (Q : precat) (A B : Q) (c : cospan A B). +Variable (p : pullback c). +Check pb_terminal p : terminal _. + + + + + + From 2e25e5c532c4459d27ccc5260c671e536d4cd78c Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Fri, 6 Oct 2023 14:12:04 +0200 Subject: [PATCH 046/147] fix Makefile --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 14cfc4a9a..499b18691 100644 --- a/Makefile +++ b/Makefile @@ -138,7 +138,7 @@ sub-%: __always__ endif # Make of individual .vo --------------------------------------------- -structures.vo : %.vo: __always__ Makefile.coq +$(addsuffix o,structures.v $(wildcard theories/*.v)): %.vo: __always__ Makefile.coq +$(COQMAKE) $@ $(addsuffix o,$(wildcard examples/*.v examples/*/*.v tests/*.v tests/unit/*.v)): __always__ config build Makefile.test-suite.coq From cb9cfb0f4283c151e7f983085b7ea89971860405 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Fri, 6 Oct 2023 16:29:16 +0200 Subject: [PATCH 047/147] colors are proofs --- theories/cat.v | 52 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/theories/cat.v b/theories/cat.v index c8fb9f7a2..52a35ee91 100644 --- a/theories/cat.v +++ b/theories/cat.v @@ -1016,8 +1016,56 @@ Theorem pbsquarec_compP : pbsquare w z h u <=> pbsquare w (z \; v) (h \; f) g. Proof. split=> [] sq. - have p : pullback (Cospan h u) := HB.pack (Span w z) sq. - + + have @sq_ispb : pullback (Cospan h u) := HB.pack (Span w z) sq. + have @uvfg_ispb : pullback (Cospan f g) := HB.pack (Span u v) uvfg. + have /=E2 := @is_square _ _ _ _ sq_ispb. + have /=E1 := @is_square _ _ _ _ uvfg_ispb. + + have p1 : @isPrePullback Q C B (Cospan (h \; f) g) (Span w (z \; v)). + by constructor; rewrite /= compoA E2 -compoA E1 compoA. + pose big_black_square : prepullback (Cospan (h \; f) g) := + HB.pack (Span w (z \; v)) p1. + + have @from : forall + (big_red_square : prepullback {| top := D; left2top := h \; f; right2top := g |}), + big_red_square ~> pb_terminal big_black_square. + + move=> big_red_square; unfold pb_terminal. + + have /= := @is_square _ _ _ _ big_red_square. + + pose F' := bot big_red_square. + set w' : F' ~> C := bot2left big_red_square. + set z' : F' ~> B := bot2right big_red_square. + move=> E3. + + have xxx : isPrePullback Q A B (Cospan f g) (Span (w' \; h) z'). + by constructor=> /=; rewrite -compoA E3. + pose red_black_square : prepullback (Cospan f g) := + HB.pack (Span (w' \; h) z') xxx. + have := @from_unique _ (pb_terminal uvfg_ispb) red_black_square. + set blue := @from _ (pb_terminal uvfg_ispb) red_black_square. + move=> blue_unique. + + have p3 : @isPrePullback Q C E (Cospan h u) (Span w' (bot_map blue)). + by constructor; rewrite /= (bot2left_map blue). (* buggy unifier without blue *) + pose blue_red_black_square : prepullback (Cospan h u) := + HB.pack (Span w' (bot_map blue)) p3. + + pose red := @from _ (pb_terminal sq_ispb) blue_red_black_square. + + + + + + have p2 : prepullback_isTerminal.axioms_ Q C B (Cospan (h \; f) g) (Span w (z \; v)) p1. + constructor. econstructor=> /=. + + pose xx : Pullback.type (Cospan (h \; f) g) := + HB.pack (Span w (z \; v)) p2 p1. + apply: Pullback.class xx. + Admitted. End th_of_pb. From feb9249fb498878533b860e7cb2e3a4e5c7a24f4 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Fri, 6 Oct 2023 19:37:27 +0200 Subject: [PATCH 048/147] HB.tag --- HB/common/database.elpi | 14 +++++++-- HB/common/utils.elpi | 18 +++++++---- HB/instance.elpi | 6 +--- HB/structure.elpi | 16 ++++++---- _CoqProject.test-suite | 2 +- structures.v | 68 +++++++++++++++++++++++++++++++++++++++++ tests/tag_wrap.v | 38 +++++++++++++++++++++++ 7 files changed, 141 insertions(+), 21 deletions(-) create mode 100644 tests/tag_wrap.v diff --git a/HB/common/database.elpi b/HB/common/database.elpi index d583b4c37..5051724b6 100644 --- a/HB/common/database.elpi +++ b/HB/common/database.elpi @@ -438,11 +438,14 @@ structure-nparams Structure NParams :- class-def (class Class Structure _), factory-nparams Class NParams. +pred factory?-split i:term, o:factoryname, o:list term, o:term, o:list term. +factory?-split (app[global GR|Args]) F [global GR|Params] T Rest :- + factory-alias->gref GR F, factory-nparams F NP, !, + std.split-at NP Args Params [T|Rest]. + pred factory? i:term, o:w-args factoryname. factory? S (triple F Params T) :- - not (var S), !, - safe-dest-app S (global GR) Args, factory-alias->gref GR F, factory-nparams F NP, !, - std.split-at NP Args Params [T|_]. + factory?-split S F [_|Params] T _. % [find-max-classes Mixins Classes] states that Classes is a list of classes % which contain all the mixins in Mixins. @@ -462,3 +465,8 @@ find-max-classes [M|Mixins] [C|Classes] :- ]. find-max-classes [M|_] _ :- coq.error "HB: cannot find a class containing mixin" M. +pred is-structure-op-w-wrapper i:term, o:int, o:classname. +is-structure-op-w-wrapper (global (const C)) N Class :- exported-op M _ C, wrapper-mixin _ (const C) _, factory-nparams M N, mixin-first-class M Class. +is-structure-op-w-wrapper (app[global (const C)|_]) N Class :- exported-op M _ C, wrapper-mixin _ (const C) _, factory-nparams M N, mixin-first-class M Class. +is-structure-op-w-wrapper (global GR) N Class :- tag GR Class N, wrapper-mixin _ GR _. +is-structure-op-w-wrapper (app[global GR|_]) N Class :- tag GR Class N, wrapper-mixin _ GR _. diff --git a/HB/common/utils.elpi b/HB/common/utils.elpi index f71a6c187..c8c30d9fb 100644 --- a/HB/common/utils.elpi +++ b/HB/common/utils.elpi @@ -317,13 +317,19 @@ re-enable-id-phant T T1 :- pred failsafe-structure-inference i:term, o:term. failsafe-structure-inference T T1 :- - (pi OP Args Args1 M Class NP S\ - copy (app [global (const OP)|Args]) (app [global (const OP)| Args1]) :- - exported-op M _ OP, mixin-first-class M Class, factory-nparams Class NP, - std.nth NP Args S, - var S, + (pi T T2 F_Params F_Params1 Args Args1 Subject Subject1 NP ArgsOp ArgsOp1 OP S\ + copy T T2 :- + factory?-split T _ F_Params Subject Args, + std.map F_Params copy F_Params1, + std.map Args copy Args1, + is-structure-op-w-wrapper Subject NP Class, + coq.safe-dest-app Subject OP ArgsOp, + std.nth NP ArgsOp S, + (var S ; name S), !, - eta-structure-record NP Class Args Args1) => + eta-structure-record NP Class ArgsOp ArgsOp1, + coq.mk-app OP ArgsOp1 Subject1, + coq.mk-app (app F_Params1) [Subject1|Args1] T2) => copy T T1. pred eta-structure-record i:int, i:classname, i:list term, o:list term. diff --git a/HB/instance.elpi b/HB/instance.elpi index d17784042..334f1d2cb 100644 --- a/HB/instance.elpi +++ b/HB/instance.elpi @@ -88,7 +88,7 @@ declare-const Name BodySkel TyWPSkel CSL :- std.do! [ % derived instance %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% (private.declare-regular-inst TheType ML TheMixins TyWP SectionName CSL) % regular instance %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - (if (get-option "wrapper" ff ; not(private.is-structure-op-w-wrapper TheType)) + (if (get-option "wrapper" ff ; not(is-structure-op-w-wrapper TheType _ _)) % regular subject %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% (private.declare-regular-inst TheType ML TheMixins TyWP SectionName CSL) % wrapper %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -462,10 +462,6 @@ declare-wrapper-inst TheType ML TheMixins TyWP SectionName CSL :- std.do![ private.declare-structure-instance-from-mixins TheNewType WML TheWrappedMixins CSL, ]. -pred is-structure-op-w-wrapper i:term. -is-structure-op-w-wrapper (global (const C)) :- exported-op _ _ C, wrapper-mixin _ (const C) _. -is-structure-op-w-wrapper (app[global (const C)|_]) :- exported-op _ _ C, wrapper-mixin _ (const C) _. - pred derive-wrapper-instances i:term, i:mixinname, o:term, o:constant. derive-wrapper-instances Instance WrapperMixin WrapperSubject C :- std.do! [ diff --git a/HB/structure.elpi b/HB/structure.elpi index d035d9428..472362333 100644 --- a/HB/structure.elpi +++ b/HB/structure.elpi @@ -12,7 +12,6 @@ declare Module BSkel Sort :- std.do! [ failsafe-structure-inference BSkelNoId BSkelNoIdX, std.assert-ok! (coq.elaborate-skeleton BSkelNoIdX _ BNoId) "illtyped structure definition", re-enable-id-phant BNoId B, - private.sigT->list-w-params B GRFSwP_or_ThingtoBeWrapped ClosureCheck, % do some work to go back to factories on a single subject @@ -214,7 +213,6 @@ clean-op-ty [exported-op _ Po C|Ops] S T1 T2 :- gref-deps (const Po) MLwP, w-params.nparams MLwP NParams, std.length {list-w-params_list MLwP} NMixins, - (pi L L1 L2 Params Rest PoArgs\ copy (app [global (const Po)| L]) (app [global (const C) | L2]) :- std.split-at NParams L Params [_|Rest], @@ -633,19 +631,25 @@ if-coverage-not-good-error.one _ _. % new class is the first covering M % hom belongs to Quiver, hence hom_isMon takes a "T of Quiver T" % checks if the term is forall A B C, Factory ... (Op A B C) ... -pred factory-on-some-structure-op? i:term, i:list term, o:gref, o:constant. +pred factory-on-some-structure-op? i:term, i:list term, o:gref, o:gref. factory-on-some-structure-op? (prod N Ty Bo) VS F OP :- @pi-decl N Ty x\ factory-on-some-structure-op? (Bo x) [x|VS] F OP. -factory-on-some-structure-op? T VS F OP :- +factory-on-some-structure-op? T VS F (const OP) :- factory? T (triple F _ Subject), coq.safe-dest-app Subject (global (const OP)) Args, exported-op _ _ OP, std.appendR _ {std.rev VS} Args. +factory-on-some-structure-op? T VS F GR :- std.do! [ + factory? T (triple F _ Subject), + coq.safe-dest-app Subject (global GR) Args, + tag GR _ _, + std.appendR _ {std.rev VS} Args, +]. kind factory-on-subject type. type factory-on-the-type w-args factoryname -> factory-on-subject. -type factory-on-structure-op term -> factoryname -> constant -> factory-on-subject. +type factory-on-structure-op term -> factoryname -> gref -> factory-on-subject. pred product->triples i:term, i:term, o:list factory-on-subject, o:bool. product->triples {{ lib:hb.prod lp:A lp:B }} T L ClosureCheck :- !, @@ -683,7 +687,7 @@ lift-to-the-subject.aux [] _ []. lift-to-the-subject.aux [factory-on-the-type F|Rest] T [F|Rest1] :- lift-to-the-subject.aux Rest T Rest1. lift-to-the-subject.aux [factory-on-structure-op Expr F OP|Rest] T [WF|Rest1] :- - wrapper-mixin Wrapper (const OP) F, !, + wrapper-mixin Wrapper OP F, !, factory-nparams Wrapper NParams, coq.mk-app {coq.env.global Wrapper} {std.append {coq.mk-n-holes NParams} [T]} W, factory? W WF, diff --git a/_CoqProject.test-suite b/_CoqProject.test-suite index 39f69e06c..5412b499b 100644 --- a/_CoqProject.test-suite +++ b/_CoqProject.test-suite @@ -53,7 +53,6 @@ examples/Coq2020_material/CoqWS_abstract.v examples/Coq2020_material/CoqWS_expansion/withHB.v examples/Coq2020_material/CoqWS_expansion/withoutHB.v -examples/cat/cat.v tests/enriched_cat_case6.v tests/type_of_exported_ops.v @@ -96,6 +95,7 @@ tests/unit/close_hole_term.v tests/unit/struct.v tests/factory_when_notation.v tests/monoid_enriched_cat.v +tests/tag_wrap.v -R tests HB.tests -R examples HB.examples diff --git a/structures.v b/structures.v index 51cd4c501..b3d5d15d8 100644 --- a/structures.v +++ b/structures.v @@ -167,6 +167,11 @@ pred mixin-mem i:term, o:gref. % wrapper-mixin (indt "hom_isMon") (const "hom") (indt "isMon"). pred wrapper-mixin o:mixinname, o:gref, o:mixinname. +% designated identity function for wrapping (sometimes you don't have a +% structure op for it). +% [tag GR Class NParams] +pred tag o:gref, o:classname, o:int. + %%%%%% Memory of exported mixins (HB.structure) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Operations (named mixin fields) need to be exported exactly once, % but the same mixin can be used in many structure, hence this memory @@ -1197,6 +1202,69 @@ Elpi Export HB.check. (* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *) (* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *) +(** [HB.tag] declares a tag for mixin subjects + +[[ +HB.tag Definition N Params x := x +]] + +*) + +#[arguments(raw)] Elpi Command HB.tag. +Elpi Accumulate Db hb.db. +Elpi Accumulate File "HB/common/stdpp.elpi". +Elpi Accumulate File "HB/common/database.elpi". +#[skip="8.1[56].*"] Elpi Accumulate File "HB/common/compat_acc_clauses_all.elpi". +#[only="8.1[56].*"] Elpi Accumulate File "HB/common/compat_acc_clauses_816.elpi". +Elpi Accumulate File "HB/common/utils.elpi". +Elpi Accumulate File "HB/common/log.elpi". +Elpi Accumulate File "HB/common/synthesis.elpi". +Elpi Accumulate File "HB/context.elpi". +Elpi Accumulate File "HB/instance.elpi". +Elpi Accumulate lp:{{ + +main [const-decl Name (some BodySkel) AritySkel] :- !, std.do! [ + std.assert-ok! (coq.elaborate-arity-skeleton AritySkel _ Arity) "HB: type illtyped", + coq.arity->nparams Arity N, + coq.arity->term Arity Ty, + std.assert-ok! (coq.elaborate-skeleton BodySkel Ty Body) "HB: body illtyped", + with-attributes (with-logging (std.do! [ + log.coq.env.add-const-noimplicits Name Body Ty @transparent! C, + coq.arity->implicits Arity CImpls, + if (coq.any-implicit? CImpls) + (@global! => coq.arguments.set-implicit (const C) [CImpls]) + true, + ])), + M is N - 1, + class-of-nth-arg M Ty Class, + acc-clause current (tag (const C) Class M), +]. +main [str G, str"|", int M] :- !, + coq.locate G GR, + coq.env.typeof GR Ty, + class-of-nth-arg M Ty Class, + acc-clause current (tag GR Class M). + +main _ :- coq.error "Usage: HB.tag Definition := T ...\nUsage: HB.tag | ". + +pred class-of-nth-arg i:int, i:term, o:classname. +class-of-nth-arg 0 (prod _ (global S) _\_) Class :- class-def (class Class S _). +class-of-nth-arg 0 (prod _ (app [global S|_]) _\_) Class :- class-def (class Class S _). +class-of-nth-arg N (prod Name Ty Bo) Class :- N > 0, !, M is N - 1, + @pi-decl Name Ty x\ class-of-nth-arg M (Bo x) Class. +class-of-nth-arg 0 T _ :- !, + coq.error "HB: the last parameter of a tag must be of a structure type:" {coq.term->string T}. +class-of-nth-arg _ T _ :- !, + coq.error "HB: not enough argsuments:" {coq.term->string T}. + +}}. +Elpi Typecheck. +Elpi Export HB.tag. + +(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *) +(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *) +(* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *) + (** Technical notations from /Canonical Structures for the working Coq user/ *) Notation "`Error_cannot_unify: t1 'with' t2" := (unify t1 t2 None) (at level 0, format "`Error_cannot_unify: t1 'with' t2", only printing) : diff --git a/tests/tag_wrap.v b/tests/tag_wrap.v new file mode 100644 index 000000000..deafbccf6 --- /dev/null +++ b/tests/tag_wrap.v @@ -0,0 +1,38 @@ +From HB Require Import structures. + +HB.mixin Record isSomething T := { clearly : True }. +HB.structure Definition Something := { T of isSomething T }. + +HB.mixin Record isTerminal (T : Type) := { p : True }. + +HB.tag Definition this_one (T : Something.type) : Type := T. + +#[wrapper] +HB.mixin Record this_one_isTerminal T of Something T := { + private : isTerminal (this_one T) +}. + +HB.tag Definition this_other_one (T : Something.type) : Type := T. + +#[wrapper] +HB.mixin Record this_other_one_isTerminal T of Something T := { + private : isTerminal (this_other_one T) +}. +(* This is a bug, maybe even in master. If I declare an instance on a mixin + which leads to no new structure instance, then the mixin is not use later + on *) +HB.structure Definition magic1 := { T of + isSomething T & + isTerminal (this_one T) +}. + +HB.structure Definition magic := { T of + isSomething T & + isTerminal (this_one T) & + isTerminal (this_other_one T) +}. + +HB.instance Definition _ : isSomething nat := isSomething.Build nat I. +HB.instance Definition _ : isTerminal (this_one nat) := isTerminal.Build nat I. +HB.instance Definition _ : isTerminal (this_other_one nat) := isTerminal.Build nat I. +Check nat : magic.type. From a1809183158e978162c4af486915f597e1973316 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Fri, 6 Oct 2023 19:58:58 +0200 Subject: [PATCH 049/147] remove ELIM hack --- HB/instance.elpi | 17 +++++++---------- HB/structure.elpi | 2 +- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/HB/instance.elpi b/HB/instance.elpi index 334f1d2cb..ffb95dfc1 100644 --- a/HB/instance.elpi +++ b/HB/instance.elpi @@ -84,16 +84,13 @@ declare-const Name BodySkel TyWPSkel CSL :- std.do! [ % derive all mixins the factory provides private.declare-mixins-from-factory Factory TheType TheFactory ML TheMixins, - if (rex.match ".*__ELIM" RealName) - % derived instance %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - (private.declare-regular-inst TheType ML TheMixins TyWP SectionName CSL) - % regular instance %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - (if (get-option "wrapper" ff ; not(is-structure-op-w-wrapper TheType _ _)) - % regular subject %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - (private.declare-regular-inst TheType ML TheMixins TyWP SectionName CSL) - % wrapper %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - (private.declare-wrapper-inst TheType ML TheMixins TyWP SectionName CSL) - ), + % regular instance %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + if (get-option "wrapper" ff ; not(is-structure-op-w-wrapper TheType _ _)) + % regular subject %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + (private.declare-regular-inst TheType ML TheMixins TyWP SectionName CSL) + % wrapper %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + (private.declare-wrapper-inst TheType ML TheMixins TyWP SectionName CSL) + , % shared to all branches if (get-option "export" tt) diff --git a/HB/structure.elpi b/HB/structure.elpi index 472362333..9714b14ee 100644 --- a/HB/structure.elpi +++ b/HB/structure.elpi @@ -717,7 +717,7 @@ reexport-wrapper-as-instance M :- std.do! [ Str0 is "Op_isMx" ^ "__" ^ {std.any->string {new_int}}, std.string.concat "__" [Str0, "ELIM"] Str, - instance.declare-const Str B Arity _ + get-option "wrapper" ff => instance.declare-const Str B Arity _ ]. }} From 450cf7e97c31583853c3f0b062b10a7f5b797c6d Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Fri, 6 Oct 2023 19:59:08 +0200 Subject: [PATCH 050/147] cleanup --- HB/structure.elpi | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/HB/structure.elpi b/HB/structure.elpi index 9714b14ee..028d6350b 100644 --- a/HB/structure.elpi +++ b/HB/structure.elpi @@ -686,12 +686,11 @@ lift-to-the-subject (w-params.nil ID T Rest) (w-params.nil ID T Rest1) :- lift-to-the-subject.aux [] _ []. lift-to-the-subject.aux [factory-on-the-type F|Rest] T [F|Rest1] :- lift-to-the-subject.aux Rest T Rest1. -lift-to-the-subject.aux [factory-on-structure-op Expr F OP|Rest] T [WF|Rest1] :- +lift-to-the-subject.aux [factory-on-structure-op _ F OP|Rest] T [WF|Rest1] :- wrapper-mixin Wrapper OP F, !, factory-nparams Wrapper NParams, coq.mk-app {coq.env.global Wrapper} {std.append {coq.mk-n-holes NParams} [T]} W, factory? W WF, - coq.say Expr "->" WF, lift-to-the-subject.aux Rest T Rest1. lift-to-the-subject.aux [factory-on-structure-op Expr _ _|_] _ _ :- coq.error "NYI: automatic wrapping for" {coq.term->string Expr}. From 79aba6c6fd55b35046803942af58830ea5aa24b9 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Fri, 6 Oct 2023 19:59:19 +0200 Subject: [PATCH 051/147] fix test --- tests/enriched_cat_case6.v | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/tests/enriched_cat_case6.v b/tests/enriched_cat_case6.v index dd9c0e951..ff272ccd5 100644 --- a/tests/enriched_cat_case6.v +++ b/tests/enriched_cat_case6.v @@ -467,9 +467,7 @@ eapply functional_extensionality; intro x0. refine (mrid _). Qed. -stop - -Program Definition icmfunQ_isICAlg (A B: ICMon.type) : +(* Program Definition icmfunQ_isICAlg (A B: ICMon.type) : isICAlg (hom A B) := isICAlg.Build (hom A B) _ _. Obligation 1. econstructor. @@ -496,24 +494,17 @@ simpl in *. destruct ica0. destruct isia0. eapply aidem0; auto. -Qed. +Qed. *) -Program Definition icmfunQ_isICMon (A B: ICMon.type) : +(* Program Definition icmfunQ_isICMon (A B: ICMon.type) : isICMon (hom A B) := isICMon.Build (hom A B) _ _. Obligation 1. eapply icmfunQ_isICAlg. Qed. Obligation 2. eapply icmfunQ_isMon. -Qed. +Qed. *) HB.instance Definition icmfunQ_isMonoid (A B: ICMon.type) : isMon (hom A B) := icmfunQ_isMon A B. -HB.instance Definition icmfunQ_isICAlgebra (A B: ICMon.type) : - isICAlg (hom A B) := icmfunQ_isICAlg A B. - -HB.instance Definition icmfunQ_isICMonoid (A B: ICMon.type) : - isICMon (hom A B) := icmfunQ_isICMon A B. - -Check ICMon.type : ICAlg_enriched_quiver.type. From 8ac8c9dcfc1e0eb6e5121898979100b6d469e38c Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Fri, 6 Oct 2023 20:00:14 +0200 Subject: [PATCH 052/147] note --- HB/common/utils.elpi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HB/common/utils.elpi b/HB/common/utils.elpi index c8c30d9fb..ebf061f87 100644 --- a/HB/common/utils.elpi +++ b/HB/common/utils.elpi @@ -325,7 +325,7 @@ failsafe-structure-inference T T1 :- is-structure-op-w-wrapper Subject NP Class, coq.safe-dest-app Subject OP ArgsOp, std.nth NP ArgsOp S, - (var S ; name S), + (var S ; name S), % TODO: should be the subject of the structure, not a random name !, eta-structure-record NP Class ArgsOp ArgsOp1, coq.mk-app OP ArgsOp1 Subject1, From 2a3946066b6f5495c6cd12dd292414b21a43363f Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Fri, 6 Oct 2023 20:09:31 +0200 Subject: [PATCH 053/147] fix HB.tag --- structures.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/structures.v b/structures.v index b3d5d15d8..eecff9c16 100644 --- a/structures.v +++ b/structures.v @@ -1229,7 +1229,7 @@ main [const-decl Name (some BodySkel) AritySkel] :- !, std.do! [ coq.arity->term Arity Ty, std.assert-ok! (coq.elaborate-skeleton BodySkel Ty Body) "HB: body illtyped", with-attributes (with-logging (std.do! [ - log.coq.env.add-const-noimplicits Name Body Ty @transparent! C, + log.coq.env.add-const Name Body Ty @transparent! C, coq.arity->implicits Arity CImpls, if (coq.any-implicit? CImpls) (@global! => coq.arguments.set-implicit (const C) [CImpls]) From a2bf6d4210095b5b2ab4c5063a8e0e3f3694ea88 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Fri, 6 Oct 2023 20:52:52 +0200 Subject: [PATCH 054/147] FIX: toposort will always be buggy ;-) --- HB/common/database.elpi | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/HB/common/database.elpi b/HB/common/database.elpi index 5051724b6..e693fbcac 100644 --- a/HB/common/database.elpi +++ b/HB/common/database.elpi @@ -179,12 +179,18 @@ toposort-proj Proj ES In Out :- !, toposort-proj.acc Proj ES [] In Out. pred topo-find i:B, o:A. pred toposort-proj.acc i:(A -> B -> prop), i:list (pair B B), i:list B, i:list A, o:list A. toposort-proj.acc _ ES Acc [] Out :- !, - std.map {std.toposort ES Acc} topo-find Out. + std.map {std.toposort ES Acc} topo-find-all Out. toposort-proj.acc Proj ES Acc [A|In] Out :- std.do![ Proj A B, topo-find B A => toposort-proj.acc Proj ES [B|Acc] In Out ]. +pred topo-find-all i:B, o:A. +topo-find-all B A :- std.do! [ + std.findall (topo-find B C_) L, + std.assert! (std.forall L (x\ x = topo-find B A)) "topofind bad", +]. + % Classes can be topologically sorted according to the subclass relation pred toposort-classes.mk-class-edge i:prop, o:pair classname classname. toposort-classes.mk-class-edge (sub-class C1 C2 _ _) (pr C2 C1). From 922d6b9664a22ec4ead40aff6df3ebe2db5daf90 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Fri, 6 Oct 2023 20:53:23 +0200 Subject: [PATCH 055/147] better eta expansion for failsafe structure elab --- HB/common/utils.elpi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/HB/common/utils.elpi b/HB/common/utils.elpi index ebf061f87..21c93f542 100644 --- a/HB/common/utils.elpi +++ b/HB/common/utils.elpi @@ -327,19 +327,19 @@ failsafe-structure-inference T T1 :- std.nth NP ArgsOp S, (var S ; name S), % TODO: should be the subject of the structure, not a random name !, - eta-structure-record NP Class ArgsOp ArgsOp1, + eta-structure-record S NP Class ArgsOp ArgsOp1, coq.mk-app OP ArgsOp1 Subject1, coq.mk-app (app F_Params1) [Subject1|Args1] T2) => copy T T1. -pred eta-structure-record i:int, i:classname, i:list term, o:list term. -eta-structure-record NP Class L L1 :- +pred eta-structure-record i:term, i:int, i:classname, i:list term, o:list term. +eta-structure-record S NP Class L L1 :- std.split-at NP L Params [_|Rest], class-def (class Class Structure _), get-constructor Structure K, std.map Params copy Params1, std.map Rest copy Rest1, - coq.mk-app {coq.env.global K} {std.append Params1 [_,_]} EtaS, + coq.mk-app {coq.env.global K} {std.append Params1 [S,_]} EtaS, std.append Params1 [EtaS|Rest1] L1. pred prod-last i:term, o:term. From 700544061e7cf833e7d932e21ad83c99c34136ac Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Fri, 6 Oct 2023 20:54:32 +0200 Subject: [PATCH 056/147] CAT: use HB.tag for pb_terminal (the wrapper is not autogen, but could be) --- theories/cat.v | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/theories/cat.v b/theories/cat.v index 52a35ee91..dc672c1b1 100644 --- a/theories/cat.v +++ b/theories/cat.v @@ -984,9 +984,10 @@ constructor=> [a b f|a b f|a b c d f g h]; Qed. End prepullback. -Definition pb_terminal (Q : precat) +HB.tag Definition pb_terminal (Q : precat) (A B : Q) (c : cospan A B) (s : prepullback c) : obj (prepullback c) := s. + #[wrapper] HB.mixin Record prepullback_isTerminal (Q : precat) (A B : Q) (c : cospan A B) @@ -994,11 +995,11 @@ HB.mixin Record prepullback_isTerminal (Q : precat) prepullback_terminal : IsTerminal (prepullback c) (pb_terminal s) }. -#[short(type="pullback")] +#[short(type="pullback"), verbose] HB.structure Definition Pullback (Q : precat) (A B : Q) (c : cospan A B) := {s of isPrePullback Q A B c s - & prepullback_isTerminal Q A B c s }. + & IsTerminal (prepullback c) (pb_terminal s) }. Notation pbsquare u v f g := (Pullback _ (Cospan f g) (Span u v)). From e24e3a1dd424aac6c510e1ca7f8f08f610836e41 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Fri, 6 Oct 2023 21:02:36 +0200 Subject: [PATCH 057/147] use subject-lifter instead of structure-op --- HB/common/database.elpi | 10 +++++----- HB/common/utils.elpi | 2 +- HB/instance.elpi | 2 +- HB/structure.elpi | 10 +++++----- structures.v | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/HB/common/database.elpi b/HB/common/database.elpi index e693fbcac..d4eb27ea2 100644 --- a/HB/common/database.elpi +++ b/HB/common/database.elpi @@ -471,8 +471,8 @@ find-max-classes [M|Mixins] [C|Classes] :- ]. find-max-classes [M|_] _ :- coq.error "HB: cannot find a class containing mixin" M. -pred is-structure-op-w-wrapper i:term, o:int, o:classname. -is-structure-op-w-wrapper (global (const C)) N Class :- exported-op M _ C, wrapper-mixin _ (const C) _, factory-nparams M N, mixin-first-class M Class. -is-structure-op-w-wrapper (app[global (const C)|_]) N Class :- exported-op M _ C, wrapper-mixin _ (const C) _, factory-nparams M N, mixin-first-class M Class. -is-structure-op-w-wrapper (global GR) N Class :- tag GR Class N, wrapper-mixin _ GR _. -is-structure-op-w-wrapper (app[global GR|_]) N Class :- tag GR Class N, wrapper-mixin _ GR _. +pred is-subject-lifter i:term, o:int, o:classname. +is-subject-lifter (global (const C)) N Class :- exported-op M _ C, wrapper-mixin _ (const C) _, factory-nparams M N, mixin-first-class M Class. +is-subject-lifter (app[global (const C)|_]) N Class :- exported-op M _ C, wrapper-mixin _ (const C) _, factory-nparams M N, mixin-first-class M Class. +is-subject-lifter (global GR) N Class :- tag GR Class N, wrapper-mixin _ GR _. +is-subject-lifter (app[global GR|_]) N Class :- tag GR Class N, wrapper-mixin _ GR _. diff --git a/HB/common/utils.elpi b/HB/common/utils.elpi index 21c93f542..00153f062 100644 --- a/HB/common/utils.elpi +++ b/HB/common/utils.elpi @@ -322,7 +322,7 @@ failsafe-structure-inference T T1 :- factory?-split T _ F_Params Subject Args, std.map F_Params copy F_Params1, std.map Args copy Args1, - is-structure-op-w-wrapper Subject NP Class, + is-subject-lifter Subject NP Class, coq.safe-dest-app Subject OP ArgsOp, std.nth NP ArgsOp S, (var S ; name S), % TODO: should be the subject of the structure, not a random name diff --git a/HB/instance.elpi b/HB/instance.elpi index ffb95dfc1..c8fe910c8 100644 --- a/HB/instance.elpi +++ b/HB/instance.elpi @@ -85,7 +85,7 @@ declare-const Name BodySkel TyWPSkel CSL :- std.do! [ private.declare-mixins-from-factory Factory TheType TheFactory ML TheMixins, % regular instance %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - if (get-option "wrapper" ff ; not(is-structure-op-w-wrapper TheType _ _)) + if (get-option "wrapper" ff ; not(is-subject-lifter TheType _ _)) % regular subject %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% (private.declare-regular-inst TheType ML TheMixins TyWP SectionName CSL) % wrapper %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/HB/structure.elpi b/HB/structure.elpi index 028d6350b..fea5c9d00 100644 --- a/HB/structure.elpi +++ b/HB/structure.elpi @@ -649,7 +649,7 @@ factory-on-some-structure-op? T VS F GR :- std.do! [ kind factory-on-subject type. type factory-on-the-type w-args factoryname -> factory-on-subject. -type factory-on-structure-op term -> factoryname -> gref -> factory-on-subject. +type factory-on-subject-lifter term -> factoryname -> gref -> factory-on-subject. pred product->triples i:term, i:term, o:list factory-on-subject, o:bool. product->triples {{ lib:hb.prod lp:A lp:B }} T L ClosureCheck :- !, @@ -659,10 +659,10 @@ product->triples {{ lib:hb.prod lp:A lp:B }} T L ClosureCheck :- !, product->triples {{ True }} _ [] tt :- !. product->triples {{ False }} _ [] ff :- !. product->triples A T [factory-on-the-type F] tt :- factory? A F, F = triple _ _ T, !. -product->triples A _ [factory-on-structure-op A F OP] tt :- factory-on-some-structure-op? A [] F OP, !. +product->triples A _ [factory-on-subject-lifter A F OP] tt :- factory-on-some-structure-op? A [] F OP, !. product->triples A T _ _ :- coq.error "HB: expecting a factory on" {coq.term->string T} - "or a factory on a structure operation. Got:" {coq.term->string A}. + "or a factory on a structure operation or tag. Got:" {coq.term->string A}. pred sigT->list-w-params i:term, o:w-params (list factory-on-subject), o:bool. sigT->list-w-params (fun N T B) L C :- @@ -686,13 +686,13 @@ lift-to-the-subject (w-params.nil ID T Rest) (w-params.nil ID T Rest1) :- lift-to-the-subject.aux [] _ []. lift-to-the-subject.aux [factory-on-the-type F|Rest] T [F|Rest1] :- lift-to-the-subject.aux Rest T Rest1. -lift-to-the-subject.aux [factory-on-structure-op _ F OP|Rest] T [WF|Rest1] :- +lift-to-the-subject.aux [factory-on-subject-lifter _ F OP|Rest] T [WF|Rest1] :- wrapper-mixin Wrapper OP F, !, factory-nparams Wrapper NParams, coq.mk-app {coq.env.global Wrapper} {std.append {coq.mk-n-holes NParams} [T]} W, factory? W WF, lift-to-the-subject.aux Rest T Rest1. -lift-to-the-subject.aux [factory-on-structure-op Expr _ _|_] _ _ :- +lift-to-the-subject.aux [factory-on-subject-lifter Expr _ _|_] _ _ :- coq.error "NYI: automatic wrapping for" {coq.term->string Expr}. diff --git a/structures.v b/structures.v index eecff9c16..3758786c2 100644 --- a/structures.v +++ b/structures.v @@ -1205,7 +1205,7 @@ Elpi Export HB.check. (** [HB.tag] declares a tag for mixin subjects [[ -HB.tag Definition N Params x := x +HB.tag Definition N Params (x : S.type) : Type := x ]] *) @@ -1245,7 +1245,7 @@ main [str G, str"|", int M] :- !, class-of-nth-arg M Ty Class, acc-clause current (tag GR Class M). -main _ :- coq.error "Usage: HB.tag Definition := T ...\nUsage: HB.tag | ". +main _ :- coq.error "Usage: HB.tag Definition ... := T ...\nUsage: HB.tag | ". pred class-of-nth-arg i:int, i:term, o:classname. class-of-nth-arg 0 (prod _ (global S) _\_) Class :- class-def (class Class S _). From 81fe41fdedd6267d75593b5c30c1bb0191d4d5cc Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Fri, 6 Oct 2023 21:04:23 +0200 Subject: [PATCH 058/147] document toposort bug --- HB/common/database.elpi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/HB/common/database.elpi b/HB/common/database.elpi index d4eb27ea2..d0ed789d4 100644 --- a/HB/common/database.elpi +++ b/HB/common/database.elpi @@ -188,6 +188,8 @@ toposort-proj.acc Proj ES Acc [A|In] Out :- std.do![ pred topo-find-all i:B, o:A. topo-find-all B A :- std.do! [ std.findall (topo-find B C_) L, + % if there were dusplicates, we ensure we keep the most instantiated, eg + % (triple m [X,Y] t) v.s. (triple m [a,b] t) std.assert! (std.forall L (x\ x = topo-find B A)) "topofind bad", ]. From da52021236759c47bc0e2b9cc55907475ca728af Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Fri, 6 Oct 2023 22:59:17 +0200 Subject: [PATCH 059/147] Enter HB.from (from factories) --- HB/common/synthesis.elpi | 16 +++++++++++ HB/pack.elpi | 58 ++++++++++++++++++++++++++++++++-------- structures.v | 23 ++++++++++++++++ theories/cat.v | 10 +++---- 4 files changed, 91 insertions(+), 16 deletions(-) diff --git a/HB/common/synthesis.elpi b/HB/common/synthesis.elpi index f6c105113..593567a96 100644 --- a/HB/common/synthesis.elpi +++ b/HB/common/synthesis.elpi @@ -74,6 +74,13 @@ infer-all-args-let Ps T GR X Diag :- std.do! [ private.instantiate-all-args-let FT T X Diag, ]. +pred try-infer-all-args-let i:list term, i:term, i:gref, o:term. +try-infer-all-args-let Ps T GR X :- std.do! [ + coq.env.typeof GR Ty, + coq.mk-eta (-1) Ty (global GR) EtaF, + coq.subst-fun {std.append Ps [T]} EtaF FT, + private.try-instantiate-all-args-let FT T X, +]. % [assert!-infer-mixin TheType M Out] infers one mixin M on TheType and % aborts with an error message if the mixin cannot be inferred @@ -271,6 +278,15 @@ instantiate-all-args-let (fun N Tm F) T (let N Tm X R) Diag :- !, std.do! [ ]. instantiate-all-args-let F _ F ok. +pred try-instantiate-all-args-let i:term, i:term, o:term. +try-instantiate-all-args-let (fun N Tm F) T (let N Tm X R) :- !, std.do! [ + coq.safe-dest-app Tm (global TmGR) _, + factory-alias->gref TmGR M, + (mixin-for T M X ; true), + (@pi-def N Tm X m\ try-instantiate-all-args-let (F m) T (R m)), +]. +try-instantiate-all-args-let F _ F. + % [structure-instance->mixin-srcs TheType Structure] finds a CS instance for % Structure on TheType (if any) and builds mixin-src clauses for all the mixins % which can be candidates from that class instance. It finds instances which are diff --git a/HB/pack.elpi b/HB/pack.elpi index b957db382..cdd8d1a3b 100644 --- a/HB/pack.elpi +++ b/HB/pack.elpi @@ -12,7 +12,6 @@ main Ty Args Instance :- std.do! [ std.assert! (Args = [trm TSkel|FactoriesSkel]) "HB.pack: not enough arguments", get-constructor Class KC, - get-constructor Structure KS, std.assert-ok! (d\ (coq.elaborate-ty-skeleton TSkel _ T d, d = ok) ; @@ -29,30 +28,67 @@ main Ty Args Instance :- std.do! [ (AllFactories = Factories) (AllFactories = Factories, Tkey = T), % it's a factory, won't add anything - private.synth-instance Params KC KS T Tkey AllFactories Instance, + private.synth-instance Params KC Tkey AllFactories ClassInstance, + + get-constructor Structure KS, + std.append Params [T, ClassInstance] InstanceArgs, + Instance = app[global KS | InstanceArgs] ]. +pred main-use-factories i:term, i:list argument, o:term. +main-use-factories Ty FactoriesSkel ClassInstance :- std.do! [ + std.assert! (not(var Ty)) "HB.from: the class cannot be unknown", + + factory? {unwind {whd Ty []}} (triple Class Params T), + + std.assert! (class-def (class Class _ _)) "HB.from: not a class", + + get-constructor Class KC, + + private.elab-factories FactoriesSkel T Factories, + + if (var T) (coq.error "HB.from: you must pass a type or at least one factory") true, + + if2 (T = app[global (const SortProj)|ProjParams], structure-key SortProj ClassProj _) + (AllFactories = [app[global (const ClassProj)|ProjParams] | Factories], Tkey = T) % already existing class on T + (def T _ _ Tkey) % we unfold letins if we can, they may hide constants with CS instances + (AllFactories = Factories) + (AllFactories = Factories, Tkey = T), % it's a factory, won't add anything + + private.try-synth-instance Params KC Tkey AllFactories ClassInstance, + +]. + + /* ------------------------------------------------------------------------- */ /* ----------------------------- private code ------------------------------ */ /* ------------------------------------------------------------------------- */ namespace private { -pred synth-instance i:list term, i:gref, i:gref, i:term, i:term, i:list term, o:term. -synth-instance Params KC KS T Tkey [Factory|Factories] Instance :- +pred synth-instance i:list term, i:gref, i:term, i:list term, o:term. +synth-instance Params KC Tkey [Factory|Factories] ClassInstance :- synthesis.under-new-mixin-src-from-factory.do! Tkey Factory (_\ - synth-instance Params KC KS T Tkey Factories Instance). -synth-instance Params KC KS T Tkey [] Instance :- coq.safe-dest-app Tkey (global _) _, !, + synth-instance Params KC Tkey Factories ClassInstance). +synth-instance Params KC Tkey [] ClassInstance :- coq.safe-dest-app Tkey (global _) _, !, synthesis.under-local-canonical-mixins-of.do! Tkey [ std.assert-ok! (synthesis.infer-all-args-let Params Tkey KC ClassInstance) "HB.pack: cannot infer the instance", - std.append Params [T, ClassInstance] InstanceArgs, - Instance = app[global KS | InstanceArgs] ]. -synth-instance Params KC KS T Tkey [] Instance :- std.do! [ +synth-instance Params KC Tkey [] ClassInstance :- std.do! [ std.assert-ok! (synthesis.infer-all-args-let Params Tkey KC ClassInstance) "HB.pack: cannot infer the instance", - std.append Params [T, ClassInstance] InstanceArgs, - Instance = app[global KS | InstanceArgs] +]. + +pred try-synth-instance i:list term, i:gref, i:term, i:list term, o:term. +try-synth-instance Params KC Tkey [Factory|Factories] ClassInstance :- + synthesis.under-new-mixin-src-from-factory.do! Tkey Factory (_\ + try-synth-instance Params KC Tkey Factories ClassInstance). +try-synth-instance Params KC Tkey [] ClassInstance :- coq.safe-dest-app Tkey (global _) _, !, + synthesis.under-local-canonical-mixins-of.do! Tkey [ + synthesis.try-infer-all-args-let Params Tkey KC ClassInstance, +]. +try-synth-instance Params KC Tkey [] ClassInstance :- std.do! [ + synthesis.try-infer-all-args-let Params Tkey KC ClassInstance, ]. pred elab-factories i:list argument, i:term, o:list term. diff --git a/structures.v b/structures.v index 3758786c2..9187b4727 100644 --- a/structures.v +++ b/structures.v @@ -579,6 +579,29 @@ solve (goal _ _ Ty _ Args as G) GLS :- with-attributes (with-logging (std.do! [ Elpi Typecheck. Elpi Export HB.pack. +Elpi Tactic HB.from. +Elpi Accumulate Db hb.db. +Elpi Accumulate File "HB/common/stdpp.elpi". +Elpi Accumulate File "HB/common/database.elpi". +#[skip="8.1[56].*"] Elpi Accumulate File "HB/common/compat_acc_clauses_all.elpi". +#[only="8.1[56].*"] Elpi Accumulate File "HB/common/compat_acc_clauses_816.elpi". +Elpi Accumulate File "HB/common/utils.elpi". +Elpi Accumulate File "HB/common/log.elpi". +Elpi Accumulate File "HB/common/synthesis.elpi". +Elpi Accumulate File "HB/pack.elpi". +Elpi Accumulate lp:{{ + +solve (goal _ _ Ty _ Args as G) GLS :- with-attributes (with-logging (std.do! [ + pack.main-use-factories Ty Args Instance, + refine Instance G GLS, +])). + +}}. +Elpi Typecheck. + +Tactic Notation "HB.from" open_constr_list(L) := + elpi HB.from ltac_term_list:(L). + (* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *) (* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *) (* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% *) diff --git a/theories/cat.v b/theories/cat.v index dc672c1b1..f2f172a94 100644 --- a/theories/cat.v +++ b/theories/cat.v @@ -1056,16 +1056,15 @@ split=> [] sq. pose red := @from _ (pb_terminal sq_ispb) blue_red_black_square. - + admit. have p2 : prepullback_isTerminal.axioms_ Q C B (Cospan (h \; f) g) (Span w (z \; v)) p1. constructor. econstructor=> /=. + admit. - pose xx : Pullback.type (Cospan (h \; f) g) := - HB.pack (Span w (z \; v)) p2 p1. - apply: Pullback.class xx. + by HB.from p1 p2. Admitted. @@ -1079,7 +1078,8 @@ Variables (Q : precat) (A B : Q) (c : cospan A B). Variable (p : pullback c). Check pb_terminal p : terminal _. - +End test. +End test. From 8d40177ee90711c74453cadda37015637c1d8662 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Mon, 9 Oct 2023 14:35:51 +0200 Subject: [PATCH 060/147] fix rebase --- HB/common/synthesis.elpi | 5 +++-- HB/instance.elpi | 28 +++++++++++++++------------- tests/hnf.v | 2 +- tests/hnf.v.out | 2 +- tests/not_same_key.v.out | 3 ++- 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/HB/common/synthesis.elpi b/HB/common/synthesis.elpi index 593567a96..055a4fc1c 100644 --- a/HB/common/synthesis.elpi +++ b/HB/common/synthesis.elpi @@ -113,9 +113,10 @@ under-mixin-src-from-factory.do! TheType TheFactory LP :- std.do! [ % Given TheType makes the provided list of mixins and instances % available for inference. -pred under-these-mixin-src.do! i:term, i:list mixinname, i:list constant, i:list prop. -under-these-mixin-src.do! TheType ML TheMixins LP :- std.do! [ +pred under-these-mixin-src.do! i:term, i:list mixinname, i:list constant, o:list prop, i:list prop. +under-these-mixin-src.do! TheType ML TheMixins ClausesHas LP :- std.do! [ std.map2 ML TheMixins (m\mi\c\ c = mixin-src TheType m (global (const mi))) MLClauses, + std.map-filter MLClauses mixin-src->has-mixin-instance ClausesHas, MLClauses => std.do! LP ]. diff --git a/HB/instance.elpi b/HB/instance.elpi index c8fe910c8..dc93e45c5 100644 --- a/HB/instance.elpi +++ b/HB/instance.elpi @@ -87,16 +87,18 @@ declare-const Name BodySkel TyWPSkel CSL :- std.do! [ % regular instance %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if (get-option "wrapper" ff ; not(is-subject-lifter TheType _ _)) % regular subject %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - (private.declare-regular-inst TheType ML TheMixins TyWP SectionName CSL) + (private.declare-regular-inst TheType ML TheMixins TyWP SectionName ClausesHas CSL) % wrapper %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - (private.declare-wrapper-inst TheType ML TheMixins TyWP SectionName CSL) + (private.declare-wrapper-inst TheType ML TheMixins TyWP SectionName ClausesHas CSL) , % shared to all branches if (get-option "export" tt) (coq.env.current-library File, - std.map CSL (x\r\ sigma i c\ x = pr i c, r = instance-to-export File i c) Clauses) - (Clauses = []), + std.map CSL (x\r\ sigma i c\ x = pr i c, r = instance-to-export File i c) ClausesExp) + (ClausesExp = []), + + std.append ClausesHas ClausesExp Clauses, ]), % we accumulate clauses now that the section is over @@ -416,13 +418,13 @@ declare-mixins-from-factory Factory T F ML TheMixins :- std.do! [ % [declare-structure-instance-from-mixins T ML MLI] given mixins ML and % their implementation MLI declares all structure instances for T -pred declare-structure-instance-from-mixins i:term, i:list mixinname, i:list constant, o:list (pair id constant). -declare-structure-instance-from-mixins T ML TheMixins CL :- std.do! [ +pred declare-structure-instance-from-mixins i:term, i:list mixinname, i:list constant, o:list prop, o:list (pair id constant). +declare-structure-instance-from-mixins T ML TheMixins ClausesHas CL :- std.do! [ % The order of the following two "under...do!" is crucial, % priority must be given to canonical mixins % as they are the ones which guarantee forgetful inheritance % hence we add these clauses last. - synthesis.under-these-mixin-src.do! T ML TheMixins [ + synthesis.under-these-mixin-src.do! T ML TheMixins ClausesHas [ synthesis.under-local-canonical-mixins-of.do! T [ instance.declare-all T {findall-classes-for ML} CL, ] @@ -436,9 +438,9 @@ close-section-if-has-params _ SectionName :- log.coq.env.end-section-name SectionName. pred declare-regular-inst i:term, i:list mixinname, i:list constant, i:arity, i:id, - o:list (pair id constant). -declare-regular-inst TheType ML TheMixins TyWP SectionName CSL :- std.do![ - private.declare-structure-instance-from-mixins TheType ML TheMixins CCSL, + o:list prop, o:list (pair id constant). +declare-regular-inst TheType ML TheMixins TyWP SectionName ClausesHas CSL :- std.do![ + private.declare-structure-instance-from-mixins TheType ML TheMixins ClausesHas CCSL, % TODO: share between the two cases and put just after declare-mixins-from-factory % since it talks about the unwrapped mixins @@ -450,13 +452,13 @@ declare-regular-inst TheType ML TheMixins TyWP SectionName CSL :- std.do![ ]. pred declare-wrapper-inst i:term, i:list mixinname, i:list constant, i:arity, i:id, - o:list (pair id constant). -declare-wrapper-inst TheType ML TheMixins TyWP SectionName CSL :- std.do![ + o:list prop, o:list (pair id constant). +declare-wrapper-inst TheType ML TheMixins TyWP SectionName ClausesHas CSL :- std.do![ coq.safe-dest-app TheType TheTypeKey _, std.assert! (TheTypeKey = global TheTypeKeyGR) "The subject to be wrapped has no key", private.close-section-if-has-params TyWP SectionName, private.wrap-mixins TheTypeKeyGR ML TheMixins TheNewType WML TheWrappedMixins, - private.declare-structure-instance-from-mixins TheNewType WML TheWrappedMixins CSL, + private.declare-structure-instance-from-mixins TheNewType WML TheWrappedMixins ClausesHas CSL, ]. pred derive-wrapper-instances i:term, i:mixinname, o:term, o:constant. diff --git a/tests/hnf.v b/tests/hnf.v index b219a6a82..c95694848 100644 --- a/tests/hnf.v +++ b/tests/hnf.v @@ -14,5 +14,5 @@ Print HB_unnamed_mixin_8. HB.instance Definition _ := f.Build bool (3 + 2). Print Datatypes_bool__canonical__hnf_S. -Print HB_unnamed_mixin_12. +(* Print HB_unnamed_mixin_12. *) diff --git a/tests/hnf.v.out b/tests/hnf.v.out index b35edbc76..7d6491aa9 100644 --- a/tests/hnf.v.out +++ b/tests/hnf.v.out @@ -5,7 +5,7 @@ HB_unnamed_mixin_8 = {| M.x := f.y nat HB_unnamed_factory_6 + 1 |} : M.axioms_ nat Datatypes_bool__canonical__hnf_S = -{| S.sort := bool; S.class := {| S.hnf_M_mixin := HB_unnamed_mixin_12 |} |} +{| S.sort := bool; S.class := {| S.hnf_M_mixin := hnf_f__to__hnf_M__11 |} |} : S.type HB_unnamed_mixin_12 = Builders_1.HB_unnamed_factory_3 bool HB_unnamed_factory_9 diff --git a/tests/not_same_key.v.out b/tests/not_same_key.v.out index b04461f4c..218208749 100644 --- a/tests/not_same_key.v.out +++ b/tests/not_same_key.v.out @@ -1,2 +1,3 @@ The command has indeed failed with message: -HB: all mixins must have the same key +HB: expecting a factory on T +or a factory on a structure operation or tag. Got: B.phant_axioms T T1 From d7007d3e7e730d294a33b5763d63a3227c1a8a28 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Wed, 18 Oct 2023 18:06:40 +0200 Subject: [PATCH 061/147] added theories/encat.v (formalization of enriched categories, in progress) --- theories/encat.v | 1509 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1509 insertions(+) create mode 100644 theories/encat.v diff --git a/theories/encat.v b/theories/encat.v new file mode 100644 index 000000000..51156a2cd --- /dev/null +++ b/theories/encat.v @@ -0,0 +1,1509 @@ +Require Import ssreflect ssrfun. +From HB Require Import structures. + +Set Implicit Arguments. +Unset Strict Implicit. +Unset Printing Implicit Defensive. +Add Search Blacklist "__canonical__". + +Declare Scope algebra_scope. +Delimit Scope algebra_scope with A. +Local Open Scope algebra_scope. + +Declare Scope cat_scope. +Delimit Scope cat_scope with cat. +Local Open Scope cat_scope. + +(* we assume a few axioms to make life easier *) +Axiom funext : forall {T : Type} {U : T -> Type} [f g : forall t, U t], + (forall t, f t = g t) -> f = g. +Axiom propext : forall P Q : Prop, P <-> Q -> P = Q. +Axiom Prop_irrelevance : forall (P : Prop) (x y : P), x = y. + +(* Shortcut *) +Notation U := Type. + +(* Base definition : raw categories = quivers *) +HB.mixin Record IsQuiver C := { hom : C -> C -> U }. +Unset Universe Checking. +#[short(type="quiver")] +HB.structure Definition Quiver : Set := { C of IsQuiver C }. +Set Universe Checking. + +Bind Scope cat_scope with quiver. +Bind Scope cat_scope with hom. +Arguments hom {C} : rename. +Notation homs T := (@hom T _ _). +Notation "a ~> b" := (hom a b) + (at level 99, b at level 200, format "a ~> b") : cat_scope. +Notation "a ~>_ C b" := (@hom C a b) + (at level 99, C at level 0, only parsing) : cat_scope. + +(* precategories are quivers + id and comp *) +HB.mixin Record Quiver_IsPreCat C of Quiver C := { + idmap : forall (a : C), a ~> a; + comp : forall (a b c : C), (a ~> b) -> (b ~> c) -> (a ~> c); +}. + +HB.factory Record IsPreCat C := { + hom : C -> C -> U; + idmap : forall (a : C), hom a a; + comp : forall (a b c : C), hom a b -> hom b c -> hom a c; +}. +HB.builders Context C of IsPreCat C. + HB.instance Definition _ := IsQuiver.Build C hom. + HB.instance Definition _ := Quiver_IsPreCat.Build C idmap comp. +HB.end. + +Unset Universe Checking. +#[short(type="precat")] +HB.structure Definition PreCat : Set := { C of IsPreCat C }. +Set Universe Checking. + +Bind Scope cat_scope with precat. +Arguments idmap {C} {a} : rename. +Arguments comp {C} {a b c} : rename. +Notation "f \o g" := (comp g f) : cat_scope. +Notation "f \; g :> T" := (@comp T _ _ _ f g) + (at level 60, g, T at level 60, format "f \; g :> T", only parsing) : cat_scope. +Notation "f \; g" := (comp f g) : cat_scope. +Notation "\idmap_ a" := (@idmap _ a) (only parsing, at level 0) : cat_scope. + +(* categories are precategories + laws *) +HB.mixin Record PreCat_IsCat C of PreCat C := { + comp1o : forall (a b : C) (f : a ~> b), idmap \; f = f; + compo1 : forall (a b : C) (f : a ~> b), f \; idmap = f; + compoA : forall (a b c d : C) (f : a ~> b) (g : b ~> c) (h : c ~> d), + f \; (g \; h) = (f \; g) \; h +}. +Unset Universe Checking. +#[short(type="cat")] +HB.structure Definition Cat : Set := { C of PreCat_IsCat C & IsPreCat C }. +Set Universe Checking. + +Bind Scope cat_scope with cat. +Arguments compo1 {C a b} : rename. +Arguments comp1o {C a b} : rename. +Arguments compoA {C a b c d} : rename. + +(* the discrete category on a type cannot be the default, we make an alias *) +Definition discrete (T : U) := T. +HB.instance Definition _ T := @IsPreCat.Build (discrete T) (fun x y => x = y) + (fun=> erefl) (@etrans _). +Lemma etransA T (a b c d : discrete T) (f : a ~> b) (g : b ~> c) (h : c ~> d) : + f \; (g \; h) = (f \; g) \; h. +Proof. by rewrite /idmap/comp/=; case: _ / h; case: _ / g. Qed. +HB.instance Definition _ T := PreCat_IsCat.Build (discrete T) (@etrans_id _) + (fun _ _ _ => erefl) (@etransA _). + +(* the category of the unit type is the discrete one *) +HB.instance Definition _ := Cat.copy unit (discrete unit). + +HB.instance Definition _ := @IsPreCat.Build U (fun A B => A -> B) + (fun a => idfun) (fun a b c (f : a -> b) (g : b -> c) => (g \o f)%FUN). +HB.instance Definition _ := PreCat_IsCat.Build U (fun _ _ _ => erefl) + (fun _ _ _ => erefl) (fun _ _ _ _ _ _ _ => erefl). + + +Lemma Ucomp (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) : f \; g = (g \o f)%FUN. +Proof. by []. Qed. +Lemma Ucompx (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) x : (f \; g) x = g (f x). +Proof. by []. Qed. +Lemma U1 (X : U) : \idmap_X = idfun. +Proof. by []. Qed. +Lemma U1x (X : U) x : \idmap_X x = x. +Proof. by []. Qed. + +(* a prefunctor is a functor without laws *) +HB.mixin Record IsPreFunctor (C D : quiver) (F : C -> D) := { + Fhom : forall (a b : C), (a ~> b) -> (F a ~> F b) +}. + +Unset Universe Checking. +HB.structure Definition PreFunctor (C D : quiver) : Set := + { F of IsPreFunctor C D F }. +Set Universe Checking. +HB.instance Definition _ := IsQuiver.Build quiver PreFunctor.type. + +Notation "F ^$" := (@Fhom _ _ F _ _) + (at level 1, format "F ^$") : cat_scope. +Notation "F <$> f" := (@Fhom _ _ F _ _ f) + (at level 58, format "F <$> f", right associativity) : cat_scope. + +(* prefunctors are equal if their object and hom part are respectively equal *) +Lemma prefunctorP (C D : quiver) (F G : C ~> D) (eqFG : F =1 G) : + let homF a b F := F a ~> F b in + (forall a b f, eq_rect _ (homF a b) (F <$> f) _ (funext eqFG) = G <$> f) -> + F = G. +Proof. +move: F G => [F [[/= Fhom]]] [G [[/= Ghom]]] in eqFG *. +case: _ / (funext eqFG) => /= in Ghom * => eqFGhom. +congr PreFunctor.Pack; congr PreFunctor.Class; congr IsPreFunctor.Axioms_. +by do 3!apply: funext=> ?. +Qed. + +(* a functor is a prefunctor + laws for id and comp *) +HB.mixin Record PreFunctor_IsFunctor (C D : precat) (F : C -> D) + of @PreFunctor C D F := { + F1 : forall (a : C), F <$> \idmap_a = idmap; + Fcomp : forall (a b c : C) (f : a ~> b) (g : b ~> c), + F <$> (f \; g) = F <$> f \; F <$> g; +}. +Unset Universe Checking. + +(* precat and cat have a quiver structure *) +HB.structure Definition Functor (C D : precat) : Set := + { F of IsPreFunctor C D F & PreFunctor_IsFunctor C D F }. +Set Universe Checking. +HB.instance Definition _ := IsQuiver.Build precat Functor.type. +HB.instance Definition _ := IsQuiver.Build cat Functor.type. + +(* functor equality is the same as prefunctor because of PI *) +Lemma functorP (C D : precat) (F G : C ~> D) (eqFG : F =1 G) : + let homF a b F := F a ~> F b in + (forall a b f, eq_rect _ (homF a b) (F^$ f) _ (funext eqFG) = G^$ f) -> + F = G. +Proof. +move=> /= /prefunctorP {eqFG}. +case: F G => [F [/= Fm Fm']] [G [/= Gm Gm']]//=. +move=> [_] /EqdepFacts.eq_sigT_iff_eq_dep eqFG. +case: _ / eqFG in Gm' *. +congr Functor.Pack; congr Functor.Class. +case: Fm' Gm' => [F1 Fc] [G1 Gc]. +by congr PreFunctor_IsFunctor.Axioms_; apply: Prop_irrelevance. +Qed. + +(* the identity function is a functor *) +HB.instance Definition _ (C : quiver) := + IsPreFunctor.Build C C idfun (fun a b => idfun). +HB.instance Definition _ (C : precat) := + PreFunctor_IsFunctor.Build C C idfun (fun=> erefl) (fun _ _ _ _ _ => erefl). + +(* the composition of prefunctors *) +Section comp_prefunctor. +Context {C D E : quiver} {F : C ~> D} {G : D ~> E}. + +HB.instance Definition _ := IsPreFunctor.Build C E (G \o F)%FUN + (fun a b f => G <$> F <$> f). +Lemma comp_Fun (a b : C) (f : a ~> b) : (G \o F)%FUN <$> f = G <$> (F <$> f). +Proof. by []. Qed. +End comp_prefunctor. + +Section comp_functor. +Context {C D E : precat} {F : C ~> D} {G : D ~> E}. +Lemma comp_F1 (a : C) : (G \o F)%FUN <$> \idmap_a = idmap. +Proof. by rewrite !comp_Fun !F1. Qed. +Lemma comp_Fcomp (a b c : C) (f : a ~> b) (g : b ~> c) : + (G \o F)%FUN <$> (f \; g) = (G \o F)%FUN <$> f \; (G \o F)%FUN <$> g. +Proof. by rewrite !comp_Fun !Fcomp. Qed. +HB.instance Definition _ := PreFunctor_IsFunctor.Build C E (G \o F)%FUN + comp_F1 comp_Fcomp. +End comp_functor. + +(* precat and cat have a precategory structure *) +HB.instance Definition _ := Quiver_IsPreCat.Build precat + (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). +HB.instance Definition _ := Quiver_IsPreCat.Build cat + (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). + +Lemma funext_frefl A B (f : A -> B) : funext (frefl f) = erefl. +Proof. exact: Prop_irrelevance. Qed. + +(* precategories and categories form a category *) +Definition precat_cat : PreCat_IsCat precat. +Proof. +by split=> [C D F|C D F|C D C' D' F G H]; + apply/functorP => a b f /=; rewrite funext_frefl. +Qed. +HB.instance Definition _ := precat_cat. +Definition cat_cat : PreCat_IsCat cat. +Proof. +by split=> [C D F|C D F|C D C' D' F G H]; + apply/functorP => a b f /=; rewrite funext_frefl. +Qed. +HB.instance Definition _ := cat_cat. + +Check (cat : cat). + +(* concrete categories *) +HB.mixin Record Quiver_IsPreConcrete T of Quiver T := { + concrete : T -> U; + concrete_fun : forall (a b : T), (a ~> b) -> concrete a -> concrete b; +}. +Unset Universe Checking. +#[short(type="preconcrete_quiver")] +HB.structure Definition PreConcreteQuiver : Set := + { C of Quiver_IsPreConcrete C & IsQuiver C }. +Set Universe Checking. +Coercion concrete : PreConcreteQuiver.sort >-> Sortclass. + +HB.mixin Record PreConcrete_IsConcrete T of PreConcreteQuiver T := { + concrete_fun_inj : forall (a b : T), injective (concrete_fun a b) +}. +Unset Universe Checking. +#[short(type="concrete_quiver")] +HB.structure Definition ConcreteQuiver : Set := + { C of PreConcreteQuiver C & PreConcrete_IsConcrete C }. +Set Universe Checking. + +HB.instance Definition _ (C : ConcreteQuiver.type) := + IsPreFunctor.Build _ _ (concrete : C -> U) concrete_fun. + +HB.mixin Record PreCat_IsConcrete T of ConcreteQuiver T & PreCat T := { + concrete1 : forall (a : T), concrete <$> \idmap_a = idfun; + concrete_comp : forall (a b c : T) (f : a ~> b) (g : b ~> c), + concrete <$> (f \; g) = ((concrete <$> g) \o (concrete <$> f))%FUN; +}. +Unset Universe Checking. +#[short(type="concrete_precat")] +HB.structure Definition ConcretePreCat : Set := + { C of PreCat C & ConcreteQuiver C & PreCat_IsConcrete C }. +#[short(type="concrete_cat")] +HB.structure Definition ConcreteCat : Set := + { C of Cat C & ConcreteQuiver C & PreCat_IsConcrete C }. +Set Universe Checking. + +HB.instance Definition _ (C : concrete_precat) := + PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). +HB.instance Definition _ (C : ConcreteCat.type) := + PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). + +HB.instance Definition _ := Quiver_IsPreConcrete.Build U (fun _ _ => id). +HB.instance Definition _ := PreConcrete_IsConcrete.Build U (fun _ _ _ _ => id). +HB.instance Definition _ := PreCat_IsConcrete.Build U + (fun=> erefl) (fun _ _ _ _ _ => erefl). + +Unset Universe Checking. +HB.instance Definition _ := Quiver_IsPreConcrete.Build quiver (fun _ _ => id). +HB.instance Definition _ := Quiver_IsPreConcrete.Build precat (fun _ _ => id). +HB.instance Definition _ := Quiver_IsPreConcrete.Build cat (fun _ _ => id). +Lemma quiver_concrete_subproof : PreConcrete_IsConcrete quiver. +Proof. +constructor=> C D F G FG; apply: prefunctorP. + by move=> x; congr (_ x); apply: FG. +by move=> *; apply: Prop_irrelevance. +Qed. +HB.instance Definition _ := quiver_concrete_subproof. + +Lemma precat_concrete_subproof : PreConcrete_IsConcrete precat. +Proof. +constructor=> C D F G FG; apply: functorP. + by move=> x; congr (_ x); apply: FG. +by move=> *; apply: Prop_irrelevance. +Qed. +HB.instance Definition _ := precat_concrete_subproof. + +Lemma cat_concrete_subproof : PreConcrete_IsConcrete cat. +Proof. +constructor=> C D F G FG; apply: functorP. + by move=> x; congr (_ x); apply: FG. +by move=> *; apply: Prop_irrelevance. +Qed. +HB.instance Definition _ := cat_concrete_subproof. +HB.instance Definition _ := PreCat_IsConcrete.Build precat + (fun=> erefl) (fun _ _ _ _ _ => erefl). +HB.instance Definition _ := PreCat_IsConcrete.Build cat + (fun=> erefl) (fun _ _ _ _ _ => erefl). +Set Universe Checking. + +(* constant functor *) +Definition cst (C D : quiver) (c : C) := fun of D => c. +Arguments cst {C} D c. +HB.instance Definition _ {C D : precat} (c : C) := + IsPreFunctor.Build D C (cst D c) (fun _ _ _ => idmap). +HB.instance Definition _ {C D : cat} (c : C) := + PreFunctor_IsFunctor.Build D C (cst D c) (fun=> erefl) + (fun _ _ _ _ _ => esym (compo1 idmap)). + +(* opposite category *) +Definition catop (C : U) : U := C. +Notation "C ^op" := (catop C) + (at level 2, format "C ^op") : cat_scope. +HB.instance Definition _ (C : quiver) := + IsQuiver.Build C^op (fun a b => hom b a). +HB.instance Definition _ (C : precat) := + Quiver_IsPreCat.Build (C^op) (fun=> idmap) (fun _ _ _ f g => g \; f). +HB.instance Definition _ (C : cat) := PreCat_IsCat.Build (C^op) + (fun _ _ _ => compo1 _) (fun _ _ _ => comp1o _) + (fun _ _ _ _ _ _ _ => esym (compoA _ _ _)). + +HB.instance Definition _ {C : precat} {c : C} := + IsPreFunctor.Build C _ (hom c) (fun a b f g => g \; f). +Lemma hom_Fhom_subproof (C : cat) (x : C) : + PreFunctor_IsFunctor _ _ (hom x). +Proof. by split=> *; apply/funext => h; [apply: compo1 | apply: compoA]. Qed. +HB.instance Definition _ {C : cat} {c : C} := hom_Fhom_subproof c. + +Check fun (C : cat) (x : C) => hom x : C ~>_cat U. + +Lemma hom_op {C : quiver} (c : C^op) : hom c = (@hom C)^~ c. +Proof. reflexivity. Qed. + +Lemma homFhomx {C : precat} (a b c : C) (f : a ~> b) (g : c ~> a) : + (hom c <$> f) g = g \; f. +Proof. reflexivity. Qed. + +(* nary product of categories *) +Definition dprod {I : U} (C : I -> U) := forall i, C i. + +Section hom_dprod. +Context {I : U} (C : I -> quiver). +Definition dprod_hom_subdef (a b : dprod C) := forall i, a i ~> b i. +HB.instance Definition _ := IsQuiver.Build (dprod C) dprod_hom_subdef. +End hom_dprod. +Arguments dprod_hom_subdef /. + +Section precat_dprod. +Context {I : U} (C : I -> precat). +Definition dprod_idmap_subdef (a : dprod C) : a ~> a := fun=> idmap. +Definition dprod_comp_subdef (a b c : dprod C) (f : a ~> b) (g : b ~> c) : a ~> c := + fun i => f i \; g i. +HB.instance Definition _ := IsPreCat.Build (dprod C) + dprod_idmap_subdef dprod_comp_subdef. +End precat_dprod. +Arguments dprod_idmap_subdef /. +Arguments dprod_comp_subdef /. + +Section cat_dprod. +Context {I : U} (C : I -> cat). +Local Notation type := (dprod C). +Lemma dprod_is_cat : PreCat_IsCat type. +Proof. +split=> [a b f|a b f|a b c d f g h]; apply/funext => i; +[exact: comp1o | exact: compo1 | exact: compoA]. +Qed. +HB.instance Definition _ := dprod_is_cat. +End cat_dprod. + +(* binary product *) +Section hom_prod. +Context {C D : quiver}. +Definition prod_hom_subdef (a b : C * D) := ((a.1 ~> b.1) * (a.2 ~> b.2))%type. +HB.instance Definition _ := IsQuiver.Build (C * D)%type prod_hom_subdef. +End hom_prod. + +Section precat_prod. +Context {C D : precat}. +HB.instance Definition _ := IsPreCat.Build (C * D)%type (fun=> (idmap, idmap)) + (fun a b c (f : a ~> b) (g : b ~> c) => (f.1 \; g.1, f.2 \; g.2)). +End precat_prod. + +Section cat_prod. +Context {C D : cat}. +Local Notation type := (C * D)%type. +Lemma prod_is_cat : PreCat_IsCat type. +Proof. +split=> [[a1 a2] [b1 b2] [f1 f2]|[a1 a2] [b1 b2] [f1 f2]| + [a1 a2] [b1 b2] [c1 c2] [d1 d2] [f1 f2] [g1 g2] [h1 h2]]; congr (_, _) => //=; +by [exact: comp1o | exact: compo1 | exact: compoA]. +Qed. +HB.instance Definition _ := prod_is_cat. +End cat_prod. + +(* naturality *) +HB.mixin Record IsNatural (C D : precat) (F G : C ~>_quiver D) + (n : forall c, F c ~> G c) := { + natural : forall (a b : C) (f : a ~> b), + F <$> f \; n b = n a \; G <$> f +}. +Unset Universe Checking. +HB.structure Definition Natural (C D : precat) + (F G : C ~>_quiver D) : Set := + { n of @IsNatural C D F G n }. +Set Universe Checking. +HB.instance Definition _ (C D : precat) := + IsQuiver.Build (PreFunctor.type C D) (@Natural.type C D). +HB.instance Definition _ (C D : cat) := + IsQuiver.Build (Functor.type C D) (@Natural.type C D). +Arguments natural {C D F G} n [a b] f : rename. + +Check fun (C D : cat) (F G : C ~> D) => F ~>_(C ~>_cat D) G. + +Lemma naturalx (C : precat) (D : concrete_precat) + (F G : C ~>_quiver D) (n : F ~> G) (a b : C) (f : a ~> b) g : + (concrete <$> n b) ((concrete <$> F <$> f) g) = + (concrete <$> G <$> f) ((concrete <$> n a) g). +Proof. +have /(congr1 (fun h => (concrete <$> h) g)) := natural n f. +by rewrite !Fcomp. +Qed. +Arguments naturalx {C D F G} n [a b] f. + +Lemma naturalU (C : precat) (F G : C ~>_quiver U) (n : F ~> G) + (a b : C) (f : a ~> b) g : n b (F^$ f g) = G^$ f (n a g). +Proof. exact: (naturalx n). Qed. + +Lemma natP (C D : precat) (F G : C ~>_quiver D) (n m : F ~> G) : + Natural.sort n = Natural.sort m -> n = m. +Proof. +case: n m => [/= n nP] [/= m mP] enm. +elim: _ / enm in mP *; congr Natural.Pack. +case: nP mP => [[?]] [[?]]; congr Natural.Class. +congr IsNatural.Axioms_. +exact: Prop_irrelevance. +Qed. + +Notation "F ~~> G" := (F ~>_(homs quiver) G) + (at level 99, G at level 200, format "F ~~> G"). +Notation "F ~~> G :> C ~> D" := (F ~> G :> (C ~>_quiver D)) + (at level 99, G at level 200, C, D at level 0, + format "F ~~> G :> C ~> D"). + +Definition natural_id {C D : precat} (F : C ~>_quiver D) (a : C) := \idmap_(F a). +Definition natural_id_natural (C D : cat) (F : C ~>_quiver D) : + IsNatural C D F F (natural_id F). +Proof. by constructor=> a b f; rewrite /natural_id/= compo1 comp1o. Qed. +HB.instance Definition _ C D F := @natural_id_natural C D F. + +Check fun {C D : cat} (F : C ~>_quiver D) => natural_id F : F ~> F. + +Definition natural_comp {C D : precat} (F G H : C ~>_quiver D) + (m : F ~> G) (n : G ~> H) (a : C) := m a \; n a. +Definition natural_comp_natural (C D : cat) (F G H : C ~>_quiver D) m n : + IsNatural C D F H (@natural_comp C D F G H m n). +Proof. +constructor=> a b f; rewrite /natural_comp/=. +by rewrite compoA natural -compoA natural compoA. +Qed. +HB.instance Definition _ C D F G H m n := @natural_comp_natural C D F G H m n. + +HB.instance Definition _ {C D : cat} := + Quiver_IsPreCat.Build (PreFunctor.type C D) natural_id natural_comp. +HB.instance Definition _ {C D : cat} := + Quiver_IsPreCat.Build (Functor.type C D) natural_id natural_comp. + +Lemma prefunctor_cat {C D : cat} : PreCat_IsCat (PreFunctor.type C D). +Proof. +constructor => [F G f|F G f|F G H J f g h]. +- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. +- by apply/natP/funext => a; rewrite /= /natural_comp compo1. +- by apply/natP/funext => a; rewrite /= /natural_comp compoA. +Qed. +HB.instance Definition _ C D := @prefunctor_cat C D. + +Lemma functor_cat {C D : cat} : PreCat_IsCat (Functor.type C D). +Proof. +constructor => [F G f|F G f|F G H J f g h]. +- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. +- by apply/natP/funext => a; rewrite /= /natural_comp compo1. +- by apply/natP/funext => a; rewrite /= /natural_comp compoA. +Qed. +HB.instance Definition _ C D := @functor_cat C D. + +Section nat_map_left. +Context {C D E : precat} {F G : C ~> D}. + +Definition nat_lmap (H : D ~>_quiver E) (n : forall c, F c ~> G c) : + forall c, (H \o F)%FUN c ~> (H \o G)%FUN c := fun c => H <$> n c. + +Fail Check fun (H : D ~> E) (n : F ~~> G) => nat_lmap H n : H \o F ~~> H \o G. + +Lemma nat_lmap_is_natural (H : D ~> E) (n : F ~~> G) : + IsNatural C E (H \o F) (H \o G) (nat_lmap H n). +Proof. by constructor=> a b f; rewrite /nat_lmap/= -!Fcomp natural. Qed. +HB.instance Definition _ H n := nat_lmap_is_natural H n. + +Check fun (H : D ~> E) (n : F ~~> G) => nat_lmap H n : H \o F ~~> H \o G. + +End nat_map_left. + +Notation "F n" := (nat_lmap F n) + (at level 58, format "F n", right associativity) : cat_scope. + +Section nat_map_right. +Context {C D E : precat} {F G : C ~> D}. + +Definition nat_rmap (H : E -> C) (n : forall c, F c ~> G c) : + forall c, (F \o H)%FUN c ~> (G \o H)%FUN c := fun c => n (H c). +Lemma nat_rmap_is_natural (H : E ~> C :> quiver) (n : F ~~> G) : + IsNatural E D (F \o H)%FUN (G \o H)%FUN (nat_rmap H n). +Proof. by constructor=> a b f; rewrite /nat_lmap/= natural. Qed. +HB.instance Definition _ H n := nat_rmap_is_natural H n. + +End nat_map_right. + +Notation "F <$o> n" := (nat_rmap F n) + (at level 58, format "F <$o> n", right associativity) : cat_scope. + +Definition delta (C D : cat) : C -> (D ~> C) := cst D. +Arguments delta C D : clear implicits. + +Definition map_delta {C D : cat} (a b : C) (f : a ~> b) : + delta C D a ~> delta C D b. +Proof. +apply: (@Natural.Pack _ _ (cst D a) (cst D b) (fun x => f)). +apply: Natural.Class; apply: (IsNatural.Build _ _ _ _ _). +by move=> a' b' ?; rewrite compo1 comp1o. +Defined. + +HB.instance Definition _ {C D : cat} := + IsPreFunctor.Build C (D ~> C) (delta C D) (@map_delta C D). + +Lemma delta_functor {C D : cat} : PreFunctor_IsFunctor _ _ (delta C D). +Proof. by constructor=> [a|a b c f g]; exact/natP. Qed. +HB.instance Definition _ C D := @delta_functor C D. + +HB.mixin Record IsMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { + unit : idfun ~~> M; + join : (M \o M)%FUN ~~> M; + bind : forall (a b : C), (a ~> M b) -> (M a ~> M b); + bindE : forall a b (f : a ~> M b), bind a b f = M <$> f \; join b; + unit_join : forall a, (M <$> unit a) \; join _ = idmap; + join_unit : forall a, join _ \; (M <$> unit a) = idmap; + join_square : forall a, M <$> join a \; join _ = join _ \; join _ +}. + +#[short(type="premonad")] +HB.structure Definition PreMonad (C : precat) := + {M of @PreFunctor C C M & IsMonad C M}. +#[short(type="monad")] +HB.structure Definition Monad (C : precat) := + {M of @Functor C C M & IsMonad C M}. + +HB.factory Record IsJoinMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { + unit : idfun ~~> M; + join : (M \o M)%FUN ~~> M; + unit_join : forall a, (M <$> unit a) \; join _ = idmap; + join_unit : forall a, join _ \; (M <$> unit a) = idmap; + join_square : forall a, M <$> join a \; join _ = join _ \; join _ +}. +HB.builders Context C M of IsJoinMonad C M. + HB.instance Definition _ := IsMonad.Build C M + (fun a b f => erefl) unit_join join_unit join_square. +HB.end. + +HB.mixin Record IsCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { + counit : M ~~> idfun; + cojoin : M ~~> (M \o M)%FUN; + cobind : forall (a b : C), (M a ~> b) -> (M a ~> M b); + cobindE : forall a b (f : M a ~> b), cobind a b f = cojoin _ \; M <$> f; + unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; + join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; + cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ +}. +#[short(type="precomonad")] +HB.structure Definition PreCoMonad (C : precat) := + {M of @PreFunctor C C M & IsCoMonad C M}. +#[short(type="comonad")] +HB.structure Definition CoMonad (C : precat) := + {M of @Functor C C M & IsCoMonad C M}. + +HB.factory Record IsJoinCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { + counit : M ~~> idfun; + cojoin : M ~~> (M \o M)%FUN; + unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; + join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; + cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ +}. +HB.builders Context C M of IsJoinCoMonad C M. + HB.instance Definition _ := IsCoMonad.Build C M + (fun a b f => erefl) unit_cojoin join_counit cojoin_square. +HB.end. + +Lemma idFmap (C : cat) (a b : C) (f : a ~> b) : idfun <$> f = f. +Proof. by []. Qed. + +Lemma compFmap (C D E : cat) (F : C ~> D) (G : D ~> E) (a b : C) (f : a ~> b) : + (G \o F) <$> f = G <$> F <$> f. +Proof. by []. Qed. + +(* yoneda *) +Section hom_repr. +Context {C : cat} (F : C ~>_cat U). + +Definition homF : C -> U := fun c => hom c ~~> F. + +Section nat. +Context (x y : C) (xy : x ~> y). + +(* Goal hom x ~~> F -> hom y ~~> F *) +Context (n : hom x ~~> F). +Definition homFhom c : hom y c ~> F c := fun g => n _ (xy \; g). + +Lemma homFhom_natural_subdef : IsNatural C U (hom y) F homFhom. +Proof. +by split=> a b f /=; apply/funext => g /=; + rewrite /homFhom !Ucompx/= !naturalU/= Fcomp. +Qed. +HB.instance Definition _ := homFhom_natural_subdef. +End nat. +Arguments homFhom / : clear implicits. + +HB.about IsPreFunctor.Build. +Check homFhom : forall x y : C, (x ~> y) -> (homF x -> homF y). +HB.instance Definition _ := IsPreFunctor.Build _ _ homF homFhom. +Lemma homF_functor_subproof : PreFunctor_IsFunctor _ _ homF. +Proof. +split=> [a|a b c f g]. + apply/funext => -[/= f natf]. + apply: natP => //=; apply: funext => b; apply: funext => g/=. + by rewrite comp1o. +apply/funext => -[/= h natf]. +apply: natP => //=; apply: funext => d; apply: funext => k/=. +by rewrite compoA. +Qed. +HB.instance Definition _ := homF_functor_subproof. + +Section pointed. +Context (c : C). +Definition hom_repr : homF c ~> F c := fun f => f _ idmap. +Arguments hom_repr /. + +Definition repr_hom (fc : F c) a : hom c a ~> F a := + fun f => F^$ f fc. +Arguments repr_hom / : clear implicits. +Lemma repr_hom_subdef (fc : F c) : IsNatural _ _ _ _ (repr_hom fc). +Proof. by split=> a b f /=; apply/funext=> x; rewrite !Ucompx/= Fcomp. Qed. +HB.instance Definition _ {fc : F c} := repr_hom_subdef fc. + +Definition repr_hom_nat : F c ~> homF c := repr_hom. + +Lemma hom_reprK : cancel hom_repr repr_hom_nat. +Proof. +move=> f; apply/natP; apply/funext => a; apply/funext => g /=. +by rewrite -naturalU/=; congr (f _ _); apply: comp1o. +Qed. +Lemma repr_homK : cancel (repr_hom : F c ~> homF c) hom_repr. +Proof. by move=> fc; rewrite /= F1. Qed. +End pointed. +Arguments hom_repr /. +Arguments repr_hom /. + +Lemma hom_repr_natural_subproof : IsNatural _ _ _ _ hom_repr. +Proof. +split=> a b f /=; apply/funext => n /=; rewrite !Ucompx/= compo1/=. +by rewrite -naturalU/=; congr (n _ _); apply/esym/comp1o. +Qed. +HB.instance Definition _ := hom_repr_natural_subproof. + +(* show this from the previous proof *) +Lemma hom_natural_repr_subproof : IsNatural _ _ _ _ repr_hom_nat. +Proof. +split=> a b f /=; apply: funext => fa /=; rewrite !Ucompx/=. +apply: natP; apply: funext => c /=; apply: funext => d /=. +by rewrite Fcomp Ucompx/=. +Qed. +HB.instance Definition _ := hom_natural_repr_subproof. + +Definition hom_repr_nat : homF ~~> F := hom_repr. +Definition repr_hom_nat_nat : F ~~> homF := repr_hom_nat. + +End hom_repr. + +(* comma categories *) +Module comma. +Section homcomma. +Context {C D E : precat} (F : C ~> E) (G : D ~> E). + +Definition type := { x : C * D & F x.1 ~> G x.2 }. +Definition hom_subdef (a b : type) := { + f : tag a ~> tag b & F <$> f.1 \; tagged b = tagged a \; G <$> f.2 + }. +HB.instance Definition _ := IsQuiver.Build type hom_subdef. +End homcomma. +Arguments hom_subdef /. +Section comma. +Context {C D E : cat} (F : C ~> E) (G : D ~> E). +Notation type := (type F G). + +Program Definition idmap_subdef (a : type) : a ~> a := @Tagged _ idmap _ _. +Next Obligation. by rewrite !F1 comp1o compo1. Qed. +Program Definition comp_subdef (a b c : type) + (f : a ~> b) (g : b ~> c) : a ~> c := + @Tagged _ (tag f \; tag g) _ _. +Next Obligation. by rewrite !Fcomp -compoA (tagged g) compoA (tagged f) compoA. Qed. +HB.instance Definition _ := IsPreCat.Build type idmap_subdef comp_subdef. +Arguments idmap_subdef /. +Arguments comp_subdef /. + +Lemma comma_homeqP (a b : type) (f g : a ~> b) : projT1 f = projT1 g -> f = g. +Proof. +case: f g => [f fP] [g +]/= eqfg; case: _ / eqfg => gP. +by congr existT; apply: Prop_irrelevance. +Qed. + +Lemma comma_is_cat : PreCat_IsCat type. +Proof. +by split=> [[a fa] [b fb] [*]|[a fa] [b fb] [*]|*]; + apply/comma_homeqP; rewrite /= ?(comp1o, compo1, compoA). +Qed. +HB.instance Definition _ := comma_is_cat. +End comma. +End comma. +Notation "F `/` G" := (@comma.type _ _ _ F G) + (at level 40, G at level 40, format "F `/` G") : cat_scope. +Notation "a /` G" := (cst unit a `/` G) + (at level 40, G at level 40, format "a /` G") : cat_scope. +Notation "F `/ b" := (F `/` cst unit b) + (at level 40, b at level 40, format "F `/ b") : cat_scope. +Notation "a / b" := (cst unit a `/ b) : cat_scope. + +Definition obj (C : quiver) : Type := C. +HB.mixin Record IsInitial {C : quiver} (i : obj C) := { + to : forall c, i ~> c; + to_unique : forall c (f : i ~> c), f = to c +}. +#[short(type="initial")] +HB.structure Definition Initial {C : quiver} := {i of IsInitial C i}. + +HB.mixin Record IsTerminal {C : quiver} (t : obj C) := { + from : forall c, c ~> t; + from_unique : forall c (f : c ~> t), f = from c +}. +#[short(type="terminal")] +HB.structure Definition Terminal {C : quiver} := {t of IsTerminal C t}. +#[short(type="universal")] +HB.structure Definition Universal {C : quiver} := + {u of Initial C u & Terminal C u}. + +(* Definition hom' {C : precat} (a b : C) := a ~> b. *) +(* (* Bug *) *) +(* Identity Coercion hom'_hom : hom' >-> hom. *) + +(* HB.mixin Record IsMono {C : precat} (b c : C) (f : hom b c) := { *) +(* monoP : forall (a : C) (g1 g2 : a ~> b), g1 \; f = g2 \; f -> g1 = g2 *) +(* }. *) +(* #[short(type="mono")] *) +(* HB.structure Definition Mono {C : precat} (a b : C) := {m of IsMono C a b m}. *) +(* Notation "a >~> b" := (mono a b) *) +(* (at level 99, b at level 200, format "a >~> b") : cat_scope. *) +(* Notation "C >~>_ T D" := (@mono T C D) *) +(* (at level 99, T at level 0, only parsing) : cat_scope. *) + +(* HB.mixin Record IsEpi {C : precat} (a b : C) (f : hom a b) := { *) +(* epiP : forall (c : C) (g1 g2 : b ~> c), g1 \o f = g2 \o f -> g1 = g2 *) +(* }. *) +(* #[short(type="epi")] *) +(* HB.structure Definition Epi {C : precat} (a b : C) := {e of IsEpi C a b e}. *) +(* Notation "a ~>> b" := (epi a b) *) +(* (at level 99, b at level 200, format "a ~>> b") : cat_scope. *) +(* Notation "C ~>>_ T D" := (@epi T C D) *) +(* (at level 99, T at level 0, only parsing) : cat_scope. *) + +(* #[short(type="iso")] *) +(* HB.structure Definition Iso {C : precat} (a b : C) := *) +(* {i of @Mono C a b i & @Epi C a b i}. *) +(* Notation "a <~> b" := (epi a b) *) +(* (at level 99, b at level 200, format "a <~> b") : cat_scope. *) +(* Notation "C <~>_ T D" := (@epi T C D) *) +(* (at level 99, T at level 0, only parsing) : cat_scope. *) + +HB.mixin Record IsRightAdjoint (D C : precat) (R : D -> C) + of @PreFunctor D C R := { + L_ : C ~> D; + phi : forall c d, (L_ c ~> d) -> (c ~> R d); + psy : forall c d, (c ~> R d) -> (L_ c ~> d); + phi_psy c d : (phi c d \o psy c d)%FUN = @id (c ~> R d); + psy_phi c d : (psy c d \o phi c d)%FUN = @id (L_ c ~> d) +}. +#[short(type="right_adjoint")] +HB.structure Definition RightAdjoint (D C : precat) := + { R of @Functor D C R & IsRightAdjoint D C R }. +Arguments L_ {_ _}. +Arguments phi {D C s} {c d}. +Arguments psy {D C s} {c d}. + + +HB.mixin Record PreCat_IsMonoidal C of PreCat C := { + onec : C; + (* prod1 : @hom precat (C * C)%type C ; *) + prod : (C * C)%type ~>_precat C; +}. +#[short(type="premonoidal")] +#[verbose] +HB.structure Definition PreMonoidal := { C of PreCat C & PreCat_IsMonoidal C }. +Notation premonoidal := premonoidal. +Arguments prod {C} : rename. +Notation "a * b" := (prod (a, b)) : cat_scope. +Reserved Notation "f <*> g" (at level 40, g at level 40, format "f <*> g"). +Notation "f <*> g" := (prod^$ (f, g)) (only printing) : cat_scope. +Notation "f <*> g" := (prod^$ ((f, g) : (_, _) ~> (_, _))) + (only parsing) : cat_scope. +Notation "1" := onec : cat_scope. + +Definition hom_cast {C : quiver} {a a' : C} (eqa : a = a') {b b' : C} (eqb : b = b') : + (a ~> b) -> (a' ~> b'). +Proof. now elim: _ / eqa; elim: _ / eqb. Defined. + +HB.mixin Record PreFunctor_IsMonoidal (C D : premonoidal) F of + @PreFunctor C D F := { + fun_one : F 1 = 1; + fun_prod : forall (x y : C), F (x * y) = F x * F y; +}. +#[short(type="monoidal_prefunctor")] +HB.structure Definition MonoidalPreFunctor C D := + { F of @PreFunctor_IsMonoidal C D F }. +Arguments fun_prod {C D F x y} : rename. +(* Arguments fun_prodF {C D F x x'} f {y y'} g : rename. *) +Unset Universe Checking. +HB.instance Definition _ := IsQuiver.Build premonoidal MonoidalPreFunctor.type. +Set Universe Checking. + +HB.instance Definition _ (C : quiver) := + IsPreFunctor.Build (C * C)%type C fst + (fun (a b : C * C) (f : a ~> b) => f.1). +HB.instance Definition _ (C : quiver) := + IsPreFunctor.Build (C * C)%type C snd + (fun (a b : C * C) (f : a ~> b) => f.2). + +Definition prod3l {C : premonoidal} (x : C * C * C) : C := + (x.1.1 * x.1.2) * x.2. +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build _ C prod3l + (fun a b (f : a ~> b) => (f.1.1 <*> f.1.2) <*> f.2). + +Definition prod3r {C : premonoidal} (x : C * C * C) : C := + x.1.1 * (x.1.2 * x.2). +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build _ C prod3r + (fun a b (f : a ~> b) => f.1.1 <*> (f.1.2 <*> f.2)). + +Definition prod1r {C : premonoidal} (x : C) : C := 1 * x. +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build C C prod1r + (fun (a b : C) (f : a ~> b) => \idmap_1 <*> f). + +Definition prod1l {C : premonoidal} (x : C) : C := x * 1. +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build C C prod1l + (fun (a b : C) (f : a ~> b) => f <*> \idmap_1). + +HB.mixin Record PreMonoidal_IsMonoidal C of PreMonoidal C := { + prodA : prod3l ~~> prod3r; + prod1c : prod1r ~~> idfun; + prodc1 : prod1l ~~> idfun; + prodc1c : forall (x y : C), + prodA (x, 1, y) \; \idmap_x <*> prod1c y = prodc1 x <*> \idmap_y; + prodA4 : forall (w x y z : C), + prodA (w * x, y, z) \; prodA (w, x, y * z) = + prodA (w, x, y) <*> \idmap_z \; prodA (w, x * y, z) \; \idmap_w <*> prodA (x, y, z); +}. + +Unset Universe Checking. +#[short(type="monoidal")] +#[verbose] +HB.structure Definition Monoidal : Set := + { C of PreMonoidal_IsMonoidal C & PreMonoidal C }. +Set Universe Checking. + +(******************************************************************) + + +Record cospan (Q : quiver) (A B : Q) := Cospan { + top : Q; + left2top : A ~> top; + right2top : B ~> top +}. + +Section cospans. +Variables (Q : precat) (A B : Q). +Record cospan_map (c c' : cospan A B) := CospanMap { + top_map : top c ~> top c'; + left2top_map : left2top c \; top_map = left2top c'; + right2top_map : right2top c \; top_map = right2top c'; +}. +HB.instance Definition _ := IsQuiver.Build (cospan A B) cospan_map. + +Lemma cospan_mapP (c c' : cospan A B) (f g : c ~> c') : + top_map f = top_map g <-> f = g. +Admitted. +End cospans. + +Section cospans_in_cat. +Variables (Q : cat) (A B : Q). +Definition cospan_idmap (c : cospan A B) := + @CospanMap Q A B c c idmap (compo1 _) (compo1 _). +Program Definition cospan_comp (c1 c2 c3 : cospan A B) + (f12 : c1 ~> c2) (f23 : c2 ~> c3) := + @CospanMap Q A B c1 c3 (top_map f12 \; top_map f23) _ _. +Next Obligation. by rewrite compoA !left2top_map. Qed. +Next Obligation. by rewrite compoA !right2top_map. Qed. +HB.instance Definition _ := IsPreCat.Build (cospan A B) cospan_idmap cospan_comp. + +Lemma cospan_are_cats : PreCat_IsCat (cospan A B). +Proof. +constructor=> [a b f|a b f|a b c d f g h]. +- by apply/cospan_mapP => /=; rewrite comp1o. +- by apply/cospan_mapP => /=; rewrite compo1. +- by apply/cospan_mapP => /=; rewrite compoA. +Qed. +HB.instance Definition _ := cospan_are_cats. +End cospans_in_cat. + +Section spans_and_co. +Variables (Q : quiver) (A B : Q). +Definition span := @cospan Q^op A B. +Definition bot (s : span) : Q := top s. +Definition bot2left (s : span) : bot s ~>_Q A := left2top s. +Definition bot2right (s : span) : bot s ~>_Q B := right2top s. +Definition Span (C : Q) (f : C ~> A) (g : C ~> B) : span := + @Cospan Q^op A B C f g. +End spans_and_co. + +HB.instance Definition _ (Q : precat) (A B : Q) := + Quiver.copy (span A B) (@cospan Q^op A B)^op. +HB.instance Definition _ (Q : cat) (A B : Q) := + Cat.copy (span A B) (@cospan Q^op A B)^op. + +Section bot_map. +Variables (C : cat) (A B : C) (s s' : span A B) (f : s ~> s'). +Definition bot_map : bot s ~> bot s' := top_map f. +Lemma bot2left_map : bot_map \; bot2left s' = bot2left s. +Proof. exact: left2top_map f. Qed. +Lemma bot2right_map : bot_map \; bot2right s' = bot2right s. +Proof. exact: right2top_map f. Qed. +End bot_map. + +HB.mixin Record isPrePullback (Q : precat) (A B : Q) + (c : cospan A B) (s : span A B) := { + is_square : bot2left s \; left2top c = bot2right s \; right2top c; +}. +#[short(type=prepullback)] +HB.structure Definition PrePullback Q A B (c : cospan A B) := + {s of isPrePullback Q A B c s}. +Arguments prepullback {Q A B} c. + +Section prepullback. +Variables (Q : precat) (A B : Q) (c : cospan A B). +HB.instance Definition _ := + IsQuiver.Build (prepullback c) + (fun a b => (a : span A B) ~>_(span A B) (b : span A B)). +Lemma eq_prepullbackP (p q : prepullback c) : + p = q :> span _ _ <-> p = q. +Admitted. +End prepullback. +Section prepullback. +Variables (Q : cat) (A B : Q) (csp : cospan A B). +(* TODO: why can't we do that? *) +(* HB.instance Definition _ := Cat.on (prepullback csp). *) +HB.instance Definition _ := + Quiver_IsPreCat.Build (prepullback csp) + (fun a => \idmap_(a : span A B)) + (* TODO: study how to make this coercion trigger + even when the target is not reduced to span *) + (fun a b c f g => f \; g). +Lemma prepullback_is_cat : PreCat_IsCat (prepullback csp). +Proof. (* should be copied from the cat on span *) +constructor=> [a b f|a b f|a b c d f g h]; + [exact: comp1o|exact: compo1|exact: compoA]. +Qed. +End prepullback. + +HB.tag Definition pb_terminal (Q : precat) + (A B : Q) (c : cospan A B) (s : prepullback c) : + obj (prepullback c) := s. + +#[wrapper] +HB.mixin Record prepullback_isTerminal (Q : precat) + (A B : Q) (c : cospan A B) + (s : span A B) of isPrePullback Q A B c s := { + prepullback_terminal : + IsTerminal (prepullback c) (pb_terminal s) +}. +#[short(type="pullback"), verbose] +HB.structure Definition Pullback (Q : precat) + (A B : Q) (c : cospan A B) := + {s of isPrePullback Q A B c s + & IsTerminal (prepullback c) (pb_terminal s) }. + +Notation pbsquare u v f g := + (Pullback _ (Cospan f g) (Span u v)). + +Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). + +(******************************************************************) + +Definition hom_object' {T} (h: T -> T -> U) : Type := + sigT (fun x:T => (sigT (fun y:T => h x y))). + +(* used to reify homsets *) +Record homset_object T (h: T -> T -> U) := hobj { + source : T; + target : T; + this_hom : U := h source target }. + +(* squiv is a quiver on a subset of T determined by S *) +Record SubQuiver T (S: T -> Prop) := { + quiv_ax : Quiver (sig S); + quiv : quiver := Quiver.Pack (Quiver.Class quiv_ax) }. + +(* the homsets of the subquiver are mapped to objects. + Obj(C) = sigT base_obj ; + C(a, b) = homset_inj A B ; *) +HB.mixin Record IsEQuiver T of Quiver T := { + base_obj : T -> Prop ; + squiv : SubQuiver base_obj ; +(* homset_inj : forall (A B: sig base_obj), (@hom (quiv squiv) A B) -> T ; *) + homset_inj : sig base_obj -> sig base_obj -> T + }. +Unset Universe Checking. +HB.structure Definition EQuiver : Set := { C of IsEQuiver C }. +Set Universe Checking. + +HB.mixin Record IsPreECat T of PreMonoidal T & EQuiver T := { + id_element : forall (A: sig (fun x: T => base_obj x)), + @hom T onec (homset_inj A A) ; + comp_morphism : forall (A B C: sig (fun x: T => base_obj x)), + @hom T (homset_inj A B * homset_inj B C) (homset_inj A C) +}. +Unset Universe Checking. +HB.structure Definition PreECat : Set := { C of IsPreECat C }. +Set Universe Checking. + + + +(*****************************************************************) +(*** dustbin *) + +About PreMonoidal. + +Unset Universe Checking. +(* HB.structure Definition MonoidalCat' := { C of PreCat_IsCat C & PreCat_IsMonoidal C }. *) +HB.structure Definition MonoidalCat := { C of Cat C & Monoidal C }. +Set Universe Checking. + + +HB.mixin Record PreECat' T of PreMonoidal T & Quiver T & EQuiver T := { + comp_morphism : forall (A B C: sig base_obj), + @hom T (homset_inj A B) (homset_inj A C) ; +}. + +HB.mixin Record PreECat0 T of PreMonoidal T & Quiver T & EQuiver T := { + + (* ccc : forall (A B C: T), + prod (A, B) = prod (A, C) ; *) + + onedef (A B: sig (fun x: T => base_obj x)) : homset_inj A B = homset_inj A B ; + + ddd : forall (A B C: sig (fun x: T => base_obj x)), + prod (homset_inj A B, homset_inj B C) = prod (homset_inj A C, homset_inj A C) ; + + comp_morphism : forall (A B C: sig (fun x: T => base_obj x)), + @hom T (homset_inj A B * homset_inj B C) (homset_inj A C) ; +}. + + + +Lemma hhh (F: quiver) : forall a b, @hom F a b = @hom F a b. + intros. + destruct F. + simpl in *. + auto. +Qed. + +Lemma fff (F: premonoidal) : + @prod F = @prod F /\ + forall a b, @prod F (a, b) = prod (a, b). + unfold prod. + unfold PreCat_IsMonoidal.prod. + unfold PreMonoidal.class. simpl. + split. + destruct F. + destruct class. + simpl. + destruct ecat2_PreCat_IsMonoidal_mixin. + unfold hom in prod0. + unfold IsQuiver.hom in prod0. + unfold Quiver.class in prod0. + unfold Quiver.ecat2_IsQuiver_mixin in prod0. + simpl in prod0. + +Check Functor.type. + + destruct prod0. + simpl in *. + auto. + auto. +Qed. + +Lemma ggg (F: premonoidal) : forall a b, @prod F (a, b) = @prod F (a, b). + intros. + unfold prod. + unfold PreCat_IsMonoidal.prod. + unfold PreMonoidal.class. simpl. + destruct F. + destruct class. + simpl. + destruct ecat2_PreCat_IsMonoidal_mixin. + simpl in prod0. + destruct prod0 eqn:bbb. + destruct class. + destruct ecat2_IsPreFunctor_mixin. + destruct ecat2_PreFunctor_IsFunctor_mixin. + simpl. + auto. +Qed. + + +HB.mixin Record PreFCat T of PreMonoidal T & Quiver T & IsEQuiver T := { + A : T ; + B : T ; + f : @hom T A B ; + X : U ; + g : prod (A, B)%type ; + }. + comp_morphism (A B C: T) : U ; + eee : forall (A B C: T), comp_morphism A B C = prod (A, B) C ; +}. + + +HB.mixin Record PreECat T of PreMonoidal T & Quiver T & IsEQuiver T := { + comp_morphism : forall (A B C: sig base_obj), + @hom T (homset_inj A B * homset_inj B C) (homset_inj A C) ; +}. + + +Record SubQuiver T (S: T -> U) := { + squiv_ax : Quiver (sigT S) ; + squiv : quiver := Quiver.Pack (Quiver.Class squiv_ax) ; + squiv_homset (A B: sigT S) : + homset_object (@hom squiv) := hobj (@hom squiv) A B }. + + + +Record SubQuiver' T (S: T -> U) := { + squiv_ax' : Quiver (sigT S); + squiv' : quiver := Quiver.Pack (Quiver.Class squiv_ax') ; + squiv_hom' : U := sigT (fun x => sigT (fun y => @hom squiv' x y)) }. + +HB.mixin Record IsEQuiver T of Quiver T := { + base_obj : T -> U ; + bq : SubQuiver base_obj ; + hom_inj : this_hom (squiv_hom bq) -> T + }. +Unset Universe Checking. +HB.structure Definition EQuiver : Set := { C of IsEQuiver C }. +Set Universe Checking. + + + +HB.mixin Record IsEQuiver T of Quiver T := { + base_obj : T -> U ; + bq : SubQuiver base_obj ; + hom_inj : this_hom (squiv_hom bq) -> T + }. +Unset Universe Checking. +HB.structure Definition EQuiver : Set := { C of IsEQuiver C }. +Set Universe Checking. + +HB.mixin Record IsEQuiver T of Quiver T := { + equiv : EQuiver T ; + hom_object : U := sigT (fun x => sigT (fun y => @hom base_quiver x y)) ; +}. + + + bq : quiver := Quiver.Pack (Quiver.Class base_quiver) }. ; + hom_object : U := sigT (fun x => sigT (fun y => @hom bq x y)) ; + hom_inj : hom_object -> T }. + + + +(* HB.mixin Record isHQuiver' T of Quiver T := + { jobj': sigT (fun x:T => (sigT (fun y:T => @hom T x y))) }. *) +HB.mixin Record IsHQuiver T of Quiver T := + { hhom : homset_object T -> homset_object T -> U ; + hom2hhom : forall (A B C: T), + @hhom (@homset_object.Build T A B (@hom T A B) eq_refl) + (@homset_object.Build T B C (@hom T B C) eq_refl) }. +Unset Universe Checking. +#[short(type="hquiver")] +HB.structure Definition HQuiver : Set := { C of IsHQuiver C }. +Set Universe Checking. + +Unset Universe Checking. +(* HB.structure Definition MonoidalCat' := { C of PreCat_IsCat C & PreCat_IsMonoidal C }. *) +HB.structure Definition MonoidalCat := { C of Cat C & Monoidal C }. +Set Universe Checking. + +Record ECat' T (tns: T -> T -> T) := { + base_obj : T -> U ; + base_quiver : Quiver (sigT base_obj) ; + bq : quiver := Quiver.Pack (Quiver.Class base_quiver) ; + hom_object : U := sigT (fun x => sigT (fun y => @hom bq x y)) ; + hom_inj : hom_object -> T }. + + + comp_morphism : forall A B C hom_object hom_object + + hom_object : forall {A B: sigT base_obj}, @hom bq A B -> T ; + comp_morhism : forall (A B C: sigT base_obj), + hom_object A B -> hom_object B C -> hom_object A C + }. + + + +Record ECat' T := { + base_obj : T -> U ; + base_quiver : Quiver (sigT base_obj) ; + bq : quiver := Quiver.Pack (Quiver.Class base_quiver) ; + hom_object : forall {A B: sigT base_obj}, @hom bq A B -> T ; + comp_morhism : forall (A B C: sigT base_obj), + hom_object A B -> hom_object B C -> hom_object A C + }. + + +HB.mixin Record ECat T of MonoidalCat T := { + ecat : ECat' T }. + + base_obj : T -> U ; + base_quiver : Quiver (sigT base_obj) ; + bbb := Quiver.Class base_quiver }. + + bbb : quiver := Quiver.Pack (sigT base_obj) (Quiver.Class base_quiver) }. + base_cat : Cat (sigT base_obj) ; + hom_object : forall (A B: sigT base_obj), + @hom (Quiver.Pack _ (Quiver.Class base_quiver)) A B -> T ; +}. + + + + + + jobj: @hom_objs T (fun x y: T => @hom T x y) }. +HB.structure Definition HQuiver := { Obj of isHQuiver Obj }. + +HB.mixin Record HQuiver_isPreCat T of IsQuiver T := { + my_prop : Quiver (hom_objs (fun x y: T => @hom T x y)); + my_prop2 : PreCat (hom_objs (fun x y: T => @hom T x y)); + my_prop3 : Monoidal (hom_objs (fun x y: T => @hom T x y)); +}. + +HB.mixin Record IsQuiver2 C := { hom2 : C -> C -> U }. +Unset Universe Checking. +HB.structure Definition Quiver2 : Set := { C of IsQuiver2 C }. + +(* precategories are quivers + id and comp *) +HB.mixin Record Quiver_IsPreCat2 C of Quiver C := { + qqq : Quiver (option C) ; + idmap : forall (a : C), a ~> a; + comp : forall (a b c : C), (a ~> b) -> (b ~> c) -> (a ~> c); +}. + + +HB.mixin Record HQuiver_isPreCat T of IsQuiver T := { + my_prop : Quiver (T -> T) +}. + + +HB.mixin Record HQuiver_isPreCat T of IsQuiver T := { + my_prop : @IsQuiver2 (hom_objs (fun x y: T => @hom T x y)) +}. + + +HB.mixin Record HQuiver_isPreCat T of IsQuiver T := { + my_prop : @IsQuiver (sigT (fun x:T => (sigT (fun y:T => @hom T x y)))) +}. + + + +HB.mixin Record HQuiver_isPreCat T of IsQuiver T := { + my_prop : @IsQuiver2 (sigT (fun x:T => (sigT (fun y:T => @hom T x y)))) +}. + + +HB.mixin Definition isPreEnriched T := { + cat: isCategory T; + + }. + + +(*******************************************************************) + +(* We want to factor constants and operators out of the axioms. + Suggestion: introducing some notion of module to bind them + together. *) + +(* monoid axioms *) +HB.mixin Record isMonoid T (mu: T) (mc: T -> T -> T): Type := { + massoc : associative mc; + mlid : left_id mu mc ; + mrid : right_id mu mc ; +}. + +(* to be used as homset identity *) +HB.mixin Record isHId T := { + hid : T; +}. +HB.structure Definition HId := { T of isHId T }. + +(* to be used as homset composition *) +HB.mixin Record isHComp T := { + hcomp : T -> T -> T; +}. +HB.structure Definition HComp := { T of isHComp T }. + +#[wrapper] +HB.mixin Record Quiver_HasId T of Quiver T := + { Quiver_HasId_private : forall A B, isHId (@hom T A B) }. +HB.structure Definition HasId := + { Obj of Quiver Obj & Quiver_HasId Obj }. + +#[wrapper] +HB.mixin Record Quiver_HasComp T of Quiver T := + { Quiver_HasComp_private : forall A B, isHComp (@hom T A B) }. +HB.structure Definition HasComp := + { Obj of Quiver Obj & Quiver_HasComp Obj }. + +(* a category, without axioms *) +HB.structure Definition Precat := + {T of Quiver_HasId T & Quiver_HasComp T}. + +(* homset monoid + drverbbe essere un wrapper *) +#[wrapper] +HB.mixin Record isHMonoid T of HId T & HComp T := + { isHMonoid_private: isMonoid T (hid: T) (@hcomp T) }. +#[verbose] +HB.structure Definition HMonoid := { T of isHMonoid T }. + +#[wrapper] +(* does not work (generic Elpi error): + HB.mixin Record isHCat T of precat_quiver T := *) +HB.mixin Record isCategory T of Precat T := + { isCategory_private : forall A B, isHMonoid (@hom T A B) }. +HB.structure Definition Category := + { Obj of Precat Obj & forall A B:Obj, isHMonoid (@hom Obj A B)}. + +HB.structure Definition Category := + { Obj of isCategory Obj }. + +(* to be used as object monoid unit *) +HB.mixin Record isMUnit T := { + munit : T; +}. +HB.structure Definition MUnit := { T of isMUnit T }. + +(* to be used as object monoid composition *) +HB.mixin Record isMComp T := { + mcomp : T -> T -> T; +}. +HB.structure Definition MComp := { T of isMComp T }. + +(* has object monoid operators *) +HB.structure Definition Premonoid := + {T of isMUnit T & isMComp T}. + +(* the precategory has monoidal operators *) +HB.structure Definition Precat_IsPremonoidal := + {T of Precat T & Premonoid T}. + +(* object monoid *) +HB.mixin Record isOMonoid T of isMUnit T & isMComp T := + { isHMonoid_private: isMonoid T (munit: T) (mcomp: T -> T -> T) }. +#[verbose] +HB.structure Definition OMonoid := { T of isOMonoid T }. + +(* some sort of monoidal category *) +HB.structure Definition MonCategory := + { Obj of isCategory Obj & isOMonoid Obj }. + + + +(********************************************************) + +(* monoid axioms *) +HB.mixin Record isMonoid T of isMUnit T & isMComp T := { + massoc : associative (mcomp: T -> T -> T); + mlid : left_id (munit: T) (mcomp: T -> T -> T) ; + mrid : right_id (munit: T) (mcomp: T -> T -> T) ; + }. +#[verbose] +HB.structure Definition Monoid := { T of isMonoid T }. + + +#[wrapper] +(* does not work (generic Elpi error): + HB.mixin Record isHCat T of precat_quiver T := *) +HB.mixin Record isCategory T of Precat T := + { isCategory_private : forall A B, isMonoid (@hom T A B) }. +HB.structure Definition Category := + { Obj of isCategory Obj }. + + + +HB.factory Record IsFastCat C of Quiver C := + +HB.mixin Record PreCat_IsEnriched C of PreMonoidal C := { + +}. + +(*******************************************************************) + +Section th_of_pb. +Variables (Q : cat) (A B C D E F : Q). +Variables (f : A ~> D) (g : B ~> D) (h : C ~> A). +Variables (u : E ~> A) (v : E ~> B) (w : F ~> C) (z : F ~> E). +Variable (uvfg : pbsquare u v f g). + +Set Printing Width 50. +Theorem pbsquarec_compP : + pbsquare w z h u <=> pbsquare w (z \; v) (h \; f) g. +Proof. +split=> [] sq. + + have @sq_ispb : pullback (Cospan h u) := HB.pack (Span w z) sq. + have @uvfg_ispb : pullback (Cospan f g) := HB.pack (Span u v) uvfg. + have /=E2 := @is_square _ _ _ _ sq_ispb. + have /=E1 := @is_square _ _ _ _ uvfg_ispb. + + have p1 : @isPrePullback Q C B (Cospan (h \; f) g) (Span w (z \; v)). + by constructor; rewrite /= compoA E2 -compoA E1 compoA. + pose big_black_square : prepullback (Cospan (h \; f) g) := + HB.pack (Span w (z \; v)) p1. + + have @from : forall + (big_red_square : prepullback {| top := D; left2top := h \; f; right2top := g |}), + big_red_square ~> pb_terminal big_black_square. + + move=> big_red_square; unfold pb_terminal. + + have /= := @is_square _ _ _ _ big_red_square. + + pose F' := bot big_red_square. + set w' : F' ~> C := bot2left big_red_square. + set z' : F' ~> B := bot2right big_red_square. + move=> E3. + + have xxx : isPrePullback Q A B (Cospan f g) (Span (w' \; h) z'). + by constructor=> /=; rewrite -compoA E3. + pose red_black_square : prepullback (Cospan f g) := + HB.pack (Span (w' \; h) z') xxx. + have := @from_unique _ (pb_terminal uvfg_ispb) red_black_square. + set blue := @from _ (pb_terminal uvfg_ispb) red_black_square. + move=> blue_unique. + + have p3 : @isPrePullback Q C E (Cospan h u) (Span w' (bot_map blue)). + by constructor; rewrite /= (bot2left_map blue). (* buggy unifier without blue *) + pose blue_red_black_square : prepullback (Cospan h u) := + HB.pack (Span w' (bot_map blue)) p3. + + pose red := @from _ (pb_terminal sq_ispb) blue_red_black_square. + + admit. + + + + have p2 : prepullback_isTerminal.axioms_ Q C B (Cospan (h \; f) g) (Span w (z \; v)) p1. + constructor. econstructor=> /=. + admit. + + by HB.from p1 p2. + +Admitted. + +End th_of_pb. + + +Module test. + +Section test. +Variables (Q : precat) (A B : Q) (c : cospan A B). +Variable (p : pullback c). +Check pb_terminal p : terminal _. + +End test. +End test. + + + + From 09618b373b59bcb757fd1d44f4f34727bffbddf6 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Thu, 19 Oct 2023 16:36:20 +0200 Subject: [PATCH 062/147] updated theories/encat.v --- theories/encat.v | 74 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 6 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index 51156a2cd..834626f05 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1013,45 +1013,107 @@ Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). (******************************************************************) +(* +(* NOT USED *) Definition hom_object' {T} (h: T -> T -> U) : Type := sigT (fun x:T => (sigT (fun y:T => h x y))). -(* used to reify homsets *) +(* NOT USED: used to reify homsets *) Record homset_object T (h: T -> T -> U) := hobj { source : T; target : T; this_hom : U := h source target }. +*) (* squiv is a quiver on a subset of T determined by S *) +(* Record SubQuiver T (S: T -> Prop) := { quiv_ax : Quiver (sig S); quiv : quiver := Quiver.Pack (Quiver.Class quiv_ax) }. +*) + +(* squiv is a quiver on a subset of T determined by S *) +(* +HB.mixin Record IsSubQuiver T (S: T -> Prop) := { + quiv_ax : Quiver (sig S) }. +HB.structure Definition SubQuiver ... +*) (* the homsets of the subquiver are mapped to objects. Obj(C) = sigT base_obj ; C(a, b) = homset_inj A B ; *) +(* HB.mixin Record IsEQuiver T of Quiver T := { base_obj : T -> Prop ; squiv : SubQuiver base_obj ; (* homset_inj : forall (A B: sig base_obj), (@hom (quiv squiv) A B) -> T ; *) homset_inj : sig base_obj -> sig base_obj -> T }. +*) + +(* both the base objects and the the homsets in the base quiver are + mapped to ecat objects. + Obj(C) = base_carrier ; C(a, b) = hom_object a b ; *) +HB.mixin Record IsEQuiver T of Quiver T := { + base_carrier : U ; + base_object : base_carrier -> T ; + base_quiver : Quiver base_carrier ; + hom_object : base_carrier -> base_carrier -> T + }. Unset Universe Checking. HB.structure Definition EQuiver : Set := { C of IsEQuiver C }. Set Universe Checking. HB.mixin Record IsPreECat T of PreMonoidal T & EQuiver T := { - id_element : forall (A: sig (fun x: T => base_obj x)), - @hom T onec (homset_inj A A) ; - comp_morphism : forall (A B C: sig (fun x: T => base_obj x)), - @hom T (homset_inj A B * homset_inj B C) (homset_inj A C) + id_element : forall (a: base_carrier), + @hom T onec (hom_object a a) ; + comp_morphism : forall (a b c: base_carrier), + @hom T (@hom_object T b c * @hom_object T a b) + (@hom_object T a c) }. Unset Universe Checking. HB.structure Definition PreECat : Set := { C of IsPreECat C }. Set Universe Checking. +Notation "a ~^ b" := (hom_object a b) + (at level 99, b at level 200, format "a ~^ b") : cat_scope. +Notation "a ~^_ T b" := (@hom_object T a b) + (at level 99, T at level 0, only parsing) : cat_scope. +Notation "~^I a" := (id_element a) + (at level 99, format "~^I a") : cat_scope. +Notation "~^I_ T a" := (@id_element T a) + (at level 99, T at level 0, only parsing) : cat_scope. +Notation "~^C a b c" := (comp_morphism a b c) + (at level 99, + format "~^C a b c") : cat_scope. +Notation "~^C_ T a b c" := (@comp_morphism T a b c) + (at level 99, T at level 0, only parsing) : cat_scope. + +HB.mixin Record IsECat T of PreECat T := { + ecat_comp_assoc : forall a b c d: base_carrier, + forall alpha: ((((c ~^_T d) * (b ~^_T c)) * (a ~^_T b)) ~>_T + ((c ~^_T d) * ((b ~^_T c) * (a ~^_T b)))), + ((@comp_morphism T b c d) <*> (@idmap T (a ~^_T b))) \; + (@comp_morphism T a b d) + = + alpha \; + ((@idmap T (c ~^_T d)) <*> (@comp_morphism T a b c)) \; + (@comp_morphism T a c d) ; + + ecat_comp_left_unital : forall a b: base_carrier, + forall l: onec * (a ~^_T b) ~>_T (a ~^_T b), + l = ((@id_element T b) <*> (@idmap T (a ~^_T b))) \; + (@comp_morphism T a b b) ; + ecat_comp_right_unital : forall a b: base_carrier, + forall r: (a ~^_T b) * onec ~>_T (a ~^_T b), + r = ((@idmap T (a ~^_T b)) <*> (@id_element T a)) \; + (@comp_morphism T a a b) +}. +Unset Universe Checking. +HB.structure Definition ECat : Set := { C of IsECat C }. +Set Universe Checking. - + (*****************************************************************) (*** dustbin *) From edb031366ca3faacb4c4289999ffd98683232be8 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Fri, 20 Oct 2023 17:20:48 +0200 Subject: [PATCH 063/147] updated theories/encat.v; definitions of enriched category and (tentatively) double category based on ncatlab --- theories/encat.v | 395 ++++++++--------------------------------------- 1 file changed, 64 insertions(+), 331 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index 834626f05..59e8b6c69 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1013,47 +1013,16 @@ Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). (******************************************************************) -(* -(* NOT USED *) -Definition hom_object' {T} (h: T -> T -> U) : Type := - sigT (fun x:T => (sigT (fun y:T => h x y))). - -(* NOT USED: used to reify homsets *) -Record homset_object T (h: T -> T -> U) := hobj { - source : T; - target : T; - this_hom : U := h source target }. -*) - -(* squiv is a quiver on a subset of T determined by S *) -(* -Record SubQuiver T (S: T -> Prop) := { - quiv_ax : Quiver (sig S); - quiv : quiver := Quiver.Pack (Quiver.Class quiv_ax) }. -*) - -(* squiv is a quiver on a subset of T determined by S *) -(* -HB.mixin Record IsSubQuiver T (S: T -> Prop) := { - quiv_ax : Quiver (sig S) }. -HB.structure Definition SubQuiver ... -*) - -(* the homsets of the subquiver are mapped to objects. - Obj(C) = sigT base_obj ; - C(a, b) = homset_inj A B ; *) -(* -HB.mixin Record IsEQuiver T of Quiver T := { - base_obj : T -> Prop ; - squiv : SubQuiver base_obj ; -(* homset_inj : forall (A B: sig base_obj), (@hom (quiv squiv) A B) -> T ; *) - homset_inj : sig base_obj -> sig base_obj -> T - }. -*) +(*** ENRICHED CATEGORIES *) (* both the base objects and the the homsets in the base quiver are mapped to ecat objects. - Obj(C) = base_carrier ; C(a, b) = hom_object a b ; *) + Obj(C) = base_carrier ; C(a, b) = hom_object a b ; + 1) Not clear how declaring a wrapper for base_quiver could help, + as there is no real lifting (base_carrier is unrelated to T). + 2) Should base_object be injective? + 3) Should (the uncurrying of) hom_object be injective? + 4) Should base_quiver be a category too? *) HB.mixin Record IsEQuiver T of Quiver T := { base_carrier : U ; base_object : base_carrier -> T ; @@ -1064,7 +1033,8 @@ Unset Universe Checking. HB.structure Definition EQuiver : Set := { C of IsEQuiver C }. Set Universe Checking. -HB.mixin Record IsPreECat T of PreMonoidal T & EQuiver T := { +(* Monoidal precategory with the enrichment operators (no axioms) *) +HB.mixin Record IsEnPreCat T of PreMonoidal T & EQuiver T := { id_element : forall (a: base_carrier), @hom T onec (hom_object a a) ; comp_morphism : forall (a b c: base_carrier), @@ -1072,7 +1042,7 @@ HB.mixin Record IsPreECat T of PreMonoidal T & EQuiver T := { (@hom_object T a c) }. Unset Universe Checking. -HB.structure Definition PreECat : Set := { C of IsPreECat C }. +HB.structure Definition EnPreCat : Set := { C of IsEnPreCat C }. Set Universe Checking. Notation "a ~^ b" := (hom_object a b) @@ -1089,7 +1059,9 @@ Notation "~^C a b c" := (comp_morphism a b c) Notation "~^C_ T a b c" := (@comp_morphism T a b c) (at level 99, T at level 0, only parsing) : cat_scope. -HB.mixin Record IsECat T of PreECat T := { +(* Enriched category + (PreMonoidal_IsMonoidal and PreCat_IsCat would suffice) *) +HB.mixin Record IsEnCat T of EnPreCat T & Cat T & Monoidal T := { ecat_comp_assoc : forall a b c d: base_carrier, forall alpha: ((((c ~^_T d) * (b ~^_T c)) * (a ~^_T b)) ~>_T ((c ~^_T d) * ((b ~^_T c) * (a ~^_T b)))), @@ -1109,270 +1081,65 @@ HB.mixin Record IsECat T of PreECat T := { r = ((@idmap T (a ~^_T b)) <*> (@id_element T a)) \; (@comp_morphism T a a b) }. -Unset Universe Checking. -HB.structure Definition ECat : Set := { C of IsECat C }. -Set Universe Checking. - - -(*****************************************************************) -(*** dustbin *) - -About PreMonoidal. - Unset Universe Checking. -(* HB.structure Definition MonoidalCat' := { C of PreCat_IsCat C & PreCat_IsMonoidal C }. *) -HB.structure Definition MonoidalCat := { C of Cat C & Monoidal C }. +#[verbose] +HB.structure Definition EnCat : Set := { C of IsEnCat C }. Set Universe Checking. -HB.mixin Record PreECat' T of PreMonoidal T & Quiver T & EQuiver T := { - comp_morphism : forall (A B C: sig base_obj), - @hom T (homset_inj A B) (homset_inj A C) ; -}. - -HB.mixin Record PreECat0 T of PreMonoidal T & Quiver T & EQuiver T := { - - (* ccc : forall (A B C: T), - prod (A, B) = prod (A, C) ; *) - - onedef (A B: sig (fun x: T => base_obj x)) : homset_inj A B = homset_inj A B ; - - ddd : forall (A B C: sig (fun x: T => base_obj x)), - prod (homset_inj A B, homset_inj B C) = prod (homset_inj A C, homset_inj A C) ; - - comp_morphism : forall (A B C: sig (fun x: T => base_obj x)), - @hom T (homset_inj A B * homset_inj B C) (homset_inj A C) ; -}. - - - -Lemma hhh (F: quiver) : forall a b, @hom F a b = @hom F a b. - intros. - destruct F. - simpl in *. - auto. -Qed. - -Lemma fff (F: premonoidal) : - @prod F = @prod F /\ - forall a b, @prod F (a, b) = prod (a, b). - unfold prod. - unfold PreCat_IsMonoidal.prod. - unfold PreMonoidal.class. simpl. - split. - destruct F. - destruct class. - simpl. - destruct ecat2_PreCat_IsMonoidal_mixin. - unfold hom in prod0. - unfold IsQuiver.hom in prod0. - unfold Quiver.class in prod0. - unfold Quiver.ecat2_IsQuiver_mixin in prod0. - simpl in prod0. - -Check Functor.type. - - destruct prod0. - simpl in *. - auto. - auto. -Qed. - -Lemma ggg (F: premonoidal) : forall a b, @prod F (a, b) = @prod F (a, b). - intros. - unfold prod. - unfold PreCat_IsMonoidal.prod. - unfold PreMonoidal.class. simpl. - destruct F. - destruct class. - simpl. - destruct ecat2_PreCat_IsMonoidal_mixin. - simpl in prod0. - destruct prod0 eqn:bbb. - destruct class. - destruct ecat2_IsPreFunctor_mixin. - destruct ecat2_PreFunctor_IsFunctor_mixin. - simpl. - auto. -Qed. - - -HB.mixin Record PreFCat T of PreMonoidal T & Quiver T & IsEQuiver T := { - A : T ; - B : T ; - f : @hom T A B ; - X : U ; - g : prod (A, B)%type ; - }. - comp_morphism (A B C: T) : U ; - eee : forall (A B C: T), comp_morphism A B C = prod (A, B) C ; -}. - - -HB.mixin Record PreECat T of PreMonoidal T & Quiver T & IsEQuiver T := { - comp_morphism : forall (A B C: sig base_obj), - @hom T (homset_inj A B * homset_inj B C) (homset_inj A C) ; -}. - - -Record SubQuiver T (S: T -> U) := { - squiv_ax : Quiver (sigT S) ; - squiv : quiver := Quiver.Pack (Quiver.Class squiv_ax) ; - squiv_homset (A B: sigT S) : - homset_object (@hom squiv) := hobj (@hom squiv) A B }. - +(*** DOUBLE CATEGORIES *) - -Record SubQuiver' T (S: T -> U) := { - squiv_ax' : Quiver (sigT S); - squiv' : quiver := Quiver.Pack (Quiver.Class squiv_ax') ; - squiv_hom' : U := sigT (fun x => sigT (fun y => @hom squiv' x y)) }. - -HB.mixin Record IsEQuiver T of Quiver T := { - base_obj : T -> U ; - bq : SubQuiver base_obj ; - hom_inj : this_hom (squiv_hom bq) -> T - }. +(* A quiver from which horizontal morphisms arise (just a copy of quiver) *) +HB.mixin Record IsHQuiver C := { hhom : C -> C -> U }. Unset Universe Checking. -HB.structure Definition EQuiver : Set := { C of IsEQuiver C }. +#[short(type="hquiver")] +HB.structure Definition HQuiver : Set := { C of IsHQuiver C }. Set Universe Checking. +(* domain-specific sigma-type to represent the 2-objects *) +Record HomObj T (h: T -> T -> U) : Type := HO { + source : T; + target : T; + this_hom : U := h source target }. - -HB.mixin Record IsEQuiver T of Quiver T := { - base_obj : T -> U ; - bq : SubQuiver base_obj ; - hom_inj : this_hom (squiv_hom bq) -> T - }. +(* A quiver from which 2-morphisms arise as arrows between 2-objects + (i.e. horizontal morphisms) *) +#[wrapper] +HB.mixin Record IsH2Quiver T of HQuiver T := { + h2quiver : Quiver (@HomObj T (@hhom T)) }. Unset Universe Checking. -HB.structure Definition EQuiver : Set := { C of IsEQuiver C }. +#[short(type="h2quiver")] +HB.structure Definition H2Quiver : Set := { C of IsH2Quiver C }. Set Universe Checking. -HB.mixin Record IsEQuiver T of Quiver T := { - equiv : EQuiver T ; - hom_object : U := sigT (fun x => sigT (fun y => @hom base_quiver x y)) ; -}. - - - bq : quiver := Quiver.Pack (Quiver.Class base_quiver) }. ; - hom_object : U := sigT (fun x => sigT (fun y => @hom bq x y)) ; - hom_inj : hom_object -> T }. - - - -(* HB.mixin Record isHQuiver' T of Quiver T := - { jobj': sigT (fun x:T => (sigT (fun y:T => @hom T x y))) }. *) -HB.mixin Record IsHQuiver T of Quiver T := - { hhom : homset_object T -> homset_object T -> U ; - hom2hhom : forall (A B C: T), - @hhom (@homset_object.Build T A B (@hom T A B) eq_refl) - (@homset_object.Build T B C (@hom T B C) eq_refl) }. +(* The category based on the H2Quiver. +The wrapper attribute does not work though +#[wrapper] *) +HB.mixin Record IsH2Cat T of H2Quiver T := { + h2cat : Cat (@HomObj T (@hhom T)) }. Unset Universe Checking. -#[short(type="hquiver")] -HB.structure Definition HQuiver : Set := { C of IsHQuiver C }. +#[short(type="h2cat")] +HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. Set Universe Checking. +(* Double category (D0, D1). + base obejcts (D0): C ; + vertical morphisms (D0): @hom C ; + horizontal morhisms (and 2-objects, D1): @vhom C ; + 2-morphisms (D1): @hom (@HomObj C (@vhom C) *) Unset Universe Checking. -(* HB.structure Definition MonoidalCat' := { C of PreCat_IsCat C & PreCat_IsMonoidal C }. *) -HB.structure Definition MonoidalCat := { C of Cat C & Monoidal C }. +#[short(type="dcat")] +HB.structure Definition DCat : Set := { C of Cat C & H2Cat C }. Set Universe Checking. -Record ECat' T (tns: T -> T -> T) := { - base_obj : T -> U ; - base_quiver : Quiver (sigT base_obj) ; - bq : quiver := Quiver.Pack (Quiver.Class base_quiver) ; - hom_object : U := sigT (fun x => sigT (fun y => @hom bq x y)) ; - hom_inj : hom_object -> T }. - - - comp_morphism : forall A B C hom_object hom_object - - hom_object : forall {A B: sigT base_obj}, @hom bq A B -> T ; - comp_morhism : forall (A B C: sigT base_obj), - hom_object A B -> hom_object B C -> hom_object A C - }. - - - -Record ECat' T := { - base_obj : T -> U ; - base_quiver : Quiver (sigT base_obj) ; - bq : quiver := Quiver.Pack (Quiver.Class base_quiver) ; - hom_object : forall {A B: sigT base_obj}, @hom bq A B -> T ; - comp_morhism : forall (A B C: sigT base_obj), - hom_object A B -> hom_object B C -> hom_object A C - }. - - -HB.mixin Record ECat T of MonoidalCat T := { - ecat : ECat' T }. - - base_obj : T -> U ; - base_quiver : Quiver (sigT base_obj) ; - bbb := Quiver.Class base_quiver }. - - bbb : quiver := Quiver.Pack (sigT base_obj) (Quiver.Class base_quiver) }. - base_cat : Cat (sigT base_obj) ; - hom_object : forall (A B: sigT base_obj), - @hom (Quiver.Pack _ (Quiver.Class base_quiver)) A B -> T ; -}. - - - - - - jobj: @hom_objs T (fun x y: T => @hom T x y) }. -HB.structure Definition HQuiver := { Obj of isHQuiver Obj }. - -HB.mixin Record HQuiver_isPreCat T of IsQuiver T := { - my_prop : Quiver (hom_objs (fun x y: T => @hom T x y)); - my_prop2 : PreCat (hom_objs (fun x y: T => @hom T x y)); - my_prop3 : Monoidal (hom_objs (fun x y: T => @hom T x y)); -}. - -HB.mixin Record IsQuiver2 C := { hom2 : C -> C -> U }. -Unset Universe Checking. -HB.structure Definition Quiver2 : Set := { C of IsQuiver2 C }. - -(* precategories are quivers + id and comp *) -HB.mixin Record Quiver_IsPreCat2 C of Quiver C := { - qqq : Quiver (option C) ; - idmap : forall (a : C), a ~> a; - comp : forall (a b c : C), (a ~> b) -> (b ~> c) -> (a ~> c); -}. - - -HB.mixin Record HQuiver_isPreCat T of IsQuiver T := { - my_prop : Quiver (T -> T) -}. - - -HB.mixin Record HQuiver_isPreCat T of IsQuiver T := { - my_prop : @IsQuiver2 (hom_objs (fun x y: T => @hom T x y)) -}. - - -HB.mixin Record HQuiver_isPreCat T of IsQuiver T := { - my_prop : @IsQuiver (sigT (fun x:T => (sigT (fun y:T => @hom T x y)))) -}. - - - -HB.mixin Record HQuiver_isPreCat T of IsQuiver T := { - my_prop : @IsQuiver2 (sigT (fun x:T => (sigT (fun y:T => @hom T x y)))) -}. - - -HB.mixin Definition isPreEnriched T := { - cat: isCategory T; - - }. - (*******************************************************************) +(*** Related to BICATEGORIES (just an experiment, + not the right formalization) *) + (* We want to factor constants and operators out of the axioms. - Suggestion: introducing some notion of module to bind them + Suggestion: introduce some notion of module to bind them together. *) (* monoid axioms *) @@ -1382,13 +1149,13 @@ HB.mixin Record isMonoid T (mu: T) (mc: T -> T -> T): Type := { mrid : right_id mu mc ; }. -(* to be used as homset identity *) +(* to be used as homset identity in bicategories *) HB.mixin Record isHId T := { hid : T; }. HB.structure Definition HId := { T of isHId T }. -(* to be used as homset composition *) +(* to be used as homset composition in bicategories *) HB.mixin Record isHComp T := { hcomp : T -> T -> T; }. @@ -1406,28 +1173,23 @@ HB.mixin Record Quiver_HasComp T of Quiver T := HB.structure Definition HasComp := { Obj of Quiver Obj & Quiver_HasComp Obj }. -(* a category, without axioms *) -HB.structure Definition Precat := +(* a bicategory, without axioms *) +HB.structure Definition BiCatQuiver := {T of Quiver_HasId T & Quiver_HasComp T}. -(* homset monoid - drverbbe essere un wrapper *) -#[wrapper] -HB.mixin Record isHMonoid T of HId T & HComp T := +#[wrapper] +HB.mixin Record isHMonoid T of HId T & HComp T := { isHMonoid_private: isMonoid T (hid: T) (@hcomp T) }. #[verbose] HB.structure Definition HMonoid := { T of isHMonoid T }. -#[wrapper] +#[wrapper] (* does not work (generic Elpi error): HB.mixin Record isHCat T of precat_quiver T := *) -HB.mixin Record isCategory T of Precat T := - { isCategory_private : forall A B, isHMonoid (@hom T A B) }. -HB.structure Definition Category := - { Obj of Precat Obj & forall A B:Obj, isHMonoid (@hom Obj A B)}. - -HB.structure Definition Category := - { Obj of isCategory Obj }. +HB.mixin Record isPreBiCategory T of IsPreCat T := + { isPreBiCategory_private : forall A B: T, HMonoid (@hom T A B) }. +HB.structure Definition PreBiCategory := + { Obj of isPreBiCategory Obj }. (* to be used as object monoid unit *) HB.mixin Record isMUnit T := { @@ -1447,7 +1209,7 @@ HB.structure Definition Premonoid := (* the precategory has monoidal operators *) HB.structure Definition Precat_IsPremonoidal := - {T of Precat T & Premonoid T}. + {T of PreCat T & Premonoid T}. (* object monoid *) HB.mixin Record isOMonoid T of isMUnit T & isMComp T := @@ -1456,39 +1218,10 @@ HB.mixin Record isOMonoid T of isMUnit T & isMComp T := HB.structure Definition OMonoid := { T of isOMonoid T }. (* some sort of monoidal category *) -HB.structure Definition MonCategory := - { Obj of isCategory Obj & isOMonoid Obj }. - +HB.structure Definition PreMonBiCategory := + { Obj of PreBiCategory Obj & OMonoid Obj }. -(********************************************************) - -(* monoid axioms *) -HB.mixin Record isMonoid T of isMUnit T & isMComp T := { - massoc : associative (mcomp: T -> T -> T); - mlid : left_id (munit: T) (mcomp: T -> T -> T) ; - mrid : right_id (munit: T) (mcomp: T -> T -> T) ; - }. -#[verbose] -HB.structure Definition Monoid := { T of isMonoid T }. - - -#[wrapper] -(* does not work (generic Elpi error): - HB.mixin Record isHCat T of precat_quiver T := *) -HB.mixin Record isCategory T of Precat T := - { isCategory_private : forall A B, isMonoid (@hom T A B) }. -HB.structure Definition Category := - { Obj of isCategory Obj }. - - - -HB.factory Record IsFastCat C of Quiver C := - -HB.mixin Record PreCat_IsEnriched C of PreMonoidal C := { - -}. - (*******************************************************************) Section th_of_pb. From 02b0fc57b939a17db8464094d047f45d8a5b0926 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Sun, 22 Oct 2023 12:54:31 +0200 Subject: [PATCH 064/147] updated theories/encat.v --- theories/encat.v | 129 +++++++++++++++++++++++++++++------------------ 1 file changed, 80 insertions(+), 49 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index 59e8b6c69..8ca169662 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1015,75 +1015,96 @@ Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). (*** ENRICHED CATEGORIES *) -(* both the base objects and the the homsets in the base quiver are - mapped to ecat objects. - Obj(C) = base_carrier ; C(a, b) = hom_object a b ; - 1) Not clear how declaring a wrapper for base_quiver could help, - as there is no real lifting (base_carrier is unrelated to T). - 2) Should base_object be injective? - 3) Should (the uncurrying of) hom_object be injective? - 4) Should base_quiver be a category too? *) -HB.mixin Record IsEQuiver T of Quiver T := { - base_carrier : U ; - base_object : base_carrier -> T ; - base_quiver : Quiver base_carrier ; - hom_object : base_carrier -> base_carrier -> T +Definition injective {A B} (f : A->B) := + forall x y, f x = f y -> x = y. + +(* Enrichment in a monoidal category, from + https://ncatlab.org/nlab/show/enriched+category + + T is the monoidal category (V on the webpage); + + B is the base category that gets enriched (C on the webpage); + + Notice that the enrichement properties do not depend in any way on + B being a category (or even a quiver), whereas they rely heavily on + T being monoidal. This reflects the ncatlab definition. However, I + think it should be understood that B is a category, before being an + enriched one. It still makes it slightly unintuitive the fact that + they speak of B as the T-enriched category, whereas we have B as a + parameter of the enriched category based on T. But given our + definition of monoidal category, I haven't found a better way of + putting it. + + I am still unsure whether the objects of B should be injected into + those of T, too. I don't find the ncatlab definition very + enlighting on this, but afer looking at double categories I am + incined to think this is not wanted. *) +HB.mixin Record IsEQuiver (B: Cat.type) T of Quiver T := { + hom_object : B -> B -> T ; + hom_object_inj: injective (fun x => hom_object (fst x) (snd x)) ; }. Unset Universe Checking. -HB.structure Definition EQuiver : Set := { C of IsEQuiver C }. +HB.structure Definition EQuiver (B: Cat.type) : Set := + { C of IsEQuiver B C }. Set Universe Checking. (* Monoidal precategory with the enrichment operators (no axioms) *) -HB.mixin Record IsEnPreCat T of PreMonoidal T & EQuiver T := { - id_element : forall (a: base_carrier), +HB.mixin Record IsEnPreCat (B: Cat.type) T + of PreMonoidal T & EQuiver B T := { + id_element : forall (a: B), @hom T onec (hom_object a a) ; - comp_morphism : forall (a b c: base_carrier), - @hom T (@hom_object T b c * @hom_object T a b) - (@hom_object T a c) + comp_morphism : forall (a b c: B), + @hom T (@hom_object B T b c * @hom_object B T a b) + (@hom_object B T a c) }. Unset Universe Checking. -HB.structure Definition EnPreCat : Set := { C of IsEnPreCat C }. +HB.structure Definition EnPreCat (B: Cat.type) : Set := + { C of IsEnPreCat B C }. Set Universe Checking. Notation "a ~^ b" := (hom_object a b) (at level 99, b at level 200, format "a ~^ b") : cat_scope. -Notation "a ~^_ T b" := (@hom_object T a b) - (at level 99, T at level 0, only parsing) : cat_scope. +Notation "a ~^_ ( B , T ) b" := (@hom_object B T a b) + (at level 99, B at level 0, T at level 0, only parsing) : cat_scope. Notation "~^I a" := (id_element a) (at level 99, format "~^I a") : cat_scope. -Notation "~^I_ T a" := (@id_element T a) - (at level 99, T at level 0, only parsing) : cat_scope. +Notation "~^I_ ( B , T ) a" := (@id_element B T a) + (at level 99, B at level 0, T at level 0, only parsing) : cat_scope. +(* not working *) Notation "~^C a b c" := (comp_morphism a b c) (at level 99, format "~^C a b c") : cat_scope. -Notation "~^C_ T a b c" := (@comp_morphism T a b c) - (at level 99, T at level 0, only parsing) : cat_scope. +Notation "~^C_ ( B , T ) a b c" := (@comp_morphism B T a b c) + (at level 99, B at level 0, T at level 0, only parsing) : cat_scope. + (* Enriched category (PreMonoidal_IsMonoidal and PreCat_IsCat would suffice) *) -HB.mixin Record IsEnCat T of EnPreCat T & Cat T & Monoidal T := { - ecat_comp_assoc : forall a b c d: base_carrier, - forall alpha: ((((c ~^_T d) * (b ~^_T c)) * (a ~^_T b)) ~>_T - ((c ~^_T d) * ((b ~^_T c) * (a ~^_T b)))), - ((@comp_morphism T b c d) <*> (@idmap T (a ~^_T b))) \; - (@comp_morphism T a b d) +HB.mixin Record IsEnCat (B: Cat.type) T + of EnPreCat B T & Cat T & Monoidal T := { + ecat_comp_assoc : forall a b c d: B, + forall alpha: + (((c ~^_(B,T) d) * (b ~^_(B,T) c)) * (a ~^_(B,T) b)) ~>_T + ((c ~^_(B,T) d) * ((b ~^_(B,T) c) * (a ~^_(B,T) b))), + ((@comp_morphism B T b c d) <*> (@idmap T (a ~^_(B,T) b))) \; + (@comp_morphism B T a b d) = alpha \; - ((@idmap T (c ~^_T d)) <*> (@comp_morphism T a b c)) \; - (@comp_morphism T a c d) ; - - ecat_comp_left_unital : forall a b: base_carrier, - forall l: onec * (a ~^_T b) ~>_T (a ~^_T b), - l = ((@id_element T b) <*> (@idmap T (a ~^_T b))) \; - (@comp_morphism T a b b) ; - ecat_comp_right_unital : forall a b: base_carrier, - forall r: (a ~^_T b) * onec ~>_T (a ~^_T b), - r = ((@idmap T (a ~^_T b)) <*> (@id_element T a)) \; - (@comp_morphism T a a b) + ((@idmap T (c ~^_(B,T) d)) <*> (@comp_morphism B T a b c)) \; + (@comp_morphism B T a c d) ; + + ecat_comp_left_unital : forall a b: B, + forall l: onec * (a ~^_(B,T) b) ~>_T (a ~^_(B,T) b), + l = ((@id_element B T b) <*> (@idmap T (a ~^_(B,T) b))) \; + (@comp_morphism B T a b b) ; + ecat_comp_right_unital : forall a b: B, + forall r: (a ~^_(B,T) b) * onec ~>_T (a ~^_(B,T) b), + r = ((@idmap T (a ~^_(B,T) b)) <*> (@id_element B T a)) \; + (@comp_morphism B T a a b) }. Unset Universe Checking. #[verbose] -HB.structure Definition EnCat : Set := { C of IsEnCat C }. +HB.structure Definition EnCat (B: Cat.type) : Set := { C of IsEnCat B C }. Set Universe Checking. @@ -1122,11 +1143,21 @@ Unset Universe Checking. HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. Set Universe Checking. -(* Double category (D0, D1). - base obejcts (D0): C ; - vertical morphisms (D0): @hom C ; - horizontal morhisms (and 2-objects, D1): @vhom C ; - 2-morphisms (D1): @hom (@HomObj C (@vhom C) *) +(* Double categories, from + https://ncatlab.org/nlab/show/double+category + + The definition we follow here however is a comparatively informal + one, which also mentions internal categories (not formalized yet). + + Double category (D0, D1). + + base obejcts (D0): C ; + + vertical morphisms (D0): @hom C ; + + horizontal morhisms (and 2-objects, D1): @hhom C ; + + 2-morphisms (D1): @hom (@HomObj C (@vhom C)) *) Unset Universe Checking. #[short(type="dcat")] HB.structure Definition DCat : Set := { C of Cat C & H2Cat C }. From 75d8bfed2046879f2fe2a2635279e584479a8e07 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Tue, 24 Oct 2023 11:22:39 +0200 Subject: [PATCH 065/147] encat.v: fixed the definition of enriched category (reversed dependency order between base category and monoidal category --- theories/encat.v | 72 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/theories/encat.v b/theories/encat.v index 8ca169662..c82b9f7f6 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1015,6 +1015,76 @@ Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). (*** ENRICHED CATEGORIES *) +(* Enrichment in a monoidal category, following + https://ncatlab.org/nlab/show/enriched+category +*) +HB.mixin Record IsEnQuiver (V: Monoidal.type) C of Quiver C := { + hom_object : C -> C -> V + }. +Unset Universe Checking. +HB.structure Definition EnQuiver (V: Monoidal.type) : Set := + { C of IsEnQuiver V C }. +Set Universe Checking. + +(* Monoidal precategory with the enrichment operators (no axioms) *) +HB.mixin Record IsEnPreCat (V: Monoidal.type) C of EnQuiver V C := { + id_element : forall (a: C), + @hom V onec (hom_object a a) ; + comp_morphism : forall (a b c: C), + @hom V (@hom_object V C b c * @hom_object V C a b) + (@hom_object V C a c) +}. +Unset Universe Checking. +HB.structure Definition EnPreCat (V: Monoidal.type) : Set := + { C of IsEnPreCat V C }. +Set Universe Checking. + +Notation "a ~^ b" := (hom_object a b) + (at level 99, b at level 200, format "a ~^ b") : cat_scope. +Notation "a ~^_ ( V , C ) b" := (@hom_object V C a b) + (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. +Notation "~^IE a" := (id_element a) + (at level 99, format "~^IE a") : cat_scope. +Notation "~^IE_ ( V , C ) a" := (@id_element V C a) + (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. +(* not working *) +Notation "~^CM a b c" := (comp_morphism a b c) + (at level 99, + format "~^CM a b c") : cat_scope. +Notation "~^CM_ ( V , C ) a b c" := (@comp_morphism V C a b c) + (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. + +(* V-enriched category: + V is the monoidal category; + C is the base category that gets enriched +*) +HB.mixin Record IsEnCat (V: Monoidal.type) C of EnPreCat V C := { + ecat_comp_assoc : forall a b c d: C, + forall alpha: + (((c ~^_(V,C) d) * (b ~^_(V,C) c)) * (a ~^_(V,C) b)) ~>_V + ((c ~^_(V,C) d) * ((b ~^_(V,C) c) * (a ~^_(V,C) b))), + ((@comp_morphism V C b c d) <*> (@idmap V (a ~^_(V,C) b))) \; + (@comp_morphism V C a b d) + = + alpha \; + ((@idmap V (c ~^_(V,C) d)) <*> (@comp_morphism V C a b c)) \; + (@comp_morphism V C a c d) ; + + ecat_comp_left_unital : forall a b: C, + forall l: onec * (a ~^_(V,C) b) ~>_V (a ~^_(V,C) b), + l = ((@id_element V C b) <*> (@idmap V (a ~^_(V,C) b))) \; + (@comp_morphism V C a b b) ; + ecat_comp_right_unital : forall a b: C, + forall r: (a ~^_(V,C) b) * onec ~>_V (a ~^_(V,C) b), + r = ((@idmap V (a ~^_(V,C) b)) <*> (@id_element V C a)) \; + (@comp_morphism V C a a b) +}. +Unset Universe Checking. +#[verbose] +HB.structure Definition EnCat (V: Monoidal.type) : Set := { C of IsEnCat V C }. +Set Universe Checking. + +(* Definition injective {A B} (f : A->B) := forall x y, f x = f y -> x = y. @@ -1106,7 +1176,7 @@ Unset Universe Checking. #[verbose] HB.structure Definition EnCat (B: Cat.type) : Set := { C of IsEnCat B C }. Set Universe Checking. - +*) (*** DOUBLE CATEGORIES *) From b415e677a96a5e6bbd2618f5d873c67545c75918 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Tue, 24 Oct 2023 13:17:47 +0200 Subject: [PATCH 066/147] encat.v: basic update of double categories --- theories/encat.v | 120 ++++++++--------------------------------------- 1 file changed, 19 insertions(+), 101 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index c82b9f7f6..4b12e647e 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1084,99 +1084,6 @@ Unset Universe Checking. HB.structure Definition EnCat (V: Monoidal.type) : Set := { C of IsEnCat V C }. Set Universe Checking. -(* -Definition injective {A B} (f : A->B) := - forall x y, f x = f y -> x = y. - -(* Enrichment in a monoidal category, from - https://ncatlab.org/nlab/show/enriched+category - - T is the monoidal category (V on the webpage); - - B is the base category that gets enriched (C on the webpage); - - Notice that the enrichement properties do not depend in any way on - B being a category (or even a quiver), whereas they rely heavily on - T being monoidal. This reflects the ncatlab definition. However, I - think it should be understood that B is a category, before being an - enriched one. It still makes it slightly unintuitive the fact that - they speak of B as the T-enriched category, whereas we have B as a - parameter of the enriched category based on T. But given our - definition of monoidal category, I haven't found a better way of - putting it. - - I am still unsure whether the objects of B should be injected into - those of T, too. I don't find the ncatlab definition very - enlighting on this, but afer looking at double categories I am - incined to think this is not wanted. *) -HB.mixin Record IsEQuiver (B: Cat.type) T of Quiver T := { - hom_object : B -> B -> T ; - hom_object_inj: injective (fun x => hom_object (fst x) (snd x)) ; - }. -Unset Universe Checking. -HB.structure Definition EQuiver (B: Cat.type) : Set := - { C of IsEQuiver B C }. -Set Universe Checking. - -(* Monoidal precategory with the enrichment operators (no axioms) *) -HB.mixin Record IsEnPreCat (B: Cat.type) T - of PreMonoidal T & EQuiver B T := { - id_element : forall (a: B), - @hom T onec (hom_object a a) ; - comp_morphism : forall (a b c: B), - @hom T (@hom_object B T b c * @hom_object B T a b) - (@hom_object B T a c) -}. -Unset Universe Checking. -HB.structure Definition EnPreCat (B: Cat.type) : Set := - { C of IsEnPreCat B C }. -Set Universe Checking. - -Notation "a ~^ b" := (hom_object a b) - (at level 99, b at level 200, format "a ~^ b") : cat_scope. -Notation "a ~^_ ( B , T ) b" := (@hom_object B T a b) - (at level 99, B at level 0, T at level 0, only parsing) : cat_scope. -Notation "~^I a" := (id_element a) - (at level 99, format "~^I a") : cat_scope. -Notation "~^I_ ( B , T ) a" := (@id_element B T a) - (at level 99, B at level 0, T at level 0, only parsing) : cat_scope. -(* not working *) -Notation "~^C a b c" := (comp_morphism a b c) - (at level 99, - format "~^C a b c") : cat_scope. -Notation "~^C_ ( B , T ) a b c" := (@comp_morphism B T a b c) - (at level 99, B at level 0, T at level 0, only parsing) : cat_scope. - - -(* Enriched category - (PreMonoidal_IsMonoidal and PreCat_IsCat would suffice) *) -HB.mixin Record IsEnCat (B: Cat.type) T - of EnPreCat B T & Cat T & Monoidal T := { - ecat_comp_assoc : forall a b c d: B, - forall alpha: - (((c ~^_(B,T) d) * (b ~^_(B,T) c)) * (a ~^_(B,T) b)) ~>_T - ((c ~^_(B,T) d) * ((b ~^_(B,T) c) * (a ~^_(B,T) b))), - ((@comp_morphism B T b c d) <*> (@idmap T (a ~^_(B,T) b))) \; - (@comp_morphism B T a b d) - = - alpha \; - ((@idmap T (c ~^_(B,T) d)) <*> (@comp_morphism B T a b c)) \; - (@comp_morphism B T a c d) ; - - ecat_comp_left_unital : forall a b: B, - forall l: onec * (a ~^_(B,T) b) ~>_T (a ~^_(B,T) b), - l = ((@id_element B T b) <*> (@idmap T (a ~^_(B,T) b))) \; - (@comp_morphism B T a b b) ; - ecat_comp_right_unital : forall a b: B, - forall r: (a ~^_(B,T) b) * onec ~>_T (a ~^_(B,T) b), - r = ((@idmap T (a ~^_(B,T) b)) <*> (@id_element B T a)) \; - (@comp_morphism B T a a b) -}. -Unset Universe Checking. -#[verbose] -HB.structure Definition EnCat (B: Cat.type) : Set := { C of IsEnCat B C }. -Set Universe Checking. -*) (*** DOUBLE CATEGORIES *) @@ -1188,27 +1095,37 @@ HB.structure Definition HQuiver : Set := { C of IsHQuiver C }. Set Universe Checking. (* domain-specific sigma-type to represent the 2-objects *) -Record HomObj T (h: T -> T -> U) : Type := HO { +Record Total2 T (h: T -> T -> U) : Type := HO { source : T; target : T; - this_hom : U := h source target }. + this_hom : h source target }. + +HB.tag Definition HHomSet (C: hquiver) := Total2 (@hhom C). (* A quiver from which 2-morphisms arise as arrows between 2-objects (i.e. horizontal morphisms) *) #[wrapper] HB.mixin Record IsH2Quiver T of HQuiver T := { - h2quiver : Quiver (@HomObj T (@hhom T)) }. + h2quiver : Quiver (@HHomSet T) }. Unset Universe Checking. #[short(type="h2quiver")] HB.structure Definition H2Quiver : Set := { C of IsH2Quiver C }. Set Universe Checking. -(* The category based on the H2Quiver. -The wrapper attribute does not work though -#[wrapper] *) -HB.mixin Record IsH2Cat T of H2Quiver T := { - h2cat : Cat (@HomObj T (@hhom T)) }. Unset Universe Checking. +#[wrapper] +HB.mixin Record IsH2PreCat T of HQuiver T & H2Quiver T := { + h2precat : Quiver_IsPreCat (@HHomSet T) }. +#[short(type="h2quiver")] +HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. +Set Universe Checking. + +Unset Universe Checking. +(* The category based on the H2Quiver. +The wrapper attribute does not work though *) +#[wrapper] +HB.mixin Record IsH2Cat T of H2PreCat T := { + h2cat : PreCat_IsCat (@HHomSet T) }. #[short(type="h2cat")] HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. Set Universe Checking. @@ -1234,6 +1151,7 @@ HB.structure Definition DCat : Set := { C of Cat C & H2Cat C }. Set Universe Checking. + (*******************************************************************) (*** Related to BICATEGORIES (just an experiment, From de22884311239dec3268a1755f2ee13716fe93e0 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Tue, 24 Oct 2023 13:48:01 +0200 Subject: [PATCH 067/147] encat.v: minor changes in comment --- theories/encat.v | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index 4b12e647e..6b3c7e2da 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1100,6 +1100,7 @@ Record Total2 T (h: T -> T -> U) : Type := HO { target : T; this_hom : h source target }. +(* needed to identify HHomSet as lifter *) HB.tag Definition HHomSet (C: hquiver) := Total2 (@hhom C). (* A quiver from which 2-morphisms arise as arrows between 2-objects @@ -1116,13 +1117,12 @@ Unset Universe Checking. #[wrapper] HB.mixin Record IsH2PreCat T of HQuiver T & H2Quiver T := { h2precat : Quiver_IsPreCat (@HHomSet T) }. -#[short(type="h2quiver")] +#[short(type="h2precat")] HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. Set Universe Checking. +(* The category based on the H2Quiver (D1). *) Unset Universe Checking. -(* The category based on the H2Quiver. -The wrapper attribute does not work though *) #[wrapper] HB.mixin Record IsH2Cat T of H2PreCat T := { h2cat : PreCat_IsCat (@HHomSet T) }. @@ -1142,9 +1142,9 @@ Set Universe Checking. vertical morphisms (D0): @hom C ; - horizontal morhisms (and 2-objects, D1): @hhom C ; + horizontal morhisms (and 2-objects, D1): @HHomSet C ; - 2-morphisms (D1): @hom (@HomObj C (@vhom C)) *) + 2-morphisms (D1): @hom (@HHomSet C) *) Unset Universe Checking. #[short(type="dcat")] HB.structure Definition DCat : Set := { C of Cat C & H2Cat C }. From 5531d119b366865c300e2e23a415f5916003e01a Mon Sep 17 00:00:00 2001 From: ptorrx Date: Tue, 24 Oct 2023 15:08:09 +0200 Subject: [PATCH 068/147] encat.v: added Cyril's definition of double categories --- theories/encat.v | 100 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) diff --git a/theories/encat.v b/theories/encat.v index 6b3c7e2da..47f901d8b 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1085,7 +1085,105 @@ HB.structure Definition EnCat (V: Monoidal.type) : Set := { C of IsEnCat V C }. Set Universe Checking. -(*** DOUBLE CATEGORIES *) + +(*** DOUBLE CATEGORIES (NEW) *) + +(* A quiver from which horizontal morphisms arise. D1 is the type of + D1 objects (horizontal morphisms in C), with source and target + functors. *) +HB.mixin Record HasD1 C := { + D1 : U ; + s10 : D1 -> C ; + t10 : D1 -> C }. +Unset Universe Checking. +#[short(type="hquiver")] +HB.structure Definition D1type : Set := { C of HasD1 C }. +Set Universe Checking. + +(* A quiver from which 2-morphisms arise as arrows between 2-objects + (i.e. horizontal morphisms) *) +#[wrapper] +HB.mixin Record IsH2Quiver T of HasD1 T := { + h2quiver : IsQuiver (@D1 T) }. +Unset Universe Checking. +#[short(type="h2quiver")] +HB.structure Definition H2Quiver : Set := { C of IsH2Quiver C }. +Set Universe Checking. + +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsH2PreCat T of H2Quiver T := { + h2precat : Quiver_IsPreCat (@D1 T) }. +#[short(type="h2quiver")] +HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. +Set Universe Checking. + +(* The category based on the H2Quiver (D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsH2Cat T of H2PreCat T := { + h2cat : PreCat_IsCat (@D1 T) }. +#[short(type="h2cat")] +#[verbose] +HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. +Set Universe Checking. + +(* Pre-double category (no functors yet): this corresponds to the old +definition *) +Unset Universe Checking. +HB.structure Definition PreDCat : Set := { D of Cat D & H2Cat D }. +Set Universe Checking. + +(* source prefunctor. + D1 here is the quiver of the 2-morphisms, thanks to IsH2Quiver. + T is the quiver of 1-morphisms. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHSPreFunctor T of Cat T & H2Cat T := { + h2s_prefunctor : IsPreFunctor D1 T s10 }. +HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. +Set Universe Checking. + +(* target prefunctor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHTPreFunctor T of Cat T & H2Cat T := { + h2t_prefunctor : IsPreFunctor D1 T t10 }. +HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. +Set Universe Checking. + +(* source functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record HSPreFunctor_IsFunctor T of Cat T & HSPreFunctor T := { + h2s_prefunctor : PreFunctor_IsFunctor D1 T s10 }. +HB.structure Definition HSFunctor : Set := {C of HSPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* target functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record HTPreFunctor_IsFunctor T of Cat T & HTPreFunctor T := { + h2t_prefunctor : PreFunctor_IsFunctor D1 T t10 }. +HB.structure Definition HTFunctor : Set := {C of HTPreFunctor_IsFunctor C}. + +(* double category *) +HB.structure Definition DCat : Set := + {D of HSPreFunctor_IsFunctor D & HTPreFunctor_IsFunctor D }. +Set Universe Checking. + +(* 2-morphisms *) +Definition hhom (D: DCat.type) := @hom (@D1 D). + +Definition transpose (D: DCat.type) : U := D. + +Fail Lemma hom_transpose (D: DCat.type) : @hom (transpose D) = @hhom D. + +Fail Lemma hhom_transpose (D: DCat.type) : @hhom (transpose D) = @hom D. + + + +(*** DOUBLE CATEGORIES (OLD) *) (* A quiver from which horizontal morphisms arise (just a copy of quiver) *) HB.mixin Record IsHQuiver C := { hhom : C -> C -> U }. From b3dd85dc9e1d5cc71cc4d358b51ce800d1483bcc Mon Sep 17 00:00:00 2001 From: ptorrx Date: Wed, 25 Oct 2023 17:57:56 +0200 Subject: [PATCH 069/147] encat.v: revised parametrisation in enriched categories; revised definition of double categories, which includes the (also needed) identity functor - there are still some problems with it though --- theories/encat.v | 187 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 180 insertions(+), 7 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index 47f901d8b..c73a87f15 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1015,19 +1015,24 @@ Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). (*** ENRICHED CATEGORIES *) +Declare Scope encat_scope. +Delimit Scope encat_scope with encat. +Local Open Scope encat_scope. + (* Enrichment in a monoidal category, following https://ncatlab.org/nlab/show/enriched+category *) -HB.mixin Record IsEnQuiver (V: Monoidal.type) C of Quiver C := { +HB.mixin Record IsEnQuiver (V: Type) C := { hom_object : C -> C -> V }. Unset Universe Checking. -HB.structure Definition EnQuiver (V: Monoidal.type) : Set := +HB.structure Definition EnQuiver (V: Type) : Set := { C of IsEnQuiver V C }. Set Universe Checking. (* Monoidal precategory with the enrichment operators (no axioms) *) -HB.mixin Record IsEnPreCat (V: Monoidal.type) C of EnQuiver V C := { +HB.mixin Record IsEnPreCat (V: PreMonoidal.type) C of + EnQuiver (PreMonoidal.sort V) C := { id_element : forall (a: C), @hom V onec (hom_object a a) ; comp_morphism : forall (a b c: C), @@ -1035,12 +1040,12 @@ HB.mixin Record IsEnPreCat (V: Monoidal.type) C of EnQuiver V C := { (@hom_object V C a c) }. Unset Universe Checking. -HB.structure Definition EnPreCat (V: Monoidal.type) : Set := +HB.structure Definition EnPreCat (V: PreMonoidal.type) : Set := { C of IsEnPreCat V C }. Set Universe Checking. Notation "a ~^ b" := (hom_object a b) - (at level 99, b at level 200, format "a ~^ b") : cat_scope. + (at level 99, b at level 200, format "a ~^ b") : encat_scope. Notation "a ~^_ ( V , C ) b" := (@hom_object V C a b) (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. Notation "~^IE a" := (id_element a) @@ -1086,7 +1091,173 @@ Set Universe Checking. -(*** DOUBLE CATEGORIES (NEW) *) +(*** DOUBLE CATEGORIES (REVISED) *) + +(* A quiver from which horizontal morphisms arise (just a copy of quiver) *) +HB.mixin Record IsHQuiver C := { hhom : C -> C -> U }. +Unset Universe Checking. +#[short(type="hquiver")] +HB.structure Definition HQuiver : Set := { C of IsHQuiver C }. +Set Universe Checking. + +(* domain-specific sigma-type to represent the 2-objects *) +Record Total2 T (h: T -> T -> U) : Type := HO { + source : T; + target : T; + this_hom : h source target }. + +(* needed to identify HHomSet as lifter *) +HB.tag Definition HHomSet (C: hquiver) := Total2 (@hhom C). + +(* A quiver from which 2-morphisms arise as arrows between 2-objects + (i.e. horizontal morphisms) *) +#[wrapper] +HB.mixin Record IsH2Quiver T of HQuiver T := { + h2quiver : IsQuiver (@HHomSet T) }. +Unset Universe Checking. +#[short(type="h2quiver")] +HB.structure Definition H2Quiver : Set := { C of IsH2Quiver C }. +Set Universe Checking. + +HB.mixin Record IsH2FQuiver T of H2Quiver T := { + h2unit_map: forall x:T, @hhom T x x ; + }. +Unset Universe Checking. +#[short(type="h2fquiver")] +HB.structure Definition H2FQuiver : Set := { C of IsH2FQuiver C }. +Set Universe Checking. + +(* +HB.mixin Record IsH2GQuiver C of H2Quiver C := { + h2unit_map := fun (x: C) => @HO C hhom x x + (h2unit_map x) + }. +Unset Universe Checking. +#[short(type="h2fquiver")] +HB.structure Definition H2FQuiver : Set := { C of IsH2FQuiver C }. +Set Universe Checking. +*) + +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsH2PreCat T of H2FQuiver T := { + h2precat : Quiver_IsPreCat (@HHomSet T) }. +#[short(type="h2precat")] +HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. +Set Universe Checking. + +(* The category based on the H2Quiver (D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsH2Cat T of H2PreCat T := { + h2cat : PreCat_IsCat (@HHomSet T) }. +#[short(type="h2cat")] +HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. +Set Universe Checking. + +(* Pre-double category (no functors yet): this corresponds to the old +definition *) +Unset Universe Checking. +#[short(type="predcat")] +HB.structure Definition PreDCat : Set := { D of Cat D & H2Cat D }. +Set Universe Checking. + +(* source functor: D1 -> D0 *) +HB.tag Definition Source C := fun (X: HHomSet C) => @source C (@hhom C) X. +(* target functor: D1 -> D0 *) +HB.tag Definition Target C := fun (X: HHomSet C) => @target C (@hhom C) X. +(* unit functor: D0 -> D1 *) +HB.tag Definition UnitF (C: h2fquiver) := fun (x:C) => + @HO _ _ x x (@h2unit_map C x). +(* +Definition UnitF C (X: H2FQuiver C) := fun (x: C) => + @HO C (@hhom (@H2FQuiver.Pack C X)) x x + (@h2unit_map (@H2FQuiver.Pack C X) x). +*) + +(* source prefunctor. + D1 here is the quiver of the 2-morphisms, thanks to IsH2Quiver. + T is the quiver of 1-morphisms. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHSPreFunctor T of Cat T & H2Cat T := { + h2s_prefunctor : IsPreFunctor (HHomSet T) T (@Source T) }. +HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. +Set Universe Checking. + +(* target prefunctor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHTPreFunctor T of Cat T & H2Cat T := { + h2t_prefunctor : IsPreFunctor (HHomSet T) T (@Target T) }. +HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. +Set Universe Checking. + +(* source functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record HSPreFunctor_IsFunctor T of Cat T & HSPreFunctor T := { + h2s_functor : PreFunctor_IsFunctor (HHomSet T) T (@Source T) }. +HB.structure Definition HSFunctor : Set := {C of HSPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* target functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record HTPreFunctor_IsFunctor T of Cat T & HTPreFunctor T := { + h2t_functor : PreFunctor_IsFunctor (HHomSet T) T (@Target T) }. +HB.structure Definition HTFunctor : Set := {C of HTPreFunctor_IsFunctor C}. +Set Universe Checking. + +Unset Universe Checking. +(* fails with wrapping + #[wrapper] *) +HB.mixin Record IsHUPreFunctor T of Cat T & H2Cat T := { + h2u_prefunctor : IsPreFunctor T (HHomSet T) (@UnitF T) }. +(* Unset Universe Checking. *) +HB.structure Definition HUPreFunctor : Set := {C of IsHUPreFunctor C}. +Set Universe Checking. + +Unset Universe Checking. +(* major problems + #[wrapper] *) +Fail HB.mixin Record HUPreFunctor_IsFunctor T of Cat T & HUPreFunctor T := { + h2u_functor : PreFunctor_IsFunctor T (HHomSet T) (@UnitF T) }. +Fail HB.structure Definition HUFunctor : Set := {C of HUPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* double category *) +Unset Universe Checking. +HB.structure Definition DCat : Set := + {D of HSPreFunctor_IsFunctor D & HTPreFunctor_IsFunctor D }. +Set Universe Checking. + +(* 2-morphisms *) +Definition h2hom (D: DCat.type) := @hom (@HHomSet D). + +(* dummy def +Definition transpose (D: DCat.type) : U := D. *) + +Fail Lemma hom_transpose (D: DCat.type) : @hom (transpose D) = @h2hom D. + +Fail Lemma hhom_transpose (D: DCat.type) : @h2hom (transpose D) = @hom D. + +Definition transpose_isquiver C (X: IsQuiver C) : IsHQuiver C. + destruct X. + econstructor. + exact hom0. +Defined. + +Definition transpose_ishquiver C (X: IsHQuiver C) : IsQuiver C. + destruct X. + econstructor. + exact hhom0. +Defined. + + + + +(*** DOUBLE CATEGORIES (PREVIOUS) *) (* A quiver from which horizontal morphisms arise. D1 is the type of D1 objects (horizontal morphisms in C), with source and target @@ -1114,7 +1285,7 @@ Unset Universe Checking. #[wrapper] HB.mixin Record IsH2PreCat T of H2Quiver T := { h2precat : Quiver_IsPreCat (@D1 T) }. -#[short(type="h2quiver")] +#[short(type="h2precat")] HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. Set Universe Checking. @@ -1166,8 +1337,10 @@ Unset Universe Checking. HB.mixin Record HTPreFunctor_IsFunctor T of Cat T & HTPreFunctor T := { h2t_prefunctor : PreFunctor_IsFunctor D1 T t10 }. HB.structure Definition HTFunctor : Set := {C of HTPreFunctor_IsFunctor C}. +Set Universe Checking. (* double category *) +Unset Universe Checking. HB.structure Definition DCat : Set := {D of HSPreFunctor_IsFunctor D & HTPreFunctor_IsFunctor D }. Set Universe Checking. From 00c66a99f33e63f090040a7755e67c2e46826c8d Mon Sep 17 00:00:00 2001 From: ptorrx Date: Wed, 25 Oct 2023 18:13:46 +0200 Subject: [PATCH 070/147] encat.v: minor changes --- theories/encat.v | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index c73a87f15..adf6afc16 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1119,6 +1119,7 @@ Unset Universe Checking. HB.structure Definition H2Quiver : Set := { C of IsH2Quiver C }. Set Universe Checking. +(* adding the map to define the unit functor D0 -> D1 *) HB.mixin Record IsH2FQuiver T of H2Quiver T := { h2unit_map: forall x:T, @hhom T x x ; }. @@ -1127,17 +1128,7 @@ Unset Universe Checking. HB.structure Definition H2FQuiver : Set := { C of IsH2FQuiver C }. Set Universe Checking. -(* -HB.mixin Record IsH2GQuiver C of H2Quiver C := { - h2unit_map := fun (x: C) => @HO C hhom x x - (h2unit_map x) - }. -Unset Universe Checking. -#[short(type="h2fquiver")] -HB.structure Definition H2FQuiver : Set := { C of IsH2FQuiver C }. -Set Universe Checking. -*) - +(* Precat based on the H2Quiver (D1). *) Unset Universe Checking. #[wrapper] HB.mixin Record IsH2PreCat T of H2FQuiver T := { @@ -1176,7 +1167,7 @@ Definition UnitF C (X: H2FQuiver C) := fun (x: C) => *) (* source prefunctor. - D1 here is the quiver of the 2-morphisms, thanks to IsH2Quiver. + HHomSet T is the quiver of the 2-morphisms, thanks to H2Quiver. T is the quiver of 1-morphisms. *) Unset Universe Checking. #[wrapper] @@ -1209,6 +1200,7 @@ HB.mixin Record HTPreFunctor_IsFunctor T of Cat T & HTPreFunctor T := { HB.structure Definition HTFunctor : Set := {C of HTPreFunctor_IsFunctor C}. Set Universe Checking. +(* unit prefunctor. PROBLEMS *) Unset Universe Checking. (* fails with wrapping #[wrapper] *) @@ -1218,6 +1210,7 @@ HB.mixin Record IsHUPreFunctor T of Cat T & H2Cat T := { HB.structure Definition HUPreFunctor : Set := {C of IsHUPreFunctor C}. Set Universe Checking. +(* unit functor. FAILS *) Unset Universe Checking. (* major problems #[wrapper] *) @@ -1226,7 +1219,7 @@ Fail HB.mixin Record HUPreFunctor_IsFunctor T of Cat T & HUPreFunctor T := { Fail HB.structure Definition HUFunctor : Set := {C of HUPreFunctor_IsFunctor C}. Set Universe Checking. -(* double category *) +(* double category (unit functor to be added) *) Unset Universe Checking. HB.structure Definition DCat : Set := {D of HSPreFunctor_IsFunctor D & HTPreFunctor_IsFunctor D }. From 31843f28c5015fdc704aa9de8d99916a0167856f Mon Sep 17 00:00:00 2001 From: ptorrx Date: Wed, 25 Oct 2023 19:41:38 +0200 Subject: [PATCH 071/147] encat.v: updates to dcat transposition --- theories/encat.v | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index adf6afc16..0425b4a27 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1228,12 +1228,16 @@ Set Universe Checking. (* 2-morphisms *) Definition h2hom (D: DCat.type) := @hom (@HHomSet D). -(* dummy def -Definition transpose (D: DCat.type) : U := D. *) - -Fail Lemma hom_transpose (D: DCat.type) : @hom (transpose D) = @h2hom D. - -Fail Lemma hhom_transpose (D: DCat.type) : @h2hom (transpose D) = @hom D. +(* still don't understand + transposition whould swap vertical and horizontal morphisms, + i.e. hom and hhom *) +Definition transpose1 (D: DCat.type) : U := D. +(* however, given transpose1 this should hold *) +Lemma hom_transpose (D: DCat.type) : @hom (transpose1 D) = @hhom D. +Admitted. +(* and this too *) +Lemma hhom_transpose (D: DCat.type) : @hhom (transpose1 D) = @hom D. +Admitted. Definition transpose_isquiver C (X: IsQuiver C) : IsHQuiver C. destruct X. @@ -1247,6 +1251,13 @@ Definition transpose_ishquiver C (X: IsHQuiver C) : IsQuiver C. exact hhom0. Defined. +(* tranposition as a relation *) +Definition isTranspose C + (FQ: PreDCat C -> Quiver C) + (FHQ: PreDCat C -> HQuiver C) + (D1 D2: PreDCat C) : Type := + @hom (Quiver.Pack (FQ D2)) = @hhom (HQuiver.Pack (FHQ D1)) /\ + @hhom (HQuiver.Pack (FHQ D2)) = @hom (Quiver.Pack (FQ D1)). From 73a9732678d67763953e37f384311dc6e6ac8e59 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Thu, 26 Oct 2023 13:54:44 +0200 Subject: [PATCH 072/147] encat.v: minor changes --- theories/encat.v | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index 0425b4a27..97feb06fd 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1239,6 +1239,14 @@ Admitted. Lemma hhom_transpose (D: DCat.type) : @hhom (transpose1 D) = @hom D. Admitted. +(* tranposition as a relation *) +Definition isTranspose C + (FQ: PreDCat C -> Quiver C) + (FHQ: PreDCat C -> HQuiver C) + (D1 D2: PreDCat C) : Type := + @hom (Quiver.Pack (FQ D2)) = @hhom (HQuiver.Pack (FHQ D1)) /\ + @hhom (HQuiver.Pack (FHQ D2)) = @hom (Quiver.Pack (FQ D1)). + Definition transpose_isquiver C (X: IsQuiver C) : IsHQuiver C. destruct X. econstructor. @@ -1251,13 +1259,25 @@ Definition transpose_ishquiver C (X: IsHQuiver C) : IsQuiver C. exact hhom0. Defined. -(* tranposition as a relation *) -Definition isTranspose C +Definition transpose_quiver C (X: Quiver C) : HQuiver C. + destruct X. + econstructor. + eapply transpose_isquiver; eauto. +Defined. + +Definition transpose_hquiver C (X: HQuiver C) : Quiver C. + destruct X. + econstructor. + eapply transpose_ishquiver; eauto. +Defined. + +(* tranposition as a relation, using the transpose functions *) +Definition isTransposeF C (FQ: PreDCat C -> Quiver C) (FHQ: PreDCat C -> HQuiver C) (D1 D2: PreDCat C) : Type := - @hom (Quiver.Pack (FQ D2)) = @hhom (HQuiver.Pack (FHQ D1)) /\ - @hhom (HQuiver.Pack (FHQ D2)) = @hom (Quiver.Pack (FQ D1)). + Quiver.Pack (FQ D2) = Quiver.Pack (@transpose_hquiver C (FHQ D1)) /\ + HQuiver.Pack (FHQ D2) = HQuiver.Pack (@transpose_quiver C (FQ D1)). From 995fef1fcc863a5333db0f5d0efdbb46d1b52535 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Thu, 26 Oct 2023 16:40:54 +0200 Subject: [PATCH 073/147] encat.v: fixed unit functor problem (by changing the definition of unit_map) --- theories/encat.v | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index 97feb06fd..8d6bc9caa 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1158,7 +1158,7 @@ HB.tag Definition Source C := fun (X: HHomSet C) => @source C (@hhom C) X. (* target functor: D1 -> D0 *) HB.tag Definition Target C := fun (X: HHomSet C) => @target C (@hhom C) X. (* unit functor: D0 -> D1 *) -HB.tag Definition UnitF (C: h2fquiver) := fun (x:C) => +HB.tag Definition UnitF (C: h2fquiver) := fun (x:H2FQuiver.sort C) => @HO _ _ x x (@h2unit_map C x). (* Definition UnitF C (X: H2FQuiver C) := fun (x: C) => @@ -1207,8 +1207,11 @@ Unset Universe Checking. HB.mixin Record IsHUPreFunctor T of Cat T & H2Cat T := { h2u_prefunctor : IsPreFunctor T (HHomSet T) (@UnitF T) }. (* Unset Universe Checking. *) -HB.structure Definition HUPreFunctor : Set := {C of IsHUPreFunctor C}. +HB.structure Definition HUPreFunctor : Set := + {C of IsHUPreFunctor C}. Set Universe Checking. +(* {T of Cat T & H2Cat T & H2FQuiver T & + IsPreFunctor _ (HHomSet _) (@UnitF T)}. *) (* unit functor. FAILS *) Unset Universe Checking. From b1f88eaebc9579fbe231b106b3276a8b6036b0d2 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Thu, 26 Oct 2023 18:49:51 +0200 Subject: [PATCH 074/147] encat.v: adding composition - however, it seems more problematic than it should --- theories/encat.v | 44 +++++++++++++++++++++----------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index 8d6bc9caa..c51eb2f47 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1121,7 +1121,16 @@ Set Universe Checking. (* adding the map to define the unit functor D0 -> D1 *) HB.mixin Record IsH2FQuiver T of H2Quiver T := { - h2unit_map: forall x:T, @hhom T x x ; + h2unit_map: forall x:T, HHomSet T ; + h2unit_map_eq: forall x:T, let y := h2unit_map x in + source y = target y ; + h2comp_map: HHomSet T * HHomSet T -> HHomSet T ; + h2comp_map_eq: forall x y: HHomSet T, target x = source y -> + exists f: hhom (source x) (target y), + h2comp_map (x, y) = @HO T (@hhom T) (source x) (target y) f ; +(* square_comp : forall (a1 b1 c1 a2 b2 c2: T), + forall (ha1: hhom a1 b1) (hb1: hhom b1 c1) + (ha2: hhom a2 b2) (hb2: hhom b2 c2), *) }. Unset Universe Checking. #[short(type="h2fquiver")] @@ -1158,13 +1167,8 @@ HB.tag Definition Source C := fun (X: HHomSet C) => @source C (@hhom C) X. (* target functor: D1 -> D0 *) HB.tag Definition Target C := fun (X: HHomSet C) => @target C (@hhom C) X. (* unit functor: D0 -> D1 *) -HB.tag Definition UnitF (C: h2fquiver) := fun (x:H2FQuiver.sort C) => - @HO _ _ x x (@h2unit_map C x). -(* -Definition UnitF C (X: H2FQuiver C) := fun (x: C) => - @HO C (@hhom (@H2FQuiver.Pack C X)) x x - (@h2unit_map (@H2FQuiver.Pack C X) x). -*) +HB.tag Definition UnitF (C: h2fquiver) := + fun (x:H2FQuiver.sort C) => @h2unit_map C x. (* source prefunctor. HHomSet T is the quiver of the 2-morphisms, thanks to H2Quiver. @@ -1200,32 +1204,26 @@ HB.mixin Record HTPreFunctor_IsFunctor T of Cat T & HTPreFunctor T := { HB.structure Definition HTFunctor : Set := {C of HTPreFunctor_IsFunctor C}. Set Universe Checking. -(* unit prefunctor. PROBLEMS *) +(* unit prefunctor. *) Unset Universe Checking. -(* fails with wrapping - #[wrapper] *) + #[wrapper] HB.mixin Record IsHUPreFunctor T of Cat T & H2Cat T := { h2u_prefunctor : IsPreFunctor T (HHomSet T) (@UnitF T) }. -(* Unset Universe Checking. *) -HB.structure Definition HUPreFunctor : Set := - {C of IsHUPreFunctor C}. +HB.structure Definition HUPreFunctor : Set := {C of IsHUPreFunctor C}. Set Universe Checking. -(* {T of Cat T & H2Cat T & H2FQuiver T & - IsPreFunctor _ (HHomSet _) (@UnitF T)}. *) -(* unit functor. FAILS *) Unset Universe Checking. -(* major problems - #[wrapper] *) -Fail HB.mixin Record HUPreFunctor_IsFunctor T of Cat T & HUPreFunctor T := { + #[wrapper] +HB.mixin Record HUPreFunctor_IsFunctor T of Cat T & HUPreFunctor T := { h2u_functor : PreFunctor_IsFunctor T (HHomSet T) (@UnitF T) }. -Fail HB.structure Definition HUFunctor : Set := {C of HUPreFunctor_IsFunctor C}. +HB.structure Definition HUFunctor : Set := {C of HUPreFunctor_IsFunctor C}. Set Universe Checking. -(* double category (unit functor to be added) *) +(* double category *) Unset Universe Checking. HB.structure Definition DCat : Set := - {D of HSPreFunctor_IsFunctor D & HTPreFunctor_IsFunctor D }. + {D of HSPreFunctor_IsFunctor D & HTPreFunctor_IsFunctor D & + HUPreFunctor_IsFunctor D}. Set Universe Checking. (* 2-morphisms *) From d0014cefc7c4406026f6ba0699db2adda7362ebe Mon Sep 17 00:00:00 2001 From: ptorrx Date: Fri, 27 Oct 2023 15:00:59 +0200 Subject: [PATCH 075/147] encat.v: adding horizontal cell composition (tough) --- theories/encat.v | 97 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 87 insertions(+), 10 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index c51eb2f47..b3ad4de25 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1094,17 +1094,30 @@ Set Universe Checking. (*** DOUBLE CATEGORIES (REVISED) *) (* A quiver from which horizontal morphisms arise (just a copy of quiver) *) -HB.mixin Record IsHQuiver C := { hhom : C -> C -> U }. +HB.mixin Record IsHQuiver C := { + hhom : C -> C -> U + }. Unset Universe Checking. #[short(type="hquiver")] HB.structure Definition HQuiver : Set := { C of IsHQuiver C }. Set Universe Checking. -(* domain-specific sigma-type to represent the 2-objects *) +(* we need horizontal morphisms to form at least a precategory *) +HB.mixin Record HQuiver_IsHPreCat C of HQuiver C := { + hidmap : forall (a : C), hhom a a; + hcomp : forall (a b c : C), hhom a b -> hhom b c -> hhom a c; +}. +Unset Universe Checking. +#[short(type="hprecat")] +HB.structure Definition HPreCat : Set := { C of HQuiver_IsHPreCat C }. +Set Universe Checking. + +(* domain-specific sigma-type to represent the 2-objects + (reified horizontal morphisms) *) Record Total2 T (h: T -> T -> U) : Type := HO { source : T; target : T; - this_hom : h source target }. + this_morph : h source target }. (* needed to identify HHomSet as lifter *) HB.tag Definition HHomSet (C: hquiver) := Total2 (@hhom C). @@ -1112,13 +1125,48 @@ HB.tag Definition HHomSet (C: hquiver) := Total2 (@hhom C). (* A quiver from which 2-morphisms arise as arrows between 2-objects (i.e. horizontal morphisms) *) #[wrapper] -HB.mixin Record IsH2Quiver T of HQuiver T := { +HB.mixin Record IsH2Quiver T of HPreCat T := { h2quiver : IsQuiver (@HHomSet T) }. Unset Universe Checking. #[short(type="h2quiver")] HB.structure Definition H2Quiver : Set := { C of IsH2Quiver C }. Set Universe Checking. +(* gives left and right edges of a 2-cell (i.e. the vertical + morphisms associated with the 2-morphism) *) +HB.mixin Record IsH2Grid T of Quiver T & H2Quiver T := { + h2left_edge : forall a b c d: T, + forall (h1: hhom a b) (h2: hhom c d), + @hom (@HHomSet T) (@HO T (@hhom T) a b h1) + (@HO T (@hhom T) c d h2) -> @hom T a c ; + h2right_edge : forall a b c d: T, + forall (h1: hhom a b) (h2: hhom c d), + @hom (@HHomSet T) (@HO T (@hhom T) a b h1) + (@HO T (@hhom T) c d h2) -> @hom T b d +}. +Unset Universe Checking. +#[short(type="h2grid")] +HB.structure Definition H2Grid : Set := { C of IsH2Grid C }. +Set Universe Checking. + +(* adding the map to define (1) the unit functor D0 -> D1 + and (2) composition D1 *d0 D1 -> D1 *) +HB.mixin Record IsH2FQuiver T of H2Quiver T := { + h2unit_map: forall x:T, HHomSet T ; + h2unit_map_eq: forall x:T, h2unit_map x = + @HO T (@hhom T) x x (hidmap x) ; + h2comp_map: HHomSet T * HHomSet T -> HHomSet T ; + h2comp_map_eq: forall (a b c: T) (h1: hhom a b) (h2: hhom b c), + let x := @HO T (@hhom T) a b h1 + in let y := @HO T (@hhom T) b c h2 + in let z := @HO T (@hhom T) a c (hcomp a b c h1 h2) + in h2comp_map (x, y) = z }. +Unset Universe Checking. +#[short(type="h2fquiver")] +HB.structure Definition H2FQuiver : Set := { C of IsH2FQuiver C }. +Set Universe Checking. + +(* (* adding the map to define the unit functor D0 -> D1 *) HB.mixin Record IsH2FQuiver T of H2Quiver T := { h2unit_map: forall x:T, HHomSet T ; @@ -1136,6 +1184,7 @@ Unset Universe Checking. #[short(type="h2fquiver")] HB.structure Definition H2FQuiver : Set := { C of IsH2FQuiver C }. Set Universe Checking. +*) (* Precat based on the H2Quiver (D1). *) Unset Universe Checking. @@ -1155,11 +1204,39 @@ HB.mixin Record IsH2Cat T of H2PreCat T := { HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. Set Universe Checking. -(* Pre-double category (no functors yet): this corresponds to the old -definition *) +(* Pre-double category, with horizontal 2-cell composition *) Unset Universe Checking. +HB.mixin Record IsPreDCat T of Cat T & H2Cat T & H2Grid T := { + h2adjacent : forall (a b c d e f: T), + forall (h1: hhom a b) (h2: hhom b c) (h3: hhom d e) (h4: hhom e f), + forall (hh1: @hom (@HHomSet T) (@HO T (@hhom T) a b h1) + (@HO T (@hhom T) d e h3)) + (hh2: @hom (@HHomSet T) (@HO T (@hhom T) b c h2) + (@HO T (@hhom T) e f h4)), + h2right_edge a b d e h1 h3 hh1 = + h2left_edge b c e f h2 h4 hh2 ; + + h2comp : forall (h1 h2 h3 h4: HHomSet T), + forall (hh1: h1 ~> h2) (hh2: h3 ~> h4), + h2comp_map (h1,h3) ~> h2comp_map (h2,h4) ; + +(* + h2comp_eq : forall (a b c d e f: T), + forall (h1: hhom a b) (h2: hhom b c) (h3: hhom d e) (h4: hhom e f), + forall (hh1: @hom (@HHomSet T) (@HO T (@hhom T) a b h1) + (@HO T (@hhom T) d e h3)) + (hh2: @hom (@HHomSet T) (@HO T (@hhom T) b c h2) + (@HO T (@hhom T) e f h4)), + h2adjacent a b c d e f h1 h2 hh1 hh2 -> + let h1' := (@HO T (@hhom T) a b h1) + in let h2' := (@HO T (@hhom T) b c h2) + in let h3' := (@HO T (@hhom T) d e h3) + in let h4' := (@HO T (@hhom T) e f h4) + h2comp h1' h2' h3' h4' hh1 hh2 = +*) + }. #[short(type="predcat")] -HB.structure Definition PreDCat : Set := { D of Cat D & H2Cat D }. +HB.structure Definition PreDCat : Set := { D of IsPreDCat D }. Set Universe Checking. (* source functor: D1 -> D0 *) @@ -1175,7 +1252,7 @@ HB.tag Definition UnitF (C: h2fquiver) := T is the quiver of 1-morphisms. *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsHSPreFunctor T of Cat T & H2Cat T := { +HB.mixin Record IsHSPreFunctor T of Cat T & PreDCat T := { h2s_prefunctor : IsPreFunctor (HHomSet T) T (@Source T) }. HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. Set Universe Checking. @@ -1183,7 +1260,7 @@ Set Universe Checking. (* target prefunctor. *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsHTPreFunctor T of Cat T & H2Cat T := { +HB.mixin Record IsHTPreFunctor T of Cat T & PreDCat T := { h2t_prefunctor : IsPreFunctor (HHomSet T) T (@Target T) }. HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. Set Universe Checking. @@ -1207,7 +1284,7 @@ Set Universe Checking. (* unit prefunctor. *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsHUPreFunctor T of Cat T & H2Cat T := { +HB.mixin Record IsHUPreFunctor T of Cat T & PreDCat T := { h2u_prefunctor : IsPreFunctor T (HHomSet T) (@UnitF T) }. HB.structure Definition HUPreFunctor : Set := {C of IsHUPreFunctor C}. Set Universe Checking. From 5c9bac2785f20a60edf2bc6e52a6e1cf98957691 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Fri, 3 Nov 2023 13:33:23 +0100 Subject: [PATCH 076/147] updated encav.v --- theories/encat.v | 122 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 107 insertions(+), 15 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index b3ad4de25..97208b13a 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1102,28 +1102,39 @@ Unset Universe Checking. HB.structure Definition HQuiver : Set := { C of IsHQuiver C }. Set Universe Checking. +(* domain-specific sigma-type to represent the type of reified morphims + (needed for 2-objects, i.e. horizontal morphisms) *) +Record Total2 T (h: T -> T -> U) : Type := HO { + source : T; + target : T; + this_morph : h source target }. + +(* the type of (reified) horizontal morphisms. + HB.tag needed to identify HHomSet as lifter *) +HB.tag Definition HHomSet (C: hquiver) := Total2 (@hhom C). + +(* the type of (reified) vertical morphisms. + HB.tag needed to identify HHomSet as lifter *) +HB.tag Definition VHomSet (C: quiver) := Total2 (@hom C). + +Record D1_prod T := { + d1_first : @HHomSet T ; + d1_second : @HHomSet T ; + d1_adjacent : target d1_first = source d1_second +}. + (* we need horizontal morphisms to form at least a precategory *) HB.mixin Record HQuiver_IsHPreCat C of HQuiver C := { hidmap : forall (a : C), hhom a a; - hcomp : forall (a b c : C), hhom a b -> hhom b c -> hhom a c; + hcomp : forall d : D1_prod C, + hhom (source (d1_first d)) (target (d1_second d)); }. Unset Universe Checking. #[short(type="hprecat")] HB.structure Definition HPreCat : Set := { C of HQuiver_IsHPreCat C }. Set Universe Checking. -(* domain-specific sigma-type to represent the 2-objects - (reified horizontal morphisms) *) -Record Total2 T (h: T -> T -> U) : Type := HO { - source : T; - target : T; - this_morph : h source target }. - -(* needed to identify HHomSet as lifter *) -HB.tag Definition HHomSet (C: hquiver) := Total2 (@hhom C). - -(* A quiver from which 2-morphisms arise as arrows between 2-objects - (i.e. horizontal morphisms) *) +(* 2-morphism quiver *) #[wrapper] HB.mixin Record IsH2Quiver T of HPreCat T := { h2quiver : IsQuiver (@HHomSet T) }. @@ -1132,8 +1143,85 @@ Unset Universe Checking. HB.structure Definition H2Quiver : Set := { C of IsH2Quiver C }. Set Universe Checking. +(* 2-morphisms (D1 morphisms) *) +Definition h2hom (D: H2Quiver.type) := @hom (@HHomSet D). + +(* The type of (reified) D1 morphisms (defined from homsets between + horizontal morphisms *) +HB.tag Definition H2HomSet (C: H2Quiver.type) := Total2 (@hom (@HHomSet C)). + +HB.mixin Record IsH2Grid T of Quiver T & H2Quiver T := { + h2left_edge : H2HomSet T -> VHomSet T ; + h2right_edge : H2HomSet T -> VHomSet T +}. +Unset Universe Checking. +#[short(type="h2grid")] +HB.structure Definition H2Grid : Set := { C of IsH2Grid C }. +Set Universe Checking. + +(* adding the map to define (1) the unit functor D0 -> D1 + and (2) composition D1 *d0 D1 -> D1 *) +HB.mixin Record IsH2FQuiver T of H2Quiver T := { + h2unit_map: forall x:T, HHomSet T ; + h2unit_map_eq: forall x:T, h2unit_map x = + @HO T (@hhom T) x x (hidmap x) ; + h2comp_map: D1_prod T -> HHomSet T ; + h2comp_map_eq: forall d: D1_prod T, h2comp_map d = + @HO T (@hhom T) (source (d1_first d)) (target (d1_second d)) (hcomp d) +}. +Unset Universe Checking. +#[short(type="h2fquiver")] +HB.structure Definition H2FQuiver : Set := { C of IsH2FQuiver C }. +Set Universe Checking. + +(* Precat based on the H2Quiver (D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsH2PreCat T of H2FQuiver T := { + h2precat : Quiver_IsPreCat (@HHomSet T) }. +#[short(type="h2precat")] +HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. +Set Universe Checking. + +(* The category based on the H2Quiver (D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsH2Cat T of H2PreCat T := { + h2cat : PreCat_IsCat (@HHomSet T) }. +#[short(type="h2cat")] +HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. +Set Universe Checking. + +Unset Universe Checking. +#[short(type="predcat")] +HB.structure Definition PreDCat : Set := { D of H2Cat D & H2Grid D }. +Set Universe Checking. + + +Record D2_prod T := { + d2_first : @H2HomSet T ; + d2_second : @H2HomSet T ; + d2_adjacent : target d2_first = source d2_second +}. + +(* probably not needed *) +HB.mixin Record HQuiver_IsH2PreCat' C of H2Grid C := { + h2idmap : forall (a : C), hhom a a; + h2comp : forall d : D2_prod C, + h2hom (source (d2_first d)) (target (d2_second d)); +}. +Unset Universe Checking. +#[short(type="hprecat")] +HB.structure Definition H2PreCat' : Set := { C of HQuiver_IsH2PreCat' C }. +Set Universe Checking. + + + +(* (* gives left and right edges of a 2-cell (i.e. the vertical - morphisms associated with the 2-morphism) *) + morphisms associated with the 2-morphism). + these should be functors + *) HB.mixin Record IsH2Grid T of Quiver T & H2Quiver T := { h2left_edge : forall a b c d: T, forall (h1: hhom a b) (h2: hhom c d), @@ -1149,6 +1237,7 @@ Unset Universe Checking. HB.structure Definition H2Grid : Set := { C of IsH2Grid C }. Set Universe Checking. +(* (* adding the map to define (1) the unit functor D0 -> D1 and (2) composition D1 *d0 D1 -> D1 *) HB.mixin Record IsH2FQuiver T of H2Quiver T := { @@ -1165,7 +1254,7 @@ Unset Universe Checking. #[short(type="h2fquiver")] HB.structure Definition H2FQuiver : Set := { C of IsH2FQuiver C }. Set Universe Checking. - +*) (* (* adding the map to define the unit functor D0 -> D1 *) HB.mixin Record IsH2FQuiver T of H2Quiver T := { @@ -1239,6 +1328,9 @@ HB.mixin Record IsPreDCat T of Cat T & H2Cat T & H2Grid T := { HB.structure Definition PreDCat : Set := { D of IsPreDCat D }. Set Universe Checking. + +*) + (* source functor: D1 -> D0 *) HB.tag Definition Source C := fun (X: HHomSet C) => @source C (@hhom C) X. (* target functor: D1 -> D0 *) From 3fb6dde07254fb39a4d7c4e847095bdfb4ea89b7 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Fri, 3 Nov 2023 21:36:40 +0100 Subject: [PATCH 077/147] updated encav.v; flat version with 4 functors (source, target, horizontal unit and horizontal composition); unital and assoc properties still missing; actual hierarchy to be revised --- theories/encat.v | 256 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 228 insertions(+), 28 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index 97208b13a..7642eed4a 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1109,19 +1109,216 @@ Record Total2 T (h: T -> T -> U) : Type := HO { target : T; this_morph : h source target }. -(* the type of (reified) horizontal morphisms. +(* a sequence of two adjacent morphisms (pullback object) *) +Record GenComp T (h: T -> T -> U) := { + comp_first : @Total2 T h ; + comp_second : @Total2 T h ; + comp_adjacent : target comp_first = source comp_second +}. + +(* the set of horizontal morphisms. HB.tag needed to identify HHomSet as lifter *) HB.tag Definition HHomSet (C: hquiver) := Total2 (@hhom C). -(* the type of (reified) vertical morphisms. - HB.tag needed to identify HHomSet as lifter *) -HB.tag Definition VHomSet (C: quiver) := Total2 (@hom C). +Definition HComp (C: hquiver) := GenComp (@hhom C). + +(* source functor: D1 -> D0 *) +HB.tag Definition HSource C := fun (X: HHomSet C) => @source C (@hhom C) X. +(* target functor: D1 -> D0 *) +HB.tag Definition HTarget C := fun (X: HHomSet C) => @target C (@hhom C) X. + +(* 2-cell quiver condition (we need to actually build the quiver) *) +#[wrapper] +HB.mixin Record IsC2QuiverCond T of HQuiver T := { + c2quiver : IsQuiver (@HHomSet T) }. +Unset Universe Checking. +#[short(type="c2quivercond")] +HB.structure Definition C2QuiverCond : Set := { C of IsC2QuiverCond C }. +Set Universe Checking. + +Unset Universe Checking. +#[short(type="c2prequiver")] +HB.structure Definition C2PreQuiver : Set := + { C of Quiver C & HQuiver C & IsC2QuiverCond C }. +Set Universe Checking. + +(* pullback category condition *) +#[wrapper] +HB.mixin Record IsHCompCat T of Cat T & C2PreQuiver T := { + hcompcat : Cat (HComp T) }. +Unset Universe Checking. +#[short(type="hcompcat")] +HB.structure Definition HCompCat : Set := { C of IsHCompCat C }. +Set Universe Checking. + +HB.mixin Record IsC2Quiver T of C2PreQuiver T & HCompCat T := { + c2unit : T -> HHomSet T ; + c2comp : HComp T -> HHomSet T ; + + c2unit_eq1 : forall a: T, a = source (c2unit a) ; + c2unit_eq2 : forall a: T, a = target (c2unit a) ; + + c2comp_eq1 : forall d, source (c2comp d) = source (comp_first d) ; + c2comp_eq2 : forall d, source (c2comp d) = source (comp_second d) ; +}. +Unset Universe Checking. +#[short(type="c2quiver")] +HB.structure Definition C2Quiver : Set := { C of IsC2Quiver C }. +Set Universe Checking. + +(* Precat based on the C2Quiver (D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsC2PreCatCond T of C2PreQuiver T := { + c2precatcond : Quiver_IsPreCat (@HHomSet T) }. +#[short(type="c2precatcond")] +HB.structure Definition C2PreCatCond : Set := { C of IsC2PreCatCond C }. +Set Universe Checking. + +(* The category based on the H2Quiver (D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsC2Cat T of C2PreCatCond T := { + c2catcond : PreCat_IsCat (@HHomSet T) }. +#[short(type="h2cat")] +HB.structure Definition C2Cat : Set := { C of IsC2Cat C }. +Set Universe Checking. + +(* unit functor: D0 -> D1 *) +HB.tag Definition UnitF (C: c2quiver) := + fun (x: C2Quiver.sort C) => @c2unit C x. +(* composition functor: D1 * D1 -> D1 *) +HB.tag Definition CompF (C: c2quiver) := + fun (x: HComp C) => @c2comp C x. + +(* source prefunctor. + HHomSet T is the quiver of the 2-morphisms, thanks to H2Quiver. + T is the quiver of 1-morphisms. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHSPreFunctor T of Cat T & C2Cat T & HCompCat T := { + h2s_prefunctor : IsPreFunctor (HHomSet T) T (@HSource T) }. +HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. +Set Universe Checking. + +(* target prefunctor. *) +Unset Universe Checking. +#[wrapper] + HB.mixin Record IsHTPreFunctor T of Cat T & C2Cat T & HCompCat T & + HSPreFunctor T := { + h2t_prefunctor : IsPreFunctor (HHomSet T) T (@HTarget T) }. +HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. +Set Universe Checking. + +(* source functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record HSPreFunctor_IsFunctor T of HSPreFunctor T := { + h2s_functor : PreFunctor_IsFunctor (HHomSet T) T (@HSource T) }. +HB.structure Definition HSFunctor : Set := {C of HSPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* target functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record HTPreFunctor_IsFunctor T of HTPreFunctor T := { + h2t_functor : PreFunctor_IsFunctor (HHomSet T) T (@HTarget T) }. +HB.structure Definition HTFunctor : Set := {C of HTPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* unit prefunctor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHUPreFunctor T of + C2Quiver T & Cat T & C2Cat T & HSPreFunctor T := + { h2u_prefunctor : IsPreFunctor T (HHomSet T) (@UnitF T) }. +HB.structure Definition HUPreFunctor : Set := {C of IsHUPreFunctor C}. +Set Universe Checking. + +Unset Universe Checking. +#[wrapper] +HB.mixin Record HUPreFunctor_IsFunctor T of HUPreFunctor T := { + h2u_functor : PreFunctor_IsFunctor T (HHomSet T) (@UnitF T) }. +HB.structure Definition HUFunctor : Set := {C of HUPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* composition prefunctor *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHCPreFunctor T of + C2Quiver T & Cat T & C2Cat T & HSPreFunctor T & HUPreFunctor T := + { h2c_prefunctor : IsPreFunctor (HComp T) (HHomSet T) (@CompF T) }. +HB.structure Definition HCPreFunctor : Set := {C of IsHCPreFunctor C}. +Set Universe Checking. + +Unset Universe Checking. +#[wrapper] +HB.mixin Record HCPreFunctor_IsFunctor T of HCPreFunctor T := { + h2c_functor : PreFunctor_IsFunctor (HComp T) (HHomSet T) (@CompF T) }. +HB.structure Definition HCFunctor : Set := {C of HCPreFunctor_IsFunctor C}. +Set Universe Checking. + + + + +(*********************************************************************) +(**** GARBAGE ****************************************************) + + + + +(* source prefunctor. + HHomSet T is the quiver of the 2-morphisms, thanks to H2Quiver. + T is the quiver of 1-morphisms. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHSPreFunctor T of Cat T & H2Cat T := { + h2s_prefunctor : IsPreFunctor (HHomSet T) T (@Source T) }. +HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. +Set Universe Checking. + +(* target prefunctor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHTPreFunctor T of Cat T & H2Cat T := { + h2t_prefunctor : IsPreFunctor (HHomSet T) T (@Target T) }. +HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. +Set Universe Checking. + + + +HB.mixin Record IsC2Quiver T of Quiver T & PreC2Quiver T := { + c2left : C2HomSet T -> VHomSet T ; + c2right : C2HomSet T -> VHomSet T ; + + c2unit : forall x:T, HHomSet T ; + + c2left_eq1 : forall d: C2HomSet T, + source (source d) = source (c2left d) ; + c2left_eq2 : forall d: C2HomSet T, + source (target d) = target (c2left d) ; + c2right_eq1 : forall d: C2HomSet T, + target (source d) = source (c2right d) ; + c2right_eq2 : forall d: C2HomSet T, + target (target d) = target (c2right d) ; + + c2unit_eq : forall a: T, + let h := c2unit a in source h = target h ; + +}. +Unset Universe Checking. +#[short(type="c2quiver")] +HB.structure Definition C2Quiver : Set := { C of IsC2Quiver C }. +Set Universe Checking. + +(* left edge functor: D1 -> D0 *) +HB.tag Definition C2Left (C: C2Quiver.type) := + fun (X: C2HomSet C) => @c2left C X. +(* right edge functor: D1 -> D0 *) +HB.tag Definition C2Right (C: C2Quiver.type) := + fun (X: C2HomSet C) => @c2right C X. + -Record D1_prod T := { - d1_first : @HHomSet T ; - d1_second : @HHomSet T ; - d1_adjacent : target d1_first = source d1_second -}. (* we need horizontal morphisms to form at least a precategory *) HB.mixin Record HQuiver_IsHPreCat C of HQuiver C := { @@ -1134,21 +1331,6 @@ Unset Universe Checking. HB.structure Definition HPreCat : Set := { C of HQuiver_IsHPreCat C }. Set Universe Checking. -(* 2-morphism quiver *) -#[wrapper] -HB.mixin Record IsH2Quiver T of HPreCat T := { - h2quiver : IsQuiver (@HHomSet T) }. -Unset Universe Checking. -#[short(type="h2quiver")] -HB.structure Definition H2Quiver : Set := { C of IsH2Quiver C }. -Set Universe Checking. - -(* 2-morphisms (D1 morphisms) *) -Definition h2hom (D: H2Quiver.type) := @hom (@HHomSet D). - -(* The type of (reified) D1 morphisms (defined from homsets between - horizontal morphisms *) -HB.tag Definition H2HomSet (C: H2Quiver.type) := Total2 (@hom (@HHomSet C)). HB.mixin Record IsH2Grid T of Quiver T & H2Quiver T := { h2left_edge : H2HomSet T -> VHomSet T ; @@ -1161,7 +1343,7 @@ Set Universe Checking. (* adding the map to define (1) the unit functor D0 -> D1 and (2) composition D1 *d0 D1 -> D1 *) -HB.mixin Record IsH2FQuiver T of H2Quiver T := { +HB.mixin Record IsH2FQuiver T of H2Quiver T & H2Grid T & PreCat T := { h2unit_map: forall x:T, HHomSet T ; h2unit_map_eq: forall x:T, h2unit_map x = @HO T (@hhom T) x x (hidmap x) ; @@ -1192,11 +1374,12 @@ HB.mixin Record IsH2Cat T of H2PreCat T := { HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. Set Universe Checking. +(* Unset Universe Checking. #[short(type="predcat")] HB.structure Definition PreDCat : Set := { D of H2Cat D & H2Grid D }. Set Universe Checking. - +*) Record D2_prod T := { d2_first : @H2HomSet T ; @@ -1344,7 +1527,7 @@ HB.tag Definition UnitF (C: h2fquiver) := T is the quiver of 1-morphisms. *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsHSPreFunctor T of Cat T & PreDCat T := { +HB.mixin Record IsHSPreFunctor T of Cat T & H2Cat T := { h2s_prefunctor : IsPreFunctor (HHomSet T) T (@Source T) }. HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. Set Universe Checking. @@ -1352,11 +1535,16 @@ Set Universe Checking. (* target prefunctor. *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsHTPreFunctor T of Cat T & PreDCat T := { +HB.mixin Record IsHTPreFunctor T of Cat T & H2Cat T := { h2t_prefunctor : IsPreFunctor (HHomSet T) T (@Target T) }. HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. Set Universe Checking. + + +HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. +Set Universe Checking. + (* source functor. *) Unset Universe Checking. #[wrapper] @@ -1381,6 +1569,18 @@ HB.mixin Record IsHUPreFunctor T of Cat T & PreDCat T := { HB.structure Definition HUPreFunctor : Set := {C of IsHUPreFunctor C}. Set Universe Checking. + +Unset Universe Checking. + #[wrapper] +HB.mixin Record HUPreFunctor_IsFunctor T of Cat T & HUPreFunctor T := { + h2u_functor : PreFunctor_IsFunctor T (HHomSet T) (@UnitF T) }. + HB.structure Definition HUFunctor : Set := {T of + Cat T & HUPreFunctor T & + PreFunctor_IsFunctor T (HHomSet T) (@UnitF T) + }. +Set Universe Checking. + + Unset Universe Checking. #[wrapper] HB.mixin Record HUPreFunctor_IsFunctor T of Cat T & HUPreFunctor T := { From e2536bcc4212a024390deb5ccb910fedf33c23e8 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Mon, 6 Nov 2023 18:21:59 +0100 Subject: [PATCH 078/147] updated encav.v; still missing: associator; product category to be fixed --- theories/encat.v | 102 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 88 insertions(+), 14 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index 7642eed4a..e2835f73d 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1102,15 +1102,16 @@ Unset Universe Checking. HB.structure Definition HQuiver : Set := { C of IsHQuiver C }. Set Universe Checking. -(* domain-specific sigma-type to represent the type of reified morphims +(* domain-specific sigma-type to represent the set of morphims (needed for 2-objects, i.e. horizontal morphisms) *) Record Total2 T (h: T -> T -> U) : Type := HO { source : T; target : T; this_morph : h source target }. -(* a sequence of two adjacent morphisms (pullback object) *) -Record GenComp T (h: T -> T -> U) := { +(* a sequence of two adjacent morphisms (pullback object), + which we can use to represent composition *) +Record GenComp' T (h: T -> T -> U) := GCmp { comp_first : @Total2 T h ; comp_second : @Total2 T h ; comp_adjacent : target comp_first = source comp_second @@ -1120,14 +1121,29 @@ Record GenComp T (h: T -> T -> U) := { HB.tag needed to identify HHomSet as lifter *) HB.tag Definition HHomSet (C: hquiver) := Total2 (@hhom C). +(* horizontal morphism composition type. ultimately though, SHOULD + DEPEND ON D0 (hence on 'Quiver T' and 'Quiver (T * T)) *) +Definition HComp' (C: hquiver) := GenComp' (@hhom C). + +Record GenComp T (h: T -> T -> U) := GC { + c_one : T; + c_two : T ; + c_three : T; + c_first : h c_one c_two ; + c_second : h c_two c_three +}. + Definition HComp (C: hquiver) := GenComp (@hhom C). -(* source functor: D1 -> D0 *) + +(* source functor: D1 -> D0. + defined as object-level function, by functoriality lifted to a + (2-cell, vertical) morphism-level one *) HB.tag Definition HSource C := fun (X: HHomSet C) => @source C (@hhom C) X. -(* target functor: D1 -> D0 *) +(* target functor: D1 -> D0. *) HB.tag Definition HTarget C := fun (X: HHomSet C) => @target C (@hhom C) X. -(* 2-cell quiver condition (we need to actually build the quiver) *) +(* 2-cell quiver condition *) #[wrapper] HB.mixin Record IsC2QuiverCond T of HQuiver T := { c2quiver : IsQuiver (@HHomSet T) }. @@ -1136,13 +1152,15 @@ Unset Universe Checking. HB.structure Definition C2QuiverCond : Set := { C of IsC2QuiverCond C }. Set Universe Checking. +(* technical *) Unset Universe Checking. #[short(type="c2prequiver")] HB.structure Definition C2PreQuiver : Set := { C of Quiver C & HQuiver C & IsC2QuiverCond C }. Set Universe Checking. -(* pullback category condition *) +(* pullback category condition (i.e. (HComp T) is a category). + requires T to be a category, and (HHomSet T) to be a quiver *) #[wrapper] HB.mixin Record IsHCompCat T of Cat T & C2PreQuiver T := { hcompcat : Cat (HComp T) }. @@ -1151,6 +1169,21 @@ Unset Universe Checking. HB.structure Definition HCompCat : Set := { C of IsHCompCat C }. Set Universe Checking. +(* c2unit - horizontal unit functor. + + c2comp - horizontal composition functor. + + Both specified as object-level functions, to be lifted by + functoriality to morphism-level ones. + + At the object level, c2unit gives a horizontal identity morphism + for each D0 object. At the morphism level, it gives horizontal + 2-cell unit for each vertical morphism. + + In the case of HComp, relying on functoriality requires some care + in defining the pullback category, making sure that adjacency at + the object-level (between horizontal morphisms) is matched by + adjacency at the morphism-level (between 2-cells). *) HB.mixin Record IsC2Quiver T of C2PreQuiver T & HCompCat T := { c2unit : T -> HHomSet T ; c2comp : HComp T -> HHomSet T ; @@ -1158,15 +1191,15 @@ HB.mixin Record IsC2Quiver T of C2PreQuiver T & HCompCat T := { c2unit_eq1 : forall a: T, a = source (c2unit a) ; c2unit_eq2 : forall a: T, a = target (c2unit a) ; - c2comp_eq1 : forall d, source (c2comp d) = source (comp_first d) ; - c2comp_eq2 : forall d, source (c2comp d) = source (comp_second d) ; + c2comp_eq1 : forall d, source (c2comp d) = c_one d ; + c2comp_eq2 : forall d, target (c2comp d) = c_three d ; }. Unset Universe Checking. #[short(type="c2quiver")] HB.structure Definition C2Quiver : Set := { C of IsC2Quiver C }. Set Universe Checking. -(* Precat based on the C2Quiver (D1). *) +(* Precat based on the C2Quiver (i.e. precategory D1). *) Unset Universe Checking. #[wrapper] HB.mixin Record IsC2PreCatCond T of C2PreQuiver T := { @@ -1175,7 +1208,7 @@ HB.mixin Record IsC2PreCatCond T of C2PreQuiver T := { HB.structure Definition C2PreCatCond : Set := { C of IsC2PreCatCond C }. Set Universe Checking. -(* The category based on the H2Quiver (D1). *) +(* The category based on the H2Quiver (i.e. category D1). *) Unset Universe Checking. #[wrapper] HB.mixin Record IsC2Cat T of C2PreCatCond T := { @@ -1235,6 +1268,7 @@ HB.mixin Record IsHUPreFunctor T of HB.structure Definition HUPreFunctor : Set := {C of IsHUPreFunctor C}. Set Universe Checking. +(* unit functor. *) Unset Universe Checking. #[wrapper] HB.mixin Record HUPreFunctor_IsFunctor T of HUPreFunctor T := { @@ -1251,6 +1285,7 @@ HB.mixin Record IsHCPreFunctor T of HB.structure Definition HCPreFunctor : Set := {C of IsHCPreFunctor C}. Set Universe Checking. +(* composition functor *) Unset Universe Checking. #[wrapper] HB.mixin Record HCPreFunctor_IsFunctor T of HCPreFunctor T := { @@ -1258,15 +1293,54 @@ HB.mixin Record HCPreFunctor_IsFunctor T of HCPreFunctor T := { HB.structure Definition HCFunctor : Set := {C of HCPreFunctor_IsFunctor C}. Set Universe Checking. - +(* 2-morphisms *) +Definition c2hom (D: C2Quiver.type) := @hom (@HHomSet D). + +(* The set of D1 morphisms *) +HB.tag Definition C2HomSet (C: C2Quiver.type) := Total2 (@c2hom C). + +(* horizontal 2-cell unit (maps vertical morphisms to horizontally + unitary 2-cells) *) +Definition HC2Unit (T: HUFunctor.type) (a b: T) (m: @hom T a b) : + c2hom (UnitF a) (UnitF b) := @Fhom _ _ (@UnitF T) a b m. + +(* horizontal 2-cell composition: maps two adjecent pairs of + horizontal morphisms (a and b) and a pullback-category morphism + between them (m, which basically gives two adjecent cells) to a + 2-cell morphism between the horizontal composition (CompF) of each + pair *) +Definition HC2Comp (T: HCFunctor.type) (a b: HComp T) + (m: @hom (HComp T) a b) : + c2hom (CompF a) (CompF b) := @Fhom _ _ (@CompF T) a b m. + +Unset Universe Checking. +HB.mixin Record IsDCat T of HCFunctor T & HQuiver T := { + left_unital : forall (a b c d: T) (r: @hhom T a c) (s: @hhom T b d), + forall (ha: @hhom T a a) (hb: @hhom T b b), + @hom (HHomSet T) (@HO T (@hhom T) a c r) (@HO T (@hhom T) b d s) = + @hom (HHomSet T) (c2comp (@GC T _ a a c ha r)) + (c2comp (@GC T _ b b d hb s)) ; + + right_unital : forall (a b c d: T) (r: @hhom T a c) (s: @hhom T b d), + forall (ha: @hhom T c c) (hb: @hhom T d d), + @hom (HHomSet T) (@HO T (@hhom T) a c r) (@HO T (@hhom T) b d s) = + @hom (HHomSet T) (c2comp (@GC T _ a c c r ha)) + (c2comp (@GC T _ b d d s hb)) ; + +(* associator : forall (a b c d: T) (r: @hhom T a c) (s: @hhom T b d), + forall (ha: @hhom T c c) (hb: @hhom T d d), + @hom (HHomSet T) (@HO T (@hhom T) a c r) (@HO T (@hhom T) b d s) = + @hom (HHomSet T) (c2comp (@GC T _ a c c r ha)) + (c2comp (@GC T _ b d d s hb)) ; +*) + +}. (*********************************************************************) (**** GARBAGE ****************************************************) - - (* source prefunctor. HHomSet T is the quiver of the 2-morphisms, thanks to H2Quiver. T is the quiver of 1-morphisms. *) From 9c092de67a6783ed8074a9c9895353362e939262 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Tue, 7 Nov 2023 14:50:44 +0100 Subject: [PATCH 079/147] updated encav.v; nlab-style definition of double categories; still missing - proof that product category is a category (does not need to be assumed) --- theories/encat.v | 75 ++++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 34 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index e2835f73d..c4503c2a0 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1109,33 +1109,10 @@ Record Total2 T (h: T -> T -> U) : Type := HO { target : T; this_morph : h source target }. -(* a sequence of two adjacent morphisms (pullback object), - which we can use to represent composition *) -Record GenComp' T (h: T -> T -> U) := GCmp { - comp_first : @Total2 T h ; - comp_second : @Total2 T h ; - comp_adjacent : target comp_first = source comp_second -}. - (* the set of horizontal morphisms. HB.tag needed to identify HHomSet as lifter *) HB.tag Definition HHomSet (C: hquiver) := Total2 (@hhom C). -(* horizontal morphism composition type. ultimately though, SHOULD - DEPEND ON D0 (hence on 'Quiver T' and 'Quiver (T * T)) *) -Definition HComp' (C: hquiver) := GenComp' (@hhom C). - -Record GenComp T (h: T -> T -> U) := GC { - c_one : T; - c_two : T ; - c_three : T; - c_first : h c_one c_two ; - c_second : h c_two c_three -}. - -Definition HComp (C: hquiver) := GenComp (@hhom C). - - (* source functor: D1 -> D0. defined as object-level function, by functoriality lifted to a (2-cell, vertical) morphism-level one *) @@ -1143,7 +1120,7 @@ HB.tag Definition HSource C := fun (X: HHomSet C) => @source C (@hhom C) X. (* target functor: D1 -> D0. *) HB.tag Definition HTarget C := fun (X: HHomSet C) => @target C (@hhom C) X. -(* 2-cell quiver condition *) +(* 2-cell quiver condition. *) #[wrapper] HB.mixin Record IsC2QuiverCond T of HQuiver T := { c2quiver : IsQuiver (@HHomSet T) }. @@ -1159,6 +1136,16 @@ HB.structure Definition C2PreQuiver : Set := { C of Quiver C & HQuiver C & IsC2QuiverCond C }. Set Universe Checking. +Record GenComp T (h: T -> T -> U) := GC { + c_one : T; + c_two : T ; + c_three : T; + c_first : h c_one c_two ; + c_second : h c_two c_three +}. + +Definition HComp (C: hquiver) := GenComp (@hhom C). + (* pullback category condition (i.e. (HComp T) is a category). requires T to be a category, and (HHomSet T) to be a quiver *) #[wrapper] @@ -1199,7 +1186,9 @@ Unset Universe Checking. HB.structure Definition C2Quiver : Set := { C of IsC2Quiver C }. Set Universe Checking. -(* Precat based on the C2Quiver (i.e. precategory D1). *) +(* Precat based on the C2Quiver (i.e. precategory D1). Gives: + vertical identity morphism. + vertical composition. *) Unset Universe Checking. #[wrapper] HB.mixin Record IsC2PreCatCond T of C2PreQuiver T := { @@ -1319,27 +1308,45 @@ HB.mixin Record IsDCat T of HCFunctor T & HQuiver T := { forall (ha: @hhom T a a) (hb: @hhom T b b), @hom (HHomSet T) (@HO T (@hhom T) a c r) (@HO T (@hhom T) b d s) = @hom (HHomSet T) (c2comp (@GC T _ a a c ha r)) - (c2comp (@GC T _ b b d hb s)) ; + (c2comp (@GC T _ b b d hb s)) ; right_unital : forall (a b c d: T) (r: @hhom T a c) (s: @hhom T b d), forall (ha: @hhom T c c) (hb: @hhom T d d), @hom (HHomSet T) (@HO T (@hhom T) a c r) (@HO T (@hhom T) b d s) = @hom (HHomSet T) (c2comp (@GC T _ a c c r ha)) - (c2comp (@GC T _ b d d s hb)) ; + (c2comp (@GC T _ b d d s hb)) ; + + associator : forall (a0 a1 a2 a3: T) + (h1: @hhom T a0 a1) (h2: @hhom T a1 a2) + (h3: @hhom T a2 a3), + forall (h12: @hhom T a0 a2) (h23: @hhom T a1 a3) (x: HHomSet T), + @HO T (@hhom T) a1 a3 h23 = c2comp (@GC T _ a1 a2 a3 h2 h3) -> + @HO T (@hhom T) a0 a2 h12 = c2comp (@GC T _ a0 a1 a2 h1 h2) -> + let hh1 := c2comp (@GC T _ a0 a1 a3 h1 h23) in + let hh2 := c2comp (@GC T _ a0 a2 a3 h12 h3) in + @hom (HHomSet T) hh1 x = @hom (HHomSet T) hh2 x -(* associator : forall (a b c d: T) (r: @hhom T a c) (s: @hhom T b d), - forall (ha: @hhom T c c) (hb: @hhom T d d), - @hom (HHomSet T) (@HO T (@hhom T) a c r) (@HO T (@hhom T) b d s) = - @hom (HHomSet T) (c2comp (@GC T _ a c c r ha)) - (c2comp (@GC T _ b d d s hb)) ; -*) - }. +#[short(type="dcat")] +HB.structure Definition DCat : Set := { C of IsDCat C }. +Set Universe Checking. + (*********************************************************************) (**** GARBAGE ****************************************************) +(* a sequence of two adjacent morphisms (pullback object), + which we can use to represent composition *) +Record GenComp' T (h: T -> T -> U) := GCmp { + comp_first : @Total2 T h ; + comp_second : @Total2 T h ; + comp_adjacent : target comp_first = source comp_second +}. +(* horizontal morphism composition type. ultimately though, SHOULD + DEPEND ON D0 (hence on 'Quiver T' and 'Quiver (T * T)) *) +Definition HComp' (C: hquiver) := GenComp' (@hhom C). + (* source prefunctor. HHomSet T is the quiver of the 2-morphisms, thanks to H2Quiver. From d158ffcef90de7dc70400f6e42d60f90676abbc4 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Tue, 7 Nov 2023 17:23:53 +0100 Subject: [PATCH 080/147] updated encav.v --- theories/encat.v | 72 +++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index c4503c2a0..18f7a6a7e 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1113,29 +1113,30 @@ Record Total2 T (h: T -> T -> U) : Type := HO { HB.tag needed to identify HHomSet as lifter *) HB.tag Definition HHomSet (C: hquiver) := Total2 (@hhom C). -(* source functor: D1 -> D0. +(* source functor (for horizontal morphisms): D1 -> D0. defined as object-level function, by functoriality lifted to a (2-cell, vertical) morphism-level one *) HB.tag Definition HSource C := fun (X: HHomSet C) => @source C (@hhom C) X. -(* target functor: D1 -> D0. *) +(* target functor (for horizontal morphisms): D1 -> D0. *) HB.tag Definition HTarget C := fun (X: HHomSet C) => @target C (@hhom C) X. -(* 2-cell quiver condition. *) +(* D1 quiver requirement. *) #[wrapper] -HB.mixin Record IsC2QuiverCond T of HQuiver T := { - c2quiver : IsQuiver (@HHomSet T) }. +HB.mixin Record IsD1Quiver T of HQuiver T := { + d1quiver : IsQuiver (@HHomSet T) }. Unset Universe Checking. -#[short(type="c2quivercond")] -HB.structure Definition C2QuiverCond : Set := { C of IsC2QuiverCond C }. +#[short(type="d1quiver")] +HB.structure Definition D1Quiver : Set := { C of IsD1Quiver C }. Set Universe Checking. -(* technical *) +(* all the quivers required by a double category *) Unset Universe Checking. -#[short(type="c2prequiver")] -HB.structure Definition C2PreQuiver : Set := - { C of Quiver C & HQuiver C & IsC2QuiverCond C }. +#[short(type="dquiver")] +HB.structure Definition DQuiver : Set := + { C of Quiver C & HQuiver C & IsD1Quiver C }. Set Universe Checking. +(* used to define composable pairs of morphisms as a set *) Record GenComp T (h: T -> T -> U) := GC { c_one : T; c_two : T ; @@ -1144,12 +1145,13 @@ Record GenComp T (h: T -> T -> U) := GC { c_second : h c_two c_three }. -Definition HComp (C: hquiver) := GenComp (@hhom C). +(* composable pairs of horizontal morphisms as a set *) +HB.tag Definition HComp (C: hquiver) := GenComp (@hhom C). (* pullback category condition (i.e. (HComp T) is a category). requires T to be a category, and (HHomSet T) to be a quiver *) #[wrapper] -HB.mixin Record IsHCompCat T of Cat T & C2PreQuiver T := { +HB.mixin Record IsHCompCat T of Cat T & DQuiver T := { hcompcat : Cat (HComp T) }. Unset Universe Checking. #[short(type="hcompcat")] @@ -1165,13 +1167,13 @@ Set Universe Checking. At the object level, c2unit gives a horizontal identity morphism for each D0 object. At the morphism level, it gives horizontal - 2-cell unit for each vertical morphism. + 2-cell identity for each vertical morphism. In the case of HComp, relying on functoriality requires some care in defining the pullback category, making sure that adjacency at the object-level (between horizontal morphisms) is matched by adjacency at the morphism-level (between 2-cells). *) -HB.mixin Record IsC2Quiver T of C2PreQuiver T & HCompCat T := { +HB.mixin Record IsC2Quiver T of DQuiver T & HCompCat T := { c2unit : T -> HHomSet T ; c2comp : HComp T -> HHomSet T ; @@ -1186,22 +1188,24 @@ Unset Universe Checking. HB.structure Definition C2Quiver : Set := { C of IsC2Quiver C }. Set Universe Checking. -(* Precat based on the C2Quiver (i.e. precategory D1). Gives: - vertical identity morphism. - vertical composition. *) +(* Precategory based on the DQuiver (i.e. precategory D1) - only, + instead of making it inherit from D1Quiver, we make it inherit from + DQuiver. DOES NOT WORK WITH C2Quiver. Gives: + vertical 2-cell identity morphism. + vertical 2-cell composition. *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsC2PreCatCond T of C2PreQuiver T := { - c2precatcond : Quiver_IsPreCat (@HHomSet T) }. -#[short(type="c2precatcond")] -HB.structure Definition C2PreCatCond : Set := { C of IsC2PreCatCond C }. +HB.mixin Record IsC2PreCat T of DQuiver T := { + c2precat : Quiver_IsPreCat (@HHomSet T) }. +#[short(type="c2precat")] +HB.structure Definition C2PreCat : Set := { C of IsC2PreCat C }. Set Universe Checking. -(* The category based on the H2Quiver (i.e. category D1). *) +(* The category based on the DQuiver (i.e. category D1). *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsC2Cat T of C2PreCatCond T := { - c2catcond : PreCat_IsCat (@HHomSet T) }. +HB.mixin Record IsC2Cat T of C2PreCat T := { + c2cat : PreCat_IsCat (@HHomSet T) }. #[short(type="h2cat")] HB.structure Definition C2Cat : Set := { C of IsC2Cat C }. Set Universe Checking. @@ -1226,8 +1230,7 @@ Set Universe Checking. (* target prefunctor. *) Unset Universe Checking. #[wrapper] - HB.mixin Record IsHTPreFunctor T of Cat T & C2Cat T & HCompCat T & - HSPreFunctor T := { + HB.mixin Record IsHTPreFunctor T of HSPreFunctor T := { h2t_prefunctor : IsPreFunctor (HHomSet T) T (@HTarget T) }. HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. Set Universe Checking. @@ -1235,7 +1238,7 @@ Set Universe Checking. (* source functor. *) Unset Universe Checking. #[wrapper] -HB.mixin Record HSPreFunctor_IsFunctor T of HSPreFunctor T := { +HB.mixin Record HSPreFunctor_IsFunctor T of HTPreFunctor T := { h2s_functor : PreFunctor_IsFunctor (HHomSet T) T (@HSource T) }. HB.structure Definition HSFunctor : Set := {C of HSPreFunctor_IsFunctor C}. Set Universe Checking. @@ -1243,7 +1246,7 @@ Set Universe Checking. (* target functor. *) Unset Universe Checking. #[wrapper] -HB.mixin Record HTPreFunctor_IsFunctor T of HTPreFunctor T := { +HB.mixin Record HTPreFunctor_IsFunctor T of HSFunctor T := { h2t_functor : PreFunctor_IsFunctor (HHomSet T) T (@HTarget T) }. HB.structure Definition HTFunctor : Set := {C of HTPreFunctor_IsFunctor C}. Set Universe Checking. @@ -1251,8 +1254,7 @@ Set Universe Checking. (* unit prefunctor. *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsHUPreFunctor T of - C2Quiver T & Cat T & C2Cat T & HSPreFunctor T := +HB.mixin Record IsHUPreFunctor T of C2Quiver T & HTFunctor T := { h2u_prefunctor : IsPreFunctor T (HHomSet T) (@UnitF T) }. HB.structure Definition HUPreFunctor : Set := {C of IsHUPreFunctor C}. Set Universe Checking. @@ -1268,8 +1270,7 @@ Set Universe Checking. (* composition prefunctor *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsHCPreFunctor T of - C2Quiver T & Cat T & C2Cat T & HSPreFunctor T & HUPreFunctor T := +HB.mixin Record IsHCPreFunctor T of HUFunctor T := { h2c_prefunctor : IsPreFunctor (HComp T) (HHomSet T) (@CompF T) }. HB.structure Definition HCPreFunctor : Set := {C of IsHCPreFunctor C}. Set Universe Checking. @@ -1302,8 +1303,10 @@ Definition HC2Comp (T: HCFunctor.type) (a b: HComp T) (m: @hom (HComp T) a b) : c2hom (CompF a) (CompF b) := @Fhom _ _ (@CompF T) a b m. +(* Double cateory complete with properties of horizontal 2-cell + identity and composition *) Unset Universe Checking. -HB.mixin Record IsDCat T of HCFunctor T & HQuiver T := { +HB.mixin Record IsDCat T of HCFunctor T := { left_unital : forall (a b c d: T) (r: @hhom T a c) (s: @hhom T b d), forall (ha: @hhom T a a) (hb: @hhom T b b), @hom (HHomSet T) (@HO T (@hhom T) a c r) (@HO T (@hhom T) b d s) = @@ -1325,7 +1328,6 @@ HB.mixin Record IsDCat T of HCFunctor T & HQuiver T := { let hh1 := c2comp (@GC T _ a0 a1 a3 h1 h23) in let hh2 := c2comp (@GC T _ a0 a2 a3 h12 h3) in @hom (HHomSet T) hh1 x = @hom (HHomSet T) hh2 x - }. #[short(type="dcat")] HB.structure Definition DCat : Set := { C of IsDCat C }. From 5220df583c37282d8cad2cf2e7df9d3954853a2f Mon Sep 17 00:00:00 2001 From: ptorrx Date: Tue, 7 Nov 2023 19:34:29 +0100 Subject: [PATCH 081/147] updated encav.v; improved some definitions --- theories/encat.v | 77 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 11 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index 18f7a6a7e..cac25e7f8 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1123,7 +1123,7 @@ HB.tag Definition HTarget C := fun (X: HHomSet C) => @target C (@hhom C) X. (* D1 quiver requirement. *) #[wrapper] HB.mixin Record IsD1Quiver T of HQuiver T := { - d1quiver : IsQuiver (@HHomSet T) }. + d1_quiver : IsQuiver (@HHomSet T) }. Unset Universe Checking. #[short(type="d1quiver")] HB.structure Definition D1Quiver : Set := { C of IsD1Quiver C }. @@ -1174,14 +1174,17 @@ Set Universe Checking. the object-level (between horizontal morphisms) is matched by adjacency at the morphism-level (between 2-cells). *) HB.mixin Record IsC2Quiver T of DQuiver T & HCompCat T := { + h2unit : forall a: T, @hhom T a a ; + h2comp : forall (a b c: T), + @hhom T a b -> @hhom T b c -> @hhom T a c; + c2unit : T -> HHomSet T ; c2comp : HComp T -> HHomSet T ; - c2unit_eq1 : forall a: T, a = source (c2unit a) ; - c2unit_eq2 : forall a: T, a = target (c2unit a) ; - - c2comp_eq1 : forall d, source (c2comp d) = c_one d ; - c2comp_eq2 : forall d, target (c2comp d) = c_three d ; + c2unit_eq : forall a: T, c2unit a = @HO T (@hhom T) a a (h2unit a) ; + c2comp_eq1 : forall (a b c: T) (h1: @hhom T a b) (h2: @hhom T b c), + c2comp (@GC T (@hhom T) a b c h1 h2) = + @HO T (@hhom T) a c (h2comp a b c h1 h2) }. Unset Universe Checking. #[short(type="c2quiver")] @@ -1303,9 +1306,65 @@ Definition HC2Comp (T: HCFunctor.type) (a b: HComp T) (m: @hom (HComp T) a b) : c2hom (CompF a) (CompF b) := @Fhom _ _ (@CompF T) a b m. -(* Double cateory complete with properties of horizontal 2-cell +(* Double category complete with properties of horizontal 2-cell identity and composition *) Unset Universe Checking. +HB.mixin Record IsDCat T of HCFunctor T := { + left_unital : forall (a0 a1 b0 b1: T) + (r: @hhom T a0 a1) (s: @hhom T b0 b1), + let rr := @HO T (@hhom T) a0 a1 r in + let ss := @HO T (@hhom T) b0 b1 s in + let aa := @h2unit T a0 in + let bb := @h2unit T b0 in + @hom (HHomSet T) rr ss = + @hom (HHomSet T) (c2comp (@GC T _ a0 a0 a1 aa r)) + (c2comp (@GC T _ b0 b0 b1 bb s)) ; + + right_unital : forall (a0 a1 b0 b1: T) + (r: @hhom T a0 a1) (s: @hhom T b0 b1), + let rr := @HO T (@hhom T) a0 a1 r in + let ss := @HO T (@hhom T) b0 b1 s in + let aa := @h2unit T a1 in + let bb := @h2unit T b1 in + @hom (HHomSet T) rr ss = + @hom (HHomSet T) (c2comp (@GC T _ a0 a1 a1 r aa)) + (c2comp (@GC T _ b0 b1 b1 s bb)) ; + + associator : forall (a0 a1 a2 a3: T) + (h1: @hhom T a0 a1) (h2: @hhom T a1 a2) + (h3: @hhom T a2 a3) (x: HHomSet T), + let h23 := h2comp a1 a2 a3 h2 h3 in + let h12 := h2comp a0 a1 a2 h1 h2 in + let hh1 := h2comp a0 a1 a3 h1 h23 in + let hh2 := h2comp a0 a2 a3 h12 h3 in + @hom (HHomSet T) (@HO T (@hhom T) a0 a3 hh1) x = + @hom (HHomSet T) (@HO T (@hhom T) a0 a3 hh2) x +}. +#[short(type="dcat")] +HB.structure Definition DCat : Set := { C of IsDCat C }. +Set Universe Checking. + + + +(*********************************************************************) +(**** GARBAGE ****************************************************) + +(* Double category *) +Unset Universe Checking. +HB.mixin Record IsDCat T of HCFunctor T := { + left_unital : forall (a b: T) (r: @hhom T a b), + let rr := @HO T (@hhom T) a b r in + let aa := @h2unit T a in + @hom (HHomSet T) (c2comp (@GC T _ a a b aa r)) rr ; + + right_unital : forall (a b: T) (r: @hhom T a b), + let rr := @HO T (@hhom T) a b r in + let bb := @h2unit T b in + @hom (HHomSet T) (c2comp (@GC T _ a b b r bb)) rr ; +}. + +(* Double category *) +Unset Universe Checking. HB.mixin Record IsDCat T of HCFunctor T := { left_unital : forall (a b c d: T) (r: @hhom T a c) (s: @hhom T b d), forall (ha: @hhom T a a) (hb: @hhom T b b), @@ -1334,10 +1393,6 @@ HB.structure Definition DCat : Set := { C of IsDCat C }. Set Universe Checking. - -(*********************************************************************) -(**** GARBAGE ****************************************************) - (* a sequence of two adjacent morphisms (pullback object), which we can use to represent composition *) Record GenComp' T (h: T -> T -> U) := GCmp { From f7a0d99562b24e8c2ee20cfdd4ed26b32015a8ef Mon Sep 17 00:00:00 2001 From: ptorrx Date: Wed, 8 Nov 2023 16:42:50 +0100 Subject: [PATCH 082/147] updated encav.v; version with transpose --- theories/encat.v | 52 +++++++++++++++++++++--------------------------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index cac25e7f8..45afe9ae1 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1093,15 +1093,17 @@ Set Universe Checking. (*** DOUBLE CATEGORIES (REVISED) *) -(* A quiver from which horizontal morphisms arise (just a copy of quiver) *) -HB.mixin Record IsHQuiver C := { - hhom : C -> C -> U - }. +HB.tag Definition transpose (C : quiver) : U := C. (* BUG *) +#[wrapper] HB.mixin Record IsTQuiver C of IsQuiver C := { + priv : IsQuiver (transpose C) +}. Unset Universe Checking. #[short(type="hquiver")] -HB.structure Definition HQuiver : Set := { C of IsHQuiver C }. +HB.structure Definition HQuiver : Set := { C of IsQuiver C & IsTQuiver C }. Set Universe Checking. +HB.tag Definition hhom (c : HQuiver.type) : c -> c -> U := @hom (transpose c). + (* domain-specific sigma-type to represent the set of morphims (needed for 2-objects, i.e. horizontal morphisms) *) Record Total2 T (h: T -> T -> U) : Type := HO { @@ -1121,19 +1123,11 @@ HB.tag Definition HSource C := fun (X: HHomSet C) => @source C (@hhom C) X. HB.tag Definition HTarget C := fun (X: HHomSet C) => @target C (@hhom C) X. (* D1 quiver requirement. *) -#[wrapper] -HB.mixin Record IsD1Quiver T of HQuiver T := { - d1_quiver : IsQuiver (@HHomSet T) }. +#[wrapper] +HB.mixin Record IsDQuiver T of HQuiver T := { d1_quiver : Quiver (HHomSet T) }. Unset Universe Checking. #[short(type="d1quiver")] -HB.structure Definition D1Quiver : Set := { C of IsD1Quiver C }. -Set Universe Checking. - -(* all the quivers required by a double category *) -Unset Universe Checking. -#[short(type="dquiver")] -HB.structure Definition DQuiver : Set := - { C of Quiver C & HQuiver C & IsD1Quiver C }. +HB.structure Definition DQuiver : Set := { C of IsDQuiver C }. Set Universe Checking. (* used to define composable pairs of morphisms as a set *) @@ -1148,16 +1142,6 @@ Record GenComp T (h: T -> T -> U) := GC { (* composable pairs of horizontal morphisms as a set *) HB.tag Definition HComp (C: hquiver) := GenComp (@hhom C). -(* pullback category condition (i.e. (HComp T) is a category). - requires T to be a category, and (HHomSet T) to be a quiver *) -#[wrapper] -HB.mixin Record IsHCompCat T of Cat T & DQuiver T := { - hcompcat : Cat (HComp T) }. -Unset Universe Checking. -#[short(type="hcompcat")] -HB.structure Definition HCompCat : Set := { C of IsHCompCat C }. -Set Universe Checking. - (* c2unit - horizontal unit functor. c2comp - horizontal composition functor. @@ -1173,7 +1157,7 @@ Set Universe Checking. in defining the pullback category, making sure that adjacency at the object-level (between horizontal morphisms) is matched by adjacency at the morphism-level (between 2-cells). *) -HB.mixin Record IsC2Quiver T of DQuiver T & HCompCat T := { +HB.mixin Record IsC2Quiver T of DQuiver T := { h2unit : forall a: T, @hhom T a a ; h2comp : forall (a b c: T), @hhom T a b -> @hhom T b c -> @hhom T a c; @@ -1225,7 +1209,7 @@ HB.tag Definition CompF (C: c2quiver) := T is the quiver of 1-morphisms. *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsHSPreFunctor T of Cat T & C2Cat T & HCompCat T := { +HB.mixin Record IsHSPreFunctor T of Cat T & C2Cat T := { h2s_prefunctor : IsPreFunctor (HHomSet T) T (@HSource T) }. HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. Set Universe Checking. @@ -1270,10 +1254,20 @@ HB.mixin Record HUPreFunctor_IsFunctor T of HUPreFunctor T := { HB.structure Definition HUFunctor : Set := {C of HUPreFunctor_IsFunctor C}. Set Universe Checking. +(* pullback category condition (i.e. (HComp T) is a category). + requires T to be a category, and (HHomSet T) to be a quiver *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHCompCat T of HUFunctor T := { + hcompcat : Cat (HComp T) }. +#[short(type="hcompcat")] +HB.structure Definition HCompCat : Set := { C of IsHCompCat C }. +Set Universe Checking. + (* composition prefunctor *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsHCPreFunctor T of HUFunctor T := +HB.mixin Record IsHCPreFunctor T of HCompCat T := { h2c_prefunctor : IsPreFunctor (HComp T) (HHomSet T) (@CompF T) }. HB.structure Definition HCPreFunctor : Set := {C of IsHCPreFunctor C}. Set Universe Checking. From 6074c789d8640f61c5d0de3d13f04438deca923a Mon Sep 17 00:00:00 2001 From: ptorrx Date: Wed, 8 Nov 2023 16:59:36 +0100 Subject: [PATCH 083/147] updated encav.v; improved a definition --- theories/encat.v | 116 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 108 insertions(+), 8 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index 45afe9ae1..00c25953e 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1161,20 +1161,18 @@ HB.mixin Record IsC2Quiver T of DQuiver T := { h2unit : forall a: T, @hhom T a a ; h2comp : forall (a b c: T), @hhom T a b -> @hhom T b c -> @hhom T a c; - - c2unit : T -> HHomSet T ; - c2comp : HComp T -> HHomSet T ; - - c2unit_eq : forall a: T, c2unit a = @HO T (@hhom T) a a (h2unit a) ; - c2comp_eq1 : forall (a b c: T) (h1: @hhom T a b) (h2: @hhom T b c), - c2comp (@GC T (@hhom T) a b c h1 h2) = - @HO T (@hhom T) a c (h2comp a b c h1 h2) }. Unset Universe Checking. #[short(type="c2quiver")] HB.structure Definition C2Quiver : Set := { C of IsC2Quiver C }. Set Universe Checking. +Definition c2unit (T: c2quiver) (a: T) : HHomSet T := @HO T (@hhom T) a a (h2unit a). + +Definition c2comp (T: c2quiver) (x: HComp T) : HHomSet T := + match x with + @GC _ _ a b c h1 h2 => @HO T (@hhom T) a c (h2comp a b c h1 h2) end. + (* Precategory based on the DQuiver (i.e. precategory D1) - only, instead of making it inherit from D1Quiver, we make it inherit from DQuiver. DOES NOT WORK WITH C2Quiver. Gives: @@ -1343,6 +1341,108 @@ Set Universe Checking. (*********************************************************************) (**** GARBAGE ****************************************************) +(* A quiver from which horizontal morphisms arise (just a copy of quiver) *) +HB.mixin Record IsHQuiver C := { + hhom : C -> C -> U + }. +Unset Universe Checking. +#[short(type="hquiver")] +HB.structure Definition HQuiver : Set := { C of IsHQuiver C }. +Set Universe Checking. + +(* domain-specific sigma-type to represent the set of morphims + (needed for 2-objects, i.e. horizontal morphisms) *) +Record Total2 T (h: T -> T -> U) : Type := HO { + source : T; + target : T; + this_morph : h source target }. + +(* the set of horizontal morphisms. + HB.tag needed to identify HHomSet as lifter *) +HB.tag Definition HHomSet (C: hquiver) := Total2 (@hhom C). + +(* source functor (for horizontal morphisms): D1 -> D0. + defined as object-level function, by functoriality lifted to a + (2-cell, vertical) morphism-level one *) +HB.tag Definition HSource C := fun (X: HHomSet C) => @source C (@hhom C) X. +(* target functor (for horizontal morphisms): D1 -> D0. *) +HB.tag Definition HTarget C := fun (X: HHomSet C) => @target C (@hhom C) X. + +(* D1 quiver requirement. *) +#[wrapper] +HB.mixin Record IsD1Quiver T of HQuiver T := { + d1_quiver : IsQuiver (@HHomSet T) }. +Unset Universe Checking. +#[short(type="d1quiver")] +HB.structure Definition D1Quiver : Set := { C of IsD1Quiver C }. +Set Universe Checking. + +(* all the quivers required by a double category *) +Unset Universe Checking. +#[short(type="dquiver")] +HB.structure Definition DQuiver : Set := + { C of Quiver C & HQuiver C & IsD1Quiver C }. +Set Universe Checking. + +(* used to define composable pairs of morphisms as a set *) +Record GenComp T (h: T -> T -> U) := GC { + c_one : T; + c_two : T ; + c_three : T; + c_first : h c_one c_two ; + c_second : h c_two c_three +}. + +(* composable pairs of horizontal morphisms as a set *) +HB.tag Definition HComp (C: hquiver) := GenComp (@hhom C). + +(* +(* pullback category condition (i.e. (HComp T) is a category). + requires T to be a category, and (HHomSet T) to be a quiver *) +#[wrapper] +HB.mixin Record IsHCompCat T of Cat T & DQuiver T := { + hcompcat : Cat (HComp T) }. +Unset Universe Checking. +#[short(type="hcompcat")] +HB.structure Definition HCompCat : Set := { C of IsHCompCat C }. +Set Universe Checking. +*) + +(* c2unit - horizontal unit functor. + + c2comp - horizontal composition functor. + + Both specified as object-level functions, to be lifted by + functoriality to morphism-level ones. + + At the object level, c2unit gives a horizontal identity morphism + for each D0 object. At the morphism level, it gives horizontal + 2-cell identity for each vertical morphism. + + In the case of HComp, relying on functoriality requires some care + in defining the pullback category, making sure that adjacency at + the object-level (between horizontal morphisms) is matched by + adjacency at the morphism-level (between 2-cells). *) +HB.mixin Record IsC2Quiver T of DQuiver T (* & HCompCat T *) := { + h2unit : forall a: T, @hhom T a a ; + h2comp : forall (a b c: T), + @hhom T a b -> @hhom T b c -> @hhom T a c; + + c2unit : T -> HHomSet T ; + c2comp : HComp T -> HHomSet T ; + + c2unit_eq : forall a: T, c2unit a = @HO T (@hhom T) a a (h2unit a) ; + c2comp_eq1 : forall (a b c: T) (h1: @hhom T a b) (h2: @hhom T b c), + c2comp (@GC T (@hhom T) a b c h1 h2) = + @HO T (@hhom T) a c (h2comp a b c h1 h2) +}. +Unset Universe Checking. +#[short(type="c2quiver")] +HB.structure Definition C2Quiver : Set := { C of IsC2Quiver C }. +Set Universe Checking. + +(************************************************************************************) + (* Double category *) Unset Universe Checking. HB.mixin Record IsDCat T of HCFunctor T := { From 0d19f51adf15e6048acd4514216354e33bcd01a6 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Wed, 8 Nov 2023 18:22:13 +0100 Subject: [PATCH 084/147] updated encav.v; minor changes --- theories/encat.v | 174 +++++++++++++++++++++++------------------------ 1 file changed, 87 insertions(+), 87 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index 00c25953e..c8f186680 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1093,27 +1093,29 @@ Set Universe Checking. (*** DOUBLE CATEGORIES (REVISED) *) -HB.tag Definition transpose (C : quiver) : U := C. (* BUG *) +(* transpose for horizontal morphism quiver. + HB.tag needed to identify transpose as lifter *) +HB.tag Definition transpose (C : quiver) : U := C. #[wrapper] HB.mixin Record IsTQuiver C of IsQuiver C := { - priv : IsQuiver (transpose C) + is_tquiver : IsQuiver (transpose C) }. +(* vertical and horizontal quivers, defining cells *) Unset Universe Checking. -#[short(type="hquiver")] -HB.structure Definition HQuiver : Set := { C of IsQuiver C & IsTQuiver C }. +#[short(type="cquiver")] +HB.structure Definition CQuiver : Set := { C of IsQuiver C & IsTQuiver C }. Set Universe Checking. -HB.tag Definition hhom (c : HQuiver.type) : c -> c -> U := @hom (transpose c). +HB.tag Definition hhom (c : CQuiver.type) : c -> c -> U := @hom (transpose c). -(* domain-specific sigma-type to represent the set of morphims +(* record to represent the set of morphims (needed for 2-objects, i.e. horizontal morphisms) *) Record Total2 T (h: T -> T -> U) : Type := HO { source : T; target : T; this_morph : h source target }. -(* the set of horizontal morphisms. - HB.tag needed to identify HHomSet as lifter *) -HB.tag Definition HHomSet (C: hquiver) := Total2 (@hhom C). +(* the set of horizontal morphisms. *) +HB.tag Definition HHomSet (C: cquiver) := Total2 (@hhom C). (* source functor (for horizontal morphisms): D1 -> D0. defined as object-level function, by functoriality lifted to a @@ -1124,9 +1126,9 @@ HB.tag Definition HTarget C := fun (X: HHomSet C) => @target C (@hhom C) X. (* D1 quiver requirement. *) #[wrapper] -HB.mixin Record IsDQuiver T of HQuiver T := { d1_quiver : Quiver (HHomSet T) }. +HB.mixin Record IsDQuiver T of CQuiver T := { is_dquiver : Quiver (HHomSet T) }. Unset Universe Checking. -#[short(type="d1quiver")] +#[short(type="dquiver")] HB.structure Definition DQuiver : Set := { C of IsDQuiver C }. Set Universe Checking. @@ -1140,48 +1142,46 @@ Record GenComp T (h: T -> T -> U) := GC { }. (* composable pairs of horizontal morphisms as a set *) -HB.tag Definition HComp (C: hquiver) := GenComp (@hhom C). +HB.tag Definition HCompSet (C: cquiver) := GenComp (@hhom C). -(* c2unit - horizontal unit functor. +(* hunit - horizontal unit functor. - c2comp - horizontal composition functor. + hcomp - horizontal composition functor. Both specified as object-level functions, to be lifted by functoriality to morphism-level ones. - At the object level, c2unit gives a horizontal identity morphism + At the object level, hunit gives a horizontal identity morphism for each D0 object. At the morphism level, it gives horizontal 2-cell identity for each vertical morphism. - In the case of HComp, relying on functoriality requires some care + In the case of hcomp, relying on functoriality requires some care in defining the pullback category, making sure that adjacency at the object-level (between horizontal morphisms) is matched by adjacency at the morphism-level (between 2-cells). *) -HB.mixin Record IsC2Quiver T of DQuiver T := { - h2unit : forall a: T, @hhom T a a ; - h2comp : forall (a b c: T), - @hhom T a b -> @hhom T b c -> @hhom T a c; +HB.mixin Record IsHDQuiver T of DQuiver T := { + hunit : forall a: T, @hhom T a a ; + hcomp : forall (a b c: T), @hhom T a b -> @hhom T b c -> @hhom T a c; }. Unset Universe Checking. -#[short(type="c2quiver")] -HB.structure Definition C2Quiver : Set := { C of IsC2Quiver C }. +#[short(type="hdquiver")] +HB.structure Definition HDQuiver : Set := { C of IsHDQuiver C }. Set Universe Checking. -Definition c2unit (T: c2quiver) (a: T) : HHomSet T := @HO T (@hhom T) a a (h2unit a). +Definition hhunit (T: hdquiver) (a: T) : HHomSet T := + @HO T (@hhom T) a a (hunit a). -Definition c2comp (T: c2quiver) (x: HComp T) : HHomSet T := +Definition hhcomp (T: hdquiver) (x: HCompSet T) : HHomSet T := match x with - @GC _ _ a b c h1 h2 => @HO T (@hhom T) a c (h2comp a b c h1 h2) end. + @GC _ _ a b c h1 h2 => @HO T (@hhom T) a c (hcomp a b c h1 h2) end. -(* Precategory based on the DQuiver (i.e. precategory D1) - only, - instead of making it inherit from D1Quiver, we make it inherit from - DQuiver. DOES NOT WORK WITH C2Quiver. Gives: +(* Precategory based on the DQuiver (i.e. precategory D1). Gives: vertical 2-cell identity morphism. vertical 2-cell composition. *) Unset Universe Checking. #[wrapper] HB.mixin Record IsC2PreCat T of DQuiver T := { - c2precat : Quiver_IsPreCat (@HHomSet T) }. + is_c2precat : Quiver_IsPreCat (@HHomSet T) }. #[short(type="c2precat")] HB.structure Definition C2PreCat : Set := { C of IsC2PreCat C }. Set Universe Checking. @@ -1190,74 +1190,74 @@ Set Universe Checking. Unset Universe Checking. #[wrapper] HB.mixin Record IsC2Cat T of C2PreCat T := { - c2cat : PreCat_IsCat (@HHomSet T) }. -#[short(type="h2cat")] + is_c2cat : PreCat_IsCat (@HHomSet T) }. +#[short(type="c2cat")] HB.structure Definition C2Cat : Set := { C of IsC2Cat C }. Set Universe Checking. -(* unit functor: D0 -> D1 *) -HB.tag Definition UnitF (C: c2quiver) := - fun (x: C2Quiver.sort C) => @c2unit C x. -(* composition functor: D1 * D1 -> D1 *) -HB.tag Definition CompF (C: c2quiver) := - fun (x: HComp C) => @c2comp C x. +(* horizontal unit functor: D0 -> D1 *) +HB.tag Definition HUnit (C: hdquiver) := + fun (x: HDQuiver.sort C) => @hhunit C x. +(* horizontal composition functor: D1 * D1 -> D1 *) +HB.tag Definition HComp (C: hdquiver) := + fun (x: HCompSet C) => @hhcomp C x. (* source prefunctor. - HHomSet T is the quiver of the 2-morphisms, thanks to H2Quiver. + HHomSet T is the quiver of the 2-morphisms, thanks to DQuiver. T is the quiver of 1-morphisms. *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsHSPreFunctor T of Cat T & C2Cat T := { - h2s_prefunctor : IsPreFunctor (HHomSet T) T (@HSource T) }. -HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. +HB.mixin Record IsSPreFunctor T of Cat T & C2Cat T := { + is_sprefunctor : IsPreFunctor (HHomSet T) T (@HSource T) }. +HB.structure Definition SPreFunctor : Set := {C of IsSPreFunctor C}. Set Universe Checking. (* target prefunctor. *) Unset Universe Checking. #[wrapper] - HB.mixin Record IsHTPreFunctor T of HSPreFunctor T := { - h2t_prefunctor : IsPreFunctor (HHomSet T) T (@HTarget T) }. -HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. + HB.mixin Record IsTPreFunctor T of SPreFunctor T := { + is_tprefunctor : IsPreFunctor (HHomSet T) T (@HTarget T) }. +HB.structure Definition TPreFunctor : Set := {C of IsTPreFunctor C}. Set Universe Checking. (* source functor. *) Unset Universe Checking. #[wrapper] -HB.mixin Record HSPreFunctor_IsFunctor T of HTPreFunctor T := { - h2s_functor : PreFunctor_IsFunctor (HHomSet T) T (@HSource T) }. -HB.structure Definition HSFunctor : Set := {C of HSPreFunctor_IsFunctor C}. +HB.mixin Record SPreFunctor_IsFunctor T of TPreFunctor T := { + is_sfunctor : PreFunctor_IsFunctor (HHomSet T) T (@HSource T) }. +HB.structure Definition SFunctor : Set := {C of SPreFunctor_IsFunctor C}. Set Universe Checking. (* target functor. *) Unset Universe Checking. #[wrapper] -HB.mixin Record HTPreFunctor_IsFunctor T of HSFunctor T := { - h2t_functor : PreFunctor_IsFunctor (HHomSet T) T (@HTarget T) }. -HB.structure Definition HTFunctor : Set := {C of HTPreFunctor_IsFunctor C}. +HB.mixin Record TPreFunctor_IsFunctor T of SFunctor T := { + is_tfunctor : PreFunctor_IsFunctor (HHomSet T) T (@HTarget T) }. +HB.structure Definition TFunctor : Set := {C of TPreFunctor_IsFunctor C}. Set Universe Checking. (* unit prefunctor. *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsHUPreFunctor T of C2Quiver T & HTFunctor T := - { h2u_prefunctor : IsPreFunctor T (HHomSet T) (@UnitF T) }. -HB.structure Definition HUPreFunctor : Set := {C of IsHUPreFunctor C}. +HB.mixin Record IsUPreFunctor T of HDQuiver T & TFunctor T := + { is_uprefunctor : IsPreFunctor T (HHomSet T) (@HUnit T) }. +HB.structure Definition UPreFunctor : Set := {C of IsUPreFunctor C}. Set Universe Checking. (* unit functor. *) Unset Universe Checking. #[wrapper] -HB.mixin Record HUPreFunctor_IsFunctor T of HUPreFunctor T := { - h2u_functor : PreFunctor_IsFunctor T (HHomSet T) (@UnitF T) }. -HB.structure Definition HUFunctor : Set := {C of HUPreFunctor_IsFunctor C}. +HB.mixin Record UPreFunctor_IsFunctor T of UPreFunctor T := { + is_ufunctor : PreFunctor_IsFunctor T (HHomSet T) (@HUnit T) }. +HB.structure Definition UFunctor : Set := {C of UPreFunctor_IsFunctor C}. Set Universe Checking. -(* pullback category condition (i.e. (HComp T) is a category). +(* pullback category condition (i.e. (HCompSet T) is a category). requires T to be a category, and (HHomSet T) to be a quiver *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsHCompCat T of HUFunctor T := { - hcompcat : Cat (HComp T) }. +HB.mixin Record IsHCompCat T of UFunctor T := { + is_hcompcat : Cat (HCompSet T) }. #[short(type="hcompcat")] HB.structure Definition HCompCat : Set := { C of IsHCompCat C }. Set Universe Checking. @@ -1265,70 +1265,70 @@ Set Universe Checking. (* composition prefunctor *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsHCPreFunctor T of HCompCat T := - { h2c_prefunctor : IsPreFunctor (HComp T) (HHomSet T) (@CompF T) }. -HB.structure Definition HCPreFunctor : Set := {C of IsHCPreFunctor C}. +HB.mixin Record IsCPreFunctor T of HCompCat T := + { is_cprefunctor : IsPreFunctor (HCompSet T) (HHomSet T) (@HComp T) }. +HB.structure Definition CPreFunctor : Set := {C of IsCPreFunctor C}. Set Universe Checking. (* composition functor *) Unset Universe Checking. #[wrapper] -HB.mixin Record HCPreFunctor_IsFunctor T of HCPreFunctor T := { - h2c_functor : PreFunctor_IsFunctor (HComp T) (HHomSet T) (@CompF T) }. -HB.structure Definition HCFunctor : Set := {C of HCPreFunctor_IsFunctor C}. +HB.mixin Record CPreFunctor_IsFunctor T of CPreFunctor T := { + is_cfunctor : PreFunctor_IsFunctor (HCompSet T) (HHomSet T) (@HComp T) }. +HB.structure Definition CFunctor : Set := {C of CPreFunctor_IsFunctor C}. Set Universe Checking. -(* 2-morphisms *) -Definition c2hom (D: C2Quiver.type) := @hom (@HHomSet D). +(* 2-cell (D1) morphisms *) +Definition c2hom (D: HDQuiver.type) := @hom (@HHomSet D). (* The set of D1 morphisms *) -HB.tag Definition C2HomSet (C: C2Quiver.type) := Total2 (@c2hom C). +HB.tag Definition C2HomSet (C: HDQuiver.type) := Total2 (@c2hom C). (* horizontal 2-cell unit (maps vertical morphisms to horizontally unitary 2-cells) *) -Definition HC2Unit (T: HUFunctor.type) (a b: T) (m: @hom T a b) : - c2hom (UnitF a) (UnitF b) := @Fhom _ _ (@UnitF T) a b m. +Definition HC2Unit (T: UFunctor.type) (a b: T) (m: @hom T a b) : + c2hom (HUnit a) (HUnit b) := @Fhom _ _ (@HUnit T) a b m. (* horizontal 2-cell composition: maps two adjecent pairs of horizontal morphisms (a and b) and a pullback-category morphism between them (m, which basically gives two adjecent cells) to a - 2-cell morphism between the horizontal composition (CompF) of each + 2-cell morphism between the horizontal composition (HComp) of each pair *) -Definition HC2Comp (T: HCFunctor.type) (a b: HComp T) - (m: @hom (HComp T) a b) : - c2hom (CompF a) (CompF b) := @Fhom _ _ (@CompF T) a b m. +Definition HC2Comp (T: CFunctor.type) (a b: HCompSet T) + (m: @hom (HCompSet T) a b) : + c2hom (HComp a) (HComp b) := @Fhom _ _ (@HComp T) a b m. (* Double category complete with properties of horizontal 2-cell identity and composition *) Unset Universe Checking. -HB.mixin Record IsDCat T of HCFunctor T := { +HB.mixin Record IsDCat T of CFunctor T := { left_unital : forall (a0 a1 b0 b1: T) (r: @hhom T a0 a1) (s: @hhom T b0 b1), let rr := @HO T (@hhom T) a0 a1 r in let ss := @HO T (@hhom T) b0 b1 s in - let aa := @h2unit T a0 in - let bb := @h2unit T b0 in + let aa := @hunit T a0 in + let bb := @hunit T b0 in @hom (HHomSet T) rr ss = - @hom (HHomSet T) (c2comp (@GC T _ a0 a0 a1 aa r)) - (c2comp (@GC T _ b0 b0 b1 bb s)) ; + @hom (HHomSet T) (hhcomp (@GC T _ a0 a0 a1 aa r)) + (hhcomp (@GC T _ b0 b0 b1 bb s)) ; right_unital : forall (a0 a1 b0 b1: T) (r: @hhom T a0 a1) (s: @hhom T b0 b1), let rr := @HO T (@hhom T) a0 a1 r in let ss := @HO T (@hhom T) b0 b1 s in - let aa := @h2unit T a1 in - let bb := @h2unit T b1 in + let aa := @hunit T a1 in + let bb := @hunit T b1 in @hom (HHomSet T) rr ss = - @hom (HHomSet T) (c2comp (@GC T _ a0 a1 a1 r aa)) - (c2comp (@GC T _ b0 b1 b1 s bb)) ; + @hom (HHomSet T) (hhcomp (@GC T _ a0 a1 a1 r aa)) + (hhcomp (@GC T _ b0 b1 b1 s bb)) ; associator : forall (a0 a1 a2 a3: T) (h1: @hhom T a0 a1) (h2: @hhom T a1 a2) (h3: @hhom T a2 a3) (x: HHomSet T), - let h23 := h2comp a1 a2 a3 h2 h3 in - let h12 := h2comp a0 a1 a2 h1 h2 in - let hh1 := h2comp a0 a1 a3 h1 h23 in - let hh2 := h2comp a0 a2 a3 h12 h3 in + let h23 := hcomp a1 a2 a3 h2 h3 in + let h12 := hcomp a0 a1 a2 h1 h2 in + let hh1 := hcomp a0 a1 a3 h1 h23 in + let hh2 := hcomp a0 a2 a3 h12 h3 in @hom (HHomSet T) (@HO T (@hhom T) a0 a3 hh1) x = @hom (HHomSet T) (@HO T (@hhom T) a0 a3 hh2) x }. From 64d354c7c8917af0ce187b021efcb1add68c67e5 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Thu, 9 Nov 2023 14:01:47 +0100 Subject: [PATCH 085/147] updated encav.v; added (alternative definitions of) horizontal 2-cell properties --- theories/encat.v | 122 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 117 insertions(+), 5 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index c8f186680..55b185abd 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1298,10 +1298,56 @@ Definition HC2Comp (T: CFunctor.type) (a b: HCompSet T) (m: @hom (HCompSet T) a b) : c2hom (HComp a) (HComp b) := @Fhom _ _ (@HComp T) a b m. -(* Double category complete with properties of horizontal 2-cell - identity and composition *) +Definition HC2Source (T: CFunctor.type) (a b: @HHomSet T) + (m: @c2hom T a b) : + @hom T (HSource a) (HSource b) := @Fhom _ _ (@HSource T) a b m. + +Definition HC2Target (T: CFunctor.type) (a b: @HHomSet T) + (m: @c2hom T a b) : + @hom T (HTarget a) (HTarget b) := @Fhom _ _ (@HTarget T) a b m. + +Definition l_hcomp (T: CFunctor.type) (a0 a1 a2: T) + (h0: hhom a0 a1) (h1: hhom a1 a2) : HHomSet T := + @HO T _ a0 a2 (hcomp a0 a1 a2 h0 h1). + +(* Double category with strong horizontal unit (Russ' paper). + hunit defines proper identity on horizontal morphisms *) +HB.mixin Record IsDCat_SU T of CFunctor T := { + left_unital : forall (a0 a1: T) (h : hhom a0 a1), + @hcomp T a0 a0 a1 (hunit a0) h = h ; + + right_unital : forall (a0 a1: T) (h : hhom a0 a1), + @hcomp T a0 a1 a1 h (hunit a1) = h ; +}. +Unset Universe Checking. +#[short(type="dcat_su")] +HB.structure Definition DCat_SU : Set := { C of IsDCat_SU C }. +Set Universe Checking. + +(* Double category with weak horizontal unit (display paper) *) +HB.mixin Record IsDCat_WU T of CFunctor T := { + left_unital : forall (a0 a1: T) (h : hhom a0 a1), + let hh := HO h + in let uh := HO (hcomp a0 a0 a1 (hunit a0) h) + in exists uhc : c2hom uh hh, + HC2Source uhc = @idmap T a0 /\ + HC2Target uhc = @idmap T a1 ; + + right_unital : forall (a0 a1: T) (h : hhom a0 a1), + let hh := HO h + in let uh := HO (hcomp a0 a1 a1 h (hunit a1)) + in exists uhc : c2hom uh hh, + HC2Source uhc = @idmap T a0 /\ + HC2Target uhc = @idmap T a1 +}. Unset Universe Checking. -HB.mixin Record IsDCat T of CFunctor T := { +#[short(type="dcat_wu")] +HB.structure Definition DCat_WU : Set := { C of IsDCat_WU C }. +Set Universe Checking. + +(* Double category with universal characterization of half-strong + horizontal unit *) +HB.mixin Record IsDCat_HU T of CFunctor T := { left_unital : forall (a0 a1 b0 b1: T) (r: @hhom T a0 a1) (s: @hhom T b0 b1), let rr := @HO T (@hhom T) a0 a1 r in @@ -1321,7 +1367,41 @@ HB.mixin Record IsDCat T of CFunctor T := { @hom (HHomSet T) rr ss = @hom (HHomSet T) (hhcomp (@GC T _ a0 a1 a1 r aa)) (hhcomp (@GC T _ b0 b1 b1 s bb)) ; +}. +Unset Universe Checking. +#[short(type="dcat_hu")] +HB.structure Definition DCat_HU : Set := { C of IsDCat_HU C }. +Set Universe Checking. +(* Double category with weak horizontal associativity (display paper) *) +HB.mixin Record IsDCat_WA T of CFunctor T := { + associator : forall (a0 a1 a2 a3: T) + (h1: @hhom T a0 a1) (h2: @hhom T a1 a2) + (h3: @hhom T a2 a3) (x: HHomSet T), + let h12 := hcomp a0 a1 a2 h1 h2 in + let h23 := hcomp a1 a2 a3 h2 h3 in + let hh1 := HO (hcomp a0 a1 a3 h1 h23) in + let hh2 := HO (hcomp a0 a2 a3 h12 h3) in + exists asc: + c2hom hh1 hh2, HC2Source asc = @idmap T a0 /\ + HC2Target asc = @idmap T a3 +}. +Unset Universe Checking. +#[short(type="dcat_wa")] +HB.structure Definition DCat_WA : Set := { C of IsDCat_WA C }. +Set Universe Checking. +(* + a0 -- h0 --> a1 -- h1 --> a2 + | | | | | + v0 hh0 v1 hh1 v2 + | | | | | + V V V V V + b0 -- k0 --> b1 -- k1 --> b2 +*) + +(* Double category with universal characterization of weak + horizontal associativity *) +HB.mixin Record IsDCat_UA T of CFunctor T := { associator : forall (a0 a1 a2 a3: T) (h1: @hhom T a0 a1) (h2: @hhom T a1 a2) (h3: @hhom T a2 a3) (x: HHomSet T), @@ -1332,10 +1412,42 @@ HB.mixin Record IsDCat T of CFunctor T := { @hom (HHomSet T) (@HO T (@hhom T) a0 a3 hh1) x = @hom (HHomSet T) (@HO T (@hhom T) a0 a3 hh2) x }. -#[short(type="dcat")] -HB.structure Definition DCat : Set := { C of IsDCat C }. +Unset Universe Checking. +#[short(type="dcat_ua")] +HB.structure Definition DCat_UA : Set := { C of IsDCat_UA C }. +Set Universe Checking. + +Unset Universe Checking. +#[short(type="dcat_dp")] +HB.structure Definition DCat_DP : Set := { C of DCat_WU C & DCat_WA C }. +Set Universe Checking. + +Unset Universe Checking. +#[short(type="dcat_rp")] +HB.structure Definition DCat_RP : Set := { C of DCat_SU C & DCat_UA C }. Set Universe Checking. +Program Definition HC2Comp_flat (T: CFunctor.type) (a0 a1 a2 b0 b1 b2: T) + (h0: hhom a0 a1) (h1: hhom a1 a2) + (k0: hhom b0 b1) (k1: hhom b1 b2) + (hh0: c2hom (HO h0) (HO k0)) + (hh1: c2hom (HO h1) (HO k1)) : + c2hom (l_hcomp h0 h1) (l_hcomp k0 k1) := + @Fhom _ _ (@HComp T) (GC h0 h1) (GC k0 k1) _. +Obligation 1. +Admitted. + +(* not working yet *) +HB.mixin Record IsDCat_U2 T of CFunctor T := { + left_unital : forall (a0 a1 b0 b1: T) (m: @hom T a0 b0) + (h : hhom a0 a1) (k : hhom b0 b1) + (hh: c2hom (HO h) (HO k)), + forall (xx: c2hom (HUnit a0) (HUnit b0)), + xx = HC2Unit m -> + HC2Source hh = m -> + @HC2Comp_flat T a0 a0 a1 b0 b0 b1 (hunit a0) h (hunit b0) k xx hh = + @HC2Comp_flat T a0 a0 a1 b0 b0 b1 (hunit a0) h (hunit b0) k xx hh +}. (*********************************************************************) From 1da3981bf8441ff92b2450cbee92210703a117f5 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Thu, 9 Nov 2023 14:32:46 +0100 Subject: [PATCH 086/147] added encatA.v, older version for experiments on instantiation. minor changes in encav.v --- theories/encat.v | 34 + theories/encatA.v | 2166 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 2200 insertions(+) create mode 100644 theories/encatA.v diff --git a/theories/encat.v b/theories/encat.v index 55b185abd..250f0465c 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1417,16 +1417,50 @@ Unset Universe Checking. HB.structure Definition DCat_UA : Set := { C of IsDCat_UA C }. Set Universe Checking. +(* double category, closer to the display paper *) Unset Universe Checking. #[short(type="dcat_dp")] HB.structure Definition DCat_DP : Set := { C of DCat_WU C & DCat_WA C }. Set Universe Checking. +(* double category, closer to (my understanding of) Russ' paper *) Unset Universe Checking. #[short(type="dcat_rp")] HB.structure Definition DCat_RP : Set := { C of DCat_SU C & DCat_UA C }. Set Universe Checking. + +(*********************************************************************) + +(** HComp quiver *) +Definition HComp_hom (T: TFunctor.type) := + (fun (A B: HCompSet T) => match (A, B) with + | (@GC _ _ a1 b1 c1 h1 k1, @GC _ _ a2 b2 c2 h2 k2) => + let h1' := @HO T (@hhom T) a1 b1 h1 + in let k1' := @HO T (@hhom T) b1 c1 k1 + in let h2' := @HO T (@hhom T) a2 b2 h2 + in let k2' := @HO T (@hhom T) b2 c2 k2 + in sigT (fun (hh: @hom (HHomSet T) h1' h2') => + (sigT (fun (kk: @hom (HHomSet T) k1' k2') => + @Fhom _ _ (@HTarget T) h1' h2' hh = + @Fhom _ _ (@HSource T) k1' k2' kk))) + end). + +Definition HCompQuiver (T: TFunctor.type) : + IsQuiver (HCompSet T) := + IsQuiver.Build (HCompSet T) (fun A B => @HComp_hom T A B). + +Program Definition HCompPreCat (T: TFunctor.type) : + Quiver_IsPreCat (HCompSet T) := + Quiver_IsPreCat.Build (HCompSet T) + (fun x: HComp T => _) (fun a b c: HCompSet T => _). +Obligation 1. +Admitted. +Obligation 2. +Admitted. + + + Program Definition HC2Comp_flat (T: CFunctor.type) (a0 a1 a2 b0 b1 b2: T) (h0: hhom a0 a1) (h1: hhom a1 a2) (k0: hhom b0 b1) (k1: hhom b1 b2) diff --git a/theories/encatA.v b/theories/encatA.v new file mode 100644 index 000000000..ee390c766 --- /dev/null +++ b/theories/encatA.v @@ -0,0 +1,2166 @@ +Require Import ssreflect ssrfun. +From HB Require Import structures. + +Set Implicit Arguments. +Unset Strict Implicit. +Unset Printing Implicit Defensive. +Add Search Blacklist "__canonical__". + +Declare Scope algebra_scope. +Delimit Scope algebra_scope with A. +Local Open Scope algebra_scope. + +Declare Scope cat_scope. +Delimit Scope cat_scope with cat. +Local Open Scope cat_scope. + +(* we assume a few axioms to make life easier *) +Axiom funext : forall {T : Type} {U : T -> Type} [f g : forall t, U t], + (forall t, f t = g t) -> f = g. +Axiom propext : forall P Q : Prop, P <-> Q -> P = Q. +Axiom Prop_irrelevance : forall (P : Prop) (x y : P), x = y. + +(* Shortcut *) +Notation U := Type. + +(* Base definition : raw categories = quivers *) +HB.mixin Record IsQuiver C := { hom : C -> C -> U }. +Unset Universe Checking. +#[short(type="quiver")] +HB.structure Definition Quiver : Set := { C of IsQuiver C }. +Set Universe Checking. + +Bind Scope cat_scope with quiver. +Bind Scope cat_scope with hom. +Arguments hom {C} : rename. +Notation homs T := (@hom T _ _). +Notation "a ~> b" := (hom a b) + (at level 99, b at level 200, format "a ~> b") : cat_scope. +Notation "a ~>_ C b" := (@hom C a b) + (at level 99, C at level 0, only parsing) : cat_scope. + +(* precategories are quivers + id and comp *) +HB.mixin Record Quiver_IsPreCat C of Quiver C := { + idmap : forall (a : C), a ~> a; + comp : forall (a b c : C), (a ~> b) -> (b ~> c) -> (a ~> c); +}. + +HB.factory Record IsPreCat C := { + hom : C -> C -> U; + idmap : forall (a : C), hom a a; + comp : forall (a b c : C), hom a b -> hom b c -> hom a c; +}. +HB.builders Context C of IsPreCat C. + HB.instance Definition _ := IsQuiver.Build C hom. + HB.instance Definition _ := Quiver_IsPreCat.Build C idmap comp. +HB.end. + +Unset Universe Checking. +#[short(type="precat")] +HB.structure Definition PreCat : Set := { C of IsPreCat C }. +Set Universe Checking. + +Bind Scope cat_scope with precat. +Arguments idmap {C} {a} : rename. +Arguments comp {C} {a b c} : rename. +Notation "f \o g" := (comp g f) : cat_scope. +Notation "f \; g :> T" := (@comp T _ _ _ f g) + (at level 60, g, T at level 60, format "f \; g :> T", only parsing) : cat_scope. +Notation "f \; g" := (comp f g) : cat_scope. +Notation "\idmap_ a" := (@idmap _ a) (only parsing, at level 0) : cat_scope. + +(* categories are precategories + laws *) +HB.mixin Record PreCat_IsCat C of PreCat C := { + comp1o : forall (a b : C) (f : a ~> b), idmap \; f = f; + compo1 : forall (a b : C) (f : a ~> b), f \; idmap = f; + compoA : forall (a b c d : C) (f : a ~> b) (g : b ~> c) (h : c ~> d), + f \; (g \; h) = (f \; g) \; h +}. +Unset Universe Checking. +#[short(type="cat")] +HB.structure Definition Cat : Set := { C of PreCat_IsCat C & IsPreCat C }. +Set Universe Checking. + +Bind Scope cat_scope with cat. +Arguments compo1 {C a b} : rename. +Arguments comp1o {C a b} : rename. +Arguments compoA {C a b c d} : rename. + +(* the discrete category on a type cannot be the default, we make an alias *) +Definition discrete (T : U) := T. +HB.instance Definition _ T := @IsPreCat.Build (discrete T) (fun x y => x = y) + (fun=> erefl) (@etrans _). +Lemma etransA T (a b c d : discrete T) (f : a ~> b) (g : b ~> c) (h : c ~> d) : + f \; (g \; h) = (f \; g) \; h. +Proof. by rewrite /idmap/comp/=; case: _ / h; case: _ / g. Qed. +HB.instance Definition _ T := PreCat_IsCat.Build (discrete T) (@etrans_id _) + (fun _ _ _ => erefl) (@etransA _). + +(* the category of the unit type is the discrete one *) +HB.instance Definition _ := Cat.copy unit (discrete unit). + +HB.instance Definition _ := @IsPreCat.Build U (fun A B => A -> B) + (fun a => idfun) (fun a b c (f : a -> b) (g : b -> c) => (g \o f)%FUN). +HB.instance Definition _ := PreCat_IsCat.Build U (fun _ _ _ => erefl) + (fun _ _ _ => erefl) (fun _ _ _ _ _ _ _ => erefl). + + +Lemma Ucomp (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) : f \; g = (g \o f)%FUN. +Proof. by []. Qed. +Lemma Ucompx (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) x : (f \; g) x = g (f x). +Proof. by []. Qed. +Lemma U1 (X : U) : \idmap_X = idfun. +Proof. by []. Qed. +Lemma U1x (X : U) x : \idmap_X x = x. +Proof. by []. Qed. + +(* a prefunctor is a functor without laws *) +HB.mixin Record IsPreFunctor (C D : quiver) (F : C -> D) := { + Fhom : forall (a b : C), (a ~> b) -> (F a ~> F b) +}. + +Unset Universe Checking. +HB.structure Definition PreFunctor (C D : quiver) : Set := + { F of IsPreFunctor C D F }. +Set Universe Checking. +HB.instance Definition _ := IsQuiver.Build quiver PreFunctor.type. + +Notation "F ^$" := (@Fhom _ _ F _ _) + (at level 1, format "F ^$") : cat_scope. +Notation "F <$> f" := (@Fhom _ _ F _ _ f) + (at level 58, format "F <$> f", right associativity) : cat_scope. + +(* prefunctors are equal if their object and hom part are respectively equal *) +Lemma prefunctorP (C D : quiver) (F G : C ~> D) (eqFG : F =1 G) : + let homF a b F := F a ~> F b in + (forall a b f, eq_rect _ (homF a b) (F <$> f) _ (funext eqFG) = G <$> f) -> + F = G. +Proof. +move: F G => [F [[/= Fhom]]] [G [[/= Ghom]]] in eqFG *. +case: _ / (funext eqFG) => /= in Ghom * => eqFGhom. +congr PreFunctor.Pack; congr PreFunctor.Class; congr IsPreFunctor.Axioms_. +by do 3!apply: funext=> ?. +Qed. + +(* a functor is a prefunctor + laws for id and comp *) +HB.mixin Record PreFunctor_IsFunctor (C D : precat) (F : C -> D) + of @PreFunctor C D F := { + F1 : forall (a : C), F <$> \idmap_a = idmap; + Fcomp : forall (a b c : C) (f : a ~> b) (g : b ~> c), + F <$> (f \; g) = F <$> f \; F <$> g; +}. +Unset Universe Checking. + +(* precat and cat have a quiver structure *) +HB.structure Definition Functor (C D : precat) : Set := + { F of IsPreFunctor C D F & PreFunctor_IsFunctor C D F }. +Set Universe Checking. +HB.instance Definition _ := IsQuiver.Build precat Functor.type. +HB.instance Definition _ := IsQuiver.Build cat Functor.type. + +(* functor equality is the same as prefunctor because of PI *) +Lemma functorP (C D : precat) (F G : C ~> D) (eqFG : F =1 G) : + let homF a b F := F a ~> F b in + (forall a b f, eq_rect _ (homF a b) (F^$ f) _ (funext eqFG) = G^$ f) -> + F = G. +Proof. +move=> /= /prefunctorP {eqFG}. +case: F G => [F [/= Fm Fm']] [G [/= Gm Gm']]//=. +move=> [_] /EqdepFacts.eq_sigT_iff_eq_dep eqFG. +case: _ / eqFG in Gm' *. +congr Functor.Pack; congr Functor.Class. +case: Fm' Gm' => [F1 Fc] [G1 Gc]. +by congr PreFunctor_IsFunctor.Axioms_; apply: Prop_irrelevance. +Qed. + +(* the identity function is a functor *) +HB.instance Definition _ (C : quiver) := + IsPreFunctor.Build C C idfun (fun a b => idfun). +HB.instance Definition _ (C : precat) := + PreFunctor_IsFunctor.Build C C idfun (fun=> erefl) (fun _ _ _ _ _ => erefl). + +(* the composition of prefunctors *) +Section comp_prefunctor. +Context {C D E : quiver} {F : C ~> D} {G : D ~> E}. + +HB.instance Definition _ := IsPreFunctor.Build C E (G \o F)%FUN + (fun a b f => G <$> F <$> f). +Lemma comp_Fun (a b : C) (f : a ~> b) : (G \o F)%FUN <$> f = G <$> (F <$> f). +Proof. by []. Qed. +End comp_prefunctor. + +Section comp_functor. +Context {C D E : precat} {F : C ~> D} {G : D ~> E}. +Lemma comp_F1 (a : C) : (G \o F)%FUN <$> \idmap_a = idmap. +Proof. by rewrite !comp_Fun !F1. Qed. +Lemma comp_Fcomp (a b c : C) (f : a ~> b) (g : b ~> c) : + (G \o F)%FUN <$> (f \; g) = (G \o F)%FUN <$> f \; (G \o F)%FUN <$> g. +Proof. by rewrite !comp_Fun !Fcomp. Qed. +HB.instance Definition _ := PreFunctor_IsFunctor.Build C E (G \o F)%FUN + comp_F1 comp_Fcomp. +End comp_functor. + +(* precat and cat have a precategory structure *) +HB.instance Definition _ := Quiver_IsPreCat.Build precat + (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). +HB.instance Definition _ := Quiver_IsPreCat.Build cat + (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). + +Lemma funext_frefl A B (f : A -> B) : funext (frefl f) = erefl. +Proof. exact: Prop_irrelevance. Qed. + +(* precategories and categories form a category *) +Definition precat_cat : PreCat_IsCat precat. +Proof. +by split=> [C D F|C D F|C D C' D' F G H]; + apply/functorP => a b f /=; rewrite funext_frefl. +Qed. +HB.instance Definition _ := precat_cat. +Definition cat_cat : PreCat_IsCat cat. +Proof. +by split=> [C D F|C D F|C D C' D' F G H]; + apply/functorP => a b f /=; rewrite funext_frefl. +Qed. +HB.instance Definition _ := cat_cat. + +Check (cat : cat). + +(* concrete categories *) +HB.mixin Record Quiver_IsPreConcrete T of Quiver T := { + concrete : T -> U; + concrete_fun : forall (a b : T), (a ~> b) -> concrete a -> concrete b; +}. +Unset Universe Checking. +#[short(type="preconcrete_quiver")] +HB.structure Definition PreConcreteQuiver : Set := + { C of Quiver_IsPreConcrete C & IsQuiver C }. +Set Universe Checking. +Coercion concrete : PreConcreteQuiver.sort >-> Sortclass. + +HB.mixin Record PreConcrete_IsConcrete T of PreConcreteQuiver T := { + concrete_fun_inj : forall (a b : T), injective (concrete_fun a b) +}. +Unset Universe Checking. +#[short(type="concrete_quiver")] +HB.structure Definition ConcreteQuiver : Set := + { C of PreConcreteQuiver C & PreConcrete_IsConcrete C }. +Set Universe Checking. + +HB.instance Definition _ (C : ConcreteQuiver.type) := + IsPreFunctor.Build _ _ (concrete : C -> U) concrete_fun. + +HB.mixin Record PreCat_IsConcrete T of ConcreteQuiver T & PreCat T := { + concrete1 : forall (a : T), concrete <$> \idmap_a = idfun; + concrete_comp : forall (a b c : T) (f : a ~> b) (g : b ~> c), + concrete <$> (f \; g) = ((concrete <$> g) \o (concrete <$> f))%FUN; +}. +Unset Universe Checking. +#[short(type="concrete_precat")] +HB.structure Definition ConcretePreCat : Set := + { C of PreCat C & ConcreteQuiver C & PreCat_IsConcrete C }. +#[short(type="concrete_cat")] +HB.structure Definition ConcreteCat : Set := + { C of Cat C & ConcreteQuiver C & PreCat_IsConcrete C }. +Set Universe Checking. + +HB.instance Definition _ (C : concrete_precat) := + PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). +HB.instance Definition _ (C : ConcreteCat.type) := + PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). + +HB.instance Definition _ := Quiver_IsPreConcrete.Build U (fun _ _ => id). +HB.instance Definition _ := PreConcrete_IsConcrete.Build U (fun _ _ _ _ => id). +HB.instance Definition _ := PreCat_IsConcrete.Build U + (fun=> erefl) (fun _ _ _ _ _ => erefl). + +Unset Universe Checking. +HB.instance Definition _ := Quiver_IsPreConcrete.Build quiver (fun _ _ => id). +HB.instance Definition _ := Quiver_IsPreConcrete.Build precat (fun _ _ => id). +HB.instance Definition _ := Quiver_IsPreConcrete.Build cat (fun _ _ => id). +Lemma quiver_concrete_subproof : PreConcrete_IsConcrete quiver. +Proof. +constructor=> C D F G FG; apply: prefunctorP. + by move=> x; congr (_ x); apply: FG. +by move=> *; apply: Prop_irrelevance. +Qed. +HB.instance Definition _ := quiver_concrete_subproof. + +Lemma precat_concrete_subproof : PreConcrete_IsConcrete precat. +Proof. +constructor=> C D F G FG; apply: functorP. + by move=> x; congr (_ x); apply: FG. +by move=> *; apply: Prop_irrelevance. +Qed. +HB.instance Definition _ := precat_concrete_subproof. + +Lemma cat_concrete_subproof : PreConcrete_IsConcrete cat. +Proof. +constructor=> C D F G FG; apply: functorP. + by move=> x; congr (_ x); apply: FG. +by move=> *; apply: Prop_irrelevance. +Qed. +HB.instance Definition _ := cat_concrete_subproof. +HB.instance Definition _ := PreCat_IsConcrete.Build precat + (fun=> erefl) (fun _ _ _ _ _ => erefl). +HB.instance Definition _ := PreCat_IsConcrete.Build cat + (fun=> erefl) (fun _ _ _ _ _ => erefl). +Set Universe Checking. + +(* constant functor *) +Definition cst (C D : quiver) (c : C) := fun of D => c. +Arguments cst {C} D c. +HB.instance Definition _ {C D : precat} (c : C) := + IsPreFunctor.Build D C (cst D c) (fun _ _ _ => idmap). +HB.instance Definition _ {C D : cat} (c : C) := + PreFunctor_IsFunctor.Build D C (cst D c) (fun=> erefl) + (fun _ _ _ _ _ => esym (compo1 idmap)). + +(* opposite category *) +Definition catop (C : U) : U := C. +Notation "C ^op" := (catop C) + (at level 2, format "C ^op") : cat_scope. +HB.instance Definition _ (C : quiver) := + IsQuiver.Build C^op (fun a b => hom b a). +HB.instance Definition _ (C : precat) := + Quiver_IsPreCat.Build (C^op) (fun=> idmap) (fun _ _ _ f g => g \; f). +HB.instance Definition _ (C : cat) := PreCat_IsCat.Build (C^op) + (fun _ _ _ => compo1 _) (fun _ _ _ => comp1o _) + (fun _ _ _ _ _ _ _ => esym (compoA _ _ _)). + +HB.instance Definition _ {C : precat} {c : C} := + IsPreFunctor.Build C _ (hom c) (fun a b f g => g \; f). +Lemma hom_Fhom_subproof (C : cat) (x : C) : + PreFunctor_IsFunctor _ _ (hom x). +Proof. by split=> *; apply/funext => h; [apply: compo1 | apply: compoA]. Qed. +HB.instance Definition _ {C : cat} {c : C} := hom_Fhom_subproof c. + +Check fun (C : cat) (x : C) => hom x : C ~>_cat U. + +Lemma hom_op {C : quiver} (c : C^op) : hom c = (@hom C)^~ c. +Proof. reflexivity. Qed. + +Lemma homFhomx {C : precat} (a b c : C) (f : a ~> b) (g : c ~> a) : + (hom c <$> f) g = g \; f. +Proof. reflexivity. Qed. + +(* nary product of categories *) +Definition dprod {I : U} (C : I -> U) := forall i, C i. + +Section hom_dprod. +Context {I : U} (C : I -> quiver). +Definition dprod_hom_subdef (a b : dprod C) := forall i, a i ~> b i. +HB.instance Definition _ := IsQuiver.Build (dprod C) dprod_hom_subdef. +End hom_dprod. +Arguments dprod_hom_subdef /. + +Section precat_dprod. +Context {I : U} (C : I -> precat). +Definition dprod_idmap_subdef (a : dprod C) : a ~> a := fun=> idmap. +Definition dprod_comp_subdef (a b c : dprod C) (f : a ~> b) (g : b ~> c) : a ~> c := + fun i => f i \; g i. +HB.instance Definition _ := IsPreCat.Build (dprod C) + dprod_idmap_subdef dprod_comp_subdef. +End precat_dprod. +Arguments dprod_idmap_subdef /. +Arguments dprod_comp_subdef /. + +Section cat_dprod. +Context {I : U} (C : I -> cat). +Local Notation type := (dprod C). +Lemma dprod_is_cat : PreCat_IsCat type. +Proof. +split=> [a b f|a b f|a b c d f g h]; apply/funext => i; +[exact: comp1o | exact: compo1 | exact: compoA]. +Qed. +HB.instance Definition _ := dprod_is_cat. +End cat_dprod. + +(* binary product *) +Section hom_prod. +Context {C D : quiver}. +Definition prod_hom_subdef (a b : C * D) := ((a.1 ~> b.1) * (a.2 ~> b.2))%type. +HB.instance Definition _ := IsQuiver.Build (C * D)%type prod_hom_subdef. +End hom_prod. + +Section precat_prod. +Context {C D : precat}. +HB.instance Definition _ := IsPreCat.Build (C * D)%type (fun=> (idmap, idmap)) + (fun a b c (f : a ~> b) (g : b ~> c) => (f.1 \; g.1, f.2 \; g.2)). +End precat_prod. + +Section cat_prod. +Context {C D : cat}. +Local Notation type := (C * D)%type. +Lemma prod_is_cat : PreCat_IsCat type. +Proof. +split=> [[a1 a2] [b1 b2] [f1 f2]|[a1 a2] [b1 b2] [f1 f2]| + [a1 a2] [b1 b2] [c1 c2] [d1 d2] [f1 f2] [g1 g2] [h1 h2]]; congr (_, _) => //=; +by [exact: comp1o | exact: compo1 | exact: compoA]. +Qed. +HB.instance Definition _ := prod_is_cat. +End cat_prod. + +(* naturality *) +HB.mixin Record IsNatural (C D : precat) (F G : C ~>_quiver D) + (n : forall c, F c ~> G c) := { + natural : forall (a b : C) (f : a ~> b), + F <$> f \; n b = n a \; G <$> f +}. +Unset Universe Checking. +HB.structure Definition Natural (C D : precat) + (F G : C ~>_quiver D) : Set := + { n of @IsNatural C D F G n }. +Set Universe Checking. +HB.instance Definition _ (C D : precat) := + IsQuiver.Build (PreFunctor.type C D) (@Natural.type C D). +HB.instance Definition _ (C D : cat) := + IsQuiver.Build (Functor.type C D) (@Natural.type C D). +Arguments natural {C D F G} n [a b] f : rename. + +Check fun (C D : cat) (F G : C ~> D) => F ~>_(C ~>_cat D) G. + +Lemma naturalx (C : precat) (D : concrete_precat) + (F G : C ~>_quiver D) (n : F ~> G) (a b : C) (f : a ~> b) g : + (concrete <$> n b) ((concrete <$> F <$> f) g) = + (concrete <$> G <$> f) ((concrete <$> n a) g). +Proof. +have /(congr1 (fun h => (concrete <$> h) g)) := natural n f. +by rewrite !Fcomp. +Qed. +Arguments naturalx {C D F G} n [a b] f. + +Lemma naturalU (C : precat) (F G : C ~>_quiver U) (n : F ~> G) + (a b : C) (f : a ~> b) g : n b (F^$ f g) = G^$ f (n a g). +Proof. exact: (naturalx n). Qed. + +Lemma natP (C D : precat) (F G : C ~>_quiver D) (n m : F ~> G) : + Natural.sort n = Natural.sort m -> n = m. +Proof. +case: n m => [/= n nP] [/= m mP] enm. +elim: _ / enm in mP *; congr Natural.Pack. +case: nP mP => [[?]] [[?]]; congr Natural.Class. +congr IsNatural.Axioms_. +exact: Prop_irrelevance. +Qed. + +Notation "F ~~> G" := (F ~>_(homs quiver) G) + (at level 99, G at level 200, format "F ~~> G"). +Notation "F ~~> G :> C ~> D" := (F ~> G :> (C ~>_quiver D)) + (at level 99, G at level 200, C, D at level 0, + format "F ~~> G :> C ~> D"). + +Definition natural_id {C D : precat} (F : C ~>_quiver D) (a : C) := \idmap_(F a). +Definition natural_id_natural (C D : cat) (F : C ~>_quiver D) : + IsNatural C D F F (natural_id F). +Proof. by constructor=> a b f; rewrite /natural_id/= compo1 comp1o. Qed. +HB.instance Definition _ C D F := @natural_id_natural C D F. + +Check fun {C D : cat} (F : C ~>_quiver D) => natural_id F : F ~> F. + +Definition natural_comp {C D : precat} (F G H : C ~>_quiver D) + (m : F ~> G) (n : G ~> H) (a : C) := m a \; n a. +Definition natural_comp_natural (C D : cat) (F G H : C ~>_quiver D) m n : + IsNatural C D F H (@natural_comp C D F G H m n). +Proof. +constructor=> a b f; rewrite /natural_comp/=. +by rewrite compoA natural -compoA natural compoA. +Qed. +HB.instance Definition _ C D F G H m n := @natural_comp_natural C D F G H m n. + +HB.instance Definition _ {C D : cat} := + Quiver_IsPreCat.Build (PreFunctor.type C D) natural_id natural_comp. +HB.instance Definition _ {C D : cat} := + Quiver_IsPreCat.Build (Functor.type C D) natural_id natural_comp. + +Lemma prefunctor_cat {C D : cat} : PreCat_IsCat (PreFunctor.type C D). +Proof. +constructor => [F G f|F G f|F G H J f g h]. +- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. +- by apply/natP/funext => a; rewrite /= /natural_comp compo1. +- by apply/natP/funext => a; rewrite /= /natural_comp compoA. +Qed. +HB.instance Definition _ C D := @prefunctor_cat C D. + +Lemma functor_cat {C D : cat} : PreCat_IsCat (Functor.type C D). +Proof. +constructor => [F G f|F G f|F G H J f g h]. +- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. +- by apply/natP/funext => a; rewrite /= /natural_comp compo1. +- by apply/natP/funext => a; rewrite /= /natural_comp compoA. +Qed. +HB.instance Definition _ C D := @functor_cat C D. + +Section nat_map_left. +Context {C D E : precat} {F G : C ~> D}. + +Definition nat_lmap (H : D ~>_quiver E) (n : forall c, F c ~> G c) : + forall c, (H \o F)%FUN c ~> (H \o G)%FUN c := fun c => H <$> n c. + +Fail Check fun (H : D ~> E) (n : F ~~> G) => nat_lmap H n : H \o F ~~> H \o G. + +Lemma nat_lmap_is_natural (H : D ~> E) (n : F ~~> G) : + IsNatural C E (H \o F) (H \o G) (nat_lmap H n). +Proof. by constructor=> a b f; rewrite /nat_lmap/= -!Fcomp natural. Qed. +HB.instance Definition _ H n := nat_lmap_is_natural H n. + +Check fun (H : D ~> E) (n : F ~~> G) => nat_lmap H n : H \o F ~~> H \o G. + +End nat_map_left. + +Notation "F n" := (nat_lmap F n) + (at level 58, format "F n", right associativity) : cat_scope. + +Section nat_map_right. +Context {C D E : precat} {F G : C ~> D}. + +Definition nat_rmap (H : E -> C) (n : forall c, F c ~> G c) : + forall c, (F \o H)%FUN c ~> (G \o H)%FUN c := fun c => n (H c). +Lemma nat_rmap_is_natural (H : E ~> C :> quiver) (n : F ~~> G) : + IsNatural E D (F \o H)%FUN (G \o H)%FUN (nat_rmap H n). +Proof. by constructor=> a b f; rewrite /nat_lmap/= natural. Qed. +HB.instance Definition _ H n := nat_rmap_is_natural H n. + +End nat_map_right. + +Notation "F <$o> n" := (nat_rmap F n) + (at level 58, format "F <$o> n", right associativity) : cat_scope. + +Definition delta (C D : cat) : C -> (D ~> C) := cst D. +Arguments delta C D : clear implicits. + +Definition map_delta {C D : cat} (a b : C) (f : a ~> b) : + delta C D a ~> delta C D b. +Proof. +apply: (@Natural.Pack _ _ (cst D a) (cst D b) (fun x => f)). +apply: Natural.Class; apply: (IsNatural.Build _ _ _ _ _). +by move=> a' b' ?; rewrite compo1 comp1o. +Defined. + +HB.instance Definition _ {C D : cat} := + IsPreFunctor.Build C (D ~> C) (delta C D) (@map_delta C D). + +Lemma delta_functor {C D : cat} : PreFunctor_IsFunctor _ _ (delta C D). +Proof. by constructor=> [a|a b c f g]; exact/natP. Qed. +HB.instance Definition _ C D := @delta_functor C D. + +HB.mixin Record IsMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { + unit : idfun ~~> M; + join : (M \o M)%FUN ~~> M; + bind : forall (a b : C), (a ~> M b) -> (M a ~> M b); + bindE : forall a b (f : a ~> M b), bind a b f = M <$> f \; join b; + unit_join : forall a, (M <$> unit a) \; join _ = idmap; + join_unit : forall a, join _ \; (M <$> unit a) = idmap; + join_square : forall a, M <$> join a \; join _ = join _ \; join _ +}. + +#[short(type="premonad")] +HB.structure Definition PreMonad (C : precat) := + {M of @PreFunctor C C M & IsMonad C M}. +#[short(type="monad")] +HB.structure Definition Monad (C : precat) := + {M of @Functor C C M & IsMonad C M}. + +HB.factory Record IsJoinMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { + unit : idfun ~~> M; + join : (M \o M)%FUN ~~> M; + unit_join : forall a, (M <$> unit a) \; join _ = idmap; + join_unit : forall a, join _ \; (M <$> unit a) = idmap; + join_square : forall a, M <$> join a \; join _ = join _ \; join _ +}. +HB.builders Context C M of IsJoinMonad C M. + HB.instance Definition _ := IsMonad.Build C M + (fun a b f => erefl) unit_join join_unit join_square. +HB.end. + +HB.mixin Record IsCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { + counit : M ~~> idfun; + cojoin : M ~~> (M \o M)%FUN; + cobind : forall (a b : C), (M a ~> b) -> (M a ~> M b); + cobindE : forall a b (f : M a ~> b), cobind a b f = cojoin _ \; M <$> f; + unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; + join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; + cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ +}. +#[short(type="precomonad")] +HB.structure Definition PreCoMonad (C : precat) := + {M of @PreFunctor C C M & IsCoMonad C M}. +#[short(type="comonad")] +HB.structure Definition CoMonad (C : precat) := + {M of @Functor C C M & IsCoMonad C M}. + +HB.factory Record IsJoinCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { + counit : M ~~> idfun; + cojoin : M ~~> (M \o M)%FUN; + unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; + join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; + cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ +}. +HB.builders Context C M of IsJoinCoMonad C M. + HB.instance Definition _ := IsCoMonad.Build C M + (fun a b f => erefl) unit_cojoin join_counit cojoin_square. +HB.end. + +Lemma idFmap (C : cat) (a b : C) (f : a ~> b) : idfun <$> f = f. +Proof. by []. Qed. + +Lemma compFmap (C D E : cat) (F : C ~> D) (G : D ~> E) (a b : C) (f : a ~> b) : + (G \o F) <$> f = G <$> F <$> f. +Proof. by []. Qed. + +(* yoneda *) +Section hom_repr. +Context {C : cat} (F : C ~>_cat U). + +Definition homF : C -> U := fun c => hom c ~~> F. + +Section nat. +Context (x y : C) (xy : x ~> y). + +(* Goal hom x ~~> F -> hom y ~~> F *) +Context (n : hom x ~~> F). +Definition homFhom c : hom y c ~> F c := fun g => n _ (xy \; g). + +Lemma homFhom_natural_subdef : IsNatural C U (hom y) F homFhom. +Proof. +by split=> a b f /=; apply/funext => g /=; + rewrite /homFhom !Ucompx/= !naturalU/= Fcomp. +Qed. +HB.instance Definition _ := homFhom_natural_subdef. +End nat. +Arguments homFhom / : clear implicits. + +HB.about IsPreFunctor.Build. +Check homFhom : forall x y : C, (x ~> y) -> (homF x -> homF y). +HB.instance Definition _ := IsPreFunctor.Build _ _ homF homFhom. +Lemma homF_functor_subproof : PreFunctor_IsFunctor _ _ homF. +Proof. +split=> [a|a b c f g]. + apply/funext => -[/= f natf]. + apply: natP => //=; apply: funext => b; apply: funext => g/=. + by rewrite comp1o. +apply/funext => -[/= h natf]. +apply: natP => //=; apply: funext => d; apply: funext => k/=. +by rewrite compoA. +Qed. +HB.instance Definition _ := homF_functor_subproof. + +Section pointed. +Context (c : C). +Definition hom_repr : homF c ~> F c := fun f => f _ idmap. +Arguments hom_repr /. + +Definition repr_hom (fc : F c) a : hom c a ~> F a := + fun f => F^$ f fc. +Arguments repr_hom / : clear implicits. +Lemma repr_hom_subdef (fc : F c) : IsNatural _ _ _ _ (repr_hom fc). +Proof. by split=> a b f /=; apply/funext=> x; rewrite !Ucompx/= Fcomp. Qed. +HB.instance Definition _ {fc : F c} := repr_hom_subdef fc. + +Definition repr_hom_nat : F c ~> homF c := repr_hom. + +Lemma hom_reprK : cancel hom_repr repr_hom_nat. +Proof. +move=> f; apply/natP; apply/funext => a; apply/funext => g /=. +by rewrite -naturalU/=; congr (f _ _); apply: comp1o. +Qed. +Lemma repr_homK : cancel (repr_hom : F c ~> homF c) hom_repr. +Proof. by move=> fc; rewrite /= F1. Qed. +End pointed. +Arguments hom_repr /. +Arguments repr_hom /. + +Lemma hom_repr_natural_subproof : IsNatural _ _ _ _ hom_repr. +Proof. +split=> a b f /=; apply/funext => n /=; rewrite !Ucompx/= compo1/=. +by rewrite -naturalU/=; congr (n _ _); apply/esym/comp1o. +Qed. +HB.instance Definition _ := hom_repr_natural_subproof. + +(* show this from the previous proof *) +Lemma hom_natural_repr_subproof : IsNatural _ _ _ _ repr_hom_nat. +Proof. +split=> a b f /=; apply: funext => fa /=; rewrite !Ucompx/=. +apply: natP; apply: funext => c /=; apply: funext => d /=. +by rewrite Fcomp Ucompx/=. +Qed. +HB.instance Definition _ := hom_natural_repr_subproof. + +Definition hom_repr_nat : homF ~~> F := hom_repr. +Definition repr_hom_nat_nat : F ~~> homF := repr_hom_nat. + +End hom_repr. + +(* comma categories *) +Module comma. +Section homcomma. +Context {C D E : precat} (F : C ~> E) (G : D ~> E). + +Definition type := { x : C * D & F x.1 ~> G x.2 }. +Definition hom_subdef (a b : type) := { + f : tag a ~> tag b & F <$> f.1 \; tagged b = tagged a \; G <$> f.2 + }. +HB.instance Definition _ := IsQuiver.Build type hom_subdef. +End homcomma. +Arguments hom_subdef /. +Section comma. +Context {C D E : cat} (F : C ~> E) (G : D ~> E). +Notation type := (type F G). + +Program Definition idmap_subdef (a : type) : a ~> a := @Tagged _ idmap _ _. +Next Obligation. by rewrite !F1 comp1o compo1. Qed. +Program Definition comp_subdef (a b c : type) + (f : a ~> b) (g : b ~> c) : a ~> c := + @Tagged _ (tag f \; tag g) _ _. +Next Obligation. by rewrite !Fcomp -compoA (tagged g) compoA (tagged f) compoA. Qed. +HB.instance Definition _ := IsPreCat.Build type idmap_subdef comp_subdef. +Arguments idmap_subdef /. +Arguments comp_subdef /. + +Lemma comma_homeqP (a b : type) (f g : a ~> b) : projT1 f = projT1 g -> f = g. +Proof. +case: f g => [f fP] [g +]/= eqfg; case: _ / eqfg => gP. +by congr existT; apply: Prop_irrelevance. +Qed. + +Lemma comma_is_cat : PreCat_IsCat type. +Proof. +by split=> [[a fa] [b fb] [*]|[a fa] [b fb] [*]|*]; + apply/comma_homeqP; rewrite /= ?(comp1o, compo1, compoA). +Qed. +HB.instance Definition _ := comma_is_cat. +End comma. +End comma. +Notation "F `/` G" := (@comma.type _ _ _ F G) + (at level 40, G at level 40, format "F `/` G") : cat_scope. +Notation "a /` G" := (cst unit a `/` G) + (at level 40, G at level 40, format "a /` G") : cat_scope. +Notation "F `/ b" := (F `/` cst unit b) + (at level 40, b at level 40, format "F `/ b") : cat_scope. +Notation "a / b" := (cst unit a `/ b) : cat_scope. + +Definition obj (C : quiver) : Type := C. +HB.mixin Record IsInitial {C : quiver} (i : obj C) := { + to : forall c, i ~> c; + to_unique : forall c (f : i ~> c), f = to c +}. +#[short(type="initial")] +HB.structure Definition Initial {C : quiver} := {i of IsInitial C i}. + +HB.mixin Record IsTerminal {C : quiver} (t : obj C) := { + from : forall c, c ~> t; + from_unique : forall c (f : c ~> t), f = from c +}. +#[short(type="terminal")] +HB.structure Definition Terminal {C : quiver} := {t of IsTerminal C t}. +#[short(type="universal")] +HB.structure Definition Universal {C : quiver} := + {u of Initial C u & Terminal C u}. + +(* Definition hom' {C : precat} (a b : C) := a ~> b. *) +(* (* Bug *) *) +(* Identity Coercion hom'_hom : hom' >-> hom. *) + +(* HB.mixin Record IsMono {C : precat} (b c : C) (f : hom b c) := { *) +(* monoP : forall (a : C) (g1 g2 : a ~> b), g1 \; f = g2 \; f -> g1 = g2 *) +(* }. *) +(* #[short(type="mono")] *) +(* HB.structure Definition Mono {C : precat} (a b : C) := {m of IsMono C a b m}. *) +(* Notation "a >~> b" := (mono a b) *) +(* (at level 99, b at level 200, format "a >~> b") : cat_scope. *) +(* Notation "C >~>_ T D" := (@mono T C D) *) +(* (at level 99, T at level 0, only parsing) : cat_scope. *) + +(* HB.mixin Record IsEpi {C : precat} (a b : C) (f : hom a b) := { *) +(* epiP : forall (c : C) (g1 g2 : b ~> c), g1 \o f = g2 \o f -> g1 = g2 *) +(* }. *) +(* #[short(type="epi")] *) +(* HB.structure Definition Epi {C : precat} (a b : C) := {e of IsEpi C a b e}. *) +(* Notation "a ~>> b" := (epi a b) *) +(* (at level 99, b at level 200, format "a ~>> b") : cat_scope. *) +(* Notation "C ~>>_ T D" := (@epi T C D) *) +(* (at level 99, T at level 0, only parsing) : cat_scope. *) + +(* #[short(type="iso")] *) +(* HB.structure Definition Iso {C : precat} (a b : C) := *) +(* {i of @Mono C a b i & @Epi C a b i}. *) +(* Notation "a <~> b" := (epi a b) *) +(* (at level 99, b at level 200, format "a <~> b") : cat_scope. *) +(* Notation "C <~>_ T D" := (@epi T C D) *) +(* (at level 99, T at level 0, only parsing) : cat_scope. *) + +HB.mixin Record IsRightAdjoint (D C : precat) (R : D -> C) + of @PreFunctor D C R := { + L_ : C ~> D; + phi : forall c d, (L_ c ~> d) -> (c ~> R d); + psy : forall c d, (c ~> R d) -> (L_ c ~> d); + phi_psy c d : (phi c d \o psy c d)%FUN = @id (c ~> R d); + psy_phi c d : (psy c d \o phi c d)%FUN = @id (L_ c ~> d) +}. +#[short(type="right_adjoint")] +HB.structure Definition RightAdjoint (D C : precat) := + { R of @Functor D C R & IsRightAdjoint D C R }. +Arguments L_ {_ _}. +Arguments phi {D C s} {c d}. +Arguments psy {D C s} {c d}. + + +HB.mixin Record PreCat_IsMonoidal C of PreCat C := { + onec : C; + (* prod1 : @hom precat (C * C)%type C ; *) + prod : (C * C)%type ~>_precat C; +}. +#[short(type="premonoidal")] +#[verbose] +HB.structure Definition PreMonoidal := { C of PreCat C & PreCat_IsMonoidal C }. +Notation premonoidal := premonoidal. +Arguments prod {C} : rename. +Notation "a * b" := (prod (a, b)) : cat_scope. +Reserved Notation "f <*> g" (at level 40, g at level 40, format "f <*> g"). +Notation "f <*> g" := (prod^$ (f, g)) (only printing) : cat_scope. +Notation "f <*> g" := (prod^$ ((f, g) : (_, _) ~> (_, _))) + (only parsing) : cat_scope. +Notation "1" := onec : cat_scope. + +Definition hom_cast {C : quiver} {a a' : C} (eqa : a = a') {b b' : C} (eqb : b = b') : + (a ~> b) -> (a' ~> b'). +Proof. now elim: _ / eqa; elim: _ / eqb. Defined. + +HB.mixin Record PreFunctor_IsMonoidal (C D : premonoidal) F of + @PreFunctor C D F := { + fun_one : F 1 = 1; + fun_prod : forall (x y : C), F (x * y) = F x * F y; +}. +#[short(type="monoidal_prefunctor")] +HB.structure Definition MonoidalPreFunctor C D := + { F of @PreFunctor_IsMonoidal C D F }. +Arguments fun_prod {C D F x y} : rename. +(* Arguments fun_prodF {C D F x x'} f {y y'} g : rename. *) +Unset Universe Checking. +HB.instance Definition _ := IsQuiver.Build premonoidal MonoidalPreFunctor.type. +Set Universe Checking. + +HB.instance Definition _ (C : quiver) := + IsPreFunctor.Build (C * C)%type C fst + (fun (a b : C * C) (f : a ~> b) => f.1). +HB.instance Definition _ (C : quiver) := + IsPreFunctor.Build (C * C)%type C snd + (fun (a b : C * C) (f : a ~> b) => f.2). + +Definition prod3l {C : premonoidal} (x : C * C * C) : C := + (x.1.1 * x.1.2) * x.2. +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build _ C prod3l + (fun a b (f : a ~> b) => (f.1.1 <*> f.1.2) <*> f.2). + +Definition prod3r {C : premonoidal} (x : C * C * C) : C := + x.1.1 * (x.1.2 * x.2). +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build _ C prod3r + (fun a b (f : a ~> b) => f.1.1 <*> (f.1.2 <*> f.2)). + +Definition prod1r {C : premonoidal} (x : C) : C := 1 * x. +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build C C prod1r + (fun (a b : C) (f : a ~> b) => \idmap_1 <*> f). + +Definition prod1l {C : premonoidal} (x : C) : C := x * 1. +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build C C prod1l + (fun (a b : C) (f : a ~> b) => f <*> \idmap_1). + +HB.mixin Record PreMonoidal_IsMonoidal C of PreMonoidal C := { + prodA : prod3l ~~> prod3r; + prod1c : prod1r ~~> idfun; + prodc1 : prod1l ~~> idfun; + prodc1c : forall (x y : C), + prodA (x, 1, y) \; \idmap_x <*> prod1c y = prodc1 x <*> \idmap_y; + prodA4 : forall (w x y z : C), + prodA (w * x, y, z) \; prodA (w, x, y * z) = + prodA (w, x, y) <*> \idmap_z \; prodA (w, x * y, z) \; \idmap_w <*> prodA (x, y, z); +}. + +Unset Universe Checking. +#[short(type="monoidal")] +#[verbose] +HB.structure Definition Monoidal : Set := + { C of PreMonoidal_IsMonoidal C & PreMonoidal C }. +Set Universe Checking. + +(******************************************************************) + + +Record cospan (Q : quiver) (A B : Q) := Cospan { + top : Q; + left2top : A ~> top; + right2top : B ~> top +}. + +Section cospans. +Variables (Q : precat) (A B : Q). +Record cospan_map (c c' : cospan A B) := CospanMap { + top_map : top c ~> top c'; + left2top_map : left2top c \; top_map = left2top c'; + right2top_map : right2top c \; top_map = right2top c'; +}. +HB.instance Definition _ := IsQuiver.Build (cospan A B) cospan_map. + +Lemma cospan_mapP (c c' : cospan A B) (f g : c ~> c') : + top_map f = top_map g <-> f = g. +Admitted. +End cospans. + +Section cospans_in_cat. +Variables (Q : cat) (A B : Q). +Definition cospan_idmap (c : cospan A B) := + @CospanMap Q A B c c idmap (compo1 _) (compo1 _). +Program Definition cospan_comp (c1 c2 c3 : cospan A B) + (f12 : c1 ~> c2) (f23 : c2 ~> c3) := + @CospanMap Q A B c1 c3 (top_map f12 \; top_map f23) _ _. +Next Obligation. by rewrite compoA !left2top_map. Qed. +Next Obligation. by rewrite compoA !right2top_map. Qed. +HB.instance Definition _ := IsPreCat.Build (cospan A B) cospan_idmap cospan_comp. + +Lemma cospan_are_cats : PreCat_IsCat (cospan A B). +Proof. +constructor=> [a b f|a b f|a b c d f g h]. +- by apply/cospan_mapP => /=; rewrite comp1o. +- by apply/cospan_mapP => /=; rewrite compo1. +- by apply/cospan_mapP => /=; rewrite compoA. +Qed. +HB.instance Definition _ := cospan_are_cats. +End cospans_in_cat. + +Section spans_and_co. +Variables (Q : quiver) (A B : Q). +Definition span := @cospan Q^op A B. +Definition bot (s : span) : Q := top s. +Definition bot2left (s : span) : bot s ~>_Q A := left2top s. +Definition bot2right (s : span) : bot s ~>_Q B := right2top s. +Definition Span (C : Q) (f : C ~> A) (g : C ~> B) : span := + @Cospan Q^op A B C f g. +End spans_and_co. + +HB.instance Definition _ (Q : precat) (A B : Q) := + Quiver.copy (span A B) (@cospan Q^op A B)^op. +HB.instance Definition _ (Q : cat) (A B : Q) := + Cat.copy (span A B) (@cospan Q^op A B)^op. + +Section bot_map. +Variables (C : cat) (A B : C) (s s' : span A B) (f : s ~> s'). +Definition bot_map : bot s ~> bot s' := top_map f. +Lemma bot2left_map : bot_map \; bot2left s' = bot2left s. +Proof. exact: left2top_map f. Qed. +Lemma bot2right_map : bot_map \; bot2right s' = bot2right s. +Proof. exact: right2top_map f. Qed. +End bot_map. + +HB.mixin Record isPrePullback (Q : precat) (A B : Q) + (c : cospan A B) (s : span A B) := { + is_square : bot2left s \; left2top c = bot2right s \; right2top c; +}. +#[short(type=prepullback)] +HB.structure Definition PrePullback Q A B (c : cospan A B) := + {s of isPrePullback Q A B c s}. +Arguments prepullback {Q A B} c. + +Section prepullback. +Variables (Q : precat) (A B : Q) (c : cospan A B). +HB.instance Definition _ := + IsQuiver.Build (prepullback c) + (fun a b => (a : span A B) ~>_(span A B) (b : span A B)). +Lemma eq_prepullbackP (p q : prepullback c) : + p = q :> span _ _ <-> p = q. +Admitted. +End prepullback. +Section prepullback. +Variables (Q : cat) (A B : Q) (csp : cospan A B). +(* TODO: why can't we do that? *) +(* HB.instance Definition _ := Cat.on (prepullback csp). *) +HB.instance Definition _ := + Quiver_IsPreCat.Build (prepullback csp) + (fun a => \idmap_(a : span A B)) + (* TODO: study how to make this coercion trigger + even when the target is not reduced to span *) + (fun a b c f g => f \; g). +Lemma prepullback_is_cat : PreCat_IsCat (prepullback csp). +Proof. (* should be copied from the cat on span *) +constructor=> [a b f|a b f|a b c d f g h]; + [exact: comp1o|exact: compo1|exact: compoA]. +Qed. +End prepullback. + +HB.tag Definition pb_terminal (Q : precat) + (A B : Q) (c : cospan A B) (s : prepullback c) : + obj (prepullback c) := s. + +#[wrapper] +HB.mixin Record prepullback_isTerminal (Q : precat) + (A B : Q) (c : cospan A B) + (s : span A B) of isPrePullback Q A B c s := { + prepullback_terminal : + IsTerminal (prepullback c) (pb_terminal s) +}. +#[short(type="pullback"), verbose] +HB.structure Definition Pullback (Q : precat) + (A B : Q) (c : cospan A B) := + {s of isPrePullback Q A B c s + & IsTerminal (prepullback c) (pb_terminal s) }. + +Notation pbsquare u v f g := + (Pullback _ (Cospan f g) (Span u v)). + +Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). + +(******************************************************************) + +(*** ENRICHED CATEGORIES *) + +Declare Scope encat_scope. +Delimit Scope encat_scope with encat. +Local Open Scope encat_scope. + +(* Enrichment in a monoidal category, following + https://ncatlab.org/nlab/show/enriched+category +*) +HB.mixin Record IsEnQuiver (V: Type) C := { + hom_object : C -> C -> V + }. +Unset Universe Checking. +HB.structure Definition EnQuiver (V: Type) : Set := + { C of IsEnQuiver V C }. +Set Universe Checking. + +(* Monoidal precategory with the enrichment operators (no axioms) *) +HB.mixin Record IsEnPreCat (V: PreMonoidal.type) C of + EnQuiver (PreMonoidal.sort V) C := { + id_element : forall (a: C), + @hom V onec (hom_object a a) ; + comp_morphism : forall (a b c: C), + @hom V (@hom_object V C b c * @hom_object V C a b) + (@hom_object V C a c) +}. +Unset Universe Checking. +HB.structure Definition EnPreCat (V: PreMonoidal.type) : Set := + { C of IsEnPreCat V C }. +Set Universe Checking. + +Notation "a ~^ b" := (hom_object a b) + (at level 99, b at level 200, format "a ~^ b") : encat_scope. +Notation "a ~^_ ( V , C ) b" := (@hom_object V C a b) + (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. +Notation "~^IE a" := (id_element a) + (at level 99, format "~^IE a") : cat_scope. +Notation "~^IE_ ( V , C ) a" := (@id_element V C a) + (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. +(* not working *) +Notation "~^CM a b c" := (comp_morphism a b c) + (at level 99, + format "~^CM a b c") : cat_scope. +Notation "~^CM_ ( V , C ) a b c" := (@comp_morphism V C a b c) + (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. + +(* V-enriched category: + V is the monoidal category; + C is the base category that gets enriched +*) +HB.mixin Record IsEnCat (V: Monoidal.type) C of EnPreCat V C := { + ecat_comp_assoc : forall a b c d: C, + forall alpha: + (((c ~^_(V,C) d) * (b ~^_(V,C) c)) * (a ~^_(V,C) b)) ~>_V + ((c ~^_(V,C) d) * ((b ~^_(V,C) c) * (a ~^_(V,C) b))), + ((@comp_morphism V C b c d) <*> (@idmap V (a ~^_(V,C) b))) \; + (@comp_morphism V C a b d) + = + alpha \; + ((@idmap V (c ~^_(V,C) d)) <*> (@comp_morphism V C a b c)) \; + (@comp_morphism V C a c d) ; + + ecat_comp_left_unital : forall a b: C, + forall l: onec * (a ~^_(V,C) b) ~>_V (a ~^_(V,C) b), + l = ((@id_element V C b) <*> (@idmap V (a ~^_(V,C) b))) \; + (@comp_morphism V C a b b) ; + ecat_comp_right_unital : forall a b: C, + forall r: (a ~^_(V,C) b) * onec ~>_V (a ~^_(V,C) b), + r = ((@idmap V (a ~^_(V,C) b)) <*> (@id_element V C a)) \; + (@comp_morphism V C a a b) +}. +Unset Universe Checking. +#[verbose] +HB.structure Definition EnCat (V: Monoidal.type) : Set := { C of IsEnCat V C }. +Set Universe Checking. + + + +(*** DOUBLE CATEGORIES (REVISED) *) + +(* A quiver from which horizontal morphisms arise (just a copy of quiver) *) +HB.mixin Record IsHQuiver C := { + hhom : C -> C -> U + }. +Unset Universe Checking. +#[short(type="hquiver")] +HB.structure Definition HQuiver : Set := { C of IsHQuiver C }. +Set Universe Checking. + +(* domain-specific sigma-type to represent the set of morphims + (needed for 2-objects, i.e. horizontal morphisms) *) +Record Total2 T (h: T -> T -> U) : Type := HO { + source : T; + target : T; + this_morph : h source target }. + +(* the set of horizontal morphisms. + HB.tag needed to identify HHomSet as lifter *) +HB.tag Definition HHomSet (C: hquiver) := Total2 (@hhom C). + +(* source functor (for horizontal morphisms): D1 -> D0. + defined as object-level function, by functoriality lifted to a + (2-cell, vertical) morphism-level one *) +HB.tag Definition HSource C := fun (X: HHomSet C) => @source C (@hhom C) X. +(* target functor (for horizontal morphisms): D1 -> D0. *) +HB.tag Definition HTarget C := fun (X: HHomSet C) => @target C (@hhom C) X. + +(* D1 quiver requirement. *) +#[wrapper] +HB.mixin Record IsD1Quiver T of HQuiver T := { + d1_quiver : IsQuiver (@HHomSet T) }. +Unset Universe Checking. +#[short(type="d1quiver")] +HB.structure Definition D1Quiver : Set := { C of IsD1Quiver C }. +Set Universe Checking. + +(* all the quivers required by a double category *) +Unset Universe Checking. +#[short(type="dquiver")] +HB.structure Definition DQuiver : Set := + { C of Quiver C & HQuiver C & IsD1Quiver C }. +Set Universe Checking. + +(* used to define composable pairs of morphisms as a set *) +Record GenComp T (h: T -> T -> U) := GC { + c_one : T; + c_two : T ; + c_three : T; + c_first : h c_one c_two ; + c_second : h c_two c_three +}. + +(* composable pairs of horizontal morphisms as a set *) +HB.tag Definition HComp (C: hquiver) := GenComp (@hhom C). + +(* +(* pullback category condition (i.e. (HComp T) is a category). + requires T to be a category, and (HHomSet T) to be a quiver *) +#[wrapper] +HB.mixin Record IsHCompCat T of Cat T & DQuiver T := { + hcompcat : Cat (HComp T) }. +Unset Universe Checking. +#[short(type="hcompcat")] +HB.structure Definition HCompCat : Set := { C of IsHCompCat C }. +Set Universe Checking. +*) + +(* c2unit - horizontal unit functor. + + c2comp - horizontal composition functor. + + Both specified as object-level functions, to be lifted by + functoriality to morphism-level ones. + + At the object level, c2unit gives a horizontal identity morphism + for each D0 object. At the morphism level, it gives horizontal + 2-cell identity for each vertical morphism. + + In the case of HComp, relying on functoriality requires some care + in defining the pullback category, making sure that adjacency at + the object-level (between horizontal morphisms) is matched by + adjacency at the morphism-level (between 2-cells). *) +HB.mixin Record IsC2Quiver T of DQuiver T (* & HCompCat T *) := { + h2unit : forall a: T, @hhom T a a ; + h2comp : forall (a b c: T), + @hhom T a b -> @hhom T b c -> @hhom T a c; + + c2unit : T -> HHomSet T ; + c2comp : HComp T -> HHomSet T ; + + c2unit_eq : forall a: T, c2unit a = @HO T (@hhom T) a a (h2unit a) ; + c2comp_eq1 : forall (a b c: T) (h1: @hhom T a b) (h2: @hhom T b c), + c2comp (@GC T (@hhom T) a b c h1 h2) = + @HO T (@hhom T) a c (h2comp a b c h1 h2) +}. +Unset Universe Checking. +#[short(type="c2quiver")] +HB.structure Definition C2Quiver : Set := { C of IsC2Quiver C }. +Set Universe Checking. + +(* Precategory based on the DQuiver (i.e. precategory D1) - only, + instead of making it inherit from D1Quiver, we make it inherit from + DQuiver. DOES NOT WORK WITH C2Quiver. Gives: + vertical 2-cell identity morphism. + vertical 2-cell composition. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsC2PreCat T of C2Quiver T := { + c2precat : Quiver_IsPreCat (@HHomSet T) }. +#[short(type="c2precat")] +HB.structure Definition C2PreCat : Set := { C of IsC2PreCat C }. +Set Universe Checking. + +(* The category based on the DQuiver (i.e. category D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsC2Cat T of C2PreCat T := { + c2cat : PreCat_IsCat (@HHomSet T) }. +#[short(type="h2cat")] +HB.structure Definition C2Cat : Set := { C of IsC2Cat C }. +Set Universe Checking. + +(* unit functor: D0 -> D1 *) +HB.tag Definition UnitF (C: c2quiver) := + fun (x: C2Quiver.sort C) => @c2unit C x. +(* composition functor: D1 * D1 -> D1 *) +HB.tag Definition CompF (C: c2quiver) := + fun (x: HComp C) => @c2comp C x. + +(* source prefunctor. + HHomSet T is the quiver of the 2-morphisms, thanks to H2Quiver. + T is the quiver of 1-morphisms. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHSPreFunctor T of Cat T & C2Cat T (* & HCompCat T *) := { + h2s_prefunctor : IsPreFunctor (HHomSet T) T (@HSource T) }. +HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. +Set Universe Checking. + +(* target prefunctor. *) +Unset Universe Checking. +#[wrapper] + HB.mixin Record IsHTPreFunctor T of HSPreFunctor T := { + h2t_prefunctor : IsPreFunctor (HHomSet T) T (@HTarget T) }. +HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. +Set Universe Checking. + +(* source functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record HSPreFunctor_IsFunctor T of HTPreFunctor T := { + h2s_functor : PreFunctor_IsFunctor (HHomSet T) T (@HSource T) }. +HB.structure Definition HSFunctor : Set := {C of HSPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* target functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record HTPreFunctor_IsFunctor T of HSFunctor T := { + h2t_functor : PreFunctor_IsFunctor (HHomSet T) T (@HTarget T) }. +HB.structure Definition HTFunctor : Set := {C of HTPreFunctor_IsFunctor C}. +Set Universe Checking. + +(** HComp quiver *) +Definition HComp_hom (T: HTFunctor.type) := + (fun (A B: HComp T) => match (A, B) with + | (@GC _ _ a1 b1 c1 h1 k1, @GC _ _ a2 b2 c2 h2 k2) => + let h1' := @HO T (@hhom T) a1 b1 h1 + in let k1' := @HO T (@hhom T) b1 c1 k1 + in let h2' := @HO T (@hhom T) a2 b2 h2 + in let k2' := @HO T (@hhom T) b2 c2 k2 + in sigT (fun (hh: @hom (HHomSet T) h1' h2') => + (sigT (fun (kk: @hom (HHomSet T) k1' k2') => + @Fhom _ _ (@HTarget T) h1' h2' hh = + @Fhom _ _ (@HSource T) k1' k2' kk))) + end). + +HB.instance Definition HCompQuiver (T: HTFunctor.type) : IsQuiver (HComp T) := + IsQuiver.Build (HComp T) (fun A B => @HComp_hom T A B). + + +Program Definition HCompPreCat (T: HTFunctor.type) : + Quiver_IsPreCat (HComp T) := + Quiver_IsPreCat.Build (HComp T) + (fun x: HComp T => _) (fun a b c: HComp T => _). +Obligation 1. +Admitted. +Obligation 2. +Admitted. + + +Definition HCompId (T: HTFunctor.type) : forall A: HComp T, HComp_hom A A := + fun A => match A with + | @GC _ _ a b c h k => + let h' := @HO T (@hhom T) a b h + in let k' := @HO T (@hhom T) b c k + in existT (idmap (HHomSet T) h') + (existT (idmap (HHomSet T) k') ) + + + +(* unit prefunctor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHUPreFunctor T of C2Quiver T & HTFunctor T := + { h2u_prefunctor : IsPreFunctor T (HHomSet T) (@UnitF T) }. +HB.structure Definition HUPreFunctor : Set := {C of IsHUPreFunctor C}. +Set Universe Checking. + +(* unit functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record HUPreFunctor_IsFunctor T of HUPreFunctor T := { + h2u_functor : PreFunctor_IsFunctor T (HHomSet T) (@UnitF T) }. +HB.structure Definition HUFunctor : Set := {C of HUPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* composition prefunctor *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHCPreFunctor T of HUFunctor T := + { h2c_prefunctor : IsPreFunctor (HComp T) (HHomSet T) (@CompF T) }. +HB.structure Definition HCPreFunctor : Set := {C of IsHCPreFunctor C}. +Set Universe Checking. + +(* composition functor *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record HCPreFunctor_IsFunctor T of HCPreFunctor T := { + h2c_functor : PreFunctor_IsFunctor (HComp T) (HHomSet T) (@CompF T) }. +HB.structure Definition HCFunctor : Set := {C of HCPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* 2-morphisms *) +Definition c2hom (D: C2Quiver.type) := @hom (@HHomSet D). + +(* The set of D1 morphisms *) +HB.tag Definition C2HomSet (C: C2Quiver.type) := Total2 (@c2hom C). + +(* horizontal 2-cell unit (maps vertical morphisms to horizontally + unitary 2-cells) *) +Definition HC2Unit (T: HUFunctor.type) (a b: T) (m: @hom T a b) : + c2hom (UnitF a) (UnitF b) := @Fhom _ _ (@UnitF T) a b m. + +(* horizontal 2-cell composition: maps two adjecent pairs of + horizontal morphisms (a and b) and a pullback-category morphism + between them (m, which basically gives two adjecent cells) to a + 2-cell morphism between the horizontal composition (CompF) of each + pair *) +Definition HC2Comp (T: HCFunctor.type) (a b: HComp T) + (m: @hom (HComp T) a b) : + c2hom (CompF a) (CompF b) := @Fhom _ _ (@CompF T) a b m. + +(* Double category complete with properties of horizontal 2-cell + identity and composition *) +Unset Universe Checking. +HB.mixin Record IsDCat T of HCFunctor T := { + left_unital : forall (a0 a1 b0 b1: T) + (r: @hhom T a0 a1) (s: @hhom T b0 b1), + let rr := @HO T (@hhom T) a0 a1 r in + let ss := @HO T (@hhom T) b0 b1 s in + let aa := @h2unit T a0 in + let bb := @h2unit T b0 in + @hom (HHomSet T) rr ss = + @hom (HHomSet T) (c2comp (@GC T _ a0 a0 a1 aa r)) + (c2comp (@GC T _ b0 b0 b1 bb s)) ; + + right_unital : forall (a0 a1 b0 b1: T) + (r: @hhom T a0 a1) (s: @hhom T b0 b1), + let rr := @HO T (@hhom T) a0 a1 r in + let ss := @HO T (@hhom T) b0 b1 s in + let aa := @h2unit T a1 in + let bb := @h2unit T b1 in + @hom (HHomSet T) rr ss = + @hom (HHomSet T) (c2comp (@GC T _ a0 a1 a1 r aa)) + (c2comp (@GC T _ b0 b1 b1 s bb)) ; + + associator : forall (a0 a1 a2 a3: T) + (h1: @hhom T a0 a1) (h2: @hhom T a1 a2) + (h3: @hhom T a2 a3) (x: HHomSet T), + let h23 := h2comp a1 a2 a3 h2 h3 in + let h12 := h2comp a0 a1 a2 h1 h2 in + let hh1 := h2comp a0 a1 a3 h1 h23 in + let hh2 := h2comp a0 a2 a3 h12 h3 in + @hom (HHomSet T) (@HO T (@hhom T) a0 a3 hh1) x = + @hom (HHomSet T) (@HO T (@hhom T) a0 a3 hh2) x +}. +#[short(type="dcat")] +HB.structure Definition DCat : Set := { C of IsDCat C }. +Set Universe Checking. + + + +(*********************************************************************) +(**** GARBAGE ****************************************************) + +(* Double category *) +Unset Universe Checking. +HB.mixin Record IsDCat T of HCFunctor T := { + left_unital : forall (a b: T) (r: @hhom T a b), + let rr := @HO T (@hhom T) a b r in + let aa := @h2unit T a in + @hom (HHomSet T) (c2comp (@GC T _ a a b aa r)) rr ; + + right_unital : forall (a b: T) (r: @hhom T a b), + let rr := @HO T (@hhom T) a b r in + let bb := @h2unit T b in + @hom (HHomSet T) (c2comp (@GC T _ a b b r bb)) rr ; +}. + +(* Double category *) +Unset Universe Checking. +HB.mixin Record IsDCat T of HCFunctor T := { + left_unital : forall (a b c d: T) (r: @hhom T a c) (s: @hhom T b d), + forall (ha: @hhom T a a) (hb: @hhom T b b), + @hom (HHomSet T) (@HO T (@hhom T) a c r) (@HO T (@hhom T) b d s) = + @hom (HHomSet T) (c2comp (@GC T _ a a c ha r)) + (c2comp (@GC T _ b b d hb s)) ; + + right_unital : forall (a b c d: T) (r: @hhom T a c) (s: @hhom T b d), + forall (ha: @hhom T c c) (hb: @hhom T d d), + @hom (HHomSet T) (@HO T (@hhom T) a c r) (@HO T (@hhom T) b d s) = + @hom (HHomSet T) (c2comp (@GC T _ a c c r ha)) + (c2comp (@GC T _ b d d s hb)) ; + + associator : forall (a0 a1 a2 a3: T) + (h1: @hhom T a0 a1) (h2: @hhom T a1 a2) + (h3: @hhom T a2 a3), + forall (h12: @hhom T a0 a2) (h23: @hhom T a1 a3) (x: HHomSet T), + @HO T (@hhom T) a1 a3 h23 = c2comp (@GC T _ a1 a2 a3 h2 h3) -> + @HO T (@hhom T) a0 a2 h12 = c2comp (@GC T _ a0 a1 a2 h1 h2) -> + let hh1 := c2comp (@GC T _ a0 a1 a3 h1 h23) in + let hh2 := c2comp (@GC T _ a0 a2 a3 h12 h3) in + @hom (HHomSet T) hh1 x = @hom (HHomSet T) hh2 x +}. +#[short(type="dcat")] +HB.structure Definition DCat : Set := { C of IsDCat C }. +Set Universe Checking. + + +(* a sequence of two adjacent morphisms (pullback object), + which we can use to represent composition *) +Record GenComp' T (h: T -> T -> U) := GCmp { + comp_first : @Total2 T h ; + comp_second : @Total2 T h ; + comp_adjacent : target comp_first = source comp_second +}. +(* horizontal morphism composition type. ultimately though, SHOULD + DEPEND ON D0 (hence on 'Quiver T' and 'Quiver (T * T)) *) +Definition HComp' (C: hquiver) := GenComp' (@hhom C). + + +(* source prefunctor. + HHomSet T is the quiver of the 2-morphisms, thanks to H2Quiver. + T is the quiver of 1-morphisms. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHSPreFunctor T of Cat T & H2Cat T := { + h2s_prefunctor : IsPreFunctor (HHomSet T) T (@Source T) }. +HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. +Set Universe Checking. + +(* target prefunctor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHTPreFunctor T of Cat T & H2Cat T := { + h2t_prefunctor : IsPreFunctor (HHomSet T) T (@Target T) }. +HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. +Set Universe Checking. + + + +HB.mixin Record IsC2Quiver T of Quiver T & PreC2Quiver T := { + c2left : C2HomSet T -> VHomSet T ; + c2right : C2HomSet T -> VHomSet T ; + + c2unit : forall x:T, HHomSet T ; + + c2left_eq1 : forall d: C2HomSet T, + source (source d) = source (c2left d) ; + c2left_eq2 : forall d: C2HomSet T, + source (target d) = target (c2left d) ; + c2right_eq1 : forall d: C2HomSet T, + target (source d) = source (c2right d) ; + c2right_eq2 : forall d: C2HomSet T, + target (target d) = target (c2right d) ; + + c2unit_eq : forall a: T, + let h := c2unit a in source h = target h ; + +}. +Unset Universe Checking. +#[short(type="c2quiver")] +HB.structure Definition C2Quiver : Set := { C of IsC2Quiver C }. +Set Universe Checking. + +(* left edge functor: D1 -> D0 *) +HB.tag Definition C2Left (C: C2Quiver.type) := + fun (X: C2HomSet C) => @c2left C X. +(* right edge functor: D1 -> D0 *) +HB.tag Definition C2Right (C: C2Quiver.type) := + fun (X: C2HomSet C) => @c2right C X. + + + +(* we need horizontal morphisms to form at least a precategory *) +HB.mixin Record HQuiver_IsHPreCat C of HQuiver C := { + hidmap : forall (a : C), hhom a a; + hcomp : forall d : D1_prod C, + hhom (source (d1_first d)) (target (d1_second d)); +}. +Unset Universe Checking. +#[short(type="hprecat")] +HB.structure Definition HPreCat : Set := { C of HQuiver_IsHPreCat C }. +Set Universe Checking. + + +HB.mixin Record IsH2Grid T of Quiver T & H2Quiver T := { + h2left_edge : H2HomSet T -> VHomSet T ; + h2right_edge : H2HomSet T -> VHomSet T +}. +Unset Universe Checking. +#[short(type="h2grid")] +HB.structure Definition H2Grid : Set := { C of IsH2Grid C }. +Set Universe Checking. + +(* adding the map to define (1) the unit functor D0 -> D1 + and (2) composition D1 *d0 D1 -> D1 *) +HB.mixin Record IsH2FQuiver T of H2Quiver T & H2Grid T & PreCat T := { + h2unit_map: forall x:T, HHomSet T ; + h2unit_map_eq: forall x:T, h2unit_map x = + @HO T (@hhom T) x x (hidmap x) ; + h2comp_map: D1_prod T -> HHomSet T ; + h2comp_map_eq: forall d: D1_prod T, h2comp_map d = + @HO T (@hhom T) (source (d1_first d)) (target (d1_second d)) (hcomp d) +}. +Unset Universe Checking. +#[short(type="h2fquiver")] +HB.structure Definition H2FQuiver : Set := { C of IsH2FQuiver C }. +Set Universe Checking. + +(* Precat based on the H2Quiver (D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsH2PreCat T of H2FQuiver T := { + h2precat : Quiver_IsPreCat (@HHomSet T) }. +#[short(type="h2precat")] +HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. +Set Universe Checking. + +(* The category based on the H2Quiver (D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsH2Cat T of H2PreCat T := { + h2cat : PreCat_IsCat (@HHomSet T) }. +#[short(type="h2cat")] +HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. +Set Universe Checking. + +(* +Unset Universe Checking. +#[short(type="predcat")] +HB.structure Definition PreDCat : Set := { D of H2Cat D & H2Grid D }. +Set Universe Checking. +*) + +Record D2_prod T := { + d2_first : @H2HomSet T ; + d2_second : @H2HomSet T ; + d2_adjacent : target d2_first = source d2_second +}. + +(* probably not needed *) +HB.mixin Record HQuiver_IsH2PreCat' C of H2Grid C := { + h2idmap : forall (a : C), hhom a a; + h2comp : forall d : D2_prod C, + h2hom (source (d2_first d)) (target (d2_second d)); +}. +Unset Universe Checking. +#[short(type="hprecat")] +HB.structure Definition H2PreCat' : Set := { C of HQuiver_IsH2PreCat' C }. +Set Universe Checking. + + + +(* +(* gives left and right edges of a 2-cell (i.e. the vertical + morphisms associated with the 2-morphism). + these should be functors + *) +HB.mixin Record IsH2Grid T of Quiver T & H2Quiver T := { + h2left_edge : forall a b c d: T, + forall (h1: hhom a b) (h2: hhom c d), + @hom (@HHomSet T) (@HO T (@hhom T) a b h1) + (@HO T (@hhom T) c d h2) -> @hom T a c ; + h2right_edge : forall a b c d: T, + forall (h1: hhom a b) (h2: hhom c d), + @hom (@HHomSet T) (@HO T (@hhom T) a b h1) + (@HO T (@hhom T) c d h2) -> @hom T b d +}. +Unset Universe Checking. +#[short(type="h2grid")] +HB.structure Definition H2Grid : Set := { C of IsH2Grid C }. +Set Universe Checking. + +(* +(* adding the map to define (1) the unit functor D0 -> D1 + and (2) composition D1 *d0 D1 -> D1 *) +HB.mixin Record IsH2FQuiver T of H2Quiver T := { + h2unit_map: forall x:T, HHomSet T ; + h2unit_map_eq: forall x:T, h2unit_map x = + @HO T (@hhom T) x x (hidmap x) ; + h2comp_map: HHomSet T * HHomSet T -> HHomSet T ; + h2comp_map_eq: forall (a b c: T) (h1: hhom a b) (h2: hhom b c), + let x := @HO T (@hhom T) a b h1 + in let y := @HO T (@hhom T) b c h2 + in let z := @HO T (@hhom T) a c (hcomp a b c h1 h2) + in h2comp_map (x, y) = z }. +Unset Universe Checking. +#[short(type="h2fquiver")] +HB.structure Definition H2FQuiver : Set := { C of IsH2FQuiver C }. +Set Universe Checking. +*) +(* +(* adding the map to define the unit functor D0 -> D1 *) +HB.mixin Record IsH2FQuiver T of H2Quiver T := { + h2unit_map: forall x:T, HHomSet T ; + h2unit_map_eq: forall x:T, let y := h2unit_map x in + source y = target y ; + h2comp_map: HHomSet T * HHomSet T -> HHomSet T ; + h2comp_map_eq: forall x y: HHomSet T, target x = source y -> + exists f: hhom (source x) (target y), + h2comp_map (x, y) = @HO T (@hhom T) (source x) (target y) f ; +(* square_comp : forall (a1 b1 c1 a2 b2 c2: T), + forall (ha1: hhom a1 b1) (hb1: hhom b1 c1) + (ha2: hhom a2 b2) (hb2: hhom b2 c2), *) + }. +Unset Universe Checking. +#[short(type="h2fquiver")] +HB.structure Definition H2FQuiver : Set := { C of IsH2FQuiver C }. +Set Universe Checking. +*) + +(* Precat based on the H2Quiver (D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsH2PreCat T of H2FQuiver T := { + h2precat : Quiver_IsPreCat (@HHomSet T) }. +#[short(type="h2precat")] +HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. +Set Universe Checking. + +(* The category based on the H2Quiver (D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsH2Cat T of H2PreCat T := { + h2cat : PreCat_IsCat (@HHomSet T) }. +#[short(type="h2cat")] +HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. +Set Universe Checking. + +(* Pre-double category, with horizontal 2-cell composition *) +Unset Universe Checking. +HB.mixin Record IsPreDCat T of Cat T & H2Cat T & H2Grid T := { + h2adjacent : forall (a b c d e f: T), + forall (h1: hhom a b) (h2: hhom b c) (h3: hhom d e) (h4: hhom e f), + forall (hh1: @hom (@HHomSet T) (@HO T (@hhom T) a b h1) + (@HO T (@hhom T) d e h3)) + (hh2: @hom (@HHomSet T) (@HO T (@hhom T) b c h2) + (@HO T (@hhom T) e f h4)), + h2right_edge a b d e h1 h3 hh1 = + h2left_edge b c e f h2 h4 hh2 ; + + h2comp : forall (h1 h2 h3 h4: HHomSet T), + forall (hh1: h1 ~> h2) (hh2: h3 ~> h4), + h2comp_map (h1,h3) ~> h2comp_map (h2,h4) ; + +(* + h2comp_eq : forall (a b c d e f: T), + forall (h1: hhom a b) (h2: hhom b c) (h3: hhom d e) (h4: hhom e f), + forall (hh1: @hom (@HHomSet T) (@HO T (@hhom T) a b h1) + (@HO T (@hhom T) d e h3)) + (hh2: @hom (@HHomSet T) (@HO T (@hhom T) b c h2) + (@HO T (@hhom T) e f h4)), + h2adjacent a b c d e f h1 h2 hh1 hh2 -> + let h1' := (@HO T (@hhom T) a b h1) + in let h2' := (@HO T (@hhom T) b c h2) + in let h3' := (@HO T (@hhom T) d e h3) + in let h4' := (@HO T (@hhom T) e f h4) + h2comp h1' h2' h3' h4' hh1 hh2 = +*) + }. +#[short(type="predcat")] +HB.structure Definition PreDCat : Set := { D of IsPreDCat D }. +Set Universe Checking. + + +*) + +(* source functor: D1 -> D0 *) +HB.tag Definition Source C := fun (X: HHomSet C) => @source C (@hhom C) X. +(* target functor: D1 -> D0 *) +HB.tag Definition Target C := fun (X: HHomSet C) => @target C (@hhom C) X. +(* unit functor: D0 -> D1 *) +HB.tag Definition UnitF (C: h2fquiver) := + fun (x:H2FQuiver.sort C) => @h2unit_map C x. + +(* source prefunctor. + HHomSet T is the quiver of the 2-morphisms, thanks to H2Quiver. + T is the quiver of 1-morphisms. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHSPreFunctor T of Cat T & H2Cat T := { + h2s_prefunctor : IsPreFunctor (HHomSet T) T (@Source T) }. +HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. +Set Universe Checking. + +(* target prefunctor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHTPreFunctor T of Cat T & H2Cat T := { + h2t_prefunctor : IsPreFunctor (HHomSet T) T (@Target T) }. +HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. +Set Universe Checking. + + + +HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. +Set Universe Checking. + +(* source functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record HSPreFunctor_IsFunctor T of Cat T & HSPreFunctor T := { + h2s_functor : PreFunctor_IsFunctor (HHomSet T) T (@Source T) }. +HB.structure Definition HSFunctor : Set := {C of HSPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* target functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record HTPreFunctor_IsFunctor T of Cat T & HTPreFunctor T := { + h2t_functor : PreFunctor_IsFunctor (HHomSet T) T (@Target T) }. +HB.structure Definition HTFunctor : Set := {C of HTPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* unit prefunctor. *) +Unset Universe Checking. + #[wrapper] +HB.mixin Record IsHUPreFunctor T of Cat T & PreDCat T := { + h2u_prefunctor : IsPreFunctor T (HHomSet T) (@UnitF T) }. +HB.structure Definition HUPreFunctor : Set := {C of IsHUPreFunctor C}. +Set Universe Checking. + + +Unset Universe Checking. + #[wrapper] +HB.mixin Record HUPreFunctor_IsFunctor T of Cat T & HUPreFunctor T := { + h2u_functor : PreFunctor_IsFunctor T (HHomSet T) (@UnitF T) }. + HB.structure Definition HUFunctor : Set := {T of + Cat T & HUPreFunctor T & + PreFunctor_IsFunctor T (HHomSet T) (@UnitF T) + }. +Set Universe Checking. + + +Unset Universe Checking. + #[wrapper] +HB.mixin Record HUPreFunctor_IsFunctor T of Cat T & HUPreFunctor T := { + h2u_functor : PreFunctor_IsFunctor T (HHomSet T) (@UnitF T) }. +HB.structure Definition HUFunctor : Set := {C of HUPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* double category *) +Unset Universe Checking. +HB.structure Definition DCat : Set := + {D of HSPreFunctor_IsFunctor D & HTPreFunctor_IsFunctor D & + HUPreFunctor_IsFunctor D}. +Set Universe Checking. + +(* 2-morphisms *) +Definition h2hom (D: DCat.type) := @hom (@HHomSet D). + +(* still don't understand + transposition whould swap vertical and horizontal morphisms, + i.e. hom and hhom *) +Definition transpose1 (D: DCat.type) : U := D. +(* however, given transpose1 this should hold *) +Lemma hom_transpose (D: DCat.type) : @hom (transpose1 D) = @hhom D. +Admitted. +(* and this too *) +Lemma hhom_transpose (D: DCat.type) : @hhom (transpose1 D) = @hom D. +Admitted. + +(* tranposition as a relation *) +Definition isTranspose C + (FQ: PreDCat C -> Quiver C) + (FHQ: PreDCat C -> HQuiver C) + (D1 D2: PreDCat C) : Type := + @hom (Quiver.Pack (FQ D2)) = @hhom (HQuiver.Pack (FHQ D1)) /\ + @hhom (HQuiver.Pack (FHQ D2)) = @hom (Quiver.Pack (FQ D1)). + +Definition transpose_isquiver C (X: IsQuiver C) : IsHQuiver C. + destruct X. + econstructor. + exact hom0. +Defined. + +Definition transpose_ishquiver C (X: IsHQuiver C) : IsQuiver C. + destruct X. + econstructor. + exact hhom0. +Defined. + +Definition transpose_quiver C (X: Quiver C) : HQuiver C. + destruct X. + econstructor. + eapply transpose_isquiver; eauto. +Defined. + +Definition transpose_hquiver C (X: HQuiver C) : Quiver C. + destruct X. + econstructor. + eapply transpose_ishquiver; eauto. +Defined. + +(* tranposition as a relation, using the transpose functions *) +Definition isTransposeF C + (FQ: PreDCat C -> Quiver C) + (FHQ: PreDCat C -> HQuiver C) + (D1 D2: PreDCat C) : Type := + Quiver.Pack (FQ D2) = Quiver.Pack (@transpose_hquiver C (FHQ D1)) /\ + HQuiver.Pack (FHQ D2) = HQuiver.Pack (@transpose_quiver C (FQ D1)). + + + +(*** DOUBLE CATEGORIES (PREVIOUS) *) + +(* A quiver from which horizontal morphisms arise. D1 is the type of + D1 objects (horizontal morphisms in C), with source and target + functors. *) +HB.mixin Record HasD1 C := { + D1 : U ; + s10 : D1 -> C ; + t10 : D1 -> C }. +Unset Universe Checking. +#[short(type="hquiver")] +HB.structure Definition D1type : Set := { C of HasD1 C }. +Set Universe Checking. + +(* A quiver from which 2-morphisms arise as arrows between 2-objects + (i.e. horizontal morphisms) *) +#[wrapper] +HB.mixin Record IsH2Quiver T of HasD1 T := { + h2quiver : IsQuiver (@D1 T) }. +Unset Universe Checking. +#[short(type="h2quiver")] +HB.structure Definition H2Quiver : Set := { C of IsH2Quiver C }. +Set Universe Checking. + +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsH2PreCat T of H2Quiver T := { + h2precat : Quiver_IsPreCat (@D1 T) }. +#[short(type="h2precat")] +HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. +Set Universe Checking. + +(* The category based on the H2Quiver (D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsH2Cat T of H2PreCat T := { + h2cat : PreCat_IsCat (@D1 T) }. +#[short(type="h2cat")] +#[verbose] +HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. +Set Universe Checking. + +(* Pre-double category (no functors yet): this corresponds to the old +definition *) +Unset Universe Checking. +HB.structure Definition PreDCat : Set := { D of Cat D & H2Cat D }. +Set Universe Checking. + +(* source prefunctor. + D1 here is the quiver of the 2-morphisms, thanks to IsH2Quiver. + T is the quiver of 1-morphisms. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHSPreFunctor T of Cat T & H2Cat T := { + h2s_prefunctor : IsPreFunctor D1 T s10 }. +HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. +Set Universe Checking. + +(* target prefunctor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHTPreFunctor T of Cat T & H2Cat T := { + h2t_prefunctor : IsPreFunctor D1 T t10 }. +HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. +Set Universe Checking. + +(* source functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record HSPreFunctor_IsFunctor T of Cat T & HSPreFunctor T := { + h2s_prefunctor : PreFunctor_IsFunctor D1 T s10 }. +HB.structure Definition HSFunctor : Set := {C of HSPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* target functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record HTPreFunctor_IsFunctor T of Cat T & HTPreFunctor T := { + h2t_prefunctor : PreFunctor_IsFunctor D1 T t10 }. +HB.structure Definition HTFunctor : Set := {C of HTPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* double category *) +Unset Universe Checking. +HB.structure Definition DCat : Set := + {D of HSPreFunctor_IsFunctor D & HTPreFunctor_IsFunctor D }. +Set Universe Checking. + +(* 2-morphisms *) +Definition hhom (D: DCat.type) := @hom (@D1 D). + +Definition transpose (D: DCat.type) : U := D. + +Fail Lemma hom_transpose (D: DCat.type) : @hom (transpose D) = @hhom D. + +Fail Lemma hhom_transpose (D: DCat.type) : @hhom (transpose D) = @hom D. + + + +(*** DOUBLE CATEGORIES (OLD) *) + +(* A quiver from which horizontal morphisms arise (just a copy of quiver) *) +HB.mixin Record IsHQuiver C := { hhom : C -> C -> U }. +Unset Universe Checking. +#[short(type="hquiver")] +HB.structure Definition HQuiver : Set := { C of IsHQuiver C }. +Set Universe Checking. + +(* domain-specific sigma-type to represent the 2-objects *) +Record Total2 T (h: T -> T -> U) : Type := HO { + source : T; + target : T; + this_hom : h source target }. + +(* needed to identify HHomSet as lifter *) +HB.tag Definition HHomSet (C: hquiver) := Total2 (@hhom C). + +(* A quiver from which 2-morphisms arise as arrows between 2-objects + (i.e. horizontal morphisms) *) +#[wrapper] +HB.mixin Record IsH2Quiver T of HQuiver T := { + h2quiver : Quiver (@HHomSet T) }. +Unset Universe Checking. +#[short(type="h2quiver")] +HB.structure Definition H2Quiver : Set := { C of IsH2Quiver C }. +Set Universe Checking. + +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsH2PreCat T of HQuiver T & H2Quiver T := { + h2precat : Quiver_IsPreCat (@HHomSet T) }. +#[short(type="h2precat")] +HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. +Set Universe Checking. + +(* The category based on the H2Quiver (D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsH2Cat T of H2PreCat T := { + h2cat : PreCat_IsCat (@HHomSet T) }. +#[short(type="h2cat")] +HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. +Set Universe Checking. + +(* Double categories, from + https://ncatlab.org/nlab/show/double+category + + The definition we follow here however is a comparatively informal + one, which also mentions internal categories (not formalized yet). + + Double category (D0, D1). + + base obejcts (D0): C ; + + vertical morphisms (D0): @hom C ; + + horizontal morhisms (and 2-objects, D1): @HHomSet C ; + + 2-morphisms (D1): @hom (@HHomSet C) *) +Unset Universe Checking. +#[short(type="dcat")] +HB.structure Definition DCat : Set := { C of Cat C & H2Cat C }. +Set Universe Checking. + + + +(*******************************************************************) + +(*** Related to BICATEGORIES (just an experiment, + not the right formalization) *) + +(* We want to factor constants and operators out of the axioms. + Suggestion: introduce some notion of module to bind them + together. *) + +(* monoid axioms *) +HB.mixin Record isMonoid T (mu: T) (mc: T -> T -> T): Type := { + massoc : associative mc; + mlid : left_id mu mc ; + mrid : right_id mu mc ; +}. + +(* to be used as homset identity in bicategories *) +HB.mixin Record isHId T := { + hid : T; +}. +HB.structure Definition HId := { T of isHId T }. + +(* to be used as homset composition in bicategories *) +HB.mixin Record isHComp T := { + hcomp : T -> T -> T; +}. +HB.structure Definition HComp := { T of isHComp T }. + +#[wrapper] +HB.mixin Record Quiver_HasId T of Quiver T := + { Quiver_HasId_private : forall A B, isHId (@hom T A B) }. +HB.structure Definition HasId := + { Obj of Quiver Obj & Quiver_HasId Obj }. + +#[wrapper] +HB.mixin Record Quiver_HasComp T of Quiver T := + { Quiver_HasComp_private : forall A B, isHComp (@hom T A B) }. +HB.structure Definition HasComp := + { Obj of Quiver Obj & Quiver_HasComp Obj }. + +(* a bicategory, without axioms *) +HB.structure Definition BiCatQuiver := + {T of Quiver_HasId T & Quiver_HasComp T}. + +#[wrapper] +HB.mixin Record isHMonoid T of HId T & HComp T := + { isHMonoid_private: isMonoid T (hid: T) (@hcomp T) }. +#[verbose] +HB.structure Definition HMonoid := { T of isHMonoid T }. + +#[wrapper] +(* does not work (generic Elpi error): + HB.mixin Record isHCat T of precat_quiver T := *) +HB.mixin Record isPreBiCategory T of IsPreCat T := + { isPreBiCategory_private : forall A B: T, HMonoid (@hom T A B) }. +HB.structure Definition PreBiCategory := + { Obj of isPreBiCategory Obj }. + +(* to be used as object monoid unit *) +HB.mixin Record isMUnit T := { + munit : T; +}. +HB.structure Definition MUnit := { T of isMUnit T }. + +(* to be used as object monoid composition *) +HB.mixin Record isMComp T := { + mcomp : T -> T -> T; +}. +HB.structure Definition MComp := { T of isMComp T }. + +(* has object monoid operators *) +HB.structure Definition Premonoid := + {T of isMUnit T & isMComp T}. + +(* the precategory has monoidal operators *) +HB.structure Definition Precat_IsPremonoidal := + {T of PreCat T & Premonoid T}. + +(* object monoid *) +HB.mixin Record isOMonoid T of isMUnit T & isMComp T := + { isHMonoid_private: isMonoid T (munit: T) (mcomp: T -> T -> T) }. +#[verbose] +HB.structure Definition OMonoid := { T of isOMonoid T }. + +(* some sort of monoidal category *) +HB.structure Definition PreMonBiCategory := + { Obj of PreBiCategory Obj & OMonoid Obj }. + + +(*******************************************************************) + +Section th_of_pb. +Variables (Q : cat) (A B C D E F : Q). +Variables (f : A ~> D) (g : B ~> D) (h : C ~> A). +Variables (u : E ~> A) (v : E ~> B) (w : F ~> C) (z : F ~> E). +Variable (uvfg : pbsquare u v f g). + +Set Printing Width 50. +Theorem pbsquarec_compP : + pbsquare w z h u <=> pbsquare w (z \; v) (h \; f) g. +Proof. +split=> [] sq. + + have @sq_ispb : pullback (Cospan h u) := HB.pack (Span w z) sq. + have @uvfg_ispb : pullback (Cospan f g) := HB.pack (Span u v) uvfg. + have /=E2 := @is_square _ _ _ _ sq_ispb. + have /=E1 := @is_square _ _ _ _ uvfg_ispb. + + have p1 : @isPrePullback Q C B (Cospan (h \; f) g) (Span w (z \; v)). + by constructor; rewrite /= compoA E2 -compoA E1 compoA. + pose big_black_square : prepullback (Cospan (h \; f) g) := + HB.pack (Span w (z \; v)) p1. + + have @from : forall + (big_red_square : prepullback {| top := D; left2top := h \; f; right2top := g |}), + big_red_square ~> pb_terminal big_black_square. + + move=> big_red_square; unfold pb_terminal. + + have /= := @is_square _ _ _ _ big_red_square. + + pose F' := bot big_red_square. + set w' : F' ~> C := bot2left big_red_square. + set z' : F' ~> B := bot2right big_red_square. + move=> E3. + + have xxx : isPrePullback Q A B (Cospan f g) (Span (w' \; h) z'). + by constructor=> /=; rewrite -compoA E3. + pose red_black_square : prepullback (Cospan f g) := + HB.pack (Span (w' \; h) z') xxx. + have := @from_unique _ (pb_terminal uvfg_ispb) red_black_square. + set blue := @from _ (pb_terminal uvfg_ispb) red_black_square. + move=> blue_unique. + + have p3 : @isPrePullback Q C E (Cospan h u) (Span w' (bot_map blue)). + by constructor; rewrite /= (bot2left_map blue). (* buggy unifier without blue *) + pose blue_red_black_square : prepullback (Cospan h u) := + HB.pack (Span w' (bot_map blue)) p3. + + pose red := @from _ (pb_terminal sq_ispb) blue_red_black_square. + + admit. + + + + have p2 : prepullback_isTerminal.axioms_ Q C B (Cospan (h \; f) g) (Span w (z \; v)) p1. + constructor. econstructor=> /=. + admit. + + by HB.from p1 p2. + +Admitted. + +End th_of_pb. + + +Module test. + +Section test. +Variables (Q : precat) (A B : Q) (c : cospan A B). +Variable (p : pullback c). +Check pb_terminal p : terminal _. + +End test. +End test. + + + + From 6a942fb9d99954bbe2171e3b6e98f383e6b74021 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Thu, 9 Nov 2023 18:17:36 +0100 Subject: [PATCH 087/147] updated encav.v; in progress --- theories/encat.v | 149 +++++++++++++++++++++++++++++++---------------- 1 file changed, 99 insertions(+), 50 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index 250f0465c..6fd2d8c5e 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1252,20 +1252,109 @@ HB.mixin Record UPreFunctor_IsFunctor T of UPreFunctor T := { HB.structure Definition UFunctor : Set := {C of UPreFunctor_IsFunctor C}. Set Universe Checking. -(* pullback category condition (i.e. (HCompSet T) is a category). - requires T to be a category, and (HHomSet T) to be a quiver *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsHCompCat T of UFunctor T := { - is_hcompcat : Cat (HCompSet T) }. -#[short(type="hcompcat")] -HB.structure Definition HCompCat : Set := { C of IsHCompCat C }. -Set Universe Checking. +(* 2-cell (D1) morphisms *) +Definition c2hom (D: HDQuiver.type) := @hom (@HHomSet D). + +(* The set of D1 morphisms *) +HB.tag Definition C2HomSet (C: HDQuiver.type) := Total2 (@c2hom C). + +(* horizontal 2-cell unit (maps vertical morphisms to horizontally + unitary 2-cells) *) +Definition HC2Unit (T: UFunctor.type) (a b: T) (m: @hom T a b) : + c2hom (HUnit a) (HUnit b) := @Fhom _ _ (@HUnit T) a b m. + +(** HCompSet T is the pseudo-pullback category used to deal with + products of D1 (where the adjacency condition is expressed + w.r.t. D0 *) + +(** HComp quiver *) +Definition HComp_hom (T: UFunctor.type) := + (fun (A B: HCompSet T) => match (A, B) with + | (@GC _ _ a0 a1 a2 h0 h1, @GC _ _ b0 b1 b2 k0 k1) => + let h0' := HO h0 + in let k0' := HO k0 + in let h1' := HO h1 + in let k1' := HO k1 + in sigT (fun (hh0: @hom (HHomSet T) h0' k0') => + (sigT (fun (hh1: @hom (HHomSet T) h1' k1') => + @Fhom _ _ (@HTarget T) h0' k0' hh0 = + @Fhom _ _ (@HSource T) h1' k1' hh1))) + end). + +(* +(** HComp quiver *) +Definition HComp_hom (T: UFunctor.type) := + (fun (A B: HCompSet T) => match (A, B) with + | (@GC _ _ a1 b1 c1 h1 k1, @GC _ _ a2 b2 c2 h2 k2) => + let h1' := HO h1 + in let k1' := HO k1 + in let h2' := HO h2 + in let k2' := HO k2 + in sigT (fun (hh: @hom (HHomSet T) h1' h2') => + (sigT (fun (kk: @hom (HHomSet T) k1' k2') => + @Fhom _ _ (@HTarget T) h1' h2' hh = + @Fhom _ _ (@HSource T) k1' k2' kk))) + end). +*) + +HB.instance Definition HCompQuiver (T: UFunctor.type) : + IsQuiver (HCompSet T) := + IsQuiver.Build (HCompSet T) (fun A B => @HComp_hom T A B). + +(* +Definition HComp_id (T: UFunctor.type) (A: HCompSet T) (* : A ~> A *) := + match A with + | @GC _ _ a0 a1 a2 h0 h1 => + let h0' := HO h0 + in let h1' := HO h1 + in let uu0 := @idmap (HHomSet T) h0' + in let uu1 := @idmap (HHomSet T) h1' + in @exist (@hom (HHomSet T) h0' h0') + (fun _ => 0 = 0) uu0 eq_refl end. + (@exist _ (fun _ => 0 = 0) uu1 eq_refl) end. +Definition HComp_id (T: UFunctor.type) (A: HCompSet T) (* : A ~> A *) := + match A with + | @GC _ _ a0 a1 a2 h0 h1 => + let h0' := HO h0 + in let h1' := HO h1 + in let uu := @idmap (HHomSet T) h0' + in let ff := @exist _ (fun _ => 0 = 0) uu + eq_refl + in True end. + + in @existT (@hom (HHomSet T) h0' h0') _ + (@idmap (HHomSet T) h0') True end. + (@existT (@hom (HHomSet T) h1' h1') _ + (@idmap (HHomSet T) h1') True) end. + +Definition HComp_id (T: UFunctor.type) (A: HCompSet T) : A ~> A := + match A with + | @GC _ _ a0 a1 a2 h0 h1 => + let h0' := HO h0 + in let h1' := HO h1 + in existT _ _ (HC2Unit a0 a1 h0) (existT _ _ (HC2Unit a1 a2 h1) ) +*) + +Program Definition HCompPreCatF (T: UFunctor.type) : + Quiver_IsPreCat (HCompSet T) := + Quiver_IsPreCat.Build (HCompSet T) + (fun x: HCompSet T => _) (fun a b c: HCompSet T => _). +Obligation 1. +Admitted. +Obligation 2. +Admitted. + +HB.instance Definition HCompPreCat (T: UFunctor.type) := HCompPreCatF T. + +Global Parameter GCompAx : forall (T: UFunctor.type), + PreCat_IsCat (HCompSet T). + +HB.instance Definition HCompCat (T: UFunctor.type) := GCompAx T. (* composition prefunctor *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsCPreFunctor T of HCompCat T := +HB.mixin Record IsCPreFunctor T of UFunctor T := { is_cprefunctor : IsPreFunctor (HCompSet T) (HHomSet T) (@HComp T) }. HB.structure Definition CPreFunctor : Set := {C of IsCPreFunctor C}. Set Universe Checking. @@ -1278,17 +1367,6 @@ HB.mixin Record CPreFunctor_IsFunctor T of CPreFunctor T := { HB.structure Definition CFunctor : Set := {C of CPreFunctor_IsFunctor C}. Set Universe Checking. -(* 2-cell (D1) morphisms *) -Definition c2hom (D: HDQuiver.type) := @hom (@HHomSet D). - -(* The set of D1 morphisms *) -HB.tag Definition C2HomSet (C: HDQuiver.type) := Total2 (@c2hom C). - -(* horizontal 2-cell unit (maps vertical morphisms to horizontally - unitary 2-cells) *) -Definition HC2Unit (T: UFunctor.type) (a b: T) (m: @hom T a b) : - c2hom (HUnit a) (HUnit b) := @Fhom _ _ (@HUnit T) a b m. - (* horizontal 2-cell composition: maps two adjecent pairs of horizontal morphisms (a and b) and a pullback-category morphism between them (m, which basically gives two adjecent cells) to a @@ -1432,35 +1510,6 @@ Set Universe Checking. (*********************************************************************) -(** HComp quiver *) -Definition HComp_hom (T: TFunctor.type) := - (fun (A B: HCompSet T) => match (A, B) with - | (@GC _ _ a1 b1 c1 h1 k1, @GC _ _ a2 b2 c2 h2 k2) => - let h1' := @HO T (@hhom T) a1 b1 h1 - in let k1' := @HO T (@hhom T) b1 c1 k1 - in let h2' := @HO T (@hhom T) a2 b2 h2 - in let k2' := @HO T (@hhom T) b2 c2 k2 - in sigT (fun (hh: @hom (HHomSet T) h1' h2') => - (sigT (fun (kk: @hom (HHomSet T) k1' k2') => - @Fhom _ _ (@HTarget T) h1' h2' hh = - @Fhom _ _ (@HSource T) k1' k2' kk))) - end). - -Definition HCompQuiver (T: TFunctor.type) : - IsQuiver (HCompSet T) := - IsQuiver.Build (HCompSet T) (fun A B => @HComp_hom T A B). - -Program Definition HCompPreCat (T: TFunctor.type) : - Quiver_IsPreCat (HCompSet T) := - Quiver_IsPreCat.Build (HCompSet T) - (fun x: HComp T => _) (fun a b c: HCompSet T => _). -Obligation 1. -Admitted. -Obligation 2. -Admitted. - - - Program Definition HC2Comp_flat (T: CFunctor.type) (a0 a1 a2 b0 b1 b2: T) (h0: hhom a0 a1) (h1: hhom a1 a2) (k0: hhom b0 b1) (k1: hhom b1 b2) From 429865c9c6b156fee7584bc272ed289629a808d2 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Fri, 10 Nov 2023 19:03:14 +0100 Subject: [PATCH 088/147] updated encav.v; discharged product precategory assumptions (still to be proved: product is a category) --- theories/encat.v | 218 +++++++++++++++++++++++++++-------------------- 1 file changed, 126 insertions(+), 92 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index 6fd2d8c5e..07e679c8b 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1134,16 +1134,21 @@ Set Universe Checking. (* used to define composable pairs of morphisms as a set *) Record GenComp T (h: T -> T -> U) := GC { - c_one : T; - c_two : T ; - c_three : T; - c_first : h c_one c_two ; - c_second : h c_two c_three + h_one : T; + h_two : T ; + h_three : T; + h_first : h h_one h_two ; + h_second : h h_two h_three }. (* composable pairs of horizontal morphisms as a set *) HB.tag Definition HCompSet (C: cquiver) := GenComp (@hhom C). +Definition H2First (C: cquiver) (X: @HCompSet C) : HHomSet C := + @HO C _ (h_one X) (h_two X) (h_first X). +Definition H2Second (C: cquiver) (X: @HCompSet C) : HHomSet C := + @HO C _ (h_two X) (h_three X) (h_second X). + (* hunit - horizontal unit functor. hcomp - horizontal composition functor. @@ -1170,7 +1175,9 @@ Set Universe Checking. Definition hhunit (T: hdquiver) (a: T) : HHomSet T := @HO T (@hhom T) a a (hunit a). - + +(* horizontal composition of two horizontal morphisms from a + cell product *) Definition hhcomp (T: hdquiver) (x: HCompSet T) : HHomSet T := match x with @GC _ _ a b c h1 h2 => @HO T (@hhom T) a c (hcomp a b c h1 h2) end. @@ -1253,7 +1260,11 @@ HB.structure Definition UFunctor : Set := {C of UPreFunctor_IsFunctor C}. Set Universe Checking. (* 2-cell (D1) morphisms *) -Definition c2hom (D: HDQuiver.type) := @hom (@HHomSet D). +Definition c2hom (D: HDQuiver.type) : HHomSet D -> HHomSet D -> U := + @hom (HHomSet D). + +Definition C2Hom (D: HDQuiver.type) (a b c d: D) (h0: hhom a b) + (h1: hhom c d) : U := c2hom (HO h0) (HO h1). (* The set of D1 morphisms *) HB.tag Definition C2HomSet (C: HDQuiver.type) := Total2 (@c2hom C). @@ -1263,89 +1274,120 @@ HB.tag Definition C2HomSet (C: HDQuiver.type) := Total2 (@c2hom C). Definition HC2Unit (T: UFunctor.type) (a b: T) (m: @hom T a b) : c2hom (HUnit a) (HUnit b) := @Fhom _ _ (@HUnit T) a b m. +(* 2-cell source *) +Definition HC2Source (T: UFunctor.type) (a b: @HHomSet T) + (m: @c2hom T a b) : + @hom T (HSource a) (HSource b) := @Fhom _ _ (@HSource T) a b m. + +(* 2-cell target *) +Definition HC2Target (T: UFunctor.type) (a b: @HHomSet T) + (m: @c2hom T a b) : + @hom T (HTarget a) (HTarget b) := @Fhom _ _ (@HTarget T) a b m. + +(* horizontal composition of two (naked) horizontal morphisms *) +Definition l_hcomp (T: UFunctor.type) (a0 a1 a2: T) + (h0: hhom a0 a1) (h1: hhom a1 a2) : HHomSet T := + @HO T _ a0 a2 (hcomp a0 a1 a2 h0 h1). + + (** HCompSet T is the pseudo-pullback category used to deal with products of D1 (where the adjacency condition is expressed w.r.t. D0 *) -(** HComp quiver *) -Definition HComp_hom (T: UFunctor.type) := - (fun (A B: HCompSet T) => match (A, B) with - | (@GC _ _ a0 a1 a2 h0 h1, @GC _ _ b0 b1 b2 k0 k1) => - let h0' := HO h0 - in let k0' := HO k0 - in let h1' := HO h1 - in let k1' := HO k1 - in sigT (fun (hh0: @hom (HHomSet T) h0' k0') => - (sigT (fun (hh1: @hom (HHomSet T) h1' k1') => - @Fhom _ _ (@HTarget T) h0' k0' hh0 = - @Fhom _ _ (@HSource T) h1' k1' hh1))) - end). +Notation "'sigma' x .. y , p" := (sigT (fun x => .. (sigT (fun y => p)) ..)) + (at level 200, x binder, right associativity, + format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") + : type_scope. -(* -(** HComp quiver *) -Definition HComp_hom (T: UFunctor.type) := - (fun (A B: HCompSet T) => match (A, B) with - | (@GC _ _ a1 b1 c1 h1 k1, @GC _ _ a2 b2 c2 h2 k2) => - let h1' := HO h1 - in let k1' := HO k1 - in let h2' := HO h2 - in let k2' := HO k2 - in sigT (fun (hh: @hom (HHomSet T) h1' h2') => - (sigT (fun (kk: @hom (HHomSet T) k1' k2') => - @Fhom _ _ (@HTarget T) h1' h2' hh = - @Fhom _ _ (@HSource T) k1' k2' kk))) - end). -*) +(** HCompSet quiver *) +Definition HComp_hom (T: UFunctor.type) (x y: HCompSet T) := + sigma (hh0: C2Hom (h_first x) (h_first y)) + (hh1: C2Hom (h_second x) (h_second y)), + HC2Target hh0 = HC2Source hh1. HB.instance Definition HCompQuiver (T: UFunctor.type) : IsQuiver (HCompSet T) := IsQuiver.Build (HCompSet T) (fun A B => @HComp_hom T A B). -(* -Definition HComp_id (T: UFunctor.type) (A: HCompSet T) (* : A ~> A *) := - match A with - | @GC _ _ a0 a1 a2 h0 h1 => - let h0' := HO h0 - in let h1' := HO h1 - in let uu0 := @idmap (HHomSet T) h0' - in let uu1 := @idmap (HHomSet T) h1' - in @exist (@hom (HHomSet T) h0' h0') - (fun _ => 0 = 0) uu0 eq_refl end. - (@exist _ (fun _ => 0 = 0) uu1 eq_refl) end. -Definition HComp_id (T: UFunctor.type) (A: HCompSet T) (* : A ~> A *) := - match A with - | @GC _ _ a0 a1 a2 h0 h1 => - let h0' := HO h0 - in let h1' := HO h1 - in let uu := @idmap (HHomSet T) h0' - in let ff := @exist _ (fun _ => 0 = 0) uu - eq_refl - in True end. - - in @existT (@hom (HHomSet T) h0' h0') _ - (@idmap (HHomSet T) h0') True end. - (@existT (@hom (HHomSet T) h1' h1') _ - (@idmap (HHomSet T) h1') True) end. - -Definition HComp_id (T: UFunctor.type) (A: HCompSet T) : A ~> A := - match A with - | @GC _ _ a0 a1 a2 h0 h1 => - let h0' := HO h0 - in let h1' := HO h1 - in existT _ _ (HC2Unit a0 a1 h0) (existT _ _ (HC2Unit a1 a2 h1) ) -*) - -Program Definition HCompPreCatF (T: UFunctor.type) : - Quiver_IsPreCat (HCompSet T) := - Quiver_IsPreCat.Build (HCompSet T) - (fun x: HCompSet T => _) (fun a b c: HCompSet T => _). +(* HCompSet identity, defined in proof mode *) +Program Definition HComp_id_P (T: UFunctor.type) (A: HCompSet T) : A ~> A. +unfold hom; simpl. +unfold HComp_hom, C2Hom; simpl. +destruct A; simpl. +set h0' := HO h_first0. +set h1' := HO h_second0. +repeat econstructor. +instantiate (1:= @idmap (HHomSet T) h1'). +instantiate (1:= @idmap (HHomSet T) h0'). +assert (HC2Target (@idmap (HHomSet T) h0') = @idmap _ h_two0) as T0. +{ unfold HC2Target, HTarget. + rewrite F1; auto. +} +assert (HC2Source (@idmap (HHomSet T) h1') = @idmap _ h_two0) as S1. +{ unfold HC2Source, HSource. + rewrite F1; auto. +} +rewrite T0. +rewrite S1. +reflexivity. +Defined. + +(* HCompSet identity, only partially in proof mode *) +Program Definition HComp_id (T: UFunctor.type) (A: HCompSet T) : A ~> A := + let h0 := h_first A + in let h1 := h_second A + in let uu0 := @idmap (HHomSet T) (HO h0) + in let uu1 := @idmap (HHomSet T) (HO h1) + in @existT (C2Hom h0 h0) + (fun hh0: (C2Hom h0 h0) => + sigma (hh1 : C2Hom h1 h1), HC2Target hh0 = HC2Source hh1) uu0 + (@existT (C2Hom h1 h1) + (fun hh1: (C2Hom h1 h1) => HC2Target uu0 = HC2Source hh1) uu1 _). Obligation 1. -Admitted. -Obligation 2. -Admitted. +unfold HC2Target, HTarget. +unfold HC2Source, HSource. +repeat rewrite F1; auto. +Defined. + +(* HCompSet composition, defined in proof mode *) +Program Definition HComp_comp (T: UFunctor.type) (A B C: HCompSet T) + (chA: A ~> B) (chB: B ~> C) : A ~> C. +destruct chA as [hhA0 pA]. +destruct chB as [hhB0 pB]. +destruct pA as [hhA1 ppA]. +destruct pB as [hhB1 ppB]. +set hh0 := comp hhA0 hhB0. +set hh1 := comp hhA1 hhB1. +econstructor 1 with (x:=hh0). +econstructor 1 with (x:=hh1). +set vv := comp (HC2Target hhA0) (HC2Target hhB0). +assert (comp (HC2Source hhA1) (HC2Source hhB1) = vv) as vv_E. +{ rewrite <- ppA. + rewrite <- ppB. + subst vv; auto. +} +assert (HC2Target hh0 = vv) as vv_ET. +{ subst vv. + unfold HC2Target, HTarget. + rewrite Fcomp; auto. +} +assert (HC2Source hh1 = vv) as vv_ES. +{ rewrite <- vv_E. + unfold HC2Source, HSource. + rewrite Fcomp; auto. +} +rewrite vv_ET. +rewrite vv_ES. +reflexivity. +Defined. -HB.instance Definition HCompPreCat (T: UFunctor.type) := HCompPreCatF T. +(* HCompSet gives a precategory *) +HB.instance Definition HCompPreCat (T: UFunctor.type) : + Quiver_IsPreCat (HCompSet T) := + Quiver_IsPreCat.Build (HCompSet T) + (@HComp_id T) (@HComp_comp T). +(* TODO: to be replaced by a proof *) Global Parameter GCompAx : forall (T: UFunctor.type), PreCat_IsCat (HCompSet T). @@ -1376,17 +1418,6 @@ Definition HC2Comp (T: CFunctor.type) (a b: HCompSet T) (m: @hom (HCompSet T) a b) : c2hom (HComp a) (HComp b) := @Fhom _ _ (@HComp T) a b m. -Definition HC2Source (T: CFunctor.type) (a b: @HHomSet T) - (m: @c2hom T a b) : - @hom T (HSource a) (HSource b) := @Fhom _ _ (@HSource T) a b m. - -Definition HC2Target (T: CFunctor.type) (a b: @HHomSet T) - (m: @c2hom T a b) : - @hom T (HTarget a) (HTarget b) := @Fhom _ _ (@HTarget T) a b m. - -Definition l_hcomp (T: CFunctor.type) (a0 a1 a2: T) - (h0: hhom a0 a1) (h1: hhom a1 a2) : HHomSet T := - @HO T _ a0 a2 (hcomp a0 a1 a2 h0 h1). (* Double category with strong horizontal unit (Russ' paper). hunit defines proper identity on horizontal morphisms *) @@ -1513,12 +1544,15 @@ Set Universe Checking. Program Definition HC2Comp_flat (T: CFunctor.type) (a0 a1 a2 b0 b1 b2: T) (h0: hhom a0 a1) (h1: hhom a1 a2) (k0: hhom b0 b1) (k1: hhom b1 b2) - (hh0: c2hom (HO h0) (HO k0)) - (hh1: c2hom (HO h1) (HO k1)) : - c2hom (l_hcomp h0 h1) (l_hcomp k0 k1) := + (hh0: C2Hom h0 k0) + (hh1: C2Hom h1 k1) + (k: HC2Target hh0 = HC2Source hh1) + : (* C2Hom (hcomp _ _ _ h0 h1) (hcomp _ _ _ k0 k1) *) + c2hom (l_hcomp h0 h1) (l_hcomp k0 k1) := @Fhom _ _ (@HComp T) (GC h0 h1) (GC k0 k1) _. Obligation 1. -Admitted. +refine (@existT (C2Hom h0 k0) _ hh0 (@existT (C2Hom h1 k1) _ hh1 k)). +Defined. (* not working yet *) HB.mixin Record IsDCat_U2 T of CFunctor T := { From 7f79278b4cee4f78afda6edb5fe725083b46cfd9 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Tue, 14 Nov 2023 19:59:51 +0100 Subject: [PATCH 089/147] added encatB.v: complete formalization of double categories, without internal categories --- theories/encatB.v | 3234 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 3234 insertions(+) create mode 100644 theories/encatB.v diff --git a/theories/encatB.v b/theories/encatB.v new file mode 100644 index 000000000..a07dccc5f --- /dev/null +++ b/theories/encatB.v @@ -0,0 +1,3234 @@ +Require Import ssreflect ssrfun. +From HB Require Import structures. + +Set Implicit Arguments. +Unset Strict Implicit. +Unset Printing Implicit Defensive. +Add Search Blacklist "__canonical__". + +Declare Scope algebra_scope. +Delimit Scope algebra_scope with A. +Local Open Scope algebra_scope. + +Declare Scope cat_scope. +Delimit Scope cat_scope with cat. +Local Open Scope cat_scope. + +Require Import Eqdep. + +(* we assume a few axioms to make life easier *) +Axiom funext : forall {T : Type} {U : T -> Type} [f g : forall t, U t], + (forall t, f t = g t) -> f = g. +Axiom propext : forall P Q : Prop, P <-> Q -> P = Q. +Axiom Prop_irrelevance : forall (P : Prop) (x y : P), x = y. + +(* Shortcut *) +Notation U := Type. + +(* Base definition : raw categories = quivers *) +HB.mixin Record IsQuiver C := { hom : C -> C -> U }. +Unset Universe Checking. +#[short(type="quiver")] +HB.structure Definition Quiver : Set := { C of IsQuiver C }. +Set Universe Checking. + +Bind Scope cat_scope with quiver. +Bind Scope cat_scope with hom. +Arguments hom {C} : rename. +Notation homs T := (@hom T _ _). +Notation "a ~> b" := (hom a b) + (at level 99, b at level 200, format "a ~> b") : cat_scope. +Notation "a ~>_ C b" := (@hom C a b) + (at level 99, C at level 0, only parsing) : cat_scope. + +(* precategories are quivers + id and comp *) +HB.mixin Record Quiver_IsPreCat C of Quiver C := { + idmap : forall (a : C), a ~> a; + comp : forall (a b c : C), (a ~> b) -> (b ~> c) -> (a ~> c); +}. + +HB.factory Record IsPreCat C := { + hom : C -> C -> U; + idmap : forall (a : C), hom a a; + comp : forall (a b c : C), hom a b -> hom b c -> hom a c; +}. +HB.builders Context C of IsPreCat C. + HB.instance Definition _ := IsQuiver.Build C hom. + HB.instance Definition _ := Quiver_IsPreCat.Build C idmap comp. +HB.end. + +Unset Universe Checking. +#[short(type="precat")] +HB.structure Definition PreCat : Set := { C of IsPreCat C }. +Set Universe Checking. + +Bind Scope cat_scope with precat. +Arguments idmap {C} {a} : rename. +Arguments comp {C} {a b c} : rename. +Notation "f \o g" := (comp g f) : cat_scope. +Notation "f \; g :> T" := (@comp T _ _ _ f g) + (at level 60, g, T at level 60, format "f \; g :> T", only parsing) : cat_scope. +Notation "f \; g" := (comp f g) : cat_scope. +Notation "\idmap_ a" := (@idmap _ a) (only parsing, at level 0) : cat_scope. + +(* categories are precategories + laws *) +HB.mixin Record PreCat_IsCat C of PreCat C := { + comp1o : forall (a b : C) (f : a ~> b), idmap \; f = f; + compo1 : forall (a b : C) (f : a ~> b), f \; idmap = f; + compoA : forall (a b c d : C) (f : a ~> b) (g : b ~> c) (h : c ~> d), + f \; (g \; h) = (f \; g) \; h +}. +Unset Universe Checking. +#[short(type="cat")] +HB.structure Definition Cat : Set := { C of PreCat_IsCat C & IsPreCat C }. +Set Universe Checking. + +Bind Scope cat_scope with cat. +Arguments compo1 {C a b} : rename. +Arguments comp1o {C a b} : rename. +Arguments compoA {C a b c d} : rename. + +(* the discrete category on a type cannot be the default, we make an alias *) +Definition discrete (T : U) := T. +HB.instance Definition _ T := @IsPreCat.Build (discrete T) (fun x y => x = y) + (fun=> erefl) (@etrans _). +Lemma etransA T (a b c d : discrete T) (f : a ~> b) (g : b ~> c) (h : c ~> d) : + f \; (g \; h) = (f \; g) \; h. +Proof. by rewrite /idmap/comp/=; case: _ / h; case: _ / g. Qed. +HB.instance Definition _ T := PreCat_IsCat.Build (discrete T) (@etrans_id _) + (fun _ _ _ => erefl) (@etransA _). + +(* the category of the unit type is the discrete one *) +HB.instance Definition _ := Cat.copy unit (discrete unit). + +HB.instance Definition _ := @IsPreCat.Build U (fun A B => A -> B) + (fun a => idfun) (fun a b c (f : a -> b) (g : b -> c) => (g \o f)%FUN). +HB.instance Definition _ := PreCat_IsCat.Build U (fun _ _ _ => erefl) + (fun _ _ _ => erefl) (fun _ _ _ _ _ _ _ => erefl). + + +Lemma Ucomp (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) : f \; g = (g \o f)%FUN. +Proof. by []. Qed. +Lemma Ucompx (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) x : (f \; g) x = g (f x). +Proof. by []. Qed. +Lemma U1 (X : U) : \idmap_X = idfun. +Proof. by []. Qed. +Lemma U1x (X : U) x : \idmap_X x = x. +Proof. by []. Qed. + +(* a prefunctor is a functor without laws *) +HB.mixin Record IsPreFunctor (C D : quiver) (F : C -> D) := { + Fhom : forall (a b : C), (a ~> b) -> (F a ~> F b) +}. + +Unset Universe Checking. +HB.structure Definition PreFunctor (C D : quiver) : Set := + { F of IsPreFunctor C D F }. +Set Universe Checking. +HB.instance Definition _ := IsQuiver.Build quiver PreFunctor.type. + +Notation "F ^$" := (@Fhom _ _ F _ _) + (at level 1, format "F ^$") : cat_scope. +Notation "F <$> f" := (@Fhom _ _ F _ _ f) + (at level 58, format "F <$> f", right associativity) : cat_scope. + +(* prefunctors are equal if their object and hom part are respectively equal *) +Lemma prefunctorP (C D : quiver) (F G : C ~> D) (eqFG : F =1 G) : + let homF a b F := F a ~> F b in + (forall a b f, eq_rect _ (homF a b) (F <$> f) _ (funext eqFG) = G <$> f) -> + F = G. +Proof. +move: F G => [F [[/= Fhom]]] [G [[/= Ghom]]] in eqFG *. +case: _ / (funext eqFG) => /= in Ghom * => eqFGhom. +congr PreFunctor.Pack; congr PreFunctor.Class; congr IsPreFunctor.Axioms_. +by do 3!apply: funext=> ?. +Qed. + +(* a functor is a prefunctor + laws for id and comp *) +HB.mixin Record PreFunctor_IsFunctor (C D : precat) (F : C -> D) + of @PreFunctor C D F := { + F1 : forall (a : C), F <$> \idmap_a = idmap; + Fcomp : forall (a b c : C) (f : a ~> b) (g : b ~> c), + F <$> (f \; g) = F <$> f \; F <$> g; +}. +Unset Universe Checking. + +(* precat and cat have a quiver structure *) +HB.structure Definition Functor (C D : precat) : Set := + { F of IsPreFunctor C D F & PreFunctor_IsFunctor C D F }. +Set Universe Checking. +HB.instance Definition _ := IsQuiver.Build precat Functor.type. +HB.instance Definition _ := IsQuiver.Build cat Functor.type. + +(* functor equality is the same as prefunctor because of PI *) +Lemma functorP (C D : precat) (F G : C ~> D) (eqFG : F =1 G) : + let homF a b F := F a ~> F b in + (forall a b f, eq_rect _ (homF a b) (F^$ f) _ (funext eqFG) = G^$ f) -> + F = G. +Proof. +move=> /= /prefunctorP {eqFG}. +case: F G => [F [/= Fm Fm']] [G [/= Gm Gm']]//=. +move=> [_] /EqdepFacts.eq_sigT_iff_eq_dep eqFG. +case: _ / eqFG in Gm' *. +congr Functor.Pack; congr Functor.Class. +case: Fm' Gm' => [F1 Fc] [G1 Gc]. +by congr PreFunctor_IsFunctor.Axioms_; apply: Prop_irrelevance. +Qed. + +(* the identity function is a functor *) +HB.instance Definition _ (C : quiver) := + IsPreFunctor.Build C C idfun (fun a b => idfun). +HB.instance Definition _ (C : precat) := + PreFunctor_IsFunctor.Build C C idfun (fun=> erefl) (fun _ _ _ _ _ => erefl). + +(* the composition of prefunctors *) +Section comp_prefunctor. +Context {C D E : quiver} {F : C ~> D} {G : D ~> E}. + +HB.instance Definition _ := IsPreFunctor.Build C E (G \o F)%FUN + (fun a b f => G <$> F <$> f). +Lemma comp_Fun (a b : C) (f : a ~> b) : (G \o F)%FUN <$> f = G <$> (F <$> f). +Proof. by []. Qed. +End comp_prefunctor. + +Section comp_functor. +Context {C D E : precat} {F : C ~> D} {G : D ~> E}. +Lemma comp_F1 (a : C) : (G \o F)%FUN <$> \idmap_a = idmap. +Proof. by rewrite !comp_Fun !F1. Qed. +Lemma comp_Fcomp (a b c : C) (f : a ~> b) (g : b ~> c) : + (G \o F)%FUN <$> (f \; g) = (G \o F)%FUN <$> f \; (G \o F)%FUN <$> g. +Proof. by rewrite !comp_Fun !Fcomp. Qed. +HB.instance Definition _ := PreFunctor_IsFunctor.Build C E (G \o F)%FUN + comp_F1 comp_Fcomp. +End comp_functor. + +(* precat and cat have a precategory structure *) +HB.instance Definition _ := Quiver_IsPreCat.Build precat + (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). +HB.instance Definition _ := Quiver_IsPreCat.Build cat + (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). + +Lemma funext_frefl A B (f : A -> B) : funext (frefl f) = erefl. +Proof. exact: Prop_irrelevance. Qed. + +(* precategories and categories form a category *) +Definition precat_cat : PreCat_IsCat precat. +Proof. +by split=> [C D F|C D F|C D C' D' F G H]; + apply/functorP => a b f /=; rewrite funext_frefl. +Qed. +HB.instance Definition _ := precat_cat. +Definition cat_cat : PreCat_IsCat cat. +Proof. +by split=> [C D F|C D F|C D C' D' F G H]; + apply/functorP => a b f /=; rewrite funext_frefl. +Qed. +HB.instance Definition _ := cat_cat. + +Check (cat : cat). + +(* concrete categories *) +HB.mixin Record Quiver_IsPreConcrete T of Quiver T := { + concrete : T -> U; + concrete_fun : forall (a b : T), (a ~> b) -> concrete a -> concrete b; +}. +Unset Universe Checking. +#[short(type="preconcrete_quiver")] +HB.structure Definition PreConcreteQuiver : Set := + { C of Quiver_IsPreConcrete C & IsQuiver C }. +Set Universe Checking. +Coercion concrete : PreConcreteQuiver.sort >-> Sortclass. + +HB.mixin Record PreConcrete_IsConcrete T of PreConcreteQuiver T := { + concrete_fun_inj : forall (a b : T), injective (concrete_fun a b) +}. +Unset Universe Checking. +#[short(type="concrete_quiver")] +HB.structure Definition ConcreteQuiver : Set := + { C of PreConcreteQuiver C & PreConcrete_IsConcrete C }. +Set Universe Checking. + +HB.instance Definition _ (C : ConcreteQuiver.type) := + IsPreFunctor.Build _ _ (concrete : C -> U) concrete_fun. + +HB.mixin Record PreCat_IsConcrete T of ConcreteQuiver T & PreCat T := { + concrete1 : forall (a : T), concrete <$> \idmap_a = idfun; + concrete_comp : forall (a b c : T) (f : a ~> b) (g : b ~> c), + concrete <$> (f \; g) = ((concrete <$> g) \o (concrete <$> f))%FUN; +}. +Unset Universe Checking. +#[short(type="concrete_precat")] +HB.structure Definition ConcretePreCat : Set := + { C of PreCat C & ConcreteQuiver C & PreCat_IsConcrete C }. +#[short(type="concrete_cat")] +HB.structure Definition ConcreteCat : Set := + { C of Cat C & ConcreteQuiver C & PreCat_IsConcrete C }. +Set Universe Checking. + +HB.instance Definition _ (C : concrete_precat) := + PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). +HB.instance Definition _ (C : ConcreteCat.type) := + PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). + +HB.instance Definition _ := Quiver_IsPreConcrete.Build U (fun _ _ => id). +HB.instance Definition _ := PreConcrete_IsConcrete.Build U (fun _ _ _ _ => id). +HB.instance Definition _ := PreCat_IsConcrete.Build U + (fun=> erefl) (fun _ _ _ _ _ => erefl). + +Unset Universe Checking. +HB.instance Definition _ := Quiver_IsPreConcrete.Build quiver (fun _ _ => id). +HB.instance Definition _ := Quiver_IsPreConcrete.Build precat (fun _ _ => id). +HB.instance Definition _ := Quiver_IsPreConcrete.Build cat (fun _ _ => id). +Lemma quiver_concrete_subproof : PreConcrete_IsConcrete quiver. +Proof. +constructor=> C D F G FG; apply: prefunctorP. + by move=> x; congr (_ x); apply: FG. +by move=> *; apply: Prop_irrelevance. +Qed. +HB.instance Definition _ := quiver_concrete_subproof. + +Lemma precat_concrete_subproof : PreConcrete_IsConcrete precat. +Proof. +constructor=> C D F G FG; apply: functorP. + by move=> x; congr (_ x); apply: FG. +by move=> *; apply: Prop_irrelevance. +Qed. +HB.instance Definition _ := precat_concrete_subproof. + +Lemma cat_concrete_subproof : PreConcrete_IsConcrete cat. +Proof. +constructor=> C D F G FG; apply: functorP. + by move=> x; congr (_ x); apply: FG. +by move=> *; apply: Prop_irrelevance. +Qed. +HB.instance Definition _ := cat_concrete_subproof. +HB.instance Definition _ := PreCat_IsConcrete.Build precat + (fun=> erefl) (fun _ _ _ _ _ => erefl). +HB.instance Definition _ := PreCat_IsConcrete.Build cat + (fun=> erefl) (fun _ _ _ _ _ => erefl). +Set Universe Checking. + +(* constant functor *) +Definition cst (C D : quiver) (c : C) := fun of D => c. +Arguments cst {C} D c. +HB.instance Definition _ {C D : precat} (c : C) := + IsPreFunctor.Build D C (cst D c) (fun _ _ _ => idmap). +HB.instance Definition _ {C D : cat} (c : C) := + PreFunctor_IsFunctor.Build D C (cst D c) (fun=> erefl) + (fun _ _ _ _ _ => esym (compo1 idmap)). + +(* opposite category *) +Definition catop (C : U) : U := C. +Notation "C ^op" := (catop C) + (at level 2, format "C ^op") : cat_scope. +HB.instance Definition _ (C : quiver) := + IsQuiver.Build C^op (fun a b => hom b a). +HB.instance Definition _ (C : precat) := + Quiver_IsPreCat.Build (C^op) (fun=> idmap) (fun _ _ _ f g => g \; f). +HB.instance Definition _ (C : cat) := PreCat_IsCat.Build (C^op) + (fun _ _ _ => compo1 _) (fun _ _ _ => comp1o _) + (fun _ _ _ _ _ _ _ => esym (compoA _ _ _)). + +HB.instance Definition _ {C : precat} {c : C} := + IsPreFunctor.Build C _ (hom c) (fun a b f g => g \; f). +Lemma hom_Fhom_subproof (C : cat) (x : C) : + PreFunctor_IsFunctor _ _ (hom x). +Proof. by split=> *; apply/funext => h; [apply: compo1 | apply: compoA]. Qed. +HB.instance Definition _ {C : cat} {c : C} := hom_Fhom_subproof c. + +Check fun (C : cat) (x : C) => hom x : C ~>_cat U. + +Lemma hom_op {C : quiver} (c : C^op) : hom c = (@hom C)^~ c. +Proof. reflexivity. Qed. + +Lemma homFhomx {C : precat} (a b c : C) (f : a ~> b) (g : c ~> a) : + (hom c <$> f) g = g \; f. +Proof. reflexivity. Qed. + +(* nary product of categories *) +Definition dprod {I : U} (C : I -> U) := forall i, C i. + +Section hom_dprod. +Context {I : U} (C : I -> quiver). +Definition dprod_hom_subdef (a b : dprod C) := forall i, a i ~> b i. +HB.instance Definition _ := IsQuiver.Build (dprod C) dprod_hom_subdef. +End hom_dprod. +Arguments dprod_hom_subdef /. + +Section precat_dprod. +Context {I : U} (C : I -> precat). +Definition dprod_idmap_subdef (a : dprod C) : a ~> a := fun=> idmap. +Definition dprod_comp_subdef (a b c : dprod C) (f : a ~> b) (g : b ~> c) : a ~> c := + fun i => f i \; g i. +HB.instance Definition _ := IsPreCat.Build (dprod C) + dprod_idmap_subdef dprod_comp_subdef. +End precat_dprod. +Arguments dprod_idmap_subdef /. +Arguments dprod_comp_subdef /. + +Section cat_dprod. +Context {I : U} (C : I -> cat). +Local Notation type := (dprod C). +Lemma dprod_is_cat : PreCat_IsCat type. +Proof. +split=> [a b f|a b f|a b c d f g h]; apply/funext => i; +[exact: comp1o | exact: compo1 | exact: compoA]. +Qed. +HB.instance Definition _ := dprod_is_cat. +End cat_dprod. + +(* binary product *) +Section hom_prod. +Context {C D : quiver}. +Definition prod_hom_subdef (a b : C * D) := ((a.1 ~> b.1) * (a.2 ~> b.2))%type. +HB.instance Definition _ := IsQuiver.Build (C * D)%type prod_hom_subdef. +End hom_prod. + +Section precat_prod. +Context {C D : precat}. +HB.instance Definition _ := IsPreCat.Build (C * D)%type (fun=> (idmap, idmap)) + (fun a b c (f : a ~> b) (g : b ~> c) => (f.1 \; g.1, f.2 \; g.2)). +End precat_prod. + +Section cat_prod. +Context {C D : cat}. +Local Notation type := (C * D)%type. +Lemma prod_is_cat : PreCat_IsCat type. +Proof. +split=> [[a1 a2] [b1 b2] [f1 f2]|[a1 a2] [b1 b2] [f1 f2]| + [a1 a2] [b1 b2] [c1 c2] [d1 d2] [f1 f2] [g1 g2] [h1 h2]]; congr (_, _) => //=; +by [exact: comp1o | exact: compo1 | exact: compoA]. +Qed. +HB.instance Definition _ := prod_is_cat. +End cat_prod. + +(* naturality *) +HB.mixin Record IsNatural (C D : precat) (F G : C ~>_quiver D) + (n : forall c, F c ~> G c) := { + natural : forall (a b : C) (f : a ~> b), + F <$> f \; n b = n a \; G <$> f +}. +Unset Universe Checking. +HB.structure Definition Natural (C D : precat) + (F G : C ~>_quiver D) : Set := + { n of @IsNatural C D F G n }. +Set Universe Checking. +HB.instance Definition _ (C D : precat) := + IsQuiver.Build (PreFunctor.type C D) (@Natural.type C D). +HB.instance Definition _ (C D : cat) := + IsQuiver.Build (Functor.type C D) (@Natural.type C D). +Arguments natural {C D F G} n [a b] f : rename. + +Check fun (C D : cat) (F G : C ~> D) => F ~>_(C ~>_cat D) G. + +Lemma naturalx (C : precat) (D : concrete_precat) + (F G : C ~>_quiver D) (n : F ~> G) (a b : C) (f : a ~> b) g : + (concrete <$> n b) ((concrete <$> F <$> f) g) = + (concrete <$> G <$> f) ((concrete <$> n a) g). +Proof. +have /(congr1 (fun h => (concrete <$> h) g)) := natural n f. +by rewrite !Fcomp. +Qed. +Arguments naturalx {C D F G} n [a b] f. + +Lemma naturalU (C : precat) (F G : C ~>_quiver U) (n : F ~> G) + (a b : C) (f : a ~> b) g : n b (F^$ f g) = G^$ f (n a g). +Proof. exact: (naturalx n). Qed. + +Lemma natP (C D : precat) (F G : C ~>_quiver D) (n m : F ~> G) : + Natural.sort n = Natural.sort m -> n = m. +Proof. +case: n m => [/= n nP] [/= m mP] enm. +elim: _ / enm in mP *; congr Natural.Pack. +case: nP mP => [[?]] [[?]]; congr Natural.Class. +congr IsNatural.Axioms_. +exact: Prop_irrelevance. +Qed. + +Notation "F ~~> G" := (F ~>_(homs quiver) G) + (at level 99, G at level 200, format "F ~~> G"). +Notation "F ~~> G :> C ~> D" := (F ~> G :> (C ~>_quiver D)) + (at level 99, G at level 200, C, D at level 0, + format "F ~~> G :> C ~> D"). + +Definition natural_id {C D : precat} (F : C ~>_quiver D) (a : C) := \idmap_(F a). +Definition natural_id_natural (C D : cat) (F : C ~>_quiver D) : + IsNatural C D F F (natural_id F). +Proof. by constructor=> a b f; rewrite /natural_id/= compo1 comp1o. Qed. +HB.instance Definition _ C D F := @natural_id_natural C D F. + +Check fun {C D : cat} (F : C ~>_quiver D) => natural_id F : F ~> F. + +Definition natural_comp {C D : precat} (F G H : C ~>_quiver D) + (m : F ~> G) (n : G ~> H) (a : C) := m a \; n a. +Definition natural_comp_natural (C D : cat) (F G H : C ~>_quiver D) m n : + IsNatural C D F H (@natural_comp C D F G H m n). +Proof. +constructor=> a b f; rewrite /natural_comp/=. +by rewrite compoA natural -compoA natural compoA. +Qed. +HB.instance Definition _ C D F G H m n := @natural_comp_natural C D F G H m n. + +HB.instance Definition _ {C D : cat} := + Quiver_IsPreCat.Build (PreFunctor.type C D) natural_id natural_comp. +HB.instance Definition _ {C D : cat} := + Quiver_IsPreCat.Build (Functor.type C D) natural_id natural_comp. + +Lemma prefunctor_cat {C D : cat} : PreCat_IsCat (PreFunctor.type C D). +Proof. +constructor => [F G f|F G f|F G H J f g h]. +- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. +- by apply/natP/funext => a; rewrite /= /natural_comp compo1. +- by apply/natP/funext => a; rewrite /= /natural_comp compoA. +Qed. +HB.instance Definition _ C D := @prefunctor_cat C D. + +Lemma functor_cat {C D : cat} : PreCat_IsCat (Functor.type C D). +Proof. +constructor => [F G f|F G f|F G H J f g h]. +- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. +- by apply/natP/funext => a; rewrite /= /natural_comp compo1. +- by apply/natP/funext => a; rewrite /= /natural_comp compoA. +Qed. +HB.instance Definition _ C D := @functor_cat C D. + +Section nat_map_left. +Context {C D E : precat} {F G : C ~> D}. + +Definition nat_lmap (H : D ~>_quiver E) (n : forall c, F c ~> G c) : + forall c, (H \o F)%FUN c ~> (H \o G)%FUN c := fun c => H <$> n c. + +Fail Check fun (H : D ~> E) (n : F ~~> G) => nat_lmap H n : H \o F ~~> H \o G. + +Lemma nat_lmap_is_natural (H : D ~> E) (n : F ~~> G) : + IsNatural C E (H \o F) (H \o G) (nat_lmap H n). +Proof. by constructor=> a b f; rewrite /nat_lmap/= -!Fcomp natural. Qed. +HB.instance Definition _ H n := nat_lmap_is_natural H n. + +Check fun (H : D ~> E) (n : F ~~> G) => nat_lmap H n : H \o F ~~> H \o G. + +End nat_map_left. + +Notation "F n" := (nat_lmap F n) + (at level 58, format "F n", right associativity) : cat_scope. + +Section nat_map_right. +Context {C D E : precat} {F G : C ~> D}. + +Definition nat_rmap (H : E -> C) (n : forall c, F c ~> G c) : + forall c, (F \o H)%FUN c ~> (G \o H)%FUN c := fun c => n (H c). +Lemma nat_rmap_is_natural (H : E ~> C :> quiver) (n : F ~~> G) : + IsNatural E D (F \o H)%FUN (G \o H)%FUN (nat_rmap H n). +Proof. by constructor=> a b f; rewrite /nat_lmap/= natural. Qed. +HB.instance Definition _ H n := nat_rmap_is_natural H n. + +End nat_map_right. + +Notation "F <$o> n" := (nat_rmap F n) + (at level 58, format "F <$o> n", right associativity) : cat_scope. + +Definition delta (C D : cat) : C -> (D ~> C) := cst D. +Arguments delta C D : clear implicits. + +Definition map_delta {C D : cat} (a b : C) (f : a ~> b) : + delta C D a ~> delta C D b. +Proof. +apply: (@Natural.Pack _ _ (cst D a) (cst D b) (fun x => f)). +apply: Natural.Class; apply: (IsNatural.Build _ _ _ _ _). +by move=> a' b' ?; rewrite compo1 comp1o. +Defined. + +HB.instance Definition _ {C D : cat} := + IsPreFunctor.Build C (D ~> C) (delta C D) (@map_delta C D). + +Lemma delta_functor {C D : cat} : PreFunctor_IsFunctor _ _ (delta C D). +Proof. by constructor=> [a|a b c f g]; exact/natP. Qed. +HB.instance Definition _ C D := @delta_functor C D. + +HB.mixin Record IsMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { + unit : idfun ~~> M; + join : (M \o M)%FUN ~~> M; + bind : forall (a b : C), (a ~> M b) -> (M a ~> M b); + bindE : forall a b (f : a ~> M b), bind a b f = M <$> f \; join b; + unit_join : forall a, (M <$> unit a) \; join _ = idmap; + join_unit : forall a, join _ \; (M <$> unit a) = idmap; + join_square : forall a, M <$> join a \; join _ = join _ \; join _ +}. + +#[short(type="premonad")] +HB.structure Definition PreMonad (C : precat) := + {M of @PreFunctor C C M & IsMonad C M}. +#[short(type="monad")] +HB.structure Definition Monad (C : precat) := + {M of @Functor C C M & IsMonad C M}. + +HB.factory Record IsJoinMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { + unit : idfun ~~> M; + join : (M \o M)%FUN ~~> M; + unit_join : forall a, (M <$> unit a) \; join _ = idmap; + join_unit : forall a, join _ \; (M <$> unit a) = idmap; + join_square : forall a, M <$> join a \; join _ = join _ \; join _ +}. +HB.builders Context C M of IsJoinMonad C M. + HB.instance Definition _ := IsMonad.Build C M + (fun a b f => erefl) unit_join join_unit join_square. +HB.end. + +HB.mixin Record IsCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { + counit : M ~~> idfun; + cojoin : M ~~> (M \o M)%FUN; + cobind : forall (a b : C), (M a ~> b) -> (M a ~> M b); + cobindE : forall a b (f : M a ~> b), cobind a b f = cojoin _ \; M <$> f; + unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; + join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; + cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ +}. +#[short(type="precomonad")] +HB.structure Definition PreCoMonad (C : precat) := + {M of @PreFunctor C C M & IsCoMonad C M}. +#[short(type="comonad")] +HB.structure Definition CoMonad (C : precat) := + {M of @Functor C C M & IsCoMonad C M}. + +HB.factory Record IsJoinCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { + counit : M ~~> idfun; + cojoin : M ~~> (M \o M)%FUN; + unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; + join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; + cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ +}. +HB.builders Context C M of IsJoinCoMonad C M. + HB.instance Definition _ := IsCoMonad.Build C M + (fun a b f => erefl) unit_cojoin join_counit cojoin_square. +HB.end. + +Lemma idFmap (C : cat) (a b : C) (f : a ~> b) : idfun <$> f = f. +Proof. by []. Qed. + +Lemma compFmap (C D E : cat) (F : C ~> D) (G : D ~> E) (a b : C) (f : a ~> b) : + (G \o F) <$> f = G <$> F <$> f. +Proof. by []. Qed. + +(* yoneda *) +Section hom_repr. +Context {C : cat} (F : C ~>_cat U). + +Definition homF : C -> U := fun c => hom c ~~> F. + +Section nat. +Context (x y : C) (xy : x ~> y). + +(* Goal hom x ~~> F -> hom y ~~> F *) +Context (n : hom x ~~> F). +Definition homFhom c : hom y c ~> F c := fun g => n _ (xy \; g). + +Lemma homFhom_natural_subdef : IsNatural C U (hom y) F homFhom. +Proof. +by split=> a b f /=; apply/funext => g /=; + rewrite /homFhom !Ucompx/= !naturalU/= Fcomp. +Qed. +HB.instance Definition _ := homFhom_natural_subdef. +End nat. +Arguments homFhom / : clear implicits. + +HB.about IsPreFunctor.Build. +Check homFhom : forall x y : C, (x ~> y) -> (homF x -> homF y). +HB.instance Definition _ := IsPreFunctor.Build _ _ homF homFhom. +Lemma homF_functor_subproof : PreFunctor_IsFunctor _ _ homF. +Proof. +split=> [a|a b c f g]. + apply/funext => -[/= f natf]. + apply: natP => //=; apply: funext => b; apply: funext => g/=. + by rewrite comp1o. +apply/funext => -[/= h natf]. +apply: natP => //=; apply: funext => d; apply: funext => k/=. +by rewrite compoA. +Qed. +HB.instance Definition _ := homF_functor_subproof. + +Section pointed. +Context (c : C). +Definition hom_repr : homF c ~> F c := fun f => f _ idmap. +Arguments hom_repr /. + +Definition repr_hom (fc : F c) a : hom c a ~> F a := + fun f => F^$ f fc. +Arguments repr_hom / : clear implicits. +Lemma repr_hom_subdef (fc : F c) : IsNatural _ _ _ _ (repr_hom fc). +Proof. by split=> a b f /=; apply/funext=> x; rewrite !Ucompx/= Fcomp. Qed. +HB.instance Definition _ {fc : F c} := repr_hom_subdef fc. + +Definition repr_hom_nat : F c ~> homF c := repr_hom. + +Lemma hom_reprK : cancel hom_repr repr_hom_nat. +Proof. +move=> f; apply/natP; apply/funext => a; apply/funext => g /=. +by rewrite -naturalU/=; congr (f _ _); apply: comp1o. +Qed. +Lemma repr_homK : cancel (repr_hom : F c ~> homF c) hom_repr. +Proof. by move=> fc; rewrite /= F1. Qed. +End pointed. +Arguments hom_repr /. +Arguments repr_hom /. + +Lemma hom_repr_natural_subproof : IsNatural _ _ _ _ hom_repr. +Proof. +split=> a b f /=; apply/funext => n /=; rewrite !Ucompx/= compo1/=. +by rewrite -naturalU/=; congr (n _ _); apply/esym/comp1o. +Qed. +HB.instance Definition _ := hom_repr_natural_subproof. + +(* show this from the previous proof *) +Lemma hom_natural_repr_subproof : IsNatural _ _ _ _ repr_hom_nat. +Proof. +split=> a b f /=; apply: funext => fa /=; rewrite !Ucompx/=. +apply: natP; apply: funext => c /=; apply: funext => d /=. +by rewrite Fcomp Ucompx/=. +Qed. +HB.instance Definition _ := hom_natural_repr_subproof. + +Definition hom_repr_nat : homF ~~> F := hom_repr. +Definition repr_hom_nat_nat : F ~~> homF := repr_hom_nat. + +End hom_repr. + +(* comma categories *) +Module comma. +Section homcomma. +Context {C D E : precat} (F : C ~> E) (G : D ~> E). + +Definition type := { x : C * D & F x.1 ~> G x.2 }. +Definition hom_subdef (a b : type) := { + f : tag a ~> tag b & F <$> f.1 \; tagged b = tagged a \; G <$> f.2 + }. +HB.instance Definition _ := IsQuiver.Build type hom_subdef. +End homcomma. +Arguments hom_subdef /. +Section comma. +Context {C D E : cat} (F : C ~> E) (G : D ~> E). +Notation type := (type F G). + +Program Definition idmap_subdef (a : type) : a ~> a := @Tagged _ idmap _ _. +Next Obligation. by rewrite !F1 comp1o compo1. Qed. +Program Definition comp_subdef (a b c : type) + (f : a ~> b) (g : b ~> c) : a ~> c := + @Tagged _ (tag f \; tag g) _ _. +Next Obligation. by rewrite !Fcomp -compoA (tagged g) compoA (tagged f) compoA. Qed. +HB.instance Definition _ := IsPreCat.Build type idmap_subdef comp_subdef. +Arguments idmap_subdef /. +Arguments comp_subdef /. + +Lemma comma_homeqP (a b : type) (f g : a ~> b) : projT1 f = projT1 g -> f = g. +Proof. +case: f g => [f fP] [g +]/= eqfg; case: _ / eqfg => gP. +by congr existT; apply: Prop_irrelevance. +Qed. + +Lemma comma_is_cat : PreCat_IsCat type. +Proof. +by split=> [[a fa] [b fb] [*]|[a fa] [b fb] [*]|*]; + apply/comma_homeqP; rewrite /= ?(comp1o, compo1, compoA). +Qed. +HB.instance Definition _ := comma_is_cat. +End comma. +End comma. +Notation "F `/` G" := (@comma.type _ _ _ F G) + (at level 40, G at level 40, format "F `/` G") : cat_scope. +Notation "a /` G" := (cst unit a `/` G) + (at level 40, G at level 40, format "a /` G") : cat_scope. +Notation "F `/ b" := (F `/` cst unit b) + (at level 40, b at level 40, format "F `/ b") : cat_scope. +Notation "a / b" := (cst unit a `/ b) : cat_scope. + +Definition obj (C : quiver) : Type := C. +HB.mixin Record IsInitial {C : quiver} (i : obj C) := { + to : forall c, i ~> c; + to_unique : forall c (f : i ~> c), f = to c +}. +#[short(type="initial")] +HB.structure Definition Initial {C : quiver} := {i of IsInitial C i}. + +HB.mixin Record IsTerminal {C : quiver} (t : obj C) := { + from : forall c, c ~> t; + from_unique : forall c (f : c ~> t), f = from c +}. +#[short(type="terminal")] +HB.structure Definition Terminal {C : quiver} := {t of IsTerminal C t}. +#[short(type="universal")] +HB.structure Definition Universal {C : quiver} := + {u of Initial C u & Terminal C u}. + +(* Definition hom' {C : precat} (a b : C) := a ~> b. *) +(* (* Bug *) *) +(* Identity Coercion hom'_hom : hom' >-> hom. *) + +(* HB.mixin Record IsMono {C : precat} (b c : C) (f : hom b c) := { *) +(* monoP : forall (a : C) (g1 g2 : a ~> b), g1 \; f = g2 \; f -> g1 = g2 *) +(* }. *) +(* #[short(type="mono")] *) +(* HB.structure Definition Mono {C : precat} (a b : C) := {m of IsMono C a b m}. *) +(* Notation "a >~> b" := (mono a b) *) +(* (at level 99, b at level 200, format "a >~> b") : cat_scope. *) +(* Notation "C >~>_ T D" := (@mono T C D) *) +(* (at level 99, T at level 0, only parsing) : cat_scope. *) + +(* HB.mixin Record IsEpi {C : precat} (a b : C) (f : hom a b) := { *) +(* epiP : forall (c : C) (g1 g2 : b ~> c), g1 \o f = g2 \o f -> g1 = g2 *) +(* }. *) +(* #[short(type="epi")] *) +(* HB.structure Definition Epi {C : precat} (a b : C) := {e of IsEpi C a b e}. *) +(* Notation "a ~>> b" := (epi a b) *) +(* (at level 99, b at level 200, format "a ~>> b") : cat_scope. *) +(* Notation "C ~>>_ T D" := (@epi T C D) *) +(* (at level 99, T at level 0, only parsing) : cat_scope. *) + +(* #[short(type="iso")] *) +(* HB.structure Definition Iso {C : precat} (a b : C) := *) +(* {i of @Mono C a b i & @Epi C a b i}. *) +(* Notation "a <~> b" := (epi a b) *) +(* (at level 99, b at level 200, format "a <~> b") : cat_scope. *) +(* Notation "C <~>_ T D" := (@epi T C D) *) +(* (at level 99, T at level 0, only parsing) : cat_scope. *) + +HB.mixin Record IsRightAdjoint (D C : precat) (R : D -> C) + of @PreFunctor D C R := { + L_ : C ~> D; + phi : forall c d, (L_ c ~> d) -> (c ~> R d); + psy : forall c d, (c ~> R d) -> (L_ c ~> d); + phi_psy c d : (phi c d \o psy c d)%FUN = @id (c ~> R d); + psy_phi c d : (psy c d \o phi c d)%FUN = @id (L_ c ~> d) +}. +#[short(type="right_adjoint")] +HB.structure Definition RightAdjoint (D C : precat) := + { R of @Functor D C R & IsRightAdjoint D C R }. +Arguments L_ {_ _}. +Arguments phi {D C s} {c d}. +Arguments psy {D C s} {c d}. + + +HB.mixin Record PreCat_IsMonoidal C of PreCat C := { + onec : C; + (* prod1 : @hom precat (C * C)%type C ; *) + prod : (C * C)%type ~>_precat C; +}. +#[short(type="premonoidal")] +#[verbose] +HB.structure Definition PreMonoidal := { C of PreCat C & PreCat_IsMonoidal C }. +Notation premonoidal := premonoidal. +Arguments prod {C} : rename. +Notation "a * b" := (prod (a, b)) : cat_scope. +Reserved Notation "f <*> g" (at level 40, g at level 40, format "f <*> g"). +Notation "f <*> g" := (prod^$ (f, g)) (only printing) : cat_scope. +Notation "f <*> g" := (prod^$ ((f, g) : (_, _) ~> (_, _))) + (only parsing) : cat_scope. +Notation "1" := onec : cat_scope. + +Definition hom_cast {C : quiver} {a a' : C} (eqa : a = a') {b b' : C} (eqb : b = b') : + (a ~> b) -> (a' ~> b'). +Proof. now elim: _ / eqa; elim: _ / eqb. Defined. + +HB.mixin Record PreFunctor_IsMonoidal (C D : premonoidal) F of + @PreFunctor C D F := { + fun_one : F 1 = 1; + fun_prod : forall (x y : C), F (x * y) = F x * F y; +}. +#[short(type="monoidal_prefunctor")] +HB.structure Definition MonoidalPreFunctor C D := + { F of @PreFunctor_IsMonoidal C D F }. +Arguments fun_prod {C D F x y} : rename. +(* Arguments fun_prodF {C D F x x'} f {y y'} g : rename. *) +Unset Universe Checking. +HB.instance Definition _ := IsQuiver.Build premonoidal MonoidalPreFunctor.type. +Set Universe Checking. + +HB.instance Definition _ (C : quiver) := + IsPreFunctor.Build (C * C)%type C fst + (fun (a b : C * C) (f : a ~> b) => f.1). +HB.instance Definition _ (C : quiver) := + IsPreFunctor.Build (C * C)%type C snd + (fun (a b : C * C) (f : a ~> b) => f.2). + +Definition prod3l {C : premonoidal} (x : C * C * C) : C := + (x.1.1 * x.1.2) * x.2. +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build _ C prod3l + (fun a b (f : a ~> b) => (f.1.1 <*> f.1.2) <*> f.2). + +Definition prod3r {C : premonoidal} (x : C * C * C) : C := + x.1.1 * (x.1.2 * x.2). +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build _ C prod3r + (fun a b (f : a ~> b) => f.1.1 <*> (f.1.2 <*> f.2)). + +Definition prod1r {C : premonoidal} (x : C) : C := 1 * x. +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build C C prod1r + (fun (a b : C) (f : a ~> b) => \idmap_1 <*> f). + +Definition prod1l {C : premonoidal} (x : C) : C := x * 1. +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build C C prod1l + (fun (a b : C) (f : a ~> b) => f <*> \idmap_1). + +HB.mixin Record PreMonoidal_IsMonoidal C of PreMonoidal C := { + prodA : prod3l ~~> prod3r; + prod1c : prod1r ~~> idfun; + prodc1 : prod1l ~~> idfun; + prodc1c : forall (x y : C), + prodA (x, 1, y) \; \idmap_x <*> prod1c y = prodc1 x <*> \idmap_y; + prodA4 : forall (w x y z : C), + prodA (w * x, y, z) \; prodA (w, x, y * z) = + prodA (w, x, y) <*> \idmap_z \; prodA (w, x * y, z) \; \idmap_w <*> prodA (x, y, z); +}. + +Unset Universe Checking. +#[short(type="monoidal")] +#[verbose] +HB.structure Definition Monoidal : Set := + { C of PreMonoidal_IsMonoidal C & PreMonoidal C }. +Set Universe Checking. + +(******************************************************************) + + +Record cospan (Q : quiver) (A B : Q) := Cospan { + top : Q; + left2top : A ~> top; + right2top : B ~> top +}. + +Section cospans. +Variables (Q : precat) (A B : Q). +Record cospan_map (c c' : cospan A B) := CospanMap { + top_map : top c ~> top c'; + left2top_map : left2top c \; top_map = left2top c'; + right2top_map : right2top c \; top_map = right2top c'; +}. +HB.instance Definition _ := IsQuiver.Build (cospan A B) cospan_map. + +Lemma cospan_mapP (c c' : cospan A B) (f g : c ~> c') : + top_map f = top_map g <-> f = g. +Admitted. +End cospans. + +Section cospans_in_cat. +Variables (Q : cat) (A B : Q). +Definition cospan_idmap (c : cospan A B) := + @CospanMap Q A B c c idmap (compo1 _) (compo1 _). +Program Definition cospan_comp (c1 c2 c3 : cospan A B) + (f12 : c1 ~> c2) (f23 : c2 ~> c3) := + @CospanMap Q A B c1 c3 (top_map f12 \; top_map f23) _ _. +Next Obligation. by rewrite compoA !left2top_map. Qed. +Next Obligation. by rewrite compoA !right2top_map. Qed. +HB.instance Definition _ := IsPreCat.Build (cospan A B) cospan_idmap cospan_comp. + +Lemma cospan_are_cats : PreCat_IsCat (cospan A B). +Proof. +constructor=> [a b f|a b f|a b c d f g h]. +- by apply/cospan_mapP => /=; rewrite comp1o. +- by apply/cospan_mapP => /=; rewrite compo1. +- by apply/cospan_mapP => /=; rewrite compoA. +Qed. +HB.instance Definition _ := cospan_are_cats. +End cospans_in_cat. + +Section spans_and_co. +Variables (Q : quiver) (A B : Q). +Definition span := @cospan Q^op A B. +Definition bot (s : span) : Q := top s. +Definition bot2left (s : span) : bot s ~>_Q A := left2top s. +Definition bot2right (s : span) : bot s ~>_Q B := right2top s. +Definition Span (C : Q) (f : C ~> A) (g : C ~> B) : span := + @Cospan Q^op A B C f g. +End spans_and_co. + +HB.instance Definition _ (Q : precat) (A B : Q) := + Quiver.copy (span A B) (@cospan Q^op A B)^op. +HB.instance Definition _ (Q : cat) (A B : Q) := + Cat.copy (span A B) (@cospan Q^op A B)^op. + +Section bot_map. +Variables (C : cat) (A B : C) (s s' : span A B) (f : s ~> s'). +Definition bot_map : bot s ~> bot s' := top_map f. +Lemma bot2left_map : bot_map \; bot2left s' = bot2left s. +Proof. exact: left2top_map f. Qed. +Lemma bot2right_map : bot_map \; bot2right s' = bot2right s. +Proof. exact: right2top_map f. Qed. +End bot_map. + +HB.mixin Record isPrePullback (Q : precat) (A B : Q) + (c : cospan A B) (s : span A B) := { + is_square : bot2left s \; left2top c = bot2right s \; right2top c; +}. +#[short(type=prepullback)] +HB.structure Definition PrePullback Q A B (c : cospan A B) := + {s of isPrePullback Q A B c s}. +Arguments prepullback {Q A B} c. + +Section prepullback. +Variables (Q : precat) (A B : Q) (c : cospan A B). +HB.instance Definition _ := + IsQuiver.Build (prepullback c) + (fun a b => (a : span A B) ~>_(span A B) (b : span A B)). +Lemma eq_prepullbackP (p q : prepullback c) : + p = q :> span _ _ <-> p = q. +Admitted. +End prepullback. +Section prepullback. +Variables (Q : cat) (A B : Q) (csp : cospan A B). +(* TODO: why can't we do that? *) +(* HB.instance Definition _ := Cat.on (prepullback csp). *) +HB.instance Definition _ := + Quiver_IsPreCat.Build (prepullback csp) + (fun a => \idmap_(a : span A B)) + (* TODO: study how to make this coercion trigger + even when the target is not reduced to span *) + (fun a b c f g => f \; g). +Lemma prepullback_is_cat : PreCat_IsCat (prepullback csp). +Proof. (* should be copied from the cat on span *) +constructor=> [a b f|a b f|a b c d f g h]; + [exact: comp1o|exact: compo1|exact: compoA]. +Qed. +End prepullback. + +HB.tag Definition pb_terminal (Q : precat) + (A B : Q) (c : cospan A B) (s : prepullback c) : + obj (prepullback c) := s. + +#[wrapper] +HB.mixin Record prepullback_isTerminal (Q : precat) + (A B : Q) (c : cospan A B) + (s : span A B) of isPrePullback Q A B c s := { + prepullback_terminal : + IsTerminal (prepullback c) (pb_terminal s) +}. +#[short(type="pullback"), verbose] +HB.structure Definition Pullback (Q : precat) + (A B : Q) (c : cospan A B) := + {s of isPrePullback Q A B c s + & IsTerminal (prepullback c) (pb_terminal s) }. + +Notation pbsquare u v f g := + (Pullback _ (Cospan f g) (Span u v)). + +Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). + +(******************************************************************) + +(*** ENRICHED CATEGORIES *) + +Declare Scope encat_scope. +Delimit Scope encat_scope with encat. +Local Open Scope encat_scope. + +(* Enrichment in a monoidal category, following + https://ncatlab.org/nlab/show/enriched+category +*) +HB.mixin Record IsEnQuiver (V: Type) C := { + hom_object : C -> C -> V + }. +Unset Universe Checking. +HB.structure Definition EnQuiver (V: Type) : Set := + { C of IsEnQuiver V C }. +Set Universe Checking. + +(* Monoidal precategory with the enrichment operators (no axioms) *) +HB.mixin Record IsEnPreCat (V: PreMonoidal.type) C of + EnQuiver (PreMonoidal.sort V) C := { + id_element : forall (a: C), + @hom V onec (hom_object a a) ; + comp_morphism : forall (a b c: C), + @hom V (@hom_object V C b c * @hom_object V C a b) + (@hom_object V C a c) +}. +Unset Universe Checking. +HB.structure Definition EnPreCat (V: PreMonoidal.type) : Set := + { C of IsEnPreCat V C }. +Set Universe Checking. + +Notation "a ~^ b" := (hom_object a b) + (at level 99, b at level 200, format "a ~^ b") : encat_scope. +Notation "a ~^_ ( V , C ) b" := (@hom_object V C a b) + (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. +Notation "~^IE a" := (id_element a) + (at level 99, format "~^IE a") : cat_scope. +Notation "~^IE_ ( V , C ) a" := (@id_element V C a) + (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. +(* not working *) +Notation "~^CM a b c" := (comp_morphism a b c) + (at level 99, + format "~^CM a b c") : cat_scope. +Notation "~^CM_ ( V , C ) a b c" := (@comp_morphism V C a b c) + (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. + +(* V-enriched category: + V is the monoidal category; + C is the base category that gets enriched +*) +HB.mixin Record IsEnCat (V: Monoidal.type) C of EnPreCat V C := { + ecat_comp_assoc : forall a b c d: C, + forall alpha: + (((c ~^_(V,C) d) * (b ~^_(V,C) c)) * (a ~^_(V,C) b)) ~>_V + ((c ~^_(V,C) d) * ((b ~^_(V,C) c) * (a ~^_(V,C) b))), + ((@comp_morphism V C b c d) <*> (@idmap V (a ~^_(V,C) b))) \; + (@comp_morphism V C a b d) + = + alpha \; + ((@idmap V (c ~^_(V,C) d)) <*> (@comp_morphism V C a b c)) \; + (@comp_morphism V C a c d) ; + + ecat_comp_left_unital : forall a b: C, + forall l: onec * (a ~^_(V,C) b) ~>_V (a ~^_(V,C) b), + l = ((@id_element V C b) <*> (@idmap V (a ~^_(V,C) b))) \; + (@comp_morphism V C a b b) ; + ecat_comp_right_unital : forall a b: C, + forall r: (a ~^_(V,C) b) * onec ~>_V (a ~^_(V,C) b), + r = ((@idmap V (a ~^_(V,C) b)) <*> (@id_element V C a)) \; + (@comp_morphism V C a a b) +}. +Unset Universe Checking. +#[verbose] +HB.structure Definition EnCat (V: Monoidal.type) : Set := { C of IsEnCat V C }. +Set Universe Checking. + + + +(*** DOUBLE CATEGORIES (REVISED) *) + +(* transpose for horizontal morphism quiver. + HB.tag needed to identify transpose as lifter *) +HB.tag Definition transpose (C : quiver) : U := C. +#[wrapper] HB.mixin Record IsHQuiver C of IsQuiver C := { + is_hquiver : IsQuiver (transpose C) +}. +(* vertical and horizontal quivers, defining cells *) +Unset Universe Checking. +#[short(type="cquiver")] +HB.structure Definition CQuiver : Set := { C of IsQuiver C & IsHQuiver C }. +Set Universe Checking. + +HB.tag Definition hhom (c : CQuiver.type) : c -> c -> U := @hom (transpose c). + +(* record to represent the set of morphims + (needed for 2-objects, i.e. horizontal morphisms) *) +Record Total2 T (h: T -> T -> U) : Type := HO { + source : T; + target : T; + this_morph : h source target }. + +(* the set of horizontal morphisms. *) +HB.tag Definition HHomSet (C: cquiver) := Total2 (@hhom C). + +(* source functor (for horizontal morphisms): D1 -> D0. + defined as object-level function, by functoriality lifted to a + (2-cell, vertical) morphism-level one *) +HB.tag Definition HSource C := fun (X: HHomSet C) => @source C (@hhom C) X. +(* target functor (for horizontal morphisms): D1 -> D0. *) +HB.tag Definition HTarget C := fun (X: HHomSet C) => @target C (@hhom C) X. + +(* D1 quiver requirement. *) +#[wrapper] +HB.mixin Record IsDQuiver T of CQuiver T := { is_dquiver : Quiver (HHomSet T) }. +Unset Universe Checking. +#[short(type="dquiver")] +HB.structure Definition DQuiver : Set := { C of IsDQuiver C }. +Set Universe Checking. + +(* Precategory based on the HQuiver (i.e. horizontal precategory on D0 + objects) *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHPreCat T of DQuiver T := { + is_hprecat : Quiver_IsPreCat (transpose T) }. +#[short(type="hprecat")] +HB.structure Definition HPreCat : Set := { C of IsHPreCat C }. +Set Universe Checking. + +(* The category based on the HQuiver (i.e. horizontal category on D0 + objects) *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHCat T of HPreCat T := { + is_hcat : PreCat_IsCat (transpose T) }. +#[short(type="hcat")] +HB.structure Definition HCat : Set := { C of IsHCat C }. +Set Universe Checking. + +(* used to define composable pairs of morphisms as a set *) +Record GenComp T (h: T -> T -> U) := GC { + h_one : T; + h_two : T ; + h_three : T; + h_first : h h_one h_two ; + h_second : h h_two h_three +}. + +(* composable pairs of horizontal morphisms as a set *) +HB.tag Definition HCompSet (C: cquiver) := GenComp (@hhom C). + +Definition H2First (C: cquiver) (X: @HCompSet C) : HHomSet C := + @HO C _ (h_one X) (h_two X) (h_first X). +Definition H2Second (C: cquiver) (X: @HCompSet C) : HHomSet C := + @HO C _ (h_two X) (h_three X) (h_second X). + +(* hhunit - horizontal unit functor. + + hhcomp - horizontal composition functor (horizontal composition of + two horizontal morphisms from a cell product). + + Both specified as object-level functions, to be lifted by + functoriality to morphism-level ones. + + At the object level, hunit gives a horizontal identity morphism for + each D0 object. At the morphism level, it gives horizontal 2-cell + identity for each vertical morphism. + + In the case of hcomp, relying on functoriality requires some care + in defining the pullback category, making sure that adjacency at + the object-level (between horizontal morphisms) is matched by + adjacency at the morphism-level (between 2-cells). *) +Definition hhunit (T: hprecat) (a: T) : HHomSet T := + @HO T (@hhom T) a a (@idmap (transpose T) a). + +Definition hhcomp (T: hprecat) (x: HCompSet T) : HHomSet T := + match x with + @GC _ _ a b c h1 h2 => @HO T (@hhom T) a c + (@comp (transpose T) a b c h1 h2) end. + +(* horizontal unit functor: D0 -> D1 *) +HB.tag Definition HUnit (C: hprecat) := + fun (x: HPreCat.sort C) => @hhunit C x. +(* horizontal composition functor: D1 * D1 -> D1 *) +HB.tag Definition HComp (C: hprecat) := + fun (x: HCompSet C) => @hhcomp C x. + +(* Precategory based on the DQuiver (i.e. precategory D1). Gives: + vertical 2-cell identity morphism. + vertical 2-cell composition. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsC2PreCat T of DQuiver T := { + is_c2precat : Quiver_IsPreCat (@HHomSet T) }. +#[short(type="c2precat")] +HB.structure Definition C2PreCat : Set := { C of IsC2PreCat C }. +Set Universe Checking. + +(* The category based on the DQuiver (i.e. category D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsC2Cat T of C2PreCat T := { + is_c2cat : PreCat_IsCat (@HHomSet T) }. +#[short(type="c2cat")] +HB.structure Definition C2Cat : Set := { C of IsC2Cat C }. +Set Universe Checking. + +(* source prefunctor. + HHomSet T is the quiver of the 2-morphisms, thanks to DQuiver. + T is the quiver of 1-morphisms. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsSPreFunctor T of Cat T & C2Cat T := { + is_sprefunctor : IsPreFunctor (HHomSet T) T (@HSource T) }. +HB.structure Definition SPreFunctor : Set := {C of IsSPreFunctor C}. +Set Universe Checking. + +(* target prefunctor. *) +Unset Universe Checking. +#[wrapper] + HB.mixin Record IsTPreFunctor T of SPreFunctor T := { + is_tprefunctor : IsPreFunctor (HHomSet T) T (@HTarget T) }. +HB.structure Definition TPreFunctor : Set := {C of IsTPreFunctor C}. +Set Universe Checking. + +(* source functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record SPreFunctor_IsFunctor T of TPreFunctor T := { + is_sfunctor : PreFunctor_IsFunctor (HHomSet T) T (@HSource T) }. +HB.structure Definition SFunctor : Set := {C of SPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* target functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record TPreFunctor_IsFunctor T of SFunctor T := { + is_tfunctor : PreFunctor_IsFunctor (HHomSet T) T (@HTarget T) }. +HB.structure Definition TFunctor : Set := {C of TPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* unit prefunctor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsUPreFunctor T of HCat T & TFunctor T := + { is_uprefunctor : IsPreFunctor T (HHomSet T) (@HUnit T) }. +HB.structure Definition UPreFunctor : Set := {C of IsUPreFunctor C}. +Set Universe Checking. + +(* unit functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record UPreFunctor_IsFunctor T of UPreFunctor T := { + is_ufunctor : PreFunctor_IsFunctor T (HHomSet T) (@HUnit T) }. +HB.structure Definition UFunctor : Set := {C of UPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* 2-cell (D1) morphisms *) +Definition c2hom (D: DQuiver.type) : HHomSet D -> HHomSet D -> U := + @hom (HHomSet D). + +Definition C2Hom (D: DQuiver.type) (a b c d: D) (h0: hhom a b) + (h1: hhom c d) : U := c2hom (HO h0) (HO h1). + +(* The set of D1 morphisms *) +HB.tag Definition C2HomSet (C: DQuiver.type) := Total2 (@c2hom C). + +(* horizontal 2-cell unit (maps vertical morphisms to horizontally + unitary 2-cells) *) +Definition HC2Unit (T: UFunctor.type) (a b: T) (m: @hom T a b) : + c2hom (HUnit a) (HUnit b) := @Fhom _ _ (@HUnit T) a b m. + +(* 2-cell source *) +Definition HC2Source (T: UFunctor.type) (a b: @HHomSet T) + (m: @c2hom T a b) : + @hom T (HSource a) (HSource b) := @Fhom _ _ (@HSource T) a b m. + +(* 2-cell target *) +Definition HC2Target (T: UFunctor.type) (a b: @HHomSet T) + (m: @c2hom T a b) : + @hom T (HTarget a) (HTarget b) := @Fhom _ _ (@HTarget T) a b m. + +(* horizontal composition of two (naked) horizontal morphisms *) +Definition l_hcomp (T: UFunctor.type) (a0 a1 a2: T) + (h0: hhom a0 a1) (h1: hhom a1 a2) : HHomSet T := + @HO T _ a0 a2 (@comp (transpose T) a0 a1 a2 h0 h1). + + +(** HCompSet T is the pseudo-pullback category used to deal with + products of D1 (where the adjacency condition is expressed + w.r.t. D0 *) + +Notation "'sigma' x .. y , p" := (sigT (fun x => .. (sigT (fun y => p)) ..)) + (at level 200, x binder, right associativity, + format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") + : type_scope. + +(** HCompSet quiver *) +Definition HComp_hom (T: UFunctor.type) (x y: HCompSet T) := + sigma (hh0: C2Hom (h_first x) (h_first y)) + (hh1: C2Hom (h_second x) (h_second y)), + HC2Target hh0 = HC2Source hh1. + +HB.instance Definition HCompQuiver (T: UFunctor.type) : + IsQuiver (HCompSet T) := + IsQuiver.Build (HCompSet T) (fun A B => @HComp_hom T A B). + +(* HCompSet identity, defined in proof mode *) +Program Definition HComp_id_P (T: UFunctor.type) (A: HCompSet T) : A ~> A. +unfold hom; simpl. +unfold HComp_hom, C2Hom; simpl. +destruct A; simpl. +set h0' := HO h_first0. +set h1' := HO h_second0. +repeat econstructor. +instantiate (1:= @idmap (HHomSet T) h1'). +instantiate (1:= @idmap (HHomSet T) h0'). +assert (HC2Target (@idmap (HHomSet T) h0') = @idmap _ h_two0) as T0. +{ unfold HC2Target, HTarget. + rewrite F1; auto. +} +assert (HC2Source (@idmap (HHomSet T) h1') = @idmap _ h_two0) as S1. +{ unfold HC2Source, HSource. + rewrite F1; auto. +} +rewrite T0. +rewrite S1. +reflexivity. +Defined. + +Lemma HComp_id_eq (T : UFunctor.type) (a: HCompSet T) : + HC2Target (@idmap (@HHomSet T) (H2First a)) = + HC2Source (@idmap (@HHomSet T) (H2Second a)). +unfold HC2Target, HTarget. +unfold HC2Source, HSource. +repeat rewrite F1; auto. +Defined. + +(* HCompSet identity, only partially in proof mode *) +Program Definition HComp_id' (T: UFunctor.type) (A: HCompSet T) : A ~> A := + let h0 := h_first A + in let h1 := h_second A + in let uu0 := @idmap (HHomSet T) (HO h0) + in let uu1 := @idmap (HHomSet T) (HO h1) + in @existT (C2Hom h0 h0) + (fun hh0: (C2Hom h0 h0) => + sigma (hh1 : C2Hom h1 h1), HC2Target hh0 = HC2Source hh1) uu0 + (@existT (C2Hom h1 h1) + (fun hh1: (C2Hom h1 h1) => HC2Target uu0 = HC2Source hh1) uu1 _). +Obligation 1. +eapply HComp_id_eq; eauto. +Defined. + +Definition HComp_id (T: UFunctor.type) (A: HCompSet T) : A ~> A := + let h0 := h_first A + in let h1 := h_second A + in let uu0 := @idmap (HHomSet T) (HO h0) + in let uu1 := @idmap (HHomSet T) (HO h1) + in @existT (C2Hom h0 h0) + (fun hh0: (C2Hom h0 h0) => + sigma (hh1 : C2Hom h1 h1), HC2Target hh0 = HC2Source hh1) uu0 + (@existT (C2Hom h1 h1) + (fun hh1: (C2Hom h1 h1) => HC2Target uu0 = HC2Source hh1) uu1 + (@HComp_id_eq T A)). + +(* HCompSet composition, defined in proof mode *) +Program Definition HComp_compP (T: UFunctor.type) (A B C: HCompSet T) + (chA: A ~> B) (chB: B ~> C) : A ~> C. +destruct chA as [hhA0 pA]. +destruct chB as [hhB0 pB]. +destruct pA as [hhA1 ppA]. +destruct pB as [hhB1 ppB]. +set hh0 := comp hhA0 hhB0. +set hh1 := comp hhA1 hhB1. +econstructor 1 with (x:=hh0). +econstructor 1 with (x:=hh1). +set vv := comp (HC2Target hhA0) (HC2Target hhB0). +assert (comp (HC2Source hhA1) (HC2Source hhB1) = vv) as vv_E. +{ rewrite <- ppA. + rewrite <- ppB. + subst vv; auto. +} +assert (HC2Target hh0 = vv) as vv_ET. +{ subst vv. + unfold HC2Target, HTarget. + rewrite Fcomp; auto. +} +assert (HC2Source hh1 = vv) as vv_ES. +{ rewrite <- vv_E. + unfold HC2Source, HSource. + rewrite Fcomp; auto. +} +rewrite vv_ET. +rewrite vv_ES. +reflexivity. +Show Proof. +Defined. + +Program Definition HComp_comp_auxA (T : UFunctor.type) + (A B C : HCompSet T) + (hhA0 : C2Hom (h_first A) (h_first B)) + (hhA1 : C2Hom (h_second A) (h_second B)) + (ppA : HC2Target hhA0 = HC2Source hhA1) + (hhB0 : C2Hom (h_first B) (h_first C)) + (hhB1 : C2Hom (h_second B) (h_second C)) + (ppB : HC2Target hhB0 = HC2Source hhB1) : + comp (HC2Target hhA0) (HC2Target hhB0) = + comp (HC2Source hhA1) (HC2Source hhB1). + rewrite ppA. + rewrite ppB. + reflexivity. +Defined. + +Program Definition HComp_comp_auxS (T : UFunctor.type) + (A B C : HCompSet T) + (hhA0 : C2Hom (h_first A) (h_first B)) + (hhA1 : C2Hom (h_second A) (h_second B)) + (ppA : HC2Target hhA0 = HC2Source hhA1) + (hhB0 : C2Hom (h_first B) (h_first C)) + (hhB1 : C2Hom (h_second B) (h_second C)) + (ppB : HC2Target hhB0 = HC2Source hhB1) : + HC2Source (comp hhA1 hhB1) = comp (HC2Source hhA1) (HC2Source hhB1). + unfold HC2Source, HSource. + repeat rewrite Fcomp. + reflexivity. +Defined. + +Program Definition HComp_comp_auxT (T : UFunctor.type) + (A B C : HCompSet T) + (hhA0 : C2Hom (h_first A) (h_first B)) + (hhA1 : C2Hom (h_second A) (h_second B)) + (ppA : HC2Target hhA0 = HC2Source hhA1) + (hhB0 : C2Hom (h_first B) (h_first C)) + (hhB1 : C2Hom (h_second B) (h_second C)) + (ppB : HC2Target hhB0 = HC2Source hhB1) : + HC2Target (comp hhA0 hhB0) = comp (HC2Target hhA0) (HC2Target hhB0). + unfold HC2Target, HTarget. + repeat rewrite Fcomp. + reflexivity. +Defined. + +Program Definition HComp_comp_auxI (T : UFunctor.type) + (A B C : HCompSet T) + (hhA0 : C2Hom (h_first A) (h_first B)) + (hhA1 : C2Hom (h_second A) (h_second B)) + (ppA : HC2Target hhA0 = HC2Source hhA1) + (hhB0 : C2Hom (h_first B) (h_first C)) + (hhB1 : C2Hom (h_second B) (h_second C)) + (ppB : HC2Target hhB0 = HC2Source hhB1) : + A ~> C. + econstructor 1 with (comp hhA0 hhB0). + econstructor 1 with (comp hhA1 hhB1). + setoid_rewrite HComp_comp_auxS; eauto. + setoid_rewrite HComp_comp_auxT; eauto. + eapply HComp_comp_auxA; eauto. +Defined. + +Program Definition HComp_comp (T: UFunctor.type) (A B C: HCompSet T) + (chA: A ~> B) (chB: B ~> C) : A ~> C. + destruct chA as [hhA0 pA]. + destruct chB as [hhB0 pB]. + destruct pA as [hhA1 ppA]. + destruct pB as [hhB1 ppB]. + eapply HComp_comp_auxI; eauto. +Defined. + +(* HCompSet gives a precategory *) +HB.instance Definition HCompPreCat (T: UFunctor.type) : + Quiver_IsPreCat (HCompSet T) := + Quiver_IsPreCat.Build (HCompSet T) + (@HComp_id T) (@HComp_comp T). + +Lemma LeftUnit_lemma (T : UFunctor.type) : + forall (a b : HCompSet T) (f : a ~> b), idmap \; f = f. + intros. + destruct f. + destruct s. + simpl in *. + unfold idmap; simpl. + unfold HComp_id; simpl. + unfold comp; simpl. + unfold HComp_comp_auxI; simpl. + + assert (idmap \; x = x) as A. + { rewrite comp1o; auto. } + + assert (idmap \; x0 = x0) as A0. + { rewrite comp1o; auto. } + + assert (HC2Target (idmap \; x) = HC2Source (idmap \; x0)) as B. + { rewrite A. + rewrite A0; auto. } + + destruct a eqn: aaa. + destruct b eqn: bbb. + simpl. + + assert (existT + (fun hh0 : C2Hom h_first0 h_first1 => + sigma hh1 : C2Hom h_second0 h_second1,HC2Target hh0 = HC2Source hh1) + (idmap \; x) + (existT + (fun hh1 : C2Hom h_second0 h_second1 => + HC2Target (idmap \; x) = HC2Source hh1) + (idmap \; x0) + B) = + existT + (fun hh0 : C2Hom h_first0 h_first1 => + sigma hh1 : C2Hom h_second0 h_second1,HC2Target hh0 = HC2Source hh1) + x + (existT + (fun hh1 : C2Hom h_second0 h_second1 => HC2Target x = HC2Source hh1) + x0 + e)) as C. + + revert B. + revert A. + revert A0. + generalize (idmap \; x) as v. + generalize (idmap \; x0) as v0. + intros v0 v A0. + rewrite A0. + intro A. + rewrite A. + intro B. + + assert (B = e) as BE. + { eapply Prop_irrelevance. } + + rewrite BE. + reflexivity. + + inversion aaa; subst. + + assert ((Morphisms.trans_sym_co_inv_impl_morphism + (RelationClasses.Equivalence_PER RelationClasses.eq_equivalence) + (HC2Source (idmap \; x0)) (HC2Source idmap \; HC2Source x0) + (HComp_comp_auxS + (HComp_id_eq + {| + h_one := h_one0; + h_two := h_two0; + h_three := h_three0; + h_first := h_first0; + h_second := h_second0 + |}) e) + (Morphisms.trans_co_eq_inv_impl_morphism + RelationClasses.eq_Transitive (HC2Target (idmap \; x)) + (HC2Target idmap \; HC2Target x) + (HComp_comp_auxT + (HComp_id_eq + {| + h_one := h_one0; + h_two := h_two0; + h_three := h_three0; + h_first := h_first0; + h_second := h_second0 + |}) e) (HC2Source idmap \; HC2Source x0) + (HC2Source idmap \; HC2Source x0) + (Morphisms.eq_proper_proxy (HC2Source idmap \; HC2Source x0)) + (HComp_comp_auxA + (HComp_id_eq + {| + h_one := h_one0; + h_two := h_two0; + h_three := h_three0; + h_first := h_first0; + h_second := h_second0 + |}) e))) = B) as BM. + { eapply Prop_irrelevance. } + rewrite BM. + eapply C. +Qed. + +Lemma RightUnit_lemma (T : UFunctor.type) : + forall (a b : HCompSet T) (f : a ~> b), f \; idmap = f. + intros. + destruct f. + destruct s. + simpl in *. + unfold idmap; simpl. + unfold HComp_id; simpl. + unfold comp; simpl. + unfold HComp_comp_auxI; simpl. + + assert (x \; idmap = x) as A. + { rewrite compo1; auto. } + + assert (x0 \; idmap = x0) as A0. + { rewrite compo1; auto. } + + assert (HC2Target (x \; idmap) = HC2Source (x0 \; idmap)) as B. + { rewrite A. + rewrite A0; auto. } + + destruct a eqn: aaa. + destruct b eqn: bbb. + simpl. + + assert (existT + (fun hh0 : C2Hom h_first0 h_first1 => + sigma hh1 : C2Hom h_second0 h_second1,HC2Target hh0 = HC2Source hh1) + (x \; idmap) + (existT + (fun hh1 : C2Hom h_second0 h_second1 => + HC2Target (x \; idmap) = HC2Source hh1) + (x0 \; idmap) + B) = + existT + (fun hh0 : C2Hom h_first0 h_first1 => + sigma hh1 : C2Hom h_second0 h_second1,HC2Target hh0 = HC2Source hh1) + x + (existT + (fun hh1 : C2Hom h_second0 h_second1 => HC2Target x = HC2Source hh1) + x0 + e)) as C. + + revert B. + revert A. + revert A0. + generalize (x \; idmap) as v. + generalize (x0 \; idmap) as v0. + intros v0 v A0. + rewrite A0. + intro A. + rewrite A. + intro B. + + assert (B = e) as BE. + { eapply Prop_irrelevance. } + + rewrite BE. + reflexivity. + + inversion aaa; subst. + + assert ((Morphisms.trans_sym_co_inv_impl_morphism + (RelationClasses.Equivalence_PER RelationClasses.eq_equivalence) + (HC2Source (x0 \; idmap)) (HC2Source x0 \; HC2Source idmap) + (HComp_comp_auxS e + (HComp_id_eq + {| + h_one := h_one1; + h_two := h_two1; + h_three := h_three1; + h_first := h_first1; + h_second := h_second1 + |})) + (Morphisms.trans_co_eq_inv_impl_morphism + RelationClasses.eq_Transitive (HC2Target (x \; idmap)) + (HC2Target x \; HC2Target idmap) + (HComp_comp_auxT e + (HComp_id_eq + {| + h_one := h_one1; + h_two := h_two1; + h_three := h_three1; + h_first := h_first1; + h_second := h_second1 + |})) (HC2Source x0 \; HC2Source idmap) + (HC2Source x0 \; HC2Source idmap) + (Morphisms.eq_proper_proxy (HC2Source x0 \; HC2Source idmap)) + (HComp_comp_auxA e + (HComp_id_eq + {| + h_one := h_one1; + h_two := h_two1; + h_three := h_three1; + h_first := h_first1; + h_second := h_second1 + |})))) = B) as BM. + { eapply Prop_irrelevance. } + rewrite BM. + eapply C. +Qed. + +Lemma Assoc_lemma (T : UFunctor.type) : + forall (a b c d : HCompSet T) (f : a ~> b) (g : b ~> c) (h : c ~> d), + f \; g \; h = (f \; g) \; h. + intros. + remember f as f1. + remember g as g1. + remember h as h1. + destruct f as [x0 s0]. + destruct g as [x1 s1]. + destruct h as [x2 s2]. + destruct s0 as [y0 e0]. + destruct s1 as [y1 e1]. + destruct s2 as [y2 e2]. + simpl. + + set (x01 := comp x0 x1). + set (x12 := comp x1 x2). + set (x0_12 := comp x0 x12). + set (x01_2 := comp x01 x2). + set (y01 := comp y0 y1). + set (y12 := comp y1 y2). + set (y0_12 := comp y0 y12). + set (y01_2 := comp y01 y2). + + assert (x0_12 = x01_2) as X0. + { subst x0_12 x01_2. + rewrite compoA; eauto. } + assert (y0_12 = y01_2) as Y0. + { subst y0_12 y01_2. + rewrite compoA; eauto. } + + set (x01_t := comp (HC2Target x0) (HC2Target x1)). + set (x01_2_t := comp x01_t (HC2Target x2)). + set (x12_t := comp (HC2Target x1) (HC2Target x2)). + set (x0_12_t := comp (HC2Target x0) x12_t). + set (y01_s := comp (HC2Source y0) (HC2Source y1)). + set (y01_2_s := comp y01_s (HC2Source y2)). + set (y12_s := comp (HC2Source y1) (HC2Source y2)). + set (y0_12_s := comp (HC2Source y0) y12_s). + + assert (x01_t = y01_s) as E01. + { subst x01_t y01_s. + rewrite e0. + rewrite e1; auto. } + assert (x01_2_t = y01_2_s) as E01_2. + { subst x01_2_t y01_2_s. + rewrite E01. + rewrite e2; auto. } + assert (x12_t = y12_s) as E12. + { subst x12_t y12_s. + rewrite e1. + rewrite e2; auto. } + assert (x0_12_t = y0_12_s) as E0_12. + { subst x0_12_t y0_12_s. + rewrite E12. + rewrite e0; auto. } + + assert (x0_12_t = x01_2_t) as E02T. + { subst x0_12_t x01_2_t. + subst x12_t x01_t. + rewrite compoA; auto. } + assert (y0_12_s = y01_2_s) as E02S. + { subst y0_12_s y01_2_s. + subst y12_s y01_s. + rewrite compoA; auto. } + + (* + rewrite E02S in E0_12. + rewrite E02T in E0_12. + + assert (E01_2 = E0_12). + *) + + unfold comp. + simpl. + unfold HComp_comp. + simpl. + inversion Heqf1; subst. + clear H. + + unfold HComp_comp_auxI; simpl. + + assert (HC2Target (x0 \; x1 \; x2) = HC2Source (y0 \; y1 \; y2)) as KR. + { subst x0_12_t y0_12_s. + subst x12_t y12_s. + unfold HC2Target. + repeat rewrite Fcomp; simpl. + unfold HC2Target in E0_12. + rewrite E0_12. + unfold HC2Source. + repeat rewrite Fcomp; simpl. + auto. + } + + assert (HC2Target ((x0 \; x1) \; x2) = HC2Source ((y0 \; y1) \; y2)) as KL. + { subst x01_2_t y01_2_s. + subst x01_t y01_s. + unfold HC2Target. + repeat rewrite Fcomp; simpl. + unfold HC2Target in E01_2. + rewrite E01_2. + unfold HC2Source. + repeat rewrite Fcomp; simpl. + auto. + } + + assert (existT + (fun hh0 : C2Hom (h_first a) (h_first d) => + sigma hh1 : C2Hom (h_second a) (h_second d), + HC2Target hh0 = HC2Source hh1) + (x0 \; x1 \; x2) + (existT + (fun hh1 : C2Hom (h_second a) (h_second d) => + HC2Target (x0 \; x1 \; x2) = HC2Source hh1) + (y0 \; y1 \; y2) + KR) + = + existT + (fun hh0 : C2Hom (h_first a) (h_first d) => + sigma hh1 : C2Hom (h_second a) (h_second d), + HC2Target hh0 = HC2Source hh1) + ((x0 \; x1) \; x2) + (existT + (fun hh1 : C2Hom (h_second a) (h_second d) => + HC2Target ((x0 \; x1) \; x2) = HC2Source hh1) + ((y0 \; y1) \; y2) + KL)) as KA. + { revert KL. + revert KR. + subst x0_12 x01_2 x12 x01. + subst y0_12 y01_2 y12 y01. + rewrite <- X0. + rewrite <- Y0. + intros KR KL. + + assert (KR = KL) as I1. + { eapply Prop_irrelevance. } + rewrite I1. + reflexivity. + } + + assert (Morphisms.trans_sym_co_inv_impl_morphism + (RelationClasses.Equivalence_PER RelationClasses.eq_equivalence) + (HC2Source (y0 \; y1 \; y2)) + (HC2Source y0 \; HC2Source (y1 \; y2)) + (HComp_comp_auxS e0 + (Morphisms.trans_sym_co_inv_impl_morphism + (RelationClasses.Equivalence_PER + RelationClasses.eq_equivalence) + (HC2Source (y1 \; y2)) (HC2Source y1 \; HC2Source y2) + (HComp_comp_auxS e1 e2) + (Morphisms.trans_co_eq_inv_impl_morphism + RelationClasses.eq_Transitive (HC2Target (x1 \; x2)) + (HC2Target x1 \; HC2Target x2) + (HComp_comp_auxT e1 e2) (HC2Source y1 \; HC2Source y2) + (HC2Source y1 \; HC2Source y2) + (Morphisms.eq_proper_proxy (HC2Source y1 \; HC2Source y2)) + (HComp_comp_auxA e1 e2)))) + (Morphisms.trans_co_eq_inv_impl_morphism + RelationClasses.eq_Transitive (HC2Target (x0 \; x1 \; x2)) + (HC2Target x0 \; HC2Target (x1 \; x2)) + (HComp_comp_auxT e0 + (Morphisms.trans_sym_co_inv_impl_morphism + (RelationClasses.Equivalence_PER + RelationClasses.eq_equivalence) + (HC2Source (y1 \; y2)) (HC2Source y1 \; HC2Source y2) + (HComp_comp_auxS e1 e2) + (Morphisms.trans_co_eq_inv_impl_morphism + RelationClasses.eq_Transitive + (HC2Target (x1 \; x2)) (HC2Target x1 \; HC2Target x2) + (HComp_comp_auxT e1 e2) (HC2Source y1 \; HC2Source y2) + (HC2Source y1 \; HC2Source y2) + (Morphisms.eq_proper_proxy + (HC2Source y1 \; HC2Source y2)) + (HComp_comp_auxA e1 e2)))) + (HC2Source y0 \; HC2Source (y1 \; y2)) + (HC2Source y0 \; HC2Source (y1 \; y2)) + (Morphisms.eq_proper_proxy + (HC2Source y0 \; HC2Source (y1 \; y2))) + (HComp_comp_auxA e0 + (Morphisms.trans_sym_co_inv_impl_morphism + (RelationClasses.Equivalence_PER + RelationClasses.eq_equivalence) + (HC2Source (y1 \; y2)) (HC2Source y1 \; HC2Source y2) + (HComp_comp_auxS e1 e2) + (Morphisms.trans_co_eq_inv_impl_morphism + RelationClasses.eq_Transitive + (HC2Target (x1 \; x2)) (HC2Target x1 \; HC2Target x2) + (HComp_comp_auxT e1 e2) (HC2Source y1 \; HC2Source y2) + (HC2Source y1 \; HC2Source y2) + (Morphisms.eq_proper_proxy + (HC2Source y1 \; HC2Source y2)) + (HComp_comp_auxA e1 e2))))) = KR) as HR. + { eapply Prop_irrelevance. } + + rewrite HR. + + assert (Morphisms.trans_sym_co_inv_impl_morphism + (RelationClasses.Equivalence_PER RelationClasses.eq_equivalence) + (HC2Source ((y0 \; y1) \; y2)) + (HC2Source (y0 \; y1) \; HC2Source y2) + (HComp_comp_auxS + (Morphisms.trans_sym_co_inv_impl_morphism + (RelationClasses.Equivalence_PER + RelationClasses.eq_equivalence) + (HC2Source (y0 \; y1)) (HC2Source y0 \; HC2Source y1) + (HComp_comp_auxS e0 e1) + (Morphisms.trans_co_eq_inv_impl_morphism + RelationClasses.eq_Transitive (HC2Target (x0 \; x1)) + (HC2Target x0 \; HC2Target x1) + (HComp_comp_auxT e0 e1) (HC2Source y0 \; HC2Source y1) + (HC2Source y0 \; HC2Source y1) + (Morphisms.eq_proper_proxy (HC2Source y0 \; HC2Source y1)) + (HComp_comp_auxA e0 e1))) e2) + (Morphisms.trans_co_eq_inv_impl_morphism + RelationClasses.eq_Transitive (HC2Target ((x0 \; x1) \; x2)) + (HC2Target (x0 \; x1) \; HC2Target x2) + (HComp_comp_auxT + (Morphisms.trans_sym_co_inv_impl_morphism + (RelationClasses.Equivalence_PER + RelationClasses.eq_equivalence) + (HC2Source (y0 \; y1)) (HC2Source y0 \; HC2Source y1) + (HComp_comp_auxS e0 e1) + (Morphisms.trans_co_eq_inv_impl_morphism + RelationClasses.eq_Transitive + (HC2Target (x0 \; x1)) (HC2Target x0 \; HC2Target x1) + (HComp_comp_auxT e0 e1) (HC2Source y0 \; HC2Source y1) + (HC2Source y0 \; HC2Source y1) + (Morphisms.eq_proper_proxy + (HC2Source y0 \; HC2Source y1)) + (HComp_comp_auxA e0 e1))) e2) + (HC2Source (y0 \; y1) \; HC2Source y2) + (HC2Source (y0 \; y1) \; HC2Source y2) + (Morphisms.eq_proper_proxy + (HC2Source (y0 \; y1) \; HC2Source y2)) + (HComp_comp_auxA + (Morphisms.trans_sym_co_inv_impl_morphism + (RelationClasses.Equivalence_PER + RelationClasses.eq_equivalence) + (HC2Source (y0 \; y1)) (HC2Source y0 \; HC2Source y1) + (HComp_comp_auxS e0 e1) + (Morphisms.trans_co_eq_inv_impl_morphism + RelationClasses.eq_Transitive + (HC2Target (x0 \; x1)) (HC2Target x0 \; HC2Target x1) + (HComp_comp_auxT e0 e1) (HC2Source y0 \; HC2Source y1) + (HC2Source y0 \; HC2Source y1) + (Morphisms.eq_proper_proxy + (HC2Source y0 \; HC2Source y1)) + (HComp_comp_auxA e0 e1))) e2)) = KL) as HL. + { eapply Prop_irrelevance. } + + rewrite HL. + + eapply KA. +Qed. + +Program Definition HCompCatP (T: UFunctor.type) : PreCat_IsCat (HCompSet T). +econstructor. +eapply LeftUnit_lemma; eauto. +eapply RightUnit_lemma; eauto. +eapply Assoc_lemma; eauto. +Qed. + +(* TODO: to be replaced by a proof *) +(* Global Parameter GCompAx : forall (T: UFunctor.type), + PreCat_IsCat (HCompSet T). +*) + +HB.instance Definition HCompCat (T: UFunctor.type) := HCompCatP T. + +(* composition prefunctor *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsCPreFunctor T of UFunctor T := + { is_cprefunctor : IsPreFunctor (HCompSet T) (HHomSet T) (@HComp T) }. +HB.structure Definition CPreFunctor : Set := {C of IsCPreFunctor C}. +Set Universe Checking. + +(* composition functor *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record CPreFunctor_IsFunctor T of CPreFunctor T := { + is_cfunctor : PreFunctor_IsFunctor (HCompSet T) (HHomSet T) (@HComp T) }. +HB.structure Definition CFunctor : Set := {C of CPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* horizontal 2-cell composition: maps two adjecent pairs of + horizontal morphisms (a and b) and a pullback-category morphism + between them (m, which basically gives two adjecent cells) to a + 2-cell morphism between the horizontal composition (HComp) of each + pair *) +Definition HC2Comp (T: CFunctor.type) (a b: HCompSet T) + (m: @hom (HCompSet T) a b) : + c2hom (HComp a) (HComp b) := @Fhom _ _ (@HComp T) a b m. + +Program Definition HC2Comp_flat (T: CFunctor.type) (a0 a1 a2 b0 b1 b2: T) + (h0: hhom a0 a1) (h1: hhom a1 a2) + (k0: hhom b0 b1) (k1: hhom b1 b2) + (hh0: C2Hom h0 k0) + (hh1: C2Hom h1 k1) + (k: HC2Target hh0 = HC2Source hh1) + : (* C2Hom (hcomp _ _ _ h0 h1) (hcomp _ _ _ k0 k1) *) + c2hom (l_hcomp h0 h1) (l_hcomp k0 k1) := + @Fhom _ _ (@HComp T) (GC h0 h1) (GC k0 k1) _. +Obligation 1. +refine (@existT (C2Hom h0 k0) _ hh0 (@existT (C2Hom h1 k1) _ hh1 k)). +Defined. + +(**************************************************************************) + + +(* hunit - horizontal unit functor. + + hcomp - horizontal composition functor. + + Both specified as object-level functions, to be lifted by + functoriality to morphism-level ones. + + At the object level, hunit gives a horizontal identity morphism + for each D0 object. At the morphism level, it gives horizontal + 2-cell identity for each vertical morphism. + + In the case of hcomp, relying on functoriality requires some care + in defining the pullback category, making sure that adjacency at + the object-level (between horizontal morphisms) is matched by + adjacency at the morphism-level (between 2-cells). *) +HB.mixin Record IsHDQuiver T of DQuiver T := { + hunit : forall a: T, @hhom T a a ; + hcomp : forall (a b c: T), @hhom T a b -> @hhom T b c -> @hhom T a c; +}. +Unset Universe Checking. +#[short(type="hdquiver")] +HB.structure Definition HDQuiver : Set := { C of IsHDQuiver C }. +Set Universe Checking. + +Definition hhunit (T: hdquiver) (a: T) : HHomSet T := + @HO T (@hhom T) a a (hunit a). + +(* horizontal composition of two horizontal morphisms from a + cell product *) +Definition hhcomp (T: hdquiver) (x: HCompSet T) : HHomSet T := + match x with + @GC _ _ a b c h1 h2 => @HO T (@hhom T) a c (hcomp a b c h1 h2) end. + +(* horizontal unit functor: D0 -> D1 *) +HB.tag Definition HUnit (C: hdquiver) := + fun (x: HDQuiver.sort C) => @hhunit C x. +(* horizontal composition functor: D1 * D1 -> D1 *) +HB.tag Definition HComp (C: hdquiver) := + fun (x: HCompSet C) => @hhcomp C x. + + + +(* 2-cell (D1) morphisms *) +Definition c2hom (D: HDQuiver.type) : HHomSet D -> HHomSet D -> U := + @hom (HHomSet D). + +Definition C2Hom (D: HDQuiver.type) (a b c d: D) (h0: hhom a b) + (h1: hhom c d) : U := c2hom (HO h0) (HO h1). + +(* The set of D1 morphisms *) +HB.tag Definition C2HomSet (C: HDQuiver.type) := Total2 (@c2hom C). + +(* horizontal 2-cell unit (maps vertical morphisms to horizontally + unitary 2-cells) *) +Definition HC2Unit (T: UFunctor.type) (a b: T) (m: @hom T a b) : + c2hom (HUnit a) (HUnit b) := @Fhom _ _ (@HUnit T) a b m. + +(* 2-cell source *) +Definition HC2Source (T: UFunctor.type) (a b: @HHomSet T) + (m: @c2hom T a b) : + @hom T (HSource a) (HSource b) := @Fhom _ _ (@HSource T) a b m. + +(* 2-cell target *) +Definition HC2Target (T: UFunctor.type) (a b: @HHomSet T) + (m: @c2hom T a b) : + @hom T (HTarget a) (HTarget b) := @Fhom _ _ (@HTarget T) a b m. + +(* horizontal composition of two (naked) horizontal morphisms *) +Definition l_hcomp (T: UFunctor.type) (a0 a1 a2: T) + (h0: hhom a0 a1) (h1: hhom a1 a2) : HHomSet T := + @HO T _ a0 a2 (hcomp a0 a1 a2 h0 h1). + + +(** HCompSet T is the pseudo-pullback category used to deal with + products of D1 (where the adjacency condition is expressed + w.r.t. D0 *) + +Notation "'sigma' x .. y , p" := (sigT (fun x => .. (sigT (fun y => p)) ..)) + (at level 200, x binder, right associativity, + format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") + : type_scope. + +(** HCompSet quiver *) +Definition HComp_hom (T: UFunctor.type) (x y: HCompSet T) := + sigma (hh0: C2Hom (h_first x) (h_first y)) + (hh1: C2Hom (h_second x) (h_second y)), + HC2Target hh0 = HC2Source hh1. + +HB.instance Definition HCompQuiver (T: UFunctor.type) : + IsQuiver (HCompSet T) := + IsQuiver.Build (HCompSet T) (fun A B => @HComp_hom T A B). + +(* HCompSet identity, defined in proof mode *) +Program Definition HComp_id_P (T: UFunctor.type) (A: HCompSet T) : A ~> A. +unfold hom; simpl. +unfold HComp_hom, C2Hom; simpl. +destruct A; simpl. +set h0' := HO h_first0. +set h1' := HO h_second0. +repeat econstructor. +instantiate (1:= @idmap (HHomSet T) h1'). +instantiate (1:= @idmap (HHomSet T) h0'). +assert (HC2Target (@idmap (HHomSet T) h0') = @idmap _ h_two0) as T0. +{ unfold HC2Target, HTarget. + rewrite F1; auto. +} +assert (HC2Source (@idmap (HHomSet T) h1') = @idmap _ h_two0) as S1. +{ unfold HC2Source, HSource. + rewrite F1; auto. +} +rewrite T0. +rewrite S1. +reflexivity. +Defined. + +(* HCompSet identity, only partially in proof mode *) +Program Definition HComp_id (T: UFunctor.type) (A: HCompSet T) : A ~> A := + let h0 := h_first A + in let h1 := h_second A + in let uu0 := @idmap (HHomSet T) (HO h0) + in let uu1 := @idmap (HHomSet T) (HO h1) + in @existT (C2Hom h0 h0) + (fun hh0: (C2Hom h0 h0) => + sigma (hh1 : C2Hom h1 h1), HC2Target hh0 = HC2Source hh1) uu0 + (@existT (C2Hom h1 h1) + (fun hh1: (C2Hom h1 h1) => HC2Target uu0 = HC2Source hh1) uu1 _). +Obligation 1. +unfold HC2Target, HTarget. +unfold HC2Source, HSource. +repeat rewrite F1; auto. +Defined. + +(* HCompSet composition, defined in proof mode *) +Program Definition HComp_comp (T: UFunctor.type) (A B C: HCompSet T) + (chA: A ~> B) (chB: B ~> C) : A ~> C. +destruct chA as [hhA0 pA]. +destruct chB as [hhB0 pB]. +destruct pA as [hhA1 ppA]. +destruct pB as [hhB1 ppB]. +set hh0 := comp hhA0 hhB0. +set hh1 := comp hhA1 hhB1. +econstructor 1 with (x:=hh0). +econstructor 1 with (x:=hh1). +set vv := comp (HC2Target hhA0) (HC2Target hhB0). +assert (comp (HC2Source hhA1) (HC2Source hhB1) = vv) as vv_E. +{ rewrite <- ppA. + rewrite <- ppB. + subst vv; auto. +} +assert (HC2Target hh0 = vv) as vv_ET. +{ subst vv. + unfold HC2Target, HTarget. + rewrite Fcomp; auto. +} +assert (HC2Source hh1 = vv) as vv_ES. +{ rewrite <- vv_E. + unfold HC2Source, HSource. + rewrite Fcomp; auto. +} +rewrite vv_ET. +rewrite vv_ES. +reflexivity. +Defined. + +(* HCompSet gives a precategory *) +HB.instance Definition HCompPreCat (T: UFunctor.type) : + Quiver_IsPreCat (HCompSet T) := + Quiver_IsPreCat.Build (HCompSet T) + (@HComp_id T) (@HComp_comp T). + +(* TODO: to be replaced by a proof *) +Global Parameter GCompAx : forall (T: UFunctor.type), + PreCat_IsCat (HCompSet T). + +HB.instance Definition HCompCat (T: UFunctor.type) := GCompAx T. + +(* composition prefunctor *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsCPreFunctor T of UFunctor T := + { is_cprefunctor : IsPreFunctor (HCompSet T) (HHomSet T) (@HComp T) }. +HB.structure Definition CPreFunctor : Set := {C of IsCPreFunctor C}. +Set Universe Checking. + +(* composition functor *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record CPreFunctor_IsFunctor T of CPreFunctor T := { + is_cfunctor : PreFunctor_IsFunctor (HCompSet T) (HHomSet T) (@HComp T) }. +HB.structure Definition CFunctor : Set := {C of CPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* horizontal 2-cell composition: maps two adjecent pairs of + horizontal morphisms (a and b) and a pullback-category morphism + between them (m, which basically gives two adjecent cells) to a + 2-cell morphism between the horizontal composition (HComp) of each + pair *) +Definition HC2Comp (T: CFunctor.type) (a b: HCompSet T) + (m: @hom (HCompSet T) a b) : + c2hom (HComp a) (HComp b) := @Fhom _ _ (@HComp T) a b m. + + +(* Double category with strong horizontal unit (Russ' paper). + hunit defines proper identity on horizontal morphisms *) +HB.mixin Record IsDCat_SU T of CFunctor T := { + left_unital : forall (a0 a1: T) (h : hhom a0 a1), + @hcomp T a0 a0 a1 (hunit a0) h = h ; + + right_unital : forall (a0 a1: T) (h : hhom a0 a1), + @hcomp T a0 a1 a1 h (hunit a1) = h ; +}. +Unset Universe Checking. +#[short(type="dcat_su")] +HB.structure Definition DCat_SU : Set := { C of IsDCat_SU C }. +Set Universe Checking. + +(* Double category with weak horizontal unit (display paper) *) +HB.mixin Record IsDCat_WU T of CFunctor T := { + left_unital : forall (a0 a1: T) (h : hhom a0 a1), + let hh := HO h + in let uh := HO (hcomp a0 a0 a1 (hunit a0) h) + in exists uhc : c2hom uh hh, + HC2Source uhc = @idmap T a0 /\ + HC2Target uhc = @idmap T a1 ; + + right_unital : forall (a0 a1: T) (h : hhom a0 a1), + let hh := HO h + in let uh := HO (hcomp a0 a1 a1 h (hunit a1)) + in exists uhc : c2hom uh hh, + HC2Source uhc = @idmap T a0 /\ + HC2Target uhc = @idmap T a1 +}. +Unset Universe Checking. +#[short(type="dcat_wu")] +HB.structure Definition DCat_WU : Set := { C of IsDCat_WU C }. +Set Universe Checking. + +(* Double category with universal characterization of half-strong + horizontal unit *) +HB.mixin Record IsDCat_HU T of CFunctor T := { + left_unital : forall (a0 a1 b0 b1: T) + (r: @hhom T a0 a1) (s: @hhom T b0 b1), + let rr := @HO T (@hhom T) a0 a1 r in + let ss := @HO T (@hhom T) b0 b1 s in + let aa := @hunit T a0 in + let bb := @hunit T b0 in + @hom (HHomSet T) rr ss = + @hom (HHomSet T) (hhcomp (@GC T _ a0 a0 a1 aa r)) + (hhcomp (@GC T _ b0 b0 b1 bb s)) ; + + right_unital : forall (a0 a1 b0 b1: T) + (r: @hhom T a0 a1) (s: @hhom T b0 b1), + let rr := @HO T (@hhom T) a0 a1 r in + let ss := @HO T (@hhom T) b0 b1 s in + let aa := @hunit T a1 in + let bb := @hunit T b1 in + @hom (HHomSet T) rr ss = + @hom (HHomSet T) (hhcomp (@GC T _ a0 a1 a1 r aa)) + (hhcomp (@GC T _ b0 b1 b1 s bb)) ; +}. +Unset Universe Checking. +#[short(type="dcat_hu")] +HB.structure Definition DCat_HU : Set := { C of IsDCat_HU C }. +Set Universe Checking. + +(* Double category with weak horizontal associativity (display paper) *) +HB.mixin Record IsDCat_WA T of CFunctor T := { + associator : forall (a0 a1 a2 a3: T) + (h1: @hhom T a0 a1) (h2: @hhom T a1 a2) + (h3: @hhom T a2 a3) (x: HHomSet T), + let h12 := hcomp a0 a1 a2 h1 h2 in + let h23 := hcomp a1 a2 a3 h2 h3 in + let hh1 := HO (hcomp a0 a1 a3 h1 h23) in + let hh2 := HO (hcomp a0 a2 a3 h12 h3) in + exists asc: + c2hom hh1 hh2, HC2Source asc = @idmap T a0 /\ + HC2Target asc = @idmap T a3 +}. +Unset Universe Checking. +#[short(type="dcat_wa")] +HB.structure Definition DCat_WA : Set := { C of IsDCat_WA C }. +Set Universe Checking. +(* + a0 -- h0 --> a1 -- h1 --> a2 + | | | | | + v0 hh0 v1 hh1 v2 + | | | | | + V V V V V + b0 -- k0 --> b1 -- k1 --> b2 +*) + +(* Double category with universal characterization of weak + horizontal associativity *) +HB.mixin Record IsDCat_UA T of CFunctor T := { + associator : forall (a0 a1 a2 a3: T) + (h1: @hhom T a0 a1) (h2: @hhom T a1 a2) + (h3: @hhom T a2 a3) (x: HHomSet T), + let h23 := hcomp a1 a2 a3 h2 h3 in + let h12 := hcomp a0 a1 a2 h1 h2 in + let hh1 := hcomp a0 a1 a3 h1 h23 in + let hh2 := hcomp a0 a2 a3 h12 h3 in + @hom (HHomSet T) (@HO T (@hhom T) a0 a3 hh1) x = + @hom (HHomSet T) (@HO T (@hhom T) a0 a3 hh2) x +}. +Unset Universe Checking. +#[short(type="dcat_ua")] +HB.structure Definition DCat_UA : Set := { C of IsDCat_UA C }. +Set Universe Checking. + +(* double category, closer to the display paper *) +Unset Universe Checking. +#[short(type="dcat_dp")] +HB.structure Definition DCat_DP : Set := { C of DCat_WU C & DCat_WA C }. +Set Universe Checking. + +(* double category, closer to (my understanding of) Russ' paper *) +Unset Universe Checking. +#[short(type="dcat_rp")] +HB.structure Definition DCat_RP : Set := { C of DCat_SU C & DCat_UA C }. +Set Universe Checking. + + +(*********************************************************************) + +Program Definition HC2Comp_flat (T: CFunctor.type) (a0 a1 a2 b0 b1 b2: T) + (h0: hhom a0 a1) (h1: hhom a1 a2) + (k0: hhom b0 b1) (k1: hhom b1 b2) + (hh0: C2Hom h0 k0) + (hh1: C2Hom h1 k1) + (k: HC2Target hh0 = HC2Source hh1) + : (* C2Hom (hcomp _ _ _ h0 h1) (hcomp _ _ _ k0 k1) *) + c2hom (l_hcomp h0 h1) (l_hcomp k0 k1) := + @Fhom _ _ (@HComp T) (GC h0 h1) (GC k0 k1) _. +Obligation 1. +refine (@existT (C2Hom h0 k0) _ hh0 (@existT (C2Hom h1 k1) _ hh1 k)). +Defined. + +(* not working yet *) +HB.mixin Record IsDCat_U2 T of CFunctor T := { + left_unital : forall (a0 a1 b0 b1: T) (m: @hom T a0 b0) + (h : hhom a0 a1) (k : hhom b0 b1) + (hh: c2hom (HO h) (HO k)), + forall (xx: c2hom (HUnit a0) (HUnit b0)), + xx = HC2Unit m -> + HC2Source hh = m -> + @HC2Comp_flat T a0 a0 a1 b0 b0 b1 (hunit a0) h (hunit b0) k xx hh = + @HC2Comp_flat T a0 a0 a1 b0 b0 b1 (hunit a0) h (hunit b0) k xx hh +}. + + +(*********************************************************************) +(**** GARBAGE ****************************************************) + +(* A quiver from which horizontal morphisms arise (just a copy of quiver) *) +HB.mixin Record IsHQuiver C := { + hhom : C -> C -> U + }. +Unset Universe Checking. +#[short(type="hquiver")] +HB.structure Definition HQuiver : Set := { C of IsHQuiver C }. +Set Universe Checking. + +(* domain-specific sigma-type to represent the set of morphims + (needed for 2-objects, i.e. horizontal morphisms) *) +Record Total2 T (h: T -> T -> U) : Type := HO { + source : T; + target : T; + this_morph : h source target }. + +(* the set of horizontal morphisms. + HB.tag needed to identify HHomSet as lifter *) +HB.tag Definition HHomSet (C: hquiver) := Total2 (@hhom C). + +(* source functor (for horizontal morphisms): D1 -> D0. + defined as object-level function, by functoriality lifted to a + (2-cell, vertical) morphism-level one *) +HB.tag Definition HSource C := fun (X: HHomSet C) => @source C (@hhom C) X. +(* target functor (for horizontal morphisms): D1 -> D0. *) +HB.tag Definition HTarget C := fun (X: HHomSet C) => @target C (@hhom C) X. + +(* D1 quiver requirement. *) +#[wrapper] +HB.mixin Record IsD1Quiver T of HQuiver T := { + d1_quiver : IsQuiver (@HHomSet T) }. +Unset Universe Checking. +#[short(type="d1quiver")] +HB.structure Definition D1Quiver : Set := { C of IsD1Quiver C }. +Set Universe Checking. + +(* all the quivers required by a double category *) +Unset Universe Checking. +#[short(type="dquiver")] +HB.structure Definition DQuiver : Set := + { C of Quiver C & HQuiver C & IsD1Quiver C }. +Set Universe Checking. + +(* used to define composable pairs of morphisms as a set *) +Record GenComp T (h: T -> T -> U) := GC { + c_one : T; + c_two : T ; + c_three : T; + c_first : h c_one c_two ; + c_second : h c_two c_three +}. + +(* composable pairs of horizontal morphisms as a set *) +HB.tag Definition HComp (C: hquiver) := GenComp (@hhom C). + +(* +(* pullback category condition (i.e. (HComp T) is a category). + requires T to be a category, and (HHomSet T) to be a quiver *) +#[wrapper] +HB.mixin Record IsHCompCat T of Cat T & DQuiver T := { + hcompcat : Cat (HComp T) }. +Unset Universe Checking. +#[short(type="hcompcat")] +HB.structure Definition HCompCat : Set := { C of IsHCompCat C }. +Set Universe Checking. +*) + +(* c2unit - horizontal unit functor. + + c2comp - horizontal composition functor. + + Both specified as object-level functions, to be lifted by + functoriality to morphism-level ones. + + At the object level, c2unit gives a horizontal identity morphism + for each D0 object. At the morphism level, it gives horizontal + 2-cell identity for each vertical morphism. + + In the case of HComp, relying on functoriality requires some care + in defining the pullback category, making sure that adjacency at + the object-level (between horizontal morphisms) is matched by + adjacency at the morphism-level (between 2-cells). *) +HB.mixin Record IsC2Quiver T of DQuiver T (* & HCompCat T *) := { + h2unit : forall a: T, @hhom T a a ; + h2comp : forall (a b c: T), + @hhom T a b -> @hhom T b c -> @hhom T a c; + + c2unit : T -> HHomSet T ; + c2comp : HComp T -> HHomSet T ; + + c2unit_eq : forall a: T, c2unit a = @HO T (@hhom T) a a (h2unit a) ; + c2comp_eq1 : forall (a b c: T) (h1: @hhom T a b) (h2: @hhom T b c), + c2comp (@GC T (@hhom T) a b c h1 h2) = + @HO T (@hhom T) a c (h2comp a b c h1 h2) +}. +Unset Universe Checking. +#[short(type="c2quiver")] +HB.structure Definition C2Quiver : Set := { C of IsC2Quiver C }. +Set Universe Checking. + +(************************************************************************************) + +(* Double category *) +Unset Universe Checking. +HB.mixin Record IsDCat T of HCFunctor T := { + left_unital : forall (a b: T) (r: @hhom T a b), + let rr := @HO T (@hhom T) a b r in + let aa := @h2unit T a in + @hom (HHomSet T) (c2comp (@GC T _ a a b aa r)) rr ; + + right_unital : forall (a b: T) (r: @hhom T a b), + let rr := @HO T (@hhom T) a b r in + let bb := @h2unit T b in + @hom (HHomSet T) (c2comp (@GC T _ a b b r bb)) rr ; +}. + +(* Double category *) +Unset Universe Checking. +HB.mixin Record IsDCat T of HCFunctor T := { + left_unital : forall (a b c d: T) (r: @hhom T a c) (s: @hhom T b d), + forall (ha: @hhom T a a) (hb: @hhom T b b), + @hom (HHomSet T) (@HO T (@hhom T) a c r) (@HO T (@hhom T) b d s) = + @hom (HHomSet T) (c2comp (@GC T _ a a c ha r)) + (c2comp (@GC T _ b b d hb s)) ; + + right_unital : forall (a b c d: T) (r: @hhom T a c) (s: @hhom T b d), + forall (ha: @hhom T c c) (hb: @hhom T d d), + @hom (HHomSet T) (@HO T (@hhom T) a c r) (@HO T (@hhom T) b d s) = + @hom (HHomSet T) (c2comp (@GC T _ a c c r ha)) + (c2comp (@GC T _ b d d s hb)) ; + + associator : forall (a0 a1 a2 a3: T) + (h1: @hhom T a0 a1) (h2: @hhom T a1 a2) + (h3: @hhom T a2 a3), + forall (h12: @hhom T a0 a2) (h23: @hhom T a1 a3) (x: HHomSet T), + @HO T (@hhom T) a1 a3 h23 = c2comp (@GC T _ a1 a2 a3 h2 h3) -> + @HO T (@hhom T) a0 a2 h12 = c2comp (@GC T _ a0 a1 a2 h1 h2) -> + let hh1 := c2comp (@GC T _ a0 a1 a3 h1 h23) in + let hh2 := c2comp (@GC T _ a0 a2 a3 h12 h3) in + @hom (HHomSet T) hh1 x = @hom (HHomSet T) hh2 x +}. +#[short(type="dcat")] +HB.structure Definition DCat : Set := { C of IsDCat C }. +Set Universe Checking. + + +(* a sequence of two adjacent morphisms (pullback object), + which we can use to represent composition *) +Record GenComp' T (h: T -> T -> U) := GCmp { + comp_first : @Total2 T h ; + comp_second : @Total2 T h ; + comp_adjacent : target comp_first = source comp_second +}. +(* horizontal morphism composition type. ultimately though, SHOULD + DEPEND ON D0 (hence on 'Quiver T' and 'Quiver (T * T)) *) +Definition HComp' (C: hquiver) := GenComp' (@hhom C). + + +(* source prefunctor. + HHomSet T is the quiver of the 2-morphisms, thanks to H2Quiver. + T is the quiver of 1-morphisms. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHSPreFunctor T of Cat T & H2Cat T := { + h2s_prefunctor : IsPreFunctor (HHomSet T) T (@Source T) }. +HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. +Set Universe Checking. + +(* target prefunctor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHTPreFunctor T of Cat T & H2Cat T := { + h2t_prefunctor : IsPreFunctor (HHomSet T) T (@Target T) }. +HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. +Set Universe Checking. + + + +HB.mixin Record IsC2Quiver T of Quiver T & PreC2Quiver T := { + c2left : C2HomSet T -> VHomSet T ; + c2right : C2HomSet T -> VHomSet T ; + + c2unit : forall x:T, HHomSet T ; + + c2left_eq1 : forall d: C2HomSet T, + source (source d) = source (c2left d) ; + c2left_eq2 : forall d: C2HomSet T, + source (target d) = target (c2left d) ; + c2right_eq1 : forall d: C2HomSet T, + target (source d) = source (c2right d) ; + c2right_eq2 : forall d: C2HomSet T, + target (target d) = target (c2right d) ; + + c2unit_eq : forall a: T, + let h := c2unit a in source h = target h ; + +}. +Unset Universe Checking. +#[short(type="c2quiver")] +HB.structure Definition C2Quiver : Set := { C of IsC2Quiver C }. +Set Universe Checking. + +(* left edge functor: D1 -> D0 *) +HB.tag Definition C2Left (C: C2Quiver.type) := + fun (X: C2HomSet C) => @c2left C X. +(* right edge functor: D1 -> D0 *) +HB.tag Definition C2Right (C: C2Quiver.type) := + fun (X: C2HomSet C) => @c2right C X. + + + +(* we need horizontal morphisms to form at least a precategory *) +HB.mixin Record HQuiver_IsHPreCat C of HQuiver C := { + hidmap : forall (a : C), hhom a a; + hcomp : forall d : D1_prod C, + hhom (source (d1_first d)) (target (d1_second d)); +}. +Unset Universe Checking. +#[short(type="hprecat")] +HB.structure Definition HPreCat : Set := { C of HQuiver_IsHPreCat C }. +Set Universe Checking. + + +HB.mixin Record IsH2Grid T of Quiver T & H2Quiver T := { + h2left_edge : H2HomSet T -> VHomSet T ; + h2right_edge : H2HomSet T -> VHomSet T +}. +Unset Universe Checking. +#[short(type="h2grid")] +HB.structure Definition H2Grid : Set := { C of IsH2Grid C }. +Set Universe Checking. + +(* adding the map to define (1) the unit functor D0 -> D1 + and (2) composition D1 *d0 D1 -> D1 *) +HB.mixin Record IsH2FQuiver T of H2Quiver T & H2Grid T & PreCat T := { + h2unit_map: forall x:T, HHomSet T ; + h2unit_map_eq: forall x:T, h2unit_map x = + @HO T (@hhom T) x x (hidmap x) ; + h2comp_map: D1_prod T -> HHomSet T ; + h2comp_map_eq: forall d: D1_prod T, h2comp_map d = + @HO T (@hhom T) (source (d1_first d)) (target (d1_second d)) (hcomp d) +}. +Unset Universe Checking. +#[short(type="h2fquiver")] +HB.structure Definition H2FQuiver : Set := { C of IsH2FQuiver C }. +Set Universe Checking. + +(* Precat based on the H2Quiver (D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsH2PreCat T of H2FQuiver T := { + h2precat : Quiver_IsPreCat (@HHomSet T) }. +#[short(type="h2precat")] +HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. +Set Universe Checking. + +(* The category based on the H2Quiver (D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsH2Cat T of H2PreCat T := { + h2cat : PreCat_IsCat (@HHomSet T) }. +#[short(type="h2cat")] +HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. +Set Universe Checking. + +(* +Unset Universe Checking. +#[short(type="predcat")] +HB.structure Definition PreDCat : Set := { D of H2Cat D & H2Grid D }. +Set Universe Checking. +*) + +Record D2_prod T := { + d2_first : @H2HomSet T ; + d2_second : @H2HomSet T ; + d2_adjacent : target d2_first = source d2_second +}. + +(* probably not needed *) +HB.mixin Record HQuiver_IsH2PreCat' C of H2Grid C := { + h2idmap : forall (a : C), hhom a a; + h2comp : forall d : D2_prod C, + h2hom (source (d2_first d)) (target (d2_second d)); +}. +Unset Universe Checking. +#[short(type="hprecat")] +HB.structure Definition H2PreCat' : Set := { C of HQuiver_IsH2PreCat' C }. +Set Universe Checking. + + + +(* +(* gives left and right edges of a 2-cell (i.e. the vertical + morphisms associated with the 2-morphism). + these should be functors + *) +HB.mixin Record IsH2Grid T of Quiver T & H2Quiver T := { + h2left_edge : forall a b c d: T, + forall (h1: hhom a b) (h2: hhom c d), + @hom (@HHomSet T) (@HO T (@hhom T) a b h1) + (@HO T (@hhom T) c d h2) -> @hom T a c ; + h2right_edge : forall a b c d: T, + forall (h1: hhom a b) (h2: hhom c d), + @hom (@HHomSet T) (@HO T (@hhom T) a b h1) + (@HO T (@hhom T) c d h2) -> @hom T b d +}. +Unset Universe Checking. +#[short(type="h2grid")] +HB.structure Definition H2Grid : Set := { C of IsH2Grid C }. +Set Universe Checking. + +(* +(* adding the map to define (1) the unit functor D0 -> D1 + and (2) composition D1 *d0 D1 -> D1 *) +HB.mixin Record IsH2FQuiver T of H2Quiver T := { + h2unit_map: forall x:T, HHomSet T ; + h2unit_map_eq: forall x:T, h2unit_map x = + @HO T (@hhom T) x x (hidmap x) ; + h2comp_map: HHomSet T * HHomSet T -> HHomSet T ; + h2comp_map_eq: forall (a b c: T) (h1: hhom a b) (h2: hhom b c), + let x := @HO T (@hhom T) a b h1 + in let y := @HO T (@hhom T) b c h2 + in let z := @HO T (@hhom T) a c (hcomp a b c h1 h2) + in h2comp_map (x, y) = z }. +Unset Universe Checking. +#[short(type="h2fquiver")] +HB.structure Definition H2FQuiver : Set := { C of IsH2FQuiver C }. +Set Universe Checking. +*) +(* +(* adding the map to define the unit functor D0 -> D1 *) +HB.mixin Record IsH2FQuiver T of H2Quiver T := { + h2unit_map: forall x:T, HHomSet T ; + h2unit_map_eq: forall x:T, let y := h2unit_map x in + source y = target y ; + h2comp_map: HHomSet T * HHomSet T -> HHomSet T ; + h2comp_map_eq: forall x y: HHomSet T, target x = source y -> + exists f: hhom (source x) (target y), + h2comp_map (x, y) = @HO T (@hhom T) (source x) (target y) f ; +(* square_comp : forall (a1 b1 c1 a2 b2 c2: T), + forall (ha1: hhom a1 b1) (hb1: hhom b1 c1) + (ha2: hhom a2 b2) (hb2: hhom b2 c2), *) + }. +Unset Universe Checking. +#[short(type="h2fquiver")] +HB.structure Definition H2FQuiver : Set := { C of IsH2FQuiver C }. +Set Universe Checking. +*) + +(* Precat based on the H2Quiver (D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsH2PreCat T of H2FQuiver T := { + h2precat : Quiver_IsPreCat (@HHomSet T) }. +#[short(type="h2precat")] +HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. +Set Universe Checking. + +(* The category based on the H2Quiver (D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsH2Cat T of H2PreCat T := { + h2cat : PreCat_IsCat (@HHomSet T) }. +#[short(type="h2cat")] +HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. +Set Universe Checking. + +(* Pre-double category, with horizontal 2-cell composition *) +Unset Universe Checking. +HB.mixin Record IsPreDCat T of Cat T & H2Cat T & H2Grid T := { + h2adjacent : forall (a b c d e f: T), + forall (h1: hhom a b) (h2: hhom b c) (h3: hhom d e) (h4: hhom e f), + forall (hh1: @hom (@HHomSet T) (@HO T (@hhom T) a b h1) + (@HO T (@hhom T) d e h3)) + (hh2: @hom (@HHomSet T) (@HO T (@hhom T) b c h2) + (@HO T (@hhom T) e f h4)), + h2right_edge a b d e h1 h3 hh1 = + h2left_edge b c e f h2 h4 hh2 ; + + h2comp : forall (h1 h2 h3 h4: HHomSet T), + forall (hh1: h1 ~> h2) (hh2: h3 ~> h4), + h2comp_map (h1,h3) ~> h2comp_map (h2,h4) ; + +(* + h2comp_eq : forall (a b c d e f: T), + forall (h1: hhom a b) (h2: hhom b c) (h3: hhom d e) (h4: hhom e f), + forall (hh1: @hom (@HHomSet T) (@HO T (@hhom T) a b h1) + (@HO T (@hhom T) d e h3)) + (hh2: @hom (@HHomSet T) (@HO T (@hhom T) b c h2) + (@HO T (@hhom T) e f h4)), + h2adjacent a b c d e f h1 h2 hh1 hh2 -> + let h1' := (@HO T (@hhom T) a b h1) + in let h2' := (@HO T (@hhom T) b c h2) + in let h3' := (@HO T (@hhom T) d e h3) + in let h4' := (@HO T (@hhom T) e f h4) + h2comp h1' h2' h3' h4' hh1 hh2 = +*) + }. +#[short(type="predcat")] +HB.structure Definition PreDCat : Set := { D of IsPreDCat D }. +Set Universe Checking. + + +*) + +(* source functor: D1 -> D0 *) +HB.tag Definition Source C := fun (X: HHomSet C) => @source C (@hhom C) X. +(* target functor: D1 -> D0 *) +HB.tag Definition Target C := fun (X: HHomSet C) => @target C (@hhom C) X. +(* unit functor: D0 -> D1 *) +HB.tag Definition UnitF (C: h2fquiver) := + fun (x:H2FQuiver.sort C) => @h2unit_map C x. + +(* source prefunctor. + HHomSet T is the quiver of the 2-morphisms, thanks to H2Quiver. + T is the quiver of 1-morphisms. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHSPreFunctor T of Cat T & H2Cat T := { + h2s_prefunctor : IsPreFunctor (HHomSet T) T (@Source T) }. +HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. +Set Universe Checking. + +(* target prefunctor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHTPreFunctor T of Cat T & H2Cat T := { + h2t_prefunctor : IsPreFunctor (HHomSet T) T (@Target T) }. +HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. +Set Universe Checking. + + + +HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. +Set Universe Checking. + +(* source functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record HSPreFunctor_IsFunctor T of Cat T & HSPreFunctor T := { + h2s_functor : PreFunctor_IsFunctor (HHomSet T) T (@Source T) }. +HB.structure Definition HSFunctor : Set := {C of HSPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* target functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record HTPreFunctor_IsFunctor T of Cat T & HTPreFunctor T := { + h2t_functor : PreFunctor_IsFunctor (HHomSet T) T (@Target T) }. +HB.structure Definition HTFunctor : Set := {C of HTPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* unit prefunctor. *) +Unset Universe Checking. + #[wrapper] +HB.mixin Record IsHUPreFunctor T of Cat T & PreDCat T := { + h2u_prefunctor : IsPreFunctor T (HHomSet T) (@UnitF T) }. +HB.structure Definition HUPreFunctor : Set := {C of IsHUPreFunctor C}. +Set Universe Checking. + + +Unset Universe Checking. + #[wrapper] +HB.mixin Record HUPreFunctor_IsFunctor T of Cat T & HUPreFunctor T := { + h2u_functor : PreFunctor_IsFunctor T (HHomSet T) (@UnitF T) }. + HB.structure Definition HUFunctor : Set := {T of + Cat T & HUPreFunctor T & + PreFunctor_IsFunctor T (HHomSet T) (@UnitF T) + }. +Set Universe Checking. + + +Unset Universe Checking. + #[wrapper] +HB.mixin Record HUPreFunctor_IsFunctor T of Cat T & HUPreFunctor T := { + h2u_functor : PreFunctor_IsFunctor T (HHomSet T) (@UnitF T) }. +HB.structure Definition HUFunctor : Set := {C of HUPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* double category *) +Unset Universe Checking. +HB.structure Definition DCat : Set := + {D of HSPreFunctor_IsFunctor D & HTPreFunctor_IsFunctor D & + HUPreFunctor_IsFunctor D}. +Set Universe Checking. + +(* 2-morphisms *) +Definition h2hom (D: DCat.type) := @hom (@HHomSet D). + +(* still don't understand + transposition whould swap vertical and horizontal morphisms, + i.e. hom and hhom *) +Definition transpose1 (D: DCat.type) : U := D. +(* however, given transpose1 this should hold *) +Lemma hom_transpose (D: DCat.type) : @hom (transpose1 D) = @hhom D. +Admitted. +(* and this too *) +Lemma hhom_transpose (D: DCat.type) : @hhom (transpose1 D) = @hom D. +Admitted. + +(* tranposition as a relation *) +Definition isTranspose C + (FQ: PreDCat C -> Quiver C) + (FHQ: PreDCat C -> HQuiver C) + (D1 D2: PreDCat C) : Type := + @hom (Quiver.Pack (FQ D2)) = @hhom (HQuiver.Pack (FHQ D1)) /\ + @hhom (HQuiver.Pack (FHQ D2)) = @hom (Quiver.Pack (FQ D1)). + +Definition transpose_isquiver C (X: IsQuiver C) : IsHQuiver C. + destruct X. + econstructor. + exact hom0. +Defined. + +Definition transpose_ishquiver C (X: IsHQuiver C) : IsQuiver C. + destruct X. + econstructor. + exact hhom0. +Defined. + +Definition transpose_quiver C (X: Quiver C) : HQuiver C. + destruct X. + econstructor. + eapply transpose_isquiver; eauto. +Defined. + +Definition transpose_hquiver C (X: HQuiver C) : Quiver C. + destruct X. + econstructor. + eapply transpose_ishquiver; eauto. +Defined. + +(* tranposition as a relation, using the transpose functions *) +Definition isTransposeF C + (FQ: PreDCat C -> Quiver C) + (FHQ: PreDCat C -> HQuiver C) + (D1 D2: PreDCat C) : Type := + Quiver.Pack (FQ D2) = Quiver.Pack (@transpose_hquiver C (FHQ D1)) /\ + HQuiver.Pack (FHQ D2) = HQuiver.Pack (@transpose_quiver C (FQ D1)). + + + +(*** DOUBLE CATEGORIES (PREVIOUS) *) + +(* A quiver from which horizontal morphisms arise. D1 is the type of + D1 objects (horizontal morphisms in C), with source and target + functors. *) +HB.mixin Record HasD1 C := { + D1 : U ; + s10 : D1 -> C ; + t10 : D1 -> C }. +Unset Universe Checking. +#[short(type="hquiver")] +HB.structure Definition D1type : Set := { C of HasD1 C }. +Set Universe Checking. + +(* A quiver from which 2-morphisms arise as arrows between 2-objects + (i.e. horizontal morphisms) *) +#[wrapper] +HB.mixin Record IsH2Quiver T of HasD1 T := { + h2quiver : IsQuiver (@D1 T) }. +Unset Universe Checking. +#[short(type="h2quiver")] +HB.structure Definition H2Quiver : Set := { C of IsH2Quiver C }. +Set Universe Checking. + +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsH2PreCat T of H2Quiver T := { + h2precat : Quiver_IsPreCat (@D1 T) }. +#[short(type="h2precat")] +HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. +Set Universe Checking. + +(* The category based on the H2Quiver (D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsH2Cat T of H2PreCat T := { + h2cat : PreCat_IsCat (@D1 T) }. +#[short(type="h2cat")] +#[verbose] +HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. +Set Universe Checking. + +(* Pre-double category (no functors yet): this corresponds to the old +definition *) +Unset Universe Checking. +HB.structure Definition PreDCat : Set := { D of Cat D & H2Cat D }. +Set Universe Checking. + +(* source prefunctor. + D1 here is the quiver of the 2-morphisms, thanks to IsH2Quiver. + T is the quiver of 1-morphisms. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHSPreFunctor T of Cat T & H2Cat T := { + h2s_prefunctor : IsPreFunctor D1 T s10 }. +HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. +Set Universe Checking. + +(* target prefunctor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHTPreFunctor T of Cat T & H2Cat T := { + h2t_prefunctor : IsPreFunctor D1 T t10 }. +HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. +Set Universe Checking. + +(* source functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record HSPreFunctor_IsFunctor T of Cat T & HSPreFunctor T := { + h2s_prefunctor : PreFunctor_IsFunctor D1 T s10 }. +HB.structure Definition HSFunctor : Set := {C of HSPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* target functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record HTPreFunctor_IsFunctor T of Cat T & HTPreFunctor T := { + h2t_prefunctor : PreFunctor_IsFunctor D1 T t10 }. +HB.structure Definition HTFunctor : Set := {C of HTPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* double category *) +Unset Universe Checking. +HB.structure Definition DCat : Set := + {D of HSPreFunctor_IsFunctor D & HTPreFunctor_IsFunctor D }. +Set Universe Checking. + +(* 2-morphisms *) +Definition hhom (D: DCat.type) := @hom (@D1 D). + +Definition transpose (D: DCat.type) : U := D. + +Fail Lemma hom_transpose (D: DCat.type) : @hom (transpose D) = @hhom D. + +Fail Lemma hhom_transpose (D: DCat.type) : @hhom (transpose D) = @hom D. + + + +(*** DOUBLE CATEGORIES (OLD) *) + +(* A quiver from which horizontal morphisms arise (just a copy of quiver) *) +HB.mixin Record IsHQuiver C := { hhom : C -> C -> U }. +Unset Universe Checking. +#[short(type="hquiver")] +HB.structure Definition HQuiver : Set := { C of IsHQuiver C }. +Set Universe Checking. + +(* domain-specific sigma-type to represent the 2-objects *) +Record Total2 T (h: T -> T -> U) : Type := HO { + source : T; + target : T; + this_hom : h source target }. + +(* needed to identify HHomSet as lifter *) +HB.tag Definition HHomSet (C: hquiver) := Total2 (@hhom C). + +(* A quiver from which 2-morphisms arise as arrows between 2-objects + (i.e. horizontal morphisms) *) +#[wrapper] +HB.mixin Record IsH2Quiver T of HQuiver T := { + h2quiver : Quiver (@HHomSet T) }. +Unset Universe Checking. +#[short(type="h2quiver")] +HB.structure Definition H2Quiver : Set := { C of IsH2Quiver C }. +Set Universe Checking. + +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsH2PreCat T of HQuiver T & H2Quiver T := { + h2precat : Quiver_IsPreCat (@HHomSet T) }. +#[short(type="h2precat")] +HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. +Set Universe Checking. + +(* The category based on the H2Quiver (D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsH2Cat T of H2PreCat T := { + h2cat : PreCat_IsCat (@HHomSet T) }. +#[short(type="h2cat")] +HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. +Set Universe Checking. + +(* Double categories, from + https://ncatlab.org/nlab/show/double+category + + The definition we follow here however is a comparatively informal + one, which also mentions internal categories (not formalized yet). + + Double category (D0, D1). + + base obejcts (D0): C ; + + vertical morphisms (D0): @hom C ; + + horizontal morhisms (and 2-objects, D1): @HHomSet C ; + + 2-morphisms (D1): @hom (@HHomSet C) *) +Unset Universe Checking. +#[short(type="dcat")] +HB.structure Definition DCat : Set := { C of Cat C & H2Cat C }. +Set Universe Checking. + + + +(*******************************************************************) + +(*** Related to BICATEGORIES (just an experiment, + not the right formalization) *) + +(* We want to factor constants and operators out of the axioms. + Suggestion: introduce some notion of module to bind them + together. *) + +(* monoid axioms *) +HB.mixin Record isMonoid T (mu: T) (mc: T -> T -> T): Type := { + massoc : associative mc; + mlid : left_id mu mc ; + mrid : right_id mu mc ; +}. + +(* to be used as homset identity in bicategories *) +HB.mixin Record isHId T := { + hid : T; +}. +HB.structure Definition HId := { T of isHId T }. + +(* to be used as homset composition in bicategories *) +HB.mixin Record isHComp T := { + hcomp : T -> T -> T; +}. +HB.structure Definition HComp := { T of isHComp T }. + +#[wrapper] +HB.mixin Record Quiver_HasId T of Quiver T := + { Quiver_HasId_private : forall A B, isHId (@hom T A B) }. +HB.structure Definition HasId := + { Obj of Quiver Obj & Quiver_HasId Obj }. + +#[wrapper] +HB.mixin Record Quiver_HasComp T of Quiver T := + { Quiver_HasComp_private : forall A B, isHComp (@hom T A B) }. +HB.structure Definition HasComp := + { Obj of Quiver Obj & Quiver_HasComp Obj }. + +(* a bicategory, without axioms *) +HB.structure Definition BiCatQuiver := + {T of Quiver_HasId T & Quiver_HasComp T}. + +#[wrapper] +HB.mixin Record isHMonoid T of HId T & HComp T := + { isHMonoid_private: isMonoid T (hid: T) (@hcomp T) }. +#[verbose] +HB.structure Definition HMonoid := { T of isHMonoid T }. + +#[wrapper] +(* does not work (generic Elpi error): + HB.mixin Record isHCat T of precat_quiver T := *) +HB.mixin Record isPreBiCategory T of IsPreCat T := + { isPreBiCategory_private : forall A B: T, HMonoid (@hom T A B) }. +HB.structure Definition PreBiCategory := + { Obj of isPreBiCategory Obj }. + +(* to be used as object monoid unit *) +HB.mixin Record isMUnit T := { + munit : T; +}. +HB.structure Definition MUnit := { T of isMUnit T }. + +(* to be used as object monoid composition *) +HB.mixin Record isMComp T := { + mcomp : T -> T -> T; +}. +HB.structure Definition MComp := { T of isMComp T }. + +(* has object monoid operators *) +HB.structure Definition Premonoid := + {T of isMUnit T & isMComp T}. + +(* the precategory has monoidal operators *) +HB.structure Definition Precat_IsPremonoidal := + {T of PreCat T & Premonoid T}. + +(* object monoid *) +HB.mixin Record isOMonoid T of isMUnit T & isMComp T := + { isHMonoid_private: isMonoid T (munit: T) (mcomp: T -> T -> T) }. +#[verbose] +HB.structure Definition OMonoid := { T of isOMonoid T }. + +(* some sort of monoidal category *) +HB.structure Definition PreMonBiCategory := + { Obj of PreBiCategory Obj & OMonoid Obj }. + + +(*******************************************************************) + +Section th_of_pb. +Variables (Q : cat) (A B C D E F : Q). +Variables (f : A ~> D) (g : B ~> D) (h : C ~> A). +Variables (u : E ~> A) (v : E ~> B) (w : F ~> C) (z : F ~> E). +Variable (uvfg : pbsquare u v f g). + +Set Printing Width 50. +Theorem pbsquarec_compP : + pbsquare w z h u <=> pbsquare w (z \; v) (h \; f) g. +Proof. +split=> [] sq. + + have @sq_ispb : pullback (Cospan h u) := HB.pack (Span w z) sq. + have @uvfg_ispb : pullback (Cospan f g) := HB.pack (Span u v) uvfg. + have /=E2 := @is_square _ _ _ _ sq_ispb. + have /=E1 := @is_square _ _ _ _ uvfg_ispb. + + have p1 : @isPrePullback Q C B (Cospan (h \; f) g) (Span w (z \; v)). + by constructor; rewrite /= compoA E2 -compoA E1 compoA. + pose big_black_square : prepullback (Cospan (h \; f) g) := + HB.pack (Span w (z \; v)) p1. + + have @from : forall + (big_red_square : prepullback {| top := D; left2top := h \; f; right2top := g |}), + big_red_square ~> pb_terminal big_black_square. + + move=> big_red_square; unfold pb_terminal. + + have /= := @is_square _ _ _ _ big_red_square. + + pose F' := bot big_red_square. + set w' : F' ~> C := bot2left big_red_square. + set z' : F' ~> B := bot2right big_red_square. + move=> E3. + + have xxx : isPrePullback Q A B (Cospan f g) (Span (w' \; h) z'). + by constructor=> /=; rewrite -compoA E3. + pose red_black_square : prepullback (Cospan f g) := + HB.pack (Span (w' \; h) z') xxx. + have := @from_unique _ (pb_terminal uvfg_ispb) red_black_square. + set blue := @from _ (pb_terminal uvfg_ispb) red_black_square. + move=> blue_unique. + + have p3 : @isPrePullback Q C E (Cospan h u) (Span w' (bot_map blue)). + by constructor; rewrite /= (bot2left_map blue). (* buggy unifier without blue *) + pose blue_red_black_square : prepullback (Cospan h u) := + HB.pack (Span w' (bot_map blue)) p3. + + pose red := @from _ (pb_terminal sq_ispb) blue_red_black_square. + + admit. + + + + have p2 : prepullback_isTerminal.axioms_ Q C B (Cospan (h \; f) g) (Span w (z \; v)) p1. + constructor. econstructor=> /=. + admit. + + by HB.from p1 p2. + +Admitted. + +End th_of_pb. + + +Module test. + +Section test. +Variables (Q : precat) (A B : Q) (c : cospan A B). +Variable (p : pullback c). +Check pb_terminal p : terminal _. + +End test. +End test. + + + + From c26463b6775b9f1b329a911fa8a074a947462cb6 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Wed, 15 Nov 2023 17:16:01 +0100 Subject: [PATCH 090/147] encatB.v: cleaned up the definition of strict double category; the definition is complete, it does not use internal categories but defines an ad-hoc product category on D1. TODO: improve the style of the proofs --- theories/encatB.v | 1560 +++++++-------------------------------------- 1 file changed, 213 insertions(+), 1347 deletions(-) diff --git a/theories/encatB.v b/theories/encatB.v index a07dccc5f..c19fa9078 100644 --- a/theories/encatB.v +++ b/theories/encatB.v @@ -14,8 +14,6 @@ Declare Scope cat_scope. Delimit Scope cat_scope with cat. Local Open Scope cat_scope. -Require Import Eqdep. - (* we assume a few axioms to make life easier *) Axiom funext : forall {T : Type} {U : T -> Type} [f g : forall t, U t], (forall t, f t = g t) -> f = g. @@ -1013,7 +1011,8 @@ Notation pbsquare u v f g := Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). -(******************************************************************) +(********************************************************************) +(********************************************************************) (*** ENRICHED CATEGORIES *) @@ -1088,12 +1087,47 @@ HB.mixin Record IsEnCat (V: Monoidal.type) C of EnPreCat V C := { }. Unset Universe Checking. #[verbose] -HB.structure Definition EnCat (V: Monoidal.type) : Set := { C of IsEnCat V C }. +HB.structure Definition EnCat (V: Monoidal.type) : Set := + { C of IsEnCat V C }. Set Universe Checking. +(********************************************************************) + +(*** DOUBLE CATEGORIES (without internal categories) *) + +(* Strict double categories, from + https://ncatlab.org/nlab/show/double+category + (we don't use internal categories though) + + base obejcts (D0): C ; + + vertical morphisms (for V-D0): @hom C ; + + horizontal morphisms (for H-D0) : @hom (transpose C) ; + + horizontal morhisms as 2-objects (for D1): @HHomSet C ; + + 2-morphisms (for D1): @hom (@HHomSet C) + + The definition of Strict Double Category (D0, D1) is given by: + + - vertical base category (V-D0) + + - horizontal base category (H-D0) + + - vertical 2-level category (D1) + + - source functor : D1 -> V-D0 + - target functor : D1 -> V-D0 -(*** DOUBLE CATEGORIES (REVISED) *) + - horizontal unit functor : V-D0 -> D1 + + - horizontal composition functor : D1 *0 D1 -> D1 +*) + + +(** Quivers for double categories *) (* transpose for horizontal morphism quiver. HB.tag needed to identify transpose as lifter *) @@ -1119,14 +1153,7 @@ Record Total2 T (h: T -> T -> U) : Type := HO { (* the set of horizontal morphisms. *) HB.tag Definition HHomSet (C: cquiver) := Total2 (@hhom C). -(* source functor (for horizontal morphisms): D1 -> D0. - defined as object-level function, by functoriality lifted to a - (2-cell, vertical) morphism-level one *) -HB.tag Definition HSource C := fun (X: HHomSet C) => @source C (@hhom C) X. -(* target functor (for horizontal morphisms): D1 -> D0. *) -HB.tag Definition HTarget C := fun (X: HHomSet C) => @target C (@hhom C) X. - -(* D1 quiver requirement. *) +(* D1 quiver requirement (includes D0 quiver and its transpose). *) #[wrapper] HB.mixin Record IsDQuiver T of CQuiver T := { is_dquiver : Quiver (HHomSet T) }. Unset Universe Checking. @@ -1134,11 +1161,14 @@ Unset Universe Checking. HB.structure Definition DQuiver : Set := { C of IsDQuiver C }. Set Universe Checking. + +(** Horizonal D0-level category (H-D0) *) + (* Precategory based on the HQuiver (i.e. horizontal precategory on D0 objects) *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsHPreCat T of DQuiver T := { +HB.mixin Record IsHPreCat T of CQuiver T := { is_hprecat : Quiver_IsPreCat (transpose T) }. #[short(type="hprecat")] HB.structure Definition HPreCat : Set := { C of IsHPreCat C }. @@ -1154,80 +1184,128 @@ HB.mixin Record IsHCat T of HPreCat T := { HB.structure Definition HCat : Set := { C of IsHCat C }. Set Universe Checking. -(* used to define composable pairs of morphisms as a set *) + +(** Horizontal 2-cell level category (D1 category) *) + +(* Precategory based on the DQuiver (i.e. precategory D1). Gives: + vertical 2-cell identity morphism. + vertical 2-cell composition. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsC2PreCat T of DQuiver T := { + is_c2precat : Quiver_IsPreCat (@HHomSet T) }. +#[short(type="c2precat")] +HB.structure Definition C2PreCat : Set := { C of IsC2PreCat C }. +Set Universe Checking. + +(* The category based on the DQuiver (i.e. category D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsC2Cat T of C2PreCat T := { + is_c2cat : PreCat_IsCat (@HHomSet T) }. +#[short(type="c2cat")] +HB.structure Definition C2Cat : Set := { C of IsC2Cat C }. +Set Universe Checking. + + +(** Naked double category *) + +(* Naked double category. Vertical (V-D0) and D1 categories. Double + category without horizontal operators and functors *) +Unset Universe Checking. +#[short(type="vdcat")] + HB.structure Definition VDCat : Set := + { C of Cat C & C2Cat C }. +Set Universe Checking. + +(* Naked strict double category. Vertical (V-D0), horizontal (H-D0) + and D1 categories. Strict double category without functors *) +Unset Universe Checking. +#[short(type="nd2cat")] +HB.structure Definition NDCat : Set := { C of Cat C & HCat C & C2Cat C }. +Set Universe Checking. + + +(** Auxiliary notions for Source, Target and + Horizontal Unit functors *) + +(* homsets of 2-cell (D1) morphisms *) +Definition c2hom (D: DQuiver.type) : HHomSet D -> HHomSet D -> U := + @hom (HHomSet D). +(* type-level smart constructor for D1 homsets *) +Definition C2Hom (D: DQuiver.type) (a b c d: D) (h0: hhom a b) + (h1: hhom c d) : U := c2hom (HO h0) (HO h1). + +(* smart projections for: + source functor (for horizontal morphisms): D1 -> D0. + defined as object-level function, by functoriality lifted to a + (2-cell, vertical) morphism-level one *) +HB.tag Definition HSource C := fun (X: HHomSet C) => @source C (@hhom C) X. +(* target functor (for horizontal morphisms): D1 -> D0. *) +HB.tag Definition HTarget C := fun (X: HHomSet C) => @target C (@hhom C) X. + +(* horizontal unit functor: D0 -> D1 *) +Definition hhunit (T: hprecat) (a: T) : HHomSet T := + @HO T (@hhom T) a a (@idmap (transpose T) a). +HB.tag Definition HUnit (C: hprecat) := + fun (x: HPreCat.sort C) => @hhunit C x. + + +(** Auxiliary notions for 2-cell Horizontal Composition functor *) + +(* composable pairs of morphisms as a set *) Record GenComp T (h: T -> T -> U) := GC { h_one : T; h_two : T ; h_three : T; h_first : h h_one h_two ; - h_second : h h_two h_three -}. + h_second : h h_two h_three }. (* composable pairs of horizontal morphisms as a set *) HB.tag Definition HCompSet (C: cquiver) := GenComp (@hhom C). +(* smart projections *) Definition H2First (C: cquiver) (X: @HCompSet C) : HHomSet C := @HO C _ (h_one X) (h_two X) (h_first X). Definition H2Second (C: cquiver) (X: @HCompSet C) : HHomSet C := @HO C _ (h_two X) (h_three X) (h_second X). -(* hhunit - horizontal unit functor. - - hhcomp - horizontal composition functor (horizontal composition of - two horizontal morphisms from a cell product). - - Both specified as object-level functions, to be lifted by - functoriality to morphism-level ones. - - At the object level, hunit gives a horizontal identity morphism for - each D0 object. At the morphism level, it gives horizontal 2-cell - identity for each vertical morphism. - - In the case of hcomp, relying on functoriality requires some care - in defining the pullback category, making sure that adjacency at - the object-level (between horizontal morphisms) is matched by - adjacency at the morphism-level (between 2-cells). *) -Definition hhunit (T: hprecat) (a: T) : HHomSet T := - @HO T (@hhom T) a a (@idmap (transpose T) a). +(* horizontal composition functor: D1 * D1 -> D1 *) Definition hhcomp (T: hprecat) (x: HCompSet T) : HHomSet T := match x with @GC _ _ a b c h1 h2 => @HO T (@hhom T) a c (@comp (transpose T) a b c h1 h2) end. - -(* horizontal unit functor: D0 -> D1 *) -HB.tag Definition HUnit (C: hprecat) := - fun (x: HPreCat.sort C) => @hhunit C x. -(* horizontal composition functor: D1 * D1 -> D1 *) HB.tag Definition HComp (C: hprecat) := fun (x: HCompSet C) => @hhcomp C x. -(* Precategory based on the DQuiver (i.e. precategory D1). Gives: - vertical 2-cell identity morphism. - vertical 2-cell composition. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsC2PreCat T of DQuiver T := { - is_c2precat : Quiver_IsPreCat (@HHomSet T) }. -#[short(type="c2precat")] -HB.structure Definition C2PreCat : Set := { C of IsC2PreCat C }. -Set Universe Checking. +(* hhunit - horizontal unit functor. + + hhcomp - horizontal composition functor (horizontal composition of + two horizontal morphisms from a cell product). + + Both specified as object-level functions (they actually come for + free from the H-D0 category, since we are in the strict case), to + be lifted by functoriality to morphism-level ones. + + At the object level, hhunit gives a horizontal identity morphism + for each D0 object. At the morphism level, it gives horizontal + 2-cell identity for each vertical morphism. + + In the case of hhcomp, relying on functoriality requires some care + in defining the product category, making sure that adjacency at the + object-level (between horizontal morphisms) is matched by adjacency + at the morphism-level (between 2-cells). *) -(* The category based on the DQuiver (i.e. category D1). *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsC2Cat T of C2PreCat T := { - is_c2cat : PreCat_IsCat (@HHomSet T) }. -#[short(type="c2cat")] -HB.structure Definition C2Cat : Set := { C of IsC2Cat C }. -Set Universe Checking. + +(** Source and target functors *) (* source prefunctor. - HHomSet T is the quiver of the 2-morphisms, thanks to DQuiver. + HHomSet T is the quiver of the 2-morphisms, thanks to CQuiver. T is the quiver of 1-morphisms. *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsSPreFunctor T of Cat T & C2Cat T := { +HB.mixin Record IsSPreFunctor T of VDCat T := { is_sprefunctor : IsPreFunctor (HHomSet T) T (@HSource T) }. HB.structure Definition SPreFunctor : Set := {C of IsSPreFunctor C}. Set Universe Checking. @@ -1235,7 +1313,7 @@ Set Universe Checking. (* target prefunctor. *) Unset Universe Checking. #[wrapper] - HB.mixin Record IsTPreFunctor T of SPreFunctor T := { + HB.mixin Record IsTPreFunctor T of VDCat T := { is_tprefunctor : IsPreFunctor (HHomSet T) T (@HTarget T) }. HB.structure Definition TPreFunctor : Set := {C of IsTPreFunctor C}. Set Universe Checking. @@ -1243,7 +1321,7 @@ Set Universe Checking. (* source functor. *) Unset Universe Checking. #[wrapper] -HB.mixin Record SPreFunctor_IsFunctor T of TPreFunctor T := { + HB.mixin Record SPreFunctor_IsFunctor T of SPreFunctor T := { is_sfunctor : PreFunctor_IsFunctor (HHomSet T) T (@HSource T) }. HB.structure Definition SFunctor : Set := {C of SPreFunctor_IsFunctor C}. Set Universe Checking. @@ -1251,15 +1329,18 @@ Set Universe Checking. (* target functor. *) Unset Universe Checking. #[wrapper] -HB.mixin Record TPreFunctor_IsFunctor T of SFunctor T := { +HB.mixin Record TPreFunctor_IsFunctor T of TPreFunctor T := { is_tfunctor : PreFunctor_IsFunctor (HHomSet T) T (@HTarget T) }. HB.structure Definition TFunctor : Set := {C of TPreFunctor_IsFunctor C}. Set Universe Checking. + +(** Unit functor *) + (* unit prefunctor. *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsUPreFunctor T of HCat T & TFunctor T := +HB.mixin Record IsUPreFunctor T of NDCat T := { is_uprefunctor : IsPreFunctor T (HHomSet T) (@HUnit T) }. HB.structure Definition UPreFunctor : Set := {C of IsUPreFunctor C}. Set Universe Checking. @@ -1272,80 +1353,60 @@ HB.mixin Record UPreFunctor_IsFunctor T of UPreFunctor T := { HB.structure Definition UFunctor : Set := {C of UPreFunctor_IsFunctor C}. Set Universe Checking. -(* 2-cell (D1) morphisms *) -Definition c2hom (D: DQuiver.type) : HHomSet D -> HHomSet D -> U := - @hom (HHomSet D). - -Definition C2Hom (D: DQuiver.type) (a b c d: D) (h0: hhom a b) - (h1: hhom c d) : U := c2hom (HO h0) (HO h1). +Unset Universe Checking. +HB.structure Definition STUFunctor : Set := + {C of SFunctor C & TFunctor C & UFunctor C}. +Set Universe Checking. -(* The set of D1 morphisms *) -HB.tag Definition C2HomSet (C: DQuiver.type) := Total2 (@c2hom C). -(* horizontal 2-cell unit (maps vertical morphisms to horizontally - unitary 2-cells) *) -Definition HC2Unit (T: UFunctor.type) (a b: T) (m: @hom T a b) : - c2hom (HUnit a) (HUnit b) := @Fhom _ _ (@HUnit T) a b m. +(** Lifting of Source, Target and Unit functors to D1 morphisms *) (* 2-cell source *) -Definition HC2Source (T: UFunctor.type) (a b: @HHomSet T) +Definition HC2Source (T: SFunctor.type) (a b: @HHomSet T) (m: @c2hom T a b) : @hom T (HSource a) (HSource b) := @Fhom _ _ (@HSource T) a b m. (* 2-cell target *) -Definition HC2Target (T: UFunctor.type) (a b: @HHomSet T) +Definition HC2Target (T: TFunctor.type) (a b: @HHomSet T) (m: @c2hom T a b) : @hom T (HTarget a) (HTarget b) := @Fhom _ _ (@HTarget T) a b m. -(* horizontal composition of two (naked) horizontal morphisms *) -Definition l_hcomp (T: UFunctor.type) (a0 a1 a2: T) - (h0: hhom a0 a1) (h1: hhom a1 a2) : HHomSet T := - @HO T _ a0 a2 (@comp (transpose T) a0 a1 a2 h0 h1). +(* horizontal 2-cell unit (maps vertical morphisms to horizontally + unitary 2-cells) *) +Definition HC2Unit (T: UFunctor.type) (a b: T) (m: @hom T a b) : + c2hom (HUnit a) (HUnit b) := @Fhom _ _ (@HUnit T) a b m. -(** HCompSet T is the pseudo-pullback category used to deal with +(** Horizontal product category (D1 *d0 D1) *) +(* HCompSet T is the pseudo-pullback category used to deal with products of D1 (where the adjacency condition is expressed w.r.t. D0 *) -Notation "'sigma' x .. y , p" := (sigT (fun x => .. (sigT (fun y => p)) ..)) +(* horizontal composition of two (naked) horizontal morphisms *) +Definition l_hcomp (T: NDCat.type) (a0 a1 a2: T) + (h0: hhom a0 a1) (h1: hhom a1 a2) : HHomSet T := + @HO T _ a0 a2 (@comp (transpose T) a0 a1 a2 h0 h1). + +Notation "'sigma' x .. y , p" := + (sigT (fun x => .. (sigT (fun y => p)) ..)) (at level 200, x binder, right associativity, format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") : type_scope. (** HCompSet quiver *) -Definition HComp_hom (T: UFunctor.type) (x y: HCompSet T) := +Definition HComp_hom (T: STUFunctor.type) (x y: HCompSet T) := sigma (hh0: C2Hom (h_first x) (h_first y)) (hh1: C2Hom (h_second x) (h_second y)), HC2Target hh0 = HC2Source hh1. -HB.instance Definition HCompQuiver (T: UFunctor.type) : +HB.instance Definition HCompQuiver (T: STUFunctor.type) : IsQuiver (HCompSet T) := IsQuiver.Build (HCompSet T) (fun A B => @HComp_hom T A B). -(* HCompSet identity, defined in proof mode *) -Program Definition HComp_id_P (T: UFunctor.type) (A: HCompSet T) : A ~> A. -unfold hom; simpl. -unfold HComp_hom, C2Hom; simpl. -destruct A; simpl. -set h0' := HO h_first0. -set h1' := HO h_second0. -repeat econstructor. -instantiate (1:= @idmap (HHomSet T) h1'). -instantiate (1:= @idmap (HHomSet T) h0'). -assert (HC2Target (@idmap (HHomSet T) h0') = @idmap _ h_two0) as T0. -{ unfold HC2Target, HTarget. - rewrite F1; auto. -} -assert (HC2Source (@idmap (HHomSet T) h1') = @idmap _ h_two0) as S1. -{ unfold HC2Source, HSource. - rewrite F1; auto. -} -rewrite T0. -rewrite S1. -reflexivity. -Defined. -Lemma HComp_id_eq (T : UFunctor.type) (a: HCompSet T) : +(** Product precategory *) + +Lemma HComp_id_eq (T : STUFunctor.type) (a: HCompSet T) : HC2Target (@idmap (@HHomSet T) (H2First a)) = HC2Source (@idmap (@HHomSet T) (H2Second a)). unfold HC2Target, HTarget. @@ -1353,22 +1414,8 @@ unfold HC2Source, HSource. repeat rewrite F1; auto. Defined. -(* HCompSet identity, only partially in proof mode *) -Program Definition HComp_id' (T: UFunctor.type) (A: HCompSet T) : A ~> A := - let h0 := h_first A - in let h1 := h_second A - in let uu0 := @idmap (HHomSet T) (HO h0) - in let uu1 := @idmap (HHomSet T) (HO h1) - in @existT (C2Hom h0 h0) - (fun hh0: (C2Hom h0 h0) => - sigma (hh1 : C2Hom h1 h1), HC2Target hh0 = HC2Source hh1) uu0 - (@existT (C2Hom h1 h1) - (fun hh1: (C2Hom h1 h1) => HC2Target uu0 = HC2Source hh1) uu1 _). -Obligation 1. -eapply HComp_id_eq; eauto. -Defined. - -Definition HComp_id (T: UFunctor.type) (A: HCompSet T) : A ~> A := +(* HCompSet identity *) +Definition HComp_id (T: STUFunctor.type) (A: HCompSet T) : A ~> A := let h0 := h_first A in let h1 := h_second A in let uu0 := @idmap (HHomSet T) (HO h0) @@ -1380,40 +1427,7 @@ Definition HComp_id (T: UFunctor.type) (A: HCompSet T) : A ~> A := (fun hh1: (C2Hom h1 h1) => HC2Target uu0 = HC2Source hh1) uu1 (@HComp_id_eq T A)). -(* HCompSet composition, defined in proof mode *) -Program Definition HComp_compP (T: UFunctor.type) (A B C: HCompSet T) - (chA: A ~> B) (chB: B ~> C) : A ~> C. -destruct chA as [hhA0 pA]. -destruct chB as [hhB0 pB]. -destruct pA as [hhA1 ppA]. -destruct pB as [hhB1 ppB]. -set hh0 := comp hhA0 hhB0. -set hh1 := comp hhA1 hhB1. -econstructor 1 with (x:=hh0). -econstructor 1 with (x:=hh1). -set vv := comp (HC2Target hhA0) (HC2Target hhB0). -assert (comp (HC2Source hhA1) (HC2Source hhB1) = vv) as vv_E. -{ rewrite <- ppA. - rewrite <- ppB. - subst vv; auto. -} -assert (HC2Target hh0 = vv) as vv_ET. -{ subst vv. - unfold HC2Target, HTarget. - rewrite Fcomp; auto. -} -assert (HC2Source hh1 = vv) as vv_ES. -{ rewrite <- vv_E. - unfold HC2Source, HSource. - rewrite Fcomp; auto. -} -rewrite vv_ET. -rewrite vv_ES. -reflexivity. -Show Proof. -Defined. - -Program Definition HComp_comp_auxA (T : UFunctor.type) +Definition HComp_comp_auxA (T : STUFunctor.type) (A B C : HCompSet T) (hhA0 : C2Hom (h_first A) (h_first B)) (hhA1 : C2Hom (h_second A) (h_second B)) @@ -1428,7 +1442,7 @@ Program Definition HComp_comp_auxA (T : UFunctor.type) reflexivity. Defined. -Program Definition HComp_comp_auxS (T : UFunctor.type) +Definition HComp_comp_auxS (T : STUFunctor.type) (A B C : HCompSet T) (hhA0 : C2Hom (h_first A) (h_first B)) (hhA1 : C2Hom (h_second A) (h_second B)) @@ -1442,7 +1456,7 @@ Program Definition HComp_comp_auxS (T : UFunctor.type) reflexivity. Defined. -Program Definition HComp_comp_auxT (T : UFunctor.type) +Definition HComp_comp_auxT (T : STUFunctor.type) (A B C : HCompSet T) (hhA0 : C2Hom (h_first A) (h_first B)) (hhA1 : C2Hom (h_second A) (h_second B)) @@ -1456,7 +1470,7 @@ Program Definition HComp_comp_auxT (T : UFunctor.type) reflexivity. Defined. -Program Definition HComp_comp_auxI (T : UFunctor.type) +Definition HComp_comp_auxI (T : STUFunctor.type) (A B C : HCompSet T) (hhA0 : C2Hom (h_first A) (h_first B)) (hhA1 : C2Hom (h_second A) (h_second B)) @@ -1472,7 +1486,8 @@ Program Definition HComp_comp_auxI (T : UFunctor.type) eapply HComp_comp_auxA; eauto. Defined. -Program Definition HComp_comp (T: UFunctor.type) (A B C: HCompSet T) +(* HCompSet composition, defined in proof mode *) +Definition HComp_comp (T: STUFunctor.type) (A B C: HCompSet T) (chA: A ~> B) (chB: B ~> C) : A ~> C. destruct chA as [hhA0 pA]. destruct chB as [hhB0 pB]. @@ -1481,13 +1496,16 @@ Program Definition HComp_comp (T: UFunctor.type) (A B C: HCompSet T) eapply HComp_comp_auxI; eauto. Defined. -(* HCompSet gives a precategory *) -HB.instance Definition HCompPreCat (T: UFunctor.type) : +(* HCompSet is a precategory *) +HB.instance Definition HCompPreCat (T: STUFunctor.type) : Quiver_IsPreCat (HCompSet T) := Quiver_IsPreCat.Build (HCompSet T) (@HComp_id T) (@HComp_comp T). -Lemma LeftUnit_lemma (T : UFunctor.type) : + +(** Product category *) + +Lemma HComp_LeftUnit_lemma (T : STUFunctor.type) : forall (a b : HCompSet T) (f : a ~> b), idmap \; f = f. intros. destruct f. @@ -1589,7 +1607,7 @@ Lemma LeftUnit_lemma (T : UFunctor.type) : eapply C. Qed. -Lemma RightUnit_lemma (T : UFunctor.type) : +Lemma HComp_RightUnit_lemma (T : STUFunctor.type) : forall (a b : HCompSet T) (f : a ~> b), f \; idmap = f. intros. destruct f. @@ -1616,7 +1634,8 @@ Lemma RightUnit_lemma (T : UFunctor.type) : assert (existT (fun hh0 : C2Hom h_first0 h_first1 => - sigma hh1 : C2Hom h_second0 h_second1,HC2Target hh0 = HC2Source hh1) + sigma hh1 : C2Hom h_second0 h_second1, + HC2Target hh0 = HC2Source hh1) (x \; idmap) (existT (fun hh1 : C2Hom h_second0 h_second1 => @@ -1625,10 +1644,12 @@ Lemma RightUnit_lemma (T : UFunctor.type) : B) = existT (fun hh0 : C2Hom h_first0 h_first1 => - sigma hh1 : C2Hom h_second0 h_second1,HC2Target hh0 = HC2Source hh1) + sigma hh1 : C2Hom h_second0 h_second1, + HC2Target hh0 = HC2Source hh1) x (existT - (fun hh1 : C2Hom h_second0 h_second1 => HC2Target x = HC2Source hh1) + (fun hh1 : C2Hom h_second0 h_second1 => + HC2Target x = HC2Source hh1) x0 e)) as C. @@ -1691,7 +1712,7 @@ Lemma RightUnit_lemma (T : UFunctor.type) : eapply C. Qed. -Lemma Assoc_lemma (T : UFunctor.type) : +Lemma HComp_Assoc_lemma (T : STUFunctor.type) : forall (a b c d : HCompSet T) (f : a ~> b) (g : b ~> c) (h : c ~> d), f \; g \; h = (f \; g) \; h. intros. @@ -1757,13 +1778,6 @@ Lemma Assoc_lemma (T : UFunctor.type) : subst y12_s y01_s. rewrite compoA; auto. } - (* - rewrite E02S in E0_12. - rewrite E02T in E0_12. - - assert (E01_2 = E0_12). - *) - unfold comp. simpl. unfold HComp_comp. @@ -1773,7 +1787,8 @@ Lemma Assoc_lemma (T : UFunctor.type) : unfold HComp_comp_auxI; simpl. - assert (HC2Target (x0 \; x1 \; x2) = HC2Source (y0 \; y1 \; y2)) as KR. + assert (HC2Target (x0 \; x1 \; x2) = + HC2Source (y0 \; y1 \; y2)) as KR. { subst x0_12_t y0_12_s. subst x12_t y12_s. unfold HC2Target. @@ -1785,7 +1800,8 @@ Lemma Assoc_lemma (T : UFunctor.type) : auto. } - assert (HC2Target ((x0 \; x1) \; x2) = HC2Source ((y0 \; y1) \; y2)) as KL. + assert (HC2Target ((x0 \; x1) \; x2) = + HC2Source ((y0 \; y1) \; y2)) as KL. { subst x01_2_t y01_2_s. subst x01_t y01_s. unfold HC2Target. @@ -1947,34 +1963,35 @@ Lemma Assoc_lemma (T : UFunctor.type) : eapply KA. Qed. -Program Definition HCompCatP (T: UFunctor.type) : PreCat_IsCat (HCompSet T). +Program Definition HCompCatP (T: STUFunctor.type) : + PreCat_IsCat (HCompSet T). econstructor. -eapply LeftUnit_lemma; eauto. -eapply RightUnit_lemma; eauto. -eapply Assoc_lemma; eauto. +eapply HComp_LeftUnit_lemma; eauto. +eapply HComp_RightUnit_lemma; eauto. +eapply HComp_Assoc_lemma; eauto. Qed. -(* TODO: to be replaced by a proof *) -(* Global Parameter GCompAx : forall (T: UFunctor.type), - PreCat_IsCat (HCompSet T). -*) +(* HCompSet is a category *) +HB.instance Definition HCompCat (T: STUFunctor.type) := HCompCatP T. -HB.instance Definition HCompCat (T: UFunctor.type) := HCompCatP T. + +(** Horizontal composition functor and strict double categories *) (* composition prefunctor *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsCPreFunctor T of UFunctor T := +HB.mixin Record IsCPreFunctor T of STUFunctor T := { is_cprefunctor : IsPreFunctor (HCompSet T) (HHomSet T) (@HComp T) }. HB.structure Definition CPreFunctor : Set := {C of IsCPreFunctor C}. Set Universe Checking. -(* composition functor *) +(* composition functor - gives the definition of Strict Double Category *) Unset Universe Checking. #[wrapper] HB.mixin Record CPreFunctor_IsFunctor T of CPreFunctor T := { is_cfunctor : PreFunctor_IsFunctor (HCompSet T) (HHomSet T) (@HComp T) }. -HB.structure Definition CFunctor : Set := {C of CPreFunctor_IsFunctor C}. +#[short(type="dcat")] +HB.structure Definition DCat : Set := {C of CPreFunctor_IsFunctor C}. Set Universe Checking. (* horizontal 2-cell composition: maps two adjecent pairs of @@ -1982,11 +1999,11 @@ Set Universe Checking. between them (m, which basically gives two adjecent cells) to a 2-cell morphism between the horizontal composition (HComp) of each pair *) -Definition HC2Comp (T: CFunctor.type) (a b: HCompSet T) +Definition HC2Comp (T: DCat.type) (a b: HCompSet T) (m: @hom (HCompSet T) a b) : c2hom (HComp a) (HComp b) := @Fhom _ _ (@HComp T) a b m. -Program Definition HC2Comp_flat (T: CFunctor.type) (a0 a1 a2 b0 b1 b2: T) +Program Definition HC2Comp_flat (T: DCat.type) (a0 a1 a2 b0 b1 b2: T) (h0: hhom a0 a1) (h1: hhom a1 a2) (k0: hhom b0 b1) (k1: hhom b1 b2) (hh0: C2Hom h0 k0) @@ -1999,1160 +2016,9 @@ Obligation 1. refine (@existT (C2Hom h0 k0) _ hh0 (@existT (C2Hom h1 k1) _ hh1 k)). Defined. -(**************************************************************************) - - -(* hunit - horizontal unit functor. - - hcomp - horizontal composition functor. - - Both specified as object-level functions, to be lifted by - functoriality to morphism-level ones. - - At the object level, hunit gives a horizontal identity morphism - for each D0 object. At the morphism level, it gives horizontal - 2-cell identity for each vertical morphism. - - In the case of hcomp, relying on functoriality requires some care - in defining the pullback category, making sure that adjacency at - the object-level (between horizontal morphisms) is matched by - adjacency at the morphism-level (between 2-cells). *) -HB.mixin Record IsHDQuiver T of DQuiver T := { - hunit : forall a: T, @hhom T a a ; - hcomp : forall (a b c: T), @hhom T a b -> @hhom T b c -> @hhom T a c; -}. -Unset Universe Checking. -#[short(type="hdquiver")] -HB.structure Definition HDQuiver : Set := { C of IsHDQuiver C }. -Set Universe Checking. - -Definition hhunit (T: hdquiver) (a: T) : HHomSet T := - @HO T (@hhom T) a a (hunit a). - -(* horizontal composition of two horizontal morphisms from a - cell product *) -Definition hhcomp (T: hdquiver) (x: HCompSet T) : HHomSet T := - match x with - @GC _ _ a b c h1 h2 => @HO T (@hhom T) a c (hcomp a b c h1 h2) end. - -(* horizontal unit functor: D0 -> D1 *) -HB.tag Definition HUnit (C: hdquiver) := - fun (x: HDQuiver.sort C) => @hhunit C x. -(* horizontal composition functor: D1 * D1 -> D1 *) -HB.tag Definition HComp (C: hdquiver) := - fun (x: HCompSet C) => @hhcomp C x. - - - -(* 2-cell (D1) morphisms *) -Definition c2hom (D: HDQuiver.type) : HHomSet D -> HHomSet D -> U := - @hom (HHomSet D). - -Definition C2Hom (D: HDQuiver.type) (a b c d: D) (h0: hhom a b) - (h1: hhom c d) : U := c2hom (HO h0) (HO h1). - -(* The set of D1 morphisms *) -HB.tag Definition C2HomSet (C: HDQuiver.type) := Total2 (@c2hom C). - -(* horizontal 2-cell unit (maps vertical morphisms to horizontally - unitary 2-cells) *) -Definition HC2Unit (T: UFunctor.type) (a b: T) (m: @hom T a b) : - c2hom (HUnit a) (HUnit b) := @Fhom _ _ (@HUnit T) a b m. - -(* 2-cell source *) -Definition HC2Source (T: UFunctor.type) (a b: @HHomSet T) - (m: @c2hom T a b) : - @hom T (HSource a) (HSource b) := @Fhom _ _ (@HSource T) a b m. - -(* 2-cell target *) -Definition HC2Target (T: UFunctor.type) (a b: @HHomSet T) - (m: @c2hom T a b) : - @hom T (HTarget a) (HTarget b) := @Fhom _ _ (@HTarget T) a b m. - -(* horizontal composition of two (naked) horizontal morphisms *) -Definition l_hcomp (T: UFunctor.type) (a0 a1 a2: T) - (h0: hhom a0 a1) (h1: hhom a1 a2) : HHomSet T := - @HO T _ a0 a2 (hcomp a0 a1 a2 h0 h1). - - -(** HCompSet T is the pseudo-pullback category used to deal with - products of D1 (where the adjacency condition is expressed - w.r.t. D0 *) - -Notation "'sigma' x .. y , p" := (sigT (fun x => .. (sigT (fun y => p)) ..)) - (at level 200, x binder, right associativity, - format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") - : type_scope. - -(** HCompSet quiver *) -Definition HComp_hom (T: UFunctor.type) (x y: HCompSet T) := - sigma (hh0: C2Hom (h_first x) (h_first y)) - (hh1: C2Hom (h_second x) (h_second y)), - HC2Target hh0 = HC2Source hh1. - -HB.instance Definition HCompQuiver (T: UFunctor.type) : - IsQuiver (HCompSet T) := - IsQuiver.Build (HCompSet T) (fun A B => @HComp_hom T A B). - -(* HCompSet identity, defined in proof mode *) -Program Definition HComp_id_P (T: UFunctor.type) (A: HCompSet T) : A ~> A. -unfold hom; simpl. -unfold HComp_hom, C2Hom; simpl. -destruct A; simpl. -set h0' := HO h_first0. -set h1' := HO h_second0. -repeat econstructor. -instantiate (1:= @idmap (HHomSet T) h1'). -instantiate (1:= @idmap (HHomSet T) h0'). -assert (HC2Target (@idmap (HHomSet T) h0') = @idmap _ h_two0) as T0. -{ unfold HC2Target, HTarget. - rewrite F1; auto. -} -assert (HC2Source (@idmap (HHomSet T) h1') = @idmap _ h_two0) as S1. -{ unfold HC2Source, HSource. - rewrite F1; auto. -} -rewrite T0. -rewrite S1. -reflexivity. -Defined. - -(* HCompSet identity, only partially in proof mode *) -Program Definition HComp_id (T: UFunctor.type) (A: HCompSet T) : A ~> A := - let h0 := h_first A - in let h1 := h_second A - in let uu0 := @idmap (HHomSet T) (HO h0) - in let uu1 := @idmap (HHomSet T) (HO h1) - in @existT (C2Hom h0 h0) - (fun hh0: (C2Hom h0 h0) => - sigma (hh1 : C2Hom h1 h1), HC2Target hh0 = HC2Source hh1) uu0 - (@existT (C2Hom h1 h1) - (fun hh1: (C2Hom h1 h1) => HC2Target uu0 = HC2Source hh1) uu1 _). -Obligation 1. -unfold HC2Target, HTarget. -unfold HC2Source, HSource. -repeat rewrite F1; auto. -Defined. - -(* HCompSet composition, defined in proof mode *) -Program Definition HComp_comp (T: UFunctor.type) (A B C: HCompSet T) - (chA: A ~> B) (chB: B ~> C) : A ~> C. -destruct chA as [hhA0 pA]. -destruct chB as [hhB0 pB]. -destruct pA as [hhA1 ppA]. -destruct pB as [hhB1 ppB]. -set hh0 := comp hhA0 hhB0. -set hh1 := comp hhA1 hhB1. -econstructor 1 with (x:=hh0). -econstructor 1 with (x:=hh1). -set vv := comp (HC2Target hhA0) (HC2Target hhB0). -assert (comp (HC2Source hhA1) (HC2Source hhB1) = vv) as vv_E. -{ rewrite <- ppA. - rewrite <- ppB. - subst vv; auto. -} -assert (HC2Target hh0 = vv) as vv_ET. -{ subst vv. - unfold HC2Target, HTarget. - rewrite Fcomp; auto. -} -assert (HC2Source hh1 = vv) as vv_ES. -{ rewrite <- vv_E. - unfold HC2Source, HSource. - rewrite Fcomp; auto. -} -rewrite vv_ET. -rewrite vv_ES. -reflexivity. -Defined. - -(* HCompSet gives a precategory *) -HB.instance Definition HCompPreCat (T: UFunctor.type) : - Quiver_IsPreCat (HCompSet T) := - Quiver_IsPreCat.Build (HCompSet T) - (@HComp_id T) (@HComp_comp T). - -(* TODO: to be replaced by a proof *) -Global Parameter GCompAx : forall (T: UFunctor.type), - PreCat_IsCat (HCompSet T). - -HB.instance Definition HCompCat (T: UFunctor.type) := GCompAx T. - -(* composition prefunctor *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsCPreFunctor T of UFunctor T := - { is_cprefunctor : IsPreFunctor (HCompSet T) (HHomSet T) (@HComp T) }. -HB.structure Definition CPreFunctor : Set := {C of IsCPreFunctor C}. -Set Universe Checking. - -(* composition functor *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record CPreFunctor_IsFunctor T of CPreFunctor T := { - is_cfunctor : PreFunctor_IsFunctor (HCompSet T) (HHomSet T) (@HComp T) }. -HB.structure Definition CFunctor : Set := {C of CPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* horizontal 2-cell composition: maps two adjecent pairs of - horizontal morphisms (a and b) and a pullback-category morphism - between them (m, which basically gives two adjecent cells) to a - 2-cell morphism between the horizontal composition (HComp) of each - pair *) -Definition HC2Comp (T: CFunctor.type) (a b: HCompSet T) - (m: @hom (HCompSet T) a b) : - c2hom (HComp a) (HComp b) := @Fhom _ _ (@HComp T) a b m. - - -(* Double category with strong horizontal unit (Russ' paper). - hunit defines proper identity on horizontal morphisms *) -HB.mixin Record IsDCat_SU T of CFunctor T := { - left_unital : forall (a0 a1: T) (h : hhom a0 a1), - @hcomp T a0 a0 a1 (hunit a0) h = h ; - - right_unital : forall (a0 a1: T) (h : hhom a0 a1), - @hcomp T a0 a1 a1 h (hunit a1) = h ; -}. -Unset Universe Checking. -#[short(type="dcat_su")] -HB.structure Definition DCat_SU : Set := { C of IsDCat_SU C }. -Set Universe Checking. - -(* Double category with weak horizontal unit (display paper) *) -HB.mixin Record IsDCat_WU T of CFunctor T := { - left_unital : forall (a0 a1: T) (h : hhom a0 a1), - let hh := HO h - in let uh := HO (hcomp a0 a0 a1 (hunit a0) h) - in exists uhc : c2hom uh hh, - HC2Source uhc = @idmap T a0 /\ - HC2Target uhc = @idmap T a1 ; - - right_unital : forall (a0 a1: T) (h : hhom a0 a1), - let hh := HO h - in let uh := HO (hcomp a0 a1 a1 h (hunit a1)) - in exists uhc : c2hom uh hh, - HC2Source uhc = @idmap T a0 /\ - HC2Target uhc = @idmap T a1 -}. -Unset Universe Checking. -#[short(type="dcat_wu")] -HB.structure Definition DCat_WU : Set := { C of IsDCat_WU C }. -Set Universe Checking. - -(* Double category with universal characterization of half-strong - horizontal unit *) -HB.mixin Record IsDCat_HU T of CFunctor T := { - left_unital : forall (a0 a1 b0 b1: T) - (r: @hhom T a0 a1) (s: @hhom T b0 b1), - let rr := @HO T (@hhom T) a0 a1 r in - let ss := @HO T (@hhom T) b0 b1 s in - let aa := @hunit T a0 in - let bb := @hunit T b0 in - @hom (HHomSet T) rr ss = - @hom (HHomSet T) (hhcomp (@GC T _ a0 a0 a1 aa r)) - (hhcomp (@GC T _ b0 b0 b1 bb s)) ; - - right_unital : forall (a0 a1 b0 b1: T) - (r: @hhom T a0 a1) (s: @hhom T b0 b1), - let rr := @HO T (@hhom T) a0 a1 r in - let ss := @HO T (@hhom T) b0 b1 s in - let aa := @hunit T a1 in - let bb := @hunit T b1 in - @hom (HHomSet T) rr ss = - @hom (HHomSet T) (hhcomp (@GC T _ a0 a1 a1 r aa)) - (hhcomp (@GC T _ b0 b1 b1 s bb)) ; -}. -Unset Universe Checking. -#[short(type="dcat_hu")] -HB.structure Definition DCat_HU : Set := { C of IsDCat_HU C }. -Set Universe Checking. - -(* Double category with weak horizontal associativity (display paper) *) -HB.mixin Record IsDCat_WA T of CFunctor T := { - associator : forall (a0 a1 a2 a3: T) - (h1: @hhom T a0 a1) (h2: @hhom T a1 a2) - (h3: @hhom T a2 a3) (x: HHomSet T), - let h12 := hcomp a0 a1 a2 h1 h2 in - let h23 := hcomp a1 a2 a3 h2 h3 in - let hh1 := HO (hcomp a0 a1 a3 h1 h23) in - let hh2 := HO (hcomp a0 a2 a3 h12 h3) in - exists asc: - c2hom hh1 hh2, HC2Source asc = @idmap T a0 /\ - HC2Target asc = @idmap T a3 -}. -Unset Universe Checking. -#[short(type="dcat_wa")] -HB.structure Definition DCat_WA : Set := { C of IsDCat_WA C }. -Set Universe Checking. -(* - a0 -- h0 --> a1 -- h1 --> a2 - | | | | | - v0 hh0 v1 hh1 v2 - | | | | | - V V V V V - b0 -- k0 --> b1 -- k1 --> b2 -*) - -(* Double category with universal characterization of weak - horizontal associativity *) -HB.mixin Record IsDCat_UA T of CFunctor T := { - associator : forall (a0 a1 a2 a3: T) - (h1: @hhom T a0 a1) (h2: @hhom T a1 a2) - (h3: @hhom T a2 a3) (x: HHomSet T), - let h23 := hcomp a1 a2 a3 h2 h3 in - let h12 := hcomp a0 a1 a2 h1 h2 in - let hh1 := hcomp a0 a1 a3 h1 h23 in - let hh2 := hcomp a0 a2 a3 h12 h3 in - @hom (HHomSet T) (@HO T (@hhom T) a0 a3 hh1) x = - @hom (HHomSet T) (@HO T (@hhom T) a0 a3 hh2) x -}. -Unset Universe Checking. -#[short(type="dcat_ua")] -HB.structure Definition DCat_UA : Set := { C of IsDCat_UA C }. -Set Universe Checking. - -(* double category, closer to the display paper *) -Unset Universe Checking. -#[short(type="dcat_dp")] -HB.structure Definition DCat_DP : Set := { C of DCat_WU C & DCat_WA C }. -Set Universe Checking. - -(* double category, closer to (my understanding of) Russ' paper *) -Unset Universe Checking. -#[short(type="dcat_rp")] -HB.structure Definition DCat_RP : Set := { C of DCat_SU C & DCat_UA C }. -Set Universe Checking. - - -(*********************************************************************) - -Program Definition HC2Comp_flat (T: CFunctor.type) (a0 a1 a2 b0 b1 b2: T) - (h0: hhom a0 a1) (h1: hhom a1 a2) - (k0: hhom b0 b1) (k1: hhom b1 b2) - (hh0: C2Hom h0 k0) - (hh1: C2Hom h1 k1) - (k: HC2Target hh0 = HC2Source hh1) - : (* C2Hom (hcomp _ _ _ h0 h1) (hcomp _ _ _ k0 k1) *) - c2hom (l_hcomp h0 h1) (l_hcomp k0 k1) := - @Fhom _ _ (@HComp T) (GC h0 h1) (GC k0 k1) _. -Obligation 1. -refine (@existT (C2Hom h0 k0) _ hh0 (@existT (C2Hom h1 k1) _ hh1 k)). -Defined. - -(* not working yet *) -HB.mixin Record IsDCat_U2 T of CFunctor T := { - left_unital : forall (a0 a1 b0 b1: T) (m: @hom T a0 b0) - (h : hhom a0 a1) (k : hhom b0 b1) - (hh: c2hom (HO h) (HO k)), - forall (xx: c2hom (HUnit a0) (HUnit b0)), - xx = HC2Unit m -> - HC2Source hh = m -> - @HC2Comp_flat T a0 a0 a1 b0 b0 b1 (hunit a0) h (hunit b0) k xx hh = - @HC2Comp_flat T a0 a0 a1 b0 b0 b1 (hunit a0) h (hunit b0) k xx hh -}. - - -(*********************************************************************) -(**** GARBAGE ****************************************************) - -(* A quiver from which horizontal morphisms arise (just a copy of quiver) *) -HB.mixin Record IsHQuiver C := { - hhom : C -> C -> U - }. -Unset Universe Checking. -#[short(type="hquiver")] -HB.structure Definition HQuiver : Set := { C of IsHQuiver C }. -Set Universe Checking. - -(* domain-specific sigma-type to represent the set of morphims - (needed for 2-objects, i.e. horizontal morphisms) *) -Record Total2 T (h: T -> T -> U) : Type := HO { - source : T; - target : T; - this_morph : h source target }. - -(* the set of horizontal morphisms. - HB.tag needed to identify HHomSet as lifter *) -HB.tag Definition HHomSet (C: hquiver) := Total2 (@hhom C). - -(* source functor (for horizontal morphisms): D1 -> D0. - defined as object-level function, by functoriality lifted to a - (2-cell, vertical) morphism-level one *) -HB.tag Definition HSource C := fun (X: HHomSet C) => @source C (@hhom C) X. -(* target functor (for horizontal morphisms): D1 -> D0. *) -HB.tag Definition HTarget C := fun (X: HHomSet C) => @target C (@hhom C) X. - -(* D1 quiver requirement. *) -#[wrapper] -HB.mixin Record IsD1Quiver T of HQuiver T := { - d1_quiver : IsQuiver (@HHomSet T) }. -Unset Universe Checking. -#[short(type="d1quiver")] -HB.structure Definition D1Quiver : Set := { C of IsD1Quiver C }. -Set Universe Checking. - -(* all the quivers required by a double category *) -Unset Universe Checking. -#[short(type="dquiver")] -HB.structure Definition DQuiver : Set := - { C of Quiver C & HQuiver C & IsD1Quiver C }. -Set Universe Checking. - -(* used to define composable pairs of morphisms as a set *) -Record GenComp T (h: T -> T -> U) := GC { - c_one : T; - c_two : T ; - c_three : T; - c_first : h c_one c_two ; - c_second : h c_two c_three -}. - -(* composable pairs of horizontal morphisms as a set *) -HB.tag Definition HComp (C: hquiver) := GenComp (@hhom C). - -(* -(* pullback category condition (i.e. (HComp T) is a category). - requires T to be a category, and (HHomSet T) to be a quiver *) -#[wrapper] -HB.mixin Record IsHCompCat T of Cat T & DQuiver T := { - hcompcat : Cat (HComp T) }. -Unset Universe Checking. -#[short(type="hcompcat")] -HB.structure Definition HCompCat : Set := { C of IsHCompCat C }. -Set Universe Checking. -*) - -(* c2unit - horizontal unit functor. - - c2comp - horizontal composition functor. - - Both specified as object-level functions, to be lifted by - functoriality to morphism-level ones. - - At the object level, c2unit gives a horizontal identity morphism - for each D0 object. At the morphism level, it gives horizontal - 2-cell identity for each vertical morphism. - - In the case of HComp, relying on functoriality requires some care - in defining the pullback category, making sure that adjacency at - the object-level (between horizontal morphisms) is matched by - adjacency at the morphism-level (between 2-cells). *) -HB.mixin Record IsC2Quiver T of DQuiver T (* & HCompCat T *) := { - h2unit : forall a: T, @hhom T a a ; - h2comp : forall (a b c: T), - @hhom T a b -> @hhom T b c -> @hhom T a c; - - c2unit : T -> HHomSet T ; - c2comp : HComp T -> HHomSet T ; - - c2unit_eq : forall a: T, c2unit a = @HO T (@hhom T) a a (h2unit a) ; - c2comp_eq1 : forall (a b c: T) (h1: @hhom T a b) (h2: @hhom T b c), - c2comp (@GC T (@hhom T) a b c h1 h2) = - @HO T (@hhom T) a c (h2comp a b c h1 h2) -}. -Unset Universe Checking. -#[short(type="c2quiver")] -HB.structure Definition C2Quiver : Set := { C of IsC2Quiver C }. -Set Universe Checking. - -(************************************************************************************) - -(* Double category *) -Unset Universe Checking. -HB.mixin Record IsDCat T of HCFunctor T := { - left_unital : forall (a b: T) (r: @hhom T a b), - let rr := @HO T (@hhom T) a b r in - let aa := @h2unit T a in - @hom (HHomSet T) (c2comp (@GC T _ a a b aa r)) rr ; - - right_unital : forall (a b: T) (r: @hhom T a b), - let rr := @HO T (@hhom T) a b r in - let bb := @h2unit T b in - @hom (HHomSet T) (c2comp (@GC T _ a b b r bb)) rr ; -}. - -(* Double category *) -Unset Universe Checking. -HB.mixin Record IsDCat T of HCFunctor T := { - left_unital : forall (a b c d: T) (r: @hhom T a c) (s: @hhom T b d), - forall (ha: @hhom T a a) (hb: @hhom T b b), - @hom (HHomSet T) (@HO T (@hhom T) a c r) (@HO T (@hhom T) b d s) = - @hom (HHomSet T) (c2comp (@GC T _ a a c ha r)) - (c2comp (@GC T _ b b d hb s)) ; - - right_unital : forall (a b c d: T) (r: @hhom T a c) (s: @hhom T b d), - forall (ha: @hhom T c c) (hb: @hhom T d d), - @hom (HHomSet T) (@HO T (@hhom T) a c r) (@HO T (@hhom T) b d s) = - @hom (HHomSet T) (c2comp (@GC T _ a c c r ha)) - (c2comp (@GC T _ b d d s hb)) ; - - associator : forall (a0 a1 a2 a3: T) - (h1: @hhom T a0 a1) (h2: @hhom T a1 a2) - (h3: @hhom T a2 a3), - forall (h12: @hhom T a0 a2) (h23: @hhom T a1 a3) (x: HHomSet T), - @HO T (@hhom T) a1 a3 h23 = c2comp (@GC T _ a1 a2 a3 h2 h3) -> - @HO T (@hhom T) a0 a2 h12 = c2comp (@GC T _ a0 a1 a2 h1 h2) -> - let hh1 := c2comp (@GC T _ a0 a1 a3 h1 h23) in - let hh2 := c2comp (@GC T _ a0 a2 a3 h12 h3) in - @hom (HHomSet T) hh1 x = @hom (HHomSet T) hh2 x -}. -#[short(type="dcat")] -HB.structure Definition DCat : Set := { C of IsDCat C }. -Set Universe Checking. - - -(* a sequence of two adjacent morphisms (pullback object), - which we can use to represent composition *) -Record GenComp' T (h: T -> T -> U) := GCmp { - comp_first : @Total2 T h ; - comp_second : @Total2 T h ; - comp_adjacent : target comp_first = source comp_second -}. -(* horizontal morphism composition type. ultimately though, SHOULD - DEPEND ON D0 (hence on 'Quiver T' and 'Quiver (T * T)) *) -Definition HComp' (C: hquiver) := GenComp' (@hhom C). - - -(* source prefunctor. - HHomSet T is the quiver of the 2-morphisms, thanks to H2Quiver. - T is the quiver of 1-morphisms. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsHSPreFunctor T of Cat T & H2Cat T := { - h2s_prefunctor : IsPreFunctor (HHomSet T) T (@Source T) }. -HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. -Set Universe Checking. - -(* target prefunctor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsHTPreFunctor T of Cat T & H2Cat T := { - h2t_prefunctor : IsPreFunctor (HHomSet T) T (@Target T) }. -HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. -Set Universe Checking. - - - -HB.mixin Record IsC2Quiver T of Quiver T & PreC2Quiver T := { - c2left : C2HomSet T -> VHomSet T ; - c2right : C2HomSet T -> VHomSet T ; - - c2unit : forall x:T, HHomSet T ; - - c2left_eq1 : forall d: C2HomSet T, - source (source d) = source (c2left d) ; - c2left_eq2 : forall d: C2HomSet T, - source (target d) = target (c2left d) ; - c2right_eq1 : forall d: C2HomSet T, - target (source d) = source (c2right d) ; - c2right_eq2 : forall d: C2HomSet T, - target (target d) = target (c2right d) ; - - c2unit_eq : forall a: T, - let h := c2unit a in source h = target h ; - -}. -Unset Universe Checking. -#[short(type="c2quiver")] -HB.structure Definition C2Quiver : Set := { C of IsC2Quiver C }. -Set Universe Checking. - -(* left edge functor: D1 -> D0 *) -HB.tag Definition C2Left (C: C2Quiver.type) := - fun (X: C2HomSet C) => @c2left C X. -(* right edge functor: D1 -> D0 *) -HB.tag Definition C2Right (C: C2Quiver.type) := - fun (X: C2HomSet C) => @c2right C X. - - - -(* we need horizontal morphisms to form at least a precategory *) -HB.mixin Record HQuiver_IsHPreCat C of HQuiver C := { - hidmap : forall (a : C), hhom a a; - hcomp : forall d : D1_prod C, - hhom (source (d1_first d)) (target (d1_second d)); -}. -Unset Universe Checking. -#[short(type="hprecat")] -HB.structure Definition HPreCat : Set := { C of HQuiver_IsHPreCat C }. -Set Universe Checking. - - -HB.mixin Record IsH2Grid T of Quiver T & H2Quiver T := { - h2left_edge : H2HomSet T -> VHomSet T ; - h2right_edge : H2HomSet T -> VHomSet T -}. -Unset Universe Checking. -#[short(type="h2grid")] -HB.structure Definition H2Grid : Set := { C of IsH2Grid C }. -Set Universe Checking. - -(* adding the map to define (1) the unit functor D0 -> D1 - and (2) composition D1 *d0 D1 -> D1 *) -HB.mixin Record IsH2FQuiver T of H2Quiver T & H2Grid T & PreCat T := { - h2unit_map: forall x:T, HHomSet T ; - h2unit_map_eq: forall x:T, h2unit_map x = - @HO T (@hhom T) x x (hidmap x) ; - h2comp_map: D1_prod T -> HHomSet T ; - h2comp_map_eq: forall d: D1_prod T, h2comp_map d = - @HO T (@hhom T) (source (d1_first d)) (target (d1_second d)) (hcomp d) -}. -Unset Universe Checking. -#[short(type="h2fquiver")] -HB.structure Definition H2FQuiver : Set := { C of IsH2FQuiver C }. -Set Universe Checking. - -(* Precat based on the H2Quiver (D1). *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2PreCat T of H2FQuiver T := { - h2precat : Quiver_IsPreCat (@HHomSet T) }. -#[short(type="h2precat")] -HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. -Set Universe Checking. - -(* The category based on the H2Quiver (D1). *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2Cat T of H2PreCat T := { - h2cat : PreCat_IsCat (@HHomSet T) }. -#[short(type="h2cat")] -HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. -Set Universe Checking. - -(* -Unset Universe Checking. -#[short(type="predcat")] -HB.structure Definition PreDCat : Set := { D of H2Cat D & H2Grid D }. -Set Universe Checking. -*) - -Record D2_prod T := { - d2_first : @H2HomSet T ; - d2_second : @H2HomSet T ; - d2_adjacent : target d2_first = source d2_second -}. - -(* probably not needed *) -HB.mixin Record HQuiver_IsH2PreCat' C of H2Grid C := { - h2idmap : forall (a : C), hhom a a; - h2comp : forall d : D2_prod C, - h2hom (source (d2_first d)) (target (d2_second d)); -}. -Unset Universe Checking. -#[short(type="hprecat")] -HB.structure Definition H2PreCat' : Set := { C of HQuiver_IsH2PreCat' C }. -Set Universe Checking. - - - -(* -(* gives left and right edges of a 2-cell (i.e. the vertical - morphisms associated with the 2-morphism). - these should be functors - *) -HB.mixin Record IsH2Grid T of Quiver T & H2Quiver T := { - h2left_edge : forall a b c d: T, - forall (h1: hhom a b) (h2: hhom c d), - @hom (@HHomSet T) (@HO T (@hhom T) a b h1) - (@HO T (@hhom T) c d h2) -> @hom T a c ; - h2right_edge : forall a b c d: T, - forall (h1: hhom a b) (h2: hhom c d), - @hom (@HHomSet T) (@HO T (@hhom T) a b h1) - (@HO T (@hhom T) c d h2) -> @hom T b d -}. -Unset Universe Checking. -#[short(type="h2grid")] -HB.structure Definition H2Grid : Set := { C of IsH2Grid C }. -Set Universe Checking. - -(* -(* adding the map to define (1) the unit functor D0 -> D1 - and (2) composition D1 *d0 D1 -> D1 *) -HB.mixin Record IsH2FQuiver T of H2Quiver T := { - h2unit_map: forall x:T, HHomSet T ; - h2unit_map_eq: forall x:T, h2unit_map x = - @HO T (@hhom T) x x (hidmap x) ; - h2comp_map: HHomSet T * HHomSet T -> HHomSet T ; - h2comp_map_eq: forall (a b c: T) (h1: hhom a b) (h2: hhom b c), - let x := @HO T (@hhom T) a b h1 - in let y := @HO T (@hhom T) b c h2 - in let z := @HO T (@hhom T) a c (hcomp a b c h1 h2) - in h2comp_map (x, y) = z }. -Unset Universe Checking. -#[short(type="h2fquiver")] -HB.structure Definition H2FQuiver : Set := { C of IsH2FQuiver C }. -Set Universe Checking. -*) -(* -(* adding the map to define the unit functor D0 -> D1 *) -HB.mixin Record IsH2FQuiver T of H2Quiver T := { - h2unit_map: forall x:T, HHomSet T ; - h2unit_map_eq: forall x:T, let y := h2unit_map x in - source y = target y ; - h2comp_map: HHomSet T * HHomSet T -> HHomSet T ; - h2comp_map_eq: forall x y: HHomSet T, target x = source y -> - exists f: hhom (source x) (target y), - h2comp_map (x, y) = @HO T (@hhom T) (source x) (target y) f ; -(* square_comp : forall (a1 b1 c1 a2 b2 c2: T), - forall (ha1: hhom a1 b1) (hb1: hhom b1 c1) - (ha2: hhom a2 b2) (hb2: hhom b2 c2), *) - }. -Unset Universe Checking. -#[short(type="h2fquiver")] -HB.structure Definition H2FQuiver : Set := { C of IsH2FQuiver C }. -Set Universe Checking. -*) - -(* Precat based on the H2Quiver (D1). *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2PreCat T of H2FQuiver T := { - h2precat : Quiver_IsPreCat (@HHomSet T) }. -#[short(type="h2precat")] -HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. -Set Universe Checking. - -(* The category based on the H2Quiver (D1). *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2Cat T of H2PreCat T := { - h2cat : PreCat_IsCat (@HHomSet T) }. -#[short(type="h2cat")] -HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. -Set Universe Checking. - -(* Pre-double category, with horizontal 2-cell composition *) -Unset Universe Checking. -HB.mixin Record IsPreDCat T of Cat T & H2Cat T & H2Grid T := { - h2adjacent : forall (a b c d e f: T), - forall (h1: hhom a b) (h2: hhom b c) (h3: hhom d e) (h4: hhom e f), - forall (hh1: @hom (@HHomSet T) (@HO T (@hhom T) a b h1) - (@HO T (@hhom T) d e h3)) - (hh2: @hom (@HHomSet T) (@HO T (@hhom T) b c h2) - (@HO T (@hhom T) e f h4)), - h2right_edge a b d e h1 h3 hh1 = - h2left_edge b c e f h2 h4 hh2 ; - - h2comp : forall (h1 h2 h3 h4: HHomSet T), - forall (hh1: h1 ~> h2) (hh2: h3 ~> h4), - h2comp_map (h1,h3) ~> h2comp_map (h2,h4) ; - -(* - h2comp_eq : forall (a b c d e f: T), - forall (h1: hhom a b) (h2: hhom b c) (h3: hhom d e) (h4: hhom e f), - forall (hh1: @hom (@HHomSet T) (@HO T (@hhom T) a b h1) - (@HO T (@hhom T) d e h3)) - (hh2: @hom (@HHomSet T) (@HO T (@hhom T) b c h2) - (@HO T (@hhom T) e f h4)), - h2adjacent a b c d e f h1 h2 hh1 hh2 -> - let h1' := (@HO T (@hhom T) a b h1) - in let h2' := (@HO T (@hhom T) b c h2) - in let h3' := (@HO T (@hhom T) d e h3) - in let h4' := (@HO T (@hhom T) e f h4) - h2comp h1' h2' h3' h4' hh1 hh2 = -*) - }. -#[short(type="predcat")] -HB.structure Definition PreDCat : Set := { D of IsPreDCat D }. -Set Universe Checking. - - -*) - -(* source functor: D1 -> D0 *) -HB.tag Definition Source C := fun (X: HHomSet C) => @source C (@hhom C) X. -(* target functor: D1 -> D0 *) -HB.tag Definition Target C := fun (X: HHomSet C) => @target C (@hhom C) X. -(* unit functor: D0 -> D1 *) -HB.tag Definition UnitF (C: h2fquiver) := - fun (x:H2FQuiver.sort C) => @h2unit_map C x. - -(* source prefunctor. - HHomSet T is the quiver of the 2-morphisms, thanks to H2Quiver. - T is the quiver of 1-morphisms. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsHSPreFunctor T of Cat T & H2Cat T := { - h2s_prefunctor : IsPreFunctor (HHomSet T) T (@Source T) }. -HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. -Set Universe Checking. - -(* target prefunctor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsHTPreFunctor T of Cat T & H2Cat T := { - h2t_prefunctor : IsPreFunctor (HHomSet T) T (@Target T) }. -HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. -Set Universe Checking. - - - -HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. -Set Universe Checking. - -(* source functor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record HSPreFunctor_IsFunctor T of Cat T & HSPreFunctor T := { - h2s_functor : PreFunctor_IsFunctor (HHomSet T) T (@Source T) }. -HB.structure Definition HSFunctor : Set := {C of HSPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* target functor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record HTPreFunctor_IsFunctor T of Cat T & HTPreFunctor T := { - h2t_functor : PreFunctor_IsFunctor (HHomSet T) T (@Target T) }. -HB.structure Definition HTFunctor : Set := {C of HTPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* unit prefunctor. *) -Unset Universe Checking. - #[wrapper] -HB.mixin Record IsHUPreFunctor T of Cat T & PreDCat T := { - h2u_prefunctor : IsPreFunctor T (HHomSet T) (@UnitF T) }. -HB.structure Definition HUPreFunctor : Set := {C of IsHUPreFunctor C}. -Set Universe Checking. - - -Unset Universe Checking. - #[wrapper] -HB.mixin Record HUPreFunctor_IsFunctor T of Cat T & HUPreFunctor T := { - h2u_functor : PreFunctor_IsFunctor T (HHomSet T) (@UnitF T) }. - HB.structure Definition HUFunctor : Set := {T of - Cat T & HUPreFunctor T & - PreFunctor_IsFunctor T (HHomSet T) (@UnitF T) - }. -Set Universe Checking. - - -Unset Universe Checking. - #[wrapper] -HB.mixin Record HUPreFunctor_IsFunctor T of Cat T & HUPreFunctor T := { - h2u_functor : PreFunctor_IsFunctor T (HHomSet T) (@UnitF T) }. -HB.structure Definition HUFunctor : Set := {C of HUPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* double category *) -Unset Universe Checking. -HB.structure Definition DCat : Set := - {D of HSPreFunctor_IsFunctor D & HTPreFunctor_IsFunctor D & - HUPreFunctor_IsFunctor D}. -Set Universe Checking. - -(* 2-morphisms *) -Definition h2hom (D: DCat.type) := @hom (@HHomSet D). - -(* still don't understand - transposition whould swap vertical and horizontal morphisms, - i.e. hom and hhom *) -Definition transpose1 (D: DCat.type) : U := D. -(* however, given transpose1 this should hold *) -Lemma hom_transpose (D: DCat.type) : @hom (transpose1 D) = @hhom D. -Admitted. -(* and this too *) -Lemma hhom_transpose (D: DCat.type) : @hhom (transpose1 D) = @hom D. -Admitted. - -(* tranposition as a relation *) -Definition isTranspose C - (FQ: PreDCat C -> Quiver C) - (FHQ: PreDCat C -> HQuiver C) - (D1 D2: PreDCat C) : Type := - @hom (Quiver.Pack (FQ D2)) = @hhom (HQuiver.Pack (FHQ D1)) /\ - @hhom (HQuiver.Pack (FHQ D2)) = @hom (Quiver.Pack (FQ D1)). - -Definition transpose_isquiver C (X: IsQuiver C) : IsHQuiver C. - destruct X. - econstructor. - exact hom0. -Defined. - -Definition transpose_ishquiver C (X: IsHQuiver C) : IsQuiver C. - destruct X. - econstructor. - exact hhom0. -Defined. - -Definition transpose_quiver C (X: Quiver C) : HQuiver C. - destruct X. - econstructor. - eapply transpose_isquiver; eauto. -Defined. - -Definition transpose_hquiver C (X: HQuiver C) : Quiver C. - destruct X. - econstructor. - eapply transpose_ishquiver; eauto. -Defined. - -(* tranposition as a relation, using the transpose functions *) -Definition isTransposeF C - (FQ: PreDCat C -> Quiver C) - (FHQ: PreDCat C -> HQuiver C) - (D1 D2: PreDCat C) : Type := - Quiver.Pack (FQ D2) = Quiver.Pack (@transpose_hquiver C (FHQ D1)) /\ - HQuiver.Pack (FHQ D2) = HQuiver.Pack (@transpose_quiver C (FQ D1)). - - - -(*** DOUBLE CATEGORIES (PREVIOUS) *) - -(* A quiver from which horizontal morphisms arise. D1 is the type of - D1 objects (horizontal morphisms in C), with source and target - functors. *) -HB.mixin Record HasD1 C := { - D1 : U ; - s10 : D1 -> C ; - t10 : D1 -> C }. -Unset Universe Checking. -#[short(type="hquiver")] -HB.structure Definition D1type : Set := { C of HasD1 C }. -Set Universe Checking. - -(* A quiver from which 2-morphisms arise as arrows between 2-objects - (i.e. horizontal morphisms) *) -#[wrapper] -HB.mixin Record IsH2Quiver T of HasD1 T := { - h2quiver : IsQuiver (@D1 T) }. -Unset Universe Checking. -#[short(type="h2quiver")] -HB.structure Definition H2Quiver : Set := { C of IsH2Quiver C }. -Set Universe Checking. - -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2PreCat T of H2Quiver T := { - h2precat : Quiver_IsPreCat (@D1 T) }. -#[short(type="h2precat")] -HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. -Set Universe Checking. - -(* The category based on the H2Quiver (D1). *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2Cat T of H2PreCat T := { - h2cat : PreCat_IsCat (@D1 T) }. -#[short(type="h2cat")] -#[verbose] -HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. -Set Universe Checking. - -(* Pre-double category (no functors yet): this corresponds to the old -definition *) -Unset Universe Checking. -HB.structure Definition PreDCat : Set := { D of Cat D & H2Cat D }. -Set Universe Checking. - -(* source prefunctor. - D1 here is the quiver of the 2-morphisms, thanks to IsH2Quiver. - T is the quiver of 1-morphisms. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsHSPreFunctor T of Cat T & H2Cat T := { - h2s_prefunctor : IsPreFunctor D1 T s10 }. -HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. -Set Universe Checking. - -(* target prefunctor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsHTPreFunctor T of Cat T & H2Cat T := { - h2t_prefunctor : IsPreFunctor D1 T t10 }. -HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. -Set Universe Checking. - -(* source functor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record HSPreFunctor_IsFunctor T of Cat T & HSPreFunctor T := { - h2s_prefunctor : PreFunctor_IsFunctor D1 T s10 }. -HB.structure Definition HSFunctor : Set := {C of HSPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* target functor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record HTPreFunctor_IsFunctor T of Cat T & HTPreFunctor T := { - h2t_prefunctor : PreFunctor_IsFunctor D1 T t10 }. -HB.structure Definition HTFunctor : Set := {C of HTPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* double category *) -Unset Universe Checking. -HB.structure Definition DCat : Set := - {D of HSPreFunctor_IsFunctor D & HTPreFunctor_IsFunctor D }. -Set Universe Checking. - -(* 2-morphisms *) -Definition hhom (D: DCat.type) := @hom (@D1 D). - -Definition transpose (D: DCat.type) : U := D. - -Fail Lemma hom_transpose (D: DCat.type) : @hom (transpose D) = @hhom D. - -Fail Lemma hhom_transpose (D: DCat.type) : @hhom (transpose D) = @hom D. - - - -(*** DOUBLE CATEGORIES (OLD) *) - -(* A quiver from which horizontal morphisms arise (just a copy of quiver) *) -HB.mixin Record IsHQuiver C := { hhom : C -> C -> U }. -Unset Universe Checking. -#[short(type="hquiver")] -HB.structure Definition HQuiver : Set := { C of IsHQuiver C }. -Set Universe Checking. - -(* domain-specific sigma-type to represent the 2-objects *) -Record Total2 T (h: T -> T -> U) : Type := HO { - source : T; - target : T; - this_hom : h source target }. - -(* needed to identify HHomSet as lifter *) -HB.tag Definition HHomSet (C: hquiver) := Total2 (@hhom C). - -(* A quiver from which 2-morphisms arise as arrows between 2-objects - (i.e. horizontal morphisms) *) -#[wrapper] -HB.mixin Record IsH2Quiver T of HQuiver T := { - h2quiver : Quiver (@HHomSet T) }. -Unset Universe Checking. -#[short(type="h2quiver")] -HB.structure Definition H2Quiver : Set := { C of IsH2Quiver C }. -Set Universe Checking. - -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2PreCat T of HQuiver T & H2Quiver T := { - h2precat : Quiver_IsPreCat (@HHomSet T) }. -#[short(type="h2precat")] -HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. -Set Universe Checking. - -(* The category based on the H2Quiver (D1). *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2Cat T of H2PreCat T := { - h2cat : PreCat_IsCat (@HHomSet T) }. -#[short(type="h2cat")] -HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. -Set Universe Checking. - -(* Double categories, from - https://ncatlab.org/nlab/show/double+category - - The definition we follow here however is a comparatively informal - one, which also mentions internal categories (not formalized yet). - - Double category (D0, D1). - - base obejcts (D0): C ; - - vertical morphisms (D0): @hom C ; - - horizontal morhisms (and 2-objects, D1): @HHomSet C ; - - 2-morphisms (D1): @hom (@HHomSet C) *) -Unset Universe Checking. -#[short(type="dcat")] -HB.structure Definition DCat : Set := { C of Cat C & H2Cat C }. -Set Universe Checking. - - - -(*******************************************************************) - -(*** Related to BICATEGORIES (just an experiment, - not the right formalization) *) - -(* We want to factor constants and operators out of the axioms. - Suggestion: introduce some notion of module to bind them - together. *) - -(* monoid axioms *) -HB.mixin Record isMonoid T (mu: T) (mc: T -> T -> T): Type := { - massoc : associative mc; - mlid : left_id mu mc ; - mrid : right_id mu mc ; -}. - -(* to be used as homset identity in bicategories *) -HB.mixin Record isHId T := { - hid : T; -}. -HB.structure Definition HId := { T of isHId T }. - -(* to be used as homset composition in bicategories *) -HB.mixin Record isHComp T := { - hcomp : T -> T -> T; -}. -HB.structure Definition HComp := { T of isHComp T }. - -#[wrapper] -HB.mixin Record Quiver_HasId T of Quiver T := - { Quiver_HasId_private : forall A B, isHId (@hom T A B) }. -HB.structure Definition HasId := - { Obj of Quiver Obj & Quiver_HasId Obj }. - -#[wrapper] -HB.mixin Record Quiver_HasComp T of Quiver T := - { Quiver_HasComp_private : forall A B, isHComp (@hom T A B) }. -HB.structure Definition HasComp := - { Obj of Quiver Obj & Quiver_HasComp Obj }. - -(* a bicategory, without axioms *) -HB.structure Definition BiCatQuiver := - {T of Quiver_HasId T & Quiver_HasComp T}. - -#[wrapper] -HB.mixin Record isHMonoid T of HId T & HComp T := - { isHMonoid_private: isMonoid T (hid: T) (@hcomp T) }. -#[verbose] -HB.structure Definition HMonoid := { T of isHMonoid T }. - -#[wrapper] -(* does not work (generic Elpi error): - HB.mixin Record isHCat T of precat_quiver T := *) -HB.mixin Record isPreBiCategory T of IsPreCat T := - { isPreBiCategory_private : forall A B: T, HMonoid (@hom T A B) }. -HB.structure Definition PreBiCategory := - { Obj of isPreBiCategory Obj }. - -(* to be used as object monoid unit *) -HB.mixin Record isMUnit T := { - munit : T; -}. -HB.structure Definition MUnit := { T of isMUnit T }. - -(* to be used as object monoid composition *) -HB.mixin Record isMComp T := { - mcomp : T -> T -> T; -}. -HB.structure Definition MComp := { T of isMComp T }. - -(* has object monoid operators *) -HB.structure Definition Premonoid := - {T of isMUnit T & isMComp T}. - -(* the precategory has monoidal operators *) -HB.structure Definition Precat_IsPremonoidal := - {T of PreCat T & Premonoid T}. - -(* object monoid *) -HB.mixin Record isOMonoid T of isMUnit T & isMComp T := - { isHMonoid_private: isMonoid T (munit: T) (mcomp: T -> T -> T) }. -#[verbose] -HB.structure Definition OMonoid := { T of isOMonoid T }. - -(* some sort of monoidal category *) -HB.structure Definition PreMonBiCategory := - { Obj of PreBiCategory Obj & OMonoid Obj }. - +(********************************************************************) +(********************************************************************) -(*******************************************************************) Section th_of_pb. Variables (Q : cat) (A B C D E F : Q). From 5faa745eb38e0b0bef911633e1c60b7d4d565bf5 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Thu, 16 Nov 2023 15:25:27 +0100 Subject: [PATCH 091/147] encatB.v: improving the proofs --- theories/encatB.v | 296 ++++++++++------------------------------------ 1 file changed, 65 insertions(+), 231 deletions(-) diff --git a/theories/encatB.v b/theories/encatB.v index c19fa9078..49a6545e6 100644 --- a/theories/encatB.v +++ b/theories/encatB.v @@ -1155,10 +1155,11 @@ HB.tag Definition HHomSet (C: cquiver) := Total2 (@hhom C). (* D1 quiver requirement (includes D0 quiver and its transpose). *) #[wrapper] -HB.mixin Record IsDQuiver T of CQuiver T := { is_dquiver : Quiver (HHomSet T) }. +HB.mixin Record IsDQuiver T of CQuiver T := + { is_dquiver : Quiver (HHomSet T) }. Unset Universe Checking. #[short(type="dquiver")] -HB.structure Definition DQuiver : Set := { C of IsDQuiver C }. +HB.structure Definition DQuiver : Set := { C of Quiver (HHomSet C) }. Set Universe Checking. @@ -1171,7 +1172,7 @@ Unset Universe Checking. HB.mixin Record IsHPreCat T of CQuiver T := { is_hprecat : Quiver_IsPreCat (transpose T) }. #[short(type="hprecat")] -HB.structure Definition HPreCat : Set := { C of IsHPreCat C }. +HB.structure Definition HPreCat : Set := { C of Quiver_IsPreCat (transpose C) }. Set Universe Checking. (* The category based on the HQuiver (i.e. horizontal category on D0 @@ -1354,6 +1355,7 @@ HB.structure Definition UFunctor : Set := {C of UPreFunctor_IsFunctor C}. Set Universe Checking. Unset Universe Checking. +HB.about Functor. HB.structure Definition STUFunctor : Set := {C of SFunctor C & TFunctor C & UFunctor C}. Set Universe Checking. @@ -1390,7 +1392,7 @@ Definition l_hcomp (T: NDCat.type) (a0 a1 a2: T) Notation "'sigma' x .. y , p" := (sigT (fun x => .. (sigT (fun y => p)) ..)) (at level 200, x binder, right associativity, - format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") + format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") : type_scope. (** HCompSet quiver *) @@ -1435,8 +1437,8 @@ Definition HComp_comp_auxA (T : STUFunctor.type) (hhB0 : C2Hom (h_first B) (h_first C)) (hhB1 : C2Hom (h_second B) (h_second C)) (ppB : HC2Target hhB0 = HC2Source hhB1) : - comp (HC2Target hhA0) (HC2Target hhB0) = - comp (HC2Source hhA1) (HC2Source hhB1). + (HC2Target hhA0) \; (HC2Target hhB0) = + (HC2Source hhA1) \; (HC2Source hhB1). rewrite ppA. rewrite ppB. reflexivity. @@ -1502,14 +1504,26 @@ HB.instance Definition HCompPreCat (T: STUFunctor.type) : Quiver_IsPreCat.Build (HCompSet T) (@HComp_id T) (@HComp_comp T). +(* + have HcompP : + (a b : HCompSet T) + (f g : a ~> b), + proj1T f = proj1t f -> + + -> + f = g. + + exists a b p, + fst f = a + f = (a,b,p) +*) (** Product category *) Lemma HComp_LeftUnit_lemma (T : STUFunctor.type) : forall (a b : HCompSet T) (f : a ~> b), idmap \; f = f. - intros. - destruct f. - destruct s. + + move => a b [x [x0 e]] /=. simpl in *. unfold idmap; simpl. unfold HComp_id; simpl. @@ -1547,71 +1561,34 @@ Lemma HComp_LeftUnit_lemma (T : STUFunctor.type) : (fun hh1 : C2Hom h_second0 h_second1 => HC2Target x = HC2Source hh1) x0 e)) as C. + { revert B. + revert A. + revert A0. + generalize (idmap \; x) as v. + generalize (idmap \; x0) as v0. + intros v0 v A0. + rewrite A0. + intro A. + rewrite A. + intro B. + + assert (B = e) as BE. + { eapply Prop_irrelevance. } - revert B. - revert A. - revert A0. - generalize (idmap \; x) as v. - generalize (idmap \; x0) as v0. - intros v0 v A0. - rewrite A0. - intro A. - rewrite A. - intro B. - - assert (B = e) as BE. - { eapply Prop_irrelevance. } - - rewrite BE. - reflexivity. + rewrite BE. + reflexivity. +} inversion aaa; subst. - - assert ((Morphisms.trans_sym_co_inv_impl_morphism - (RelationClasses.Equivalence_PER RelationClasses.eq_equivalence) - (HC2Source (idmap \; x0)) (HC2Source idmap \; HC2Source x0) - (HComp_comp_auxS - (HComp_id_eq - {| - h_one := h_one0; - h_two := h_two0; - h_three := h_three0; - h_first := h_first0; - h_second := h_second0 - |}) e) - (Morphisms.trans_co_eq_inv_impl_morphism - RelationClasses.eq_Transitive (HC2Target (idmap \; x)) - (HC2Target idmap \; HC2Target x) - (HComp_comp_auxT - (HComp_id_eq - {| - h_one := h_one0; - h_two := h_two0; - h_three := h_three0; - h_first := h_first0; - h_second := h_second0 - |}) e) (HC2Source idmap \; HC2Source x0) - (HC2Source idmap \; HC2Source x0) - (Morphisms.eq_proper_proxy (HC2Source idmap \; HC2Source x0)) - (HComp_comp_auxA - (HComp_id_eq - {| - h_one := h_one0; - h_two := h_two0; - h_three := h_three0; - h_first := h_first0; - h_second := h_second0 - |}) e))) = B) as BM. - { eapply Prop_irrelevance. } - rewrite BM. + rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] + (Prop_irrelevance _ B). eapply C. Qed. Lemma HComp_RightUnit_lemma (T : STUFunctor.type) : forall (a b : HCompSet T) (f : a ~> b), f \; idmap = f. - intros. - destruct f. - destruct s. + + move => a b [x [x0 e]] /=. simpl in *. unfold idmap; simpl. unfold HComp_id; simpl. @@ -1652,63 +1629,27 @@ Lemma HComp_RightUnit_lemma (T : STUFunctor.type) : HC2Target x = HC2Source hh1) x0 e)) as C. + { revert B. + revert A. + revert A0. + generalize (x \; idmap) as v. + generalize (x0 \; idmap) as v0. + intros v0 v A0. + rewrite A0. + intro A. + rewrite A. + intro B. + + assert (B = e) as BE. + { eapply Prop_irrelevance. } - revert B. - revert A. - revert A0. - generalize (x \; idmap) as v. - generalize (x0 \; idmap) as v0. - intros v0 v A0. - rewrite A0. - intro A. - rewrite A. - intro B. - - assert (B = e) as BE. - { eapply Prop_irrelevance. } - - rewrite BE. - reflexivity. + rewrite BE. + reflexivity. + } inversion aaa; subst. - - assert ((Morphisms.trans_sym_co_inv_impl_morphism - (RelationClasses.Equivalence_PER RelationClasses.eq_equivalence) - (HC2Source (x0 \; idmap)) (HC2Source x0 \; HC2Source idmap) - (HComp_comp_auxS e - (HComp_id_eq - {| - h_one := h_one1; - h_two := h_two1; - h_three := h_three1; - h_first := h_first1; - h_second := h_second1 - |})) - (Morphisms.trans_co_eq_inv_impl_morphism - RelationClasses.eq_Transitive (HC2Target (x \; idmap)) - (HC2Target x \; HC2Target idmap) - (HComp_comp_auxT e - (HComp_id_eq - {| - h_one := h_one1; - h_two := h_two1; - h_three := h_three1; - h_first := h_first1; - h_second := h_second1 - |})) (HC2Source x0 \; HC2Source idmap) - (HC2Source x0 \; HC2Source idmap) - (Morphisms.eq_proper_proxy (HC2Source x0 \; HC2Source idmap)) - (HComp_comp_auxA e - (HComp_id_eq - {| - h_one := h_one1; - h_two := h_two1; - h_three := h_three1; - h_first := h_first1; - h_second := h_second1 - |})))) = B) as BM. - { eapply Prop_irrelevance. } - rewrite BM. + rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] + (Prop_irrelevance _ B). eapply C. Qed. @@ -1848,118 +1789,11 @@ Lemma HComp_Assoc_lemma (T : STUFunctor.type) : reflexivity. } - assert (Morphisms.trans_sym_co_inv_impl_morphism - (RelationClasses.Equivalence_PER RelationClasses.eq_equivalence) - (HC2Source (y0 \; y1 \; y2)) - (HC2Source y0 \; HC2Source (y1 \; y2)) - (HComp_comp_auxS e0 - (Morphisms.trans_sym_co_inv_impl_morphism - (RelationClasses.Equivalence_PER - RelationClasses.eq_equivalence) - (HC2Source (y1 \; y2)) (HC2Source y1 \; HC2Source y2) - (HComp_comp_auxS e1 e2) - (Morphisms.trans_co_eq_inv_impl_morphism - RelationClasses.eq_Transitive (HC2Target (x1 \; x2)) - (HC2Target x1 \; HC2Target x2) - (HComp_comp_auxT e1 e2) (HC2Source y1 \; HC2Source y2) - (HC2Source y1 \; HC2Source y2) - (Morphisms.eq_proper_proxy (HC2Source y1 \; HC2Source y2)) - (HComp_comp_auxA e1 e2)))) - (Morphisms.trans_co_eq_inv_impl_morphism - RelationClasses.eq_Transitive (HC2Target (x0 \; x1 \; x2)) - (HC2Target x0 \; HC2Target (x1 \; x2)) - (HComp_comp_auxT e0 - (Morphisms.trans_sym_co_inv_impl_morphism - (RelationClasses.Equivalence_PER - RelationClasses.eq_equivalence) - (HC2Source (y1 \; y2)) (HC2Source y1 \; HC2Source y2) - (HComp_comp_auxS e1 e2) - (Morphisms.trans_co_eq_inv_impl_morphism - RelationClasses.eq_Transitive - (HC2Target (x1 \; x2)) (HC2Target x1 \; HC2Target x2) - (HComp_comp_auxT e1 e2) (HC2Source y1 \; HC2Source y2) - (HC2Source y1 \; HC2Source y2) - (Morphisms.eq_proper_proxy - (HC2Source y1 \; HC2Source y2)) - (HComp_comp_auxA e1 e2)))) - (HC2Source y0 \; HC2Source (y1 \; y2)) - (HC2Source y0 \; HC2Source (y1 \; y2)) - (Morphisms.eq_proper_proxy - (HC2Source y0 \; HC2Source (y1 \; y2))) - (HComp_comp_auxA e0 - (Morphisms.trans_sym_co_inv_impl_morphism - (RelationClasses.Equivalence_PER - RelationClasses.eq_equivalence) - (HC2Source (y1 \; y2)) (HC2Source y1 \; HC2Source y2) - (HComp_comp_auxS e1 e2) - (Morphisms.trans_co_eq_inv_impl_morphism - RelationClasses.eq_Transitive - (HC2Target (x1 \; x2)) (HC2Target x1 \; HC2Target x2) - (HComp_comp_auxT e1 e2) (HC2Source y1 \; HC2Source y2) - (HC2Source y1 \; HC2Source y2) - (Morphisms.eq_proper_proxy - (HC2Source y1 \; HC2Source y2)) - (HComp_comp_auxA e1 e2))))) = KR) as HR. - { eapply Prop_irrelevance. } - - rewrite HR. - - assert (Morphisms.trans_sym_co_inv_impl_morphism - (RelationClasses.Equivalence_PER RelationClasses.eq_equivalence) - (HC2Source ((y0 \; y1) \; y2)) - (HC2Source (y0 \; y1) \; HC2Source y2) - (HComp_comp_auxS - (Morphisms.trans_sym_co_inv_impl_morphism - (RelationClasses.Equivalence_PER - RelationClasses.eq_equivalence) - (HC2Source (y0 \; y1)) (HC2Source y0 \; HC2Source y1) - (HComp_comp_auxS e0 e1) - (Morphisms.trans_co_eq_inv_impl_morphism - RelationClasses.eq_Transitive (HC2Target (x0 \; x1)) - (HC2Target x0 \; HC2Target x1) - (HComp_comp_auxT e0 e1) (HC2Source y0 \; HC2Source y1) - (HC2Source y0 \; HC2Source y1) - (Morphisms.eq_proper_proxy (HC2Source y0 \; HC2Source y1)) - (HComp_comp_auxA e0 e1))) e2) - (Morphisms.trans_co_eq_inv_impl_morphism - RelationClasses.eq_Transitive (HC2Target ((x0 \; x1) \; x2)) - (HC2Target (x0 \; x1) \; HC2Target x2) - (HComp_comp_auxT - (Morphisms.trans_sym_co_inv_impl_morphism - (RelationClasses.Equivalence_PER - RelationClasses.eq_equivalence) - (HC2Source (y0 \; y1)) (HC2Source y0 \; HC2Source y1) - (HComp_comp_auxS e0 e1) - (Morphisms.trans_co_eq_inv_impl_morphism - RelationClasses.eq_Transitive - (HC2Target (x0 \; x1)) (HC2Target x0 \; HC2Target x1) - (HComp_comp_auxT e0 e1) (HC2Source y0 \; HC2Source y1) - (HC2Source y0 \; HC2Source y1) - (Morphisms.eq_proper_proxy - (HC2Source y0 \; HC2Source y1)) - (HComp_comp_auxA e0 e1))) e2) - (HC2Source (y0 \; y1) \; HC2Source y2) - (HC2Source (y0 \; y1) \; HC2Source y2) - (Morphisms.eq_proper_proxy - (HC2Source (y0 \; y1) \; HC2Source y2)) - (HComp_comp_auxA - (Morphisms.trans_sym_co_inv_impl_morphism - (RelationClasses.Equivalence_PER - RelationClasses.eq_equivalence) - (HC2Source (y0 \; y1)) (HC2Source y0 \; HC2Source y1) - (HComp_comp_auxS e0 e1) - (Morphisms.trans_co_eq_inv_impl_morphism - RelationClasses.eq_Transitive - (HC2Target (x0 \; x1)) (HC2Target x0 \; HC2Target x1) - (HComp_comp_auxT e0 e1) (HC2Source y0 \; HC2Source y1) - (HC2Source y0 \; HC2Source y1) - (Morphisms.eq_proper_proxy - (HC2Source y0 \; HC2Source y1)) - (HComp_comp_auxA e0 e1))) e2)) = KL) as HL. - { eapply Prop_irrelevance. } - - rewrite HL. + rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] + (Prop_irrelevance _ KR). + rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] + (Prop_irrelevance _ KL). eapply KA. Qed. From a5e0e21d246ff5fd7453fa5595b1573ea0c4d081 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Thu, 16 Nov 2023 16:01:16 +0100 Subject: [PATCH 092/147] encatB.v: improving the notation --- theories/encatB.v | 57 +++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 27 deletions(-) diff --git a/theories/encatB.v b/theories/encatB.v index 49a6545e6..162a420dd 100644 --- a/theories/encatB.v +++ b/theories/encatB.v @@ -1132,13 +1132,14 @@ Set Universe Checking. (* transpose for horizontal morphism quiver. HB.tag needed to identify transpose as lifter *) HB.tag Definition transpose (C : quiver) : U := C. -#[wrapper] HB.mixin Record IsHQuiver C of IsQuiver C := { +#[wrapper] HB.mixin Record _IsHQuiver C of IsQuiver C := { is_hquiver : IsQuiver (transpose C) }. (* vertical and horizontal quivers, defining cells *) Unset Universe Checking. #[short(type="cquiver")] -HB.structure Definition CQuiver : Set := { C of IsQuiver C & IsHQuiver C }. +HB.structure Definition CQuiver : Set := + { C of IsQuiver C & IsQuiver (transpose C) }. Set Universe Checking. HB.tag Definition hhom (c : CQuiver.type) : c -> c -> U := @hom (transpose c). @@ -1155,7 +1156,7 @@ HB.tag Definition HHomSet (C: cquiver) := Total2 (@hhom C). (* D1 quiver requirement (includes D0 quiver and its transpose). *) #[wrapper] -HB.mixin Record IsDQuiver T of CQuiver T := +HB.mixin Record _IsDQuiver T of CQuiver T := { is_dquiver : Quiver (HHomSet T) }. Unset Universe Checking. #[short(type="dquiver")] @@ -1169,20 +1170,22 @@ Set Universe Checking. objects) *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsHPreCat T of CQuiver T := { +HB.mixin Record _IsHPreCat T of CQuiver T := { is_hprecat : Quiver_IsPreCat (transpose T) }. #[short(type="hprecat")] -HB.structure Definition HPreCat : Set := { C of Quiver_IsPreCat (transpose C) }. +HB.structure Definition HPreCat : Set := + { C of Quiver_IsPreCat (transpose C) }. Set Universe Checking. (* The category based on the HQuiver (i.e. horizontal category on D0 objects) *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsHCat T of HPreCat T := { +HB.mixin Record _IsHCat T of HPreCat T := { is_hcat : PreCat_IsCat (transpose T) }. #[short(type="hcat")] -HB.structure Definition HCat : Set := { C of IsHCat C }. +HB.structure Definition HCat : Set := + { C of PreCat_IsCat (transpose C) }. Set Universe Checking. @@ -1193,19 +1196,21 @@ Set Universe Checking. vertical 2-cell composition. *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsC2PreCat T of DQuiver T := { +HB.mixin Record _IsC2PreCat T of DQuiver T := { is_c2precat : Quiver_IsPreCat (@HHomSet T) }. #[short(type="c2precat")] -HB.structure Definition C2PreCat : Set := { C of IsC2PreCat C }. +HB.structure Definition C2PreCat : Set := + { C of Quiver_IsPreCat (@HHomSet C) }. Set Universe Checking. (* The category based on the DQuiver (i.e. category D1). *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsC2Cat T of C2PreCat T := { +HB.mixin Record _IsC2Cat T of C2PreCat T := { is_c2cat : PreCat_IsCat (@HHomSet T) }. #[short(type="c2cat")] -HB.structure Definition C2Cat : Set := { C of IsC2Cat C }. +HB.structure Definition C2Cat : Set := + { C of PreCat_IsCat (@HHomSet C) }. Set Universe Checking. @@ -1215,7 +1220,7 @@ Set Universe Checking. category without horizontal operators and functors *) Unset Universe Checking. #[short(type="vdcat")] - HB.structure Definition VDCat : Set := +HB.structure Definition VDCat : Set := { C of Cat C & C2Cat C }. Set Universe Checking. @@ -1275,8 +1280,7 @@ Definition H2Second (C: cquiver) (X: @HCompSet C) : HHomSet C := (* horizontal composition functor: D1 * D1 -> D1 *) Definition hhcomp (T: hprecat) (x: HCompSet T) : HHomSet T := match x with - @GC _ _ a b c h1 h2 => @HO T (@hhom T) a c - (@comp (transpose T) a b c h1 h2) end. + @GC _ _ a b c h1 h2 => @HO T (@hhom T) a c (h1 \; h2) end. HB.tag Definition HComp (C: hprecat) := fun (x: HCompSet C) => @hhcomp C x. @@ -1366,17 +1370,17 @@ Set Universe Checking. (* 2-cell source *) Definition HC2Source (T: SFunctor.type) (a b: @HHomSet T) (m: @c2hom T a b) : - @hom T (HSource a) (HSource b) := @Fhom _ _ (@HSource T) a b m. + (HSource a) ~> (HSource b) := (@HSource T) <$> m. (* 2-cell target *) Definition HC2Target (T: TFunctor.type) (a b: @HHomSet T) (m: @c2hom T a b) : - @hom T (HTarget a) (HTarget b) := @Fhom _ _ (@HTarget T) a b m. + (HTarget a) ~> (HTarget b) := (@HTarget T) <$> m. (* horizontal 2-cell unit (maps vertical morphisms to horizontally unitary 2-cells) *) Definition HC2Unit (T: UFunctor.type) (a b: T) (m: @hom T a b) : - c2hom (HUnit a) (HUnit b) := @Fhom _ _ (@HUnit T) a b m. + (HUnit a) ~> (HUnit b) := (@HUnit T) <$> m. (** Horizontal product category (D1 *d0 D1) *) @@ -1387,12 +1391,12 @@ Definition HC2Unit (T: UFunctor.type) (a b: T) (m: @hom T a b) : (* horizontal composition of two (naked) horizontal morphisms *) Definition l_hcomp (T: NDCat.type) (a0 a1 a2: T) (h0: hhom a0 a1) (h1: hhom a1 a2) : HHomSet T := - @HO T _ a0 a2 (@comp (transpose T) a0 a1 a2 h0 h1). + @HO T _ a0 a2 (h0 \; h1). Notation "'sigma' x .. y , p" := (sigT (fun x => .. (sigT (fun y => p)) ..)) (at level 200, x binder, right associativity, - format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") + format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") : type_scope. (** HCompSet quiver *) @@ -1452,7 +1456,7 @@ Definition HComp_comp_auxS (T : STUFunctor.type) (hhB0 : C2Hom (h_first B) (h_first C)) (hhB1 : C2Hom (h_second B) (h_second C)) (ppB : HC2Target hhB0 = HC2Source hhB1) : - HC2Source (comp hhA1 hhB1) = comp (HC2Source hhA1) (HC2Source hhB1). + HC2Source (hhA1 \; hhB1) = (HC2Source hhA1) \; (HC2Source hhB1). unfold HC2Source, HSource. repeat rewrite Fcomp. reflexivity. @@ -1466,7 +1470,7 @@ Definition HComp_comp_auxT (T : STUFunctor.type) (hhB0 : C2Hom (h_first B) (h_first C)) (hhB1 : C2Hom (h_second B) (h_second C)) (ppB : HC2Target hhB0 = HC2Source hhB1) : - HC2Target (comp hhA0 hhB0) = comp (HC2Target hhA0) (HC2Target hhB0). + HC2Target (hhA0 \; hhB0) = (HC2Target hhA0) \; (HC2Target hhB0). unfold HC2Target, HTarget. repeat rewrite Fcomp. reflexivity. @@ -1489,12 +1493,11 @@ Definition HComp_comp_auxI (T : STUFunctor.type) Defined. (* HCompSet composition, defined in proof mode *) -Definition HComp_comp (T: STUFunctor.type) (A B C: HCompSet T) - (chA: A ~> B) (chB: B ~> C) : A ~> C. - destruct chA as [hhA0 pA]. - destruct chB as [hhB0 pB]. - destruct pA as [hhA1 ppA]. - destruct pB as [hhB1 ppB]. +Definition HComp_comp (T: STUFunctor.type) (A B C: HCompSet T) : + (A ~> B) -> (B ~> C) -> A ~> C. + intros chA chB. + destruct chA as [hhA0 [hhA1 ppA]]. + destruct chB as [hhB0 [hhB1 ppB]]. eapply HComp_comp_auxI; eauto. Defined. From d2e0580fbf1bce86737e7f813912b1df6e66f233 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Sun, 19 Nov 2023 19:46:09 +0100 Subject: [PATCH 093/147] encatB.v: renamed definition to be consistent with slide presentation --- theories/encatB.v | 479 ++++++++++++++++++++++++---------------------- 1 file changed, 247 insertions(+), 232 deletions(-) diff --git a/theories/encatB.v b/theories/encatB.v index 162a420dd..6b1d40250 100644 --- a/theories/encatB.v +++ b/theories/encatB.v @@ -1097,33 +1097,45 @@ Set Universe Checking. (* Strict double categories, from https://ncatlab.org/nlab/show/double+category - (we don't use internal categories though) + (we don't use internal categories) - base obejcts (D0): C ; + base obejcts as 0-cells: C ; - vertical morphisms (for V-D0): @hom C ; + vertical 1-morphisms (category D0 on C): hom C ; - horizontal morphisms (for H-D0) : @hom (transpose C) ; + horizontal 1-morphisms (category H on C): hom (transpose C) ; - horizontal morhisms as 2-objects (for D1): @HHomSet C ; + horizontal 1-morhisms as 1-cells for D1: D1obj C ; - 2-morphisms (for D1): @hom (@HHomSet C) + 2-morphisms (category D1 on C1obj): hom (D1obj C) ; - The definition of Strict Double Category (D0, D1) is given by: + horizontally composable pairs of 1-cells : DPobj C ; - - vertical base category (V-D0) + horizontally composable pairs of 2-morphisms + (product category DP, D1 *0 D1) : hom (DPobj C) ; - - horizontal base category (H-D0) + The definition of Strict Double Category, SDouble = (D0, H, D1, Dp), + is given by: - - vertical 2-level category (D1) + - base objects C - - source functor : D1 -> V-D0 + - (level-1) category (D0) of vertical 1-morphism on C - - target functor : D1 -> V-D0 + - (level-1) category (H) of horizontal 1-morphism (D1obj) on C - - horizontal unit functor : V-D0 -> D1 + - (level-2) category (D1) of vertical 2-morphism on D1obj - - horizontal composition functor : D1 *0 D1 -> D1 + - (derived) category (DP) of vertical 2-morphisms on + horizontally D0-composable D1 products + ($\mbox{D1} *_0 \mbox{D1}$) + + - Source functor: $\mbox{D1} \to \mbox{D0}$ + + - Target functor: $\mbox{D1} \to \mbox{D0}$ + + - Horizontal unit functor: $\mbox{D0} \to \mbox{D1}$ + + - Horizontal composition functor: $\mbox{DP} \to \mbox{D1}$ *) @@ -1137,30 +1149,32 @@ HB.tag Definition transpose (C : quiver) : U := C. }. (* vertical and horizontal quivers, defining cells *) Unset Universe Checking. -#[short(type="cquiver")] -HB.structure Definition CQuiver : Set := +#[short(type="vhquiver")] +HB.structure Definition VHQuiver : Set := { C of IsQuiver C & IsQuiver (transpose C) }. Set Universe Checking. -HB.tag Definition hhom (c : CQuiver.type) : c -> c -> U := @hom (transpose c). +HB.tag Definition hhom (c : VHQuiver.type) : c -> c -> U := @hom (transpose c). +Notation "a +> b" := (hhom a b) + (at level 99, b at level 200, format "a +> b") : cat_scope. (* record to represent the set of morphims (needed for 2-objects, i.e. horizontal morphisms) *) -Record Total2 T (h: T -> T -> U) : Type := HO { +Record Total2 T (h: T -> T -> U) : Type := TT2 { source : T; target : T; this_morph : h source target }. (* the set of horizontal morphisms. *) -HB.tag Definition HHomSet (C: cquiver) := Total2 (@hhom C). +HB.tag Definition D1obj (C: vhquiver) := Total2 (@hhom C). (* D1 quiver requirement (includes D0 quiver and its transpose). *) #[wrapper] -HB.mixin Record _IsDQuiver T of CQuiver T := - { is_dquiver : Quiver (HHomSet T) }. +HB.mixin Record _IsDQuiver T of VHQuiver T := + { is_dquiver : Quiver (D1obj T) }. Unset Universe Checking. #[short(type="dquiver")] -HB.structure Definition DQuiver : Set := { C of Quiver (HHomSet C) }. +HB.structure Definition DQuiver : Set := { C of Quiver (D1obj C) }. Set Universe Checking. @@ -1170,7 +1184,7 @@ Set Universe Checking. objects) *) Unset Universe Checking. #[wrapper] -HB.mixin Record _IsHPreCat T of CQuiver T := { +HB.mixin Record _IsHPreCat T of VHQuiver T := { is_hprecat : Quiver_IsPreCat (transpose T) }. #[short(type="hprecat")] HB.structure Definition HPreCat : Set := @@ -1189,28 +1203,28 @@ HB.structure Definition HCat : Set := Set Universe Checking. -(** Horizontal 2-cell level category (D1 category) *) +(** Vertical 2-cell level category (D1 category) *) (* Precategory based on the DQuiver (i.e. precategory D1). Gives: vertical 2-cell identity morphism. vertical 2-cell composition. *) Unset Universe Checking. #[wrapper] -HB.mixin Record _IsC2PreCat T of DQuiver T := { - is_c2precat : Quiver_IsPreCat (@HHomSet T) }. -#[short(type="c2precat")] -HB.structure Definition C2PreCat : Set := - { C of Quiver_IsPreCat (@HHomSet C) }. +HB.mixin Record _IsD1PreCat T of DQuiver T := { + is_d1precat : Quiver_IsPreCat (@D1obj T) }. +#[short(type="d1precat")] +HB.structure Definition D1PreCat : Set := + { C of Quiver_IsPreCat (@D1obj C) }. Set Universe Checking. (* The category based on the DQuiver (i.e. category D1). *) Unset Universe Checking. #[wrapper] -HB.mixin Record _IsC2Cat T of C2PreCat T := { - is_c2cat : PreCat_IsCat (@HHomSet T) }. -#[short(type="c2cat")] -HB.structure Definition C2Cat : Set := - { C of PreCat_IsCat (@HHomSet C) }. +HB.mixin Record _IsD1Cat T of D1PreCat T := { + is_d1cat : PreCat_IsCat (@D1obj T) }. +#[short(type="d1cat")] +HB.structure Definition D1Cat : Set := + { C of PreCat_IsCat (@D1obj C) }. Set Universe Checking. @@ -1219,41 +1233,43 @@ Set Universe Checking. (* Naked double category. Vertical (V-D0) and D1 categories. Double category without horizontal operators and functors *) Unset Universe Checking. -#[short(type="vdcat")] -HB.structure Definition VDCat : Set := - { C of Cat C & C2Cat C }. +#[short(type="dcat")] +HB.structure Definition DCat : Set := + { C of Cat C & D1Cat C }. Set Universe Checking. (* Naked strict double category. Vertical (V-D0), horizontal (H-D0) and D1 categories. Strict double category without functors *) Unset Universe Checking. -#[short(type="nd2cat")] -HB.structure Definition NDCat : Set := { C of Cat C & HCat C & C2Cat C }. +#[short(type="sd2cat")] +HB.structure Definition SDCat : Set := { C of Cat C & HCat C & D1Cat C }. Set Universe Checking. (** Auxiliary notions for Source, Target and Horizontal Unit functors *) + + (* homsets of 2-cell (D1) morphisms *) -Definition c2hom (D: DQuiver.type) : HHomSet D -> HHomSet D -> U := - @hom (HHomSet D). +Definition d1hom (D: DQuiver.type) : D1obj D -> D1obj D -> U := + @hom (D1obj D). (* type-level smart constructor for D1 homsets *) -Definition C2Hom (D: DQuiver.type) (a b c d: D) (h0: hhom a b) - (h1: hhom c d) : U := c2hom (HO h0) (HO h1). +Definition D1hom (D: DQuiver.type) (a b c d: D) (h0: hhom a b) + (h1: hhom c d) : U := d1hom (TT2 h0) (TT2 h1). (* smart projections for: source functor (for horizontal morphisms): D1 -> D0. defined as object-level function, by functoriality lifted to a (2-cell, vertical) morphism-level one *) -HB.tag Definition HSource C := fun (X: HHomSet C) => @source C (@hhom C) X. +HB.tag Definition HSource C := fun (X: D1obj C) => @source C (@hhom C) X. (* target functor (for horizontal morphisms): D1 -> D0. *) -HB.tag Definition HTarget C := fun (X: HHomSet C) => @target C (@hhom C) X. +HB.tag Definition HTarget C := fun (X: D1obj C) => @target C (@hhom C) X. (* horizontal unit functor: D0 -> D1 *) -Definition hhunit (T: hprecat) (a: T) : HHomSet T := - @HO T (@hhom T) a a (@idmap (transpose T) a). -HB.tag Definition HUnit (C: hprecat) := +Definition hhunit (T: hprecat) (a: T) : D1obj T := + @TT2 T (@hhom T) a a (@idmap (transpose T) a). +HB.tag Definition H1Unit (C: hprecat) := fun (x: HPreCat.sort C) => @hhunit C x. @@ -1268,21 +1284,21 @@ Record GenComp T (h: T -> T -> U) := GC { h_second : h h_two h_three }. (* composable pairs of horizontal morphisms as a set *) -HB.tag Definition HCompSet (C: cquiver) := GenComp (@hhom C). +HB.tag Definition DPobj (C: vhquiver) := GenComp (@hhom C). (* smart projections *) -Definition H2First (C: cquiver) (X: @HCompSet C) : HHomSet C := - @HO C _ (h_one X) (h_two X) (h_first X). -Definition H2Second (C: cquiver) (X: @HCompSet C) : HHomSet C := - @HO C _ (h_two X) (h_three X) (h_second X). +Definition H2First (C: vhquiver) (X: @DPobj C) : D1obj C := + @TT2 C _ (h_one X) (h_two X) (h_first X). +Definition H2Second (C: vhquiver) (X: @DPobj C) : D1obj C := + @TT2 C _ (h_two X) (h_three X) (h_second X). (* horizontal composition functor: D1 * D1 -> D1 *) -Definition hhcomp (T: hprecat) (x: HCompSet T) : HHomSet T := +Definition hhcomp (T: hprecat) (x: DPobj T) : D1obj T := match x with - @GC _ _ a b c h1 h2 => @HO T (@hhom T) a c (h1 \; h2) end. -HB.tag Definition HComp (C: hprecat) := - fun (x: HCompSet C) => @hhcomp C x. + @GC _ _ a b c h1 h2 => @TT2 T (@hhom T) a c (h1 \; h2) end. +HB.tag Definition H1Comp (C: hprecat) := + fun (x: DPobj C) => @hhcomp C x. (* hhunit - horizontal unit functor. @@ -1306,20 +1322,20 @@ HB.tag Definition HComp (C: hprecat) := (** Source and target functors *) (* source prefunctor. - HHomSet T is the quiver of the 2-morphisms, thanks to CQuiver. + D1obj T is the quiver of the 2-morphisms, thanks to VHQuiver. T is the quiver of 1-morphisms. *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsSPreFunctor T of VDCat T := { - is_sprefunctor : IsPreFunctor (HHomSet T) T (@HSource T) }. +HB.mixin Record IsSPreFunctor T of DCat T := { + is_sprefunctor : IsPreFunctor (D1obj T) T (@HSource T) }. HB.structure Definition SPreFunctor : Set := {C of IsSPreFunctor C}. Set Universe Checking. (* target prefunctor. *) Unset Universe Checking. #[wrapper] - HB.mixin Record IsTPreFunctor T of VDCat T := { - is_tprefunctor : IsPreFunctor (HHomSet T) T (@HTarget T) }. + HB.mixin Record IsTPreFunctor T of DCat T := { + is_tprefunctor : IsPreFunctor (D1obj T) T (@HTarget T) }. HB.structure Definition TPreFunctor : Set := {C of IsTPreFunctor C}. Set Universe Checking. @@ -1327,7 +1343,7 @@ Set Universe Checking. Unset Universe Checking. #[wrapper] HB.mixin Record SPreFunctor_IsFunctor T of SPreFunctor T := { - is_sfunctor : PreFunctor_IsFunctor (HHomSet T) T (@HSource T) }. + is_sfunctor : PreFunctor_IsFunctor (D1obj T) T (@HSource T) }. HB.structure Definition SFunctor : Set := {C of SPreFunctor_IsFunctor C}. Set Universe Checking. @@ -1335,7 +1351,7 @@ Set Universe Checking. Unset Universe Checking. #[wrapper] HB.mixin Record TPreFunctor_IsFunctor T of TPreFunctor T := { - is_tfunctor : PreFunctor_IsFunctor (HHomSet T) T (@HTarget T) }. + is_tfunctor : PreFunctor_IsFunctor (D1obj T) T (@HTarget T) }. HB.structure Definition TFunctor : Set := {C of TPreFunctor_IsFunctor C}. Set Universe Checking. @@ -1345,8 +1361,8 @@ Set Universe Checking. (* unit prefunctor. *) Unset Universe Checking. #[wrapper] -HB.mixin Record IsUPreFunctor T of NDCat T := - { is_uprefunctor : IsPreFunctor T (HHomSet T) (@HUnit T) }. +HB.mixin Record IsUPreFunctor T of SDCat T := + { is_uprefunctor : IsPreFunctor T (D1obj T) (@H1Unit T) }. HB.structure Definition UPreFunctor : Set := {C of IsUPreFunctor C}. Set Universe Checking. @@ -1354,7 +1370,7 @@ Set Universe Checking. Unset Universe Checking. #[wrapper] HB.mixin Record UPreFunctor_IsFunctor T of UPreFunctor T := { - is_ufunctor : PreFunctor_IsFunctor T (HHomSet T) (@HUnit T) }. + is_ufunctor : PreFunctor_IsFunctor T (D1obj T) (@H1Unit T) }. HB.structure Definition UFunctor : Set := {C of UPreFunctor_IsFunctor C}. Set Universe Checking. @@ -1368,30 +1384,30 @@ Set Universe Checking. (** Lifting of Source, Target and Unit functors to D1 morphisms *) (* 2-cell source *) -Definition HC2Source (T: SFunctor.type) (a b: @HHomSet T) - (m: @c2hom T a b) : +Definition H1Source (T: SFunctor.type) (a b: @D1obj T) + (m: @d1hom T a b) : (HSource a) ~> (HSource b) := (@HSource T) <$> m. (* 2-cell target *) -Definition HC2Target (T: TFunctor.type) (a b: @HHomSet T) - (m: @c2hom T a b) : +Definition H1Target (T: TFunctor.type) (a b: @D1obj T) + (m: @d1hom T a b) : (HTarget a) ~> (HTarget b) := (@HTarget T) <$> m. (* horizontal 2-cell unit (maps vertical morphisms to horizontally unitary 2-cells) *) -Definition HC2Unit (T: UFunctor.type) (a b: T) (m: @hom T a b) : - (HUnit a) ~> (HUnit b) := (@HUnit T) <$> m. +Definition H2Unit (T: UFunctor.type) (a b: T) (m: @hom T a b) : + (H1Unit a) ~> (H1Unit b) := (@H1Unit T) <$> m. (** Horizontal product category (D1 *d0 D1) *) -(* HCompSet T is the pseudo-pullback category used to deal with +(* DPobj T is the pseudo-pullback category used to deal with products of D1 (where the adjacency condition is expressed w.r.t. D0 *) (* horizontal composition of two (naked) horizontal morphisms *) -Definition l_hcomp (T: NDCat.type) (a0 a1 a2: T) - (h0: hhom a0 a1) (h1: hhom a1 a2) : HHomSet T := - @HO T _ a0 a2 (h0 \; h1). +Definition l_hcomp (T: SDCat.type) (a0 a1 a2: T) + (h0: hhom a0 a1) (h1: hhom a1 a2) : D1obj T := + @TT2 T _ a0 a2 (h0 \; h1). Notation "'sigma' x .. y , p" := (sigT (fun x => .. (sigT (fun y => p)) ..)) @@ -1399,117 +1415,116 @@ Notation "'sigma' x .. y , p" := format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") : type_scope. -(** HCompSet quiver *) -Definition HComp_hom (T: STUFunctor.type) (x y: HCompSet T) := - sigma (hh0: C2Hom (h_first x) (h_first y)) - (hh1: C2Hom (h_second x) (h_second y)), - HC2Target hh0 = HC2Source hh1. +(** DPobj quiver *) +Definition DP_hom (T: STUFunctor.type) (x y: DPobj T) := + sigma (hh0: D1hom (h_first x) (h_first y)) + (hh1: D1hom (h_second x) (h_second y)), + H1Target hh0 = H1Source hh1. -HB.instance Definition HCompQuiver (T: STUFunctor.type) : - IsQuiver (HCompSet T) := - IsQuiver.Build (HCompSet T) (fun A B => @HComp_hom T A B). +HB.instance Definition DPQuiver (T: STUFunctor.type) : + IsQuiver (DPobj T) := + IsQuiver.Build (DPobj T) (fun A B => @DP_hom T A B). (** Product precategory *) -Lemma HComp_id_eq (T : STUFunctor.type) (a: HCompSet T) : - HC2Target (@idmap (@HHomSet T) (H2First a)) = - HC2Source (@idmap (@HHomSet T) (H2Second a)). -unfold HC2Target, HTarget. -unfold HC2Source, HSource. +Lemma DP_id_eq (T : STUFunctor.type) (a: DPobj T) : + H1Target (@idmap (@D1obj T) (H2First a)) = + H1Source (@idmap (@D1obj T) (H2Second a)). +unfold H1Target, HTarget. +unfold H1Source, HSource. repeat rewrite F1; auto. Defined. -(* HCompSet identity *) -Definition HComp_id (T: STUFunctor.type) (A: HCompSet T) : A ~> A := +(* DPobj identity *) +Definition DP_id (T: STUFunctor.type) (A: DPobj T) : A ~> A := let h0 := h_first A in let h1 := h_second A - in let uu0 := @idmap (HHomSet T) (HO h0) - in let uu1 := @idmap (HHomSet T) (HO h1) - in @existT (C2Hom h0 h0) - (fun hh0: (C2Hom h0 h0) => - sigma (hh1 : C2Hom h1 h1), HC2Target hh0 = HC2Source hh1) uu0 - (@existT (C2Hom h1 h1) - (fun hh1: (C2Hom h1 h1) => HC2Target uu0 = HC2Source hh1) uu1 - (@HComp_id_eq T A)). - -Definition HComp_comp_auxA (T : STUFunctor.type) - (A B C : HCompSet T) - (hhA0 : C2Hom (h_first A) (h_first B)) - (hhA1 : C2Hom (h_second A) (h_second B)) - (ppA : HC2Target hhA0 = HC2Source hhA1) - (hhB0 : C2Hom (h_first B) (h_first C)) - (hhB1 : C2Hom (h_second B) (h_second C)) - (ppB : HC2Target hhB0 = HC2Source hhB1) : - (HC2Target hhA0) \; (HC2Target hhB0) = - (HC2Source hhA1) \; (HC2Source hhB1). + in let uu0 := @idmap (D1obj T) (TT2 h0) + in let uu1 := @idmap (D1obj T) (TT2 h1) + in @existT (D1hom h0 h0) + (fun hh0: (D1hom h0 h0) => + sigma (hh1 : D1hom h1 h1), H1Target hh0 = H1Source hh1) uu0 + (@existT (D1hom h1 h1) + (fun hh1: (D1hom h1 h1) => H1Target uu0 = H1Source hh1) uu1 + (@DP_id_eq T A)). + +Definition DP_comp_auxA (T : STUFunctor.type) + (A B C : DPobj T) + (hhA0 : D1hom (h_first A) (h_first B)) + (hhA1 : D1hom (h_second A) (h_second B)) + (ppA : H1Target hhA0 = H1Source hhA1) + (hhB0 : D1hom (h_first B) (h_first C)) + (hhB1 : D1hom (h_second B) (h_second C)) + (ppB : H1Target hhB0 = H1Source hhB1) : + (H1Target hhA0) \; (H1Target hhB0) = + (H1Source hhA1) \; (H1Source hhB1). rewrite ppA. rewrite ppB. reflexivity. Defined. -Definition HComp_comp_auxS (T : STUFunctor.type) - (A B C : HCompSet T) - (hhA0 : C2Hom (h_first A) (h_first B)) - (hhA1 : C2Hom (h_second A) (h_second B)) - (ppA : HC2Target hhA0 = HC2Source hhA1) - (hhB0 : C2Hom (h_first B) (h_first C)) - (hhB1 : C2Hom (h_second B) (h_second C)) - (ppB : HC2Target hhB0 = HC2Source hhB1) : - HC2Source (hhA1 \; hhB1) = (HC2Source hhA1) \; (HC2Source hhB1). - unfold HC2Source, HSource. +Definition DP_comp_auxS (T : STUFunctor.type) + (A B C : DPobj T) + (hhA0 : D1hom (h_first A) (h_first B)) + (hhA1 : D1hom (h_second A) (h_second B)) + (ppA : H1Target hhA0 = H1Source hhA1) + (hhB0 : D1hom (h_first B) (h_first C)) + (hhB1 : D1hom (h_second B) (h_second C)) + (ppB : H1Target hhB0 = H1Source hhB1) : + H1Source (hhA1 \; hhB1) = (H1Source hhA1) \; (H1Source hhB1). + unfold H1Source, HSource. repeat rewrite Fcomp. reflexivity. Defined. -Definition HComp_comp_auxT (T : STUFunctor.type) - (A B C : HCompSet T) - (hhA0 : C2Hom (h_first A) (h_first B)) - (hhA1 : C2Hom (h_second A) (h_second B)) - (ppA : HC2Target hhA0 = HC2Source hhA1) - (hhB0 : C2Hom (h_first B) (h_first C)) - (hhB1 : C2Hom (h_second B) (h_second C)) - (ppB : HC2Target hhB0 = HC2Source hhB1) : - HC2Target (hhA0 \; hhB0) = (HC2Target hhA0) \; (HC2Target hhB0). - unfold HC2Target, HTarget. +Definition DP_comp_auxT (T : STUFunctor.type) + (A B C : DPobj T) + (hhA0 : D1hom (h_first A) (h_first B)) + (hhA1 : D1hom (h_second A) (h_second B)) + (ppA : H1Target hhA0 = H1Source hhA1) + (hhB0 : D1hom (h_first B) (h_first C)) + (hhB1 : D1hom (h_second B) (h_second C)) + (ppB : H1Target hhB0 = H1Source hhB1) : + H1Target (hhA0 \; hhB0) = (H1Target hhA0) \; (H1Target hhB0). + unfold H1Target, HTarget. repeat rewrite Fcomp. reflexivity. Defined. -Definition HComp_comp_auxI (T : STUFunctor.type) - (A B C : HCompSet T) - (hhA0 : C2Hom (h_first A) (h_first B)) - (hhA1 : C2Hom (h_second A) (h_second B)) - (ppA : HC2Target hhA0 = HC2Source hhA1) - (hhB0 : C2Hom (h_first B) (h_first C)) - (hhB1 : C2Hom (h_second B) (h_second C)) - (ppB : HC2Target hhB0 = HC2Source hhB1) : +Definition DP_comp_auxI (T : STUFunctor.type) + (A B C : DPobj T) + (hhA0 : D1hom (h_first A) (h_first B)) + (hhA1 : D1hom (h_second A) (h_second B)) + (ppA : H1Target hhA0 = H1Source hhA1) + (hhB0 : D1hom (h_first B) (h_first C)) + (hhB1 : D1hom (h_second B) (h_second C)) + (ppB : H1Target hhB0 = H1Source hhB1) : A ~> C. econstructor 1 with (comp hhA0 hhB0). econstructor 1 with (comp hhA1 hhB1). - setoid_rewrite HComp_comp_auxS; eauto. - setoid_rewrite HComp_comp_auxT; eauto. - eapply HComp_comp_auxA; eauto. + setoid_rewrite DP_comp_auxS; eauto. + setoid_rewrite DP_comp_auxT; eauto. + eapply DP_comp_auxA; eauto. Defined. -(* HCompSet composition, defined in proof mode *) -Definition HComp_comp (T: STUFunctor.type) (A B C: HCompSet T) : +(* DPobj composition, defined in proof mode *) +Definition DP_comp (T: STUFunctor.type) (A B C: DPobj T) : (A ~> B) -> (B ~> C) -> A ~> C. intros chA chB. destruct chA as [hhA0 [hhA1 ppA]]. destruct chB as [hhB0 [hhB1 ppB]]. - eapply HComp_comp_auxI; eauto. + eapply DP_comp_auxI; eauto. Defined. -(* HCompSet is a precategory *) -HB.instance Definition HCompPreCat (T: STUFunctor.type) : - Quiver_IsPreCat (HCompSet T) := - Quiver_IsPreCat.Build (HCompSet T) - (@HComp_id T) (@HComp_comp T). +(* DPobj is a precategory *) +HB.instance Definition DPPreCat (T: STUFunctor.type) : + Quiver_IsPreCat (DPobj T) := + Quiver_IsPreCat.Build (DPobj T) (@DP_id T) (@DP_comp T). (* have HcompP : - (a b : HCompSet T) + (a b : DPobj T) (f g : a ~> b), proj1T f = proj1t f -> @@ -1523,15 +1538,15 @@ HB.instance Definition HCompPreCat (T: STUFunctor.type) : (** Product category *) -Lemma HComp_LeftUnit_lemma (T : STUFunctor.type) : - forall (a b : HCompSet T) (f : a ~> b), idmap \; f = f. +Lemma DP_LeftUnit_lemma (T : STUFunctor.type) : + forall (a b : DPobj T) (f : a ~> b), idmap \; f = f. move => a b [x [x0 e]] /=. simpl in *. unfold idmap; simpl. - unfold HComp_id; simpl. + unfold DP_id; simpl. unfold comp; simpl. - unfold HComp_comp_auxI; simpl. + unfold DP_comp_auxI; simpl. assert (idmap \; x = x) as A. { rewrite comp1o; auto. } @@ -1539,7 +1554,7 @@ Lemma HComp_LeftUnit_lemma (T : STUFunctor.type) : assert (idmap \; x0 = x0) as A0. { rewrite comp1o; auto. } - assert (HC2Target (idmap \; x) = HC2Source (idmap \; x0)) as B. + assert (H1Target (idmap \; x) = H1Source (idmap \; x0)) as B. { rewrite A. rewrite A0; auto. } @@ -1548,20 +1563,20 @@ Lemma HComp_LeftUnit_lemma (T : STUFunctor.type) : simpl. assert (existT - (fun hh0 : C2Hom h_first0 h_first1 => - sigma hh1 : C2Hom h_second0 h_second1,HC2Target hh0 = HC2Source hh1) + (fun hh0 : D1hom h_first0 h_first1 => + sigma hh1 : D1hom h_second0 h_second1,H1Target hh0 = H1Source hh1) (idmap \; x) (existT - (fun hh1 : C2Hom h_second0 h_second1 => - HC2Target (idmap \; x) = HC2Source hh1) + (fun hh1 : D1hom h_second0 h_second1 => + H1Target (idmap \; x) = H1Source hh1) (idmap \; x0) B) = existT - (fun hh0 : C2Hom h_first0 h_first1 => - sigma hh1 : C2Hom h_second0 h_second1,HC2Target hh0 = HC2Source hh1) + (fun hh0 : D1hom h_first0 h_first1 => + sigma hh1 : D1hom h_second0 h_second1,H1Target hh0 = H1Source hh1) x (existT - (fun hh1 : C2Hom h_second0 h_second1 => HC2Target x = HC2Source hh1) + (fun hh1 : D1hom h_second0 h_second1 => H1Target x = H1Source hh1) x0 e)) as C. { revert B. @@ -1588,15 +1603,15 @@ Lemma HComp_LeftUnit_lemma (T : STUFunctor.type) : eapply C. Qed. -Lemma HComp_RightUnit_lemma (T : STUFunctor.type) : - forall (a b : HCompSet T) (f : a ~> b), f \; idmap = f. +Lemma DP_RightUnit_lemma (T : STUFunctor.type) : + forall (a b : DPobj T) (f : a ~> b), f \; idmap = f. move => a b [x [x0 e]] /=. simpl in *. unfold idmap; simpl. - unfold HComp_id; simpl. + unfold DP_id; simpl. unfold comp; simpl. - unfold HComp_comp_auxI; simpl. + unfold DP_comp_auxI; simpl. assert (x \; idmap = x) as A. { rewrite compo1; auto. } @@ -1604,7 +1619,7 @@ Lemma HComp_RightUnit_lemma (T : STUFunctor.type) : assert (x0 \; idmap = x0) as A0. { rewrite compo1; auto. } - assert (HC2Target (x \; idmap) = HC2Source (x0 \; idmap)) as B. + assert (H1Target (x \; idmap) = H1Source (x0 \; idmap)) as B. { rewrite A. rewrite A0; auto. } @@ -1613,23 +1628,23 @@ Lemma HComp_RightUnit_lemma (T : STUFunctor.type) : simpl. assert (existT - (fun hh0 : C2Hom h_first0 h_first1 => - sigma hh1 : C2Hom h_second0 h_second1, - HC2Target hh0 = HC2Source hh1) + (fun hh0 : D1hom h_first0 h_first1 => + sigma hh1 : D1hom h_second0 h_second1, + H1Target hh0 = H1Source hh1) (x \; idmap) (existT - (fun hh1 : C2Hom h_second0 h_second1 => - HC2Target (x \; idmap) = HC2Source hh1) + (fun hh1 : D1hom h_second0 h_second1 => + H1Target (x \; idmap) = H1Source hh1) (x0 \; idmap) B) = existT - (fun hh0 : C2Hom h_first0 h_first1 => - sigma hh1 : C2Hom h_second0 h_second1, - HC2Target hh0 = HC2Source hh1) + (fun hh0 : D1hom h_first0 h_first1 => + sigma hh1 : D1hom h_second0 h_second1, + H1Target hh0 = H1Source hh1) x (existT - (fun hh1 : C2Hom h_second0 h_second1 => - HC2Target x = HC2Source hh1) + (fun hh1 : D1hom h_second0 h_second1 => + H1Target x = H1Source hh1) x0 e)) as C. { revert B. @@ -1656,8 +1671,8 @@ Lemma HComp_RightUnit_lemma (T : STUFunctor.type) : eapply C. Qed. -Lemma HComp_Assoc_lemma (T : STUFunctor.type) : - forall (a b c d : HCompSet T) (f : a ~> b) (g : b ~> c) (h : c ~> d), +Lemma DP_Assoc_lemma (T : STUFunctor.type) : + forall (a b c d : DPobj T) (f : a ~> b) (g : b ~> c) (h : c ~> d), f \; g \; h = (f \; g) \; h. intros. remember f as f1. @@ -1687,14 +1702,14 @@ Lemma HComp_Assoc_lemma (T : STUFunctor.type) : { subst y0_12 y01_2. rewrite compoA; eauto. } - set (x01_t := comp (HC2Target x0) (HC2Target x1)). - set (x01_2_t := comp x01_t (HC2Target x2)). - set (x12_t := comp (HC2Target x1) (HC2Target x2)). - set (x0_12_t := comp (HC2Target x0) x12_t). - set (y01_s := comp (HC2Source y0) (HC2Source y1)). - set (y01_2_s := comp y01_s (HC2Source y2)). - set (y12_s := comp (HC2Source y1) (HC2Source y2)). - set (y0_12_s := comp (HC2Source y0) y12_s). + set (x01_t := comp (H1Target x0) (H1Target x1)). + set (x01_2_t := comp x01_t (H1Target x2)). + set (x12_t := comp (H1Target x1) (H1Target x2)). + set (x0_12_t := comp (H1Target x0) x12_t). + set (y01_s := comp (H1Source y0) (H1Source y1)). + set (y01_2_s := comp y01_s (H1Source y2)). + set (y12_s := comp (H1Source y1) (H1Source y2)). + set (y0_12_s := comp (H1Source y0) y12_s). assert (x01_t = y01_s) as E01. { subst x01_t y01_s. @@ -1724,58 +1739,58 @@ Lemma HComp_Assoc_lemma (T : STUFunctor.type) : unfold comp. simpl. - unfold HComp_comp. + unfold DP_comp. simpl. inversion Heqf1; subst. clear H. - unfold HComp_comp_auxI; simpl. + unfold DP_comp_auxI; simpl. - assert (HC2Target (x0 \; x1 \; x2) = - HC2Source (y0 \; y1 \; y2)) as KR. + assert (H1Target (x0 \; x1 \; x2) = + H1Source (y0 \; y1 \; y2)) as KR. { subst x0_12_t y0_12_s. subst x12_t y12_s. - unfold HC2Target. + unfold H1Target. repeat rewrite Fcomp; simpl. - unfold HC2Target in E0_12. + unfold H1Target in E0_12. rewrite E0_12. - unfold HC2Source. + unfold H1Source. repeat rewrite Fcomp; simpl. auto. } - assert (HC2Target ((x0 \; x1) \; x2) = - HC2Source ((y0 \; y1) \; y2)) as KL. + assert (H1Target ((x0 \; x1) \; x2) = + H1Source ((y0 \; y1) \; y2)) as KL. { subst x01_2_t y01_2_s. subst x01_t y01_s. - unfold HC2Target. + unfold H1Target. repeat rewrite Fcomp; simpl. - unfold HC2Target in E01_2. + unfold H1Target in E01_2. rewrite E01_2. - unfold HC2Source. + unfold H1Source. repeat rewrite Fcomp; simpl. auto. } assert (existT - (fun hh0 : C2Hom (h_first a) (h_first d) => - sigma hh1 : C2Hom (h_second a) (h_second d), - HC2Target hh0 = HC2Source hh1) + (fun hh0 : D1hom (h_first a) (h_first d) => + sigma hh1 : D1hom (h_second a) (h_second d), + H1Target hh0 = H1Source hh1) (x0 \; x1 \; x2) (existT - (fun hh1 : C2Hom (h_second a) (h_second d) => - HC2Target (x0 \; x1 \; x2) = HC2Source hh1) + (fun hh1 : D1hom (h_second a) (h_second d) => + H1Target (x0 \; x1 \; x2) = H1Source hh1) (y0 \; y1 \; y2) KR) = existT - (fun hh0 : C2Hom (h_first a) (h_first d) => - sigma hh1 : C2Hom (h_second a) (h_second d), - HC2Target hh0 = HC2Source hh1) + (fun hh0 : D1hom (h_first a) (h_first d) => + sigma hh1 : D1hom (h_second a) (h_second d), + H1Target hh0 = H1Source hh1) ((x0 \; x1) \; x2) (existT - (fun hh1 : C2Hom (h_second a) (h_second d) => - HC2Target ((x0 \; x1) \; x2) = HC2Source hh1) + (fun hh1 : D1hom (h_second a) (h_second d) => + H1Target ((x0 \; x1) \; x2) = H1Source hh1) ((y0 \; y1) \; y2) KL)) as KA. { revert KL. @@ -1800,16 +1815,16 @@ Lemma HComp_Assoc_lemma (T : STUFunctor.type) : eapply KA. Qed. -Program Definition HCompCatP (T: STUFunctor.type) : - PreCat_IsCat (HCompSet T). +Program Definition DPCatP (T: STUFunctor.type) : + PreCat_IsCat (DPobj T). econstructor. -eapply HComp_LeftUnit_lemma; eauto. -eapply HComp_RightUnit_lemma; eauto. -eapply HComp_Assoc_lemma; eauto. +eapply DP_LeftUnit_lemma; eauto. +eapply DP_RightUnit_lemma; eauto. +eapply DP_Assoc_lemma; eauto. Qed. -(* HCompSet is a category *) -HB.instance Definition HCompCat (T: STUFunctor.type) := HCompCatP T. +(* DPobj is a category *) +HB.instance Definition DPCat (T: STUFunctor.type) := DPCatP T. (** Horizontal composition functor and strict double categories *) @@ -1818,7 +1833,7 @@ HB.instance Definition HCompCat (T: STUFunctor.type) := HCompCatP T. Unset Universe Checking. #[wrapper] HB.mixin Record IsCPreFunctor T of STUFunctor T := - { is_cprefunctor : IsPreFunctor (HCompSet T) (HHomSet T) (@HComp T) }. + { is_cprefunctor : IsPreFunctor (DPobj T) (D1obj T) (@H1Comp T) }. HB.structure Definition CPreFunctor : Set := {C of IsCPreFunctor C}. Set Universe Checking. @@ -1826,9 +1841,9 @@ Set Universe Checking. Unset Universe Checking. #[wrapper] HB.mixin Record CPreFunctor_IsFunctor T of CPreFunctor T := { - is_cfunctor : PreFunctor_IsFunctor (HCompSet T) (HHomSet T) (@HComp T) }. -#[short(type="dcat")] -HB.structure Definition DCat : Set := {C of CPreFunctor_IsFunctor C}. + is_cfunctor : PreFunctor_IsFunctor (DPobj T) (D1obj T) (@H1Comp T) }. +#[short(type="sdoublecat")] +HB.structure Definition SDoubleCat : Set := {C of CPreFunctor_IsFunctor C}. Set Universe Checking. (* horizontal 2-cell composition: maps two adjecent pairs of @@ -1836,21 +1851,21 @@ Set Universe Checking. between them (m, which basically gives two adjecent cells) to a 2-cell morphism between the horizontal composition (HComp) of each pair *) -Definition HC2Comp (T: DCat.type) (a b: HCompSet T) - (m: @hom (HCompSet T) a b) : - c2hom (HComp a) (HComp b) := @Fhom _ _ (@HComp T) a b m. +Definition HC2Comp (T: SDoubleCat.type) (a b: DPobj T) + (m: @hom (DPobj T) a b) : + d1hom (H1Comp a) (H1Comp b) := @Fhom _ _ (@H1Comp T) a b m. -Program Definition HC2Comp_flat (T: DCat.type) (a0 a1 a2 b0 b1 b2: T) +Program Definition HC2Comp_flat (T: SDoubleCat.type) (a0 a1 a2 b0 b1 b2: T) (h0: hhom a0 a1) (h1: hhom a1 a2) (k0: hhom b0 b1) (k1: hhom b1 b2) - (hh0: C2Hom h0 k0) - (hh1: C2Hom h1 k1) - (k: HC2Target hh0 = HC2Source hh1) - : (* C2Hom (hcomp _ _ _ h0 h1) (hcomp _ _ _ k0 k1) *) - c2hom (l_hcomp h0 h1) (l_hcomp k0 k1) := - @Fhom _ _ (@HComp T) (GC h0 h1) (GC k0 k1) _. + (hh0: D1hom h0 k0) + (hh1: D1hom h1 k1) + (k: H1Target hh0 = H1Source hh1) + : (* D1hom (hcomp _ _ _ h0 h1) (hcomp _ _ _ k0 k1) *) + d1hom (l_hcomp h0 h1) (l_hcomp k0 k1) := + @Fhom _ _ (@H1Comp T) (GC h0 h1) (GC k0 k1) _. Obligation 1. -refine (@existT (C2Hom h0 k0) _ hh0 (@existT (C2Hom h1 k1) _ hh1 k)). +refine (@existT (D1hom h0 k0) _ hh0 (@existT (D1hom h1 k1) _ hh1 k)). Defined. (********************************************************************) From 6fdcfb57f4149c21a77be10edb6f817cf87bdf7f Mon Sep 17 00:00:00 2001 From: ptorrx Date: Fri, 24 Nov 2023 20:01:14 +0100 Subject: [PATCH 094/147] added encatD.v (starting with internal categories) --- theories/encatD.v | 2155 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2155 insertions(+) create mode 100644 theories/encatD.v diff --git a/theories/encatD.v b/theories/encatD.v new file mode 100644 index 000000000..86a44787c --- /dev/null +++ b/theories/encatD.v @@ -0,0 +1,2155 @@ +Require Import ssreflect ssrfun. +From HB Require Import structures. + +Set Implicit Arguments. +Unset Strict Implicit. +Unset Printing Implicit Defensive. +Add Search Blacklist "__canonical__". + +Declare Scope algebra_scope. +Delimit Scope algebra_scope with A. +Local Open Scope algebra_scope. + +Declare Scope cat_scope. +Delimit Scope cat_scope with cat. +Local Open Scope cat_scope. + +(* we assume a few axioms to make life easier *) +Axiom funext : forall {T : Type} {U : T -> Type} [f g : forall t, U t], + (forall t, f t = g t) -> f = g. +Axiom propext : forall P Q : Prop, P <-> Q -> P = Q. +Axiom Prop_irrelevance : forall (P : Prop) (x y : P), x = y. + +(* Shortcut *) +Notation U := Type. + +(* Base definition : raw categories = quivers *) +HB.mixin Record IsQuiver C := { hom : C -> C -> U }. +Unset Universe Checking. +#[short(type="quiver")] +HB.structure Definition Quiver : Set := { C of IsQuiver C }. +Set Universe Checking. + +Bind Scope cat_scope with quiver. +Bind Scope cat_scope with hom. +Arguments hom {C} : rename. +Notation homs T := (@hom T _ _). +Notation "a ~> b" := (hom a b) + (at level 99, b at level 200, format "a ~> b") : cat_scope. +Notation "a ~>_ C b" := (@hom C a b) + (at level 99, C at level 0, only parsing) : cat_scope. + +(* precategories are quivers + id and comp *) +HB.mixin Record Quiver_IsPreCat C of Quiver C := { + idmap : forall (a : C), a ~> a; + comp : forall (a b c : C), (a ~> b) -> (b ~> c) -> (a ~> c); +}. + +HB.factory Record IsPreCat C := { + hom : C -> C -> U; + idmap : forall (a : C), hom a a; + comp : forall (a b c : C), hom a b -> hom b c -> hom a c; +}. +HB.builders Context C of IsPreCat C. + HB.instance Definition _ := IsQuiver.Build C hom. + HB.instance Definition _ := Quiver_IsPreCat.Build C idmap comp. +HB.end. + +Unset Universe Checking. +#[short(type="precat")] +HB.structure Definition PreCat : Set := { C of IsPreCat C }. +Set Universe Checking. + +Bind Scope cat_scope with precat. +Arguments idmap {C} {a} : rename. +Arguments comp {C} {a b c} : rename. +Notation "f \o g" := (comp g f) : cat_scope. +Notation "f \; g :> T" := (@comp T _ _ _ f g) + (at level 60, g, T at level 60, format "f \; g :> T", only parsing) : cat_scope. +Notation "f \; g" := (comp f g) : cat_scope. +Notation "\idmap_ a" := (@idmap _ a) (only parsing, at level 0) : cat_scope. + +(* categories are precategories + laws *) +HB.mixin Record PreCat_IsCat C of PreCat C := { + comp1o : forall (a b : C) (f : a ~> b), idmap \; f = f; + compo1 : forall (a b : C) (f : a ~> b), f \; idmap = f; + compoA : forall (a b c d : C) (f : a ~> b) (g : b ~> c) (h : c ~> d), + f \; (g \; h) = (f \; g) \; h +}. +Unset Universe Checking. +#[short(type="cat")] +HB.structure Definition Cat : Set := { C of PreCat_IsCat C & IsPreCat C }. +Set Universe Checking. + +Bind Scope cat_scope with cat. +Arguments compo1 {C a b} : rename. +Arguments comp1o {C a b} : rename. +Arguments compoA {C a b c d} : rename. + +(* the discrete category on a type cannot be the default, we make an alias *) +Definition discrete (T : U) := T. +HB.instance Definition _ T := @IsPreCat.Build (discrete T) (fun x y => x = y) + (fun=> erefl) (@etrans _). +Lemma etransA T (a b c d : discrete T) (f : a ~> b) (g : b ~> c) (h : c ~> d) : + f \; (g \; h) = (f \; g) \; h. +Proof. by rewrite /idmap/comp/=; case: _ / h; case: _ / g. Qed. +HB.instance Definition _ T := PreCat_IsCat.Build (discrete T) (@etrans_id _) + (fun _ _ _ => erefl) (@etransA _). + +(* the category of the unit type is the discrete one *) +HB.instance Definition _ := Cat.copy unit (discrete unit). + +HB.instance Definition _ := @IsPreCat.Build U (fun A B => A -> B) + (fun a => idfun) (fun a b c (f : a -> b) (g : b -> c) => (g \o f)%FUN). +HB.instance Definition _ := PreCat_IsCat.Build U (fun _ _ _ => erefl) + (fun _ _ _ => erefl) (fun _ _ _ _ _ _ _ => erefl). + + +Lemma Ucomp (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) : f \; g = (g \o f)%FUN. +Proof. by []. Qed. +Lemma Ucompx (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) x : (f \; g) x = g (f x). +Proof. by []. Qed. +Lemma U1 (X : U) : \idmap_X = idfun. +Proof. by []. Qed. +Lemma U1x (X : U) x : \idmap_X x = x. +Proof. by []. Qed. + +(* a prefunctor is a functor without laws *) +HB.mixin Record IsPreFunctor (C D : quiver) (F : C -> D) := { + Fhom : forall (a b : C), (a ~> b) -> (F a ~> F b) +}. + +Unset Universe Checking. +HB.structure Definition PreFunctor (C D : quiver) : Set := + { F of IsPreFunctor C D F }. +Set Universe Checking. +HB.instance Definition _ := IsQuiver.Build quiver PreFunctor.type. + +Notation "F ^$" := (@Fhom _ _ F _ _) + (at level 1, format "F ^$") : cat_scope. +Notation "F <$> f" := (@Fhom _ _ F _ _ f) + (at level 58, format "F <$> f", right associativity) : cat_scope. + +(* prefunctors are equal if their object and hom part are respectively equal *) +Lemma prefunctorP (C D : quiver) (F G : C ~> D) (eqFG : F =1 G) : + let homF a b F := F a ~> F b in + (forall a b f, eq_rect _ (homF a b) (F <$> f) _ (funext eqFG) = G <$> f) -> + F = G. +Proof. +move: F G => [F [[/= Fhom]]] [G [[/= Ghom]]] in eqFG *. +case: _ / (funext eqFG) => /= in Ghom * => eqFGhom. +congr PreFunctor.Pack; congr PreFunctor.Class; congr IsPreFunctor.Axioms_. +by do 3!apply: funext=> ?. +Qed. + +(* a functor is a prefunctor + laws for id and comp *) +HB.mixin Record PreFunctor_IsFunctor (C D : precat) (F : C -> D) + of @PreFunctor C D F := { + F1 : forall (a : C), F <$> \idmap_a = idmap; + Fcomp : forall (a b c : C) (f : a ~> b) (g : b ~> c), + F <$> (f \; g) = F <$> f \; F <$> g; +}. +Unset Universe Checking. + +(* precat and cat have a quiver structure *) +HB.structure Definition Functor (C D : precat) : Set := + { F of IsPreFunctor C D F & PreFunctor_IsFunctor C D F }. +Set Universe Checking. +HB.instance Definition _ := IsQuiver.Build precat Functor.type. +HB.instance Definition _ := IsQuiver.Build cat Functor.type. + +(* functor equality is the same as prefunctor because of PI *) +Lemma functorP (C D : precat) (F G : C ~> D) (eqFG : F =1 G) : + let homF a b F := F a ~> F b in + (forall a b f, eq_rect _ (homF a b) (F^$ f) _ (funext eqFG) = G^$ f) -> + F = G. +Proof. +move=> /= /prefunctorP {eqFG}. +case: F G => [F [/= Fm Fm']] [G [/= Gm Gm']]//=. +move=> [_] /EqdepFacts.eq_sigT_iff_eq_dep eqFG. +case: _ / eqFG in Gm' *. +congr Functor.Pack; congr Functor.Class. +case: Fm' Gm' => [F1 Fc] [G1 Gc]. +by congr PreFunctor_IsFunctor.Axioms_; apply: Prop_irrelevance. +Qed. + +(* the identity function is a functor *) +HB.instance Definition _ (C : quiver) := + IsPreFunctor.Build C C idfun (fun a b => idfun). +HB.instance Definition _ (C : precat) := + PreFunctor_IsFunctor.Build C C idfun (fun=> erefl) (fun _ _ _ _ _ => erefl). + +(* the composition of prefunctors *) +Section comp_prefunctor. +Context {C D E : quiver} {F : C ~> D} {G : D ~> E}. + +HB.instance Definition _ := IsPreFunctor.Build C E (G \o F)%FUN + (fun a b f => G <$> F <$> f). +Lemma comp_Fun (a b : C) (f : a ~> b) : (G \o F)%FUN <$> f = G <$> (F <$> f). +Proof. by []. Qed. +End comp_prefunctor. + +Section comp_functor. +Context {C D E : precat} {F : C ~> D} {G : D ~> E}. +Lemma comp_F1 (a : C) : (G \o F)%FUN <$> \idmap_a = idmap. +Proof. by rewrite !comp_Fun !F1. Qed. +Lemma comp_Fcomp (a b c : C) (f : a ~> b) (g : b ~> c) : + (G \o F)%FUN <$> (f \; g) = (G \o F)%FUN <$> f \; (G \o F)%FUN <$> g. +Proof. by rewrite !comp_Fun !Fcomp. Qed. +HB.instance Definition _ := PreFunctor_IsFunctor.Build C E (G \o F)%FUN + comp_F1 comp_Fcomp. +End comp_functor. + +(* precat and cat have a precategory structure *) +HB.instance Definition _ := Quiver_IsPreCat.Build precat + (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). +HB.instance Definition _ := Quiver_IsPreCat.Build cat + (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). + +Lemma funext_frefl A B (f : A -> B) : funext (frefl f) = erefl. +Proof. exact: Prop_irrelevance. Qed. + +(* precategories and categories form a category *) +Definition precat_cat : PreCat_IsCat precat. +Proof. +by split=> [C D F|C D F|C D C' D' F G H]; + apply/functorP => a b f /=; rewrite funext_frefl. +Qed. +HB.instance Definition _ := precat_cat. +Definition cat_cat : PreCat_IsCat cat. +Proof. +by split=> [C D F|C D F|C D C' D' F G H]; + apply/functorP => a b f /=; rewrite funext_frefl. +Qed. +HB.instance Definition _ := cat_cat. + +Check (cat : cat). + +(* concrete categories *) +HB.mixin Record Quiver_IsPreConcrete T of Quiver T := { + concrete : T -> U; + concrete_fun : forall (a b : T), (a ~> b) -> concrete a -> concrete b; +}. +Unset Universe Checking. +#[short(type="preconcrete_quiver")] +HB.structure Definition PreConcreteQuiver : Set := + { C of Quiver_IsPreConcrete C & IsQuiver C }. +Set Universe Checking. +Coercion concrete : PreConcreteQuiver.sort >-> Sortclass. + +HB.mixin Record PreConcrete_IsConcrete T of PreConcreteQuiver T := { + concrete_fun_inj : forall (a b : T), injective (concrete_fun a b) +}. +Unset Universe Checking. +#[short(type="concrete_quiver")] +HB.structure Definition ConcreteQuiver : Set := + { C of PreConcreteQuiver C & PreConcrete_IsConcrete C }. +Set Universe Checking. + +HB.instance Definition _ (C : ConcreteQuiver.type) := + IsPreFunctor.Build _ _ (concrete : C -> U) concrete_fun. + +HB.mixin Record PreCat_IsConcrete T of ConcreteQuiver T & PreCat T := { + concrete1 : forall (a : T), concrete <$> \idmap_a = idfun; + concrete_comp : forall (a b c : T) (f : a ~> b) (g : b ~> c), + concrete <$> (f \; g) = ((concrete <$> g) \o (concrete <$> f))%FUN; +}. +Unset Universe Checking. +#[short(type="concrete_precat")] +HB.structure Definition ConcretePreCat : Set := + { C of PreCat C & ConcreteQuiver C & PreCat_IsConcrete C }. +#[short(type="concrete_cat")] +HB.structure Definition ConcreteCat : Set := + { C of Cat C & ConcreteQuiver C & PreCat_IsConcrete C }. +Set Universe Checking. + +HB.instance Definition _ (C : concrete_precat) := + PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). +HB.instance Definition _ (C : ConcreteCat.type) := + PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). + +HB.instance Definition _ := Quiver_IsPreConcrete.Build U (fun _ _ => id). +HB.instance Definition _ := PreConcrete_IsConcrete.Build U (fun _ _ _ _ => id). +HB.instance Definition _ := PreCat_IsConcrete.Build U + (fun=> erefl) (fun _ _ _ _ _ => erefl). + +Unset Universe Checking. +HB.instance Definition _ := Quiver_IsPreConcrete.Build quiver (fun _ _ => id). +HB.instance Definition _ := Quiver_IsPreConcrete.Build precat (fun _ _ => id). +HB.instance Definition _ := Quiver_IsPreConcrete.Build cat (fun _ _ => id). +Lemma quiver_concrete_subproof : PreConcrete_IsConcrete quiver. +Proof. +constructor=> C D F G FG; apply: prefunctorP. + by move=> x; congr (_ x); apply: FG. +by move=> *; apply: Prop_irrelevance. +Qed. +HB.instance Definition _ := quiver_concrete_subproof. + +Lemma precat_concrete_subproof : PreConcrete_IsConcrete precat. +Proof. +constructor=> C D F G FG; apply: functorP. + by move=> x; congr (_ x); apply: FG. +by move=> *; apply: Prop_irrelevance. +Qed. +HB.instance Definition _ := precat_concrete_subproof. + +Lemma cat_concrete_subproof : PreConcrete_IsConcrete cat. +Proof. +constructor=> C D F G FG; apply: functorP. + by move=> x; congr (_ x); apply: FG. +by move=> *; apply: Prop_irrelevance. +Qed. +HB.instance Definition _ := cat_concrete_subproof. +HB.instance Definition _ := PreCat_IsConcrete.Build precat + (fun=> erefl) (fun _ _ _ _ _ => erefl). +HB.instance Definition _ := PreCat_IsConcrete.Build cat + (fun=> erefl) (fun _ _ _ _ _ => erefl). +Set Universe Checking. + +(* constant functor *) +Definition cst (C D : quiver) (c : C) := fun of D => c. +Arguments cst {C} D c. +HB.instance Definition _ {C D : precat} (c : C) := + IsPreFunctor.Build D C (cst D c) (fun _ _ _ => idmap). +HB.instance Definition _ {C D : cat} (c : C) := + PreFunctor_IsFunctor.Build D C (cst D c) (fun=> erefl) + (fun _ _ _ _ _ => esym (compo1 idmap)). + +(* opposite category *) +Definition catop (C : U) : U := C. +Notation "C ^op" := (catop C) + (at level 2, format "C ^op") : cat_scope. +HB.instance Definition _ (C : quiver) := + IsQuiver.Build C^op (fun a b => hom b a). +HB.instance Definition _ (C : precat) := + Quiver_IsPreCat.Build (C^op) (fun=> idmap) (fun _ _ _ f g => g \; f). +HB.instance Definition _ (C : cat) := PreCat_IsCat.Build (C^op) + (fun _ _ _ => compo1 _) (fun _ _ _ => comp1o _) + (fun _ _ _ _ _ _ _ => esym (compoA _ _ _)). + +HB.instance Definition _ {C : precat} {c : C} := + IsPreFunctor.Build C _ (hom c) (fun a b f g => g \; f). +Lemma hom_Fhom_subproof (C : cat) (x : C) : + PreFunctor_IsFunctor _ _ (hom x). +Proof. by split=> *; apply/funext => h; [apply: compo1 | apply: compoA]. Qed. +HB.instance Definition _ {C : cat} {c : C} := hom_Fhom_subproof c. + +Check fun (C : cat) (x : C) => hom x : C ~>_cat U. + +Lemma hom_op {C : quiver} (c : C^op) : hom c = (@hom C)^~ c. +Proof. reflexivity. Qed. + +Lemma homFhomx {C : precat} (a b c : C) (f : a ~> b) (g : c ~> a) : + (hom c <$> f) g = g \; f. +Proof. reflexivity. Qed. + +(* nary product of categories *) +Definition dprod {I : U} (C : I -> U) := forall i, C i. + +Section hom_dprod. +Context {I : U} (C : I -> quiver). +Definition dprod_hom_subdef (a b : dprod C) := forall i, a i ~> b i. +HB.instance Definition _ := IsQuiver.Build (dprod C) dprod_hom_subdef. +End hom_dprod. +Arguments dprod_hom_subdef /. + +Section precat_dprod. +Context {I : U} (C : I -> precat). +Definition dprod_idmap_subdef (a : dprod C) : a ~> a := fun=> idmap. +Definition dprod_comp_subdef (a b c : dprod C) (f : a ~> b) (g : b ~> c) : a ~> c := + fun i => f i \; g i. +HB.instance Definition _ := IsPreCat.Build (dprod C) + dprod_idmap_subdef dprod_comp_subdef. +End precat_dprod. +Arguments dprod_idmap_subdef /. +Arguments dprod_comp_subdef /. + +Section cat_dprod. +Context {I : U} (C : I -> cat). +Local Notation type := (dprod C). +Lemma dprod_is_cat : PreCat_IsCat type. +Proof. +split=> [a b f|a b f|a b c d f g h]; apply/funext => i; +[exact: comp1o | exact: compo1 | exact: compoA]. +Qed. +HB.instance Definition _ := dprod_is_cat. +End cat_dprod. + +(* binary product *) +Section hom_prod. +Context {C D : quiver}. +Definition prod_hom_subdef (a b : C * D) := ((a.1 ~> b.1) * (a.2 ~> b.2))%type. +HB.instance Definition _ := IsQuiver.Build (C * D)%type prod_hom_subdef. +End hom_prod. + +Section precat_prod. +Context {C D : precat}. +HB.instance Definition _ := IsPreCat.Build (C * D)%type (fun=> (idmap, idmap)) + (fun a b c (f : a ~> b) (g : b ~> c) => (f.1 \; g.1, f.2 \; g.2)). +End precat_prod. + +Section cat_prod. +Context {C D : cat}. +Local Notation type := (C * D)%type. +Lemma prod_is_cat : PreCat_IsCat type. +Proof. +split=> [[a1 a2] [b1 b2] [f1 f2]|[a1 a2] [b1 b2] [f1 f2]| + [a1 a2] [b1 b2] [c1 c2] [d1 d2] [f1 f2] [g1 g2] [h1 h2]]; congr (_, _) => //=; +by [exact: comp1o | exact: compo1 | exact: compoA]. +Qed. +HB.instance Definition _ := prod_is_cat. +End cat_prod. + +(* naturality *) +HB.mixin Record IsNatural (C D : precat) (F G : C ~>_quiver D) + (n : forall c, F c ~> G c) := { + natural : forall (a b : C) (f : a ~> b), + F <$> f \; n b = n a \; G <$> f +}. +Unset Universe Checking. +HB.structure Definition Natural (C D : precat) + (F G : C ~>_quiver D) : Set := + { n of @IsNatural C D F G n }. +Set Universe Checking. +HB.instance Definition _ (C D : precat) := + IsQuiver.Build (PreFunctor.type C D) (@Natural.type C D). +HB.instance Definition _ (C D : cat) := + IsQuiver.Build (Functor.type C D) (@Natural.type C D). +Arguments natural {C D F G} n [a b] f : rename. + +Check fun (C D : cat) (F G : C ~> D) => F ~>_(C ~>_cat D) G. + +Lemma naturalx (C : precat) (D : concrete_precat) + (F G : C ~>_quiver D) (n : F ~> G) (a b : C) (f : a ~> b) g : + (concrete <$> n b) ((concrete <$> F <$> f) g) = + (concrete <$> G <$> f) ((concrete <$> n a) g). +Proof. +have /(congr1 (fun h => (concrete <$> h) g)) := natural n f. +by rewrite !Fcomp. +Qed. +Arguments naturalx {C D F G} n [a b] f. + +Lemma naturalU (C : precat) (F G : C ~>_quiver U) (n : F ~> G) + (a b : C) (f : a ~> b) g : n b (F^$ f g) = G^$ f (n a g). +Proof. exact: (naturalx n). Qed. + +Lemma natP (C D : precat) (F G : C ~>_quiver D) (n m : F ~> G) : + Natural.sort n = Natural.sort m -> n = m. +Proof. +case: n m => [/= n nP] [/= m mP] enm. +elim: _ / enm in mP *; congr Natural.Pack. +case: nP mP => [[?]] [[?]]; congr Natural.Class. +congr IsNatural.Axioms_. +exact: Prop_irrelevance. +Qed. + +Notation "F ~~> G" := (F ~>_(homs quiver) G) + (at level 99, G at level 200, format "F ~~> G"). +Notation "F ~~> G :> C ~> D" := (F ~> G :> (C ~>_quiver D)) + (at level 99, G at level 200, C, D at level 0, + format "F ~~> G :> C ~> D"). + +Definition natural_id {C D : precat} (F : C ~>_quiver D) (a : C) := \idmap_(F a). +Definition natural_id_natural (C D : cat) (F : C ~>_quiver D) : + IsNatural C D F F (natural_id F). +Proof. by constructor=> a b f; rewrite /natural_id/= compo1 comp1o. Qed. +HB.instance Definition _ C D F := @natural_id_natural C D F. + +Check fun {C D : cat} (F : C ~>_quiver D) => natural_id F : F ~> F. + +Definition natural_comp {C D : precat} (F G H : C ~>_quiver D) + (m : F ~> G) (n : G ~> H) (a : C) := m a \; n a. +Definition natural_comp_natural (C D : cat) (F G H : C ~>_quiver D) m n : + IsNatural C D F H (@natural_comp C D F G H m n). +Proof. +constructor=> a b f; rewrite /natural_comp/=. +by rewrite compoA natural -compoA natural compoA. +Qed. +HB.instance Definition _ C D F G H m n := @natural_comp_natural C D F G H m n. + +HB.instance Definition _ {C D : cat} := + Quiver_IsPreCat.Build (PreFunctor.type C D) natural_id natural_comp. +HB.instance Definition _ {C D : cat} := + Quiver_IsPreCat.Build (Functor.type C D) natural_id natural_comp. + +Lemma prefunctor_cat {C D : cat} : PreCat_IsCat (PreFunctor.type C D). +Proof. +constructor => [F G f|F G f|F G H J f g h]. +- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. +- by apply/natP/funext => a; rewrite /= /natural_comp compo1. +- by apply/natP/funext => a; rewrite /= /natural_comp compoA. +Qed. +HB.instance Definition _ C D := @prefunctor_cat C D. + +Lemma functor_cat {C D : cat} : PreCat_IsCat (Functor.type C D). +Proof. +constructor => [F G f|F G f|F G H J f g h]. +- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. +- by apply/natP/funext => a; rewrite /= /natural_comp compo1. +- by apply/natP/funext => a; rewrite /= /natural_comp compoA. +Qed. +HB.instance Definition _ C D := @functor_cat C D. + +Section nat_map_left. +Context {C D E : precat} {F G : C ~> D}. + +Definition nat_lmap (H : D ~>_quiver E) (n : forall c, F c ~> G c) : + forall c, (H \o F)%FUN c ~> (H \o G)%FUN c := fun c => H <$> n c. + +Fail Check fun (H : D ~> E) (n : F ~~> G) => nat_lmap H n : H \o F ~~> H \o G. + +Lemma nat_lmap_is_natural (H : D ~> E) (n : F ~~> G) : + IsNatural C E (H \o F) (H \o G) (nat_lmap H n). +Proof. by constructor=> a b f; rewrite /nat_lmap/= -!Fcomp natural. Qed. +HB.instance Definition _ H n := nat_lmap_is_natural H n. + +Check fun (H : D ~> E) (n : F ~~> G) => nat_lmap H n : H \o F ~~> H \o G. + +End nat_map_left. + +Notation "F n" := (nat_lmap F n) + (at level 58, format "F n", right associativity) : cat_scope. + +Section nat_map_right. +Context {C D E : precat} {F G : C ~> D}. + +Definition nat_rmap (H : E -> C) (n : forall c, F c ~> G c) : + forall c, (F \o H)%FUN c ~> (G \o H)%FUN c := fun c => n (H c). +Lemma nat_rmap_is_natural (H : E ~> C :> quiver) (n : F ~~> G) : + IsNatural E D (F \o H)%FUN (G \o H)%FUN (nat_rmap H n). +Proof. by constructor=> a b f; rewrite /nat_lmap/= natural. Qed. +HB.instance Definition _ H n := nat_rmap_is_natural H n. + +End nat_map_right. + +Notation "F <$o> n" := (nat_rmap F n) + (at level 58, format "F <$o> n", right associativity) : cat_scope. + +Definition delta (C D : cat) : C -> (D ~> C) := cst D. +Arguments delta C D : clear implicits. + +Definition map_delta {C D : cat} (a b : C) (f : a ~> b) : + delta C D a ~> delta C D b. +Proof. +apply: (@Natural.Pack _ _ (cst D a) (cst D b) (fun x => f)). +apply: Natural.Class; apply: (IsNatural.Build _ _ _ _ _). +by move=> a' b' ?; rewrite compo1 comp1o. +Defined. + +HB.instance Definition _ {C D : cat} := + IsPreFunctor.Build C (D ~> C) (delta C D) (@map_delta C D). + +Lemma delta_functor {C D : cat} : PreFunctor_IsFunctor _ _ (delta C D). +Proof. by constructor=> [a|a b c f g]; exact/natP. Qed. +HB.instance Definition _ C D := @delta_functor C D. + +HB.mixin Record IsMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { + unit : idfun ~~> M; + join : (M \o M)%FUN ~~> M; + bind : forall (a b : C), (a ~> M b) -> (M a ~> M b); + bindE : forall a b (f : a ~> M b), bind a b f = M <$> f \; join b; + unit_join : forall a, (M <$> unit a) \; join _ = idmap; + join_unit : forall a, join _ \; (M <$> unit a) = idmap; + join_square : forall a, M <$> join a \; join _ = join _ \; join _ +}. + +#[short(type="premonad")] +HB.structure Definition PreMonad (C : precat) := + {M of @PreFunctor C C M & IsMonad C M}. +#[short(type="monad")] +HB.structure Definition Monad (C : precat) := + {M of @Functor C C M & IsMonad C M}. + +HB.factory Record IsJoinMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { + unit : idfun ~~> M; + join : (M \o M)%FUN ~~> M; + unit_join : forall a, (M <$> unit a) \; join _ = idmap; + join_unit : forall a, join _ \; (M <$> unit a) = idmap; + join_square : forall a, M <$> join a \; join _ = join _ \; join _ +}. +HB.builders Context C M of IsJoinMonad C M. + HB.instance Definition _ := IsMonad.Build C M + (fun a b f => erefl) unit_join join_unit join_square. +HB.end. + +HB.mixin Record IsCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { + counit : M ~~> idfun; + cojoin : M ~~> (M \o M)%FUN; + cobind : forall (a b : C), (M a ~> b) -> (M a ~> M b); + cobindE : forall a b (f : M a ~> b), cobind a b f = cojoin _ \; M <$> f; + unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; + join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; + cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ +}. +#[short(type="precomonad")] +HB.structure Definition PreCoMonad (C : precat) := + {M of @PreFunctor C C M & IsCoMonad C M}. +#[short(type="comonad")] +HB.structure Definition CoMonad (C : precat) := + {M of @Functor C C M & IsCoMonad C M}. + +HB.factory Record IsJoinCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { + counit : M ~~> idfun; + cojoin : M ~~> (M \o M)%FUN; + unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; + join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; + cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ +}. +HB.builders Context C M of IsJoinCoMonad C M. + HB.instance Definition _ := IsCoMonad.Build C M + (fun a b f => erefl) unit_cojoin join_counit cojoin_square. +HB.end. + +Lemma idFmap (C : cat) (a b : C) (f : a ~> b) : idfun <$> f = f. +Proof. by []. Qed. + +Lemma compFmap (C D E : cat) (F : C ~> D) (G : D ~> E) (a b : C) (f : a ~> b) : + (G \o F) <$> f = G <$> F <$> f. +Proof. by []. Qed. + +(* yoneda *) +Section hom_repr. +Context {C : cat} (F : C ~>_cat U). + +Definition homF : C -> U := fun c => hom c ~~> F. + +Section nat. +Context (x y : C) (xy : x ~> y). + +(* Goal hom x ~~> F -> hom y ~~> F *) +Context (n : hom x ~~> F). +Definition homFhom c : hom y c ~> F c := fun g => n _ (xy \; g). + +Lemma homFhom_natural_subdef : IsNatural C U (hom y) F homFhom. +Proof. +by split=> a b f /=; apply/funext => g /=; + rewrite /homFhom !Ucompx/= !naturalU/= Fcomp. +Qed. +HB.instance Definition _ := homFhom_natural_subdef. +End nat. +Arguments homFhom / : clear implicits. + +HB.about IsPreFunctor.Build. +Check homFhom : forall x y : C, (x ~> y) -> (homF x -> homF y). +HB.instance Definition _ := IsPreFunctor.Build _ _ homF homFhom. +Lemma homF_functor_subproof : PreFunctor_IsFunctor _ _ homF. +Proof. +split=> [a|a b c f g]. + apply/funext => -[/= f natf]. + apply: natP => //=; apply: funext => b; apply: funext => g/=. + by rewrite comp1o. +apply/funext => -[/= h natf]. +apply: natP => //=; apply: funext => d; apply: funext => k/=. +by rewrite compoA. +Qed. +HB.instance Definition _ := homF_functor_subproof. + +Section pointed. +Context (c : C). +Definition hom_repr : homF c ~> F c := fun f => f _ idmap. +Arguments hom_repr /. + +Definition repr_hom (fc : F c) a : hom c a ~> F a := + fun f => F^$ f fc. +Arguments repr_hom / : clear implicits. +Lemma repr_hom_subdef (fc : F c) : IsNatural _ _ _ _ (repr_hom fc). +Proof. by split=> a b f /=; apply/funext=> x; rewrite !Ucompx/= Fcomp. Qed. +HB.instance Definition _ {fc : F c} := repr_hom_subdef fc. + +Definition repr_hom_nat : F c ~> homF c := repr_hom. + +Lemma hom_reprK : cancel hom_repr repr_hom_nat. +Proof. +move=> f; apply/natP; apply/funext => a; apply/funext => g /=. +by rewrite -naturalU/=; congr (f _ _); apply: comp1o. +Qed. +Lemma repr_homK : cancel (repr_hom : F c ~> homF c) hom_repr. +Proof. by move=> fc; rewrite /= F1. Qed. +End pointed. +Arguments hom_repr /. +Arguments repr_hom /. + +Lemma hom_repr_natural_subproof : IsNatural _ _ _ _ hom_repr. +Proof. +split=> a b f /=; apply/funext => n /=; rewrite !Ucompx/= compo1/=. +by rewrite -naturalU/=; congr (n _ _); apply/esym/comp1o. +Qed. +HB.instance Definition _ := hom_repr_natural_subproof. + +(* show this from the previous proof *) +Lemma hom_natural_repr_subproof : IsNatural _ _ _ _ repr_hom_nat. +Proof. +split=> a b f /=; apply: funext => fa /=; rewrite !Ucompx/=. +apply: natP; apply: funext => c /=; apply: funext => d /=. +by rewrite Fcomp Ucompx/=. +Qed. +HB.instance Definition _ := hom_natural_repr_subproof. + +Definition hom_repr_nat : homF ~~> F := hom_repr. +Definition repr_hom_nat_nat : F ~~> homF := repr_hom_nat. + +End hom_repr. + +(* comma categories *) +Module comma. +Section homcomma. +Context {C D E : precat} (F : C ~> E) (G : D ~> E). + +Definition type := { x : C * D & F x.1 ~> G x.2 }. +Definition hom_subdef (a b : type) := { + f : tag a ~> tag b & F <$> f.1 \; tagged b = tagged a \; G <$> f.2 + }. +HB.instance Definition _ := IsQuiver.Build type hom_subdef. +End homcomma. +Arguments hom_subdef /. +Section comma. +Context {C D E : cat} (F : C ~> E) (G : D ~> E). +Notation type := (type F G). + +Program Definition idmap_subdef (a : type) : a ~> a := @Tagged _ idmap _ _. +Next Obligation. by rewrite !F1 comp1o compo1. Qed. +Program Definition comp_subdef (a b c : type) + (f : a ~> b) (g : b ~> c) : a ~> c := + @Tagged _ (tag f \; tag g) _ _. +Next Obligation. by rewrite !Fcomp -compoA (tagged g) compoA (tagged f) compoA. Qed. +HB.instance Definition _ := IsPreCat.Build type idmap_subdef comp_subdef. +Arguments idmap_subdef /. +Arguments comp_subdef /. + +Lemma comma_homeqP (a b : type) (f g : a ~> b) : projT1 f = projT1 g -> f = g. +Proof. +case: f g => [f fP] [g +]/= eqfg; case: _ / eqfg => gP. +by congr existT; apply: Prop_irrelevance. +Qed. + +Lemma comma_is_cat : PreCat_IsCat type. +Proof. +by split=> [[a fa] [b fb] [*]|[a fa] [b fb] [*]|*]; + apply/comma_homeqP; rewrite /= ?(comp1o, compo1, compoA). +Qed. +HB.instance Definition _ := comma_is_cat. +End comma. +End comma. +Notation "F `/` G" := (@comma.type _ _ _ F G) + (at level 40, G at level 40, format "F `/` G") : cat_scope. +Notation "a /` G" := (cst unit a `/` G) + (at level 40, G at level 40, format "a /` G") : cat_scope. +Notation "F `/ b" := (F `/` cst unit b) + (at level 40, b at level 40, format "F `/ b") : cat_scope. +Notation "a / b" := (cst unit a `/ b) : cat_scope. + +Definition obj (C : quiver) : Type := C. +HB.mixin Record IsInitial {C : quiver} (i : obj C) := { + to : forall c, i ~> c; + to_unique : forall c (f : i ~> c), f = to c +}. +#[short(type="initial")] +HB.structure Definition Initial {C : quiver} := {i of IsInitial C i}. + +HB.mixin Record IsTerminal {C : quiver} (t : obj C) := { + from : forall c, c ~> t; + from_unique : forall c (f : c ~> t), f = from c +}. +#[short(type="terminal")] +HB.structure Definition Terminal {C : quiver} := {t of IsTerminal C t}. +#[short(type="universal")] +HB.structure Definition Universal {C : quiver} := + {u of Initial C u & Terminal C u}. + +(* Definition hom' {C : precat} (a b : C) := a ~> b. *) +(* (* Bug *) *) +(* Identity Coercion hom'_hom : hom' >-> hom. *) + +(* HB.mixin Record IsMono {C : precat} (b c : C) (f : hom b c) := { *) +(* monoP : forall (a : C) (g1 g2 : a ~> b), g1 \; f = g2 \; f -> g1 = g2 *) +(* }. *) +(* #[short(type="mono")] *) +(* HB.structure Definition Mono {C : precat} (a b : C) := {m of IsMono C a b m}. *) +(* Notation "a >~> b" := (mono a b) *) +(* (at level 99, b at level 200, format "a >~> b") : cat_scope. *) +(* Notation "C >~>_ T D" := (@mono T C D) *) +(* (at level 99, T at level 0, only parsing) : cat_scope. *) + +(* HB.mixin Record IsEpi {C : precat} (a b : C) (f : hom a b) := { *) +(* epiP : forall (c : C) (g1 g2 : b ~> c), g1 \o f = g2 \o f -> g1 = g2 *) +(* }. *) +(* #[short(type="epi")] *) +(* HB.structure Definition Epi {C : precat} (a b : C) := {e of IsEpi C a b e}. *) +(* Notation "a ~>> b" := (epi a b) *) +(* (at level 99, b at level 200, format "a ~>> b") : cat_scope. *) +(* Notation "C ~>>_ T D" := (@epi T C D) *) +(* (at level 99, T at level 0, only parsing) : cat_scope. *) + +(* #[short(type="iso")] *) +(* HB.structure Definition Iso {C : precat} (a b : C) := *) +(* {i of @Mono C a b i & @Epi C a b i}. *) +(* Notation "a <~> b" := (epi a b) *) +(* (at level 99, b at level 200, format "a <~> b") : cat_scope. *) +(* Notation "C <~>_ T D" := (@epi T C D) *) +(* (at level 99, T at level 0, only parsing) : cat_scope. *) + +HB.mixin Record IsRightAdjoint (D C : precat) (R : D -> C) + of @PreFunctor D C R := { + L_ : C ~> D; + phi : forall c d, (L_ c ~> d) -> (c ~> R d); + psy : forall c d, (c ~> R d) -> (L_ c ~> d); + phi_psy c d : (phi c d \o psy c d)%FUN = @id (c ~> R d); + psy_phi c d : (psy c d \o phi c d)%FUN = @id (L_ c ~> d) +}. +#[short(type="right_adjoint")] +HB.structure Definition RightAdjoint (D C : precat) := + { R of @Functor D C R & IsRightAdjoint D C R }. +Arguments L_ {_ _}. +Arguments phi {D C s} {c d}. +Arguments psy {D C s} {c d}. + + +HB.mixin Record PreCat_IsMonoidal C of PreCat C := { + onec : C; + (* prod1 : @hom precat (C * C)%type C ; *) + prod : (C * C)%type ~>_precat C; +}. +#[short(type="premonoidal")] +#[verbose] +HB.structure Definition PreMonoidal := { C of PreCat C & PreCat_IsMonoidal C }. +Notation premonoidal := premonoidal. +Arguments prod {C} : rename. +Notation "a * b" := (prod (a, b)) : cat_scope. +Reserved Notation "f <*> g" (at level 40, g at level 40, format "f <*> g"). +Notation "f <*> g" := (prod^$ (f, g)) (only printing) : cat_scope. +Notation "f <*> g" := (prod^$ ((f, g) : (_, _) ~> (_, _))) + (only parsing) : cat_scope. +Notation "1" := onec : cat_scope. + +Definition hom_cast {C : quiver} {a a' : C} (eqa : a = a') {b b' : C} (eqb : b = b') : + (a ~> b) -> (a' ~> b'). +Proof. now elim: _ / eqa; elim: _ / eqb. Defined. + +HB.mixin Record PreFunctor_IsMonoidal (C D : premonoidal) F of + @PreFunctor C D F := { + fun_one : F 1 = 1; + fun_prod : forall (x y : C), F (x * y) = F x * F y; +}. +#[short(type="monoidal_prefunctor")] +HB.structure Definition MonoidalPreFunctor C D := + { F of @PreFunctor_IsMonoidal C D F }. +Arguments fun_prod {C D F x y} : rename. +(* Arguments fun_prodF {C D F x x'} f {y y'} g : rename. *) +Unset Universe Checking. +HB.instance Definition _ := IsQuiver.Build premonoidal MonoidalPreFunctor.type. +Set Universe Checking. + +HB.instance Definition _ (C : quiver) := + IsPreFunctor.Build (C * C)%type C fst + (fun (a b : C * C) (f : a ~> b) => f.1). +HB.instance Definition _ (C : quiver) := + IsPreFunctor.Build (C * C)%type C snd + (fun (a b : C * C) (f : a ~> b) => f.2). + +Definition prod3l {C : premonoidal} (x : C * C * C) : C := + (x.1.1 * x.1.2) * x.2. +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build _ C prod3l + (fun a b (f : a ~> b) => (f.1.1 <*> f.1.2) <*> f.2). + +Definition prod3r {C : premonoidal} (x : C * C * C) : C := + x.1.1 * (x.1.2 * x.2). +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build _ C prod3r + (fun a b (f : a ~> b) => f.1.1 <*> (f.1.2 <*> f.2)). + +Definition prod1r {C : premonoidal} (x : C) : C := 1 * x. +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build C C prod1r + (fun (a b : C) (f : a ~> b) => \idmap_1 <*> f). + +Definition prod1l {C : premonoidal} (x : C) : C := x * 1. +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build C C prod1l + (fun (a b : C) (f : a ~> b) => f <*> \idmap_1). + +HB.mixin Record PreMonoidal_IsMonoidal C of PreMonoidal C := { + prodA : prod3l ~~> prod3r; + prod1c : prod1r ~~> idfun; + prodc1 : prod1l ~~> idfun; + prodc1c : forall (x y : C), + prodA (x, 1, y) \; \idmap_x <*> prod1c y = prodc1 x <*> \idmap_y; + prodA4 : forall (w x y z : C), + prodA (w * x, y, z) \; prodA (w, x, y * z) = + prodA (w, x, y) <*> \idmap_z \; prodA (w, x * y, z) \; \idmap_w <*> prodA (x, y, z); +}. + +Unset Universe Checking. +#[short(type="monoidal")] +#[verbose] +HB.structure Definition Monoidal : Set := + { C of PreMonoidal_IsMonoidal C & PreMonoidal C }. +Set Universe Checking. + +(******************************************************************) + + +Record cospan (Q : quiver) (A B : Q) := Cospan { + top : Q; + left2top : A ~> top; + right2top : B ~> top +}. + +Section cospans. +Variables (Q : precat) (A B : Q). +Record cospan_map (c c' : cospan A B) := CospanMap { + top_map : top c ~> top c'; + left2top_map : left2top c \; top_map = left2top c'; + right2top_map : right2top c \; top_map = right2top c'; +}. +HB.instance Definition _ := IsQuiver.Build (cospan A B) cospan_map. + +Lemma cospan_mapP (c c' : cospan A B) (f g : c ~> c') : + top_map f = top_map g <-> f = g. +Admitted. +End cospans. + +Section cospans_in_cat. +Variables (Q : cat) (A B : Q). +Definition cospan_idmap (c : cospan A B) := + @CospanMap Q A B c c idmap (compo1 _) (compo1 _). +Program Definition cospan_comp (c1 c2 c3 : cospan A B) + (f12 : c1 ~> c2) (f23 : c2 ~> c3) := + @CospanMap Q A B c1 c3 (top_map f12 \; top_map f23) _ _. +Next Obligation. by rewrite compoA !left2top_map. Qed. +Next Obligation. by rewrite compoA !right2top_map. Qed. +HB.instance Definition _ := IsPreCat.Build (cospan A B) cospan_idmap cospan_comp. + +Lemma cospan_are_cats : PreCat_IsCat (cospan A B). +Proof. +constructor=> [a b f|a b f|a b c d f g h]. +- by apply/cospan_mapP => /=; rewrite comp1o. +- by apply/cospan_mapP => /=; rewrite compo1. +- by apply/cospan_mapP => /=; rewrite compoA. +Qed. +HB.instance Definition _ := cospan_are_cats. +End cospans_in_cat. + +Section spans_and_co. +Variables (Q : quiver) (A B : Q). +Definition span := @cospan Q^op A B. +Definition bot (s : span) : Q := top s. +Definition bot2left (s : span) : bot s ~>_Q A := left2top s. +Definition bot2right (s : span) : bot s ~>_Q B := right2top s. +Definition Span (C : Q) (f : C ~> A) (g : C ~> B) : span := + @Cospan Q^op A B C f g. +End spans_and_co. + +HB.instance Definition _ (Q : precat) (A B : Q) := + Quiver.copy (span A B) (@cospan Q^op A B)^op. +HB.instance Definition _ (Q : cat) (A B : Q) := + Cat.copy (span A B) (@cospan Q^op A B)^op. + +Section bot_map. +Variables (C : cat) (A B : C) (s s' : span A B) (f : s ~> s'). +Definition bot_map : bot s ~> bot s' := top_map f. +Lemma bot2left_map : bot_map \; bot2left s' = bot2left s. +Proof. exact: left2top_map f. Qed. +Lemma bot2right_map : bot_map \; bot2right s' = bot2right s. +Proof. exact: right2top_map f. Qed. +End bot_map. + +HB.mixin Record isPrePullback (Q : precat) (A B : Q) + (c : cospan A B) (s : span A B) := { + is_square : bot2left s \; left2top c = bot2right s \; right2top c; +}. +#[short(type=prepullback)] +HB.structure Definition PrePullback Q A B (c : cospan A B) := + {s of isPrePullback Q A B c s}. +Arguments prepullback {Q A B} c. + +Section prepullback. +Variables (Q : precat) (A B : Q) (c : cospan A B). +HB.instance Definition _ := + IsQuiver.Build (prepullback c) + (fun a b => (a : span A B) ~>_(span A B) (b : span A B)). +Lemma eq_prepullbackP (p q : prepullback c) : + p = q :> span _ _ <-> p = q. +Admitted. +End prepullback. +Section prepullback. +Variables (Q : cat) (A B : Q) (csp : cospan A B). +(* TODO: why can't we do that? *) +(* HB.instance Definition _ := Cat.on (prepullback csp). *) +HB.instance Definition _ := + Quiver_IsPreCat.Build (prepullback csp) + (fun a => \idmap_(a : span A B)) + (* TODO: study how to make this coercion trigger + even when the target is not reduced to span *) + (fun a b c f g => f \; g). +Lemma prepullback_is_cat : PreCat_IsCat (prepullback csp). +Proof. (* should be copied from the cat on span *) +constructor=> [a b f|a b f|a b c d f g h]; + [exact: comp1o|exact: compo1|exact: compoA]. +Qed. +End prepullback. + +HB.tag Definition pb_terminal (Q : precat) + (A B : Q) (c : cospan A B) (s : prepullback c) : + obj (prepullback c) := s. + +#[wrapper] +HB.mixin Record prepullback_isTerminal (Q : precat) + (A B : Q) (c : cospan A B) + (s : span A B) of isPrePullback Q A B c s := { + prepullback_terminal : + IsTerminal (prepullback c) (pb_terminal s) +}. +#[short(type="pullback"), verbose] +HB.structure Definition Pullback (Q : precat) + (A B : Q) (c : cospan A B) := + {s of isPrePullback Q A B c s + & IsTerminal (prepullback c) (pb_terminal s) }. + +Notation pbsquare u v f g := + (Pullback _ (Cospan f g) (Span u v)). + +Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). + +(********************************************************************) +(********************************************************************) + +(* Defining a category with pullbacks +Ideally span is in fact expanded and the final mixin has +a pb : forall A B, cospan A B -> C +but it is not clear how to do that yet +*) +(* Definition has_all_pbcks (C: Quiver.type) : Type := + forall (A B: C), cospan A B -> span A B. +HB.mixin Record HasPBop C of Cat C := { + pb : has_all_pbcks C + }. + +Definition pb_is_pullback (C: PBop.type) : Type := + forall (a b: C) (c: cospan a b), Pullback C c (@pb C a b c). +HB.mixin Record IsPBCat C of PBop C : Type := + { + is_pb : pb_is_pullback C + }. +#[short(type="pbcat")] +HB.structure Definition PBCat := + {C of IsPBCat C}. +*) + +(* category with all prepullbacks *) +HB.mixin Record HasPBop C of Cat C := { + pb : forall (A B: C), cospan A B -> span A B + }. +#[short(type="pbop")] +HB.structure Definition PBop := + {C of HasPBop C & PreCat C }. + +(* category with all pullbacks *) +#[wrapper] +HB.mixin Record HasPBCat C of PBop C : Type := { + is_pb : forall (a b: C) (c: cospan a b), Pullback C c (@pb C a b c) + }. +#[short(type="pbcat")] +HB.structure Definition PBCat := + {C of HasPBCat C}. + +(* Defining internal hom objects. + C0 and C1 are objects of C. + C0 is the object of objects, + C1 is the object of morphims (and the subject). + this will allow to define a generic _ *_C0 _ notation + by recognizing the structure of hom objects on the LHS and RHS *) +HB.mixin Record isInternalHom {C: quiver} (C0 C1 : C) := { + src : C1 ~> C0; tgt : C1 ~> C0 +}. +#[short(type="iHom")] +HB.structure Definition InternalHom {C: quiver} (C0 : C) := + { C1 of isInternalHom C C0 C1 }. + +(* +Definition tgt' := @tgt. +Arguments tgt' {_ _} _. + +(* X and Y are morphisms in the morphism object associated with C0 *) +Definition iprod {C: pbcat} {C0 : C} (X Y : @iHom C C0) : C := + bot (pb _ _ (Cospan (tgt : InternalHom.sort X ~> C0) (src : Y ~> C0))). +Notation "X *_ C0 Y" := (@iprod _ C0 X Y) (at level 99). +*) +(* BEWARE: this cospan is a type-level one: it basically just says +that for ANY morphism, source and target are objects (NOT necesarily +the SAME object). X and Y are two instances of the morphism object +(iHom C0), which (unlike in most presentations) depends on the object +of objects C0. This is just like saying that X and Y are two versions +of C1 (I find this duplication, which does not appear in the +literature, rather confusing). X and Y are NOT two distinct morphisms +in the ambient category. The cospan does NOT imply that ambient +morphisms typed by X and Y are composable (i.e. adjacent). Also, the +pullback is not a morphism, it is just an object of C (also rather +confusing). + +original Cyril's code: + +Definition iprod {C} {C0 : C} (X Y : iHom C0) := bottom (pb (Cospan + (src X) (tgt Y))). Notation "X *_ C0 Y" := (@iprod _ C0 X Y). + +HB.instance Definition iprod_iHom := isInternalHom.Build C0 (X *_C0 Y) + (src (bot2left _)) (tgt (bot2right _)). *) +Definition iprod_pb {C: pbcat} {C0 : C} (X Y : iHom C0) : span X Y := + pb _ _ (Cospan (tgt : X ~> C0) (src : Y ~> C0)). + +Definition iprod {C: pbcat} {C0 : C} (X Y : iHom C0) : C := + bot (@iprod_pb C C0 X Y). +Notation "X *_ C0 Y" := (@iprod _ C0 X Y) + (at level 99, C0 at level 0, only parsing) : cat_scope. + +Definition iprodl {C: pbcat} {C0 : C} (X Y : iHom C0) : X *_C0 Y ~> X := + bot2left (iprod_pb X Y). +Definition iprodr {C: pbcat} {C0 : C} (X Y : iHom C0) : X *_C0 Y ~> Y := + bot2right (iprod_pb X Y). + +(* Given (iHom C0) instances X and Y, we want to say that (X *_C0 Y) +is also an instance of (iHom C0). Notice, however, that X and Y do not +represent composable morphisms *) +Program Definition iprod_iHom {C: pbcat} {C0: C} (X Y: @iHom C C0) : + @isInternalHom C C0 (X *_C0 Y) := + @isInternalHom.Build C C0 (X *_C0 Y) + ((iprodl X Y) \; src) + ((iprodr X Y) \; tgt). + + + +(* +(* X and Y are morphisms in the morphism object associated with C0 *) +Definition iprod {C: pbcat} {C0 : C} (X Y : @iHom C C0) : C := + bot (pb _ _ (Cospan (tgt : X ~> C0) (src : Y ~> C0))). +Notation "X *_ C0 Y" := (@iprod _ C0 X Y) + (at level 99, C0 at level 0, only parsing) : cat_scope. +*) +(* +HB.instance Definition iprod_iHom := + isInternalHom.Build C0 (X *_C0 Y) (src (bot2left _)) (tgt (bot2right _)). +*) + +(* +Definition iprodl {C} {C0 : C} (X Y : iHom C0) : X *_C0 Y ~> X := + bot2left. +Definition iprodr {C} {C0 : C} (X Y : iHom C0) : X *_C0 Y ~> Y := + bot2right. +*) + +(* we also define the trivial internal hom type *) +HB.instance Definition trivial_iHom {C: pbcat} {C0: C} := + isInternalHom.Build C C0 C0 idmap idmap. + +(* we need internal hom morphisms: +the ones that preserve sources and targets *) +HB.mixin Record IsInternalHomHom {C} (C0 : C) + (C1 C1' : @iHom U C) (f : C1 ~> C1') := { + hom_src : f \; src = src; + hom_tgt : f \; tgt = tgt; +}. +#[short(type="iHomHom")] +HB.structure Definition InternalHomHom {C} + (C0 : C) (C1 C1' : @iHom U C) := + { f of @IsInternalHomHom C C0 C1 C1' f }. + +(* internal homs form a category, + the morphisms are the one that preserve source and target *) +HB.instance Definition _ {C} (C0 : C) := + Cat.Build (@iHom C C0) (@iHomHom C C0) _ _ _ _ _. + +Definition iprodA {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0): + (C1 *_C0 C2) *_C0 C3 ~> C1 *_C0 (C2 *_C0 C3) := ... + (* define it with the universal arrow of the pullback *) + +Definition ipair {C : pbcat} {C0 : C} {C1 C2 C3 C4 : iHom C0} + (f : C1 ~> C3) (g : C2 ~> C4) : C1 *_C0 C2 ~> C3 *_C0 C4 := ... + +Notation "< f , g >" := (ipair f g). + +(* Now we define an internal quiver as an object C0, + which has a C1 : iHom C0 attached to it *) +HB.mixin Record IsPreInternalQuiver {C} (C0 : C) := PreInteralQuiver { C1 : C }. +#[short(type="internalQuiver")] +HB.structure Definition InternalQuiver {C} := { + C0 of IsPreInternalQuiver C0 & InternalHom C0 (@C1 C0) +}. + +(* An internal precategory is an internal category with two operators that + must be src and tgt preserving, i.e. iHom morphisms *) +HB.mixin Record IsInternalPreCat (C : pbcat) (C0 : C) of InternalQuiver C0 := { + iid : C0 ~>_(iHom C0) C1; + icomp : C1 *_C0 C1 ~>_(iHom C0) C1; +} +#[short(type="internalprecat")] +HB.structure Definition InternalPrecat (C : pbcat) := + { q of @IsPreInternalPreCat C q }. + +(* An internal category moreover must satisfy additional properies on iid and icomp *) +HB.mixin Record IsInternalCat (C : pbcat) (C0 : C) of InternalPreCat C0 := { + icompA : \; icomp = iprodA \; \; icomp; + icomp1l : \; icomp = iprodl; + icomp1r : \; icomp = iprodr; +HB.structure Definition InternalCat (C : pbcat) := {C0 of @IsInternalCat C C0}. + +(* A double category is an internal category in cat + - The objects are the objects of C0 + - The vertical maps are the maps of C0 + - The horizontal maps are the objects of C1 + - The 2-cells are the maps of C1 + + About identities: + - The identity vertical map on (x : C) is \idmap_x + - The identity horizontal map on (x : C) is iid x + - the identity 2-cell on (x : C) is iid (\idmap_x) = \idmap_(iid x) + + About compositions: + - The vertical composition of maps is the composition of C0 + - The vertical compositions of 2-cells is the composition of C1 + (and it agrees with the former because src and tgt are functors + and because iid is a iHom-map) + - The horizontal composition of maps is the object part of icomp + - The horizontal composition of 2-cells is the map part of icomp +*) +HB.structure' Definition DoubleCat := @InternalCat cat. + + + + + +(*** ENRICHED CATEGORIES *) + +Declare Scope encat_scope. +Delimit Scope encat_scope with encat. +Local Open Scope encat_scope. + +(* Enrichment in a monoidal category, following + https://ncatlab.org/nlab/show/enriched+category +*) +HB.mixin Record IsEnQuiver (V: Type) C := { + hom_object : C -> C -> V + }. +Unset Universe Checking. +HB.structure Definition EnQuiver (V: Type) : Set := + { C of IsEnQuiver V C }. +Set Universe Checking. + +(* Monoidal precategory with the enrichment operators (no axioms) *) +HB.mixin Record IsEnPreCat (V: PreMonoidal.type) C of + EnQuiver (PreMonoidal.sort V) C := { + id_element : forall (a: C), + @hom V onec (hom_object a a) ; + comp_morphism : forall (a b c: C), + @hom V (@hom_object V C b c * @hom_object V C a b) + (@hom_object V C a c) +}. +Unset Universe Checking. +HB.structure Definition EnPreCat (V: PreMonoidal.type) : Set := + { C of IsEnPreCat V C }. +Set Universe Checking. + +Notation "a ~^ b" := (hom_object a b) + (at level 99, b at level 200, format "a ~^ b") : encat_scope. +Notation "a ~^_ ( V , C ) b" := (@hom_object V C a b) + (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. +Notation "~^IE a" := (id_element a) + (at level 99, format "~^IE a") : cat_scope. +Notation "~^IE_ ( V , C ) a" := (@id_element V C a) + (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. +(* not working *) +Notation "~^CM a b c" := (comp_morphism a b c) + (at level 99, + format "~^CM a b c") : cat_scope. +Notation "~^CM_ ( V , C ) a b c" := (@comp_morphism V C a b c) + (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. + +(* V-enriched category: + V is the monoidal category; + C is the base category that gets enriched +*) +HB.mixin Record IsEnCat (V: Monoidal.type) C of EnPreCat V C := { + ecat_comp_assoc : forall a b c d: C, + forall alpha: + (((c ~^_(V,C) d) * (b ~^_(V,C) c)) * (a ~^_(V,C) b)) ~>_V + ((c ~^_(V,C) d) * ((b ~^_(V,C) c) * (a ~^_(V,C) b))), + ((@comp_morphism V C b c d) <*> (@idmap V (a ~^_(V,C) b))) \; + (@comp_morphism V C a b d) + = + alpha \; + ((@idmap V (c ~^_(V,C) d)) <*> (@comp_morphism V C a b c)) \; + (@comp_morphism V C a c d) ; + + ecat_comp_left_unital : forall a b: C, + forall l: onec * (a ~^_(V,C) b) ~>_V (a ~^_(V,C) b), + l = ((@id_element V C b) <*> (@idmap V (a ~^_(V,C) b))) \; + (@comp_morphism V C a b b) ; + ecat_comp_right_unital : forall a b: C, + forall r: (a ~^_(V,C) b) * onec ~>_V (a ~^_(V,C) b), + r = ((@idmap V (a ~^_(V,C) b)) <*> (@id_element V C a)) \; + (@comp_morphism V C a a b) +}. +Unset Universe Checking. +#[verbose] +HB.structure Definition EnCat (V: Monoidal.type) : Set := + { C of IsEnCat V C }. +Set Universe Checking. + +(********************************************************************) + +(*** DOUBLE CATEGORIES (without internal categories) *) + +(* Strict double categories, from + https://ncatlab.org/nlab/show/double+category + (we don't use internal categories) + + base obejcts as 0-cells: C ; + + vertical 1-morphisms (category D0 on C): hom C ; + + horizontal 1-morphisms (category H on C): hom (transpose C) ; + + horizontal 1-morhisms as 1-cells for D1: D1obj C ; + + 2-morphisms (category D1 on C1obj): hom (D1obj C) ; + + horizontally composable pairs of 1-cells : DPobj C ; + + horizontally composable pairs of 2-morphisms + (product category DP, D1 *0 D1) : hom (DPobj C) ; + + The definition of Strict Double Category, SDouble = (D0, H, D1, Dp), + is given by: + + - base objects C + + - (level-1) category (D0) of vertical 1-morphism on C + + - (level-1) category (H) of horizontal 1-morphism (D1obj) on C + + - (level-2) category (D1) of vertical 2-morphism on D1obj + + - (derived) category (DP) of vertical 2-morphisms on + horizontally D0-composable D1 products + ($\mbox{D1} *_0 \mbox{D1}$) + + - Source functor: $\mbox{D1} \to \mbox{D0}$ + + - Target functor: $\mbox{D1} \to \mbox{D0}$ + + - Horizontal unit functor: $\mbox{D0} \to \mbox{D1}$ + + - Horizontal composition functor: $\mbox{DP} \to \mbox{D1}$ +*) + + +(** Quivers for double categories *) + +(* transpose for horizontal morphism quiver. + HB.tag needed to identify transpose as lifter *) +HB.tag Definition transpose (C : quiver) : U := C. +#[wrapper] HB.mixin Record _IsHQuiver C of IsQuiver C := { + is_hquiver : IsQuiver (transpose C) +}. +(* vertical and horizontal quivers, defining cells *) +Unset Universe Checking. +#[short(type="vhquiver")] +HB.structure Definition VHQuiver : Set := + { C of IsQuiver C & IsQuiver (transpose C) }. +Set Universe Checking. + +HB.tag Definition hhom (c : VHQuiver.type) : c -> c -> U := @hom (transpose c). +Notation "a +> b" := (hhom a b) + (at level 99, b at level 200, format "a +> b") : cat_scope. + +(* record to represent the set of morphims + (needed for 2-objects, i.e. horizontal morphisms) *) +Record Total2 T (h: T -> T -> U) : Type := TT2 { + source : T; + target : T; + this_morph : h source target }. + +(* the set of horizontal morphisms. *) +HB.tag Definition D1obj (C: vhquiver) := Total2 (@hhom C). + +(* D1 quiver requirement (includes D0 quiver and its transpose). *) +#[wrapper] +HB.mixin Record _IsDQuiver T of VHQuiver T := + { is_dquiver : Quiver (D1obj T) }. +Unset Universe Checking. +#[short(type="dquiver")] +HB.structure Definition DQuiver : Set := { C of Quiver (D1obj C) }. +Set Universe Checking. + + +(** Horizonal D0-level category (H-D0) *) + +(* Precategory based on the HQuiver (i.e. horizontal precategory on D0 + objects) *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record _IsHPreCat T of VHQuiver T := { + is_hprecat : Quiver_IsPreCat (transpose T) }. +#[short(type="hprecat")] +HB.structure Definition HPreCat : Set := + { C of Quiver_IsPreCat (transpose C) }. +Set Universe Checking. + +(* The category based on the HQuiver (i.e. horizontal category on D0 + objects) *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record _IsHCat T of HPreCat T := { + is_hcat : PreCat_IsCat (transpose T) }. +#[short(type="hcat")] +HB.structure Definition HCat : Set := + { C of PreCat_IsCat (transpose C) }. +Set Universe Checking. + + +(** Vertical 2-cell level category (D1 category) *) + +(* Precategory based on the DQuiver (i.e. precategory D1). Gives: + vertical 2-cell identity morphism. + vertical 2-cell composition. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record _IsD1PreCat T of DQuiver T := { + is_d1precat : Quiver_IsPreCat (@D1obj T) }. +#[short(type="d1precat")] +HB.structure Definition D1PreCat : Set := + { C of Quiver_IsPreCat (@D1obj C) }. +Set Universe Checking. + +(* The category based on the DQuiver (i.e. category D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record _IsD1Cat T of D1PreCat T := { + is_d1cat : PreCat_IsCat (@D1obj T) }. +#[short(type="d1cat")] +HB.structure Definition D1Cat : Set := + { C of PreCat_IsCat (@D1obj C) }. +Set Universe Checking. + + +(** Naked double category *) + +(* Naked double category. Vertical (V-D0) and D1 categories. Double + category without horizontal operators and functors *) +Unset Universe Checking. +#[short(type="dcat")] +HB.structure Definition DCat : Set := + { C of Cat C & D1Cat C }. +Set Universe Checking. + +(* Naked strict double category. Vertical (V-D0), horizontal (H-D0) + and D1 categories. Strict double category without functors *) +Unset Universe Checking. +#[short(type="sd2cat")] +HB.structure Definition SDCat : Set := { C of Cat C & HCat C & D1Cat C }. +Set Universe Checking. + + +(** Auxiliary notions for Source, Target and + Horizontal Unit functors *) + + + +(* homsets of 2-cell (D1) morphisms *) +Definition d1hom (D: DQuiver.type) : D1obj D -> D1obj D -> U := + @hom (D1obj D). +(* type-level smart constructor for D1 homsets *) +Definition D1hom (D: DQuiver.type) (a b c d: D) (h0: hhom a b) + (h1: hhom c d) : U := d1hom (TT2 h0) (TT2 h1). + +(* smart projections for: + source functor (for horizontal morphisms): D1 -> D0. + defined as object-level function, by functoriality lifted to a + (2-cell, vertical) morphism-level one *) +HB.tag Definition HSource C := fun (X: D1obj C) => @source C (@hhom C) X. +(* target functor (for horizontal morphisms): D1 -> D0. *) +HB.tag Definition HTarget C := fun (X: D1obj C) => @target C (@hhom C) X. + +(* horizontal unit functor: D0 -> D1 *) +Definition hhunit (T: hprecat) (a: T) : D1obj T := + @TT2 T (@hhom T) a a (@idmap (transpose T) a). +HB.tag Definition H1Unit (C: hprecat) := + fun (x: HPreCat.sort C) => @hhunit C x. + + +(** Auxiliary notions for 2-cell Horizontal Composition functor *) + +(* composable pairs of morphisms as a set *) +Record GenComp T (h: T -> T -> U) := GC { + h_one : T; + h_two : T ; + h_three : T; + h_first : h h_one h_two ; + h_second : h h_two h_three }. + +(* composable pairs of horizontal morphisms as a set *) +HB.tag Definition DPobj (C: vhquiver) := GenComp (@hhom C). + +(* smart projections *) +Definition H2First (C: vhquiver) (X: @DPobj C) : D1obj C := + @TT2 C _ (h_one X) (h_two X) (h_first X). +Definition H2Second (C: vhquiver) (X: @DPobj C) : D1obj C := + @TT2 C _ (h_two X) (h_three X) (h_second X). + + +(* horizontal composition functor: D1 * D1 -> D1 *) +Definition hhcomp (T: hprecat) (x: DPobj T) : D1obj T := + match x with + @GC _ _ a b c h1 h2 => @TT2 T (@hhom T) a c (h1 \; h2) end. +HB.tag Definition H1Comp (C: hprecat) := + fun (x: DPobj C) => @hhcomp C x. + +(* hhunit - horizontal unit functor. + + hhcomp - horizontal composition functor (horizontal composition of + two horizontal morphisms from a cell product). + + Both specified as object-level functions (they actually come for + free from the H-D0 category, since we are in the strict case), to + be lifted by functoriality to morphism-level ones. + + At the object level, hhunit gives a horizontal identity morphism + for each D0 object. At the morphism level, it gives horizontal + 2-cell identity for each vertical morphism. + + In the case of hhcomp, relying on functoriality requires some care + in defining the product category, making sure that adjacency at the + object-level (between horizontal morphisms) is matched by adjacency + at the morphism-level (between 2-cells). *) + + +(** Source and target functors *) + +(* source prefunctor. + D1obj T is the quiver of the 2-morphisms, thanks to VHQuiver. + T is the quiver of 1-morphisms. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsSPreFunctor T of DCat T := { + is_sprefunctor : IsPreFunctor (D1obj T) T (@HSource T) }. +HB.structure Definition SPreFunctor : Set := {C of IsSPreFunctor C}. +Set Universe Checking. + +(* target prefunctor. *) +Unset Universe Checking. +#[wrapper] + HB.mixin Record IsTPreFunctor T of DCat T := { + is_tprefunctor : IsPreFunctor (D1obj T) T (@HTarget T) }. +HB.structure Definition TPreFunctor : Set := {C of IsTPreFunctor C}. +Set Universe Checking. + +(* source functor. *) +Unset Universe Checking. +#[wrapper] + HB.mixin Record SPreFunctor_IsFunctor T of SPreFunctor T := { + is_sfunctor : PreFunctor_IsFunctor (D1obj T) T (@HSource T) }. +HB.structure Definition SFunctor : Set := {C of SPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* target functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record TPreFunctor_IsFunctor T of TPreFunctor T := { + is_tfunctor : PreFunctor_IsFunctor (D1obj T) T (@HTarget T) }. +HB.structure Definition TFunctor : Set := {C of TPreFunctor_IsFunctor C}. +Set Universe Checking. + + +(** Unit functor *) + +(* unit prefunctor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsUPreFunctor T of SDCat T := + { is_uprefunctor : IsPreFunctor T (D1obj T) (@H1Unit T) }. +HB.structure Definition UPreFunctor : Set := {C of IsUPreFunctor C}. +Set Universe Checking. + +(* unit functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record UPreFunctor_IsFunctor T of UPreFunctor T := { + is_ufunctor : PreFunctor_IsFunctor T (D1obj T) (@H1Unit T) }. +HB.structure Definition UFunctor : Set := {C of UPreFunctor_IsFunctor C}. +Set Universe Checking. + +Unset Universe Checking. +HB.about Functor. +HB.structure Definition STUFunctor : Set := + {C of SFunctor C & TFunctor C & UFunctor C}. +Set Universe Checking. + + +(** Lifting of Source, Target and Unit functors to D1 morphisms *) + +(* 2-cell source *) +Definition H1Source (T: SFunctor.type) (a b: @D1obj T) + (m: @d1hom T a b) : + (HSource a) ~> (HSource b) := (@HSource T) <$> m. + +(* 2-cell target *) +Definition H1Target (T: TFunctor.type) (a b: @D1obj T) + (m: @d1hom T a b) : + (HTarget a) ~> (HTarget b) := (@HTarget T) <$> m. + +(* horizontal 2-cell unit (maps vertical morphisms to horizontally + unitary 2-cells) *) +Definition H2Unit (T: UFunctor.type) (a b: T) (m: @hom T a b) : + (H1Unit a) ~> (H1Unit b) := (@H1Unit T) <$> m. + + +(** Horizontal product category (D1 *d0 D1) *) +(* DPobj T is the pseudo-pullback category used to deal with + products of D1 (where the adjacency condition is expressed + w.r.t. D0 *) + +(* horizontal composition of two (naked) horizontal morphisms *) +Definition l_hcomp (T: SDCat.type) (a0 a1 a2: T) + (h0: hhom a0 a1) (h1: hhom a1 a2) : D1obj T := + @TT2 T _ a0 a2 (h0 \; h1). + +Notation "'sigma' x .. y , p" := + (sigT (fun x => .. (sigT (fun y => p)) ..)) + (at level 200, x binder, right associativity, + format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") + : type_scope. + +(** DPobj quiver *) +Definition DP_hom (T: STUFunctor.type) (x y: DPobj T) := + sigma (hh0: D1hom (h_first x) (h_first y)) + (hh1: D1hom (h_second x) (h_second y)), + H1Target hh0 = H1Source hh1. + +HB.instance Definition DPQuiver (T: STUFunctor.type) : + IsQuiver (DPobj T) := + IsQuiver.Build (DPobj T) (fun A B => @DP_hom T A B). + + +(** Product precategory *) + +Lemma DP_id_eq (T : STUFunctor.type) (a: DPobj T) : + H1Target (@idmap (@D1obj T) (H2First a)) = + H1Source (@idmap (@D1obj T) (H2Second a)). +unfold H1Target, HTarget. +unfold H1Source, HSource. +repeat rewrite F1; auto. +Defined. + +(* DPobj identity *) +Definition DP_id (T: STUFunctor.type) (A: DPobj T) : A ~> A := + let h0 := h_first A + in let h1 := h_second A + in let uu0 := @idmap (D1obj T) (TT2 h0) + in let uu1 := @idmap (D1obj T) (TT2 h1) + in @existT (D1hom h0 h0) + (fun hh0: (D1hom h0 h0) => + sigma (hh1 : D1hom h1 h1), H1Target hh0 = H1Source hh1) uu0 + (@existT (D1hom h1 h1) + (fun hh1: (D1hom h1 h1) => H1Target uu0 = H1Source hh1) uu1 + (@DP_id_eq T A)). + +Definition DP_comp_auxA (T : STUFunctor.type) + (A B C : DPobj T) + (hhA0 : D1hom (h_first A) (h_first B)) + (hhA1 : D1hom (h_second A) (h_second B)) + (ppA : H1Target hhA0 = H1Source hhA1) + (hhB0 : D1hom (h_first B) (h_first C)) + (hhB1 : D1hom (h_second B) (h_second C)) + (ppB : H1Target hhB0 = H1Source hhB1) : + (H1Target hhA0) \; (H1Target hhB0) = + (H1Source hhA1) \; (H1Source hhB1). + rewrite ppA. + rewrite ppB. + reflexivity. +Defined. + +Definition DP_comp_auxS (T : STUFunctor.type) + (A B C : DPobj T) + (hhA0 : D1hom (h_first A) (h_first B)) + (hhA1 : D1hom (h_second A) (h_second B)) + (ppA : H1Target hhA0 = H1Source hhA1) + (hhB0 : D1hom (h_first B) (h_first C)) + (hhB1 : D1hom (h_second B) (h_second C)) + (ppB : H1Target hhB0 = H1Source hhB1) : + H1Source (hhA1 \; hhB1) = (H1Source hhA1) \; (H1Source hhB1). + unfold H1Source, HSource. + repeat rewrite Fcomp. + reflexivity. +Defined. + +Definition DP_comp_auxT (T : STUFunctor.type) + (A B C : DPobj T) + (hhA0 : D1hom (h_first A) (h_first B)) + (hhA1 : D1hom (h_second A) (h_second B)) + (ppA : H1Target hhA0 = H1Source hhA1) + (hhB0 : D1hom (h_first B) (h_first C)) + (hhB1 : D1hom (h_second B) (h_second C)) + (ppB : H1Target hhB0 = H1Source hhB1) : + H1Target (hhA0 \; hhB0) = (H1Target hhA0) \; (H1Target hhB0). + unfold H1Target, HTarget. + repeat rewrite Fcomp. + reflexivity. +Defined. + +Definition DP_comp_auxI (T : STUFunctor.type) + (A B C : DPobj T) + (hhA0 : D1hom (h_first A) (h_first B)) + (hhA1 : D1hom (h_second A) (h_second B)) + (ppA : H1Target hhA0 = H1Source hhA1) + (hhB0 : D1hom (h_first B) (h_first C)) + (hhB1 : D1hom (h_second B) (h_second C)) + (ppB : H1Target hhB0 = H1Source hhB1) : + A ~> C. + econstructor 1 with (comp hhA0 hhB0). + econstructor 1 with (comp hhA1 hhB1). + setoid_rewrite DP_comp_auxS; eauto. + setoid_rewrite DP_comp_auxT; eauto. + eapply DP_comp_auxA; eauto. +Defined. + +(* DPobj composition, defined in proof mode *) +Definition DP_comp (T: STUFunctor.type) (A B C: DPobj T) : + (A ~> B) -> (B ~> C) -> A ~> C. + intros chA chB. + destruct chA as [hhA0 [hhA1 ppA]]. + destruct chB as [hhB0 [hhB1 ppB]]. + eapply DP_comp_auxI; eauto. +Defined. + +(* DPobj is a precategory *) +HB.instance Definition DPPreCat (T: STUFunctor.type) : + Quiver_IsPreCat (DPobj T) := + Quiver_IsPreCat.Build (DPobj T) (@DP_id T) (@DP_comp T). + +(* + have HcompP : + (a b : DPobj T) + (f g : a ~> b), + proj1T f = proj1t f -> + + -> + f = g. + + exists a b p, + fst f = a + f = (a,b,p) +*) + +(** Product category *) + +Lemma DP_LeftUnit_lemma (T : STUFunctor.type) : + forall (a b : DPobj T) (f : a ~> b), idmap \; f = f. + + move => a b [x [x0 e]] /=. + simpl in *. + unfold idmap; simpl. + unfold DP_id; simpl. + unfold comp; simpl. + unfold DP_comp_auxI; simpl. + + assert (idmap \; x = x) as A. + { rewrite comp1o; auto. } + + assert (idmap \; x0 = x0) as A0. + { rewrite comp1o; auto. } + + assert (H1Target (idmap \; x) = H1Source (idmap \; x0)) as B. + { rewrite A. + rewrite A0; auto. } + + destruct a eqn: aaa. + destruct b eqn: bbb. + simpl. + + assert (existT + (fun hh0 : D1hom h_first0 h_first1 => + sigma hh1 : D1hom h_second0 h_second1,H1Target hh0 = H1Source hh1) + (idmap \; x) + (existT + (fun hh1 : D1hom h_second0 h_second1 => + H1Target (idmap \; x) = H1Source hh1) + (idmap \; x0) + B) = + existT + (fun hh0 : D1hom h_first0 h_first1 => + sigma hh1 : D1hom h_second0 h_second1,H1Target hh0 = H1Source hh1) + x + (existT + (fun hh1 : D1hom h_second0 h_second1 => H1Target x = H1Source hh1) + x0 + e)) as C. + { revert B. + revert A. + revert A0. + generalize (idmap \; x) as v. + generalize (idmap \; x0) as v0. + intros v0 v A0. + rewrite A0. + intro A. + rewrite A. + intro B. + + assert (B = e) as BE. + { eapply Prop_irrelevance. } + + rewrite BE. + reflexivity. +} + + inversion aaa; subst. + rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] + (Prop_irrelevance _ B). + eapply C. +Qed. + +Lemma DP_RightUnit_lemma (T : STUFunctor.type) : + forall (a b : DPobj T) (f : a ~> b), f \; idmap = f. + + move => a b [x [x0 e]] /=. + simpl in *. + unfold idmap; simpl. + unfold DP_id; simpl. + unfold comp; simpl. + unfold DP_comp_auxI; simpl. + + assert (x \; idmap = x) as A. + { rewrite compo1; auto. } + + assert (x0 \; idmap = x0) as A0. + { rewrite compo1; auto. } + + assert (H1Target (x \; idmap) = H1Source (x0 \; idmap)) as B. + { rewrite A. + rewrite A0; auto. } + + destruct a eqn: aaa. + destruct b eqn: bbb. + simpl. + + assert (existT + (fun hh0 : D1hom h_first0 h_first1 => + sigma hh1 : D1hom h_second0 h_second1, + H1Target hh0 = H1Source hh1) + (x \; idmap) + (existT + (fun hh1 : D1hom h_second0 h_second1 => + H1Target (x \; idmap) = H1Source hh1) + (x0 \; idmap) + B) = + existT + (fun hh0 : D1hom h_first0 h_first1 => + sigma hh1 : D1hom h_second0 h_second1, + H1Target hh0 = H1Source hh1) + x + (existT + (fun hh1 : D1hom h_second0 h_second1 => + H1Target x = H1Source hh1) + x0 + e)) as C. + { revert B. + revert A. + revert A0. + generalize (x \; idmap) as v. + generalize (x0 \; idmap) as v0. + intros v0 v A0. + rewrite A0. + intro A. + rewrite A. + intro B. + + assert (B = e) as BE. + { eapply Prop_irrelevance. } + + rewrite BE. + reflexivity. + } + + inversion aaa; subst. + rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] + (Prop_irrelevance _ B). + eapply C. +Qed. + +Lemma DP_Assoc_lemma (T : STUFunctor.type) : + forall (a b c d : DPobj T) (f : a ~> b) (g : b ~> c) (h : c ~> d), + f \; g \; h = (f \; g) \; h. + intros. + remember f as f1. + remember g as g1. + remember h as h1. + destruct f as [x0 s0]. + destruct g as [x1 s1]. + destruct h as [x2 s2]. + destruct s0 as [y0 e0]. + destruct s1 as [y1 e1]. + destruct s2 as [y2 e2]. + simpl. + + set (x01 := comp x0 x1). + set (x12 := comp x1 x2). + set (x0_12 := comp x0 x12). + set (x01_2 := comp x01 x2). + set (y01 := comp y0 y1). + set (y12 := comp y1 y2). + set (y0_12 := comp y0 y12). + set (y01_2 := comp y01 y2). + + assert (x0_12 = x01_2) as X0. + { subst x0_12 x01_2. + rewrite compoA; eauto. } + assert (y0_12 = y01_2) as Y0. + { subst y0_12 y01_2. + rewrite compoA; eauto. } + + set (x01_t := comp (H1Target x0) (H1Target x1)). + set (x01_2_t := comp x01_t (H1Target x2)). + set (x12_t := comp (H1Target x1) (H1Target x2)). + set (x0_12_t := comp (H1Target x0) x12_t). + set (y01_s := comp (H1Source y0) (H1Source y1)). + set (y01_2_s := comp y01_s (H1Source y2)). + set (y12_s := comp (H1Source y1) (H1Source y2)). + set (y0_12_s := comp (H1Source y0) y12_s). + + assert (x01_t = y01_s) as E01. + { subst x01_t y01_s. + rewrite e0. + rewrite e1; auto. } + assert (x01_2_t = y01_2_s) as E01_2. + { subst x01_2_t y01_2_s. + rewrite E01. + rewrite e2; auto. } + assert (x12_t = y12_s) as E12. + { subst x12_t y12_s. + rewrite e1. + rewrite e2; auto. } + assert (x0_12_t = y0_12_s) as E0_12. + { subst x0_12_t y0_12_s. + rewrite E12. + rewrite e0; auto. } + + assert (x0_12_t = x01_2_t) as E02T. + { subst x0_12_t x01_2_t. + subst x12_t x01_t. + rewrite compoA; auto. } + assert (y0_12_s = y01_2_s) as E02S. + { subst y0_12_s y01_2_s. + subst y12_s y01_s. + rewrite compoA; auto. } + + unfold comp. + simpl. + unfold DP_comp. + simpl. + inversion Heqf1; subst. + clear H. + + unfold DP_comp_auxI; simpl. + + assert (H1Target (x0 \; x1 \; x2) = + H1Source (y0 \; y1 \; y2)) as KR. + { subst x0_12_t y0_12_s. + subst x12_t y12_s. + unfold H1Target. + repeat rewrite Fcomp; simpl. + unfold H1Target in E0_12. + rewrite E0_12. + unfold H1Source. + repeat rewrite Fcomp; simpl. + auto. + } + + assert (H1Target ((x0 \; x1) \; x2) = + H1Source ((y0 \; y1) \; y2)) as KL. + { subst x01_2_t y01_2_s. + subst x01_t y01_s. + unfold H1Target. + repeat rewrite Fcomp; simpl. + unfold H1Target in E01_2. + rewrite E01_2. + unfold H1Source. + repeat rewrite Fcomp; simpl. + auto. + } + + assert (existT + (fun hh0 : D1hom (h_first a) (h_first d) => + sigma hh1 : D1hom (h_second a) (h_second d), + H1Target hh0 = H1Source hh1) + (x0 \; x1 \; x2) + (existT + (fun hh1 : D1hom (h_second a) (h_second d) => + H1Target (x0 \; x1 \; x2) = H1Source hh1) + (y0 \; y1 \; y2) + KR) + = + existT + (fun hh0 : D1hom (h_first a) (h_first d) => + sigma hh1 : D1hom (h_second a) (h_second d), + H1Target hh0 = H1Source hh1) + ((x0 \; x1) \; x2) + (existT + (fun hh1 : D1hom (h_second a) (h_second d) => + H1Target ((x0 \; x1) \; x2) = H1Source hh1) + ((y0 \; y1) \; y2) + KL)) as KA. + { revert KL. + revert KR. + subst x0_12 x01_2 x12 x01. + subst y0_12 y01_2 y12 y01. + rewrite <- X0. + rewrite <- Y0. + intros KR KL. + + assert (KR = KL) as I1. + { eapply Prop_irrelevance. } + rewrite I1. + reflexivity. + } + + rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] + (Prop_irrelevance _ KR). + + rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] + (Prop_irrelevance _ KL). + eapply KA. +Qed. + +Program Definition DPCatP (T: STUFunctor.type) : + PreCat_IsCat (DPobj T). +econstructor. +eapply DP_LeftUnit_lemma; eauto. +eapply DP_RightUnit_lemma; eauto. +eapply DP_Assoc_lemma; eauto. +Qed. + +(* DPobj is a category *) +HB.instance Definition DPCat (T: STUFunctor.type) := DPCatP T. + + +(** Horizontal composition functor and strict double categories *) + +(* composition prefunctor *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsCPreFunctor T of STUFunctor T := + { is_cprefunctor : IsPreFunctor (DPobj T) (D1obj T) (@H1Comp T) }. +HB.structure Definition CPreFunctor : Set := {C of IsCPreFunctor C}. +Set Universe Checking. + +(* composition functor - gives the definition of Strict Double Category *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record CPreFunctor_IsFunctor T of CPreFunctor T := { + is_cfunctor : PreFunctor_IsFunctor (DPobj T) (D1obj T) (@H1Comp T) }. +#[short(type="sdoublecat")] +HB.structure Definition SDoubleCat : Set := {C of CPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* horizontal 2-cell composition: maps two adjecent pairs of + horizontal morphisms (a and b) and a pullback-category morphism + between them (m, which basically gives two adjecent cells) to a + 2-cell morphism between the horizontal composition (HComp) of each + pair *) +Definition HC2Comp (T: SDoubleCat.type) (a b: DPobj T) + (m: @hom (DPobj T) a b) : + d1hom (H1Comp a) (H1Comp b) := @Fhom _ _ (@H1Comp T) a b m. + +Program Definition HC2Comp_flat (T: SDoubleCat.type) (a0 a1 a2 b0 b1 b2: T) + (h0: hhom a0 a1) (h1: hhom a1 a2) + (k0: hhom b0 b1) (k1: hhom b1 b2) + (hh0: D1hom h0 k0) + (hh1: D1hom h1 k1) + (k: H1Target hh0 = H1Source hh1) + : (* D1hom (hcomp _ _ _ h0 h1) (hcomp _ _ _ k0 k1) *) + d1hom (l_hcomp h0 h1) (l_hcomp k0 k1) := + @Fhom _ _ (@H1Comp T) (GC h0 h1) (GC k0 k1) _. +Obligation 1. +refine (@existT (D1hom h0 k0) _ hh0 (@existT (D1hom h1 k1) _ hh1 k)). +Defined. + +(********************************************************************) +(********************************************************************) + + +Section th_of_pb. +Variables (Q : cat) (A B C D E F : Q). +Variables (f : A ~> D) (g : B ~> D) (h : C ~> A). +Variables (u : E ~> A) (v : E ~> B) (w : F ~> C) (z : F ~> E). +Variable (uvfg : pbsquare u v f g). + +Set Printing Width 50. +Theorem pbsquarec_compP : + pbsquare w z h u <=> pbsquare w (z \; v) (h \; f) g. +Proof. +split=> [] sq. + + have @sq_ispb : pullback (Cospan h u) := HB.pack (Span w z) sq. + have @uvfg_ispb : pullback (Cospan f g) := HB.pack (Span u v) uvfg. + have /=E2 := @is_square _ _ _ _ sq_ispb. + have /=E1 := @is_square _ _ _ _ uvfg_ispb. + + have p1 : @isPrePullback Q C B (Cospan (h \; f) g) (Span w (z \; v)). + by constructor; rewrite /= compoA E2 -compoA E1 compoA. + pose big_black_square : prepullback (Cospan (h \; f) g) := + HB.pack (Span w (z \; v)) p1. + + have @from : forall + (big_red_square : prepullback {| top := D; left2top := h \; f; right2top := g |}), + big_red_square ~> pb_terminal big_black_square. + + move=> big_red_square; unfold pb_terminal. + + have /= := @is_square _ _ _ _ big_red_square. + + pose F' := bot big_red_square. + set w' : F' ~> C := bot2left big_red_square. + set z' : F' ~> B := bot2right big_red_square. + move=> E3. + + have xxx : isPrePullback Q A B (Cospan f g) (Span (w' \; h) z'). + by constructor=> /=; rewrite -compoA E3. + pose red_black_square : prepullback (Cospan f g) := + HB.pack (Span (w' \; h) z') xxx. + have := @from_unique _ (pb_terminal uvfg_ispb) red_black_square. + set blue := @from _ (pb_terminal uvfg_ispb) red_black_square. + move=> blue_unique. + + have p3 : @isPrePullback Q C E (Cospan h u) (Span w' (bot_map blue)). + by constructor; rewrite /= (bot2left_map blue). (* buggy unifier without blue *) + pose blue_red_black_square : prepullback (Cospan h u) := + HB.pack (Span w' (bot_map blue)) p3. + + pose red := @from _ (pb_terminal sq_ispb) blue_red_black_square. + + admit. + + + + have p2 : prepullback_isTerminal.axioms_ Q C B (Cospan (h \; f) g) (Span w (z \; v)) p1. + constructor. econstructor=> /=. + admit. + + by HB.from p1 p2. + +Admitted. + +End th_of_pb. + + +Module test. + +Section test. +Variables (Q : precat) (A B : Q) (c : cospan A B). +Variable (p : pullback c). +Check pb_terminal p : terminal _. + +End test. +End test. + + + + From 5cb88f9334e1711f188ec38ce28c6c6e04ac6bf2 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Mon, 27 Nov 2023 14:19:45 +0100 Subject: [PATCH 095/147] updated encatD.v --- theories/encatD.v | 89 ++++++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 39 deletions(-) diff --git a/theories/encatD.v b/theories/encatD.v index 86a44787c..04644331c 100644 --- a/theories/encatD.v +++ b/theories/encatD.v @@ -1116,71 +1116,82 @@ Program Definition iprod_iHom {C: pbcat} {C0: C} (X Y: @iHom C C0) : ((iprodl X Y) \; src) ((iprodr X Y) \; tgt). - - -(* -(* X and Y are morphisms in the morphism object associated with C0 *) -Definition iprod {C: pbcat} {C0 : C} (X Y : @iHom C C0) : C := - bot (pb _ _ (Cospan (tgt : X ~> C0) (src : Y ~> C0))). -Notation "X *_ C0 Y" := (@iprod _ C0 X Y) - (at level 99, C0 at level 0, only parsing) : cat_scope. -*) -(* -HB.instance Definition iprod_iHom := - isInternalHom.Build C0 (X *_C0 Y) (src (bot2left _)) (tgt (bot2right _)). -*) - -(* -Definition iprodl {C} {C0 : C} (X Y : iHom C0) : X *_C0 Y ~> X := - bot2left. -Definition iprodr {C} {C0 : C} (X Y : iHom C0) : X *_C0 Y ~> Y := - bot2right. -*) - (* we also define the trivial internal hom type *) HB.instance Definition trivial_iHom {C: pbcat} {C0: C} := isInternalHom.Build C C0 C0 idmap idmap. (* we need internal hom morphisms: the ones that preserve sources and targets *) -HB.mixin Record IsInternalHomHom {C} (C0 : C) - (C1 C1' : @iHom U C) (f : C1 ~> C1') := { +HB.mixin Record IsInternalHomHom {C: pbcat} (C0 : C) + (C1 C1' : @iHom C C0) (f : C1 ~> C1') := { hom_src : f \; src = src; hom_tgt : f \; tgt = tgt; }. #[short(type="iHomHom")] -HB.structure Definition InternalHomHom {C} - (C0 : C) (C1 C1' : @iHom U C) := - { f of @IsInternalHomHom C C0 C1 C1' f }. +HB.structure Definition InternalHomHom {C: pbcat} + (C0 : C) (C1 C1' : @iHom C C0) := + { f of @IsInternalHomHom C C0 C1 C1' f }. (* internal homs form a category, the morphisms are the one that preserve source and target *) -HB.instance Definition _ {C} (C0 : C) := - Cat.Build (@iHom C C0) (@iHomHom C C0) _ _ _ _ _. +HB.instance Definition iHom_quiver {C: pbcat} (C0 : C) : + IsQuiver (@iHom C C0) := + IsQuiver.Build (@iHom C C0) (@iHomHom C C0). -Definition iprodA {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0): - (C1 *_C0 C2) *_C0 C3 ~> C1 *_C0 (C2 *_C0 C3) := ... - (* define it with the universal arrow of the pullback *) +Program Definition iHom_precat {C: pbcat} (C0 : C) : + Quiver_IsPreCat (@iHom C C0) := + Quiver_IsPreCat.Build (@iHom C C0) _ _. +Obligation 1. +Admitted. +Obligation 2. +Admitted. -Definition ipair {C : pbcat} {C0 : C} {C1 C2 C3 C4 : iHom C0} - (f : C1 ~> C3) (g : C2 ~> C4) : C1 *_C0 C2 ~> C3 *_C0 C4 := ... +HB.instance Definition iHom_precat' {C: pbcat} (C0 : C) := iHom_precat C0. + +Program Definition iHom_cat {C: pbcat} (C0 : C) : + PreCat_IsCat (@iHom C C0) := + PreCat_IsCat.Build (@iHom C C0) _ _ _. +Obligation 1. +Admitted. +Obligation 2. +Admitted. +Obligation 3. +Admitted. + +HB.instance Definition iHom_cat' {C: pbcat} (C0 : C) := iHom_cat C0. -Notation "< f , g >" := (ipair f g). (* Now we define an internal quiver as an object C0, which has a C1 : iHom C0 attached to it *) -HB.mixin Record IsPreInternalQuiver {C} (C0 : C) := PreInteralQuiver { C1 : C }. -#[short(type="internalQuiver")] +HB.mixin Record IsPreInternalQuiver {C} (C0 : C) := + { isC1 : C }. +(* PROBLEM: probably a bug *) +Fail #[short(type="preInternalQuiver")] +HB.structure Definition PreInternalQuiver {C} := { + C0 of IsPreInternalQuiver C C0 }. + +Fail #[short(type="internalQuiver")] HB.structure Definition InternalQuiver {C} := { - C0 of IsPreInternalQuiver C0 & InternalHom C0 (@C1 C0) + C0 of IsPreInternalQuiver C C0 & InternalHom C C0 (@C1 C C0) }. +(* PROBLEM: nested product does not typecheck *) +Fail Definition iprodA {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0): + (C1 *_C0 C2) *_C0 C3 ~> C1 *_C0 (C2 *_C0 C3). (* := ... *) + (* define it with the universal arrow of the pullback *) + +Definition ipair {C : pbcat} {C0 : C} {C1 C2 C3 C4 : iHom C0} + (f : C1 ~> C3) (g : C2 ~> C4) : C1 *_C0 C2 ~> C3 *_C0 C4. +Admitted. +Notation "< f , g >" := (ipair f g). + + (* An internal precategory is an internal category with two operators that must be src and tgt preserving, i.e. iHom morphisms *) HB.mixin Record IsInternalPreCat (C : pbcat) (C0 : C) of InternalQuiver C0 := { iid : C0 ~>_(iHom C0) C1; - icomp : C1 *_C0 C1 ~>_(iHom C0) C1; -} + icomp : C1 *_C0 C1 ~>_(iHom C0) C1 +}. #[short(type="internalprecat")] HB.structure Definition InternalPrecat (C : pbcat) := { q of @IsPreInternalPreCat C q }. From 7a60a013630a1156874a1c21942ec7510618077d Mon Sep 17 00:00:00 2001 From: ptorrx Date: Tue, 28 Nov 2023 15:34:48 +0100 Subject: [PATCH 096/147] updated encatD.v, added definition of internal category based on operators --- theories/encatD.v | 420 +++++++++++++++++++++++++--------------------- 1 file changed, 227 insertions(+), 193 deletions(-) diff --git a/theories/encatD.v b/theories/encatD.v index 04644331c..e26ea5e91 100644 --- a/theories/encatD.v +++ b/theories/encatD.v @@ -1014,29 +1014,13 @@ Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). (********************************************************************) (********************************************************************) -(* Defining a category with pullbacks -Ideally span is in fact expanded and the final mixin has +(*** CATEGORIES WITH PULLBACKS *) + +(* category with all prepullbacks *) +(* Ideally span is in fact expanded and the final mixin has a pb : forall A B, cospan A B -> C but it is not clear how to do that yet *) -(* Definition has_all_pbcks (C: Quiver.type) : Type := - forall (A B: C), cospan A B -> span A B. -HB.mixin Record HasPBop C of Cat C := { - pb : has_all_pbcks C - }. - -Definition pb_is_pullback (C: PBop.type) : Type := - forall (a b: C) (c: cospan a b), Pullback C c (@pb C a b c). -HB.mixin Record IsPBCat C of PBop C : Type := - { - is_pb : pb_is_pullback C - }. -#[short(type="pbcat")] -HB.structure Definition PBCat := - {C of IsPBCat C}. -*) - -(* category with all prepullbacks *) HB.mixin Record HasPBop C of Cat C := { pb : forall (A B: C), cospan A B -> span A B }. @@ -1053,182 +1037,64 @@ HB.mixin Record HasPBCat C of PBop C : Type := { HB.structure Definition PBCat := {C of HasPBCat C}. -(* Defining internal hom objects. - C0 and C1 are objects of C. - C0 is the object of objects, - C1 is the object of morphims (and the subject). - this will allow to define a generic _ *_C0 _ notation - by recognizing the structure of hom objects on the LHS and RHS *) -HB.mixin Record isInternalHom {C: quiver} (C0 C1 : C) := { - src : C1 ~> C0; tgt : C1 ~> C0 -}. -#[short(type="iHom")] -HB.structure Definition InternalHom {C: quiver} (C0 : C) := - { C1 of isInternalHom C C0 C1 }. - -(* -Definition tgt' := @tgt. -Arguments tgt' {_ _} _. - -(* X and Y are morphisms in the morphism object associated with C0 *) -Definition iprod {C: pbcat} {C0 : C} (X Y : @iHom C C0) : C := - bot (pb _ _ (Cospan (tgt : InternalHom.sort X ~> C0) (src : Y ~> C0))). -Notation "X *_ C0 Y" := (@iprod _ C0 X Y) (at level 99). -*) -(* BEWARE: this cospan is a type-level one: it basically just says -that for ANY morphism, source and target are objects (NOT necesarily -the SAME object). X and Y are two instances of the morphism object -(iHom C0), which (unlike in most presentations) depends on the object -of objects C0. This is just like saying that X and Y are two versions -of C1 (I find this duplication, which does not appear in the -literature, rather confusing). X and Y are NOT two distinct morphisms -in the ambient category. The cospan does NOT imply that ambient -morphisms typed by X and Y are composable (i.e. adjacent). Also, the -pullback is not a morphism, it is just an object of C (also rather -confusing). - -original Cyril's code: - -Definition iprod {C} {C0 : C} (X Y : iHom C0) := bottom (pb (Cospan - (src X) (tgt Y))). Notation "X *_ C0 Y" := (@iprod _ C0 X Y). - -HB.instance Definition iprod_iHom := isInternalHom.Build C0 (X *_C0 Y) - (src (bot2left _)) (tgt (bot2right _)). *) -Definition iprod_pb {C: pbcat} {C0 : C} (X Y : iHom C0) : span X Y := - pb _ _ (Cospan (tgt : X ~> C0) (src : Y ~> C0)). - -Definition iprod {C: pbcat} {C0 : C} (X Y : iHom C0) : C := - bot (@iprod_pb C C0 X Y). -Notation "X *_ C0 Y" := (@iprod _ C0 X Y) - (at level 99, C0 at level 0, only parsing) : cat_scope. - -Definition iprodl {C: pbcat} {C0 : C} (X Y : iHom C0) : X *_C0 Y ~> X := - bot2left (iprod_pb X Y). -Definition iprodr {C: pbcat} {C0 : C} (X Y : iHom C0) : X *_C0 Y ~> Y := - bot2right (iprod_pb X Y). - -(* Given (iHom C0) instances X and Y, we want to say that (X *_C0 Y) -is also an instance of (iHom C0). Notice, however, that X and Y do not -represent composable morphisms *) -Program Definition iprod_iHom {C: pbcat} {C0: C} (X Y: @iHom C C0) : - @isInternalHom C C0 (X *_C0 Y) := - @isInternalHom.Build C C0 (X *_C0 Y) - ((iprodl X Y) \; src) - ((iprodr X Y) \; tgt). - -(* we also define the trivial internal hom type *) -HB.instance Definition trivial_iHom {C: pbcat} {C0: C} := - isInternalHom.Build C C0 C0 idmap idmap. - -(* we need internal hom morphisms: -the ones that preserve sources and targets *) -HB.mixin Record IsInternalHomHom {C: pbcat} (C0 : C) - (C1 C1' : @iHom C C0) (f : C1 ~> C1') := { - hom_src : f \; src = src; - hom_tgt : f \; tgt = tgt; -}. -#[short(type="iHomHom")] -HB.structure Definition InternalHomHom {C: pbcat} - (C0 : C) (C1 C1' : @iHom C C0) := - { f of @IsInternalHomHom C C0 C1 C1' f }. - -(* internal homs form a category, - the morphisms are the one that preserve source and target *) -HB.instance Definition iHom_quiver {C: pbcat} (C0 : C) : - IsQuiver (@iHom C C0) := - IsQuiver.Build (@iHom C C0) (@iHomHom C C0). - -Program Definition iHom_precat {C: pbcat} (C0 : C) : - Quiver_IsPreCat (@iHom C C0) := - Quiver_IsPreCat.Build (@iHom C C0) _ _. -Obligation 1. -Admitted. -Obligation 2. -Admitted. - -HB.instance Definition iHom_precat' {C: pbcat} (C0 : C) := iHom_precat C0. - -Program Definition iHom_cat {C: pbcat} (C0 : C) : - PreCat_IsCat (@iHom C C0) := - PreCat_IsCat.Build (@iHom C C0) _ _ _. -Obligation 1. -Admitted. -Obligation 2. -Admitted. -Obligation 3. -Admitted. - -HB.instance Definition iHom_cat' {C: pbcat} (C0 : C) := iHom_cat C0. - - -(* Now we define an internal quiver as an object C0, - which has a C1 : iHom C0 attached to it *) -HB.mixin Record IsPreInternalQuiver {C} (C0 : C) := - { isC1 : C }. -(* PROBLEM: probably a bug *) -Fail #[short(type="preInternalQuiver")] -HB.structure Definition PreInternalQuiver {C} := { - C0 of IsPreInternalQuiver C C0 }. - -Fail #[short(type="internalQuiver")] -HB.structure Definition InternalQuiver {C} := { - C0 of IsPreInternalQuiver C C0 & InternalHom C C0 (@C1 C C0) -}. - -(* PROBLEM: nested product does not typecheck *) -Fail Definition iprodA {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0): - (C1 *_C0 C2) *_C0 C3 ~> C1 *_C0 (C2 *_C0 C3). (* := ... *) - (* define it with the universal arrow of the pullback *) - -Definition ipair {C : pbcat} {C0 : C} {C1 C2 C3 C4 : iHom C0} - (f : C1 ~> C3) (g : C2 ~> C4) : C1 *_C0 C2 ~> C3 *_C0 C4. -Admitted. -Notation "< f , g >" := (ipair f g). - - -(* An internal precategory is an internal category with two operators that - must be src and tgt preserving, i.e. iHom morphisms *) -HB.mixin Record IsInternalPreCat (C : pbcat) (C0 : C) of InternalQuiver C0 := { - iid : C0 ~>_(iHom C0) C1; - icomp : C1 *_C0 C1 ~>_(iHom C0) C1 -}. -#[short(type="internalprecat")] -HB.structure Definition InternalPrecat (C : pbcat) := - { q of @IsPreInternalPreCat C q }. - -(* An internal category moreover must satisfy additional properies on iid and icomp *) -HB.mixin Record IsInternalCat (C : pbcat) (C0 : C) of InternalPreCat C0 := { - icompA : \; icomp = iprodA \; \; icomp; - icomp1l : \; icomp = iprodl; - icomp1r : \; icomp = iprodr; -HB.structure Definition InternalCat (C : pbcat) := {C0 of @IsInternalCat C C0}. - -(* A double category is an internal category in cat - - The objects are the objects of C0 - - The vertical maps are the maps of C0 - - The horizontal maps are the objects of C1 - - The 2-cells are the maps of C1 - - About identities: - - The identity vertical map on (x : C) is \idmap_x - - The identity horizontal map on (x : C) is iid x - - the identity 2-cell on (x : C) is iid (\idmap_x) = \idmap_(iid x) - - About compositions: - - The vertical composition of maps is the composition of C0 - - The vertical compositions of 2-cells is the composition of C1 - (and it agrees with the former because src and tgt are functors - and because iid is a iHom-map) - - The horizontal composition of maps is the object part of icomp - - The horizontal composition of 2-cells is the map part of icomp -*) -HB.structure' Definition DoubleCat := @InternalCat cat. +(********************************************************************) +(*** INTERNAL CATEGORIES *) + +HB.mixin Record IsIObject C of Cat C := { + Obj : C ; + Morph : C +}. +HB.structure Definition IObject := + { C of IsIObject C }. + +HB.mixin Record HasProd C of IObject C := { + prd : C -> C -> C ; + prj1 : forall c1 c2, prd c1 c2 ~> c1 ; + prj2 : forall c1 c2, prd c1 c2 ~> c2 ; + mprd : forall c1 c2 c3 c4, + (c1 ~> c3) -> (c2 ~> c4) -> prd c1 c2 ~> prd c3 c4 ; + mjn : forall c1 c2 c3, + (c1 ~> c2) -> (c1 ~> c3) -> c1 ~> prd c2 c3 +}. +HB.structure Definition Prod := + { C of HasProd C }. + +HB.mixin Record IsIQuiver C of Prod C := { + iid : Obj ~>_C Morph ; + isrc : Morph ~>_C Obj ; + itrg : Morph ~>_C Obj ; + icmp : @prd C Morph Morph ~> Morph +}. +HB.structure Definition IQuiver := + { C of IsIQuiver C }. + +HB.mixin Record IsICat C of IQuiver C := { + iid_s : iid \; isrc = @idmap C Obj ; + iid_t : iid \; itrg = @idmap C Obj ; + icmp_s : @icmp C \; isrc = prj1 Morph Morph \; isrc ; + icmp_t : @icmp C \; itrg = prj2 Morph Morph \; itrg ; + unit_l : mprd Obj Morph Morph Morph iid (@idmap C Morph) \; icmp = + prj2 Obj Morph ; + unit_r : mprd Morph Obj Morph Morph (@idmap C Morph) iid \; icmp = + prj1 Morph Obj ; + assoc : mprd (prd Morph Morph) Morph Morph Morph icmp (@idmap C Morph) + \; icmp = + (mjn (prd (prd Morph Morph) Morph) Morph (prd Morph Morph) + (prj1 (prd Morph Morph) Morph \; prj1 Morph Morph) + (mjn (prd (prd Morph Morph) Morph) Morph Morph + (prj1 (prd Morph Morph) Morph \; prj2 Morph Morph) + (prj2 (prd Morph Morph) Morph))) \; + (mprd Morph (prd Morph Morph) Morph Morph (@idmap C Morph) icmp) \; icmp +}. +HB.structure Definition ICat := + { C of IsICat C }. +(********************************************************************) -(*** ENRICHED CATEGORIES *) +(*** GENERALISED ENRICHED CATEGORIES *) Declare Scope encat_scope. Delimit Scope encat_scope with encat. @@ -1463,8 +1329,6 @@ Set Universe Checking. (** Auxiliary notions for Source, Target and Horizontal Unit functors *) - - (* homsets of 2-cell (D1) morphisms *) Definition d1hom (D: DQuiver.type) : D1obj D -> D1obj D -> U := @hom (D1obj D). @@ -2163,4 +2027,174 @@ End test. +(************************************************************************) + +(**** INTERNAL CATEGORIES - ALTERNATIVE DEFINITION *) +(* still problematic *) + +(* Defining internal hom objects. + C0 and C1 are objects of C. + C0 is the object of objects, + C1 is the object of morphims (and the subject). + this will allow to define a generic _ *_C0 _ notation + by recognizing the structure of hom objects on the LHS and RHS *) +HB.mixin Record isInternalHom {C: quiver} (C0 C1 : C) := { + src : C1 ~> C0; tgt : C1 ~> C0 +}. +#[short(type="iHom")] +HB.structure Definition InternalHom {C: quiver} (C0 : C) := + { C1 of isInternalHom C C0 C1 }. + +(* +Definition tgt' := @tgt. +Arguments tgt' {_ _} _. +*) +(* The cospan is a type-level one: it says that for ANY morphism, +source and target are objects (NOT necesarily the SAME object). X and +Y are two instances of the morphism object (iHom C0), which here +depends on the object of objects C0. Basically, X and Y are two +versions of C1. X and Y are NOT two distinct morphisms in the ambient +category. The cospan does NOT imply that ambient morphisms typed by X +and Y are composable (i.e. adjacent). 'iprod' is not a morphism, it is +just an object of C. + +Original code: + +Definition iprod {C} {C0 : C} (X Y : iHom C0) := bottom (pb (Cospan + (src X) (tgt Y))). Notation "X *_ C0 Y" := (@iprod _ C0 X Y). + +HB.instance Definition iprod_iHom := isInternalHom.Build C0 (X *_C0 Y) + (src (bot2left _)) (tgt (bot2right _)). *) +Definition iprod_pb {C: pbcat} {C0 : C} (X Y : iHom C0) : span X Y := + pb _ _ (Cospan (tgt : X ~> C0) (src : Y ~> C0)). + +Definition iprod {C: pbcat} {C0 : C} (X Y : iHom C0) : C := + bot (@iprod_pb C C0 X Y). +Notation "X *_ C0 Y" := (@iprod _ C0 X Y) + (at level 99, C0 at level 0, only parsing) : cat_scope. + +Definition iprodl {C: pbcat} {C0 : C} (X Y : iHom C0) : X *_C0 Y ~> X := + bot2left (iprod_pb X Y). +Definition iprodr {C: pbcat} {C0 : C} (X Y : iHom C0) : X *_C0 Y ~> Y := + bot2right (iprod_pb X Y). + +(* Given (iHom C0) instances X and Y, we want to say that (X *_C0 Y) +is also an instance of (iHom C0). Notice, however, that X and Y do not +represent composable morphisms *) +Program Definition iprod_iHom {C: pbcat} {C0: C} (X Y: @iHom C C0) : + @isInternalHom C C0 (X *_C0 Y) := + @isInternalHom.Build C C0 (X *_C0 Y) + ((iprodl X Y) \; src) + ((iprodr X Y) \; tgt). + +(* we also define the trivial internal hom type *) +HB.instance Definition trivial_iHom {C: pbcat} {C0: C} := + isInternalHom.Build C C0 C0 idmap idmap. + +(* we need internal hom morphisms: +the ones that preserve sources and targets *) +HB.mixin Record IsInternalHomHom {C: pbcat} (C0 : C) + (C1 C1' : @iHom C C0) (f : C1 ~> C1') := { + hom_src : f \; src = src; + hom_tgt : f \; tgt = tgt; +}. +#[short(type="iHomHom")] +HB.structure Definition InternalHomHom {C: pbcat} + (C0 : C) (C1 C1' : @iHom C C0) := + { f of @IsInternalHomHom C C0 C1 C1' f }. + +(* internal homs form a category, + the morphisms are the one that preserve source and target *) +HB.instance Definition iHom_quiver {C: pbcat} (C0 : C) : + IsQuiver (@iHom C C0) := + IsQuiver.Build (@iHom C C0) (@iHomHom C C0). + +Program Definition iHom_precat {C: pbcat} (C0 : C) : + Quiver_IsPreCat (@iHom C C0) := + Quiver_IsPreCat.Build (@iHom C C0) _ _. +Obligation 1. +Admitted. +Obligation 2. +Admitted. + +HB.instance Definition iHom_precat' {C: pbcat} (C0 : C) := iHom_precat C0. + +Program Definition iHom_cat {C: pbcat} (C0 : C) : + PreCat_IsCat (@iHom C C0) := + PreCat_IsCat.Build (@iHom C C0) _ _ _. +Obligation 1. +Admitted. +Obligation 2. +Admitted. +Obligation 3. +Admitted. + +HB.instance Definition iHom_cat' {C: pbcat} (C0 : C) := iHom_cat C0. + + +(* Now we define an internal quiver as an object C0, + which has a C1 : iHom C0 attached to it *) +HB.mixin Record IsPreInternalQuiver {C} (C0 : C) := + { isC1 : C }. +(* PROBLEM: probably a bug *) +Fail #[short(type="preInternalQuiver")] +HB.structure Definition PreInternalQuiver {C} := { + C0 of IsPreInternalQuiver C C0 }. + +Fail #[short(type="internalQuiver")] +HB.structure Definition InternalQuiver {C} := { + C0 of IsPreInternalQuiver C C0 & InternalHom C C0 (@C1 C C0) +}. + +(* PROBLEM: nested product does not typecheck *) +Fail Definition iprodA {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0): + (C1 *_C0 C2) *_C0 C3 ~> C1 *_C0 (C2 *_C0 C3). (* := ... *) + (* define it with the universal arrow of the pullback *) + +Definition ipair {C : pbcat} {C0 : C} {C1 C2 C3 C4 : iHom C0} + (f : C1 ~> C3) (g : C2 ~> C4) : C1 *_C0 C2 ~> C3 *_C0 C4. +Admitted. +Notation "< f , g >" := (ipair f g). + + +(* An internal precategory is an internal category with two operators that + must be src and tgt preserving, i.e. iHom morphisms *) +HB.mixin Record IsInternalPreCat (C : pbcat) (C0 : C) of + InternalQuiver C0 := { + iid : C0 ~>_(iHom C0) C1; + icomp : C1 *_C0 C1 ~>_(iHom C0) C1 +}. +#[short(type="internalprecat")] +HB.structure Definition InternalPrecat (C : pbcat) := + { q of @IsPreInternalPreCat C q }. + +(* An internal category moreover must satisfy additional properies on iid and icomp *) +HB.mixin Record IsInternalCat (C : pbcat) (C0 : C) of InternalPreCat C0 := { + icompA : \; icomp = iprodA \; \; icomp; + icomp1l : \; icomp = iprodl; + icomp1r : \; icomp = iprodr; +HB.structure Definition InternalCat (C : pbcat) := {C0 of @IsInternalCat C C0}. + +(* A double category is an internal category in cat + - The objects are the objects of C0 + - The vertical maps are the maps of C0 + - The horizontal maps are the objects of C1 + - The 2-cells are the maps of C1 + + About identities: + - The identity vertical map on (x : C) is \idmap_x + - The identity horizontal map on (x : C) is iid x + - the identity 2-cell on (x : C) is iid (\idmap_x) = \idmap_(iid x) + + About compositions: + - The vertical composition of maps is the composition of C0 + - The vertical compositions of 2-cells is the composition of C1 + (and it agrees with the former because src and tgt are functors + and because iid is a iHom-map) + - The horizontal composition of maps is the object part of icomp + - The horizontal composition of 2-cells is the map part of icomp +*) +HB.structure' Definition DoubleCat := @InternalCat cat. + + From 45565f9fe89cfda07c6f226e7bf84a6d478152c2 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Wed, 29 Nov 2023 14:15:33 +0100 Subject: [PATCH 097/147] updated encatD.v, complete definition of internal category based on NLab --- theories/encatD.v | 123 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 93 insertions(+), 30 deletions(-) diff --git a/theories/encatD.v b/theories/encatD.v index e26ea5e91..0d756ba8c 100644 --- a/theories/encatD.v +++ b/theories/encatD.v @@ -1041,15 +1041,20 @@ HB.structure Definition PBCat := (********************************************************************) (*** INTERNAL CATEGORIES *) +(* based on the NLab definition at + https://ncatlab.org/nlab/show/internal+category +*) -HB.mixin Record IsIObject C of Cat C := { +(* category extended with internal objects *) +HB.mixin Record HasIObjects C of Cat C := { Obj : C ; - Morph : C + Mor : C }. -HB.structure Definition IObject := - { C of IsIObject C }. +HB.structure Definition IObjects := + { C of HasIObjects C }. -HB.mixin Record HasProd C of IObject C := { +(* operators (meant to abstract over pullbacks and pushouts*) +HB.mixin Record HasPOps C of IObjects C := { prd : C -> C -> C ; prj1 : forall c1 c2, prd c1 c2 ~> c1 ; prj2 : forall c1 c2, prd c1 c2 ~> c2 ; @@ -1058,39 +1063,97 @@ HB.mixin Record HasProd C of IObject C := { mjn : forall c1 c2 c3, (c1 ~> c2) -> (c1 ~> c3) -> c1 ~> prd c2 c3 }. -HB.structure Definition Prod := - { C of HasProd C }. - -HB.mixin Record IsIQuiver C of Prod C := { - iid : Obj ~>_C Morph ; - isrc : Morph ~>_C Obj ; - itrg : Morph ~>_C Obj ; - icmp : @prd C Morph Morph ~> Morph +HB.structure Definition POps := + { C of HasPOps C }. + +(* category extended with internal morphisms *) +HB.mixin Record IsIQuiver C of POps C := { + iid : Obj ~>_C Mor ; + isrc : Mor ~>_C Obj ; + itrg : Mor ~>_C Obj ; + icmp : @prd C Mor Mor ~> Mor }. HB.structure Definition IQuiver := { C of IsIQuiver C }. +Notation idO C := (@idmap C Obj). +Notation idM C := (@idmap C Mor). +Notation prdMM := (prd Mor Mor). +Notation prdPM := (prd (prd Mor Mor) Mor). +Notation prjMM1 := (prj1 Mor Mor). +Notation prjMM2 := (prj2 Mor Mor). +Notation prjOM1 := (prj1 Obj Mor). +Notation prjOM2 := (prj2 Obj Mor). +Notation prjMO1 := (prj1 Mor Obj). +Notation prjMO2 := (prj2 Mor Obj). +Notation prjPM1 := (prj1 (prd Mor Mor) Mor). +Notation prjPM2 := (prj2 (prd Mor Mor) Mor). +Notation prjPM1_ C := (@prj1 C (prd Mor Mor) Mor). +Notation prjPM2_ C := (@prj2 C (prd Mor Mor) Mor). +Notation prjMP1 := (prj1 Mor (prd Mor Mor)). +Notation prjMP2 := (prj2 Mor (prd Mor Mor)). +Notation mprdOMMM := (mprd Obj Mor Mor Mor). +Notation mprdMOMM := (mprd Mor Obj Mor Mor). +Notation mprdPMMM := (mprd (prd Mor Mor) Mor Mor Mor). +Notation mprdMPMM := (mprd Mor (prd Mor Mor) Mor Mor). + +(* internal quiver extended with the required pullback properties *) +HB.mixin Record IsIPreCat C of IQuiver C := { + pbkMM : prjMM2 \; @isrc C = prjMM1 \; itrg ; + pbkPMcmp : prjPM2 \; @isrc C = prjPM1 \; icmp \; itrg ; + pbkMPcmp : prjMP2 \; @icmp C \; isrc = prjMP1 \; itrg ; + pbkPM : prjPM2 \; @isrc C = prjPM1 \; prjMM2 \; itrg ; + pbkMP : prjMP2 \; prjMM1 \; @isrc C = prjMP1 \; itrg ; + pbkPM2MM1 : prjPM1_ C \; prjMM2 = + mjn prdPM Mor Mor (prjPM1 \; prjMM2) prjPM2 \; prjMM1 ; + pbkPM2MM2 : prjPM2_ C = + mjn prdPM Mor Mor (prjPM1 \; prjMM2) prjPM2 \; prjMM2 ; + pbkPM2MP1 : prjPM1_ C \; prjMM1 = + mjn prdPM Mor prdMM (prjPM1 \; prjMM1) + (mjn prdPM Mor Mor (prjPM1 \; prjMM2) prjPM2) \; prjMP1 ; + pbkPM2MP2 : mjn prdPM Mor Mor (prjPM1_ C \; prjMM2) prjPM2 = + mjn prdPM Mor prdMM (prjPM1 \; prjMM1) + (mjn prdPM Mor Mor (prjPM1 \; prjMM2) prjPM2) \; prjMP2 ; +}. +HB.structure Definition IPreCat := + { C of IsIPreCat C }. + +(* definition of internal category *) +HB.mixin Record IsICat C of IPreCat C := { + iid_s : iid \; isrc = idO C ; + iid_t : iid \; itrg = idO C ; + icmp_s : @icmp C \; isrc = prjMM1 \; isrc ; + icmp_t : @icmp C \; itrg = prjMM2 \; itrg ; + unit_l : mprdOMMM iid (idM C) \; icmp = prjOM2 ; + unit_r : mprdMOMM (idM C) iid \; icmp = prjMO1 ; + assoc : mprdPMMM icmp (idM C) \; icmp = + mjn prdPM Mor prdMM (prjPM1 \; prjMM1) + (mjn prdPM Mor Mor (prjPM1 \; prjMM2) prjPM2) \; + mprdMPMM (idM C) icmp \; icmp +}. +HB.structure Definition ICat := + { C of IsICat C }. +(* HB.mixin Record IsICat C of IQuiver C := { iid_s : iid \; isrc = @idmap C Obj ; iid_t : iid \; itrg = @idmap C Obj ; - icmp_s : @icmp C \; isrc = prj1 Morph Morph \; isrc ; - icmp_t : @icmp C \; itrg = prj2 Morph Morph \; itrg ; - unit_l : mprd Obj Morph Morph Morph iid (@idmap C Morph) \; icmp = - prj2 Obj Morph ; - unit_r : mprd Morph Obj Morph Morph (@idmap C Morph) iid \; icmp = - prj1 Morph Obj ; - assoc : mprd (prd Morph Morph) Morph Morph Morph icmp (@idmap C Morph) + icmp_s : @icmp C \; isrc = prj1 Mor Mor \; isrc ; + icmp_t : @icmp C \; itrg = prj2 Mor Mor \; itrg ; + unit_l : mprd Obj Mor Mor Mor iid (@idmap C Mor) \; icmp = + prj2 Obj Mor ; + unit_r : mprd Mor Obj Mor Mor (@idmap C Mor) iid \; icmp = + prj1 Mor Obj ; + assoc : mprd (prd Mor Mor) Mor Mor Mor icmp (@idmap C Mor) \; icmp = - (mjn (prd (prd Morph Morph) Morph) Morph (prd Morph Morph) - (prj1 (prd Morph Morph) Morph \; prj1 Morph Morph) - (mjn (prd (prd Morph Morph) Morph) Morph Morph - (prj1 (prd Morph Morph) Morph \; prj2 Morph Morph) - (prj2 (prd Morph Morph) Morph))) \; - (mprd Morph (prd Morph Morph) Morph Morph (@idmap C Morph) icmp) \; icmp -}. -HB.structure Definition ICat := - { C of IsICat C }. - + (mjn (prd (prd Mor Mor) Mor) Mor (prd Mor Mor) + (prj1 (prd Mor Mor) Mor \; prj1 Mor Mor) + (mjn (prd (prd Mor Mor) Mor) Mor Mor + (prj1 (prd Mor Mor) Mor \; prj2 Mor Mor) + (prj2 (prd Mor Mor) Mor))) \; + (mprd Mor (prd Mor Mor) Mor Mor (@idmap C Mor) icmp) + \; icmp +}. +*) (********************************************************************) From 0fcd38c36d139e577a8c95333e6a7755f6e93482 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Wed, 29 Nov 2023 20:54:45 +0100 Subject: [PATCH 098/147] updated encatD.v, minor changes --- theories/encatD.v | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/theories/encatD.v b/theories/encatD.v index 0d756ba8c..055e9abec 100644 --- a/theories/encatD.v +++ b/theories/encatD.v @@ -2197,17 +2197,18 @@ HB.instance Definition iHom_cat' {C: pbcat} (C0 : C) := iHom_cat C0. (* Now we define an internal quiver as an object C0, which has a C1 : iHom C0 attached to it *) -HB.mixin Record IsPreInternalQuiver {C} (C0 : C) := - { isC1 : C }. -(* PROBLEM: probably a bug *) -Fail #[short(type="preInternalQuiver")] -HB.structure Definition PreInternalQuiver {C} := { - C0 of IsPreInternalQuiver C C0 }. - -Fail #[short(type="internalQuiver")] -HB.structure Definition InternalQuiver {C} := { - C0 of IsPreInternalQuiver C C0 & InternalHom C C0 (@C1 C C0) -}. +HB.mixin Record IsPreInternalQuiver C of Quiver C := + { C0 : C; + C1 : C }. +HB.structure Definition PreInternalQuiver := { + C of IsPreInternalQuiver C }. + +#[wrapper] HB.mixin Record IsInternalQuiver C of + Quiver C & PreInternalQuiver C := { + priv: Quiver (@InternalHom C (@C0 C) (@C1 C)) + }. +HB.structure Definition InternalQuiver := { + C of IsInternalQuiver C }. (* PROBLEM: nested product does not typecheck *) Fail Definition iprodA {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0): @@ -2222,10 +2223,10 @@ Notation "< f , g >" := (ipair f g). (* An internal precategory is an internal category with two operators that must be src and tgt preserving, i.e. iHom morphisms *) -HB.mixin Record IsInternalPreCat (C : pbcat) (C0 : C) of - InternalQuiver C0 := { - iid : C0 ~>_(iHom C0) C1; - icomp : C1 *_C0 C1 ~>_(iHom C0) C1 +HB.mixin Record IsInternalPreCat C of PBCat C & + InternalQuiver C := { + iid : (@C0 C) ~>_(@iHom C (@C0 C)) (@C1 C); + icomp : C1 *_C0 C1 ~>_(@iHom C C0) C1 }. #[short(type="internalprecat")] HB.structure Definition InternalPrecat (C : pbcat) := From a2757c4c66f439a469300bace5f19bc36d6a27e4 Mon Sep 17 00:00:00 2001 From: Cyril Cohen Date: Mon, 20 Nov 2023 14:26:33 +0100 Subject: [PATCH 099/147] mono/epi code works now --- theories/cat.v | 75 +++++++++++++++++++++++--------------------------- 1 file changed, 34 insertions(+), 41 deletions(-) diff --git a/theories/cat.v b/theories/cat.v index f2f172a94..372998808 100644 --- a/theories/cat.v +++ b/theories/cat.v @@ -752,41 +752,34 @@ HB.mixin Record IsTerminal {C : quiver} (t : obj C) := { }. #[short(type="terminal")] HB.structure Definition Terminal {C : quiver} := {t of IsTerminal C t}. -#[short(type="universal")] -HB.structure Definition Universal {C : quiver} := - {u of Initial C u & Terminal C u}. - -(* Definition hom' {C : precat} (a b : C) := a ~> b. *) -(* (* Bug *) *) -(* Identity Coercion hom'_hom : hom' >-> hom. *) - -(* HB.mixin Record IsMono {C : precat} (b c : C) (f : hom b c) := { *) -(* monoP : forall (a : C) (g1 g2 : a ~> b), g1 \; f = g2 \; f -> g1 = g2 *) -(* }. *) -(* #[short(type="mono")] *) -(* HB.structure Definition Mono {C : precat} (a b : C) := {m of IsMono C a b m}. *) -(* Notation "a >~> b" := (mono a b) *) -(* (at level 99, b at level 200, format "a >~> b") : cat_scope. *) -(* Notation "C >~>_ T D" := (@mono T C D) *) -(* (at level 99, T at level 0, only parsing) : cat_scope. *) - -(* HB.mixin Record IsEpi {C : precat} (a b : C) (f : hom a b) := { *) -(* epiP : forall (c : C) (g1 g2 : b ~> c), g1 \o f = g2 \o f -> g1 = g2 *) -(* }. *) -(* #[short(type="epi")] *) -(* HB.structure Definition Epi {C : precat} (a b : C) := {e of IsEpi C a b e}. *) -(* Notation "a ~>> b" := (epi a b) *) -(* (at level 99, b at level 200, format "a ~>> b") : cat_scope. *) -(* Notation "C ~>>_ T D" := (@epi T C D) *) -(* (at level 99, T at level 0, only parsing) : cat_scope. *) - -(* #[short(type="iso")] *) -(* HB.structure Definition Iso {C : precat} (a b : C) := *) -(* {i of @Mono C a b i & @Epi C a b i}. *) -(* Notation "a <~> b" := (epi a b) *) -(* (at level 99, b at level 200, format "a <~> b") : cat_scope. *) -(* Notation "C <~>_ T D" := (@epi T C D) *) -(* (at level 99, T at level 0, only parsing) : cat_scope. *) + +HB.mixin Record IsMono {C : precat} (b c : C) (f : hom b c) := { + monoP : forall (a : C) (g1 g2 : a ~> b), g1 \; f = g2 \; f -> g1 = g2 +}. +#[short(type="mono")] +HB.structure Definition Mono {C : precat} (a b : C) := {m of IsMono C a b m}. +Notation "a >~> b" := (mono a b) + (at level 99, b at level 200, format "a >~> b") : cat_scope. +Notation "C >~>_ T D" := (@mono T C D) + (at level 99, T at level 0, only parsing) : cat_scope. + +HB.mixin Record IsEpi {C : precat} (a b : C) (f : hom a b) := { + epiP : forall (c : C) (g1 g2 : b ~> c), g1 \o f = g2 \o f -> g1 = g2 +}. +#[short(type="epi")] +HB.structure Definition Epi {C : precat} (a b : C) := {e of IsEpi C a b e}. +Notation "a ~>> b" := (epi a b) + (at level 99, b at level 200, format "a ~>> b") : cat_scope. +Notation "C ~>>_ T D" := (@epi T C D) + (at level 99, T at level 0, only parsing) : cat_scope. + +#[short(type="iso")] +HB.structure Definition Iso {C : precat} (a b : C) := + {i of @Mono C a b i & @Epi C a b i}. +Notation "a <~> b" := (epi a b) + (at level 99, b at level 200, format "a <~> b") : cat_scope. +Notation "C <~>_ T D" := (@epi T C D) + (at level 99, T at level 0, only parsing) : cat_scope. HB.mixin Record IsRightAdjoint (D C : precat) (R : D -> C) of @PreFunctor D C R := { @@ -794,7 +787,8 @@ HB.mixin Record IsRightAdjoint (D C : precat) (R : D -> C) phi : forall c d, (L_ c ~> d) -> (c ~> R d); psy : forall c d, (c ~> R d) -> (L_ c ~> d); phi_psy c d : (phi c d \o psy c d)%FUN = @id (c ~> R d); - psy_phi c d : (psy c d \o phi c d)%FUN = @id (L_ c ~> d) + psy_phi c d : (psy c d \o phi c d)%FUN = @id (L_ c ~> d); + (* naturality is missing *) }. #[short(type="right_adjoint")] HB.structure Definition RightAdjoint (D C : precat) := @@ -803,7 +797,6 @@ Arguments L_ {_ _}. Arguments phi {D C s} {c d}. Arguments psy {D C s} {c d}. - HB.mixin Record PreCat_IsMonoidal C of PreCat C := { onec : C; prod : (C * C)%type ~>_precat C; @@ -819,7 +812,8 @@ Notation "f <*> g" := (prod^$ ((f, g) : (_, _) ~> (_, _))) (only parsing) : cat_scope. Notation "1" := onec : cat_scope. -Definition hom_cast {C : quiver} {a a' : C} (eqa : a = a') {b b' : C} (eqb : b = b') : +Definition hom_cast {C : quiver} {a a' : C} (eqa : a = a') + {b b' : C} (eqb : b = b') : (a ~> b) -> (a' ~> b'). Proof. now elim: _ / eqa; elim: _ / eqb. Defined. @@ -883,7 +877,6 @@ HB.structure Definition Monoidal : Set := { C of PreMonoidal_IsMonoidal C & PreMonoidal C }. Set Universe Checking. - Record cospan (Q : quiver) (A B : Q) := Cospan { top : Q; left2top : A ~> top; @@ -913,7 +906,8 @@ Program Definition cospan_comp (c1 c2 c3 : cospan A B) @CospanMap Q A B c1 c3 (top_map f12 \; top_map f23) _ _. Next Obligation. by rewrite compoA !left2top_map. Qed. Next Obligation. by rewrite compoA !right2top_map. Qed. -HB.instance Definition _ := IsPreCat.Build (cospan A B) cospan_idmap cospan_comp. +HB.instance Definition _ := IsPreCat.Build (cospan A B) + cospan_idmap cospan_comp. Lemma cospan_are_cats : PreCat_IsCat (cospan A B). Proof. @@ -1012,7 +1006,6 @@ Variables (f : A ~> D) (g : B ~> D) (h : C ~> A). Variables (u : E ~> A) (v : E ~> B) (w : F ~> C) (z : F ~> E). Variable (uvfg : pbsquare u v f g). -Set Printing Width 50. Theorem pbsquarec_compP : pbsquare w z h u <=> pbsquare w (z \; v) (h \; f) g. Proof. From d42cc3ef2dea8a6ed00bb51af01d610495a00de2 Mon Sep 17 00:00:00 2001 From: Cyril Cohen Date: Thu, 23 Nov 2023 09:43:28 +0100 Subject: [PATCH 100/147] walking span --- theories/cat.v | 168 +++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 141 insertions(+), 27 deletions(-) diff --git a/theories/cat.v b/theories/cat.v index 372998808..3017db67f 100644 --- a/theories/cat.v +++ b/theories/cat.v @@ -877,6 +877,52 @@ HB.structure Definition Monoidal : Set := { C of PreMonoidal_IsMonoidal C & PreMonoidal C }. Set Universe Checking. +Record span (Q : quiver) (A B : Q) := Span { + bot : Q; + bot2left : bot ~> A; + bot2right : bot ~> B +}. + +Section spans. +Variables (Q : precat) (A B : Q). +Record span_map (c c' : span A B) := SpanMap { + bot_map : bot c ~> bot c'; + bot2left_map : bot_map \; bot2left c' = bot2left c; + bot2right_map : bot_map \; bot2right c' = bot2right c; +}. +HB.instance Definition _ := IsQuiver.Build (span A B) span_map. + +Lemma span_mapP (c c' : span A B) (f g : c ~> c') : + bot_map f = bot_map g <-> f = g. +Proof. +split=> [|->]//; case: f g => [/= f ? ?] [/= g + +] efg. +by elim: efg => // ? ?; congr SpanMap; apply: Prop_irrelevance. +Qed. + +End spans. + +Section spans_in_cat. +Variables (Q : cat) (A B : Q). +Definition span_idmap (c : span A B) := + @SpanMap Q A B c c idmap (comp1o _) (comp1o _). +Program Definition span_comp (c1 c2 c3 : span A B) + (f12 : c1 ~> c2) (f23 : c2 ~> c3) := + @SpanMap Q A B c1 c3 (bot_map f12 \; bot_map f23) _ _. +Next Obligation. by rewrite -compoA !bot2left_map. Qed. +Next Obligation. by rewrite -compoA !bot2right_map. Qed. +HB.instance Definition _ := IsPreCat.Build (span A B) + span_idmap span_comp. + +Lemma span_are_cats : PreCat_IsCat (span A B). +Proof. +constructor=> [a b f|a b f|a b c d f g h]. +- by apply/span_mapP => /=; rewrite comp1o. +- by apply/span_mapP => /=; rewrite compo1. +- by apply/span_mapP => /=; rewrite compoA. +Qed. +HB.instance Definition _ := span_are_cats. +End spans_in_cat. + Record cospan (Q : quiver) (A B : Q) := Cospan { top : Q; left2top : A ~> top; @@ -894,7 +940,11 @@ HB.instance Definition _ := IsQuiver.Build (cospan A B) cospan_map. Lemma cospan_mapP (c c' : cospan A B) (f g : c ~> c') : top_map f = top_map g <-> f = g. -Admitted. +Proof. +split=> [|->]//; case: f g => [/= f ? ?] [/= g + +] efg. +by elim: efg => // ? ?; congr CospanMap; apply: Prop_irrelevance. +Qed. + End cospans. Section cospans_in_cat. @@ -919,30 +969,6 @@ Qed. HB.instance Definition _ := cospan_are_cats. End cospans_in_cat. -Section spans_and_co. -Variables (Q : quiver) (A B : Q). -Definition span := @cospan Q^op A B. -Definition bot (s : span) : Q := top s. -Definition bot2left (s : span) : bot s ~>_Q A := left2top s. -Definition bot2right (s : span) : bot s ~>_Q B := right2top s. -Definition Span (C : Q) (f : C ~> A) (g : C ~> B) : span := - @Cospan Q^op A B C f g. -End spans_and_co. - -HB.instance Definition _ (Q : precat) (A B : Q) := - Quiver.copy (span A B) (@cospan Q^op A B)^op. -HB.instance Definition _ (Q : cat) (A B : Q) := - Cat.copy (span A B) (@cospan Q^op A B)^op. - -Section bot_map. -Variables (C : cat) (A B : C) (s s' : span A B) (f : s ~> s'). -Definition bot_map : bot s ~> bot s' := top_map f. -Lemma bot2left_map : bot_map \; bot2left s' = bot2left s. -Proof. exact: left2top_map f. Qed. -Lemma bot2right_map : bot_map \; bot2right s' = bot2right s. -Proof. exact: right2top_map f. Qed. -End bot_map. - HB.mixin Record isPrePullback (Q : precat) (A B : Q) (c : cospan A B) (s : span A B) := { is_square : bot2left s \; left2top c = bot2right s \; right2top c; @@ -959,6 +985,7 @@ HB.instance Definition _ := (fun a b => (a : span A B) ~>_(span A B) (b : span A B)). Lemma eq_prepullbackP (p q : prepullback c) : p = q :> span _ _ <-> p = q. +Proof. Admitted. End prepullback. Section prepullback. @@ -984,7 +1011,7 @@ HB.tag Definition pb_terminal (Q : precat) #[wrapper] HB.mixin Record prepullback_isTerminal (Q : precat) - (A B : Q) (c : cospan A B) + (A B : Q) (c : cospan A B) (s : span A B) of isPrePullback Q A B c s := { prepullback_terminal : IsTerminal (prepullback c) (pb_terminal s) @@ -992,11 +1019,98 @@ HB.mixin Record prepullback_isTerminal (Q : precat) #[short(type="pullback"), verbose] HB.structure Definition Pullback (Q : precat) (A B : Q) (c : cospan A B) := - {s of isPrePullback Q A B c s + {s of isPrePullback Q A B c s & IsTerminal (prepullback c) (pb_terminal s) }. +Inductive walking_cospan := Top | Left | Right. +Definition walking_cospan_hom (x y : walking_cospan) := match x, y with + | Top, Top | Left, Left | Right, Right | + Left, Top | Right, Top => Datatypes.unit + | _, _ => False + end. + +HB.instance Definition _ := + IsQuiver.Build walking_cospan walking_cospan_hom. + +Definition walking_cospan_id (x : walking_cospan) : x ~> x. +Proof. by case: x; constructor. Defined. + +Definition walking_cospan_comp (x y z : walking_cospan) : + (x ~> y) -> (y ~> z) -> (x ~> z). +Proof. by case: x y z => [] [] []. Defined. + +HB.instance Definition _ := Quiver_IsPreCat.Build walking_cospan + walking_cospan_id walking_cospan_comp. + +Lemma walking_cospan_cat : PreCat_IsCat walking_cospan. +Proof. by constructor=> [[] []|[] []|[] [] [] []]// []. Qed. +HB.instance Definition _ := walking_cospan_cat. + +Section Pullback_Natural. +Context (C : cat) (A B : C) (csp : cospan A B). + +Definition cspF (x : walking_cospan) : C := + match x with Left => A | Right => B | Top => top csp end. + +Definition cspFhom : forall (x y : walking_cospan), + (x ~> y) -> cspF x ~> cspF y. +Proof. +move=> [] []//. +- move=> _; exact: idmap. +- move=> _; exact: left2top csp. +- move=> _; exact: idmap. +- move=> _; exact: right2top csp. +- move=> _; exact: idmap. +Defined. + +HB.instance Definition _ := IsPreFunctor.Build _ _ cspF cspFhom. +Lemma cspF_functor : PreFunctor_IsFunctor _ _ cspF. +Proof. +by constructor=> [[]|[] [] []]//= [] []//=; + rewrite ?(compo1, comp1o)//. +Qed. +HB.instance Definition _ := cspF_functor. + +Section prepullback2natural. +Variable (p : prepullback csp). + +Definition wcsp w : cst walking_cospan (bot p) w ~> cspF w. +Proof. +case: w; rewrite /cst /=. +- exact: (bot2left _ \; left2top _). +- exact: bot2left. +- exact: bot2right. +Defined. + +Lemma wcsp_natural : IsNatural _ _ _ _ wcsp. +Proof. +constructor=> - [] [] //= [] /=; rewrite ?(comp1o, compo1)//=. +exact: is_square. +Qed. + +End prepullback2natural. + +Section natural2prepullback. +Variables (c : C) (n : cst walking_cospan c ~~> cspF). + +Definition s := {| bot := c; bot2left := n Left; bot2right := n Right |}. + +Lemma s_prepullback : isPrePullback _ _ _ csp s. +Proof. +constructor => /=. +have p := natural n (tt : Right ~> Top). +have /esym q := natural n (tt : Left ~> Top). +exact: etrans q p. +Qed. + +End natural2prepullback. + +End Pullback_Natural. +Notation square u v f g := + (isPrePullback _ _ _ (Cospan f g) (Span u v)). Notation pbsquare u v f g := (Pullback _ (Cospan f g) (Span u v)). +Notation pb s := (prepullback_isTerminal _ _ _ _ s). Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). From dc4548e4123a2a9f4c7cbdb9b42d22cc053980aa Mon Sep 17 00:00:00 2001 From: Cyril Cohen Date: Thu, 30 Nov 2023 11:31:19 +0100 Subject: [PATCH 101/147] rephrasing adjunctions (needs wrapping) --- theories/cat.v | 174 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 129 insertions(+), 45 deletions(-) diff --git a/theories/cat.v b/theories/cat.v index 3017db67f..3e4ef8edb 100644 --- a/theories/cat.v +++ b/theories/cat.v @@ -400,20 +400,23 @@ Qed. HB.instance Definition _ := prod_is_cat. End cat_prod. +HB.instance Definition _ (C : U) (D : quiver) := + IsQuiver.Build (C -> D) (fun f g => forall c, f c ~> g c). + (* naturality *) -HB.mixin Record IsNatural (C D : precat) (F G : C ~>_quiver D) +HB.mixin Record IsNatural (C : quiver) (D : precat) (F G : C ~>_quiver D) (n : forall c, F c ~> G c) := { natural : forall (a b : C) (f : a ~> b), F <$> f \; n b = n a \; G <$> f }. Unset Universe Checking. -HB.structure Definition Natural (C D : precat) +HB.structure Definition Natural (C : quiver) (D : precat) (F G : C ~>_quiver D) : Set := { n of @IsNatural C D F G n }. Set Universe Checking. -HB.instance Definition _ (C D : precat) := +HB.instance Definition _ (C : quiver) (D : precat) := IsQuiver.Build (PreFunctor.type C D) (@Natural.type C D). -HB.instance Definition _ (C D : cat) := +HB.instance Definition _ (C D : precat) := IsQuiver.Build (Functor.type C D) (@Natural.type C D). Arguments natural {C D F G} n [a b] f : rename. @@ -490,41 +493,68 @@ constructor => [F G f|F G f|F G H J f g h]. Qed. HB.instance Definition _ C D := @functor_cat C D. -Section nat_map_left. -Context {C D E : precat} {F G : C ~> D}. +Lemma idFmap (C : cat) (a b : C) (f : a ~> b) : idfun <$> f = f. +Proof. by []. Qed. -Definition nat_lmap (H : D ~>_quiver E) (n : forall c, F c ~> G c) : - forall c, (H \o F)%FUN c ~> (H \o G)%FUN c := fun c => H <$> n c. +Lemma compFmap (C D E : cat) (F : C ~> D) (G : D ~> E) (a b : C) (f : a ~> b) : + (G \o F) <$> f = G <$> F <$> f. +Proof. by []. Qed. -Fail Check fun (H : D ~> E) (n : F ~~> G) => nat_lmap H n : H \o F ~~> H \o G. +Section left_whiskering. +Context {C D E : precat} {F G : C ~> D}. -Lemma nat_lmap_is_natural (H : D ~> E) (n : F ~~> G) : - IsNatural C E (H \o F) (H \o G) (nat_lmap H n). -Proof. by constructor=> a b f; rewrite /nat_lmap/= -!Fcomp natural. Qed. -HB.instance Definition _ H n := nat_lmap_is_natural H n. +Definition whiskerl_fun (eta : forall c, F c ~> G c) (H : D ~> E) : + forall c, (F \; H) c ~> (G \; H) c := fun c => H <$> eta c. -Check fun (H : D ~> E) (n : F ~~> G) => nat_lmap H n : H \o F ~~> H \o G. +Lemma whiskerl_is_nat (eta : F ~> G) (H : D ~> E) : + IsNatural _ _ _ _ (whiskerl_fun eta H). +Proof. by constructor=> a b f; rewrite /whiskerl_fun/= -!Fcomp natural. Qed. -End nat_map_left. +HB.instance Definition _ (eta : F ~> G) (H : D ~> E) := whiskerl_is_nat eta H. +Definition whiskerl (eta : F ~> G) (H : D ~> E) : (F \; H) ~> (G \; H) := + whiskerl_fun eta H : Natural.type _ _. +End left_whiskering. -Notation "F n" := (nat_lmap F n) +Notation "F n" := (whiskerl F n) (at level 58, format "F n", right associativity) : cat_scope. -Section nat_map_right. -Context {C D E : precat} {F G : C ~> D}. +Section right_whiskering. +Context {C D E : precat} {F G : D ~> E}. + +Definition whiskerr_fun (H : C ~> D) (eta : forall d, F d ~> G d) + (c : C) : (H \; F) c ~> (H \; G) c := eta (H c). -Definition nat_rmap (H : E -> C) (n : forall c, F c ~> G c) : - forall c, (F \o H)%FUN c ~> (G \o H)%FUN c := fun c => n (H c). -Lemma nat_rmap_is_natural (H : E ~> C :> quiver) (n : F ~~> G) : - IsNatural E D (F \o H)%FUN (G \o H)%FUN (nat_rmap H n). -Proof. by constructor=> a b f; rewrite /nat_lmap/= natural. Qed. -HB.instance Definition _ H n := nat_rmap_is_natural H n. +Lemma whiskerr_is_nat (H : C ~> D) (eta : F ~> G) : + IsNatural _ _ _ _ (whiskerr_fun H eta). +Proof. by constructor=> a b f; rewrite /whiskerr_fun/= natural. Qed. +HB.instance Definition _ (H : C ~> D) (eta : F ~> G) := whiskerr_is_nat H eta. -End nat_map_right. +Definition whiskerr (H : C ~> D) (eta : F ~> G) : (H \; F) ~> (H \; G) := + whiskerr_fun H eta : Natural.type _ _. +End right_whiskering. -Notation "F <$o> n" := (nat_rmap F n) +Notation "F <$o> n" := (whiskerr F n) (at level 58, format "F <$o> n", right associativity) : cat_scope. +Definition whisker {C : cat} {D : precat} {E : cat} + {F G : C ~>_precat D} {H K : D ~> E} + (eta : F ~> G) (mu : H ~> K) : (F \; H) ~> (G \; K) := + (eta H) \; (G <$o> mu). + +Notation "eta mu" := (whisker eta mu) + (at level 58, format "eta mu", right associativity) : cat_scope. + +Lemma whiskern1 {C D E : cat} {F G : C ~>_precat D} (eta : F ~> G) (H : D ~> E) : + eta \idmap_H = eta H. +Proof. by apply/natP/funext=> c /=; apply: compo1. Qed. + +Lemma whisker1n {C D E : cat} {F G : D ~> E} (H : C ~> D) (eta : F ~> G) : + \idmap_H eta = H <$o> eta. +Proof. +apply/natP/funext=> c /=; rewrite /natural_comp/=. +by rewrite [X in X \; _]F1 comp1o. +Qed. + Definition delta (C D : cat) : C -> (D ~> C) := cst D. Arguments delta C D : clear implicits. @@ -600,13 +630,6 @@ HB.builders Context C M of IsJoinCoMonad C M. (fun a b f => erefl) unit_cojoin join_counit cojoin_square. HB.end. -Lemma idFmap (C : cat) (a b : C) (f : a ~> b) : idfun <$> f = f. -Proof. by []. Qed. - -Lemma compFmap (C D E : cat) (F : C ~> D) (G : D ~> E) (a b : C) (f : a ~> b) : - (G \o F) <$> f = G <$> F <$> f. -Proof. by []. Qed. - (* yoneda *) Section hom_repr. Context {C : cat} (F : C ~>_cat U). @@ -781,21 +804,82 @@ Notation "a <~> b" := (epi a b) Notation "C <~>_ T D" := (@epi T C D) (at level 99, T at level 0, only parsing) : cat_scope. -HB.mixin Record IsRightAdjoint (D C : precat) (R : D -> C) - of @PreFunctor D C R := { - L_ : C ~> D; - phi : forall c d, (L_ c ~> d) -> (c ~> R d); - psy : forall c d, (c ~> R d) -> (L_ c ~> d); - phi_psy c d : (phi c d \o psy c d)%FUN = @id (c ~> R d); - psy_phi c d : (psy c d \o phi c d)%FUN = @id (L_ c ~> d); - (* naturality is missing *) +Definition comp1F {C D : cat} (F : C ~> D) : idmap \; F = F. +Proof. by apply/functorP=> a b f; rewrite funext_frefl/= compFmap. Qed. + +Definition compF1 {C D : cat} (F : C ~> D) : F \; idmap = F. +Proof. by apply/functorP=> a b f; rewrite funext_frefl/= compFmap. Qed. + +Definition feq {C : precat} {a b : C} : a = b -> a ~> b. +Proof. by move<-; exact idmap. Defined. + +Definition feqsym {C : precat} {a b : C} : a = b -> b ~> a. +Proof. by move<-; exact idmap. Defined. + +HB.mixin Record IsLeftAdjointOf (C D : cat) (R : D ~> C) L + of @Functor C D L := { + Lphi : forall c d, (L c ~> d) -> (c ~> R d); + Lpsi : forall c d, (c ~> R d) -> (L c ~> d); + (* there should be a monad and comonad structure wrappers instead *) + Lunit : (idmap : C ~> C) ~~> R \o ((L : Functor.type C D) : C ~> D); + Lcounit : ((L : Functor.type C D) : C ~> D) \o R ~~> idmap :> D ~> D; + LphiE : forall c d (g : L c ~> d), Lphi c d g = Lunit c \; (R <$> g); + LpsiE : forall c d (f : c ~> R d), Lpsi c d f = (L <$> f) \; Lcounit d; + Lwhiskerlr : let L : C ~> D := L : Functor.type C D in + (feqsym (comp1F _) \; Lunit L) \; + (L <$o> Lcounit \; feq (compF1 _)) = idmap; + Lwhiskerrl : let L : C ~> D := L : Functor.type C D in + (feqsym (compF1 _) \; R <$o> Lunit) \; + (Lcounit R \; feq (comp1F _)) = idmap; +}. +#[short(type="left_adjoint_of")] +HB.structure Definition LeftAdjointOf (C D : cat) (R : D ~> C) := + { L of @Functor C D L & IsLeftAdjointOf C D R L}. +Arguments Lphi {C D R s} {c d}. +Arguments Lpsi {C D R s} {c d}. +Arguments Lunit {C D R s}. +Arguments Lcounit {C D R s}. + +Section LeftAdjointOf_Theory. +Variables (C D : cat) (R : D ~> C) (L : LeftAdjointOf.type R). + +Lemma Lphi_psi (c : C) (d : D) : + (@Lphi _ _ R L c d \o @Lpsi _ _ R L c d)%FUN = @id (c ~> R d). +Proof. +apply/funext => f /=; rewrite LphiE LpsiE. +Admitted. + +Lemma Lpsi_phi (c : C) (d : D) : + (@Lpsi _ _ R L c d \o @Lphi _ _ R L c d)%FUN = @id (L c ~> d). +Proof. +Admitted. +End LeftAdjointOf_Theory. + +HB.mixin Record IsRightAdjoint (D C : cat) (R : D -> C) + of @Functor D C R := { + (* we should have a wrapper instead *) + left_adjoint : C ~> D; + LLphi : forall c d, (left_adjoint c ~> d) -> (c ~> R d); + LLpsi : forall c d, (c ~> R d) -> (left_adjoint c ~> d); + LLunit : (idmap : C ~> C) ~~> (R : Functor.type D C) \o left_adjoint; + LLcounit : left_adjoint \o (R : Functor.type D C) ~~> idmap :> D ~> D; + LLphiE : forall c d (g : left_adjoint c ~> d), LLphi c d g = LLunit c \; (R <$> g); + LLpsiE : forall c d (f : c ~> R d), LLpsi c d f = (left_adjoint <$> f) \; LLcounit d; + LLwhiskerlr : + (feqsym (comp1F _) \; LLunit left_adjoint) \; + (left_adjoint <$o> LLcounit \; feq (compF1 _)) = idmap; + LLwhiskerrl : + (feqsym (compF1 _) \; (R : Functor.type D C) <$o> LLunit) \; + (LLcounit (R : Functor.type D C) \; feq (comp1F _)) = idmap; }. #[short(type="right_adjoint")] -HB.structure Definition RightAdjoint (D C : precat) := +HB.structure Definition RightAdjoint (D C : cat) := { R of @Functor D C R & IsRightAdjoint D C R }. -Arguments L_ {_ _}. -Arguments phi {D C s} {c d}. -Arguments psy {D C s} {c d}. +Arguments left_adjoint {_ _}. +Arguments LLphi {D C s} {c d}. +Arguments LLpsi {D C s} {c d}. +Arguments LLunit {D C s}. +Arguments LLcounit {D C s}. HB.mixin Record PreCat_IsMonoidal C of PreCat C := { onec : C; From b00a244ddfb97b9d3356071986087d52426b2f37 Mon Sep 17 00:00:00 2001 From: Cyril Cohen Date: Thu, 30 Nov 2023 15:56:09 +0100 Subject: [PATCH 102/147] internal categories parametrized with the ambiant one --- theories/encatD.v | 338 +++++++++++++++++++++++++++------------------- 1 file changed, 201 insertions(+), 137 deletions(-) diff --git a/theories/encatD.v b/theories/encatD.v index 055e9abec..e5434e3cc 100644 --- a/theories/encatD.v +++ b/theories/encatD.v @@ -36,7 +36,7 @@ Arguments hom {C} : rename. Notation homs T := (@hom T _ _). Notation "a ~> b" := (hom a b) (at level 99, b at level 200, format "a ~> b") : cat_scope. -Notation "a ~>_ C b" := (@hom C a b) +Notation "a ~>_ C b" := (@hom C (a : C) (b : C)) (at level 99, C at level 0, only parsing) : cat_scope. (* precategories are quivers + id and comp *) @@ -738,7 +738,7 @@ Notation "F `/ b" := (F `/` cst unit b) (at level 40, b at level 40, format "F `/ b") : cat_scope. Notation "a / b" := (cst unit a `/ b) : cat_scope. -Definition obj (C : quiver) : Type := C. +Definition obj (C : U) : U := C. HB.mixin Record IsInitial {C : quiver} (i : obj C) := { to : forall c, i ~> c; to_unique : forall c (f : i ~> c), f = to c @@ -806,7 +806,7 @@ Arguments psy {D C s} {c d}. HB.mixin Record PreCat_IsMonoidal C of PreCat C := { onec : C; - (* prod1 : @hom precat (C * C)%type C ; *) + (* prod1 : @hom precat (C * C)%type C ; *) prod : (C * C)%type ~>_precat C; }. #[short(type="premonoidal")] @@ -995,7 +995,7 @@ HB.tag Definition pb_terminal (Q : precat) #[wrapper] HB.mixin Record prepullback_isTerminal (Q : precat) - (A B : Q) (c : cospan A B) + (A B : Q) (c : cospan A B) (s : span A B) of isPrePullback Q A B c s := { prepullback_terminal : IsTerminal (prepullback c) (pb_terminal s) @@ -1003,7 +1003,7 @@ HB.mixin Record prepullback_isTerminal (Q : precat) #[short(type="pullback"), verbose] HB.structure Definition Pullback (Q : precat) (A B : Q) (c : cospan A B) := - {s of isPrePullback Q A B c s + {s of isPrePullback Q A B c s & IsTerminal (prepullback c) (pb_terminal s) }. Notation pbsquare u v f g := @@ -1018,7 +1018,7 @@ Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). (* category with all prepullbacks *) (* Ideally span is in fact expanded and the final mixin has -a pb : forall A B, cospan A B -> C +a pb : forall A B, cospan A B -> C but it is not clear how to do that yet *) HB.mixin Record HasPBop C of Cat C := { @@ -1029,9 +1029,19 @@ HB.structure Definition PBop := {C of HasPBop C & PreCat C }. (* category with all pullbacks *) -#[wrapper] -HB.mixin Record HasPBCat C of PBop C : Type := { - is_pb : forall (a b: C) (c: cospan a b), Pullback C c (@pb C a b c) +(* Wrong: we don't wrap classes, only mixins *) +#[wrapper] +HB.mixin Record HasPreBCat C of PBop C : Type := { + is_pb : forall (a b : C) (c : cospan a b), isPrePullback C a b c (@pb C a b c) + }. +#[short(type="pbcat")] +HB.structure Definition PreBCat := + {C of HasPreBCat C}. + +#[wrapper] +HB.mixin Record HasPBCat C of PBop C & HasPreBCat C : Type := { + is_pb : forall (a b : C) (c : cospan a b), + prepullback_isTerminal C a b c (@pb C a b c) }. #[short(type="pbcat")] HB.structure Definition PBCat := @@ -1048,8 +1058,8 @@ HB.structure Definition PBCat := (* category extended with internal objects *) HB.mixin Record HasIObjects C of Cat C := { Obj : C ; - Mor : C -}. + Mor : C +}. HB.structure Definition IObjects := { C of HasIObjects C }. @@ -1062,17 +1072,17 @@ HB.mixin Record HasPOps C of IObjects C := { (c1 ~> c3) -> (c2 ~> c4) -> prd c1 c2 ~> prd c3 c4 ; mjn : forall c1 c2 c3, (c1 ~> c2) -> (c1 ~> c3) -> c1 ~> prd c2 c3 -}. +}. HB.structure Definition POps := { C of HasPOps C }. (* category extended with internal morphisms *) HB.mixin Record IsIQuiver C of POps C := { - iid : Obj ~>_C Mor ; - isrc : Mor ~>_C Obj ; + iid : Obj ~>_C Mor ; + isrc : Mor ~>_C Obj ; itrg : Mor ~>_C Obj ; icmp : @prd C Mor Mor ~> Mor -}. +}. HB.structure Definition IQuiver := { C of IsIQuiver C }. @@ -1102,7 +1112,7 @@ HB.mixin Record IsIPreCat C of IQuiver C := { pbkMM : prjMM2 \; @isrc C = prjMM1 \; itrg ; pbkPMcmp : prjPM2 \; @isrc C = prjPM1 \; icmp \; itrg ; pbkMPcmp : prjMP2 \; @icmp C \; isrc = prjMP1 \; itrg ; - pbkPM : prjPM2 \; @isrc C = prjPM1 \; prjMM2 \; itrg ; + pbkPM : prjPM2 \; @isrc C = prjPM1 \; prjMM2 \; itrg ; pbkMP : prjMP2 \; prjMM1 \; @isrc C = prjMP1 \; itrg ; pbkPM2MM1 : prjPM1_ C \; prjMM2 = mjn prdPM Mor Mor (prjPM1 \; prjMM2) prjPM2 \; prjMM1 ; @@ -1113,8 +1123,8 @@ HB.mixin Record IsIPreCat C of IQuiver C := { (mjn prdPM Mor Mor (prjPM1 \; prjMM2) prjPM2) \; prjMP1 ; pbkPM2MP2 : mjn prdPM Mor Mor (prjPM1_ C \; prjMM2) prjPM2 = mjn prdPM Mor prdMM (prjPM1 \; prjMM1) - (mjn prdPM Mor Mor (prjPM1 \; prjMM2) prjPM2) \; prjMP2 ; -}. + (mjn prdPM Mor Mor (prjPM1 \; prjMM2) prjPM2) \; prjMP2 ; +}. HB.structure Definition IPreCat := { C of IsIPreCat C }. @@ -1125,12 +1135,12 @@ HB.mixin Record IsICat C of IPreCat C := { icmp_s : @icmp C \; isrc = prjMM1 \; isrc ; icmp_t : @icmp C \; itrg = prjMM2 \; itrg ; unit_l : mprdOMMM iid (idM C) \; icmp = prjOM2 ; - unit_r : mprdMOMM (idM C) iid \; icmp = prjMO1 ; - assoc : mprdPMMM icmp (idM C) \; icmp = + unit_r : mprdMOMM (idM C) iid \; icmp = prjMO1 ; + assoc : mprdPMMM icmp (idM C) \; icmp = mjn prdPM Mor prdMM (prjPM1 \; prjMM1) (mjn prdPM Mor Mor (prjPM1 \; prjMM2) prjPM2) \; - mprdMPMM (idM C) icmp \; icmp -}. + mprdMPMM (idM C) icmp \; icmp +}. HB.structure Definition ICat := { C of IsICat C }. (* @@ -1142,16 +1152,16 @@ HB.mixin Record IsICat C of IQuiver C := { unit_l : mprd Obj Mor Mor Mor iid (@idmap C Mor) \; icmp = prj2 Obj Mor ; unit_r : mprd Mor Obj Mor Mor (@idmap C Mor) iid \; icmp = - prj1 Mor Obj ; + prj1 Mor Obj ; assoc : mprd (prd Mor Mor) Mor Mor Mor icmp (@idmap C Mor) - \; icmp = + \; icmp = (mjn (prd (prd Mor Mor) Mor) Mor (prd Mor Mor) (prj1 (prd Mor Mor) Mor \; prj1 Mor Mor) (mjn (prd (prd Mor Mor) Mor) Mor Mor (prj1 (prd Mor Mor) Mor \; prj2 Mor Mor) (prj2 (prd Mor Mor) Mor))) \; (mprd Mor (prd Mor Mor) Mor Mor (@idmap C Mor) icmp) - \; icmp + \; icmp }. *) @@ -1163,11 +1173,11 @@ Declare Scope encat_scope. Delimit Scope encat_scope with encat. Local Open Scope encat_scope. -(* Enrichment in a monoidal category, following +(* Enrichment in a monoidal category, following https://ncatlab.org/nlab/show/enriched+category *) HB.mixin Record IsEnQuiver (V: Type) C := { - hom_object : C -> C -> V + hom_object : C -> C -> V }. Unset Universe Checking. HB.structure Definition EnQuiver (V: Type) : Set := @@ -1176,14 +1186,14 @@ Set Universe Checking. (* Monoidal precategory with the enrichment operators (no axioms) *) HB.mixin Record IsEnPreCat (V: PreMonoidal.type) C of - EnQuiver (PreMonoidal.sort V) C := { + EnQuiver (PreMonoidal.sort V) C := { id_element : forall (a: C), @hom V onec (hom_object a a) ; comp_morphism : forall (a b c: C), @hom V (@hom_object V C b c * @hom_object V C a b) - (@hom_object V C a c) -}. -Unset Universe Checking. + (@hom_object V C a c) +}. +Unset Universe Checking. HB.structure Definition EnPreCat (V: PreMonoidal.type) : Set := { C of IsEnPreCat V C }. Set Universe Checking. @@ -1203,11 +1213,11 @@ Notation "~^CM a b c" := (comp_morphism a b c) Notation "~^CM_ ( V , C ) a b c" := (@comp_morphism V C a b c) (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. -(* V-enriched category: +(* V-enriched category: V is the monoidal category; C is the base category that gets enriched *) -HB.mixin Record IsEnCat (V: Monoidal.type) C of EnPreCat V C := { +HB.mixin Record IsEnCat (V: Monoidal.type) C of EnPreCat V C := { ecat_comp_assoc : forall a b c d: C, forall alpha: (((c ~^_(V,C) d) * (b ~^_(V,C) c)) * (a ~^_(V,C) b)) ~>_V @@ -1217,16 +1227,16 @@ HB.mixin Record IsEnCat (V: Monoidal.type) C of EnPreCat V C := { = alpha \; ((@idmap V (c ~^_(V,C) d)) <*> (@comp_morphism V C a b c)) \; - (@comp_morphism V C a c d) ; + (@comp_morphism V C a c d) ; ecat_comp_left_unital : forall a b: C, - forall l: onec * (a ~^_(V,C) b) ~>_V (a ~^_(V,C) b), + forall l: onec * (a ~^_(V,C) b) ~>_V (a ~^_(V,C) b), l = ((@id_element V C b) <*> (@idmap V (a ~^_(V,C) b))) \; - (@comp_morphism V C a b b) ; + (@comp_morphism V C a b b) ; ecat_comp_right_unital : forall a b: C, - forall r: (a ~^_(V,C) b) * onec ~>_V (a ~^_(V,C) b), + forall r: (a ~^_(V,C) b) * onec ~>_V (a ~^_(V,C) b), r = ((@idmap V (a ~^_(V,C) b)) <*> (@id_element V C a)) \; - (@comp_morphism V C a a b) + (@comp_morphism V C a a b) }. Unset Universe Checking. #[verbose] @@ -1286,13 +1296,13 @@ Set Universe Checking. (* transpose for horizontal morphism quiver. HB.tag needed to identify transpose as lifter *) -HB.tag Definition transpose (C : quiver) : U := C. +HB.tag Definition transpose (C : quiver) : U := C. #[wrapper] HB.mixin Record _IsHQuiver C of IsQuiver C := { is_hquiver : IsQuiver (transpose C) }. (* vertical and horizontal quivers, defining cells *) Unset Universe Checking. -#[short(type="vhquiver")] +#[short(type="vhquiver")] HB.structure Definition VHQuiver : Set := { C of IsQuiver C & IsQuiver (transpose C) }. Set Universe Checking. @@ -1312,7 +1322,7 @@ Record Total2 T (h: T -> T -> U) : Type := TT2 { HB.tag Definition D1obj (C: vhquiver) := Total2 (@hhom C). (* D1 quiver requirement (includes D0 quiver and its transpose). *) -#[wrapper] +#[wrapper] HB.mixin Record _IsDQuiver T of VHQuiver T := { is_dquiver : Quiver (D1obj T) }. Unset Universe Checking. @@ -1337,7 +1347,7 @@ Set Universe Checking. (* The category based on the HQuiver (i.e. horizontal category on D0 objects) *) Unset Universe Checking. -#[wrapper] +#[wrapper] HB.mixin Record _IsHCat T of HPreCat T := { is_hcat : PreCat_IsCat (transpose T) }. #[short(type="hcat")] @@ -1362,7 +1372,7 @@ Set Universe Checking. (* The category based on the DQuiver (i.e. category D1). *) Unset Universe Checking. -#[wrapper] +#[wrapper] HB.mixin Record _IsD1Cat T of D1PreCat T := { is_d1cat : PreCat_IsCat (@D1obj T) }. #[short(type="d1cat")] @@ -1411,7 +1421,7 @@ HB.tag Definition HTarget C := fun (X: D1obj C) => @target C (@hhom C) X. Definition hhunit (T: hprecat) (a: T) : D1obj T := @TT2 T (@hhom T) a a (@idmap (transpose T) a). HB.tag Definition H1Unit (C: hprecat) := - fun (x: HPreCat.sort C) => @hhunit C x. + fun (x: HPreCat.sort C) => @hhunit C x. (** Auxiliary notions for 2-cell Horizontal Composition functor *) @@ -1435,11 +1445,11 @@ Definition H2Second (C: vhquiver) (X: @DPobj C) : D1obj C := (* horizontal composition functor: D1 * D1 -> D1 *) -Definition hhcomp (T: hprecat) (x: DPobj T) : D1obj T := - match x with +Definition hhcomp (T: hprecat) (x: DPobj T) : D1obj T := + match x with @GC _ _ a b c h1 h2 => @TT2 T (@hhom T) a c (h1 \; h2) end. HB.tag Definition H1Comp (C: hprecat) := - fun (x: DPobj C) => @hhcomp C x. + fun (x: DPobj C) => @hhcomp C x. (* hhunit - horizontal unit functor. @@ -1501,15 +1511,15 @@ Set Universe Checking. (* unit prefunctor. *) Unset Universe Checking. -#[wrapper] -HB.mixin Record IsUPreFunctor T of SDCat T := +#[wrapper] +HB.mixin Record IsUPreFunctor T of SDCat T := { is_uprefunctor : IsPreFunctor T (D1obj T) (@H1Unit T) }. HB.structure Definition UPreFunctor : Set := {C of IsUPreFunctor C}. Set Universe Checking. (* unit functor. *) Unset Universe Checking. -#[wrapper] +#[wrapper] HB.mixin Record UPreFunctor_IsFunctor T of UPreFunctor T := { is_ufunctor : PreFunctor_IsFunctor T (D1obj T) (@H1Unit T) }. HB.structure Definition UFunctor : Set := {C of UPreFunctor_IsFunctor C}. @@ -1527,17 +1537,17 @@ Set Universe Checking. (* 2-cell source *) Definition H1Source (T: SFunctor.type) (a b: @D1obj T) (m: @d1hom T a b) : - (HSource a) ~> (HSource b) := (@HSource T) <$> m. + (HSource a) ~> (HSource b) := (@HSource T) <$> m. (* 2-cell target *) Definition H1Target (T: TFunctor.type) (a b: @D1obj T) (m: @d1hom T a b) : - (HTarget a) ~> (HTarget b) := (@HTarget T) <$> m. + (HTarget a) ~> (HTarget b) := (@HTarget T) <$> m. (* horizontal 2-cell unit (maps vertical morphisms to horizontally unitary 2-cells) *) Definition H2Unit (T: UFunctor.type) (a b: T) (m: @hom T a b) : - (H1Unit a) ~> (H1Unit b) := (@H1Unit T) <$> m. + (H1Unit a) ~> (H1Unit b) := (@H1Unit T) <$> m. (** Horizontal product category (D1 *d0 D1) *) @@ -1558,8 +1568,8 @@ Notation "'sigma' x .. y , p" := (** DPobj quiver *) Definition DP_hom (T: STUFunctor.type) (x y: DPobj T) := - sigma (hh0: D1hom (h_first x) (h_first y)) - (hh1: D1hom (h_second x) (h_second y)), + sigma (hh0: D1hom (h_first x) (h_first y)) + (hh1: D1hom (h_second x) (h_second y)), H1Target hh0 = H1Source hh1. HB.instance Definition DPQuiver (T: STUFunctor.type) : @@ -1597,7 +1607,7 @@ Definition DP_comp_auxA (T : STUFunctor.type) (ppA : H1Target hhA0 = H1Source hhA1) (hhB0 : D1hom (h_first B) (h_first C)) (hhB1 : D1hom (h_second B) (h_second C)) - (ppB : H1Target hhB0 = H1Source hhB1) : + (ppB : H1Target hhB0 = H1Source hhB1) : (H1Target hhA0) \; (H1Target hhB0) = (H1Source hhA1) \; (H1Source hhB1). rewrite ppA. @@ -1613,7 +1623,7 @@ Definition DP_comp_auxS (T : STUFunctor.type) (hhB0 : D1hom (h_first B) (h_first C)) (hhB1 : D1hom (h_second B) (h_second C)) (ppB : H1Target hhB0 = H1Source hhB1) : - H1Source (hhA1 \; hhB1) = (H1Source hhA1) \; (H1Source hhB1). + H1Source (hhA1 \; hhB1) = (H1Source hhA1) \; (H1Source hhB1). unfold H1Source, HSource. repeat rewrite Fcomp. reflexivity. @@ -1647,10 +1657,10 @@ Definition DP_comp_auxI (T : STUFunctor.type) setoid_rewrite DP_comp_auxS; eauto. setoid_rewrite DP_comp_auxT; eauto. eapply DP_comp_auxA; eauto. -Defined. - +Defined. + (* DPobj composition, defined in proof mode *) -Definition DP_comp (T: STUFunctor.type) (A B C: DPobj T) : +Definition DP_comp (T: STUFunctor.type) (A B C: DPobj T) : (A ~> B) -> (B ~> C) -> A ~> C. intros chA chB. destruct chA as [hhA0 [hhA1 ppA]]. @@ -1660,7 +1670,7 @@ Defined. (* DPobj is a precategory *) HB.instance Definition DPPreCat (T: STUFunctor.type) : - Quiver_IsPreCat (DPobj T) := + Quiver_IsPreCat (DPobj T) := Quiver_IsPreCat.Build (DPobj T) (@DP_id T) (@DP_comp T). (* @@ -1683,12 +1693,12 @@ Lemma DP_LeftUnit_lemma (T : STUFunctor.type) : forall (a b : DPobj T) (f : a ~> b), idmap \; f = f. move => a b [x [x0 e]] /=. - simpl in *. + simpl in *. unfold idmap; simpl. unfold DP_id; simpl. unfold comp; simpl. unfold DP_comp_auxI; simpl. - + assert (idmap \; x = x) as A. { rewrite comp1o; auto. } @@ -1702,7 +1712,7 @@ Lemma DP_LeftUnit_lemma (T : STUFunctor.type) : destruct a eqn: aaa. destruct b eqn: bbb. simpl. - + assert (existT (fun hh0 : D1hom h_first0 h_first1 => sigma hh1 : D1hom h_second0 h_second1,H1Target hh0 = H1Source hh1) @@ -1742,18 +1752,18 @@ Lemma DP_LeftUnit_lemma (T : STUFunctor.type) : rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] (Prop_irrelevance _ B). eapply C. -Qed. +Qed. Lemma DP_RightUnit_lemma (T : STUFunctor.type) : forall (a b : DPobj T) (f : a ~> b), f \; idmap = f. - + move => a b [x [x0 e]] /=. - simpl in *. + simpl in *. unfold idmap; simpl. unfold DP_id; simpl. unfold comp; simpl. unfold DP_comp_auxI; simpl. - + assert (x \; idmap = x) as A. { rewrite compo1; auto. } @@ -1767,7 +1777,7 @@ Lemma DP_RightUnit_lemma (T : STUFunctor.type) : destruct a eqn: aaa. destruct b eqn: bbb. simpl. - + assert (existT (fun hh0 : D1hom h_first0 h_first1 => sigma hh1 : D1hom h_second0 h_second1, @@ -1804,13 +1814,13 @@ Lemma DP_RightUnit_lemma (T : STUFunctor.type) : rewrite BE. reflexivity. - } + } inversion aaa; subst. rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] (Prop_irrelevance _ B). eapply C. -Qed. +Qed. Lemma DP_Assoc_lemma (T : STUFunctor.type) : forall (a b c d : DPobj T) (f : a ~> b) (g : b ~> c) (h : c ~> d), @@ -1843,14 +1853,14 @@ Lemma DP_Assoc_lemma (T : STUFunctor.type) : { subst y0_12 y01_2. rewrite compoA; eauto. } - set (x01_t := comp (H1Target x0) (H1Target x1)). - set (x01_2_t := comp x01_t (H1Target x2)). - set (x12_t := comp (H1Target x1) (H1Target x2)). - set (x0_12_t := comp (H1Target x0) x12_t). - set (y01_s := comp (H1Source y0) (H1Source y1)). - set (y01_2_s := comp y01_s (H1Source y2)). - set (y12_s := comp (H1Source y1) (H1Source y2)). - set (y0_12_s := comp (H1Source y0) y12_s). + set (x01_t := comp (H1Target x0) (H1Target x1)). + set (x01_2_t := comp x01_t (H1Target x2)). + set (x12_t := comp (H1Target x1) (H1Target x2)). + set (x0_12_t := comp (H1Target x0) x12_t). + set (y01_s := comp (H1Source y0) (H1Source y1)). + set (y01_2_s := comp y01_s (H1Source y2)). + set (y12_s := comp (H1Source y1) (H1Source y2)). + set (y0_12_s := comp (H1Source y0) y12_s). assert (x01_t = y01_s) as E01. { subst x01_t y01_s. @@ -1877,7 +1887,7 @@ Lemma DP_Assoc_lemma (T : STUFunctor.type) : { subst y0_12_s y01_2_s. subst y12_s y01_s. rewrite compoA; auto. } - + unfold comp. simpl. unfold DP_comp. @@ -1898,7 +1908,7 @@ Lemma DP_Assoc_lemma (T : STUFunctor.type) : unfold H1Source. repeat rewrite Fcomp; simpl. auto. - } + } assert (H1Target ((x0 \; x1) \; x2) = H1Source ((y0 \; y1) \; y2)) as KL. @@ -1911,8 +1921,8 @@ Lemma DP_Assoc_lemma (T : STUFunctor.type) : unfold H1Source. repeat rewrite Fcomp; simpl. auto. - } - + } + assert (existT (fun hh0 : D1hom (h_first a) (h_first d) => sigma hh1 : D1hom (h_second a) (h_second d), @@ -1920,9 +1930,9 @@ Lemma DP_Assoc_lemma (T : STUFunctor.type) : (x0 \; x1 \; x2) (existT (fun hh1 : D1hom (h_second a) (h_second d) => - H1Target (x0 \; x1 \; x2) = H1Source hh1) + H1Target (x0 \; x1 \; x2) = H1Source hh1) (y0 \; y1 \; y2) - KR) + KR) = existT (fun hh0 : D1hom (h_first a) (h_first d) => @@ -1931,7 +1941,7 @@ Lemma DP_Assoc_lemma (T : STUFunctor.type) : ((x0 \; x1) \; x2) (existT (fun hh1 : D1hom (h_second a) (h_second d) => - H1Target ((x0 \; x1) \; x2) = H1Source hh1) + H1Target ((x0 \; x1) \; x2) = H1Source hh1) ((y0 \; y1) \; y2) KL)) as KA. { revert KL. @@ -1941,7 +1951,7 @@ Lemma DP_Assoc_lemma (T : STUFunctor.type) : rewrite <- X0. rewrite <- Y0. intros KR KL. - + assert (KR = KL) as I1. { eapply Prop_irrelevance. } rewrite I1. @@ -1972,7 +1982,7 @@ HB.instance Definition DPCat (T: STUFunctor.type) := DPCatP T. (* composition prefunctor *) Unset Universe Checking. -#[wrapper] +#[wrapper] HB.mixin Record IsCPreFunctor T of STUFunctor T := { is_cprefunctor : IsPreFunctor (DPobj T) (D1obj T) (@H1Comp T) }. HB.structure Definition CPreFunctor : Set := {C of IsCPreFunctor C}. @@ -1980,7 +1990,7 @@ Set Universe Checking. (* composition functor - gives the definition of Strict Double Category *) Unset Universe Checking. -#[wrapper] +#[wrapper] HB.mixin Record CPreFunctor_IsFunctor T of CPreFunctor T := { is_cfunctor : PreFunctor_IsFunctor (DPobj T) (D1obj T) (@H1Comp T) }. #[short(type="sdoublecat")] @@ -2047,7 +2057,7 @@ split=> [] sq. set w' : F' ~> C := bot2left big_red_square. set z' : F' ~> B := bot2right big_red_square. move=> E3. - + have xxx : isPrePullback Q A B (Cospan f g) (Span (w' \; h) z'). by constructor=> /=; rewrite -compoA E3. pose red_black_square : prepullback (Cospan f g) := @@ -2096,18 +2106,25 @@ End test. (* still problematic *) (* Defining internal hom objects. - C0 and C1 are objects of C. - C0 is the object of objects, - C1 is the object of morphims (and the subject). + C0 and C1 are objects of C. + C0 is the object of objects, + C1 is the object of morphims (and the subject). this will allow to define a generic _ *_C0 _ notation by recognizing the structure of hom objects on the LHS and RHS *) -HB.mixin Record isInternalHom {C: quiver} (C0 C1 : C) := { +HB.mixin Record isInternalHom {C: quiver} (C0 : C) (C1 : obj C) := { src : C1 ~> C0; tgt : C1 ~> C0 }. #[short(type="iHom")] HB.structure Definition InternalHom {C: quiver} (C0 : C) := { C1 of isInternalHom C C0 C1 }. +Notation "X ':>' C" := (X : obj C) (at level 60, C at next level). + +(* HB.instance Definition _ (T : quiver) := Quiver.on (obj T). *) +(* HB.instance Definition _ (T : precat) := PreCat.on (obj T). *) +(* HB.instance Definition _ (T : cat) := Cat.on (obj T). *) +(* HB.instance Definition _ (T : pbcat) := PBCat.on (obj T). *) + (* Definition tgt' := @tgt. Arguments tgt' {_ _} _. @@ -2125,39 +2142,49 @@ Original code: Definition iprod {C} {C0 : C} (X Y : iHom C0) := bottom (pb (Cospan (src X) (tgt Y))). Notation "X *_ C0 Y" := (@iprod _ C0 X Y). - + HB.instance Definition iprod_iHom := isInternalHom.Build C0 (X *_C0 Y) (src (bot2left _)) (tgt (bot2right _)). *) -Definition iprod_pb {C: pbcat} {C0 : C} (X Y : iHom C0) : span X Y := - pb _ _ (Cospan (tgt : X ~> C0) (src : Y ~> C0)). -Definition iprod {C: pbcat} {C0 : C} (X Y : iHom C0) : C := +Definition iprod_pb {C: pbcat} {C0 : C} (X Y : iHom C0) : + span (X :> C) (Y :> C) := + pb _ _ (Cospan (tgt : (X :> C) ~> C0) (src : (Y :> C) ~> C0)). + +Definition iprod {C: pbcat} {C0 : obj C} (X Y : iHom C0) : obj C := bot (@iprod_pb C C0 X Y). -Notation "X *_ C0 Y" := (@iprod _ C0 X Y) +Notation "X *_ C0 Y" := (@iprod _ C0 (X : iHom C0) (Y : iHom C0)) (at level 99, C0 at level 0, only parsing) : cat_scope. +Notation "X *_ C0 Y" := (@iprod _ C0 X Y) + (at level 99, C0 at level 0) : cat_scope. -Definition iprodl {C: pbcat} {C0 : C} (X Y : iHom C0) : X *_C0 Y ~> X := +Definition iprodl {C: pbcat} {C0 : C} (X Y : iHom C0) : X *_C0 Y ~> (X :> C) := bot2left (iprod_pb X Y). -Definition iprodr {C: pbcat} {C0 : C} (X Y : iHom C0) : X *_C0 Y ~> Y := +Definition iprodr {C: pbcat} {C0 : C} (X Y : iHom C0) : X *_C0 Y ~> (Y :> C) := bot2right (iprod_pb X Y). (* Given (iHom C0) instances X and Y, we want to say that (X *_C0 Y) is also an instance of (iHom C0). Notice, however, that X and Y do not represent composable morphisms *) -Program Definition iprod_iHom {C: pbcat} {C0: C} (X Y: @iHom C C0) : +Definition iprod_iHom {C: pbcat} {C0: C} (X Y: @iHom C C0) : @isInternalHom C C0 (X *_C0 Y) := - @isInternalHom.Build C C0 (X *_C0 Y) - ((iprodl X Y) \; src) + @isInternalHom.Build C C0 (X *_C0 Y) + ((iprodl X Y) \; src) ((iprodr X Y) \; tgt). +HB.instance Definition _ {C: pbcat} {C0: C} (X Y: @iHom C C0) := iprod_iHom X Y. + +Definition pbC0 (C : pbcat) (C0 : C) (X Y : iHom C0) : iHom C0 := + (X *_C0 Y) : iHom C0. + (* we also define the trivial internal hom type *) HB.instance Definition trivial_iHom {C: pbcat} {C0: C} := isInternalHom.Build C C0 C0 idmap idmap. + (* we need internal hom morphisms: the ones that preserve sources and targets *) HB.mixin Record IsInternalHomHom {C: pbcat} (C0 : C) - (C1 C1' : @iHom C C0) (f : C1 ~> C1') := { + (C1 C1' : @iHom C C0) (f : (C1 :> C) ~> (C1' :> C)) := { hom_src : f \; src = src; hom_tgt : f \; tgt = tgt; }. @@ -2190,66 +2217,92 @@ Admitted. Obligation 2. Admitted. Obligation 3. -Admitted. +Admitted. + +HB.instance Definition _ {C: pbcat} (C0 : C) := iHom_cat C0. -HB.instance Definition iHom_cat' {C: pbcat} (C0 : C) := iHom_cat C0. +Definition iprodlC0 {C: pbcat} {C0 : C} (X Y : iHom C0) : + pbC0 X Y ~>_(iHom C0) X. +Admitted. +Definition iprodrC0 {C: pbcat} {C0 : C} (X Y : iHom C0) : + pbC0 X Y ~>_(iHom C0) Y. +Admitted. (* Now we define an internal quiver as an object C0, which has a C1 : iHom C0 attached to it *) -HB.mixin Record IsPreInternalQuiver C of Quiver C := - { C0 : C; - C1 : C }. -HB.structure Definition PreInternalQuiver := { - C of IsPreInternalQuiver C }. - -#[wrapper] HB.mixin Record IsInternalQuiver C of - Quiver C & PreInternalQuiver C := { - priv: Quiver (@InternalHom C (@C0 C) (@C1 C)) +HB.mixin Record IsPreInternalQuiver (C : quiver) (C0 : obj C) := + { C1 : obj C }. +HB.structure Definition PreInternalQuiver C := + { C0 of @IsPreInternalQuiver C C0 }. + +Arguments C1 {C s}. + +#[wrapper] HB.mixin Record IsInternalQuiver (C : quiver) (C0 : obj C) of + @PreInternalQuiver C C0 := { + priv: @InternalHom C C0 (@C1 _ C0) }. -HB.structure Definition InternalQuiver := { - C of IsInternalQuiver C }. +#[short(type="iquiver")] +HB.structure Definition InternalQuiver (C : quiver) := + { C0 of IsInternalQuiver C C0 }. + +Coercion iquiver_quiver (C : quiver) (C0 : iquiver C) : C := C0 :> C. +Coercion iquiver_precat (C : precat) (C0 : iquiver C) : C := C0 :> C. +Coercion iquiver_cat (C : precat) (C0 : iquiver C) : C := C0 :> C. + (* PROBLEM: nested product does not typecheck *) -Fail Definition iprodA {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0): - (C1 *_C0 C2) *_C0 C3 ~> C1 *_C0 (C2 *_C0 C3). (* := ... *) +Definition iprodA {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0): + ((C1 *_C0 C2 : iHom C0) *_C0 C3) ~>_(iHom C0) + (C1 *_C0 (C2 *_C0 C3 : iHom C0) : iHom C0). (* := ... *) (* define it with the universal arrow of the pullback *) +Admitted. Definition ipair {C : pbcat} {C0 : C} {C1 C2 C3 C4 : iHom C0} - (f : C1 ~> C3) (g : C2 ~> C4) : C1 *_C0 C2 ~> C3 *_C0 C4. + (f : C1 ~> C3) (g : C2 ~> C4) : (C1 *_C0 C2) ~>_(iHom C0) (C3 *_C0 C4). Admitted. -Notation "< f , g >" := (ipair f g). +Notation "<( f , g )>" := (ipair f g). (* An internal precategory is an internal category with two operators that must be src and tgt preserving, i.e. iHom morphisms *) -HB.mixin Record IsInternalPreCat C of PBCat C & - InternalQuiver C := { - iid : (@C0 C) ~>_(@iHom C (@C0 C)) (@C1 C); - icomp : C1 *_C0 C1 ~>_(@iHom C C0) C1 +HB.mixin Record IsInternalPreCat (C : pbcat) (C0 : obj C) + of @InternalQuiver C C0 := { + iid : (C0 : iHom C0) ~>_(iHom C0) (@C1 C C0 : iHom C0); + icomp : let C1 := @C1 C C0 : iHom C0 in + let C2 := pbC0 C1 C1 : iHom C0 in + (C2 ~>_(iHom C0) C1) }. -#[short(type="internalprecat")] -HB.structure Definition InternalPrecat (C : pbcat) := - { q of @IsPreInternalPreCat C q }. +#[short(type="iprecat")] +HB.structure Definition InternalPreCat (C : pbcat) := + { C0 of @IsInternalPreCat C C0 }. + +(* Check (iquiver Type <~> quiver). *) +(* Check (iprecat Type <~> precat). *) (* An internal category moreover must satisfy additional properies on iid and icomp *) -HB.mixin Record IsInternalCat (C : pbcat) (C0 : C) of InternalPreCat C0 := { - icompA : \; icomp = iprodA \; \; icomp; - icomp1l : \; icomp = iprodl; - icomp1r : \; icomp = iprodr; +#[key="C0"] +HB.mixin Record IsInternalCat (C : pbcat) (C0 : obj C) of InternalPreCat C C0 := { + (* icompA : <(icomp, idmap)> \; icomp = (iprodA _ _ _) \; <(idmap, icomp)> \; icomp; *) + (* icomp1l : <(idmap, iid)> \; icomp = iprodlC0 C1 C1; *) + (* icomp1r : <(iid, idmap)> \; icomp = iprodrC0 C1 C1; *) +}. +#[short(type="icat")] HB.structure Definition InternalCat (C : pbcat) := {C0 of @IsInternalCat C C0}. +(* Check (icat Type <~> cat). *) + -(* A double category is an internal category in cat +(* A double category is an internal category in cat - The objects are the objects of C0 - The vertical maps are the maps of C0 - The horizontal maps are the objects of C1 - The 2-cells are the maps of C1 - + About identities: - The identity vertical map on (x : C) is \idmap_x - The identity horizontal map on (x : C) is iid x - the identity 2-cell on (x : C) is iid (\idmap_x) = \idmap_(iid x) - + About compositions: - The vertical composition of maps is the composition of C0 - The vertical compositions of 2-cells is the composition of C1 @@ -2258,7 +2311,18 @@ HB.structure Definition InternalCat (C : pbcat) := {C0 of @IsInternalCat C C0}. - The horizontal composition of maps is the object part of icomp - The horizontal composition of 2-cells is the map part of icomp *) -HB.structure' Definition DoubleCat := @InternalCat cat. +(* HB.structure' Definition DoubleCat := @InternalCat cat. *) +Axiom cat_pbop : HasPBop cat. +HB.instance Definition _ := cat_pbop. +Axiom cat_preb : + forall (a b: cat) (c: cospan a b), isPrePullback cat a b c (@pb cat a b c). +HB.instance Definition _ (a b: cat) (c: cospan a b) := @cat_preb a b c. +Axiom cat_pb : + forall (a b: cat) (c: cospan a b), + prepullback_isTerminal cat a b c (@pb cat a b c). +HB.instance Definition _ (a b: cat) (c: cospan a b) := @cat_pb a b c. +Definition doublecat := icat cat. +(* Check (doublecat <~> ???) *) From 415136976335bbc9a98926d66359a78483ee9818 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Thu, 7 Dec 2023 18:41:35 +0100 Subject: [PATCH 103/147] updated encatD.v --- theories/encatD.v | 288 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 243 insertions(+), 45 deletions(-) diff --git a/theories/encatD.v b/theories/encatD.v index e5434e3cc..47c9a4aee 100644 --- a/theories/encatD.v +++ b/theories/encatD.v @@ -1,3 +1,4 @@ +Require Import Coq.Program.Equality. Require Import ssreflect ssrfun. From HB Require Import structures. @@ -2102,15 +2103,17 @@ End test. (************************************************************************) -(**** INTERNAL CATEGORIES - ALTERNATIVE DEFINITION *) -(* still problematic *) +(**** INTERNAL CATEGORIES - NEW DEFINITION *) (* Defining internal hom objects. C0 and C1 are objects of C. C0 is the object of objects, C1 is the object of morphims (and the subject). this will allow to define a generic _ *_C0 _ notation - by recognizing the structure of hom objects on the LHS and RHS *) + by recognizing the structure of hom objects on the LHS and RHS + Basically, w.r.t. double categories, C1 represents 'horizontal' + 1-morpshisms and the D1 category, whereas C0 represents the objects + of the base D0 category. *) HB.mixin Record isInternalHom {C: quiver} (C0 : C) (C1 : obj C) := { src : C1 ~> C0; tgt : C1 ~> C0 }. @@ -2125,27 +2128,12 @@ Notation "X ':>' C" := (X : obj C) (at level 60, C at next level). (* HB.instance Definition _ (T : cat) := Cat.on (obj T). *) (* HB.instance Definition _ (T : pbcat) := PBCat.on (obj T). *) -(* -Definition tgt' := @tgt. -Arguments tgt' {_ _} _. -*) -(* The cospan is a type-level one: it says that for ANY morphism, -source and target are objects (NOT necesarily the SAME object). X and -Y are two instances of the morphism object (iHom C0), which here -depends on the object of objects C0. Basically, X and Y are two -versions of C1. X and Y are NOT two distinct morphisms in the ambient -category. The cospan does NOT imply that ambient morphisms typed by X -and Y are composable (i.e. adjacent). 'iprod' is not a morphism, it is -just an object of C. - -Original code: - -Definition iprod {C} {C0 : C} (X Y : iHom C0) := bottom (pb (Cospan - (src X) (tgt Y))). Notation "X *_ C0 Y" := (@iprod _ C0 X Y). - -HB.instance Definition iprod_iHom := isInternalHom.Build C0 (X *_C0 Y) - (src (bot2left _)) (tgt (bot2right _)). *) - +(* constructs the pullback from the cospan given by target and source. + Type-level construction: it says that for ANY morphism, source and + target are objects (NOT necesarily the SAME object). X and Y are + two instances of the morphism object, specified by (iHom C0), and + are objects of (obj C). Here 'iprod' is just an object of (obj + C). *) Definition iprod_pb {C: pbcat} {C0 : C} (X Y : iHom C0) : span (X :> C) (Y :> C) := pb _ _ (Cospan (tgt : (X :> C) ~> C0) (src : (Y :> C) ~> C0)). @@ -2157,22 +2145,48 @@ Notation "X *_ C0 Y" := (@iprod _ C0 (X : iHom C0) (Y : iHom C0)) Notation "X *_ C0 Y" := (@iprod _ C0 X Y) (at level 99, C0 at level 0) : cat_scope. -Definition iprodl {C: pbcat} {C0 : C} (X Y : iHom C0) : X *_C0 Y ~> (X :> C) := - bot2left (iprod_pb X Y). -Definition iprodr {C: pbcat} {C0 : C} (X Y : iHom C0) : X *_C0 Y ~> (Y :> C) := - bot2right (iprod_pb X Y). +(* +(1) Defines pullback square (iprod_pb) + + X --- tgt -----> C0 + ^ ^ + | | + bot2left src + | | + X*Y - bot2right -> Y + + +(2) Defines source and target of the product (iprod_iHom) + + X --- src -----> C0 + ^ ^ + | | + iprodl tgt + | | + X*Y -- iprodr ---> Y +*) + +(* left and right projection morphisms of the product *) +Definition iprodl {C: pbcat} {C0 : C} (X Y : iHom C0) : + X *_C0 Y ~> (X :> C) := bot2left (iprod_pb X Y). +Definition iprodr {C: pbcat} {C0 : C} (X Y : iHom C0) : + X *_C0 Y ~> (Y :> C) := bot2right (iprod_pb X Y). (* Given (iHom C0) instances X and Y, we want to say that (X *_C0 Y) -is also an instance of (iHom C0). Notice, however, that X and Y do not -represent composable morphisms *) +is also an instance of (iHom C0). X and Y represent composable +morphisms, as by pullback properties, the diagram (1) commutes. +source and target are obtained by composing with product projections +(2) *) Definition iprod_iHom {C: pbcat} {C0: C} (X Y: @iHom C C0) : @isInternalHom C C0 (X *_C0 Y) := @isInternalHom.Build C C0 (X *_C0 Y) ((iprodl X Y) \; src) ((iprodr X Y) \; tgt). -HB.instance Definition _ {C: pbcat} {C0: C} (X Y: @iHom C C0) := iprod_iHom X Y. +HB.instance Definition iprod_iHom' {C: pbcat} {C0: C} (X Y: @iHom C C0) : + @isInternalHom C C0 (X *_C0 Y) := iprod_iHom X Y. +(* the product as (iHom C0) object *) Definition pbC0 (C : pbcat) (C0 : C) (X Y : iHom C0) : iHom C0 := (X *_C0 Y) : iHom C0. @@ -2181,8 +2195,10 @@ HB.instance Definition trivial_iHom {C: pbcat} {C0: C} := isInternalHom.Build C C0 C0 idmap idmap. -(* we need internal hom morphisms: -the ones that preserve sources and targets *) +(* we need internal hom morphisms: +the ones that preserve sources and targets. +basically, we recast morphisms in (obj C) into some in (@iHom C C0), +i.e. into morphism between copies of C1 *) HB.mixin Record IsInternalHomHom {C: pbcat} (C0 : C) (C1 C1' : @iHom C C0) (f : (C1 :> C) ~> (C1' :> C)) := { hom_src : f \; src = src; @@ -2198,28 +2214,200 @@ HB.structure Definition InternalHomHom {C: pbcat} HB.instance Definition iHom_quiver {C: pbcat} (C0 : C) : IsQuiver (@iHom C C0) := IsQuiver.Build (@iHom C C0) (@iHomHom C C0). +Print iHom_quiver. + +Program Definition pre_iHom_id {C: pbcat} (C0 : C) (C1 : @iHom C C0) : + @IsInternalHomHom C C0 C1 C1 idmap := + @IsInternalHomHom.Build C C0 C1 C1 idmap _ _. +Obligation 1. +setoid_rewrite comp1o; reflexivity. +Defined. +Obligation 2. +setoid_rewrite comp1o; reflexivity. +Defined. + +Program Definition iHom_id {C: pbcat} (C0 : C) (C1 : @iHom C C0) : + C1 ~>_(@iHom C C0) C1 := + @InternalHomHom.Pack C C0 C1 C1 idmap _. +(* +The term "pre_iHom_id C1" has type "IsInternalHomHom.phant_axioms idmap" +while it is expected to have type "InternalHomHom.axioms_ ?sort". +*) +Obligation 1. +econstructor. +eapply (@pre_iHom_id C C0 C1). +Defined. + +Program Definition pre_iHom_comp {C: pbcat} (C0 : C) (C1 C2 C3: @iHom C C0) + (f: C1 ~>_(@iHom C C0) C2) (g: C2 ~>_(@iHom C C0) C3) : + @IsInternalHomHom C C0 C1 C3 (f \; g) := + @IsInternalHomHom.Build C C0 C1 C3 (f \; g) _ _. +Obligation 1. +setoid_rewrite <- compoA. +repeat (setoid_rewrite hom_src); auto. +Defined. +Obligation 2. +setoid_rewrite <- compoA. +repeat (setoid_rewrite hom_tgt); auto. +Defined. + +Program Definition iHom_comp {C: pbcat} (C0 : C) (C1 C2 C3: @iHom C C0) + (f: C1 ~>_(@iHom C C0) C2) (g: C2 ~>_(@iHom C C0) C3) : + C1 ~>_(@iHom C C0) C3 := + @InternalHomHom.Pack C C0 C1 C3 (f \; g) _. +Obligation 1. +econstructor. +eapply (@pre_iHom_comp C C0 C1 C2 C3 f g). +Defined. Program Definition iHom_precat {C: pbcat} (C0 : C) : Quiver_IsPreCat (@iHom C C0) := Quiver_IsPreCat.Build (@iHom C C0) _ _. Obligation 1. -Admitted. +eapply (@iHom_id C C0 a). +Defined. Obligation 2. -Admitted. +eapply (@iHom_comp C C0 a b c0 X X0). +Defined. HB.instance Definition iHom_precat' {C: pbcat} (C0 : C) := iHom_precat C0. +Lemma iHom_LeftUnit_lemma (C : pbcat) (C0 : C) + (a b : iHom C0) (f : a ~> b) : idmap \; f = f. +unfold idmap; simpl. +unfold iHom_precat_obligation_1. +unfold comp; simpl. +unfold iHom_precat_obligation_2. +unfold iHom_comp. +remember f as f1. +remember a as a1. +remember b as b1. +destruct f as [ff class]. +destruct a as [Ca class_a]. +destruct b as [Cb class_b]. +destruct class_a as [IMa]. +destruct class_b as [IMb]. +destruct class as [IM]. +destruct IMa. +destruct IMb. +destruct IM. +unfold obj in *. +simpl in *; simpl. + +eassert ( forall x, exists y, + {| + InternalHomHom.sort := idmap \; f1; + InternalHomHom.class := x + |} = + {| + InternalHomHom.sort := f1; + InternalHomHom.class := y + |} ) as A2. +{ rewrite Heqf1; simpl. + rewrite comp1o. + intros. + destruct x as [X]. + econstructor. + destruct X. + reflexivity. +}. + +setoid_rewrite Heqf1 at 3. +specialize (A2 (iHom_comp_obligation_1 (iHom_id a1) f1)). +destruct A2. +rewrite H. + +inversion Heqf1; subst. +simpl. +destruct x as [IM]. +destruct IM. + +assert (hom_src0 = hom_src1) as D1. +{ eapply Prop_irrelevance. } + +assert (hom_tgt0 = hom_tgt1) as D2. +{ eapply Prop_irrelevance. } + +rewrite D1. +rewrite D2. +reflexivity. +Qed. + +Lemma iHom_RightUnit_lemma (C : pbcat) (C0 : C) + (a b : iHom C0) (f : a ~> b) : f \; idmap = f. +unfold idmap; simpl. +unfold iHom_precat_obligation_1. +unfold comp; simpl. +unfold iHom_precat_obligation_2. +unfold iHom_comp. +remember f as f1. +remember a as a1. +remember b as b1. +destruct f as [ff class]. +destruct a as [Ca class_a]. +destruct b as [Cb class_b]. +destruct class_a as [IMa]. +destruct class_b as [IMb]. +destruct class as [IM]. +destruct IMa. +destruct IMb. +destruct IM. +unfold obj in *. +simpl in *; simpl. + +eassert ( forall x, exists y, + {| + InternalHomHom.sort := f1 \; idmap; + InternalHomHom.class := x + |} = + {| + InternalHomHom.sort := f1; + InternalHomHom.class := y + |} ) as A2. +{ rewrite Heqf1; simpl. + rewrite compo1. + intros. + destruct x as [X]. + econstructor. + destruct X. + reflexivity. +}. + +setoid_rewrite Heqf1 at 3. +specialize (A2 (iHom_comp_obligation_1 f1 (iHom_id b1))). +destruct A2. +rewrite H. + +inversion Heqf1; subst. +simpl. +destruct x as [IM]. +destruct IM. + +assert (hom_src0 = hom_src1) as D1. +{ eapply Prop_irrelevance. } + +assert (hom_tgt0 = hom_tgt1) as D2. +{ eapply Prop_irrelevance. } + +rewrite D1. +rewrite D2. +reflexivity. +Qed. + + Program Definition iHom_cat {C: pbcat} (C0 : C) : PreCat_IsCat (@iHom C C0) := PreCat_IsCat.Build (@iHom C C0) _ _ _. Obligation 1. -Admitted. +eapply iHom_LeftUnit_lemma; eauto. +Qed. Obligation 2. -Admitted. +eapply iHom_RightUnit_lemma; eauto. +Qed. Obligation 3. Admitted. -HB.instance Definition _ {C: pbcat} (C0 : C) := iHom_cat C0. +HB.instance Definition iHom_cat' {C: pbcat} (C0 : C) := iHom_cat C0. Definition iprodlC0 {C: pbcat} {C0 : C} (X Y : iHom C0) : pbC0 X Y ~>_(iHom C0) X. @@ -2248,24 +2436,29 @@ HB.structure Definition InternalQuiver (C : quiver) := Coercion iquiver_quiver (C : quiver) (C0 : iquiver C) : C := C0 :> C. Coercion iquiver_precat (C : precat) (C0 : iquiver C) : C := C0 :> C. -Coercion iquiver_cat (C : precat) (C0 : iquiver C) : C := C0 :> C. +Coercion iquiver_cat (C : cat) (C0 : iquiver C) : C := C0 :> C. -(* PROBLEM: nested product does not typecheck *) -Definition iprodA {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0): +(* nested product *) +Program Definition iprodA {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : ((C1 *_C0 C2 : iHom C0) *_C0 C3) ~>_(iHom C0) - (C1 *_C0 (C2 *_C0 C3 : iHom C0) : iHom C0). (* := ... *) + (C1 *_C0 (C2 *_C0 C3 : iHom C0) : iHom C0). + (* := ... *) (* define it with the universal arrow of the pullback *) Admitted. +(* product morphism *) Definition ipair {C : pbcat} {C0 : C} {C1 C2 C3 C4 : iHom C0} (f : C1 ~> C3) (g : C2 ~> C4) : (C1 *_C0 C2) ~>_(iHom C0) (C3 *_C0 C4). Admitted. Notation "<( f , g )>" := (ipair f g). -(* An internal precategory is an internal category with two operators that - must be src and tgt preserving, i.e. iHom morphisms *) +(* An internal precategory is an internal category with two operators + that must be src and tgt preserving, i.e. iHom morphisms: identity + : C0 -> C1 (corresponding to horizontal 1-morphism identity in + double cat) and composition : C1 * C1 -> C1 (corresponding to + horizontal composition) *) HB.mixin Record IsInternalPreCat (C : pbcat) (C0 : obj C) of @InternalQuiver C C0 := { iid : (C0 : iHom C0) ~>_(iHom C0) (@C1 C C0 : iHom C0); @@ -2280,7 +2473,8 @@ HB.structure Definition InternalPreCat (C : pbcat) := (* Check (iquiver Type <~> quiver). *) (* Check (iprecat Type <~> precat). *) -(* An internal category moreover must satisfy additional properies on iid and icomp *) +(* An internal category moreover must satisfy additional properies on iid and icomp +(associativity and unit laws) *) #[key="C0"] HB.mixin Record IsInternalCat (C : pbcat) (C0 : obj C) of InternalPreCat C C0 := { (* icompA : <(icomp, idmap)> \; icomp = (iprodA _ _ _) \; <(idmap, icomp)> \; icomp; *) @@ -2323,6 +2517,10 @@ Axiom cat_pb : prepullback_isTerminal cat a b c (@pb cat a b c). HB.instance Definition _ (a b: cat) (c: cospan a b) := @cat_pb a b c. +(* basically, the internal category adds the D1 category to the base +D0 category, which is C0 (an object of cat, which is shown to have +pullbacks) *) Definition doublecat := icat cat. (* Check (doublecat <~> ???) *) + From fc63ca4d99aedabfc8cc8e463ddf5d98acf392ef Mon Sep 17 00:00:00 2001 From: ptorrx Date: Fri, 8 Dec 2023 11:24:09 +0100 Subject: [PATCH 104/147] updated encatD.v --- theories/encatD.v | 70 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/theories/encatD.v b/theories/encatD.v index 47c9a4aee..b36c9af83 100644 --- a/theories/encatD.v +++ b/theories/encatD.v @@ -2394,7 +2394,74 @@ rewrite D2. reflexivity. Qed. +Lemma iHom_Assoc_lemma {C : pbcat} (C0 : C) + (a b c d : iHom C0) (f : a ~> b) (g : b ~> c) (h : c ~> d) : + f \; g \; h = (f \; g) \; h. + unfold comp; simpl. + unfold iHom_precat_obligation_2; simpl. + unfold iHom_comp; simpl. + remember a as a1. + remember b as b1. + remember c as c1. + remember d as d1. + remember f as f1. + remember g as g1. + remember h as h1. + destruct a as [C_a class_a]. + destruct b as [C_b class_b]. + destruct c as [C_c class_c]. + destruct d as [C_d class_d]. + destruct f as [M_f class_f]. + destruct g as [M_g class_g]. + destruct h as [M_h class_h]. + destruct class_a as [IM_a]. + destruct class_b as [IM_b]. + destruct class_c as [IM_c]. + destruct class_d as [IM_d]. + destruct IM_a. + destruct IM_b. + destruct IM_c. + destruct IM_d. + destruct class_f as [IM_f]. + destruct class_g as [IM_g]. + destruct class_h as [IM_h]. + destruct IM_f. + destruct IM_g. + destruct IM_h. + unfold obj in *; simpl in *; simpl. + + eassert ( forall x y, + {| + InternalHomHom.sort := f1 \; g1 \; h1; + InternalHomHom.class := x + |} = + {| + InternalHomHom.sort := (f1 \; g1) \; h1; + InternalHomHom.class := y + |} ) as A2. + { rewrite Heqf1; simpl. + rewrite compoA. + intros. + destruct x as [X]. + destruct y as [Y]. + destruct X. + destruct Y. + + assert (hom_src3 = hom_src4) as D1. + { eapply Prop_irrelevance. } + + assert (hom_tgt3 = hom_tgt4) as D2. + { eapply Prop_irrelevance. } + + rewrite D1. + rewrite D2. + reflexivity. + }. + setoid_rewrite A2. + reflexivity. +Qed. + Program Definition iHom_cat {C: pbcat} (C0 : C) : PreCat_IsCat (@iHom C C0) := PreCat_IsCat.Build (@iHom C C0) _ _ _. @@ -2405,7 +2472,8 @@ Obligation 2. eapply iHom_RightUnit_lemma; eauto. Qed. Obligation 3. -Admitted. +eapply iHom_Assoc_lemma; eauto. +Qed. HB.instance Definition iHom_cat' {C: pbcat} (C0 : C) := iHom_cat C0. From f661ea233c5ba5c72fce80b0acbfe4430fe73ab3 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Fri, 8 Dec 2023 17:59:42 +0100 Subject: [PATCH 105/147] updated encatD.v, added encatD1.v; open problems in both --- theories/encatD.v | 24 +- theories/encatD1.v | 2587 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 2603 insertions(+), 8 deletions(-) create mode 100644 theories/encatD1.v diff --git a/theories/encatD.v b/theories/encatD.v index b36c9af83..60a3f166c 100644 --- a/theories/encatD.v +++ b/theories/encatD.v @@ -2129,11 +2129,12 @@ Notation "X ':>' C" := (X : obj C) (at level 60, C at next level). (* HB.instance Definition _ (T : pbcat) := PBCat.on (obj T). *) (* constructs the pullback from the cospan given by target and source. - Type-level construction: it says that for ANY morphism, source and - target are objects (NOT necesarily the SAME object). X and Y are - two instances of the morphism object, specified by (iHom C0), and - are objects of (obj C). Here 'iprod' is just an object of (obj - C). *) + Type-level construction: X and Y are two instances of the morphism + object, specified by (iHom C0), and are objects of (obj C). Here + 'iprod' is just an object of (obj C). The cospan is given by the + target of X and the source of Y. The pullback provides a commuting + square on the cospan, which basically ensures that the morphisms in + X and Y can be composed. *) Definition iprod_pb {C: pbcat} {C0 : C} (X Y : iHom C0) : span (X :> C) (Y :> C) := pb _ _ (Cospan (tgt : (X :> C) ~> C0) (src : (Y :> C) ~> C0)). @@ -2477,14 +2478,21 @@ Qed. HB.instance Definition iHom_cat' {C: pbcat} (C0 : C) := iHom_cat C0. +(* PROBLEM: this morphism cannot exist, as the target of the product + isn't generally the same as the target of the first projection. + Similarly, the source of the product can be different from the + source of the sencond projection. *) Definition iprodlC0 {C: pbcat} {C0 : C} (X Y : iHom C0) : pbC0 X Y ~>_(iHom C0) X. -Admitted. + assert (@src C C0 (pbC0 X Y) = (iprodl X Y) \; @src C C0 X) as A1. + { auto. } + assert (@tgt C C0 (pbC0 X Y) = (iprodr X Y) \; @tgt C C0 Y) as A2. + { auto. } +Admitted. Definition iprodrC0 {C: pbcat} {C0 : C} (X Y : iHom C0) : pbC0 X Y ~>_(iHom C0) Y. Admitted. - (* Now we define an internal quiver as an object C0, which has a C1 : iHom C0 attached to it *) HB.mixin Record IsPreInternalQuiver (C : quiver) (C0 : obj C) := @@ -2512,7 +2520,7 @@ Program Definition iprodA {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : ((C1 *_C0 C2 : iHom C0) *_C0 C3) ~>_(iHom C0) (C1 *_C0 (C2 *_C0 C3 : iHom C0) : iHom C0). (* := ... *) - (* define it with the universal arrow of the pullback *) + (* OK define it with the universal arrow of the pullback *) Admitted. (* product morphism *) diff --git a/theories/encatD1.v b/theories/encatD1.v new file mode 100644 index 000000000..7f957d9ab --- /dev/null +++ b/theories/encatD1.v @@ -0,0 +1,2587 @@ +Require Import Coq.Program.Equality. +Require Import ssreflect ssrfun. +From HB Require Import structures. + +Set Implicit Arguments. +Unset Strict Implicit. +Unset Printing Implicit Defensive. +Add Search Blacklist "__canonical__". + +Declare Scope algebra_scope. +Delimit Scope algebra_scope with A. +Local Open Scope algebra_scope. + +Declare Scope cat_scope. +Delimit Scope cat_scope with cat. +Local Open Scope cat_scope. + +(* we assume a few axioms to make life easier *) +Axiom funext : forall {T : Type} {U : T -> Type} [f g : forall t, U t], + (forall t, f t = g t) -> f = g. +Axiom propext : forall P Q : Prop, P <-> Q -> P = Q. +Axiom Prop_irrelevance : forall (P : Prop) (x y : P), x = y. + +(* Shortcut *) +Notation U := Type. + +(* Base definition : raw categories = quivers *) +HB.mixin Record IsQuiver C := { hom : C -> C -> U }. +Unset Universe Checking. +#[short(type="quiver")] +HB.structure Definition Quiver : Set := { C of IsQuiver C }. +Set Universe Checking. + +Bind Scope cat_scope with quiver. +Bind Scope cat_scope with hom. +Arguments hom {C} : rename. +Notation homs T := (@hom T _ _). +Notation "a ~> b" := (hom a b) + (at level 99, b at level 200, format "a ~> b") : cat_scope. +Notation "a ~>_ C b" := (@hom C (a : C) (b : C)) + (at level 99, C at level 0, only parsing) : cat_scope. + +(* precategories are quivers + id and comp *) +HB.mixin Record Quiver_IsPreCat C of Quiver C := { + idmap : forall (a : C), a ~> a; + comp : forall (a b c : C), (a ~> b) -> (b ~> c) -> (a ~> c); +}. + +HB.factory Record IsPreCat C := { + hom : C -> C -> U; + idmap : forall (a : C), hom a a; + comp : forall (a b c : C), hom a b -> hom b c -> hom a c; +}. +HB.builders Context C of IsPreCat C. + HB.instance Definition _ := IsQuiver.Build C hom. + HB.instance Definition _ := Quiver_IsPreCat.Build C idmap comp. +HB.end. + +Unset Universe Checking. +#[short(type="precat")] +HB.structure Definition PreCat : Set := { C of IsPreCat C }. +Set Universe Checking. + +Bind Scope cat_scope with precat. +Arguments idmap {C} {a} : rename. +Arguments comp {C} {a b c} : rename. +Notation "f \o g" := (comp g f) : cat_scope. +Notation "f \; g :> T" := (@comp T _ _ _ f g) + (at level 60, g, T at level 60, format "f \; g :> T", only parsing) : cat_scope. +Notation "f \; g" := (comp f g) : cat_scope. +Notation "\idmap_ a" := (@idmap _ a) (only parsing, at level 0) : cat_scope. + +(* categories are precategories + laws *) +HB.mixin Record PreCat_IsCat C of PreCat C := { + comp1o : forall (a b : C) (f : a ~> b), idmap \; f = f; + compo1 : forall (a b : C) (f : a ~> b), f \; idmap = f; + compoA : forall (a b c d : C) (f : a ~> b) (g : b ~> c) (h : c ~> d), + f \; (g \; h) = (f \; g) \; h +}. +Unset Universe Checking. +#[short(type="cat")] +HB.structure Definition Cat : Set := { C of PreCat_IsCat C & IsPreCat C }. +Set Universe Checking. + +Bind Scope cat_scope with cat. +Arguments compo1 {C a b} : rename. +Arguments comp1o {C a b} : rename. +Arguments compoA {C a b c d} : rename. + +(* the discrete category on a type cannot be the default, we make an alias *) +Definition discrete (T : U) := T. +HB.instance Definition _ T := @IsPreCat.Build (discrete T) (fun x y => x = y) + (fun=> erefl) (@etrans _). +Lemma etransA T (a b c d : discrete T) (f : a ~> b) (g : b ~> c) (h : c ~> d) : + f \; (g \; h) = (f \; g) \; h. +Proof. by rewrite /idmap/comp/=; case: _ / h; case: _ / g. Qed. +HB.instance Definition _ T := PreCat_IsCat.Build (discrete T) (@etrans_id _) + (fun _ _ _ => erefl) (@etransA _). + +(* the category of the unit type is the discrete one *) +HB.instance Definition _ := Cat.copy unit (discrete unit). + +HB.instance Definition _ := @IsPreCat.Build U (fun A B => A -> B) + (fun a => idfun) (fun a b c (f : a -> b) (g : b -> c) => (g \o f)%FUN). +HB.instance Definition _ := PreCat_IsCat.Build U (fun _ _ _ => erefl) + (fun _ _ _ => erefl) (fun _ _ _ _ _ _ _ => erefl). + + +Lemma Ucomp (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) : f \; g = (g \o f)%FUN. +Proof. by []. Qed. +Lemma Ucompx (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) x : (f \; g) x = g (f x). +Proof. by []. Qed. +Lemma U1 (X : U) : \idmap_X = idfun. +Proof. by []. Qed. +Lemma U1x (X : U) x : \idmap_X x = x. +Proof. by []. Qed. + +(* a prefunctor is a functor without laws *) +HB.mixin Record IsPreFunctor (C D : quiver) (F : C -> D) := { + Fhom : forall (a b : C), (a ~> b) -> (F a ~> F b) +}. + +Unset Universe Checking. +HB.structure Definition PreFunctor (C D : quiver) : Set := + { F of IsPreFunctor C D F }. +Set Universe Checking. +HB.instance Definition _ := IsQuiver.Build quiver PreFunctor.type. + +Notation "F ^$" := (@Fhom _ _ F _ _) + (at level 1, format "F ^$") : cat_scope. +Notation "F <$> f" := (@Fhom _ _ F _ _ f) + (at level 58, format "F <$> f", right associativity) : cat_scope. + +(* prefunctors are equal if their object and hom part are respectively equal *) +Lemma prefunctorP (C D : quiver) (F G : C ~> D) (eqFG : F =1 G) : + let homF a b F := F a ~> F b in + (forall a b f, eq_rect _ (homF a b) (F <$> f) _ (funext eqFG) = G <$> f) -> + F = G. +Proof. +move: F G => [F [[/= Fhom]]] [G [[/= Ghom]]] in eqFG *. +case: _ / (funext eqFG) => /= in Ghom * => eqFGhom. +congr PreFunctor.Pack; congr PreFunctor.Class; congr IsPreFunctor.Axioms_. +by do 3!apply: funext=> ?. +Qed. + +(* a functor is a prefunctor + laws for id and comp *) +HB.mixin Record PreFunctor_IsFunctor (C D : precat) (F : C -> D) + of @PreFunctor C D F := { + F1 : forall (a : C), F <$> \idmap_a = idmap; + Fcomp : forall (a b c : C) (f : a ~> b) (g : b ~> c), + F <$> (f \; g) = F <$> f \; F <$> g; +}. +Unset Universe Checking. + +(* precat and cat have a quiver structure *) +HB.structure Definition Functor (C D : precat) : Set := + { F of IsPreFunctor C D F & PreFunctor_IsFunctor C D F }. +Set Universe Checking. +HB.instance Definition _ := IsQuiver.Build precat Functor.type. +HB.instance Definition _ := IsQuiver.Build cat Functor.type. + +(* functor equality is the same as prefunctor because of PI *) +Lemma functorP (C D : precat) (F G : C ~> D) (eqFG : F =1 G) : + let homF a b F := F a ~> F b in + (forall a b f, eq_rect _ (homF a b) (F^$ f) _ (funext eqFG) = G^$ f) -> + F = G. +Proof. +move=> /= /prefunctorP {eqFG}. +case: F G => [F [/= Fm Fm']] [G [/= Gm Gm']]//=. +move=> [_] /EqdepFacts.eq_sigT_iff_eq_dep eqFG. +case: _ / eqFG in Gm' *. +congr Functor.Pack; congr Functor.Class. +case: Fm' Gm' => [F1 Fc] [G1 Gc]. +by congr PreFunctor_IsFunctor.Axioms_; apply: Prop_irrelevance. +Qed. + +(* the identity function is a functor *) +HB.instance Definition _ (C : quiver) := + IsPreFunctor.Build C C idfun (fun a b => idfun). +HB.instance Definition _ (C : precat) := + PreFunctor_IsFunctor.Build C C idfun (fun=> erefl) (fun _ _ _ _ _ => erefl). + +(* the composition of prefunctors *) +Section comp_prefunctor. +Context {C D E : quiver} {F : C ~> D} {G : D ~> E}. + +HB.instance Definition _ := IsPreFunctor.Build C E (G \o F)%FUN + (fun a b f => G <$> F <$> f). +Lemma comp_Fun (a b : C) (f : a ~> b) : (G \o F)%FUN <$> f = G <$> (F <$> f). +Proof. by []. Qed. +End comp_prefunctor. + +Section comp_functor. +Context {C D E : precat} {F : C ~> D} {G : D ~> E}. +Lemma comp_F1 (a : C) : (G \o F)%FUN <$> \idmap_a = idmap. +Proof. by rewrite !comp_Fun !F1. Qed. +Lemma comp_Fcomp (a b c : C) (f : a ~> b) (g : b ~> c) : + (G \o F)%FUN <$> (f \; g) = (G \o F)%FUN <$> f \; (G \o F)%FUN <$> g. +Proof. by rewrite !comp_Fun !Fcomp. Qed. +HB.instance Definition _ := PreFunctor_IsFunctor.Build C E (G \o F)%FUN + comp_F1 comp_Fcomp. +End comp_functor. + +(* precat and cat have a precategory structure *) +HB.instance Definition _ := Quiver_IsPreCat.Build precat + (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). +HB.instance Definition _ := Quiver_IsPreCat.Build cat + (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). + +Lemma funext_frefl A B (f : A -> B) : funext (frefl f) = erefl. +Proof. exact: Prop_irrelevance. Qed. + +(* precategories and categories form a category *) +Definition precat_cat : PreCat_IsCat precat. +Proof. +by split=> [C D F|C D F|C D C' D' F G H]; + apply/functorP => a b f /=; rewrite funext_frefl. +Qed. +HB.instance Definition _ := precat_cat. +Definition cat_cat : PreCat_IsCat cat. +Proof. +by split=> [C D F|C D F|C D C' D' F G H]; + apply/functorP => a b f /=; rewrite funext_frefl. +Qed. +HB.instance Definition _ := cat_cat. + +Check (cat : cat). + +(* concrete categories *) +HB.mixin Record Quiver_IsPreConcrete T of Quiver T := { + concrete : T -> U; + concrete_fun : forall (a b : T), (a ~> b) -> concrete a -> concrete b; +}. +Unset Universe Checking. +#[short(type="preconcrete_quiver")] +HB.structure Definition PreConcreteQuiver : Set := + { C of Quiver_IsPreConcrete C & IsQuiver C }. +Set Universe Checking. +Coercion concrete : PreConcreteQuiver.sort >-> Sortclass. + +HB.mixin Record PreConcrete_IsConcrete T of PreConcreteQuiver T := { + concrete_fun_inj : forall (a b : T), injective (concrete_fun a b) +}. +Unset Universe Checking. +#[short(type="concrete_quiver")] +HB.structure Definition ConcreteQuiver : Set := + { C of PreConcreteQuiver C & PreConcrete_IsConcrete C }. +Set Universe Checking. + +HB.instance Definition _ (C : ConcreteQuiver.type) := + IsPreFunctor.Build _ _ (concrete : C -> U) concrete_fun. + +HB.mixin Record PreCat_IsConcrete T of ConcreteQuiver T & PreCat T := { + concrete1 : forall (a : T), concrete <$> \idmap_a = idfun; + concrete_comp : forall (a b c : T) (f : a ~> b) (g : b ~> c), + concrete <$> (f \; g) = ((concrete <$> g) \o (concrete <$> f))%FUN; +}. +Unset Universe Checking. +#[short(type="concrete_precat")] +HB.structure Definition ConcretePreCat : Set := + { C of PreCat C & ConcreteQuiver C & PreCat_IsConcrete C }. +#[short(type="concrete_cat")] +HB.structure Definition ConcreteCat : Set := + { C of Cat C & ConcreteQuiver C & PreCat_IsConcrete C }. +Set Universe Checking. + +HB.instance Definition _ (C : concrete_precat) := + PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). +HB.instance Definition _ (C : ConcreteCat.type) := + PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). + +HB.instance Definition _ := Quiver_IsPreConcrete.Build U (fun _ _ => id). +HB.instance Definition _ := PreConcrete_IsConcrete.Build U (fun _ _ _ _ => id). +HB.instance Definition _ := PreCat_IsConcrete.Build U + (fun=> erefl) (fun _ _ _ _ _ => erefl). + +Unset Universe Checking. +HB.instance Definition _ := Quiver_IsPreConcrete.Build quiver (fun _ _ => id). +HB.instance Definition _ := Quiver_IsPreConcrete.Build precat (fun _ _ => id). +HB.instance Definition _ := Quiver_IsPreConcrete.Build cat (fun _ _ => id). +Lemma quiver_concrete_subproof : PreConcrete_IsConcrete quiver. +Proof. +constructor=> C D F G FG; apply: prefunctorP. + by move=> x; congr (_ x); apply: FG. +by move=> *; apply: Prop_irrelevance. +Qed. +HB.instance Definition _ := quiver_concrete_subproof. + +Lemma precat_concrete_subproof : PreConcrete_IsConcrete precat. +Proof. +constructor=> C D F G FG; apply: functorP. + by move=> x; congr (_ x); apply: FG. +by move=> *; apply: Prop_irrelevance. +Qed. +HB.instance Definition _ := precat_concrete_subproof. + +Lemma cat_concrete_subproof : PreConcrete_IsConcrete cat. +Proof. +constructor=> C D F G FG; apply: functorP. + by move=> x; congr (_ x); apply: FG. +by move=> *; apply: Prop_irrelevance. +Qed. +HB.instance Definition _ := cat_concrete_subproof. +HB.instance Definition _ := PreCat_IsConcrete.Build precat + (fun=> erefl) (fun _ _ _ _ _ => erefl). +HB.instance Definition _ := PreCat_IsConcrete.Build cat + (fun=> erefl) (fun _ _ _ _ _ => erefl). +Set Universe Checking. + +(* constant functor *) +Definition cst (C D : quiver) (c : C) := fun of D => c. +Arguments cst {C} D c. +HB.instance Definition _ {C D : precat} (c : C) := + IsPreFunctor.Build D C (cst D c) (fun _ _ _ => idmap). +HB.instance Definition _ {C D : cat} (c : C) := + PreFunctor_IsFunctor.Build D C (cst D c) (fun=> erefl) + (fun _ _ _ _ _ => esym (compo1 idmap)). + +(* opposite category *) +Definition catop (C : U) : U := C. +Notation "C ^op" := (catop C) + (at level 2, format "C ^op") : cat_scope. +HB.instance Definition _ (C : quiver) := + IsQuiver.Build C^op (fun a b => hom b a). +HB.instance Definition _ (C : precat) := + Quiver_IsPreCat.Build (C^op) (fun=> idmap) (fun _ _ _ f g => g \; f). +HB.instance Definition _ (C : cat) := PreCat_IsCat.Build (C^op) + (fun _ _ _ => compo1 _) (fun _ _ _ => comp1o _) + (fun _ _ _ _ _ _ _ => esym (compoA _ _ _)). + +HB.instance Definition _ {C : precat} {c : C} := + IsPreFunctor.Build C _ (hom c) (fun a b f g => g \; f). +Lemma hom_Fhom_subproof (C : cat) (x : C) : + PreFunctor_IsFunctor _ _ (hom x). +Proof. by split=> *; apply/funext => h; [apply: compo1 | apply: compoA]. Qed. +HB.instance Definition _ {C : cat} {c : C} := hom_Fhom_subproof c. + +Check fun (C : cat) (x : C) => hom x : C ~>_cat U. + +Lemma hom_op {C : quiver} (c : C^op) : hom c = (@hom C)^~ c. +Proof. reflexivity. Qed. + +Lemma homFhomx {C : precat} (a b c : C) (f : a ~> b) (g : c ~> a) : + (hom c <$> f) g = g \; f. +Proof. reflexivity. Qed. + +(* nary product of categories *) +Definition dprod {I : U} (C : I -> U) := forall i, C i. + +Section hom_dprod. +Context {I : U} (C : I -> quiver). +Definition dprod_hom_subdef (a b : dprod C) := forall i, a i ~> b i. +HB.instance Definition _ := IsQuiver.Build (dprod C) dprod_hom_subdef. +End hom_dprod. +Arguments dprod_hom_subdef /. + +Section precat_dprod. +Context {I : U} (C : I -> precat). +Definition dprod_idmap_subdef (a : dprod C) : a ~> a := fun=> idmap. +Definition dprod_comp_subdef (a b c : dprod C) (f : a ~> b) (g : b ~> c) : a ~> c := + fun i => f i \; g i. +HB.instance Definition _ := IsPreCat.Build (dprod C) + dprod_idmap_subdef dprod_comp_subdef. +End precat_dprod. +Arguments dprod_idmap_subdef /. +Arguments dprod_comp_subdef /. + +Section cat_dprod. +Context {I : U} (C : I -> cat). +Local Notation type := (dprod C). +Lemma dprod_is_cat : PreCat_IsCat type. +Proof. +split=> [a b f|a b f|a b c d f g h]; apply/funext => i; +[exact: comp1o | exact: compo1 | exact: compoA]. +Qed. +HB.instance Definition _ := dprod_is_cat. +End cat_dprod. + +(* binary product *) +Section hom_prod. +Context {C D : quiver}. +Definition prod_hom_subdef (a b : C * D) := ((a.1 ~> b.1) * (a.2 ~> b.2))%type. +HB.instance Definition _ := IsQuiver.Build (C * D)%type prod_hom_subdef. +End hom_prod. + +Section precat_prod. +Context {C D : precat}. +HB.instance Definition _ := IsPreCat.Build (C * D)%type (fun=> (idmap, idmap)) + (fun a b c (f : a ~> b) (g : b ~> c) => (f.1 \; g.1, f.2 \; g.2)). +End precat_prod. + +Section cat_prod. +Context {C D : cat}. +Local Notation type := (C * D)%type. +Lemma prod_is_cat : PreCat_IsCat type. +Proof. +split=> [[a1 a2] [b1 b2] [f1 f2]|[a1 a2] [b1 b2] [f1 f2]| + [a1 a2] [b1 b2] [c1 c2] [d1 d2] [f1 f2] [g1 g2] [h1 h2]]; congr (_, _) => //=; +by [exact: comp1o | exact: compo1 | exact: compoA]. +Qed. +HB.instance Definition _ := prod_is_cat. +End cat_prod. + +(* naturality *) +HB.mixin Record IsNatural (C D : precat) (F G : C ~>_quiver D) + (n : forall c, F c ~> G c) := { + natural : forall (a b : C) (f : a ~> b), + F <$> f \; n b = n a \; G <$> f +}. +Unset Universe Checking. +HB.structure Definition Natural (C D : precat) + (F G : C ~>_quiver D) : Set := + { n of @IsNatural C D F G n }. +Set Universe Checking. +HB.instance Definition _ (C D : precat) := + IsQuiver.Build (PreFunctor.type C D) (@Natural.type C D). +HB.instance Definition _ (C D : cat) := + IsQuiver.Build (Functor.type C D) (@Natural.type C D). +Arguments natural {C D F G} n [a b] f : rename. + +Check fun (C D : cat) (F G : C ~> D) => F ~>_(C ~>_cat D) G. + +Lemma naturalx (C : precat) (D : concrete_precat) + (F G : C ~>_quiver D) (n : F ~> G) (a b : C) (f : a ~> b) g : + (concrete <$> n b) ((concrete <$> F <$> f) g) = + (concrete <$> G <$> f) ((concrete <$> n a) g). +Proof. +have /(congr1 (fun h => (concrete <$> h) g)) := natural n f. +by rewrite !Fcomp. +Qed. +Arguments naturalx {C D F G} n [a b] f. + +Lemma naturalU (C : precat) (F G : C ~>_quiver U) (n : F ~> G) + (a b : C) (f : a ~> b) g : n b (F^$ f g) = G^$ f (n a g). +Proof. exact: (naturalx n). Qed. + +Lemma natP (C D : precat) (F G : C ~>_quiver D) (n m : F ~> G) : + Natural.sort n = Natural.sort m -> n = m. +Proof. +case: n m => [/= n nP] [/= m mP] enm. +elim: _ / enm in mP *; congr Natural.Pack. +case: nP mP => [[?]] [[?]]; congr Natural.Class. +congr IsNatural.Axioms_. +exact: Prop_irrelevance. +Qed. + +Notation "F ~~> G" := (F ~>_(homs quiver) G) + (at level 99, G at level 200, format "F ~~> G"). +Notation "F ~~> G :> C ~> D" := (F ~> G :> (C ~>_quiver D)) + (at level 99, G at level 200, C, D at level 0, + format "F ~~> G :> C ~> D"). + +Definition natural_id {C D : precat} (F : C ~>_quiver D) (a : C) := \idmap_(F a). +Definition natural_id_natural (C D : cat) (F : C ~>_quiver D) : + IsNatural C D F F (natural_id F). +Proof. by constructor=> a b f; rewrite /natural_id/= compo1 comp1o. Qed. +HB.instance Definition _ C D F := @natural_id_natural C D F. + +Check fun {C D : cat} (F : C ~>_quiver D) => natural_id F : F ~> F. + +Definition natural_comp {C D : precat} (F G H : C ~>_quiver D) + (m : F ~> G) (n : G ~> H) (a : C) := m a \; n a. +Definition natural_comp_natural (C D : cat) (F G H : C ~>_quiver D) m n : + IsNatural C D F H (@natural_comp C D F G H m n). +Proof. +constructor=> a b f; rewrite /natural_comp/=. +by rewrite compoA natural -compoA natural compoA. +Qed. +HB.instance Definition _ C D F G H m n := @natural_comp_natural C D F G H m n. + +HB.instance Definition _ {C D : cat} := + Quiver_IsPreCat.Build (PreFunctor.type C D) natural_id natural_comp. +HB.instance Definition _ {C D : cat} := + Quiver_IsPreCat.Build (Functor.type C D) natural_id natural_comp. + +Lemma prefunctor_cat {C D : cat} : PreCat_IsCat (PreFunctor.type C D). +Proof. +constructor => [F G f|F G f|F G H J f g h]. +- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. +- by apply/natP/funext => a; rewrite /= /natural_comp compo1. +- by apply/natP/funext => a; rewrite /= /natural_comp compoA. +Qed. +HB.instance Definition _ C D := @prefunctor_cat C D. + +Lemma functor_cat {C D : cat} : PreCat_IsCat (Functor.type C D). +Proof. +constructor => [F G f|F G f|F G H J f g h]. +- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. +- by apply/natP/funext => a; rewrite /= /natural_comp compo1. +- by apply/natP/funext => a; rewrite /= /natural_comp compoA. +Qed. +HB.instance Definition _ C D := @functor_cat C D. + +Section nat_map_left. +Context {C D E : precat} {F G : C ~> D}. + +Definition nat_lmap (H : D ~>_quiver E) (n : forall c, F c ~> G c) : + forall c, (H \o F)%FUN c ~> (H \o G)%FUN c := fun c => H <$> n c. + +Fail Check fun (H : D ~> E) (n : F ~~> G) => nat_lmap H n : H \o F ~~> H \o G. + +Lemma nat_lmap_is_natural (H : D ~> E) (n : F ~~> G) : + IsNatural C E (H \o F) (H \o G) (nat_lmap H n). +Proof. by constructor=> a b f; rewrite /nat_lmap/= -!Fcomp natural. Qed. +HB.instance Definition _ H n := nat_lmap_is_natural H n. + +Check fun (H : D ~> E) (n : F ~~> G) => nat_lmap H n : H \o F ~~> H \o G. + +End nat_map_left. + +Notation "F n" := (nat_lmap F n) + (at level 58, format "F n", right associativity) : cat_scope. + +Section nat_map_right. +Context {C D E : precat} {F G : C ~> D}. + +Definition nat_rmap (H : E -> C) (n : forall c, F c ~> G c) : + forall c, (F \o H)%FUN c ~> (G \o H)%FUN c := fun c => n (H c). +Lemma nat_rmap_is_natural (H : E ~> C :> quiver) (n : F ~~> G) : + IsNatural E D (F \o H)%FUN (G \o H)%FUN (nat_rmap H n). +Proof. by constructor=> a b f; rewrite /nat_lmap/= natural. Qed. +HB.instance Definition _ H n := nat_rmap_is_natural H n. + +End nat_map_right. + +Notation "F <$o> n" := (nat_rmap F n) + (at level 58, format "F <$o> n", right associativity) : cat_scope. + +Definition delta (C D : cat) : C -> (D ~> C) := cst D. +Arguments delta C D : clear implicits. + +Definition map_delta {C D : cat} (a b : C) (f : a ~> b) : + delta C D a ~> delta C D b. +Proof. +apply: (@Natural.Pack _ _ (cst D a) (cst D b) (fun x => f)). +apply: Natural.Class; apply: (IsNatural.Build _ _ _ _ _). +by move=> a' b' ?; rewrite compo1 comp1o. +Defined. + +HB.instance Definition _ {C D : cat} := + IsPreFunctor.Build C (D ~> C) (delta C D) (@map_delta C D). + +Lemma delta_functor {C D : cat} : PreFunctor_IsFunctor _ _ (delta C D). +Proof. by constructor=> [a|a b c f g]; exact/natP. Qed. +HB.instance Definition _ C D := @delta_functor C D. + +HB.mixin Record IsMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { + unit : idfun ~~> M; + join : (M \o M)%FUN ~~> M; + bind : forall (a b : C), (a ~> M b) -> (M a ~> M b); + bindE : forall a b (f : a ~> M b), bind a b f = M <$> f \; join b; + unit_join : forall a, (M <$> unit a) \; join _ = idmap; + join_unit : forall a, join _ \; (M <$> unit a) = idmap; + join_square : forall a, M <$> join a \; join _ = join _ \; join _ +}. + +#[short(type="premonad")] +HB.structure Definition PreMonad (C : precat) := + {M of @PreFunctor C C M & IsMonad C M}. +#[short(type="monad")] +HB.structure Definition Monad (C : precat) := + {M of @Functor C C M & IsMonad C M}. + +HB.factory Record IsJoinMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { + unit : idfun ~~> M; + join : (M \o M)%FUN ~~> M; + unit_join : forall a, (M <$> unit a) \; join _ = idmap; + join_unit : forall a, join _ \; (M <$> unit a) = idmap; + join_square : forall a, M <$> join a \; join _ = join _ \; join _ +}. +HB.builders Context C M of IsJoinMonad C M. + HB.instance Definition _ := IsMonad.Build C M + (fun a b f => erefl) unit_join join_unit join_square. +HB.end. + +HB.mixin Record IsCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { + counit : M ~~> idfun; + cojoin : M ~~> (M \o M)%FUN; + cobind : forall (a b : C), (M a ~> b) -> (M a ~> M b); + cobindE : forall a b (f : M a ~> b), cobind a b f = cojoin _ \; M <$> f; + unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; + join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; + cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ +}. +#[short(type="precomonad")] +HB.structure Definition PreCoMonad (C : precat) := + {M of @PreFunctor C C M & IsCoMonad C M}. +#[short(type="comonad")] +HB.structure Definition CoMonad (C : precat) := + {M of @Functor C C M & IsCoMonad C M}. + +HB.factory Record IsJoinCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { + counit : M ~~> idfun; + cojoin : M ~~> (M \o M)%FUN; + unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; + join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; + cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ +}. +HB.builders Context C M of IsJoinCoMonad C M. + HB.instance Definition _ := IsCoMonad.Build C M + (fun a b f => erefl) unit_cojoin join_counit cojoin_square. +HB.end. + +Lemma idFmap (C : cat) (a b : C) (f : a ~> b) : idfun <$> f = f. +Proof. by []. Qed. + +Lemma compFmap (C D E : cat) (F : C ~> D) (G : D ~> E) (a b : C) (f : a ~> b) : + (G \o F) <$> f = G <$> F <$> f. +Proof. by []. Qed. + +(* yoneda *) +Section hom_repr. +Context {C : cat} (F : C ~>_cat U). + +Definition homF : C -> U := fun c => hom c ~~> F. + +Section nat. +Context (x y : C) (xy : x ~> y). + +(* Goal hom x ~~> F -> hom y ~~> F *) +Context (n : hom x ~~> F). +Definition homFhom c : hom y c ~> F c := fun g => n _ (xy \; g). + +Lemma homFhom_natural_subdef : IsNatural C U (hom y) F homFhom. +Proof. +by split=> a b f /=; apply/funext => g /=; + rewrite /homFhom !Ucompx/= !naturalU/= Fcomp. +Qed. +HB.instance Definition _ := homFhom_natural_subdef. +End nat. +Arguments homFhom / : clear implicits. + +HB.about IsPreFunctor.Build. +Check homFhom : forall x y : C, (x ~> y) -> (homF x -> homF y). +HB.instance Definition _ := IsPreFunctor.Build _ _ homF homFhom. +Lemma homF_functor_subproof : PreFunctor_IsFunctor _ _ homF. +Proof. +split=> [a|a b c f g]. + apply/funext => -[/= f natf]. + apply: natP => //=; apply: funext => b; apply: funext => g/=. + by rewrite comp1o. +apply/funext => -[/= h natf]. +apply: natP => //=; apply: funext => d; apply: funext => k/=. +by rewrite compoA. +Qed. +HB.instance Definition _ := homF_functor_subproof. + +Section pointed. +Context (c : C). +Definition hom_repr : homF c ~> F c := fun f => f _ idmap. +Arguments hom_repr /. + +Definition repr_hom (fc : F c) a : hom c a ~> F a := + fun f => F^$ f fc. +Arguments repr_hom / : clear implicits. +Lemma repr_hom_subdef (fc : F c) : IsNatural _ _ _ _ (repr_hom fc). +Proof. by split=> a b f /=; apply/funext=> x; rewrite !Ucompx/= Fcomp. Qed. +HB.instance Definition _ {fc : F c} := repr_hom_subdef fc. + +Definition repr_hom_nat : F c ~> homF c := repr_hom. + +Lemma hom_reprK : cancel hom_repr repr_hom_nat. +Proof. +move=> f; apply/natP; apply/funext => a; apply/funext => g /=. +by rewrite -naturalU/=; congr (f _ _); apply: comp1o. +Qed. +Lemma repr_homK : cancel (repr_hom : F c ~> homF c) hom_repr. +Proof. by move=> fc; rewrite /= F1. Qed. +End pointed. +Arguments hom_repr /. +Arguments repr_hom /. + +Lemma hom_repr_natural_subproof : IsNatural _ _ _ _ hom_repr. +Proof. +split=> a b f /=; apply/funext => n /=; rewrite !Ucompx/= compo1/=. +by rewrite -naturalU/=; congr (n _ _); apply/esym/comp1o. +Qed. +HB.instance Definition _ := hom_repr_natural_subproof. + +(* show this from the previous proof *) +Lemma hom_natural_repr_subproof : IsNatural _ _ _ _ repr_hom_nat. +Proof. +split=> a b f /=; apply: funext => fa /=; rewrite !Ucompx/=. +apply: natP; apply: funext => c /=; apply: funext => d /=. +by rewrite Fcomp Ucompx/=. +Qed. +HB.instance Definition _ := hom_natural_repr_subproof. + +Definition hom_repr_nat : homF ~~> F := hom_repr. +Definition repr_hom_nat_nat : F ~~> homF := repr_hom_nat. + +End hom_repr. + +(* comma categories *) +Module comma. +Section homcomma. +Context {C D E : precat} (F : C ~> E) (G : D ~> E). + +Definition type := { x : C * D & F x.1 ~> G x.2 }. +Definition hom_subdef (a b : type) := { + f : tag a ~> tag b & F <$> f.1 \; tagged b = tagged a \; G <$> f.2 + }. +HB.instance Definition _ := IsQuiver.Build type hom_subdef. +End homcomma. +Arguments hom_subdef /. +Section comma. +Context {C D E : cat} (F : C ~> E) (G : D ~> E). +Notation type := (type F G). + +Program Definition idmap_subdef (a : type) : a ~> a := @Tagged _ idmap _ _. +Next Obligation. by rewrite !F1 comp1o compo1. Qed. +Program Definition comp_subdef (a b c : type) + (f : a ~> b) (g : b ~> c) : a ~> c := + @Tagged _ (tag f \; tag g) _ _. +Next Obligation. by rewrite !Fcomp -compoA (tagged g) compoA (tagged f) compoA. Qed. +HB.instance Definition _ := IsPreCat.Build type idmap_subdef comp_subdef. +Arguments idmap_subdef /. +Arguments comp_subdef /. + +Lemma comma_homeqP (a b : type) (f g : a ~> b) : projT1 f = projT1 g -> f = g. +Proof. +case: f g => [f fP] [g +]/= eqfg; case: _ / eqfg => gP. +by congr existT; apply: Prop_irrelevance. +Qed. + +Lemma comma_is_cat : PreCat_IsCat type. +Proof. +by split=> [[a fa] [b fb] [*]|[a fa] [b fb] [*]|*]; + apply/comma_homeqP; rewrite /= ?(comp1o, compo1, compoA). +Qed. +HB.instance Definition _ := comma_is_cat. +End comma. +End comma. +Notation "F `/` G" := (@comma.type _ _ _ F G) + (at level 40, G at level 40, format "F `/` G") : cat_scope. +Notation "a /` G" := (cst unit a `/` G) + (at level 40, G at level 40, format "a /` G") : cat_scope. +Notation "F `/ b" := (F `/` cst unit b) + (at level 40, b at level 40, format "F `/ b") : cat_scope. +Notation "a / b" := (cst unit a `/ b) : cat_scope. + +Definition obj (C : U) : U := C. +HB.mixin Record IsInitial {C : quiver} (i : obj C) := { + to : forall c, i ~> c; + to_unique : forall c (f : i ~> c), f = to c +}. +#[short(type="initial")] +HB.structure Definition Initial {C : quiver} := {i of IsInitial C i}. + +HB.mixin Record IsTerminal {C : quiver} (t : obj C) := { + from : forall c, c ~> t; + from_unique : forall c (f : c ~> t), f = from c +}. +#[short(type="terminal")] +HB.structure Definition Terminal {C : quiver} := {t of IsTerminal C t}. +#[short(type="universal")] +HB.structure Definition Universal {C : quiver} := + {u of Initial C u & Terminal C u}. + +(* Definition hom' {C : precat} (a b : C) := a ~> b. *) +(* (* Bug *) *) +(* Identity Coercion hom'_hom : hom' >-> hom. *) + +(* HB.mixin Record IsMono {C : precat} (b c : C) (f : hom b c) := { *) +(* monoP : forall (a : C) (g1 g2 : a ~> b), g1 \; f = g2 \; f -> g1 = g2 *) +(* }. *) +(* #[short(type="mono")] *) +(* HB.structure Definition Mono {C : precat} (a b : C) := {m of IsMono C a b m}. *) +(* Notation "a >~> b" := (mono a b) *) +(* (at level 99, b at level 200, format "a >~> b") : cat_scope. *) +(* Notation "C >~>_ T D" := (@mono T C D) *) +(* (at level 99, T at level 0, only parsing) : cat_scope. *) + +(* HB.mixin Record IsEpi {C : precat} (a b : C) (f : hom a b) := { *) +(* epiP : forall (c : C) (g1 g2 : b ~> c), g1 \o f = g2 \o f -> g1 = g2 *) +(* }. *) +(* #[short(type="epi")] *) +(* HB.structure Definition Epi {C : precat} (a b : C) := {e of IsEpi C a b e}. *) +(* Notation "a ~>> b" := (epi a b) *) +(* (at level 99, b at level 200, format "a ~>> b") : cat_scope. *) +(* Notation "C ~>>_ T D" := (@epi T C D) *) +(* (at level 99, T at level 0, only parsing) : cat_scope. *) + +(* #[short(type="iso")] *) +(* HB.structure Definition Iso {C : precat} (a b : C) := *) +(* {i of @Mono C a b i & @Epi C a b i}. *) +(* Notation "a <~> b" := (epi a b) *) +(* (at level 99, b at level 200, format "a <~> b") : cat_scope. *) +(* Notation "C <~>_ T D" := (@epi T C D) *) +(* (at level 99, T at level 0, only parsing) : cat_scope. *) + +HB.mixin Record IsRightAdjoint (D C : precat) (R : D -> C) + of @PreFunctor D C R := { + L_ : C ~> D; + phi : forall c d, (L_ c ~> d) -> (c ~> R d); + psy : forall c d, (c ~> R d) -> (L_ c ~> d); + phi_psy c d : (phi c d \o psy c d)%FUN = @id (c ~> R d); + psy_phi c d : (psy c d \o phi c d)%FUN = @id (L_ c ~> d) +}. +#[short(type="right_adjoint")] +HB.structure Definition RightAdjoint (D C : precat) := + { R of @Functor D C R & IsRightAdjoint D C R }. +Arguments L_ {_ _}. +Arguments phi {D C s} {c d}. +Arguments psy {D C s} {c d}. + + +HB.mixin Record PreCat_IsMonoidal C of PreCat C := { + onec : C; + (* prod1 : @hom precat (C * C)%type C ; *) + prod : (C * C)%type ~>_precat C; +}. +#[short(type="premonoidal")] +#[verbose] +HB.structure Definition PreMonoidal := { C of PreCat C & PreCat_IsMonoidal C }. +Notation premonoidal := premonoidal. +Arguments prod {C} : rename. +Notation "a * b" := (prod (a, b)) : cat_scope. +Reserved Notation "f <*> g" (at level 40, g at level 40, format "f <*> g"). +Notation "f <*> g" := (prod^$ (f, g)) (only printing) : cat_scope. +Notation "f <*> g" := (prod^$ ((f, g) : (_, _) ~> (_, _))) + (only parsing) : cat_scope. +Notation "1" := onec : cat_scope. + +Definition hom_cast {C : quiver} {a a' : C} (eqa : a = a') {b b' : C} (eqb : b = b') : + (a ~> b) -> (a' ~> b'). +Proof. now elim: _ / eqa; elim: _ / eqb. Defined. + +HB.mixin Record PreFunctor_IsMonoidal (C D : premonoidal) F of + @PreFunctor C D F := { + fun_one : F 1 = 1; + fun_prod : forall (x y : C), F (x * y) = F x * F y; +}. +#[short(type="monoidal_prefunctor")] +HB.structure Definition MonoidalPreFunctor C D := + { F of @PreFunctor_IsMonoidal C D F }. +Arguments fun_prod {C D F x y} : rename. +(* Arguments fun_prodF {C D F x x'} f {y y'} g : rename. *) +Unset Universe Checking. +HB.instance Definition _ := IsQuiver.Build premonoidal MonoidalPreFunctor.type. +Set Universe Checking. + +HB.instance Definition _ (C : quiver) := + IsPreFunctor.Build (C * C)%type C fst + (fun (a b : C * C) (f : a ~> b) => f.1). +HB.instance Definition _ (C : quiver) := + IsPreFunctor.Build (C * C)%type C snd + (fun (a b : C * C) (f : a ~> b) => f.2). + +Definition prod3l {C : premonoidal} (x : C * C * C) : C := + (x.1.1 * x.1.2) * x.2. +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build _ C prod3l + (fun a b (f : a ~> b) => (f.1.1 <*> f.1.2) <*> f.2). + +Definition prod3r {C : premonoidal} (x : C * C * C) : C := + x.1.1 * (x.1.2 * x.2). +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build _ C prod3r + (fun a b (f : a ~> b) => f.1.1 <*> (f.1.2 <*> f.2)). + +Definition prod1r {C : premonoidal} (x : C) : C := 1 * x. +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build C C prod1r + (fun (a b : C) (f : a ~> b) => \idmap_1 <*> f). + +Definition prod1l {C : premonoidal} (x : C) : C := x * 1. +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build C C prod1l + (fun (a b : C) (f : a ~> b) => f <*> \idmap_1). + +HB.mixin Record PreMonoidal_IsMonoidal C of PreMonoidal C := { + prodA : prod3l ~~> prod3r; + prod1c : prod1r ~~> idfun; + prodc1 : prod1l ~~> idfun; + prodc1c : forall (x y : C), + prodA (x, 1, y) \; \idmap_x <*> prod1c y = prodc1 x <*> \idmap_y; + prodA4 : forall (w x y z : C), + prodA (w * x, y, z) \; prodA (w, x, y * z) = + prodA (w, x, y) <*> \idmap_z \; prodA (w, x * y, z) \; \idmap_w <*> prodA (x, y, z); +}. + +Unset Universe Checking. +#[short(type="monoidal")] +#[verbose] +HB.structure Definition Monoidal : Set := + { C of PreMonoidal_IsMonoidal C & PreMonoidal C }. +Set Universe Checking. + +(******************************************************************) + + +Record cospan (Q : quiver) (A B : Q) := Cospan { + top : Q; + left2top : A ~> top; + right2top : B ~> top +}. + +Section cospans. +Variables (Q : precat) (A B : Q). +Record cospan_map (c c' : cospan A B) := CospanMap { + top_map : top c ~> top c'; + left2top_map : left2top c \; top_map = left2top c'; + right2top_map : right2top c \; top_map = right2top c'; +}. +HB.instance Definition _ := IsQuiver.Build (cospan A B) cospan_map. + +Lemma cospan_mapP (c c' : cospan A B) (f g : c ~> c') : + top_map f = top_map g <-> f = g. +Admitted. +End cospans. + +Section cospans_in_cat. +Variables (Q : cat) (A B : Q). +Definition cospan_idmap (c : cospan A B) := + @CospanMap Q A B c c idmap (compo1 _) (compo1 _). +Program Definition cospan_comp (c1 c2 c3 : cospan A B) + (f12 : c1 ~> c2) (f23 : c2 ~> c3) := + @CospanMap Q A B c1 c3 (top_map f12 \; top_map f23) _ _. +Next Obligation. by rewrite compoA !left2top_map. Qed. +Next Obligation. by rewrite compoA !right2top_map. Qed. +HB.instance Definition _ := IsPreCat.Build (cospan A B) cospan_idmap cospan_comp. + +Lemma cospan_are_cats : PreCat_IsCat (cospan A B). +Proof. +constructor=> [a b f|a b f|a b c d f g h]. +- by apply/cospan_mapP => /=; rewrite comp1o. +- by apply/cospan_mapP => /=; rewrite compo1. +- by apply/cospan_mapP => /=; rewrite compoA. +Qed. +HB.instance Definition _ := cospan_are_cats. +End cospans_in_cat. + +Section spans_and_co. +Variables (Q : quiver) (A B : Q). +Definition span := @cospan Q^op A B. +Definition bot (s : span) : Q := top s. +Definition bot2left (s : span) : bot s ~>_Q A := left2top s. +Definition bot2right (s : span) : bot s ~>_Q B := right2top s. +Definition Span (C : Q) (f : C ~> A) (g : C ~> B) : span := + @Cospan Q^op A B C f g. +End spans_and_co. + +HB.instance Definition _ (Q : precat) (A B : Q) := + Quiver.copy (span A B) (@cospan Q^op A B)^op. +HB.instance Definition _ (Q : cat) (A B : Q) := + Cat.copy (span A B) (@cospan Q^op A B)^op. + +Section bot_map. +Variables (C : cat) (A B : C) (s s' : span A B) (f : s ~> s'). +Definition bot_map : bot s ~> bot s' := top_map f. +Lemma bot2left_map : bot_map \; bot2left s' = bot2left s. +Proof. exact: left2top_map f. Qed. +Lemma bot2right_map : bot_map \; bot2right s' = bot2right s. +Proof. exact: right2top_map f. Qed. +End bot_map. + +HB.mixin Record isPrePullback (Q : precat) (A B : Q) + (c : cospan A B) (s : span A B) := { + is_square : bot2left s \; left2top c = bot2right s \; right2top c; +}. +#[short(type=prepullback)] +HB.structure Definition PrePullback Q A B (c : cospan A B) := + {s of isPrePullback Q A B c s}. +Arguments prepullback {Q A B} c. + +Section prepullback. +Variables (Q : precat) (A B : Q) (c : cospan A B). +HB.instance Definition _ := + IsQuiver.Build (prepullback c) + (fun a b => (a : span A B) ~>_(span A B) (b : span A B)). +Lemma eq_prepullbackP (p q : prepullback c) : + p = q :> span _ _ <-> p = q. +Admitted. +End prepullback. +Section prepullback. +Variables (Q : cat) (A B : Q) (csp : cospan A B). +(* TODO: why can't we do that? *) +(* HB.instance Definition _ := Cat.on (prepullback csp). *) +HB.instance Definition _ := + Quiver_IsPreCat.Build (prepullback csp) + (fun a => \idmap_(a : span A B)) + (* TODO: study how to make this coercion trigger + even when the target is not reduced to span *) + (fun a b c f g => f \; g). +Lemma prepullback_is_cat : PreCat_IsCat (prepullback csp). +Proof. (* should be copied from the cat on span *) +constructor=> [a b f|a b f|a b c d f g h]; + [exact: comp1o|exact: compo1|exact: compoA]. +Qed. +End prepullback. + +HB.tag Definition pb_terminal (Q : precat) + (A B : Q) (c : cospan A B) (s : prepullback c) : + obj (prepullback c) := s. + +#[wrapper] +HB.mixin Record prepullback_isTerminal (Q : precat) + (A B : Q) (c : cospan A B) + (s : span A B) of isPrePullback Q A B c s := { + prepullback_terminal : + IsTerminal (prepullback c) (pb_terminal s) +}. +#[short(type="pullback"), verbose] +HB.structure Definition Pullback (Q : precat) + (A B : Q) (c : cospan A B) := + {s of isPrePullback Q A B c s + & IsTerminal (prepullback c) (pb_terminal s) }. + +Notation pbsquare u v f g := + (Pullback _ (Cospan f g) (Span u v)). + +Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). + +(********************************************************************) +(********************************************************************) + +(*** CATEGORIES WITH PULLBACKS *) + +(* category with all prepullbacks *) +(* Ideally span is in fact expanded and the final mixin has +a pb : forall A B, cospan A B -> C +but it is not clear how to do that yet +*) +HB.mixin Record HasPBop C of Cat C := { + pb : forall (A B: C), cospan A B -> span A B + }. +#[short(type="pbop")] +HB.structure Definition PBop := + {C of HasPBop C & PreCat C }. + +(* category with all pullbacks *) +(* Wrong: we don't wrap classes, only mixins *) +#[wrapper] +HB.mixin Record HasPreBCat C of PBop C : Type := { + is_pb : forall (a b : C) (c : cospan a b), isPrePullback C a b c (@pb C a b c) + }. +#[short(type="pbcat")] +HB.structure Definition PreBCat := + {C of HasPreBCat C}. + +#[wrapper] +HB.mixin Record HasPBCat C of PBop C & HasPreBCat C : Type := { + is_pb : forall (a b : C) (c : cospan a b), + prepullback_isTerminal C a b c (@pb C a b c) + }. +#[short(type="pbcat")] +HB.structure Definition PBCat := + {C of HasPBCat C}. + + +(********************************************************************) + +(*** INTERNAL CATEGORIES *) +(* based on the NLab definition at + https://ncatlab.org/nlab/show/internal+category +*) + +(* category extended with internal objects *) +HB.mixin Record HasIObjects C of Cat C := { + Obj : C ; + Mor : C +}. +HB.structure Definition IObjects := + { C of HasIObjects C }. + +(* operators (meant to abstract over pullbacks and pushouts*) +HB.mixin Record HasPOps C of IObjects C := { + prd : C -> C -> C ; + prj1 : forall c1 c2, prd c1 c2 ~> c1 ; + prj2 : forall c1 c2, prd c1 c2 ~> c2 ; + mprd : forall c1 c2 c3 c4, + (c1 ~> c3) -> (c2 ~> c4) -> prd c1 c2 ~> prd c3 c4 ; + mjn : forall c1 c2 c3, + (c1 ~> c2) -> (c1 ~> c3) -> c1 ~> prd c2 c3 +}. +HB.structure Definition POps := + { C of HasPOps C }. + +(* category extended with internal morphisms *) +HB.mixin Record IsIQuiver C of POps C := { + iid : Obj ~>_C Mor ; + isrc : Mor ~>_C Obj ; + itrg : Mor ~>_C Obj ; + icmp : @prd C Mor Mor ~> Mor +}. +HB.structure Definition IQuiver := + { C of IsIQuiver C }. + +Notation idO C := (@idmap C Obj). +Notation idM C := (@idmap C Mor). +Notation prdMM := (prd Mor Mor). +Notation prdPM := (prd (prd Mor Mor) Mor). +Notation prjMM1 := (prj1 Mor Mor). +Notation prjMM2 := (prj2 Mor Mor). +Notation prjOM1 := (prj1 Obj Mor). +Notation prjOM2 := (prj2 Obj Mor). +Notation prjMO1 := (prj1 Mor Obj). +Notation prjMO2 := (prj2 Mor Obj). +Notation prjPM1 := (prj1 (prd Mor Mor) Mor). +Notation prjPM2 := (prj2 (prd Mor Mor) Mor). +Notation prjPM1_ C := (@prj1 C (prd Mor Mor) Mor). +Notation prjPM2_ C := (@prj2 C (prd Mor Mor) Mor). +Notation prjMP1 := (prj1 Mor (prd Mor Mor)). +Notation prjMP2 := (prj2 Mor (prd Mor Mor)). +Notation mprdOMMM := (mprd Obj Mor Mor Mor). +Notation mprdMOMM := (mprd Mor Obj Mor Mor). +Notation mprdPMMM := (mprd (prd Mor Mor) Mor Mor Mor). +Notation mprdMPMM := (mprd Mor (prd Mor Mor) Mor Mor). + +(* internal quiver extended with the required pullback properties *) +HB.mixin Record IsIPreCat C of IQuiver C := { + pbkMM : prjMM2 \; @isrc C = prjMM1 \; itrg ; + pbkPMcmp : prjPM2 \; @isrc C = prjPM1 \; icmp \; itrg ; + pbkMPcmp : prjMP2 \; @icmp C \; isrc = prjMP1 \; itrg ; + pbkPM : prjPM2 \; @isrc C = prjPM1 \; prjMM2 \; itrg ; + pbkMP : prjMP2 \; prjMM1 \; @isrc C = prjMP1 \; itrg ; + pbkPM2MM1 : prjPM1_ C \; prjMM2 = + mjn prdPM Mor Mor (prjPM1 \; prjMM2) prjPM2 \; prjMM1 ; + pbkPM2MM2 : prjPM2_ C = + mjn prdPM Mor Mor (prjPM1 \; prjMM2) prjPM2 \; prjMM2 ; + pbkPM2MP1 : prjPM1_ C \; prjMM1 = + mjn prdPM Mor prdMM (prjPM1 \; prjMM1) + (mjn prdPM Mor Mor (prjPM1 \; prjMM2) prjPM2) \; prjMP1 ; + pbkPM2MP2 : mjn prdPM Mor Mor (prjPM1_ C \; prjMM2) prjPM2 = + mjn prdPM Mor prdMM (prjPM1 \; prjMM1) + (mjn prdPM Mor Mor (prjPM1 \; prjMM2) prjPM2) \; prjMP2 ; +}. +HB.structure Definition IPreCat := + { C of IsIPreCat C }. + +(* definition of internal category *) +HB.mixin Record IsICat C of IPreCat C := { + iid_s : iid \; isrc = idO C ; + iid_t : iid \; itrg = idO C ; + icmp_s : @icmp C \; isrc = prjMM1 \; isrc ; + icmp_t : @icmp C \; itrg = prjMM2 \; itrg ; + unit_l : mprdOMMM iid (idM C) \; icmp = prjOM2 ; + unit_r : mprdMOMM (idM C) iid \; icmp = prjMO1 ; + assoc : mprdPMMM icmp (idM C) \; icmp = + mjn prdPM Mor prdMM (prjPM1 \; prjMM1) + (mjn prdPM Mor Mor (prjPM1 \; prjMM2) prjPM2) \; + mprdMPMM (idM C) icmp \; icmp +}. +HB.structure Definition ICat := + { C of IsICat C }. +(* +HB.mixin Record IsICat C of IQuiver C := { + iid_s : iid \; isrc = @idmap C Obj ; + iid_t : iid \; itrg = @idmap C Obj ; + icmp_s : @icmp C \; isrc = prj1 Mor Mor \; isrc ; + icmp_t : @icmp C \; itrg = prj2 Mor Mor \; itrg ; + unit_l : mprd Obj Mor Mor Mor iid (@idmap C Mor) \; icmp = + prj2 Obj Mor ; + unit_r : mprd Mor Obj Mor Mor (@idmap C Mor) iid \; icmp = + prj1 Mor Obj ; + assoc : mprd (prd Mor Mor) Mor Mor Mor icmp (@idmap C Mor) + \; icmp = + (mjn (prd (prd Mor Mor) Mor) Mor (prd Mor Mor) + (prj1 (prd Mor Mor) Mor \; prj1 Mor Mor) + (mjn (prd (prd Mor Mor) Mor) Mor Mor + (prj1 (prd Mor Mor) Mor \; prj2 Mor Mor) + (prj2 (prd Mor Mor) Mor))) \; + (mprd Mor (prd Mor Mor) Mor Mor (@idmap C Mor) icmp) + \; icmp +}. +*) + +(********************************************************************) + +(*** GENERALISED ENRICHED CATEGORIES *) + +Declare Scope encat_scope. +Delimit Scope encat_scope with encat. +Local Open Scope encat_scope. + +(* Enrichment in a monoidal category, following + https://ncatlab.org/nlab/show/enriched+category +*) +HB.mixin Record IsEnQuiver (V: Type) C := { + hom_object : C -> C -> V + }. +Unset Universe Checking. +HB.structure Definition EnQuiver (V: Type) : Set := + { C of IsEnQuiver V C }. +Set Universe Checking. + +(* Monoidal precategory with the enrichment operators (no axioms) *) +HB.mixin Record IsEnPreCat (V: PreMonoidal.type) C of + EnQuiver (PreMonoidal.sort V) C := { + id_element : forall (a: C), + @hom V onec (hom_object a a) ; + comp_morphism : forall (a b c: C), + @hom V (@hom_object V C b c * @hom_object V C a b) + (@hom_object V C a c) +}. +Unset Universe Checking. +HB.structure Definition EnPreCat (V: PreMonoidal.type) : Set := + { C of IsEnPreCat V C }. +Set Universe Checking. + +Notation "a ~^ b" := (hom_object a b) + (at level 99, b at level 200, format "a ~^ b") : encat_scope. +Notation "a ~^_ ( V , C ) b" := (@hom_object V C a b) + (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. +Notation "~^IE a" := (id_element a) + (at level 99, format "~^IE a") : cat_scope. +Notation "~^IE_ ( V , C ) a" := (@id_element V C a) + (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. +(* not working *) +Notation "~^CM a b c" := (comp_morphism a b c) + (at level 99, + format "~^CM a b c") : cat_scope. +Notation "~^CM_ ( V , C ) a b c" := (@comp_morphism V C a b c) + (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. + +(* V-enriched category: + V is the monoidal category; + C is the base category that gets enriched +*) +HB.mixin Record IsEnCat (V: Monoidal.type) C of EnPreCat V C := { + ecat_comp_assoc : forall a b c d: C, + forall alpha: + (((c ~^_(V,C) d) * (b ~^_(V,C) c)) * (a ~^_(V,C) b)) ~>_V + ((c ~^_(V,C) d) * ((b ~^_(V,C) c) * (a ~^_(V,C) b))), + ((@comp_morphism V C b c d) <*> (@idmap V (a ~^_(V,C) b))) \; + (@comp_morphism V C a b d) + = + alpha \; + ((@idmap V (c ~^_(V,C) d)) <*> (@comp_morphism V C a b c)) \; + (@comp_morphism V C a c d) ; + + ecat_comp_left_unital : forall a b: C, + forall l: onec * (a ~^_(V,C) b) ~>_V (a ~^_(V,C) b), + l = ((@id_element V C b) <*> (@idmap V (a ~^_(V,C) b))) \; + (@comp_morphism V C a b b) ; + ecat_comp_right_unital : forall a b: C, + forall r: (a ~^_(V,C) b) * onec ~>_V (a ~^_(V,C) b), + r = ((@idmap V (a ~^_(V,C) b)) <*> (@id_element V C a)) \; + (@comp_morphism V C a a b) +}. +Unset Universe Checking. +#[verbose] +HB.structure Definition EnCat (V: Monoidal.type) : Set := + { C of IsEnCat V C }. +Set Universe Checking. + +(********************************************************************) + +(*** DOUBLE CATEGORIES (without internal categories) *) + +(* Strict double categories, from + https://ncatlab.org/nlab/show/double+category + (we don't use internal categories) + + base obejcts as 0-cells: C ; + + vertical 1-morphisms (category D0 on C): hom C ; + + horizontal 1-morphisms (category H on C): hom (transpose C) ; + + horizontal 1-morhisms as 1-cells for D1: D1obj C ; + + 2-morphisms (category D1 on C1obj): hom (D1obj C) ; + + horizontally composable pairs of 1-cells : DPobj C ; + + horizontally composable pairs of 2-morphisms + (product category DP, D1 *0 D1) : hom (DPobj C) ; + + The definition of Strict Double Category, SDouble = (D0, H, D1, Dp), + is given by: + + - base objects C + + - (level-1) category (D0) of vertical 1-morphism on C + + - (level-1) category (H) of horizontal 1-morphism (D1obj) on C + + - (level-2) category (D1) of vertical 2-morphism on D1obj + + - (derived) category (DP) of vertical 2-morphisms on + horizontally D0-composable D1 products + ($\mbox{D1} *_0 \mbox{D1}$) + + - Source functor: $\mbox{D1} \to \mbox{D0}$ + + - Target functor: $\mbox{D1} \to \mbox{D0}$ + + - Horizontal unit functor: $\mbox{D0} \to \mbox{D1}$ + + - Horizontal composition functor: $\mbox{DP} \to \mbox{D1}$ +*) + + +(** Quivers for double categories *) + +(* transpose for horizontal morphism quiver. + HB.tag needed to identify transpose as lifter *) +HB.tag Definition transpose (C : quiver) : U := C. +#[wrapper] HB.mixin Record _IsHQuiver C of IsQuiver C := { + is_hquiver : IsQuiver (transpose C) +}. +(* vertical and horizontal quivers, defining cells *) +Unset Universe Checking. +#[short(type="vhquiver")] +HB.structure Definition VHQuiver : Set := + { C of IsQuiver C & IsQuiver (transpose C) }. +Set Universe Checking. + +HB.tag Definition hhom (c : VHQuiver.type) : c -> c -> U := @hom (transpose c). +Notation "a +> b" := (hhom a b) + (at level 99, b at level 200, format "a +> b") : cat_scope. + +(* record to represent the set of morphims + (needed for 2-objects, i.e. horizontal morphisms) *) +Record Total2 T (h: T -> T -> U) : Type := TT2 { + source : T; + target : T; + this_morph : h source target }. + +(* the set of horizontal morphisms. *) +HB.tag Definition D1obj (C: vhquiver) := Total2 (@hhom C). + +(* D1 quiver requirement (includes D0 quiver and its transpose). *) +#[wrapper] +HB.mixin Record _IsDQuiver T of VHQuiver T := + { is_dquiver : Quiver (D1obj T) }. +Unset Universe Checking. +#[short(type="dquiver")] +HB.structure Definition DQuiver : Set := { C of Quiver (D1obj C) }. +Set Universe Checking. + + +(** Horizonal D0-level category (H-D0) *) + +(* Precategory based on the HQuiver (i.e. horizontal precategory on D0 + objects) *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record _IsHPreCat T of VHQuiver T := { + is_hprecat : Quiver_IsPreCat (transpose T) }. +#[short(type="hprecat")] +HB.structure Definition HPreCat : Set := + { C of Quiver_IsPreCat (transpose C) }. +Set Universe Checking. + +(* The category based on the HQuiver (i.e. horizontal category on D0 + objects) *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record _IsHCat T of HPreCat T := { + is_hcat : PreCat_IsCat (transpose T) }. +#[short(type="hcat")] +HB.structure Definition HCat : Set := + { C of PreCat_IsCat (transpose C) }. +Set Universe Checking. + + +(** Vertical 2-cell level category (D1 category) *) + +(* Precategory based on the DQuiver (i.e. precategory D1). Gives: + vertical 2-cell identity morphism. + vertical 2-cell composition. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record _IsD1PreCat T of DQuiver T := { + is_d1precat : Quiver_IsPreCat (@D1obj T) }. +#[short(type="d1precat")] +HB.structure Definition D1PreCat : Set := + { C of Quiver_IsPreCat (@D1obj C) }. +Set Universe Checking. + +(* The category based on the DQuiver (i.e. category D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record _IsD1Cat T of D1PreCat T := { + is_d1cat : PreCat_IsCat (@D1obj T) }. +#[short(type="d1cat")] +HB.structure Definition D1Cat : Set := + { C of PreCat_IsCat (@D1obj C) }. +Set Universe Checking. + + +(** Naked double category *) + +(* Naked double category. Vertical (V-D0) and D1 categories. Double + category without horizontal operators and functors *) +Unset Universe Checking. +#[short(type="dcat")] +HB.structure Definition DCat : Set := + { C of Cat C & D1Cat C }. +Set Universe Checking. + +(* Naked strict double category. Vertical (V-D0), horizontal (H-D0) + and D1 categories. Strict double category without functors *) +Unset Universe Checking. +#[short(type="sd2cat")] +HB.structure Definition SDCat : Set := { C of Cat C & HCat C & D1Cat C }. +Set Universe Checking. + + +(** Auxiliary notions for Source, Target and + Horizontal Unit functors *) + +(* homsets of 2-cell (D1) morphisms *) +Definition d1hom (D: DQuiver.type) : D1obj D -> D1obj D -> U := + @hom (D1obj D). +(* type-level smart constructor for D1 homsets *) +Definition D1hom (D: DQuiver.type) (a b c d: D) (h0: hhom a b) + (h1: hhom c d) : U := d1hom (TT2 h0) (TT2 h1). + +(* smart projections for: + source functor (for horizontal morphisms): D1 -> D0. + defined as object-level function, by functoriality lifted to a + (2-cell, vertical) morphism-level one *) +HB.tag Definition HSource C := fun (X: D1obj C) => @source C (@hhom C) X. +(* target functor (for horizontal morphisms): D1 -> D0. *) +HB.tag Definition HTarget C := fun (X: D1obj C) => @target C (@hhom C) X. + +(* horizontal unit functor: D0 -> D1 *) +Definition hhunit (T: hprecat) (a: T) : D1obj T := + @TT2 T (@hhom T) a a (@idmap (transpose T) a). +HB.tag Definition H1Unit (C: hprecat) := + fun (x: HPreCat.sort C) => @hhunit C x. + + +(** Auxiliary notions for 2-cell Horizontal Composition functor *) + +(* composable pairs of morphisms as a set *) +Record GenComp T (h: T -> T -> U) := GC { + h_one : T; + h_two : T ; + h_three : T; + h_first : h h_one h_two ; + h_second : h h_two h_three }. + +(* composable pairs of horizontal morphisms as a set *) +HB.tag Definition DPobj (C: vhquiver) := GenComp (@hhom C). + +(* smart projections *) +Definition H2First (C: vhquiver) (X: @DPobj C) : D1obj C := + @TT2 C _ (h_one X) (h_two X) (h_first X). +Definition H2Second (C: vhquiver) (X: @DPobj C) : D1obj C := + @TT2 C _ (h_two X) (h_three X) (h_second X). + + +(* horizontal composition functor: D1 * D1 -> D1 *) +Definition hhcomp (T: hprecat) (x: DPobj T) : D1obj T := + match x with + @GC _ _ a b c h1 h2 => @TT2 T (@hhom T) a c (h1 \; h2) end. +HB.tag Definition H1Comp (C: hprecat) := + fun (x: DPobj C) => @hhcomp C x. + +(* hhunit - horizontal unit functor. + + hhcomp - horizontal composition functor (horizontal composition of + two horizontal morphisms from a cell product). + + Both specified as object-level functions (they actually come for + free from the H-D0 category, since we are in the strict case), to + be lifted by functoriality to morphism-level ones. + + At the object level, hhunit gives a horizontal identity morphism + for each D0 object. At the morphism level, it gives horizontal + 2-cell identity for each vertical morphism. + + In the case of hhcomp, relying on functoriality requires some care + in defining the product category, making sure that adjacency at the + object-level (between horizontal morphisms) is matched by adjacency + at the morphism-level (between 2-cells). *) + + +(** Source and target functors *) + +(* source prefunctor. + D1obj T is the quiver of the 2-morphisms, thanks to VHQuiver. + T is the quiver of 1-morphisms. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsSPreFunctor T of DCat T := { + is_sprefunctor : IsPreFunctor (D1obj T) T (@HSource T) }. +HB.structure Definition SPreFunctor : Set := {C of IsSPreFunctor C}. +Set Universe Checking. + +(* target prefunctor. *) +Unset Universe Checking. +#[wrapper] + HB.mixin Record IsTPreFunctor T of DCat T := { + is_tprefunctor : IsPreFunctor (D1obj T) T (@HTarget T) }. +HB.structure Definition TPreFunctor : Set := {C of IsTPreFunctor C}. +Set Universe Checking. + +(* source functor. *) +Unset Universe Checking. +#[wrapper] + HB.mixin Record SPreFunctor_IsFunctor T of SPreFunctor T := { + is_sfunctor : PreFunctor_IsFunctor (D1obj T) T (@HSource T) }. +HB.structure Definition SFunctor : Set := {C of SPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* target functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record TPreFunctor_IsFunctor T of TPreFunctor T := { + is_tfunctor : PreFunctor_IsFunctor (D1obj T) T (@HTarget T) }. +HB.structure Definition TFunctor : Set := {C of TPreFunctor_IsFunctor C}. +Set Universe Checking. + + +(** Unit functor *) + +(* unit prefunctor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsUPreFunctor T of SDCat T := + { is_uprefunctor : IsPreFunctor T (D1obj T) (@H1Unit T) }. +HB.structure Definition UPreFunctor : Set := {C of IsUPreFunctor C}. +Set Universe Checking. + +(* unit functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record UPreFunctor_IsFunctor T of UPreFunctor T := { + is_ufunctor : PreFunctor_IsFunctor T (D1obj T) (@H1Unit T) }. +HB.structure Definition UFunctor : Set := {C of UPreFunctor_IsFunctor C}. +Set Universe Checking. + +Unset Universe Checking. +HB.about Functor. +HB.structure Definition STUFunctor : Set := + {C of SFunctor C & TFunctor C & UFunctor C}. +Set Universe Checking. + + +(** Lifting of Source, Target and Unit functors to D1 morphisms *) + +(* 2-cell source *) +Definition H1Source (T: SFunctor.type) (a b: @D1obj T) + (m: @d1hom T a b) : + (HSource a) ~> (HSource b) := (@HSource T) <$> m. + +(* 2-cell target *) +Definition H1Target (T: TFunctor.type) (a b: @D1obj T) + (m: @d1hom T a b) : + (HTarget a) ~> (HTarget b) := (@HTarget T) <$> m. + +(* horizontal 2-cell unit (maps vertical morphisms to horizontally + unitary 2-cells) *) +Definition H2Unit (T: UFunctor.type) (a b: T) (m: @hom T a b) : + (H1Unit a) ~> (H1Unit b) := (@H1Unit T) <$> m. + + +(** Horizontal product category (D1 *d0 D1) *) +(* DPobj T is the pseudo-pullback category used to deal with + products of D1 (where the adjacency condition is expressed + w.r.t. D0 *) + +(* horizontal composition of two (naked) horizontal morphisms *) +Definition l_hcomp (T: SDCat.type) (a0 a1 a2: T) + (h0: hhom a0 a1) (h1: hhom a1 a2) : D1obj T := + @TT2 T _ a0 a2 (h0 \; h1). + +Notation "'sigma' x .. y , p" := + (sigT (fun x => .. (sigT (fun y => p)) ..)) + (at level 200, x binder, right associativity, + format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") + : type_scope. + +(** DPobj quiver *) +Definition DP_hom (T: STUFunctor.type) (x y: DPobj T) := + sigma (hh0: D1hom (h_first x) (h_first y)) + (hh1: D1hom (h_second x) (h_second y)), + H1Target hh0 = H1Source hh1. + +HB.instance Definition DPQuiver (T: STUFunctor.type) : + IsQuiver (DPobj T) := + IsQuiver.Build (DPobj T) (fun A B => @DP_hom T A B). + + +(** Product precategory *) + +Lemma DP_id_eq (T : STUFunctor.type) (a: DPobj T) : + H1Target (@idmap (@D1obj T) (H2First a)) = + H1Source (@idmap (@D1obj T) (H2Second a)). +unfold H1Target, HTarget. +unfold H1Source, HSource. +repeat rewrite F1; auto. +Defined. + +(* DPobj identity *) +Definition DP_id (T: STUFunctor.type) (A: DPobj T) : A ~> A := + let h0 := h_first A + in let h1 := h_second A + in let uu0 := @idmap (D1obj T) (TT2 h0) + in let uu1 := @idmap (D1obj T) (TT2 h1) + in @existT (D1hom h0 h0) + (fun hh0: (D1hom h0 h0) => + sigma (hh1 : D1hom h1 h1), H1Target hh0 = H1Source hh1) uu0 + (@existT (D1hom h1 h1) + (fun hh1: (D1hom h1 h1) => H1Target uu0 = H1Source hh1) uu1 + (@DP_id_eq T A)). + +Definition DP_comp_auxA (T : STUFunctor.type) + (A B C : DPobj T) + (hhA0 : D1hom (h_first A) (h_first B)) + (hhA1 : D1hom (h_second A) (h_second B)) + (ppA : H1Target hhA0 = H1Source hhA1) + (hhB0 : D1hom (h_first B) (h_first C)) + (hhB1 : D1hom (h_second B) (h_second C)) + (ppB : H1Target hhB0 = H1Source hhB1) : + (H1Target hhA0) \; (H1Target hhB0) = + (H1Source hhA1) \; (H1Source hhB1). + rewrite ppA. + rewrite ppB. + reflexivity. +Defined. + +Definition DP_comp_auxS (T : STUFunctor.type) + (A B C : DPobj T) + (hhA0 : D1hom (h_first A) (h_first B)) + (hhA1 : D1hom (h_second A) (h_second B)) + (ppA : H1Target hhA0 = H1Source hhA1) + (hhB0 : D1hom (h_first B) (h_first C)) + (hhB1 : D1hom (h_second B) (h_second C)) + (ppB : H1Target hhB0 = H1Source hhB1) : + H1Source (hhA1 \; hhB1) = (H1Source hhA1) \; (H1Source hhB1). + unfold H1Source, HSource. + repeat rewrite Fcomp. + reflexivity. +Defined. + +Definition DP_comp_auxT (T : STUFunctor.type) + (A B C : DPobj T) + (hhA0 : D1hom (h_first A) (h_first B)) + (hhA1 : D1hom (h_second A) (h_second B)) + (ppA : H1Target hhA0 = H1Source hhA1) + (hhB0 : D1hom (h_first B) (h_first C)) + (hhB1 : D1hom (h_second B) (h_second C)) + (ppB : H1Target hhB0 = H1Source hhB1) : + H1Target (hhA0 \; hhB0) = (H1Target hhA0) \; (H1Target hhB0). + unfold H1Target, HTarget. + repeat rewrite Fcomp. + reflexivity. +Defined. + +Definition DP_comp_auxI (T : STUFunctor.type) + (A B C : DPobj T) + (hhA0 : D1hom (h_first A) (h_first B)) + (hhA1 : D1hom (h_second A) (h_second B)) + (ppA : H1Target hhA0 = H1Source hhA1) + (hhB0 : D1hom (h_first B) (h_first C)) + (hhB1 : D1hom (h_second B) (h_second C)) + (ppB : H1Target hhB0 = H1Source hhB1) : + A ~> C. + econstructor 1 with (comp hhA0 hhB0). + econstructor 1 with (comp hhA1 hhB1). + setoid_rewrite DP_comp_auxS; eauto. + setoid_rewrite DP_comp_auxT; eauto. + eapply DP_comp_auxA; eauto. +Defined. + +(* DPobj composition, defined in proof mode *) +Definition DP_comp (T: STUFunctor.type) (A B C: DPobj T) : + (A ~> B) -> (B ~> C) -> A ~> C. + intros chA chB. + destruct chA as [hhA0 [hhA1 ppA]]. + destruct chB as [hhB0 [hhB1 ppB]]. + eapply DP_comp_auxI; eauto. +Defined. + +(* DPobj is a precategory *) +HB.instance Definition DPPreCat (T: STUFunctor.type) : + Quiver_IsPreCat (DPobj T) := + Quiver_IsPreCat.Build (DPobj T) (@DP_id T) (@DP_comp T). + +(* + have HcompP : + (a b : DPobj T) + (f g : a ~> b), + proj1T f = proj1t f -> + + -> + f = g. + + exists a b p, + fst f = a + f = (a,b,p) +*) + +(** Product category *) + +Lemma DP_LeftUnit_lemma (T : STUFunctor.type) : + forall (a b : DPobj T) (f : a ~> b), idmap \; f = f. + + move => a b [x [x0 e]] /=. + simpl in *. + unfold idmap; simpl. + unfold DP_id; simpl. + unfold comp; simpl. + unfold DP_comp_auxI; simpl. + + assert (idmap \; x = x) as A. + { rewrite comp1o; auto. } + + assert (idmap \; x0 = x0) as A0. + { rewrite comp1o; auto. } + + assert (H1Target (idmap \; x) = H1Source (idmap \; x0)) as B. + { rewrite A. + rewrite A0; auto. } + + destruct a eqn: aaa. + destruct b eqn: bbb. + simpl. + + assert (existT + (fun hh0 : D1hom h_first0 h_first1 => + sigma hh1 : D1hom h_second0 h_second1,H1Target hh0 = H1Source hh1) + (idmap \; x) + (existT + (fun hh1 : D1hom h_second0 h_second1 => + H1Target (idmap \; x) = H1Source hh1) + (idmap \; x0) + B) = + existT + (fun hh0 : D1hom h_first0 h_first1 => + sigma hh1 : D1hom h_second0 h_second1,H1Target hh0 = H1Source hh1) + x + (existT + (fun hh1 : D1hom h_second0 h_second1 => H1Target x = H1Source hh1) + x0 + e)) as C. + { revert B. + revert A. + revert A0. + generalize (idmap \; x) as v. + generalize (idmap \; x0) as v0. + intros v0 v A0. + rewrite A0. + intro A. + rewrite A. + intro B. + + assert (B = e) as BE. + { eapply Prop_irrelevance. } + + rewrite BE. + reflexivity. +} + + inversion aaa; subst. + rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] + (Prop_irrelevance _ B). + eapply C. +Qed. + +Lemma DP_RightUnit_lemma (T : STUFunctor.type) : + forall (a b : DPobj T) (f : a ~> b), f \; idmap = f. + + move => a b [x [x0 e]] /=. + simpl in *. + unfold idmap; simpl. + unfold DP_id; simpl. + unfold comp; simpl. + unfold DP_comp_auxI; simpl. + + assert (x \; idmap = x) as A. + { rewrite compo1; auto. } + + assert (x0 \; idmap = x0) as A0. + { rewrite compo1; auto. } + + assert (H1Target (x \; idmap) = H1Source (x0 \; idmap)) as B. + { rewrite A. + rewrite A0; auto. } + + destruct a eqn: aaa. + destruct b eqn: bbb. + simpl. + + assert (existT + (fun hh0 : D1hom h_first0 h_first1 => + sigma hh1 : D1hom h_second0 h_second1, + H1Target hh0 = H1Source hh1) + (x \; idmap) + (existT + (fun hh1 : D1hom h_second0 h_second1 => + H1Target (x \; idmap) = H1Source hh1) + (x0 \; idmap) + B) = + existT + (fun hh0 : D1hom h_first0 h_first1 => + sigma hh1 : D1hom h_second0 h_second1, + H1Target hh0 = H1Source hh1) + x + (existT + (fun hh1 : D1hom h_second0 h_second1 => + H1Target x = H1Source hh1) + x0 + e)) as C. + { revert B. + revert A. + revert A0. + generalize (x \; idmap) as v. + generalize (x0 \; idmap) as v0. + intros v0 v A0. + rewrite A0. + intro A. + rewrite A. + intro B. + + assert (B = e) as BE. + { eapply Prop_irrelevance. } + + rewrite BE. + reflexivity. + } + + inversion aaa; subst. + rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] + (Prop_irrelevance _ B). + eapply C. +Qed. + +Lemma DP_Assoc_lemma (T : STUFunctor.type) : + forall (a b c d : DPobj T) (f : a ~> b) (g : b ~> c) (h : c ~> d), + f \; g \; h = (f \; g) \; h. + intros. + remember f as f1. + remember g as g1. + remember h as h1. + destruct f as [x0 s0]. + destruct g as [x1 s1]. + destruct h as [x2 s2]. + destruct s0 as [y0 e0]. + destruct s1 as [y1 e1]. + destruct s2 as [y2 e2]. + simpl. + + set (x01 := comp x0 x1). + set (x12 := comp x1 x2). + set (x0_12 := comp x0 x12). + set (x01_2 := comp x01 x2). + set (y01 := comp y0 y1). + set (y12 := comp y1 y2). + set (y0_12 := comp y0 y12). + set (y01_2 := comp y01 y2). + + assert (x0_12 = x01_2) as X0. + { subst x0_12 x01_2. + rewrite compoA; eauto. } + assert (y0_12 = y01_2) as Y0. + { subst y0_12 y01_2. + rewrite compoA; eauto. } + + set (x01_t := comp (H1Target x0) (H1Target x1)). + set (x01_2_t := comp x01_t (H1Target x2)). + set (x12_t := comp (H1Target x1) (H1Target x2)). + set (x0_12_t := comp (H1Target x0) x12_t). + set (y01_s := comp (H1Source y0) (H1Source y1)). + set (y01_2_s := comp y01_s (H1Source y2)). + set (y12_s := comp (H1Source y1) (H1Source y2)). + set (y0_12_s := comp (H1Source y0) y12_s). + + assert (x01_t = y01_s) as E01. + { subst x01_t y01_s. + rewrite e0. + rewrite e1; auto. } + assert (x01_2_t = y01_2_s) as E01_2. + { subst x01_2_t y01_2_s. + rewrite E01. + rewrite e2; auto. } + assert (x12_t = y12_s) as E12. + { subst x12_t y12_s. + rewrite e1. + rewrite e2; auto. } + assert (x0_12_t = y0_12_s) as E0_12. + { subst x0_12_t y0_12_s. + rewrite E12. + rewrite e0; auto. } + + assert (x0_12_t = x01_2_t) as E02T. + { subst x0_12_t x01_2_t. + subst x12_t x01_t. + rewrite compoA; auto. } + assert (y0_12_s = y01_2_s) as E02S. + { subst y0_12_s y01_2_s. + subst y12_s y01_s. + rewrite compoA; auto. } + + unfold comp. + simpl. + unfold DP_comp. + simpl. + inversion Heqf1; subst. + clear H. + + unfold DP_comp_auxI; simpl. + + assert (H1Target (x0 \; x1 \; x2) = + H1Source (y0 \; y1 \; y2)) as KR. + { subst x0_12_t y0_12_s. + subst x12_t y12_s. + unfold H1Target. + repeat rewrite Fcomp; simpl. + unfold H1Target in E0_12. + rewrite E0_12. + unfold H1Source. + repeat rewrite Fcomp; simpl. + auto. + } + + assert (H1Target ((x0 \; x1) \; x2) = + H1Source ((y0 \; y1) \; y2)) as KL. + { subst x01_2_t y01_2_s. + subst x01_t y01_s. + unfold H1Target. + repeat rewrite Fcomp; simpl. + unfold H1Target in E01_2. + rewrite E01_2. + unfold H1Source. + repeat rewrite Fcomp; simpl. + auto. + } + + assert (existT + (fun hh0 : D1hom (h_first a) (h_first d) => + sigma hh1 : D1hom (h_second a) (h_second d), + H1Target hh0 = H1Source hh1) + (x0 \; x1 \; x2) + (existT + (fun hh1 : D1hom (h_second a) (h_second d) => + H1Target (x0 \; x1 \; x2) = H1Source hh1) + (y0 \; y1 \; y2) + KR) + = + existT + (fun hh0 : D1hom (h_first a) (h_first d) => + sigma hh1 : D1hom (h_second a) (h_second d), + H1Target hh0 = H1Source hh1) + ((x0 \; x1) \; x2) + (existT + (fun hh1 : D1hom (h_second a) (h_second d) => + H1Target ((x0 \; x1) \; x2) = H1Source hh1) + ((y0 \; y1) \; y2) + KL)) as KA. + { revert KL. + revert KR. + subst x0_12 x01_2 x12 x01. + subst y0_12 y01_2 y12 y01. + rewrite <- X0. + rewrite <- Y0. + intros KR KL. + + assert (KR = KL) as I1. + { eapply Prop_irrelevance. } + rewrite I1. + reflexivity. + } + + rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] + (Prop_irrelevance _ KR). + + rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] + (Prop_irrelevance _ KL). + eapply KA. +Qed. + +Program Definition DPCatP (T: STUFunctor.type) : + PreCat_IsCat (DPobj T). +econstructor. +eapply DP_LeftUnit_lemma; eauto. +eapply DP_RightUnit_lemma; eauto. +eapply DP_Assoc_lemma; eauto. +Qed. + +(* DPobj is a category *) +HB.instance Definition DPCat (T: STUFunctor.type) := DPCatP T. + + +(** Horizontal composition functor and strict double categories *) + +(* composition prefunctor *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsCPreFunctor T of STUFunctor T := + { is_cprefunctor : IsPreFunctor (DPobj T) (D1obj T) (@H1Comp T) }. +HB.structure Definition CPreFunctor : Set := {C of IsCPreFunctor C}. +Set Universe Checking. + +(* composition functor - gives the definition of Strict Double Category *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record CPreFunctor_IsFunctor T of CPreFunctor T := { + is_cfunctor : PreFunctor_IsFunctor (DPobj T) (D1obj T) (@H1Comp T) }. +#[short(type="sdoublecat")] +HB.structure Definition SDoubleCat : Set := {C of CPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* horizontal 2-cell composition: maps two adjecent pairs of + horizontal morphisms (a and b) and a pullback-category morphism + between them (m, which basically gives two adjecent cells) to a + 2-cell morphism between the horizontal composition (HComp) of each + pair *) +Definition HC2Comp (T: SDoubleCat.type) (a b: DPobj T) + (m: @hom (DPobj T) a b) : + d1hom (H1Comp a) (H1Comp b) := @Fhom _ _ (@H1Comp T) a b m. + +Program Definition HC2Comp_flat (T: SDoubleCat.type) (a0 a1 a2 b0 b1 b2: T) + (h0: hhom a0 a1) (h1: hhom a1 a2) + (k0: hhom b0 b1) (k1: hhom b1 b2) + (hh0: D1hom h0 k0) + (hh1: D1hom h1 k1) + (k: H1Target hh0 = H1Source hh1) + : (* D1hom (hcomp _ _ _ h0 h1) (hcomp _ _ _ k0 k1) *) + d1hom (l_hcomp h0 h1) (l_hcomp k0 k1) := + @Fhom _ _ (@H1Comp T) (GC h0 h1) (GC k0 k1) _. +Obligation 1. +refine (@existT (D1hom h0 k0) _ hh0 (@existT (D1hom h1 k1) _ hh1 k)). +Defined. + +(********************************************************************) +(********************************************************************) + + +Section th_of_pb. +Variables (Q : cat) (A B C D E F : Q). +Variables (f : A ~> D) (g : B ~> D) (h : C ~> A). +Variables (u : E ~> A) (v : E ~> B) (w : F ~> C) (z : F ~> E). +Variable (uvfg : pbsquare u v f g). + +Set Printing Width 50. +Theorem pbsquarec_compP : + pbsquare w z h u <=> pbsquare w (z \; v) (h \; f) g. +Proof. +split=> [] sq. + + have @sq_ispb : pullback (Cospan h u) := HB.pack (Span w z) sq. + have @uvfg_ispb : pullback (Cospan f g) := HB.pack (Span u v) uvfg. + have /=E2 := @is_square _ _ _ _ sq_ispb. + have /=E1 := @is_square _ _ _ _ uvfg_ispb. + + have p1 : @isPrePullback Q C B (Cospan (h \; f) g) (Span w (z \; v)). + by constructor; rewrite /= compoA E2 -compoA E1 compoA. + pose big_black_square : prepullback (Cospan (h \; f) g) := + HB.pack (Span w (z \; v)) p1. + + have @from : forall + (big_red_square : prepullback {| top := D; left2top := h \; f; right2top := g |}), + big_red_square ~> pb_terminal big_black_square. + + move=> big_red_square; unfold pb_terminal. + + have /= := @is_square _ _ _ _ big_red_square. + + pose F' := bot big_red_square. + set w' : F' ~> C := bot2left big_red_square. + set z' : F' ~> B := bot2right big_red_square. + move=> E3. + + have xxx : isPrePullback Q A B (Cospan f g) (Span (w' \; h) z'). + by constructor=> /=; rewrite -compoA E3. + pose red_black_square : prepullback (Cospan f g) := + HB.pack (Span (w' \; h) z') xxx. + have := @from_unique _ (pb_terminal uvfg_ispb) red_black_square. + set blue := @from _ (pb_terminal uvfg_ispb) red_black_square. + move=> blue_unique. + + have p3 : @isPrePullback Q C E (Cospan h u) (Span w' (bot_map blue)). + by constructor; rewrite /= (bot2left_map blue). (* buggy unifier without blue *) + pose blue_red_black_square : prepullback (Cospan h u) := + HB.pack (Span w' (bot_map blue)) p3. + + pose red := @from _ (pb_terminal sq_ispb) blue_red_black_square. + + admit. + + + + have p2 : prepullback_isTerminal.axioms_ Q C B (Cospan (h \; f) g) (Span w (z \; v)) p1. + constructor. econstructor=> /=. + admit. + + by HB.from p1 p2. + +Admitted. + +End th_of_pb. + + +Module test. + +Section test. +Variables (Q : precat) (A B : Q) (c : cospan A B). +Variable (p : pullback c). +Check pb_terminal p : terminal _. + +End test. +End test. + + + +(************************************************************************) + +(**** INTERNAL CATEGORIES - NEW DEFINITION *) + +(* Defining internal hom objects. + C0 and C1 are objects of C. + C0 is the object of objects, + C1 is the object of morphims (and the subject). + this will allow to define a generic _ *_C0 _ notation + by recognizing the structure of hom objects on the LHS and RHS + Basically, w.r.t. double categories, C1 represents 'horizontal' + 1-morpshisms and the D1 category, whereas C0 represents the objects + of the base D0 category. *) +HB.mixin Record isInternalHom {C: quiver} (C0 : C) (C1 : obj C) := { + src : C1 ~> C0; tgt : C1 ~> C0 +}. +#[short(type="iHom")] +HB.structure Definition InternalHom {C: quiver} (C0 : C) := + { C1 of isInternalHom C C0 C1 }. + +Notation "X ':>' C" := (X : obj C) (at level 60, C at next level). + +(* HB.instance Definition _ (T : quiver) := Quiver.on (obj T). *) +(* HB.instance Definition _ (T : precat) := PreCat.on (obj T). *) +(* HB.instance Definition _ (T : cat) := Cat.on (obj T). *) +(* HB.instance Definition _ (T : pbcat) := PBCat.on (obj T). *) + +(* constructs the pullback from the cospan given by target and source. + Type-level construction: X and Y are two instances of the morphism + object, specified by (iHom C0), and are objects of (obj C). Here + 'iprod' is just an object of (obj C). The cospan is given by the + target of X and the source of Y. The pullback provides a commuting + square on the cospan, which basically ensures that the morphisms in + X and Y can be composed. *) +Definition iprod_pb {C: pbcat} {C0 : C} (X Y : iHom C0) : + span (X :> C) (Y :> C) := + pb _ _ (Cospan (tgt : (X :> C) ~> C0) (src : (Y :> C) ~> C0)). + +Definition iprod {C: pbcat} {C0 : obj C} (X Y : iHom C0) : obj C := + bot (@iprod_pb C C0 X Y). +Notation "X *_ C0 Y" := (@iprod _ C0 (X : iHom C0) (Y : iHom C0)) + (at level 99, C0 at level 0, only parsing) : cat_scope. +Notation "X *_ C0 Y" := (@iprod _ C0 X Y) + (at level 99, C0 at level 0) : cat_scope. + +(* +(1) Defines pullback square (iprod_pb) + + X --- tgt -----> C0 + ^ ^ + | | + bot2left src + | | + X*Y - bot2right -> Y + + +(2) Defines source and target of the product (iprod_iHom) + + X --- src -----> C0 + ^ ^ + | | + iprodl tgt + | | + X*Y -- iprodr ---> Y +*) + +(* left and right projection morphisms of the product *) +Definition iprodl {C: pbcat} {C0 : C} (X Y : iHom C0) : + X *_C0 Y ~> (X :> C) := bot2left (iprod_pb X Y). +Definition iprodr {C: pbcat} {C0 : C} (X Y : iHom C0) : + X *_C0 Y ~> (Y :> C) := bot2right (iprod_pb X Y). + +(* Given (iHom C0) instances X and Y, we want to say that (X *_C0 Y) +is also an instance of (iHom C0). X and Y represent composable +morphisms, as by pullback properties, the diagram (1) commutes. +source and target are obtained by composing with product projections +(2) *) +Definition iprod_iHom {C: pbcat} {C0: C} (X Y: @iHom C C0) : + @isInternalHom C C0 (X *_C0 Y) := + @isInternalHom.Build C C0 (X *_C0 Y) + ((iprodl X Y) \; src) + ((iprodr X Y) \; tgt). + +HB.instance Definition iprod_iHom' {C: pbcat} {C0: C} (X Y: @iHom C C0) : + @isInternalHom C C0 (X *_C0 Y) := iprod_iHom X Y. + +(* the product as (iHom C0) object *) +Definition pbC0 (C : pbcat) (C0 : C) (X Y : iHom C0) : iHom C0 := + (X *_C0 Y) : iHom C0. + +(* we also define the trivial internal hom type *) +HB.instance Definition trivial_iHom {C: pbcat} {C0: C} := + isInternalHom.Build C C0 C0 idmap idmap. + + + +(* we need internal hom morphisms: +the ones that preserve sources and targets. +basically, we recast morphisms in (obj C) into some in (@iHom C C0), +i.e. into morphism between copies of C1 *) +HB.mixin Record IsInternalHomHom {C: pbcat} (C0 : C) + (C1 C1' : @iHom C C0) (f : (C1 :> C) ~> (C1' :> C)) := { +(* hom_src : f \; src = src; + hom_tgt : f \; tgt = tgt; *) +}. +#[short(type="iHomHom")] +HB.structure Definition InternalHomHom {C: pbcat} + (C0 : C) (C1 C1' : @iHom C C0) := + { f of @IsInternalHomHom C C0 C1 C1' f }. + +(* internal homs form a category, + the morphisms are the one that preserve source and target *) +HB.instance Definition iHom_quiver {C: pbcat} (C0 : C) : + IsQuiver (@iHom C C0) := + IsQuiver.Build (@iHom C C0) (@iHomHom C C0). +Print iHom_quiver. + +Definition pre_iHom_id {C: pbcat} (C0 : C) (C1 : @iHom C C0) : + @IsInternalHomHom C C0 C1 C1 idmap := + @IsInternalHomHom.Build C C0 C1 C1 idmap. +(* +Obligation 1. +setoid_rewrite comp1o; reflexivity. +Defined. +Obligation 2. +setoid_rewrite comp1o; reflexivity. +Defined. +*) + +Program Definition iHom_id {C: pbcat} (C0 : C) (C1 : @iHom C C0) : + C1 ~>_(@iHom C C0) C1 := + @InternalHomHom.Pack C C0 C1 C1 idmap _. +(* +The term "pre_iHom_id C1" has type "IsInternalHomHom.phant_axioms idmap" +while it is expected to have type "InternalHomHom.axioms_ ?sort". +*) +Obligation 1. +econstructor. +eapply (@pre_iHom_id C C0 C1). +Defined. + +Definition pre_iHom_comp {C: pbcat} (C0 : C) (C1 C2 C3: @iHom C C0) + (f: C1 ~>_(@iHom C C0) C2) (g: C2 ~>_(@iHom C C0) C3) : + @IsInternalHomHom C C0 C1 C3 (f \; g) := + @IsInternalHomHom.Build C C0 C1 C3 (f \; g). +(* +Obligation 1. +setoid_rewrite <- compoA. +repeat (setoid_rewrite hom_src); auto. +Defined. +Obligation 2. +setoid_rewrite <- compoA. +repeat (setoid_rewrite hom_tgt); auto. +Defined. +*) + +Program Definition iHom_comp {C: pbcat} (C0 : C) (C1 C2 C3: @iHom C C0) + (f: C1 ~>_(@iHom C C0) C2) (g: C2 ~>_(@iHom C C0) C3) : + C1 ~>_(@iHom C C0) C3 := + @InternalHomHom.Pack C C0 C1 C3 (f \; g) _. +Obligation 1. +econstructor. +eapply (@pre_iHom_comp C C0 C1 C2 C3 f g). +Defined. + +Program Definition iHom_precat {C: pbcat} (C0 : C) : + Quiver_IsPreCat (@iHom C C0) := + Quiver_IsPreCat.Build (@iHom C C0) _ _. +Obligation 1. +eapply (@iHom_id C C0 a). +Defined. +Obligation 2. +eapply (@iHom_comp C C0 a b c0 X X0). +Defined. + +HB.instance Definition iHom_precat' {C: pbcat} (C0 : C) := iHom_precat C0. + +Lemma iHom_LeftUnit_lemma (C : pbcat) (C0 : C) + (a b : iHom C0) (f : a ~> b) : idmap \; f = f. +unfold idmap; simpl. +unfold iHom_precat_obligation_1. +unfold comp; simpl. +unfold iHom_precat_obligation_2. +unfold iHom_comp. +remember f as f1. +remember a as a1. +remember b as b1. +destruct f as [ff class]. +destruct a as [Ca class_a]. +destruct b as [Cb class_b]. +destruct class_a as [IMa]. +destruct class_b as [IMb]. +destruct class as [IM]. +destruct IMa. +destruct IMb. +destruct IM. +unfold obj in *. +simpl in *; simpl. + +eassert ( forall x, exists y, + {| + InternalHomHom.sort := idmap \; f1; + InternalHomHom.class := x + |} = + {| + InternalHomHom.sort := f1; + InternalHomHom.class := y + |} ) as A2. +{ rewrite Heqf1; simpl. + rewrite comp1o. + intros. + destruct x as [X]. + econstructor. + destruct X. + reflexivity. +}. + +setoid_rewrite Heqf1 at 3. +specialize (A2 (iHom_comp_obligation_1 (iHom_id a1) f1)). +destruct A2. +rewrite H. + +inversion Heqf1; subst. +simpl. +destruct x as [IM]. +destruct IM. +reflexivity. +Qed. + +Lemma iHom_RightUnit_lemma (C : pbcat) (C0 : C) + (a b : iHom C0) (f : a ~> b) : f \; idmap = f. +unfold idmap; simpl. +unfold iHom_precat_obligation_1. +unfold comp; simpl. +unfold iHom_precat_obligation_2. +unfold iHom_comp. +remember f as f1. +remember a as a1. +remember b as b1. +destruct f as [ff class]. +destruct a as [Ca class_a]. +destruct b as [Cb class_b]. +destruct class_a as [IMa]. +destruct class_b as [IMb]. +destruct class as [IM]. +destruct IMa. +destruct IMb. +destruct IM. +unfold obj in *. +simpl in *; simpl. + +eassert ( forall x, exists y, + {| + InternalHomHom.sort := f1 \; idmap; + InternalHomHom.class := x + |} = + {| + InternalHomHom.sort := f1; + InternalHomHom.class := y + |} ) as A2. +{ rewrite Heqf1; simpl. + rewrite compo1. + intros. + destruct x as [X]. + econstructor. + destruct X. + reflexivity. +}. + +setoid_rewrite Heqf1 at 3. +specialize (A2 (iHom_comp_obligation_1 f1 (iHom_id b1))). +destruct A2. +rewrite H. + +inversion Heqf1; subst. +simpl. +destruct x as [IM]. +destruct IM. +reflexivity. +Qed. + +Lemma iHom_Assoc_lemma {C : pbcat} (C0 : C) + (a b c d : iHom C0) (f : a ~> b) (g : b ~> c) (h : c ~> d) : + f \; g \; h = (f \; g) \; h. + unfold comp; simpl. + unfold iHom_precat_obligation_2; simpl. + unfold iHom_comp; simpl. + remember a as a1. + remember b as b1. + remember c as c1. + remember d as d1. + remember f as f1. + remember g as g1. + remember h as h1. + destruct a as [C_a class_a]. + destruct b as [C_b class_b]. + destruct c as [C_c class_c]. + destruct d as [C_d class_d]. + destruct f as [M_f class_f]. + destruct g as [M_g class_g]. + destruct h as [M_h class_h]. + destruct class_a as [IM_a]. + destruct class_b as [IM_b]. + destruct class_c as [IM_c]. + destruct class_d as [IM_d]. + destruct IM_a. + destruct IM_b. + destruct IM_c. + destruct IM_d. + destruct class_f as [IM_f]. + destruct class_g as [IM_g]. + destruct class_h as [IM_h]. + destruct IM_f. + destruct IM_g. + destruct IM_h. + unfold obj in *; simpl in *; simpl. + + eassert ( forall x y, + {| + InternalHomHom.sort := f1 \; g1 \; h1; + InternalHomHom.class := x + |} = + {| + InternalHomHom.sort := (f1 \; g1) \; h1; + InternalHomHom.class := y + |} ) as A2. + { rewrite Heqf1; simpl. + rewrite compoA. + intros. + destruct x as [X]. + destruct y as [Y]. + destruct X. + destruct Y. + reflexivity. + }. + + setoid_rewrite A2. + reflexivity. +Qed. + +Program Definition iHom_cat {C: pbcat} (C0 : C) : + PreCat_IsCat (@iHom C C0) := + PreCat_IsCat.Build (@iHom C C0) _ _ _. +Obligation 1. +eapply iHom_LeftUnit_lemma; eauto. +Qed. +Obligation 2. +eapply iHom_RightUnit_lemma; eauto. +Qed. +Obligation 3. +eapply iHom_Assoc_lemma; eauto. +Qed. + +HB.instance Definition iHom_cat' {C: pbcat} (C0 : C) := iHom_cat C0. + +Definition iprodlC0 {C: pbcat} {C0 : C} (X Y : iHom C0) : + pbC0 X Y ~>_(iHom C0) X. + econstructor. + instantiate (1:=(iprodl X Y)). + econstructor. + econstructor. +Defined. +Definition iprodrC0 {C: pbcat} {C0 : C} (X Y : iHom C0) : + pbC0 X Y ~>_(iHom C0) Y. + econstructor. + instantiate (1:=(iprodr X Y)). + econstructor. + econstructor. +Defined. + + +(* Now we define an internal quiver as an object C0, + which has a C1 : iHom C0 attached to it *) +HB.mixin Record IsPreInternalQuiver (C : quiver) (C0 : obj C) := + { C1 : obj C }. +HB.structure Definition PreInternalQuiver C := + { C0 of @IsPreInternalQuiver C C0 }. + +Arguments C1 {C s}. + +#[wrapper] HB.mixin Record IsInternalQuiver (C : quiver) (C0 : obj C) of + @PreInternalQuiver C C0 := { + priv: @InternalHom C C0 (@C1 _ C0) + }. +#[short(type="iquiver")] +HB.structure Definition InternalQuiver (C : quiver) := + { C0 of IsInternalQuiver C C0 }. + +Coercion iquiver_quiver (C : quiver) (C0 : iquiver C) : C := C0 :> C. +Coercion iquiver_precat (C : precat) (C0 : iquiver C) : C := C0 :> C. +Coercion iquiver_cat (C : cat) (C0 : iquiver C) : C := C0 :> C. + + +(* nested product *) +Program Definition iprodA {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : + ((C1 *_C0 C2 : iHom C0) *_C0 C3) ~>_(iHom C0) + (C1 *_C0 (C2 *_C0 C3 : iHom C0)). + (* := ... *) + (* OK define it with the universal arrow of the pullback *) +Admitted. + +(* product morphism. + PROBLEM: f and g do not generally preserve source and target, + therefore there is no guarantee that + iprodlC0 \; f \; tgt = iprodrC0 \; g \; src + missing which, we cannot derive the existence of the morphism + between the two products. +*) +Definition ipair {C : pbcat} {C0 : C} {a b c d : iHom C0} + (f : a ~> c) (g : b ~> d) : (a *_C0 b) ~> (c *_C0 d). +Admitted. +Notation "<( f , g )>" := (ipair f g). + + +(* An internal precategory is an internal category with two operators + that must be src and tgt preserving, i.e. iHom morphisms: identity + : C0 -> C1 (corresponding to horizontal 1-morphism identity in + double cat) and composition : C1 * C1 -> C1 (corresponding to + horizontal composition) *) +HB.mixin Record IsInternalPreCat (C : pbcat) (C0 : obj C) + of @InternalQuiver C C0 := { + iid : (C0 : iHom C0) ~>_(iHom C0) (@C1 C C0 : iHom C0); + icomp : let C1 := @C1 C C0 : iHom C0 in + let C2 := pbC0 C1 C1 : iHom C0 in + (C2 ~>_(iHom C0) C1) +}. +#[short(type="iprecat")] +HB.structure Definition InternalPreCat (C : pbcat) := + { C0 of @IsInternalPreCat C C0 }. + +(* Check (iquiver Type <~> quiver). *) +(* Check (iprecat Type <~> precat). *) + +(* An internal category moreover must satisfy additional properies on iid and icomp +(associativity and unit laws) *) +#[key="C0"] +HB.mixin Record IsInternalCat (C : pbcat) (C0 : obj C) of InternalPreCat C C0 := { + (* icompA : <(icomp, idmap)> \; icomp = (iprodA _ _ _) \; <(idmap, icomp)> \; icomp; *) + (* icomp1l : <(idmap, iid)> \; icomp = iprodlC0 C1 C1; *) + (* icomp1r : <(iid, idmap)> \; icomp = iprodrC0 C1 C1; *) +}. +#[short(type="icat")] +HB.structure Definition InternalCat (C : pbcat) := {C0 of @IsInternalCat C C0}. +(* Check (icat Type <~> cat). *) + + +(* A double category is an internal category in cat + - The objects are the objects of C0 + - The vertical maps are the maps of C0 + - The horizontal maps are the objects of C1 + - The 2-cells are the maps of C1 + + About identities: + - The identity vertical map on (x : C) is \idmap_x + - The identity horizontal map on (x : C) is iid x + - the identity 2-cell on (x : C) is iid (\idmap_x) = \idmap_(iid x) + + About compositions: + - The vertical composition of maps is the composition of C0 + - The vertical compositions of 2-cells is the composition of C1 + (and it agrees with the former because src and tgt are functors + and because iid is a iHom-map) + - The horizontal composition of maps is the object part of icomp + - The horizontal composition of 2-cells is the map part of icomp +*) +(* HB.structure' Definition DoubleCat := @InternalCat cat. *) +Axiom cat_pbop : HasPBop cat. +HB.instance Definition _ := cat_pbop. + +Axiom cat_preb : + forall (a b: cat) (c: cospan a b), isPrePullback cat a b c (@pb cat a b c). +HB.instance Definition _ (a b: cat) (c: cospan a b) := @cat_preb a b c. +Axiom cat_pb : + forall (a b: cat) (c: cospan a b), + prepullback_isTerminal cat a b c (@pb cat a b c). +HB.instance Definition _ (a b: cat) (c: cospan a b) := @cat_pb a b c. + +(* basically, the internal category adds the D1 category to the base +D0 category, which is C0 (an object of cat, which is shown to have +pullbacks) *) +Definition doublecat := icat cat. + +(* Check (doublecat <~> ???) *) + From 6284697a8077e629cc2797178463feccd5fa0410 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Tue, 12 Dec 2023 16:18:30 +0100 Subject: [PATCH 106/147] updated encatD.v --- theories/encatD.v | 85 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 72 insertions(+), 13 deletions(-) diff --git a/theories/encatD.v b/theories/encatD.v index 60a3f166c..0a59455aa 100644 --- a/theories/encatD.v +++ b/theories/encatD.v @@ -2476,12 +2476,12 @@ Obligation 3. eapply iHom_Assoc_lemma; eauto. Qed. -HB.instance Definition iHom_cat' {C: pbcat} (C0 : C) := iHom_cat C0. (* PROBLEM: this morphism cannot exist, as the target of the product isn't generally the same as the target of the first projection. Similarly, the source of the product can be different from the source of the sencond projection. *) +(* Definition iprodlC0 {C: pbcat} {C0 : C} (X Y : iHom C0) : pbC0 X Y ~>_(iHom C0) X. assert (@src C C0 (pbC0 X Y) = (iprodl X Y) \; @src C C0 X) as A1. @@ -2492,6 +2492,7 @@ Admitted. Definition iprodrC0 {C: pbcat} {C0 : C} (X Y : iHom C0) : pbC0 X Y ~>_(iHom C0) Y. Admitted. +*) (* Now we define an internal quiver as an object C0, which has a C1 : iHom C0 attached to it *) @@ -2514,21 +2515,45 @@ Coercion iquiver_quiver (C : quiver) (C0 : iquiver C) : C := C0 :> C. Coercion iquiver_precat (C : precat) (C0 : iquiver C) : C := C0 :> C. Coercion iquiver_cat (C : cat) (C0 : iquiver C) : C := C0 :> C. - +Lemma ihom_morph (C : pbcat) (C0 : C) (a b: iHom C0) (f: a ~>_(iHom C0) b) : + (a :> C) ~>_C (b :> C). + simpl. + destruct a. + destruct b. + destruct f. + simpl in *. + exact sort1. +Defined. + (* nested product *) -Program Definition iprodA {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : +Program Definition iprodIAsc {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : ((C1 *_C0 C2 : iHom C0) *_C0 C3) ~>_(iHom C0) (C1 *_C0 (C2 *_C0 C3 : iHom C0) : iHom C0). (* := ... *) (* OK define it with the universal arrow of the pullback *) Admitted. +Program Definition iprodCAsc {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : + (((C1 *_C0 C2 : iHom C0) *_C0 C3) :> C) ~>_C + ((C1 *_C0 (C2 *_C0 C3 : iHom C0) : iHom C0) :> C). +eapply ihom_morph. +eapply iprodIAsc; eauto. +Defined. + (* product morphism *) -Definition ipair {C : pbcat} {C0 : C} {C1 C2 C3 C4 : iHom C0} +Program Definition ipairI {C : pbcat} {C0 : C} {C1 C2 C3 C4 : iHom C0} (f : C1 ~> C3) (g : C2 ~> C4) : (C1 *_C0 C2) ~>_(iHom C0) (C3 *_C0 C4). Admitted. -Notation "<( f , g )>" := (ipair f g). +Program Definition ipairC {C : pbcat} {C0 : C} {C1 C2 C3 C4 : iHom C0} + (f : C1 ~> C3) (g : C2 ~> C4) : + ((C1 *_C0 C2) :> C) ~>_C ((C3 *_C0 C4) :> C). +eapply ihom_morph. +eapply ipairI; eauto. +Defined. + +Notation "<( f , g )>" := (ipairI f g). +Notation "<(' f , g )>" := (ipairC f g). (* An internal precategory is an internal category with two operators that must be src and tgt preserving, i.e. iHom morphisms: identity @@ -2537,8 +2562,8 @@ Notation "<( f , g )>" := (ipair f g). horizontal composition) *) HB.mixin Record IsInternalPreCat (C : pbcat) (C0 : obj C) of @InternalQuiver C C0 := { - iid : (C0 : iHom C0) ~>_(iHom C0) (@C1 C C0 : iHom C0); - icomp : let C1 := @C1 C C0 : iHom C0 in + iidI : (C0 : iHom C0) ~>_(iHom C0) (@C1 C C0 : iHom C0); + icompI : let C1 := @C1 C C0 : iHom C0 in let C2 := pbC0 C1 C1 : iHom C0 in (C2 ~>_(iHom C0) C1) }. @@ -2546,19 +2571,53 @@ HB.mixin Record IsInternalPreCat (C : pbcat) (C0 : obj C) HB.structure Definition InternalPreCat (C : pbcat) := { C0 of @IsInternalPreCat C C0 }. +Program Definition iidC' {C : pbcat} {C0 : iprecat C} : + ((C0 : iHom C0) :> C) ~>_C + ((@C1 C C0 : iHom C0) :> C). +destruct C0; simpl in *. +destruct class as [IM1 IM2 IM3]; simpl in *. +destruct IM3; simpl in *. +exact iidI0. +Defined. +Program Definition iidC {C : pbcat} {C0 : iprecat C} : + (C0 :> C) ~>_C (@C1 C C0 :> C). +eapply iidC'; eauto. +Defined. + +Program Definition icompC {C : pbcat} {C0 : iprecat C} : + let C1 := @C1 C C0 : iHom C0 in + let C2 := pbC0 C1 C1 : iHom C0 in + ((C2 :> C) ~>_C (C1 :> C)). +destruct C0; simpl in *. +destruct class as [IM1 IM2 IM3]; simpl in *. +destruct IM3; simpl in *. +exact icompI0. +Defined. + (* Check (iquiver Type <~> quiver). *) (* Check (iprecat Type <~> precat). *) (* An internal category moreover must satisfy additional properies on iid and icomp (associativity and unit laws) *) #[key="C0"] -HB.mixin Record IsInternalCat (C : pbcat) (C0 : obj C) of InternalPreCat C C0 := { - (* icompA : <(icomp, idmap)> \; icomp = (iprodA _ _ _) \; <(idmap, icomp)> \; icomp; *) - (* icomp1l : <(idmap, iid)> \; icomp = iprodlC0 C1 C1; *) - (* icomp1r : <(iid, idmap)> \; icomp = iprodrC0 C1 C1; *) -}. + HB.mixin Record IsInternalCat (C : pbcat) (C0 : obj C) + of InternalPreCat C C0 := { + + icompA1 : + (<( (@icompI C C0), + (@idmap (iHom C0) (@C1 C C0: iHom C0)) )> \; icompI) = + ((@iprodIAsc C C0 (@C1 C C0: iHom C0) _ _) \; + <( (@idmap (iHom C0) (@C1 C C0: iHom C0)), icompI )> \; icompI) ; + + icomp1l : <(' @idmap (iHom C0) (@C1 C C0: iHom C0), (@iidI C C0) )> \; + icompC = @iprodl C C0 (C1 :> C) (C0 :> C); + + icomp1r : <(' (@iidI C C0), @idmap (iHom C0) (@C1 C C0: iHom C0) )> \; + icompC = @iprodr C C0 (C0 :> C) (C1 :> C); + }. #[short(type="icat")] -HB.structure Definition InternalCat (C : pbcat) := {C0 of @IsInternalCat C C0}. +HB.structure Definition InternalCat (C : pbcat) := + {C0 of @IsInternalCat C C0}. (* Check (icat Type <~> cat). *) From 9560c9fa72efe92c07e41576a621de87edac595b Mon Sep 17 00:00:00 2001 From: ptorrx Date: Wed, 13 Dec 2023 17:27:06 +0100 Subject: [PATCH 107/147] updated encatD.v --- theories/encatD.v | 83 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 2 deletions(-) diff --git a/theories/encatD.v b/theories/encatD.v index 0a59455aa..a5fb4d157 100644 --- a/theories/encatD.v +++ b/theories/encatD.v @@ -2540,9 +2540,88 @@ eapply ihom_morph. eapply iprodIAsc; eauto. Defined. +Lemma pbsquare_universal {C: cat} (A B T P0 P1 : C) + (t: A ~> T) (s: B ~> T) (p1: P0 ~> A) (p2: P0 ~> B) + (f: P1 ~> A) (g: P1 ~> B) : + pbsquare p1 p2 t s -> + f \; t = g \; s -> + sigma m: P1 ~> P0, f = m \; p1 /\ g = m \; p2. + intros sq E. + destruct sq as [IM1 IM2]. + + remember (Span p1 p2) as Spn0. + remember (@Cospan C A B T t s) as Csp. + remember (@Cospan C^op A B P1 f g) as Spn1. + + unfold Span in HeqSpn0. + + destruct IM1 as [IM3]. + destruct IM2 as [IM4]. + + assert (bot2left Spn1 \; left2top Csp = bot2right Spn1 \; right2top Csp) + as K1. + { unfold bot2left, bot2right. + rewrite HeqCsp. + rewrite HeqSpn1. + simpl; auto. + } + remember ( @isPrePullback.Build C A B Csp Spn1 K1) as Pb1. + assert (PrePullback.axioms_ Csp Spn1) as Pb2. + { econstructor. + exact Pb1. } + remember ( @PrePullback.Pack C A B Csp Spn1 Pb2) as PB. + + destruct IM4 as [IM5 IM6]. + clear IM6. + specialize (IM5 PB). + + inversion HeqSpn1; subst. + simpl in *. + clear H K1. + + unfold pb_terminal in *. + destruct Pb2 as [IM]. + destruct IM. + simpl in *. + + destruct IM5. + simpl in *. + + econstructor. + instantiate (1:= top_map0). + split; auto. +Qed. + +Lemma pbquare_universal_aux1 {C: cat} (A0 A1 B0 B1 P0 P1 T : C) + (t: A0 ~> T) (s: B0 ~> T) (p01: P0 ~> A0) (p02: P0 ~> B0) + (f: A1 ~> A0) (g: B1 ~> B0) (p11: P1 ~> A1) (p12: P1 ~> B1) : + pbsquare p01 p02 t s -> + p11 \; f \; t = p12 \; g \; s -> + sigma m: P1 ~> P0, p11 \; f = m \; p01 /\ p12 \; g = m \; p02. + intros. + eapply pbsquare_universal; eauto. + setoid_rewrite <- compoA; auto. +Qed. + (* product morphism *) -Program Definition ipairI {C : pbcat} {C0 : C} {C1 C2 C3 C4 : iHom C0} - (f : C1 ~> C3) (g : C2 ~> C4) : (C1 *_C0 C2) ~>_(iHom C0) (C3 *_C0 C4). +Program Definition ipairI {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} + (f : x0 ~> x2) (g : x1 ~> x3) : (x0 *_C0 x1) ~>_(iHom C0) (x2 *_C0 x3). + unfold iprod. + unfold iprod_pb. + remember (pb (x0 :> C) (x1 :> C) + {| top := C0; left2top := tgt; right2top := src |}) as Pb1. + remember (pb (x2 :> C) (x3 :> C) + {| top := C0; left2top := tgt; right2top := src |}) as Pb2. + destruct Pb1 as [P1 J1]. + destruct Pb2 as [P2 J2]. + + simpl in *; simpl. + + remember ({| top := C0; left2top := tgt; right2top := src |}) as Csp. + + remember (@is_pb C (x0 :> C) (x1 :> C) Csp) as X. + clear HeqX. + destruct X. Admitted. Program Definition ipairC {C : pbcat} {C0 : C} {C1 C2 C3 C4 : iHom C0} From b0444ce2e048e6aac5b6b0aa78e0a7023459a422 Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Thu, 14 Dec 2023 19:46:15 +0100 Subject: [PATCH 108/147] added encatI.v, which merges new version of cat.v with internal category development from encatD.v --- theories/encatI.v | 1985 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1985 insertions(+) create mode 100644 theories/encatI.v diff --git a/theories/encatI.v b/theories/encatI.v new file mode 100644 index 000000000..28765a2e2 --- /dev/null +++ b/theories/encatI.v @@ -0,0 +1,1985 @@ +Require Import ssreflect ssrfun. +From HB Require Import structures. +Require Import Coq.Program.Equality. + +Set Implicit Arguments. +Unset Strict Implicit. +Unset Printing Implicit Defensive. +Add Search Blacklist "__canonical__". + +Declare Scope algebra_scope. +Delimit Scope algebra_scope with A. +Local Open Scope algebra_scope. + +Declare Scope cat_scope. +Delimit Scope cat_scope with cat. +Local Open Scope cat_scope. + +(* we assume a few axioms to make life easier *) +Axiom funext : forall {T : Type} {U : T -> Type} [f g : forall t, U t], + (forall t, f t = g t) -> f = g. +Axiom propext : forall P Q : Prop, P <-> Q -> P = Q. +Axiom Prop_irrelevance : forall (P : Prop) (x y : P), x = y. + +(* Shortcut *) +Notation U := Type. + +(* Base definition : raw categories = quivers *) +HB.mixin Record IsQuiver C := { hom : C -> C -> U }. +Unset Universe Checking. +#[short(type="quiver")] +HB.structure Definition Quiver : Set := { C of IsQuiver C }. +Set Universe Checking. + +Bind Scope cat_scope with quiver. +Bind Scope cat_scope with hom. +Arguments hom {C} : rename. +Notation homs T := (@hom T _ _). +Notation "a ~> b" := (hom a b) + (at level 99, b at level 200, format "a ~> b") : cat_scope. +Notation "a ~>_ C b" := (@hom C a b) + (at level 99, C at level 0, only parsing) : cat_scope. + +(* precategories are quivers + id and comp *) +HB.mixin Record Quiver_IsPreCat C of Quiver C := { + idmap : forall (a : C), a ~> a; + comp : forall (a b c : C), (a ~> b) -> (b ~> c) -> (a ~> c); +}. + +HB.factory Record IsPreCat C := { + hom : C -> C -> U; + idmap : forall (a : C), hom a a; + comp : forall (a b c : C), hom a b -> hom b c -> hom a c; +}. +HB.builders Context C of IsPreCat C. + HB.instance Definition _ := IsQuiver.Build C hom. + HB.instance Definition _ := Quiver_IsPreCat.Build C idmap comp. +HB.end. + +Unset Universe Checking. +#[short(type="precat")] +HB.structure Definition PreCat : Set := { C of IsPreCat C }. +Set Universe Checking. + +Bind Scope cat_scope with precat. +Arguments idmap {C} {a} : rename. +Arguments comp {C} {a b c} : rename. +Notation "f \o g" := (comp g f) : cat_scope. +Notation "f \; g :> T" := (@comp T _ _ _ f g) + (at level 60, g, T at level 60, format "f \; g :> T", only parsing) : cat_scope. +Notation "f \; g" := (comp f g) : cat_scope. +Notation "\idmap_ a" := (@idmap _ a) (only parsing, at level 0) : cat_scope. + +(* categories are precategories + laws *) +HB.mixin Record PreCat_IsCat C of PreCat C := { + comp1o : forall (a b : C) (f : a ~> b), idmap \; f = f; + compo1 : forall (a b : C) (f : a ~> b), f \; idmap = f; + compoA : forall (a b c d : C) (f : a ~> b) (g : b ~> c) (h : c ~> d), + f \; (g \; h) = (f \; g) \; h +}. +Unset Universe Checking. +#[short(type="cat")] +HB.structure Definition Cat : Set := { C of PreCat_IsCat C & IsPreCat C }. +Set Universe Checking. + +Bind Scope cat_scope with cat. +Arguments compo1 {C a b} : rename. +Arguments comp1o {C a b} : rename. +Arguments compoA {C a b c d} : rename. + +(* the discrete category on a type cannot be the default, we make an alias *) +Definition discrete (T : U) := T. +HB.instance Definition _ T := @IsPreCat.Build (discrete T) (fun x y => x = y) + (fun=> erefl) (@etrans _). +Lemma etransA T (a b c d : discrete T) (f : a ~> b) (g : b ~> c) (h : c ~> d) : + f \; (g \; h) = (f \; g) \; h. +Proof. by rewrite /idmap/comp/=; case: _ / h; case: _ / g. Qed. +HB.instance Definition _ T := PreCat_IsCat.Build (discrete T) (@etrans_id _) + (fun _ _ _ => erefl) (@etransA _). + +(* the category of the unit type is the discrete one *) +HB.instance Definition _ := Cat.copy unit (discrete unit). + +HB.instance Definition _ := @IsPreCat.Build U (fun A B => A -> B) + (fun a => idfun) (fun a b c (f : a -> b) (g : b -> c) => (g \o f)%FUN). +HB.instance Definition _ := PreCat_IsCat.Build U (fun _ _ _ => erefl) + (fun _ _ _ => erefl) (fun _ _ _ _ _ _ _ => erefl). + + +Lemma Ucomp (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) : f \; g = (g \o f)%FUN. +Proof. by []. Qed. +Lemma Ucompx (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) x : (f \; g) x = g (f x). +Proof. by []. Qed. +Lemma U1 (X : U) : \idmap_X = idfun. +Proof. by []. Qed. +Lemma U1x (X : U) x : \idmap_X x = x. +Proof. by []. Qed. + +(* a prefunctor is a functor without laws *) +HB.mixin Record IsPreFunctor (C D : quiver) (F : C -> D) := { + Fhom : forall (a b : C), (a ~> b) -> (F a ~> F b) +}. + +Unset Universe Checking. +HB.structure Definition PreFunctor (C D : quiver) : Set := + { F of IsPreFunctor C D F }. +Set Universe Checking. +HB.instance Definition _ := IsQuiver.Build quiver PreFunctor.type. + +Notation "F ^$" := (@Fhom _ _ F _ _) + (at level 1, format "F ^$") : cat_scope. +Notation "F <$> f" := (@Fhom _ _ F _ _ f) + (at level 58, format "F <$> f", right associativity) : cat_scope. + +(* prefunctors are equal if their object and hom part are respectively equal *) +Lemma prefunctorP (C D : quiver) (F G : C ~> D) (eqFG : F =1 G) : + let homF a b F := F a ~> F b in + (forall a b f, eq_rect _ (homF a b) (F <$> f) _ (funext eqFG) = G <$> f) -> + F = G. +Proof. +move: F G => [F [[/= Fhom]]] [G [[/= Ghom]]] in eqFG *. +case: _ / (funext eqFG) => /= in Ghom * => eqFGhom. +congr PreFunctor.Pack; congr PreFunctor.Class; congr IsPreFunctor.Axioms_. +by do 3!apply: funext=> ?. +Qed. + +(* a functor is a prefunctor + laws for id and comp *) +HB.mixin Record PreFunctor_IsFunctor (C D : precat) (F : C -> D) + of @PreFunctor C D F := { + F1 : forall (a : C), F <$> \idmap_a = idmap; + Fcomp : forall (a b c : C) (f : a ~> b) (g : b ~> c), + F <$> (f \; g) = F <$> f \; F <$> g; +}. +Unset Universe Checking. + +(* precat and cat have a quiver structure *) +HB.structure Definition Functor (C D : precat) : Set := + { F of IsPreFunctor C D F & PreFunctor_IsFunctor C D F }. +Set Universe Checking. +HB.instance Definition _ := IsQuiver.Build precat Functor.type. +HB.instance Definition _ := IsQuiver.Build cat Functor.type. + +(* functor equality is the same as prefunctor because of PI *) +Lemma functorP (C D : precat) (F G : C ~> D) (eqFG : F =1 G) : + let homF a b F := F a ~> F b in + (forall a b f, eq_rect _ (homF a b) (F^$ f) _ (funext eqFG) = G^$ f) -> + F = G. +Proof. +move=> /= /prefunctorP {eqFG}. +case: F G => [F [/= Fm Fm']] [G [/= Gm Gm']]//=. +move=> [_] /EqdepFacts.eq_sigT_iff_eq_dep eqFG. +case: _ / eqFG in Gm' *. +congr Functor.Pack; congr Functor.Class. +case: Fm' Gm' => [F1 Fc] [G1 Gc]. +by congr PreFunctor_IsFunctor.Axioms_; apply: Prop_irrelevance. +Qed. + +(* the identity function is a functor *) +HB.instance Definition _ (C : quiver) := + IsPreFunctor.Build C C idfun (fun a b => idfun). +HB.instance Definition _ (C : precat) := + PreFunctor_IsFunctor.Build C C idfun (fun=> erefl) (fun _ _ _ _ _ => erefl). + +(* the composition of prefunctors *) +Section comp_prefunctor. +Context {C D E : quiver} {F : C ~> D} {G : D ~> E}. + +HB.instance Definition _ := IsPreFunctor.Build C E (G \o F)%FUN + (fun a b f => G <$> F <$> f). +Lemma comp_Fun (a b : C) (f : a ~> b) : (G \o F)%FUN <$> f = G <$> (F <$> f). +Proof. by []. Qed. +End comp_prefunctor. + +Section comp_functor. +Context {C D E : precat} {F : C ~> D} {G : D ~> E}. +Lemma comp_F1 (a : C) : (G \o F)%FUN <$> \idmap_a = idmap. +Proof. by rewrite !comp_Fun !F1. Qed. +Lemma comp_Fcomp (a b c : C) (f : a ~> b) (g : b ~> c) : + (G \o F)%FUN <$> (f \; g) = (G \o F)%FUN <$> f \; (G \o F)%FUN <$> g. +Proof. by rewrite !comp_Fun !Fcomp. Qed. +HB.instance Definition _ := PreFunctor_IsFunctor.Build C E (G \o F)%FUN + comp_F1 comp_Fcomp. +End comp_functor. + +(* precat and cat have a precategory structure *) +HB.instance Definition _ := Quiver_IsPreCat.Build precat + (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). +HB.instance Definition _ := Quiver_IsPreCat.Build cat + (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). + +Lemma funext_frefl A B (f : A -> B) : funext (frefl f) = erefl. +Proof. exact: Prop_irrelevance. Qed. + +(* precategories and categories form a category *) +Definition precat_cat : PreCat_IsCat precat. +Proof. +by split=> [C D F|C D F|C D C' D' F G H]; + apply/functorP => a b f /=; rewrite funext_frefl. +Qed. +HB.instance Definition _ := precat_cat. +Definition cat_cat : PreCat_IsCat cat. +Proof. +by split=> [C D F|C D F|C D C' D' F G H]; + apply/functorP => a b f /=; rewrite funext_frefl. +Qed. +HB.instance Definition _ := cat_cat. + +Check (cat : cat). + +(* concrete categories *) +HB.mixin Record Quiver_IsPreConcrete T of Quiver T := { + concrete : T -> U; + concrete_fun : forall (a b : T), (a ~> b) -> concrete a -> concrete b; +}. +Unset Universe Checking. +#[short(type="preconcrete_quiver")] +HB.structure Definition PreConcreteQuiver : Set := + { C of Quiver_IsPreConcrete C & IsQuiver C }. +Set Universe Checking. +Coercion concrete : PreConcreteQuiver.sort >-> Sortclass. + +HB.mixin Record PreConcrete_IsConcrete T of PreConcreteQuiver T := { + concrete_fun_inj : forall (a b : T), injective (concrete_fun a b) +}. +Unset Universe Checking. +#[short(type="concrete_quiver")] +HB.structure Definition ConcreteQuiver : Set := + { C of PreConcreteQuiver C & PreConcrete_IsConcrete C }. +Set Universe Checking. + +HB.instance Definition _ (C : ConcreteQuiver.type) := + IsPreFunctor.Build _ _ (concrete : C -> U) concrete_fun. + +HB.mixin Record PreCat_IsConcrete T of ConcreteQuiver T & PreCat T := { + concrete1 : forall (a : T), concrete <$> \idmap_a = idfun; + concrete_comp : forall (a b c : T) (f : a ~> b) (g : b ~> c), + concrete <$> (f \; g) = ((concrete <$> g) \o (concrete <$> f))%FUN; +}. +Unset Universe Checking. +#[short(type="concrete_precat")] +HB.structure Definition ConcretePreCat : Set := + { C of PreCat C & ConcreteQuiver C & PreCat_IsConcrete C }. +#[short(type="concrete_cat")] +HB.structure Definition ConcreteCat : Set := + { C of Cat C & ConcreteQuiver C & PreCat_IsConcrete C }. +Set Universe Checking. + +HB.instance Definition _ (C : concrete_precat) := + PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). +HB.instance Definition _ (C : ConcreteCat.type) := + PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). + +HB.instance Definition _ := Quiver_IsPreConcrete.Build U (fun _ _ => id). +HB.instance Definition _ := PreConcrete_IsConcrete.Build U (fun _ _ _ _ => id). +HB.instance Definition _ := PreCat_IsConcrete.Build U + (fun=> erefl) (fun _ _ _ _ _ => erefl). + +Unset Universe Checking. +HB.instance Definition _ := Quiver_IsPreConcrete.Build quiver (fun _ _ => id). +HB.instance Definition _ := Quiver_IsPreConcrete.Build precat (fun _ _ => id). +HB.instance Definition _ := Quiver_IsPreConcrete.Build cat (fun _ _ => id). +Lemma quiver_concrete_subproof : PreConcrete_IsConcrete quiver. +Proof. +constructor=> C D F G FG; apply: prefunctorP. + by move=> x; congr (_ x); apply: FG. +by move=> *; apply: Prop_irrelevance. +Qed. +HB.instance Definition _ := quiver_concrete_subproof. + +Lemma precat_concrete_subproof : PreConcrete_IsConcrete precat. +Proof. +constructor=> C D F G FG; apply: functorP. + by move=> x; congr (_ x); apply: FG. +by move=> *; apply: Prop_irrelevance. +Qed. +HB.instance Definition _ := precat_concrete_subproof. + +Lemma cat_concrete_subproof : PreConcrete_IsConcrete cat. +Proof. +constructor=> C D F G FG; apply: functorP. + by move=> x; congr (_ x); apply: FG. +by move=> *; apply: Prop_irrelevance. +Qed. +HB.instance Definition _ := cat_concrete_subproof. +HB.instance Definition _ := PreCat_IsConcrete.Build precat + (fun=> erefl) (fun _ _ _ _ _ => erefl). +HB.instance Definition _ := PreCat_IsConcrete.Build cat + (fun=> erefl) (fun _ _ _ _ _ => erefl). +Set Universe Checking. + +(* constant functor *) +Definition cst (C D : quiver) (c : C) := fun of D => c. +Arguments cst {C} D c. +HB.instance Definition _ {C D : precat} (c : C) := + IsPreFunctor.Build D C (cst D c) (fun _ _ _ => idmap). +HB.instance Definition _ {C D : cat} (c : C) := + PreFunctor_IsFunctor.Build D C (cst D c) (fun=> erefl) + (fun _ _ _ _ _ => esym (compo1 idmap)). + +(* opposite category *) +Definition catop (C : U) : U := C. +Notation "C ^op" := (catop C) + (at level 2, format "C ^op") : cat_scope. +HB.instance Definition _ (C : quiver) := + IsQuiver.Build C^op (fun a b => hom b a). +HB.instance Definition _ (C : precat) := + Quiver_IsPreCat.Build (C^op) (fun=> idmap) (fun _ _ _ f g => g \; f). +HB.instance Definition _ (C : cat) := PreCat_IsCat.Build (C^op) + (fun _ _ _ => compo1 _) (fun _ _ _ => comp1o _) + (fun _ _ _ _ _ _ _ => esym (compoA _ _ _)). + +HB.instance Definition _ {C : precat} {c : C} := + IsPreFunctor.Build C _ (hom c) (fun a b f g => g \; f). +Lemma hom_Fhom_subproof (C : cat) (x : C) : + PreFunctor_IsFunctor _ _ (hom x). +Proof. by split=> *; apply/funext => h; [apply: compo1 | apply: compoA]. Qed. +HB.instance Definition _ {C : cat} {c : C} := hom_Fhom_subproof c. + +Check fun (C : cat) (x : C) => hom x : C ~>_cat U. + +Lemma hom_op {C : quiver} (c : C^op) : hom c = (@hom C)^~ c. +Proof. reflexivity. Qed. + +Lemma homFhomx {C : precat} (a b c : C) (f : a ~> b) (g : c ~> a) : + (hom c <$> f) g = g \; f. +Proof. reflexivity. Qed. + +(* nary product of categories *) +Definition dprod {I : U} (C : I -> U) := forall i, C i. + +Section hom_dprod. +Context {I : U} (C : I -> quiver). +Definition dprod_hom_subdef (a b : dprod C) := forall i, a i ~> b i. +HB.instance Definition _ := IsQuiver.Build (dprod C) dprod_hom_subdef. +End hom_dprod. +Arguments dprod_hom_subdef /. + +Section precat_dprod. +Context {I : U} (C : I -> precat). +Definition dprod_idmap_subdef (a : dprod C) : a ~> a := fun=> idmap. +Definition dprod_comp_subdef (a b c : dprod C) (f : a ~> b) (g : b ~> c) : a ~> c := + fun i => f i \; g i. +HB.instance Definition _ := IsPreCat.Build (dprod C) + dprod_idmap_subdef dprod_comp_subdef. +End precat_dprod. +Arguments dprod_idmap_subdef /. +Arguments dprod_comp_subdef /. + +Section cat_dprod. +Context {I : U} (C : I -> cat). +Local Notation type := (dprod C). +Lemma dprod_is_cat : PreCat_IsCat type. +Proof. +split=> [a b f|a b f|a b c d f g h]; apply/funext => i; +[exact: comp1o | exact: compo1 | exact: compoA]. +Qed. +HB.instance Definition _ := dprod_is_cat. +End cat_dprod. + +(* binary product *) +Section hom_prod. +Context {C D : quiver}. +Definition prod_hom_subdef (a b : C * D) := ((a.1 ~> b.1) * (a.2 ~> b.2))%type. +HB.instance Definition _ := IsQuiver.Build (C * D)%type prod_hom_subdef. +End hom_prod. + +Section precat_prod. +Context {C D : precat}. +HB.instance Definition _ := IsPreCat.Build (C * D)%type (fun=> (idmap, idmap)) + (fun a b c (f : a ~> b) (g : b ~> c) => (f.1 \; g.1, f.2 \; g.2)). +End precat_prod. + +Section cat_prod. +Context {C D : cat}. +Local Notation type := (C * D)%type. +Lemma prod_is_cat : PreCat_IsCat type. +Proof. +split=> [[a1 a2] [b1 b2] [f1 f2]|[a1 a2] [b1 b2] [f1 f2]| + [a1 a2] [b1 b2] [c1 c2] [d1 d2] [f1 f2] [g1 g2] [h1 h2]]; congr (_, _) => //=; +by [exact: comp1o | exact: compo1 | exact: compoA]. +Qed. +HB.instance Definition _ := prod_is_cat. +End cat_prod. + +HB.instance Definition _ (C : U) (D : quiver) := + IsQuiver.Build (C -> D) (fun f g => forall c, f c ~> g c). + +(* naturality *) +HB.mixin Record IsNatural (C : quiver) (D : precat) (F G : C ~>_quiver D) + (n : forall c, F c ~> G c) := { + natural : forall (a b : C) (f : a ~> b), + F <$> f \; n b = n a \; G <$> f +}. +Unset Universe Checking. +HB.structure Definition Natural (C : quiver) (D : precat) + (F G : C ~>_quiver D) : Set := + { n of @IsNatural C D F G n }. +Set Universe Checking. +HB.instance Definition _ (C : quiver) (D : precat) := + IsQuiver.Build (PreFunctor.type C D) (@Natural.type C D). +HB.instance Definition _ (C D : precat) := + IsQuiver.Build (Functor.type C D) (@Natural.type C D). +Arguments natural {C D F G} n [a b] f : rename. + +Check fun (C D : cat) (F G : C ~> D) => F ~>_(C ~>_cat D) G. + +Lemma naturalx (C : precat) (D : concrete_precat) + (F G : C ~>_quiver D) (n : F ~> G) (a b : C) (f : a ~> b) g : + (concrete <$> n b) ((concrete <$> F <$> f) g) = + (concrete <$> G <$> f) ((concrete <$> n a) g). +Proof. +have /(congr1 (fun h => (concrete <$> h) g)) := natural n f. +by rewrite !Fcomp. +Qed. +Arguments naturalx {C D F G} n [a b] f. + +Lemma naturalU (C : precat) (F G : C ~>_quiver U) (n : F ~> G) + (a b : C) (f : a ~> b) g : n b (F^$ f g) = G^$ f (n a g). +Proof. exact: (naturalx n). Qed. + +Lemma natP (C D : precat) (F G : C ~>_quiver D) (n m : F ~> G) : + Natural.sort n = Natural.sort m -> n = m. +Proof. +case: n m => [/= n nP] [/= m mP] enm. +elim: _ / enm in mP *; congr Natural.Pack. +case: nP mP => [[?]] [[?]]; congr Natural.Class. +congr IsNatural.Axioms_. +exact: Prop_irrelevance. +Qed. + +Notation "F ~~> G" := (F ~>_(homs quiver) G) + (at level 99, G at level 200, format "F ~~> G"). +Notation "F ~~> G :> C ~> D" := (F ~> G :> (C ~>_quiver D)) + (at level 99, G at level 200, C, D at level 0, + format "F ~~> G :> C ~> D"). + +Definition natural_id {C D : precat} (F : C ~>_quiver D) (a : C) := \idmap_(F a). +Definition natural_id_natural (C D : cat) (F : C ~>_quiver D) : + IsNatural C D F F (natural_id F). +Proof. by constructor=> a b f; rewrite /natural_id/= compo1 comp1o. Qed. +HB.instance Definition _ C D F := @natural_id_natural C D F. + +Check fun {C D : cat} (F : C ~>_quiver D) => natural_id F : F ~> F. + +Definition natural_comp {C D : precat} (F G H : C ~>_quiver D) + (m : F ~> G) (n : G ~> H) (a : C) := m a \; n a. +Definition natural_comp_natural (C D : cat) (F G H : C ~>_quiver D) m n : + IsNatural C D F H (@natural_comp C D F G H m n). +Proof. +constructor=> a b f; rewrite /natural_comp/=. +by rewrite compoA natural -compoA natural compoA. +Qed. +HB.instance Definition _ C D F G H m n := @natural_comp_natural C D F G H m n. + +HB.instance Definition _ {C D : cat} := + Quiver_IsPreCat.Build (PreFunctor.type C D) natural_id natural_comp. +HB.instance Definition _ {C D : cat} := + Quiver_IsPreCat.Build (Functor.type C D) natural_id natural_comp. + +Lemma prefunctor_cat {C D : cat} : PreCat_IsCat (PreFunctor.type C D). +Proof. +constructor => [F G f|F G f|F G H J f g h]. +- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. +- by apply/natP/funext => a; rewrite /= /natural_comp compo1. +- by apply/natP/funext => a; rewrite /= /natural_comp compoA. +Qed. +HB.instance Definition _ C D := @prefunctor_cat C D. + +Lemma functor_cat {C D : cat} : PreCat_IsCat (Functor.type C D). +Proof. +constructor => [F G f|F G f|F G H J f g h]. +- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. +- by apply/natP/funext => a; rewrite /= /natural_comp compo1. +- by apply/natP/funext => a; rewrite /= /natural_comp compoA. +Qed. +HB.instance Definition _ C D := @functor_cat C D. + +Lemma idFmap (C : cat) (a b : C) (f : a ~> b) : idfun <$> f = f. +Proof. by []. Qed. + +Lemma compFmap (C D E : cat) (F : C ~> D) (G : D ~> E) (a b : C) (f : a ~> b) : + (G \o F) <$> f = G <$> F <$> f. +Proof. by []. Qed. + +Section left_whiskering. +Context {C D E : precat} {F G : C ~> D}. + +Definition whiskerl_fun (eta : forall c, F c ~> G c) (H : D ~> E) : + forall c, (F \; H) c ~> (G \; H) c := fun c => H <$> eta c. + +Lemma whiskerl_is_nat (eta : F ~> G) (H : D ~> E) : + IsNatural _ _ _ _ (whiskerl_fun eta H). +Proof. by constructor=> a b f; rewrite /whiskerl_fun/= -!Fcomp natural. Qed. + +HB.instance Definition _ (eta : F ~> G) (H : D ~> E) := whiskerl_is_nat eta H. +Definition whiskerl (eta : F ~> G) (H : D ~> E) : (F \; H) ~> (G \; H) := + whiskerl_fun eta H : Natural.type _ _. +End left_whiskering. + +Notation "F n" := (whiskerl F n) + (at level 58, format "F n", right associativity) : cat_scope. + +Section right_whiskering. +Context {C D E : precat} {F G : D ~> E}. + +Definition whiskerr_fun (H : C ~> D) (eta : forall d, F d ~> G d) + (c : C) : (H \; F) c ~> (H \; G) c := eta (H c). + +Lemma whiskerr_is_nat (H : C ~> D) (eta : F ~> G) : + IsNatural _ _ _ _ (whiskerr_fun H eta). +Proof. by constructor=> a b f; rewrite /whiskerr_fun/= natural. Qed. +HB.instance Definition _ (H : C ~> D) (eta : F ~> G) := whiskerr_is_nat H eta. + +Definition whiskerr (H : C ~> D) (eta : F ~> G) : (H \; F) ~> (H \; G) := + whiskerr_fun H eta : Natural.type _ _. +End right_whiskering. + +Notation "F <$o> n" := (whiskerr F n) + (at level 58, format "F <$o> n", right associativity) : cat_scope. + +Definition whisker {C : cat} {D : precat} {E : cat} + {F G : C ~>_precat D} {H K : D ~> E} + (eta : F ~> G) (mu : H ~> K) : (F \; H) ~> (G \; K) := + (eta H) \; (G <$o> mu). + +Notation "eta mu" := (whisker eta mu) + (at level 58, format "eta mu", right associativity) : cat_scope. + +Lemma whiskern1 {C D E : cat} {F G : C ~>_precat D} (eta : F ~> G) (H : D ~> E) : + eta \idmap_H = eta H. +Proof. by apply/natP/funext=> c /=; apply: compo1. Qed. + +Lemma whisker1n {C D E : cat} {F G : D ~> E} (H : C ~> D) (eta : F ~> G) : + \idmap_H eta = H <$o> eta. +Proof. +apply/natP/funext=> c /=; rewrite /natural_comp/=. +by rewrite [X in X \; _]F1 comp1o. +Qed. + +Definition delta (C D : cat) : C -> (D ~> C) := cst D. +Arguments delta C D : clear implicits. + +Definition map_delta {C D : cat} (a b : C) (f : a ~> b) : + delta C D a ~> delta C D b. +Proof. +apply: (@Natural.Pack _ _ (cst D a) (cst D b) (fun x => f)). +apply: Natural.Class; apply: (IsNatural.Build _ _ _ _ _). +by move=> a' b' ?; rewrite compo1 comp1o. +Defined. + +HB.instance Definition _ {C D : cat} := + IsPreFunctor.Build C (D ~> C) (delta C D) (@map_delta C D). + +Lemma delta_functor {C D : cat} : PreFunctor_IsFunctor _ _ (delta C D). +Proof. by constructor=> [a|a b c f g]; exact/natP. Qed. +HB.instance Definition _ C D := @delta_functor C D. + +HB.mixin Record IsMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { + unit : idfun ~~> M; + join : (M \o M)%FUN ~~> M; + bind : forall (a b : C), (a ~> M b) -> (M a ~> M b); + bindE : forall a b (f : a ~> M b), bind a b f = M <$> f \; join b; + unit_join : forall a, (M <$> unit a) \; join _ = idmap; + join_unit : forall a, join _ \; (M <$> unit a) = idmap; + join_square : forall a, M <$> join a \; join _ = join _ \; join _ +}. + +#[short(type="premonad")] +HB.structure Definition PreMonad (C : precat) := + {M of @PreFunctor C C M & IsMonad C M}. +#[short(type="monad")] +HB.structure Definition Monad (C : precat) := + {M of @Functor C C M & IsMonad C M}. + +HB.factory Record IsJoinMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { + unit : idfun ~~> M; + join : (M \o M)%FUN ~~> M; + unit_join : forall a, (M <$> unit a) \; join _ = idmap; + join_unit : forall a, join _ \; (M <$> unit a) = idmap; + join_square : forall a, M <$> join a \; join _ = join _ \; join _ +}. +HB.builders Context C M of IsJoinMonad C M. + HB.instance Definition _ := IsMonad.Build C M + (fun a b f => erefl) unit_join join_unit join_square. +HB.end. + +HB.mixin Record IsCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { + counit : M ~~> idfun; + cojoin : M ~~> (M \o M)%FUN; + cobind : forall (a b : C), (M a ~> b) -> (M a ~> M b); + cobindE : forall a b (f : M a ~> b), cobind a b f = cojoin _ \; M <$> f; + unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; + join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; + cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ +}. +#[short(type="precomonad")] +HB.structure Definition PreCoMonad (C : precat) := + {M of @PreFunctor C C M & IsCoMonad C M}. +#[short(type="comonad")] +HB.structure Definition CoMonad (C : precat) := + {M of @Functor C C M & IsCoMonad C M}. + +HB.factory Record IsJoinCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { + counit : M ~~> idfun; + cojoin : M ~~> (M \o M)%FUN; + unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; + join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; + cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ +}. +HB.builders Context C M of IsJoinCoMonad C M. + HB.instance Definition _ := IsCoMonad.Build C M + (fun a b f => erefl) unit_cojoin join_counit cojoin_square. +HB.end. + +(* yoneda *) +Section hom_repr. +Context {C : cat} (F : C ~>_cat U). + +Definition homF : C -> U := fun c => hom c ~~> F. + +Section nat. +Context (x y : C) (xy : x ~> y). + +(* Goal hom x ~~> F -> hom y ~~> F *) +Context (n : hom x ~~> F). +Definition homFhom c : hom y c ~> F c := fun g => n _ (xy \; g). + +Lemma homFhom_natural_subdef : IsNatural C U (hom y) F homFhom. +Proof. +by split=> a b f /=; apply/funext => g /=; + rewrite /homFhom !Ucompx/= !naturalU/= Fcomp. +Qed. +HB.instance Definition _ := homFhom_natural_subdef. +End nat. +Arguments homFhom / : clear implicits. + +HB.about IsPreFunctor.Build. +Check homFhom : forall x y : C, (x ~> y) -> (homF x -> homF y). +HB.instance Definition _ := IsPreFunctor.Build _ _ homF homFhom. +Lemma homF_functor_subproof : PreFunctor_IsFunctor _ _ homF. +Proof. +split=> [a|a b c f g]. + apply/funext => -[/= f natf]. + apply: natP => //=; apply: funext => b; apply: funext => g/=. + by rewrite comp1o. +apply/funext => -[/= h natf]. +apply: natP => //=; apply: funext => d; apply: funext => k/=. +by rewrite compoA. +Qed. +HB.instance Definition _ := homF_functor_subproof. + +Section pointed. +Context (c : C). +Definition hom_repr : homF c ~> F c := fun f => f _ idmap. +Arguments hom_repr /. + +Definition repr_hom (fc : F c) a : hom c a ~> F a := + fun f => F^$ f fc. +Arguments repr_hom / : clear implicits. +Lemma repr_hom_subdef (fc : F c) : IsNatural _ _ _ _ (repr_hom fc). +Proof. by split=> a b f /=; apply/funext=> x; rewrite !Ucompx/= Fcomp. Qed. +HB.instance Definition _ {fc : F c} := repr_hom_subdef fc. + +Definition repr_hom_nat : F c ~> homF c := repr_hom. + +Lemma hom_reprK : cancel hom_repr repr_hom_nat. +Proof. +move=> f; apply/natP; apply/funext => a; apply/funext => g /=. +by rewrite -naturalU/=; congr (f _ _); apply: comp1o. +Qed. +Lemma repr_homK : cancel (repr_hom : F c ~> homF c) hom_repr. +Proof. by move=> fc; rewrite /= F1. Qed. +End pointed. +Arguments hom_repr /. +Arguments repr_hom /. + +Lemma hom_repr_natural_subproof : IsNatural _ _ _ _ hom_repr. +Proof. +split=> a b f /=; apply/funext => n /=; rewrite !Ucompx/= compo1/=. +by rewrite -naturalU/=; congr (n _ _); apply/esym/comp1o. +Qed. +HB.instance Definition _ := hom_repr_natural_subproof. + +(* show this from the previous proof *) +Lemma hom_natural_repr_subproof : IsNatural _ _ _ _ repr_hom_nat. +Proof. +split=> a b f /=; apply: funext => fa /=; rewrite !Ucompx/=. +apply: natP; apply: funext => c /=; apply: funext => d /=. +by rewrite Fcomp Ucompx/=. +Qed. +HB.instance Definition _ := hom_natural_repr_subproof. + +Definition hom_repr_nat : homF ~~> F := hom_repr. +Definition repr_hom_nat_nat : F ~~> homF := repr_hom_nat. + +End hom_repr. + +(* comma categories *) +Module comma. +Section homcomma. +Context {C D E : precat} (F : C ~> E) (G : D ~> E). + +Definition type := { x : C * D & F x.1 ~> G x.2 }. +Definition hom_subdef (a b : type) := { + f : tag a ~> tag b & F <$> f.1 \; tagged b = tagged a \; G <$> f.2 + }. +HB.instance Definition _ := IsQuiver.Build type hom_subdef. +End homcomma. +Arguments hom_subdef /. +Section comma. +Context {C D E : cat} (F : C ~> E) (G : D ~> E). +Notation type := (type F G). + +Program Definition idmap_subdef (a : type) : a ~> a := @Tagged _ idmap _ _. +Next Obligation. by rewrite !F1 comp1o compo1. Qed. +Program Definition comp_subdef (a b c : type) + (f : a ~> b) (g : b ~> c) : a ~> c := + @Tagged _ (tag f \; tag g) _ _. +Next Obligation. by rewrite !Fcomp -compoA (tagged g) compoA (tagged f) compoA. Qed. +HB.instance Definition _ := IsPreCat.Build type idmap_subdef comp_subdef. +Arguments idmap_subdef /. +Arguments comp_subdef /. + +Lemma comma_homeqP (a b : type) (f g : a ~> b) : projT1 f = projT1 g -> f = g. +Proof. +case: f g => [f fP] [g +]/= eqfg; case: _ / eqfg => gP. +by congr existT; apply: Prop_irrelevance. +Qed. + +Lemma comma_is_cat : PreCat_IsCat type. +Proof. +by split=> [[a fa] [b fb] [*]|[a fa] [b fb] [*]|*]; + apply/comma_homeqP; rewrite /= ?(comp1o, compo1, compoA). +Qed. +HB.instance Definition _ := comma_is_cat. +End comma. +End comma. +Notation "F `/` G" := (@comma.type _ _ _ F G) + (at level 40, G at level 40, format "F `/` G") : cat_scope. +Notation "a /` G" := (cst unit a `/` G) + (at level 40, G at level 40, format "a /` G") : cat_scope. +Notation "F `/ b" := (F `/` cst unit b) + (at level 40, b at level 40, format "F `/ b") : cat_scope. +Notation "a / b" := (cst unit a `/ b) : cat_scope. + +Definition obj (C : quiver) : Type := C. +HB.mixin Record IsInitial {C : quiver} (i : obj C) := { + to : forall c, i ~> c; + to_unique : forall c (f : i ~> c), f = to c +}. +#[short(type="initial")] +HB.structure Definition Initial {C : quiver} := {i of IsInitial C i}. + +HB.mixin Record IsTerminal {C : quiver} (t : obj C) := { + from : forall c, c ~> t; + from_unique : forall c (f : c ~> t), f = from c +}. +#[short(type="terminal")] +HB.structure Definition Terminal {C : quiver} := {t of IsTerminal C t}. + +HB.mixin Record IsMono {C : precat} (b c : C) (f : hom b c) := { + monoP : forall (a : C) (g1 g2 : a ~> b), g1 \; f = g2 \; f -> g1 = g2 +}. +#[short(type="mono")] +HB.structure Definition Mono {C : precat} (a b : C) := {m of IsMono C a b m}. +Notation "a >~> b" := (mono a b) + (at level 99, b at level 200, format "a >~> b") : cat_scope. +Notation "C >~>_ T D" := (@mono T C D) + (at level 99, T at level 0, only parsing) : cat_scope. + +HB.mixin Record IsEpi {C : precat} (a b : C) (f : hom a b) := { + epiP : forall (c : C) (g1 g2 : b ~> c), g1 \o f = g2 \o f -> g1 = g2 +}. +#[short(type="epi")] +HB.structure Definition Epi {C : precat} (a b : C) := {e of IsEpi C a b e}. +Notation "a ~>> b" := (epi a b) + (at level 99, b at level 200, format "a ~>> b") : cat_scope. +Notation "C ~>>_ T D" := (@epi T C D) + (at level 99, T at level 0, only parsing) : cat_scope. + +#[short(type="iso")] +HB.structure Definition Iso {C : precat} (a b : C) := + {i of @Mono C a b i & @Epi C a b i}. +Notation "a <~> b" := (epi a b) + (at level 99, b at level 200, format "a <~> b") : cat_scope. +Notation "C <~>_ T D" := (@epi T C D) + (at level 99, T at level 0, only parsing) : cat_scope. + +Definition comp1F {C D : cat} (F : C ~> D) : idmap \; F = F. +Proof. by apply/functorP=> a b f; rewrite funext_frefl/= compFmap. Qed. + +Definition compF1 {C D : cat} (F : C ~> D) : F \; idmap = F. +Proof. by apply/functorP=> a b f; rewrite funext_frefl/= compFmap. Qed. + +Definition feq {C : precat} {a b : C} : a = b -> a ~> b. +Proof. by move<-; exact idmap. Defined. + +Definition feqsym {C : precat} {a b : C} : a = b -> b ~> a. +Proof. by move<-; exact idmap. Defined. + +HB.mixin Record IsLeftAdjointOf (C D : cat) (R : D ~> C) L + of @Functor C D L := { + Lphi : forall c d, (L c ~> d) -> (c ~> R d); + Lpsi : forall c d, (c ~> R d) -> (L c ~> d); + (* there should be a monad and comonad structure wrappers instead *) + Lunit : (idmap : C ~> C) ~~> R \o ((L : Functor.type C D) : C ~> D); + Lcounit : ((L : Functor.type C D) : C ~> D) \o R ~~> idmap :> D ~> D; + LphiE : forall c d (g : L c ~> d), Lphi c d g = Lunit c \; (R <$> g); + LpsiE : forall c d (f : c ~> R d), Lpsi c d f = (L <$> f) \; Lcounit d; + Lwhiskerlr : let L : C ~> D := L : Functor.type C D in + (feqsym (comp1F _) \; Lunit L) \; + (L <$o> Lcounit \; feq (compF1 _)) = idmap; + Lwhiskerrl : let L : C ~> D := L : Functor.type C D in + (feqsym (compF1 _) \; R <$o> Lunit) \; + (Lcounit R \; feq (comp1F _)) = idmap; +}. +#[short(type="left_adjoint_of")] +HB.structure Definition LeftAdjointOf (C D : cat) (R : D ~> C) := + { L of @Functor C D L & IsLeftAdjointOf C D R L}. +Arguments Lphi {C D R s} {c d}. +Arguments Lpsi {C D R s} {c d}. +Arguments Lunit {C D R s}. +Arguments Lcounit {C D R s}. + +Section LeftAdjointOf_Theory. +Variables (C D : cat) (R : D ~> C) (L : LeftAdjointOf.type R). + +Lemma Lphi_psi (c : C) (d : D) : + (@Lphi _ _ R L c d \o @Lpsi _ _ R L c d)%FUN = @id (c ~> R d). +Proof. +apply/funext => f /=; rewrite LphiE LpsiE. +Admitted. + +Lemma Lpsi_phi (c : C) (d : D) : + (@Lpsi _ _ R L c d \o @Lphi _ _ R L c d)%FUN = @id (L c ~> d). +Proof. +Admitted. +End LeftAdjointOf_Theory. + +HB.mixin Record IsRightAdjoint (D C : cat) (R : D -> C) + of @Functor D C R := { + (* we should have a wrapper instead *) + left_adjoint : C ~> D; + LLphi : forall c d, (left_adjoint c ~> d) -> (c ~> R d); + LLpsi : forall c d, (c ~> R d) -> (left_adjoint c ~> d); + LLunit : (idmap : C ~> C) ~~> (R : Functor.type D C) \o left_adjoint; + LLcounit : left_adjoint \o (R : Functor.type D C) ~~> idmap :> D ~> D; + LLphiE : forall c d (g : left_adjoint c ~> d), LLphi c d g = LLunit c \; (R <$> g); + LLpsiE : forall c d (f : c ~> R d), LLpsi c d f = (left_adjoint <$> f) \; LLcounit d; + LLwhiskerlr : + (feqsym (comp1F _) \; LLunit left_adjoint) \; + (left_adjoint <$o> LLcounit \; feq (compF1 _)) = idmap; + LLwhiskerrl : + (feqsym (compF1 _) \; (R : Functor.type D C) <$o> LLunit) \; + (LLcounit (R : Functor.type D C) \; feq (comp1F _)) = idmap; +}. +#[short(type="right_adjoint")] +HB.structure Definition RightAdjoint (D C : cat) := + { R of @Functor D C R & IsRightAdjoint D C R }. +Arguments left_adjoint {_ _}. +Arguments LLphi {D C s} {c d}. +Arguments LLpsi {D C s} {c d}. +Arguments LLunit {D C s}. +Arguments LLcounit {D C s}. + +HB.mixin Record PreCat_IsMonoidal C of PreCat C := { + onec : C; + prod : (C * C)%type ~>_precat C; +}. +#[short(type="premonoidal")] +HB.structure Definition PreMonoidal := { C of PreCat C & PreCat_IsMonoidal C }. +Notation premonoidal := premonoidal. +Arguments prod {C} : rename. +Notation "a * b" := (prod (a, b)) : cat_scope. +Reserved Notation "f <*> g" (at level 40, g at level 40, format "f <*> g"). +Notation "f <*> g" := (prod^$ (f, g)) (only printing) : cat_scope. +Notation "f <*> g" := (prod^$ ((f, g) : (_, _) ~> (_, _))) + (only parsing) : cat_scope. +Notation "1" := onec : cat_scope. + +Definition hom_cast {C : quiver} {a a' : C} (eqa : a = a') + {b b' : C} (eqb : b = b') : + (a ~> b) -> (a' ~> b'). +Proof. now elim: _ / eqa; elim: _ / eqb. Defined. + +HB.mixin Record PreFunctor_IsMonoidal (C D : premonoidal) F of + @PreFunctor C D F := { + fun_one : F 1 = 1; + fun_prod : forall (x y : C), F (x * y) = F x * F y; +}. +#[short(type="monoidal_prefunctor")] +HB.structure Definition MonoidalPreFunctor C D := + { F of @PreFunctor_IsMonoidal C D F }. +Arguments fun_prod {C D F x y} : rename. +(* Arguments fun_prodF {C D F x x'} f {y y'} g : rename. *) +Unset Universe Checking. +HB.instance Definition _ := IsQuiver.Build premonoidal MonoidalPreFunctor.type. +Set Universe Checking. + +HB.instance Definition _ (C : quiver) := + IsPreFunctor.Build (C * C)%type C fst + (fun (a b : C * C) (f : a ~> b) => f.1). +HB.instance Definition _ (C : quiver) := + IsPreFunctor.Build (C * C)%type C snd + (fun (a b : C * C) (f : a ~> b) => f.2). + +Definition prod3l {C : premonoidal} (x : C * C * C) : C := + (x.1.1 * x.1.2) * x.2. +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build _ C prod3l + (fun a b (f : a ~> b) => (f.1.1 <*> f.1.2) <*> f.2). + +Definition prod3r {C : premonoidal} (x : C * C * C) : C := + x.1.1 * (x.1.2 * x.2). +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build _ C prod3r + (fun a b (f : a ~> b) => f.1.1 <*> (f.1.2 <*> f.2)). + +Definition prod1r {C : premonoidal} (x : C) : C := 1 * x. +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build C C prod1r + (fun (a b : C) (f : a ~> b) => \idmap_1 <*> f). + +Definition prod1l {C : premonoidal} (x : C) : C := x * 1. +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build C C prod1l + (fun (a b : C) (f : a ~> b) => f <*> \idmap_1). + +HB.mixin Record PreMonoidal_IsMonoidal C of PreMonoidal C := { + prodA : prod3l ~~> prod3r; + prod1c : prod1r ~~> idfun; + prodc1 : prod1l ~~> idfun; + prodc1c : forall (x y : C), + prodA (x, 1, y) \; \idmap_x <*> prod1c y = prodc1 x <*> \idmap_y; + prodA4 : forall (w x y z : C), + prodA (w * x, y, z) \; prodA (w, x, y * z) = + prodA (w, x, y) <*> \idmap_z \; prodA (w, x * y, z) \; \idmap_w <*> prodA (x, y, z); +}. + +Unset Universe Checking. +#[short(type="monoidal")] +HB.structure Definition Monoidal : Set := + { C of PreMonoidal_IsMonoidal C & PreMonoidal C }. +Set Universe Checking. + +Record span (Q : quiver) (A B : Q) := Span { + bot : Q; + bot2left : bot ~> A; + bot2right : bot ~> B +}. + +Section spans. +Variables (Q : precat) (A B : Q). +Record span_map (c c' : span A B) := SpanMap { + bot_map : bot c ~> bot c'; + bot2left_map : bot_map \; bot2left c' = bot2left c; + bot2right_map : bot_map \; bot2right c' = bot2right c; +}. +HB.instance Definition _ := IsQuiver.Build (span A B) span_map. + +Lemma span_mapP (c c' : span A B) (f g : c ~> c') : + bot_map f = bot_map g <-> f = g. +Proof. +split=> [|->]//; case: f g => [/= f ? ?] [/= g + +] efg. +by elim: efg => // ? ?; congr SpanMap; apply: Prop_irrelevance. +Qed. + +End spans. + +Section spans_in_cat. +Variables (Q : cat) (A B : Q). +Definition span_idmap (c : span A B) := + @SpanMap Q A B c c idmap (comp1o _) (comp1o _). +Program Definition span_comp (c1 c2 c3 : span A B) + (f12 : c1 ~> c2) (f23 : c2 ~> c3) := + @SpanMap Q A B c1 c3 (bot_map f12 \; bot_map f23) _ _. +Next Obligation. by rewrite -compoA !bot2left_map. Qed. +Next Obligation. by rewrite -compoA !bot2right_map. Qed. +HB.instance Definition _ := IsPreCat.Build (span A B) + span_idmap span_comp. + +Lemma span_are_cats : PreCat_IsCat (span A B). +Proof. +constructor=> [a b f|a b f|a b c d f g h]. +- by apply/span_mapP => /=; rewrite comp1o. +- by apply/span_mapP => /=; rewrite compo1. +- by apply/span_mapP => /=; rewrite compoA. +Qed. +HB.instance Definition _ := span_are_cats. +End spans_in_cat. + +Record cospan (Q : quiver) (A B : Q) := Cospan { + top : Q; + left2top : A ~> top; + right2top : B ~> top +}. + +Section cospans. +Variables (Q : precat) (A B : Q). +Record cospan_map (c c' : cospan A B) := CospanMap { + top_map : top c ~> top c'; + left2top_map : left2top c \; top_map = left2top c'; + right2top_map : right2top c \; top_map = right2top c'; +}. +HB.instance Definition _ := IsQuiver.Build (cospan A B) cospan_map. + +Lemma cospan_mapP (c c' : cospan A B) (f g : c ~> c') : + top_map f = top_map g <-> f = g. +Proof. +split=> [|->]//; case: f g => [/= f ? ?] [/= g + +] efg. +by elim: efg => // ? ?; congr CospanMap; apply: Prop_irrelevance. +Qed. + +End cospans. + +Section cospans_in_cat. +Variables (Q : cat) (A B : Q). +Definition cospan_idmap (c : cospan A B) := + @CospanMap Q A B c c idmap (compo1 _) (compo1 _). +Program Definition cospan_comp (c1 c2 c3 : cospan A B) + (f12 : c1 ~> c2) (f23 : c2 ~> c3) := + @CospanMap Q A B c1 c3 (top_map f12 \; top_map f23) _ _. +Next Obligation. by rewrite compoA !left2top_map. Qed. +Next Obligation. by rewrite compoA !right2top_map. Qed. +HB.instance Definition _ := IsPreCat.Build (cospan A B) + cospan_idmap cospan_comp. + +Lemma cospan_are_cats : PreCat_IsCat (cospan A B). +Proof. +constructor=> [a b f|a b f|a b c d f g h]. +- by apply/cospan_mapP => /=; rewrite comp1o. +- by apply/cospan_mapP => /=; rewrite compo1. +- by apply/cospan_mapP => /=; rewrite compoA. +Qed. +HB.instance Definition _ := cospan_are_cats. +End cospans_in_cat. + +HB.mixin Record isPrePullback (Q : precat) (A B : Q) + (c : cospan A B) (s : span A B) := { + is_square : bot2left s \; left2top c = bot2right s \; right2top c; +}. +#[short(type=prepullback)] +HB.structure Definition PrePullback Q A B (c : cospan A B) := + {s of isPrePullback Q A B c s}. +Arguments prepullback {Q A B} c. + +Section prepullback. +Variables (Q : precat) (A B : Q) (c : cospan A B). +HB.instance Definition _ := + IsQuiver.Build (prepullback c) + (fun a b => (a : span A B) ~>_(span A B) (b : span A B)). +Lemma eq_prepullbackP (p q : prepullback c) : + p = q :> span _ _ <-> p = q. +Proof. +Admitted. +End prepullback. +Section prepullback. +Variables (Q : cat) (A B : Q) (csp : cospan A B). +(* TODO: why can't we do that? *) +(* HB.instance Definition _ := Cat.on (prepullback csp). *) +HB.instance Definition _ := + Quiver_IsPreCat.Build (prepullback csp) + (fun a => \idmap_(a : span A B)) + (* TODO: study how to make this coercion trigger + even when the target is not reduced to span *) + (fun a b c f g => f \; g). +Lemma prepullback_is_cat : PreCat_IsCat (prepullback csp). +Proof. (* should be copied from the cat on span *) +constructor=> [a b f|a b f|a b c d f g h]; + [exact: comp1o|exact: compo1|exact: compoA]. +Qed. +End prepullback. + +HB.tag Definition pb_terminal (Q : precat) + (A B : Q) (c : cospan A B) (s : prepullback c) : + obj (prepullback c) := s. + +#[wrapper] +HB.mixin Record prepullback_isTerminal (Q : precat) + (A B : Q) (c : cospan A B) + (s : span A B) of isPrePullback Q A B c s := { + prepullback_terminal : + IsTerminal (prepullback c) (pb_terminal s) +}. +#[short(type="pullback"), verbose] +HB.structure Definition Pullback (Q : precat) + (A B : Q) (c : cospan A B) := + {s of isPrePullback Q A B c s + & IsTerminal (prepullback c) (pb_terminal s) }. + +Inductive walking_cospan := Top | Left | Right. +Definition walking_cospan_hom (x y : walking_cospan) := match x, y with + | Top, Top | Left, Left | Right, Right | + Left, Top | Right, Top => Datatypes.unit + | _, _ => False + end. + +HB.instance Definition _ := + IsQuiver.Build walking_cospan walking_cospan_hom. + +Definition walking_cospan_id (x : walking_cospan) : x ~> x. +Proof. by case: x; constructor. Defined. + +Definition walking_cospan_comp (x y z : walking_cospan) : + (x ~> y) -> (y ~> z) -> (x ~> z). +Proof. by case: x y z => [] [] []. Defined. + +HB.instance Definition _ := Quiver_IsPreCat.Build walking_cospan + walking_cospan_id walking_cospan_comp. + +Lemma walking_cospan_cat : PreCat_IsCat walking_cospan. +Proof. by constructor=> [[] []|[] []|[] [] [] []]// []. Qed. +HB.instance Definition _ := walking_cospan_cat. + +Section Pullback_Natural. +Context (C : cat) (A B : C) (csp : cospan A B). + +Definition cspF (x : walking_cospan) : C := + match x with Left => A | Right => B | Top => top csp end. + +Definition cspFhom : forall (x y : walking_cospan), + (x ~> y) -> cspF x ~> cspF y. +Proof. +move=> [] []//. +- move=> _; exact: idmap. +- move=> _; exact: left2top csp. +- move=> _; exact: idmap. +- move=> _; exact: right2top csp. +- move=> _; exact: idmap. +Defined. + +HB.instance Definition _ := IsPreFunctor.Build _ _ cspF cspFhom. +Lemma cspF_functor : PreFunctor_IsFunctor _ _ cspF. +Proof. +by constructor=> [[]|[] [] []]//= [] []//=; + rewrite ?(compo1, comp1o)//. +Qed. +HB.instance Definition _ := cspF_functor. + +Section prepullback2natural. +Variable (p : prepullback csp). + +Definition wcsp w : cst walking_cospan (bot p) w ~> cspF w. +Proof. +case: w; rewrite /cst /=. +- exact: (bot2left _ \; left2top _). +- exact: bot2left. +- exact: bot2right. +Defined. + +Lemma wcsp_natural : IsNatural _ _ _ _ wcsp. +Proof. +constructor=> - [] [] //= [] /=; rewrite ?(comp1o, compo1)//=. +exact: is_square. +Qed. + +End prepullback2natural. + +Section natural2prepullback. +Variables (c : C) (n : cst walking_cospan c ~~> cspF). + +Definition s := {| bot := c; bot2left := n Left; bot2right := n Right |}. + +Lemma s_prepullback : isPrePullback _ _ _ csp s. +Proof. +constructor => /=. +have p := natural n (tt : Right ~> Top). +have /esym q := natural n (tt : Left ~> Top). +exact: etrans q p. +Qed. + +End natural2prepullback. + +End Pullback_Natural. +Notation square u v f g := + (isPrePullback _ _ _ (Cospan f g) (Span u v)). +Notation pbsquare u v f g := + (Pullback _ (Cospan f g) (Span u v)). +Notation pb s := (prepullback_isTerminal _ _ _ _ s). + +Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). + +(**********************************************************************) + +Section th_of_pb. +Variables (Q : cat) (A B C D E F : Q). +Variables (f : A ~> D) (g : B ~> D) (h : C ~> A). +Variables (u : E ~> A) (v : E ~> B) (w : F ~> C) (z : F ~> E). +Variable (uvfg : pbsquare u v f g). + +Theorem pbsquarec_compP : + pbsquare w z h u <=> pbsquare w (z \; v) (h \; f) g. +Proof. +split=> [] sq. + + have @sq_ispb : pullback (Cospan h u) := HB.pack (Span w z) sq. + have @uvfg_ispb : pullback (Cospan f g) := HB.pack (Span u v) uvfg. + have /=E2 := @is_square _ _ _ _ sq_ispb. + have /=E1 := @is_square _ _ _ _ uvfg_ispb. + + have p1 : @isPrePullback Q C B (Cospan (h \; f) g) (Span w (z \; v)). + by constructor; rewrite /= compoA E2 -compoA E1 compoA. + pose big_black_square : prepullback (Cospan (h \; f) g) := + HB.pack (Span w (z \; v)) p1. + + have @from : forall + (big_red_square : prepullback {| top := D; left2top := h \; f; right2top := g |}), + big_red_square ~> pb_terminal big_black_square. + + move=> big_red_square; unfold pb_terminal. + + have /= := @is_square _ _ _ _ big_red_square. + + pose F' := bot big_red_square. + set w' : F' ~> C := bot2left big_red_square. + set z' : F' ~> B := bot2right big_red_square. + move=> E3. + + have xxx : isPrePullback Q A B (Cospan f g) (Span (w' \; h) z'). + by constructor=> /=; rewrite -compoA E3. + pose red_black_square : prepullback (Cospan f g) := + HB.pack (Span (w' \; h) z') xxx. + have := @from_unique _ (pb_terminal uvfg_ispb) red_black_square. + set blue := @from _ (pb_terminal uvfg_ispb) red_black_square. + move=> blue_unique. + + have p3 : @isPrePullback Q C E (Cospan h u) (Span w' (bot_map blue)). + by constructor; rewrite /= (bot2left_map blue). (* buggy unifier without blue *) + pose blue_red_black_square : prepullback (Cospan h u) := + HB.pack (Span w' (bot_map blue)) p3. + + pose red := @from _ (pb_terminal sq_ispb) blue_red_black_square. + + admit. + + + + have p2 : prepullback_isTerminal.axioms_ Q C B (Cospan (h \; f) g) (Span w (z \; v)) p1. + constructor. econstructor=> /=. + admit. + + by HB.from p1 p2. + +Admitted. + +End th_of_pb. + + +Module test. + +Section test. +Variables (Q : precat) (A B : Q) (c : cospan A B). +Variable (p : pullback c). +Check pb_terminal p : terminal _. + +End test. +End test. + + +(********************************************************************) +(********************************************************************) + +Notation "'sigma' x .. y , p" := + (sigT (fun x => .. (sigT (fun y => p)) ..)) + (at level 200, x binder, right associativity, + format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") + : type_scope. + +(*** CATEGORIES WITH PULLBACKS *) + +(* category with all prepullbacks *) +(* Ideally span is in fact expanded and the final mixin has +a pb : forall A B, cospan A B -> C +but it is not clear how to do that yet +*) +HB.mixin Record HasPBop C of Cat C := { + pbk : forall (A B: C), cospan A B -> span A B + }. +#[short(type="pbop")] +HB.structure Definition PBop := + {C of HasPBop C & PreCat C }. + +(* category with all pullbacks *) +(* Wrong: we don't wrap classes, only mixins *) +#[wrapper] +HB.mixin Record HasPreBCat C of PBop C : Type := { + is_ppbk : forall (a b : C) (c : cospan a b), + isPrePullback C a b c (@pbk C a b c) + }. +#[short(type="pbcat")] +HB.structure Definition PreBCat := + {C of HasPreBCat C}. + +#[wrapper] +HB.mixin Record HasPBCat C of PBop C & HasPreBCat C : Type := { + is_tpbk : forall (a b : C) (c : cospan a b), + prepullback_isTerminal C a b c (@pbk C a b c) + }. +#[short(type="pbcat")] +HB.structure Definition PBCat := + {C of HasPBCat C}. + + +(************************************************************************) + +(**** INTERNAL CATEGORIES - NEW DEFINITION *) + +(* Defining internal hom objects. + C0 and C1 are objects of C. + C0 is the object of objects, + C1 is the object of morphims (and the subject). + this will allow to define a generic _ *_C0 _ notation + by recognizing the structure of hom objects on the LHS and RHS + Basically, w.r.t. double categories, C1 represents 'horizontal' + 1-morpshisms and the D1 category, whereas C0 represents the objects + of the base D0 category. *) +HB.mixin Record isInternalHom {C: quiver} (C0 : C) (C1 : obj C) := { + src : C1 ~> C0; tgt : C1 ~> C0 +}. +#[short(type="iHom")] +HB.structure Definition InternalHom {C: quiver} (C0 : C) := + { C1 of isInternalHom C C0 C1 }. + +Notation "X ':>' C" := (X : obj C) (at level 60, C at next level). + +(* HB.instance Definition _ (T : quiver) := Quiver.on (obj T). *) +(* HB.instance Definition _ (T : precat) := PreCat.on (obj T). *) +(* HB.instance Definition _ (T : cat) := Cat.on (obj T). *) +(* HB.instance Definition _ (T : pbcat) := PBCat.on (obj T). *) + +(* constructs the pullback from the cospan given by target and source. + Type-level construction: X and Y are two instances of the morphism + object, specified by (iHom C0), and are objects of (obj C). Here + 'iprod' is just an object of (obj C). The cospan is given by the + target of X and the source of Y. The pullback provides a commuting + square on the cospan, which basically ensures that the morphisms in + X and Y can be composed. *) +Definition iprod_pb {C: pbcat} {C0 : C} (X Y : iHom C0) : + span (X :> C) (Y :> C) := + pbk _ _ (Cospan (tgt : (X :> C) ~> C0) (src : (Y :> C) ~> C0)). + +Definition iprod {C: pbcat} {C0 : obj C} (X Y : iHom C0) : obj C := + bot (@iprod_pb C C0 X Y). +Notation "X *_ C0 Y" := (@iprod _ C0 (X : iHom C0) (Y : iHom C0)) + (at level 99, C0 at level 0, only parsing) : cat_scope. +Notation "X *_ C0 Y" := (@iprod _ C0 X Y) + (at level 99, C0 at level 0) : cat_scope. + +(* +(1) Defines pullback square (iprod_pb) + + X --- tgt -----> C0 + ^ ^ + | | + bot2left src + | | + X*Y - bot2right -> Y + + +(2) Defines source and target of the product (iprod_iHom) + + X --- src -----> C0 + ^ ^ + | | + iprodl tgt + | | + X*Y -- iprodr ---> Y +*) + +(* left and right projection morphisms of the product *) +Definition iprodl {C: pbcat} {C0 : C} (X Y : iHom C0) : + X *_C0 Y ~> (X :> C) := bot2left (iprod_pb X Y). +Definition iprodr {C: pbcat} {C0 : C} (X Y : iHom C0) : + X *_C0 Y ~> (Y :> C) := bot2right (iprod_pb X Y). + +(* Given (iHom C0) instances X and Y, we want to say that (X *_C0 Y) +is also an instance of (iHom C0). X and Y represent composable +morphisms, as by pullback properties, the diagram (1) commutes. +source and target are obtained by composing with product projections +(2) *) +Definition iprod_iHom {C: pbcat} {C0: C} (X Y: @iHom C C0) : + @isInternalHom C C0 (X *_C0 Y) := + @isInternalHom.Build C C0 (X *_C0 Y) + ((iprodl X Y) \; src) + ((iprodr X Y) \; tgt). + +HB.instance Definition iprod_iHom' {C: pbcat} {C0: C} (X Y: @iHom C C0) : + @isInternalHom C C0 (X *_C0 Y) := iprod_iHom X Y. + +(* the product as (iHom C0) object *) +Definition pbC0 (C : pbcat) (C0 : C) (X Y : iHom C0) : iHom C0 := + (X *_C0 Y) : iHom C0. + +(* we also define the trivial internal hom type *) +HB.instance Definition trivial_iHom {C: pbcat} {C0: C} : + @isInternalHom C C0 C0 := + isInternalHom.Build C C0 C0 idmap idmap. + +(**) + +Definition trivial_iHom' {C: pbcat} {C0: C} : @iHom C C0 := + InternalHom.Pack (InternalHom.Class (@trivial_iHom C C0)). + +Definition trivial_iprod_iHom {C: pbcat} {C0: C} : + @isInternalHom C C0 ((@trivial_iHom' C C0) *_C0 (@trivial_iHom' C C0)) := + @iprod_iHom' C C0 (@trivial_iHom' C C0) (@trivial_iHom' C C0). + +Definition trivial_iprod_iHom' {C: pbcat} {C0: C} : @iHom C C0 := + InternalHom.Pack (InternalHom.Class (@trivial_iprod_iHom C C0)). + +(**) + +(* we need internal hom morphisms: +the ones that preserve sources and targets. +basically, we recast morphisms in (obj C) into some in (@iHom C C0), +i.e. into morphism between copies of C1 *) +HB.mixin Record IsInternalHomHom {C: pbcat} (C0 : C) + (C1 C1' : @iHom C C0) (f : (C1 :> C) ~> (C1' :> C)) := { + hom_src : f \; src = src; + hom_tgt : f \; tgt = tgt; +}. +#[short(type="iHomHom")] +HB.structure Definition InternalHomHom {C: pbcat} + (C0 : C) (C1 C1' : @iHom C C0) := + { f of @IsInternalHomHom C C0 C1 C1' f }. + +(* internal homs form a category, + the morphisms are the one that preserve source and target *) +HB.instance Definition iHom_quiver {C: pbcat} (C0 : C) : + IsQuiver (@iHom C C0) := + IsQuiver.Build (@iHom C C0) (@iHomHom C C0). +Print iHom_quiver. + +Program Definition pre_iHom_id {C: pbcat} (C0 : C) (C1 : @iHom C C0) : + @IsInternalHomHom C C0 C1 C1 idmap := + @IsInternalHomHom.Build C C0 C1 C1 idmap _ _. +Obligation 1. +setoid_rewrite comp1o; reflexivity. +Defined. +Obligation 2. +setoid_rewrite comp1o; reflexivity. +Defined. + +Program Definition iHom_id {C: pbcat} (C0 : C) (C1 : @iHom C C0) : + C1 ~>_(@iHom C C0) C1 := + @InternalHomHom.Pack C C0 C1 C1 idmap _. +(* +The term "pre_iHom_id C1" has type "IsInternalHomHom.phant_axioms idmap" +while it is expected to have type "InternalHomHom.axioms_ ?sort". +*) +Obligation 1. +econstructor. +eapply (@pre_iHom_id C C0 C1). +Defined. + +Program Definition pre_iHom_comp {C: pbcat} (C0 : C) (C1 C2 C3: @iHom C C0) + (f: C1 ~>_(@iHom C C0) C2) (g: C2 ~>_(@iHom C C0) C3) : + @IsInternalHomHom C C0 C1 C3 (f \; g) := + @IsInternalHomHom.Build C C0 C1 C3 (f \; g) _ _. +Obligation 1. +setoid_rewrite <- compoA. +repeat (setoid_rewrite hom_src); auto. +Defined. +Obligation 2. +setoid_rewrite <- compoA. +repeat (setoid_rewrite hom_tgt); auto. +Defined. + +Program Definition iHom_comp {C: pbcat} (C0 : C) (C1 C2 C3: @iHom C C0) + (f: C1 ~>_(@iHom C C0) C2) (g: C2 ~>_(@iHom C C0) C3) : + C1 ~>_(@iHom C C0) C3 := + @InternalHomHom.Pack C C0 C1 C3 (f \; g) _. +Obligation 1. +econstructor. +eapply (@pre_iHom_comp C C0 C1 C2 C3 f g). +Defined. + +Program Definition iHom_precat {C: pbcat} (C0 : C) : + Quiver_IsPreCat (@iHom C C0) := + Quiver_IsPreCat.Build (@iHom C C0) _ _. +Obligation 1. +eapply (@iHom_id C C0 a). +Defined. +Obligation 2. +eapply (@iHom_comp C C0 a b c0 X X0). +Defined. + +HB.instance Definition iHom_precat' {C: pbcat} (C0 : C) := iHom_precat C0. + +Lemma iHom_LeftUnit_lemma (C : pbcat) (C0 : C) + (a b : iHom C0) (f : a ~> b) : idmap \; f = f. +unfold idmap; simpl. +unfold iHom_precat_obligation_1. +unfold comp; simpl. +unfold iHom_precat_obligation_2. +unfold iHom_comp. +remember f as f1. +remember a as a1. +remember b as b1. +destruct f as [ff class]. +destruct a as [Ca class_a]. +destruct b as [Cb class_b]. +destruct class_a as [IMa]. +destruct class_b as [IMb]. +destruct class as [IM]. +destruct IMa. +destruct IMb. +destruct IM. +unfold obj in *. +simpl in *; simpl. + +eassert ( forall x, exists y, + {| + InternalHomHom.sort := idmap \; f1; + InternalHomHom.class := x + |} = + {| + InternalHomHom.sort := f1; + InternalHomHom.class := y + |} ) as A2. +{ rewrite Heqf1; simpl. + rewrite comp1o. + intros. + destruct x as [X]. + econstructor. + destruct X. + reflexivity. +}. + +setoid_rewrite Heqf1 at 3. +specialize (A2 (iHom_comp_obligation_1 (iHom_id a1) f1)). +destruct A2. +rewrite H. + +inversion Heqf1; subst. +simpl. +destruct x as [IM]. +destruct IM. + +assert (hom_src0 = hom_src1) as D1. +{ eapply Prop_irrelevance. } + +assert (hom_tgt0 = hom_tgt1) as D2. +{ eapply Prop_irrelevance. } + +rewrite D1. +rewrite D2. +reflexivity. +Qed. + +Lemma iHom_RightUnit_lemma (C : pbcat) (C0 : C) + (a b : iHom C0) (f : a ~> b) : f \; idmap = f. +unfold idmap; simpl. +unfold iHom_precat_obligation_1. +unfold comp; simpl. +unfold iHom_precat_obligation_2. +unfold iHom_comp. +remember f as f1. +remember a as a1. +remember b as b1. +destruct f as [ff class]. +destruct a as [Ca class_a]. +destruct b as [Cb class_b]. +destruct class_a as [IMa]. +destruct class_b as [IMb]. +destruct class as [IM]. +destruct IMa. +destruct IMb. +destruct IM. +unfold obj in *. +simpl in *; simpl. + +eassert ( forall x, exists y, + {| + InternalHomHom.sort := f1 \; idmap; + InternalHomHom.class := x + |} = + {| + InternalHomHom.sort := f1; + InternalHomHom.class := y + |} ) as A2. +{ rewrite Heqf1; simpl. + rewrite compo1. + intros. + destruct x as [X]. + econstructor. + destruct X. + reflexivity. +} + +setoid_rewrite Heqf1 at 3. +specialize (A2 (iHom_comp_obligation_1 f1 (iHom_id b1))). +destruct A2. +rewrite H. + +inversion Heqf1; subst. +simpl. +destruct x as [IM]. +destruct IM. + +assert (hom_src0 = hom_src1) as D1. +{ eapply Prop_irrelevance. } + +assert (hom_tgt0 = hom_tgt1) as D2. +{ eapply Prop_irrelevance. } + +rewrite D1. +rewrite D2. +reflexivity. +Qed. + +Lemma iHom_Assoc_lemma {C : pbcat} (C0 : C) + (a b c d : iHom C0) (f : a ~> b) (g : b ~> c) (h : c ~> d) : + f \; g \; h = (f \; g) \; h. + unfold comp; simpl. + unfold iHom_precat_obligation_2; simpl. + unfold iHom_comp; simpl. + remember a as a1. + remember b as b1. + remember c as c1. + remember d as d1. + remember f as f1. + remember g as g1. + remember h as h1. + destruct a as [C_a class_a]. + destruct b as [C_b class_b]. + destruct c as [C_c class_c]. + destruct d as [C_d class_d]. + destruct f as [M_f class_f]. + destruct g as [M_g class_g]. + destruct h as [M_h class_h]. + destruct class_a as [IM_a]. + destruct class_b as [IM_b]. + destruct class_c as [IM_c]. + destruct class_d as [IM_d]. + destruct IM_a. + destruct IM_b. + destruct IM_c. + destruct IM_d. + destruct class_f as [IM_f]. + destruct class_g as [IM_g]. + destruct class_h as [IM_h]. + destruct IM_f. + destruct IM_g. + destruct IM_h. + unfold obj in *; simpl in *; simpl. + + eassert ( forall x y, + {| + InternalHomHom.sort := f1 \; g1 \; h1; + InternalHomHom.class := x + |} = + {| + InternalHomHom.sort := (f1 \; g1) \; h1; + InternalHomHom.class := y + |} ) as A2. + { rewrite Heqf1; simpl. + rewrite compoA. + intros. + destruct x as [X]. + destruct y as [Y]. + destruct X. + destruct Y. + + assert (hom_src3 = hom_src4) as D1. + { eapply Prop_irrelevance. } + + assert (hom_tgt3 = hom_tgt4) as D2. + { eapply Prop_irrelevance. } + + rewrite D1. + rewrite D2. + reflexivity. + }. + + setoid_rewrite A2. + reflexivity. +Qed. + +Program Definition iHom_cat {C: pbcat} (C0 : C) : + PreCat_IsCat (@iHom C C0) := + PreCat_IsCat.Build (@iHom C C0) _ _ _. +Obligation 1. +eapply iHom_LeftUnit_lemma; eauto. +Qed. +Obligation 2. +eapply iHom_RightUnit_lemma; eauto. +Qed. +Obligation 3. +eapply iHom_Assoc_lemma; eauto. +Qed. + + +(* PROBLEM: this morphism cannot exist, as the target of the product + isn't generally the same as the target of the first projection. + Similarly, the source of the product can be different from the + source of the sencond projection. *) +(* +Definition iprodlC0 {C: pbcat} {C0 : C} (X Y : iHom C0) : + pbC0 X Y ~>_(iHom C0) X. + assert (@src C C0 (pbC0 X Y) = (iprodl X Y) \; @src C C0 X) as A1. + { auto. } + assert (@tgt C C0 (pbC0 X Y) = (iprodr X Y) \; @tgt C C0 Y) as A2. + { auto. } +Admitted. +Definition iprodrC0 {C: pbcat} {C0 : C} (X Y : iHom C0) : + pbC0 X Y ~>_(iHom C0) Y. +Admitted. +*) + +(* Now we define an internal quiver as an object C0, + which has a C1 : iHom C0 attached to it *) +HB.mixin Record IsPreInternalQuiver (C : quiver) (C0 : obj C) := + { C1 : obj C }. +HB.structure Definition PreInternalQuiver C := + { C0 of @IsPreInternalQuiver C C0 }. + +Arguments C1 {C s}. + +#[wrapper] HB.mixin Record IsInternalQuiver (C : quiver) (C0 : obj C) of + @PreInternalQuiver C C0 := { + priv: @InternalHom C C0 (@C1 _ C0) + }. +#[short(type="iquiver")] +HB.structure Definition InternalQuiver (C : quiver) := + { C0 of IsInternalQuiver C C0 }. + +Coercion iquiver_quiver (C : quiver) (C0 : iquiver C) : C := C0 :> C. +Coercion iquiver_precat (C : precat) (C0 : iquiver C) : C := C0 :> C. +Coercion iquiver_cat (C : cat) (C0 : iquiver C) : C := C0 :> C. + +Lemma ihom_morph (C : pbcat) (C0 : C) (a b: iHom C0) (f: a ~>_(iHom C0) b) : + (a :> C) ~>_C (b :> C). + simpl. + destruct a. + destruct b. + destruct f. + simpl in *. + exact sort1. +Defined. + +(* nested product *) +Program Definition iprodIAsc {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : + ((C1 *_C0 C2 : iHom C0) *_C0 C3 : iHom C0) ~>_(iHom C0) + (C1 *_C0 (C2 *_C0 C3 : iHom C0) : iHom C0). + (* := ... *) + (* OK define it with the universal arrow of the pullback *) +Admitted. + +Program Definition iprodCAsc {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : + (((C1 *_C0 C2 : iHom C0) *_C0 C3) :> C) ~>_C + ((C1 *_C0 (C2 *_C0 C3 : iHom C0) : iHom C0) :> C). +eapply ihom_morph. +eapply iprodIAsc; eauto. +Defined. + +Lemma pbsquare_universal {C: cat} (A B T P0 P1 : C) + (t: A ~> T) (s: B ~> T) (p1: P0 ~> A) (p2: P0 ~> B) + (f: P1 ~> A) (g: P1 ~> B) : + pbsquare p1 p2 t s -> + f \; t = g \; s -> + sigma m: P1 ~> P0, f = m \; p1 /\ g = m \; p2. + intros sq E. + destruct sq as [IM1 IM2]. + + remember (Span p1 p2) as Spn0. + remember (@Cospan C A B T t s) as Csp. + remember (@Span C A B P1 f g) as Spn1. + +(* unfold Span in HeqSpn0. *) + + destruct IM1 as [IM3]. + destruct IM2 as [IM4]. + + assert (bot2left Spn1 \; left2top Csp = bot2right Spn1 \; right2top Csp) + as K1. + { unfold bot2left, bot2right. + rewrite HeqCsp. + rewrite HeqSpn1. + simpl; auto. + } + remember ( @isPrePullback.Build C A B Csp Spn1 K1) as Pb1. + assert (PrePullback.axioms_ Csp Spn1) as Pb2. + { econstructor. + exact Pb1. } + remember ( @PrePullback.Pack C A B Csp Spn1 Pb2) as PB. + + destruct IM4 as [IM5 IM6]. + clear IM6. + specialize (IM5 PB). + + inversion HeqSpn1; subst. + simpl in *. + clear H K1. + + unfold pb_terminal in *. + destruct Pb2 as [IM]. + destruct IM. + simpl in *. + + destruct IM5. + simpl in *. + + econstructor. + instantiate (1:= bot_map0). + split; auto. +Qed. + +Lemma pbquare_universal_aux1 {C: cat} (A0 A1 B0 B1 P0 P1 T : C) + (t: A0 ~> T) (s: B0 ~> T) (p01: P0 ~> A0) (p02: P0 ~> B0) + (f: A1 ~> A0) (g: B1 ~> B0) (p11: P1 ~> A1) (p12: P1 ~> B1) : + pbsquare p01 p02 t s -> + p11 \; f \; t = p12 \; g \; s -> + sigma m: P1 ~> P0, p11 \; f = m \; p01 /\ p12 \; g = m \; p02. + intros. + eapply pbsquare_universal; eauto. + setoid_rewrite <- compoA; auto. +Qed. + +(* Lemma is_pullback_in_pbcat {C: pbcat} *) + +(* product morphism *) +Program Definition ipairI {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} + (f : x0 ~> x2) (g : x1 ~> x3) : + (x0 *_C0 x1 : iHom C0) ~>_(iHom C0) (x2 *_C0 x3 : iHom C0). + unfold iprod. + unfold iprod_pb. + + remember (@Cospan C (x0 :> C) (x1 :> C) _ tgt src) as Csp1. + + remember (@Cospan C (x2 :> C) (x3 :> C) _ tgt src) as Csp2. + + remember (pbk (x0 :> C) (x1 :> C) Csp1) as Sp1. + remember (pbk (x2 :> C) (x3 :> C) Csp2) as Sp2. + + assert (@Pullback C (x0 :> C) (x1 :> C) Csp1 Sp1). + admit. + + assert (@Pullback C (x2 :> C) (x3 :> C) Csp2 Sp2). + admit. + + assert (@tgt C C0 x0 = (f : (x0 :> C) ~>_C (x2 :> C)) \; @tgt C C0 x2). + admit. + + assert (@src C C0 x1 = (g : (x1 :> C) ~>_C (x3 :> C)) \; @src C C0 x3). + admit. + + assert (bot2left Sp1 \; (f : (x0 :> C) ~>_C (x2 :> C)) \; @tgt C C0 x2 = + bot2right Sp1 \; (g : (x1 :> C) ~>_C (x3 :> C)) \; @src C C0 x3). + admit. +Admitted. + +Program Definition ipairC {C : pbcat} {C0 : C} {C1 C2 C3 C4 : iHom C0} + (f : C1 ~> C3) (g : C2 ~> C4) : + ((C1 *_C0 C2) :> C) ~>_C ((C3 *_C0 C4) :> C). +eapply ihom_morph. +eapply ipairI; eauto. +Defined. + +Notation "<( f , g )>" := (ipairI f g). +Notation "<(' f , g )>" := (ipairC f g). + +(* An internal precategory is an internal category with two operators + that must be src and tgt preserving, i.e. iHom morphisms: identity + : C0 -> C1 (corresponding to horizontal 1-morphism identity in + double cat) and composition : C1 * C1 -> C1 (corresponding to + horizontal composition) *) +HB.mixin Record IsInternalPreCat (C : pbcat) (C0 : obj C) + of @InternalQuiver C C0 := { + iidI : (C0 : iHom C0) ~>_(iHom C0) (@C1 C C0 : iHom C0); + icompI : let C1 := @C1 C C0 : iHom C0 in + let C2 := pbC0 C1 C1 : iHom C0 in + (C2 ~>_(iHom C0) C1) +}. +#[short(type="iprecat")] +HB.structure Definition InternalPreCat (C : pbcat) := + { C0 of @IsInternalPreCat C C0 }. + +Program Definition iidC' {C : pbcat} {C0 : iprecat C} : + ((C0 : iHom C0) :> C) ~>_C + ((@C1 C C0 : iHom C0) :> C). +destruct C0; simpl in *. +destruct class as [IM1 IM2 IM3]; simpl in *. +destruct IM3; simpl in *. +exact iidI0. +Defined. +Program Definition iidC {C : pbcat} {C0 : iprecat C} : + (C0 :> C) ~>_C (@C1 C C0 :> C). +eapply iidC'; eauto. +Defined. + +Program Definition icompC {C : pbcat} {C0 : iprecat C} : + let C1 := @C1 C C0 : iHom C0 in + let C2 := pbC0 C1 C1 : iHom C0 in + ((C2 :> C) ~>_C (C1 :> C)). +destruct C0; simpl in *. +destruct class as [IM1 IM2 IM3]; simpl in *. +destruct IM3; simpl in *. +exact icompI0. +Defined. + +(* Check (iquiver Type <~> quiver). *) +(* Check (iprecat Type <~> precat). *) + +(* An internal category moreover must satisfy additional properies on iid and icomp +(associativity and unit laws) *) +#[key="C0"] + HB.mixin Record IsInternalCat (C : pbcat) (C0 : obj C) + of InternalPreCat C C0 := { + + icompA1 : + (<( (@icompI C C0), + (@idmap (iHom C0) (@C1 C C0: iHom C0)) )> \; icompI) = + ((@iprodIAsc C C0 (@C1 C C0: iHom C0) _ _) \; + <( (@idmap (iHom C0) (@C1 C C0: iHom C0)), icompI )> \; icompI) ; + + icomp1l : <(' @idmap (iHom C0) (@C1 C C0: iHom C0), (@iidI C C0) )> \; + icompC = @iprodl C C0 (C1 :> C) (C0 :> C); + + icomp1r : <(' (@iidI C C0), @idmap (iHom C0) (@C1 C C0: iHom C0) )> \; + icompC = @iprodr C C0 (C0 :> C) (C1 :> C); + }. +#[short(type="icat")] +HB.structure Definition InternalCat (C : pbcat) := + {C0 of @IsInternalCat C C0}. +(* Check (icat Type <~> cat). *) + + +(* A double category is an internal category in cat + - The objects are the objects of C0 + - The vertical maps are the maps of C0 + - The horizontal maps are the objects of C1 + - The 2-cells are the maps of C1 + + About identities: + - The identity vertical map on (x : C) is \idmap_x + - The identity horizontal map on (x : C) is iid x + - the identity 2-cell on (x : C) is iid (\idmap_x) = \idmap_(iid x) + + About compositions: + - The vertical composition of maps is the composition of C0 + - The vertical compositions of 2-cells is the composition of C1 + (and it agrees with the former because src and tgt are functors + and because iid is a iHom-map) + - The horizontal composition of maps is the object part of icomp + - The horizontal composition of 2-cells is the map part of icomp +*) +(* HB.structure' Definition DoubleCat := @InternalCat cat. *) +Axiom cat_pbop : HasPBop cat. +HB.instance Definition _ := cat_pbop. + +Axiom cat_preb : + forall (a b: cat) (c: cospan a b), isPrePullback cat a b c (@pbk cat a b c). +HB.instance Definition _ (a b: cat) (c: cospan a b) := @cat_preb a b c. +Axiom cat_pb : + forall (a b: cat) (c: cospan a b), + prepullback_isTerminal cat a b c (@pbk cat a b c). +HB.instance Definition _ (a b: cat) (c: cospan a b) := @cat_pb a b c. + +(* basically, the internal category adds the D1 category to the base +D0 category, which is C0 (an object of cat, which is shown to have +pullbacks) *) +Definition doublecat := icat cat. + +(* Check (doublecat <~> ???) *) + From f1325d77465924e3048d6d08d87f9f4d799b969b Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Fri, 15 Dec 2023 19:55:33 +0100 Subject: [PATCH 109/147] updated encatI.v --- theories/encatI.v | 103 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 92 insertions(+), 11 deletions(-) diff --git a/theories/encatI.v b/theories/encatI.v index 28765a2e2..e4f68b4fc 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -1435,7 +1435,7 @@ basically, we recast morphisms in (obj C) into some in (@iHom C C0), i.e. into morphism between copies of C1 *) HB.mixin Record IsInternalHomHom {C: pbcat} (C0 : C) (C1 C1' : @iHom C C0) (f : (C1 :> C) ~> (C1' :> C)) := { - hom_src : f \; src = src; + hom_src : f \; (@src C C0 C1') = (@src C C0 C1); hom_tgt : f \; tgt = tgt; }. #[short(type="iHomHom")] @@ -1838,37 +1838,118 @@ Qed. (* Lemma is_pullback_in_pbcat {C: pbcat} *) +(* +Set Debug "unification". +Lemma ... +Proof. + Fail ... +*) + (* product morphism *) Program Definition ipairI {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} - (f : x0 ~> x2) (g : x1 ~> x3) : + (f : x0 ~>_(iHom C0) x2) (g : x1 ~>_(iHom C0) x3) : (x0 *_C0 x1 : iHom C0) ~>_(iHom C0) (x2 *_C0 x3 : iHom C0). - unfold iprod. - unfold iprod_pb. - remember (@Cospan C (x0 :> C) (x1 :> C) _ tgt src) as Csp1. + remember (x0 *_ C0 x1 : iHom C0) as Pb1. + remember (x2 *_ C0 x3 : iHom C0) as Pb2. - remember (@Cospan C (x2 :> C) (x3 :> C) _ tgt src) as Csp2. + remember (@Cospan C (x0 :> C) (x1 :> C) C0 + (@tgt C C0 x0) (@src C C0 x1)) as Csp1. + + remember (@Cospan C (x2 :> C) (x3 :> C) C0 + (@tgt C C0 x2) (@src C C0 x3)) as Csp2. remember (pbk (x0 :> C) (x1 :> C) Csp1) as Sp1. remember (pbk (x2 :> C) (x3 :> C) Csp2) as Sp2. - assert (@Pullback C (x0 :> C) (x1 :> C) Csp1 Sp1). + assert (@Pullback C (x0 :> C) (x1 :> C) Csp1 Sp1) as PBa1. admit. - assert (@Pullback C (x2 :> C) (x3 :> C) Csp2 Sp2). + assert (@Pullback C (x2 :> C) (x3 :> C) Csp2 Sp2) as PBa2. admit. - assert (@tgt C C0 x0 = (f : (x0 :> C) ~>_C (x2 :> C)) \; @tgt C C0 x2). + assert (((x0 *_ C0 x1) :> C) = bot Sp1) as Sp1_eq. + { unfold iprod. + unfold iprod_pb. + rewrite HeqSp1. + rewrite HeqCsp1. + auto. + } + + assert (((x2 *_ C0 x3) :> C) = bot Sp2) as Sp2_eq. + { unfold iprod. + unfold iprod_pb. + rewrite HeqSp2. + rewrite HeqCsp2. + auto. + } + + assert (@tgt C C0 x0 = (f : (x0 :> C) ~>_C (x2 :> C)) \; @tgt C C0 x2) as E1. admit. - assert (@src C C0 x1 = (g : (x1 :> C) ~>_C (x3 :> C)) \; @src C C0 x3). + assert (@src C C0 x1 = (g : (x1 :> C) ~>_C (x3 :> C)) \; @src C C0 x3) as E2. admit. assert (bot2left Sp1 \; (f : (x0 :> C) ~>_C (x2 :> C)) \; @tgt C C0 x2 = - bot2right Sp1 \; (g : (x1 :> C) ~>_C (x3 :> C)) \; @src C C0 x3). + bot2right Sp1 \; (g : (x1 :> C) ~>_C (x3 :> C)) \; @src C C0 x3) + as E3. + admit. + + assert (sigma m: bot Sp1 ~>_C bot Sp2, bot2left Sp1 \; f = + m \; bot2left Sp2 /\ + bot2right Sp1 \; g = m \; bot2right Sp2) as E4. + admit. + + destruct E4 as [m4 E44]. + destruct E44 as [A41 A42]. + + assert (sigma m: ((x0 *_ C0 x1) :> C) ~>_C ((x2 *_ C0 x3) :> C), + (@iprodl C C0 x0 x1) \; f = m \; (@iprodl C C0 x2 x3) /\ + (@iprodr C C0 x0 x1) \; g = m \; (@iprodr C C0 x2 x3)) as E5. + admit. + + destruct E5 as [m5 E55]. + destruct E55 as [A51 A52]. + + assert ((x0 :> C) ~>_C C0) as tgt1. + { destruct Csp1 as [u v z]. + inversion HeqCsp1; subst. + exact v. + } + + assert ((x1 :> C) ~>_C C0) as src1. + { destruct Csp1 as [u v z]. + inversion HeqCsp1; subst. + exact z. + } + + assert (@isInternalHom C C0 (bot Sp1)) as MM. + { exact (@isInternalHom.Build C C0 (bot Sp1) + (bot2left Sp1 \; tgt1) (bot2right Sp1 \; src1)). } + + assert (@InternalHom C C0 (bot Sp1)) as MM1. + { eapply (InternalHom.Pack (InternalHom.Class MM)). } + + assert ((Pb1 :> C) ~>_C (Pb2 :> C)) as V. + { rewrite HeqPb1. + rewrite HeqPb2. + rewrite Sp1_eq. + rewrite Sp2_eq. + simpl. + eapply m5. + } + + econstructor. + instantiate (1:= V). + + econstructor. + econstructor. + + assert (@src C C0 (x0 *_ C0 x1 : iHom C0) = (@iprodl C C0 x0 x1) \; src). admit. Admitted. + Program Definition ipairC {C : pbcat} {C0 : C} {C1 C2 C3 C4 : iHom C0} (f : C1 ~> C3) (g : C2 ~> C4) : ((C1 *_C0 C2) :> C) ~>_C ((C3 *_C0 C4) :> C). From 527dd0ffadac451ff444f1c8951037eee8068e3d Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Mon, 18 Dec 2023 18:13:34 +0100 Subject: [PATCH 110/147] updated encatI.v --- theories/encatI.v | 191 +++++++++++++++------------------------------- 1 file changed, 63 insertions(+), 128 deletions(-) diff --git a/theories/encatI.v b/theories/encatI.v index e4f68b4fc..f4a47f071 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -1709,24 +1709,6 @@ Obligation 3. eapply iHom_Assoc_lemma; eauto. Qed. - -(* PROBLEM: this morphism cannot exist, as the target of the product - isn't generally the same as the target of the first projection. - Similarly, the source of the product can be different from the - source of the sencond projection. *) -(* -Definition iprodlC0 {C: pbcat} {C0 : C} (X Y : iHom C0) : - pbC0 X Y ~>_(iHom C0) X. - assert (@src C C0 (pbC0 X Y) = (iprodl X Y) \; @src C C0 X) as A1. - { auto. } - assert (@tgt C C0 (pbC0 X Y) = (iprodr X Y) \; @tgt C C0 Y) as A2. - { auto. } -Admitted. -Definition iprodrC0 {C: pbcat} {C0 : C} (X Y : iHom C0) : - pbC0 X Y ~>_(iHom C0) Y. -Admitted. -*) - (* Now we define an internal quiver as an object C0, which has a C1 : iHom C0 attached to it *) HB.mixin Record IsPreInternalQuiver (C : quiver) (C0 : obj C) := @@ -1748,30 +1730,11 @@ Coercion iquiver_quiver (C : quiver) (C0 : iquiver C) : C := C0 :> C. Coercion iquiver_precat (C : precat) (C0 : iquiver C) : C := C0 :> C. Coercion iquiver_cat (C : cat) (C0 : iquiver C) : C := C0 :> C. -Lemma ihom_morph (C : pbcat) (C0 : C) (a b: iHom C0) (f: a ~>_(iHom C0) b) : - (a :> C) ~>_C (b :> C). - simpl. - destruct a. - destruct b. - destruct f. - simpl in *. - exact sort1. -Defined. - (* nested product *) -Program Definition iprodIAsc {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : - ((C1 *_C0 C2 : iHom C0) *_C0 C3 : iHom C0) ~>_(iHom C0) - (C1 *_C0 (C2 *_C0 C3 : iHom C0) : iHom C0). - (* := ... *) - (* OK define it with the universal arrow of the pullback *) -Admitted. - Program Definition iprodCAsc {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : (((C1 *_C0 C2 : iHom C0) *_C0 C3) :> C) ~>_C ((C1 *_C0 (C2 *_C0 C3 : iHom C0) : iHom C0) :> C). -eapply ihom_morph. -eapply iprodIAsc; eauto. -Defined. +Admitted. Lemma pbsquare_universal {C: cat} (A B T P0 P1 : C) (t: A ~> T) (s: B ~> T) (p1: P0 ~> A) (p2: P0 ~> B) @@ -1786,8 +1749,6 @@ Lemma pbsquare_universal {C: cat} (A B T P0 P1 : C) remember (@Cospan C A B T t s) as Csp. remember (@Span C A B P1 f g) as Spn1. -(* unfold Span in HeqSpn0. *) - destruct IM1 as [IM3]. destruct IM2 as [IM4]. @@ -1845,10 +1806,10 @@ Proof. Fail ... *) -(* product morphism *) -Program Definition ipairI {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} + +Program Definition ipairC {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} (f : x0 ~>_(iHom C0) x2) (g : x1 ~>_(iHom C0) x3) : - (x0 *_C0 x1 : iHom C0) ~>_(iHom C0) (x2 *_C0 x3 : iHom C0). + (x0 *_C0 x1 :> C) ~>_C (x2 *_C0 x3 :> C). remember (x0 *_ C0 x1 : iHom C0) as Pb1. remember (x2 *_ C0 x3 : iHom C0) as Pb2. @@ -1858,107 +1819,83 @@ Program Definition ipairI {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} remember (@Cospan C (x2 :> C) (x3 :> C) C0 (@tgt C C0 x2) (@src C C0 x3)) as Csp2. + + remember (@src C C0 x0) as src0. + remember (@tgt C C0 x0) as tgt0. + + remember (@src C C0 x1) as src1. + remember (@tgt C C0 x1) as tgt1. + + remember (@src C C0 x2) as src2. + remember (@tgt C C0 x2) as tgt2. + + remember (@src C C0 x3) as src3. + remember (@tgt C C0 x3) as tgt3. + + remember (@src C C0 (x0 *_C0 x1)) as src01. + remember (@tgt C C0 (x0 *_C0 x1)) as tgt01. + remember (@src C C0 (x2 *_C0 x3)) as src23. + remember (@tgt C C0 (x2 *_C0 x3)) as tgt23. + remember (pbk (x0 :> C) (x1 :> C) Csp1) as Sp1. remember (pbk (x2 :> C) (x3 :> C) Csp2) as Sp2. + (* follows from def of Sp1, Sp2 *) assert (@Pullback C (x0 :> C) (x1 :> C) Csp1 Sp1) as PBa1. admit. assert (@Pullback C (x2 :> C) (x3 :> C) Csp2 Sp2) as PBa2. admit. - assert (((x0 *_ C0 x1) :> C) = bot Sp1) as Sp1_eq. - { unfold iprod. + assert ((x0 *_ C0 x1) = bot Sp1) as E01. + { subst Sp1. + unfold iprod. unfold iprod_pb. - rewrite HeqSp1. rewrite HeqCsp1. + subst tgt0. + subst src1. auto. - } + } - assert (((x2 *_ C0 x3) :> C) = bot Sp2) as Sp2_eq. - { unfold iprod. + assert ((x2 *_ C0 x3) = bot Sp2) as E23. + { subst Sp2. + unfold iprod. unfold iprod_pb. - rewrite HeqSp2. rewrite HeqCsp2. + subst tgt2. + subst src3. auto. - } + } - assert (@tgt C C0 x0 = (f : (x0 :> C) ~>_C (x2 :> C)) \; @tgt C C0 x2) as E1. - admit. + set (prj11 := @iprodl C C0 x0 x1). + set (prj12 := @iprodr C C0 x0 x1). - assert (@src C C0 x1 = (g : (x1 :> C) ~>_C (x3 :> C)) \; @src C C0 x3) as E2. - admit. - - assert (bot2left Sp1 \; (f : (x0 :> C) ~>_C (x2 :> C)) \; @tgt C C0 x2 = - bot2right Sp1 \; (g : (x1 :> C) ~>_C (x3 :> C)) \; @src C C0 x3) - as E3. - admit. + set (prj21 := @iprodl C C0 x2 x3). + set (prj22 := @iprodr C C0 x2 x3). - assert (sigma m: bot Sp1 ~>_C bot Sp2, bot2left Sp1 \; f = - m \; bot2left Sp2 /\ - bot2right Sp1 \; g = m \; bot2right Sp2) as E4. - admit. + set (ff := prj11 \; f). + set (gg := prj12 \; g). - destruct E4 as [m4 E44]. - destruct E44 as [A41 A42]. - - assert (sigma m: ((x0 *_ C0 x1) :> C) ~>_C ((x2 *_ C0 x3) :> C), - (@iprodl C C0 x0 x1) \; f = m \; (@iprodl C C0 x2 x3) /\ - (@iprodr C C0 x0 x1) \; g = m \; (@iprodr C C0 x2 x3)) as E5. + (* follows from f being in iHomHom, so + f \; tgt2 = tgt0 + g \; src3 = src1 + and Pb1 being a pullback, so + prj11 \; tgt0 = prj12 \; src1 *) + assert (ff \; tgt2 = gg \; src3) as E1. admit. - destruct E5 as [m5 E55]. - destruct E55 as [A51 A52]. - - assert ((x0 :> C) ~>_C C0) as tgt1. - { destruct Csp1 as [u v z]. - inversion HeqCsp1; subst. - exact v. - } - - assert ((x1 :> C) ~>_C C0) as src1. - { destruct Csp1 as [u v z]. - inversion HeqCsp1; subst. - exact z. - } - - assert (@isInternalHom C C0 (bot Sp1)) as MM. - { exact (@isInternalHom.Build C C0 (bot Sp1) - (bot2left Sp1 \; tgt1) (bot2right Sp1 \; src1)). } - - assert (@InternalHom C C0 (bot Sp1)) as MM1. - { eapply (InternalHom.Pack (InternalHom.Class MM)). } - - assert ((Pb1 :> C) ~>_C (Pb2 :> C)) as V. - { rewrite HeqPb1. - rewrite HeqPb2. - rewrite Sp1_eq. - rewrite Sp2_eq. - simpl. - eapply m5. - } - - econstructor. - instantiate (1:= V). - - econstructor. - econstructor. - - assert (@src C C0 (x0 *_ C0 x1 : iHom C0) = (@iprodl C C0 x0 x1) \; src). + (* follows from pbquare_universal_aux1 and E1 *) + assert (sigma m: ((x0 *_ C0 x1) ~>_C (x2 *_ C0 x3) :> C), + ff = m \; prj21 /\ gg = m \; prj22) as EM. admit. -Admitted. + destruct EM as [mm [EM1 EM2]]. -Program Definition ipairC {C : pbcat} {C0 : C} {C1 C2 C3 C4 : iHom C0} - (f : C1 ~> C3) (g : C2 ~> C4) : - ((C1 *_C0 C2) :> C) ~>_C ((C3 *_C0 C4) :> C). -eapply ihom_morph. -eapply ipairI; eauto. -Defined. - -Notation "<( f , g )>" := (ipairI f g). -Notation "<(' f , g )>" := (ipairC f g). + exact mm. +Admitted. + +Notation "<( f , g )>" := (ipairC f g). (* An internal precategory is an internal category with two operators that must be src and tgt preserving, i.e. iHom morphisms: identity @@ -1999,25 +1936,24 @@ destruct IM3; simpl in *. exact icompI0. Defined. -(* Check (iquiver Type <~> quiver). *) +(* Check (iquiver Type <~> quiver). *) (* Check (iprecat Type <~> precat). *) -(* An internal category moreover must satisfy additional properies on iid and icomp -(associativity and unit laws) *) +(* An internal category moreover must satisfy additional properies on +iid and icomp (associativity and unit laws) *) #[key="C0"] HB.mixin Record IsInternalCat (C : pbcat) (C0 : obj C) of InternalPreCat C C0 := { - icompA1 : (<( (@icompI C C0), - (@idmap (iHom C0) (@C1 C C0: iHom C0)) )> \; icompI) = - ((@iprodIAsc C C0 (@C1 C C0: iHom C0) _ _) \; - <( (@idmap (iHom C0) (@C1 C C0: iHom C0)), icompI )> \; icompI) ; + (@idmap (iHom C0) (@C1 C C0: iHom C0)) )> \; icompC) = + ((@iprodCAsc C C0 (@C1 C C0: iHom C0) _ _) \; + <( (@idmap (iHom C0) (@C1 C C0: iHom C0)), icompI )> \; icompC) ; - icomp1l : <(' @idmap (iHom C0) (@C1 C C0: iHom C0), (@iidI C C0) )> \; + icomp1l : <( @idmap (iHom C0) (@C1 C C0: iHom C0), (@iidI C C0) )> \; icompC = @iprodl C C0 (C1 :> C) (C0 :> C); - icomp1r : <(' (@iidI C C0), @idmap (iHom C0) (@C1 C C0: iHom C0) )> \; + icomp1r : <( (@iidI C C0), @idmap (iHom C0) (@C1 C C0: iHom C0) )> \; icompC = @iprodr C C0 (C0 :> C) (C1 :> C); }. #[short(type="icat")] @@ -2025,7 +1961,6 @@ HB.structure Definition InternalCat (C : pbcat) := {C0 of @IsInternalCat C C0}. (* Check (icat Type <~> cat). *) - (* A double category is an internal category in cat - The objects are the objects of C0 - The vertical maps are the maps of C0 From c820234f978a0aba8f791089dfb2dcb99c712c28 Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Mon, 18 Dec 2023 19:28:11 +0100 Subject: [PATCH 111/147] updated encatI.v --- theories/encatI.v | 139 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 138 insertions(+), 1 deletion(-) diff --git a/theories/encatI.v b/theories/encatI.v index f4a47f071..f72d9238f 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -1806,7 +1806,143 @@ Proof. Fail ... *) +Program Definition ipairC {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} + (f : x0 ~>_(iHom C0) x2) (g : x1 ~>_(iHom C0) x3) : + (x0 *_C0 x1 :> C) ~>_C (x2 *_C0 x3 :> C). + + remember (x0 *_ C0 x1 : iHom C0) as Pb1. + remember (x2 *_ C0 x3 : iHom C0) as Pb2. + + remember (@Cospan C (x0 :> C) (x1 :> C) C0 + (@tgt C C0 x0) (@src C C0 x1)) as Csp1. + + remember (@Cospan C (x2 :> C) (x3 :> C) C0 + (@tgt C C0 x2) (@src C C0 x3)) as Csp2. + + set (src0 := @src C C0 x0). + set (tgt0 := @tgt C C0 x0). + + set (src1 := @src C C0 x1). + set (tgt1 := @tgt C C0 x1). + + set (src2 := @src C C0 x2). + set (tgt2 := @tgt C C0 x2). + + set (src3 := @src C C0 x3). + set (tgt3 := @tgt C C0 x3). + + remember (@src C C0 (x0 *_C0 x1)) as src01. + remember (@tgt C C0 (x0 *_C0 x1)) as tgt01. + + remember (@src C C0 (x2 *_C0 x3)) as src23. + remember (@tgt C C0 (x2 *_C0 x3)) as tgt23. + + set (Sp1 := pbk (x0 :> C) (x1 :> C) Csp1). + set (Sp2 := pbk (x2 :> C) (x3 :> C) Csp2). + + (* follows from def of Sp1, Sp2 *) +(* assert (@pb (pbk (x0 :> C) (x1 :> C) Csp1)) as PBa1. + { remember C as C'. + destruct C as [C class]. + destruct class as [A1 A2 A3 A4 A5 A6]. + destruct A6 as [B1]. + inversion HeqC'; subst. + auto. + } + + assert (@pb (pbk (x2 :> C) (x3 :> C) Csp2)) as PBa2. + { remember C as C'. + destruct C as [C class]. + destruct class as [A1 A2 A3 A4 A5 A6]. + destruct A6 as [B1]. + inversion HeqC'; subst. + auto. + } + *) + + assert (@Pullback C (x0 :> C) (x1 :> C) Csp1 Sp1) as PBa1. + { remember C as C'. + destruct C as [C class]. + destruct class as [A1 A2 A3 A4 A5 A6]. + destruct A6 as [B1]. + assert (pb (pbk (x0 :> C') (x1 :> C') Csp1)). + inversion HeqC'; subst. + eapply B1; eauto. + econstructor; eauto. + } + + assert ((x0 *_ C0 x1) = bot Sp1) as E01. + { subst Sp1. + unfold iprod. + unfold iprod_pb. + rewrite HeqCsp1; auto. + } + + assert ((x2 *_ C0 x3) = bot Sp2) as E23. + { subst Sp2. + unfold iprod. + unfold iprod_pb. + rewrite HeqCsp2; auto. + } + + set (prj11 := @iprodl C C0 x0 x1). + set (prj12 := @iprodr C C0 x0 x1). + + set (prj21 := @iprodl C C0 x2 x3). + set (prj22 := @iprodr C C0 x2 x3). + + set (ff := prj11 \; f). + set (gg := prj12 \; g). + + assert ((f : (x0 :> C) ~>_C (x2 :> C)) \; tgt2 = tgt0) as E20. + { remember f as f1. + destruct f as [fsort fclass]. + destruct fclass as [fIM]. + destruct fIM. + inversion Heqf1; subst. + simpl in *; simpl. + auto. + } + + assert ((g : (x1 :> C) ~>_C (x3 :> C)) \; src3 = src1) as E31. + { remember g as g1. + destruct g as [gsort gclass]. + destruct gclass as [gIM]. + destruct gIM. + inversion Heqg1; subst. + simpl in *; simpl. + auto. + } + assert (prj11 \; tgt0 = prj12 \; src1) as E11. + { destruct PBa1 as [C1 C2]. + destruct C1 as [C3]. + inversion HeqCsp1; subst. + simpl in *. + auto. + } + + assert (ff \; tgt2 = gg \; src3) as E1. + { subst ff gg. + setoid_rewrite <- compoA. + rewrite E20. + rewrite E31. + exact E11. + } + + (* follows from pbquare_universal_aux1 and E1 *) + assert (sigma m: ((x0 *_ C0 x1) ~>_C (x2 *_ C0 x3) :> C), + ff = m \; prj21 /\ gg = m \; prj22) as EM. + { eapply (@pbsquare_universal C) ; eauto. + admit. + } + + destruct EM as [mm [EM1 EM2]]. + + exact mm. +Admitted. + +(* Program Definition ipairC {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} (f : x0 ~>_(iHom C0) x2) (g : x1 ~>_(iHom C0) x3) : (x0 *_C0 x1 :> C) ~>_C (x2 *_C0 x3 :> C). @@ -1894,7 +2030,8 @@ Program Definition ipairC {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} exact mm. Admitted. - +*) + Notation "<( f , g )>" := (ipairC f g). (* An internal precategory is an internal category with two operators From 1e0aa1b24460a2735714d6a195b93bdf719d4939 Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Tue, 19 Dec 2023 17:54:10 +0100 Subject: [PATCH 112/147] updated encatI.v --- theories/encatI.v | 199 +++++++++++++++++++--------------------------- 1 file changed, 80 insertions(+), 119 deletions(-) diff --git a/theories/encatI.v b/theories/encatI.v index f72d9238f..f85d4e388 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -1806,6 +1806,55 @@ Proof. Fail ... *) +Lemma pbk_eta {C: pbcat} {C0} (X Y: iHom C0) : + (pbk (X :> C) (Y :> C) (Cospan (@tgt C C0 X) (@src C C0 Y))) = + (Span (iprodl X Y) (iprodr X Y)). + unfold iprodl. + unfold iprodr. + unfold iprod_pb. + assert ((X *_C0 Y :> C) = (bot (pbk (X :> C) (Y :> C) {| top := C0; left2top := tgt; right2top := src |}))) + as A1. + { unfold iprod. + simpl. + unfold iprod_pb. + auto. + } + simpl. + + unfold iprod. + unfold iprod_pb. + simpl. + + generalize (pbk (X :> C) (Y :> C) {| top := C0; left2top := tgt; right2top := src |}). + + intros. + destruct s0. + simpl; auto. +Qed. + +Lemma pbk_pullback_is_pullback {C: pbcat} {C0} (X Y: iHom C0) : + Pullback C (Cospan (@tgt C C0 X) (@src C C0 Y)) + (pbk (X :> C) (Y :> C) (Cospan (@tgt C C0 X) (@src C C0 Y))) = + Pullback C (Cospan (@tgt C C0 X) (@src C C0 Y)) + (Span (iprodl X Y) (iprodr X Y)). + rewrite pbk_eta. + auto. +Qed. + +Lemma pbsquare_is_pullback_sym {C: pbcat} {C0} (X Y: iHom C0) : + Pullback C (Cospan (@tgt C C0 X) (@src C C0 Y)) + (pbk (X :> C) (Y :> C) (Cospan (@tgt C C0 X) (@src C C0 Y))) = + pbsquare (iprodl X Y) (iprodr X Y) (@tgt C C0 X) (@src C C0 Y). + rewrite pbk_pullback_is_pullback; auto. +Qed. + +Lemma pbsquare_is_pullback {C: pbcat} {C0} (X Y: iHom C0) : + pbsquare (iprodl X Y) (iprodr X Y) (@tgt C C0 X) (@src C C0 Y) = + Pullback C (Cospan (@tgt C C0 X) (@src C C0 Y)) + (pbk (X :> C) (Y :> C) (Cospan (@tgt C C0 X) (@src C C0 Y))). + rewrite pbk_pullback_is_pullback; auto. +Qed. + Program Definition ipairC {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} (f : x0 ~>_(iHom C0) x2) (g : x1 ~>_(iHom C0) x3) : (x0 *_C0 x1 :> C) ~>_C (x2 *_C0 x3 :> C). @@ -1840,37 +1889,31 @@ Program Definition ipairC {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} set (Sp1 := pbk (x0 :> C) (x1 :> C) Csp1). set (Sp2 := pbk (x2 :> C) (x3 :> C) Csp2). - (* follows from def of Sp1, Sp2 *) -(* assert (@pb (pbk (x0 :> C) (x1 :> C) Csp1)) as PBa1. - { remember C as C'. - destruct C as [C class]. - destruct class as [A1 A2 A3 A4 A5 A6]. - destruct A6 as [B1]. - inversion HeqC'; subst. - auto. - } - - assert (@pb (pbk (x2 :> C) (x3 :> C) Csp2)) as PBa2. + assert (@Pullback C (x0 :> C) (x1 :> C) Csp1 Sp1) as PBa1. { remember C as C'. destruct C as [C class]. destruct class as [A1 A2 A3 A4 A5 A6]. destruct A6 as [B1]. - inversion HeqC'; subst. - auto. + assert (pb (pbk (x0 :> C') (x1 :> C') Csp1)). + { inversion HeqC'; subst. + eapply B1; eauto. } + econstructor; eauto. } - *) - - assert (@Pullback C (x0 :> C) (x1 :> C) Csp1 Sp1) as PBa1. + + assert (@Pullback C (x2 :> C) (x3 :> C) Csp2 Sp2) as PBa2. { remember C as C'. destruct C as [C class]. destruct class as [A1 A2 A3 A4 A5 A6]. destruct A6 as [B1]. - assert (pb (pbk (x0 :> C') (x1 :> C') Csp1)). - inversion HeqC'; subst. - eapply B1; eauto. + assert (pb (pbk (x2 :> C') (x3 :> C') Csp2)). + { inversion HeqC'; subst. + eapply B1; eauto. } econstructor; eauto. } +(* assert (@Pullback C (x2 :> C) (x3 :> C) Csp2 Sp2) as PBa2. + admit. +*) assert ((x0 *_ C0 x1) = bot Sp1) as E01. { subst Sp1. unfold iprod. @@ -1893,15 +1936,14 @@ Program Definition ipairC {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} set (ff := prj11 \; f). set (gg := prj12 \; g). - + assert ((f : (x0 :> C) ~>_C (x2 :> C)) \; tgt2 = tgt0) as E20. { remember f as f1. destruct f as [fsort fclass]. destruct fclass as [fIM]. destruct fIM. inversion Heqf1; subst. - simpl in *; simpl. - auto. + simpl in *; simpl; auto. } assert ((g : (x1 :> C) ~>_C (x3 :> C)) \; src3 = src1) as E31. @@ -1910,16 +1952,14 @@ Program Definition ipairC {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} destruct gclass as [gIM]. destruct gIM. inversion Heqg1; subst. - simpl in *; simpl. - auto. + simpl in *; simpl; auto. } assert (prj11 \; tgt0 = prj12 \; src1) as E11. { destruct PBa1 as [C1 C2]. destruct C1 as [C3]. inversion HeqCsp1; subst. - simpl in *. - auto. + simpl in *; auto. } assert (ff \; tgt2 = gg \; src3) as E1. @@ -1930,107 +1970,28 @@ Program Definition ipairC {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} exact E11. } - (* follows from pbquare_universal_aux1 and E1 *) + (* basically, follows from pbquare_universal and E1. + sordid eta-conversion issue fixed by pbsquare_is_pullback *) assert (sigma m: ((x0 *_ C0 x1) ~>_C (x2 *_ C0 x3) :> C), ff = m \; prj21 /\ gg = m \; prj22) as EM. { eapply (@pbsquare_universal C) ; eauto. - admit. - } - destruct EM as [mm [EM1 EM2]]. - - exact mm. -Admitted. - -(* -Program Definition ipairC {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} - (f : x0 ~>_(iHom C0) x2) (g : x1 ~>_(iHom C0) x3) : - (x0 *_C0 x1 :> C) ~>_C (x2 *_C0 x3 :> C). - - remember (x0 *_ C0 x1 : iHom C0) as Pb1. - remember (x2 *_ C0 x3 : iHom C0) as Pb2. - - remember (@Cospan C (x0 :> C) (x1 :> C) C0 - (@tgt C C0 x0) (@src C C0 x1)) as Csp1. - - remember (@Cospan C (x2 :> C) (x3 :> C) C0 - (@tgt C C0 x2) (@src C C0 x3)) as Csp2. - - remember (@src C C0 x0) as src0. - remember (@tgt C C0 x0) as tgt0. - - remember (@src C C0 x1) as src1. - remember (@tgt C C0 x1) as tgt1. - - remember (@src C C0 x2) as src2. - remember (@tgt C C0 x2) as tgt2. - - remember (@src C C0 x3) as src3. - remember (@tgt C C0 x3) as tgt3. - - remember (@src C C0 (x0 *_C0 x1)) as src01. - remember (@tgt C C0 (x0 *_C0 x1)) as tgt01. - - remember (@src C C0 (x2 *_C0 x3)) as src23. - remember (@tgt C C0 (x2 *_C0 x3)) as tgt23. - - remember (pbk (x0 :> C) (x1 :> C) Csp1) as Sp1. - remember (pbk (x2 :> C) (x3 :> C) Csp2) as Sp2. - - (* follows from def of Sp1, Sp2 *) - assert (@Pullback C (x0 :> C) (x1 :> C) Csp1 Sp1) as PBa1. - admit. - - assert (@Pullback C (x2 :> C) (x3 :> C) Csp2 Sp2) as PBa2. - admit. - - assert ((x0 *_ C0 x1) = bot Sp1) as E01. - { subst Sp1. - unfold iprod. - unfold iprod_pb. - rewrite HeqCsp1. - subst tgt0. - subst src1. - auto. - } + remember C as C'. + destruct C as [C class]. + destruct class as [A1 A2 A3 A4 A5 A6]. + destruct A6 as [B1]. + subst prj21 prj22. - assert ((x2 *_ C0 x3) = bot Sp2) as E23. - { subst Sp2. - unfold iprod. - unfold iprod_pb. - rewrite HeqCsp2. - subst tgt2. - subst src3. - auto. + (* surprisingly, this does not work with pbsquare_is_pulback_sym *) + rewrite pbsquare_is_pullback. + inversion HeqCsp2; subst. + subst Sp2. + exact PBa2. } - - set (prj11 := @iprodl C C0 x0 x1). - set (prj12 := @iprodr C C0 x0 x1). - - set (prj21 := @iprodl C C0 x2 x3). - set (prj22 := @iprodr C C0 x2 x3). - - set (ff := prj11 \; f). - set (gg := prj12 \; g). - - (* follows from f being in iHomHom, so - f \; tgt2 = tgt0 - g \; src3 = src1 - and Pb1 being a pullback, so - prj11 \; tgt0 = prj12 \; src1 *) - assert (ff \; tgt2 = gg \; src3) as E1. - admit. - - (* follows from pbquare_universal_aux1 and E1 *) - assert (sigma m: ((x0 *_ C0 x1) ~>_C (x2 *_ C0 x3) :> C), - ff = m \; prj21 /\ gg = m \; prj22) as EM. - admit. - + destruct EM as [mm [EM1 EM2]]. - exact mm. -Admitted. -*) +Qed. Notation "<( f , g )>" := (ipairC f g). From eb7d3eb1358ec8e6685dda35e08dfadb70a2d5d9 Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Tue, 19 Dec 2023 18:17:04 +0100 Subject: [PATCH 113/147] updated encatI.v --- theories/encatI.v | 49 ++++++++--------------------------------------- 1 file changed, 8 insertions(+), 41 deletions(-) diff --git a/theories/encatI.v b/theories/encatI.v index f85d4e388..7356ae945 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -1634,28 +1634,12 @@ Lemma iHom_Assoc_lemma {C : pbcat} (C0 : C) unfold comp; simpl. unfold iHom_precat_obligation_2; simpl. unfold iHom_comp; simpl. - remember a as a1. - remember b as b1. - remember c as c1. - remember d as d1. remember f as f1. remember g as g1. remember h as h1. - destruct a as [C_a class_a]. - destruct b as [C_b class_b]. - destruct c as [C_c class_c]. - destruct d as [C_d class_d]. destruct f as [M_f class_f]. destruct g as [M_g class_g]. destruct h as [M_h class_h]. - destruct class_a as [IM_a]. - destruct class_b as [IM_b]. - destruct class_c as [IM_c]. - destruct class_d as [IM_d]. - destruct IM_a. - destruct IM_b. - destruct IM_c. - destruct IM_d. destruct class_f as [IM_f]. destruct class_g as [IM_g]. destruct class_h as [IM_h]. @@ -1665,14 +1649,10 @@ Lemma iHom_Assoc_lemma {C : pbcat} (C0 : C) unfold obj in *; simpl in *; simpl. eassert ( forall x y, - {| - InternalHomHom.sort := f1 \; g1 \; h1; - InternalHomHom.class := x - |} = - {| - InternalHomHom.sort := (f1 \; g1) \; h1; - InternalHomHom.class := y - |} ) as A2. + {| InternalHomHom.sort := f1 \; g1 \; h1; + InternalHomHom.class := x |} = + {| InternalHomHom.sort := (f1 \; g1) \; h1; + InternalHomHom.class := y |} ) as A2. { rewrite Heqf1; simpl. rewrite compoA. intros. @@ -1809,25 +1789,11 @@ Proof. Lemma pbk_eta {C: pbcat} {C0} (X Y: iHom C0) : (pbk (X :> C) (Y :> C) (Cospan (@tgt C C0 X) (@src C C0 Y))) = (Span (iprodl X Y) (iprodr X Y)). - unfold iprodl. - unfold iprodr. - unfold iprod_pb. - assert ((X *_C0 Y :> C) = (bot (pbk (X :> C) (Y :> C) {| top := C0; left2top := tgt; right2top := src |}))) - as A1. - { unfold iprod. - simpl. - unfold iprod_pb. - auto. - } - simpl. - - unfold iprod. - unfold iprod_pb. - simpl. + unfold iprodl, iprodr, iprod. + unfold iprod_pb; simpl. generalize (pbk (X :> C) (Y :> C) {| top := C0; left2top := tgt; right2top := src |}). - - intros. + intro s0. destruct s0. simpl; auto. Qed. @@ -1983,6 +1949,7 @@ Program Definition ipairC {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} subst prj21 prj22. (* surprisingly, this does not work with pbsquare_is_pulback_sym *) + (* rewrite <- pbsquare_is_pullback_sym. *) rewrite pbsquare_is_pullback. inversion HeqCsp2; subst. subst Sp2. From 9974744a90d465560631f2edf32e7c0b3c8deb09 Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Thu, 21 Dec 2023 21:22:12 +0100 Subject: [PATCH 114/147] updated encatI.v --- theories/encatI.v | 125 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 119 insertions(+), 6 deletions(-) diff --git a/theories/encatI.v b/theories/encatI.v index 7356ae945..fc36aa220 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -1710,12 +1710,6 @@ Coercion iquiver_quiver (C : quiver) (C0 : iquiver C) : C := C0 :> C. Coercion iquiver_precat (C : precat) (C0 : iquiver C) : C := C0 :> C. Coercion iquiver_cat (C : cat) (C0 : iquiver C) : C := C0 :> C. -(* nested product *) -Program Definition iprodCAsc {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : - (((C1 *_C0 C2 : iHom C0) *_C0 C3) :> C) ~>_C - ((C1 *_C0 (C2 *_C0 C3 : iHom C0) : iHom C0) :> C). -Admitted. - Lemma pbsquare_universal {C: cat} (A B T P0 P1 : C) (t: A ~> T) (s: B ~> T) (p1: P0 ~> A) (p2: P0 ~> B) (f: P1 ~> A) (g: P1 ~> B) : @@ -1821,6 +1815,125 @@ Lemma pbsquare_is_pullback {C: pbcat} {C0} (X Y: iHom C0) : rewrite pbk_pullback_is_pullback; auto. Qed. +Definition jmcomp {C: cat} {a b c d: C} (e: c = b) (f: a ~> b) (g: c ~> d) := + f \; match e with eq_refl => g end. +Notation "f \;;_ e g" := (@jmcomp _ _ _ _ _ e f g) + (at level 60, g at level 60, e at level 0, format "f \;;_ e g", + only parsing) : cat_scope. + +(* nested product *) +Program Definition iprodCAsc {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : + (((C1 *_C0 C2 : iHom C0) *_C0 C3) :> C) ~>_C + ((C1 *_C0 (C2 *_C0 C3 : iHom C0) : iHom C0) :> C). +remember C1 as c1. +remember C2 as c2. +remember C3 as c3. +destruct C1 as [C1s C1c]. +destruct C2 as [C2s C2c]. +destruct C3 as [C3s C3c]. +destruct C1c as [IM1]. +destruct C2c as [IM2]. +destruct C3c as [IM3]. + +destruct IM1 as [src1 tgt1]. +destruct IM2 as [src2 tgt2]. +destruct IM3 as [src3 tgt3]. +simpl in *; simpl. + +set (Pb12 := c1 *_ C0 c2 : iHom C0). +set (Pb23 := c2 *_ C0 c3 : iHom C0). +set (Pb15 := c1 *_ C0 Pb23 : iHom C0). +set (Pb33 := Pb12 *_ C0 c3 : iHom C0). + +(* +remember (c1 *_ C0 c2 : iHom C0) as Pb12. +remember (c2 *_ C0 c3 : iHom C0) as Pb23. +remember ((c1 *_ C0 Pb23) : iHom C0) as Pb15. +remember ((Pb12 *_ C0 c3) : iHom C0) as Pb33. +*) + +set (pb12 := c1 *_ C0 c2 :> C). +set (pb23 := c2 *_ C0 c3 :> C). +set (pb15 := (c1 *_ C0 Pb23) :> C). +set (pb33 := (Pb12 *_ C0 c3) :> C). + +(* +remember (c1 *_ C0 c2 :> C) as pb12. +remember (c2 *_ C0 c3 :> C) as pb23. +remember ((c1 *_ C0 Pb23) :> C) as pb15. +remember ((Pb12 *_ C0 c3) :> C) as pb33. +*) + +set (j12L := iprodl c1 c2). +set (j12R := iprodr c1 c2). +set (j23L := iprodl c2 c3). +set (j23R := iprodr c2 c3). +set (j15L := iprodl c1 Pb23). +set (j15R := iprodr c1 Pb23). +set (j33L := iprodl Pb12 c3). +set (j33R := iprodr Pb12 c3). + +(* +remember (iprodl c1 c2) as j12L. +remember (iprodr c1 c2) as j12R. +remember (iprodl c2 c3) as j23L. +remember (iprodr c2 c3) as j23R. +remember (iprodl c1 Pb23) as j15L. +remember (iprodr c1 Pb23) as j15R. +remember (iprodl Pb12 c3) as j33L. +remember (iprodr Pb12 c3) as j33R. +*) + +assert (forall (e1: C1s = (c1 :> C)) (e2: C2s = (c2 :> C)), + j12L \;;_e1 tgt1 = j12R \;;_e2 src2) as sqPb12. +admit. + +assert (forall (e1: C2s = (c2 :> C)) (e2: C3s = (c3 :> C)), + j23L \;;_e1 tgt2 = j23R \;;_e2 src3) as sqPb23. +admit. + +assert (@tgt C C0 Pb12 = j12R \; @tgt C C0 c2) as tgtPb12. +admit. + +assert (@src C C0 Pb23 = j23L \; @src C C0 c2) as srcPb23. +admit. + +assert (forall (e1: C1s = (c1 :> C)), + j15L \;;_e1 tgt1 = j15R \; @src C C0 Pb23) as sqPb15. +admit. + +assert (forall (e2: C3s = (c3 :> C)), + j33L \; @tgt C C0 Pb12 = j33R \;;_e2 src3) as sqPb33. +admit. + +assert (forall (e1: ((c1 *_C0 c2) :> C) = Pb12), + sigma (m12: Pb15 ~> Pb12), + (j15L = m12 \;;_e1 j12L) /\ (j15R \; j23L = m12 \;;_e1 j12R)) as M12. +admit. + +assert (forall (e1: ((c2 *_C0 c3) :> C) = Pb23), + sigma (m23: Pb33 ~> Pb23), + (j33L \; j12R = m23 \;;_e1 j23L) /\ (j33R = m23 \;;_e1 j23R)) as M23. +admit. + +(* +unfold iprod. +unfold iprod_pb; simpl. +unfold iprod. +unfold iprod_pb; simpl. +unfold hom. +unfold IsQuiver.hom. +simpl. +setoid_rewrite pbk_eta. +simpl. +unfold hom. +unfold IsQuiver.hom. +*) + +Admitted. + + + Program Definition ipairC {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} (f : x0 ~>_(iHom C0) x2) (g : x1 ~>_(iHom C0) x3) : (x0 *_C0 x1 :> C) ~>_C (x2 *_C0 x3 :> C). From f81757d566f765314670f27056d2eea2d9b690ed Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Fri, 22 Dec 2023 15:28:37 +0100 Subject: [PATCH 115/147] updated encatI.v; added encatI0.v as experiment --- theories/encatI0.v | 2318 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 2318 insertions(+) create mode 100644 theories/encatI0.v diff --git a/theories/encatI0.v b/theories/encatI0.v new file mode 100644 index 000000000..5b98e343c --- /dev/null +++ b/theories/encatI0.v @@ -0,0 +1,2318 @@ +Require Import ssreflect ssrfun. +From HB Require Import structures. +Require Import Coq.Program.Equality. + +Set Implicit Arguments. +Unset Strict Implicit. +Unset Printing Implicit Defensive. +Add Search Blacklist "__canonical__". + +Declare Scope algebra_scope. +Delimit Scope algebra_scope with A. +Local Open Scope algebra_scope. + +Declare Scope cat_scope. +Delimit Scope cat_scope with cat. +Local Open Scope cat_scope. + +(* we assume a few axioms to make life easier *) +Axiom funext : forall {T : Type} {U : T -> Type} [f g : forall t, U t], + (forall t, f t = g t) -> f = g. +Axiom propext : forall P Q : Prop, P <-> Q -> P = Q. +Axiom Prop_irrelevance : forall (P : Prop) (x y : P), x = y. + +(* Shortcut *) +Notation U := Type. + +(* Base definition : raw categories = quivers *) +HB.mixin Record IsQuiver C := { hom : C -> C -> U }. +Unset Universe Checking. +#[short(type="quiver")] +HB.structure Definition Quiver : Set := { C of IsQuiver C }. +Set Universe Checking. + +Bind Scope cat_scope with quiver. +Bind Scope cat_scope with hom. +Arguments hom {C} : rename. +Notation homs T := (@hom T _ _). +Notation "a ~> b" := (hom a b) + (at level 99, b at level 200, format "a ~> b") : cat_scope. +Notation "a ~>_ C b" := (@hom C a b) + (at level 99, C at level 0, only parsing) : cat_scope. + +(* precategories are quivers + id and comp *) +HB.mixin Record Quiver_IsPreCat C of Quiver C := { + idmap : forall (a : C), a ~> a; + comp : forall (a b c : C), (a ~> b) -> (b ~> c) -> (a ~> c); +}. + +HB.factory Record IsPreCat C := { + hom : C -> C -> U; + idmap : forall (a : C), hom a a; + comp : forall (a b c : C), hom a b -> hom b c -> hom a c; +}. +HB.builders Context C of IsPreCat C. + HB.instance Definition _ := IsQuiver.Build C hom. + HB.instance Definition _ := Quiver_IsPreCat.Build C idmap comp. +HB.end. + +Unset Universe Checking. +#[short(type="precat")] +HB.structure Definition PreCat : Set := { C of IsPreCat C }. +Set Universe Checking. + +Bind Scope cat_scope with precat. +Arguments idmap {C} {a} : rename. +Arguments comp {C} {a b c} : rename. +Notation "f \o g" := (comp g f) : cat_scope. +Notation "f \; g :> T" := (@comp T _ _ _ f g) + (at level 60, g, T at level 60, format "f \; g :> T", only parsing) : cat_scope. +Notation "f \; g" := (comp f g) : cat_scope. +Notation "\idmap_ a" := (@idmap _ a) (only parsing, at level 0) : cat_scope. + +(* categories are precategories + laws *) +HB.mixin Record PreCat_IsCat C of PreCat C := { + comp1o : forall (a b : C) (f : a ~> b), idmap \; f = f; + compo1 : forall (a b : C) (f : a ~> b), f \; idmap = f; + compoA : forall (a b c d : C) (f : a ~> b) (g : b ~> c) (h : c ~> d), + f \; (g \; h) = (f \; g) \; h +}. +Unset Universe Checking. +#[short(type="cat")] +HB.structure Definition Cat : Set := { C of PreCat_IsCat C & IsPreCat C }. +Set Universe Checking. + +Bind Scope cat_scope with cat. +Arguments compo1 {C a b} : rename. +Arguments comp1o {C a b} : rename. +Arguments compoA {C a b c d} : rename. + +(* the discrete category on a type cannot be the default, we make an alias *) +Definition discrete (T : U) := T. +HB.instance Definition _ T := @IsPreCat.Build (discrete T) (fun x y => x = y) + (fun=> erefl) (@etrans _). +Lemma etransA T (a b c d : discrete T) (f : a ~> b) (g : b ~> c) (h : c ~> d) : + f \; (g \; h) = (f \; g) \; h. +Proof. by rewrite /idmap/comp/=; case: _ / h; case: _ / g. Qed. +HB.instance Definition _ T := PreCat_IsCat.Build (discrete T) (@etrans_id _) + (fun _ _ _ => erefl) (@etransA _). + +(* the category of the unit type is the discrete one *) +HB.instance Definition _ := Cat.copy unit (discrete unit). + +HB.instance Definition _ := @IsPreCat.Build U (fun A B => A -> B) + (fun a => idfun) (fun a b c (f : a -> b) (g : b -> c) => (g \o f)%FUN). +HB.instance Definition _ := PreCat_IsCat.Build U (fun _ _ _ => erefl) + (fun _ _ _ => erefl) (fun _ _ _ _ _ _ _ => erefl). + + +Lemma Ucomp (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) : f \; g = (g \o f)%FUN. +Proof. by []. Qed. +Lemma Ucompx (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) x : (f \; g) x = g (f x). +Proof. by []. Qed. +Lemma U1 (X : U) : \idmap_X = idfun. +Proof. by []. Qed. +Lemma U1x (X : U) x : \idmap_X x = x. +Proof. by []. Qed. + +(* a prefunctor is a functor without laws *) +HB.mixin Record IsPreFunctor (C D : quiver) (F : C -> D) := { + Fhom : forall (a b : C), (a ~> b) -> (F a ~> F b) +}. + +Unset Universe Checking. +HB.structure Definition PreFunctor (C D : quiver) : Set := + { F of IsPreFunctor C D F }. +Set Universe Checking. +HB.instance Definition _ := IsQuiver.Build quiver PreFunctor.type. + +Notation "F ^$" := (@Fhom _ _ F _ _) + (at level 1, format "F ^$") : cat_scope. +Notation "F <$> f" := (@Fhom _ _ F _ _ f) + (at level 58, format "F <$> f", right associativity) : cat_scope. + +(* prefunctors are equal if their object and hom part are respectively equal *) +Lemma prefunctorP (C D : quiver) (F G : C ~> D) (eqFG : F =1 G) : + let homF a b F := F a ~> F b in + (forall a b f, eq_rect _ (homF a b) (F <$> f) _ (funext eqFG) = G <$> f) -> + F = G. +Proof. +move: F G => [F [[/= Fhom]]] [G [[/= Ghom]]] in eqFG *. +case: _ / (funext eqFG) => /= in Ghom * => eqFGhom. +congr PreFunctor.Pack; congr PreFunctor.Class; congr IsPreFunctor.Axioms_. +by do 3!apply: funext=> ?. +Qed. + +(* a functor is a prefunctor + laws for id and comp *) +HB.mixin Record PreFunctor_IsFunctor (C D : precat) (F : C -> D) + of @PreFunctor C D F := { + F1 : forall (a : C), F <$> \idmap_a = idmap; + Fcomp : forall (a b c : C) (f : a ~> b) (g : b ~> c), + F <$> (f \; g) = F <$> f \; F <$> g; +}. +Unset Universe Checking. + +(* precat and cat have a quiver structure *) +HB.structure Definition Functor (C D : precat) : Set := + { F of IsPreFunctor C D F & PreFunctor_IsFunctor C D F }. +Set Universe Checking. +HB.instance Definition _ := IsQuiver.Build precat Functor.type. +HB.instance Definition _ := IsQuiver.Build cat Functor.type. + +(* functor equality is the same as prefunctor because of PI *) +Lemma functorP (C D : precat) (F G : C ~> D) (eqFG : F =1 G) : + let homF a b F := F a ~> F b in + (forall a b f, eq_rect _ (homF a b) (F^$ f) _ (funext eqFG) = G^$ f) -> + F = G. +Proof. +move=> /= /prefunctorP {eqFG}. +case: F G => [F [/= Fm Fm']] [G [/= Gm Gm']]//=. +move=> [_] /EqdepFacts.eq_sigT_iff_eq_dep eqFG. +case: _ / eqFG in Gm' *. +congr Functor.Pack; congr Functor.Class. +case: Fm' Gm' => [F1 Fc] [G1 Gc]. +by congr PreFunctor_IsFunctor.Axioms_; apply: Prop_irrelevance. +Qed. + +(* the identity function is a functor *) +HB.instance Definition _ (C : quiver) := + IsPreFunctor.Build C C idfun (fun a b => idfun). +HB.instance Definition _ (C : precat) := + PreFunctor_IsFunctor.Build C C idfun (fun=> erefl) (fun _ _ _ _ _ => erefl). + +(* the composition of prefunctors *) +Section comp_prefunctor. +Context {C D E : quiver} {F : C ~> D} {G : D ~> E}. + +HB.instance Definition _ := IsPreFunctor.Build C E (G \o F)%FUN + (fun a b f => G <$> F <$> f). +Lemma comp_Fun (a b : C) (f : a ~> b) : (G \o F)%FUN <$> f = G <$> (F <$> f). +Proof. by []. Qed. +End comp_prefunctor. + +Section comp_functor. +Context {C D E : precat} {F : C ~> D} {G : D ~> E}. +Lemma comp_F1 (a : C) : (G \o F)%FUN <$> \idmap_a = idmap. +Proof. by rewrite !comp_Fun !F1. Qed. +Lemma comp_Fcomp (a b c : C) (f : a ~> b) (g : b ~> c) : + (G \o F)%FUN <$> (f \; g) = (G \o F)%FUN <$> f \; (G \o F)%FUN <$> g. +Proof. by rewrite !comp_Fun !Fcomp. Qed. +HB.instance Definition _ := PreFunctor_IsFunctor.Build C E (G \o F)%FUN + comp_F1 comp_Fcomp. +End comp_functor. + +(* precat and cat have a precategory structure *) +HB.instance Definition _ := Quiver_IsPreCat.Build precat + (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). +HB.instance Definition _ := Quiver_IsPreCat.Build cat + (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). + +Lemma funext_frefl A B (f : A -> B) : funext (frefl f) = erefl. +Proof. exact: Prop_irrelevance. Qed. + +(* precategories and categories form a category *) +Definition precat_cat : PreCat_IsCat precat. +Proof. +by split=> [C D F|C D F|C D C' D' F G H]; + apply/functorP => a b f /=; rewrite funext_frefl. +Qed. +HB.instance Definition _ := precat_cat. +Definition cat_cat : PreCat_IsCat cat. +Proof. +by split=> [C D F|C D F|C D C' D' F G H]; + apply/functorP => a b f /=; rewrite funext_frefl. +Qed. +HB.instance Definition _ := cat_cat. + +Check (cat : cat). + +(* concrete categories *) +HB.mixin Record Quiver_IsPreConcrete T of Quiver T := { + concrete : T -> U; + concrete_fun : forall (a b : T), (a ~> b) -> concrete a -> concrete b; +}. +Unset Universe Checking. +#[short(type="preconcrete_quiver")] +HB.structure Definition PreConcreteQuiver : Set := + { C of Quiver_IsPreConcrete C & IsQuiver C }. +Set Universe Checking. +Coercion concrete : PreConcreteQuiver.sort >-> Sortclass. + +HB.mixin Record PreConcrete_IsConcrete T of PreConcreteQuiver T := { + concrete_fun_inj : forall (a b : T), injective (concrete_fun a b) +}. +Unset Universe Checking. +#[short(type="concrete_quiver")] +HB.structure Definition ConcreteQuiver : Set := + { C of PreConcreteQuiver C & PreConcrete_IsConcrete C }. +Set Universe Checking. + +HB.instance Definition _ (C : ConcreteQuiver.type) := + IsPreFunctor.Build _ _ (concrete : C -> U) concrete_fun. + +HB.mixin Record PreCat_IsConcrete T of ConcreteQuiver T & PreCat T := { + concrete1 : forall (a : T), concrete <$> \idmap_a = idfun; + concrete_comp : forall (a b c : T) (f : a ~> b) (g : b ~> c), + concrete <$> (f \; g) = ((concrete <$> g) \o (concrete <$> f))%FUN; +}. +Unset Universe Checking. +#[short(type="concrete_precat")] +HB.structure Definition ConcretePreCat : Set := + { C of PreCat C & ConcreteQuiver C & PreCat_IsConcrete C }. +#[short(type="concrete_cat")] +HB.structure Definition ConcreteCat : Set := + { C of Cat C & ConcreteQuiver C & PreCat_IsConcrete C }. +Set Universe Checking. + +HB.instance Definition _ (C : concrete_precat) := + PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). +HB.instance Definition _ (C : ConcreteCat.type) := + PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). + +HB.instance Definition _ := Quiver_IsPreConcrete.Build U (fun _ _ => id). +HB.instance Definition _ := PreConcrete_IsConcrete.Build U (fun _ _ _ _ => id). +HB.instance Definition _ := PreCat_IsConcrete.Build U + (fun=> erefl) (fun _ _ _ _ _ => erefl). + +Unset Universe Checking. +HB.instance Definition _ := Quiver_IsPreConcrete.Build quiver (fun _ _ => id). +HB.instance Definition _ := Quiver_IsPreConcrete.Build precat (fun _ _ => id). +HB.instance Definition _ := Quiver_IsPreConcrete.Build cat (fun _ _ => id). +Lemma quiver_concrete_subproof : PreConcrete_IsConcrete quiver. +Proof. +constructor=> C D F G FG; apply: prefunctorP. + by move=> x; congr (_ x); apply: FG. +by move=> *; apply: Prop_irrelevance. +Qed. +HB.instance Definition _ := quiver_concrete_subproof. + +Lemma precat_concrete_subproof : PreConcrete_IsConcrete precat. +Proof. +constructor=> C D F G FG; apply: functorP. + by move=> x; congr (_ x); apply: FG. +by move=> *; apply: Prop_irrelevance. +Qed. +HB.instance Definition _ := precat_concrete_subproof. + +Lemma cat_concrete_subproof : PreConcrete_IsConcrete cat. +Proof. +constructor=> C D F G FG; apply: functorP. + by move=> x; congr (_ x); apply: FG. +by move=> *; apply: Prop_irrelevance. +Qed. +HB.instance Definition _ := cat_concrete_subproof. +HB.instance Definition _ := PreCat_IsConcrete.Build precat + (fun=> erefl) (fun _ _ _ _ _ => erefl). +HB.instance Definition _ := PreCat_IsConcrete.Build cat + (fun=> erefl) (fun _ _ _ _ _ => erefl). +Set Universe Checking. + +(* constant functor *) +Definition cst (C D : quiver) (c : C) := fun of D => c. +Arguments cst {C} D c. +HB.instance Definition _ {C D : precat} (c : C) := + IsPreFunctor.Build D C (cst D c) (fun _ _ _ => idmap). +HB.instance Definition _ {C D : cat} (c : C) := + PreFunctor_IsFunctor.Build D C (cst D c) (fun=> erefl) + (fun _ _ _ _ _ => esym (compo1 idmap)). + +(* opposite category *) +Definition catop (C : U) : U := C. +Notation "C ^op" := (catop C) + (at level 2, format "C ^op") : cat_scope. +HB.instance Definition _ (C : quiver) := + IsQuiver.Build C^op (fun a b => hom b a). +HB.instance Definition _ (C : precat) := + Quiver_IsPreCat.Build (C^op) (fun=> idmap) (fun _ _ _ f g => g \; f). +HB.instance Definition _ (C : cat) := PreCat_IsCat.Build (C^op) + (fun _ _ _ => compo1 _) (fun _ _ _ => comp1o _) + (fun _ _ _ _ _ _ _ => esym (compoA _ _ _)). + +HB.instance Definition _ {C : precat} {c : C} := + IsPreFunctor.Build C _ (hom c) (fun a b f g => g \; f). +Lemma hom_Fhom_subproof (C : cat) (x : C) : + PreFunctor_IsFunctor _ _ (hom x). +Proof. by split=> *; apply/funext => h; [apply: compo1 | apply: compoA]. Qed. +HB.instance Definition _ {C : cat} {c : C} := hom_Fhom_subproof c. + +Check fun (C : cat) (x : C) => hom x : C ~>_cat U. + +Lemma hom_op {C : quiver} (c : C^op) : hom c = (@hom C)^~ c. +Proof. reflexivity. Qed. + +Lemma homFhomx {C : precat} (a b c : C) (f : a ~> b) (g : c ~> a) : + (hom c <$> f) g = g \; f. +Proof. reflexivity. Qed. + +(* nary product of categories *) +Definition dprod {I : U} (C : I -> U) := forall i, C i. + +Section hom_dprod. +Context {I : U} (C : I -> quiver). +Definition dprod_hom_subdef (a b : dprod C) := forall i, a i ~> b i. +HB.instance Definition _ := IsQuiver.Build (dprod C) dprod_hom_subdef. +End hom_dprod. +Arguments dprod_hom_subdef /. + +Section precat_dprod. +Context {I : U} (C : I -> precat). +Definition dprod_idmap_subdef (a : dprod C) : a ~> a := fun=> idmap. +Definition dprod_comp_subdef (a b c : dprod C) (f : a ~> b) (g : b ~> c) : a ~> c := + fun i => f i \; g i. +HB.instance Definition _ := IsPreCat.Build (dprod C) + dprod_idmap_subdef dprod_comp_subdef. +End precat_dprod. +Arguments dprod_idmap_subdef /. +Arguments dprod_comp_subdef /. + +Section cat_dprod. +Context {I : U} (C : I -> cat). +Local Notation type := (dprod C). +Lemma dprod_is_cat : PreCat_IsCat type. +Proof. +split=> [a b f|a b f|a b c d f g h]; apply/funext => i; +[exact: comp1o | exact: compo1 | exact: compoA]. +Qed. +HB.instance Definition _ := dprod_is_cat. +End cat_dprod. + +(* binary product *) +Section hom_prod. +Context {C D : quiver}. +Definition prod_hom_subdef (a b : C * D) := ((a.1 ~> b.1) * (a.2 ~> b.2))%type. +HB.instance Definition _ := IsQuiver.Build (C * D)%type prod_hom_subdef. +End hom_prod. + +Section precat_prod. +Context {C D : precat}. +HB.instance Definition _ := IsPreCat.Build (C * D)%type (fun=> (idmap, idmap)) + (fun a b c (f : a ~> b) (g : b ~> c) => (f.1 \; g.1, f.2 \; g.2)). +End precat_prod. + +Section cat_prod. +Context {C D : cat}. +Local Notation type := (C * D)%type. +Lemma prod_is_cat : PreCat_IsCat type. +Proof. +split=> [[a1 a2] [b1 b2] [f1 f2]|[a1 a2] [b1 b2] [f1 f2]| + [a1 a2] [b1 b2] [c1 c2] [d1 d2] [f1 f2] [g1 g2] [h1 h2]]; congr (_, _) => //=; +by [exact: comp1o | exact: compo1 | exact: compoA]. +Qed. +HB.instance Definition _ := prod_is_cat. +End cat_prod. + +HB.instance Definition _ (C : U) (D : quiver) := + IsQuiver.Build (C -> D) (fun f g => forall c, f c ~> g c). + +(* naturality *) +HB.mixin Record IsNatural (C : quiver) (D : precat) (F G : C ~>_quiver D) + (n : forall c, F c ~> G c) := { + natural : forall (a b : C) (f : a ~> b), + F <$> f \; n b = n a \; G <$> f +}. +Unset Universe Checking. +HB.structure Definition Natural (C : quiver) (D : precat) + (F G : C ~>_quiver D) : Set := + { n of @IsNatural C D F G n }. +Set Universe Checking. +HB.instance Definition _ (C : quiver) (D : precat) := + IsQuiver.Build (PreFunctor.type C D) (@Natural.type C D). +HB.instance Definition _ (C D : precat) := + IsQuiver.Build (Functor.type C D) (@Natural.type C D). +Arguments natural {C D F G} n [a b] f : rename. + +Check fun (C D : cat) (F G : C ~> D) => F ~>_(C ~>_cat D) G. + +Lemma naturalx (C : precat) (D : concrete_precat) + (F G : C ~>_quiver D) (n : F ~> G) (a b : C) (f : a ~> b) g : + (concrete <$> n b) ((concrete <$> F <$> f) g) = + (concrete <$> G <$> f) ((concrete <$> n a) g). +Proof. +have /(congr1 (fun h => (concrete <$> h) g)) := natural n f. +by rewrite !Fcomp. +Qed. +Arguments naturalx {C D F G} n [a b] f. + +Lemma naturalU (C : precat) (F G : C ~>_quiver U) (n : F ~> G) + (a b : C) (f : a ~> b) g : n b (F^$ f g) = G^$ f (n a g). +Proof. exact: (naturalx n). Qed. + +Lemma natP (C D : precat) (F G : C ~>_quiver D) (n m : F ~> G) : + Natural.sort n = Natural.sort m -> n = m. +Proof. +case: n m => [/= n nP] [/= m mP] enm. +elim: _ / enm in mP *; congr Natural.Pack. +case: nP mP => [[?]] [[?]]; congr Natural.Class. +congr IsNatural.Axioms_. +exact: Prop_irrelevance. +Qed. + +Notation "F ~~> G" := (F ~>_(homs quiver) G) + (at level 99, G at level 200, format "F ~~> G"). +Notation "F ~~> G :> C ~> D" := (F ~> G :> (C ~>_quiver D)) + (at level 99, G at level 200, C, D at level 0, + format "F ~~> G :> C ~> D"). + +Definition natural_id {C D : precat} (F : C ~>_quiver D) (a : C) := \idmap_(F a). +Definition natural_id_natural (C D : cat) (F : C ~>_quiver D) : + IsNatural C D F F (natural_id F). +Proof. by constructor=> a b f; rewrite /natural_id/= compo1 comp1o. Qed. +HB.instance Definition _ C D F := @natural_id_natural C D F. + +Check fun {C D : cat} (F : C ~>_quiver D) => natural_id F : F ~> F. + +Definition natural_comp {C D : precat} (F G H : C ~>_quiver D) + (m : F ~> G) (n : G ~> H) (a : C) := m a \; n a. +Definition natural_comp_natural (C D : cat) (F G H : C ~>_quiver D) m n : + IsNatural C D F H (@natural_comp C D F G H m n). +Proof. +constructor=> a b f; rewrite /natural_comp/=. +by rewrite compoA natural -compoA natural compoA. +Qed. +HB.instance Definition _ C D F G H m n := @natural_comp_natural C D F G H m n. + +HB.instance Definition _ {C D : cat} := + Quiver_IsPreCat.Build (PreFunctor.type C D) natural_id natural_comp. +HB.instance Definition _ {C D : cat} := + Quiver_IsPreCat.Build (Functor.type C D) natural_id natural_comp. + +Lemma prefunctor_cat {C D : cat} : PreCat_IsCat (PreFunctor.type C D). +Proof. +constructor => [F G f|F G f|F G H J f g h]. +- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. +- by apply/natP/funext => a; rewrite /= /natural_comp compo1. +- by apply/natP/funext => a; rewrite /= /natural_comp compoA. +Qed. +HB.instance Definition _ C D := @prefunctor_cat C D. + +Lemma functor_cat {C D : cat} : PreCat_IsCat (Functor.type C D). +Proof. +constructor => [F G f|F G f|F G H J f g h]. +- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. +- by apply/natP/funext => a; rewrite /= /natural_comp compo1. +- by apply/natP/funext => a; rewrite /= /natural_comp compoA. +Qed. +HB.instance Definition _ C D := @functor_cat C D. + +Lemma idFmap (C : cat) (a b : C) (f : a ~> b) : idfun <$> f = f. +Proof. by []. Qed. + +Lemma compFmap (C D E : cat) (F : C ~> D) (G : D ~> E) (a b : C) (f : a ~> b) : + (G \o F) <$> f = G <$> F <$> f. +Proof. by []. Qed. + +Section left_whiskering. +Context {C D E : precat} {F G : C ~> D}. + +Definition whiskerl_fun (eta : forall c, F c ~> G c) (H : D ~> E) : + forall c, (F \; H) c ~> (G \; H) c := fun c => H <$> eta c. + +Lemma whiskerl_is_nat (eta : F ~> G) (H : D ~> E) : + IsNatural _ _ _ _ (whiskerl_fun eta H). +Proof. by constructor=> a b f; rewrite /whiskerl_fun/= -!Fcomp natural. Qed. + +HB.instance Definition _ (eta : F ~> G) (H : D ~> E) := whiskerl_is_nat eta H. +Definition whiskerl (eta : F ~> G) (H : D ~> E) : (F \; H) ~> (G \; H) := + whiskerl_fun eta H : Natural.type _ _. +End left_whiskering. + +Notation "F n" := (whiskerl F n) + (at level 58, format "F n", right associativity) : cat_scope. + +Section right_whiskering. +Context {C D E : precat} {F G : D ~> E}. + +Definition whiskerr_fun (H : C ~> D) (eta : forall d, F d ~> G d) + (c : C) : (H \; F) c ~> (H \; G) c := eta (H c). + +Lemma whiskerr_is_nat (H : C ~> D) (eta : F ~> G) : + IsNatural _ _ _ _ (whiskerr_fun H eta). +Proof. by constructor=> a b f; rewrite /whiskerr_fun/= natural. Qed. +HB.instance Definition _ (H : C ~> D) (eta : F ~> G) := whiskerr_is_nat H eta. + +Definition whiskerr (H : C ~> D) (eta : F ~> G) : (H \; F) ~> (H \; G) := + whiskerr_fun H eta : Natural.type _ _. +End right_whiskering. + +Notation "F <$o> n" := (whiskerr F n) + (at level 58, format "F <$o> n", right associativity) : cat_scope. + +Definition whisker {C : cat} {D : precat} {E : cat} + {F G : C ~>_precat D} {H K : D ~> E} + (eta : F ~> G) (mu : H ~> K) : (F \; H) ~> (G \; K) := + (eta H) \; (G <$o> mu). + +Notation "eta mu" := (whisker eta mu) + (at level 58, format "eta mu", right associativity) : cat_scope. + +Lemma whiskern1 {C D E : cat} {F G : C ~>_precat D} (eta : F ~> G) (H : D ~> E) : + eta \idmap_H = eta H. +Proof. by apply/natP/funext=> c /=; apply: compo1. Qed. + +Lemma whisker1n {C D E : cat} {F G : D ~> E} (H : C ~> D) (eta : F ~> G) : + \idmap_H eta = H <$o> eta. +Proof. +apply/natP/funext=> c /=; rewrite /natural_comp/=. +by rewrite [X in X \; _]F1 comp1o. +Qed. + +Definition delta (C D : cat) : C -> (D ~> C) := cst D. +Arguments delta C D : clear implicits. + +Definition map_delta {C D : cat} (a b : C) (f : a ~> b) : + delta C D a ~> delta C D b. +Proof. +apply: (@Natural.Pack _ _ (cst D a) (cst D b) (fun x => f)). +apply: Natural.Class; apply: (IsNatural.Build _ _ _ _ _). +by move=> a' b' ?; rewrite compo1 comp1o. +Defined. + +HB.instance Definition _ {C D : cat} := + IsPreFunctor.Build C (D ~> C) (delta C D) (@map_delta C D). + +Lemma delta_functor {C D : cat} : PreFunctor_IsFunctor _ _ (delta C D). +Proof. by constructor=> [a|a b c f g]; exact/natP. Qed. +HB.instance Definition _ C D := @delta_functor C D. + +HB.mixin Record IsMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { + unit : idfun ~~> M; + join : (M \o M)%FUN ~~> M; + bind : forall (a b : C), (a ~> M b) -> (M a ~> M b); + bindE : forall a b (f : a ~> M b), bind a b f = M <$> f \; join b; + unit_join : forall a, (M <$> unit a) \; join _ = idmap; + join_unit : forall a, join _ \; (M <$> unit a) = idmap; + join_square : forall a, M <$> join a \; join _ = join _ \; join _ +}. + +#[short(type="premonad")] +HB.structure Definition PreMonad (C : precat) := + {M of @PreFunctor C C M & IsMonad C M}. +#[short(type="monad")] +HB.structure Definition Monad (C : precat) := + {M of @Functor C C M & IsMonad C M}. + +HB.factory Record IsJoinMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { + unit : idfun ~~> M; + join : (M \o M)%FUN ~~> M; + unit_join : forall a, (M <$> unit a) \; join _ = idmap; + join_unit : forall a, join _ \; (M <$> unit a) = idmap; + join_square : forall a, M <$> join a \; join _ = join _ \; join _ +}. +HB.builders Context C M of IsJoinMonad C M. + HB.instance Definition _ := IsMonad.Build C M + (fun a b f => erefl) unit_join join_unit join_square. +HB.end. + +HB.mixin Record IsCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { + counit : M ~~> idfun; + cojoin : M ~~> (M \o M)%FUN; + cobind : forall (a b : C), (M a ~> b) -> (M a ~> M b); + cobindE : forall a b (f : M a ~> b), cobind a b f = cojoin _ \; M <$> f; + unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; + join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; + cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ +}. +#[short(type="precomonad")] +HB.structure Definition PreCoMonad (C : precat) := + {M of @PreFunctor C C M & IsCoMonad C M}. +#[short(type="comonad")] +HB.structure Definition CoMonad (C : precat) := + {M of @Functor C C M & IsCoMonad C M}. + +HB.factory Record IsJoinCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { + counit : M ~~> idfun; + cojoin : M ~~> (M \o M)%FUN; + unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; + join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; + cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ +}. +HB.builders Context C M of IsJoinCoMonad C M. + HB.instance Definition _ := IsCoMonad.Build C M + (fun a b f => erefl) unit_cojoin join_counit cojoin_square. +HB.end. + +(* yoneda *) +Section hom_repr. +Context {C : cat} (F : C ~>_cat U). + +Definition homF : C -> U := fun c => hom c ~~> F. + +Section nat. +Context (x y : C) (xy : x ~> y). + +(* Goal hom x ~~> F -> hom y ~~> F *) +Context (n : hom x ~~> F). +Definition homFhom c : hom y c ~> F c := fun g => n _ (xy \; g). + +Lemma homFhom_natural_subdef : IsNatural C U (hom y) F homFhom. +Proof. +by split=> a b f /=; apply/funext => g /=; + rewrite /homFhom !Ucompx/= !naturalU/= Fcomp. +Qed. +HB.instance Definition _ := homFhom_natural_subdef. +End nat. +Arguments homFhom / : clear implicits. + +HB.about IsPreFunctor.Build. +Check homFhom : forall x y : C, (x ~> y) -> (homF x -> homF y). +HB.instance Definition _ := IsPreFunctor.Build _ _ homF homFhom. +Lemma homF_functor_subproof : PreFunctor_IsFunctor _ _ homF. +Proof. +split=> [a|a b c f g]. + apply/funext => -[/= f natf]. + apply: natP => //=; apply: funext => b; apply: funext => g/=. + by rewrite comp1o. +apply/funext => -[/= h natf]. +apply: natP => //=; apply: funext => d; apply: funext => k/=. +by rewrite compoA. +Qed. +HB.instance Definition _ := homF_functor_subproof. + +Section pointed. +Context (c : C). +Definition hom_repr : homF c ~> F c := fun f => f _ idmap. +Arguments hom_repr /. + +Definition repr_hom (fc : F c) a : hom c a ~> F a := + fun f => F^$ f fc. +Arguments repr_hom / : clear implicits. +Lemma repr_hom_subdef (fc : F c) : IsNatural _ _ _ _ (repr_hom fc). +Proof. by split=> a b f /=; apply/funext=> x; rewrite !Ucompx/= Fcomp. Qed. +HB.instance Definition _ {fc : F c} := repr_hom_subdef fc. + +Definition repr_hom_nat : F c ~> homF c := repr_hom. + +Lemma hom_reprK : cancel hom_repr repr_hom_nat. +Proof. +move=> f; apply/natP; apply/funext => a; apply/funext => g /=. +by rewrite -naturalU/=; congr (f _ _); apply: comp1o. +Qed. +Lemma repr_homK : cancel (repr_hom : F c ~> homF c) hom_repr. +Proof. by move=> fc; rewrite /= F1. Qed. +End pointed. +Arguments hom_repr /. +Arguments repr_hom /. + +Lemma hom_repr_natural_subproof : IsNatural _ _ _ _ hom_repr. +Proof. +split=> a b f /=; apply/funext => n /=; rewrite !Ucompx/= compo1/=. +by rewrite -naturalU/=; congr (n _ _); apply/esym/comp1o. +Qed. +HB.instance Definition _ := hom_repr_natural_subproof. + +(* show this from the previous proof *) +Lemma hom_natural_repr_subproof : IsNatural _ _ _ _ repr_hom_nat. +Proof. +split=> a b f /=; apply: funext => fa /=; rewrite !Ucompx/=. +apply: natP; apply: funext => c /=; apply: funext => d /=. +by rewrite Fcomp Ucompx/=. +Qed. +HB.instance Definition _ := hom_natural_repr_subproof. + +Definition hom_repr_nat : homF ~~> F := hom_repr. +Definition repr_hom_nat_nat : F ~~> homF := repr_hom_nat. + +End hom_repr. + +(* comma categories *) +Module comma. +Section homcomma. +Context {C D E : precat} (F : C ~> E) (G : D ~> E). + +Definition type := { x : C * D & F x.1 ~> G x.2 }. +Definition hom_subdef (a b : type) := { + f : tag a ~> tag b & F <$> f.1 \; tagged b = tagged a \; G <$> f.2 + }. +HB.instance Definition _ := IsQuiver.Build type hom_subdef. +End homcomma. +Arguments hom_subdef /. +Section comma. +Context {C D E : cat} (F : C ~> E) (G : D ~> E). +Notation type := (type F G). + +Program Definition idmap_subdef (a : type) : a ~> a := @Tagged _ idmap _ _. +Next Obligation. by rewrite !F1 comp1o compo1. Qed. +Program Definition comp_subdef (a b c : type) + (f : a ~> b) (g : b ~> c) : a ~> c := + @Tagged _ (tag f \; tag g) _ _. +Next Obligation. by rewrite !Fcomp -compoA (tagged g) compoA (tagged f) compoA. Qed. +HB.instance Definition _ := IsPreCat.Build type idmap_subdef comp_subdef. +Arguments idmap_subdef /. +Arguments comp_subdef /. + +Lemma comma_homeqP (a b : type) (f g : a ~> b) : projT1 f = projT1 g -> f = g. +Proof. +case: f g => [f fP] [g +]/= eqfg; case: _ / eqfg => gP. +by congr existT; apply: Prop_irrelevance. +Qed. + +Lemma comma_is_cat : PreCat_IsCat type. +Proof. +by split=> [[a fa] [b fb] [*]|[a fa] [b fb] [*]|*]; + apply/comma_homeqP; rewrite /= ?(comp1o, compo1, compoA). +Qed. +HB.instance Definition _ := comma_is_cat. +End comma. +End comma. +Notation "F `/` G" := (@comma.type _ _ _ F G) + (at level 40, G at level 40, format "F `/` G") : cat_scope. +Notation "a /` G" := (cst unit a `/` G) + (at level 40, G at level 40, format "a /` G") : cat_scope. +Notation "F `/ b" := (F `/` cst unit b) + (at level 40, b at level 40, format "F `/ b") : cat_scope. +Notation "a / b" := (cst unit a `/ b) : cat_scope. + +Definition obj (C : quiver) : Type := C. +HB.mixin Record IsInitial {C : quiver} (i : obj C) := { + to : forall c, i ~> c; + to_unique : forall c (f : i ~> c), f = to c +}. +#[short(type="initial")] +HB.structure Definition Initial {C : quiver} := {i of IsInitial C i}. + +HB.mixin Record IsTerminal {C : quiver} (t : obj C) := { + from : forall c, c ~> t; + from_unique : forall c (f : c ~> t), f = from c +}. +#[short(type="terminal")] +HB.structure Definition Terminal {C : quiver} := {t of IsTerminal C t}. + +HB.mixin Record IsMono {C : precat} (b c : C) (f : hom b c) := { + monoP : forall (a : C) (g1 g2 : a ~> b), g1 \; f = g2 \; f -> g1 = g2 +}. +#[short(type="mono")] +HB.structure Definition Mono {C : precat} (a b : C) := {m of IsMono C a b m}. +Notation "a >~> b" := (mono a b) + (at level 99, b at level 200, format "a >~> b") : cat_scope. +Notation "C >~>_ T D" := (@mono T C D) + (at level 99, T at level 0, only parsing) : cat_scope. + +HB.mixin Record IsEpi {C : precat} (a b : C) (f : hom a b) := { + epiP : forall (c : C) (g1 g2 : b ~> c), g1 \o f = g2 \o f -> g1 = g2 +}. +#[short(type="epi")] +HB.structure Definition Epi {C : precat} (a b : C) := {e of IsEpi C a b e}. +Notation "a ~>> b" := (epi a b) + (at level 99, b at level 200, format "a ~>> b") : cat_scope. +Notation "C ~>>_ T D" := (@epi T C D) + (at level 99, T at level 0, only parsing) : cat_scope. + +#[short(type="iso")] +HB.structure Definition Iso {C : precat} (a b : C) := + {i of @Mono C a b i & @Epi C a b i}. +Notation "a <~> b" := (epi a b) + (at level 99, b at level 200, format "a <~> b") : cat_scope. +Notation "C <~>_ T D" := (@epi T C D) + (at level 99, T at level 0, only parsing) : cat_scope. + +Definition comp1F {C D : cat} (F : C ~> D) : idmap \; F = F. +Proof. by apply/functorP=> a b f; rewrite funext_frefl/= compFmap. Qed. + +Definition compF1 {C D : cat} (F : C ~> D) : F \; idmap = F. +Proof. by apply/functorP=> a b f; rewrite funext_frefl/= compFmap. Qed. + +Definition feq {C : precat} {a b : C} : a = b -> a ~> b. +Proof. by move<-; exact idmap. Defined. + +Definition feqsym {C : precat} {a b : C} : a = b -> b ~> a. +Proof. by move<-; exact idmap. Defined. + +HB.mixin Record IsLeftAdjointOf (C D : cat) (R : D ~> C) L + of @Functor C D L := { + Lphi : forall c d, (L c ~> d) -> (c ~> R d); + Lpsi : forall c d, (c ~> R d) -> (L c ~> d); + (* there should be a monad and comonad structure wrappers instead *) + Lunit : (idmap : C ~> C) ~~> R \o ((L : Functor.type C D) : C ~> D); + Lcounit : ((L : Functor.type C D) : C ~> D) \o R ~~> idmap :> D ~> D; + LphiE : forall c d (g : L c ~> d), Lphi c d g = Lunit c \; (R <$> g); + LpsiE : forall c d (f : c ~> R d), Lpsi c d f = (L <$> f) \; Lcounit d; + Lwhiskerlr : let L : C ~> D := L : Functor.type C D in + (feqsym (comp1F _) \; Lunit L) \; + (L <$o> Lcounit \; feq (compF1 _)) = idmap; + Lwhiskerrl : let L : C ~> D := L : Functor.type C D in + (feqsym (compF1 _) \; R <$o> Lunit) \; + (Lcounit R \; feq (comp1F _)) = idmap; +}. +#[short(type="left_adjoint_of")] +HB.structure Definition LeftAdjointOf (C D : cat) (R : D ~> C) := + { L of @Functor C D L & IsLeftAdjointOf C D R L}. +Arguments Lphi {C D R s} {c d}. +Arguments Lpsi {C D R s} {c d}. +Arguments Lunit {C D R s}. +Arguments Lcounit {C D R s}. + +Section LeftAdjointOf_Theory. +Variables (C D : cat) (R : D ~> C) (L : LeftAdjointOf.type R). + +Lemma Lphi_psi (c : C) (d : D) : + (@Lphi _ _ R L c d \o @Lpsi _ _ R L c d)%FUN = @id (c ~> R d). +Proof. +apply/funext => f /=; rewrite LphiE LpsiE. +Admitted. + +Lemma Lpsi_phi (c : C) (d : D) : + (@Lpsi _ _ R L c d \o @Lphi _ _ R L c d)%FUN = @id (L c ~> d). +Proof. +Admitted. +End LeftAdjointOf_Theory. + +HB.mixin Record IsRightAdjoint (D C : cat) (R : D -> C) + of @Functor D C R := { + (* we should have a wrapper instead *) + left_adjoint : C ~> D; + LLphi : forall c d, (left_adjoint c ~> d) -> (c ~> R d); + LLpsi : forall c d, (c ~> R d) -> (left_adjoint c ~> d); + LLunit : (idmap : C ~> C) ~~> (R : Functor.type D C) \o left_adjoint; + LLcounit : left_adjoint \o (R : Functor.type D C) ~~> idmap :> D ~> D; + LLphiE : forall c d (g : left_adjoint c ~> d), LLphi c d g = LLunit c \; (R <$> g); + LLpsiE : forall c d (f : c ~> R d), LLpsi c d f = (left_adjoint <$> f) \; LLcounit d; + LLwhiskerlr : + (feqsym (comp1F _) \; LLunit left_adjoint) \; + (left_adjoint <$o> LLcounit \; feq (compF1 _)) = idmap; + LLwhiskerrl : + (feqsym (compF1 _) \; (R : Functor.type D C) <$o> LLunit) \; + (LLcounit (R : Functor.type D C) \; feq (comp1F _)) = idmap; +}. +#[short(type="right_adjoint")] +HB.structure Definition RightAdjoint (D C : cat) := + { R of @Functor D C R & IsRightAdjoint D C R }. +Arguments left_adjoint {_ _}. +Arguments LLphi {D C s} {c d}. +Arguments LLpsi {D C s} {c d}. +Arguments LLunit {D C s}. +Arguments LLcounit {D C s}. + +HB.mixin Record PreCat_IsMonoidal C of PreCat C := { + onec : C; + prod : (C * C)%type ~>_precat C; +}. +#[short(type="premonoidal")] +HB.structure Definition PreMonoidal := { C of PreCat C & PreCat_IsMonoidal C }. +Notation premonoidal := premonoidal. +Arguments prod {C} : rename. +Notation "a * b" := (prod (a, b)) : cat_scope. +Reserved Notation "f <*> g" (at level 40, g at level 40, format "f <*> g"). +Notation "f <*> g" := (prod^$ (f, g)) (only printing) : cat_scope. +Notation "f <*> g" := (prod^$ ((f, g) : (_, _) ~> (_, _))) + (only parsing) : cat_scope. +Notation "1" := onec : cat_scope. + +Definition hom_cast {C : quiver} {a a' : C} (eqa : a = a') + {b b' : C} (eqb : b = b') : + (a ~> b) -> (a' ~> b'). +Proof. now elim: _ / eqa; elim: _ / eqb. Defined. + +HB.mixin Record PreFunctor_IsMonoidal (C D : premonoidal) F of + @PreFunctor C D F := { + fun_one : F 1 = 1; + fun_prod : forall (x y : C), F (x * y) = F x * F y; +}. +#[short(type="monoidal_prefunctor")] +HB.structure Definition MonoidalPreFunctor C D := + { F of @PreFunctor_IsMonoidal C D F }. +Arguments fun_prod {C D F x y} : rename. +(* Arguments fun_prodF {C D F x x'} f {y y'} g : rename. *) +Unset Universe Checking. +HB.instance Definition _ := IsQuiver.Build premonoidal MonoidalPreFunctor.type. +Set Universe Checking. + +HB.instance Definition _ (C : quiver) := + IsPreFunctor.Build (C * C)%type C fst + (fun (a b : C * C) (f : a ~> b) => f.1). +HB.instance Definition _ (C : quiver) := + IsPreFunctor.Build (C * C)%type C snd + (fun (a b : C * C) (f : a ~> b) => f.2). + +Definition prod3l {C : premonoidal} (x : C * C * C) : C := + (x.1.1 * x.1.2) * x.2. +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build _ C prod3l + (fun a b (f : a ~> b) => (f.1.1 <*> f.1.2) <*> f.2). + +Definition prod3r {C : premonoidal} (x : C * C * C) : C := + x.1.1 * (x.1.2 * x.2). +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build _ C prod3r + (fun a b (f : a ~> b) => f.1.1 <*> (f.1.2 <*> f.2)). + +Definition prod1r {C : premonoidal} (x : C) : C := 1 * x. +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build C C prod1r + (fun (a b : C) (f : a ~> b) => \idmap_1 <*> f). + +Definition prod1l {C : premonoidal} (x : C) : C := x * 1. +HB.instance Definition _ {C : premonoidal} := + IsPreFunctor.Build C C prod1l + (fun (a b : C) (f : a ~> b) => f <*> \idmap_1). + +HB.mixin Record PreMonoidal_IsMonoidal C of PreMonoidal C := { + prodA : prod3l ~~> prod3r; + prod1c : prod1r ~~> idfun; + prodc1 : prod1l ~~> idfun; + prodc1c : forall (x y : C), + prodA (x, 1, y) \; \idmap_x <*> prod1c y = prodc1 x <*> \idmap_y; + prodA4 : forall (w x y z : C), + prodA (w * x, y, z) \; prodA (w, x, y * z) = + prodA (w, x, y) <*> \idmap_z \; prodA (w, x * y, z) \; \idmap_w <*> prodA (x, y, z); +}. + +Unset Universe Checking. +#[short(type="monoidal")] +HB.structure Definition Monoidal : Set := + { C of PreMonoidal_IsMonoidal C & PreMonoidal C }. +Set Universe Checking. + +Record span (Q : quiver) (A B : Q) := Span { + bot : Q; + bot2left : bot ~> A; + bot2right : bot ~> B +}. + +Section spans. +Variables (Q : precat) (A B : Q). +Record span_map (c c' : span A B) := SpanMap { + bot_map : bot c ~> bot c'; + bot2left_map : bot_map \; bot2left c' = bot2left c; + bot2right_map : bot_map \; bot2right c' = bot2right c; +}. +HB.instance Definition _ := IsQuiver.Build (span A B) span_map. + +Lemma span_mapP (c c' : span A B) (f g : c ~> c') : + bot_map f = bot_map g <-> f = g. +Proof. +split=> [|->]//; case: f g => [/= f ? ?] [/= g + +] efg. +by elim: efg => // ? ?; congr SpanMap; apply: Prop_irrelevance. +Qed. + +End spans. + +Section spans_in_cat. +Variables (Q : cat) (A B : Q). +Definition span_idmap (c : span A B) := + @SpanMap Q A B c c idmap (comp1o _) (comp1o _). +Program Definition span_comp (c1 c2 c3 : span A B) + (f12 : c1 ~> c2) (f23 : c2 ~> c3) := + @SpanMap Q A B c1 c3 (bot_map f12 \; bot_map f23) _ _. +Next Obligation. by rewrite -compoA !bot2left_map. Qed. +Next Obligation. by rewrite -compoA !bot2right_map. Qed. +HB.instance Definition _ := IsPreCat.Build (span A B) + span_idmap span_comp. + +Lemma span_are_cats : PreCat_IsCat (span A B). +Proof. +constructor=> [a b f|a b f|a b c d f g h]. +- by apply/span_mapP => /=; rewrite comp1o. +- by apply/span_mapP => /=; rewrite compo1. +- by apply/span_mapP => /=; rewrite compoA. +Qed. +HB.instance Definition _ := span_are_cats. +End spans_in_cat. + +Record cospan (Q : quiver) (A B : Q) := Cospan { + top : Q; + left2top : A ~> top; + right2top : B ~> top +}. + +Section cospans. +Variables (Q : precat) (A B : Q). +Record cospan_map (c c' : cospan A B) := CospanMap { + top_map : top c ~> top c'; + left2top_map : left2top c \; top_map = left2top c'; + right2top_map : right2top c \; top_map = right2top c'; +}. +HB.instance Definition _ := IsQuiver.Build (cospan A B) cospan_map. + +Lemma cospan_mapP (c c' : cospan A B) (f g : c ~> c') : + top_map f = top_map g <-> f = g. +Proof. +split=> [|->]//; case: f g => [/= f ? ?] [/= g + +] efg. +by elim: efg => // ? ?; congr CospanMap; apply: Prop_irrelevance. +Qed. + +End cospans. + +Section cospans_in_cat. +Variables (Q : cat) (A B : Q). +Definition cospan_idmap (c : cospan A B) := + @CospanMap Q A B c c idmap (compo1 _) (compo1 _). +Program Definition cospan_comp (c1 c2 c3 : cospan A B) + (f12 : c1 ~> c2) (f23 : c2 ~> c3) := + @CospanMap Q A B c1 c3 (top_map f12 \; top_map f23) _ _. +Next Obligation. by rewrite compoA !left2top_map. Qed. +Next Obligation. by rewrite compoA !right2top_map. Qed. +HB.instance Definition _ := IsPreCat.Build (cospan A B) + cospan_idmap cospan_comp. + +Lemma cospan_are_cats : PreCat_IsCat (cospan A B). +Proof. +constructor=> [a b f|a b f|a b c d f g h]. +- by apply/cospan_mapP => /=; rewrite comp1o. +- by apply/cospan_mapP => /=; rewrite compo1. +- by apply/cospan_mapP => /=; rewrite compoA. +Qed. +HB.instance Definition _ := cospan_are_cats. +End cospans_in_cat. + +HB.mixin Record isPrePullback (Q : precat) (A B : Q) + (c : cospan A B) (s : span A B) := { + is_square : bot2left s \; left2top c = bot2right s \; right2top c; +}. +#[short(type=prepullback)] +HB.structure Definition PrePullback Q A B (c : cospan A B) := + {s of isPrePullback Q A B c s}. +Arguments prepullback {Q A B} c. + +Section prepullback. +Variables (Q : precat) (A B : Q) (c : cospan A B). +HB.instance Definition _ := + IsQuiver.Build (prepullback c) + (fun a b => (a : span A B) ~>_(span A B) (b : span A B)). +Lemma eq_prepullbackP (p q : prepullback c) : + p = q :> span _ _ <-> p = q. +Proof. +Admitted. +End prepullback. +Section prepullback. +Variables (Q : cat) (A B : Q) (csp : cospan A B). +(* TODO: why can't we do that? *) +(* HB.instance Definition _ := Cat.on (prepullback csp). *) +HB.instance Definition _ := + Quiver_IsPreCat.Build (prepullback csp) + (fun a => \idmap_(a : span A B)) + (* TODO: study how to make this coercion trigger + even when the target is not reduced to span *) + (fun a b c f g => f \; g). +Lemma prepullback_is_cat : PreCat_IsCat (prepullback csp). +Proof. (* should be copied from the cat on span *) +constructor=> [a b f|a b f|a b c d f g h]; + [exact: comp1o|exact: compo1|exact: compoA]. +Qed. +End prepullback. + +HB.tag Definition pb_terminal (Q : precat) + (A B : Q) (c : cospan A B) (s : prepullback c) : + obj (prepullback c) := s. + +#[wrapper] +HB.mixin Record prepullback_isTerminal (Q : precat) + (A B : Q) (c : cospan A B) + (s : span A B) of isPrePullback Q A B c s := { + prepullback_terminal : + IsTerminal (prepullback c) (pb_terminal s) +}. +#[short(type="pullback"), verbose] +HB.structure Definition Pullback (Q : precat) + (A B : Q) (c : cospan A B) := + {s of isPrePullback Q A B c s + & IsTerminal (prepullback c) (pb_terminal s) }. + +Inductive walking_cospan := Top | Left | Right. +Definition walking_cospan_hom (x y : walking_cospan) := match x, y with + | Top, Top | Left, Left | Right, Right | + Left, Top | Right, Top => Datatypes.unit + | _, _ => False + end. + +HB.instance Definition _ := + IsQuiver.Build walking_cospan walking_cospan_hom. + +Definition walking_cospan_id (x : walking_cospan) : x ~> x. +Proof. by case: x; constructor. Defined. + +Definition walking_cospan_comp (x y z : walking_cospan) : + (x ~> y) -> (y ~> z) -> (x ~> z). +Proof. by case: x y z => [] [] []. Defined. + +HB.instance Definition _ := Quiver_IsPreCat.Build walking_cospan + walking_cospan_id walking_cospan_comp. + +Lemma walking_cospan_cat : PreCat_IsCat walking_cospan. +Proof. by constructor=> [[] []|[] []|[] [] [] []]// []. Qed. +HB.instance Definition _ := walking_cospan_cat. + +Section Pullback_Natural. +Context (C : cat) (A B : C) (csp : cospan A B). + +Definition cspF (x : walking_cospan) : C := + match x with Left => A | Right => B | Top => top csp end. + +Definition cspFhom : forall (x y : walking_cospan), + (x ~> y) -> cspF x ~> cspF y. +Proof. +move=> [] []//. +- move=> _; exact: idmap. +- move=> _; exact: left2top csp. +- move=> _; exact: idmap. +- move=> _; exact: right2top csp. +- move=> _; exact: idmap. +Defined. + +HB.instance Definition _ := IsPreFunctor.Build _ _ cspF cspFhom. +Lemma cspF_functor : PreFunctor_IsFunctor _ _ cspF. +Proof. +by constructor=> [[]|[] [] []]//= [] []//=; + rewrite ?(compo1, comp1o)//. +Qed. +HB.instance Definition _ := cspF_functor. + +Section prepullback2natural. +Variable (p : prepullback csp). + +Definition wcsp w : cst walking_cospan (bot p) w ~> cspF w. +Proof. +case: w; rewrite /cst /=. +- exact: (bot2left _ \; left2top _). +- exact: bot2left. +- exact: bot2right. +Defined. + +Lemma wcsp_natural : IsNatural _ _ _ _ wcsp. +Proof. +constructor=> - [] [] //= [] /=; rewrite ?(comp1o, compo1)//=. +exact: is_square. +Qed. + +End prepullback2natural. + +Section natural2prepullback. +Variables (c : C) (n : cst walking_cospan c ~~> cspF). + +Definition s := {| bot := c; bot2left := n Left; bot2right := n Right |}. + +Lemma s_prepullback : isPrePullback _ _ _ csp s. +Proof. +constructor => /=. +have p := natural n (tt : Right ~> Top). +have /esym q := natural n (tt : Left ~> Top). +exact: etrans q p. +Qed. + +End natural2prepullback. + +End Pullback_Natural. +Notation square u v f g := + (isPrePullback _ _ _ (Cospan f g) (Span u v)). +Notation pbsquare u v f g := + (Pullback _ (Cospan f g) (Span u v)). +Notation pb s := (prepullback_isTerminal _ _ _ _ s). + +Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). + +(**********************************************************************) + +Section th_of_pb. +Variables (Q : cat) (A B C D E F : Q). +Variables (f : A ~> D) (g : B ~> D) (h : C ~> A). +Variables (u : E ~> A) (v : E ~> B) (w : F ~> C) (z : F ~> E). +Variable (uvfg : pbsquare u v f g). + +Theorem pbsquarec_compP : + pbsquare w z h u <=> pbsquare w (z \; v) (h \; f) g. +Proof. +split=> [] sq. + + have @sq_ispb : pullback (Cospan h u) := HB.pack (Span w z) sq. + have @uvfg_ispb : pullback (Cospan f g) := HB.pack (Span u v) uvfg. + have /=E2 := @is_square _ _ _ _ sq_ispb. + have /=E1 := @is_square _ _ _ _ uvfg_ispb. + + have p1 : @isPrePullback Q C B (Cospan (h \; f) g) (Span w (z \; v)). + by constructor; rewrite /= compoA E2 -compoA E1 compoA. + pose big_black_square : prepullback (Cospan (h \; f) g) := + HB.pack (Span w (z \; v)) p1. + + have @from : forall + (big_red_square : prepullback {| top := D; left2top := h \; f; right2top := g |}), + big_red_square ~> pb_terminal big_black_square. + + move=> big_red_square; unfold pb_terminal. + + have /= := @is_square _ _ _ _ big_red_square. + + pose F' := bot big_red_square. + set w' : F' ~> C := bot2left big_red_square. + set z' : F' ~> B := bot2right big_red_square. + move=> E3. + + have xxx : isPrePullback Q A B (Cospan f g) (Span (w' \; h) z'). + by constructor=> /=; rewrite -compoA E3. + pose red_black_square : prepullback (Cospan f g) := + HB.pack (Span (w' \; h) z') xxx. + have := @from_unique _ (pb_terminal uvfg_ispb) red_black_square. + set blue := @from _ (pb_terminal uvfg_ispb) red_black_square. + move=> blue_unique. + + have p3 : @isPrePullback Q C E (Cospan h u) (Span w' (bot_map blue)). + by constructor; rewrite /= (bot2left_map blue). (* buggy unifier without blue *) + pose blue_red_black_square : prepullback (Cospan h u) := + HB.pack (Span w' (bot_map blue)) p3. + + pose red := @from _ (pb_terminal sq_ispb) blue_red_black_square. + + admit. + + + + have p2 : prepullback_isTerminal.axioms_ Q C B (Cospan (h \; f) g) (Span w (z \; v)) p1. + constructor. econstructor=> /=. + admit. + + by HB.from p1 p2. + +Admitted. + +End th_of_pb. + + +Module test. + +Section test. +Variables (Q : precat) (A B : Q) (c : cospan A B). +Variable (p : pullback c). +Check pb_terminal p : terminal _. + +End test. +End test. + + +(********************************************************************) +(********************************************************************) + +Notation "'sigma' x .. y , p" := + (sigT (fun x => .. (sigT (fun y => p)) ..)) + (at level 200, x binder, right associativity, + format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") + : type_scope. + +(*** CATEGORIES WITH PULLBACKS *) + +(* category with all prepullbacks *) +(* Ideally span is in fact expanded and the final mixin has +a pb : forall A B, cospan A B -> C +but it is not clear how to do that yet +*) +HB.mixin Record HasPBop C of Cat C := { + pbk : forall (A B: C), cospan A B -> span A B + }. +#[short(type="pbop")] +HB.structure Definition PBop := + {C of HasPBop C & PreCat C }. + +(* category with all pullbacks *) +(* Wrong: we don't wrap classes, only mixins *) +#[wrapper] +HB.mixin Record HasPreBCat C of PBop C : Type := { + is_ppbk : forall (a b : C) (c : cospan a b), + isPrePullback C a b c (@pbk C a b c) + }. +#[short(type="pbcat")] +HB.structure Definition PreBCat := + {C of HasPreBCat C}. + +#[wrapper] +HB.mixin Record HasPBCat C of PBop C & HasPreBCat C : Type := { + is_tpbk : forall (a b : C) (c : cospan a b), + prepullback_isTerminal C a b c (@pbk C a b c) + }. +#[short(type="pbcat")] +HB.structure Definition PBCat := + {C of HasPBCat C}. + + +(************************************************************************) + +(* AUXILIARY for pullbacks *) + +Definition comm_square {Q: precat} {L R T: Q} + (l: L ~> T) (r: R ~> T) {B: Q} (p1: B ~> L) (p2: B ~> R) : Prop := + p1 \; l = p2 \; r. + +Definition comm_triangle {Q: precat} {A B C: Q} + (h: A ~> C) (f: A ~> B) (g: B ~> C) : Prop := + h = f \; g. + +Record GMedArrow {Q: precat} {L R T: Q} + (l: L ~> T) (r: R ~> T) + (P: forall (B: Q) (p1: B ~> L) (p2: B ~> R), Type) + {B: Q} (p1: B ~> L) (p2: B ~> R) {B0: Q} + (m: B0 ~> B) := { + gmedarrow_prop : forall (p01: B0 ~> L) (p02: B0 ~> R), + P B0 p01 p02 -> comm_triangle p01 m p1 /\ comm_triangle p02 m p2 +}. + +(************************************************************************) + +(* PULLBACKS *) + +(* Span pinned to an object *) +HB.mixin Record IsPSpan {Q: precat} {L R T: Q} + (l: L ~> T) (r: R ~> T) (B: Q) : Type := { + lprj : B ~> L ; + rprj : B ~> R + }. +#[short(type="pspan"), verbose] +HB.structure Definition PSpan {Q: precat} + {L R T : Q} (l: L ~> T) (r: R ~> T) := + { B of IsPSpan Q L R T l r B }. + +Definition medarrow_prop {Q: precat} {L R T: Q} + (l: L ~> T) (r: R ~> T) + (B: @pspan Q L R T l r) + {B0: Q} (m: B0 ~> PSpan.sort B) : Prop := + @GMedArrow Q L R T l r (@comm_square Q L R T l r) B lprj rprj B0 m. + +Definition has_medarrow {Q: precat} {L R T: Q} + (l: L ~> T) (r: R ~> T) + (B: @pspan Q L R T l r) + (B0: Q) : Type := sigma m, @medarrow_prop Q L R T l r B B0 m. + +Definition medarrow_is_unique {Q: precat} {L R T: Q} + (l: L ~> T) (r: R ~> T) + (B: @pspan Q L R T l r) {B0: Q} : Prop := + forall (m m': B0 ~> PSpan.sort B), + @medarrow_prop Q L R T l r B B0 m -> + @medarrow_prop Q L R T l r B B0 m' -> m = m'. + +HB.mixin Record IsPrePBack (Q: precat) (L R T: Q) (l: L ~> T) (r: R ~> T) + (B: @pspan Q L R T l r) : Type := { + comm_sq : comm_square l r (@lprj Q L R T l r B) rprj ; + }. +#[short(type="prepback"), verbose] +HB.structure Definition PrePBack (Q: precat) + {L R T : Q} (l: L ~> T) (r: R ~> T) := + { B of IsPrePBack Q L R T l r B }. + +HB.mixin Record IsPBack (Q: precat) (L R T: Q) (l: L ~> T) (r: R ~> T) + (B: @prepback Q L R T l r) : Type := { + has_umarrow : forall B0: Q, @has_medarrow Q L R T l r B B0 + * @medarrow_is_unique Q L R T l r B B0 + }. +#[short(type="pback"), verbose] +HB.structure Definition PBack (Q: precat) + {L R T : Q} (l: L ~> T) (r: R ~> T) := + { B of IsPBack Q L R T l r B }. + +(* packs all the definition together *) +HB.mixin Record IsPBack2 (Q: precat) (L R T: Q) (l: L ~> T) (r: R ~> T) + (B: @pspan Q L R T l r) : Type := { + comm_sq : comm_square l r (@lprj Q L R T l r B) rprj ; + has_umarrow : forall B0: Q, @has_medarrow Q L R T l r B B0 + * @medarrow_is_unique Q L R T l r B B0 + }. +#[short(type="pback2"), verbose] +HB.structure Definition PBack2 (Q: precat) + {L R T : Q} (l: L ~> T) (r: R ~> T) := + { B of IsPBack2 Q L R T l r B }. + + +(***********************************************************************) + +(*** CATEGORIES WITH PULLBACKS *) + +(* category with all pullbacks *) +HB.mixin Record HasPBKop C of Cat C := { + pbkop : forall {L R T: C} (l: L ~> T) (r: R ~> T), @pspan C L R T l r + }. +#[short(type="pbkop")] +HB.structure Definition PBKop := + {C of HasPBKop C & PreCat C }. + +#[wrapper] +HB.mixin Record HasPrePBKcat C of PBKop C : Type := { + is_gppbk : forall {L R T: C} (l: L ~> T) (r: R ~> T), + @IsPrePBack C L R T l r (@pbkop C L R T l r) + }. +#[short(type="prepbkcat")] +HB.structure Definition PrePBKcat := + {C of HasPrePBKcat C}. + +(* category with all pullbacks *) +(* PROBLEM: fails as a wrapper *) +(* #[wrapper] *) +HB.mixin Record HasPBKcat C of PrePBKcat C := { + is_gpbk : forall {L R T: C} (l: L ~> T) (r: R ~> T), + @IsPBack C L R T l r (@pbkop C L R T l r) + }. +#[short(type="pbkcat")] +HB.structure Definition PBKcat := + {C of HasPBKcat C & PreCat C }. + +(* on the other hand, this works... *) +#[wrapper] +HB.mixin Record HasPBK2cat C of PBKop C := { + is_gpbk2 : forall {L R T: C} (l: L ~> T) (r: R ~> T), + @IsPBack2 C L R T l r (@pbkop C L R T l r) + }. +#[short(type="pbk2cat")] +HB.structure Definition PBK2cat := + {C of HasPBK2cat C & PreCat C }. + + +(***********************************************************************) + +HB.mixin Record isInternalHom {C: quiver} (C0 : C) (C1 : obj C) := { + src : C1 ~> C0; tgt : C1 ~> C0 +}. +#[short(type="iHom")] +HB.structure Definition InternalHom {C: quiver} (C0 : C) := + { C1 of isInternalHom C C0 C1 }. + +Notation "X ':>' C" := (X : obj C) (at level 60, C at next level). + +Definition iprod_pb {C: pbk2cat} {C0 : C} (X Y : iHom C0) : + pspan (@tgt C C0 (X :> C)) (@src C C0 (Y :> C)) := + @pbkop C (X :> C) (Y :> C) C0 (tgt : (X :> C) ~> C0) (src : (Y :> C) ~> C0). + +(* could be problematic... *) +Program Definition iprod {C: pbk2cat} {C0 : obj C} (X Y : iHom C0) : C. +set (x := @iprod_pb C C0 X Y). +eapply x. +Defined. + +Notation "X *_ C0 Y" := (@iprod _ C0 (X : iHom C0) (Y : iHom C0)) + (at level 99, C0 at level 0, only parsing) : cat_scope. +Notation "X *_ C0 Y" := (@iprod _ C0 X Y) + (at level 99, C0 at level 0) : cat_scope. + +(* +HB.mixin Record IsPBkObj {Q: precat} {L R T: Q} + (l: L ~> T) (r: R ~> T) (B: Q) : Type := { + lprj : B ~> L ; + rprj : B ~> R + }. +#[short(type="pbkobj"), verbose] +HB.structure Definition PBkObj {Q: precat} + {L R T : Q} (l: L ~> T) (r: R ~> T) := + { B of IsPBkObj Q L R T l r B }. + +Definition comm_square {Q: precat} {L R T: Q} + (l: L ~> T) (r: R ~> T) {B: Q} (p1: B ~> L) (p2: B ~> R) : Prop := + p1 \; l = p2 \; r. + +Definition comm_triangle {Q: precat} {A B C: Q} + (h: A ~> C) (f: A ~> B) (g: B ~> C) : Prop := + h = f \; g. + +HB.mixin Record IsMedArrow {Q: precat} {L R T: Q} + (l: L ~> T) (r: R ~> T) + (P: forall (B: Q) (p1: B ~> L) (p2: B ~> R), Type) + {B: Q} (p1: B ~> L) (p2: B ~> R) {B0: Q} + (m: B0 ~> B) := { + marrow_prop : forall (p01: B0 ~> L) (p02: B0 ~> R), + P B0 p01 p02 -> comm_triangle p01 m p1 /\ comm_triangle p02 m p2 +}. +#[short(type="medarrow"), verbose] + HB.structure Definition MedArrow {Q: precat} {L R T: Q} + (l: L ~> T) (r: R ~> T) + (P: forall (B: Q) (p1: B ~> L) (p2: B ~> R), Type) + {B: Q} (p1: B ~> L) (p2: B ~> R) (B0: Q) := { + m of @IsMedArrow Q L R T l r P B p1 p2 B0 m }. + +HB.tag +Definition has_medarrow {Q: precat} {L R T: Q} + (l: L ~> T) (r: R ~> T) (B: @pbkobj Q L R T l r) := + forall B0, sigma m, forall p1 p2, + @MedArrow Q L R T l r (@comm_square Q L R T l r) B p1 p2 B0 m. + +#[wrapper] +HB.mixin Record HasMedArrow {Q: precat} {L R T: Q} + (l: L ~> T) (r: R ~> T) + {B: Q} (p1: B ~> L) (p2: B ~> R) {B0: Q} := { + marrow : @has_medarrow Q L R T l r (@comm_square Q L R T l r) B p1 p2 B0 +}. + + +HB.tag +Definition has_medarrow {Q: precat} {L R T: Q} + (l: L ~> T) (r: R ~> T) (B: @pbkobj Q L R T l r) := + forall B0, sigma m, forall p1 p2, + @MedArrow Q L R T l r (@comm_square Q L R T l r) B p1 p2 B0 m. + +Definition medarrow_unique {Q: precat} {L R T: Q} + (l: L ~> T) (r: R ~> T) + (P: forall (B: Q) (p1: B ~> L) (p2: B ~> R), Type) + {B: Q} (p1: B ~> L) (p2: B ~> R) {B0: Q} + (m m': medarrow l r P p1 p2 B0) : Prop := m = m'. + +HB.mixin Record IsPrePBack (Q: precat) (L R T: Q) (l: L ~> T) (r: R ~> T) + (B: @pbkobj Q L R T l r) : Type := { + comm_sq : comm_square l r (@lprj Q L R T l r B) rprj + }. +#[short(type="prepback"), verbose] +HB.structure Definition PrePBack (Q: precat) + {L R T : Q} (l: L ~> T) (r: R ~> T) := + { B of IsPrePBack Q L R T l r B }. + +#[wrapper] +HB.mixin Record IsPBack (Q: precat) (L R T: Q) (l: L ~> T) (r: R ~> T) + (B: @prepback Q L R T l r) : Type := { + marrow : @has_medarrow Q L R T l r B +}. + +HB.mixin unique_limit_prop {Q: precat} {L R T: Q} (l: L ~> T) (r: R ~> T) + (P: forall (B: Q) (p1: B ~> L) (p2: B ~> R), Type) + {B: Q} (p1: B ~> L) (p2: B ~> R) {B0: Q} (p01: B ~> L) (p02: B ~> R) : + Type := P B p1 p2 -> + forall B0 p01 p02, + P B0 p01 p02 -> + sigma (m: B0 ~> B), comm_triangle p01 m p1 /\ comm_triangle p02 m p2. + +Record isPBack (Q : precat) (L R T B : Q) : U := { + (p1: B ~> L) (p2: B ~> R) (l: L ~> T) (r: R ~> T) + (c : cospan A B) (s : span A B) := { + is_square : bot2left s \; left2top c = bot2right s \; right2top c; +}. + +HB.mixin Record isPBsquare (Q : precat) (L R T B : Q) + (p1: B ~> L) (p2: B ~> R) (l: L ~> T) (r: R ~> T) + (c : cospan A B) (s : span A B) := { + is_square : bot2left s \; left2top c = bot2right s \; right2top c; +}. +#[short(type=prepullback)] +HB.structure Definition PrePullback Q A B (c : cospan A B) := + {s of isPrePullback Q A B c s}. +Arguments prepullback {Q A B} c. +*) + +(************************************************************************) + +(**** INTERNAL CATEGORIES - NEW DEFINITION *) + +(* Defining internal hom objects. + C0 and C1 are objects of C. + C0 is the object of objects, + C1 is the object of morphims (and the subject). + this will allow to define a generic _ *_C0 _ notation + by recognizing the structure of hom objects on the LHS and RHS + Basically, w.r.t. double categories, C1 represents 'horizontal' + 1-morpshisms and the D1 category, whereas C0 represents the objects + of the base D0 category. *) +HB.mixin Record isInternalHom {C: quiver} (C0 : C) (C1 : obj C) := { + src : C1 ~> C0; tgt : C1 ~> C0 +}. +#[short(type="iHom")] +HB.structure Definition InternalHom {C: quiver} (C0 : C) := + { C1 of isInternalHom C C0 C1 }. + +Notation "X ':>' C" := (X : obj C) (at level 60, C at next level). + +(* HB.instance Definition _ (T : quiver) := Quiver.on (obj T). *) +(* HB.instance Definition _ (T : precat) := PreCat.on (obj T). *) +(* HB.instance Definition _ (T : cat) := Cat.on (obj T). *) +(* HB.instance Definition _ (T : pbcat) := PBCat.on (obj T). *) + +(* constructs the pullback from the cospan given by target and source. + Type-level construction: X and Y are two instances of the morphism + object, specified by (iHom C0), and are objects of (obj C). Here + 'iprod' is just an object of (obj C). The cospan is given by the + target of X and the source of Y. The pullback provides a commuting + square on the cospan, which basically ensures that the morphisms in + X and Y can be composed. *) +Definition iprod_pb {C: pbcat} {C0 : C} (X Y : iHom C0) : + span (X :> C) (Y :> C) := + pbk _ _ (Cospan (tgt : (X :> C) ~> C0) (src : (Y :> C) ~> C0)). + +Definition iprod {C: pbcat} {C0 : obj C} (X Y : iHom C0) : obj C := + bot (@iprod_pb C C0 X Y). +Notation "X *_ C0 Y" := (@iprod _ C0 (X : iHom C0) (Y : iHom C0)) + (at level 99, C0 at level 0, only parsing) : cat_scope. +Notation "X *_ C0 Y" := (@iprod _ C0 X Y) + (at level 99, C0 at level 0) : cat_scope. + +(* +(1) Defines pullback square (iprod_pb) + + X --- tgt -----> C0 + ^ ^ + | | + bot2left src + | | + X*Y - bot2right -> Y + + +(2) Defines source and target of the product (iprod_iHom) + + X --- src -----> C0 + ^ ^ + | | + iprodl tgt + | | + X*Y -- iprodr ---> Y +*) + +(* left and right projection morphisms of the product *) +Definition iprodl {C: pbcat} {C0 : C} (X Y : iHom C0) : + X *_C0 Y ~> (X :> C) := bot2left (iprod_pb X Y). +Definition iprodr {C: pbcat} {C0 : C} (X Y : iHom C0) : + X *_C0 Y ~> (Y :> C) := bot2right (iprod_pb X Y). + +(* Given (iHom C0) instances X and Y, we want to say that (X *_C0 Y) +is also an instance of (iHom C0). X and Y represent composable +morphisms, as by pullback properties, the diagram (1) commutes. +source and target are obtained by composing with product projections +(2) *) +Definition iprod_iHom {C: pbcat} {C0: C} (X Y: @iHom C C0) : + @isInternalHom C C0 (X *_C0 Y) := + @isInternalHom.Build C C0 (X *_C0 Y) + ((iprodl X Y) \; src) + ((iprodr X Y) \; tgt). + +HB.instance Definition iprod_iHom' {C: pbcat} {C0: C} (X Y: @iHom C C0) : + @isInternalHom C C0 (X *_C0 Y) := iprod_iHom X Y. + +(* the product as (iHom C0) object *) +Definition pbC0 (C : pbcat) (C0 : C) (X Y : iHom C0) : iHom C0 := + (X *_C0 Y) : iHom C0. + +(* we also define the trivial internal hom type *) +HB.instance Definition trivial_iHom {C: pbcat} {C0: C} : + @isInternalHom C C0 C0 := + isInternalHom.Build C C0 C0 idmap idmap. + +(**) + +Definition trivial_iHom' {C: pbcat} {C0: C} : @iHom C C0 := + InternalHom.Pack (InternalHom.Class (@trivial_iHom C C0)). + +Definition trivial_iprod_iHom {C: pbcat} {C0: C} : + @isInternalHom C C0 ((@trivial_iHom' C C0) *_C0 (@trivial_iHom' C C0)) := + @iprod_iHom' C C0 (@trivial_iHom' C C0) (@trivial_iHom' C C0). + +Definition trivial_iprod_iHom' {C: pbcat} {C0: C} : @iHom C C0 := + InternalHom.Pack (InternalHom.Class (@trivial_iprod_iHom C C0)). + +(**) + +(* we need internal hom morphisms: +the ones that preserve sources and targets. +basically, we recast morphisms in (obj C) into some in (@iHom C C0), +i.e. into morphism between copies of C1 *) +HB.mixin Record IsInternalHomHom {C: pbcat} (C0 : C) + (C1 C1' : @iHom C C0) (f : (C1 :> C) ~> (C1' :> C)) := { + hom_src : f \; (@src C C0 C1') = (@src C C0 C1); + hom_tgt : f \; tgt = tgt; +}. +#[short(type="iHomHom")] +HB.structure Definition InternalHomHom {C: pbcat} + (C0 : C) (C1 C1' : @iHom C C0) := + { f of @IsInternalHomHom C C0 C1 C1' f }. + +(* internal homs form a category, + the morphisms are the one that preserve source and target *) +HB.instance Definition iHom_quiver {C: pbcat} (C0 : C) : + IsQuiver (@iHom C C0) := + IsQuiver.Build (@iHom C C0) (@iHomHom C C0). +Print iHom_quiver. + +Program Definition pre_iHom_id {C: pbcat} (C0 : C) (C1 : @iHom C C0) : + @IsInternalHomHom C C0 C1 C1 idmap := + @IsInternalHomHom.Build C C0 C1 C1 idmap _ _. +Obligation 1. +setoid_rewrite comp1o; reflexivity. +Defined. +Obligation 2. +setoid_rewrite comp1o; reflexivity. +Defined. + +Program Definition iHom_id {C: pbcat} (C0 : C) (C1 : @iHom C C0) : + C1 ~>_(@iHom C C0) C1 := + @InternalHomHom.Pack C C0 C1 C1 idmap _. +(* +The term "pre_iHom_id C1" has type "IsInternalHomHom.phant_axioms idmap" +while it is expected to have type "InternalHomHom.axioms_ ?sort". +*) +Obligation 1. +econstructor. +eapply (@pre_iHom_id C C0 C1). +Defined. + +Program Definition pre_iHom_comp {C: pbcat} (C0 : C) (C1 C2 C3: @iHom C C0) + (f: C1 ~>_(@iHom C C0) C2) (g: C2 ~>_(@iHom C C0) C3) : + @IsInternalHomHom C C0 C1 C3 (f \; g) := + @IsInternalHomHom.Build C C0 C1 C3 (f \; g) _ _. +Obligation 1. +setoid_rewrite <- compoA. +repeat (setoid_rewrite hom_src); auto. +Defined. +Obligation 2. +setoid_rewrite <- compoA. +repeat (setoid_rewrite hom_tgt); auto. +Defined. + +Program Definition iHom_comp {C: pbcat} (C0 : C) (C1 C2 C3: @iHom C C0) + (f: C1 ~>_(@iHom C C0) C2) (g: C2 ~>_(@iHom C C0) C3) : + C1 ~>_(@iHom C C0) C3 := + @InternalHomHom.Pack C C0 C1 C3 (f \; g) _. +Obligation 1. +econstructor. +eapply (@pre_iHom_comp C C0 C1 C2 C3 f g). +Defined. + +Program Definition iHom_precat {C: pbcat} (C0 : C) : + Quiver_IsPreCat (@iHom C C0) := + Quiver_IsPreCat.Build (@iHom C C0) _ _. +Obligation 1. +eapply (@iHom_id C C0 a). +Defined. +Obligation 2. +eapply (@iHom_comp C C0 a b c0 X X0). +Defined. + +HB.instance Definition iHom_precat' {C: pbcat} (C0 : C) := iHom_precat C0. + +Lemma iHom_LeftUnit_lemma (C : pbcat) (C0 : C) + (a b : iHom C0) (f : a ~> b) : idmap \; f = f. +unfold idmap; simpl. +unfold iHom_precat_obligation_1. +unfold comp; simpl. +unfold iHom_precat_obligation_2. +unfold iHom_comp. +remember f as f1. +remember a as a1. +remember b as b1. +destruct f as [ff class]. +destruct a as [Ca class_a]. +destruct b as [Cb class_b]. +destruct class_a as [IMa]. +destruct class_b as [IMb]. +destruct class as [IM]. +destruct IMa. +destruct IMb. +destruct IM. +unfold obj in *. +simpl in *; simpl. + +eassert ( forall x, exists y, + {| + InternalHomHom.sort := idmap \; f1; + InternalHomHom.class := x + |} = + {| + InternalHomHom.sort := f1; + InternalHomHom.class := y + |} ) as A2. +{ rewrite Heqf1; simpl. + rewrite comp1o. + intros. + destruct x as [X]. + econstructor. + destruct X. + reflexivity. +}. + +setoid_rewrite Heqf1 at 3. +specialize (A2 (iHom_comp_obligation_1 (iHom_id a1) f1)). +destruct A2. +rewrite H. + +inversion Heqf1; subst. +simpl. +destruct x as [IM]. +destruct IM. + +assert (hom_src0 = hom_src1) as D1. +{ eapply Prop_irrelevance. } + +assert (hom_tgt0 = hom_tgt1) as D2. +{ eapply Prop_irrelevance. } + +rewrite D1. +rewrite D2. +reflexivity. +Qed. + +Lemma iHom_RightUnit_lemma (C : pbcat) (C0 : C) + (a b : iHom C0) (f : a ~> b) : f \; idmap = f. +unfold idmap; simpl. +unfold iHom_precat_obligation_1. +unfold comp; simpl. +unfold iHom_precat_obligation_2. +unfold iHom_comp. +remember f as f1. +remember a as a1. +remember b as b1. +destruct f as [ff class]. +destruct a as [Ca class_a]. +destruct b as [Cb class_b]. +destruct class_a as [IMa]. +destruct class_b as [IMb]. +destruct class as [IM]. +destruct IMa. +destruct IMb. +destruct IM. +unfold obj in *. +simpl in *; simpl. + +eassert ( forall x, exists y, + {| + InternalHomHom.sort := f1 \; idmap; + InternalHomHom.class := x + |} = + {| + InternalHomHom.sort := f1; + InternalHomHom.class := y + |} ) as A2. +{ rewrite Heqf1; simpl. + rewrite compo1. + intros. + destruct x as [X]. + econstructor. + destruct X. + reflexivity. +} + +setoid_rewrite Heqf1 at 3. +specialize (A2 (iHom_comp_obligation_1 f1 (iHom_id b1))). +destruct A2. +rewrite H. + +inversion Heqf1; subst. +simpl. +destruct x as [IM]. +destruct IM. + +assert (hom_src0 = hom_src1) as D1. +{ eapply Prop_irrelevance. } + +assert (hom_tgt0 = hom_tgt1) as D2. +{ eapply Prop_irrelevance. } + +rewrite D1. +rewrite D2. +reflexivity. +Qed. + +Lemma iHom_Assoc_lemma {C : pbcat} (C0 : C) + (a b c d : iHom C0) (f : a ~> b) (g : b ~> c) (h : c ~> d) : + f \; g \; h = (f \; g) \; h. + unfold comp; simpl. + unfold iHom_precat_obligation_2; simpl. + unfold iHom_comp; simpl. + remember f as f1. + remember g as g1. + remember h as h1. + destruct f as [M_f class_f]. + destruct g as [M_g class_g]. + destruct h as [M_h class_h]. + destruct class_f as [IM_f]. + destruct class_g as [IM_g]. + destruct class_h as [IM_h]. + destruct IM_f. + destruct IM_g. + destruct IM_h. + unfold obj in *; simpl in *; simpl. + + eassert ( forall x y, + {| InternalHomHom.sort := f1 \; g1 \; h1; + InternalHomHom.class := x |} = + {| InternalHomHom.sort := (f1 \; g1) \; h1; + InternalHomHom.class := y |} ) as A2. + { rewrite Heqf1; simpl. + rewrite compoA. + intros. + destruct x as [X]. + destruct y as [Y]. + destruct X. + destruct Y. + + assert (hom_src3 = hom_src4) as D1. + { eapply Prop_irrelevance. } + + assert (hom_tgt3 = hom_tgt4) as D2. + { eapply Prop_irrelevance. } + + rewrite D1. + rewrite D2. + reflexivity. + }. + + setoid_rewrite A2. + reflexivity. +Qed. + +Program Definition iHom_cat {C: pbcat} (C0 : C) : + PreCat_IsCat (@iHom C C0) := + PreCat_IsCat.Build (@iHom C C0) _ _ _. +Obligation 1. +eapply iHom_LeftUnit_lemma; eauto. +Qed. +Obligation 2. +eapply iHom_RightUnit_lemma; eauto. +Qed. +Obligation 3. +eapply iHom_Assoc_lemma; eauto. +Qed. + +(* Now we define an internal quiver as an object C0, + which has a C1 : iHom C0 attached to it *) +HB.mixin Record IsPreInternalQuiver (C : quiver) (C0 : obj C) := + { C1 : obj C }. +HB.structure Definition PreInternalQuiver C := + { C0 of @IsPreInternalQuiver C C0 }. + +Arguments C1 {C s}. + +#[wrapper] HB.mixin Record IsInternalQuiver (C : quiver) (C0 : obj C) of + @PreInternalQuiver C C0 := { + priv: @InternalHom C C0 (@C1 _ C0) + }. +#[short(type="iquiver")] +HB.structure Definition InternalQuiver (C : quiver) := + { C0 of IsInternalQuiver C C0 }. + +Coercion iquiver_quiver (C : quiver) (C0 : iquiver C) : C := C0 :> C. +Coercion iquiver_precat (C : precat) (C0 : iquiver C) : C := C0 :> C. +Coercion iquiver_cat (C : cat) (C0 : iquiver C) : C := C0 :> C. + +(* nested product *) +Program Definition iprodCAsc {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : + (((C1 *_C0 C2 : iHom C0) *_C0 C3) :> C) ~>_C + ((C1 *_C0 (C2 *_C0 C3 : iHom C0) : iHom C0) :> C). +Admitted. + +Lemma pbsquare_universal {C: cat} (A B T P0 P1 : C) + (t: A ~> T) (s: B ~> T) (p1: P0 ~> A) (p2: P0 ~> B) + (f: P1 ~> A) (g: P1 ~> B) : + pbsquare p1 p2 t s -> + f \; t = g \; s -> + sigma m: P1 ~> P0, f = m \; p1 /\ g = m \; p2. + intros sq E. + destruct sq as [IM1 IM2]. + + remember (Span p1 p2) as Spn0. + remember (@Cospan C A B T t s) as Csp. + remember (@Span C A B P1 f g) as Spn1. + + destruct IM1 as [IM3]. + destruct IM2 as [IM4]. + + assert (bot2left Spn1 \; left2top Csp = bot2right Spn1 \; right2top Csp) + as K1. + { unfold bot2left, bot2right. + rewrite HeqCsp. + rewrite HeqSpn1. + simpl; auto. + } + remember ( @isPrePullback.Build C A B Csp Spn1 K1) as Pb1. + assert (PrePullback.axioms_ Csp Spn1) as Pb2. + { econstructor. + exact Pb1. } + remember ( @PrePullback.Pack C A B Csp Spn1 Pb2) as PB. + + destruct IM4 as [IM5 IM6]. + clear IM6. + specialize (IM5 PB). + + inversion HeqSpn1; subst. + simpl in *. + clear H K1. + + unfold pb_terminal in *. + destruct Pb2 as [IM]. + destruct IM. + simpl in *. + + destruct IM5. + simpl in *. + + econstructor. + instantiate (1:= bot_map0). + split; auto. +Qed. + +Lemma pbquare_universal_aux1 {C: cat} (A0 A1 B0 B1 P0 P1 T : C) + (t: A0 ~> T) (s: B0 ~> T) (p01: P0 ~> A0) (p02: P0 ~> B0) + (f: A1 ~> A0) (g: B1 ~> B0) (p11: P1 ~> A1) (p12: P1 ~> B1) : + pbsquare p01 p02 t s -> + p11 \; f \; t = p12 \; g \; s -> + sigma m: P1 ~> P0, p11 \; f = m \; p01 /\ p12 \; g = m \; p02. + intros. + eapply pbsquare_universal; eauto. + setoid_rewrite <- compoA; auto. +Qed. + +(* Lemma is_pullback_in_pbcat {C: pbcat} *) + +(* +Set Debug "unification". +Lemma ... +Proof. + Fail ... +*) + +Lemma pbk_eta {C: pbcat} {C0} (X Y: iHom C0) : + (pbk (X :> C) (Y :> C) (Cospan (@tgt C C0 X) (@src C C0 Y))) = + (Span (iprodl X Y) (iprodr X Y)). + unfold iprodl, iprodr, iprod. + unfold iprod_pb; simpl. + destruct (pbk (X :> C) (Y :> C) + {| top := C0; left2top := tgt; right2top := src |}). + simpl; auto. +Qed. + +Lemma pbk_pullback_is_pullback {C: pbcat} {C0} (X Y: iHom C0) : + Pullback C (Cospan (@tgt C C0 X) (@src C C0 Y)) + (pbk (X :> C) (Y :> C) (Cospan (@tgt C C0 X) (@src C C0 Y))) = + Pullback C (Cospan (@tgt C C0 X) (@src C C0 Y)) + (Span (iprodl X Y) (iprodr X Y)). + rewrite pbk_eta; auto. +Qed. + +Lemma pbsquare_is_pullback {C: pbcat} {C0} (X Y: iHom C0) : + pbsquare (iprodl X Y) (iprodr X Y) (@tgt C C0 X) (@src C C0 Y) = + Pullback C (Cospan (@tgt C C0 X) (@src C C0 Y)) + (pbk (X :> C) (Y :> C) (Cospan (@tgt C C0 X) (@src C C0 Y))). + rewrite pbk_pullback_is_pullback; auto. +Qed. + +Lemma pbsquare_is_pullback_sym {C: pbcat} {C0} (X Y: iHom C0) : + Pullback C (Cospan (@tgt C C0 X) (@src C C0 Y)) + (pbk (X :> C) (Y :> C) (Cospan (@tgt C C0 X) (@src C C0 Y))) = + pbsquare (iprodl X Y) (iprodr X Y) (@tgt C C0 X) (@src C C0 Y). + rewrite pbk_pullback_is_pullback; auto. +Qed. + +Program Definition ipairC {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} + (f : x0 ~>_(iHom C0) x2) (g : x1 ~>_(iHom C0) x3) : + (x0 *_C0 x1 :> C) ~>_C (x2 *_C0 x3 :> C). + + remember (x0 *_ C0 x1 : iHom C0) as Pb1. + remember (x2 *_ C0 x3 : iHom C0) as Pb2. + + remember (@Cospan C (x0 :> C) (x1 :> C) C0 + (@tgt C C0 x0) (@src C C0 x1)) as Csp1. + + remember (@Cospan C (x2 :> C) (x3 :> C) C0 + (@tgt C C0 x2) (@src C C0 x3)) as Csp2. + + set (src0 := @src C C0 x0). + set (tgt0 := @tgt C C0 x0). + + set (src1 := @src C C0 x1). + set (tgt1 := @tgt C C0 x1). + + set (src2 := @src C C0 x2). + set (tgt2 := @tgt C C0 x2). + + set (src3 := @src C C0 x3). + set (tgt3 := @tgt C C0 x3). + + remember (@src C C0 (x0 *_C0 x1)) as src01. + remember (@tgt C C0 (x0 *_C0 x1)) as tgt01. + + remember (@src C C0 (x2 *_C0 x3)) as src23. + remember (@tgt C C0 (x2 *_C0 x3)) as tgt23. + + set (Sp1 := pbk (x0 :> C) (x1 :> C) Csp1). + set (Sp2 := pbk (x2 :> C) (x3 :> C) Csp2). + + assert (@Pullback C (x0 :> C) (x1 :> C) Csp1 Sp1) as PBa1. + { remember C as C'. + destruct C as [C class]. + destruct class as [A1 A2 A3 A4 A5 A6]. + destruct A6 as [B1]. + assert (pb (pbk (x0 :> C') (x1 :> C') Csp1)). + { inversion HeqC'; subst. + eapply B1; eauto. } + econstructor; eauto. + } + + assert (@Pullback C (x2 :> C) (x3 :> C) Csp2 Sp2) as PBa2. + { remember C as C'. + destruct C as [C class]. + destruct class as [A1 A2 A3 A4 A5 A6]. + destruct A6 as [B1]. + assert (pb (pbk (x2 :> C') (x3 :> C') Csp2)). + { inversion HeqC'; subst. + eapply B1; eauto. } + econstructor; eauto. + } + +(* assert (@Pullback C (x2 :> C) (x3 :> C) Csp2 Sp2) as PBa2. + admit. +*) + assert ((x0 *_ C0 x1) = bot Sp1) as E01. + { subst Sp1. + unfold iprod. + unfold iprod_pb. + rewrite HeqCsp1; auto. + } + + assert ((x2 *_ C0 x3) = bot Sp2) as E23. + { subst Sp2. + unfold iprod. + unfold iprod_pb. + rewrite HeqCsp2; auto. + } + + set (prj11 := @iprodl C C0 x0 x1). + set (prj12 := @iprodr C C0 x0 x1). + + set (prj21 := @iprodl C C0 x2 x3). + set (prj22 := @iprodr C C0 x2 x3). + + set (ff := prj11 \; f). + set (gg := prj12 \; g). + + assert ((f : (x0 :> C) ~>_C (x2 :> C)) \; tgt2 = tgt0) as E20. + { remember f as f1. + destruct f as [fsort fclass]. + destruct fclass as [fIM]. + destruct fIM. + inversion Heqf1; subst. + simpl in *; simpl; auto. + } + + assert ((g : (x1 :> C) ~>_C (x3 :> C)) \; src3 = src1) as E31. + { remember g as g1. + destruct g as [gsort gclass]. + destruct gclass as [gIM]. + destruct gIM. + inversion Heqg1; subst. + simpl in *; simpl; auto. + } + + assert (prj11 \; tgt0 = prj12 \; src1) as E11. + { destruct PBa1 as [C1 C2]. + destruct C1 as [C3]. + inversion HeqCsp1; subst. + simpl in *; auto. + } + + assert (ff \; tgt2 = gg \; src3) as E1. + { subst ff gg. + setoid_rewrite <- compoA. + rewrite E20. + rewrite E31. + exact E11. + } + + (* basically, follows from pbquare_universal and E1. + sordid eta-conversion issue fixed by pbsquare_is_pullback *) + assert (sigma m: ((x0 *_ C0 x1) ~>_C (x2 *_ C0 x3) :> C), + ff = m \; prj21 /\ gg = m \; prj22) as EM. + { eapply (@pbsquare_universal C) ; eauto. + + remember C as C'. + destruct C as [C class]. + destruct class as [A1 A2 A3 A4 A5 A6]. + destruct A6 as [B1]. + subst prj21 prj22. + + (* surprisingly, this does not work with pbsquare_is_pulback_sym *) + (* rewrite <- pbsquare_is_pullback_sym. *) + rewrite pbsquare_is_pullback. + inversion HeqCsp2; subst. + subst Sp2. + exact PBa2. + } + + destruct EM as [mm [EM1 EM2]]. + exact mm. +Qed. + +Notation "<( f , g )>" := (ipairC f g). + +(* An internal precategory is an internal category with two operators + that must be src and tgt preserving, i.e. iHom morphisms: identity + : C0 -> C1 (corresponding to horizontal 1-morphism identity in + double cat) and composition : C1 * C1 -> C1 (corresponding to + horizontal composition) *) +HB.mixin Record IsInternalPreCat (C : pbcat) (C0 : obj C) + of @InternalQuiver C C0 := { + iidI : (C0 : iHom C0) ~>_(iHom C0) (@C1 C C0 : iHom C0); + icompI : let C1 := @C1 C C0 : iHom C0 in + let C2 := pbC0 C1 C1 : iHom C0 in + (C2 ~>_(iHom C0) C1) +}. +#[short(type="iprecat")] +HB.structure Definition InternalPreCat (C : pbcat) := + { C0 of @IsInternalPreCat C C0 }. + +Program Definition iidC' {C : pbcat} {C0 : iprecat C} : + ((C0 : iHom C0) :> C) ~>_C + ((@C1 C C0 : iHom C0) :> C). +destruct C0; simpl in *. +destruct class as [IM1 IM2 IM3]; simpl in *. +destruct IM3; simpl in *. +exact iidI0. +Defined. +Program Definition iidC {C : pbcat} {C0 : iprecat C} : + (C0 :> C) ~>_C (@C1 C C0 :> C). +eapply iidC'; eauto. +Defined. + +Program Definition icompC {C : pbcat} {C0 : iprecat C} : + let C1 := @C1 C C0 : iHom C0 in + let C2 := pbC0 C1 C1 : iHom C0 in + ((C2 :> C) ~>_C (C1 :> C)). +destruct C0; simpl in *. +destruct class as [IM1 IM2 IM3]; simpl in *. +destruct IM3; simpl in *. +exact icompI0. +Defined. + +(* Check (iquiver Type <~> quiver). *) +(* Check (iprecat Type <~> precat). *) + +(* An internal category moreover must satisfy additional properies on +iid and icomp (associativity and unit laws) *) +#[key="C0"] + HB.mixin Record IsInternalCat (C : pbcat) (C0 : obj C) + of InternalPreCat C C0 := { + icompA1 : + (<( (@icompI C C0), + (@idmap (iHom C0) (@C1 C C0: iHom C0)) )> \; icompC) = + ((@iprodCAsc C C0 (@C1 C C0: iHom C0) _ _) \; + <( (@idmap (iHom C0) (@C1 C C0: iHom C0)), icompI )> \; icompC) ; + + icomp1l : <( @idmap (iHom C0) (@C1 C C0: iHom C0), (@iidI C C0) )> \; + icompC = @iprodl C C0 (C1 :> C) (C0 :> C); + + icomp1r : <( (@iidI C C0), @idmap (iHom C0) (@C1 C C0: iHom C0) )> \; + icompC = @iprodr C C0 (C0 :> C) (C1 :> C); + }. +#[short(type="icat")] +HB.structure Definition InternalCat (C : pbcat) := + {C0 of @IsInternalCat C C0}. +(* Check (icat Type <~> cat). *) + +(* A double category is an internal category in cat + - The objects are the objects of C0 + - The vertical maps are the maps of C0 + - The horizontal maps are the objects of C1 + - The 2-cells are the maps of C1 + + About identities: + - The identity vertical map on (x : C) is \idmap_x + - The identity horizontal map on (x : C) is iid x + - the identity 2-cell on (x : C) is iid (\idmap_x) = \idmap_(iid x) + + About compositions: + - The vertical composition of maps is the composition of C0 + - The vertical compositions of 2-cells is the composition of C1 + (and it agrees with the former because src and tgt are functors + and because iid is a iHom-map) + - The horizontal composition of maps is the object part of icomp + - The horizontal composition of 2-cells is the map part of icomp +*) +(* HB.structure' Definition DoubleCat := @InternalCat cat. *) +Axiom cat_pbop : HasPBop cat. +HB.instance Definition _ := cat_pbop. + +Axiom cat_preb : + forall (a b: cat) (c: cospan a b), isPrePullback cat a b c (@pbk cat a b c). +HB.instance Definition _ (a b: cat) (c: cospan a b) := @cat_preb a b c. +Axiom cat_pb : + forall (a b: cat) (c: cospan a b), + prepullback_isTerminal cat a b c (@pbk cat a b c). +HB.instance Definition _ (a b: cat) (c: cospan a b) := @cat_pb a b c. + +(* basically, the internal category adds the D1 category to the base +D0 category, which is C0 (an object of cat, which is shown to have +pullbacks) *) +Definition doublecat := icat cat. + +(* Check (doublecat <~> ???) *) + From ab638819325c4eac6bc638f61cd8165e2b61cb2d Mon Sep 17 00:00:00 2001 From: ptorrx Date: Tue, 9 Jan 2024 17:39:38 +0100 Subject: [PATCH 116/147] updated encatI.v --- theories/encatI.v | 126 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 110 insertions(+), 16 deletions(-) diff --git a/theories/encatI.v b/theories/encatI.v index fc36aa220..2596902fd 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -1710,6 +1710,12 @@ Coercion iquiver_quiver (C : quiver) (C0 : iquiver C) : C := C0 :> C. Coercion iquiver_precat (C : precat) (C0 : iquiver C) : C := C0 :> C. Coercion iquiver_cat (C : cat) (C0 : iquiver C) : C := C0 :> C. +Definition jmcomp {C: cat} {a b c d: C} (e: c = b) (f: a ~> b) (g: c ~> d) := + f \; match e with eq_refl => g end. +Notation "f \;;_ e g" := (@jmcomp _ _ _ _ _ e f g) + (at level 60, g at level 60, e at level 0, format "f \;;_ e g", + only parsing) : cat_scope. + Lemma pbsquare_universal {C: cat} (A B T P0 P1 : C) (t: A ~> T) (s: B ~> T) (p1: P0 ~> A) (p2: P0 ~> B) (f: P1 ~> A) (g: P1 ~> B) : @@ -1759,6 +1765,18 @@ Lemma pbsquare_universal {C: cat} (A B T P0 P1 : C) instantiate (1:= bot_map0). split; auto. Qed. + +Lemma jm_pbsquare_universal {C: cat} (A B T P0 P1 P2 : C) + (t: A ~> T) (s: B ~> T) (p1: P0 ~> A) (p2: P0 ~> B) + (f: P1 ~> A) (g: P1 ~> B) + (sq: pbsquare p1 p2 t s) + (E0: f \; t = g \; s) + (e: P0 = P2) : + sigma m: P1 ~> P2, f = m \;;_e p1 /\ g = m \;;_e p2. + unfold jmcomp. + dependent destruction e. + eapply pbsquare_universal; eauto. +Qed. Lemma pbquare_universal_aux1 {C: cat} (A0 A1 B0 B1 P0 P1 T : C) (t: A0 ~> T) (s: B0 ~> T) (p01: P0 ~> A0) (p02: P0 ~> B0) @@ -1815,12 +1833,6 @@ Lemma pbsquare_is_pullback {C: pbcat} {C0} (X Y: iHom C0) : rewrite pbk_pullback_is_pullback; auto. Qed. -Definition jmcomp {C: cat} {a b c d: C} (e: c = b) (f: a ~> b) (g: c ~> d) := - f \; match e with eq_refl => g end. -Notation "f \;;_ e g" := (@jmcomp _ _ _ _ _ e f g) - (at level 60, g at level 60, e at level 0, format "f \;;_ e g", - only parsing) : cat_scope. - (* nested product *) Program Definition iprodCAsc {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : (((C1 *_C0 C2 : iHom C0) *_C0 C3) :> C) ~>_C @@ -1885,12 +1897,68 @@ remember (iprodr Pb12 c3) as j33R. *) assert (forall (e1: C1s = (c1 :> C)) (e2: C2s = (c2 :> C)), - j12L \;;_e1 tgt1 = j12R \;;_e2 src2) as sqPb12. -admit. + j12L \;;_e1 tgt1 = j12R \;;_e2 src2) as sqPb12. +{ + set (X := @is_ppbk C). + specialize (X C1s C2s). + specialize (X (Cospan tgt1 src2)). + destruct X as [X]. + simpl in X. + + inversion Heqc1; subst. + simpl; simpl in *. + + assert (j12L = bot2left + (pbk C1s C2s {| top := C0; left2top := tgt1; + right2top := src2 |})) as A1. + { auto. } + + assert (j12R = bot2right + (pbk C1s C2s {| top := C0; left2top := tgt1; + right2top := src2 |})) as A2. + { auto. } + + intros e1 e2. + rewrite A1. + rewrite A2. + + unfold jmcomp. + dependent destruction e1. + dependent destruction e2. + auto. +} assert (forall (e1: C2s = (c2 :> C)) (e2: C3s = (c3 :> C)), j23L \;;_e1 tgt2 = j23R \;;_e2 src3) as sqPb23. -admit. +{ + set (X := @is_ppbk C). + specialize (X C2s C3s). + specialize (X (Cospan tgt2 src3)). + destruct X as [X]. + simpl in X. + + inversion Heqc2; subst. + simpl; simpl in *. + + assert (j23L = bot2left + (pbk C2s C3s {| top := C0; left2top := tgt2; + right2top := src3 |})) as A1. + { auto. } + + assert (j23R = bot2right + (pbk C2s C3s {| top := C0; left2top := tgt2; + right2top := src3 |})) as A2. + { auto. } + + intros e1 e2. + rewrite A1. + rewrite A2. + + unfold jmcomp. + dependent destruction e1. + dependent destruction e2. + auto. +} assert (@tgt C C0 Pb12 = j12R \; @tgt C C0 c2) as tgtPb12. admit. @@ -1906,14 +1974,40 @@ assert (forall (e2: C3s = (c3 :> C)), j33L \; @tgt C C0 Pb12 = j33R \;;_e2 src3) as sqPb33. admit. -assert (forall (e1: ((c1 *_C0 c2) :> C) = Pb12), - sigma (m12: Pb15 ~> Pb12), - (j15L = m12 \;;_e1 j12L) /\ (j15R \; j23L = m12 \;;_e1 j12R)) as M12. -admit. +assert (forall (e1: ((c2 *_C0 c3) :> C) = (Pb23 :> C)), + sigma (m23: (Pb33 :> C) ~> (Pb23 :> C)), + (j33L \; j12R = m23 \;;_e1 j23L) /\ (j33R = m23 \;;_e1 j23R)) + as M23. +{ intro e1. + subst Pb33. + eapply (@jm_pbsquare_universal C _ _ _ + (c2 *_ C0 c3 :> C) (Pb12 *_ C0 c3 :> C) (Pb23 :> C) _ _ + j23L j23R (j33L \; j12R) j33R _ _ e1); eauto. +} + +assert (forall (e1: ((c1 *_C0 c2) :> C) = (Pb12 :> C)), + sigma (m12: (Pb15 :> C) ~> (Pb12 :> C)), + (j15L = m12 \;;_e1 j12L) /\ (j15R \; j23L = m12 \;;_e1 j12R)) + as M12. +{ intro e1. + subst Pb15. + eapply (@jm_pbsquare_universal C _ _ _ + (c1 *_ C0 c2 :> C) (c1 *_ C0 Pb23 :> C) (Pb12 :> C) _ _ + j12L j12R j15L (j15R \; j23L) _ _ e1); eauto. +} + +(* +assert ((c2 *_ C0 c3) :> C = Pb23 :> C) as E2. +{ auto. } + +specialize (M23 E2). + +destruct M23 as [mm X]. +subst Pb33. +subst Pb23. +subst Pb12. +*) -assert (forall (e1: ((c2 *_C0 c3) :> C) = Pb23), - sigma (m23: Pb33 ~> Pb23), - (j33L \; j12R = m23 \;;_e1 j23L) /\ (j33R = m23 \;;_e1 j23R)) as M23. admit. (* From 3459991ea35823f0ecbdd821af4ce4658ceda89f Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Wed, 10 Jan 2024 17:20:20 +0100 Subject: [PATCH 117/147] updated encatI.v --- theories/encatI.v | 81 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 76 insertions(+), 5 deletions(-) diff --git a/theories/encatI.v b/theories/encatI.v index 2596902fd..8ec302fcb 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -1996,6 +1996,80 @@ assert (forall (e1: ((c1 *_C0 c2) :> C) = (Pb12 :> C)), j12L j12R j15L (j15R \; j23L) _ _ e1); eauto. } +assert (((c1 *_C0 c2) :> C) = Pb12) as E12. +{ auto. } +destruct (M12 E12) as [m12 [m12_E m12_U]]. + +assert (((c2 *_C0 c3) :> C) = Pb23) as E23. +{ auto. } +destruct (M23 E23) as [m23 [m23_E m23_U]]. + +assert (C1s = (c1 :> C)) as E1. +{ inversion Heqc2; subst. + simpl; auto. +} +assert (C2s = (c2 :> C)) as E2. +{ inversion Heqc2; subst. + simpl; auto. +} + +assert (forall (e1: (C2s = (c2 :> C))) (e2: ((c2 *_C0 c3) :> C) = Pb23), + j33L \; (j12R \;;_e1 src2) = m23 \;;_e2 j23L \;;_e1 src2) as M23_E1. +{ intros e1 e2. + unfold jmcomp. + dependent destruction e1. + dependent destruction e2. + rewrite compoA. + rewrite m23_E. + rewrite compoA; auto. +} + +assert (forall (e1: (C1s = (c1 :> C))) + (e2: (C2s = (c2 :> C))) (e3: ((c2 *_C0 c3) :> C) = Pb23), + (j33L \; j12L) \;;_e1 tgt1 = m23 \;;_e3 j23L \;;_e2 src2) as M23_E2. +{ intros e1 e2 e3. + specialize (sqPb12 E1 E2). + specialize (M23_E1 E2 E23). + unfold jmcomp in sqPb12, M23_E1. + dependent destruction E1. + dependent destruction E2. + dependent destruction E23. + unfold jmcomp. + dependent destruction e1. + dependent destruction e3. + dependent destruction e2. + setoid_rewrite <- compoA. + rewrite sqPb12. + rewrite M23_E1. + auto. +} + +assert ((((c1 *_ C0 c2) *_ C0 c3) :> C) = Pb33) as E33. +{ auto. } + +assert ( + forall (e1: (((c1 *_ C0 c2) *_ C0 c3) :> C) = Pb33), + sigma mm: ((c1 *_ C0 c2) *_ C0 c3) ~> (c1 *_ C0 (c2 *_ C0 c3)), + (j33L \; j12L = mm \; j15L) /\ (idmap \;;_e1 m23 = mm \; j15R)) as X. +{ intro e1. + + unfold jmcomp. + dependent destruction e1. + rewrite comp1o. + + subst Pb12. + eapply (@pbsquare_universal C _ _ _ _ _ _ _ _ _ (j33L \; j12L) m23). + + 2: { + specialize (M23_E2 E1 E2 E23). + admit. + } + admit. +} +destruct (X E33) as [mm R]. +exact mm. +Admitted. + (* assert ((c2 *_ C0 c3) :> C = Pb23 :> C) as E2. { auto. } @@ -2006,11 +2080,9 @@ destruct M23 as [mm X]. subst Pb33. subst Pb23. subst Pb12. -*) admit. -(* unfold iprod. unfold iprod_pb; simpl. unfold iprod. @@ -2022,10 +2094,9 @@ setoid_rewrite pbk_eta. simpl. unfold hom. unfold IsQuiver.hom. -*) - + Admitted. - +*) Program Definition ipairC {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} From ca8bffd1233420666020db36f4d18ffb6705dbf7 Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Thu, 11 Jan 2024 18:45:29 +0100 Subject: [PATCH 118/147] updated encatI.v --- theories/encatI.v | 972 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 817 insertions(+), 155 deletions(-) diff --git a/theories/encatI.v b/theories/encatI.v index 8ec302fcb..aef8fe3c7 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -1833,6 +1833,662 @@ Lemma pbsquare_is_pullback {C: pbcat} {C0} (X Y: iHom C0) : rewrite pbk_pullback_is_pullback; auto. Qed. + +Program Definition ipairC {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} + (f : x0 ~>_(iHom C0) x2) (g : x1 ~>_(iHom C0) x3) : + (x0 *_C0 x1 :> C) ~>_C (x2 *_C0 x3 :> C). + + remember (x0 *_ C0 x1 : iHom C0) as Pb1. + remember (x2 *_ C0 x3 : iHom C0) as Pb2. + + remember (@Cospan C (x0 :> C) (x1 :> C) C0 + (@tgt C C0 x0) (@src C C0 x1)) as Csp1. + + remember (@Cospan C (x2 :> C) (x3 :> C) C0 + (@tgt C C0 x2) (@src C C0 x3)) as Csp2. + + set (src0 := @src C C0 x0). + set (tgt0 := @tgt C C0 x0). + + set (src1 := @src C C0 x1). + set (tgt1 := @tgt C C0 x1). + + set (src2 := @src C C0 x2). + set (tgt2 := @tgt C C0 x2). + + set (src3 := @src C C0 x3). + set (tgt3 := @tgt C C0 x3). + + remember (@src C C0 (x0 *_C0 x1)) as src01. + remember (@tgt C C0 (x0 *_C0 x1)) as tgt01. + + remember (@src C C0 (x2 *_C0 x3)) as src23. + remember (@tgt C C0 (x2 *_C0 x3)) as tgt23. + + set (Sp1 := pbk (x0 :> C) (x1 :> C) Csp1). + set (Sp2 := pbk (x2 :> C) (x3 :> C) Csp2). + + assert (@Pullback C (x0 :> C) (x1 :> C) Csp1 Sp1) as PBa1. + { remember C as C'. + destruct C as [C class]. + destruct class as [A1 A2 A3 A4 A5 A6]. + destruct A6 as [B1]. + assert (pb (pbk (x0 :> C') (x1 :> C') Csp1)). + { inversion HeqC'; subst. + eapply B1; eauto. } + econstructor; eauto. + } + + assert (@Pullback C (x2 :> C) (x3 :> C) Csp2 Sp2) as PBa2. + { remember C as C'. + destruct C as [C class]. + destruct class as [A1 A2 A3 A4 A5 A6]. + destruct A6 as [B1]. + assert (pb (pbk (x2 :> C') (x3 :> C') Csp2)). + { inversion HeqC'; subst. + eapply B1; eauto. } + econstructor; eauto. + } + +(* assert (@Pullback C (x2 :> C) (x3 :> C) Csp2 Sp2) as PBa2. + admit. +*) + assert ((x0 *_ C0 x1) = bot Sp1) as E01. + { subst Sp1. + unfold iprod. + unfold iprod_pb. + rewrite HeqCsp1; auto. + } + + assert ((x2 *_ C0 x3) = bot Sp2) as E23. + { subst Sp2. + unfold iprod. + unfold iprod_pb. + rewrite HeqCsp2; auto. + } + + set (prj11 := @iprodl C C0 x0 x1). + set (prj12 := @iprodr C C0 x0 x1). + + set (prj21 := @iprodl C C0 x2 x3). + set (prj22 := @iprodr C C0 x2 x3). + + set (ff := prj11 \; f). + set (gg := prj12 \; g). + + assert ((f : (x0 :> C) ~>_C (x2 :> C)) \; tgt2 = tgt0) as E20. + { remember f as f1. + destruct f as [fsort fclass]. + destruct fclass as [fIM]. + destruct fIM. + inversion Heqf1; subst. + simpl in *; simpl; auto. + } + + assert ((g : (x1 :> C) ~>_C (x3 :> C)) \; src3 = src1) as E31. + { remember g as g1. + destruct g as [gsort gclass]. + destruct gclass as [gIM]. + destruct gIM. + inversion Heqg1; subst. + simpl in *; simpl; auto. + } + + assert (prj11 \; tgt0 = prj12 \; src1) as E11. + { destruct PBa1 as [C1 C2]. + destruct C1 as [C3]. + inversion HeqCsp1; subst. + simpl in *; auto. + } + + assert (ff \; tgt2 = gg \; src3) as E1. + { subst ff gg. + setoid_rewrite <- compoA. + rewrite E20. + rewrite E31. + exact E11. + } + + (* basically, follows from pbquare_universal and E1. + sordid eta-conversion issue fixed by pbsquare_is_pullback *) + assert (sigma m: ((x0 *_ C0 x1) ~>_C (x2 *_ C0 x3) :> C), + ff = m \; prj21 /\ gg = m \; prj22) as EM. + { eapply (@pbsquare_universal C) ; eauto. + + remember C as C'. + destruct C as [C class]. + destruct class as [A1 A2 A3 A4 A5 A6]. + destruct A6 as [B1]. + subst prj21 prj22. + + (* surprisingly, this does not work with pbsquare_is_pulback_sym *) + (* rewrite <- pbsquare_is_pullback_sym. *) + rewrite pbsquare_is_pullback. + inversion HeqCsp2; subst. + subst Sp2. + exact PBa2. + } + + destruct EM as [mm [EM1 EM2]]. + exact mm. +Qed. + +Notation "<( f , g )>" := (ipairC f g). + + + +(* nested product *) +Program Definition iprodCAsc {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : + (((C1 *_C0 C2 : iHom C0) *_C0 C3) :> C) ~>_C + ((C1 *_C0 (C2 *_C0 C3 : iHom C0) : iHom C0) :> C). +remember C1 as c1. +remember C2 as c2. +remember C3 as c3. + +set (src1 := @src C C0 c1). +set (src2 := @src C C0 c2). +set (src3 := @src C C0 c3). +set (tgt1 := @tgt C C0 c1). +set (tgt2 := @tgt C C0 c2). +set (tgt3 := @tgt C C0 c3). +simpl. + +set (Pb12 := c1 *_ C0 c2 : iHom C0). +set (Pb23 := c2 *_ C0 c3 : iHom C0). +set (Pb15 := c1 *_ C0 Pb23 : iHom C0). +set (Pb33 := Pb12 *_ C0 c3 : iHom C0). + +set (pb12 := c1 *_ C0 c2 :> C). +set (pb23 := c2 *_ C0 c3 :> C). +set (pb15 := (c1 *_ C0 Pb23) :> C). +set (pb33 := (Pb12 *_ C0 c3) :> C). + +set (j12L := iprodl c1 c2). +set (j12R := iprodr c1 c2). +set (j23L := iprodl c2 c3). +set (j23R := iprodr c2 c3). +set (j15L := iprodl c1 Pb23). +set (j15R := iprodr c1 Pb23). +set (j33L := iprodl Pb12 c3). +set (j33R := iprodr Pb12 c3). + +assert (j12L \; tgt1 = j12R \; src2) as sqPb12. +{ set (X := @is_ppbk C). + specialize (X (c1 :> C) (c2 :> C)). + specialize (X (Cospan tgt1 src2)). + destruct X as [X]. + simpl in X. + auto. +} + +assert (j23L \; tgt2 = j23R \; src3) as sqPb23. +{ set (X := @is_ppbk C). + specialize (X (c2 :> C) (c3 :> C)). + specialize (X (Cospan tgt2 src3)). + destruct X as [X]. + simpl in X. + auto. +} + +assert (@src C C0 Pb23 = j23L \; src2) as srcPb23. +{ subst Pb23 j23L src2. + auto. +} + +assert (forall (e1: ((c2 *_C0 c3) :> C) = (Pb23 :> C)), + sigma (m23: (Pb33 :> C) ~> (Pb23 :> C)), + (j33L \; j12R = m23 \;;_e1 j23L) /\ (j33R = m23 \;;_e1 j23R)) + as M23. +{ intro e1. + subst Pb33. + + assert ((j33L \; j12R) \; tgt2 = j33R \; src3) as V1. + { (* setoid_rewrite <- compoA. subst j33L j33R j12R. + unfold Pb12. subst tgt2 src3. auto. *) + admit. + } + + assert (pbsquare j23L j23R tgt2 src3) as V2. + { admit. } + + eapply (@jm_pbsquare_universal C (c2 :> C) (c3 :> C) C0 + (c2 *_ C0 c3 :> C) (Pb12 *_ C0 c3 :> C) (Pb23 :> C) + tgt2 src3 j23L j23R (j33L \; j12R) j33R V2 V1 e1); eauto. +} + +assert (forall (e1: ((c1 *_C0 c2) :> C) = (Pb12 :> C)), + sigma (m12: (Pb15 :> C) ~> (Pb12 :> C)), + (j15L = m12 \;;_e1 j12L) /\ (j15R \; j23L = m12 \;;_e1 j12R)) + as M12. +{ intro e1. + subst Pb15. + + assert (j15L \; tgt1 = (j15R \; j23L) \; src2) as V1. + { (* setoid_rewrite <- compoA. subst j33L j33R j12R. + unfold Pb12. subst tgt2 src3. auto. *) + admit. + } + + assert (pbsquare j12L j12R tgt1 src2) as V2. + { admit. } + + eapply (@jm_pbsquare_universal C (c1 :> C) (c2 :> C) C0 + (c1 *_ C0 c2 :> C) (c1 *_ C0 Pb23 :> C) (Pb12 :> C) + tgt1 src2 j12L j12R j15L (j15R \; j23L) V2 V1 e1); eauto. +} + +assert (((c1 *_C0 c2) :> C) = Pb12) as E12. +{ auto. } +destruct (M12 E12) as [m12 [m12_E m12_U]]. + +assert (((c2 *_C0 c3) :> C) = Pb23) as E23. +{ auto. } +destruct (M23 E23) as [m23 [m23_E m23_U]]. + +assert (forall (e2: ((c2 *_C0 c3) :> C) = Pb23), + j33L \; (j12R \; src2) = m23 \;;_e2 j23L \; src2) as M23_E1. +{ intros e2. + unfold jmcomp. + dependent destruction e2. + rewrite compoA. + rewrite m23_E. + unfold jmcomp. + dependent destruction E23. + rewrite compoA; auto. +} + +assert (forall (e3: ((c2 *_C0 c3) :> C) = Pb23), + (j33L \; j12L) \; tgt1 = m23 \;;_e3 j23L \; src2) as M23_E2. +{ intros e3. + specialize (M23_E1 E23). + unfold jmcomp in M23_E1. + dependent destruction E23. + unfold jmcomp. + dependent destruction e3. + setoid_rewrite <- compoA. + rewrite sqPb12. + rewrite M23_E1. + auto. +} + +assert ((((c1 *_ C0 c2) *_ C0 c3) :> C) = Pb33) as E33. +{ auto. } + +assert ( + forall (e1: (((c1 *_ C0 c2) *_ C0 c3) :> C) = Pb33), + sigma mm: ((c1 *_ C0 c2) *_ C0 c3) ~> (c1 *_ C0 (c2 *_ C0 c3)), + (j33L \; j12L = mm \; j15L) /\ (idmap \;;_e1 m23 = mm \; j15R)) as X. +{ intro e1. + + unfold jmcomp. + dependent destruction e1. + rewrite comp1o. + + subst Pb12. + eapply (@pbsquare_universal C _ _ _ _ _ _ _ _ _ (j33L \; j12L) m23). + + 2: { + specialize (M23_E2 E23). + dependent destruction E23. + exact M23_E2. + } + + set (Csp15 (* : cospan (c1 :> C) (Pb23 :> C) *) := + @Cospan C (c1 :> C) (Pb23 :> C) _ tgt1 (j23L \; src2)). + + rewrite <- srcPb23. + + subst j15L j15R tgt1. + rewrite pbsquare_is_pullback. + + remember C as C'. + destruct C as [C class]. + destruct class as [A1 A2 A3 A4 A5 A6]. + destruct A6 as [B1]. + assert (pb (pbk (c1 :> C') (Pb23 :> C') Csp15)). + { inversion HeqC'; subst. + eapply B1; eauto. } + econstructor; eauto. +} + +destruct (X E33) as [mm R]. +exact mm. +Admitted. + + + +(* + assert () + + inversion Heqc1; subst. + + + + unfold iprodl. + unfold iprodr. + unfold iprod_pb. + simpl. + + unfold pbk. + unfold bot2left. + unfold bot2right. + simpl. + + econstructor; eauto. + + unfold jmcomp. + dependent destruction E2. + unfold src2. + rewrite <- srcPb23. + + econstructor. + + admit. +} +*) + +destruct (X E33) as [mm R]. +exact mm. +Admitted. + + + + + + + +(* nested product *) +Program Definition iprodCAsc' {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : + (((C1 *_C0 C2 : iHom C0) *_C0 C3) :> C) ~>_C + ((C1 *_C0 (C2 *_C0 C3 : iHom C0) : iHom C0) :> C). +remember C1 as c1. +remember C2 as c2. +remember C3 as c3. + +destruct C1 as [C1s C1c]. +destruct C2 as [C2s C2c]. +destruct C3 as [C3s C3c]. +destruct C1c as [IM1]. +destruct C2c as [IM2]. +destruct C3c as [IM3]. + +destruct IM1 as [src1 tgt1]. +destruct IM2 as [src2 tgt2]. +destruct IM3 as [src3 tgt3]. +simpl in *; simpl. + +set (Pb12 := c1 *_ C0 c2 : iHom C0). +set (Pb23 := c2 *_ C0 c3 : iHom C0). +set (Pb15 := c1 *_ C0 Pb23 : iHom C0). +set (Pb33 := Pb12 *_ C0 c3 : iHom C0). + +(* +remember (c1 *_ C0 c2 : iHom C0) as Pb12. +remember (c2 *_ C0 c3 : iHom C0) as Pb23. +remember ((c1 *_ C0 Pb23) : iHom C0) as Pb15. +remember ((Pb12 *_ C0 c3) : iHom C0) as Pb33. +*) + +set (pb12 := c1 *_ C0 c2 :> C). +set (pb23 := c2 *_ C0 c3 :> C). +set (pb15 := (c1 *_ C0 Pb23) :> C). +set (pb33 := (Pb12 *_ C0 c3) :> C). + +(* +remember (c1 *_ C0 c2 :> C) as pb12. +remember (c2 *_ C0 c3 :> C) as pb23. +remember ((c1 *_ C0 Pb23) :> C) as pb15. +remember ((Pb12 *_ C0 c3) :> C) as pb33. +*) + +set (j12L := iprodl c1 c2). +set (j12R := iprodr c1 c2). +set (j23L := iprodl c2 c3). +set (j23R := iprodr c2 c3). +set (j15L := iprodl c1 Pb23). +set (j15R := iprodr c1 Pb23). +set (j33L := iprodl Pb12 c3). +set (j33R := iprodr Pb12 c3). + +(* +remember (iprodl c1 c2) as j12L. +remember (iprodr c1 c2) as j12R. +remember (iprodl c2 c3) as j23L. +remember (iprodr c2 c3) as j23R. +remember (iprodl c1 Pb23) as j15L. +remember (iprodr c1 Pb23) as j15R. +remember (iprodl Pb12 c3) as j33L. +remember (iprodr Pb12 c3) as j33R. +*) + +assert (forall (e1: C1s = (c1 :> C)) (e2: C2s = (c2 :> C)), + j12L \;;_e1 tgt1 = j12R \;;_e2 src2) as sqPb12. +{ + set (X := @is_ppbk C). + specialize (X C1s C2s). + specialize (X (Cospan tgt1 src2)). + destruct X as [X]. + simpl in X. + + inversion Heqc1; subst. + simpl; simpl in *. + + assert (j12L = bot2left + (pbk C1s C2s {| top := C0; left2top := tgt1; + right2top := src2 |})) as A1. + { auto. } + + assert (j12R = bot2right + (pbk C1s C2s {| top := C0; left2top := tgt1; + right2top := src2 |})) as A2. + { auto. } + + intros e1 e2. + rewrite A1. + rewrite A2. + + unfold jmcomp. + dependent destruction e1. + dependent destruction e2. + auto. +} + +assert (forall (e1: C2s = (c2 :> C)) (e2: C3s = (c3 :> C)), + j23L \;;_e1 tgt2 = j23R \;;_e2 src3) as sqPb23. +{ + set (X := @is_ppbk C). + specialize (X C2s C3s). + specialize (X (Cospan tgt2 src3)). + destruct X as [X]. + simpl in X. + + inversion Heqc2; subst. + simpl; simpl in *. + + assert (j23L = bot2left + (pbk C2s C3s {| top := C0; left2top := tgt2; + right2top := src3 |})) as A1. + { auto. } + + assert (j23R = bot2right + (pbk C2s C3s {| top := C0; left2top := tgt2; + right2top := src3 |})) as A2. + { auto. } + + intros e1 e2. + rewrite A1. + rewrite A2. + + unfold jmcomp. + dependent destruction e1. + dependent destruction e2. + auto. +} + +(* +assert (@tgt C C0 Pb12 = j12R \; @tgt C C0 c2) as tgtPb12. +admit. +*) + +assert (@src C C0 Pb23 = j23L \; @src C C0 c2) as srcPb23. +admit. + +assert (forall (e1: C1s = (c1 :> C)), + j15L \;;_e1 tgt1 = j15R \; @src C C0 Pb23) as sqPb15. +admit. + +assert (forall (e2: C3s = (c3 :> C)), + j33L \; @tgt C C0 Pb12 = j33R \;;_e2 src3) as sqPb33. +admit. + +assert (forall (e1: ((c2 *_C0 c3) :> C) = (Pb23 :> C)), + sigma (m23: (Pb33 :> C) ~> (Pb23 :> C)), + (j33L \; j12R = m23 \;;_e1 j23L) /\ (j33R = m23 \;;_e1 j23R)) + as M23. +{ intro e1. + subst Pb33. + eapply (@jm_pbsquare_universal C _ _ _ + (c2 *_ C0 c3 :> C) (Pb12 *_ C0 c3 :> C) (Pb23 :> C) _ _ + j23L j23R (j33L \; j12R) j33R _ _ e1); eauto. +} + +assert (forall (e1: ((c1 *_C0 c2) :> C) = (Pb12 :> C)), + sigma (m12: (Pb15 :> C) ~> (Pb12 :> C)), + (j15L = m12 \;;_e1 j12L) /\ (j15R \; j23L = m12 \;;_e1 j12R)) + as M12. +{ intro e1. + subst Pb15. + eapply (@jm_pbsquare_universal C _ _ _ + (c1 *_ C0 c2 :> C) (c1 *_ C0 Pb23 :> C) (Pb12 :> C) _ _ + j12L j12R j15L (j15R \; j23L) _ _ e1); eauto. +} + +assert (((c1 *_C0 c2) :> C) = Pb12) as E12. +{ auto. } +destruct (M12 E12) as [m12 [m12_E m12_U]]. + +assert (((c2 *_C0 c3) :> C) = Pb23) as E23. +{ auto. } +destruct (M23 E23) as [m23 [m23_E m23_U]]. + +assert (C1s = (c1 :> C)) as E1. +{ inversion Heqc2; subst. + simpl; auto. +} +assert (C2s = (c2 :> C)) as E2. +{ inversion Heqc2; subst. + simpl; auto. +} + +assert (@src C C0 Pb23 = j23L \;;_E2 src2) as srcPb23'. +admit. + +assert (forall (e1: (C2s = (c2 :> C))) (e2: ((c2 *_C0 c3) :> C) = Pb23), + j33L \; (j12R \;;_e1 src2) = m23 \;;_e2 j23L \;;_e1 src2) as M23_E1. +{ intros e1 e2. + unfold jmcomp. + dependent destruction e1. + dependent destruction e2. + rewrite compoA. + rewrite m23_E. + rewrite compoA; auto. +} + +assert (forall (e1: (C1s = (c1 :> C))) + (e2: (C2s = (c2 :> C))) (e3: ((c2 *_C0 c3) :> C) = Pb23), + (j33L \; j12L) \;;_e1 tgt1 = m23 \;;_e3 j23L \;;_e2 src2) as M23_E2. +{ intros e1 e2 e3. + specialize (sqPb12 E1 E2). + specialize (M23_E1 E2 E23). + unfold jmcomp in sqPb12, M23_E1. + dependent destruction E1. + dependent destruction E2. + dependent destruction E23. + unfold jmcomp. + dependent destruction e1. + dependent destruction e3. + dependent destruction e2. + setoid_rewrite <- compoA. + rewrite sqPb12. + rewrite M23_E1. + auto. +} + +assert ((((c1 *_ C0 c2) *_ C0 c3) :> C) = Pb33) as E33. +{ auto. } + +assert ( + forall (e1: (((c1 *_ C0 c2) *_ C0 c3) :> C) = Pb33), + sigma mm: ((c1 *_ C0 c2) *_ C0 c3) ~> (c1 *_ C0 (c2 *_ C0 c3)), + (j33L \; j12L = mm \; j15L) /\ (idmap \;;_e1 m23 = mm \; j15R)) as X. +{ intro e1. + + unfold jmcomp. + dependent destruction e1. + rewrite comp1o. + + subst Pb12. +(* eapply (@jm_pbsquare_universal C _ _ _ _ _ _ _ _ _ _ (j33L \; j12L) m23). *) + eapply (@pbsquare_universal C _ _ _ _ _ _ _ _ _ (j33L \; j12L) m23). + +(* assert (forall y1 y2, pbsquare j15L j15R y1 y2). *) + + 2: { + specialize (M23_E2 E1 E2 E23). + dependent destruction E23. + exact M23_E2. + } + dependent destruction E1. + rewrite <- srcPb23'. + + subst j15R. + + assert (pbsquare (iprodl c1 Pb23) (iprodr c1 Pb23) (@tgt C C0 c1) + (@src C C0 Pb23)). + { + rewrite pbsquare_is_pullback. + admit. + } + destruct c1. + admit. +} + +(* + assert () + + inversion Heqc1; subst. + + + + unfold iprodl. + unfold iprodr. + unfold iprod_pb. + simpl. + + unfold pbk. + unfold bot2left. + unfold bot2right. + simpl. + + econstructor; eauto. + + unfold jmcomp. + dependent destruction E2. + unfold src2. + rewrite <- srcPb23. + + econstructor. + + admit. +} +*) + +destruct (X E33) as [mm R]. +exact mm. +Admitted. + + + (* nested product *) Program Definition iprodCAsc {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : (((C1 *_C0 C2 : iHom C0) *_C0 C3) :> C) ~>_C @@ -1840,6 +2496,15 @@ Program Definition iprodCAsc {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : remember C1 as c1. remember C2 as c2. remember C3 as c3. + +set (src1 := @src C C0 c1). +set (src2 := @src C C0 c2). +set (src3 := @src C C0 c3). +set (tgt1 := @tgt C C0 c1). +set (tgt2 := @tgt C C0 c2). +set (tgt3 := @tgt C C0 c3). + +(* destruct C1 as [C1s C1c]. destruct C2 as [C2s C2c]. destruct C3 as [C3s C3c]. @@ -1851,6 +2516,9 @@ destruct IM1 as [src1 tgt1]. destruct IM2 as [src2 tgt2]. destruct IM3 as [src3 tgt3]. simpl in *; simpl. +*) + +simpl. set (Pb12 := c1 *_ C0 c2 : iHom C0). set (Pb23 := c2 *_ C0 c3 : iHom C0). @@ -1896,11 +2564,33 @@ remember (iprodl Pb12 c3) as j33L. remember (iprodr Pb12 c3) as j33R. *) -assert (forall (e1: C1s = (c1 :> C)) (e2: C2s = (c2 :> C)), - j12L \;;_e1 tgt1 = j12R \;;_e2 src2) as sqPb12. +assert (j12L \; tgt1 = j12R \; src2) as sqPb12. +{ + set (X := @is_ppbk C). + specialize (X (c1 :> C) (c2 :> C)). + specialize (X (Cospan tgt1 src2)). + destruct X as [X]. + simpl in X. + + auto. +} + +assert (j23L \; tgt2 = j23R \; src3) as sqPb23. { set (X := @is_ppbk C). - specialize (X C1s C2s). + specialize (X (c2 :> C) (c3 :> C)). + specialize (X (Cospan tgt2 src3)). + destruct X as [X]. + simpl in X. + + auto. +} + +(* +assert (j12L \; tgt1 = j12R \; src2) as sqPb12. +{ + set (X := @is_ppbk C). + specialize (X (c1 :> C) (c2 :> C)). specialize (X (Cospan tgt1 src2)). destruct X as [X]. simpl in X. @@ -1927,7 +2617,8 @@ assert (forall (e1: C1s = (c1 :> C)) (e2: C2s = (c2 :> C)), dependent destruction e2. auto. } - +*) +(* assert (forall (e1: C2s = (c2 :> C)) (e2: C3s = (c3 :> C)), j23L \;;_e1 tgt2 = j23R \;;_e2 src3) as sqPb23. { @@ -1959,20 +2650,23 @@ assert (forall (e1: C2s = (c2 :> C)) (e2: C3s = (c3 :> C)), dependent destruction e2. auto. } - -assert (@tgt C C0 Pb12 = j12R \; @tgt C C0 c2) as tgtPb12. +*) +(* +assert (@tgt C C0 Pb12 = j12R \; tgt2) as tgtPb12. admit. +*) -assert (@src C C0 Pb23 = j23L \; @src C C0 c2) as srcPb23. +assert (@src C C0 Pb23 = j23L \; src2) as srcPb23. admit. -assert (forall (e1: C1s = (c1 :> C)), - j15L \;;_e1 tgt1 = j15R \; @src C C0 Pb23) as sqPb15. + +(* +assert (j15L \; tgt1 = j15R \; @src C C0 Pb23) as sqPb15. admit. -assert (forall (e2: C3s = (c3 :> C)), - j33L \; @tgt C C0 Pb12 = j33R \;;_e2 src3) as sqPb33. +assert (j33L \; @tgt C C0 Pb12 = j33R \; src3) as sqPb33. admit. +*) assert (forall (e1: ((c2 *_C0 c3) :> C) = (Pb23 :> C)), sigma (m23: (Pb33 :> C) ~> (Pb23 :> C)), @@ -2004,6 +2698,7 @@ assert (((c2 *_C0 c3) :> C) = Pb23) as E23. { auto. } destruct (M23 E23) as [m23 [m23_E m23_U]]. +(* assert (C1s = (c1 :> C)) as E1. { inversion Heqc2; subst. simpl; auto. @@ -2013,6 +2708,37 @@ assert (C2s = (c2 :> C)) as E2. simpl; auto. } +assert (@src C C0 Pb23 = j23L \;;_E2 src2) as srcPb23'. +admit. +*) + +assert (forall (e2: ((c2 *_C0 c3) :> C) = Pb23), + j33L \; (j12R \; src2) = m23 \;;_e2 j23L \; src2) as M23_E1. +{ intros e2. + unfold jmcomp. + dependent destruction e2. + rewrite compoA. + rewrite m23_E. + unfold jmcomp. + dependent destruction E23. + rewrite compoA; auto. +} + +assert (forall (e3: ((c2 *_C0 c3) :> C) = Pb23), + (j33L \; j12L) \; tgt1 = m23 \;;_e3 j23L \; src2) as M23_E2. +{ intros e3. + specialize (M23_E1 E23). + unfold jmcomp in M23_E1. + dependent destruction E23. + unfold jmcomp. + dependent destruction e3. + setoid_rewrite <- compoA. + rewrite sqPb12. + rewrite M23_E1. + auto. +} + +(* assert (forall (e1: (C2s = (c2 :> C))) (e2: ((c2 *_C0 c3) :> C) = Pb23), j33L \; (j12R \;;_e1 src2) = m23 \;;_e2 j23L \;;_e1 src2) as M23_E1. { intros e1 e2. @@ -2043,6 +2769,7 @@ assert (forall (e1: (C1s = (c1 :> C))) rewrite M23_E1. auto. } +*) assert ((((c1 *_ C0 c2) *_ C0 c3) :> C) = Pb33) as E33. { auto. } @@ -2052,24 +2779,99 @@ assert ( sigma mm: ((c1 *_ C0 c2) *_ C0 c3) ~> (c1 *_ C0 (c2 *_ C0 c3)), (j33L \; j12L = mm \; j15L) /\ (idmap \;;_e1 m23 = mm \; j15R)) as X. { intro e1. - + unfold jmcomp. dependent destruction e1. rewrite comp1o. subst Pb12. +(* eapply (@jm_pbsquare_universal C _ _ _ _ _ _ _ _ _ _ (j33L \; j12L) m23). *) eapply (@pbsquare_universal C _ _ _ _ _ _ _ _ _ (j33L \; j12L) m23). - 2: { - specialize (M23_E2 E1 E2 E23). - admit. +(* assert (forall y1 y2, pbsquare j15L j15R y1 y2). *) + + 2: { + specialize (M23_E2 E23). + dependent destruction E23. + exact M23_E2. + } + +(* + set (Csp15 := cospan (c1 :> C) (Pb23 :> C)). + set (Spn15 := span (c1 :> C) (Pb23 :> C)). + + assert (@Pullback C (c1 :> C) (Pb23 :> C) Csp15 Spn15) as PBa1. + { remember C as C'. + destruct C as [C class]. + destruct class as [A1 A2 A3 A4 A5 A6]. + destruct A6 as [B1]. + assert (pb (pbk (x0 :> C') (x1 :> C') Csp1)). + { inversion HeqC'; subst. + eapply B1; eauto. } + econstructor; eauto. } +*) + + set (Csp15 (* : cospan (c1 :> C) (Pb23 :> C) *) := + @Cospan C (c1 :> C) (Pb23 :> C) _ tgt1 (j23L \; src2)). + + rewrite <- srcPb23. + + subst j15L j15R tgt1. + rewrite pbsquare_is_pullback. + + remember C as C'. + destruct C as [C class]. + destruct class as [A1 A2 A3 A4 A5 A6]. + destruct A6 as [B1]. + assert (pb (pbk (c1 :> C') (Pb23 :> C') Csp15)). + { inversion HeqC'; subst. + eapply B1; eauto. } + econstructor; eauto. +} + +destruct (X E33) as [mm R]. +exact mm. +Admitted. + + + +(* + assert () + + inversion Heqc1; subst. + + + + unfold iprodl. + unfold iprodr. + unfold iprod_pb. + simpl. + + unfold pbk. + unfold bot2left. + unfold bot2right. + simpl. + + econstructor; eauto. + + unfold jmcomp. + dependent destruction E2. + unfold src2. + rewrite <- srcPb23. + + econstructor. + admit. } +*) + destruct (X E33) as [mm R]. exact mm. Admitted. + + (* assert ((c2 *_ C0 c3) :> C = Pb23 :> C) as E2. { auto. } @@ -2099,146 +2901,6 @@ Admitted. *) -Program Definition ipairC {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} - (f : x0 ~>_(iHom C0) x2) (g : x1 ~>_(iHom C0) x3) : - (x0 *_C0 x1 :> C) ~>_C (x2 *_C0 x3 :> C). - - remember (x0 *_ C0 x1 : iHom C0) as Pb1. - remember (x2 *_ C0 x3 : iHom C0) as Pb2. - - remember (@Cospan C (x0 :> C) (x1 :> C) C0 - (@tgt C C0 x0) (@src C C0 x1)) as Csp1. - - remember (@Cospan C (x2 :> C) (x3 :> C) C0 - (@tgt C C0 x2) (@src C C0 x3)) as Csp2. - - set (src0 := @src C C0 x0). - set (tgt0 := @tgt C C0 x0). - - set (src1 := @src C C0 x1). - set (tgt1 := @tgt C C0 x1). - - set (src2 := @src C C0 x2). - set (tgt2 := @tgt C C0 x2). - - set (src3 := @src C C0 x3). - set (tgt3 := @tgt C C0 x3). - - remember (@src C C0 (x0 *_C0 x1)) as src01. - remember (@tgt C C0 (x0 *_C0 x1)) as tgt01. - - remember (@src C C0 (x2 *_C0 x3)) as src23. - remember (@tgt C C0 (x2 *_C0 x3)) as tgt23. - - set (Sp1 := pbk (x0 :> C) (x1 :> C) Csp1). - set (Sp2 := pbk (x2 :> C) (x3 :> C) Csp2). - - assert (@Pullback C (x0 :> C) (x1 :> C) Csp1 Sp1) as PBa1. - { remember C as C'. - destruct C as [C class]. - destruct class as [A1 A2 A3 A4 A5 A6]. - destruct A6 as [B1]. - assert (pb (pbk (x0 :> C') (x1 :> C') Csp1)). - { inversion HeqC'; subst. - eapply B1; eauto. } - econstructor; eauto. - } - - assert (@Pullback C (x2 :> C) (x3 :> C) Csp2 Sp2) as PBa2. - { remember C as C'. - destruct C as [C class]. - destruct class as [A1 A2 A3 A4 A5 A6]. - destruct A6 as [B1]. - assert (pb (pbk (x2 :> C') (x3 :> C') Csp2)). - { inversion HeqC'; subst. - eapply B1; eauto. } - econstructor; eauto. - } - -(* assert (@Pullback C (x2 :> C) (x3 :> C) Csp2 Sp2) as PBa2. - admit. -*) - assert ((x0 *_ C0 x1) = bot Sp1) as E01. - { subst Sp1. - unfold iprod. - unfold iprod_pb. - rewrite HeqCsp1; auto. - } - - assert ((x2 *_ C0 x3) = bot Sp2) as E23. - { subst Sp2. - unfold iprod. - unfold iprod_pb. - rewrite HeqCsp2; auto. - } - - set (prj11 := @iprodl C C0 x0 x1). - set (prj12 := @iprodr C C0 x0 x1). - - set (prj21 := @iprodl C C0 x2 x3). - set (prj22 := @iprodr C C0 x2 x3). - - set (ff := prj11 \; f). - set (gg := prj12 \; g). - - assert ((f : (x0 :> C) ~>_C (x2 :> C)) \; tgt2 = tgt0) as E20. - { remember f as f1. - destruct f as [fsort fclass]. - destruct fclass as [fIM]. - destruct fIM. - inversion Heqf1; subst. - simpl in *; simpl; auto. - } - - assert ((g : (x1 :> C) ~>_C (x3 :> C)) \; src3 = src1) as E31. - { remember g as g1. - destruct g as [gsort gclass]. - destruct gclass as [gIM]. - destruct gIM. - inversion Heqg1; subst. - simpl in *; simpl; auto. - } - - assert (prj11 \; tgt0 = prj12 \; src1) as E11. - { destruct PBa1 as [C1 C2]. - destruct C1 as [C3]. - inversion HeqCsp1; subst. - simpl in *; auto. - } - - assert (ff \; tgt2 = gg \; src3) as E1. - { subst ff gg. - setoid_rewrite <- compoA. - rewrite E20. - rewrite E31. - exact E11. - } - - (* basically, follows from pbquare_universal and E1. - sordid eta-conversion issue fixed by pbsquare_is_pullback *) - assert (sigma m: ((x0 *_ C0 x1) ~>_C (x2 *_ C0 x3) :> C), - ff = m \; prj21 /\ gg = m \; prj22) as EM. - { eapply (@pbsquare_universal C) ; eauto. - - remember C as C'. - destruct C as [C class]. - destruct class as [A1 A2 A3 A4 A5 A6]. - destruct A6 as [B1]. - subst prj21 prj22. - - (* surprisingly, this does not work with pbsquare_is_pulback_sym *) - (* rewrite <- pbsquare_is_pullback_sym. *) - rewrite pbsquare_is_pullback. - inversion HeqCsp2; subst. - subst Sp2. - exact PBa2. - } - - destruct EM as [mm [EM1 EM2]]. - exact mm. -Qed. - -Notation "<( f , g )>" := (ipairC f g). (* An internal precategory is an internal category with two operators that must be src and tgt preserving, i.e. iHom morphisms: identity From 82e72d639c1432483abd65eb6073f5e5b0a9f07a Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Thu, 11 Jan 2024 18:48:09 +0100 Subject: [PATCH 119/147] updated encatI.v --- theories/encatI.v | 745 ---------------------------------------------- 1 file changed, 745 deletions(-) diff --git a/theories/encatI.v b/theories/encatI.v index aef8fe3c7..f6826e628 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -2157,751 +2157,6 @@ Admitted. -(* - assert () - - inversion Heqc1; subst. - - - - unfold iprodl. - unfold iprodr. - unfold iprod_pb. - simpl. - - unfold pbk. - unfold bot2left. - unfold bot2right. - simpl. - - econstructor; eauto. - - unfold jmcomp. - dependent destruction E2. - unfold src2. - rewrite <- srcPb23. - - econstructor. - - admit. -} -*) - -destruct (X E33) as [mm R]. -exact mm. -Admitted. - - - - - - - -(* nested product *) -Program Definition iprodCAsc' {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : - (((C1 *_C0 C2 : iHom C0) *_C0 C3) :> C) ~>_C - ((C1 *_C0 (C2 *_C0 C3 : iHom C0) : iHom C0) :> C). -remember C1 as c1. -remember C2 as c2. -remember C3 as c3. - -destruct C1 as [C1s C1c]. -destruct C2 as [C2s C2c]. -destruct C3 as [C3s C3c]. -destruct C1c as [IM1]. -destruct C2c as [IM2]. -destruct C3c as [IM3]. - -destruct IM1 as [src1 tgt1]. -destruct IM2 as [src2 tgt2]. -destruct IM3 as [src3 tgt3]. -simpl in *; simpl. - -set (Pb12 := c1 *_ C0 c2 : iHom C0). -set (Pb23 := c2 *_ C0 c3 : iHom C0). -set (Pb15 := c1 *_ C0 Pb23 : iHom C0). -set (Pb33 := Pb12 *_ C0 c3 : iHom C0). - -(* -remember (c1 *_ C0 c2 : iHom C0) as Pb12. -remember (c2 *_ C0 c3 : iHom C0) as Pb23. -remember ((c1 *_ C0 Pb23) : iHom C0) as Pb15. -remember ((Pb12 *_ C0 c3) : iHom C0) as Pb33. -*) - -set (pb12 := c1 *_ C0 c2 :> C). -set (pb23 := c2 *_ C0 c3 :> C). -set (pb15 := (c1 *_ C0 Pb23) :> C). -set (pb33 := (Pb12 *_ C0 c3) :> C). - -(* -remember (c1 *_ C0 c2 :> C) as pb12. -remember (c2 *_ C0 c3 :> C) as pb23. -remember ((c1 *_ C0 Pb23) :> C) as pb15. -remember ((Pb12 *_ C0 c3) :> C) as pb33. -*) - -set (j12L := iprodl c1 c2). -set (j12R := iprodr c1 c2). -set (j23L := iprodl c2 c3). -set (j23R := iprodr c2 c3). -set (j15L := iprodl c1 Pb23). -set (j15R := iprodr c1 Pb23). -set (j33L := iprodl Pb12 c3). -set (j33R := iprodr Pb12 c3). - -(* -remember (iprodl c1 c2) as j12L. -remember (iprodr c1 c2) as j12R. -remember (iprodl c2 c3) as j23L. -remember (iprodr c2 c3) as j23R. -remember (iprodl c1 Pb23) as j15L. -remember (iprodr c1 Pb23) as j15R. -remember (iprodl Pb12 c3) as j33L. -remember (iprodr Pb12 c3) as j33R. -*) - -assert (forall (e1: C1s = (c1 :> C)) (e2: C2s = (c2 :> C)), - j12L \;;_e1 tgt1 = j12R \;;_e2 src2) as sqPb12. -{ - set (X := @is_ppbk C). - specialize (X C1s C2s). - specialize (X (Cospan tgt1 src2)). - destruct X as [X]. - simpl in X. - - inversion Heqc1; subst. - simpl; simpl in *. - - assert (j12L = bot2left - (pbk C1s C2s {| top := C0; left2top := tgt1; - right2top := src2 |})) as A1. - { auto. } - - assert (j12R = bot2right - (pbk C1s C2s {| top := C0; left2top := tgt1; - right2top := src2 |})) as A2. - { auto. } - - intros e1 e2. - rewrite A1. - rewrite A2. - - unfold jmcomp. - dependent destruction e1. - dependent destruction e2. - auto. -} - -assert (forall (e1: C2s = (c2 :> C)) (e2: C3s = (c3 :> C)), - j23L \;;_e1 tgt2 = j23R \;;_e2 src3) as sqPb23. -{ - set (X := @is_ppbk C). - specialize (X C2s C3s). - specialize (X (Cospan tgt2 src3)). - destruct X as [X]. - simpl in X. - - inversion Heqc2; subst. - simpl; simpl in *. - - assert (j23L = bot2left - (pbk C2s C3s {| top := C0; left2top := tgt2; - right2top := src3 |})) as A1. - { auto. } - - assert (j23R = bot2right - (pbk C2s C3s {| top := C0; left2top := tgt2; - right2top := src3 |})) as A2. - { auto. } - - intros e1 e2. - rewrite A1. - rewrite A2. - - unfold jmcomp. - dependent destruction e1. - dependent destruction e2. - auto. -} - -(* -assert (@tgt C C0 Pb12 = j12R \; @tgt C C0 c2) as tgtPb12. -admit. -*) - -assert (@src C C0 Pb23 = j23L \; @src C C0 c2) as srcPb23. -admit. - -assert (forall (e1: C1s = (c1 :> C)), - j15L \;;_e1 tgt1 = j15R \; @src C C0 Pb23) as sqPb15. -admit. - -assert (forall (e2: C3s = (c3 :> C)), - j33L \; @tgt C C0 Pb12 = j33R \;;_e2 src3) as sqPb33. -admit. - -assert (forall (e1: ((c2 *_C0 c3) :> C) = (Pb23 :> C)), - sigma (m23: (Pb33 :> C) ~> (Pb23 :> C)), - (j33L \; j12R = m23 \;;_e1 j23L) /\ (j33R = m23 \;;_e1 j23R)) - as M23. -{ intro e1. - subst Pb33. - eapply (@jm_pbsquare_universal C _ _ _ - (c2 *_ C0 c3 :> C) (Pb12 *_ C0 c3 :> C) (Pb23 :> C) _ _ - j23L j23R (j33L \; j12R) j33R _ _ e1); eauto. -} - -assert (forall (e1: ((c1 *_C0 c2) :> C) = (Pb12 :> C)), - sigma (m12: (Pb15 :> C) ~> (Pb12 :> C)), - (j15L = m12 \;;_e1 j12L) /\ (j15R \; j23L = m12 \;;_e1 j12R)) - as M12. -{ intro e1. - subst Pb15. - eapply (@jm_pbsquare_universal C _ _ _ - (c1 *_ C0 c2 :> C) (c1 *_ C0 Pb23 :> C) (Pb12 :> C) _ _ - j12L j12R j15L (j15R \; j23L) _ _ e1); eauto. -} - -assert (((c1 *_C0 c2) :> C) = Pb12) as E12. -{ auto. } -destruct (M12 E12) as [m12 [m12_E m12_U]]. - -assert (((c2 *_C0 c3) :> C) = Pb23) as E23. -{ auto. } -destruct (M23 E23) as [m23 [m23_E m23_U]]. - -assert (C1s = (c1 :> C)) as E1. -{ inversion Heqc2; subst. - simpl; auto. -} -assert (C2s = (c2 :> C)) as E2. -{ inversion Heqc2; subst. - simpl; auto. -} - -assert (@src C C0 Pb23 = j23L \;;_E2 src2) as srcPb23'. -admit. - -assert (forall (e1: (C2s = (c2 :> C))) (e2: ((c2 *_C0 c3) :> C) = Pb23), - j33L \; (j12R \;;_e1 src2) = m23 \;;_e2 j23L \;;_e1 src2) as M23_E1. -{ intros e1 e2. - unfold jmcomp. - dependent destruction e1. - dependent destruction e2. - rewrite compoA. - rewrite m23_E. - rewrite compoA; auto. -} - -assert (forall (e1: (C1s = (c1 :> C))) - (e2: (C2s = (c2 :> C))) (e3: ((c2 *_C0 c3) :> C) = Pb23), - (j33L \; j12L) \;;_e1 tgt1 = m23 \;;_e3 j23L \;;_e2 src2) as M23_E2. -{ intros e1 e2 e3. - specialize (sqPb12 E1 E2). - specialize (M23_E1 E2 E23). - unfold jmcomp in sqPb12, M23_E1. - dependent destruction E1. - dependent destruction E2. - dependent destruction E23. - unfold jmcomp. - dependent destruction e1. - dependent destruction e3. - dependent destruction e2. - setoid_rewrite <- compoA. - rewrite sqPb12. - rewrite M23_E1. - auto. -} - -assert ((((c1 *_ C0 c2) *_ C0 c3) :> C) = Pb33) as E33. -{ auto. } - -assert ( - forall (e1: (((c1 *_ C0 c2) *_ C0 c3) :> C) = Pb33), - sigma mm: ((c1 *_ C0 c2) *_ C0 c3) ~> (c1 *_ C0 (c2 *_ C0 c3)), - (j33L \; j12L = mm \; j15L) /\ (idmap \;;_e1 m23 = mm \; j15R)) as X. -{ intro e1. - - unfold jmcomp. - dependent destruction e1. - rewrite comp1o. - - subst Pb12. -(* eapply (@jm_pbsquare_universal C _ _ _ _ _ _ _ _ _ _ (j33L \; j12L) m23). *) - eapply (@pbsquare_universal C _ _ _ _ _ _ _ _ _ (j33L \; j12L) m23). - -(* assert (forall y1 y2, pbsquare j15L j15R y1 y2). *) - - 2: { - specialize (M23_E2 E1 E2 E23). - dependent destruction E23. - exact M23_E2. - } - dependent destruction E1. - rewrite <- srcPb23'. - - subst j15R. - - assert (pbsquare (iprodl c1 Pb23) (iprodr c1 Pb23) (@tgt C C0 c1) - (@src C C0 Pb23)). - { - rewrite pbsquare_is_pullback. - admit. - } - destruct c1. - admit. -} - -(* - assert () - - inversion Heqc1; subst. - - - - unfold iprodl. - unfold iprodr. - unfold iprod_pb. - simpl. - - unfold pbk. - unfold bot2left. - unfold bot2right. - simpl. - - econstructor; eauto. - - unfold jmcomp. - dependent destruction E2. - unfold src2. - rewrite <- srcPb23. - - econstructor. - - admit. -} -*) - -destruct (X E33) as [mm R]. -exact mm. -Admitted. - - - -(* nested product *) -Program Definition iprodCAsc {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : - (((C1 *_C0 C2 : iHom C0) *_C0 C3) :> C) ~>_C - ((C1 *_C0 (C2 *_C0 C3 : iHom C0) : iHom C0) :> C). -remember C1 as c1. -remember C2 as c2. -remember C3 as c3. - -set (src1 := @src C C0 c1). -set (src2 := @src C C0 c2). -set (src3 := @src C C0 c3). -set (tgt1 := @tgt C C0 c1). -set (tgt2 := @tgt C C0 c2). -set (tgt3 := @tgt C C0 c3). - -(* -destruct C1 as [C1s C1c]. -destruct C2 as [C2s C2c]. -destruct C3 as [C3s C3c]. -destruct C1c as [IM1]. -destruct C2c as [IM2]. -destruct C3c as [IM3]. - -destruct IM1 as [src1 tgt1]. -destruct IM2 as [src2 tgt2]. -destruct IM3 as [src3 tgt3]. -simpl in *; simpl. -*) - -simpl. - -set (Pb12 := c1 *_ C0 c2 : iHom C0). -set (Pb23 := c2 *_ C0 c3 : iHom C0). -set (Pb15 := c1 *_ C0 Pb23 : iHom C0). -set (Pb33 := Pb12 *_ C0 c3 : iHom C0). - -(* -remember (c1 *_ C0 c2 : iHom C0) as Pb12. -remember (c2 *_ C0 c3 : iHom C0) as Pb23. -remember ((c1 *_ C0 Pb23) : iHom C0) as Pb15. -remember ((Pb12 *_ C0 c3) : iHom C0) as Pb33. -*) - -set (pb12 := c1 *_ C0 c2 :> C). -set (pb23 := c2 *_ C0 c3 :> C). -set (pb15 := (c1 *_ C0 Pb23) :> C). -set (pb33 := (Pb12 *_ C0 c3) :> C). - -(* -remember (c1 *_ C0 c2 :> C) as pb12. -remember (c2 *_ C0 c3 :> C) as pb23. -remember ((c1 *_ C0 Pb23) :> C) as pb15. -remember ((Pb12 *_ C0 c3) :> C) as pb33. -*) - -set (j12L := iprodl c1 c2). -set (j12R := iprodr c1 c2). -set (j23L := iprodl c2 c3). -set (j23R := iprodr c2 c3). -set (j15L := iprodl c1 Pb23). -set (j15R := iprodr c1 Pb23). -set (j33L := iprodl Pb12 c3). -set (j33R := iprodr Pb12 c3). - -(* -remember (iprodl c1 c2) as j12L. -remember (iprodr c1 c2) as j12R. -remember (iprodl c2 c3) as j23L. -remember (iprodr c2 c3) as j23R. -remember (iprodl c1 Pb23) as j15L. -remember (iprodr c1 Pb23) as j15R. -remember (iprodl Pb12 c3) as j33L. -remember (iprodr Pb12 c3) as j33R. -*) - -assert (j12L \; tgt1 = j12R \; src2) as sqPb12. -{ - set (X := @is_ppbk C). - specialize (X (c1 :> C) (c2 :> C)). - specialize (X (Cospan tgt1 src2)). - destruct X as [X]. - simpl in X. - - auto. -} - -assert (j23L \; tgt2 = j23R \; src3) as sqPb23. -{ - set (X := @is_ppbk C). - specialize (X (c2 :> C) (c3 :> C)). - specialize (X (Cospan tgt2 src3)). - destruct X as [X]. - simpl in X. - - auto. -} - -(* -assert (j12L \; tgt1 = j12R \; src2) as sqPb12. -{ - set (X := @is_ppbk C). - specialize (X (c1 :> C) (c2 :> C)). - specialize (X (Cospan tgt1 src2)). - destruct X as [X]. - simpl in X. - - inversion Heqc1; subst. - simpl; simpl in *. - - assert (j12L = bot2left - (pbk C1s C2s {| top := C0; left2top := tgt1; - right2top := src2 |})) as A1. - { auto. } - - assert (j12R = bot2right - (pbk C1s C2s {| top := C0; left2top := tgt1; - right2top := src2 |})) as A2. - { auto. } - - intros e1 e2. - rewrite A1. - rewrite A2. - - unfold jmcomp. - dependent destruction e1. - dependent destruction e2. - auto. -} -*) -(* -assert (forall (e1: C2s = (c2 :> C)) (e2: C3s = (c3 :> C)), - j23L \;;_e1 tgt2 = j23R \;;_e2 src3) as sqPb23. -{ - set (X := @is_ppbk C). - specialize (X C2s C3s). - specialize (X (Cospan tgt2 src3)). - destruct X as [X]. - simpl in X. - - inversion Heqc2; subst. - simpl; simpl in *. - - assert (j23L = bot2left - (pbk C2s C3s {| top := C0; left2top := tgt2; - right2top := src3 |})) as A1. - { auto. } - - assert (j23R = bot2right - (pbk C2s C3s {| top := C0; left2top := tgt2; - right2top := src3 |})) as A2. - { auto. } - - intros e1 e2. - rewrite A1. - rewrite A2. - - unfold jmcomp. - dependent destruction e1. - dependent destruction e2. - auto. -} -*) -(* -assert (@tgt C C0 Pb12 = j12R \; tgt2) as tgtPb12. -admit. -*) - -assert (@src C C0 Pb23 = j23L \; src2) as srcPb23. -admit. - - -(* -assert (j15L \; tgt1 = j15R \; @src C C0 Pb23) as sqPb15. -admit. - -assert (j33L \; @tgt C C0 Pb12 = j33R \; src3) as sqPb33. -admit. -*) - -assert (forall (e1: ((c2 *_C0 c3) :> C) = (Pb23 :> C)), - sigma (m23: (Pb33 :> C) ~> (Pb23 :> C)), - (j33L \; j12R = m23 \;;_e1 j23L) /\ (j33R = m23 \;;_e1 j23R)) - as M23. -{ intro e1. - subst Pb33. - eapply (@jm_pbsquare_universal C _ _ _ - (c2 *_ C0 c3 :> C) (Pb12 *_ C0 c3 :> C) (Pb23 :> C) _ _ - j23L j23R (j33L \; j12R) j33R _ _ e1); eauto. -} - -assert (forall (e1: ((c1 *_C0 c2) :> C) = (Pb12 :> C)), - sigma (m12: (Pb15 :> C) ~> (Pb12 :> C)), - (j15L = m12 \;;_e1 j12L) /\ (j15R \; j23L = m12 \;;_e1 j12R)) - as M12. -{ intro e1. - subst Pb15. - eapply (@jm_pbsquare_universal C _ _ _ - (c1 *_ C0 c2 :> C) (c1 *_ C0 Pb23 :> C) (Pb12 :> C) _ _ - j12L j12R j15L (j15R \; j23L) _ _ e1); eauto. -} - -assert (((c1 *_C0 c2) :> C) = Pb12) as E12. -{ auto. } -destruct (M12 E12) as [m12 [m12_E m12_U]]. - -assert (((c2 *_C0 c3) :> C) = Pb23) as E23. -{ auto. } -destruct (M23 E23) as [m23 [m23_E m23_U]]. - -(* -assert (C1s = (c1 :> C)) as E1. -{ inversion Heqc2; subst. - simpl; auto. -} -assert (C2s = (c2 :> C)) as E2. -{ inversion Heqc2; subst. - simpl; auto. -} - -assert (@src C C0 Pb23 = j23L \;;_E2 src2) as srcPb23'. -admit. -*) - -assert (forall (e2: ((c2 *_C0 c3) :> C) = Pb23), - j33L \; (j12R \; src2) = m23 \;;_e2 j23L \; src2) as M23_E1. -{ intros e2. - unfold jmcomp. - dependent destruction e2. - rewrite compoA. - rewrite m23_E. - unfold jmcomp. - dependent destruction E23. - rewrite compoA; auto. -} - -assert (forall (e3: ((c2 *_C0 c3) :> C) = Pb23), - (j33L \; j12L) \; tgt1 = m23 \;;_e3 j23L \; src2) as M23_E2. -{ intros e3. - specialize (M23_E1 E23). - unfold jmcomp in M23_E1. - dependent destruction E23. - unfold jmcomp. - dependent destruction e3. - setoid_rewrite <- compoA. - rewrite sqPb12. - rewrite M23_E1. - auto. -} - -(* -assert (forall (e1: (C2s = (c2 :> C))) (e2: ((c2 *_C0 c3) :> C) = Pb23), - j33L \; (j12R \;;_e1 src2) = m23 \;;_e2 j23L \;;_e1 src2) as M23_E1. -{ intros e1 e2. - unfold jmcomp. - dependent destruction e1. - dependent destruction e2. - rewrite compoA. - rewrite m23_E. - rewrite compoA; auto. -} - -assert (forall (e1: (C1s = (c1 :> C))) - (e2: (C2s = (c2 :> C))) (e3: ((c2 *_C0 c3) :> C) = Pb23), - (j33L \; j12L) \;;_e1 tgt1 = m23 \;;_e3 j23L \;;_e2 src2) as M23_E2. -{ intros e1 e2 e3. - specialize (sqPb12 E1 E2). - specialize (M23_E1 E2 E23). - unfold jmcomp in sqPb12, M23_E1. - dependent destruction E1. - dependent destruction E2. - dependent destruction E23. - unfold jmcomp. - dependent destruction e1. - dependent destruction e3. - dependent destruction e2. - setoid_rewrite <- compoA. - rewrite sqPb12. - rewrite M23_E1. - auto. -} -*) - -assert ((((c1 *_ C0 c2) *_ C0 c3) :> C) = Pb33) as E33. -{ auto. } - -assert ( - forall (e1: (((c1 *_ C0 c2) *_ C0 c3) :> C) = Pb33), - sigma mm: ((c1 *_ C0 c2) *_ C0 c3) ~> (c1 *_ C0 (c2 *_ C0 c3)), - (j33L \; j12L = mm \; j15L) /\ (idmap \;;_e1 m23 = mm \; j15R)) as X. -{ intro e1. - - unfold jmcomp. - dependent destruction e1. - rewrite comp1o. - - subst Pb12. -(* eapply (@jm_pbsquare_universal C _ _ _ _ _ _ _ _ _ _ (j33L \; j12L) m23). *) - eapply (@pbsquare_universal C _ _ _ _ _ _ _ _ _ (j33L \; j12L) m23). - -(* assert (forall y1 y2, pbsquare j15L j15R y1 y2). *) - - 2: { - specialize (M23_E2 E23). - dependent destruction E23. - exact M23_E2. - } - -(* - set (Csp15 := cospan (c1 :> C) (Pb23 :> C)). - set (Spn15 := span (c1 :> C) (Pb23 :> C)). - - assert (@Pullback C (c1 :> C) (Pb23 :> C) Csp15 Spn15) as PBa1. - { remember C as C'. - destruct C as [C class]. - destruct class as [A1 A2 A3 A4 A5 A6]. - destruct A6 as [B1]. - assert (pb (pbk (x0 :> C') (x1 :> C') Csp1)). - { inversion HeqC'; subst. - eapply B1; eauto. } - econstructor; eauto. - } -*) - - set (Csp15 (* : cospan (c1 :> C) (Pb23 :> C) *) := - @Cospan C (c1 :> C) (Pb23 :> C) _ tgt1 (j23L \; src2)). - - rewrite <- srcPb23. - - subst j15L j15R tgt1. - rewrite pbsquare_is_pullback. - - remember C as C'. - destruct C as [C class]. - destruct class as [A1 A2 A3 A4 A5 A6]. - destruct A6 as [B1]. - assert (pb (pbk (c1 :> C') (Pb23 :> C') Csp15)). - { inversion HeqC'; subst. - eapply B1; eauto. } - econstructor; eauto. -} - -destruct (X E33) as [mm R]. -exact mm. -Admitted. - - - -(* - assert () - - inversion Heqc1; subst. - - - - unfold iprodl. - unfold iprodr. - unfold iprod_pb. - simpl. - - unfold pbk. - unfold bot2left. - unfold bot2right. - simpl. - - econstructor; eauto. - - unfold jmcomp. - dependent destruction E2. - unfold src2. - rewrite <- srcPb23. - - econstructor. - - admit. -} -*) - -destruct (X E33) as [mm R]. -exact mm. -Admitted. - - - -(* -assert ((c2 *_ C0 c3) :> C = Pb23 :> C) as E2. -{ auto. } - -specialize (M23 E2). - -destruct M23 as [mm X]. -subst Pb33. -subst Pb23. -subst Pb12. - -admit. - -unfold iprod. -unfold iprod_pb; simpl. -unfold iprod. -unfold iprod_pb; simpl. -unfold hom. -unfold IsQuiver.hom. -simpl. -setoid_rewrite pbk_eta. -simpl. -unfold hom. -unfold IsQuiver.hom. - -Admitted. -*) - - - (* An internal precategory is an internal category with two operators that must be src and tgt preserving, i.e. iHom morphisms: identity : C0 -> C1 (corresponding to horizontal 1-morphism identity in From f1ab058119df1637c0ac112472ec2ac0f5cbef23 Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Fri, 12 Jan 2024 11:21:43 +0100 Subject: [PATCH 120/147] updated encatI.v; complete definition of double cat based on internal cat --- theories/encatI.v | 102 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 87 insertions(+), 15 deletions(-) diff --git a/theories/encatI.v b/theories/encatI.v index f6826e628..d1c4fa93a 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -2012,6 +2012,31 @@ set (j15R := iprodr c1 Pb23). set (j33L := iprodl Pb12 c3). set (j33R := iprodr Pb12 c3). +set (src23 := @src C C0 Pb23). +set (tgt23 := @tgt C C0 Pb23). +set (src12 := @src C C0 Pb12). +set (tgt12 := @tgt C C0 Pb12). + +assert (src23 = j23L \; src2) as srcPb23. +{ subst src23 j23L src2. + auto. +} + +assert (tgt23 = j23R \; tgt3) as tgtPb23. +{ subst tgt23 j23R tgt3. + auto. +} + +assert (src12 = j12L \; src1) as srcPb12. +{ subst src12 j12L src1. + auto. +} + +assert (tgt12 = j12R \; tgt2) as tgtPb12. +{ subst tgt12 j12R tgt2. + auto. +} + assert (j12L \; tgt1 = j12R \; src2) as sqPb12. { set (X := @is_ppbk C). specialize (X (c1 :> C) (c2 :> C)). @@ -2029,11 +2054,13 @@ assert (j23L \; tgt2 = j23R \; src3) as sqPb23. simpl in X. auto. } - + +(* assert (@src C C0 Pb23 = j23L \; src2) as srcPb23. { subst Pb23 j23L src2. auto. } +*) assert (forall (e1: ((c2 *_C0 c3) :> C) = (Pb23 :> C)), sigma (m23: (Pb33 :> C) ~> (Pb23 :> C)), @@ -2043,13 +2070,36 @@ assert (forall (e1: ((c2 *_C0 c3) :> C) = (Pb23 :> C)), subst Pb33. assert ((j33L \; j12R) \; tgt2 = j33R \; src3) as V1. - { (* setoid_rewrite <- compoA. subst j33L j33R j12R. - unfold Pb12. subst tgt2 src3. auto. *) - admit. - } - + { setoid_rewrite <- compoA. + assert (j33L \; tgt12 = j33R \; src3) as H. + { subst j33L j33R. + set (X := @is_ppbk C). + specialize (X (Pb12 :> C) (c3 :> C)). + specialize (X (Cospan tgt12 src3)). + destruct X as [X]. + simpl in X. + auto. + } + rewrite tgtPb12 in H; auto. + } + assert (pbsquare j23L j23R tgt2 src3) as V2. - { admit. } + { subst j23L j23R. + rewrite pbsquare_is_pullback. + + set (Csp23 := @Cospan C (c2 :> C) (c3 :> C) _ tgt2 src3). + + remember C as C'. + destruct C as [C class]. + destruct class as [A1 A2 A3 A4 A5 A6]. + destruct A6 as [B1]. + + assert (pb (pbk (c2 :> C') (c3 :> C') Csp23)). + { inversion HeqC'; subst. + eapply B1; eauto. + } + econstructor; eauto. + } eapply (@jm_pbsquare_universal C (c2 :> C) (c3 :> C) C0 (c2 *_ C0 c3 :> C) (Pb12 *_ C0 c3 :> C) (Pb23 :> C) @@ -2064,14 +2114,37 @@ assert (forall (e1: ((c1 *_C0 c2) :> C) = (Pb12 :> C)), subst Pb15. assert (j15L \; tgt1 = (j15R \; j23L) \; src2) as V1. - { (* setoid_rewrite <- compoA. subst j33L j33R j12R. - unfold Pb12. subst tgt2 src3. auto. *) - admit. - } + { setoid_rewrite <- compoA. + assert (j15L \; tgt1 = j15R \; src23) as H. + { subst j15L j15R. + set (X := @is_ppbk C). + specialize (X (c1 :> C) (Pb23 :> C)). + specialize (X (Cospan tgt1 src23)). + destruct X as [X]. + simpl in X. + auto. + } + rewrite srcPb23 in H; auto. + } assert (pbsquare j12L j12R tgt1 src2) as V2. - { admit. } - + { subst j12L j12R. + rewrite pbsquare_is_pullback. + + set (Csp12 := @Cospan C (c1 :> C) (c2 :> C) _ tgt1 src2). + + remember C as C'. + destruct C as [C class]. + destruct class as [A1 A2 A3 A4 A5 A6]. + destruct A6 as [B1]. + + assert (pb (pbk (c1 :> C') (c2 :> C') Csp12)). + { inversion HeqC'; subst. + eapply B1; eauto. + } + econstructor; eauto. + } + eapply (@jm_pbsquare_universal C (c1 :> C) (c2 :> C) C0 (c1 *_ C0 c2 :> C) (c1 *_ C0 Pb23 :> C) (Pb12 :> C) tgt1 src2 j12L j12R j15L (j15R \; j23L) V2 V1 e1); eauto. @@ -2153,8 +2226,7 @@ assert ( destruct (X E33) as [mm R]. exact mm. -Admitted. - +Qed. (* An internal precategory is an internal category with two operators From 9ff344820bf31707eeaadfd46ed6ba43924d52ce Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Fri, 12 Jan 2024 14:04:24 +0100 Subject: [PATCH 121/147] updated encatI.v; cleaning up --- theories/encatI.v | 214 +++++++++++++++++++++------------------------- 1 file changed, 97 insertions(+), 117 deletions(-) diff --git a/theories/encatI.v b/theories/encatI.v index d1c4fa93a..c85b45375 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -1976,14 +1976,10 @@ Qed. Notation "<( f , g )>" := (ipairC f g). - (* nested product *) -Program Definition iprodCAsc {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : - (((C1 *_C0 C2 : iHom C0) *_C0 C3) :> C) ~>_C - ((C1 *_C0 (C2 *_C0 C3 : iHom C0) : iHom C0) :> C). -remember C1 as c1. -remember C2 as c2. -remember C3 as c3. +Program Definition iprodCAsc {C : pbcat} {C0 : C} (c1 c2 c3 : iHom C0) : + (((c1 *_C0 c2 : iHom C0) *_C0 c3) :> C) ~>_C + ((c1 *_C0 (c2 *_C0 c3 : iHom C0) : iHom C0) :> C). set (src1 := @src C C0 c1). set (src2 := @src C C0 c2). @@ -1991,18 +1987,12 @@ set (src3 := @src C C0 c3). set (tgt1 := @tgt C C0 c1). set (tgt2 := @tgt C C0 c2). set (tgt3 := @tgt C C0 c3). -simpl. set (Pb12 := c1 *_ C0 c2 : iHom C0). set (Pb23 := c2 *_ C0 c3 : iHom C0). set (Pb15 := c1 *_ C0 Pb23 : iHom C0). set (Pb33 := Pb12 *_ C0 c3 : iHom C0). -set (pb12 := c1 *_ C0 c2 :> C). -set (pb23 := c2 *_ C0 c3 :> C). -set (pb15 := (c1 *_ C0 Pb23) :> C). -set (pb33 := (Pb12 *_ C0 c3) :> C). - set (j12L := iprodl c1 c2). set (j12R := iprodr c1 c2). set (j23L := iprodl c2 c3). @@ -2016,6 +2006,7 @@ set (src23 := @src C C0 Pb23). set (tgt23 := @tgt C C0 Pb23). set (src12 := @src C C0 Pb12). set (tgt12 := @tgt C C0 Pb12). +simpl. assert (src23 = j23L \; src2) as srcPb23. { subst src23 j23L src2. @@ -2042,8 +2033,7 @@ assert (j12L \; tgt1 = j12R \; src2) as sqPb12. specialize (X (c1 :> C) (c2 :> C)). specialize (X (Cospan tgt1 src2)). destruct X as [X]. - simpl in X. - auto. + simpl in X; auto. } assert (j23L \; tgt2 = j23R \; src3) as sqPb23. @@ -2051,16 +2041,54 @@ assert (j23L \; tgt2 = j23R \; src3) as sqPb23. specialize (X (c2 :> C) (c3 :> C)). specialize (X (Cospan tgt2 src3)). destruct X as [X]. - simpl in X. - auto. + simpl in X; auto. } -(* -assert (@src C C0 Pb23 = j23L \; src2) as srcPb23. -{ subst Pb23 j23L src2. - auto. -} -*) +assert ((j33L \; j12R) \; tgt2 = j33R \; src3) as sqPb33. +{ assert (j33L \; tgt12 = j33R \; src3) as H. + { subst j33L j33R. + set (X := @is_ppbk C). + specialize (X (Pb12 :> C) (c3 :> C)). + specialize (X (Cospan tgt12 src3)). + destruct X as [X]. + simpl in X. + auto. + } + setoid_rewrite <- compoA. + rewrite tgtPb12 in H; auto. +} + +assert (pbsquare j23L j23R tgt2 src3) as pbsq23. +{ subst j23L j23R. + rewrite pbsquare_is_pullback. + + set (Csp23 := @Cospan C (c2 :> C) (c3 :> C) _ tgt2 src3). + + remember C as C'. + destruct C as [C class]. + destruct class as [A1 A2 A3 A4 A5 A6]. + destruct A6 as [B1]. + + assert (pb (pbk (c2 :> C') (c3 :> C') Csp23)) as X. + { inversion HeqC'; subst. + eapply B1; eauto. + } + econstructor; eauto. +} + +assert (j15L \; tgt1 = (j15R \; j23L) \; src2) as sqPb15. +{ assert (j15L \; tgt1 = j15R \; src23) as H. + { subst j15L j15R. + set (X := @is_ppbk C). + specialize (X (c1 :> C) (Pb23 :> C)). + specialize (X (Cospan tgt1 src23)). + destruct X as [X]. + simpl in X; auto. + } + setoid_rewrite <- compoA. + rewrite srcPb23 in H; auto. +} + assert (forall (e1: ((c2 *_C0 c3) :> C) = (Pb23 :> C)), sigma (m23: (Pb33 :> C) ~> (Pb23 :> C)), @@ -2068,42 +2096,28 @@ assert (forall (e1: ((c2 *_C0 c3) :> C) = (Pb23 :> C)), as M23. { intro e1. subst Pb33. - - assert ((j33L \; j12R) \; tgt2 = j33R \; src3) as V1. - { setoid_rewrite <- compoA. - assert (j33L \; tgt12 = j33R \; src3) as H. - { subst j33L j33R. - set (X := @is_ppbk C). - specialize (X (Pb12 :> C) (c3 :> C)). - specialize (X (Cospan tgt12 src3)). - destruct X as [X]. - simpl in X. - auto. - } - rewrite tgtPb12 in H; auto. - } - - assert (pbsquare j23L j23R tgt2 src3) as V2. - { subst j23L j23R. - rewrite pbsquare_is_pullback. - set (Csp23 := @Cospan C (c2 :> C) (c3 :> C) _ tgt2 src3). + eapply (@jm_pbsquare_universal C (c2 :> C) (c3 :> C) C0 + (c2 *_ C0 c3 :> C) (Pb12 *_ C0 c3 :> C) (Pb23 :> C) + tgt2 src3 j23L j23R (j33L \; j12R) j33R pbsq23 sqPb33 e1); eauto. +} - remember C as C'. - destruct C as [C class]. - destruct class as [A1 A2 A3 A4 A5 A6]. - destruct A6 as [B1]. +assert (pbsquare j12L j12R tgt1 src2) as pbsq12. +{ subst j12L j12R. + rewrite pbsquare_is_pullback. + + set (Csp12 := @Cospan C (c1 :> C) (c2 :> C) _ tgt1 src2). + + remember C as C'. + destruct C as [C class]. + destruct class as [A1 A2 A3 A4 A5 A6]. + destruct A6 as [B1]. - assert (pb (pbk (c2 :> C') (c3 :> C') Csp23)). - { inversion HeqC'; subst. - eapply B1; eauto. - } - econstructor; eauto. + assert (pb (pbk (c1 :> C') (c2 :> C') Csp12)) as X. + { inversion HeqC'; subst. + eapply B1; eauto. } - - eapply (@jm_pbsquare_universal C (c2 :> C) (c3 :> C) C0 - (c2 *_ C0 c3 :> C) (Pb12 *_ C0 c3 :> C) (Pb23 :> C) - tgt2 src3 j23L j23R (j33L \; j12R) j33R V2 V1 e1); eauto. + econstructor; eauto. } assert (forall (e1: ((c1 *_C0 c2) :> C) = (Pb12 :> C)), @@ -2113,41 +2127,9 @@ assert (forall (e1: ((c1 *_C0 c2) :> C) = (Pb12 :> C)), { intro e1. subst Pb15. - assert (j15L \; tgt1 = (j15R \; j23L) \; src2) as V1. - { setoid_rewrite <- compoA. - assert (j15L \; tgt1 = j15R \; src23) as H. - { subst j15L j15R. - set (X := @is_ppbk C). - specialize (X (c1 :> C) (Pb23 :> C)). - specialize (X (Cospan tgt1 src23)). - destruct X as [X]. - simpl in X. - auto. - } - rewrite srcPb23 in H; auto. - } - - assert (pbsquare j12L j12R tgt1 src2) as V2. - { subst j12L j12R. - rewrite pbsquare_is_pullback. - - set (Csp12 := @Cospan C (c1 :> C) (c2 :> C) _ tgt1 src2). - - remember C as C'. - destruct C as [C class]. - destruct class as [A1 A2 A3 A4 A5 A6]. - destruct A6 as [B1]. - - assert (pb (pbk (c1 :> C') (c2 :> C') Csp12)). - { inversion HeqC'; subst. - eapply B1; eauto. - } - econstructor; eauto. - } - eapply (@jm_pbsquare_universal C (c1 :> C) (c2 :> C) C0 (c1 *_ C0 c2 :> C) (c1 *_ C0 Pb23 :> C) (Pb12 :> C) - tgt1 src2 j12L j12R j15L (j15R \; j23L) V2 V1 e1); eauto. + tgt1 src2 j12L j12R j15L (j15R \; j23L) pbsq12 sqPb15 e1); eauto. } assert (((c1 *_C0 c2) :> C) = Pb12) as E12. @@ -2180,8 +2162,30 @@ assert (forall (e3: ((c2 *_C0 c3) :> C) = Pb23), dependent destruction e3. setoid_rewrite <- compoA. rewrite sqPb12. - rewrite M23_E1. - auto. + rewrite M23_E1; auto. +} + +assert (pbsquare j15L j15R tgt1 src23) as pbsq15. +{ set (Csp15 := + @Cospan C (c1 :> C) (Pb23 :> C) _ tgt1 (j23L \; src2)). + + subst j15L j15R. + rewrite pbsquare_is_pullback. + + remember C as C'. + destruct C as [C class]. + destruct class as [A1 A2 A3 A4 A5 A6]. + destruct A6 as [B1]. + assert (pb (pbk (c1 :> C') (Pb23 :> C') Csp15)) as X. + { inversion HeqC'; subst. + eapply B1; eauto. } + econstructor; eauto. +} + +assert ((j33L \; j12L) \; tgt1 = m23 \; src23) as sqM23. +{ specialize (M23_E2 E23). + dependent destruction E23. + exact M23_E2. } assert ((((c1 *_ C0 c2) *_ C0 c3) :> C) = Pb33) as E33. @@ -2192,43 +2196,19 @@ assert ( sigma mm: ((c1 *_ C0 c2) *_ C0 c3) ~> (c1 *_ C0 (c2 *_ C0 c3)), (j33L \; j12L = mm \; j15L) /\ (idmap \;;_e1 m23 = mm \; j15R)) as X. { intro e1. - unfold jmcomp. dependent destruction e1. rewrite comp1o. - subst Pb12. eapply (@pbsquare_universal C _ _ _ _ _ _ _ _ _ (j33L \; j12L) m23). - - 2: { - specialize (M23_E2 E23). - dependent destruction E23. - exact M23_E2. - } - - set (Csp15 (* : cospan (c1 :> C) (Pb23 :> C) *) := - @Cospan C (c1 :> C) (Pb23 :> C) _ tgt1 (j23L \; src2)). - - rewrite <- srcPb23. - - subst j15L j15R tgt1. - rewrite pbsquare_is_pullback. - - remember C as C'. - destruct C as [C class]. - destruct class as [A1 A2 A3 A4 A5 A6]. - destruct A6 as [B1]. - assert (pb (pbk (c1 :> C') (Pb23 :> C') Csp15)). - { inversion HeqC'; subst. - eapply B1; eauto. } - econstructor; eauto. + exact pbsq15. + exact sqM23. } - + destruct (X E33) as [mm R]. exact mm. Qed. - (* An internal precategory is an internal category with two operators that must be src and tgt preserving, i.e. iHom morphisms: identity : C0 -> C1 (corresponding to horizontal 1-morphism identity in From d9c68696df1022c9e4d253bc689ed3fcd26f48fb Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Fri, 12 Jan 2024 14:45:12 +0100 Subject: [PATCH 122/147] updated encatI.v; merged in the strict double category direct definition from encatD.v --- theories/encatI.v | 864 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 863 insertions(+), 1 deletion(-) diff --git a/theories/encatI.v b/theories/encatI.v index c85b45375..390e1900a 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -1279,12 +1279,94 @@ End test. (********************************************************************) (********************************************************************) + Notation "'sigma' x .. y , p" := (sigT (fun x => .. (sigT (fun y => p)) ..)) (at level 200, x binder, right associativity, format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") : type_scope. + +(*** GENERALISED ENRICHED CATEGORIES *) + +Declare Scope encat_scope. +Delimit Scope encat_scope with encat. +Local Open Scope encat_scope. + +(* Enrichment in a monoidal category, following + https://ncatlab.org/nlab/show/enriched+category +*) +HB.mixin Record IsEnQuiver (V: Type) C := { + hom_object : C -> C -> V + }. +Unset Universe Checking. +HB.structure Definition EnQuiver (V: Type) : Set := + { C of IsEnQuiver V C }. +Set Universe Checking. + +(* Monoidal precategory with the enrichment operators (no axioms) *) +HB.mixin Record IsEnPreCat (V: PreMonoidal.type) C of + EnQuiver (PreMonoidal.sort V) C := { + id_element : forall (a: C), + @hom V onec (hom_object a a) ; + comp_morphism : forall (a b c: C), + @hom V (@hom_object V C b c * @hom_object V C a b) + (@hom_object V C a c) +}. +Unset Universe Checking. +HB.structure Definition EnPreCat (V: PreMonoidal.type) : Set := + { C of IsEnPreCat V C }. +Set Universe Checking. + +Notation "a ~^ b" := (hom_object a b) + (at level 99, b at level 200, format "a ~^ b") : encat_scope. +Notation "a ~^_ ( V , C ) b" := (@hom_object V C a b) + (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. +Notation "~^IE a" := (id_element a) + (at level 99, format "~^IE a") : cat_scope. +Notation "~^IE_ ( V , C ) a" := (@id_element V C a) + (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. +(* not working *) +Notation "~^CM a b c" := (comp_morphism a b c) + (at level 99, + format "~^CM a b c") : cat_scope. +Notation "~^CM_ ( V , C ) a b c" := (@comp_morphism V C a b c) + (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. + +(* V-enriched category: + V is the monoidal category; + C is the base category that gets enriched +*) +HB.mixin Record IsEnCat (V: Monoidal.type) C of EnPreCat V C := { + ecat_comp_assoc : forall a b c d: C, + forall alpha: + (((c ~^_(V,C) d) * (b ~^_(V,C) c)) * (a ~^_(V,C) b)) ~>_V + ((c ~^_(V,C) d) * ((b ~^_(V,C) c) * (a ~^_(V,C) b))), + ((@comp_morphism V C b c d) <*> (@idmap V (a ~^_(V,C) b))) \; + (@comp_morphism V C a b d) + = + alpha \; + ((@idmap V (c ~^_(V,C) d)) <*> (@comp_morphism V C a b c)) \; + (@comp_morphism V C a c d) ; + + ecat_comp_left_unital : forall a b: C, + forall l: onec * (a ~^_(V,C) b) ~>_V (a ~^_(V,C) b), + l = ((@id_element V C b) <*> (@idmap V (a ~^_(V,C) b))) \; + (@comp_morphism V C a b b) ; + ecat_comp_right_unital : forall a b: C, + forall r: (a ~^_(V,C) b) * onec ~>_V (a ~^_(V,C) b), + r = ((@idmap V (a ~^_(V,C) b)) <*> (@id_element V C a)) \; + (@comp_morphism V C a a b) +}. +Unset Universe Checking. +#[verbose] +HB.structure Definition EnCat (V: Monoidal.type) : Set := + { C of IsEnCat V C }. +Set Universe Checking. + + +(************************************************************************) + (*** CATEGORIES WITH PULLBACKS *) (* category with all prepullbacks *) @@ -1322,7 +1404,7 @@ HB.structure Definition PBCat := (************************************************************************) -(**** INTERNAL CATEGORIES - NEW DEFINITION *) +(**** INTERNAL CATEGORIES *) (* Defining internal hom objects. C0 and C1 are objects of C. @@ -2273,6 +2355,11 @@ HB.structure Definition InternalCat (C : pbcat) := {C0 of @IsInternalCat C C0}. (* Check (icat Type <~> cat). *) + +(************************************************************************) + +(** DEFINITION OF DOUBLE CATEGORY (based on internal category) *) + (* A double category is an internal category in cat - The objects are the objects of C0 - The vertical maps are the maps of C0 @@ -2311,3 +2398,778 @@ Definition doublecat := icat cat. (* Check (doublecat <~> ???) *) + +(************************************************************************) + +(*** STRICT DOUBLE CATEGORIES (without internal categories) *) + +(* Strict double categories, from + https://ncatlab.org/nlab/show/double+category + (we don't use internal categories) + + base obejcts as 0-cells: C ; + + vertical 1-morphisms (category D0 on C): hom C ; + + horizontal 1-morphisms (category H on C): hom (transpose C) ; + + horizontal 1-morhisms as 1-cells for D1: D1obj C ; + + 2-morphisms (category D1 on C1obj): hom (D1obj C) ; + + horizontally composable pairs of 1-cells : DPobj C ; + + horizontally composable pairs of 2-morphisms + (product category DP, D1 *0 D1) : hom (DPobj C) ; + + The definition of Strict Double Category, SDouble = (D0, H, D1, Dp), + is given by: + + - base objects C + + - (level-1) category (D0) of vertical 1-morphism on C + + - (level-1) category (H) of horizontal 1-morphism (D1obj) on C + + - (level-2) category (D1) of vertical 2-morphism on D1obj + + - (derived) category (DP) of vertical 2-morphisms on + horizontally D0-composable D1 products + ($\mbox{D1} *_0 \mbox{D1}$) + + - Source functor: $\mbox{D1} \to \mbox{D0}$ + + - Target functor: $\mbox{D1} \to \mbox{D0}$ + + - Horizontal unit functor: $\mbox{D0} \to \mbox{D1}$ + + - Horizontal composition functor: $\mbox{DP} \to \mbox{D1}$ +*) + + +(** Quivers for double categories *) + +(* transpose for horizontal morphism quiver. + HB.tag needed to identify transpose as lifter *) +HB.tag Definition transpose (C : quiver) : U := C. +#[wrapper] HB.mixin Record _IsHQuiver C of IsQuiver C := { + is_hquiver : IsQuiver (transpose C) +}. +(* vertical and horizontal quivers, defining cells *) +Unset Universe Checking. +#[short(type="vhquiver")] +HB.structure Definition VHQuiver : Set := + { C of IsQuiver C & IsQuiver (transpose C) }. +Set Universe Checking. + +HB.tag Definition hhom (c : VHQuiver.type) : c -> c -> U := @hom (transpose c). +Notation "a +> b" := (hhom a b) + (at level 99, b at level 200, format "a +> b") : cat_scope. + +(* record to represent the set of morphims + (needed for 2-objects, i.e. horizontal morphisms) *) +Record Total2 T (h: T -> T -> U) : Type := TT2 { + source : T; + target : T; + this_morph : h source target }. + +(* the set of horizontal morphisms. *) +HB.tag Definition D1obj (C: vhquiver) := Total2 (@hhom C). + +(* D1 quiver requirement (includes D0 quiver and its transpose). *) +#[wrapper] +HB.mixin Record _IsDQuiver T of VHQuiver T := + { is_dquiver : Quiver (D1obj T) }. +Unset Universe Checking. +#[short(type="dquiver")] +HB.structure Definition DQuiver : Set := { C of Quiver (D1obj C) }. +Set Universe Checking. + + +(** Horizonal D0-level category (H-D0) *) + +(* Precategory based on the HQuiver (i.e. horizontal precategory on D0 + objects) *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record _IsHPreCat T of VHQuiver T := { + is_hprecat : Quiver_IsPreCat (transpose T) }. +#[short(type="hprecat")] +HB.structure Definition HPreCat : Set := + { C of Quiver_IsPreCat (transpose C) }. +Set Universe Checking. + +(* The category based on the HQuiver (i.e. horizontal category on D0 + objects) *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record _IsHCat T of HPreCat T := { + is_hcat : PreCat_IsCat (transpose T) }. +#[short(type="hcat")] +HB.structure Definition HCat : Set := + { C of PreCat_IsCat (transpose C) }. +Set Universe Checking. + + +(** Vertical 2-cell level category (D1 category) *) + +(* Precategory based on the DQuiver (i.e. precategory D1). Gives: + vertical 2-cell identity morphism. + vertical 2-cell composition. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record _IsD1PreCat T of DQuiver T := { + is_d1precat : Quiver_IsPreCat (@D1obj T) }. +#[short(type="d1precat")] +HB.structure Definition D1PreCat : Set := + { C of Quiver_IsPreCat (@D1obj C) }. +Set Universe Checking. + +(* The category based on the DQuiver (i.e. category D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record _IsD1Cat T of D1PreCat T := { + is_d1cat : PreCat_IsCat (@D1obj T) }. +#[short(type="d1cat")] +HB.structure Definition D1Cat : Set := + { C of PreCat_IsCat (@D1obj C) }. +Set Universe Checking. + + +(** Naked double category *) + +(* Naked double category. Vertical (V-D0) and D1 categories. Double + category without horizontal operators and functors *) +Unset Universe Checking. +#[short(type="dcat")] +HB.structure Definition DCat : Set := + { C of Cat C & D1Cat C }. +Set Universe Checking. + +(* Naked strict double category. Vertical (V-D0), horizontal (H-D0) + and D1 categories. Strict double category without functors *) +Unset Universe Checking. +#[short(type="sd2cat")] +HB.structure Definition SDCat : Set := { C of Cat C & HCat C & D1Cat C }. +Set Universe Checking. + + +(** Auxiliary notions for Source, Target and + Horizontal Unit functors *) + +(* homsets of 2-cell (D1) morphisms *) +Definition d1hom (D: DQuiver.type) : D1obj D -> D1obj D -> U := + @hom (D1obj D). +(* type-level smart constructor for D1 homsets *) +Definition D1hom (D: DQuiver.type) (a b c d: D) (h0: hhom a b) + (h1: hhom c d) : U := d1hom (TT2 h0) (TT2 h1). + +(* smart projections for: + source functor (for horizontal morphisms): D1 -> D0. + defined as object-level function, by functoriality lifted to a + (2-cell, vertical) morphism-level one *) +HB.tag Definition HSource C := fun (X: D1obj C) => @source C (@hhom C) X. +(* target functor (for horizontal morphisms): D1 -> D0. *) +HB.tag Definition HTarget C := fun (X: D1obj C) => @target C (@hhom C) X. + +(* horizontal unit functor: D0 -> D1 *) +Definition hhunit (T: hprecat) (a: T) : D1obj T := + @TT2 T (@hhom T) a a (@idmap (transpose T) a). +HB.tag Definition H1Unit (C: hprecat) := + fun (x: HPreCat.sort C) => @hhunit C x. + + +(** Auxiliary notions for 2-cell Horizontal Composition functor *) + +(* composable pairs of morphisms as a set *) +Record GenComp T (h: T -> T -> U) := GC { + h_one : T; + h_two : T ; + h_three : T; + h_first : h h_one h_two ; + h_second : h h_two h_three }. + +(* composable pairs of horizontal morphisms as a set *) +HB.tag Definition DPobj (C: vhquiver) := GenComp (@hhom C). + +(* smart projections *) +Definition H2First (C: vhquiver) (X: @DPobj C) : D1obj C := + @TT2 C _ (h_one X) (h_two X) (h_first X). +Definition H2Second (C: vhquiver) (X: @DPobj C) : D1obj C := + @TT2 C _ (h_two X) (h_three X) (h_second X). + + +(* horizontal composition functor: D1 * D1 -> D1 *) +Definition hhcomp (T: hprecat) (x: DPobj T) : D1obj T := + match x with + @GC _ _ a b c h1 h2 => @TT2 T (@hhom T) a c (h1 \; h2) end. +HB.tag Definition H1Comp (C: hprecat) := + fun (x: DPobj C) => @hhcomp C x. + +(* hhunit - horizontal unit functor. + + hhcomp - horizontal composition functor (horizontal composition of + two horizontal morphisms from a cell product). + + Both specified as object-level functions (they actually come for + free from the H-D0 category, since we are in the strict case), to + be lifted by functoriality to morphism-level ones. + + At the object level, hhunit gives a horizontal identity morphism + for each D0 object. At the morphism level, it gives horizontal + 2-cell identity for each vertical morphism. + + In the case of hhcomp, relying on functoriality requires some care + in defining the product category, making sure that adjacency at the + object-level (between horizontal morphisms) is matched by adjacency + at the morphism-level (between 2-cells). *) + + +(** Source and target functors *) + +(* source prefunctor. + D1obj T is the quiver of the 2-morphisms, thanks to VHQuiver. + T is the quiver of 1-morphisms. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsSPreFunctor T of DCat T := { + is_sprefunctor : IsPreFunctor (D1obj T) T (@HSource T) }. +HB.structure Definition SPreFunctor : Set := {C of IsSPreFunctor C}. +Set Universe Checking. + +(* target prefunctor. *) +Unset Universe Checking. +#[wrapper] + HB.mixin Record IsTPreFunctor T of DCat T := { + is_tprefunctor : IsPreFunctor (D1obj T) T (@HTarget T) }. +HB.structure Definition TPreFunctor : Set := {C of IsTPreFunctor C}. +Set Universe Checking. + +(* source functor. *) +Unset Universe Checking. +#[wrapper] + HB.mixin Record SPreFunctor_IsFunctor T of SPreFunctor T := { + is_sfunctor : PreFunctor_IsFunctor (D1obj T) T (@HSource T) }. +HB.structure Definition SFunctor : Set := {C of SPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* target functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record TPreFunctor_IsFunctor T of TPreFunctor T := { + is_tfunctor : PreFunctor_IsFunctor (D1obj T) T (@HTarget T) }. +HB.structure Definition TFunctor : Set := {C of TPreFunctor_IsFunctor C}. +Set Universe Checking. + + +(** Unit functor *) + +(* unit prefunctor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsUPreFunctor T of SDCat T := + { is_uprefunctor : IsPreFunctor T (D1obj T) (@H1Unit T) }. +HB.structure Definition UPreFunctor : Set := {C of IsUPreFunctor C}. +Set Universe Checking. + +(* unit functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record UPreFunctor_IsFunctor T of UPreFunctor T := { + is_ufunctor : PreFunctor_IsFunctor T (D1obj T) (@H1Unit T) }. +HB.structure Definition UFunctor : Set := {C of UPreFunctor_IsFunctor C}. +Set Universe Checking. + +Unset Universe Checking. +HB.about Functor. +HB.structure Definition STUFunctor : Set := + {C of SFunctor C & TFunctor C & UFunctor C}. +Set Universe Checking. + + +(** Lifting of Source, Target and Unit functors to D1 morphisms *) + +(* 2-cell source *) +Definition H1Source (T: SFunctor.type) (a b: @D1obj T) + (m: @d1hom T a b) : + (HSource a) ~> (HSource b) := (@HSource T) <$> m. + +(* 2-cell target *) +Definition H1Target (T: TFunctor.type) (a b: @D1obj T) + (m: @d1hom T a b) : + (HTarget a) ~> (HTarget b) := (@HTarget T) <$> m. + +(* horizontal 2-cell unit (maps vertical morphisms to horizontally + unitary 2-cells) *) +Definition H2Unit (T: UFunctor.type) (a b: T) (m: @hom T a b) : + (H1Unit a) ~> (H1Unit b) := (@H1Unit T) <$> m. + + +(** Horizontal product category (D1 *d0 D1) *) +(* DPobj T is the pseudo-pullback category used to deal with + products of D1 (where the adjacency condition is expressed + w.r.t. D0 *) + +(* horizontal composition of two (naked) horizontal morphisms *) +Definition l_hcomp (T: SDCat.type) (a0 a1 a2: T) + (h0: hhom a0 a1) (h1: hhom a1 a2) : D1obj T := + @TT2 T _ a0 a2 (h0 \; h1). + +Notation "'sigma' x .. y , p" := + (sigT (fun x => .. (sigT (fun y => p)) ..)) + (at level 200, x binder, right associativity, + format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") + : type_scope. + +(** DPobj quiver *) +Definition DP_hom (T: STUFunctor.type) (x y: DPobj T) := + sigma (hh0: D1hom (h_first x) (h_first y)) + (hh1: D1hom (h_second x) (h_second y)), + H1Target hh0 = H1Source hh1. + +HB.instance Definition DPQuiver (T: STUFunctor.type) : + IsQuiver (DPobj T) := + IsQuiver.Build (DPobj T) (fun A B => @DP_hom T A B). + + +(** Product precategory *) + +Lemma DP_id_eq (T : STUFunctor.type) (a: DPobj T) : + H1Target (@idmap (@D1obj T) (H2First a)) = + H1Source (@idmap (@D1obj T) (H2Second a)). +unfold H1Target, HTarget. +unfold H1Source, HSource. +repeat rewrite F1; auto. +Defined. + +(* DPobj identity *) +Definition DP_id (T: STUFunctor.type) (A: DPobj T) : A ~> A := + let h0 := h_first A + in let h1 := h_second A + in let uu0 := @idmap (D1obj T) (TT2 h0) + in let uu1 := @idmap (D1obj T) (TT2 h1) + in @existT (D1hom h0 h0) + (fun hh0: (D1hom h0 h0) => + sigma (hh1 : D1hom h1 h1), H1Target hh0 = H1Source hh1) uu0 + (@existT (D1hom h1 h1) + (fun hh1: (D1hom h1 h1) => H1Target uu0 = H1Source hh1) uu1 + (@DP_id_eq T A)). + +Definition DP_comp_auxA (T : STUFunctor.type) + (A B C : DPobj T) + (hhA0 : D1hom (h_first A) (h_first B)) + (hhA1 : D1hom (h_second A) (h_second B)) + (ppA : H1Target hhA0 = H1Source hhA1) + (hhB0 : D1hom (h_first B) (h_first C)) + (hhB1 : D1hom (h_second B) (h_second C)) + (ppB : H1Target hhB0 = H1Source hhB1) : + (H1Target hhA0) \; (H1Target hhB0) = + (H1Source hhA1) \; (H1Source hhB1). + rewrite ppA. + rewrite ppB. + reflexivity. +Defined. + +Definition DP_comp_auxS (T : STUFunctor.type) + (A B C : DPobj T) + (hhA0 : D1hom (h_first A) (h_first B)) + (hhA1 : D1hom (h_second A) (h_second B)) + (ppA : H1Target hhA0 = H1Source hhA1) + (hhB0 : D1hom (h_first B) (h_first C)) + (hhB1 : D1hom (h_second B) (h_second C)) + (ppB : H1Target hhB0 = H1Source hhB1) : + H1Source (hhA1 \; hhB1) = (H1Source hhA1) \; (H1Source hhB1). + unfold H1Source, HSource. + repeat rewrite Fcomp. + reflexivity. +Defined. + +Definition DP_comp_auxT (T : STUFunctor.type) + (A B C : DPobj T) + (hhA0 : D1hom (h_first A) (h_first B)) + (hhA1 : D1hom (h_second A) (h_second B)) + (ppA : H1Target hhA0 = H1Source hhA1) + (hhB0 : D1hom (h_first B) (h_first C)) + (hhB1 : D1hom (h_second B) (h_second C)) + (ppB : H1Target hhB0 = H1Source hhB1) : + H1Target (hhA0 \; hhB0) = (H1Target hhA0) \; (H1Target hhB0). + unfold H1Target, HTarget. + repeat rewrite Fcomp. + reflexivity. +Defined. + +Definition DP_comp_auxI (T : STUFunctor.type) + (A B C : DPobj T) + (hhA0 : D1hom (h_first A) (h_first B)) + (hhA1 : D1hom (h_second A) (h_second B)) + (ppA : H1Target hhA0 = H1Source hhA1) + (hhB0 : D1hom (h_first B) (h_first C)) + (hhB1 : D1hom (h_second B) (h_second C)) + (ppB : H1Target hhB0 = H1Source hhB1) : + A ~> C. + econstructor 1 with (comp hhA0 hhB0). + econstructor 1 with (comp hhA1 hhB1). + setoid_rewrite DP_comp_auxS; eauto. + setoid_rewrite DP_comp_auxT; eauto. + eapply DP_comp_auxA; eauto. +Defined. + +(* DPobj composition, defined in proof mode *) +Definition DP_comp (T: STUFunctor.type) (A B C: DPobj T) : + (A ~> B) -> (B ~> C) -> A ~> C. + intros chA chB. + destruct chA as [hhA0 [hhA1 ppA]]. + destruct chB as [hhB0 [hhB1 ppB]]. + eapply DP_comp_auxI; eauto. +Defined. + +(* DPobj is a precategory *) +HB.instance Definition DPPreCat (T: STUFunctor.type) : + Quiver_IsPreCat (DPobj T) := + Quiver_IsPreCat.Build (DPobj T) (@DP_id T) (@DP_comp T). + +(* + have HcompP : + (a b : DPobj T) + (f g : a ~> b), + proj1T f = proj1t f -> + + -> + f = g. + + exists a b p, + fst f = a + f = (a,b,p) +*) + +(** Product category *) + +Lemma DP_LeftUnit_lemma (T : STUFunctor.type) : + forall (a b : DPobj T) (f : a ~> b), idmap \; f = f. + + move => a b [x [x0 e]] /=. + simpl in *. + unfold idmap; simpl. + unfold DP_id; simpl. + unfold comp; simpl. + unfold DP_comp_auxI; simpl. + + assert (idmap \; x = x) as A. + { rewrite comp1o; auto. } + + assert (idmap \; x0 = x0) as A0. + { rewrite comp1o; auto. } + + assert (H1Target (idmap \; x) = H1Source (idmap \; x0)) as B. + { rewrite A. + rewrite A0; auto. } + + destruct a eqn: aaa. + destruct b eqn: bbb. + simpl. + + assert (existT + (fun hh0 : D1hom h_first0 h_first1 => + sigma hh1 : D1hom h_second0 h_second1,H1Target hh0 = H1Source hh1) + (idmap \; x) + (existT + (fun hh1 : D1hom h_second0 h_second1 => + H1Target (idmap \; x) = H1Source hh1) + (idmap \; x0) + B) = + existT + (fun hh0 : D1hom h_first0 h_first1 => + sigma hh1 : D1hom h_second0 h_second1,H1Target hh0 = H1Source hh1) + x + (existT + (fun hh1 : D1hom h_second0 h_second1 => H1Target x = H1Source hh1) + x0 + e)) as C. + { revert B. + revert A. + revert A0. + generalize (idmap \; x) as v. + generalize (idmap \; x0) as v0. + intros v0 v A0. + rewrite A0. + intro A. + rewrite A. + intro B. + + assert (B = e) as BE. + { eapply Prop_irrelevance. } + + rewrite BE. + reflexivity. +} + + inversion aaa; subst. + rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] + (Prop_irrelevance _ B). + eapply C. +Qed. + +Lemma DP_RightUnit_lemma (T : STUFunctor.type) : + forall (a b : DPobj T) (f : a ~> b), f \; idmap = f. + + move => a b [x [x0 e]] /=. + simpl in *. + unfold idmap; simpl. + unfold DP_id; simpl. + unfold comp; simpl. + unfold DP_comp_auxI; simpl. + + assert (x \; idmap = x) as A. + { rewrite compo1; auto. } + + assert (x0 \; idmap = x0) as A0. + { rewrite compo1; auto. } + + assert (H1Target (x \; idmap) = H1Source (x0 \; idmap)) as B. + { rewrite A. + rewrite A0; auto. } + + destruct a eqn: aaa. + destruct b eqn: bbb. + simpl. + + assert (existT + (fun hh0 : D1hom h_first0 h_first1 => + sigma hh1 : D1hom h_second0 h_second1, + H1Target hh0 = H1Source hh1) + (x \; idmap) + (existT + (fun hh1 : D1hom h_second0 h_second1 => + H1Target (x \; idmap) = H1Source hh1) + (x0 \; idmap) + B) = + existT + (fun hh0 : D1hom h_first0 h_first1 => + sigma hh1 : D1hom h_second0 h_second1, + H1Target hh0 = H1Source hh1) + x + (existT + (fun hh1 : D1hom h_second0 h_second1 => + H1Target x = H1Source hh1) + x0 + e)) as C. + { revert B. + revert A. + revert A0. + generalize (x \; idmap) as v. + generalize (x0 \; idmap) as v0. + intros v0 v A0. + rewrite A0. + intro A. + rewrite A. + intro B. + + assert (B = e) as BE. + { eapply Prop_irrelevance. } + + rewrite BE. + reflexivity. + } + + inversion aaa; subst. + rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] + (Prop_irrelevance _ B). + eapply C. +Qed. + +Lemma DP_Assoc_lemma (T : STUFunctor.type) : + forall (a b c d : DPobj T) (f : a ~> b) (g : b ~> c) (h : c ~> d), + f \; g \; h = (f \; g) \; h. + intros. + remember f as f1. + remember g as g1. + remember h as h1. + destruct f as [x0 s0]. + destruct g as [x1 s1]. + destruct h as [x2 s2]. + destruct s0 as [y0 e0]. + destruct s1 as [y1 e1]. + destruct s2 as [y2 e2]. + simpl. + + set (x01 := comp x0 x1). + set (x12 := comp x1 x2). + set (x0_12 := comp x0 x12). + set (x01_2 := comp x01 x2). + set (y01 := comp y0 y1). + set (y12 := comp y1 y2). + set (y0_12 := comp y0 y12). + set (y01_2 := comp y01 y2). + + assert (x0_12 = x01_2) as X0. + { subst x0_12 x01_2. + rewrite compoA; eauto. } + assert (y0_12 = y01_2) as Y0. + { subst y0_12 y01_2. + rewrite compoA; eauto. } + + set (x01_t := comp (H1Target x0) (H1Target x1)). + set (x01_2_t := comp x01_t (H1Target x2)). + set (x12_t := comp (H1Target x1) (H1Target x2)). + set (x0_12_t := comp (H1Target x0) x12_t). + set (y01_s := comp (H1Source y0) (H1Source y1)). + set (y01_2_s := comp y01_s (H1Source y2)). + set (y12_s := comp (H1Source y1) (H1Source y2)). + set (y0_12_s := comp (H1Source y0) y12_s). + + assert (x01_t = y01_s) as E01. + { subst x01_t y01_s. + rewrite e0. + rewrite e1; auto. } + assert (x01_2_t = y01_2_s) as E01_2. + { subst x01_2_t y01_2_s. + rewrite E01. + rewrite e2; auto. } + assert (x12_t = y12_s) as E12. + { subst x12_t y12_s. + rewrite e1. + rewrite e2; auto. } + assert (x0_12_t = y0_12_s) as E0_12. + { subst x0_12_t y0_12_s. + rewrite E12. + rewrite e0; auto. } + + assert (x0_12_t = x01_2_t) as E02T. + { subst x0_12_t x01_2_t. + subst x12_t x01_t. + rewrite compoA; auto. } + assert (y0_12_s = y01_2_s) as E02S. + { subst y0_12_s y01_2_s. + subst y12_s y01_s. + rewrite compoA; auto. } + + unfold comp. + simpl. + unfold DP_comp. + simpl. + inversion Heqf1; subst. + clear H. + + unfold DP_comp_auxI; simpl. + + assert (H1Target (x0 \; x1 \; x2) = + H1Source (y0 \; y1 \; y2)) as KR. + { subst x0_12_t y0_12_s. + subst x12_t y12_s. + unfold H1Target. + repeat rewrite Fcomp; simpl. + unfold H1Target in E0_12. + rewrite E0_12. + unfold H1Source. + repeat rewrite Fcomp; simpl. + auto. + } + + assert (H1Target ((x0 \; x1) \; x2) = + H1Source ((y0 \; y1) \; y2)) as KL. + { subst x01_2_t y01_2_s. + subst x01_t y01_s. + unfold H1Target. + repeat rewrite Fcomp; simpl. + unfold H1Target in E01_2. + rewrite E01_2. + unfold H1Source. + repeat rewrite Fcomp; simpl. + auto. + } + + assert (existT + (fun hh0 : D1hom (h_first a) (h_first d) => + sigma hh1 : D1hom (h_second a) (h_second d), + H1Target hh0 = H1Source hh1) + (x0 \; x1 \; x2) + (existT + (fun hh1 : D1hom (h_second a) (h_second d) => + H1Target (x0 \; x1 \; x2) = H1Source hh1) + (y0 \; y1 \; y2) + KR) + = + existT + (fun hh0 : D1hom (h_first a) (h_first d) => + sigma hh1 : D1hom (h_second a) (h_second d), + H1Target hh0 = H1Source hh1) + ((x0 \; x1) \; x2) + (existT + (fun hh1 : D1hom (h_second a) (h_second d) => + H1Target ((x0 \; x1) \; x2) = H1Source hh1) + ((y0 \; y1) \; y2) + KL)) as KA. + { revert KL. + revert KR. + subst x0_12 x01_2 x12 x01. + subst y0_12 y01_2 y12 y01. + rewrite <- X0. + rewrite <- Y0. + intros KR KL. + + assert (KR = KL) as I1. + { eapply Prop_irrelevance. } + rewrite I1. + reflexivity. + } + + rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] + (Prop_irrelevance _ KR). + + rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] + (Prop_irrelevance _ KL). + eapply KA. +Qed. + +Program Definition DPCatP (T: STUFunctor.type) : + PreCat_IsCat (DPobj T). +econstructor. +eapply DP_LeftUnit_lemma; eauto. +eapply DP_RightUnit_lemma; eauto. +eapply DP_Assoc_lemma; eauto. +Qed. + +(* DPobj is a category *) +HB.instance Definition DPCat (T: STUFunctor.type) := DPCatP T. + + +(** Horizontal composition functor and strict double categories *) + +(* composition prefunctor *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsCPreFunctor T of STUFunctor T := + { is_cprefunctor : IsPreFunctor (DPobj T) (D1obj T) (@H1Comp T) }. +HB.structure Definition CPreFunctor : Set := {C of IsCPreFunctor C}. +Set Universe Checking. + +(* composition functor - gives the definition of Strict Double Category *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record CPreFunctor_IsFunctor T of CPreFunctor T := { + is_cfunctor : PreFunctor_IsFunctor (DPobj T) (D1obj T) (@H1Comp T) }. +#[short(type="sdoublecat")] +HB.structure Definition SDoubleCat : Set := {C of CPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* horizontal 2-cell composition: maps two adjecent pairs of + horizontal morphisms (a and b) and a pullback-category morphism + between them (m, which basically gives two adjecent cells) to a + 2-cell morphism between the horizontal composition (HComp) of each + pair *) +Definition HC2Comp (T: SDoubleCat.type) (a b: DPobj T) + (m: @hom (DPobj T) a b) : + d1hom (H1Comp a) (H1Comp b) := @Fhom _ _ (@H1Comp T) a b m. + +Program Definition HC2Comp_flat (T: SDoubleCat.type) (a0 a1 a2 b0 b1 b2: T) + (h0: hhom a0 a1) (h1: hhom a1 a2) + (k0: hhom b0 b1) (k1: hhom b1 b2) + (hh0: D1hom h0 k0) + (hh1: D1hom h1 k1) + (k: H1Target hh0 = H1Source hh1) + : (* D1hom (hcomp _ _ _ h0 h1) (hcomp _ _ _ k0 k1) *) + d1hom (l_hcomp h0 h1) (l_hcomp k0 k1) := + @Fhom _ _ (@H1Comp T) (GC h0 h1) (GC k0 k1) _. +Obligation 1. +refine (@existT (D1hom h0 k0) _ hh0 (@existT (D1hom h1 k1) _ hh1 k)). +Defined. From 41ad7c1f56967104edbd89a4b5f43594df2bb5a4 Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Fri, 12 Jan 2024 20:10:28 +0100 Subject: [PATCH 123/147] updated comment in encatI.v --- theories/encat.v | 13 +++++++++++++ theories/encatI.v | 24 +++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/theories/encat.v b/theories/encat.v index 07e679c8b..5bc2060cc 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1520,7 +1520,20 @@ HB.mixin Record IsDCat_UA T of CFunctor T := { let hh2 := hcomp a0 a2 a3 h12 h3 in @hom (HHomSet T) (@HO T (@hhom T) a0 a3 hh1) x = @hom (HHomSet T) (@HO T (@hhom T) a0 a3 hh2) x + }. +(* +HB.mixin Record IsDCat_UA' T of CFunctor T := { + associator : forall (a0 a1 a2 a3: T) + (h1: @hhom T a0 a1) (h2: @hhom T a1 a2) + (h3: @hhom T a2 a3), + let h23 := hcomp a1 a2 a3 h2 h3 in + let h12 := hcomp a0 a1 a2 h1 h2 in + let hh1 := hcomp a0 a1 a3 h1 h23 in + let hh2 := hcomp a0 a2 a3 h12 h3 in + @hom (HHomSet T) (@HO T (@hhom T) a0 a3 hh2) + (@HO T (@hhom T) a0 a3 hh1) }. +*) Unset Universe Checking. #[short(type="dcat_ua")] HB.structure Definition DCat_UA : Set := { C of IsDCat_UA C }. diff --git a/theories/encatI.v b/theories/encatI.v index 390e1900a..f327b7d11 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -2378,7 +2378,7 @@ HB.structure Definition InternalCat (C : pbcat) := and because iid is a iHom-map) - The horizontal composition of maps is the object part of icomp - The horizontal composition of 2-cells is the map part of icomp -*) + *) (* HB.structure' Definition DoubleCat := @InternalCat cat. *) Axiom cat_pbop : HasPBop cat. HB.instance Definition _ := cat_pbop. @@ -3173,3 +3173,25 @@ Program Definition HC2Comp_flat (T: SDoubleCat.type) (a0 a1 a2 b0 b1 b2: T) Obligation 1. refine (@existT (D1hom h0 k0) _ hh0 (@existT (D1hom h1 k1) _ hh1 k)). Defined. + +(* hcomp (hm, hu) = prj1 (hm, hu) = hm + hcomp (hu, hm) = prj2 (hu, hm) = hm + (hm1 * hm2) * hm3 ~> hm1 * (hm2 * hm3) + + +(* Double category with universal characterization of weak + horizontal associativity *) +HB.mixin Record IsDCat_UA T of CFunctor T := { + associator : forall (a0 a1 a2 a3: T) + (h1: @hhom T a0 a1) (h2: @hhom T a1 a2) + (h3: @hhom T a2 a3), + let h23 := hcomp a1 a2 a3 h2 h3 in + let h12 := hcomp a0 a1 a2 h1 h2 in + let hh1 := hcomp a0 a1 a3 h1 h23 in + let hh2 := hcomp a0 a2 a3 h12 h3 in + @hom (HHomSet T) (@HO T (@hhom T) a0 a3 hh2) + (@HO T (@hhom T) a0 a3 hh1) +}. + + +*) From 40f762bbcc0c258f592b3822f1f87c3655650236 Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Fri, 12 Jan 2024 20:10:55 +0100 Subject: [PATCH 124/147] updated comment in encatI.v --- theories/encatI.v | 2 -- 1 file changed, 2 deletions(-) diff --git a/theories/encatI.v b/theories/encatI.v index f327b7d11..c5ddc5999 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -3178,7 +3178,6 @@ Defined. hcomp (hu, hm) = prj2 (hu, hm) = hm (hm1 * hm2) * hm3 ~> hm1 * (hm2 * hm3) - (* Double category with universal characterization of weak horizontal associativity *) HB.mixin Record IsDCat_UA T of CFunctor T := { @@ -3193,5 +3192,4 @@ HB.mixin Record IsDCat_UA T of CFunctor T := { (@HO T (@hhom T) a0 a3 hh1) }. - *) From c4724d7cf96f57026e18d63e9d4ce3a2ce49f499 Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Tue, 16 Jan 2024 15:37:25 +0100 Subject: [PATCH 125/147] changes in encatI0.v --- theories/encatI0.v | 217 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 212 insertions(+), 5 deletions(-) diff --git a/theories/encatI0.v b/theories/encatI0.v index 5b98e343c..4dddc114c 100644 --- a/theories/encatI0.v +++ b/theories/encatI0.v @@ -1332,19 +1332,222 @@ Definition comm_triangle {Q: precat} {A B C: Q} (h: A ~> C) (f: A ~> B) (g: B ~> C) : Prop := h = f \; g. -Record GMedArrow {Q: precat} {L R T: Q} - (l: L ~> T) (r: R ~> T) - (P: forall (B: Q) (p1: B ~> L) (p2: B ~> R), Type) - {B: Q} (p1: B ~> L) (p2: B ~> R) {B0: Q} +Record GMedArrow {Q: precat} + (* cospan *) + {L R T: Q} (l: L ~> T) (r: R ~> T) + (* span (for the pullback) *) + {B: Q} (p1: B ~> L) (p2: B ~> R) + (* another object *) + {B0: Q} + (* mediating morphism from B0 to B *) (m: B0 ~> B) := { gmedarrow_prop : forall (p01: B0 ~> L) (p02: B0 ~> R), - P B0 p01 p02 -> comm_triangle p01 m p1 /\ comm_triangle p02 m p2 + @comm_square Q L R T l r B0 p01 p02 -> + comm_triangle p01 m p1 /\ comm_triangle p02 m p2 }. (************************************************************************) (* PULLBACKS *) +(* Span pinned to an object *) +HB.mixin Record IsPSpan {Q: precat} + {L R T: Q} (l: L ~> T) (r: R ~> T) (B: Q) : Type := { + lprj : B ~> L ; + rprj : B ~> R + }. +#[short(type="pspan"), verbose] +HB.structure Definition PSpan {Q: precat} + {L R T : Q} (l: L ~> T) (r: R ~> T) := + { B of IsPSpan Q L R T l r B }. + +Definition medarrow_prop {Q: precat} {L R T: Q} + (l: L ~> T) (r: R ~> T) + (B: @pspan Q L R T l r) + {B0: Q} (m: B0 ~> PSpan.sort B) : Prop := + @GMedArrow Q L R T l r B lprj rprj B0 m. + +Definition has_medarrow {Q: precat} {L R T: Q} + (l: L ~> T) (r: R ~> T) + (B: @pspan Q L R T l r) + (B0: Q) : Type := sigma m, @medarrow_prop Q L R T l r B B0 m. + +Definition medarrow_is_unique {Q: precat} {L R T: Q} + (l: L ~> T) (r: R ~> T) + (B: @pspan Q L R T l r) {B0: Q} : Prop := + forall (m m': B0 ~> PSpan.sort B), + @medarrow_prop Q L R T l r B B0 m -> + @medarrow_prop Q L R T l r B B0 m' -> m = m'. + +HB.mixin Record IsPrePBack (Q: precat) (L R T: Q) (l: L ~> T) (r: R ~> T) + (B: Q) of IsPSpan Q L R T l r B : Type := { + comm_sq : comm_square l r (@lprj Q L R T l r B) rprj ; + }. +#[short(type="prepback"), verbose] +HB.structure Definition PrePBack (Q: precat) + (L R T : Q) (l: L ~> T) (r: R ~> T) := + { B of IsPrePBack Q L R T l r B & }. + +HB.status. +(* BUG: IsPrePBack -> IsPSpan missing down here? It is there before *) +#[verbose] +HB.mixin Record IsPBack (Q: precat) (L R T: Q) (l: L ~> T) (r: R ~> T) + (B: Q) of (*IsPrePBack Q L R T l r B*) PrePBack Q l r B : Type := { + has_umarrow : forall B0: Q, @has_medarrow Q L R T l r B B0 + * @medarrow_is_unique Q L R T l r B B0 + }. +#[short(type="pback"), verbose] +HB.structure Definition PBack (Q: precat) + {L R T : Q} (l: L ~> T) (r: R ~> T) := + { B of IsPBack Q L R T l r B }. + +(* +(* packs all the definition together *) +HB.mixin Record IsPBack2 (Q: precat) (L R T: Q) (l: L ~> T) (r: R ~> T) + (B: @pspan Q L R T l r) : Type := { + comm_sq : comm_square l r (@lprj Q L R T l r B) rprj ; + has_umarrow : forall B0: Q, @has_medarrow Q L R T l r B B0 + * @medarrow_is_unique Q L R T l r B B0 + }. +#[short(type="pback2"), verbose] +HB.structure Definition PBack2 (Q: precat) + {L R T : Q} (l: L ~> T) (r: R ~> T) := + { B of IsPBack2 Q L R T l r B }. +*) + +(***********************************************************************) + +(*** CATEGORIES WITH PULLBACKS *) + +(* category with all pullbacks *) +HB.mixin Record HasPBKop C of Cat C := { + pbkop : forall {L R T: C} (l: L ~> T) (r: R ~> T), C + }. +#[short(type="pbkop")] +HB.structure Definition PBKop := + {C of HasPBKop C & PreCat C }. + +#[wrapper] +HB.mixin Record HasPreSpanCat C of PBKop C : Type := { + has_prespan : forall {L R T: C} (l: L ~> T) (r: R ~> T), + @IsPSpan C L R T l r (@pbkop C L R T l r) + }. +#[short(type="prespancat")] +HB.structure Definition PreSpanCat := + {C of HasPreSpanCat C}. + +#[wrapper] +HB.mixin Record HasPrePBKcat C of PreSpanCat C : Type := { + has_prepbk : forall {L R T: C} (l: L ~> T) (r: R ~> T), + @IsPrePBack C L R T l r (@pbkop C L R T l r) + }. +#[short(type="prepbkcat")] +HB.structure Definition PrePBKcat := + {C of HasPrePBKcat C}. + +(* category with all pullbacks *) +#[wrapper] +HB.mixin Record HasPBKcat C of PrePBKcat C := { + has_pbk : forall {L R T: C} (l: L ~> T) (r: R ~> T), + @IsPBack C L R T l r (@pbkop C L R T l r) + }. +#[short(type="pbkcat")] +HB.structure Definition PBKcat := + {C of HasPBKcat C & PreCat C }. + +(* +(* on the other hand, this works... *) +#[wrapper] +HB.mixin Record HasPBK2cat C of PBKop C := { + is_gpbk2 : forall {L R T: C} (l: L ~> T) (r: R ~> T), + @IsPBack2 C L R T l r (@pbkop C L R T l r) + }. +#[short(type="pbk2cat")] +HB.structure Definition PBK2cat := + {C of HasPBK2cat C & PreCat C }. +*) + +(***********************************************************************) + +HB.mixin Record isInternalHom {C: quiver} (C0 : C) (C1 : obj C) := { + src : C1 ~> C0; tgt : C1 ~> C0 +}. +#[short(type="iHom")] +HB.structure Definition InternalHom {C: quiver} (C0 : C) := + { C1 of isInternalHom C C0 C1 }. + +Notation "X ':>' C" := (X : obj C) (at level 60, C at next level). + +Definition iprod {C: pbkcat} {C0 : C} (X Y : iHom C0) : C := +(* pspan (@tgt C C0 (X :> C)) (@src C C0 (Y :> C)) := *) + @pbkop C (X :> C) (Y :> C) C0 (tgt : (X :> C) ~> C0) (src : (Y :> C) ~> C0). + +(* could be problematic... *) +Program Definition iprod_pspan {C: pbkcat} {C0 : obj C} (X Y : iHom C0) : + pspan (@tgt C C0 (X :> C)) (@src C C0 (Y :> C)). +set (x := @iprod C C0 X Y). +destruct C. +destruct class as [A0 A1 A2 A3 A4 A5 A6]. +destruct A4 as [IM]. +econstructor. +econstructor. +eapply IM. +Defined. + +Program Definition iprod_pbk {C: pbkcat} {C0 : obj C} (X Y : iHom C0) : + pback (@tgt C C0 (X :> C)) (@src C C0 (Y :> C)). +set (x := @iprod C C0 X Y). +destruct C. +destruct class as [A0 A1 A2 A3 A4 A5 A6]. +destruct A6 as [IM]. +econstructor. +econstructor. +eapply IM. +Defined. + +Notation "X *_ C0 Y" := (@iprod _ C0 (X : iHom C0) (Y : iHom C0)) + (at level 99, C0 at level 0, only parsing) : encat_scope. +Notation "X *_ C0 Y" := (@iprod _ C0 X Y) + (at level 99, C0 at level 0) : cat_scope. + +(*** PROBLEMATIC *) +(* left and right projection morphisms of the product *) +Program Definition iprodl {C: pbkcat} {C0 : C} (X Y : iHom C0) : + X *_C0 Y ~> (X :> C). +remember C as C'. +destruct C'. +destruct class as [A0 A1 A2 A3 A4 A5 A6]. +destruct A4 as [IM]. +destruct X as [J1 J2]. +destruct Y as [I1 I2]. +simpl in *. +simpl. +unfold iprod. +simpl. +(* specialize (IM J1 I1 C0). *) +Admitted. +Fail Definition iprodr {C: pbcat} {C0 : C} (X Y : iHom C0) : + X *_C0 Y ~> (Y :> C) := bot2right (iprod_pb X Y). + +Definition iprod_iHom {C: pbkcat} {C0: C} (X Y: @iHom C C0) : + @isInternalHom C C0 (X *_C0 Y) := + @isInternalHom.Build C C0 (X *_C0 Y) + ((iprodl X Y) \; src) + ((iprodr X Y) \; tgt). + +HB.instance Definition iprod_iHom' {C: pbcat} {C0: C} (X Y: @iHom C C0) : + @isInternalHom C C0 (X *_C0 Y) := iprod_iHom X Y. + +(* the product as (iHom C0) object *) +Definition pbC0 (C : pbcat) (C0 : C) (X Y : iHom C0) : iHom C0 := + (X *_C0 Y) : iHom C0. + + + +(*** OLDER VERSION, not good *************************************) + +(* PULLBACKS *) + (* Span pinned to an object *) HB.mixin Record IsPSpan {Q: precat} {L R T: Q} (l: L ~> T) (r: R ~> T) (B: Q) : Type := { @@ -1475,6 +1678,10 @@ Notation "X *_ C0 Y" := (@iprod _ C0 (X : iHom C0) (Y : iHom C0)) Notation "X *_ C0 Y" := (@iprod _ C0 X Y) (at level 99, C0 at level 0) : cat_scope. + +(*** END OF IT *) + + (* HB.mixin Record IsPBkObj {Q: precat} {L R T: Q} (l: L ~> T) (r: R ~> T) (B: Q) : Type := { From 65701672e41f4761a63a63ff87e12478eca6100c Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Tue, 16 Jan 2024 16:12:39 +0100 Subject: [PATCH 126/147] encatI.v and encatI0.v now depend on cat.v --- theories/cat.v | 4 + theories/encatI.v | 1278 +------------------------------------------- theories/encatI0.v | 1273 +------------------------------------------ 3 files changed, 14 insertions(+), 2541 deletions(-) diff --git a/theories/cat.v b/theories/cat.v index 3e4ef8edb..3f1235a26 100644 --- a/theories/cat.v +++ b/theories/cat.v @@ -1190,6 +1190,7 @@ Qed. End natural2prepullback. End Pullback_Natural. + Notation square u v f g := (isPrePullback _ _ _ (Cospan f g) (Span u v)). Notation pbsquare u v f g := @@ -1198,6 +1199,9 @@ Notation pb s := (prepullback_isTerminal _ _ _ _ s). Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). + +(**********************************************************************) + Section th_of_pb. Variables (Q : cat) (A B C D E F : Q). Variables (f : A ~> D) (g : B ~> D) (h : C ~> A). diff --git a/theories/encatI.v b/theories/encatI.v index c5ddc5999..08b4fbea2 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -1,5 +1,7 @@ Require Import ssreflect ssrfun. -From HB Require Import structures. +Unset Universe Checking. +From HB Require Import structures cat. +Set Universe Checking. Require Import Coq.Program.Equality. Set Implicit Arguments. @@ -7,1286 +9,16 @@ Unset Strict Implicit. Unset Printing Implicit Defensive. Add Search Blacklist "__canonical__". -Declare Scope algebra_scope. -Delimit Scope algebra_scope with A. Local Open Scope algebra_scope. -Declare Scope cat_scope. -Delimit Scope cat_scope with cat. Local Open Scope cat_scope. -(* we assume a few axioms to make life easier *) -Axiom funext : forall {T : Type} {U : T -> Type} [f g : forall t, U t], - (forall t, f t = g t) -> f = g. -Axiom propext : forall P Q : Prop, P <-> Q -> P = Q. -Axiom Prop_irrelevance : forall (P : Prop) (x y : P), x = y. - -(* Shortcut *) -Notation U := Type. - -(* Base definition : raw categories = quivers *) -HB.mixin Record IsQuiver C := { hom : C -> C -> U }. -Unset Universe Checking. -#[short(type="quiver")] -HB.structure Definition Quiver : Set := { C of IsQuiver C }. -Set Universe Checking. - -Bind Scope cat_scope with quiver. -Bind Scope cat_scope with hom. -Arguments hom {C} : rename. -Notation homs T := (@hom T _ _). -Notation "a ~> b" := (hom a b) - (at level 99, b at level 200, format "a ~> b") : cat_scope. -Notation "a ~>_ C b" := (@hom C a b) - (at level 99, C at level 0, only parsing) : cat_scope. - -(* precategories are quivers + id and comp *) -HB.mixin Record Quiver_IsPreCat C of Quiver C := { - idmap : forall (a : C), a ~> a; - comp : forall (a b c : C), (a ~> b) -> (b ~> c) -> (a ~> c); -}. - -HB.factory Record IsPreCat C := { - hom : C -> C -> U; - idmap : forall (a : C), hom a a; - comp : forall (a b c : C), hom a b -> hom b c -> hom a c; -}. -HB.builders Context C of IsPreCat C. - HB.instance Definition _ := IsQuiver.Build C hom. - HB.instance Definition _ := Quiver_IsPreCat.Build C idmap comp. -HB.end. - -Unset Universe Checking. -#[short(type="precat")] -HB.structure Definition PreCat : Set := { C of IsPreCat C }. -Set Universe Checking. - -Bind Scope cat_scope with precat. -Arguments idmap {C} {a} : rename. -Arguments comp {C} {a b c} : rename. -Notation "f \o g" := (comp g f) : cat_scope. -Notation "f \; g :> T" := (@comp T _ _ _ f g) - (at level 60, g, T at level 60, format "f \; g :> T", only parsing) : cat_scope. -Notation "f \; g" := (comp f g) : cat_scope. -Notation "\idmap_ a" := (@idmap _ a) (only parsing, at level 0) : cat_scope. - -(* categories are precategories + laws *) -HB.mixin Record PreCat_IsCat C of PreCat C := { - comp1o : forall (a b : C) (f : a ~> b), idmap \; f = f; - compo1 : forall (a b : C) (f : a ~> b), f \; idmap = f; - compoA : forall (a b c d : C) (f : a ~> b) (g : b ~> c) (h : c ~> d), - f \; (g \; h) = (f \; g) \; h -}. -Unset Universe Checking. -#[short(type="cat")] -HB.structure Definition Cat : Set := { C of PreCat_IsCat C & IsPreCat C }. -Set Universe Checking. - -Bind Scope cat_scope with cat. -Arguments compo1 {C a b} : rename. -Arguments comp1o {C a b} : rename. -Arguments compoA {C a b c d} : rename. - -(* the discrete category on a type cannot be the default, we make an alias *) -Definition discrete (T : U) := T. -HB.instance Definition _ T := @IsPreCat.Build (discrete T) (fun x y => x = y) - (fun=> erefl) (@etrans _). -Lemma etransA T (a b c d : discrete T) (f : a ~> b) (g : b ~> c) (h : c ~> d) : - f \; (g \; h) = (f \; g) \; h. -Proof. by rewrite /idmap/comp/=; case: _ / h; case: _ / g. Qed. -HB.instance Definition _ T := PreCat_IsCat.Build (discrete T) (@etrans_id _) - (fun _ _ _ => erefl) (@etransA _). - -(* the category of the unit type is the discrete one *) -HB.instance Definition _ := Cat.copy unit (discrete unit). - -HB.instance Definition _ := @IsPreCat.Build U (fun A B => A -> B) - (fun a => idfun) (fun a b c (f : a -> b) (g : b -> c) => (g \o f)%FUN). -HB.instance Definition _ := PreCat_IsCat.Build U (fun _ _ _ => erefl) - (fun _ _ _ => erefl) (fun _ _ _ _ _ _ _ => erefl). - - -Lemma Ucomp (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) : f \; g = (g \o f)%FUN. -Proof. by []. Qed. -Lemma Ucompx (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) x : (f \; g) x = g (f x). -Proof. by []. Qed. -Lemma U1 (X : U) : \idmap_X = idfun. -Proof. by []. Qed. -Lemma U1x (X : U) x : \idmap_X x = x. -Proof. by []. Qed. - -(* a prefunctor is a functor without laws *) -HB.mixin Record IsPreFunctor (C D : quiver) (F : C -> D) := { - Fhom : forall (a b : C), (a ~> b) -> (F a ~> F b) -}. - -Unset Universe Checking. -HB.structure Definition PreFunctor (C D : quiver) : Set := - { F of IsPreFunctor C D F }. -Set Universe Checking. -HB.instance Definition _ := IsQuiver.Build quiver PreFunctor.type. - -Notation "F ^$" := (@Fhom _ _ F _ _) - (at level 1, format "F ^$") : cat_scope. -Notation "F <$> f" := (@Fhom _ _ F _ _ f) - (at level 58, format "F <$> f", right associativity) : cat_scope. - -(* prefunctors are equal if their object and hom part are respectively equal *) -Lemma prefunctorP (C D : quiver) (F G : C ~> D) (eqFG : F =1 G) : - let homF a b F := F a ~> F b in - (forall a b f, eq_rect _ (homF a b) (F <$> f) _ (funext eqFG) = G <$> f) -> - F = G. -Proof. -move: F G => [F [[/= Fhom]]] [G [[/= Ghom]]] in eqFG *. -case: _ / (funext eqFG) => /= in Ghom * => eqFGhom. -congr PreFunctor.Pack; congr PreFunctor.Class; congr IsPreFunctor.Axioms_. -by do 3!apply: funext=> ?. -Qed. - -(* a functor is a prefunctor + laws for id and comp *) -HB.mixin Record PreFunctor_IsFunctor (C D : precat) (F : C -> D) - of @PreFunctor C D F := { - F1 : forall (a : C), F <$> \idmap_a = idmap; - Fcomp : forall (a b c : C) (f : a ~> b) (g : b ~> c), - F <$> (f \; g) = F <$> f \; F <$> g; -}. -Unset Universe Checking. - -(* precat and cat have a quiver structure *) -HB.structure Definition Functor (C D : precat) : Set := - { F of IsPreFunctor C D F & PreFunctor_IsFunctor C D F }. -Set Universe Checking. -HB.instance Definition _ := IsQuiver.Build precat Functor.type. -HB.instance Definition _ := IsQuiver.Build cat Functor.type. - -(* functor equality is the same as prefunctor because of PI *) -Lemma functorP (C D : precat) (F G : C ~> D) (eqFG : F =1 G) : - let homF a b F := F a ~> F b in - (forall a b f, eq_rect _ (homF a b) (F^$ f) _ (funext eqFG) = G^$ f) -> - F = G. -Proof. -move=> /= /prefunctorP {eqFG}. -case: F G => [F [/= Fm Fm']] [G [/= Gm Gm']]//=. -move=> [_] /EqdepFacts.eq_sigT_iff_eq_dep eqFG. -case: _ / eqFG in Gm' *. -congr Functor.Pack; congr Functor.Class. -case: Fm' Gm' => [F1 Fc] [G1 Gc]. -by congr PreFunctor_IsFunctor.Axioms_; apply: Prop_irrelevance. -Qed. - -(* the identity function is a functor *) -HB.instance Definition _ (C : quiver) := - IsPreFunctor.Build C C idfun (fun a b => idfun). -HB.instance Definition _ (C : precat) := - PreFunctor_IsFunctor.Build C C idfun (fun=> erefl) (fun _ _ _ _ _ => erefl). - -(* the composition of prefunctors *) -Section comp_prefunctor. -Context {C D E : quiver} {F : C ~> D} {G : D ~> E}. - -HB.instance Definition _ := IsPreFunctor.Build C E (G \o F)%FUN - (fun a b f => G <$> F <$> f). -Lemma comp_Fun (a b : C) (f : a ~> b) : (G \o F)%FUN <$> f = G <$> (F <$> f). -Proof. by []. Qed. -End comp_prefunctor. - -Section comp_functor. -Context {C D E : precat} {F : C ~> D} {G : D ~> E}. -Lemma comp_F1 (a : C) : (G \o F)%FUN <$> \idmap_a = idmap. -Proof. by rewrite !comp_Fun !F1. Qed. -Lemma comp_Fcomp (a b c : C) (f : a ~> b) (g : b ~> c) : - (G \o F)%FUN <$> (f \; g) = (G \o F)%FUN <$> f \; (G \o F)%FUN <$> g. -Proof. by rewrite !comp_Fun !Fcomp. Qed. -HB.instance Definition _ := PreFunctor_IsFunctor.Build C E (G \o F)%FUN - comp_F1 comp_Fcomp. -End comp_functor. - -(* precat and cat have a precategory structure *) -HB.instance Definition _ := Quiver_IsPreCat.Build precat - (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). -HB.instance Definition _ := Quiver_IsPreCat.Build cat - (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). - -Lemma funext_frefl A B (f : A -> B) : funext (frefl f) = erefl. -Proof. exact: Prop_irrelevance. Qed. - -(* precategories and categories form a category *) -Definition precat_cat : PreCat_IsCat precat. -Proof. -by split=> [C D F|C D F|C D C' D' F G H]; - apply/functorP => a b f /=; rewrite funext_frefl. -Qed. -HB.instance Definition _ := precat_cat. -Definition cat_cat : PreCat_IsCat cat. -Proof. -by split=> [C D F|C D F|C D C' D' F G H]; - apply/functorP => a b f /=; rewrite funext_frefl. -Qed. -HB.instance Definition _ := cat_cat. - -Check (cat : cat). - -(* concrete categories *) -HB.mixin Record Quiver_IsPreConcrete T of Quiver T := { - concrete : T -> U; - concrete_fun : forall (a b : T), (a ~> b) -> concrete a -> concrete b; -}. -Unset Universe Checking. -#[short(type="preconcrete_quiver")] -HB.structure Definition PreConcreteQuiver : Set := - { C of Quiver_IsPreConcrete C & IsQuiver C }. -Set Universe Checking. -Coercion concrete : PreConcreteQuiver.sort >-> Sortclass. - -HB.mixin Record PreConcrete_IsConcrete T of PreConcreteQuiver T := { - concrete_fun_inj : forall (a b : T), injective (concrete_fun a b) -}. -Unset Universe Checking. -#[short(type="concrete_quiver")] -HB.structure Definition ConcreteQuiver : Set := - { C of PreConcreteQuiver C & PreConcrete_IsConcrete C }. -Set Universe Checking. - -HB.instance Definition _ (C : ConcreteQuiver.type) := - IsPreFunctor.Build _ _ (concrete : C -> U) concrete_fun. - -HB.mixin Record PreCat_IsConcrete T of ConcreteQuiver T & PreCat T := { - concrete1 : forall (a : T), concrete <$> \idmap_a = idfun; - concrete_comp : forall (a b c : T) (f : a ~> b) (g : b ~> c), - concrete <$> (f \; g) = ((concrete <$> g) \o (concrete <$> f))%FUN; -}. -Unset Universe Checking. -#[short(type="concrete_precat")] -HB.structure Definition ConcretePreCat : Set := - { C of PreCat C & ConcreteQuiver C & PreCat_IsConcrete C }. -#[short(type="concrete_cat")] -HB.structure Definition ConcreteCat : Set := - { C of Cat C & ConcreteQuiver C & PreCat_IsConcrete C }. -Set Universe Checking. - -HB.instance Definition _ (C : concrete_precat) := - PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). -HB.instance Definition _ (C : ConcreteCat.type) := - PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). - -HB.instance Definition _ := Quiver_IsPreConcrete.Build U (fun _ _ => id). -HB.instance Definition _ := PreConcrete_IsConcrete.Build U (fun _ _ _ _ => id). -HB.instance Definition _ := PreCat_IsConcrete.Build U - (fun=> erefl) (fun _ _ _ _ _ => erefl). - -Unset Universe Checking. -HB.instance Definition _ := Quiver_IsPreConcrete.Build quiver (fun _ _ => id). -HB.instance Definition _ := Quiver_IsPreConcrete.Build precat (fun _ _ => id). -HB.instance Definition _ := Quiver_IsPreConcrete.Build cat (fun _ _ => id). -Lemma quiver_concrete_subproof : PreConcrete_IsConcrete quiver. -Proof. -constructor=> C D F G FG; apply: prefunctorP. - by move=> x; congr (_ x); apply: FG. -by move=> *; apply: Prop_irrelevance. -Qed. -HB.instance Definition _ := quiver_concrete_subproof. - -Lemma precat_concrete_subproof : PreConcrete_IsConcrete precat. -Proof. -constructor=> C D F G FG; apply: functorP. - by move=> x; congr (_ x); apply: FG. -by move=> *; apply: Prop_irrelevance. -Qed. -HB.instance Definition _ := precat_concrete_subproof. - -Lemma cat_concrete_subproof : PreConcrete_IsConcrete cat. -Proof. -constructor=> C D F G FG; apply: functorP. - by move=> x; congr (_ x); apply: FG. -by move=> *; apply: Prop_irrelevance. -Qed. -HB.instance Definition _ := cat_concrete_subproof. -HB.instance Definition _ := PreCat_IsConcrete.Build precat - (fun=> erefl) (fun _ _ _ _ _ => erefl). -HB.instance Definition _ := PreCat_IsConcrete.Build cat - (fun=> erefl) (fun _ _ _ _ _ => erefl). -Set Universe Checking. - -(* constant functor *) -Definition cst (C D : quiver) (c : C) := fun of D => c. -Arguments cst {C} D c. -HB.instance Definition _ {C D : precat} (c : C) := - IsPreFunctor.Build D C (cst D c) (fun _ _ _ => idmap). -HB.instance Definition _ {C D : cat} (c : C) := - PreFunctor_IsFunctor.Build D C (cst D c) (fun=> erefl) - (fun _ _ _ _ _ => esym (compo1 idmap)). - -(* opposite category *) -Definition catop (C : U) : U := C. -Notation "C ^op" := (catop C) - (at level 2, format "C ^op") : cat_scope. -HB.instance Definition _ (C : quiver) := - IsQuiver.Build C^op (fun a b => hom b a). -HB.instance Definition _ (C : precat) := - Quiver_IsPreCat.Build (C^op) (fun=> idmap) (fun _ _ _ f g => g \; f). -HB.instance Definition _ (C : cat) := PreCat_IsCat.Build (C^op) - (fun _ _ _ => compo1 _) (fun _ _ _ => comp1o _) - (fun _ _ _ _ _ _ _ => esym (compoA _ _ _)). - -HB.instance Definition _ {C : precat} {c : C} := - IsPreFunctor.Build C _ (hom c) (fun a b f g => g \; f). -Lemma hom_Fhom_subproof (C : cat) (x : C) : - PreFunctor_IsFunctor _ _ (hom x). -Proof. by split=> *; apply/funext => h; [apply: compo1 | apply: compoA]. Qed. -HB.instance Definition _ {C : cat} {c : C} := hom_Fhom_subproof c. - -Check fun (C : cat) (x : C) => hom x : C ~>_cat U. - -Lemma hom_op {C : quiver} (c : C^op) : hom c = (@hom C)^~ c. -Proof. reflexivity. Qed. - -Lemma homFhomx {C : precat} (a b c : C) (f : a ~> b) (g : c ~> a) : - (hom c <$> f) g = g \; f. -Proof. reflexivity. Qed. - -(* nary product of categories *) -Definition dprod {I : U} (C : I -> U) := forall i, C i. - -Section hom_dprod. -Context {I : U} (C : I -> quiver). -Definition dprod_hom_subdef (a b : dprod C) := forall i, a i ~> b i. -HB.instance Definition _ := IsQuiver.Build (dprod C) dprod_hom_subdef. -End hom_dprod. -Arguments dprod_hom_subdef /. - -Section precat_dprod. -Context {I : U} (C : I -> precat). -Definition dprod_idmap_subdef (a : dprod C) : a ~> a := fun=> idmap. -Definition dprod_comp_subdef (a b c : dprod C) (f : a ~> b) (g : b ~> c) : a ~> c := - fun i => f i \; g i. -HB.instance Definition _ := IsPreCat.Build (dprod C) - dprod_idmap_subdef dprod_comp_subdef. -End precat_dprod. -Arguments dprod_idmap_subdef /. -Arguments dprod_comp_subdef /. - -Section cat_dprod. -Context {I : U} (C : I -> cat). -Local Notation type := (dprod C). -Lemma dprod_is_cat : PreCat_IsCat type. -Proof. -split=> [a b f|a b f|a b c d f g h]; apply/funext => i; -[exact: comp1o | exact: compo1 | exact: compoA]. -Qed. -HB.instance Definition _ := dprod_is_cat. -End cat_dprod. - -(* binary product *) -Section hom_prod. -Context {C D : quiver}. -Definition prod_hom_subdef (a b : C * D) := ((a.1 ~> b.1) * (a.2 ~> b.2))%type. -HB.instance Definition _ := IsQuiver.Build (C * D)%type prod_hom_subdef. -End hom_prod. - -Section precat_prod. -Context {C D : precat}. -HB.instance Definition _ := IsPreCat.Build (C * D)%type (fun=> (idmap, idmap)) - (fun a b c (f : a ~> b) (g : b ~> c) => (f.1 \; g.1, f.2 \; g.2)). -End precat_prod. - -Section cat_prod. -Context {C D : cat}. -Local Notation type := (C * D)%type. -Lemma prod_is_cat : PreCat_IsCat type. -Proof. -split=> [[a1 a2] [b1 b2] [f1 f2]|[a1 a2] [b1 b2] [f1 f2]| - [a1 a2] [b1 b2] [c1 c2] [d1 d2] [f1 f2] [g1 g2] [h1 h2]]; congr (_, _) => //=; -by [exact: comp1o | exact: compo1 | exact: compoA]. -Qed. -HB.instance Definition _ := prod_is_cat. -End cat_prod. - -HB.instance Definition _ (C : U) (D : quiver) := - IsQuiver.Build (C -> D) (fun f g => forall c, f c ~> g c). - -(* naturality *) -HB.mixin Record IsNatural (C : quiver) (D : precat) (F G : C ~>_quiver D) - (n : forall c, F c ~> G c) := { - natural : forall (a b : C) (f : a ~> b), - F <$> f \; n b = n a \; G <$> f -}. -Unset Universe Checking. -HB.structure Definition Natural (C : quiver) (D : precat) - (F G : C ~>_quiver D) : Set := - { n of @IsNatural C D F G n }. -Set Universe Checking. -HB.instance Definition _ (C : quiver) (D : precat) := - IsQuiver.Build (PreFunctor.type C D) (@Natural.type C D). -HB.instance Definition _ (C D : precat) := - IsQuiver.Build (Functor.type C D) (@Natural.type C D). -Arguments natural {C D F G} n [a b] f : rename. - -Check fun (C D : cat) (F G : C ~> D) => F ~>_(C ~>_cat D) G. - -Lemma naturalx (C : precat) (D : concrete_precat) - (F G : C ~>_quiver D) (n : F ~> G) (a b : C) (f : a ~> b) g : - (concrete <$> n b) ((concrete <$> F <$> f) g) = - (concrete <$> G <$> f) ((concrete <$> n a) g). -Proof. -have /(congr1 (fun h => (concrete <$> h) g)) := natural n f. -by rewrite !Fcomp. -Qed. -Arguments naturalx {C D F G} n [a b] f. - -Lemma naturalU (C : precat) (F G : C ~>_quiver U) (n : F ~> G) - (a b : C) (f : a ~> b) g : n b (F^$ f g) = G^$ f (n a g). -Proof. exact: (naturalx n). Qed. - -Lemma natP (C D : precat) (F G : C ~>_quiver D) (n m : F ~> G) : - Natural.sort n = Natural.sort m -> n = m. -Proof. -case: n m => [/= n nP] [/= m mP] enm. -elim: _ / enm in mP *; congr Natural.Pack. -case: nP mP => [[?]] [[?]]; congr Natural.Class. -congr IsNatural.Axioms_. -exact: Prop_irrelevance. -Qed. - -Notation "F ~~> G" := (F ~>_(homs quiver) G) - (at level 99, G at level 200, format "F ~~> G"). -Notation "F ~~> G :> C ~> D" := (F ~> G :> (C ~>_quiver D)) - (at level 99, G at level 200, C, D at level 0, - format "F ~~> G :> C ~> D"). - -Definition natural_id {C D : precat} (F : C ~>_quiver D) (a : C) := \idmap_(F a). -Definition natural_id_natural (C D : cat) (F : C ~>_quiver D) : - IsNatural C D F F (natural_id F). -Proof. by constructor=> a b f; rewrite /natural_id/= compo1 comp1o. Qed. -HB.instance Definition _ C D F := @natural_id_natural C D F. - -Check fun {C D : cat} (F : C ~>_quiver D) => natural_id F : F ~> F. - -Definition natural_comp {C D : precat} (F G H : C ~>_quiver D) - (m : F ~> G) (n : G ~> H) (a : C) := m a \; n a. -Definition natural_comp_natural (C D : cat) (F G H : C ~>_quiver D) m n : - IsNatural C D F H (@natural_comp C D F G H m n). -Proof. -constructor=> a b f; rewrite /natural_comp/=. -by rewrite compoA natural -compoA natural compoA. -Qed. -HB.instance Definition _ C D F G H m n := @natural_comp_natural C D F G H m n. - -HB.instance Definition _ {C D : cat} := - Quiver_IsPreCat.Build (PreFunctor.type C D) natural_id natural_comp. -HB.instance Definition _ {C D : cat} := - Quiver_IsPreCat.Build (Functor.type C D) natural_id natural_comp. - -Lemma prefunctor_cat {C D : cat} : PreCat_IsCat (PreFunctor.type C D). -Proof. -constructor => [F G f|F G f|F G H J f g h]. -- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. -- by apply/natP/funext => a; rewrite /= /natural_comp compo1. -- by apply/natP/funext => a; rewrite /= /natural_comp compoA. -Qed. -HB.instance Definition _ C D := @prefunctor_cat C D. - -Lemma functor_cat {C D : cat} : PreCat_IsCat (Functor.type C D). -Proof. -constructor => [F G f|F G f|F G H J f g h]. -- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. -- by apply/natP/funext => a; rewrite /= /natural_comp compo1. -- by apply/natP/funext => a; rewrite /= /natural_comp compoA. -Qed. -HB.instance Definition _ C D := @functor_cat C D. - -Lemma idFmap (C : cat) (a b : C) (f : a ~> b) : idfun <$> f = f. -Proof. by []. Qed. - -Lemma compFmap (C D E : cat) (F : C ~> D) (G : D ~> E) (a b : C) (f : a ~> b) : - (G \o F) <$> f = G <$> F <$> f. -Proof. by []. Qed. - -Section left_whiskering. -Context {C D E : precat} {F G : C ~> D}. - -Definition whiskerl_fun (eta : forall c, F c ~> G c) (H : D ~> E) : - forall c, (F \; H) c ~> (G \; H) c := fun c => H <$> eta c. - -Lemma whiskerl_is_nat (eta : F ~> G) (H : D ~> E) : - IsNatural _ _ _ _ (whiskerl_fun eta H). -Proof. by constructor=> a b f; rewrite /whiskerl_fun/= -!Fcomp natural. Qed. - -HB.instance Definition _ (eta : F ~> G) (H : D ~> E) := whiskerl_is_nat eta H. -Definition whiskerl (eta : F ~> G) (H : D ~> E) : (F \; H) ~> (G \; H) := - whiskerl_fun eta H : Natural.type _ _. -End left_whiskering. - -Notation "F n" := (whiskerl F n) - (at level 58, format "F n", right associativity) : cat_scope. - -Section right_whiskering. -Context {C D E : precat} {F G : D ~> E}. - -Definition whiskerr_fun (H : C ~> D) (eta : forall d, F d ~> G d) - (c : C) : (H \; F) c ~> (H \; G) c := eta (H c). - -Lemma whiskerr_is_nat (H : C ~> D) (eta : F ~> G) : - IsNatural _ _ _ _ (whiskerr_fun H eta). -Proof. by constructor=> a b f; rewrite /whiskerr_fun/= natural. Qed. -HB.instance Definition _ (H : C ~> D) (eta : F ~> G) := whiskerr_is_nat H eta. - -Definition whiskerr (H : C ~> D) (eta : F ~> G) : (H \; F) ~> (H \; G) := - whiskerr_fun H eta : Natural.type _ _. -End right_whiskering. - -Notation "F <$o> n" := (whiskerr F n) - (at level 58, format "F <$o> n", right associativity) : cat_scope. - -Definition whisker {C : cat} {D : precat} {E : cat} - {F G : C ~>_precat D} {H K : D ~> E} - (eta : F ~> G) (mu : H ~> K) : (F \; H) ~> (G \; K) := - (eta H) \; (G <$o> mu). - -Notation "eta mu" := (whisker eta mu) - (at level 58, format "eta mu", right associativity) : cat_scope. - -Lemma whiskern1 {C D E : cat} {F G : C ~>_precat D} (eta : F ~> G) (H : D ~> E) : - eta \idmap_H = eta H. -Proof. by apply/natP/funext=> c /=; apply: compo1. Qed. - -Lemma whisker1n {C D E : cat} {F G : D ~> E} (H : C ~> D) (eta : F ~> G) : - \idmap_H eta = H <$o> eta. -Proof. -apply/natP/funext=> c /=; rewrite /natural_comp/=. -by rewrite [X in X \; _]F1 comp1o. -Qed. - -Definition delta (C D : cat) : C -> (D ~> C) := cst D. -Arguments delta C D : clear implicits. - -Definition map_delta {C D : cat} (a b : C) (f : a ~> b) : - delta C D a ~> delta C D b. -Proof. -apply: (@Natural.Pack _ _ (cst D a) (cst D b) (fun x => f)). -apply: Natural.Class; apply: (IsNatural.Build _ _ _ _ _). -by move=> a' b' ?; rewrite compo1 comp1o. -Defined. - -HB.instance Definition _ {C D : cat} := - IsPreFunctor.Build C (D ~> C) (delta C D) (@map_delta C D). - -Lemma delta_functor {C D : cat} : PreFunctor_IsFunctor _ _ (delta C D). -Proof. by constructor=> [a|a b c f g]; exact/natP. Qed. -HB.instance Definition _ C D := @delta_functor C D. - -HB.mixin Record IsMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { - unit : idfun ~~> M; - join : (M \o M)%FUN ~~> M; - bind : forall (a b : C), (a ~> M b) -> (M a ~> M b); - bindE : forall a b (f : a ~> M b), bind a b f = M <$> f \; join b; - unit_join : forall a, (M <$> unit a) \; join _ = idmap; - join_unit : forall a, join _ \; (M <$> unit a) = idmap; - join_square : forall a, M <$> join a \; join _ = join _ \; join _ -}. - -#[short(type="premonad")] -HB.structure Definition PreMonad (C : precat) := - {M of @PreFunctor C C M & IsMonad C M}. -#[short(type="monad")] -HB.structure Definition Monad (C : precat) := - {M of @Functor C C M & IsMonad C M}. - -HB.factory Record IsJoinMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { - unit : idfun ~~> M; - join : (M \o M)%FUN ~~> M; - unit_join : forall a, (M <$> unit a) \; join _ = idmap; - join_unit : forall a, join _ \; (M <$> unit a) = idmap; - join_square : forall a, M <$> join a \; join _ = join _ \; join _ -}. -HB.builders Context C M of IsJoinMonad C M. - HB.instance Definition _ := IsMonad.Build C M - (fun a b f => erefl) unit_join join_unit join_square. -HB.end. - -HB.mixin Record IsCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { - counit : M ~~> idfun; - cojoin : M ~~> (M \o M)%FUN; - cobind : forall (a b : C), (M a ~> b) -> (M a ~> M b); - cobindE : forall a b (f : M a ~> b), cobind a b f = cojoin _ \; M <$> f; - unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; - join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; - cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ -}. -#[short(type="precomonad")] -HB.structure Definition PreCoMonad (C : precat) := - {M of @PreFunctor C C M & IsCoMonad C M}. -#[short(type="comonad")] -HB.structure Definition CoMonad (C : precat) := - {M of @Functor C C M & IsCoMonad C M}. - -HB.factory Record IsJoinCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { - counit : M ~~> idfun; - cojoin : M ~~> (M \o M)%FUN; - unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; - join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; - cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ -}. -HB.builders Context C M of IsJoinCoMonad C M. - HB.instance Definition _ := IsCoMonad.Build C M - (fun a b f => erefl) unit_cojoin join_counit cojoin_square. -HB.end. - -(* yoneda *) -Section hom_repr. -Context {C : cat} (F : C ~>_cat U). - -Definition homF : C -> U := fun c => hom c ~~> F. - -Section nat. -Context (x y : C) (xy : x ~> y). - -(* Goal hom x ~~> F -> hom y ~~> F *) -Context (n : hom x ~~> F). -Definition homFhom c : hom y c ~> F c := fun g => n _ (xy \; g). - -Lemma homFhom_natural_subdef : IsNatural C U (hom y) F homFhom. -Proof. -by split=> a b f /=; apply/funext => g /=; - rewrite /homFhom !Ucompx/= !naturalU/= Fcomp. -Qed. -HB.instance Definition _ := homFhom_natural_subdef. -End nat. -Arguments homFhom / : clear implicits. - -HB.about IsPreFunctor.Build. -Check homFhom : forall x y : C, (x ~> y) -> (homF x -> homF y). -HB.instance Definition _ := IsPreFunctor.Build _ _ homF homFhom. -Lemma homF_functor_subproof : PreFunctor_IsFunctor _ _ homF. -Proof. -split=> [a|a b c f g]. - apply/funext => -[/= f natf]. - apply: natP => //=; apply: funext => b; apply: funext => g/=. - by rewrite comp1o. -apply/funext => -[/= h natf]. -apply: natP => //=; apply: funext => d; apply: funext => k/=. -by rewrite compoA. -Qed. -HB.instance Definition _ := homF_functor_subproof. - -Section pointed. -Context (c : C). -Definition hom_repr : homF c ~> F c := fun f => f _ idmap. -Arguments hom_repr /. - -Definition repr_hom (fc : F c) a : hom c a ~> F a := - fun f => F^$ f fc. -Arguments repr_hom / : clear implicits. -Lemma repr_hom_subdef (fc : F c) : IsNatural _ _ _ _ (repr_hom fc). -Proof. by split=> a b f /=; apply/funext=> x; rewrite !Ucompx/= Fcomp. Qed. -HB.instance Definition _ {fc : F c} := repr_hom_subdef fc. - -Definition repr_hom_nat : F c ~> homF c := repr_hom. - -Lemma hom_reprK : cancel hom_repr repr_hom_nat. -Proof. -move=> f; apply/natP; apply/funext => a; apply/funext => g /=. -by rewrite -naturalU/=; congr (f _ _); apply: comp1o. -Qed. -Lemma repr_homK : cancel (repr_hom : F c ~> homF c) hom_repr. -Proof. by move=> fc; rewrite /= F1. Qed. -End pointed. -Arguments hom_repr /. -Arguments repr_hom /. - -Lemma hom_repr_natural_subproof : IsNatural _ _ _ _ hom_repr. -Proof. -split=> a b f /=; apply/funext => n /=; rewrite !Ucompx/= compo1/=. -by rewrite -naturalU/=; congr (n _ _); apply/esym/comp1o. -Qed. -HB.instance Definition _ := hom_repr_natural_subproof. - -(* show this from the previous proof *) -Lemma hom_natural_repr_subproof : IsNatural _ _ _ _ repr_hom_nat. -Proof. -split=> a b f /=; apply: funext => fa /=; rewrite !Ucompx/=. -apply: natP; apply: funext => c /=; apply: funext => d /=. -by rewrite Fcomp Ucompx/=. -Qed. -HB.instance Definition _ := hom_natural_repr_subproof. - -Definition hom_repr_nat : homF ~~> F := hom_repr. -Definition repr_hom_nat_nat : F ~~> homF := repr_hom_nat. - -End hom_repr. - -(* comma categories *) -Module comma. -Section homcomma. -Context {C D E : precat} (F : C ~> E) (G : D ~> E). - -Definition type := { x : C * D & F x.1 ~> G x.2 }. -Definition hom_subdef (a b : type) := { - f : tag a ~> tag b & F <$> f.1 \; tagged b = tagged a \; G <$> f.2 - }. -HB.instance Definition _ := IsQuiver.Build type hom_subdef. -End homcomma. -Arguments hom_subdef /. -Section comma. -Context {C D E : cat} (F : C ~> E) (G : D ~> E). -Notation type := (type F G). - -Program Definition idmap_subdef (a : type) : a ~> a := @Tagged _ idmap _ _. -Next Obligation. by rewrite !F1 comp1o compo1. Qed. -Program Definition comp_subdef (a b c : type) - (f : a ~> b) (g : b ~> c) : a ~> c := - @Tagged _ (tag f \; tag g) _ _. -Next Obligation. by rewrite !Fcomp -compoA (tagged g) compoA (tagged f) compoA. Qed. -HB.instance Definition _ := IsPreCat.Build type idmap_subdef comp_subdef. -Arguments idmap_subdef /. -Arguments comp_subdef /. - -Lemma comma_homeqP (a b : type) (f g : a ~> b) : projT1 f = projT1 g -> f = g. -Proof. -case: f g => [f fP] [g +]/= eqfg; case: _ / eqfg => gP. -by congr existT; apply: Prop_irrelevance. -Qed. - -Lemma comma_is_cat : PreCat_IsCat type. -Proof. -by split=> [[a fa] [b fb] [*]|[a fa] [b fb] [*]|*]; - apply/comma_homeqP; rewrite /= ?(comp1o, compo1, compoA). -Qed. -HB.instance Definition _ := comma_is_cat. -End comma. -End comma. -Notation "F `/` G" := (@comma.type _ _ _ F G) - (at level 40, G at level 40, format "F `/` G") : cat_scope. -Notation "a /` G" := (cst unit a `/` G) - (at level 40, G at level 40, format "a /` G") : cat_scope. -Notation "F `/ b" := (F `/` cst unit b) - (at level 40, b at level 40, format "F `/ b") : cat_scope. -Notation "a / b" := (cst unit a `/ b) : cat_scope. - -Definition obj (C : quiver) : Type := C. -HB.mixin Record IsInitial {C : quiver} (i : obj C) := { - to : forall c, i ~> c; - to_unique : forall c (f : i ~> c), f = to c -}. -#[short(type="initial")] -HB.structure Definition Initial {C : quiver} := {i of IsInitial C i}. - -HB.mixin Record IsTerminal {C : quiver} (t : obj C) := { - from : forall c, c ~> t; - from_unique : forall c (f : c ~> t), f = from c -}. -#[short(type="terminal")] -HB.structure Definition Terminal {C : quiver} := {t of IsTerminal C t}. - -HB.mixin Record IsMono {C : precat} (b c : C) (f : hom b c) := { - monoP : forall (a : C) (g1 g2 : a ~> b), g1 \; f = g2 \; f -> g1 = g2 -}. -#[short(type="mono")] -HB.structure Definition Mono {C : precat} (a b : C) := {m of IsMono C a b m}. -Notation "a >~> b" := (mono a b) - (at level 99, b at level 200, format "a >~> b") : cat_scope. -Notation "C >~>_ T D" := (@mono T C D) - (at level 99, T at level 0, only parsing) : cat_scope. - -HB.mixin Record IsEpi {C : precat} (a b : C) (f : hom a b) := { - epiP : forall (c : C) (g1 g2 : b ~> c), g1 \o f = g2 \o f -> g1 = g2 -}. -#[short(type="epi")] -HB.structure Definition Epi {C : precat} (a b : C) := {e of IsEpi C a b e}. -Notation "a ~>> b" := (epi a b) - (at level 99, b at level 200, format "a ~>> b") : cat_scope. -Notation "C ~>>_ T D" := (@epi T C D) - (at level 99, T at level 0, only parsing) : cat_scope. - -#[short(type="iso")] -HB.structure Definition Iso {C : precat} (a b : C) := - {i of @Mono C a b i & @Epi C a b i}. -Notation "a <~> b" := (epi a b) - (at level 99, b at level 200, format "a <~> b") : cat_scope. -Notation "C <~>_ T D" := (@epi T C D) - (at level 99, T at level 0, only parsing) : cat_scope. - -Definition comp1F {C D : cat} (F : C ~> D) : idmap \; F = F. -Proof. by apply/functorP=> a b f; rewrite funext_frefl/= compFmap. Qed. - -Definition compF1 {C D : cat} (F : C ~> D) : F \; idmap = F. -Proof. by apply/functorP=> a b f; rewrite funext_frefl/= compFmap. Qed. - -Definition feq {C : precat} {a b : C} : a = b -> a ~> b. -Proof. by move<-; exact idmap. Defined. - -Definition feqsym {C : precat} {a b : C} : a = b -> b ~> a. -Proof. by move<-; exact idmap. Defined. - -HB.mixin Record IsLeftAdjointOf (C D : cat) (R : D ~> C) L - of @Functor C D L := { - Lphi : forall c d, (L c ~> d) -> (c ~> R d); - Lpsi : forall c d, (c ~> R d) -> (L c ~> d); - (* there should be a monad and comonad structure wrappers instead *) - Lunit : (idmap : C ~> C) ~~> R \o ((L : Functor.type C D) : C ~> D); - Lcounit : ((L : Functor.type C D) : C ~> D) \o R ~~> idmap :> D ~> D; - LphiE : forall c d (g : L c ~> d), Lphi c d g = Lunit c \; (R <$> g); - LpsiE : forall c d (f : c ~> R d), Lpsi c d f = (L <$> f) \; Lcounit d; - Lwhiskerlr : let L : C ~> D := L : Functor.type C D in - (feqsym (comp1F _) \; Lunit L) \; - (L <$o> Lcounit \; feq (compF1 _)) = idmap; - Lwhiskerrl : let L : C ~> D := L : Functor.type C D in - (feqsym (compF1 _) \; R <$o> Lunit) \; - (Lcounit R \; feq (comp1F _)) = idmap; -}. -#[short(type="left_adjoint_of")] -HB.structure Definition LeftAdjointOf (C D : cat) (R : D ~> C) := - { L of @Functor C D L & IsLeftAdjointOf C D R L}. -Arguments Lphi {C D R s} {c d}. -Arguments Lpsi {C D R s} {c d}. -Arguments Lunit {C D R s}. -Arguments Lcounit {C D R s}. - -Section LeftAdjointOf_Theory. -Variables (C D : cat) (R : D ~> C) (L : LeftAdjointOf.type R). - -Lemma Lphi_psi (c : C) (d : D) : - (@Lphi _ _ R L c d \o @Lpsi _ _ R L c d)%FUN = @id (c ~> R d). -Proof. -apply/funext => f /=; rewrite LphiE LpsiE. -Admitted. - -Lemma Lpsi_phi (c : C) (d : D) : - (@Lpsi _ _ R L c d \o @Lphi _ _ R L c d)%FUN = @id (L c ~> d). -Proof. -Admitted. -End LeftAdjointOf_Theory. - -HB.mixin Record IsRightAdjoint (D C : cat) (R : D -> C) - of @Functor D C R := { - (* we should have a wrapper instead *) - left_adjoint : C ~> D; - LLphi : forall c d, (left_adjoint c ~> d) -> (c ~> R d); - LLpsi : forall c d, (c ~> R d) -> (left_adjoint c ~> d); - LLunit : (idmap : C ~> C) ~~> (R : Functor.type D C) \o left_adjoint; - LLcounit : left_adjoint \o (R : Functor.type D C) ~~> idmap :> D ~> D; - LLphiE : forall c d (g : left_adjoint c ~> d), LLphi c d g = LLunit c \; (R <$> g); - LLpsiE : forall c d (f : c ~> R d), LLpsi c d f = (left_adjoint <$> f) \; LLcounit d; - LLwhiskerlr : - (feqsym (comp1F _) \; LLunit left_adjoint) \; - (left_adjoint <$o> LLcounit \; feq (compF1 _)) = idmap; - LLwhiskerrl : - (feqsym (compF1 _) \; (R : Functor.type D C) <$o> LLunit) \; - (LLcounit (R : Functor.type D C) \; feq (comp1F _)) = idmap; -}. -#[short(type="right_adjoint")] -HB.structure Definition RightAdjoint (D C : cat) := - { R of @Functor D C R & IsRightAdjoint D C R }. -Arguments left_adjoint {_ _}. -Arguments LLphi {D C s} {c d}. -Arguments LLpsi {D C s} {c d}. -Arguments LLunit {D C s}. -Arguments LLcounit {D C s}. - -HB.mixin Record PreCat_IsMonoidal C of PreCat C := { - onec : C; - prod : (C * C)%type ~>_precat C; -}. -#[short(type="premonoidal")] -HB.structure Definition PreMonoidal := { C of PreCat C & PreCat_IsMonoidal C }. -Notation premonoidal := premonoidal. -Arguments prod {C} : rename. -Notation "a * b" := (prod (a, b)) : cat_scope. -Reserved Notation "f <*> g" (at level 40, g at level 40, format "f <*> g"). -Notation "f <*> g" := (prod^$ (f, g)) (only printing) : cat_scope. -Notation "f <*> g" := (prod^$ ((f, g) : (_, _) ~> (_, _))) - (only parsing) : cat_scope. -Notation "1" := onec : cat_scope. - -Definition hom_cast {C : quiver} {a a' : C} (eqa : a = a') - {b b' : C} (eqb : b = b') : - (a ~> b) -> (a' ~> b'). -Proof. now elim: _ / eqa; elim: _ / eqb. Defined. - -HB.mixin Record PreFunctor_IsMonoidal (C D : premonoidal) F of - @PreFunctor C D F := { - fun_one : F 1 = 1; - fun_prod : forall (x y : C), F (x * y) = F x * F y; -}. -#[short(type="monoidal_prefunctor")] -HB.structure Definition MonoidalPreFunctor C D := - { F of @PreFunctor_IsMonoidal C D F }. -Arguments fun_prod {C D F x y} : rename. -(* Arguments fun_prodF {C D F x x'} f {y y'} g : rename. *) -Unset Universe Checking. -HB.instance Definition _ := IsQuiver.Build premonoidal MonoidalPreFunctor.type. -Set Universe Checking. - -HB.instance Definition _ (C : quiver) := - IsPreFunctor.Build (C * C)%type C fst - (fun (a b : C * C) (f : a ~> b) => f.1). -HB.instance Definition _ (C : quiver) := - IsPreFunctor.Build (C * C)%type C snd - (fun (a b : C * C) (f : a ~> b) => f.2). - -Definition prod3l {C : premonoidal} (x : C * C * C) : C := - (x.1.1 * x.1.2) * x.2. -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build _ C prod3l - (fun a b (f : a ~> b) => (f.1.1 <*> f.1.2) <*> f.2). - -Definition prod3r {C : premonoidal} (x : C * C * C) : C := - x.1.1 * (x.1.2 * x.2). -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build _ C prod3r - (fun a b (f : a ~> b) => f.1.1 <*> (f.1.2 <*> f.2)). - -Definition prod1r {C : premonoidal} (x : C) : C := 1 * x. -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build C C prod1r - (fun (a b : C) (f : a ~> b) => \idmap_1 <*> f). - -Definition prod1l {C : premonoidal} (x : C) : C := x * 1. -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build C C prod1l - (fun (a b : C) (f : a ~> b) => f <*> \idmap_1). - -HB.mixin Record PreMonoidal_IsMonoidal C of PreMonoidal C := { - prodA : prod3l ~~> prod3r; - prod1c : prod1r ~~> idfun; - prodc1 : prod1l ~~> idfun; - prodc1c : forall (x y : C), - prodA (x, 1, y) \; \idmap_x <*> prod1c y = prodc1 x <*> \idmap_y; - prodA4 : forall (w x y z : C), - prodA (w * x, y, z) \; prodA (w, x, y * z) = - prodA (w, x, y) <*> \idmap_z \; prodA (w, x * y, z) \; \idmap_w <*> prodA (x, y, z); -}. - -Unset Universe Checking. -#[short(type="monoidal")] -HB.structure Definition Monoidal : Set := - { C of PreMonoidal_IsMonoidal C & PreMonoidal C }. -Set Universe Checking. - -Record span (Q : quiver) (A B : Q) := Span { - bot : Q; - bot2left : bot ~> A; - bot2right : bot ~> B -}. - -Section spans. -Variables (Q : precat) (A B : Q). -Record span_map (c c' : span A B) := SpanMap { - bot_map : bot c ~> bot c'; - bot2left_map : bot_map \; bot2left c' = bot2left c; - bot2right_map : bot_map \; bot2right c' = bot2right c; -}. -HB.instance Definition _ := IsQuiver.Build (span A B) span_map. - -Lemma span_mapP (c c' : span A B) (f g : c ~> c') : - bot_map f = bot_map g <-> f = g. -Proof. -split=> [|->]//; case: f g => [/= f ? ?] [/= g + +] efg. -by elim: efg => // ? ?; congr SpanMap; apply: Prop_irrelevance. -Qed. - -End spans. - -Section spans_in_cat. -Variables (Q : cat) (A B : Q). -Definition span_idmap (c : span A B) := - @SpanMap Q A B c c idmap (comp1o _) (comp1o _). -Program Definition span_comp (c1 c2 c3 : span A B) - (f12 : c1 ~> c2) (f23 : c2 ~> c3) := - @SpanMap Q A B c1 c3 (bot_map f12 \; bot_map f23) _ _. -Next Obligation. by rewrite -compoA !bot2left_map. Qed. -Next Obligation. by rewrite -compoA !bot2right_map. Qed. -HB.instance Definition _ := IsPreCat.Build (span A B) - span_idmap span_comp. - -Lemma span_are_cats : PreCat_IsCat (span A B). -Proof. -constructor=> [a b f|a b f|a b c d f g h]. -- by apply/span_mapP => /=; rewrite comp1o. -- by apply/span_mapP => /=; rewrite compo1. -- by apply/span_mapP => /=; rewrite compoA. -Qed. -HB.instance Definition _ := span_are_cats. -End spans_in_cat. - -Record cospan (Q : quiver) (A B : Q) := Cospan { - top : Q; - left2top : A ~> top; - right2top : B ~> top -}. - -Section cospans. -Variables (Q : precat) (A B : Q). -Record cospan_map (c c' : cospan A B) := CospanMap { - top_map : top c ~> top c'; - left2top_map : left2top c \; top_map = left2top c'; - right2top_map : right2top c \; top_map = right2top c'; -}. -HB.instance Definition _ := IsQuiver.Build (cospan A B) cospan_map. - -Lemma cospan_mapP (c c' : cospan A B) (f g : c ~> c') : - top_map f = top_map g <-> f = g. -Proof. -split=> [|->]//; case: f g => [/= f ? ?] [/= g + +] efg. -by elim: efg => // ? ?; congr CospanMap; apply: Prop_irrelevance. -Qed. - -End cospans. - -Section cospans_in_cat. -Variables (Q : cat) (A B : Q). -Definition cospan_idmap (c : cospan A B) := - @CospanMap Q A B c c idmap (compo1 _) (compo1 _). -Program Definition cospan_comp (c1 c2 c3 : cospan A B) - (f12 : c1 ~> c2) (f23 : c2 ~> c3) := - @CospanMap Q A B c1 c3 (top_map f12 \; top_map f23) _ _. -Next Obligation. by rewrite compoA !left2top_map. Qed. -Next Obligation. by rewrite compoA !right2top_map. Qed. -HB.instance Definition _ := IsPreCat.Build (cospan A B) - cospan_idmap cospan_comp. - -Lemma cospan_are_cats : PreCat_IsCat (cospan A B). -Proof. -constructor=> [a b f|a b f|a b c d f g h]. -- by apply/cospan_mapP => /=; rewrite comp1o. -- by apply/cospan_mapP => /=; rewrite compo1. -- by apply/cospan_mapP => /=; rewrite compoA. -Qed. -HB.instance Definition _ := cospan_are_cats. -End cospans_in_cat. - -HB.mixin Record isPrePullback (Q : precat) (A B : Q) - (c : cospan A B) (s : span A B) := { - is_square : bot2left s \; left2top c = bot2right s \; right2top c; -}. -#[short(type=prepullback)] -HB.structure Definition PrePullback Q A B (c : cospan A B) := - {s of isPrePullback Q A B c s}. -Arguments prepullback {Q A B} c. - -Section prepullback. -Variables (Q : precat) (A B : Q) (c : cospan A B). -HB.instance Definition _ := - IsQuiver.Build (prepullback c) - (fun a b => (a : span A B) ~>_(span A B) (b : span A B)). -Lemma eq_prepullbackP (p q : prepullback c) : - p = q :> span _ _ <-> p = q. -Proof. -Admitted. -End prepullback. -Section prepullback. -Variables (Q : cat) (A B : Q) (csp : cospan A B). -(* TODO: why can't we do that? *) -(* HB.instance Definition _ := Cat.on (prepullback csp). *) -HB.instance Definition _ := - Quiver_IsPreCat.Build (prepullback csp) - (fun a => \idmap_(a : span A B)) - (* TODO: study how to make this coercion trigger - even when the target is not reduced to span *) - (fun a b c f g => f \; g). -Lemma prepullback_is_cat : PreCat_IsCat (prepullback csp). -Proof. (* should be copied from the cat on span *) -constructor=> [a b f|a b f|a b c d f g h]; - [exact: comp1o|exact: compo1|exact: compoA]. -Qed. -End prepullback. - -HB.tag Definition pb_terminal (Q : precat) - (A B : Q) (c : cospan A B) (s : prepullback c) : - obj (prepullback c) := s. - -#[wrapper] -HB.mixin Record prepullback_isTerminal (Q : precat) - (A B : Q) (c : cospan A B) - (s : span A B) of isPrePullback Q A B c s := { - prepullback_terminal : - IsTerminal (prepullback c) (pb_terminal s) -}. -#[short(type="pullback"), verbose] -HB.structure Definition Pullback (Q : precat) - (A B : Q) (c : cospan A B) := - {s of isPrePullback Q A B c s - & IsTerminal (prepullback c) (pb_terminal s) }. - -Inductive walking_cospan := Top | Left | Right. -Definition walking_cospan_hom (x y : walking_cospan) := match x, y with - | Top, Top | Left, Left | Right, Right | - Left, Top | Right, Top => Datatypes.unit - | _, _ => False - end. - -HB.instance Definition _ := - IsQuiver.Build walking_cospan walking_cospan_hom. - -Definition walking_cospan_id (x : walking_cospan) : x ~> x. -Proof. by case: x; constructor. Defined. - -Definition walking_cospan_comp (x y z : walking_cospan) : - (x ~> y) -> (y ~> z) -> (x ~> z). -Proof. by case: x y z => [] [] []. Defined. - -HB.instance Definition _ := Quiver_IsPreCat.Build walking_cospan - walking_cospan_id walking_cospan_comp. - -Lemma walking_cospan_cat : PreCat_IsCat walking_cospan. -Proof. by constructor=> [[] []|[] []|[] [] [] []]// []. Qed. -HB.instance Definition _ := walking_cospan_cat. - -Section Pullback_Natural. -Context (C : cat) (A B : C) (csp : cospan A B). - -Definition cspF (x : walking_cospan) : C := - match x with Left => A | Right => B | Top => top csp end. - -Definition cspFhom : forall (x y : walking_cospan), - (x ~> y) -> cspF x ~> cspF y. -Proof. -move=> [] []//. -- move=> _; exact: idmap. -- move=> _; exact: left2top csp. -- move=> _; exact: idmap. -- move=> _; exact: right2top csp. -- move=> _; exact: idmap. -Defined. - -HB.instance Definition _ := IsPreFunctor.Build _ _ cspF cspFhom. -Lemma cspF_functor : PreFunctor_IsFunctor _ _ cspF. -Proof. -by constructor=> [[]|[] [] []]//= [] []//=; - rewrite ?(compo1, comp1o)//. -Qed. -HB.instance Definition _ := cspF_functor. - -Section prepullback2natural. -Variable (p : prepullback csp). - -Definition wcsp w : cst walking_cospan (bot p) w ~> cspF w. -Proof. -case: w; rewrite /cst /=. -- exact: (bot2left _ \; left2top _). -- exact: bot2left. -- exact: bot2right. -Defined. - -Lemma wcsp_natural : IsNatural _ _ _ _ wcsp. -Proof. -constructor=> - [] [] //= [] /=; rewrite ?(comp1o, compo1)//=. -exact: is_square. -Qed. - -End prepullback2natural. - -Section natural2prepullback. -Variables (c : C) (n : cst walking_cospan c ~~> cspF). - -Definition s := {| bot := c; bot2left := n Left; bot2right := n Right |}. - -Lemma s_prepullback : isPrePullback _ _ _ csp s. -Proof. -constructor => /=. -have p := natural n (tt : Right ~> Top). -have /esym q := natural n (tt : Left ~> Top). -exact: etrans q p. -Qed. - -End natural2prepullback. - -End Pullback_Natural. -Notation square u v f g := - (isPrePullback _ _ _ (Cospan f g) (Span u v)). -Notation pbsquare u v f g := - (Pullback _ (Cospan f g) (Span u v)). -Notation pb s := (prepullback_isTerminal _ _ _ _ s). - -Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). - -(**********************************************************************) - -Section th_of_pb. -Variables (Q : cat) (A B C D E F : Q). -Variables (f : A ~> D) (g : B ~> D) (h : C ~> A). -Variables (u : E ~> A) (v : E ~> B) (w : F ~> C) (z : F ~> E). -Variable (uvfg : pbsquare u v f g). - -Theorem pbsquarec_compP : - pbsquare w z h u <=> pbsquare w (z \; v) (h \; f) g. -Proof. -split=> [] sq. - - have @sq_ispb : pullback (Cospan h u) := HB.pack (Span w z) sq. - have @uvfg_ispb : pullback (Cospan f g) := HB.pack (Span u v) uvfg. - have /=E2 := @is_square _ _ _ _ sq_ispb. - have /=E1 := @is_square _ _ _ _ uvfg_ispb. - - have p1 : @isPrePullback Q C B (Cospan (h \; f) g) (Span w (z \; v)). - by constructor; rewrite /= compoA E2 -compoA E1 compoA. - pose big_black_square : prepullback (Cospan (h \; f) g) := - HB.pack (Span w (z \; v)) p1. - - have @from : forall - (big_red_square : prepullback {| top := D; left2top := h \; f; right2top := g |}), - big_red_square ~> pb_terminal big_black_square. - - move=> big_red_square; unfold pb_terminal. - - have /= := @is_square _ _ _ _ big_red_square. - - pose F' := bot big_red_square. - set w' : F' ~> C := bot2left big_red_square. - set z' : F' ~> B := bot2right big_red_square. - move=> E3. - - have xxx : isPrePullback Q A B (Cospan f g) (Span (w' \; h) z'). - by constructor=> /=; rewrite -compoA E3. - pose red_black_square : prepullback (Cospan f g) := - HB.pack (Span (w' \; h) z') xxx. - have := @from_unique _ (pb_terminal uvfg_ispb) red_black_square. - set blue := @from _ (pb_terminal uvfg_ispb) red_black_square. - move=> blue_unique. - - have p3 : @isPrePullback Q C E (Cospan h u) (Span w' (bot_map blue)). - by constructor; rewrite /= (bot2left_map blue). (* buggy unifier without blue *) - pose blue_red_black_square : prepullback (Cospan h u) := - HB.pack (Span w' (bot_map blue)) p3. - - pose red := @from _ (pb_terminal sq_ispb) blue_red_black_square. - - admit. - - - - have p2 : prepullback_isTerminal.axioms_ Q C B (Cospan (h \; f) g) (Span w (z \; v)) p1. - constructor. econstructor=> /=. - admit. - - by HB.from p1 p2. - -Admitted. - -End th_of_pb. - - -Module test. - -Section test. -Variables (Q : precat) (A B : Q) (c : cospan A B). -Variable (p : pullback c). -Check pb_terminal p : terminal _. - -End test. -End test. - - -(********************************************************************) -(********************************************************************) - - Notation "'sigma' x .. y , p" := (sigT (fun x => .. (sigT (fun y => p)) ..)) (at level 200, x binder, right associativity, format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") : type_scope. - (*** GENERALISED ENRICHED CATEGORIES *) Declare Scope encat_scope. @@ -1369,6 +101,8 @@ Set Universe Checking. (*** CATEGORIES WITH PULLBACKS *) +(* Local Open Scope type_scope. *) + (* category with all prepullbacks *) (* Ideally span is in fact expanded and the final mixin has a pb : forall A B, cospan A B -> C @@ -1844,7 +578,7 @@ Lemma pbsquare_universal {C: cat} (A B T P0 P1 : C) simpl in *. econstructor. - instantiate (1:= bot_map0). + instantiate (1:= bot_map). split; auto. Qed. diff --git a/theories/encatI0.v b/theories/encatI0.v index 4dddc114c..f6a5504d5 100644 --- a/theories/encatI0.v +++ b/theories/encatI0.v @@ -1,5 +1,7 @@ Require Import ssreflect ssrfun. -From HB Require Import structures. +Unset Universe Checking. +From HB Require Import structures cat. +Set Universe Checking. Require Import Coq.Program.Equality. Set Implicit Arguments. @@ -7,1284 +9,17 @@ Unset Strict Implicit. Unset Printing Implicit Defensive. Add Search Blacklist "__canonical__". -Declare Scope algebra_scope. -Delimit Scope algebra_scope with A. Local Open Scope algebra_scope. -Declare Scope cat_scope. -Delimit Scope cat_scope with cat. Local Open Scope cat_scope. -(* we assume a few axioms to make life easier *) -Axiom funext : forall {T : Type} {U : T -> Type} [f g : forall t, U t], - (forall t, f t = g t) -> f = g. -Axiom propext : forall P Q : Prop, P <-> Q -> P = Q. -Axiom Prop_irrelevance : forall (P : Prop) (x y : P), x = y. - -(* Shortcut *) -Notation U := Type. - -(* Base definition : raw categories = quivers *) -HB.mixin Record IsQuiver C := { hom : C -> C -> U }. -Unset Universe Checking. -#[short(type="quiver")] -HB.structure Definition Quiver : Set := { C of IsQuiver C }. -Set Universe Checking. - -Bind Scope cat_scope with quiver. -Bind Scope cat_scope with hom. -Arguments hom {C} : rename. -Notation homs T := (@hom T _ _). -Notation "a ~> b" := (hom a b) - (at level 99, b at level 200, format "a ~> b") : cat_scope. -Notation "a ~>_ C b" := (@hom C a b) - (at level 99, C at level 0, only parsing) : cat_scope. - -(* precategories are quivers + id and comp *) -HB.mixin Record Quiver_IsPreCat C of Quiver C := { - idmap : forall (a : C), a ~> a; - comp : forall (a b c : C), (a ~> b) -> (b ~> c) -> (a ~> c); -}. - -HB.factory Record IsPreCat C := { - hom : C -> C -> U; - idmap : forall (a : C), hom a a; - comp : forall (a b c : C), hom a b -> hom b c -> hom a c; -}. -HB.builders Context C of IsPreCat C. - HB.instance Definition _ := IsQuiver.Build C hom. - HB.instance Definition _ := Quiver_IsPreCat.Build C idmap comp. -HB.end. - -Unset Universe Checking. -#[short(type="precat")] -HB.structure Definition PreCat : Set := { C of IsPreCat C }. -Set Universe Checking. - -Bind Scope cat_scope with precat. -Arguments idmap {C} {a} : rename. -Arguments comp {C} {a b c} : rename. -Notation "f \o g" := (comp g f) : cat_scope. -Notation "f \; g :> T" := (@comp T _ _ _ f g) - (at level 60, g, T at level 60, format "f \; g :> T", only parsing) : cat_scope. -Notation "f \; g" := (comp f g) : cat_scope. -Notation "\idmap_ a" := (@idmap _ a) (only parsing, at level 0) : cat_scope. - -(* categories are precategories + laws *) -HB.mixin Record PreCat_IsCat C of PreCat C := { - comp1o : forall (a b : C) (f : a ~> b), idmap \; f = f; - compo1 : forall (a b : C) (f : a ~> b), f \; idmap = f; - compoA : forall (a b c d : C) (f : a ~> b) (g : b ~> c) (h : c ~> d), - f \; (g \; h) = (f \; g) \; h -}. -Unset Universe Checking. -#[short(type="cat")] -HB.structure Definition Cat : Set := { C of PreCat_IsCat C & IsPreCat C }. -Set Universe Checking. - -Bind Scope cat_scope with cat. -Arguments compo1 {C a b} : rename. -Arguments comp1o {C a b} : rename. -Arguments compoA {C a b c d} : rename. - -(* the discrete category on a type cannot be the default, we make an alias *) -Definition discrete (T : U) := T. -HB.instance Definition _ T := @IsPreCat.Build (discrete T) (fun x y => x = y) - (fun=> erefl) (@etrans _). -Lemma etransA T (a b c d : discrete T) (f : a ~> b) (g : b ~> c) (h : c ~> d) : - f \; (g \; h) = (f \; g) \; h. -Proof. by rewrite /idmap/comp/=; case: _ / h; case: _ / g. Qed. -HB.instance Definition _ T := PreCat_IsCat.Build (discrete T) (@etrans_id _) - (fun _ _ _ => erefl) (@etransA _). - -(* the category of the unit type is the discrete one *) -HB.instance Definition _ := Cat.copy unit (discrete unit). - -HB.instance Definition _ := @IsPreCat.Build U (fun A B => A -> B) - (fun a => idfun) (fun a b c (f : a -> b) (g : b -> c) => (g \o f)%FUN). -HB.instance Definition _ := PreCat_IsCat.Build U (fun _ _ _ => erefl) - (fun _ _ _ => erefl) (fun _ _ _ _ _ _ _ => erefl). - - -Lemma Ucomp (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) : f \; g = (g \o f)%FUN. -Proof. by []. Qed. -Lemma Ucompx (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) x : (f \; g) x = g (f x). -Proof. by []. Qed. -Lemma U1 (X : U) : \idmap_X = idfun. -Proof. by []. Qed. -Lemma U1x (X : U) x : \idmap_X x = x. -Proof. by []. Qed. - -(* a prefunctor is a functor without laws *) -HB.mixin Record IsPreFunctor (C D : quiver) (F : C -> D) := { - Fhom : forall (a b : C), (a ~> b) -> (F a ~> F b) -}. - -Unset Universe Checking. -HB.structure Definition PreFunctor (C D : quiver) : Set := - { F of IsPreFunctor C D F }. -Set Universe Checking. -HB.instance Definition _ := IsQuiver.Build quiver PreFunctor.type. - -Notation "F ^$" := (@Fhom _ _ F _ _) - (at level 1, format "F ^$") : cat_scope. -Notation "F <$> f" := (@Fhom _ _ F _ _ f) - (at level 58, format "F <$> f", right associativity) : cat_scope. - -(* prefunctors are equal if their object and hom part are respectively equal *) -Lemma prefunctorP (C D : quiver) (F G : C ~> D) (eqFG : F =1 G) : - let homF a b F := F a ~> F b in - (forall a b f, eq_rect _ (homF a b) (F <$> f) _ (funext eqFG) = G <$> f) -> - F = G. -Proof. -move: F G => [F [[/= Fhom]]] [G [[/= Ghom]]] in eqFG *. -case: _ / (funext eqFG) => /= in Ghom * => eqFGhom. -congr PreFunctor.Pack; congr PreFunctor.Class; congr IsPreFunctor.Axioms_. -by do 3!apply: funext=> ?. -Qed. - -(* a functor is a prefunctor + laws for id and comp *) -HB.mixin Record PreFunctor_IsFunctor (C D : precat) (F : C -> D) - of @PreFunctor C D F := { - F1 : forall (a : C), F <$> \idmap_a = idmap; - Fcomp : forall (a b c : C) (f : a ~> b) (g : b ~> c), - F <$> (f \; g) = F <$> f \; F <$> g; -}. -Unset Universe Checking. - -(* precat and cat have a quiver structure *) -HB.structure Definition Functor (C D : precat) : Set := - { F of IsPreFunctor C D F & PreFunctor_IsFunctor C D F }. -Set Universe Checking. -HB.instance Definition _ := IsQuiver.Build precat Functor.type. -HB.instance Definition _ := IsQuiver.Build cat Functor.type. - -(* functor equality is the same as prefunctor because of PI *) -Lemma functorP (C D : precat) (F G : C ~> D) (eqFG : F =1 G) : - let homF a b F := F a ~> F b in - (forall a b f, eq_rect _ (homF a b) (F^$ f) _ (funext eqFG) = G^$ f) -> - F = G. -Proof. -move=> /= /prefunctorP {eqFG}. -case: F G => [F [/= Fm Fm']] [G [/= Gm Gm']]//=. -move=> [_] /EqdepFacts.eq_sigT_iff_eq_dep eqFG. -case: _ / eqFG in Gm' *. -congr Functor.Pack; congr Functor.Class. -case: Fm' Gm' => [F1 Fc] [G1 Gc]. -by congr PreFunctor_IsFunctor.Axioms_; apply: Prop_irrelevance. -Qed. - -(* the identity function is a functor *) -HB.instance Definition _ (C : quiver) := - IsPreFunctor.Build C C idfun (fun a b => idfun). -HB.instance Definition _ (C : precat) := - PreFunctor_IsFunctor.Build C C idfun (fun=> erefl) (fun _ _ _ _ _ => erefl). - -(* the composition of prefunctors *) -Section comp_prefunctor. -Context {C D E : quiver} {F : C ~> D} {G : D ~> E}. - -HB.instance Definition _ := IsPreFunctor.Build C E (G \o F)%FUN - (fun a b f => G <$> F <$> f). -Lemma comp_Fun (a b : C) (f : a ~> b) : (G \o F)%FUN <$> f = G <$> (F <$> f). -Proof. by []. Qed. -End comp_prefunctor. - -Section comp_functor. -Context {C D E : precat} {F : C ~> D} {G : D ~> E}. -Lemma comp_F1 (a : C) : (G \o F)%FUN <$> \idmap_a = idmap. -Proof. by rewrite !comp_Fun !F1. Qed. -Lemma comp_Fcomp (a b c : C) (f : a ~> b) (g : b ~> c) : - (G \o F)%FUN <$> (f \; g) = (G \o F)%FUN <$> f \; (G \o F)%FUN <$> g. -Proof. by rewrite !comp_Fun !Fcomp. Qed. -HB.instance Definition _ := PreFunctor_IsFunctor.Build C E (G \o F)%FUN - comp_F1 comp_Fcomp. -End comp_functor. - -(* precat and cat have a precategory structure *) -HB.instance Definition _ := Quiver_IsPreCat.Build precat - (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). -HB.instance Definition _ := Quiver_IsPreCat.Build cat - (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). - -Lemma funext_frefl A B (f : A -> B) : funext (frefl f) = erefl. -Proof. exact: Prop_irrelevance. Qed. - -(* precategories and categories form a category *) -Definition precat_cat : PreCat_IsCat precat. -Proof. -by split=> [C D F|C D F|C D C' D' F G H]; - apply/functorP => a b f /=; rewrite funext_frefl. -Qed. -HB.instance Definition _ := precat_cat. -Definition cat_cat : PreCat_IsCat cat. -Proof. -by split=> [C D F|C D F|C D C' D' F G H]; - apply/functorP => a b f /=; rewrite funext_frefl. -Qed. -HB.instance Definition _ := cat_cat. - -Check (cat : cat). - -(* concrete categories *) -HB.mixin Record Quiver_IsPreConcrete T of Quiver T := { - concrete : T -> U; - concrete_fun : forall (a b : T), (a ~> b) -> concrete a -> concrete b; -}. -Unset Universe Checking. -#[short(type="preconcrete_quiver")] -HB.structure Definition PreConcreteQuiver : Set := - { C of Quiver_IsPreConcrete C & IsQuiver C }. -Set Universe Checking. -Coercion concrete : PreConcreteQuiver.sort >-> Sortclass. - -HB.mixin Record PreConcrete_IsConcrete T of PreConcreteQuiver T := { - concrete_fun_inj : forall (a b : T), injective (concrete_fun a b) -}. -Unset Universe Checking. -#[short(type="concrete_quiver")] -HB.structure Definition ConcreteQuiver : Set := - { C of PreConcreteQuiver C & PreConcrete_IsConcrete C }. -Set Universe Checking. - -HB.instance Definition _ (C : ConcreteQuiver.type) := - IsPreFunctor.Build _ _ (concrete : C -> U) concrete_fun. - -HB.mixin Record PreCat_IsConcrete T of ConcreteQuiver T & PreCat T := { - concrete1 : forall (a : T), concrete <$> \idmap_a = idfun; - concrete_comp : forall (a b c : T) (f : a ~> b) (g : b ~> c), - concrete <$> (f \; g) = ((concrete <$> g) \o (concrete <$> f))%FUN; -}. -Unset Universe Checking. -#[short(type="concrete_precat")] -HB.structure Definition ConcretePreCat : Set := - { C of PreCat C & ConcreteQuiver C & PreCat_IsConcrete C }. -#[short(type="concrete_cat")] -HB.structure Definition ConcreteCat : Set := - { C of Cat C & ConcreteQuiver C & PreCat_IsConcrete C }. -Set Universe Checking. - -HB.instance Definition _ (C : concrete_precat) := - PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). -HB.instance Definition _ (C : ConcreteCat.type) := - PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). - -HB.instance Definition _ := Quiver_IsPreConcrete.Build U (fun _ _ => id). -HB.instance Definition _ := PreConcrete_IsConcrete.Build U (fun _ _ _ _ => id). -HB.instance Definition _ := PreCat_IsConcrete.Build U - (fun=> erefl) (fun _ _ _ _ _ => erefl). - -Unset Universe Checking. -HB.instance Definition _ := Quiver_IsPreConcrete.Build quiver (fun _ _ => id). -HB.instance Definition _ := Quiver_IsPreConcrete.Build precat (fun _ _ => id). -HB.instance Definition _ := Quiver_IsPreConcrete.Build cat (fun _ _ => id). -Lemma quiver_concrete_subproof : PreConcrete_IsConcrete quiver. -Proof. -constructor=> C D F G FG; apply: prefunctorP. - by move=> x; congr (_ x); apply: FG. -by move=> *; apply: Prop_irrelevance. -Qed. -HB.instance Definition _ := quiver_concrete_subproof. - -Lemma precat_concrete_subproof : PreConcrete_IsConcrete precat. -Proof. -constructor=> C D F G FG; apply: functorP. - by move=> x; congr (_ x); apply: FG. -by move=> *; apply: Prop_irrelevance. -Qed. -HB.instance Definition _ := precat_concrete_subproof. - -Lemma cat_concrete_subproof : PreConcrete_IsConcrete cat. -Proof. -constructor=> C D F G FG; apply: functorP. - by move=> x; congr (_ x); apply: FG. -by move=> *; apply: Prop_irrelevance. -Qed. -HB.instance Definition _ := cat_concrete_subproof. -HB.instance Definition _ := PreCat_IsConcrete.Build precat - (fun=> erefl) (fun _ _ _ _ _ => erefl). -HB.instance Definition _ := PreCat_IsConcrete.Build cat - (fun=> erefl) (fun _ _ _ _ _ => erefl). -Set Universe Checking. - -(* constant functor *) -Definition cst (C D : quiver) (c : C) := fun of D => c. -Arguments cst {C} D c. -HB.instance Definition _ {C D : precat} (c : C) := - IsPreFunctor.Build D C (cst D c) (fun _ _ _ => idmap). -HB.instance Definition _ {C D : cat} (c : C) := - PreFunctor_IsFunctor.Build D C (cst D c) (fun=> erefl) - (fun _ _ _ _ _ => esym (compo1 idmap)). - -(* opposite category *) -Definition catop (C : U) : U := C. -Notation "C ^op" := (catop C) - (at level 2, format "C ^op") : cat_scope. -HB.instance Definition _ (C : quiver) := - IsQuiver.Build C^op (fun a b => hom b a). -HB.instance Definition _ (C : precat) := - Quiver_IsPreCat.Build (C^op) (fun=> idmap) (fun _ _ _ f g => g \; f). -HB.instance Definition _ (C : cat) := PreCat_IsCat.Build (C^op) - (fun _ _ _ => compo1 _) (fun _ _ _ => comp1o _) - (fun _ _ _ _ _ _ _ => esym (compoA _ _ _)). - -HB.instance Definition _ {C : precat} {c : C} := - IsPreFunctor.Build C _ (hom c) (fun a b f g => g \; f). -Lemma hom_Fhom_subproof (C : cat) (x : C) : - PreFunctor_IsFunctor _ _ (hom x). -Proof. by split=> *; apply/funext => h; [apply: compo1 | apply: compoA]. Qed. -HB.instance Definition _ {C : cat} {c : C} := hom_Fhom_subproof c. - -Check fun (C : cat) (x : C) => hom x : C ~>_cat U. - -Lemma hom_op {C : quiver} (c : C^op) : hom c = (@hom C)^~ c. -Proof. reflexivity. Qed. - -Lemma homFhomx {C : precat} (a b c : C) (f : a ~> b) (g : c ~> a) : - (hom c <$> f) g = g \; f. -Proof. reflexivity. Qed. - -(* nary product of categories *) -Definition dprod {I : U} (C : I -> U) := forall i, C i. - -Section hom_dprod. -Context {I : U} (C : I -> quiver). -Definition dprod_hom_subdef (a b : dprod C) := forall i, a i ~> b i. -HB.instance Definition _ := IsQuiver.Build (dprod C) dprod_hom_subdef. -End hom_dprod. -Arguments dprod_hom_subdef /. - -Section precat_dprod. -Context {I : U} (C : I -> precat). -Definition dprod_idmap_subdef (a : dprod C) : a ~> a := fun=> idmap. -Definition dprod_comp_subdef (a b c : dprod C) (f : a ~> b) (g : b ~> c) : a ~> c := - fun i => f i \; g i. -HB.instance Definition _ := IsPreCat.Build (dprod C) - dprod_idmap_subdef dprod_comp_subdef. -End precat_dprod. -Arguments dprod_idmap_subdef /. -Arguments dprod_comp_subdef /. - -Section cat_dprod. -Context {I : U} (C : I -> cat). -Local Notation type := (dprod C). -Lemma dprod_is_cat : PreCat_IsCat type. -Proof. -split=> [a b f|a b f|a b c d f g h]; apply/funext => i; -[exact: comp1o | exact: compo1 | exact: compoA]. -Qed. -HB.instance Definition _ := dprod_is_cat. -End cat_dprod. - -(* binary product *) -Section hom_prod. -Context {C D : quiver}. -Definition prod_hom_subdef (a b : C * D) := ((a.1 ~> b.1) * (a.2 ~> b.2))%type. -HB.instance Definition _ := IsQuiver.Build (C * D)%type prod_hom_subdef. -End hom_prod. - -Section precat_prod. -Context {C D : precat}. -HB.instance Definition _ := IsPreCat.Build (C * D)%type (fun=> (idmap, idmap)) - (fun a b c (f : a ~> b) (g : b ~> c) => (f.1 \; g.1, f.2 \; g.2)). -End precat_prod. - -Section cat_prod. -Context {C D : cat}. -Local Notation type := (C * D)%type. -Lemma prod_is_cat : PreCat_IsCat type. -Proof. -split=> [[a1 a2] [b1 b2] [f1 f2]|[a1 a2] [b1 b2] [f1 f2]| - [a1 a2] [b1 b2] [c1 c2] [d1 d2] [f1 f2] [g1 g2] [h1 h2]]; congr (_, _) => //=; -by [exact: comp1o | exact: compo1 | exact: compoA]. -Qed. -HB.instance Definition _ := prod_is_cat. -End cat_prod. - -HB.instance Definition _ (C : U) (D : quiver) := - IsQuiver.Build (C -> D) (fun f g => forall c, f c ~> g c). - -(* naturality *) -HB.mixin Record IsNatural (C : quiver) (D : precat) (F G : C ~>_quiver D) - (n : forall c, F c ~> G c) := { - natural : forall (a b : C) (f : a ~> b), - F <$> f \; n b = n a \; G <$> f -}. -Unset Universe Checking. -HB.structure Definition Natural (C : quiver) (D : precat) - (F G : C ~>_quiver D) : Set := - { n of @IsNatural C D F G n }. -Set Universe Checking. -HB.instance Definition _ (C : quiver) (D : precat) := - IsQuiver.Build (PreFunctor.type C D) (@Natural.type C D). -HB.instance Definition _ (C D : precat) := - IsQuiver.Build (Functor.type C D) (@Natural.type C D). -Arguments natural {C D F G} n [a b] f : rename. - -Check fun (C D : cat) (F G : C ~> D) => F ~>_(C ~>_cat D) G. - -Lemma naturalx (C : precat) (D : concrete_precat) - (F G : C ~>_quiver D) (n : F ~> G) (a b : C) (f : a ~> b) g : - (concrete <$> n b) ((concrete <$> F <$> f) g) = - (concrete <$> G <$> f) ((concrete <$> n a) g). -Proof. -have /(congr1 (fun h => (concrete <$> h) g)) := natural n f. -by rewrite !Fcomp. -Qed. -Arguments naturalx {C D F G} n [a b] f. - -Lemma naturalU (C : precat) (F G : C ~>_quiver U) (n : F ~> G) - (a b : C) (f : a ~> b) g : n b (F^$ f g) = G^$ f (n a g). -Proof. exact: (naturalx n). Qed. - -Lemma natP (C D : precat) (F G : C ~>_quiver D) (n m : F ~> G) : - Natural.sort n = Natural.sort m -> n = m. -Proof. -case: n m => [/= n nP] [/= m mP] enm. -elim: _ / enm in mP *; congr Natural.Pack. -case: nP mP => [[?]] [[?]]; congr Natural.Class. -congr IsNatural.Axioms_. -exact: Prop_irrelevance. -Qed. - -Notation "F ~~> G" := (F ~>_(homs quiver) G) - (at level 99, G at level 200, format "F ~~> G"). -Notation "F ~~> G :> C ~> D" := (F ~> G :> (C ~>_quiver D)) - (at level 99, G at level 200, C, D at level 0, - format "F ~~> G :> C ~> D"). - -Definition natural_id {C D : precat} (F : C ~>_quiver D) (a : C) := \idmap_(F a). -Definition natural_id_natural (C D : cat) (F : C ~>_quiver D) : - IsNatural C D F F (natural_id F). -Proof. by constructor=> a b f; rewrite /natural_id/= compo1 comp1o. Qed. -HB.instance Definition _ C D F := @natural_id_natural C D F. - -Check fun {C D : cat} (F : C ~>_quiver D) => natural_id F : F ~> F. - -Definition natural_comp {C D : precat} (F G H : C ~>_quiver D) - (m : F ~> G) (n : G ~> H) (a : C) := m a \; n a. -Definition natural_comp_natural (C D : cat) (F G H : C ~>_quiver D) m n : - IsNatural C D F H (@natural_comp C D F G H m n). -Proof. -constructor=> a b f; rewrite /natural_comp/=. -by rewrite compoA natural -compoA natural compoA. -Qed. -HB.instance Definition _ C D F G H m n := @natural_comp_natural C D F G H m n. - -HB.instance Definition _ {C D : cat} := - Quiver_IsPreCat.Build (PreFunctor.type C D) natural_id natural_comp. -HB.instance Definition _ {C D : cat} := - Quiver_IsPreCat.Build (Functor.type C D) natural_id natural_comp. - -Lemma prefunctor_cat {C D : cat} : PreCat_IsCat (PreFunctor.type C D). -Proof. -constructor => [F G f|F G f|F G H J f g h]. -- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. -- by apply/natP/funext => a; rewrite /= /natural_comp compo1. -- by apply/natP/funext => a; rewrite /= /natural_comp compoA. -Qed. -HB.instance Definition _ C D := @prefunctor_cat C D. - -Lemma functor_cat {C D : cat} : PreCat_IsCat (Functor.type C D). -Proof. -constructor => [F G f|F G f|F G H J f g h]. -- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. -- by apply/natP/funext => a; rewrite /= /natural_comp compo1. -- by apply/natP/funext => a; rewrite /= /natural_comp compoA. -Qed. -HB.instance Definition _ C D := @functor_cat C D. - -Lemma idFmap (C : cat) (a b : C) (f : a ~> b) : idfun <$> f = f. -Proof. by []. Qed. - -Lemma compFmap (C D E : cat) (F : C ~> D) (G : D ~> E) (a b : C) (f : a ~> b) : - (G \o F) <$> f = G <$> F <$> f. -Proof. by []. Qed. - -Section left_whiskering. -Context {C D E : precat} {F G : C ~> D}. - -Definition whiskerl_fun (eta : forall c, F c ~> G c) (H : D ~> E) : - forall c, (F \; H) c ~> (G \; H) c := fun c => H <$> eta c. - -Lemma whiskerl_is_nat (eta : F ~> G) (H : D ~> E) : - IsNatural _ _ _ _ (whiskerl_fun eta H). -Proof. by constructor=> a b f; rewrite /whiskerl_fun/= -!Fcomp natural. Qed. - -HB.instance Definition _ (eta : F ~> G) (H : D ~> E) := whiskerl_is_nat eta H. -Definition whiskerl (eta : F ~> G) (H : D ~> E) : (F \; H) ~> (G \; H) := - whiskerl_fun eta H : Natural.type _ _. -End left_whiskering. - -Notation "F n" := (whiskerl F n) - (at level 58, format "F n", right associativity) : cat_scope. - -Section right_whiskering. -Context {C D E : precat} {F G : D ~> E}. - -Definition whiskerr_fun (H : C ~> D) (eta : forall d, F d ~> G d) - (c : C) : (H \; F) c ~> (H \; G) c := eta (H c). - -Lemma whiskerr_is_nat (H : C ~> D) (eta : F ~> G) : - IsNatural _ _ _ _ (whiskerr_fun H eta). -Proof. by constructor=> a b f; rewrite /whiskerr_fun/= natural. Qed. -HB.instance Definition _ (H : C ~> D) (eta : F ~> G) := whiskerr_is_nat H eta. - -Definition whiskerr (H : C ~> D) (eta : F ~> G) : (H \; F) ~> (H \; G) := - whiskerr_fun H eta : Natural.type _ _. -End right_whiskering. - -Notation "F <$o> n" := (whiskerr F n) - (at level 58, format "F <$o> n", right associativity) : cat_scope. - -Definition whisker {C : cat} {D : precat} {E : cat} - {F G : C ~>_precat D} {H K : D ~> E} - (eta : F ~> G) (mu : H ~> K) : (F \; H) ~> (G \; K) := - (eta H) \; (G <$o> mu). - -Notation "eta mu" := (whisker eta mu) - (at level 58, format "eta mu", right associativity) : cat_scope. - -Lemma whiskern1 {C D E : cat} {F G : C ~>_precat D} (eta : F ~> G) (H : D ~> E) : - eta \idmap_H = eta H. -Proof. by apply/natP/funext=> c /=; apply: compo1. Qed. - -Lemma whisker1n {C D E : cat} {F G : D ~> E} (H : C ~> D) (eta : F ~> G) : - \idmap_H eta = H <$o> eta. -Proof. -apply/natP/funext=> c /=; rewrite /natural_comp/=. -by rewrite [X in X \; _]F1 comp1o. -Qed. - -Definition delta (C D : cat) : C -> (D ~> C) := cst D. -Arguments delta C D : clear implicits. - -Definition map_delta {C D : cat} (a b : C) (f : a ~> b) : - delta C D a ~> delta C D b. -Proof. -apply: (@Natural.Pack _ _ (cst D a) (cst D b) (fun x => f)). -apply: Natural.Class; apply: (IsNatural.Build _ _ _ _ _). -by move=> a' b' ?; rewrite compo1 comp1o. -Defined. - -HB.instance Definition _ {C D : cat} := - IsPreFunctor.Build C (D ~> C) (delta C D) (@map_delta C D). - -Lemma delta_functor {C D : cat} : PreFunctor_IsFunctor _ _ (delta C D). -Proof. by constructor=> [a|a b c f g]; exact/natP. Qed. -HB.instance Definition _ C D := @delta_functor C D. - -HB.mixin Record IsMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { - unit : idfun ~~> M; - join : (M \o M)%FUN ~~> M; - bind : forall (a b : C), (a ~> M b) -> (M a ~> M b); - bindE : forall a b (f : a ~> M b), bind a b f = M <$> f \; join b; - unit_join : forall a, (M <$> unit a) \; join _ = idmap; - join_unit : forall a, join _ \; (M <$> unit a) = idmap; - join_square : forall a, M <$> join a \; join _ = join _ \; join _ -}. - -#[short(type="premonad")] -HB.structure Definition PreMonad (C : precat) := - {M of @PreFunctor C C M & IsMonad C M}. -#[short(type="monad")] -HB.structure Definition Monad (C : precat) := - {M of @Functor C C M & IsMonad C M}. - -HB.factory Record IsJoinMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { - unit : idfun ~~> M; - join : (M \o M)%FUN ~~> M; - unit_join : forall a, (M <$> unit a) \; join _ = idmap; - join_unit : forall a, join _ \; (M <$> unit a) = idmap; - join_square : forall a, M <$> join a \; join _ = join _ \; join _ -}. -HB.builders Context C M of IsJoinMonad C M. - HB.instance Definition _ := IsMonad.Build C M - (fun a b f => erefl) unit_join join_unit join_square. -HB.end. - -HB.mixin Record IsCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { - counit : M ~~> idfun; - cojoin : M ~~> (M \o M)%FUN; - cobind : forall (a b : C), (M a ~> b) -> (M a ~> M b); - cobindE : forall a b (f : M a ~> b), cobind a b f = cojoin _ \; M <$> f; - unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; - join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; - cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ -}. -#[short(type="precomonad")] -HB.structure Definition PreCoMonad (C : precat) := - {M of @PreFunctor C C M & IsCoMonad C M}. -#[short(type="comonad")] -HB.structure Definition CoMonad (C : precat) := - {M of @Functor C C M & IsCoMonad C M}. - -HB.factory Record IsJoinCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { - counit : M ~~> idfun; - cojoin : M ~~> (M \o M)%FUN; - unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; - join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; - cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ -}. -HB.builders Context C M of IsJoinCoMonad C M. - HB.instance Definition _ := IsCoMonad.Build C M - (fun a b f => erefl) unit_cojoin join_counit cojoin_square. -HB.end. - -(* yoneda *) -Section hom_repr. -Context {C : cat} (F : C ~>_cat U). - -Definition homF : C -> U := fun c => hom c ~~> F. - -Section nat. -Context (x y : C) (xy : x ~> y). - -(* Goal hom x ~~> F -> hom y ~~> F *) -Context (n : hom x ~~> F). -Definition homFhom c : hom y c ~> F c := fun g => n _ (xy \; g). - -Lemma homFhom_natural_subdef : IsNatural C U (hom y) F homFhom. -Proof. -by split=> a b f /=; apply/funext => g /=; - rewrite /homFhom !Ucompx/= !naturalU/= Fcomp. -Qed. -HB.instance Definition _ := homFhom_natural_subdef. -End nat. -Arguments homFhom / : clear implicits. - -HB.about IsPreFunctor.Build. -Check homFhom : forall x y : C, (x ~> y) -> (homF x -> homF y). -HB.instance Definition _ := IsPreFunctor.Build _ _ homF homFhom. -Lemma homF_functor_subproof : PreFunctor_IsFunctor _ _ homF. -Proof. -split=> [a|a b c f g]. - apply/funext => -[/= f natf]. - apply: natP => //=; apply: funext => b; apply: funext => g/=. - by rewrite comp1o. -apply/funext => -[/= h natf]. -apply: natP => //=; apply: funext => d; apply: funext => k/=. -by rewrite compoA. -Qed. -HB.instance Definition _ := homF_functor_subproof. - -Section pointed. -Context (c : C). -Definition hom_repr : homF c ~> F c := fun f => f _ idmap. -Arguments hom_repr /. - -Definition repr_hom (fc : F c) a : hom c a ~> F a := - fun f => F^$ f fc. -Arguments repr_hom / : clear implicits. -Lemma repr_hom_subdef (fc : F c) : IsNatural _ _ _ _ (repr_hom fc). -Proof. by split=> a b f /=; apply/funext=> x; rewrite !Ucompx/= Fcomp. Qed. -HB.instance Definition _ {fc : F c} := repr_hom_subdef fc. - -Definition repr_hom_nat : F c ~> homF c := repr_hom. - -Lemma hom_reprK : cancel hom_repr repr_hom_nat. -Proof. -move=> f; apply/natP; apply/funext => a; apply/funext => g /=. -by rewrite -naturalU/=; congr (f _ _); apply: comp1o. -Qed. -Lemma repr_homK : cancel (repr_hom : F c ~> homF c) hom_repr. -Proof. by move=> fc; rewrite /= F1. Qed. -End pointed. -Arguments hom_repr /. -Arguments repr_hom /. - -Lemma hom_repr_natural_subproof : IsNatural _ _ _ _ hom_repr. -Proof. -split=> a b f /=; apply/funext => n /=; rewrite !Ucompx/= compo1/=. -by rewrite -naturalU/=; congr (n _ _); apply/esym/comp1o. -Qed. -HB.instance Definition _ := hom_repr_natural_subproof. - -(* show this from the previous proof *) -Lemma hom_natural_repr_subproof : IsNatural _ _ _ _ repr_hom_nat. -Proof. -split=> a b f /=; apply: funext => fa /=; rewrite !Ucompx/=. -apply: natP; apply: funext => c /=; apply: funext => d /=. -by rewrite Fcomp Ucompx/=. -Qed. -HB.instance Definition _ := hom_natural_repr_subproof. - -Definition hom_repr_nat : homF ~~> F := hom_repr. -Definition repr_hom_nat_nat : F ~~> homF := repr_hom_nat. - -End hom_repr. - -(* comma categories *) -Module comma. -Section homcomma. -Context {C D E : precat} (F : C ~> E) (G : D ~> E). - -Definition type := { x : C * D & F x.1 ~> G x.2 }. -Definition hom_subdef (a b : type) := { - f : tag a ~> tag b & F <$> f.1 \; tagged b = tagged a \; G <$> f.2 - }. -HB.instance Definition _ := IsQuiver.Build type hom_subdef. -End homcomma. -Arguments hom_subdef /. -Section comma. -Context {C D E : cat} (F : C ~> E) (G : D ~> E). -Notation type := (type F G). - -Program Definition idmap_subdef (a : type) : a ~> a := @Tagged _ idmap _ _. -Next Obligation. by rewrite !F1 comp1o compo1. Qed. -Program Definition comp_subdef (a b c : type) - (f : a ~> b) (g : b ~> c) : a ~> c := - @Tagged _ (tag f \; tag g) _ _. -Next Obligation. by rewrite !Fcomp -compoA (tagged g) compoA (tagged f) compoA. Qed. -HB.instance Definition _ := IsPreCat.Build type idmap_subdef comp_subdef. -Arguments idmap_subdef /. -Arguments comp_subdef /. - -Lemma comma_homeqP (a b : type) (f g : a ~> b) : projT1 f = projT1 g -> f = g. -Proof. -case: f g => [f fP] [g +]/= eqfg; case: _ / eqfg => gP. -by congr existT; apply: Prop_irrelevance. -Qed. - -Lemma comma_is_cat : PreCat_IsCat type. -Proof. -by split=> [[a fa] [b fb] [*]|[a fa] [b fb] [*]|*]; - apply/comma_homeqP; rewrite /= ?(comp1o, compo1, compoA). -Qed. -HB.instance Definition _ := comma_is_cat. -End comma. -End comma. -Notation "F `/` G" := (@comma.type _ _ _ F G) - (at level 40, G at level 40, format "F `/` G") : cat_scope. -Notation "a /` G" := (cst unit a `/` G) - (at level 40, G at level 40, format "a /` G") : cat_scope. -Notation "F `/ b" := (F `/` cst unit b) - (at level 40, b at level 40, format "F `/ b") : cat_scope. -Notation "a / b" := (cst unit a `/ b) : cat_scope. - -Definition obj (C : quiver) : Type := C. -HB.mixin Record IsInitial {C : quiver} (i : obj C) := { - to : forall c, i ~> c; - to_unique : forall c (f : i ~> c), f = to c -}. -#[short(type="initial")] -HB.structure Definition Initial {C : quiver} := {i of IsInitial C i}. - -HB.mixin Record IsTerminal {C : quiver} (t : obj C) := { - from : forall c, c ~> t; - from_unique : forall c (f : c ~> t), f = from c -}. -#[short(type="terminal")] -HB.structure Definition Terminal {C : quiver} := {t of IsTerminal C t}. - -HB.mixin Record IsMono {C : precat} (b c : C) (f : hom b c) := { - monoP : forall (a : C) (g1 g2 : a ~> b), g1 \; f = g2 \; f -> g1 = g2 -}. -#[short(type="mono")] -HB.structure Definition Mono {C : precat} (a b : C) := {m of IsMono C a b m}. -Notation "a >~> b" := (mono a b) - (at level 99, b at level 200, format "a >~> b") : cat_scope. -Notation "C >~>_ T D" := (@mono T C D) - (at level 99, T at level 0, only parsing) : cat_scope. - -HB.mixin Record IsEpi {C : precat} (a b : C) (f : hom a b) := { - epiP : forall (c : C) (g1 g2 : b ~> c), g1 \o f = g2 \o f -> g1 = g2 -}. -#[short(type="epi")] -HB.structure Definition Epi {C : precat} (a b : C) := {e of IsEpi C a b e}. -Notation "a ~>> b" := (epi a b) - (at level 99, b at level 200, format "a ~>> b") : cat_scope. -Notation "C ~>>_ T D" := (@epi T C D) - (at level 99, T at level 0, only parsing) : cat_scope. - -#[short(type="iso")] -HB.structure Definition Iso {C : precat} (a b : C) := - {i of @Mono C a b i & @Epi C a b i}. -Notation "a <~> b" := (epi a b) - (at level 99, b at level 200, format "a <~> b") : cat_scope. -Notation "C <~>_ T D" := (@epi T C D) - (at level 99, T at level 0, only parsing) : cat_scope. - -Definition comp1F {C D : cat} (F : C ~> D) : idmap \; F = F. -Proof. by apply/functorP=> a b f; rewrite funext_frefl/= compFmap. Qed. - -Definition compF1 {C D : cat} (F : C ~> D) : F \; idmap = F. -Proof. by apply/functorP=> a b f; rewrite funext_frefl/= compFmap. Qed. - -Definition feq {C : precat} {a b : C} : a = b -> a ~> b. -Proof. by move<-; exact idmap. Defined. - -Definition feqsym {C : precat} {a b : C} : a = b -> b ~> a. -Proof. by move<-; exact idmap. Defined. - -HB.mixin Record IsLeftAdjointOf (C D : cat) (R : D ~> C) L - of @Functor C D L := { - Lphi : forall c d, (L c ~> d) -> (c ~> R d); - Lpsi : forall c d, (c ~> R d) -> (L c ~> d); - (* there should be a monad and comonad structure wrappers instead *) - Lunit : (idmap : C ~> C) ~~> R \o ((L : Functor.type C D) : C ~> D); - Lcounit : ((L : Functor.type C D) : C ~> D) \o R ~~> idmap :> D ~> D; - LphiE : forall c d (g : L c ~> d), Lphi c d g = Lunit c \; (R <$> g); - LpsiE : forall c d (f : c ~> R d), Lpsi c d f = (L <$> f) \; Lcounit d; - Lwhiskerlr : let L : C ~> D := L : Functor.type C D in - (feqsym (comp1F _) \; Lunit L) \; - (L <$o> Lcounit \; feq (compF1 _)) = idmap; - Lwhiskerrl : let L : C ~> D := L : Functor.type C D in - (feqsym (compF1 _) \; R <$o> Lunit) \; - (Lcounit R \; feq (comp1F _)) = idmap; -}. -#[short(type="left_adjoint_of")] -HB.structure Definition LeftAdjointOf (C D : cat) (R : D ~> C) := - { L of @Functor C D L & IsLeftAdjointOf C D R L}. -Arguments Lphi {C D R s} {c d}. -Arguments Lpsi {C D R s} {c d}. -Arguments Lunit {C D R s}. -Arguments Lcounit {C D R s}. - -Section LeftAdjointOf_Theory. -Variables (C D : cat) (R : D ~> C) (L : LeftAdjointOf.type R). - -Lemma Lphi_psi (c : C) (d : D) : - (@Lphi _ _ R L c d \o @Lpsi _ _ R L c d)%FUN = @id (c ~> R d). -Proof. -apply/funext => f /=; rewrite LphiE LpsiE. -Admitted. - -Lemma Lpsi_phi (c : C) (d : D) : - (@Lpsi _ _ R L c d \o @Lphi _ _ R L c d)%FUN = @id (L c ~> d). -Proof. -Admitted. -End LeftAdjointOf_Theory. - -HB.mixin Record IsRightAdjoint (D C : cat) (R : D -> C) - of @Functor D C R := { - (* we should have a wrapper instead *) - left_adjoint : C ~> D; - LLphi : forall c d, (left_adjoint c ~> d) -> (c ~> R d); - LLpsi : forall c d, (c ~> R d) -> (left_adjoint c ~> d); - LLunit : (idmap : C ~> C) ~~> (R : Functor.type D C) \o left_adjoint; - LLcounit : left_adjoint \o (R : Functor.type D C) ~~> idmap :> D ~> D; - LLphiE : forall c d (g : left_adjoint c ~> d), LLphi c d g = LLunit c \; (R <$> g); - LLpsiE : forall c d (f : c ~> R d), LLpsi c d f = (left_adjoint <$> f) \; LLcounit d; - LLwhiskerlr : - (feqsym (comp1F _) \; LLunit left_adjoint) \; - (left_adjoint <$o> LLcounit \; feq (compF1 _)) = idmap; - LLwhiskerrl : - (feqsym (compF1 _) \; (R : Functor.type D C) <$o> LLunit) \; - (LLcounit (R : Functor.type D C) \; feq (comp1F _)) = idmap; -}. -#[short(type="right_adjoint")] -HB.structure Definition RightAdjoint (D C : cat) := - { R of @Functor D C R & IsRightAdjoint D C R }. -Arguments left_adjoint {_ _}. -Arguments LLphi {D C s} {c d}. -Arguments LLpsi {D C s} {c d}. -Arguments LLunit {D C s}. -Arguments LLcounit {D C s}. - -HB.mixin Record PreCat_IsMonoidal C of PreCat C := { - onec : C; - prod : (C * C)%type ~>_precat C; -}. -#[short(type="premonoidal")] -HB.structure Definition PreMonoidal := { C of PreCat C & PreCat_IsMonoidal C }. -Notation premonoidal := premonoidal. -Arguments prod {C} : rename. -Notation "a * b" := (prod (a, b)) : cat_scope. -Reserved Notation "f <*> g" (at level 40, g at level 40, format "f <*> g"). -Notation "f <*> g" := (prod^$ (f, g)) (only printing) : cat_scope. -Notation "f <*> g" := (prod^$ ((f, g) : (_, _) ~> (_, _))) - (only parsing) : cat_scope. -Notation "1" := onec : cat_scope. - -Definition hom_cast {C : quiver} {a a' : C} (eqa : a = a') - {b b' : C} (eqb : b = b') : - (a ~> b) -> (a' ~> b'). -Proof. now elim: _ / eqa; elim: _ / eqb. Defined. - -HB.mixin Record PreFunctor_IsMonoidal (C D : premonoidal) F of - @PreFunctor C D F := { - fun_one : F 1 = 1; - fun_prod : forall (x y : C), F (x * y) = F x * F y; -}. -#[short(type="monoidal_prefunctor")] -HB.structure Definition MonoidalPreFunctor C D := - { F of @PreFunctor_IsMonoidal C D F }. -Arguments fun_prod {C D F x y} : rename. -(* Arguments fun_prodF {C D F x x'} f {y y'} g : rename. *) -Unset Universe Checking. -HB.instance Definition _ := IsQuiver.Build premonoidal MonoidalPreFunctor.type. -Set Universe Checking. - -HB.instance Definition _ (C : quiver) := - IsPreFunctor.Build (C * C)%type C fst - (fun (a b : C * C) (f : a ~> b) => f.1). -HB.instance Definition _ (C : quiver) := - IsPreFunctor.Build (C * C)%type C snd - (fun (a b : C * C) (f : a ~> b) => f.2). - -Definition prod3l {C : premonoidal} (x : C * C * C) : C := - (x.1.1 * x.1.2) * x.2. -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build _ C prod3l - (fun a b (f : a ~> b) => (f.1.1 <*> f.1.2) <*> f.2). - -Definition prod3r {C : premonoidal} (x : C * C * C) : C := - x.1.1 * (x.1.2 * x.2). -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build _ C prod3r - (fun a b (f : a ~> b) => f.1.1 <*> (f.1.2 <*> f.2)). - -Definition prod1r {C : premonoidal} (x : C) : C := 1 * x. -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build C C prod1r - (fun (a b : C) (f : a ~> b) => \idmap_1 <*> f). - -Definition prod1l {C : premonoidal} (x : C) : C := x * 1. -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build C C prod1l - (fun (a b : C) (f : a ~> b) => f <*> \idmap_1). - -HB.mixin Record PreMonoidal_IsMonoidal C of PreMonoidal C := { - prodA : prod3l ~~> prod3r; - prod1c : prod1r ~~> idfun; - prodc1 : prod1l ~~> idfun; - prodc1c : forall (x y : C), - prodA (x, 1, y) \; \idmap_x <*> prod1c y = prodc1 x <*> \idmap_y; - prodA4 : forall (w x y z : C), - prodA (w * x, y, z) \; prodA (w, x, y * z) = - prodA (w, x, y) <*> \idmap_z \; prodA (w, x * y, z) \; \idmap_w <*> prodA (x, y, z); -}. - -Unset Universe Checking. -#[short(type="monoidal")] -HB.structure Definition Monoidal : Set := - { C of PreMonoidal_IsMonoidal C & PreMonoidal C }. -Set Universe Checking. - -Record span (Q : quiver) (A B : Q) := Span { - bot : Q; - bot2left : bot ~> A; - bot2right : bot ~> B -}. - -Section spans. -Variables (Q : precat) (A B : Q). -Record span_map (c c' : span A B) := SpanMap { - bot_map : bot c ~> bot c'; - bot2left_map : bot_map \; bot2left c' = bot2left c; - bot2right_map : bot_map \; bot2right c' = bot2right c; -}. -HB.instance Definition _ := IsQuiver.Build (span A B) span_map. - -Lemma span_mapP (c c' : span A B) (f g : c ~> c') : - bot_map f = bot_map g <-> f = g. -Proof. -split=> [|->]//; case: f g => [/= f ? ?] [/= g + +] efg. -by elim: efg => // ? ?; congr SpanMap; apply: Prop_irrelevance. -Qed. - -End spans. - -Section spans_in_cat. -Variables (Q : cat) (A B : Q). -Definition span_idmap (c : span A B) := - @SpanMap Q A B c c idmap (comp1o _) (comp1o _). -Program Definition span_comp (c1 c2 c3 : span A B) - (f12 : c1 ~> c2) (f23 : c2 ~> c3) := - @SpanMap Q A B c1 c3 (bot_map f12 \; bot_map f23) _ _. -Next Obligation. by rewrite -compoA !bot2left_map. Qed. -Next Obligation. by rewrite -compoA !bot2right_map. Qed. -HB.instance Definition _ := IsPreCat.Build (span A B) - span_idmap span_comp. - -Lemma span_are_cats : PreCat_IsCat (span A B). -Proof. -constructor=> [a b f|a b f|a b c d f g h]. -- by apply/span_mapP => /=; rewrite comp1o. -- by apply/span_mapP => /=; rewrite compo1. -- by apply/span_mapP => /=; rewrite compoA. -Qed. -HB.instance Definition _ := span_are_cats. -End spans_in_cat. - -Record cospan (Q : quiver) (A B : Q) := Cospan { - top : Q; - left2top : A ~> top; - right2top : B ~> top -}. - -Section cospans. -Variables (Q : precat) (A B : Q). -Record cospan_map (c c' : cospan A B) := CospanMap { - top_map : top c ~> top c'; - left2top_map : left2top c \; top_map = left2top c'; - right2top_map : right2top c \; top_map = right2top c'; -}. -HB.instance Definition _ := IsQuiver.Build (cospan A B) cospan_map. - -Lemma cospan_mapP (c c' : cospan A B) (f g : c ~> c') : - top_map f = top_map g <-> f = g. -Proof. -split=> [|->]//; case: f g => [/= f ? ?] [/= g + +] efg. -by elim: efg => // ? ?; congr CospanMap; apply: Prop_irrelevance. -Qed. - -End cospans. - -Section cospans_in_cat. -Variables (Q : cat) (A B : Q). -Definition cospan_idmap (c : cospan A B) := - @CospanMap Q A B c c idmap (compo1 _) (compo1 _). -Program Definition cospan_comp (c1 c2 c3 : cospan A B) - (f12 : c1 ~> c2) (f23 : c2 ~> c3) := - @CospanMap Q A B c1 c3 (top_map f12 \; top_map f23) _ _. -Next Obligation. by rewrite compoA !left2top_map. Qed. -Next Obligation. by rewrite compoA !right2top_map. Qed. -HB.instance Definition _ := IsPreCat.Build (cospan A B) - cospan_idmap cospan_comp. - -Lemma cospan_are_cats : PreCat_IsCat (cospan A B). -Proof. -constructor=> [a b f|a b f|a b c d f g h]. -- by apply/cospan_mapP => /=; rewrite comp1o. -- by apply/cospan_mapP => /=; rewrite compo1. -- by apply/cospan_mapP => /=; rewrite compoA. -Qed. -HB.instance Definition _ := cospan_are_cats. -End cospans_in_cat. - -HB.mixin Record isPrePullback (Q : precat) (A B : Q) - (c : cospan A B) (s : span A B) := { - is_square : bot2left s \; left2top c = bot2right s \; right2top c; -}. -#[short(type=prepullback)] -HB.structure Definition PrePullback Q A B (c : cospan A B) := - {s of isPrePullback Q A B c s}. -Arguments prepullback {Q A B} c. - -Section prepullback. -Variables (Q : precat) (A B : Q) (c : cospan A B). -HB.instance Definition _ := - IsQuiver.Build (prepullback c) - (fun a b => (a : span A B) ~>_(span A B) (b : span A B)). -Lemma eq_prepullbackP (p q : prepullback c) : - p = q :> span _ _ <-> p = q. -Proof. -Admitted. -End prepullback. -Section prepullback. -Variables (Q : cat) (A B : Q) (csp : cospan A B). -(* TODO: why can't we do that? *) -(* HB.instance Definition _ := Cat.on (prepullback csp). *) -HB.instance Definition _ := - Quiver_IsPreCat.Build (prepullback csp) - (fun a => \idmap_(a : span A B)) - (* TODO: study how to make this coercion trigger - even when the target is not reduced to span *) - (fun a b c f g => f \; g). -Lemma prepullback_is_cat : PreCat_IsCat (prepullback csp). -Proof. (* should be copied from the cat on span *) -constructor=> [a b f|a b f|a b c d f g h]; - [exact: comp1o|exact: compo1|exact: compoA]. -Qed. -End prepullback. - -HB.tag Definition pb_terminal (Q : precat) - (A B : Q) (c : cospan A B) (s : prepullback c) : - obj (prepullback c) := s. - -#[wrapper] -HB.mixin Record prepullback_isTerminal (Q : precat) - (A B : Q) (c : cospan A B) - (s : span A B) of isPrePullback Q A B c s := { - prepullback_terminal : - IsTerminal (prepullback c) (pb_terminal s) -}. -#[short(type="pullback"), verbose] -HB.structure Definition Pullback (Q : precat) - (A B : Q) (c : cospan A B) := - {s of isPrePullback Q A B c s - & IsTerminal (prepullback c) (pb_terminal s) }. - -Inductive walking_cospan := Top | Left | Right. -Definition walking_cospan_hom (x y : walking_cospan) := match x, y with - | Top, Top | Left, Left | Right, Right | - Left, Top | Right, Top => Datatypes.unit - | _, _ => False - end. - -HB.instance Definition _ := - IsQuiver.Build walking_cospan walking_cospan_hom. - -Definition walking_cospan_id (x : walking_cospan) : x ~> x. -Proof. by case: x; constructor. Defined. - -Definition walking_cospan_comp (x y z : walking_cospan) : - (x ~> y) -> (y ~> z) -> (x ~> z). -Proof. by case: x y z => [] [] []. Defined. - -HB.instance Definition _ := Quiver_IsPreCat.Build walking_cospan - walking_cospan_id walking_cospan_comp. - -Lemma walking_cospan_cat : PreCat_IsCat walking_cospan. -Proof. by constructor=> [[] []|[] []|[] [] [] []]// []. Qed. -HB.instance Definition _ := walking_cospan_cat. - -Section Pullback_Natural. -Context (C : cat) (A B : C) (csp : cospan A B). - -Definition cspF (x : walking_cospan) : C := - match x with Left => A | Right => B | Top => top csp end. - -Definition cspFhom : forall (x y : walking_cospan), - (x ~> y) -> cspF x ~> cspF y. -Proof. -move=> [] []//. -- move=> _; exact: idmap. -- move=> _; exact: left2top csp. -- move=> _; exact: idmap. -- move=> _; exact: right2top csp. -- move=> _; exact: idmap. -Defined. - -HB.instance Definition _ := IsPreFunctor.Build _ _ cspF cspFhom. -Lemma cspF_functor : PreFunctor_IsFunctor _ _ cspF. -Proof. -by constructor=> [[]|[] [] []]//= [] []//=; - rewrite ?(compo1, comp1o)//. -Qed. -HB.instance Definition _ := cspF_functor. - -Section prepullback2natural. -Variable (p : prepullback csp). - -Definition wcsp w : cst walking_cospan (bot p) w ~> cspF w. -Proof. -case: w; rewrite /cst /=. -- exact: (bot2left _ \; left2top _). -- exact: bot2left. -- exact: bot2right. -Defined. - -Lemma wcsp_natural : IsNatural _ _ _ _ wcsp. -Proof. -constructor=> - [] [] //= [] /=; rewrite ?(comp1o, compo1)//=. -exact: is_square. -Qed. - -End prepullback2natural. - -Section natural2prepullback. -Variables (c : C) (n : cst walking_cospan c ~~> cspF). - -Definition s := {| bot := c; bot2left := n Left; bot2right := n Right |}. - -Lemma s_prepullback : isPrePullback _ _ _ csp s. -Proof. -constructor => /=. -have p := natural n (tt : Right ~> Top). -have /esym q := natural n (tt : Left ~> Top). -exact: etrans q p. -Qed. - -End natural2prepullback. - -End Pullback_Natural. -Notation square u v f g := - (isPrePullback _ _ _ (Cospan f g) (Span u v)). -Notation pbsquare u v f g := - (Pullback _ (Cospan f g) (Span u v)). -Notation pb s := (prepullback_isTerminal _ _ _ _ s). - -Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). - -(**********************************************************************) - -Section th_of_pb. -Variables (Q : cat) (A B C D E F : Q). -Variables (f : A ~> D) (g : B ~> D) (h : C ~> A). -Variables (u : E ~> A) (v : E ~> B) (w : F ~> C) (z : F ~> E). -Variable (uvfg : pbsquare u v f g). - -Theorem pbsquarec_compP : - pbsquare w z h u <=> pbsquare w (z \; v) (h \; f) g. -Proof. -split=> [] sq. - - have @sq_ispb : pullback (Cospan h u) := HB.pack (Span w z) sq. - have @uvfg_ispb : pullback (Cospan f g) := HB.pack (Span u v) uvfg. - have /=E2 := @is_square _ _ _ _ sq_ispb. - have /=E1 := @is_square _ _ _ _ uvfg_ispb. - - have p1 : @isPrePullback Q C B (Cospan (h \; f) g) (Span w (z \; v)). - by constructor; rewrite /= compoA E2 -compoA E1 compoA. - pose big_black_square : prepullback (Cospan (h \; f) g) := - HB.pack (Span w (z \; v)) p1. - - have @from : forall - (big_red_square : prepullback {| top := D; left2top := h \; f; right2top := g |}), - big_red_square ~> pb_terminal big_black_square. - - move=> big_red_square; unfold pb_terminal. - - have /= := @is_square _ _ _ _ big_red_square. - - pose F' := bot big_red_square. - set w' : F' ~> C := bot2left big_red_square. - set z' : F' ~> B := bot2right big_red_square. - move=> E3. - - have xxx : isPrePullback Q A B (Cospan f g) (Span (w' \; h) z'). - by constructor=> /=; rewrite -compoA E3. - pose red_black_square : prepullback (Cospan f g) := - HB.pack (Span (w' \; h) z') xxx. - have := @from_unique _ (pb_terminal uvfg_ispb) red_black_square. - set blue := @from _ (pb_terminal uvfg_ispb) red_black_square. - move=> blue_unique. - - have p3 : @isPrePullback Q C E (Cospan h u) (Span w' (bot_map blue)). - by constructor; rewrite /= (bot2left_map blue). (* buggy unifier without blue *) - pose blue_red_black_square : prepullback (Cospan h u) := - HB.pack (Span w' (bot_map blue)) p3. - - pose red := @from _ (pb_terminal sq_ispb) blue_red_black_square. - - admit. - - - - have p2 : prepullback_isTerminal.axioms_ Q C B (Cospan (h \; f) g) (Span w (z \; v)) p1. - constructor. econstructor=> /=. - admit. - - by HB.from p1 p2. - -Admitted. - -End th_of_pb. - - -Module test. - -Section test. -Variables (Q : precat) (A B : Q) (c : cospan A B). -Variable (p : pullback c). -Check pb_terminal p : terminal _. - -End test. -End test. - - -(********************************************************************) -(********************************************************************) - Notation "'sigma' x .. y , p" := (sigT (fun x => .. (sigT (fun y => p)) ..)) (at level 200, x binder, right associativity, format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") : type_scope. + (*** CATEGORIES WITH PULLBACKS *) (* category with all prepullbacks *) From deb0352fe8dbc165c5bf292244f791aecb3d1860 Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Wed, 17 Jan 2024 17:02:21 +0100 Subject: [PATCH 127/147] updated encatI.v --- theories/encatI.v | 259 +++++++++++++++- theories/encatI0.v | 757 +-------------------------------------------- 2 files changed, 263 insertions(+), 753 deletions(-) diff --git a/theories/encatI.v b/theories/encatI.v index 08b4fbea2..043d6ce9e 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -1449,11 +1449,6 @@ Definition l_hcomp (T: SDCat.type) (a0 a1 a2: T) (h0: hhom a0 a1) (h1: hhom a1 a2) : D1obj T := @TT2 T _ a0 a2 (h0 \; h1). -Notation "'sigma' x .. y , p" := - (sigT (fun x => .. (sigT (fun y => p)) ..)) - (at level 200, x binder, right associativity, - format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") - : type_scope. (** DPobj quiver *) Definition DP_hom (T: STUFunctor.type) (x y: DPobj T) := @@ -1925,5 +1920,259 @@ HB.mixin Record IsDCat_UA T of CFunctor T := { @hom (HHomSet T) (@HO T (@hhom T) a0 a3 hh2) (@HO T (@hhom T) a0 a3 hh1) }. +*) + +(*********************************************************************) + +Program Definition brel_fcast {X Y C : Type} {F: X -> C} {G: Y -> C} + {a1 b1: X} {a2 b2: Y} {R: C -> C -> Type} + (e1: F a1 = G a2) (e2: F b1 = G b2) : + R (G a2) (G b2) = R (F a1) (F b1). +rewrite e1. +rewrite e2. +auto. +Defined. + +Program Definition recast2 {X Y C : Type} {F: X -> C} {G: Y -> C} + {a1 b1: X} {a2 b2: Y} {R: C -> C -> Type} + (e1: F a1 = G a2) (e2: F b1 = G b2) + (x: R (G a2) (G b2)) : R (F a1) (F b1). +rewrite -(brel_fcast e1 e2). +exact x. +Defined. + +Program Definition brel_fcast_h {X Y C : Type} {F: X -> C} {G: Y -> C} + {a1 b1: X} {a2 b2: Y} {R: C -> C -> Type} + (e1: F a1 = G a2) (e2: F b1 = G b2) + (x: R (G a2) (G b2)) (P: forall T: Type, T -> Prop) : + P _ x = P _ (recast2 e1 e2 x). +unfold recast2. +unfold eq_rect. +unfold brel_fcast. +unfold eq_ind_r. +unfold eq_ind. +unfold eq_sym. +dependent destruction e1. +dependent destruction e2. +auto. +Defined. + +Program Definition brel_fcast_3h {X Y C : Type} {F: X -> C} {G: Y -> C} + {a1 b1 c1: X} {a2 b2 c2: Y} {R: C -> C -> Type} + (e1: F a1 = G a2) (e2: F b1 = G b2) (e3: F c1 = G c2) + (x: R (G a2) (G b2)) (y: R (G b2) (G c2)) (z: R (G a2) (G c2)) + (P: forall T1 T2 T3: Type, T1 -> T2 -> T3 -> Prop) : + P _ _ _ x y z = P _ _ _ (recast2 e1 e2 x) (recast2 e2 e3 y) (recast2 e1 e3 z). +unfold recast2. +unfold eq_rect. +unfold brel_fcast. +unfold eq_ind_r. +unfold eq_ind. +unfold eq_sym. +dependent destruction e1. +dependent destruction e2. +dependent destruction e3. +auto. +Defined. + +Program Definition brel_fcast_3hh {X Y C : Type} {F: X -> C} {G: Y -> C} + {a1 b1 c1: X} {a2 b2 c2: Y} {R: C -> C -> Type} + (e1: F a1 = G a2) (e2: F b1 = G b2) (e3: F c1 = G c2) + (x: R (G a2) (G b2)) (y: R (G b2) (G c2)) (z: R (G a2) (G c2)) + (P: forall (d1 d2 d3: C), R d1 d2 -> R d2 d3 -> R d1 d3 -> Prop) : + P _ _ _ x y z = P _ _ _ (recast2 e1 e2 x) (recast2 e2 e3 y) (recast2 e1 e3 z). +unfold recast2. +unfold eq_rect. +unfold brel_fcast. +unfold eq_ind_r. +unfold eq_ind. +unfold eq_sym. +dependent destruction e1. +dependent destruction e2. +dependent destruction e3. +auto. +Defined. + +Program Definition recast2_h {X Y C : Type} {F: X -> C} {G: Y -> C} + {a1 b1: X} {a2 b2: Y} {R: C -> C -> Type} + (e1: F a1 = G a2) (e2: F b1 = G b2) + (x: R (G a2) (G b2)) (P: forall T: Type, T -> Prop) + (p: P _ x) : P _ (recast2 e1 e2 x). +rewrite -(brel_fcast_h e1 e2). +exact p. +Defined. + +Program Definition recast2_3h {X Y C : Type} {F: X -> C} {G: Y -> C} + {a1 b1 c1: X} {a2 b2 c2: Y} {R: C -> C -> Type} + (e1: F a1 = G a2) (e2: F b1 = G b2) (e3: F c1 = G c2) + (x: R (G a2) (G b2)) (y: R (G b2) (G c2)) (z: R (G a2) (G c2)) + (P: forall T1 T2 T3: Type, T1 -> T2 -> T3 -> Prop) + (p: P _ _ _ x y z) : + P _ _ _ (recast2 e1 e2 x) (recast2 e2 e3 y) (recast2 e1 e3 z). +rewrite -(brel_fcast_3h e1 e2 e3). +exact p. +Defined. + +Program Definition recast2_3hh {X Y C : Type} {F: X -> C} {G: Y -> C} + {a1 b1 c1: X} {a2 b2 c2: Y} {R: C -> C -> Type} + (e1: F a1 = G a2) (e2: F b1 = G b2) (e3: F c1 = G c2) + (x: R (G a2) (G b2)) (y: R (G b2) (G c2)) (z: R (G a2) (G c2)) + (P: forall (d1 d2 d3: C), R d1 d2 -> R d2 d3 -> R d1 d3 -> Prop) + (p: P _ _ _ x y z) : + P _ _ _ (recast2 e1 e2 x) (recast2 e2 e3 y) (recast2 e1 e3 z). +rewrite -(brel_fcast_3hh e1 e2 e3). +exact p. +Defined. + +Program Definition recast_hom {X Y C : precat} {F: X -> C} {G: Y -> C} + {a1 b1: X} {a2 b2: Y} {R: C -> C -> Type} + (e1: F a1 = G a2) (e2: F b1 = G b2) + (x: (G a2) ~> (G b2)) : (F a1) ~> (F b1). +eapply recast2; eauto. +Defined. + +Definition recast21 {X Y C : Type} {F: X -> C} {G: Y -> C} + {R: C -> C -> Type} {a b: (X * Y)} + (e: (F (fst a), F (fst b)) = (G (snd a), G (snd b))) +(* + (e1: F (fst a) = G (snd a)) (e2: F (fst b) = G (snd b)) *) + (x: R (G (snd a)) (G (snd b))) : R (F (fst a)) (F (fst b)). + destruct a as [a1 a2]. + destruct b as [b1 b2]. + inversion e; subst. + rewrite H0. + rewrite H1. + auto. +Defined. + +Definition mk_pair_eq {X Y C: Type} {F: X -> C} {G: Y -> C} {a b: (X * Y)} + (e1: F (fst a) = G (snd a)) (e2: F (fst b) = G (snd b)) : + (F (fst a), F (fst b)) = (G (snd a), G (snd b)). + destruct a as [a1 a2]. + destruct b as [b1 b2]. + simpl in *; simpl. + rewrite e1. + rewrite e2. + auto. +Defined. + +Module commaE. +Section homcommaE. +Context {C D E : precat} (F : C ~> E) (G : D ~> E). + +Definition ptype := { x : C * D & F x.1 = G x.2 }. + +Definition hom_psubdef (a b : ptype) := { + f : tag a ~> tag b & + (F <$> f.1) = (recast2 (tagged a) (tagged b) (G <$> f.2)) }. +HB.instance Definition _ := IsQuiver.Build ptype hom_psubdef. +End homcommaE. +Arguments hom_psubdef /. +Section commaE. +Context {C D E : cat} (F : C ~> E) (G : D ~> E). +Notation ptype := (ptype F G). + +Program Definition idmap_psubdef (a : ptype) : a ~> a := @Tagged _ idmap _ _. +Next Obligation. + unfold recast2. + unfold eq_rect. + unfold brel_fcast. + unfold eq_ind_r. + unfold eq_ind. + unfold eq_sym. + destruct a. + destruct x. + simpl in *; simpl. + rewrite F1. + rewrite F1. + unfold idmap. + simpl. + dependent destruction e. + auto. +Defined. + +Program Definition comp_psubdef (a b c : ptype) + (f : a ~> b) (g : b ~> c) : a ~> c := + @Tagged _ (tag f \; tag g) _ _. +Next Obligation. + destruct f as [ff ef]. + destruct g as [gg eg]. + destruct a as [aa ea]. + destruct aa as [a1 a2]. + destruct b as [bb eb]. + destruct bb as [b1 b2]. + destruct c as [cc ec]. + destruct cc as [c1 c2]. + destruct ff as [f1 f2]. + destruct gg as [g1 g2]. + + simpl; simpl in *. + + rewrite Fcomp. + rewrite Fcomp. + + rewrite ef. + rewrite eg. + clear ef eg. + + eapply (@recast2_3hh _ _ _ _ _ _ _ _ _ _ _ _ + ea eb ec (G <$> f2) (G <$> g2) (G <$> f2 \; G <$> g2) + (fun (d1 d2 d3: E) (x: d1 ~> d2) (y: d2 ~> d3) + (z: d1 ~> d3) => x \; y = z) ); auto. +Defined. + (* by rewrite !Fcomp -compoA (tagged g) compoA (tagged f) compoA. Qed. *) +HB.instance Definition _ := IsPreCat.Build ptype idmap_psubdef comp_psubdef. +Arguments idmap_psubdef /. +Arguments comp_psubdef /. + +Lemma comma_homeqP (a b : ptype) (f g : a ~> b) : projT1 f = projT1 g -> f = g. +Proof. +case: f g => [f fP] [g +]/= eqfg; case: _ / eqfg => gP. +by congr existT; apply: Prop_irrelevance. +Qed. +Lemma comma_is_cat : PreCat_IsCat ptype. +Proof. +by split=> [[a fa] [b fb] [*]|[a fa] [b fb] [*]|*]; + apply/comma_homeqP; rewrite /= ?(comp1o, compo1, compoA). +Qed. +HB.instance Definition _ := comma_is_cat. +End commaE. +End commaE. +(* +Notation "F `/` G" := (@comma.type _ _ _ F G) + (at level 40, G at level 40, format "F `/` G") : cat_scope. +Notation "a /` G" := (cst unit a `/` G) + (at level 40, G at level 40, format "a /` G") : cat_scope. +Notation "F `/ b" := (F `/` cst unit b) + (at level 40, b at level 40, format "F `/ b") : cat_scope. +Notation "a / b" := (cst unit a `/ b) : cat_scope. *) +(* +Lemma cat_pbop : HasPBop cat. + econstructor; intros. + destruct A. + destruct class as [B1 B2 B3]. + destruct B1. + destruct H. + econstructor. +Admitted. +*) +(* +Program Definition pb_cat (A B: cat) (H: cospan A B) : cat. + remember A as a. + destruct a as [a_sort a_class]. + remember B as b. + destruct b as [b_sort b_class]. + remember H as H0. + destruct H as [t l r]. + + econstructor. + instantiate (1:= sigma (x: a_sort) (y: b_sort), ). + + + remember t as t0. + destruct t as [s c]. + destruct c as [a1 a2 a3]. + econstructor. +*) diff --git a/theories/encatI0.v b/theories/encatI0.v index f6a5504d5..f02dec3ac 100644 --- a/theories/encatI0.v +++ b/theories/encatI0.v @@ -152,7 +152,7 @@ HB.structure Definition PBack2 (Q: precat) (***********************************************************************) -(*** CATEGORIES WITH PULLBACKS *) +(*** alternative CATEGORIES WITH PULLBACKS *) (* category with all pullbacks *) HB.mixin Record HasPBKop C of Cat C := { @@ -264,22 +264,23 @@ Admitted. Fail Definition iprodr {C: pbcat} {C0 : C} (X Y : iHom C0) : X *_C0 Y ~> (Y :> C) := bot2right (iprod_pb X Y). -Definition iprod_iHom {C: pbkcat} {C0: C} (X Y: @iHom C C0) : +Fail Definition iprod_iHom {C: pbkcat} {C0: C} (X Y: @iHom C C0) : @isInternalHom C C0 (X *_C0 Y) := @isInternalHom.Build C C0 (X *_C0 Y) ((iprodl X Y) \; src) ((iprodr X Y) \; tgt). -HB.instance Definition iprod_iHom' {C: pbcat} {C0: C} (X Y: @iHom C C0) : +Fail HB.instance Definition iprod_iHom' {C: pbcat} {C0: C} (X Y: @iHom C C0) : @isInternalHom C C0 (X *_C0 Y) := iprod_iHom X Y. (* the product as (iHom C0) object *) -Definition pbC0 (C : pbcat) (C0 : C) (X Y : iHom C0) : iHom C0 := +Fail Definition pbC0 (C : pbcat) (C0 : C) (X Y : iHom C0) : iHom C0 := (X *_C0 Y) : iHom C0. -(*** OLDER VERSION, not good *************************************) +(*** OLDER VERSION, even worse *************************************) +(* doesn't avoid repetition, comment out previous version to run *) (* PULLBACKS *) @@ -348,7 +349,8 @@ HB.structure Definition PBack2 (Q: precat) (*** CATEGORIES WITH PULLBACKS *) -(* category with all pullbacks *) +(* category with all pullbacks + This is not right, but shows the idea *) HB.mixin Record HasPBKop C of Cat C := { pbkop : forall {L R T: C} (l: L ~> T) (r: R ~> T), @pspan C L R T l r }. @@ -414,7 +416,7 @@ Notation "X *_ C0 Y" := (@iprod _ C0 X Y) (at level 99, C0 at level 0) : cat_scope. -(*** END OF IT *) +(************************** END OF IT ********************) (* @@ -517,744 +519,3 @@ HB.structure Definition PrePullback Q A B (c : cospan A B) := Arguments prepullback {Q A B} c. *) -(************************************************************************) - -(**** INTERNAL CATEGORIES - NEW DEFINITION *) - -(* Defining internal hom objects. - C0 and C1 are objects of C. - C0 is the object of objects, - C1 is the object of morphims (and the subject). - this will allow to define a generic _ *_C0 _ notation - by recognizing the structure of hom objects on the LHS and RHS - Basically, w.r.t. double categories, C1 represents 'horizontal' - 1-morpshisms and the D1 category, whereas C0 represents the objects - of the base D0 category. *) -HB.mixin Record isInternalHom {C: quiver} (C0 : C) (C1 : obj C) := { - src : C1 ~> C0; tgt : C1 ~> C0 -}. -#[short(type="iHom")] -HB.structure Definition InternalHom {C: quiver} (C0 : C) := - { C1 of isInternalHom C C0 C1 }. - -Notation "X ':>' C" := (X : obj C) (at level 60, C at next level). - -(* HB.instance Definition _ (T : quiver) := Quiver.on (obj T). *) -(* HB.instance Definition _ (T : precat) := PreCat.on (obj T). *) -(* HB.instance Definition _ (T : cat) := Cat.on (obj T). *) -(* HB.instance Definition _ (T : pbcat) := PBCat.on (obj T). *) - -(* constructs the pullback from the cospan given by target and source. - Type-level construction: X and Y are two instances of the morphism - object, specified by (iHom C0), and are objects of (obj C). Here - 'iprod' is just an object of (obj C). The cospan is given by the - target of X and the source of Y. The pullback provides a commuting - square on the cospan, which basically ensures that the morphisms in - X and Y can be composed. *) -Definition iprod_pb {C: pbcat} {C0 : C} (X Y : iHom C0) : - span (X :> C) (Y :> C) := - pbk _ _ (Cospan (tgt : (X :> C) ~> C0) (src : (Y :> C) ~> C0)). - -Definition iprod {C: pbcat} {C0 : obj C} (X Y : iHom C0) : obj C := - bot (@iprod_pb C C0 X Y). -Notation "X *_ C0 Y" := (@iprod _ C0 (X : iHom C0) (Y : iHom C0)) - (at level 99, C0 at level 0, only parsing) : cat_scope. -Notation "X *_ C0 Y" := (@iprod _ C0 X Y) - (at level 99, C0 at level 0) : cat_scope. - -(* -(1) Defines pullback square (iprod_pb) - - X --- tgt -----> C0 - ^ ^ - | | - bot2left src - | | - X*Y - bot2right -> Y - - -(2) Defines source and target of the product (iprod_iHom) - - X --- src -----> C0 - ^ ^ - | | - iprodl tgt - | | - X*Y -- iprodr ---> Y -*) - -(* left and right projection morphisms of the product *) -Definition iprodl {C: pbcat} {C0 : C} (X Y : iHom C0) : - X *_C0 Y ~> (X :> C) := bot2left (iprod_pb X Y). -Definition iprodr {C: pbcat} {C0 : C} (X Y : iHom C0) : - X *_C0 Y ~> (Y :> C) := bot2right (iprod_pb X Y). - -(* Given (iHom C0) instances X and Y, we want to say that (X *_C0 Y) -is also an instance of (iHom C0). X and Y represent composable -morphisms, as by pullback properties, the diagram (1) commutes. -source and target are obtained by composing with product projections -(2) *) -Definition iprod_iHom {C: pbcat} {C0: C} (X Y: @iHom C C0) : - @isInternalHom C C0 (X *_C0 Y) := - @isInternalHom.Build C C0 (X *_C0 Y) - ((iprodl X Y) \; src) - ((iprodr X Y) \; tgt). - -HB.instance Definition iprod_iHom' {C: pbcat} {C0: C} (X Y: @iHom C C0) : - @isInternalHom C C0 (X *_C0 Y) := iprod_iHom X Y. - -(* the product as (iHom C0) object *) -Definition pbC0 (C : pbcat) (C0 : C) (X Y : iHom C0) : iHom C0 := - (X *_C0 Y) : iHom C0. - -(* we also define the trivial internal hom type *) -HB.instance Definition trivial_iHom {C: pbcat} {C0: C} : - @isInternalHom C C0 C0 := - isInternalHom.Build C C0 C0 idmap idmap. - -(**) - -Definition trivial_iHom' {C: pbcat} {C0: C} : @iHom C C0 := - InternalHom.Pack (InternalHom.Class (@trivial_iHom C C0)). - -Definition trivial_iprod_iHom {C: pbcat} {C0: C} : - @isInternalHom C C0 ((@trivial_iHom' C C0) *_C0 (@trivial_iHom' C C0)) := - @iprod_iHom' C C0 (@trivial_iHom' C C0) (@trivial_iHom' C C0). - -Definition trivial_iprod_iHom' {C: pbcat} {C0: C} : @iHom C C0 := - InternalHom.Pack (InternalHom.Class (@trivial_iprod_iHom C C0)). - -(**) - -(* we need internal hom morphisms: -the ones that preserve sources and targets. -basically, we recast morphisms in (obj C) into some in (@iHom C C0), -i.e. into morphism between copies of C1 *) -HB.mixin Record IsInternalHomHom {C: pbcat} (C0 : C) - (C1 C1' : @iHom C C0) (f : (C1 :> C) ~> (C1' :> C)) := { - hom_src : f \; (@src C C0 C1') = (@src C C0 C1); - hom_tgt : f \; tgt = tgt; -}. -#[short(type="iHomHom")] -HB.structure Definition InternalHomHom {C: pbcat} - (C0 : C) (C1 C1' : @iHom C C0) := - { f of @IsInternalHomHom C C0 C1 C1' f }. - -(* internal homs form a category, - the morphisms are the one that preserve source and target *) -HB.instance Definition iHom_quiver {C: pbcat} (C0 : C) : - IsQuiver (@iHom C C0) := - IsQuiver.Build (@iHom C C0) (@iHomHom C C0). -Print iHom_quiver. - -Program Definition pre_iHom_id {C: pbcat} (C0 : C) (C1 : @iHom C C0) : - @IsInternalHomHom C C0 C1 C1 idmap := - @IsInternalHomHom.Build C C0 C1 C1 idmap _ _. -Obligation 1. -setoid_rewrite comp1o; reflexivity. -Defined. -Obligation 2. -setoid_rewrite comp1o; reflexivity. -Defined. - -Program Definition iHom_id {C: pbcat} (C0 : C) (C1 : @iHom C C0) : - C1 ~>_(@iHom C C0) C1 := - @InternalHomHom.Pack C C0 C1 C1 idmap _. -(* -The term "pre_iHom_id C1" has type "IsInternalHomHom.phant_axioms idmap" -while it is expected to have type "InternalHomHom.axioms_ ?sort". -*) -Obligation 1. -econstructor. -eapply (@pre_iHom_id C C0 C1). -Defined. - -Program Definition pre_iHom_comp {C: pbcat} (C0 : C) (C1 C2 C3: @iHom C C0) - (f: C1 ~>_(@iHom C C0) C2) (g: C2 ~>_(@iHom C C0) C3) : - @IsInternalHomHom C C0 C1 C3 (f \; g) := - @IsInternalHomHom.Build C C0 C1 C3 (f \; g) _ _. -Obligation 1. -setoid_rewrite <- compoA. -repeat (setoid_rewrite hom_src); auto. -Defined. -Obligation 2. -setoid_rewrite <- compoA. -repeat (setoid_rewrite hom_tgt); auto. -Defined. - -Program Definition iHom_comp {C: pbcat} (C0 : C) (C1 C2 C3: @iHom C C0) - (f: C1 ~>_(@iHom C C0) C2) (g: C2 ~>_(@iHom C C0) C3) : - C1 ~>_(@iHom C C0) C3 := - @InternalHomHom.Pack C C0 C1 C3 (f \; g) _. -Obligation 1. -econstructor. -eapply (@pre_iHom_comp C C0 C1 C2 C3 f g). -Defined. - -Program Definition iHom_precat {C: pbcat} (C0 : C) : - Quiver_IsPreCat (@iHom C C0) := - Quiver_IsPreCat.Build (@iHom C C0) _ _. -Obligation 1. -eapply (@iHom_id C C0 a). -Defined. -Obligation 2. -eapply (@iHom_comp C C0 a b c0 X X0). -Defined. - -HB.instance Definition iHom_precat' {C: pbcat} (C0 : C) := iHom_precat C0. - -Lemma iHom_LeftUnit_lemma (C : pbcat) (C0 : C) - (a b : iHom C0) (f : a ~> b) : idmap \; f = f. -unfold idmap; simpl. -unfold iHom_precat_obligation_1. -unfold comp; simpl. -unfold iHom_precat_obligation_2. -unfold iHom_comp. -remember f as f1. -remember a as a1. -remember b as b1. -destruct f as [ff class]. -destruct a as [Ca class_a]. -destruct b as [Cb class_b]. -destruct class_a as [IMa]. -destruct class_b as [IMb]. -destruct class as [IM]. -destruct IMa. -destruct IMb. -destruct IM. -unfold obj in *. -simpl in *; simpl. - -eassert ( forall x, exists y, - {| - InternalHomHom.sort := idmap \; f1; - InternalHomHom.class := x - |} = - {| - InternalHomHom.sort := f1; - InternalHomHom.class := y - |} ) as A2. -{ rewrite Heqf1; simpl. - rewrite comp1o. - intros. - destruct x as [X]. - econstructor. - destruct X. - reflexivity. -}. - -setoid_rewrite Heqf1 at 3. -specialize (A2 (iHom_comp_obligation_1 (iHom_id a1) f1)). -destruct A2. -rewrite H. - -inversion Heqf1; subst. -simpl. -destruct x as [IM]. -destruct IM. - -assert (hom_src0 = hom_src1) as D1. -{ eapply Prop_irrelevance. } - -assert (hom_tgt0 = hom_tgt1) as D2. -{ eapply Prop_irrelevance. } - -rewrite D1. -rewrite D2. -reflexivity. -Qed. - -Lemma iHom_RightUnit_lemma (C : pbcat) (C0 : C) - (a b : iHom C0) (f : a ~> b) : f \; idmap = f. -unfold idmap; simpl. -unfold iHom_precat_obligation_1. -unfold comp; simpl. -unfold iHom_precat_obligation_2. -unfold iHom_comp. -remember f as f1. -remember a as a1. -remember b as b1. -destruct f as [ff class]. -destruct a as [Ca class_a]. -destruct b as [Cb class_b]. -destruct class_a as [IMa]. -destruct class_b as [IMb]. -destruct class as [IM]. -destruct IMa. -destruct IMb. -destruct IM. -unfold obj in *. -simpl in *; simpl. - -eassert ( forall x, exists y, - {| - InternalHomHom.sort := f1 \; idmap; - InternalHomHom.class := x - |} = - {| - InternalHomHom.sort := f1; - InternalHomHom.class := y - |} ) as A2. -{ rewrite Heqf1; simpl. - rewrite compo1. - intros. - destruct x as [X]. - econstructor. - destruct X. - reflexivity. -} - -setoid_rewrite Heqf1 at 3. -specialize (A2 (iHom_comp_obligation_1 f1 (iHom_id b1))). -destruct A2. -rewrite H. - -inversion Heqf1; subst. -simpl. -destruct x as [IM]. -destruct IM. - -assert (hom_src0 = hom_src1) as D1. -{ eapply Prop_irrelevance. } - -assert (hom_tgt0 = hom_tgt1) as D2. -{ eapply Prop_irrelevance. } - -rewrite D1. -rewrite D2. -reflexivity. -Qed. - -Lemma iHom_Assoc_lemma {C : pbcat} (C0 : C) - (a b c d : iHom C0) (f : a ~> b) (g : b ~> c) (h : c ~> d) : - f \; g \; h = (f \; g) \; h. - unfold comp; simpl. - unfold iHom_precat_obligation_2; simpl. - unfold iHom_comp; simpl. - remember f as f1. - remember g as g1. - remember h as h1. - destruct f as [M_f class_f]. - destruct g as [M_g class_g]. - destruct h as [M_h class_h]. - destruct class_f as [IM_f]. - destruct class_g as [IM_g]. - destruct class_h as [IM_h]. - destruct IM_f. - destruct IM_g. - destruct IM_h. - unfold obj in *; simpl in *; simpl. - - eassert ( forall x y, - {| InternalHomHom.sort := f1 \; g1 \; h1; - InternalHomHom.class := x |} = - {| InternalHomHom.sort := (f1 \; g1) \; h1; - InternalHomHom.class := y |} ) as A2. - { rewrite Heqf1; simpl. - rewrite compoA. - intros. - destruct x as [X]. - destruct y as [Y]. - destruct X. - destruct Y. - - assert (hom_src3 = hom_src4) as D1. - { eapply Prop_irrelevance. } - - assert (hom_tgt3 = hom_tgt4) as D2. - { eapply Prop_irrelevance. } - - rewrite D1. - rewrite D2. - reflexivity. - }. - - setoid_rewrite A2. - reflexivity. -Qed. - -Program Definition iHom_cat {C: pbcat} (C0 : C) : - PreCat_IsCat (@iHom C C0) := - PreCat_IsCat.Build (@iHom C C0) _ _ _. -Obligation 1. -eapply iHom_LeftUnit_lemma; eauto. -Qed. -Obligation 2. -eapply iHom_RightUnit_lemma; eauto. -Qed. -Obligation 3. -eapply iHom_Assoc_lemma; eauto. -Qed. - -(* Now we define an internal quiver as an object C0, - which has a C1 : iHom C0 attached to it *) -HB.mixin Record IsPreInternalQuiver (C : quiver) (C0 : obj C) := - { C1 : obj C }. -HB.structure Definition PreInternalQuiver C := - { C0 of @IsPreInternalQuiver C C0 }. - -Arguments C1 {C s}. - -#[wrapper] HB.mixin Record IsInternalQuiver (C : quiver) (C0 : obj C) of - @PreInternalQuiver C C0 := { - priv: @InternalHom C C0 (@C1 _ C0) - }. -#[short(type="iquiver")] -HB.structure Definition InternalQuiver (C : quiver) := - { C0 of IsInternalQuiver C C0 }. - -Coercion iquiver_quiver (C : quiver) (C0 : iquiver C) : C := C0 :> C. -Coercion iquiver_precat (C : precat) (C0 : iquiver C) : C := C0 :> C. -Coercion iquiver_cat (C : cat) (C0 : iquiver C) : C := C0 :> C. - -(* nested product *) -Program Definition iprodCAsc {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : - (((C1 *_C0 C2 : iHom C0) *_C0 C3) :> C) ~>_C - ((C1 *_C0 (C2 *_C0 C3 : iHom C0) : iHom C0) :> C). -Admitted. - -Lemma pbsquare_universal {C: cat} (A B T P0 P1 : C) - (t: A ~> T) (s: B ~> T) (p1: P0 ~> A) (p2: P0 ~> B) - (f: P1 ~> A) (g: P1 ~> B) : - pbsquare p1 p2 t s -> - f \; t = g \; s -> - sigma m: P1 ~> P0, f = m \; p1 /\ g = m \; p2. - intros sq E. - destruct sq as [IM1 IM2]. - - remember (Span p1 p2) as Spn0. - remember (@Cospan C A B T t s) as Csp. - remember (@Span C A B P1 f g) as Spn1. - - destruct IM1 as [IM3]. - destruct IM2 as [IM4]. - - assert (bot2left Spn1 \; left2top Csp = bot2right Spn1 \; right2top Csp) - as K1. - { unfold bot2left, bot2right. - rewrite HeqCsp. - rewrite HeqSpn1. - simpl; auto. - } - remember ( @isPrePullback.Build C A B Csp Spn1 K1) as Pb1. - assert (PrePullback.axioms_ Csp Spn1) as Pb2. - { econstructor. - exact Pb1. } - remember ( @PrePullback.Pack C A B Csp Spn1 Pb2) as PB. - - destruct IM4 as [IM5 IM6]. - clear IM6. - specialize (IM5 PB). - - inversion HeqSpn1; subst. - simpl in *. - clear H K1. - - unfold pb_terminal in *. - destruct Pb2 as [IM]. - destruct IM. - simpl in *. - - destruct IM5. - simpl in *. - - econstructor. - instantiate (1:= bot_map0). - split; auto. -Qed. - -Lemma pbquare_universal_aux1 {C: cat} (A0 A1 B0 B1 P0 P1 T : C) - (t: A0 ~> T) (s: B0 ~> T) (p01: P0 ~> A0) (p02: P0 ~> B0) - (f: A1 ~> A0) (g: B1 ~> B0) (p11: P1 ~> A1) (p12: P1 ~> B1) : - pbsquare p01 p02 t s -> - p11 \; f \; t = p12 \; g \; s -> - sigma m: P1 ~> P0, p11 \; f = m \; p01 /\ p12 \; g = m \; p02. - intros. - eapply pbsquare_universal; eauto. - setoid_rewrite <- compoA; auto. -Qed. - -(* Lemma is_pullback_in_pbcat {C: pbcat} *) - -(* -Set Debug "unification". -Lemma ... -Proof. - Fail ... -*) - -Lemma pbk_eta {C: pbcat} {C0} (X Y: iHom C0) : - (pbk (X :> C) (Y :> C) (Cospan (@tgt C C0 X) (@src C C0 Y))) = - (Span (iprodl X Y) (iprodr X Y)). - unfold iprodl, iprodr, iprod. - unfold iprod_pb; simpl. - destruct (pbk (X :> C) (Y :> C) - {| top := C0; left2top := tgt; right2top := src |}). - simpl; auto. -Qed. - -Lemma pbk_pullback_is_pullback {C: pbcat} {C0} (X Y: iHom C0) : - Pullback C (Cospan (@tgt C C0 X) (@src C C0 Y)) - (pbk (X :> C) (Y :> C) (Cospan (@tgt C C0 X) (@src C C0 Y))) = - Pullback C (Cospan (@tgt C C0 X) (@src C C0 Y)) - (Span (iprodl X Y) (iprodr X Y)). - rewrite pbk_eta; auto. -Qed. - -Lemma pbsquare_is_pullback {C: pbcat} {C0} (X Y: iHom C0) : - pbsquare (iprodl X Y) (iprodr X Y) (@tgt C C0 X) (@src C C0 Y) = - Pullback C (Cospan (@tgt C C0 X) (@src C C0 Y)) - (pbk (X :> C) (Y :> C) (Cospan (@tgt C C0 X) (@src C C0 Y))). - rewrite pbk_pullback_is_pullback; auto. -Qed. - -Lemma pbsquare_is_pullback_sym {C: pbcat} {C0} (X Y: iHom C0) : - Pullback C (Cospan (@tgt C C0 X) (@src C C0 Y)) - (pbk (X :> C) (Y :> C) (Cospan (@tgt C C0 X) (@src C C0 Y))) = - pbsquare (iprodl X Y) (iprodr X Y) (@tgt C C0 X) (@src C C0 Y). - rewrite pbk_pullback_is_pullback; auto. -Qed. - -Program Definition ipairC {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} - (f : x0 ~>_(iHom C0) x2) (g : x1 ~>_(iHom C0) x3) : - (x0 *_C0 x1 :> C) ~>_C (x2 *_C0 x3 :> C). - - remember (x0 *_ C0 x1 : iHom C0) as Pb1. - remember (x2 *_ C0 x3 : iHom C0) as Pb2. - - remember (@Cospan C (x0 :> C) (x1 :> C) C0 - (@tgt C C0 x0) (@src C C0 x1)) as Csp1. - - remember (@Cospan C (x2 :> C) (x3 :> C) C0 - (@tgt C C0 x2) (@src C C0 x3)) as Csp2. - - set (src0 := @src C C0 x0). - set (tgt0 := @tgt C C0 x0). - - set (src1 := @src C C0 x1). - set (tgt1 := @tgt C C0 x1). - - set (src2 := @src C C0 x2). - set (tgt2 := @tgt C C0 x2). - - set (src3 := @src C C0 x3). - set (tgt3 := @tgt C C0 x3). - - remember (@src C C0 (x0 *_C0 x1)) as src01. - remember (@tgt C C0 (x0 *_C0 x1)) as tgt01. - - remember (@src C C0 (x2 *_C0 x3)) as src23. - remember (@tgt C C0 (x2 *_C0 x3)) as tgt23. - - set (Sp1 := pbk (x0 :> C) (x1 :> C) Csp1). - set (Sp2 := pbk (x2 :> C) (x3 :> C) Csp2). - - assert (@Pullback C (x0 :> C) (x1 :> C) Csp1 Sp1) as PBa1. - { remember C as C'. - destruct C as [C class]. - destruct class as [A1 A2 A3 A4 A5 A6]. - destruct A6 as [B1]. - assert (pb (pbk (x0 :> C') (x1 :> C') Csp1)). - { inversion HeqC'; subst. - eapply B1; eauto. } - econstructor; eauto. - } - - assert (@Pullback C (x2 :> C) (x3 :> C) Csp2 Sp2) as PBa2. - { remember C as C'. - destruct C as [C class]. - destruct class as [A1 A2 A3 A4 A5 A6]. - destruct A6 as [B1]. - assert (pb (pbk (x2 :> C') (x3 :> C') Csp2)). - { inversion HeqC'; subst. - eapply B1; eauto. } - econstructor; eauto. - } - -(* assert (@Pullback C (x2 :> C) (x3 :> C) Csp2 Sp2) as PBa2. - admit. -*) - assert ((x0 *_ C0 x1) = bot Sp1) as E01. - { subst Sp1. - unfold iprod. - unfold iprod_pb. - rewrite HeqCsp1; auto. - } - - assert ((x2 *_ C0 x3) = bot Sp2) as E23. - { subst Sp2. - unfold iprod. - unfold iprod_pb. - rewrite HeqCsp2; auto. - } - - set (prj11 := @iprodl C C0 x0 x1). - set (prj12 := @iprodr C C0 x0 x1). - - set (prj21 := @iprodl C C0 x2 x3). - set (prj22 := @iprodr C C0 x2 x3). - - set (ff := prj11 \; f). - set (gg := prj12 \; g). - - assert ((f : (x0 :> C) ~>_C (x2 :> C)) \; tgt2 = tgt0) as E20. - { remember f as f1. - destruct f as [fsort fclass]. - destruct fclass as [fIM]. - destruct fIM. - inversion Heqf1; subst. - simpl in *; simpl; auto. - } - - assert ((g : (x1 :> C) ~>_C (x3 :> C)) \; src3 = src1) as E31. - { remember g as g1. - destruct g as [gsort gclass]. - destruct gclass as [gIM]. - destruct gIM. - inversion Heqg1; subst. - simpl in *; simpl; auto. - } - - assert (prj11 \; tgt0 = prj12 \; src1) as E11. - { destruct PBa1 as [C1 C2]. - destruct C1 as [C3]. - inversion HeqCsp1; subst. - simpl in *; auto. - } - - assert (ff \; tgt2 = gg \; src3) as E1. - { subst ff gg. - setoid_rewrite <- compoA. - rewrite E20. - rewrite E31. - exact E11. - } - - (* basically, follows from pbquare_universal and E1. - sordid eta-conversion issue fixed by pbsquare_is_pullback *) - assert (sigma m: ((x0 *_ C0 x1) ~>_C (x2 *_ C0 x3) :> C), - ff = m \; prj21 /\ gg = m \; prj22) as EM. - { eapply (@pbsquare_universal C) ; eauto. - - remember C as C'. - destruct C as [C class]. - destruct class as [A1 A2 A3 A4 A5 A6]. - destruct A6 as [B1]. - subst prj21 prj22. - - (* surprisingly, this does not work with pbsquare_is_pulback_sym *) - (* rewrite <- pbsquare_is_pullback_sym. *) - rewrite pbsquare_is_pullback. - inversion HeqCsp2; subst. - subst Sp2. - exact PBa2. - } - - destruct EM as [mm [EM1 EM2]]. - exact mm. -Qed. - -Notation "<( f , g )>" := (ipairC f g). - -(* An internal precategory is an internal category with two operators - that must be src and tgt preserving, i.e. iHom morphisms: identity - : C0 -> C1 (corresponding to horizontal 1-morphism identity in - double cat) and composition : C1 * C1 -> C1 (corresponding to - horizontal composition) *) -HB.mixin Record IsInternalPreCat (C : pbcat) (C0 : obj C) - of @InternalQuiver C C0 := { - iidI : (C0 : iHom C0) ~>_(iHom C0) (@C1 C C0 : iHom C0); - icompI : let C1 := @C1 C C0 : iHom C0 in - let C2 := pbC0 C1 C1 : iHom C0 in - (C2 ~>_(iHom C0) C1) -}. -#[short(type="iprecat")] -HB.structure Definition InternalPreCat (C : pbcat) := - { C0 of @IsInternalPreCat C C0 }. - -Program Definition iidC' {C : pbcat} {C0 : iprecat C} : - ((C0 : iHom C0) :> C) ~>_C - ((@C1 C C0 : iHom C0) :> C). -destruct C0; simpl in *. -destruct class as [IM1 IM2 IM3]; simpl in *. -destruct IM3; simpl in *. -exact iidI0. -Defined. -Program Definition iidC {C : pbcat} {C0 : iprecat C} : - (C0 :> C) ~>_C (@C1 C C0 :> C). -eapply iidC'; eauto. -Defined. - -Program Definition icompC {C : pbcat} {C0 : iprecat C} : - let C1 := @C1 C C0 : iHom C0 in - let C2 := pbC0 C1 C1 : iHom C0 in - ((C2 :> C) ~>_C (C1 :> C)). -destruct C0; simpl in *. -destruct class as [IM1 IM2 IM3]; simpl in *. -destruct IM3; simpl in *. -exact icompI0. -Defined. - -(* Check (iquiver Type <~> quiver). *) -(* Check (iprecat Type <~> precat). *) - -(* An internal category moreover must satisfy additional properies on -iid and icomp (associativity and unit laws) *) -#[key="C0"] - HB.mixin Record IsInternalCat (C : pbcat) (C0 : obj C) - of InternalPreCat C C0 := { - icompA1 : - (<( (@icompI C C0), - (@idmap (iHom C0) (@C1 C C0: iHom C0)) )> \; icompC) = - ((@iprodCAsc C C0 (@C1 C C0: iHom C0) _ _) \; - <( (@idmap (iHom C0) (@C1 C C0: iHom C0)), icompI )> \; icompC) ; - - icomp1l : <( @idmap (iHom C0) (@C1 C C0: iHom C0), (@iidI C C0) )> \; - icompC = @iprodl C C0 (C1 :> C) (C0 :> C); - - icomp1r : <( (@iidI C C0), @idmap (iHom C0) (@C1 C C0: iHom C0) )> \; - icompC = @iprodr C C0 (C0 :> C) (C1 :> C); - }. -#[short(type="icat")] -HB.structure Definition InternalCat (C : pbcat) := - {C0 of @IsInternalCat C C0}. -(* Check (icat Type <~> cat). *) - -(* A double category is an internal category in cat - - The objects are the objects of C0 - - The vertical maps are the maps of C0 - - The horizontal maps are the objects of C1 - - The 2-cells are the maps of C1 - - About identities: - - The identity vertical map on (x : C) is \idmap_x - - The identity horizontal map on (x : C) is iid x - - the identity 2-cell on (x : C) is iid (\idmap_x) = \idmap_(iid x) - - About compositions: - - The vertical composition of maps is the composition of C0 - - The vertical compositions of 2-cells is the composition of C1 - (and it agrees with the former because src and tgt are functors - and because iid is a iHom-map) - - The horizontal composition of maps is the object part of icomp - - The horizontal composition of 2-cells is the map part of icomp -*) -(* HB.structure' Definition DoubleCat := @InternalCat cat. *) -Axiom cat_pbop : HasPBop cat. -HB.instance Definition _ := cat_pbop. - -Axiom cat_preb : - forall (a b: cat) (c: cospan a b), isPrePullback cat a b c (@pbk cat a b c). -HB.instance Definition _ (a b: cat) (c: cospan a b) := @cat_preb a b c. -Axiom cat_pb : - forall (a b: cat) (c: cospan a b), - prepullback_isTerminal cat a b c (@pbk cat a b c). -HB.instance Definition _ (a b: cat) (c: cospan a b) := @cat_pb a b c. - -(* basically, the internal category adds the D1 category to the base -D0 category, which is C0 (an object of cat, which is shown to have -pullbacks) *) -Definition doublecat := icat cat. - -(* Check (doublecat <~> ???) *) - From 11e40e2289c952421f6fc95da748cb8e9d57829a Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Thu, 18 Jan 2024 14:06:06 +0100 Subject: [PATCH 128/147] updated encatI.v --- theories/encatI.v | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/theories/encatI.v b/theories/encatI.v index 043d6ce9e..82db9882f 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -1921,6 +1921,12 @@ HB.mixin Record IsDCat_UA T of CFunctor T := { (@HO T (@hhom T) a0 a3 hh1) }. *) +(* +Class pip (Y: Type) := {}. +Class pip2 (T: Type) := {}. + +Instance pipO (T1 T2: Type) : pip T1 -> pip T2 -> pip2 (T1 + T2)%type. +*) (*********************************************************************) From 429249469f77710e22f38eb0cee30a0f4edda386 Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Fri, 19 Jan 2024 11:50:45 +0100 Subject: [PATCH 129/147] updated encatI.v --- theories/encatI.v | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/theories/encatI.v b/theories/encatI.v index 82db9882f..ba2e5c68d 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -101,8 +101,6 @@ Set Universe Checking. (*** CATEGORIES WITH PULLBACKS *) -(* Local Open Scope type_scope. *) - (* category with all prepullbacks *) (* Ideally span is in fact expanded and the final mixin has a pb : forall A B, cospan A B -> C @@ -590,7 +588,8 @@ Lemma jm_pbsquare_universal {C: cat} (A B T P0 P1 P2 : C) (e: P0 = P2) : sigma m: P1 ~> P2, f = m \;;_e p1 /\ g = m \;;_e p2. unfold jmcomp. - dependent destruction e. + destruct e. +(* dependent destruction e. *) eapply pbsquare_universal; eauto. Qed. @@ -778,7 +777,10 @@ Program Definition ipairC {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} subst prj21 prj22. (* surprisingly, this does not work with pbsquare_is_pulback_sym *) - (* rewrite <- pbsquare_is_pullback_sym. *) + (* rewrite - pbsquare_is_pullback_sym. + Set Printing All. + *) + rewrite pbsquare_is_pullback. inversion HeqCsp2; subst. subst Sp2. @@ -960,10 +962,11 @@ assert (forall (e2: ((c2 *_C0 c3) :> C) = Pb23), j33L \; (j12R \; src2) = m23 \;;_e2 j23L \; src2) as M23_E1. { intros e2. unfold jmcomp. - dependent destruction e2. + destruct e2. +(* dependent destruction e2. *) rewrite compoA. rewrite m23_E. - unfold jmcomp. + unfold jmcomp. dependent destruction E23. rewrite compoA; auto. } @@ -973,7 +976,8 @@ assert (forall (e3: ((c2 *_C0 c3) :> C) = Pb23), { intros e3. specialize (M23_E1 E23). unfold jmcomp in M23_E1. - dependent destruction E23. + destruct E23. +(* dependent destruction E23. *) unfold jmcomp. dependent destruction e3. setoid_rewrite <- compoA. @@ -999,7 +1003,7 @@ assert (pbsquare j15L j15R tgt1 src23) as pbsq15. } assert ((j33L \; j12L) \; tgt1 = m23 \; src23) as sqM23. -{ specialize (M23_E2 E23). +{ specialize (M23_E2 E23). dependent destruction E23. exact M23_E2. } @@ -1019,12 +1023,13 @@ assert ( eapply (@pbsquare_universal C _ _ _ _ _ _ _ _ _ (j33L \; j12L) m23). exact pbsq15. exact sqM23. -} - +} destruct (X E33) as [mm R]. exact mm. Qed. +Print Assumptions iprodCAsc. + (* An internal precategory is an internal category with two operators that must be src and tgt preserving, i.e. iHom morphisms: identity : C0 -> C1 (corresponding to horizontal 1-morphism identity in @@ -1903,6 +1908,9 @@ Obligation 1. refine (@existT (D1hom h0 k0) _ hh0 (@existT (D1hom h1 k1) _ hh1 k)). Defined. +(*HB.builders Context (T : obj cat) (f : IsInternalCat cat T).*) +(* Context (f : doublecat). *) + (* hcomp (hm, hu) = prj1 (hm, hu) = hm hcomp (hu, hm) = prj2 (hu, hm) = hm (hm1 * hm2) * hm3 ~> hm1 * (hm2 * hm3) @@ -1921,12 +1929,6 @@ HB.mixin Record IsDCat_UA T of CFunctor T := { (@HO T (@hhom T) a0 a3 hh1) }. *) -(* -Class pip (Y: Type) := {}. -Class pip2 (T: Type) := {}. - -Instance pipO (T1 T2: Type) : pip T1 -> pip T2 -> pip2 (T1 + T2)%type. -*) (*********************************************************************) @@ -2182,3 +2184,5 @@ Program Definition pb_cat (A B: cat) (H: cospan A B) : cat. destruct c as [a1 a2 a3]. econstructor. *) + + From b21e282a6901ce9f64682abd6fdddfed8c9b0fe9 Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Fri, 19 Jan 2024 14:05:01 +0100 Subject: [PATCH 130/147] updated encatI.v --- theories/encatI.v | 1 - 1 file changed, 1 deletion(-) diff --git a/theories/encatI.v b/theories/encatI.v index ba2e5c68d..706369800 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -262,7 +262,6 @@ HB.structure Definition InternalHomHom {C: pbcat} HB.instance Definition iHom_quiver {C: pbcat} (C0 : C) : IsQuiver (@iHom C C0) := IsQuiver.Build (@iHom C C0) (@iHomHom C C0). -Print iHom_quiver. Program Definition pre_iHom_id {C: pbcat} (C0 : C) (C1 : @iHom C C0) : @IsInternalHomHom C C0 C1 C1 idmap := From 2167b3d116301773f814936664a869f162136e4b Mon Sep 17 00:00:00 2001 From: ptorrx Date: Thu, 18 Jan 2024 18:04:24 +0100 Subject: [PATCH 131/147] restructuring --- theories/encat.v | 1969 +-------------------------------------------- theories/encatD.v | 1782 +--------------------------------------- 2 files changed, 36 insertions(+), 3715 deletions(-) diff --git a/theories/encat.v b/theories/encat.v index 5bc2060cc..8681f31cb 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -1,1094 +1,23 @@ Require Import ssreflect ssrfun. -From HB Require Import structures. +Unset Universe Checking. +From HB Require Import structures cat. +Set Universe Checking. +Require Import Coq.Program.Equality. Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Add Search Blacklist "__canonical__". -Declare Scope algebra_scope. -Delimit Scope algebra_scope with A. Local Open Scope algebra_scope. -Declare Scope cat_scope. -Delimit Scope cat_scope with cat. Local Open Scope cat_scope. -(* we assume a few axioms to make life easier *) -Axiom funext : forall {T : Type} {U : T -> Type} [f g : forall t, U t], - (forall t, f t = g t) -> f = g. -Axiom propext : forall P Q : Prop, P <-> Q -> P = Q. -Axiom Prop_irrelevance : forall (P : Prop) (x y : P), x = y. - -(* Shortcut *) -Notation U := Type. - -(* Base definition : raw categories = quivers *) -HB.mixin Record IsQuiver C := { hom : C -> C -> U }. -Unset Universe Checking. -#[short(type="quiver")] -HB.structure Definition Quiver : Set := { C of IsQuiver C }. -Set Universe Checking. - -Bind Scope cat_scope with quiver. -Bind Scope cat_scope with hom. -Arguments hom {C} : rename. -Notation homs T := (@hom T _ _). -Notation "a ~> b" := (hom a b) - (at level 99, b at level 200, format "a ~> b") : cat_scope. -Notation "a ~>_ C b" := (@hom C a b) - (at level 99, C at level 0, only parsing) : cat_scope. - -(* precategories are quivers + id and comp *) -HB.mixin Record Quiver_IsPreCat C of Quiver C := { - idmap : forall (a : C), a ~> a; - comp : forall (a b c : C), (a ~> b) -> (b ~> c) -> (a ~> c); -}. - -HB.factory Record IsPreCat C := { - hom : C -> C -> U; - idmap : forall (a : C), hom a a; - comp : forall (a b c : C), hom a b -> hom b c -> hom a c; -}. -HB.builders Context C of IsPreCat C. - HB.instance Definition _ := IsQuiver.Build C hom. - HB.instance Definition _ := Quiver_IsPreCat.Build C idmap comp. -HB.end. - -Unset Universe Checking. -#[short(type="precat")] -HB.structure Definition PreCat : Set := { C of IsPreCat C }. -Set Universe Checking. - -Bind Scope cat_scope with precat. -Arguments idmap {C} {a} : rename. -Arguments comp {C} {a b c} : rename. -Notation "f \o g" := (comp g f) : cat_scope. -Notation "f \; g :> T" := (@comp T _ _ _ f g) - (at level 60, g, T at level 60, format "f \; g :> T", only parsing) : cat_scope. -Notation "f \; g" := (comp f g) : cat_scope. -Notation "\idmap_ a" := (@idmap _ a) (only parsing, at level 0) : cat_scope. - -(* categories are precategories + laws *) -HB.mixin Record PreCat_IsCat C of PreCat C := { - comp1o : forall (a b : C) (f : a ~> b), idmap \; f = f; - compo1 : forall (a b : C) (f : a ~> b), f \; idmap = f; - compoA : forall (a b c d : C) (f : a ~> b) (g : b ~> c) (h : c ~> d), - f \; (g \; h) = (f \; g) \; h -}. -Unset Universe Checking. -#[short(type="cat")] -HB.structure Definition Cat : Set := { C of PreCat_IsCat C & IsPreCat C }. -Set Universe Checking. - -Bind Scope cat_scope with cat. -Arguments compo1 {C a b} : rename. -Arguments comp1o {C a b} : rename. -Arguments compoA {C a b c d} : rename. - -(* the discrete category on a type cannot be the default, we make an alias *) -Definition discrete (T : U) := T. -HB.instance Definition _ T := @IsPreCat.Build (discrete T) (fun x y => x = y) - (fun=> erefl) (@etrans _). -Lemma etransA T (a b c d : discrete T) (f : a ~> b) (g : b ~> c) (h : c ~> d) : - f \; (g \; h) = (f \; g) \; h. -Proof. by rewrite /idmap/comp/=; case: _ / h; case: _ / g. Qed. -HB.instance Definition _ T := PreCat_IsCat.Build (discrete T) (@etrans_id _) - (fun _ _ _ => erefl) (@etransA _). - -(* the category of the unit type is the discrete one *) -HB.instance Definition _ := Cat.copy unit (discrete unit). - -HB.instance Definition _ := @IsPreCat.Build U (fun A B => A -> B) - (fun a => idfun) (fun a b c (f : a -> b) (g : b -> c) => (g \o f)%FUN). -HB.instance Definition _ := PreCat_IsCat.Build U (fun _ _ _ => erefl) - (fun _ _ _ => erefl) (fun _ _ _ _ _ _ _ => erefl). - - -Lemma Ucomp (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) : f \; g = (g \o f)%FUN. -Proof. by []. Qed. -Lemma Ucompx (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) x : (f \; g) x = g (f x). -Proof. by []. Qed. -Lemma U1 (X : U) : \idmap_X = idfun. -Proof. by []. Qed. -Lemma U1x (X : U) x : \idmap_X x = x. -Proof. by []. Qed. - -(* a prefunctor is a functor without laws *) -HB.mixin Record IsPreFunctor (C D : quiver) (F : C -> D) := { - Fhom : forall (a b : C), (a ~> b) -> (F a ~> F b) -}. - -Unset Universe Checking. -HB.structure Definition PreFunctor (C D : quiver) : Set := - { F of IsPreFunctor C D F }. -Set Universe Checking. -HB.instance Definition _ := IsQuiver.Build quiver PreFunctor.type. - -Notation "F ^$" := (@Fhom _ _ F _ _) - (at level 1, format "F ^$") : cat_scope. -Notation "F <$> f" := (@Fhom _ _ F _ _ f) - (at level 58, format "F <$> f", right associativity) : cat_scope. - -(* prefunctors are equal if their object and hom part are respectively equal *) -Lemma prefunctorP (C D : quiver) (F G : C ~> D) (eqFG : F =1 G) : - let homF a b F := F a ~> F b in - (forall a b f, eq_rect _ (homF a b) (F <$> f) _ (funext eqFG) = G <$> f) -> - F = G. -Proof. -move: F G => [F [[/= Fhom]]] [G [[/= Ghom]]] in eqFG *. -case: _ / (funext eqFG) => /= in Ghom * => eqFGhom. -congr PreFunctor.Pack; congr PreFunctor.Class; congr IsPreFunctor.Axioms_. -by do 3!apply: funext=> ?. -Qed. - -(* a functor is a prefunctor + laws for id and comp *) -HB.mixin Record PreFunctor_IsFunctor (C D : precat) (F : C -> D) - of @PreFunctor C D F := { - F1 : forall (a : C), F <$> \idmap_a = idmap; - Fcomp : forall (a b c : C) (f : a ~> b) (g : b ~> c), - F <$> (f \; g) = F <$> f \; F <$> g; -}. -Unset Universe Checking. - -(* precat and cat have a quiver structure *) -HB.structure Definition Functor (C D : precat) : Set := - { F of IsPreFunctor C D F & PreFunctor_IsFunctor C D F }. -Set Universe Checking. -HB.instance Definition _ := IsQuiver.Build precat Functor.type. -HB.instance Definition _ := IsQuiver.Build cat Functor.type. - -(* functor equality is the same as prefunctor because of PI *) -Lemma functorP (C D : precat) (F G : C ~> D) (eqFG : F =1 G) : - let homF a b F := F a ~> F b in - (forall a b f, eq_rect _ (homF a b) (F^$ f) _ (funext eqFG) = G^$ f) -> - F = G. -Proof. -move=> /= /prefunctorP {eqFG}. -case: F G => [F [/= Fm Fm']] [G [/= Gm Gm']]//=. -move=> [_] /EqdepFacts.eq_sigT_iff_eq_dep eqFG. -case: _ / eqFG in Gm' *. -congr Functor.Pack; congr Functor.Class. -case: Fm' Gm' => [F1 Fc] [G1 Gc]. -by congr PreFunctor_IsFunctor.Axioms_; apply: Prop_irrelevance. -Qed. - -(* the identity function is a functor *) -HB.instance Definition _ (C : quiver) := - IsPreFunctor.Build C C idfun (fun a b => idfun). -HB.instance Definition _ (C : precat) := - PreFunctor_IsFunctor.Build C C idfun (fun=> erefl) (fun _ _ _ _ _ => erefl). - -(* the composition of prefunctors *) -Section comp_prefunctor. -Context {C D E : quiver} {F : C ~> D} {G : D ~> E}. - -HB.instance Definition _ := IsPreFunctor.Build C E (G \o F)%FUN - (fun a b f => G <$> F <$> f). -Lemma comp_Fun (a b : C) (f : a ~> b) : (G \o F)%FUN <$> f = G <$> (F <$> f). -Proof. by []. Qed. -End comp_prefunctor. - -Section comp_functor. -Context {C D E : precat} {F : C ~> D} {G : D ~> E}. -Lemma comp_F1 (a : C) : (G \o F)%FUN <$> \idmap_a = idmap. -Proof. by rewrite !comp_Fun !F1. Qed. -Lemma comp_Fcomp (a b c : C) (f : a ~> b) (g : b ~> c) : - (G \o F)%FUN <$> (f \; g) = (G \o F)%FUN <$> f \; (G \o F)%FUN <$> g. -Proof. by rewrite !comp_Fun !Fcomp. Qed. -HB.instance Definition _ := PreFunctor_IsFunctor.Build C E (G \o F)%FUN - comp_F1 comp_Fcomp. -End comp_functor. - -(* precat and cat have a precategory structure *) -HB.instance Definition _ := Quiver_IsPreCat.Build precat - (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). -HB.instance Definition _ := Quiver_IsPreCat.Build cat - (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). - -Lemma funext_frefl A B (f : A -> B) : funext (frefl f) = erefl. -Proof. exact: Prop_irrelevance. Qed. - -(* precategories and categories form a category *) -Definition precat_cat : PreCat_IsCat precat. -Proof. -by split=> [C D F|C D F|C D C' D' F G H]; - apply/functorP => a b f /=; rewrite funext_frefl. -Qed. -HB.instance Definition _ := precat_cat. -Definition cat_cat : PreCat_IsCat cat. -Proof. -by split=> [C D F|C D F|C D C' D' F G H]; - apply/functorP => a b f /=; rewrite funext_frefl. -Qed. -HB.instance Definition _ := cat_cat. - -Check (cat : cat). - -(* concrete categories *) -HB.mixin Record Quiver_IsPreConcrete T of Quiver T := { - concrete : T -> U; - concrete_fun : forall (a b : T), (a ~> b) -> concrete a -> concrete b; -}. -Unset Universe Checking. -#[short(type="preconcrete_quiver")] -HB.structure Definition PreConcreteQuiver : Set := - { C of Quiver_IsPreConcrete C & IsQuiver C }. -Set Universe Checking. -Coercion concrete : PreConcreteQuiver.sort >-> Sortclass. - -HB.mixin Record PreConcrete_IsConcrete T of PreConcreteQuiver T := { - concrete_fun_inj : forall (a b : T), injective (concrete_fun a b) -}. -Unset Universe Checking. -#[short(type="concrete_quiver")] -HB.structure Definition ConcreteQuiver : Set := - { C of PreConcreteQuiver C & PreConcrete_IsConcrete C }. -Set Universe Checking. - -HB.instance Definition _ (C : ConcreteQuiver.type) := - IsPreFunctor.Build _ _ (concrete : C -> U) concrete_fun. - -HB.mixin Record PreCat_IsConcrete T of ConcreteQuiver T & PreCat T := { - concrete1 : forall (a : T), concrete <$> \idmap_a = idfun; - concrete_comp : forall (a b c : T) (f : a ~> b) (g : b ~> c), - concrete <$> (f \; g) = ((concrete <$> g) \o (concrete <$> f))%FUN; -}. -Unset Universe Checking. -#[short(type="concrete_precat")] -HB.structure Definition ConcretePreCat : Set := - { C of PreCat C & ConcreteQuiver C & PreCat_IsConcrete C }. -#[short(type="concrete_cat")] -HB.structure Definition ConcreteCat : Set := - { C of Cat C & ConcreteQuiver C & PreCat_IsConcrete C }. -Set Universe Checking. - -HB.instance Definition _ (C : concrete_precat) := - PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). -HB.instance Definition _ (C : ConcreteCat.type) := - PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). - -HB.instance Definition _ := Quiver_IsPreConcrete.Build U (fun _ _ => id). -HB.instance Definition _ := PreConcrete_IsConcrete.Build U (fun _ _ _ _ => id). -HB.instance Definition _ := PreCat_IsConcrete.Build U - (fun=> erefl) (fun _ _ _ _ _ => erefl). - -Unset Universe Checking. -HB.instance Definition _ := Quiver_IsPreConcrete.Build quiver (fun _ _ => id). -HB.instance Definition _ := Quiver_IsPreConcrete.Build precat (fun _ _ => id). -HB.instance Definition _ := Quiver_IsPreConcrete.Build cat (fun _ _ => id). -Lemma quiver_concrete_subproof : PreConcrete_IsConcrete quiver. -Proof. -constructor=> C D F G FG; apply: prefunctorP. - by move=> x; congr (_ x); apply: FG. -by move=> *; apply: Prop_irrelevance. -Qed. -HB.instance Definition _ := quiver_concrete_subproof. - -Lemma precat_concrete_subproof : PreConcrete_IsConcrete precat. -Proof. -constructor=> C D F G FG; apply: functorP. - by move=> x; congr (_ x); apply: FG. -by move=> *; apply: Prop_irrelevance. -Qed. -HB.instance Definition _ := precat_concrete_subproof. - -Lemma cat_concrete_subproof : PreConcrete_IsConcrete cat. -Proof. -constructor=> C D F G FG; apply: functorP. - by move=> x; congr (_ x); apply: FG. -by move=> *; apply: Prop_irrelevance. -Qed. -HB.instance Definition _ := cat_concrete_subproof. -HB.instance Definition _ := PreCat_IsConcrete.Build precat - (fun=> erefl) (fun _ _ _ _ _ => erefl). -HB.instance Definition _ := PreCat_IsConcrete.Build cat - (fun=> erefl) (fun _ _ _ _ _ => erefl). -Set Universe Checking. - -(* constant functor *) -Definition cst (C D : quiver) (c : C) := fun of D => c. -Arguments cst {C} D c. -HB.instance Definition _ {C D : precat} (c : C) := - IsPreFunctor.Build D C (cst D c) (fun _ _ _ => idmap). -HB.instance Definition _ {C D : cat} (c : C) := - PreFunctor_IsFunctor.Build D C (cst D c) (fun=> erefl) - (fun _ _ _ _ _ => esym (compo1 idmap)). - -(* opposite category *) -Definition catop (C : U) : U := C. -Notation "C ^op" := (catop C) - (at level 2, format "C ^op") : cat_scope. -HB.instance Definition _ (C : quiver) := - IsQuiver.Build C^op (fun a b => hom b a). -HB.instance Definition _ (C : precat) := - Quiver_IsPreCat.Build (C^op) (fun=> idmap) (fun _ _ _ f g => g \; f). -HB.instance Definition _ (C : cat) := PreCat_IsCat.Build (C^op) - (fun _ _ _ => compo1 _) (fun _ _ _ => comp1o _) - (fun _ _ _ _ _ _ _ => esym (compoA _ _ _)). - -HB.instance Definition _ {C : precat} {c : C} := - IsPreFunctor.Build C _ (hom c) (fun a b f g => g \; f). -Lemma hom_Fhom_subproof (C : cat) (x : C) : - PreFunctor_IsFunctor _ _ (hom x). -Proof. by split=> *; apply/funext => h; [apply: compo1 | apply: compoA]. Qed. -HB.instance Definition _ {C : cat} {c : C} := hom_Fhom_subproof c. - -Check fun (C : cat) (x : C) => hom x : C ~>_cat U. - -Lemma hom_op {C : quiver} (c : C^op) : hom c = (@hom C)^~ c. -Proof. reflexivity. Qed. - -Lemma homFhomx {C : precat} (a b c : C) (f : a ~> b) (g : c ~> a) : - (hom c <$> f) g = g \; f. -Proof. reflexivity. Qed. - -(* nary product of categories *) -Definition dprod {I : U} (C : I -> U) := forall i, C i. - -Section hom_dprod. -Context {I : U} (C : I -> quiver). -Definition dprod_hom_subdef (a b : dprod C) := forall i, a i ~> b i. -HB.instance Definition _ := IsQuiver.Build (dprod C) dprod_hom_subdef. -End hom_dprod. -Arguments dprod_hom_subdef /. - -Section precat_dprod. -Context {I : U} (C : I -> precat). -Definition dprod_idmap_subdef (a : dprod C) : a ~> a := fun=> idmap. -Definition dprod_comp_subdef (a b c : dprod C) (f : a ~> b) (g : b ~> c) : a ~> c := - fun i => f i \; g i. -HB.instance Definition _ := IsPreCat.Build (dprod C) - dprod_idmap_subdef dprod_comp_subdef. -End precat_dprod. -Arguments dprod_idmap_subdef /. -Arguments dprod_comp_subdef /. - -Section cat_dprod. -Context {I : U} (C : I -> cat). -Local Notation type := (dprod C). -Lemma dprod_is_cat : PreCat_IsCat type. -Proof. -split=> [a b f|a b f|a b c d f g h]; apply/funext => i; -[exact: comp1o | exact: compo1 | exact: compoA]. -Qed. -HB.instance Definition _ := dprod_is_cat. -End cat_dprod. - -(* binary product *) -Section hom_prod. -Context {C D : quiver}. -Definition prod_hom_subdef (a b : C * D) := ((a.1 ~> b.1) * (a.2 ~> b.2))%type. -HB.instance Definition _ := IsQuiver.Build (C * D)%type prod_hom_subdef. -End hom_prod. - -Section precat_prod. -Context {C D : precat}. -HB.instance Definition _ := IsPreCat.Build (C * D)%type (fun=> (idmap, idmap)) - (fun a b c (f : a ~> b) (g : b ~> c) => (f.1 \; g.1, f.2 \; g.2)). -End precat_prod. - -Section cat_prod. -Context {C D : cat}. -Local Notation type := (C * D)%type. -Lemma prod_is_cat : PreCat_IsCat type. -Proof. -split=> [[a1 a2] [b1 b2] [f1 f2]|[a1 a2] [b1 b2] [f1 f2]| - [a1 a2] [b1 b2] [c1 c2] [d1 d2] [f1 f2] [g1 g2] [h1 h2]]; congr (_, _) => //=; -by [exact: comp1o | exact: compo1 | exact: compoA]. -Qed. -HB.instance Definition _ := prod_is_cat. -End cat_prod. - -(* naturality *) -HB.mixin Record IsNatural (C D : precat) (F G : C ~>_quiver D) - (n : forall c, F c ~> G c) := { - natural : forall (a b : C) (f : a ~> b), - F <$> f \; n b = n a \; G <$> f -}. -Unset Universe Checking. -HB.structure Definition Natural (C D : precat) - (F G : C ~>_quiver D) : Set := - { n of @IsNatural C D F G n }. -Set Universe Checking. -HB.instance Definition _ (C D : precat) := - IsQuiver.Build (PreFunctor.type C D) (@Natural.type C D). -HB.instance Definition _ (C D : cat) := - IsQuiver.Build (Functor.type C D) (@Natural.type C D). -Arguments natural {C D F G} n [a b] f : rename. - -Check fun (C D : cat) (F G : C ~> D) => F ~>_(C ~>_cat D) G. - -Lemma naturalx (C : precat) (D : concrete_precat) - (F G : C ~>_quiver D) (n : F ~> G) (a b : C) (f : a ~> b) g : - (concrete <$> n b) ((concrete <$> F <$> f) g) = - (concrete <$> G <$> f) ((concrete <$> n a) g). -Proof. -have /(congr1 (fun h => (concrete <$> h) g)) := natural n f. -by rewrite !Fcomp. -Qed. -Arguments naturalx {C D F G} n [a b] f. - -Lemma naturalU (C : precat) (F G : C ~>_quiver U) (n : F ~> G) - (a b : C) (f : a ~> b) g : n b (F^$ f g) = G^$ f (n a g). -Proof. exact: (naturalx n). Qed. - -Lemma natP (C D : precat) (F G : C ~>_quiver D) (n m : F ~> G) : - Natural.sort n = Natural.sort m -> n = m. -Proof. -case: n m => [/= n nP] [/= m mP] enm. -elim: _ / enm in mP *; congr Natural.Pack. -case: nP mP => [[?]] [[?]]; congr Natural.Class. -congr IsNatural.Axioms_. -exact: Prop_irrelevance. -Qed. - -Notation "F ~~> G" := (F ~>_(homs quiver) G) - (at level 99, G at level 200, format "F ~~> G"). -Notation "F ~~> G :> C ~> D" := (F ~> G :> (C ~>_quiver D)) - (at level 99, G at level 200, C, D at level 0, - format "F ~~> G :> C ~> D"). - -Definition natural_id {C D : precat} (F : C ~>_quiver D) (a : C) := \idmap_(F a). -Definition natural_id_natural (C D : cat) (F : C ~>_quiver D) : - IsNatural C D F F (natural_id F). -Proof. by constructor=> a b f; rewrite /natural_id/= compo1 comp1o. Qed. -HB.instance Definition _ C D F := @natural_id_natural C D F. - -Check fun {C D : cat} (F : C ~>_quiver D) => natural_id F : F ~> F. - -Definition natural_comp {C D : precat} (F G H : C ~>_quiver D) - (m : F ~> G) (n : G ~> H) (a : C) := m a \; n a. -Definition natural_comp_natural (C D : cat) (F G H : C ~>_quiver D) m n : - IsNatural C D F H (@natural_comp C D F G H m n). -Proof. -constructor=> a b f; rewrite /natural_comp/=. -by rewrite compoA natural -compoA natural compoA. -Qed. -HB.instance Definition _ C D F G H m n := @natural_comp_natural C D F G H m n. - -HB.instance Definition _ {C D : cat} := - Quiver_IsPreCat.Build (PreFunctor.type C D) natural_id natural_comp. -HB.instance Definition _ {C D : cat} := - Quiver_IsPreCat.Build (Functor.type C D) natural_id natural_comp. - -Lemma prefunctor_cat {C D : cat} : PreCat_IsCat (PreFunctor.type C D). -Proof. -constructor => [F G f|F G f|F G H J f g h]. -- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. -- by apply/natP/funext => a; rewrite /= /natural_comp compo1. -- by apply/natP/funext => a; rewrite /= /natural_comp compoA. -Qed. -HB.instance Definition _ C D := @prefunctor_cat C D. - -Lemma functor_cat {C D : cat} : PreCat_IsCat (Functor.type C D). -Proof. -constructor => [F G f|F G f|F G H J f g h]. -- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. -- by apply/natP/funext => a; rewrite /= /natural_comp compo1. -- by apply/natP/funext => a; rewrite /= /natural_comp compoA. -Qed. -HB.instance Definition _ C D := @functor_cat C D. - -Section nat_map_left. -Context {C D E : precat} {F G : C ~> D}. - -Definition nat_lmap (H : D ~>_quiver E) (n : forall c, F c ~> G c) : - forall c, (H \o F)%FUN c ~> (H \o G)%FUN c := fun c => H <$> n c. - -Fail Check fun (H : D ~> E) (n : F ~~> G) => nat_lmap H n : H \o F ~~> H \o G. - -Lemma nat_lmap_is_natural (H : D ~> E) (n : F ~~> G) : - IsNatural C E (H \o F) (H \o G) (nat_lmap H n). -Proof. by constructor=> a b f; rewrite /nat_lmap/= -!Fcomp natural. Qed. -HB.instance Definition _ H n := nat_lmap_is_natural H n. - -Check fun (H : D ~> E) (n : F ~~> G) => nat_lmap H n : H \o F ~~> H \o G. - -End nat_map_left. - -Notation "F n" := (nat_lmap F n) - (at level 58, format "F n", right associativity) : cat_scope. - -Section nat_map_right. -Context {C D E : precat} {F G : C ~> D}. - -Definition nat_rmap (H : E -> C) (n : forall c, F c ~> G c) : - forall c, (F \o H)%FUN c ~> (G \o H)%FUN c := fun c => n (H c). -Lemma nat_rmap_is_natural (H : E ~> C :> quiver) (n : F ~~> G) : - IsNatural E D (F \o H)%FUN (G \o H)%FUN (nat_rmap H n). -Proof. by constructor=> a b f; rewrite /nat_lmap/= natural. Qed. -HB.instance Definition _ H n := nat_rmap_is_natural H n. - -End nat_map_right. - -Notation "F <$o> n" := (nat_rmap F n) - (at level 58, format "F <$o> n", right associativity) : cat_scope. - -Definition delta (C D : cat) : C -> (D ~> C) := cst D. -Arguments delta C D : clear implicits. - -Definition map_delta {C D : cat} (a b : C) (f : a ~> b) : - delta C D a ~> delta C D b. -Proof. -apply: (@Natural.Pack _ _ (cst D a) (cst D b) (fun x => f)). -apply: Natural.Class; apply: (IsNatural.Build _ _ _ _ _). -by move=> a' b' ?; rewrite compo1 comp1o. -Defined. - -HB.instance Definition _ {C D : cat} := - IsPreFunctor.Build C (D ~> C) (delta C D) (@map_delta C D). - -Lemma delta_functor {C D : cat} : PreFunctor_IsFunctor _ _ (delta C D). -Proof. by constructor=> [a|a b c f g]; exact/natP. Qed. -HB.instance Definition _ C D := @delta_functor C D. - -HB.mixin Record IsMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { - unit : idfun ~~> M; - join : (M \o M)%FUN ~~> M; - bind : forall (a b : C), (a ~> M b) -> (M a ~> M b); - bindE : forall a b (f : a ~> M b), bind a b f = M <$> f \; join b; - unit_join : forall a, (M <$> unit a) \; join _ = idmap; - join_unit : forall a, join _ \; (M <$> unit a) = idmap; - join_square : forall a, M <$> join a \; join _ = join _ \; join _ -}. - -#[short(type="premonad")] -HB.structure Definition PreMonad (C : precat) := - {M of @PreFunctor C C M & IsMonad C M}. -#[short(type="monad")] -HB.structure Definition Monad (C : precat) := - {M of @Functor C C M & IsMonad C M}. - -HB.factory Record IsJoinMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { - unit : idfun ~~> M; - join : (M \o M)%FUN ~~> M; - unit_join : forall a, (M <$> unit a) \; join _ = idmap; - join_unit : forall a, join _ \; (M <$> unit a) = idmap; - join_square : forall a, M <$> join a \; join _ = join _ \; join _ -}. -HB.builders Context C M of IsJoinMonad C M. - HB.instance Definition _ := IsMonad.Build C M - (fun a b f => erefl) unit_join join_unit join_square. -HB.end. - -HB.mixin Record IsCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { - counit : M ~~> idfun; - cojoin : M ~~> (M \o M)%FUN; - cobind : forall (a b : C), (M a ~> b) -> (M a ~> M b); - cobindE : forall a b (f : M a ~> b), cobind a b f = cojoin _ \; M <$> f; - unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; - join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; - cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ -}. -#[short(type="precomonad")] -HB.structure Definition PreCoMonad (C : precat) := - {M of @PreFunctor C C M & IsCoMonad C M}. -#[short(type="comonad")] -HB.structure Definition CoMonad (C : precat) := - {M of @Functor C C M & IsCoMonad C M}. - -HB.factory Record IsJoinCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { - counit : M ~~> idfun; - cojoin : M ~~> (M \o M)%FUN; - unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; - join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; - cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ -}. -HB.builders Context C M of IsJoinCoMonad C M. - HB.instance Definition _ := IsCoMonad.Build C M - (fun a b f => erefl) unit_cojoin join_counit cojoin_square. -HB.end. - -Lemma idFmap (C : cat) (a b : C) (f : a ~> b) : idfun <$> f = f. -Proof. by []. Qed. - -Lemma compFmap (C D E : cat) (F : C ~> D) (G : D ~> E) (a b : C) (f : a ~> b) : - (G \o F) <$> f = G <$> F <$> f. -Proof. by []. Qed. - -(* yoneda *) -Section hom_repr. -Context {C : cat} (F : C ~>_cat U). - -Definition homF : C -> U := fun c => hom c ~~> F. - -Section nat. -Context (x y : C) (xy : x ~> y). - -(* Goal hom x ~~> F -> hom y ~~> F *) -Context (n : hom x ~~> F). -Definition homFhom c : hom y c ~> F c := fun g => n _ (xy \; g). - -Lemma homFhom_natural_subdef : IsNatural C U (hom y) F homFhom. -Proof. -by split=> a b f /=; apply/funext => g /=; - rewrite /homFhom !Ucompx/= !naturalU/= Fcomp. -Qed. -HB.instance Definition _ := homFhom_natural_subdef. -End nat. -Arguments homFhom / : clear implicits. - -HB.about IsPreFunctor.Build. -Check homFhom : forall x y : C, (x ~> y) -> (homF x -> homF y). -HB.instance Definition _ := IsPreFunctor.Build _ _ homF homFhom. -Lemma homF_functor_subproof : PreFunctor_IsFunctor _ _ homF. -Proof. -split=> [a|a b c f g]. - apply/funext => -[/= f natf]. - apply: natP => //=; apply: funext => b; apply: funext => g/=. - by rewrite comp1o. -apply/funext => -[/= h natf]. -apply: natP => //=; apply: funext => d; apply: funext => k/=. -by rewrite compoA. -Qed. -HB.instance Definition _ := homF_functor_subproof. - -Section pointed. -Context (c : C). -Definition hom_repr : homF c ~> F c := fun f => f _ idmap. -Arguments hom_repr /. - -Definition repr_hom (fc : F c) a : hom c a ~> F a := - fun f => F^$ f fc. -Arguments repr_hom / : clear implicits. -Lemma repr_hom_subdef (fc : F c) : IsNatural _ _ _ _ (repr_hom fc). -Proof. by split=> a b f /=; apply/funext=> x; rewrite !Ucompx/= Fcomp. Qed. -HB.instance Definition _ {fc : F c} := repr_hom_subdef fc. - -Definition repr_hom_nat : F c ~> homF c := repr_hom. - -Lemma hom_reprK : cancel hom_repr repr_hom_nat. -Proof. -move=> f; apply/natP; apply/funext => a; apply/funext => g /=. -by rewrite -naturalU/=; congr (f _ _); apply: comp1o. -Qed. -Lemma repr_homK : cancel (repr_hom : F c ~> homF c) hom_repr. -Proof. by move=> fc; rewrite /= F1. Qed. -End pointed. -Arguments hom_repr /. -Arguments repr_hom /. - -Lemma hom_repr_natural_subproof : IsNatural _ _ _ _ hom_repr. -Proof. -split=> a b f /=; apply/funext => n /=; rewrite !Ucompx/= compo1/=. -by rewrite -naturalU/=; congr (n _ _); apply/esym/comp1o. -Qed. -HB.instance Definition _ := hom_repr_natural_subproof. - -(* show this from the previous proof *) -Lemma hom_natural_repr_subproof : IsNatural _ _ _ _ repr_hom_nat. -Proof. -split=> a b f /=; apply: funext => fa /=; rewrite !Ucompx/=. -apply: natP; apply: funext => c /=; apply: funext => d /=. -by rewrite Fcomp Ucompx/=. -Qed. -HB.instance Definition _ := hom_natural_repr_subproof. - -Definition hom_repr_nat : homF ~~> F := hom_repr. -Definition repr_hom_nat_nat : F ~~> homF := repr_hom_nat. - -End hom_repr. - -(* comma categories *) -Module comma. -Section homcomma. -Context {C D E : precat} (F : C ~> E) (G : D ~> E). - -Definition type := { x : C * D & F x.1 ~> G x.2 }. -Definition hom_subdef (a b : type) := { - f : tag a ~> tag b & F <$> f.1 \; tagged b = tagged a \; G <$> f.2 - }. -HB.instance Definition _ := IsQuiver.Build type hom_subdef. -End homcomma. -Arguments hom_subdef /. -Section comma. -Context {C D E : cat} (F : C ~> E) (G : D ~> E). -Notation type := (type F G). - -Program Definition idmap_subdef (a : type) : a ~> a := @Tagged _ idmap _ _. -Next Obligation. by rewrite !F1 comp1o compo1. Qed. -Program Definition comp_subdef (a b c : type) - (f : a ~> b) (g : b ~> c) : a ~> c := - @Tagged _ (tag f \; tag g) _ _. -Next Obligation. by rewrite !Fcomp -compoA (tagged g) compoA (tagged f) compoA. Qed. -HB.instance Definition _ := IsPreCat.Build type idmap_subdef comp_subdef. -Arguments idmap_subdef /. -Arguments comp_subdef /. - -Lemma comma_homeqP (a b : type) (f g : a ~> b) : projT1 f = projT1 g -> f = g. -Proof. -case: f g => [f fP] [g +]/= eqfg; case: _ / eqfg => gP. -by congr existT; apply: Prop_irrelevance. -Qed. - -Lemma comma_is_cat : PreCat_IsCat type. -Proof. -by split=> [[a fa] [b fb] [*]|[a fa] [b fb] [*]|*]; - apply/comma_homeqP; rewrite /= ?(comp1o, compo1, compoA). -Qed. -HB.instance Definition _ := comma_is_cat. -End comma. -End comma. -Notation "F `/` G" := (@comma.type _ _ _ F G) - (at level 40, G at level 40, format "F `/` G") : cat_scope. -Notation "a /` G" := (cst unit a `/` G) - (at level 40, G at level 40, format "a /` G") : cat_scope. -Notation "F `/ b" := (F `/` cst unit b) - (at level 40, b at level 40, format "F `/ b") : cat_scope. -Notation "a / b" := (cst unit a `/ b) : cat_scope. - -Definition obj (C : quiver) : Type := C. -HB.mixin Record IsInitial {C : quiver} (i : obj C) := { - to : forall c, i ~> c; - to_unique : forall c (f : i ~> c), f = to c -}. -#[short(type="initial")] -HB.structure Definition Initial {C : quiver} := {i of IsInitial C i}. - -HB.mixin Record IsTerminal {C : quiver} (t : obj C) := { - from : forall c, c ~> t; - from_unique : forall c (f : c ~> t), f = from c -}. -#[short(type="terminal")] -HB.structure Definition Terminal {C : quiver} := {t of IsTerminal C t}. -#[short(type="universal")] -HB.structure Definition Universal {C : quiver} := - {u of Initial C u & Terminal C u}. - -(* Definition hom' {C : precat} (a b : C) := a ~> b. *) -(* (* Bug *) *) -(* Identity Coercion hom'_hom : hom' >-> hom. *) - -(* HB.mixin Record IsMono {C : precat} (b c : C) (f : hom b c) := { *) -(* monoP : forall (a : C) (g1 g2 : a ~> b), g1 \; f = g2 \; f -> g1 = g2 *) -(* }. *) -(* #[short(type="mono")] *) -(* HB.structure Definition Mono {C : precat} (a b : C) := {m of IsMono C a b m}. *) -(* Notation "a >~> b" := (mono a b) *) -(* (at level 99, b at level 200, format "a >~> b") : cat_scope. *) -(* Notation "C >~>_ T D" := (@mono T C D) *) -(* (at level 99, T at level 0, only parsing) : cat_scope. *) - -(* HB.mixin Record IsEpi {C : precat} (a b : C) (f : hom a b) := { *) -(* epiP : forall (c : C) (g1 g2 : b ~> c), g1 \o f = g2 \o f -> g1 = g2 *) -(* }. *) -(* #[short(type="epi")] *) -(* HB.structure Definition Epi {C : precat} (a b : C) := {e of IsEpi C a b e}. *) -(* Notation "a ~>> b" := (epi a b) *) -(* (at level 99, b at level 200, format "a ~>> b") : cat_scope. *) -(* Notation "C ~>>_ T D" := (@epi T C D) *) -(* (at level 99, T at level 0, only parsing) : cat_scope. *) - -(* #[short(type="iso")] *) -(* HB.structure Definition Iso {C : precat} (a b : C) := *) -(* {i of @Mono C a b i & @Epi C a b i}. *) -(* Notation "a <~> b" := (epi a b) *) -(* (at level 99, b at level 200, format "a <~> b") : cat_scope. *) -(* Notation "C <~>_ T D" := (@epi T C D) *) -(* (at level 99, T at level 0, only parsing) : cat_scope. *) - -HB.mixin Record IsRightAdjoint (D C : precat) (R : D -> C) - of @PreFunctor D C R := { - L_ : C ~> D; - phi : forall c d, (L_ c ~> d) -> (c ~> R d); - psy : forall c d, (c ~> R d) -> (L_ c ~> d); - phi_psy c d : (phi c d \o psy c d)%FUN = @id (c ~> R d); - psy_phi c d : (psy c d \o phi c d)%FUN = @id (L_ c ~> d) -}. -#[short(type="right_adjoint")] -HB.structure Definition RightAdjoint (D C : precat) := - { R of @Functor D C R & IsRightAdjoint D C R }. -Arguments L_ {_ _}. -Arguments phi {D C s} {c d}. -Arguments psy {D C s} {c d}. - - -HB.mixin Record PreCat_IsMonoidal C of PreCat C := { - onec : C; - (* prod1 : @hom precat (C * C)%type C ; *) - prod : (C * C)%type ~>_precat C; -}. -#[short(type="premonoidal")] -#[verbose] -HB.structure Definition PreMonoidal := { C of PreCat C & PreCat_IsMonoidal C }. -Notation premonoidal := premonoidal. -Arguments prod {C} : rename. -Notation "a * b" := (prod (a, b)) : cat_scope. -Reserved Notation "f <*> g" (at level 40, g at level 40, format "f <*> g"). -Notation "f <*> g" := (prod^$ (f, g)) (only printing) : cat_scope. -Notation "f <*> g" := (prod^$ ((f, g) : (_, _) ~> (_, _))) - (only parsing) : cat_scope. -Notation "1" := onec : cat_scope. - -Definition hom_cast {C : quiver} {a a' : C} (eqa : a = a') {b b' : C} (eqb : b = b') : - (a ~> b) -> (a' ~> b'). -Proof. now elim: _ / eqa; elim: _ / eqb. Defined. - -HB.mixin Record PreFunctor_IsMonoidal (C D : premonoidal) F of - @PreFunctor C D F := { - fun_one : F 1 = 1; - fun_prod : forall (x y : C), F (x * y) = F x * F y; -}. -#[short(type="monoidal_prefunctor")] -HB.structure Definition MonoidalPreFunctor C D := - { F of @PreFunctor_IsMonoidal C D F }. -Arguments fun_prod {C D F x y} : rename. -(* Arguments fun_prodF {C D F x x'} f {y y'} g : rename. *) -Unset Universe Checking. -HB.instance Definition _ := IsQuiver.Build premonoidal MonoidalPreFunctor.type. -Set Universe Checking. - -HB.instance Definition _ (C : quiver) := - IsPreFunctor.Build (C * C)%type C fst - (fun (a b : C * C) (f : a ~> b) => f.1). -HB.instance Definition _ (C : quiver) := - IsPreFunctor.Build (C * C)%type C snd - (fun (a b : C * C) (f : a ~> b) => f.2). - -Definition prod3l {C : premonoidal} (x : C * C * C) : C := - (x.1.1 * x.1.2) * x.2. -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build _ C prod3l - (fun a b (f : a ~> b) => (f.1.1 <*> f.1.2) <*> f.2). - -Definition prod3r {C : premonoidal} (x : C * C * C) : C := - x.1.1 * (x.1.2 * x.2). -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build _ C prod3r - (fun a b (f : a ~> b) => f.1.1 <*> (f.1.2 <*> f.2)). - -Definition prod1r {C : premonoidal} (x : C) : C := 1 * x. -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build C C prod1r - (fun (a b : C) (f : a ~> b) => \idmap_1 <*> f). - -Definition prod1l {C : premonoidal} (x : C) : C := x * 1. -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build C C prod1l - (fun (a b : C) (f : a ~> b) => f <*> \idmap_1). - -HB.mixin Record PreMonoidal_IsMonoidal C of PreMonoidal C := { - prodA : prod3l ~~> prod3r; - prod1c : prod1r ~~> idfun; - prodc1 : prod1l ~~> idfun; - prodc1c : forall (x y : C), - prodA (x, 1, y) \; \idmap_x <*> prod1c y = prodc1 x <*> \idmap_y; - prodA4 : forall (w x y z : C), - prodA (w * x, y, z) \; prodA (w, x, y * z) = - prodA (w, x, y) <*> \idmap_z \; prodA (w, x * y, z) \; \idmap_w <*> prodA (x, y, z); -}. - -Unset Universe Checking. -#[short(type="monoidal")] -#[verbose] -HB.structure Definition Monoidal : Set := - { C of PreMonoidal_IsMonoidal C & PreMonoidal C }. -Set Universe Checking. - -(******************************************************************) - - -Record cospan (Q : quiver) (A B : Q) := Cospan { - top : Q; - left2top : A ~> top; - right2top : B ~> top -}. - -Section cospans. -Variables (Q : precat) (A B : Q). -Record cospan_map (c c' : cospan A B) := CospanMap { - top_map : top c ~> top c'; - left2top_map : left2top c \; top_map = left2top c'; - right2top_map : right2top c \; top_map = right2top c'; -}. -HB.instance Definition _ := IsQuiver.Build (cospan A B) cospan_map. - -Lemma cospan_mapP (c c' : cospan A B) (f g : c ~> c') : - top_map f = top_map g <-> f = g. -Admitted. -End cospans. - -Section cospans_in_cat. -Variables (Q : cat) (A B : Q). -Definition cospan_idmap (c : cospan A B) := - @CospanMap Q A B c c idmap (compo1 _) (compo1 _). -Program Definition cospan_comp (c1 c2 c3 : cospan A B) - (f12 : c1 ~> c2) (f23 : c2 ~> c3) := - @CospanMap Q A B c1 c3 (top_map f12 \; top_map f23) _ _. -Next Obligation. by rewrite compoA !left2top_map. Qed. -Next Obligation. by rewrite compoA !right2top_map. Qed. -HB.instance Definition _ := IsPreCat.Build (cospan A B) cospan_idmap cospan_comp. - -Lemma cospan_are_cats : PreCat_IsCat (cospan A B). -Proof. -constructor=> [a b f|a b f|a b c d f g h]. -- by apply/cospan_mapP => /=; rewrite comp1o. -- by apply/cospan_mapP => /=; rewrite compo1. -- by apply/cospan_mapP => /=; rewrite compoA. -Qed. -HB.instance Definition _ := cospan_are_cats. -End cospans_in_cat. - -Section spans_and_co. -Variables (Q : quiver) (A B : Q). -Definition span := @cospan Q^op A B. -Definition bot (s : span) : Q := top s. -Definition bot2left (s : span) : bot s ~>_Q A := left2top s. -Definition bot2right (s : span) : bot s ~>_Q B := right2top s. -Definition Span (C : Q) (f : C ~> A) (g : C ~> B) : span := - @Cospan Q^op A B C f g. -End spans_and_co. - -HB.instance Definition _ (Q : precat) (A B : Q) := - Quiver.copy (span A B) (@cospan Q^op A B)^op. -HB.instance Definition _ (Q : cat) (A B : Q) := - Cat.copy (span A B) (@cospan Q^op A B)^op. - -Section bot_map. -Variables (C : cat) (A B : C) (s s' : span A B) (f : s ~> s'). -Definition bot_map : bot s ~> bot s' := top_map f. -Lemma bot2left_map : bot_map \; bot2left s' = bot2left s. -Proof. exact: left2top_map f. Qed. -Lemma bot2right_map : bot_map \; bot2right s' = bot2right s. -Proof. exact: right2top_map f. Qed. -End bot_map. - -HB.mixin Record isPrePullback (Q : precat) (A B : Q) - (c : cospan A B) (s : span A B) := { - is_square : bot2left s \; left2top c = bot2right s \; right2top c; -}. -#[short(type=prepullback)] -HB.structure Definition PrePullback Q A B (c : cospan A B) := - {s of isPrePullback Q A B c s}. -Arguments prepullback {Q A B} c. - -Section prepullback. -Variables (Q : precat) (A B : Q) (c : cospan A B). -HB.instance Definition _ := - IsQuiver.Build (prepullback c) - (fun a b => (a : span A B) ~>_(span A B) (b : span A B)). -Lemma eq_prepullbackP (p q : prepullback c) : - p = q :> span _ _ <-> p = q. -Admitted. -End prepullback. -Section prepullback. -Variables (Q : cat) (A B : Q) (csp : cospan A B). -(* TODO: why can't we do that? *) -(* HB.instance Definition _ := Cat.on (prepullback csp). *) -HB.instance Definition _ := - Quiver_IsPreCat.Build (prepullback csp) - (fun a => \idmap_(a : span A B)) - (* TODO: study how to make this coercion trigger - even when the target is not reduced to span *) - (fun a b c f g => f \; g). -Lemma prepullback_is_cat : PreCat_IsCat (prepullback csp). -Proof. (* should be copied from the cat on span *) -constructor=> [a b f|a b f|a b c d f g h]; - [exact: comp1o|exact: compo1|exact: compoA]. -Qed. -End prepullback. - -HB.tag Definition pb_terminal (Q : precat) - (A B : Q) (c : cospan A B) (s : prepullback c) : - obj (prepullback c) := s. - -#[wrapper] -HB.mixin Record prepullback_isTerminal (Q : precat) - (A B : Q) (c : cospan A B) - (s : span A B) of isPrePullback Q A B c s := { - prepullback_terminal : - IsTerminal (prepullback c) (pb_terminal s) -}. -#[short(type="pullback"), verbose] -HB.structure Definition Pullback (Q : precat) - (A B : Q) (c : cospan A B) := - {s of isPrePullback Q A B c s - & IsTerminal (prepullback c) (pb_terminal s) }. - -Notation pbsquare u v f g := - (Pullback _ (Cospan f g) (Span u v)). - -Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). - -(******************************************************************) - -(*** ENRICHED CATEGORIES *) - -Declare Scope encat_scope. -Delimit Scope encat_scope with encat. -Local Open Scope encat_scope. - -(* Enrichment in a monoidal category, following - https://ncatlab.org/nlab/show/enriched+category -*) -HB.mixin Record IsEnQuiver (V: Type) C := { - hom_object : C -> C -> V - }. -Unset Universe Checking. -HB.structure Definition EnQuiver (V: Type) : Set := - { C of IsEnQuiver V C }. -Set Universe Checking. - -(* Monoidal precategory with the enrichment operators (no axioms) *) -HB.mixin Record IsEnPreCat (V: PreMonoidal.type) C of - EnQuiver (PreMonoidal.sort V) C := { - id_element : forall (a: C), - @hom V onec (hom_object a a) ; - comp_morphism : forall (a b c: C), - @hom V (@hom_object V C b c * @hom_object V C a b) - (@hom_object V C a c) -}. -Unset Universe Checking. -HB.structure Definition EnPreCat (V: PreMonoidal.type) : Set := - { C of IsEnPreCat V C }. -Set Universe Checking. - -Notation "a ~^ b" := (hom_object a b) - (at level 99, b at level 200, format "a ~^ b") : encat_scope. -Notation "a ~^_ ( V , C ) b" := (@hom_object V C a b) - (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. -Notation "~^IE a" := (id_element a) - (at level 99, format "~^IE a") : cat_scope. -Notation "~^IE_ ( V , C ) a" := (@id_element V C a) - (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. -(* not working *) -Notation "~^CM a b c" := (comp_morphism a b c) - (at level 99, - format "~^CM a b c") : cat_scope. -Notation "~^CM_ ( V , C ) a b c" := (@comp_morphism V C a b c) - (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. - -(* V-enriched category: - V is the monoidal category; - C is the base category that gets enriched -*) -HB.mixin Record IsEnCat (V: Monoidal.type) C of EnPreCat V C := { - ecat_comp_assoc : forall a b c d: C, - forall alpha: - (((c ~^_(V,C) d) * (b ~^_(V,C) c)) * (a ~^_(V,C) b)) ~>_V - ((c ~^_(V,C) d) * ((b ~^_(V,C) c) * (a ~^_(V,C) b))), - ((@comp_morphism V C b c d) <*> (@idmap V (a ~^_(V,C) b))) \; - (@comp_morphism V C a b d) - = - alpha \; - ((@idmap V (c ~^_(V,C) d)) <*> (@comp_morphism V C a b c)) \; - (@comp_morphism V C a c d) ; - - ecat_comp_left_unital : forall a b: C, - forall l: onec * (a ~^_(V,C) b) ~>_V (a ~^_(V,C) b), - l = ((@id_element V C b) <*> (@idmap V (a ~^_(V,C) b))) \; - (@comp_morphism V C a b b) ; - ecat_comp_right_unital : forall a b: C, - forall r: (a ~^_(V,C) b) * onec ~>_V (a ~^_(V,C) b), - r = ((@idmap V (a ~^_(V,C) b)) <*> (@id_element V C a)) \; - (@comp_morphism V C a a b) -}. -Unset Universe Checking. -#[verbose] -HB.structure Definition EnCat (V: Monoidal.type) : Set := { C of IsEnCat V C }. -Set Universe Checking. - +Notation "'sigma' x .. y , p" := + (sigT (fun x => .. (sigT (fun y => p)) ..)) + (at level 200, x binder, right associativity, + format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") + : type_scope. (*** DOUBLE CATEGORIES (REVISED) *) @@ -1580,883 +509,3 @@ HB.mixin Record IsDCat_U2 T of CFunctor T := { }. -(*********************************************************************) -(**** GARBAGE ****************************************************) - -(* A quiver from which horizontal morphisms arise (just a copy of quiver) *) -HB.mixin Record IsHQuiver C := { - hhom : C -> C -> U - }. -Unset Universe Checking. -#[short(type="hquiver")] -HB.structure Definition HQuiver : Set := { C of IsHQuiver C }. -Set Universe Checking. - -(* domain-specific sigma-type to represent the set of morphims - (needed for 2-objects, i.e. horizontal morphisms) *) -Record Total2 T (h: T -> T -> U) : Type := HO { - source : T; - target : T; - this_morph : h source target }. - -(* the set of horizontal morphisms. - HB.tag needed to identify HHomSet as lifter *) -HB.tag Definition HHomSet (C: hquiver) := Total2 (@hhom C). - -(* source functor (for horizontal morphisms): D1 -> D0. - defined as object-level function, by functoriality lifted to a - (2-cell, vertical) morphism-level one *) -HB.tag Definition HSource C := fun (X: HHomSet C) => @source C (@hhom C) X. -(* target functor (for horizontal morphisms): D1 -> D0. *) -HB.tag Definition HTarget C := fun (X: HHomSet C) => @target C (@hhom C) X. - -(* D1 quiver requirement. *) -#[wrapper] -HB.mixin Record IsD1Quiver T of HQuiver T := { - d1_quiver : IsQuiver (@HHomSet T) }. -Unset Universe Checking. -#[short(type="d1quiver")] -HB.structure Definition D1Quiver : Set := { C of IsD1Quiver C }. -Set Universe Checking. - -(* all the quivers required by a double category *) -Unset Universe Checking. -#[short(type="dquiver")] -HB.structure Definition DQuiver : Set := - { C of Quiver C & HQuiver C & IsD1Quiver C }. -Set Universe Checking. - -(* used to define composable pairs of morphisms as a set *) -Record GenComp T (h: T -> T -> U) := GC { - c_one : T; - c_two : T ; - c_three : T; - c_first : h c_one c_two ; - c_second : h c_two c_three -}. - -(* composable pairs of horizontal morphisms as a set *) -HB.tag Definition HComp (C: hquiver) := GenComp (@hhom C). - -(* -(* pullback category condition (i.e. (HComp T) is a category). - requires T to be a category, and (HHomSet T) to be a quiver *) -#[wrapper] -HB.mixin Record IsHCompCat T of Cat T & DQuiver T := { - hcompcat : Cat (HComp T) }. -Unset Universe Checking. -#[short(type="hcompcat")] -HB.structure Definition HCompCat : Set := { C of IsHCompCat C }. -Set Universe Checking. -*) - -(* c2unit - horizontal unit functor. - - c2comp - horizontal composition functor. - - Both specified as object-level functions, to be lifted by - functoriality to morphism-level ones. - - At the object level, c2unit gives a horizontal identity morphism - for each D0 object. At the morphism level, it gives horizontal - 2-cell identity for each vertical morphism. - - In the case of HComp, relying on functoriality requires some care - in defining the pullback category, making sure that adjacency at - the object-level (between horizontal morphisms) is matched by - adjacency at the morphism-level (between 2-cells). *) -HB.mixin Record IsC2Quiver T of DQuiver T (* & HCompCat T *) := { - h2unit : forall a: T, @hhom T a a ; - h2comp : forall (a b c: T), - @hhom T a b -> @hhom T b c -> @hhom T a c; - - c2unit : T -> HHomSet T ; - c2comp : HComp T -> HHomSet T ; - - c2unit_eq : forall a: T, c2unit a = @HO T (@hhom T) a a (h2unit a) ; - c2comp_eq1 : forall (a b c: T) (h1: @hhom T a b) (h2: @hhom T b c), - c2comp (@GC T (@hhom T) a b c h1 h2) = - @HO T (@hhom T) a c (h2comp a b c h1 h2) -}. -Unset Universe Checking. -#[short(type="c2quiver")] -HB.structure Definition C2Quiver : Set := { C of IsC2Quiver C }. -Set Universe Checking. - -(************************************************************************************) - -(* Double category *) -Unset Universe Checking. -HB.mixin Record IsDCat T of HCFunctor T := { - left_unital : forall (a b: T) (r: @hhom T a b), - let rr := @HO T (@hhom T) a b r in - let aa := @h2unit T a in - @hom (HHomSet T) (c2comp (@GC T _ a a b aa r)) rr ; - - right_unital : forall (a b: T) (r: @hhom T a b), - let rr := @HO T (@hhom T) a b r in - let bb := @h2unit T b in - @hom (HHomSet T) (c2comp (@GC T _ a b b r bb)) rr ; -}. - -(* Double category *) -Unset Universe Checking. -HB.mixin Record IsDCat T of HCFunctor T := { - left_unital : forall (a b c d: T) (r: @hhom T a c) (s: @hhom T b d), - forall (ha: @hhom T a a) (hb: @hhom T b b), - @hom (HHomSet T) (@HO T (@hhom T) a c r) (@HO T (@hhom T) b d s) = - @hom (HHomSet T) (c2comp (@GC T _ a a c ha r)) - (c2comp (@GC T _ b b d hb s)) ; - - right_unital : forall (a b c d: T) (r: @hhom T a c) (s: @hhom T b d), - forall (ha: @hhom T c c) (hb: @hhom T d d), - @hom (HHomSet T) (@HO T (@hhom T) a c r) (@HO T (@hhom T) b d s) = - @hom (HHomSet T) (c2comp (@GC T _ a c c r ha)) - (c2comp (@GC T _ b d d s hb)) ; - - associator : forall (a0 a1 a2 a3: T) - (h1: @hhom T a0 a1) (h2: @hhom T a1 a2) - (h3: @hhom T a2 a3), - forall (h12: @hhom T a0 a2) (h23: @hhom T a1 a3) (x: HHomSet T), - @HO T (@hhom T) a1 a3 h23 = c2comp (@GC T _ a1 a2 a3 h2 h3) -> - @HO T (@hhom T) a0 a2 h12 = c2comp (@GC T _ a0 a1 a2 h1 h2) -> - let hh1 := c2comp (@GC T _ a0 a1 a3 h1 h23) in - let hh2 := c2comp (@GC T _ a0 a2 a3 h12 h3) in - @hom (HHomSet T) hh1 x = @hom (HHomSet T) hh2 x -}. -#[short(type="dcat")] -HB.structure Definition DCat : Set := { C of IsDCat C }. -Set Universe Checking. - - -(* a sequence of two adjacent morphisms (pullback object), - which we can use to represent composition *) -Record GenComp' T (h: T -> T -> U) := GCmp { - comp_first : @Total2 T h ; - comp_second : @Total2 T h ; - comp_adjacent : target comp_first = source comp_second -}. -(* horizontal morphism composition type. ultimately though, SHOULD - DEPEND ON D0 (hence on 'Quiver T' and 'Quiver (T * T)) *) -Definition HComp' (C: hquiver) := GenComp' (@hhom C). - - -(* source prefunctor. - HHomSet T is the quiver of the 2-morphisms, thanks to H2Quiver. - T is the quiver of 1-morphisms. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsHSPreFunctor T of Cat T & H2Cat T := { - h2s_prefunctor : IsPreFunctor (HHomSet T) T (@Source T) }. -HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. -Set Universe Checking. - -(* target prefunctor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsHTPreFunctor T of Cat T & H2Cat T := { - h2t_prefunctor : IsPreFunctor (HHomSet T) T (@Target T) }. -HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. -Set Universe Checking. - - - -HB.mixin Record IsC2Quiver T of Quiver T & PreC2Quiver T := { - c2left : C2HomSet T -> VHomSet T ; - c2right : C2HomSet T -> VHomSet T ; - - c2unit : forall x:T, HHomSet T ; - - c2left_eq1 : forall d: C2HomSet T, - source (source d) = source (c2left d) ; - c2left_eq2 : forall d: C2HomSet T, - source (target d) = target (c2left d) ; - c2right_eq1 : forall d: C2HomSet T, - target (source d) = source (c2right d) ; - c2right_eq2 : forall d: C2HomSet T, - target (target d) = target (c2right d) ; - - c2unit_eq : forall a: T, - let h := c2unit a in source h = target h ; - -}. -Unset Universe Checking. -#[short(type="c2quiver")] -HB.structure Definition C2Quiver : Set := { C of IsC2Quiver C }. -Set Universe Checking. - -(* left edge functor: D1 -> D0 *) -HB.tag Definition C2Left (C: C2Quiver.type) := - fun (X: C2HomSet C) => @c2left C X. -(* right edge functor: D1 -> D0 *) -HB.tag Definition C2Right (C: C2Quiver.type) := - fun (X: C2HomSet C) => @c2right C X. - - - -(* we need horizontal morphisms to form at least a precategory *) -HB.mixin Record HQuiver_IsHPreCat C of HQuiver C := { - hidmap : forall (a : C), hhom a a; - hcomp : forall d : D1_prod C, - hhom (source (d1_first d)) (target (d1_second d)); -}. -Unset Universe Checking. -#[short(type="hprecat")] -HB.structure Definition HPreCat : Set := { C of HQuiver_IsHPreCat C }. -Set Universe Checking. - - -HB.mixin Record IsH2Grid T of Quiver T & H2Quiver T := { - h2left_edge : H2HomSet T -> VHomSet T ; - h2right_edge : H2HomSet T -> VHomSet T -}. -Unset Universe Checking. -#[short(type="h2grid")] -HB.structure Definition H2Grid : Set := { C of IsH2Grid C }. -Set Universe Checking. - -(* adding the map to define (1) the unit functor D0 -> D1 - and (2) composition D1 *d0 D1 -> D1 *) -HB.mixin Record IsH2FQuiver T of H2Quiver T & H2Grid T & PreCat T := { - h2unit_map: forall x:T, HHomSet T ; - h2unit_map_eq: forall x:T, h2unit_map x = - @HO T (@hhom T) x x (hidmap x) ; - h2comp_map: D1_prod T -> HHomSet T ; - h2comp_map_eq: forall d: D1_prod T, h2comp_map d = - @HO T (@hhom T) (source (d1_first d)) (target (d1_second d)) (hcomp d) -}. -Unset Universe Checking. -#[short(type="h2fquiver")] -HB.structure Definition H2FQuiver : Set := { C of IsH2FQuiver C }. -Set Universe Checking. - -(* Precat based on the H2Quiver (D1). *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2PreCat T of H2FQuiver T := { - h2precat : Quiver_IsPreCat (@HHomSet T) }. -#[short(type="h2precat")] -HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. -Set Universe Checking. - -(* The category based on the H2Quiver (D1). *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2Cat T of H2PreCat T := { - h2cat : PreCat_IsCat (@HHomSet T) }. -#[short(type="h2cat")] -HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. -Set Universe Checking. - -(* -Unset Universe Checking. -#[short(type="predcat")] -HB.structure Definition PreDCat : Set := { D of H2Cat D & H2Grid D }. -Set Universe Checking. -*) - -Record D2_prod T := { - d2_first : @H2HomSet T ; - d2_second : @H2HomSet T ; - d2_adjacent : target d2_first = source d2_second -}. - -(* probably not needed *) -HB.mixin Record HQuiver_IsH2PreCat' C of H2Grid C := { - h2idmap : forall (a : C), hhom a a; - h2comp : forall d : D2_prod C, - h2hom (source (d2_first d)) (target (d2_second d)); -}. -Unset Universe Checking. -#[short(type="hprecat")] -HB.structure Definition H2PreCat' : Set := { C of HQuiver_IsH2PreCat' C }. -Set Universe Checking. - - - -(* -(* gives left and right edges of a 2-cell (i.e. the vertical - morphisms associated with the 2-morphism). - these should be functors - *) -HB.mixin Record IsH2Grid T of Quiver T & H2Quiver T := { - h2left_edge : forall a b c d: T, - forall (h1: hhom a b) (h2: hhom c d), - @hom (@HHomSet T) (@HO T (@hhom T) a b h1) - (@HO T (@hhom T) c d h2) -> @hom T a c ; - h2right_edge : forall a b c d: T, - forall (h1: hhom a b) (h2: hhom c d), - @hom (@HHomSet T) (@HO T (@hhom T) a b h1) - (@HO T (@hhom T) c d h2) -> @hom T b d -}. -Unset Universe Checking. -#[short(type="h2grid")] -HB.structure Definition H2Grid : Set := { C of IsH2Grid C }. -Set Universe Checking. - -(* -(* adding the map to define (1) the unit functor D0 -> D1 - and (2) composition D1 *d0 D1 -> D1 *) -HB.mixin Record IsH2FQuiver T of H2Quiver T := { - h2unit_map: forall x:T, HHomSet T ; - h2unit_map_eq: forall x:T, h2unit_map x = - @HO T (@hhom T) x x (hidmap x) ; - h2comp_map: HHomSet T * HHomSet T -> HHomSet T ; - h2comp_map_eq: forall (a b c: T) (h1: hhom a b) (h2: hhom b c), - let x := @HO T (@hhom T) a b h1 - in let y := @HO T (@hhom T) b c h2 - in let z := @HO T (@hhom T) a c (hcomp a b c h1 h2) - in h2comp_map (x, y) = z }. -Unset Universe Checking. -#[short(type="h2fquiver")] -HB.structure Definition H2FQuiver : Set := { C of IsH2FQuiver C }. -Set Universe Checking. -*) -(* -(* adding the map to define the unit functor D0 -> D1 *) -HB.mixin Record IsH2FQuiver T of H2Quiver T := { - h2unit_map: forall x:T, HHomSet T ; - h2unit_map_eq: forall x:T, let y := h2unit_map x in - source y = target y ; - h2comp_map: HHomSet T * HHomSet T -> HHomSet T ; - h2comp_map_eq: forall x y: HHomSet T, target x = source y -> - exists f: hhom (source x) (target y), - h2comp_map (x, y) = @HO T (@hhom T) (source x) (target y) f ; -(* square_comp : forall (a1 b1 c1 a2 b2 c2: T), - forall (ha1: hhom a1 b1) (hb1: hhom b1 c1) - (ha2: hhom a2 b2) (hb2: hhom b2 c2), *) - }. -Unset Universe Checking. -#[short(type="h2fquiver")] -HB.structure Definition H2FQuiver : Set := { C of IsH2FQuiver C }. -Set Universe Checking. -*) - -(* Precat based on the H2Quiver (D1). *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2PreCat T of H2FQuiver T := { - h2precat : Quiver_IsPreCat (@HHomSet T) }. -#[short(type="h2precat")] -HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. -Set Universe Checking. - -(* The category based on the H2Quiver (D1). *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2Cat T of H2PreCat T := { - h2cat : PreCat_IsCat (@HHomSet T) }. -#[short(type="h2cat")] -HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. -Set Universe Checking. - -(* Pre-double category, with horizontal 2-cell composition *) -Unset Universe Checking. -HB.mixin Record IsPreDCat T of Cat T & H2Cat T & H2Grid T := { - h2adjacent : forall (a b c d e f: T), - forall (h1: hhom a b) (h2: hhom b c) (h3: hhom d e) (h4: hhom e f), - forall (hh1: @hom (@HHomSet T) (@HO T (@hhom T) a b h1) - (@HO T (@hhom T) d e h3)) - (hh2: @hom (@HHomSet T) (@HO T (@hhom T) b c h2) - (@HO T (@hhom T) e f h4)), - h2right_edge a b d e h1 h3 hh1 = - h2left_edge b c e f h2 h4 hh2 ; - - h2comp : forall (h1 h2 h3 h4: HHomSet T), - forall (hh1: h1 ~> h2) (hh2: h3 ~> h4), - h2comp_map (h1,h3) ~> h2comp_map (h2,h4) ; - -(* - h2comp_eq : forall (a b c d e f: T), - forall (h1: hhom a b) (h2: hhom b c) (h3: hhom d e) (h4: hhom e f), - forall (hh1: @hom (@HHomSet T) (@HO T (@hhom T) a b h1) - (@HO T (@hhom T) d e h3)) - (hh2: @hom (@HHomSet T) (@HO T (@hhom T) b c h2) - (@HO T (@hhom T) e f h4)), - h2adjacent a b c d e f h1 h2 hh1 hh2 -> - let h1' := (@HO T (@hhom T) a b h1) - in let h2' := (@HO T (@hhom T) b c h2) - in let h3' := (@HO T (@hhom T) d e h3) - in let h4' := (@HO T (@hhom T) e f h4) - h2comp h1' h2' h3' h4' hh1 hh2 = -*) - }. -#[short(type="predcat")] -HB.structure Definition PreDCat : Set := { D of IsPreDCat D }. -Set Universe Checking. - - -*) - -(* source functor: D1 -> D0 *) -HB.tag Definition Source C := fun (X: HHomSet C) => @source C (@hhom C) X. -(* target functor: D1 -> D0 *) -HB.tag Definition Target C := fun (X: HHomSet C) => @target C (@hhom C) X. -(* unit functor: D0 -> D1 *) -HB.tag Definition UnitF (C: h2fquiver) := - fun (x:H2FQuiver.sort C) => @h2unit_map C x. - -(* source prefunctor. - HHomSet T is the quiver of the 2-morphisms, thanks to H2Quiver. - T is the quiver of 1-morphisms. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsHSPreFunctor T of Cat T & H2Cat T := { - h2s_prefunctor : IsPreFunctor (HHomSet T) T (@Source T) }. -HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. -Set Universe Checking. - -(* target prefunctor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsHTPreFunctor T of Cat T & H2Cat T := { - h2t_prefunctor : IsPreFunctor (HHomSet T) T (@Target T) }. -HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. -Set Universe Checking. - - - -HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. -Set Universe Checking. - -(* source functor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record HSPreFunctor_IsFunctor T of Cat T & HSPreFunctor T := { - h2s_functor : PreFunctor_IsFunctor (HHomSet T) T (@Source T) }. -HB.structure Definition HSFunctor : Set := {C of HSPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* target functor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record HTPreFunctor_IsFunctor T of Cat T & HTPreFunctor T := { - h2t_functor : PreFunctor_IsFunctor (HHomSet T) T (@Target T) }. -HB.structure Definition HTFunctor : Set := {C of HTPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* unit prefunctor. *) -Unset Universe Checking. - #[wrapper] -HB.mixin Record IsHUPreFunctor T of Cat T & PreDCat T := { - h2u_prefunctor : IsPreFunctor T (HHomSet T) (@UnitF T) }. -HB.structure Definition HUPreFunctor : Set := {C of IsHUPreFunctor C}. -Set Universe Checking. - - -Unset Universe Checking. - #[wrapper] -HB.mixin Record HUPreFunctor_IsFunctor T of Cat T & HUPreFunctor T := { - h2u_functor : PreFunctor_IsFunctor T (HHomSet T) (@UnitF T) }. - HB.structure Definition HUFunctor : Set := {T of - Cat T & HUPreFunctor T & - PreFunctor_IsFunctor T (HHomSet T) (@UnitF T) - }. -Set Universe Checking. - - -Unset Universe Checking. - #[wrapper] -HB.mixin Record HUPreFunctor_IsFunctor T of Cat T & HUPreFunctor T := { - h2u_functor : PreFunctor_IsFunctor T (HHomSet T) (@UnitF T) }. -HB.structure Definition HUFunctor : Set := {C of HUPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* double category *) -Unset Universe Checking. -HB.structure Definition DCat : Set := - {D of HSPreFunctor_IsFunctor D & HTPreFunctor_IsFunctor D & - HUPreFunctor_IsFunctor D}. -Set Universe Checking. - -(* 2-morphisms *) -Definition h2hom (D: DCat.type) := @hom (@HHomSet D). - -(* still don't understand - transposition whould swap vertical and horizontal morphisms, - i.e. hom and hhom *) -Definition transpose1 (D: DCat.type) : U := D. -(* however, given transpose1 this should hold *) -Lemma hom_transpose (D: DCat.type) : @hom (transpose1 D) = @hhom D. -Admitted. -(* and this too *) -Lemma hhom_transpose (D: DCat.type) : @hhom (transpose1 D) = @hom D. -Admitted. - -(* tranposition as a relation *) -Definition isTranspose C - (FQ: PreDCat C -> Quiver C) - (FHQ: PreDCat C -> HQuiver C) - (D1 D2: PreDCat C) : Type := - @hom (Quiver.Pack (FQ D2)) = @hhom (HQuiver.Pack (FHQ D1)) /\ - @hhom (HQuiver.Pack (FHQ D2)) = @hom (Quiver.Pack (FQ D1)). - -Definition transpose_isquiver C (X: IsQuiver C) : IsHQuiver C. - destruct X. - econstructor. - exact hom0. -Defined. - -Definition transpose_ishquiver C (X: IsHQuiver C) : IsQuiver C. - destruct X. - econstructor. - exact hhom0. -Defined. - -Definition transpose_quiver C (X: Quiver C) : HQuiver C. - destruct X. - econstructor. - eapply transpose_isquiver; eauto. -Defined. - -Definition transpose_hquiver C (X: HQuiver C) : Quiver C. - destruct X. - econstructor. - eapply transpose_ishquiver; eauto. -Defined. - -(* tranposition as a relation, using the transpose functions *) -Definition isTransposeF C - (FQ: PreDCat C -> Quiver C) - (FHQ: PreDCat C -> HQuiver C) - (D1 D2: PreDCat C) : Type := - Quiver.Pack (FQ D2) = Quiver.Pack (@transpose_hquiver C (FHQ D1)) /\ - HQuiver.Pack (FHQ D2) = HQuiver.Pack (@transpose_quiver C (FQ D1)). - - - -(*** DOUBLE CATEGORIES (PREVIOUS) *) - -(* A quiver from which horizontal morphisms arise. D1 is the type of - D1 objects (horizontal morphisms in C), with source and target - functors. *) -HB.mixin Record HasD1 C := { - D1 : U ; - s10 : D1 -> C ; - t10 : D1 -> C }. -Unset Universe Checking. -#[short(type="hquiver")] -HB.structure Definition D1type : Set := { C of HasD1 C }. -Set Universe Checking. - -(* A quiver from which 2-morphisms arise as arrows between 2-objects - (i.e. horizontal morphisms) *) -#[wrapper] -HB.mixin Record IsH2Quiver T of HasD1 T := { - h2quiver : IsQuiver (@D1 T) }. -Unset Universe Checking. -#[short(type="h2quiver")] -HB.structure Definition H2Quiver : Set := { C of IsH2Quiver C }. -Set Universe Checking. - -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2PreCat T of H2Quiver T := { - h2precat : Quiver_IsPreCat (@D1 T) }. -#[short(type="h2precat")] -HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. -Set Universe Checking. - -(* The category based on the H2Quiver (D1). *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2Cat T of H2PreCat T := { - h2cat : PreCat_IsCat (@D1 T) }. -#[short(type="h2cat")] -#[verbose] -HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. -Set Universe Checking. - -(* Pre-double category (no functors yet): this corresponds to the old -definition *) -Unset Universe Checking. -HB.structure Definition PreDCat : Set := { D of Cat D & H2Cat D }. -Set Universe Checking. - -(* source prefunctor. - D1 here is the quiver of the 2-morphisms, thanks to IsH2Quiver. - T is the quiver of 1-morphisms. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsHSPreFunctor T of Cat T & H2Cat T := { - h2s_prefunctor : IsPreFunctor D1 T s10 }. -HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. -Set Universe Checking. - -(* target prefunctor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsHTPreFunctor T of Cat T & H2Cat T := { - h2t_prefunctor : IsPreFunctor D1 T t10 }. -HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. -Set Universe Checking. - -(* source functor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record HSPreFunctor_IsFunctor T of Cat T & HSPreFunctor T := { - h2s_prefunctor : PreFunctor_IsFunctor D1 T s10 }. -HB.structure Definition HSFunctor : Set := {C of HSPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* target functor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record HTPreFunctor_IsFunctor T of Cat T & HTPreFunctor T := { - h2t_prefunctor : PreFunctor_IsFunctor D1 T t10 }. -HB.structure Definition HTFunctor : Set := {C of HTPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* double category *) -Unset Universe Checking. -HB.structure Definition DCat : Set := - {D of HSPreFunctor_IsFunctor D & HTPreFunctor_IsFunctor D }. -Set Universe Checking. - -(* 2-morphisms *) -Definition hhom (D: DCat.type) := @hom (@D1 D). - -Definition transpose (D: DCat.type) : U := D. - -Fail Lemma hom_transpose (D: DCat.type) : @hom (transpose D) = @hhom D. - -Fail Lemma hhom_transpose (D: DCat.type) : @hhom (transpose D) = @hom D. - - - -(*** DOUBLE CATEGORIES (OLD) *) - -(* A quiver from which horizontal morphisms arise (just a copy of quiver) *) -HB.mixin Record IsHQuiver C := { hhom : C -> C -> U }. -Unset Universe Checking. -#[short(type="hquiver")] -HB.structure Definition HQuiver : Set := { C of IsHQuiver C }. -Set Universe Checking. - -(* domain-specific sigma-type to represent the 2-objects *) -Record Total2 T (h: T -> T -> U) : Type := HO { - source : T; - target : T; - this_hom : h source target }. - -(* needed to identify HHomSet as lifter *) -HB.tag Definition HHomSet (C: hquiver) := Total2 (@hhom C). - -(* A quiver from which 2-morphisms arise as arrows between 2-objects - (i.e. horizontal morphisms) *) -#[wrapper] -HB.mixin Record IsH2Quiver T of HQuiver T := { - h2quiver : Quiver (@HHomSet T) }. -Unset Universe Checking. -#[short(type="h2quiver")] -HB.structure Definition H2Quiver : Set := { C of IsH2Quiver C }. -Set Universe Checking. - -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2PreCat T of HQuiver T & H2Quiver T := { - h2precat : Quiver_IsPreCat (@HHomSet T) }. -#[short(type="h2precat")] -HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. -Set Universe Checking. - -(* The category based on the H2Quiver (D1). *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2Cat T of H2PreCat T := { - h2cat : PreCat_IsCat (@HHomSet T) }. -#[short(type="h2cat")] -HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. -Set Universe Checking. - -(* Double categories, from - https://ncatlab.org/nlab/show/double+category - - The definition we follow here however is a comparatively informal - one, which also mentions internal categories (not formalized yet). - - Double category (D0, D1). - - base obejcts (D0): C ; - - vertical morphisms (D0): @hom C ; - - horizontal morhisms (and 2-objects, D1): @HHomSet C ; - - 2-morphisms (D1): @hom (@HHomSet C) *) -Unset Universe Checking. -#[short(type="dcat")] -HB.structure Definition DCat : Set := { C of Cat C & H2Cat C }. -Set Universe Checking. - - - -(*******************************************************************) - -(*** Related to BICATEGORIES (just an experiment, - not the right formalization) *) - -(* We want to factor constants and operators out of the axioms. - Suggestion: introduce some notion of module to bind them - together. *) - -(* monoid axioms *) -HB.mixin Record isMonoid T (mu: T) (mc: T -> T -> T): Type := { - massoc : associative mc; - mlid : left_id mu mc ; - mrid : right_id mu mc ; -}. - -(* to be used as homset identity in bicategories *) -HB.mixin Record isHId T := { - hid : T; -}. -HB.structure Definition HId := { T of isHId T }. - -(* to be used as homset composition in bicategories *) -HB.mixin Record isHComp T := { - hcomp : T -> T -> T; -}. -HB.structure Definition HComp := { T of isHComp T }. - -#[wrapper] -HB.mixin Record Quiver_HasId T of Quiver T := - { Quiver_HasId_private : forall A B, isHId (@hom T A B) }. -HB.structure Definition HasId := - { Obj of Quiver Obj & Quiver_HasId Obj }. - -#[wrapper] -HB.mixin Record Quiver_HasComp T of Quiver T := - { Quiver_HasComp_private : forall A B, isHComp (@hom T A B) }. -HB.structure Definition HasComp := - { Obj of Quiver Obj & Quiver_HasComp Obj }. - -(* a bicategory, without axioms *) -HB.structure Definition BiCatQuiver := - {T of Quiver_HasId T & Quiver_HasComp T}. - -#[wrapper] -HB.mixin Record isHMonoid T of HId T & HComp T := - { isHMonoid_private: isMonoid T (hid: T) (@hcomp T) }. -#[verbose] -HB.structure Definition HMonoid := { T of isHMonoid T }. - -#[wrapper] -(* does not work (generic Elpi error): - HB.mixin Record isHCat T of precat_quiver T := *) -HB.mixin Record isPreBiCategory T of IsPreCat T := - { isPreBiCategory_private : forall A B: T, HMonoid (@hom T A B) }. -HB.structure Definition PreBiCategory := - { Obj of isPreBiCategory Obj }. - -(* to be used as object monoid unit *) -HB.mixin Record isMUnit T := { - munit : T; -}. -HB.structure Definition MUnit := { T of isMUnit T }. - -(* to be used as object monoid composition *) -HB.mixin Record isMComp T := { - mcomp : T -> T -> T; -}. -HB.structure Definition MComp := { T of isMComp T }. - -(* has object monoid operators *) -HB.structure Definition Premonoid := - {T of isMUnit T & isMComp T}. - -(* the precategory has monoidal operators *) -HB.structure Definition Precat_IsPremonoidal := - {T of PreCat T & Premonoid T}. - -(* object monoid *) -HB.mixin Record isOMonoid T of isMUnit T & isMComp T := - { isHMonoid_private: isMonoid T (munit: T) (mcomp: T -> T -> T) }. -#[verbose] -HB.structure Definition OMonoid := { T of isOMonoid T }. - -(* some sort of monoidal category *) -HB.structure Definition PreMonBiCategory := - { Obj of PreBiCategory Obj & OMonoid Obj }. - - -(*******************************************************************) - -Section th_of_pb. -Variables (Q : cat) (A B C D E F : Q). -Variables (f : A ~> D) (g : B ~> D) (h : C ~> A). -Variables (u : E ~> A) (v : E ~> B) (w : F ~> C) (z : F ~> E). -Variable (uvfg : pbsquare u v f g). - -Set Printing Width 50. -Theorem pbsquarec_compP : - pbsquare w z h u <=> pbsquare w (z \; v) (h \; f) g. -Proof. -split=> [] sq. - - have @sq_ispb : pullback (Cospan h u) := HB.pack (Span w z) sq. - have @uvfg_ispb : pullback (Cospan f g) := HB.pack (Span u v) uvfg. - have /=E2 := @is_square _ _ _ _ sq_ispb. - have /=E1 := @is_square _ _ _ _ uvfg_ispb. - - have p1 : @isPrePullback Q C B (Cospan (h \; f) g) (Span w (z \; v)). - by constructor; rewrite /= compoA E2 -compoA E1 compoA. - pose big_black_square : prepullback (Cospan (h \; f) g) := - HB.pack (Span w (z \; v)) p1. - - have @from : forall - (big_red_square : prepullback {| top := D; left2top := h \; f; right2top := g |}), - big_red_square ~> pb_terminal big_black_square. - - move=> big_red_square; unfold pb_terminal. - - have /= := @is_square _ _ _ _ big_red_square. - - pose F' := bot big_red_square. - set w' : F' ~> C := bot2left big_red_square. - set z' : F' ~> B := bot2right big_red_square. - move=> E3. - - have xxx : isPrePullback Q A B (Cospan f g) (Span (w' \; h) z'). - by constructor=> /=; rewrite -compoA E3. - pose red_black_square : prepullback (Cospan f g) := - HB.pack (Span (w' \; h) z') xxx. - have := @from_unique _ (pb_terminal uvfg_ispb) red_black_square. - set blue := @from _ (pb_terminal uvfg_ispb) red_black_square. - move=> blue_unique. - - have p3 : @isPrePullback Q C E (Cospan h u) (Span w' (bot_map blue)). - by constructor; rewrite /= (bot2left_map blue). (* buggy unifier without blue *) - pose blue_red_black_square : prepullback (Cospan h u) := - HB.pack (Span w' (bot_map blue)) p3. - - pose red := @from _ (pb_terminal sq_ispb) blue_red_black_square. - - admit. - - - - have p2 : prepullback_isTerminal.axioms_ Q C B (Cospan (h \; f) g) (Span w (z \; v)) p1. - constructor. econstructor=> /=. - admit. - - by HB.from p1 p2. - -Admitted. - -End th_of_pb. - - -Module test. - -Section test. -Variables (Q : precat) (A B : Q) (c : cospan A B). -Variable (p : pullback c). -Check pb_terminal p : terminal _. - -End test. -End test. - - - - diff --git a/theories/encatD.v b/theories/encatD.v index a5fb4d157..de39bddde 100644 --- a/theories/encatD.v +++ b/theories/encatD.v @@ -1,1057 +1,28 @@ -Require Import Coq.Program.Equality. Require Import ssreflect ssrfun. -From HB Require Import structures. +Unset Universe Checking. +From HB Require Import structures cat. +Set Universe Checking. +Require Import Coq.Program.Equality. Set Implicit Arguments. Unset Strict Implicit. Unset Printing Implicit Defensive. Add Search Blacklist "__canonical__". -Declare Scope algebra_scope. -Delimit Scope algebra_scope with A. Local Open Scope algebra_scope. -Declare Scope cat_scope. -Delimit Scope cat_scope with cat. Local Open Scope cat_scope. -(* we assume a few axioms to make life easier *) -Axiom funext : forall {T : Type} {U : T -> Type} [f g : forall t, U t], - (forall t, f t = g t) -> f = g. -Axiom propext : forall P Q : Prop, P <-> Q -> P = Q. -Axiom Prop_irrelevance : forall (P : Prop) (x y : P), x = y. - -(* Shortcut *) -Notation U := Type. - -(* Base definition : raw categories = quivers *) -HB.mixin Record IsQuiver C := { hom : C -> C -> U }. -Unset Universe Checking. -#[short(type="quiver")] -HB.structure Definition Quiver : Set := { C of IsQuiver C }. -Set Universe Checking. - -Bind Scope cat_scope with quiver. -Bind Scope cat_scope with hom. -Arguments hom {C} : rename. -Notation homs T := (@hom T _ _). -Notation "a ~> b" := (hom a b) - (at level 99, b at level 200, format "a ~> b") : cat_scope. -Notation "a ~>_ C b" := (@hom C (a : C) (b : C)) - (at level 99, C at level 0, only parsing) : cat_scope. - -(* precategories are quivers + id and comp *) -HB.mixin Record Quiver_IsPreCat C of Quiver C := { - idmap : forall (a : C), a ~> a; - comp : forall (a b c : C), (a ~> b) -> (b ~> c) -> (a ~> c); -}. - -HB.factory Record IsPreCat C := { - hom : C -> C -> U; - idmap : forall (a : C), hom a a; - comp : forall (a b c : C), hom a b -> hom b c -> hom a c; -}. -HB.builders Context C of IsPreCat C. - HB.instance Definition _ := IsQuiver.Build C hom. - HB.instance Definition _ := Quiver_IsPreCat.Build C idmap comp. -HB.end. - -Unset Universe Checking. -#[short(type="precat")] -HB.structure Definition PreCat : Set := { C of IsPreCat C }. -Set Universe Checking. - -Bind Scope cat_scope with precat. -Arguments idmap {C} {a} : rename. -Arguments comp {C} {a b c} : rename. -Notation "f \o g" := (comp g f) : cat_scope. -Notation "f \; g :> T" := (@comp T _ _ _ f g) - (at level 60, g, T at level 60, format "f \; g :> T", only parsing) : cat_scope. -Notation "f \; g" := (comp f g) : cat_scope. -Notation "\idmap_ a" := (@idmap _ a) (only parsing, at level 0) : cat_scope. - -(* categories are precategories + laws *) -HB.mixin Record PreCat_IsCat C of PreCat C := { - comp1o : forall (a b : C) (f : a ~> b), idmap \; f = f; - compo1 : forall (a b : C) (f : a ~> b), f \; idmap = f; - compoA : forall (a b c d : C) (f : a ~> b) (g : b ~> c) (h : c ~> d), - f \; (g \; h) = (f \; g) \; h -}. -Unset Universe Checking. -#[short(type="cat")] -HB.structure Definition Cat : Set := { C of PreCat_IsCat C & IsPreCat C }. -Set Universe Checking. - -Bind Scope cat_scope with cat. -Arguments compo1 {C a b} : rename. -Arguments comp1o {C a b} : rename. -Arguments compoA {C a b c d} : rename. - -(* the discrete category on a type cannot be the default, we make an alias *) -Definition discrete (T : U) := T. -HB.instance Definition _ T := @IsPreCat.Build (discrete T) (fun x y => x = y) - (fun=> erefl) (@etrans _). -Lemma etransA T (a b c d : discrete T) (f : a ~> b) (g : b ~> c) (h : c ~> d) : - f \; (g \; h) = (f \; g) \; h. -Proof. by rewrite /idmap/comp/=; case: _ / h; case: _ / g. Qed. -HB.instance Definition _ T := PreCat_IsCat.Build (discrete T) (@etrans_id _) - (fun _ _ _ => erefl) (@etransA _). - -(* the category of the unit type is the discrete one *) -HB.instance Definition _ := Cat.copy unit (discrete unit). - -HB.instance Definition _ := @IsPreCat.Build U (fun A B => A -> B) - (fun a => idfun) (fun a b c (f : a -> b) (g : b -> c) => (g \o f)%FUN). -HB.instance Definition _ := PreCat_IsCat.Build U (fun _ _ _ => erefl) - (fun _ _ _ => erefl) (fun _ _ _ _ _ _ _ => erefl). - - -Lemma Ucomp (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) : f \; g = (g \o f)%FUN. -Proof. by []. Qed. -Lemma Ucompx (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) x : (f \; g) x = g (f x). -Proof. by []. Qed. -Lemma U1 (X : U) : \idmap_X = idfun. -Proof. by []. Qed. -Lemma U1x (X : U) x : \idmap_X x = x. -Proof. by []. Qed. - -(* a prefunctor is a functor without laws *) -HB.mixin Record IsPreFunctor (C D : quiver) (F : C -> D) := { - Fhom : forall (a b : C), (a ~> b) -> (F a ~> F b) -}. - -Unset Universe Checking. -HB.structure Definition PreFunctor (C D : quiver) : Set := - { F of IsPreFunctor C D F }. -Set Universe Checking. -HB.instance Definition _ := IsQuiver.Build quiver PreFunctor.type. - -Notation "F ^$" := (@Fhom _ _ F _ _) - (at level 1, format "F ^$") : cat_scope. -Notation "F <$> f" := (@Fhom _ _ F _ _ f) - (at level 58, format "F <$> f", right associativity) : cat_scope. - -(* prefunctors are equal if their object and hom part are respectively equal *) -Lemma prefunctorP (C D : quiver) (F G : C ~> D) (eqFG : F =1 G) : - let homF a b F := F a ~> F b in - (forall a b f, eq_rect _ (homF a b) (F <$> f) _ (funext eqFG) = G <$> f) -> - F = G. -Proof. -move: F G => [F [[/= Fhom]]] [G [[/= Ghom]]] in eqFG *. -case: _ / (funext eqFG) => /= in Ghom * => eqFGhom. -congr PreFunctor.Pack; congr PreFunctor.Class; congr IsPreFunctor.Axioms_. -by do 3!apply: funext=> ?. -Qed. - -(* a functor is a prefunctor + laws for id and comp *) -HB.mixin Record PreFunctor_IsFunctor (C D : precat) (F : C -> D) - of @PreFunctor C D F := { - F1 : forall (a : C), F <$> \idmap_a = idmap; - Fcomp : forall (a b c : C) (f : a ~> b) (g : b ~> c), - F <$> (f \; g) = F <$> f \; F <$> g; -}. -Unset Universe Checking. - -(* precat and cat have a quiver structure *) -HB.structure Definition Functor (C D : precat) : Set := - { F of IsPreFunctor C D F & PreFunctor_IsFunctor C D F }. -Set Universe Checking. -HB.instance Definition _ := IsQuiver.Build precat Functor.type. -HB.instance Definition _ := IsQuiver.Build cat Functor.type. - -(* functor equality is the same as prefunctor because of PI *) -Lemma functorP (C D : precat) (F G : C ~> D) (eqFG : F =1 G) : - let homF a b F := F a ~> F b in - (forall a b f, eq_rect _ (homF a b) (F^$ f) _ (funext eqFG) = G^$ f) -> - F = G. -Proof. -move=> /= /prefunctorP {eqFG}. -case: F G => [F [/= Fm Fm']] [G [/= Gm Gm']]//=. -move=> [_] /EqdepFacts.eq_sigT_iff_eq_dep eqFG. -case: _ / eqFG in Gm' *. -congr Functor.Pack; congr Functor.Class. -case: Fm' Gm' => [F1 Fc] [G1 Gc]. -by congr PreFunctor_IsFunctor.Axioms_; apply: Prop_irrelevance. -Qed. - -(* the identity function is a functor *) -HB.instance Definition _ (C : quiver) := - IsPreFunctor.Build C C idfun (fun a b => idfun). -HB.instance Definition _ (C : precat) := - PreFunctor_IsFunctor.Build C C idfun (fun=> erefl) (fun _ _ _ _ _ => erefl). - -(* the composition of prefunctors *) -Section comp_prefunctor. -Context {C D E : quiver} {F : C ~> D} {G : D ~> E}. - -HB.instance Definition _ := IsPreFunctor.Build C E (G \o F)%FUN - (fun a b f => G <$> F <$> f). -Lemma comp_Fun (a b : C) (f : a ~> b) : (G \o F)%FUN <$> f = G <$> (F <$> f). -Proof. by []. Qed. -End comp_prefunctor. - -Section comp_functor. -Context {C D E : precat} {F : C ~> D} {G : D ~> E}. -Lemma comp_F1 (a : C) : (G \o F)%FUN <$> \idmap_a = idmap. -Proof. by rewrite !comp_Fun !F1. Qed. -Lemma comp_Fcomp (a b c : C) (f : a ~> b) (g : b ~> c) : - (G \o F)%FUN <$> (f \; g) = (G \o F)%FUN <$> f \; (G \o F)%FUN <$> g. -Proof. by rewrite !comp_Fun !Fcomp. Qed. -HB.instance Definition _ := PreFunctor_IsFunctor.Build C E (G \o F)%FUN - comp_F1 comp_Fcomp. -End comp_functor. - -(* precat and cat have a precategory structure *) -HB.instance Definition _ := Quiver_IsPreCat.Build precat - (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). -HB.instance Definition _ := Quiver_IsPreCat.Build cat - (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). - -Lemma funext_frefl A B (f : A -> B) : funext (frefl f) = erefl. -Proof. exact: Prop_irrelevance. Qed. - -(* precategories and categories form a category *) -Definition precat_cat : PreCat_IsCat precat. -Proof. -by split=> [C D F|C D F|C D C' D' F G H]; - apply/functorP => a b f /=; rewrite funext_frefl. -Qed. -HB.instance Definition _ := precat_cat. -Definition cat_cat : PreCat_IsCat cat. -Proof. -by split=> [C D F|C D F|C D C' D' F G H]; - apply/functorP => a b f /=; rewrite funext_frefl. -Qed. -HB.instance Definition _ := cat_cat. - -Check (cat : cat). - -(* concrete categories *) -HB.mixin Record Quiver_IsPreConcrete T of Quiver T := { - concrete : T -> U; - concrete_fun : forall (a b : T), (a ~> b) -> concrete a -> concrete b; -}. -Unset Universe Checking. -#[short(type="preconcrete_quiver")] -HB.structure Definition PreConcreteQuiver : Set := - { C of Quiver_IsPreConcrete C & IsQuiver C }. -Set Universe Checking. -Coercion concrete : PreConcreteQuiver.sort >-> Sortclass. - -HB.mixin Record PreConcrete_IsConcrete T of PreConcreteQuiver T := { - concrete_fun_inj : forall (a b : T), injective (concrete_fun a b) -}. -Unset Universe Checking. -#[short(type="concrete_quiver")] -HB.structure Definition ConcreteQuiver : Set := - { C of PreConcreteQuiver C & PreConcrete_IsConcrete C }. -Set Universe Checking. - -HB.instance Definition _ (C : ConcreteQuiver.type) := - IsPreFunctor.Build _ _ (concrete : C -> U) concrete_fun. - -HB.mixin Record PreCat_IsConcrete T of ConcreteQuiver T & PreCat T := { - concrete1 : forall (a : T), concrete <$> \idmap_a = idfun; - concrete_comp : forall (a b c : T) (f : a ~> b) (g : b ~> c), - concrete <$> (f \; g) = ((concrete <$> g) \o (concrete <$> f))%FUN; -}. -Unset Universe Checking. -#[short(type="concrete_precat")] -HB.structure Definition ConcretePreCat : Set := - { C of PreCat C & ConcreteQuiver C & PreCat_IsConcrete C }. -#[short(type="concrete_cat")] -HB.structure Definition ConcreteCat : Set := - { C of Cat C & ConcreteQuiver C & PreCat_IsConcrete C }. -Set Universe Checking. - -HB.instance Definition _ (C : concrete_precat) := - PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). -HB.instance Definition _ (C : ConcreteCat.type) := - PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). - -HB.instance Definition _ := Quiver_IsPreConcrete.Build U (fun _ _ => id). -HB.instance Definition _ := PreConcrete_IsConcrete.Build U (fun _ _ _ _ => id). -HB.instance Definition _ := PreCat_IsConcrete.Build U - (fun=> erefl) (fun _ _ _ _ _ => erefl). - -Unset Universe Checking. -HB.instance Definition _ := Quiver_IsPreConcrete.Build quiver (fun _ _ => id). -HB.instance Definition _ := Quiver_IsPreConcrete.Build precat (fun _ _ => id). -HB.instance Definition _ := Quiver_IsPreConcrete.Build cat (fun _ _ => id). -Lemma quiver_concrete_subproof : PreConcrete_IsConcrete quiver. -Proof. -constructor=> C D F G FG; apply: prefunctorP. - by move=> x; congr (_ x); apply: FG. -by move=> *; apply: Prop_irrelevance. -Qed. -HB.instance Definition _ := quiver_concrete_subproof. - -Lemma precat_concrete_subproof : PreConcrete_IsConcrete precat. -Proof. -constructor=> C D F G FG; apply: functorP. - by move=> x; congr (_ x); apply: FG. -by move=> *; apply: Prop_irrelevance. -Qed. -HB.instance Definition _ := precat_concrete_subproof. - -Lemma cat_concrete_subproof : PreConcrete_IsConcrete cat. -Proof. -constructor=> C D F G FG; apply: functorP. - by move=> x; congr (_ x); apply: FG. -by move=> *; apply: Prop_irrelevance. -Qed. -HB.instance Definition _ := cat_concrete_subproof. -HB.instance Definition _ := PreCat_IsConcrete.Build precat - (fun=> erefl) (fun _ _ _ _ _ => erefl). -HB.instance Definition _ := PreCat_IsConcrete.Build cat - (fun=> erefl) (fun _ _ _ _ _ => erefl). -Set Universe Checking. - -(* constant functor *) -Definition cst (C D : quiver) (c : C) := fun of D => c. -Arguments cst {C} D c. -HB.instance Definition _ {C D : precat} (c : C) := - IsPreFunctor.Build D C (cst D c) (fun _ _ _ => idmap). -HB.instance Definition _ {C D : cat} (c : C) := - PreFunctor_IsFunctor.Build D C (cst D c) (fun=> erefl) - (fun _ _ _ _ _ => esym (compo1 idmap)). - -(* opposite category *) -Definition catop (C : U) : U := C. -Notation "C ^op" := (catop C) - (at level 2, format "C ^op") : cat_scope. -HB.instance Definition _ (C : quiver) := - IsQuiver.Build C^op (fun a b => hom b a). -HB.instance Definition _ (C : precat) := - Quiver_IsPreCat.Build (C^op) (fun=> idmap) (fun _ _ _ f g => g \; f). -HB.instance Definition _ (C : cat) := PreCat_IsCat.Build (C^op) - (fun _ _ _ => compo1 _) (fun _ _ _ => comp1o _) - (fun _ _ _ _ _ _ _ => esym (compoA _ _ _)). - -HB.instance Definition _ {C : precat} {c : C} := - IsPreFunctor.Build C _ (hom c) (fun a b f g => g \; f). -Lemma hom_Fhom_subproof (C : cat) (x : C) : - PreFunctor_IsFunctor _ _ (hom x). -Proof. by split=> *; apply/funext => h; [apply: compo1 | apply: compoA]. Qed. -HB.instance Definition _ {C : cat} {c : C} := hom_Fhom_subproof c. - -Check fun (C : cat) (x : C) => hom x : C ~>_cat U. - -Lemma hom_op {C : quiver} (c : C^op) : hom c = (@hom C)^~ c. -Proof. reflexivity. Qed. - -Lemma homFhomx {C : precat} (a b c : C) (f : a ~> b) (g : c ~> a) : - (hom c <$> f) g = g \; f. -Proof. reflexivity. Qed. - -(* nary product of categories *) -Definition dprod {I : U} (C : I -> U) := forall i, C i. - -Section hom_dprod. -Context {I : U} (C : I -> quiver). -Definition dprod_hom_subdef (a b : dprod C) := forall i, a i ~> b i. -HB.instance Definition _ := IsQuiver.Build (dprod C) dprod_hom_subdef. -End hom_dprod. -Arguments dprod_hom_subdef /. - -Section precat_dprod. -Context {I : U} (C : I -> precat). -Definition dprod_idmap_subdef (a : dprod C) : a ~> a := fun=> idmap. -Definition dprod_comp_subdef (a b c : dprod C) (f : a ~> b) (g : b ~> c) : a ~> c := - fun i => f i \; g i. -HB.instance Definition _ := IsPreCat.Build (dprod C) - dprod_idmap_subdef dprod_comp_subdef. -End precat_dprod. -Arguments dprod_idmap_subdef /. -Arguments dprod_comp_subdef /. - -Section cat_dprod. -Context {I : U} (C : I -> cat). -Local Notation type := (dprod C). -Lemma dprod_is_cat : PreCat_IsCat type. -Proof. -split=> [a b f|a b f|a b c d f g h]; apply/funext => i; -[exact: comp1o | exact: compo1 | exact: compoA]. -Qed. -HB.instance Definition _ := dprod_is_cat. -End cat_dprod. - -(* binary product *) -Section hom_prod. -Context {C D : quiver}. -Definition prod_hom_subdef (a b : C * D) := ((a.1 ~> b.1) * (a.2 ~> b.2))%type. -HB.instance Definition _ := IsQuiver.Build (C * D)%type prod_hom_subdef. -End hom_prod. - -Section precat_prod. -Context {C D : precat}. -HB.instance Definition _ := IsPreCat.Build (C * D)%type (fun=> (idmap, idmap)) - (fun a b c (f : a ~> b) (g : b ~> c) => (f.1 \; g.1, f.2 \; g.2)). -End precat_prod. - -Section cat_prod. -Context {C D : cat}. -Local Notation type := (C * D)%type. -Lemma prod_is_cat : PreCat_IsCat type. -Proof. -split=> [[a1 a2] [b1 b2] [f1 f2]|[a1 a2] [b1 b2] [f1 f2]| - [a1 a2] [b1 b2] [c1 c2] [d1 d2] [f1 f2] [g1 g2] [h1 h2]]; congr (_, _) => //=; -by [exact: comp1o | exact: compo1 | exact: compoA]. -Qed. -HB.instance Definition _ := prod_is_cat. -End cat_prod. - -(* naturality *) -HB.mixin Record IsNatural (C D : precat) (F G : C ~>_quiver D) - (n : forall c, F c ~> G c) := { - natural : forall (a b : C) (f : a ~> b), - F <$> f \; n b = n a \; G <$> f -}. -Unset Universe Checking. -HB.structure Definition Natural (C D : precat) - (F G : C ~>_quiver D) : Set := - { n of @IsNatural C D F G n }. -Set Universe Checking. -HB.instance Definition _ (C D : precat) := - IsQuiver.Build (PreFunctor.type C D) (@Natural.type C D). -HB.instance Definition _ (C D : cat) := - IsQuiver.Build (Functor.type C D) (@Natural.type C D). -Arguments natural {C D F G} n [a b] f : rename. - -Check fun (C D : cat) (F G : C ~> D) => F ~>_(C ~>_cat D) G. - -Lemma naturalx (C : precat) (D : concrete_precat) - (F G : C ~>_quiver D) (n : F ~> G) (a b : C) (f : a ~> b) g : - (concrete <$> n b) ((concrete <$> F <$> f) g) = - (concrete <$> G <$> f) ((concrete <$> n a) g). -Proof. -have /(congr1 (fun h => (concrete <$> h) g)) := natural n f. -by rewrite !Fcomp. -Qed. -Arguments naturalx {C D F G} n [a b] f. - -Lemma naturalU (C : precat) (F G : C ~>_quiver U) (n : F ~> G) - (a b : C) (f : a ~> b) g : n b (F^$ f g) = G^$ f (n a g). -Proof. exact: (naturalx n). Qed. - -Lemma natP (C D : precat) (F G : C ~>_quiver D) (n m : F ~> G) : - Natural.sort n = Natural.sort m -> n = m. -Proof. -case: n m => [/= n nP] [/= m mP] enm. -elim: _ / enm in mP *; congr Natural.Pack. -case: nP mP => [[?]] [[?]]; congr Natural.Class. -congr IsNatural.Axioms_. -exact: Prop_irrelevance. -Qed. - -Notation "F ~~> G" := (F ~>_(homs quiver) G) - (at level 99, G at level 200, format "F ~~> G"). -Notation "F ~~> G :> C ~> D" := (F ~> G :> (C ~>_quiver D)) - (at level 99, G at level 200, C, D at level 0, - format "F ~~> G :> C ~> D"). - -Definition natural_id {C D : precat} (F : C ~>_quiver D) (a : C) := \idmap_(F a). -Definition natural_id_natural (C D : cat) (F : C ~>_quiver D) : - IsNatural C D F F (natural_id F). -Proof. by constructor=> a b f; rewrite /natural_id/= compo1 comp1o. Qed. -HB.instance Definition _ C D F := @natural_id_natural C D F. - -Check fun {C D : cat} (F : C ~>_quiver D) => natural_id F : F ~> F. - -Definition natural_comp {C D : precat} (F G H : C ~>_quiver D) - (m : F ~> G) (n : G ~> H) (a : C) := m a \; n a. -Definition natural_comp_natural (C D : cat) (F G H : C ~>_quiver D) m n : - IsNatural C D F H (@natural_comp C D F G H m n). -Proof. -constructor=> a b f; rewrite /natural_comp/=. -by rewrite compoA natural -compoA natural compoA. -Qed. -HB.instance Definition _ C D F G H m n := @natural_comp_natural C D F G H m n. - -HB.instance Definition _ {C D : cat} := - Quiver_IsPreCat.Build (PreFunctor.type C D) natural_id natural_comp. -HB.instance Definition _ {C D : cat} := - Quiver_IsPreCat.Build (Functor.type C D) natural_id natural_comp. - -Lemma prefunctor_cat {C D : cat} : PreCat_IsCat (PreFunctor.type C D). -Proof. -constructor => [F G f|F G f|F G H J f g h]. -- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. -- by apply/natP/funext => a; rewrite /= /natural_comp compo1. -- by apply/natP/funext => a; rewrite /= /natural_comp compoA. -Qed. -HB.instance Definition _ C D := @prefunctor_cat C D. - -Lemma functor_cat {C D : cat} : PreCat_IsCat (Functor.type C D). -Proof. -constructor => [F G f|F G f|F G H J f g h]. -- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. -- by apply/natP/funext => a; rewrite /= /natural_comp compo1. -- by apply/natP/funext => a; rewrite /= /natural_comp compoA. -Qed. -HB.instance Definition _ C D := @functor_cat C D. - -Section nat_map_left. -Context {C D E : precat} {F G : C ~> D}. - -Definition nat_lmap (H : D ~>_quiver E) (n : forall c, F c ~> G c) : - forall c, (H \o F)%FUN c ~> (H \o G)%FUN c := fun c => H <$> n c. - -Fail Check fun (H : D ~> E) (n : F ~~> G) => nat_lmap H n : H \o F ~~> H \o G. - -Lemma nat_lmap_is_natural (H : D ~> E) (n : F ~~> G) : - IsNatural C E (H \o F) (H \o G) (nat_lmap H n). -Proof. by constructor=> a b f; rewrite /nat_lmap/= -!Fcomp natural. Qed. -HB.instance Definition _ H n := nat_lmap_is_natural H n. - -Check fun (H : D ~> E) (n : F ~~> G) => nat_lmap H n : H \o F ~~> H \o G. - -End nat_map_left. - -Notation "F n" := (nat_lmap F n) - (at level 58, format "F n", right associativity) : cat_scope. - -Section nat_map_right. -Context {C D E : precat} {F G : C ~> D}. - -Definition nat_rmap (H : E -> C) (n : forall c, F c ~> G c) : - forall c, (F \o H)%FUN c ~> (G \o H)%FUN c := fun c => n (H c). -Lemma nat_rmap_is_natural (H : E ~> C :> quiver) (n : F ~~> G) : - IsNatural E D (F \o H)%FUN (G \o H)%FUN (nat_rmap H n). -Proof. by constructor=> a b f; rewrite /nat_lmap/= natural. Qed. -HB.instance Definition _ H n := nat_rmap_is_natural H n. - -End nat_map_right. - -Notation "F <$o> n" := (nat_rmap F n) - (at level 58, format "F <$o> n", right associativity) : cat_scope. - -Definition delta (C D : cat) : C -> (D ~> C) := cst D. -Arguments delta C D : clear implicits. - -Definition map_delta {C D : cat} (a b : C) (f : a ~> b) : - delta C D a ~> delta C D b. -Proof. -apply: (@Natural.Pack _ _ (cst D a) (cst D b) (fun x => f)). -apply: Natural.Class; apply: (IsNatural.Build _ _ _ _ _). -by move=> a' b' ?; rewrite compo1 comp1o. -Defined. - -HB.instance Definition _ {C D : cat} := - IsPreFunctor.Build C (D ~> C) (delta C D) (@map_delta C D). - -Lemma delta_functor {C D : cat} : PreFunctor_IsFunctor _ _ (delta C D). -Proof. by constructor=> [a|a b c f g]; exact/natP. Qed. -HB.instance Definition _ C D := @delta_functor C D. - -HB.mixin Record IsMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { - unit : idfun ~~> M; - join : (M \o M)%FUN ~~> M; - bind : forall (a b : C), (a ~> M b) -> (M a ~> M b); - bindE : forall a b (f : a ~> M b), bind a b f = M <$> f \; join b; - unit_join : forall a, (M <$> unit a) \; join _ = idmap; - join_unit : forall a, join _ \; (M <$> unit a) = idmap; - join_square : forall a, M <$> join a \; join _ = join _ \; join _ -}. - -#[short(type="premonad")] -HB.structure Definition PreMonad (C : precat) := - {M of @PreFunctor C C M & IsMonad C M}. -#[short(type="monad")] -HB.structure Definition Monad (C : precat) := - {M of @Functor C C M & IsMonad C M}. - -HB.factory Record IsJoinMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { - unit : idfun ~~> M; - join : (M \o M)%FUN ~~> M; - unit_join : forall a, (M <$> unit a) \; join _ = idmap; - join_unit : forall a, join _ \; (M <$> unit a) = idmap; - join_square : forall a, M <$> join a \; join _ = join _ \; join _ -}. -HB.builders Context C M of IsJoinMonad C M. - HB.instance Definition _ := IsMonad.Build C M - (fun a b f => erefl) unit_join join_unit join_square. -HB.end. - -HB.mixin Record IsCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { - counit : M ~~> idfun; - cojoin : M ~~> (M \o M)%FUN; - cobind : forall (a b : C), (M a ~> b) -> (M a ~> M b); - cobindE : forall a b (f : M a ~> b), cobind a b f = cojoin _ \; M <$> f; - unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; - join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; - cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ -}. -#[short(type="precomonad")] -HB.structure Definition PreCoMonad (C : precat) := - {M of @PreFunctor C C M & IsCoMonad C M}. -#[short(type="comonad")] -HB.structure Definition CoMonad (C : precat) := - {M of @Functor C C M & IsCoMonad C M}. - -HB.factory Record IsJoinCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { - counit : M ~~> idfun; - cojoin : M ~~> (M \o M)%FUN; - unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; - join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; - cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ -}. -HB.builders Context C M of IsJoinCoMonad C M. - HB.instance Definition _ := IsCoMonad.Build C M - (fun a b f => erefl) unit_cojoin join_counit cojoin_square. -HB.end. - -Lemma idFmap (C : cat) (a b : C) (f : a ~> b) : idfun <$> f = f. -Proof. by []. Qed. - -Lemma compFmap (C D E : cat) (F : C ~> D) (G : D ~> E) (a b : C) (f : a ~> b) : - (G \o F) <$> f = G <$> F <$> f. -Proof. by []. Qed. - -(* yoneda *) -Section hom_repr. -Context {C : cat} (F : C ~>_cat U). - -Definition homF : C -> U := fun c => hom c ~~> F. - -Section nat. -Context (x y : C) (xy : x ~> y). - -(* Goal hom x ~~> F -> hom y ~~> F *) -Context (n : hom x ~~> F). -Definition homFhom c : hom y c ~> F c := fun g => n _ (xy \; g). - -Lemma homFhom_natural_subdef : IsNatural C U (hom y) F homFhom. -Proof. -by split=> a b f /=; apply/funext => g /=; - rewrite /homFhom !Ucompx/= !naturalU/= Fcomp. -Qed. -HB.instance Definition _ := homFhom_natural_subdef. -End nat. -Arguments homFhom / : clear implicits. - -HB.about IsPreFunctor.Build. -Check homFhom : forall x y : C, (x ~> y) -> (homF x -> homF y). -HB.instance Definition _ := IsPreFunctor.Build _ _ homF homFhom. -Lemma homF_functor_subproof : PreFunctor_IsFunctor _ _ homF. -Proof. -split=> [a|a b c f g]. - apply/funext => -[/= f natf]. - apply: natP => //=; apply: funext => b; apply: funext => g/=. - by rewrite comp1o. -apply/funext => -[/= h natf]. -apply: natP => //=; apply: funext => d; apply: funext => k/=. -by rewrite compoA. -Qed. -HB.instance Definition _ := homF_functor_subproof. - -Section pointed. -Context (c : C). -Definition hom_repr : homF c ~> F c := fun f => f _ idmap. -Arguments hom_repr /. - -Definition repr_hom (fc : F c) a : hom c a ~> F a := - fun f => F^$ f fc. -Arguments repr_hom / : clear implicits. -Lemma repr_hom_subdef (fc : F c) : IsNatural _ _ _ _ (repr_hom fc). -Proof. by split=> a b f /=; apply/funext=> x; rewrite !Ucompx/= Fcomp. Qed. -HB.instance Definition _ {fc : F c} := repr_hom_subdef fc. - -Definition repr_hom_nat : F c ~> homF c := repr_hom. - -Lemma hom_reprK : cancel hom_repr repr_hom_nat. -Proof. -move=> f; apply/natP; apply/funext => a; apply/funext => g /=. -by rewrite -naturalU/=; congr (f _ _); apply: comp1o. -Qed. -Lemma repr_homK : cancel (repr_hom : F c ~> homF c) hom_repr. -Proof. by move=> fc; rewrite /= F1. Qed. -End pointed. -Arguments hom_repr /. -Arguments repr_hom /. - -Lemma hom_repr_natural_subproof : IsNatural _ _ _ _ hom_repr. -Proof. -split=> a b f /=; apply/funext => n /=; rewrite !Ucompx/= compo1/=. -by rewrite -naturalU/=; congr (n _ _); apply/esym/comp1o. -Qed. -HB.instance Definition _ := hom_repr_natural_subproof. - -(* show this from the previous proof *) -Lemma hom_natural_repr_subproof : IsNatural _ _ _ _ repr_hom_nat. -Proof. -split=> a b f /=; apply: funext => fa /=; rewrite !Ucompx/=. -apply: natP; apply: funext => c /=; apply: funext => d /=. -by rewrite Fcomp Ucompx/=. -Qed. -HB.instance Definition _ := hom_natural_repr_subproof. - -Definition hom_repr_nat : homF ~~> F := hom_repr. -Definition repr_hom_nat_nat : F ~~> homF := repr_hom_nat. - -End hom_repr. - -(* comma categories *) -Module comma. -Section homcomma. -Context {C D E : precat} (F : C ~> E) (G : D ~> E). - -Definition type := { x : C * D & F x.1 ~> G x.2 }. -Definition hom_subdef (a b : type) := { - f : tag a ~> tag b & F <$> f.1 \; tagged b = tagged a \; G <$> f.2 - }. -HB.instance Definition _ := IsQuiver.Build type hom_subdef. -End homcomma. -Arguments hom_subdef /. -Section comma. -Context {C D E : cat} (F : C ~> E) (G : D ~> E). -Notation type := (type F G). - -Program Definition idmap_subdef (a : type) : a ~> a := @Tagged _ idmap _ _. -Next Obligation. by rewrite !F1 comp1o compo1. Qed. -Program Definition comp_subdef (a b c : type) - (f : a ~> b) (g : b ~> c) : a ~> c := - @Tagged _ (tag f \; tag g) _ _. -Next Obligation. by rewrite !Fcomp -compoA (tagged g) compoA (tagged f) compoA. Qed. -HB.instance Definition _ := IsPreCat.Build type idmap_subdef comp_subdef. -Arguments idmap_subdef /. -Arguments comp_subdef /. - -Lemma comma_homeqP (a b : type) (f g : a ~> b) : projT1 f = projT1 g -> f = g. -Proof. -case: f g => [f fP] [g +]/= eqfg; case: _ / eqfg => gP. -by congr existT; apply: Prop_irrelevance. -Qed. - -Lemma comma_is_cat : PreCat_IsCat type. -Proof. -by split=> [[a fa] [b fb] [*]|[a fa] [b fb] [*]|*]; - apply/comma_homeqP; rewrite /= ?(comp1o, compo1, compoA). -Qed. -HB.instance Definition _ := comma_is_cat. -End comma. -End comma. -Notation "F `/` G" := (@comma.type _ _ _ F G) - (at level 40, G at level 40, format "F `/` G") : cat_scope. -Notation "a /` G" := (cst unit a `/` G) - (at level 40, G at level 40, format "a /` G") : cat_scope. -Notation "F `/ b" := (F `/` cst unit b) - (at level 40, b at level 40, format "F `/ b") : cat_scope. -Notation "a / b" := (cst unit a `/ b) : cat_scope. - -Definition obj (C : U) : U := C. -HB.mixin Record IsInitial {C : quiver} (i : obj C) := { - to : forall c, i ~> c; - to_unique : forall c (f : i ~> c), f = to c -}. -#[short(type="initial")] -HB.structure Definition Initial {C : quiver} := {i of IsInitial C i}. - -HB.mixin Record IsTerminal {C : quiver} (t : obj C) := { - from : forall c, c ~> t; - from_unique : forall c (f : c ~> t), f = from c -}. -#[short(type="terminal")] -HB.structure Definition Terminal {C : quiver} := {t of IsTerminal C t}. -#[short(type="universal")] -HB.structure Definition Universal {C : quiver} := - {u of Initial C u & Terminal C u}. - -(* Definition hom' {C : precat} (a b : C) := a ~> b. *) -(* (* Bug *) *) -(* Identity Coercion hom'_hom : hom' >-> hom. *) - -(* HB.mixin Record IsMono {C : precat} (b c : C) (f : hom b c) := { *) -(* monoP : forall (a : C) (g1 g2 : a ~> b), g1 \; f = g2 \; f -> g1 = g2 *) -(* }. *) -(* #[short(type="mono")] *) -(* HB.structure Definition Mono {C : precat} (a b : C) := {m of IsMono C a b m}. *) -(* Notation "a >~> b" := (mono a b) *) -(* (at level 99, b at level 200, format "a >~> b") : cat_scope. *) -(* Notation "C >~>_ T D" := (@mono T C D) *) -(* (at level 99, T at level 0, only parsing) : cat_scope. *) - -(* HB.mixin Record IsEpi {C : precat} (a b : C) (f : hom a b) := { *) -(* epiP : forall (c : C) (g1 g2 : b ~> c), g1 \o f = g2 \o f -> g1 = g2 *) -(* }. *) -(* #[short(type="epi")] *) -(* HB.structure Definition Epi {C : precat} (a b : C) := {e of IsEpi C a b e}. *) -(* Notation "a ~>> b" := (epi a b) *) -(* (at level 99, b at level 200, format "a ~>> b") : cat_scope. *) -(* Notation "C ~>>_ T D" := (@epi T C D) *) -(* (at level 99, T at level 0, only parsing) : cat_scope. *) - -(* #[short(type="iso")] *) -(* HB.structure Definition Iso {C : precat} (a b : C) := *) -(* {i of @Mono C a b i & @Epi C a b i}. *) -(* Notation "a <~> b" := (epi a b) *) -(* (at level 99, b at level 200, format "a <~> b") : cat_scope. *) -(* Notation "C <~>_ T D" := (@epi T C D) *) -(* (at level 99, T at level 0, only parsing) : cat_scope. *) - -HB.mixin Record IsRightAdjoint (D C : precat) (R : D -> C) - of @PreFunctor D C R := { - L_ : C ~> D; - phi : forall c d, (L_ c ~> d) -> (c ~> R d); - psy : forall c d, (c ~> R d) -> (L_ c ~> d); - phi_psy c d : (phi c d \o psy c d)%FUN = @id (c ~> R d); - psy_phi c d : (psy c d \o phi c d)%FUN = @id (L_ c ~> d) -}. -#[short(type="right_adjoint")] -HB.structure Definition RightAdjoint (D C : precat) := - { R of @Functor D C R & IsRightAdjoint D C R }. -Arguments L_ {_ _}. -Arguments phi {D C s} {c d}. -Arguments psy {D C s} {c d}. - - -HB.mixin Record PreCat_IsMonoidal C of PreCat C := { - onec : C; - (* prod1 : @hom precat (C * C)%type C ; *) - prod : (C * C)%type ~>_precat C; -}. -#[short(type="premonoidal")] -#[verbose] -HB.structure Definition PreMonoidal := { C of PreCat C & PreCat_IsMonoidal C }. -Notation premonoidal := premonoidal. -Arguments prod {C} : rename. -Notation "a * b" := (prod (a, b)) : cat_scope. -Reserved Notation "f <*> g" (at level 40, g at level 40, format "f <*> g"). -Notation "f <*> g" := (prod^$ (f, g)) (only printing) : cat_scope. -Notation "f <*> g" := (prod^$ ((f, g) : (_, _) ~> (_, _))) - (only parsing) : cat_scope. -Notation "1" := onec : cat_scope. - -Definition hom_cast {C : quiver} {a a' : C} (eqa : a = a') {b b' : C} (eqb : b = b') : - (a ~> b) -> (a' ~> b'). -Proof. now elim: _ / eqa; elim: _ / eqb. Defined. - -HB.mixin Record PreFunctor_IsMonoidal (C D : premonoidal) F of - @PreFunctor C D F := { - fun_one : F 1 = 1; - fun_prod : forall (x y : C), F (x * y) = F x * F y; -}. -#[short(type="monoidal_prefunctor")] -HB.structure Definition MonoidalPreFunctor C D := - { F of @PreFunctor_IsMonoidal C D F }. -Arguments fun_prod {C D F x y} : rename. -(* Arguments fun_prodF {C D F x x'} f {y y'} g : rename. *) -Unset Universe Checking. -HB.instance Definition _ := IsQuiver.Build premonoidal MonoidalPreFunctor.type. -Set Universe Checking. - -HB.instance Definition _ (C : quiver) := - IsPreFunctor.Build (C * C)%type C fst - (fun (a b : C * C) (f : a ~> b) => f.1). -HB.instance Definition _ (C : quiver) := - IsPreFunctor.Build (C * C)%type C snd - (fun (a b : C * C) (f : a ~> b) => f.2). - -Definition prod3l {C : premonoidal} (x : C * C * C) : C := - (x.1.1 * x.1.2) * x.2. -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build _ C prod3l - (fun a b (f : a ~> b) => (f.1.1 <*> f.1.2) <*> f.2). - -Definition prod3r {C : premonoidal} (x : C * C * C) : C := - x.1.1 * (x.1.2 * x.2). -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build _ C prod3r - (fun a b (f : a ~> b) => f.1.1 <*> (f.1.2 <*> f.2)). - -Definition prod1r {C : premonoidal} (x : C) : C := 1 * x. -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build C C prod1r - (fun (a b : C) (f : a ~> b) => \idmap_1 <*> f). - -Definition prod1l {C : premonoidal} (x : C) : C := x * 1. -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build C C prod1l - (fun (a b : C) (f : a ~> b) => f <*> \idmap_1). - -HB.mixin Record PreMonoidal_IsMonoidal C of PreMonoidal C := { - prodA : prod3l ~~> prod3r; - prod1c : prod1r ~~> idfun; - prodc1 : prod1l ~~> idfun; - prodc1c : forall (x y : C), - prodA (x, 1, y) \; \idmap_x <*> prod1c y = prodc1 x <*> \idmap_y; - prodA4 : forall (w x y z : C), - prodA (w * x, y, z) \; prodA (w, x, y * z) = - prodA (w, x, y) <*> \idmap_z \; prodA (w, x * y, z) \; \idmap_w <*> prodA (x, y, z); -}. - -Unset Universe Checking. -#[short(type="monoidal")] -#[verbose] -HB.structure Definition Monoidal : Set := - { C of PreMonoidal_IsMonoidal C & PreMonoidal C }. -Set Universe Checking. - -(******************************************************************) - - -Record cospan (Q : quiver) (A B : Q) := Cospan { - top : Q; - left2top : A ~> top; - right2top : B ~> top -}. - -Section cospans. -Variables (Q : precat) (A B : Q). -Record cospan_map (c c' : cospan A B) := CospanMap { - top_map : top c ~> top c'; - left2top_map : left2top c \; top_map = left2top c'; - right2top_map : right2top c \; top_map = right2top c'; -}. -HB.instance Definition _ := IsQuiver.Build (cospan A B) cospan_map. - -Lemma cospan_mapP (c c' : cospan A B) (f g : c ~> c') : - top_map f = top_map g <-> f = g. -Admitted. -End cospans. - -Section cospans_in_cat. -Variables (Q : cat) (A B : Q). -Definition cospan_idmap (c : cospan A B) := - @CospanMap Q A B c c idmap (compo1 _) (compo1 _). -Program Definition cospan_comp (c1 c2 c3 : cospan A B) - (f12 : c1 ~> c2) (f23 : c2 ~> c3) := - @CospanMap Q A B c1 c3 (top_map f12 \; top_map f23) _ _. -Next Obligation. by rewrite compoA !left2top_map. Qed. -Next Obligation. by rewrite compoA !right2top_map. Qed. -HB.instance Definition _ := IsPreCat.Build (cospan A B) cospan_idmap cospan_comp. - -Lemma cospan_are_cats : PreCat_IsCat (cospan A B). -Proof. -constructor=> [a b f|a b f|a b c d f g h]. -- by apply/cospan_mapP => /=; rewrite comp1o. -- by apply/cospan_mapP => /=; rewrite compo1. -- by apply/cospan_mapP => /=; rewrite compoA. -Qed. -HB.instance Definition _ := cospan_are_cats. -End cospans_in_cat. - -Section spans_and_co. -Variables (Q : quiver) (A B : Q). -Definition span := @cospan Q^op A B. -Definition bot (s : span) : Q := top s. -Definition bot2left (s : span) : bot s ~>_Q A := left2top s. -Definition bot2right (s : span) : bot s ~>_Q B := right2top s. -Definition Span (C : Q) (f : C ~> A) (g : C ~> B) : span := - @Cospan Q^op A B C f g. -End spans_and_co. - -HB.instance Definition _ (Q : precat) (A B : Q) := - Quiver.copy (span A B) (@cospan Q^op A B)^op. -HB.instance Definition _ (Q : cat) (A B : Q) := - Cat.copy (span A B) (@cospan Q^op A B)^op. - -Section bot_map. -Variables (C : cat) (A B : C) (s s' : span A B) (f : s ~> s'). -Definition bot_map : bot s ~> bot s' := top_map f. -Lemma bot2left_map : bot_map \; bot2left s' = bot2left s. -Proof. exact: left2top_map f. Qed. -Lemma bot2right_map : bot_map \; bot2right s' = bot2right s. -Proof. exact: right2top_map f. Qed. -End bot_map. - -HB.mixin Record isPrePullback (Q : precat) (A B : Q) - (c : cospan A B) (s : span A B) := { - is_square : bot2left s \; left2top c = bot2right s \; right2top c; -}. -#[short(type=prepullback)] -HB.structure Definition PrePullback Q A B (c : cospan A B) := - {s of isPrePullback Q A B c s}. -Arguments prepullback {Q A B} c. - -Section prepullback. -Variables (Q : precat) (A B : Q) (c : cospan A B). -HB.instance Definition _ := - IsQuiver.Build (prepullback c) - (fun a b => (a : span A B) ~>_(span A B) (b : span A B)). -Lemma eq_prepullbackP (p q : prepullback c) : - p = q :> span _ _ <-> p = q. -Admitted. -End prepullback. -Section prepullback. -Variables (Q : cat) (A B : Q) (csp : cospan A B). -(* TODO: why can't we do that? *) -(* HB.instance Definition _ := Cat.on (prepullback csp). *) -HB.instance Definition _ := - Quiver_IsPreCat.Build (prepullback csp) - (fun a => \idmap_(a : span A B)) - (* TODO: study how to make this coercion trigger - even when the target is not reduced to span *) - (fun a b c f g => f \; g). -Lemma prepullback_is_cat : PreCat_IsCat (prepullback csp). -Proof. (* should be copied from the cat on span *) -constructor=> [a b f|a b f|a b c d f g h]; - [exact: comp1o|exact: compo1|exact: compoA]. -Qed. -End prepullback. - -HB.tag Definition pb_terminal (Q : precat) - (A B : Q) (c : cospan A B) (s : prepullback c) : - obj (prepullback c) := s. - -#[wrapper] -HB.mixin Record prepullback_isTerminal (Q : precat) - (A B : Q) (c : cospan A B) - (s : span A B) of isPrePullback Q A B c s := { - prepullback_terminal : - IsTerminal (prepullback c) (pb_terminal s) -}. -#[short(type="pullback"), verbose] -HB.structure Definition Pullback (Q : precat) - (A B : Q) (c : cospan A B) := - {s of isPrePullback Q A B c s - & IsTerminal (prepullback c) (pb_terminal s) }. - -Notation pbsquare u v f g := - (Pullback _ (Cospan f g) (Span u v)). - -Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). - -(********************************************************************) -(********************************************************************) - -(*** CATEGORIES WITH PULLBACKS *) - -(* category with all prepullbacks *) -(* Ideally span is in fact expanded and the final mixin has -a pb : forall A B, cospan A B -> C -but it is not clear how to do that yet -*) -HB.mixin Record HasPBop C of Cat C := { - pb : forall (A B: C), cospan A B -> span A B - }. -#[short(type="pbop")] -HB.structure Definition PBop := - {C of HasPBop C & PreCat C }. - -(* category with all pullbacks *) -(* Wrong: we don't wrap classes, only mixins *) -#[wrapper] -HB.mixin Record HasPreBCat C of PBop C : Type := { - is_pb : forall (a b : C) (c : cospan a b), isPrePullback C a b c (@pb C a b c) - }. -#[short(type="pbcat")] -HB.structure Definition PreBCat := - {C of HasPreBCat C}. - -#[wrapper] -HB.mixin Record HasPBCat C of PBop C & HasPreBCat C : Type := { - is_pb : forall (a b : C) (c : cospan a b), - prepullback_isTerminal C a b c (@pb C a b c) - }. -#[short(type="pbcat")] -HB.structure Definition PBCat := - {C of HasPBCat C}. +Notation "'sigma' x .. y , p" := + (sigT (fun x => .. (sigT (fun y => p)) ..)) + (at level 200, x binder, right associativity, + format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") + : type_scope. (********************************************************************) -(*** INTERNAL CATEGORIES *) +(*** INTERNAL CATEGORIES assuming products *) (* based on the NLab definition at https://ncatlab.org/nlab/show/internal+category *) @@ -2020,721 +991,22 @@ Obligation 1. refine (@existT (D1hom h0 k0) _ hh0 (@existT (D1hom h1 k1) _ hh1 k)). Defined. -(********************************************************************) -(********************************************************************) - - -Section th_of_pb. -Variables (Q : cat) (A B C D E F : Q). -Variables (f : A ~> D) (g : B ~> D) (h : C ~> A). -Variables (u : E ~> A) (v : E ~> B) (w : F ~> C) (z : F ~> E). -Variable (uvfg : pbsquare u v f g). - -Set Printing Width 50. -Theorem pbsquarec_compP : - pbsquare w z h u <=> pbsquare w (z \; v) (h \; f) g. -Proof. -split=> [] sq. - - have @sq_ispb : pullback (Cospan h u) := HB.pack (Span w z) sq. - have @uvfg_ispb : pullback (Cospan f g) := HB.pack (Span u v) uvfg. - have /=E2 := @is_square _ _ _ _ sq_ispb. - have /=E1 := @is_square _ _ _ _ uvfg_ispb. - - have p1 : @isPrePullback Q C B (Cospan (h \; f) g) (Span w (z \; v)). - by constructor; rewrite /= compoA E2 -compoA E1 compoA. - pose big_black_square : prepullback (Cospan (h \; f) g) := - HB.pack (Span w (z \; v)) p1. - - have @from : forall - (big_red_square : prepullback {| top := D; left2top := h \; f; right2top := g |}), - big_red_square ~> pb_terminal big_black_square. - - move=> big_red_square; unfold pb_terminal. - - have /= := @is_square _ _ _ _ big_red_square. - - pose F' := bot big_red_square. - set w' : F' ~> C := bot2left big_red_square. - set z' : F' ~> B := bot2right big_red_square. - move=> E3. - - have xxx : isPrePullback Q A B (Cospan f g) (Span (w' \; h) z'). - by constructor=> /=; rewrite -compoA E3. - pose red_black_square : prepullback (Cospan f g) := - HB.pack (Span (w' \; h) z') xxx. - have := @from_unique _ (pb_terminal uvfg_ispb) red_black_square. - set blue := @from _ (pb_terminal uvfg_ispb) red_black_square. - move=> blue_unique. - - have p3 : @isPrePullback Q C E (Cospan h u) (Span w' (bot_map blue)). - by constructor; rewrite /= (bot2left_map blue). (* buggy unifier without blue *) - pose blue_red_black_square : prepullback (Cospan h u) := - HB.pack (Span w' (bot_map blue)) p3. - - pose red := @from _ (pb_terminal sq_ispb) blue_red_black_square. - - admit. - - - - have p2 : prepullback_isTerminal.axioms_ Q C B (Cospan (h \; f) g) (Span w (z \; v)) p1. - constructor. econstructor=> /=. - admit. - - by HB.from p1 p2. - -Admitted. - -End th_of_pb. - - -Module test. - -Section test. -Variables (Q : precat) (A B : Q) (c : cospan A B). -Variable (p : pullback c). -Check pb_terminal p : terminal _. - -End test. -End test. - - - -(************************************************************************) - -(**** INTERNAL CATEGORIES - NEW DEFINITION *) - -(* Defining internal hom objects. - C0 and C1 are objects of C. - C0 is the object of objects, - C1 is the object of morphims (and the subject). - this will allow to define a generic _ *_C0 _ notation - by recognizing the structure of hom objects on the LHS and RHS - Basically, w.r.t. double categories, C1 represents 'horizontal' - 1-morpshisms and the D1 category, whereas C0 represents the objects - of the base D0 category. *) -HB.mixin Record isInternalHom {C: quiver} (C0 : C) (C1 : obj C) := { - src : C1 ~> C0; tgt : C1 ~> C0 -}. -#[short(type="iHom")] -HB.structure Definition InternalHom {C: quiver} (C0 : C) := - { C1 of isInternalHom C C0 C1 }. - -Notation "X ':>' C" := (X : obj C) (at level 60, C at next level). - -(* HB.instance Definition _ (T : quiver) := Quiver.on (obj T). *) -(* HB.instance Definition _ (T : precat) := PreCat.on (obj T). *) -(* HB.instance Definition _ (T : cat) := Cat.on (obj T). *) -(* HB.instance Definition _ (T : pbcat) := PBCat.on (obj T). *) - -(* constructs the pullback from the cospan given by target and source. - Type-level construction: X and Y are two instances of the morphism - object, specified by (iHom C0), and are objects of (obj C). Here - 'iprod' is just an object of (obj C). The cospan is given by the - target of X and the source of Y. The pullback provides a commuting - square on the cospan, which basically ensures that the morphisms in - X and Y can be composed. *) -Definition iprod_pb {C: pbcat} {C0 : C} (X Y : iHom C0) : - span (X :> C) (Y :> C) := - pb _ _ (Cospan (tgt : (X :> C) ~> C0) (src : (Y :> C) ~> C0)). - -Definition iprod {C: pbcat} {C0 : obj C} (X Y : iHom C0) : obj C := - bot (@iprod_pb C C0 X Y). -Notation "X *_ C0 Y" := (@iprod _ C0 (X : iHom C0) (Y : iHom C0)) - (at level 99, C0 at level 0, only parsing) : cat_scope. -Notation "X *_ C0 Y" := (@iprod _ C0 X Y) - (at level 99, C0 at level 0) : cat_scope. - -(* -(1) Defines pullback square (iprod_pb) - - X --- tgt -----> C0 - ^ ^ - | | - bot2left src - | | - X*Y - bot2right -> Y - - -(2) Defines source and target of the product (iprod_iHom) - - X --- src -----> C0 - ^ ^ - | | - iprodl tgt - | | - X*Y -- iprodr ---> Y -*) - -(* left and right projection morphisms of the product *) -Definition iprodl {C: pbcat} {C0 : C} (X Y : iHom C0) : - X *_C0 Y ~> (X :> C) := bot2left (iprod_pb X Y). -Definition iprodr {C: pbcat} {C0 : C} (X Y : iHom C0) : - X *_C0 Y ~> (Y :> C) := bot2right (iprod_pb X Y). - -(* Given (iHom C0) instances X and Y, we want to say that (X *_C0 Y) -is also an instance of (iHom C0). X and Y represent composable -morphisms, as by pullback properties, the diagram (1) commutes. -source and target are obtained by composing with product projections -(2) *) -Definition iprod_iHom {C: pbcat} {C0: C} (X Y: @iHom C C0) : - @isInternalHom C C0 (X *_C0 Y) := - @isInternalHom.Build C C0 (X *_C0 Y) - ((iprodl X Y) \; src) - ((iprodr X Y) \; tgt). - -HB.instance Definition iprod_iHom' {C: pbcat} {C0: C} (X Y: @iHom C C0) : - @isInternalHom C C0 (X *_C0 Y) := iprod_iHom X Y. - -(* the product as (iHom C0) object *) -Definition pbC0 (C : pbcat) (C0 : C) (X Y : iHom C0) : iHom C0 := - (X *_C0 Y) : iHom C0. - -(* we also define the trivial internal hom type *) -HB.instance Definition trivial_iHom {C: pbcat} {C0: C} := - isInternalHom.Build C C0 C0 idmap idmap. - - -(* we need internal hom morphisms: -the ones that preserve sources and targets. -basically, we recast morphisms in (obj C) into some in (@iHom C C0), -i.e. into morphism between copies of C1 *) -HB.mixin Record IsInternalHomHom {C: pbcat} (C0 : C) - (C1 C1' : @iHom C C0) (f : (C1 :> C) ~> (C1' :> C)) := { - hom_src : f \; src = src; - hom_tgt : f \; tgt = tgt; -}. -#[short(type="iHomHom")] -HB.structure Definition InternalHomHom {C: pbcat} - (C0 : C) (C1 C1' : @iHom C C0) := - { f of @IsInternalHomHom C C0 C1 C1' f }. - -(* internal homs form a category, - the morphisms are the one that preserve source and target *) -HB.instance Definition iHom_quiver {C: pbcat} (C0 : C) : - IsQuiver (@iHom C C0) := - IsQuiver.Build (@iHom C C0) (@iHomHom C C0). -Print iHom_quiver. - -Program Definition pre_iHom_id {C: pbcat} (C0 : C) (C1 : @iHom C C0) : - @IsInternalHomHom C C0 C1 C1 idmap := - @IsInternalHomHom.Build C C0 C1 C1 idmap _ _. -Obligation 1. -setoid_rewrite comp1o; reflexivity. -Defined. -Obligation 2. -setoid_rewrite comp1o; reflexivity. -Defined. - -Program Definition iHom_id {C: pbcat} (C0 : C) (C1 : @iHom C C0) : - C1 ~>_(@iHom C C0) C1 := - @InternalHomHom.Pack C C0 C1 C1 idmap _. -(* -The term "pre_iHom_id C1" has type "IsInternalHomHom.phant_axioms idmap" -while it is expected to have type "InternalHomHom.axioms_ ?sort". -*) -Obligation 1. -econstructor. -eapply (@pre_iHom_id C C0 C1). -Defined. - -Program Definition pre_iHom_comp {C: pbcat} (C0 : C) (C1 C2 C3: @iHom C C0) - (f: C1 ~>_(@iHom C C0) C2) (g: C2 ~>_(@iHom C C0) C3) : - @IsInternalHomHom C C0 C1 C3 (f \; g) := - @IsInternalHomHom.Build C C0 C1 C3 (f \; g) _ _. -Obligation 1. -setoid_rewrite <- compoA. -repeat (setoid_rewrite hom_src); auto. -Defined. -Obligation 2. -setoid_rewrite <- compoA. -repeat (setoid_rewrite hom_tgt); auto. -Defined. - -Program Definition iHom_comp {C: pbcat} (C0 : C) (C1 C2 C3: @iHom C C0) - (f: C1 ~>_(@iHom C C0) C2) (g: C2 ~>_(@iHom C C0) C3) : - C1 ~>_(@iHom C C0) C3 := - @InternalHomHom.Pack C C0 C1 C3 (f \; g) _. -Obligation 1. -econstructor. -eapply (@pre_iHom_comp C C0 C1 C2 C3 f g). -Defined. - -Program Definition iHom_precat {C: pbcat} (C0 : C) : - Quiver_IsPreCat (@iHom C C0) := - Quiver_IsPreCat.Build (@iHom C C0) _ _. -Obligation 1. -eapply (@iHom_id C C0 a). -Defined. -Obligation 2. -eapply (@iHom_comp C C0 a b c0 X X0). -Defined. - -HB.instance Definition iHom_precat' {C: pbcat} (C0 : C) := iHom_precat C0. - -Lemma iHom_LeftUnit_lemma (C : pbcat) (C0 : C) - (a b : iHom C0) (f : a ~> b) : idmap \; f = f. -unfold idmap; simpl. -unfold iHom_precat_obligation_1. -unfold comp; simpl. -unfold iHom_precat_obligation_2. -unfold iHom_comp. -remember f as f1. -remember a as a1. -remember b as b1. -destruct f as [ff class]. -destruct a as [Ca class_a]. -destruct b as [Cb class_b]. -destruct class_a as [IMa]. -destruct class_b as [IMb]. -destruct class as [IM]. -destruct IMa. -destruct IMb. -destruct IM. -unfold obj in *. -simpl in *; simpl. - -eassert ( forall x, exists y, - {| - InternalHomHom.sort := idmap \; f1; - InternalHomHom.class := x - |} = - {| - InternalHomHom.sort := f1; - InternalHomHom.class := y - |} ) as A2. -{ rewrite Heqf1; simpl. - rewrite comp1o. - intros. - destruct x as [X]. - econstructor. - destruct X. - reflexivity. -}. - -setoid_rewrite Heqf1 at 3. -specialize (A2 (iHom_comp_obligation_1 (iHom_id a1) f1)). -destruct A2. -rewrite H. - -inversion Heqf1; subst. -simpl. -destruct x as [IM]. -destruct IM. - -assert (hom_src0 = hom_src1) as D1. -{ eapply Prop_irrelevance. } - -assert (hom_tgt0 = hom_tgt1) as D2. -{ eapply Prop_irrelevance. } - -rewrite D1. -rewrite D2. -reflexivity. -Qed. - -Lemma iHom_RightUnit_lemma (C : pbcat) (C0 : C) - (a b : iHom C0) (f : a ~> b) : f \; idmap = f. -unfold idmap; simpl. -unfold iHom_precat_obligation_1. -unfold comp; simpl. -unfold iHom_precat_obligation_2. -unfold iHom_comp. -remember f as f1. -remember a as a1. -remember b as b1. -destruct f as [ff class]. -destruct a as [Ca class_a]. -destruct b as [Cb class_b]. -destruct class_a as [IMa]. -destruct class_b as [IMb]. -destruct class as [IM]. -destruct IMa. -destruct IMb. -destruct IM. -unfold obj in *. -simpl in *; simpl. - -eassert ( forall x, exists y, - {| - InternalHomHom.sort := f1 \; idmap; - InternalHomHom.class := x - |} = - {| - InternalHomHom.sort := f1; - InternalHomHom.class := y - |} ) as A2. -{ rewrite Heqf1; simpl. - rewrite compo1. - intros. - destruct x as [X]. - econstructor. - destruct X. - reflexivity. -}. - -setoid_rewrite Heqf1 at 3. -specialize (A2 (iHom_comp_obligation_1 f1 (iHom_id b1))). -destruct A2. -rewrite H. - -inversion Heqf1; subst. -simpl. -destruct x as [IM]. -destruct IM. - -assert (hom_src0 = hom_src1) as D1. -{ eapply Prop_irrelevance. } - -assert (hom_tgt0 = hom_tgt1) as D2. -{ eapply Prop_irrelevance. } - -rewrite D1. -rewrite D2. -reflexivity. -Qed. - -Lemma iHom_Assoc_lemma {C : pbcat} (C0 : C) - (a b c d : iHom C0) (f : a ~> b) (g : b ~> c) (h : c ~> d) : - f \; g \; h = (f \; g) \; h. - unfold comp; simpl. - unfold iHom_precat_obligation_2; simpl. - unfold iHom_comp; simpl. - remember a as a1. - remember b as b1. - remember c as c1. - remember d as d1. - remember f as f1. - remember g as g1. - remember h as h1. - destruct a as [C_a class_a]. - destruct b as [C_b class_b]. - destruct c as [C_c class_c]. - destruct d as [C_d class_d]. - destruct f as [M_f class_f]. - destruct g as [M_g class_g]. - destruct h as [M_h class_h]. - destruct class_a as [IM_a]. - destruct class_b as [IM_b]. - destruct class_c as [IM_c]. - destruct class_d as [IM_d]. - destruct IM_a. - destruct IM_b. - destruct IM_c. - destruct IM_d. - destruct class_f as [IM_f]. - destruct class_g as [IM_g]. - destruct class_h as [IM_h]. - destruct IM_f. - destruct IM_g. - destruct IM_h. - unfold obj in *; simpl in *; simpl. - - eassert ( forall x y, - {| - InternalHomHom.sort := f1 \; g1 \; h1; - InternalHomHom.class := x - |} = - {| - InternalHomHom.sort := (f1 \; g1) \; h1; - InternalHomHom.class := y - |} ) as A2. - { rewrite Heqf1; simpl. - rewrite compoA. - intros. - destruct x as [X]. - destruct y as [Y]. - destruct X. - destruct Y. - - assert (hom_src3 = hom_src4) as D1. - { eapply Prop_irrelevance. } - - assert (hom_tgt3 = hom_tgt4) as D2. - { eapply Prop_irrelevance. } - - rewrite D1. - rewrite D2. - reflexivity. - }. - - setoid_rewrite A2. - reflexivity. -Qed. - -Program Definition iHom_cat {C: pbcat} (C0 : C) : - PreCat_IsCat (@iHom C C0) := - PreCat_IsCat.Build (@iHom C C0) _ _ _. -Obligation 1. -eapply iHom_LeftUnit_lemma; eauto. -Qed. -Obligation 2. -eapply iHom_RightUnit_lemma; eauto. -Qed. -Obligation 3. -eapply iHom_Assoc_lemma; eauto. -Qed. - - -(* PROBLEM: this morphism cannot exist, as the target of the product - isn't generally the same as the target of the first projection. - Similarly, the source of the product can be different from the - source of the sencond projection. *) -(* -Definition iprodlC0 {C: pbcat} {C0 : C} (X Y : iHom C0) : - pbC0 X Y ~>_(iHom C0) X. - assert (@src C C0 (pbC0 X Y) = (iprodl X Y) \; @src C C0 X) as A1. - { auto. } - assert (@tgt C C0 (pbC0 X Y) = (iprodr X Y) \; @tgt C C0 Y) as A2. - { auto. } -Admitted. -Definition iprodrC0 {C: pbcat} {C0 : C} (X Y : iHom C0) : - pbC0 X Y ~>_(iHom C0) Y. -Admitted. -*) - -(* Now we define an internal quiver as an object C0, - which has a C1 : iHom C0 attached to it *) -HB.mixin Record IsPreInternalQuiver (C : quiver) (C0 : obj C) := - { C1 : obj C }. -HB.structure Definition PreInternalQuiver C := - { C0 of @IsPreInternalQuiver C C0 }. - -Arguments C1 {C s}. - -#[wrapper] HB.mixin Record IsInternalQuiver (C : quiver) (C0 : obj C) of - @PreInternalQuiver C C0 := { - priv: @InternalHom C C0 (@C1 _ C0) - }. -#[short(type="iquiver")] -HB.structure Definition InternalQuiver (C : quiver) := - { C0 of IsInternalQuiver C C0 }. - -Coercion iquiver_quiver (C : quiver) (C0 : iquiver C) : C := C0 :> C. -Coercion iquiver_precat (C : precat) (C0 : iquiver C) : C := C0 :> C. -Coercion iquiver_cat (C : cat) (C0 : iquiver C) : C := C0 :> C. - -Lemma ihom_morph (C : pbcat) (C0 : C) (a b: iHom C0) (f: a ~>_(iHom C0) b) : - (a :> C) ~>_C (b :> C). - simpl. - destruct a. - destruct b. - destruct f. - simpl in *. - exact sort1. -Defined. - -(* nested product *) -Program Definition iprodIAsc {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : - ((C1 *_C0 C2 : iHom C0) *_C0 C3) ~>_(iHom C0) - (C1 *_C0 (C2 *_C0 C3 : iHom C0) : iHom C0). - (* := ... *) - (* OK define it with the universal arrow of the pullback *) -Admitted. - -Program Definition iprodCAsc {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : - (((C1 *_C0 C2 : iHom C0) *_C0 C3) :> C) ~>_C - ((C1 *_C0 (C2 *_C0 C3 : iHom C0) : iHom C0) :> C). -eapply ihom_morph. -eapply iprodIAsc; eauto. -Defined. - -Lemma pbsquare_universal {C: cat} (A B T P0 P1 : C) - (t: A ~> T) (s: B ~> T) (p1: P0 ~> A) (p2: P0 ~> B) - (f: P1 ~> A) (g: P1 ~> B) : - pbsquare p1 p2 t s -> - f \; t = g \; s -> - sigma m: P1 ~> P0, f = m \; p1 /\ g = m \; p2. - intros sq E. - destruct sq as [IM1 IM2]. - - remember (Span p1 p2) as Spn0. - remember (@Cospan C A B T t s) as Csp. - remember (@Cospan C^op A B P1 f g) as Spn1. - - unfold Span in HeqSpn0. - - destruct IM1 as [IM3]. - destruct IM2 as [IM4]. - - assert (bot2left Spn1 \; left2top Csp = bot2right Spn1 \; right2top Csp) - as K1. - { unfold bot2left, bot2right. - rewrite HeqCsp. - rewrite HeqSpn1. - simpl; auto. - } - remember ( @isPrePullback.Build C A B Csp Spn1 K1) as Pb1. - assert (PrePullback.axioms_ Csp Spn1) as Pb2. - { econstructor. - exact Pb1. } - remember ( @PrePullback.Pack C A B Csp Spn1 Pb2) as PB. - - destruct IM4 as [IM5 IM6]. - clear IM6. - specialize (IM5 PB). - - inversion HeqSpn1; subst. - simpl in *. - clear H K1. - - unfold pb_terminal in *. - destruct Pb2 as [IM]. - destruct IM. - simpl in *. - - destruct IM5. - simpl in *. - - econstructor. - instantiate (1:= top_map0). - split; auto. -Qed. - -Lemma pbquare_universal_aux1 {C: cat} (A0 A1 B0 B1 P0 P1 T : C) - (t: A0 ~> T) (s: B0 ~> T) (p01: P0 ~> A0) (p02: P0 ~> B0) - (f: A1 ~> A0) (g: B1 ~> B0) (p11: P1 ~> A1) (p12: P1 ~> B1) : - pbsquare p01 p02 t s -> - p11 \; f \; t = p12 \; g \; s -> - sigma m: P1 ~> P0, p11 \; f = m \; p01 /\ p12 \; g = m \; p02. - intros. - eapply pbsquare_universal; eauto. - setoid_rewrite <- compoA; auto. -Qed. - -(* product morphism *) -Program Definition ipairI {C : pbcat} {C0 : C} {x0 x1 x2 x3 : iHom C0} - (f : x0 ~> x2) (g : x1 ~> x3) : (x0 *_C0 x1) ~>_(iHom C0) (x2 *_C0 x3). - unfold iprod. - unfold iprod_pb. - remember (pb (x0 :> C) (x1 :> C) - {| top := C0; left2top := tgt; right2top := src |}) as Pb1. - remember (pb (x2 :> C) (x3 :> C) - {| top := C0; left2top := tgt; right2top := src |}) as Pb2. - destruct Pb1 as [P1 J1]. - destruct Pb2 as [P2 J2]. - - simpl in *; simpl. - - remember ({| top := C0; left2top := tgt; right2top := src |}) as Csp. - - remember (@is_pb C (x0 :> C) (x1 :> C) Csp) as X. - clear HeqX. - destruct X. -Admitted. - -Program Definition ipairC {C : pbcat} {C0 : C} {C1 C2 C3 C4 : iHom C0} - (f : C1 ~> C3) (g : C2 ~> C4) : - ((C1 *_C0 C2) :> C) ~>_C ((C3 *_C0 C4) :> C). -eapply ihom_morph. -eapply ipairI; eauto. -Defined. - -Notation "<( f , g )>" := (ipairI f g). -Notation "<(' f , g )>" := (ipairC f g). - -(* An internal precategory is an internal category with two operators - that must be src and tgt preserving, i.e. iHom morphisms: identity - : C0 -> C1 (corresponding to horizontal 1-morphism identity in - double cat) and composition : C1 * C1 -> C1 (corresponding to - horizontal composition) *) -HB.mixin Record IsInternalPreCat (C : pbcat) (C0 : obj C) - of @InternalQuiver C C0 := { - iidI : (C0 : iHom C0) ~>_(iHom C0) (@C1 C C0 : iHom C0); - icompI : let C1 := @C1 C C0 : iHom C0 in - let C2 := pbC0 C1 C1 : iHom C0 in - (C2 ~>_(iHom C0) C1) -}. -#[short(type="iprecat")] -HB.structure Definition InternalPreCat (C : pbcat) := - { C0 of @IsInternalPreCat C C0 }. - -Program Definition iidC' {C : pbcat} {C0 : iprecat C} : - ((C0 : iHom C0) :> C) ~>_C - ((@C1 C C0 : iHom C0) :> C). -destruct C0; simpl in *. -destruct class as [IM1 IM2 IM3]; simpl in *. -destruct IM3; simpl in *. -exact iidI0. -Defined. -Program Definition iidC {C : pbcat} {C0 : iprecat C} : - (C0 :> C) ~>_C (@C1 C C0 :> C). -eapply iidC'; eauto. -Defined. - -Program Definition icompC {C : pbcat} {C0 : iprecat C} : - let C1 := @C1 C C0 : iHom C0 in - let C2 := pbC0 C1 C1 : iHom C0 in - ((C2 :> C) ~>_C (C1 :> C)). -destruct C0; simpl in *. -destruct class as [IM1 IM2 IM3]; simpl in *. -destruct IM3; simpl in *. -exact icompI0. -Defined. - -(* Check (iquiver Type <~> quiver). *) -(* Check (iprecat Type <~> precat). *) - -(* An internal category moreover must satisfy additional properies on iid and icomp -(associativity and unit laws) *) -#[key="C0"] - HB.mixin Record IsInternalCat (C : pbcat) (C0 : obj C) - of InternalPreCat C C0 := { - - icompA1 : - (<( (@icompI C C0), - (@idmap (iHom C0) (@C1 C C0: iHom C0)) )> \; icompI) = - ((@iprodIAsc C C0 (@C1 C C0: iHom C0) _ _) \; - <( (@idmap (iHom C0) (@C1 C C0: iHom C0)), icompI )> \; icompI) ; - - icomp1l : <(' @idmap (iHom C0) (@C1 C C0: iHom C0), (@iidI C C0) )> \; - icompC = @iprodl C C0 (C1 :> C) (C0 :> C); - - icomp1r : <(' (@iidI C C0), @idmap (iHom C0) (@C1 C C0: iHom C0) )> \; - icompC = @iprodr C C0 (C0 :> C) (C1 :> C); - }. -#[short(type="icat")] -HB.structure Definition InternalCat (C : pbcat) := - {C0 of @IsInternalCat C C0}. -(* Check (icat Type <~> cat). *) - - -(* A double category is an internal category in cat - - The objects are the objects of C0 - - The vertical maps are the maps of C0 - - The horizontal maps are the objects of C1 - - The 2-cells are the maps of C1 - - About identities: - - The identity vertical map on (x : C) is \idmap_x - - The identity horizontal map on (x : C) is iid x - - the identity 2-cell on (x : C) is iid (\idmap_x) = \idmap_(iid x) - - About compositions: - - The vertical composition of maps is the composition of C0 - - The vertical compositions of 2-cells is the composition of C1 - (and it agrees with the former because src and tgt are functors - and because iid is a iHom-map) - - The horizontal composition of maps is the object part of icomp - - The horizontal composition of 2-cells is the map part of icomp +(* hcomp (hm, hu) = prj1 (hm, hu) = hm + hcomp (hu, hm) = prj2 (hu, hm) = hm + (hm1 * hm2) * hm3 ~> hm1 * (hm2 * hm3) + +(* Double category with universal characterization of weak + horizontal associativity *) +HB.mixin Record IsDCat_UA T of CFunctor T := { + associator : forall (a0 a1 a2 a3: T) + (h1: @hhom T a0 a1) (h2: @hhom T a1 a2) + (h3: @hhom T a2 a3), + let h23 := hcomp a1 a2 a3 h2 h3 in + let h12 := hcomp a0 a1 a2 h1 h2 in + let hh1 := hcomp a0 a1 a3 h1 h23 in + let hh2 := hcomp a0 a2 a3 h12 h3 in + @hom (HHomSet T) (@HO T (@hhom T) a0 a3 hh2) + (@HO T (@hhom T) a0 a3 hh1) +}. *) -(* HB.structure' Definition DoubleCat := @InternalCat cat. *) -Axiom cat_pbop : HasPBop cat. -HB.instance Definition _ := cat_pbop. - -Axiom cat_preb : - forall (a b: cat) (c: cospan a b), isPrePullback cat a b c (@pb cat a b c). -HB.instance Definition _ (a b: cat) (c: cospan a b) := @cat_preb a b c. -Axiom cat_pb : - forall (a b: cat) (c: cospan a b), - prepullback_isTerminal cat a b c (@pb cat a b c). -HB.instance Definition _ (a b: cat) (c: cospan a b) := @cat_pb a b c. - -(* basically, the internal category adds the D1 category to the base -D0 category, which is C0 (an object of cat, which is shown to have -pullbacks) *) -Definition doublecat := icat cat. - -(* Check (doublecat <~> ???) *) From a2cc7228447c54a7083347fbab68783cf0bc57f6 Mon Sep 17 00:00:00 2001 From: ptorrx Date: Thu, 18 Jan 2024 18:43:27 +0100 Subject: [PATCH 132/147] restructuring --- theories/encatA.v | 2166 ------------------------------------- theories/encatB.v | 1952 --------------------------------- theories/encatD1.v | 2587 -------------------------------------------- 3 files changed, 6705 deletions(-) delete mode 100644 theories/encatA.v delete mode 100644 theories/encatB.v delete mode 100644 theories/encatD1.v diff --git a/theories/encatA.v b/theories/encatA.v deleted file mode 100644 index ee390c766..000000000 --- a/theories/encatA.v +++ /dev/null @@ -1,2166 +0,0 @@ -Require Import ssreflect ssrfun. -From HB Require Import structures. - -Set Implicit Arguments. -Unset Strict Implicit. -Unset Printing Implicit Defensive. -Add Search Blacklist "__canonical__". - -Declare Scope algebra_scope. -Delimit Scope algebra_scope with A. -Local Open Scope algebra_scope. - -Declare Scope cat_scope. -Delimit Scope cat_scope with cat. -Local Open Scope cat_scope. - -(* we assume a few axioms to make life easier *) -Axiom funext : forall {T : Type} {U : T -> Type} [f g : forall t, U t], - (forall t, f t = g t) -> f = g. -Axiom propext : forall P Q : Prop, P <-> Q -> P = Q. -Axiom Prop_irrelevance : forall (P : Prop) (x y : P), x = y. - -(* Shortcut *) -Notation U := Type. - -(* Base definition : raw categories = quivers *) -HB.mixin Record IsQuiver C := { hom : C -> C -> U }. -Unset Universe Checking. -#[short(type="quiver")] -HB.structure Definition Quiver : Set := { C of IsQuiver C }. -Set Universe Checking. - -Bind Scope cat_scope with quiver. -Bind Scope cat_scope with hom. -Arguments hom {C} : rename. -Notation homs T := (@hom T _ _). -Notation "a ~> b" := (hom a b) - (at level 99, b at level 200, format "a ~> b") : cat_scope. -Notation "a ~>_ C b" := (@hom C a b) - (at level 99, C at level 0, only parsing) : cat_scope. - -(* precategories are quivers + id and comp *) -HB.mixin Record Quiver_IsPreCat C of Quiver C := { - idmap : forall (a : C), a ~> a; - comp : forall (a b c : C), (a ~> b) -> (b ~> c) -> (a ~> c); -}. - -HB.factory Record IsPreCat C := { - hom : C -> C -> U; - idmap : forall (a : C), hom a a; - comp : forall (a b c : C), hom a b -> hom b c -> hom a c; -}. -HB.builders Context C of IsPreCat C. - HB.instance Definition _ := IsQuiver.Build C hom. - HB.instance Definition _ := Quiver_IsPreCat.Build C idmap comp. -HB.end. - -Unset Universe Checking. -#[short(type="precat")] -HB.structure Definition PreCat : Set := { C of IsPreCat C }. -Set Universe Checking. - -Bind Scope cat_scope with precat. -Arguments idmap {C} {a} : rename. -Arguments comp {C} {a b c} : rename. -Notation "f \o g" := (comp g f) : cat_scope. -Notation "f \; g :> T" := (@comp T _ _ _ f g) - (at level 60, g, T at level 60, format "f \; g :> T", only parsing) : cat_scope. -Notation "f \; g" := (comp f g) : cat_scope. -Notation "\idmap_ a" := (@idmap _ a) (only parsing, at level 0) : cat_scope. - -(* categories are precategories + laws *) -HB.mixin Record PreCat_IsCat C of PreCat C := { - comp1o : forall (a b : C) (f : a ~> b), idmap \; f = f; - compo1 : forall (a b : C) (f : a ~> b), f \; idmap = f; - compoA : forall (a b c d : C) (f : a ~> b) (g : b ~> c) (h : c ~> d), - f \; (g \; h) = (f \; g) \; h -}. -Unset Universe Checking. -#[short(type="cat")] -HB.structure Definition Cat : Set := { C of PreCat_IsCat C & IsPreCat C }. -Set Universe Checking. - -Bind Scope cat_scope with cat. -Arguments compo1 {C a b} : rename. -Arguments comp1o {C a b} : rename. -Arguments compoA {C a b c d} : rename. - -(* the discrete category on a type cannot be the default, we make an alias *) -Definition discrete (T : U) := T. -HB.instance Definition _ T := @IsPreCat.Build (discrete T) (fun x y => x = y) - (fun=> erefl) (@etrans _). -Lemma etransA T (a b c d : discrete T) (f : a ~> b) (g : b ~> c) (h : c ~> d) : - f \; (g \; h) = (f \; g) \; h. -Proof. by rewrite /idmap/comp/=; case: _ / h; case: _ / g. Qed. -HB.instance Definition _ T := PreCat_IsCat.Build (discrete T) (@etrans_id _) - (fun _ _ _ => erefl) (@etransA _). - -(* the category of the unit type is the discrete one *) -HB.instance Definition _ := Cat.copy unit (discrete unit). - -HB.instance Definition _ := @IsPreCat.Build U (fun A B => A -> B) - (fun a => idfun) (fun a b c (f : a -> b) (g : b -> c) => (g \o f)%FUN). -HB.instance Definition _ := PreCat_IsCat.Build U (fun _ _ _ => erefl) - (fun _ _ _ => erefl) (fun _ _ _ _ _ _ _ => erefl). - - -Lemma Ucomp (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) : f \; g = (g \o f)%FUN. -Proof. by []. Qed. -Lemma Ucompx (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) x : (f \; g) x = g (f x). -Proof. by []. Qed. -Lemma U1 (X : U) : \idmap_X = idfun. -Proof. by []. Qed. -Lemma U1x (X : U) x : \idmap_X x = x. -Proof. by []. Qed. - -(* a prefunctor is a functor without laws *) -HB.mixin Record IsPreFunctor (C D : quiver) (F : C -> D) := { - Fhom : forall (a b : C), (a ~> b) -> (F a ~> F b) -}. - -Unset Universe Checking. -HB.structure Definition PreFunctor (C D : quiver) : Set := - { F of IsPreFunctor C D F }. -Set Universe Checking. -HB.instance Definition _ := IsQuiver.Build quiver PreFunctor.type. - -Notation "F ^$" := (@Fhom _ _ F _ _) - (at level 1, format "F ^$") : cat_scope. -Notation "F <$> f" := (@Fhom _ _ F _ _ f) - (at level 58, format "F <$> f", right associativity) : cat_scope. - -(* prefunctors are equal if their object and hom part are respectively equal *) -Lemma prefunctorP (C D : quiver) (F G : C ~> D) (eqFG : F =1 G) : - let homF a b F := F a ~> F b in - (forall a b f, eq_rect _ (homF a b) (F <$> f) _ (funext eqFG) = G <$> f) -> - F = G. -Proof. -move: F G => [F [[/= Fhom]]] [G [[/= Ghom]]] in eqFG *. -case: _ / (funext eqFG) => /= in Ghom * => eqFGhom. -congr PreFunctor.Pack; congr PreFunctor.Class; congr IsPreFunctor.Axioms_. -by do 3!apply: funext=> ?. -Qed. - -(* a functor is a prefunctor + laws for id and comp *) -HB.mixin Record PreFunctor_IsFunctor (C D : precat) (F : C -> D) - of @PreFunctor C D F := { - F1 : forall (a : C), F <$> \idmap_a = idmap; - Fcomp : forall (a b c : C) (f : a ~> b) (g : b ~> c), - F <$> (f \; g) = F <$> f \; F <$> g; -}. -Unset Universe Checking. - -(* precat and cat have a quiver structure *) -HB.structure Definition Functor (C D : precat) : Set := - { F of IsPreFunctor C D F & PreFunctor_IsFunctor C D F }. -Set Universe Checking. -HB.instance Definition _ := IsQuiver.Build precat Functor.type. -HB.instance Definition _ := IsQuiver.Build cat Functor.type. - -(* functor equality is the same as prefunctor because of PI *) -Lemma functorP (C D : precat) (F G : C ~> D) (eqFG : F =1 G) : - let homF a b F := F a ~> F b in - (forall a b f, eq_rect _ (homF a b) (F^$ f) _ (funext eqFG) = G^$ f) -> - F = G. -Proof. -move=> /= /prefunctorP {eqFG}. -case: F G => [F [/= Fm Fm']] [G [/= Gm Gm']]//=. -move=> [_] /EqdepFacts.eq_sigT_iff_eq_dep eqFG. -case: _ / eqFG in Gm' *. -congr Functor.Pack; congr Functor.Class. -case: Fm' Gm' => [F1 Fc] [G1 Gc]. -by congr PreFunctor_IsFunctor.Axioms_; apply: Prop_irrelevance. -Qed. - -(* the identity function is a functor *) -HB.instance Definition _ (C : quiver) := - IsPreFunctor.Build C C idfun (fun a b => idfun). -HB.instance Definition _ (C : precat) := - PreFunctor_IsFunctor.Build C C idfun (fun=> erefl) (fun _ _ _ _ _ => erefl). - -(* the composition of prefunctors *) -Section comp_prefunctor. -Context {C D E : quiver} {F : C ~> D} {G : D ~> E}. - -HB.instance Definition _ := IsPreFunctor.Build C E (G \o F)%FUN - (fun a b f => G <$> F <$> f). -Lemma comp_Fun (a b : C) (f : a ~> b) : (G \o F)%FUN <$> f = G <$> (F <$> f). -Proof. by []. Qed. -End comp_prefunctor. - -Section comp_functor. -Context {C D E : precat} {F : C ~> D} {G : D ~> E}. -Lemma comp_F1 (a : C) : (G \o F)%FUN <$> \idmap_a = idmap. -Proof. by rewrite !comp_Fun !F1. Qed. -Lemma comp_Fcomp (a b c : C) (f : a ~> b) (g : b ~> c) : - (G \o F)%FUN <$> (f \; g) = (G \o F)%FUN <$> f \; (G \o F)%FUN <$> g. -Proof. by rewrite !comp_Fun !Fcomp. Qed. -HB.instance Definition _ := PreFunctor_IsFunctor.Build C E (G \o F)%FUN - comp_F1 comp_Fcomp. -End comp_functor. - -(* precat and cat have a precategory structure *) -HB.instance Definition _ := Quiver_IsPreCat.Build precat - (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). -HB.instance Definition _ := Quiver_IsPreCat.Build cat - (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). - -Lemma funext_frefl A B (f : A -> B) : funext (frefl f) = erefl. -Proof. exact: Prop_irrelevance. Qed. - -(* precategories and categories form a category *) -Definition precat_cat : PreCat_IsCat precat. -Proof. -by split=> [C D F|C D F|C D C' D' F G H]; - apply/functorP => a b f /=; rewrite funext_frefl. -Qed. -HB.instance Definition _ := precat_cat. -Definition cat_cat : PreCat_IsCat cat. -Proof. -by split=> [C D F|C D F|C D C' D' F G H]; - apply/functorP => a b f /=; rewrite funext_frefl. -Qed. -HB.instance Definition _ := cat_cat. - -Check (cat : cat). - -(* concrete categories *) -HB.mixin Record Quiver_IsPreConcrete T of Quiver T := { - concrete : T -> U; - concrete_fun : forall (a b : T), (a ~> b) -> concrete a -> concrete b; -}. -Unset Universe Checking. -#[short(type="preconcrete_quiver")] -HB.structure Definition PreConcreteQuiver : Set := - { C of Quiver_IsPreConcrete C & IsQuiver C }. -Set Universe Checking. -Coercion concrete : PreConcreteQuiver.sort >-> Sortclass. - -HB.mixin Record PreConcrete_IsConcrete T of PreConcreteQuiver T := { - concrete_fun_inj : forall (a b : T), injective (concrete_fun a b) -}. -Unset Universe Checking. -#[short(type="concrete_quiver")] -HB.structure Definition ConcreteQuiver : Set := - { C of PreConcreteQuiver C & PreConcrete_IsConcrete C }. -Set Universe Checking. - -HB.instance Definition _ (C : ConcreteQuiver.type) := - IsPreFunctor.Build _ _ (concrete : C -> U) concrete_fun. - -HB.mixin Record PreCat_IsConcrete T of ConcreteQuiver T & PreCat T := { - concrete1 : forall (a : T), concrete <$> \idmap_a = idfun; - concrete_comp : forall (a b c : T) (f : a ~> b) (g : b ~> c), - concrete <$> (f \; g) = ((concrete <$> g) \o (concrete <$> f))%FUN; -}. -Unset Universe Checking. -#[short(type="concrete_precat")] -HB.structure Definition ConcretePreCat : Set := - { C of PreCat C & ConcreteQuiver C & PreCat_IsConcrete C }. -#[short(type="concrete_cat")] -HB.structure Definition ConcreteCat : Set := - { C of Cat C & ConcreteQuiver C & PreCat_IsConcrete C }. -Set Universe Checking. - -HB.instance Definition _ (C : concrete_precat) := - PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). -HB.instance Definition _ (C : ConcreteCat.type) := - PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). - -HB.instance Definition _ := Quiver_IsPreConcrete.Build U (fun _ _ => id). -HB.instance Definition _ := PreConcrete_IsConcrete.Build U (fun _ _ _ _ => id). -HB.instance Definition _ := PreCat_IsConcrete.Build U - (fun=> erefl) (fun _ _ _ _ _ => erefl). - -Unset Universe Checking. -HB.instance Definition _ := Quiver_IsPreConcrete.Build quiver (fun _ _ => id). -HB.instance Definition _ := Quiver_IsPreConcrete.Build precat (fun _ _ => id). -HB.instance Definition _ := Quiver_IsPreConcrete.Build cat (fun _ _ => id). -Lemma quiver_concrete_subproof : PreConcrete_IsConcrete quiver. -Proof. -constructor=> C D F G FG; apply: prefunctorP. - by move=> x; congr (_ x); apply: FG. -by move=> *; apply: Prop_irrelevance. -Qed. -HB.instance Definition _ := quiver_concrete_subproof. - -Lemma precat_concrete_subproof : PreConcrete_IsConcrete precat. -Proof. -constructor=> C D F G FG; apply: functorP. - by move=> x; congr (_ x); apply: FG. -by move=> *; apply: Prop_irrelevance. -Qed. -HB.instance Definition _ := precat_concrete_subproof. - -Lemma cat_concrete_subproof : PreConcrete_IsConcrete cat. -Proof. -constructor=> C D F G FG; apply: functorP. - by move=> x; congr (_ x); apply: FG. -by move=> *; apply: Prop_irrelevance. -Qed. -HB.instance Definition _ := cat_concrete_subproof. -HB.instance Definition _ := PreCat_IsConcrete.Build precat - (fun=> erefl) (fun _ _ _ _ _ => erefl). -HB.instance Definition _ := PreCat_IsConcrete.Build cat - (fun=> erefl) (fun _ _ _ _ _ => erefl). -Set Universe Checking. - -(* constant functor *) -Definition cst (C D : quiver) (c : C) := fun of D => c. -Arguments cst {C} D c. -HB.instance Definition _ {C D : precat} (c : C) := - IsPreFunctor.Build D C (cst D c) (fun _ _ _ => idmap). -HB.instance Definition _ {C D : cat} (c : C) := - PreFunctor_IsFunctor.Build D C (cst D c) (fun=> erefl) - (fun _ _ _ _ _ => esym (compo1 idmap)). - -(* opposite category *) -Definition catop (C : U) : U := C. -Notation "C ^op" := (catop C) - (at level 2, format "C ^op") : cat_scope. -HB.instance Definition _ (C : quiver) := - IsQuiver.Build C^op (fun a b => hom b a). -HB.instance Definition _ (C : precat) := - Quiver_IsPreCat.Build (C^op) (fun=> idmap) (fun _ _ _ f g => g \; f). -HB.instance Definition _ (C : cat) := PreCat_IsCat.Build (C^op) - (fun _ _ _ => compo1 _) (fun _ _ _ => comp1o _) - (fun _ _ _ _ _ _ _ => esym (compoA _ _ _)). - -HB.instance Definition _ {C : precat} {c : C} := - IsPreFunctor.Build C _ (hom c) (fun a b f g => g \; f). -Lemma hom_Fhom_subproof (C : cat) (x : C) : - PreFunctor_IsFunctor _ _ (hom x). -Proof. by split=> *; apply/funext => h; [apply: compo1 | apply: compoA]. Qed. -HB.instance Definition _ {C : cat} {c : C} := hom_Fhom_subproof c. - -Check fun (C : cat) (x : C) => hom x : C ~>_cat U. - -Lemma hom_op {C : quiver} (c : C^op) : hom c = (@hom C)^~ c. -Proof. reflexivity. Qed. - -Lemma homFhomx {C : precat} (a b c : C) (f : a ~> b) (g : c ~> a) : - (hom c <$> f) g = g \; f. -Proof. reflexivity. Qed. - -(* nary product of categories *) -Definition dprod {I : U} (C : I -> U) := forall i, C i. - -Section hom_dprod. -Context {I : U} (C : I -> quiver). -Definition dprod_hom_subdef (a b : dprod C) := forall i, a i ~> b i. -HB.instance Definition _ := IsQuiver.Build (dprod C) dprod_hom_subdef. -End hom_dprod. -Arguments dprod_hom_subdef /. - -Section precat_dprod. -Context {I : U} (C : I -> precat). -Definition dprod_idmap_subdef (a : dprod C) : a ~> a := fun=> idmap. -Definition dprod_comp_subdef (a b c : dprod C) (f : a ~> b) (g : b ~> c) : a ~> c := - fun i => f i \; g i. -HB.instance Definition _ := IsPreCat.Build (dprod C) - dprod_idmap_subdef dprod_comp_subdef. -End precat_dprod. -Arguments dprod_idmap_subdef /. -Arguments dprod_comp_subdef /. - -Section cat_dprod. -Context {I : U} (C : I -> cat). -Local Notation type := (dprod C). -Lemma dprod_is_cat : PreCat_IsCat type. -Proof. -split=> [a b f|a b f|a b c d f g h]; apply/funext => i; -[exact: comp1o | exact: compo1 | exact: compoA]. -Qed. -HB.instance Definition _ := dprod_is_cat. -End cat_dprod. - -(* binary product *) -Section hom_prod. -Context {C D : quiver}. -Definition prod_hom_subdef (a b : C * D) := ((a.1 ~> b.1) * (a.2 ~> b.2))%type. -HB.instance Definition _ := IsQuiver.Build (C * D)%type prod_hom_subdef. -End hom_prod. - -Section precat_prod. -Context {C D : precat}. -HB.instance Definition _ := IsPreCat.Build (C * D)%type (fun=> (idmap, idmap)) - (fun a b c (f : a ~> b) (g : b ~> c) => (f.1 \; g.1, f.2 \; g.2)). -End precat_prod. - -Section cat_prod. -Context {C D : cat}. -Local Notation type := (C * D)%type. -Lemma prod_is_cat : PreCat_IsCat type. -Proof. -split=> [[a1 a2] [b1 b2] [f1 f2]|[a1 a2] [b1 b2] [f1 f2]| - [a1 a2] [b1 b2] [c1 c2] [d1 d2] [f1 f2] [g1 g2] [h1 h2]]; congr (_, _) => //=; -by [exact: comp1o | exact: compo1 | exact: compoA]. -Qed. -HB.instance Definition _ := prod_is_cat. -End cat_prod. - -(* naturality *) -HB.mixin Record IsNatural (C D : precat) (F G : C ~>_quiver D) - (n : forall c, F c ~> G c) := { - natural : forall (a b : C) (f : a ~> b), - F <$> f \; n b = n a \; G <$> f -}. -Unset Universe Checking. -HB.structure Definition Natural (C D : precat) - (F G : C ~>_quiver D) : Set := - { n of @IsNatural C D F G n }. -Set Universe Checking. -HB.instance Definition _ (C D : precat) := - IsQuiver.Build (PreFunctor.type C D) (@Natural.type C D). -HB.instance Definition _ (C D : cat) := - IsQuiver.Build (Functor.type C D) (@Natural.type C D). -Arguments natural {C D F G} n [a b] f : rename. - -Check fun (C D : cat) (F G : C ~> D) => F ~>_(C ~>_cat D) G. - -Lemma naturalx (C : precat) (D : concrete_precat) - (F G : C ~>_quiver D) (n : F ~> G) (a b : C) (f : a ~> b) g : - (concrete <$> n b) ((concrete <$> F <$> f) g) = - (concrete <$> G <$> f) ((concrete <$> n a) g). -Proof. -have /(congr1 (fun h => (concrete <$> h) g)) := natural n f. -by rewrite !Fcomp. -Qed. -Arguments naturalx {C D F G} n [a b] f. - -Lemma naturalU (C : precat) (F G : C ~>_quiver U) (n : F ~> G) - (a b : C) (f : a ~> b) g : n b (F^$ f g) = G^$ f (n a g). -Proof. exact: (naturalx n). Qed. - -Lemma natP (C D : precat) (F G : C ~>_quiver D) (n m : F ~> G) : - Natural.sort n = Natural.sort m -> n = m. -Proof. -case: n m => [/= n nP] [/= m mP] enm. -elim: _ / enm in mP *; congr Natural.Pack. -case: nP mP => [[?]] [[?]]; congr Natural.Class. -congr IsNatural.Axioms_. -exact: Prop_irrelevance. -Qed. - -Notation "F ~~> G" := (F ~>_(homs quiver) G) - (at level 99, G at level 200, format "F ~~> G"). -Notation "F ~~> G :> C ~> D" := (F ~> G :> (C ~>_quiver D)) - (at level 99, G at level 200, C, D at level 0, - format "F ~~> G :> C ~> D"). - -Definition natural_id {C D : precat} (F : C ~>_quiver D) (a : C) := \idmap_(F a). -Definition natural_id_natural (C D : cat) (F : C ~>_quiver D) : - IsNatural C D F F (natural_id F). -Proof. by constructor=> a b f; rewrite /natural_id/= compo1 comp1o. Qed. -HB.instance Definition _ C D F := @natural_id_natural C D F. - -Check fun {C D : cat} (F : C ~>_quiver D) => natural_id F : F ~> F. - -Definition natural_comp {C D : precat} (F G H : C ~>_quiver D) - (m : F ~> G) (n : G ~> H) (a : C) := m a \; n a. -Definition natural_comp_natural (C D : cat) (F G H : C ~>_quiver D) m n : - IsNatural C D F H (@natural_comp C D F G H m n). -Proof. -constructor=> a b f; rewrite /natural_comp/=. -by rewrite compoA natural -compoA natural compoA. -Qed. -HB.instance Definition _ C D F G H m n := @natural_comp_natural C D F G H m n. - -HB.instance Definition _ {C D : cat} := - Quiver_IsPreCat.Build (PreFunctor.type C D) natural_id natural_comp. -HB.instance Definition _ {C D : cat} := - Quiver_IsPreCat.Build (Functor.type C D) natural_id natural_comp. - -Lemma prefunctor_cat {C D : cat} : PreCat_IsCat (PreFunctor.type C D). -Proof. -constructor => [F G f|F G f|F G H J f g h]. -- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. -- by apply/natP/funext => a; rewrite /= /natural_comp compo1. -- by apply/natP/funext => a; rewrite /= /natural_comp compoA. -Qed. -HB.instance Definition _ C D := @prefunctor_cat C D. - -Lemma functor_cat {C D : cat} : PreCat_IsCat (Functor.type C D). -Proof. -constructor => [F G f|F G f|F G H J f g h]. -- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. -- by apply/natP/funext => a; rewrite /= /natural_comp compo1. -- by apply/natP/funext => a; rewrite /= /natural_comp compoA. -Qed. -HB.instance Definition _ C D := @functor_cat C D. - -Section nat_map_left. -Context {C D E : precat} {F G : C ~> D}. - -Definition nat_lmap (H : D ~>_quiver E) (n : forall c, F c ~> G c) : - forall c, (H \o F)%FUN c ~> (H \o G)%FUN c := fun c => H <$> n c. - -Fail Check fun (H : D ~> E) (n : F ~~> G) => nat_lmap H n : H \o F ~~> H \o G. - -Lemma nat_lmap_is_natural (H : D ~> E) (n : F ~~> G) : - IsNatural C E (H \o F) (H \o G) (nat_lmap H n). -Proof. by constructor=> a b f; rewrite /nat_lmap/= -!Fcomp natural. Qed. -HB.instance Definition _ H n := nat_lmap_is_natural H n. - -Check fun (H : D ~> E) (n : F ~~> G) => nat_lmap H n : H \o F ~~> H \o G. - -End nat_map_left. - -Notation "F n" := (nat_lmap F n) - (at level 58, format "F n", right associativity) : cat_scope. - -Section nat_map_right. -Context {C D E : precat} {F G : C ~> D}. - -Definition nat_rmap (H : E -> C) (n : forall c, F c ~> G c) : - forall c, (F \o H)%FUN c ~> (G \o H)%FUN c := fun c => n (H c). -Lemma nat_rmap_is_natural (H : E ~> C :> quiver) (n : F ~~> G) : - IsNatural E D (F \o H)%FUN (G \o H)%FUN (nat_rmap H n). -Proof. by constructor=> a b f; rewrite /nat_lmap/= natural. Qed. -HB.instance Definition _ H n := nat_rmap_is_natural H n. - -End nat_map_right. - -Notation "F <$o> n" := (nat_rmap F n) - (at level 58, format "F <$o> n", right associativity) : cat_scope. - -Definition delta (C D : cat) : C -> (D ~> C) := cst D. -Arguments delta C D : clear implicits. - -Definition map_delta {C D : cat} (a b : C) (f : a ~> b) : - delta C D a ~> delta C D b. -Proof. -apply: (@Natural.Pack _ _ (cst D a) (cst D b) (fun x => f)). -apply: Natural.Class; apply: (IsNatural.Build _ _ _ _ _). -by move=> a' b' ?; rewrite compo1 comp1o. -Defined. - -HB.instance Definition _ {C D : cat} := - IsPreFunctor.Build C (D ~> C) (delta C D) (@map_delta C D). - -Lemma delta_functor {C D : cat} : PreFunctor_IsFunctor _ _ (delta C D). -Proof. by constructor=> [a|a b c f g]; exact/natP. Qed. -HB.instance Definition _ C D := @delta_functor C D. - -HB.mixin Record IsMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { - unit : idfun ~~> M; - join : (M \o M)%FUN ~~> M; - bind : forall (a b : C), (a ~> M b) -> (M a ~> M b); - bindE : forall a b (f : a ~> M b), bind a b f = M <$> f \; join b; - unit_join : forall a, (M <$> unit a) \; join _ = idmap; - join_unit : forall a, join _ \; (M <$> unit a) = idmap; - join_square : forall a, M <$> join a \; join _ = join _ \; join _ -}. - -#[short(type="premonad")] -HB.structure Definition PreMonad (C : precat) := - {M of @PreFunctor C C M & IsMonad C M}. -#[short(type="monad")] -HB.structure Definition Monad (C : precat) := - {M of @Functor C C M & IsMonad C M}. - -HB.factory Record IsJoinMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { - unit : idfun ~~> M; - join : (M \o M)%FUN ~~> M; - unit_join : forall a, (M <$> unit a) \; join _ = idmap; - join_unit : forall a, join _ \; (M <$> unit a) = idmap; - join_square : forall a, M <$> join a \; join _ = join _ \; join _ -}. -HB.builders Context C M of IsJoinMonad C M. - HB.instance Definition _ := IsMonad.Build C M - (fun a b f => erefl) unit_join join_unit join_square. -HB.end. - -HB.mixin Record IsCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { - counit : M ~~> idfun; - cojoin : M ~~> (M \o M)%FUN; - cobind : forall (a b : C), (M a ~> b) -> (M a ~> M b); - cobindE : forall a b (f : M a ~> b), cobind a b f = cojoin _ \; M <$> f; - unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; - join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; - cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ -}. -#[short(type="precomonad")] -HB.structure Definition PreCoMonad (C : precat) := - {M of @PreFunctor C C M & IsCoMonad C M}. -#[short(type="comonad")] -HB.structure Definition CoMonad (C : precat) := - {M of @Functor C C M & IsCoMonad C M}. - -HB.factory Record IsJoinCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { - counit : M ~~> idfun; - cojoin : M ~~> (M \o M)%FUN; - unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; - join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; - cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ -}. -HB.builders Context C M of IsJoinCoMonad C M. - HB.instance Definition _ := IsCoMonad.Build C M - (fun a b f => erefl) unit_cojoin join_counit cojoin_square. -HB.end. - -Lemma idFmap (C : cat) (a b : C) (f : a ~> b) : idfun <$> f = f. -Proof. by []. Qed. - -Lemma compFmap (C D E : cat) (F : C ~> D) (G : D ~> E) (a b : C) (f : a ~> b) : - (G \o F) <$> f = G <$> F <$> f. -Proof. by []. Qed. - -(* yoneda *) -Section hom_repr. -Context {C : cat} (F : C ~>_cat U). - -Definition homF : C -> U := fun c => hom c ~~> F. - -Section nat. -Context (x y : C) (xy : x ~> y). - -(* Goal hom x ~~> F -> hom y ~~> F *) -Context (n : hom x ~~> F). -Definition homFhom c : hom y c ~> F c := fun g => n _ (xy \; g). - -Lemma homFhom_natural_subdef : IsNatural C U (hom y) F homFhom. -Proof. -by split=> a b f /=; apply/funext => g /=; - rewrite /homFhom !Ucompx/= !naturalU/= Fcomp. -Qed. -HB.instance Definition _ := homFhom_natural_subdef. -End nat. -Arguments homFhom / : clear implicits. - -HB.about IsPreFunctor.Build. -Check homFhom : forall x y : C, (x ~> y) -> (homF x -> homF y). -HB.instance Definition _ := IsPreFunctor.Build _ _ homF homFhom. -Lemma homF_functor_subproof : PreFunctor_IsFunctor _ _ homF. -Proof. -split=> [a|a b c f g]. - apply/funext => -[/= f natf]. - apply: natP => //=; apply: funext => b; apply: funext => g/=. - by rewrite comp1o. -apply/funext => -[/= h natf]. -apply: natP => //=; apply: funext => d; apply: funext => k/=. -by rewrite compoA. -Qed. -HB.instance Definition _ := homF_functor_subproof. - -Section pointed. -Context (c : C). -Definition hom_repr : homF c ~> F c := fun f => f _ idmap. -Arguments hom_repr /. - -Definition repr_hom (fc : F c) a : hom c a ~> F a := - fun f => F^$ f fc. -Arguments repr_hom / : clear implicits. -Lemma repr_hom_subdef (fc : F c) : IsNatural _ _ _ _ (repr_hom fc). -Proof. by split=> a b f /=; apply/funext=> x; rewrite !Ucompx/= Fcomp. Qed. -HB.instance Definition _ {fc : F c} := repr_hom_subdef fc. - -Definition repr_hom_nat : F c ~> homF c := repr_hom. - -Lemma hom_reprK : cancel hom_repr repr_hom_nat. -Proof. -move=> f; apply/natP; apply/funext => a; apply/funext => g /=. -by rewrite -naturalU/=; congr (f _ _); apply: comp1o. -Qed. -Lemma repr_homK : cancel (repr_hom : F c ~> homF c) hom_repr. -Proof. by move=> fc; rewrite /= F1. Qed. -End pointed. -Arguments hom_repr /. -Arguments repr_hom /. - -Lemma hom_repr_natural_subproof : IsNatural _ _ _ _ hom_repr. -Proof. -split=> a b f /=; apply/funext => n /=; rewrite !Ucompx/= compo1/=. -by rewrite -naturalU/=; congr (n _ _); apply/esym/comp1o. -Qed. -HB.instance Definition _ := hom_repr_natural_subproof. - -(* show this from the previous proof *) -Lemma hom_natural_repr_subproof : IsNatural _ _ _ _ repr_hom_nat. -Proof. -split=> a b f /=; apply: funext => fa /=; rewrite !Ucompx/=. -apply: natP; apply: funext => c /=; apply: funext => d /=. -by rewrite Fcomp Ucompx/=. -Qed. -HB.instance Definition _ := hom_natural_repr_subproof. - -Definition hom_repr_nat : homF ~~> F := hom_repr. -Definition repr_hom_nat_nat : F ~~> homF := repr_hom_nat. - -End hom_repr. - -(* comma categories *) -Module comma. -Section homcomma. -Context {C D E : precat} (F : C ~> E) (G : D ~> E). - -Definition type := { x : C * D & F x.1 ~> G x.2 }. -Definition hom_subdef (a b : type) := { - f : tag a ~> tag b & F <$> f.1 \; tagged b = tagged a \; G <$> f.2 - }. -HB.instance Definition _ := IsQuiver.Build type hom_subdef. -End homcomma. -Arguments hom_subdef /. -Section comma. -Context {C D E : cat} (F : C ~> E) (G : D ~> E). -Notation type := (type F G). - -Program Definition idmap_subdef (a : type) : a ~> a := @Tagged _ idmap _ _. -Next Obligation. by rewrite !F1 comp1o compo1. Qed. -Program Definition comp_subdef (a b c : type) - (f : a ~> b) (g : b ~> c) : a ~> c := - @Tagged _ (tag f \; tag g) _ _. -Next Obligation. by rewrite !Fcomp -compoA (tagged g) compoA (tagged f) compoA. Qed. -HB.instance Definition _ := IsPreCat.Build type idmap_subdef comp_subdef. -Arguments idmap_subdef /. -Arguments comp_subdef /. - -Lemma comma_homeqP (a b : type) (f g : a ~> b) : projT1 f = projT1 g -> f = g. -Proof. -case: f g => [f fP] [g +]/= eqfg; case: _ / eqfg => gP. -by congr existT; apply: Prop_irrelevance. -Qed. - -Lemma comma_is_cat : PreCat_IsCat type. -Proof. -by split=> [[a fa] [b fb] [*]|[a fa] [b fb] [*]|*]; - apply/comma_homeqP; rewrite /= ?(comp1o, compo1, compoA). -Qed. -HB.instance Definition _ := comma_is_cat. -End comma. -End comma. -Notation "F `/` G" := (@comma.type _ _ _ F G) - (at level 40, G at level 40, format "F `/` G") : cat_scope. -Notation "a /` G" := (cst unit a `/` G) - (at level 40, G at level 40, format "a /` G") : cat_scope. -Notation "F `/ b" := (F `/` cst unit b) - (at level 40, b at level 40, format "F `/ b") : cat_scope. -Notation "a / b" := (cst unit a `/ b) : cat_scope. - -Definition obj (C : quiver) : Type := C. -HB.mixin Record IsInitial {C : quiver} (i : obj C) := { - to : forall c, i ~> c; - to_unique : forall c (f : i ~> c), f = to c -}. -#[short(type="initial")] -HB.structure Definition Initial {C : quiver} := {i of IsInitial C i}. - -HB.mixin Record IsTerminal {C : quiver} (t : obj C) := { - from : forall c, c ~> t; - from_unique : forall c (f : c ~> t), f = from c -}. -#[short(type="terminal")] -HB.structure Definition Terminal {C : quiver} := {t of IsTerminal C t}. -#[short(type="universal")] -HB.structure Definition Universal {C : quiver} := - {u of Initial C u & Terminal C u}. - -(* Definition hom' {C : precat} (a b : C) := a ~> b. *) -(* (* Bug *) *) -(* Identity Coercion hom'_hom : hom' >-> hom. *) - -(* HB.mixin Record IsMono {C : precat} (b c : C) (f : hom b c) := { *) -(* monoP : forall (a : C) (g1 g2 : a ~> b), g1 \; f = g2 \; f -> g1 = g2 *) -(* }. *) -(* #[short(type="mono")] *) -(* HB.structure Definition Mono {C : precat} (a b : C) := {m of IsMono C a b m}. *) -(* Notation "a >~> b" := (mono a b) *) -(* (at level 99, b at level 200, format "a >~> b") : cat_scope. *) -(* Notation "C >~>_ T D" := (@mono T C D) *) -(* (at level 99, T at level 0, only parsing) : cat_scope. *) - -(* HB.mixin Record IsEpi {C : precat} (a b : C) (f : hom a b) := { *) -(* epiP : forall (c : C) (g1 g2 : b ~> c), g1 \o f = g2 \o f -> g1 = g2 *) -(* }. *) -(* #[short(type="epi")] *) -(* HB.structure Definition Epi {C : precat} (a b : C) := {e of IsEpi C a b e}. *) -(* Notation "a ~>> b" := (epi a b) *) -(* (at level 99, b at level 200, format "a ~>> b") : cat_scope. *) -(* Notation "C ~>>_ T D" := (@epi T C D) *) -(* (at level 99, T at level 0, only parsing) : cat_scope. *) - -(* #[short(type="iso")] *) -(* HB.structure Definition Iso {C : precat} (a b : C) := *) -(* {i of @Mono C a b i & @Epi C a b i}. *) -(* Notation "a <~> b" := (epi a b) *) -(* (at level 99, b at level 200, format "a <~> b") : cat_scope. *) -(* Notation "C <~>_ T D" := (@epi T C D) *) -(* (at level 99, T at level 0, only parsing) : cat_scope. *) - -HB.mixin Record IsRightAdjoint (D C : precat) (R : D -> C) - of @PreFunctor D C R := { - L_ : C ~> D; - phi : forall c d, (L_ c ~> d) -> (c ~> R d); - psy : forall c d, (c ~> R d) -> (L_ c ~> d); - phi_psy c d : (phi c d \o psy c d)%FUN = @id (c ~> R d); - psy_phi c d : (psy c d \o phi c d)%FUN = @id (L_ c ~> d) -}. -#[short(type="right_adjoint")] -HB.structure Definition RightAdjoint (D C : precat) := - { R of @Functor D C R & IsRightAdjoint D C R }. -Arguments L_ {_ _}. -Arguments phi {D C s} {c d}. -Arguments psy {D C s} {c d}. - - -HB.mixin Record PreCat_IsMonoidal C of PreCat C := { - onec : C; - (* prod1 : @hom precat (C * C)%type C ; *) - prod : (C * C)%type ~>_precat C; -}. -#[short(type="premonoidal")] -#[verbose] -HB.structure Definition PreMonoidal := { C of PreCat C & PreCat_IsMonoidal C }. -Notation premonoidal := premonoidal. -Arguments prod {C} : rename. -Notation "a * b" := (prod (a, b)) : cat_scope. -Reserved Notation "f <*> g" (at level 40, g at level 40, format "f <*> g"). -Notation "f <*> g" := (prod^$ (f, g)) (only printing) : cat_scope. -Notation "f <*> g" := (prod^$ ((f, g) : (_, _) ~> (_, _))) - (only parsing) : cat_scope. -Notation "1" := onec : cat_scope. - -Definition hom_cast {C : quiver} {a a' : C} (eqa : a = a') {b b' : C} (eqb : b = b') : - (a ~> b) -> (a' ~> b'). -Proof. now elim: _ / eqa; elim: _ / eqb. Defined. - -HB.mixin Record PreFunctor_IsMonoidal (C D : premonoidal) F of - @PreFunctor C D F := { - fun_one : F 1 = 1; - fun_prod : forall (x y : C), F (x * y) = F x * F y; -}. -#[short(type="monoidal_prefunctor")] -HB.structure Definition MonoidalPreFunctor C D := - { F of @PreFunctor_IsMonoidal C D F }. -Arguments fun_prod {C D F x y} : rename. -(* Arguments fun_prodF {C D F x x'} f {y y'} g : rename. *) -Unset Universe Checking. -HB.instance Definition _ := IsQuiver.Build premonoidal MonoidalPreFunctor.type. -Set Universe Checking. - -HB.instance Definition _ (C : quiver) := - IsPreFunctor.Build (C * C)%type C fst - (fun (a b : C * C) (f : a ~> b) => f.1). -HB.instance Definition _ (C : quiver) := - IsPreFunctor.Build (C * C)%type C snd - (fun (a b : C * C) (f : a ~> b) => f.2). - -Definition prod3l {C : premonoidal} (x : C * C * C) : C := - (x.1.1 * x.1.2) * x.2. -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build _ C prod3l - (fun a b (f : a ~> b) => (f.1.1 <*> f.1.2) <*> f.2). - -Definition prod3r {C : premonoidal} (x : C * C * C) : C := - x.1.1 * (x.1.2 * x.2). -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build _ C prod3r - (fun a b (f : a ~> b) => f.1.1 <*> (f.1.2 <*> f.2)). - -Definition prod1r {C : premonoidal} (x : C) : C := 1 * x. -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build C C prod1r - (fun (a b : C) (f : a ~> b) => \idmap_1 <*> f). - -Definition prod1l {C : premonoidal} (x : C) : C := x * 1. -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build C C prod1l - (fun (a b : C) (f : a ~> b) => f <*> \idmap_1). - -HB.mixin Record PreMonoidal_IsMonoidal C of PreMonoidal C := { - prodA : prod3l ~~> prod3r; - prod1c : prod1r ~~> idfun; - prodc1 : prod1l ~~> idfun; - prodc1c : forall (x y : C), - prodA (x, 1, y) \; \idmap_x <*> prod1c y = prodc1 x <*> \idmap_y; - prodA4 : forall (w x y z : C), - prodA (w * x, y, z) \; prodA (w, x, y * z) = - prodA (w, x, y) <*> \idmap_z \; prodA (w, x * y, z) \; \idmap_w <*> prodA (x, y, z); -}. - -Unset Universe Checking. -#[short(type="monoidal")] -#[verbose] -HB.structure Definition Monoidal : Set := - { C of PreMonoidal_IsMonoidal C & PreMonoidal C }. -Set Universe Checking. - -(******************************************************************) - - -Record cospan (Q : quiver) (A B : Q) := Cospan { - top : Q; - left2top : A ~> top; - right2top : B ~> top -}. - -Section cospans. -Variables (Q : precat) (A B : Q). -Record cospan_map (c c' : cospan A B) := CospanMap { - top_map : top c ~> top c'; - left2top_map : left2top c \; top_map = left2top c'; - right2top_map : right2top c \; top_map = right2top c'; -}. -HB.instance Definition _ := IsQuiver.Build (cospan A B) cospan_map. - -Lemma cospan_mapP (c c' : cospan A B) (f g : c ~> c') : - top_map f = top_map g <-> f = g. -Admitted. -End cospans. - -Section cospans_in_cat. -Variables (Q : cat) (A B : Q). -Definition cospan_idmap (c : cospan A B) := - @CospanMap Q A B c c idmap (compo1 _) (compo1 _). -Program Definition cospan_comp (c1 c2 c3 : cospan A B) - (f12 : c1 ~> c2) (f23 : c2 ~> c3) := - @CospanMap Q A B c1 c3 (top_map f12 \; top_map f23) _ _. -Next Obligation. by rewrite compoA !left2top_map. Qed. -Next Obligation. by rewrite compoA !right2top_map. Qed. -HB.instance Definition _ := IsPreCat.Build (cospan A B) cospan_idmap cospan_comp. - -Lemma cospan_are_cats : PreCat_IsCat (cospan A B). -Proof. -constructor=> [a b f|a b f|a b c d f g h]. -- by apply/cospan_mapP => /=; rewrite comp1o. -- by apply/cospan_mapP => /=; rewrite compo1. -- by apply/cospan_mapP => /=; rewrite compoA. -Qed. -HB.instance Definition _ := cospan_are_cats. -End cospans_in_cat. - -Section spans_and_co. -Variables (Q : quiver) (A B : Q). -Definition span := @cospan Q^op A B. -Definition bot (s : span) : Q := top s. -Definition bot2left (s : span) : bot s ~>_Q A := left2top s. -Definition bot2right (s : span) : bot s ~>_Q B := right2top s. -Definition Span (C : Q) (f : C ~> A) (g : C ~> B) : span := - @Cospan Q^op A B C f g. -End spans_and_co. - -HB.instance Definition _ (Q : precat) (A B : Q) := - Quiver.copy (span A B) (@cospan Q^op A B)^op. -HB.instance Definition _ (Q : cat) (A B : Q) := - Cat.copy (span A B) (@cospan Q^op A B)^op. - -Section bot_map. -Variables (C : cat) (A B : C) (s s' : span A B) (f : s ~> s'). -Definition bot_map : bot s ~> bot s' := top_map f. -Lemma bot2left_map : bot_map \; bot2left s' = bot2left s. -Proof. exact: left2top_map f. Qed. -Lemma bot2right_map : bot_map \; bot2right s' = bot2right s. -Proof. exact: right2top_map f. Qed. -End bot_map. - -HB.mixin Record isPrePullback (Q : precat) (A B : Q) - (c : cospan A B) (s : span A B) := { - is_square : bot2left s \; left2top c = bot2right s \; right2top c; -}. -#[short(type=prepullback)] -HB.structure Definition PrePullback Q A B (c : cospan A B) := - {s of isPrePullback Q A B c s}. -Arguments prepullback {Q A B} c. - -Section prepullback. -Variables (Q : precat) (A B : Q) (c : cospan A B). -HB.instance Definition _ := - IsQuiver.Build (prepullback c) - (fun a b => (a : span A B) ~>_(span A B) (b : span A B)). -Lemma eq_prepullbackP (p q : prepullback c) : - p = q :> span _ _ <-> p = q. -Admitted. -End prepullback. -Section prepullback. -Variables (Q : cat) (A B : Q) (csp : cospan A B). -(* TODO: why can't we do that? *) -(* HB.instance Definition _ := Cat.on (prepullback csp). *) -HB.instance Definition _ := - Quiver_IsPreCat.Build (prepullback csp) - (fun a => \idmap_(a : span A B)) - (* TODO: study how to make this coercion trigger - even when the target is not reduced to span *) - (fun a b c f g => f \; g). -Lemma prepullback_is_cat : PreCat_IsCat (prepullback csp). -Proof. (* should be copied from the cat on span *) -constructor=> [a b f|a b f|a b c d f g h]; - [exact: comp1o|exact: compo1|exact: compoA]. -Qed. -End prepullback. - -HB.tag Definition pb_terminal (Q : precat) - (A B : Q) (c : cospan A B) (s : prepullback c) : - obj (prepullback c) := s. - -#[wrapper] -HB.mixin Record prepullback_isTerminal (Q : precat) - (A B : Q) (c : cospan A B) - (s : span A B) of isPrePullback Q A B c s := { - prepullback_terminal : - IsTerminal (prepullback c) (pb_terminal s) -}. -#[short(type="pullback"), verbose] -HB.structure Definition Pullback (Q : precat) - (A B : Q) (c : cospan A B) := - {s of isPrePullback Q A B c s - & IsTerminal (prepullback c) (pb_terminal s) }. - -Notation pbsquare u v f g := - (Pullback _ (Cospan f g) (Span u v)). - -Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). - -(******************************************************************) - -(*** ENRICHED CATEGORIES *) - -Declare Scope encat_scope. -Delimit Scope encat_scope with encat. -Local Open Scope encat_scope. - -(* Enrichment in a monoidal category, following - https://ncatlab.org/nlab/show/enriched+category -*) -HB.mixin Record IsEnQuiver (V: Type) C := { - hom_object : C -> C -> V - }. -Unset Universe Checking. -HB.structure Definition EnQuiver (V: Type) : Set := - { C of IsEnQuiver V C }. -Set Universe Checking. - -(* Monoidal precategory with the enrichment operators (no axioms) *) -HB.mixin Record IsEnPreCat (V: PreMonoidal.type) C of - EnQuiver (PreMonoidal.sort V) C := { - id_element : forall (a: C), - @hom V onec (hom_object a a) ; - comp_morphism : forall (a b c: C), - @hom V (@hom_object V C b c * @hom_object V C a b) - (@hom_object V C a c) -}. -Unset Universe Checking. -HB.structure Definition EnPreCat (V: PreMonoidal.type) : Set := - { C of IsEnPreCat V C }. -Set Universe Checking. - -Notation "a ~^ b" := (hom_object a b) - (at level 99, b at level 200, format "a ~^ b") : encat_scope. -Notation "a ~^_ ( V , C ) b" := (@hom_object V C a b) - (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. -Notation "~^IE a" := (id_element a) - (at level 99, format "~^IE a") : cat_scope. -Notation "~^IE_ ( V , C ) a" := (@id_element V C a) - (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. -(* not working *) -Notation "~^CM a b c" := (comp_morphism a b c) - (at level 99, - format "~^CM a b c") : cat_scope. -Notation "~^CM_ ( V , C ) a b c" := (@comp_morphism V C a b c) - (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. - -(* V-enriched category: - V is the monoidal category; - C is the base category that gets enriched -*) -HB.mixin Record IsEnCat (V: Monoidal.type) C of EnPreCat V C := { - ecat_comp_assoc : forall a b c d: C, - forall alpha: - (((c ~^_(V,C) d) * (b ~^_(V,C) c)) * (a ~^_(V,C) b)) ~>_V - ((c ~^_(V,C) d) * ((b ~^_(V,C) c) * (a ~^_(V,C) b))), - ((@comp_morphism V C b c d) <*> (@idmap V (a ~^_(V,C) b))) \; - (@comp_morphism V C a b d) - = - alpha \; - ((@idmap V (c ~^_(V,C) d)) <*> (@comp_morphism V C a b c)) \; - (@comp_morphism V C a c d) ; - - ecat_comp_left_unital : forall a b: C, - forall l: onec * (a ~^_(V,C) b) ~>_V (a ~^_(V,C) b), - l = ((@id_element V C b) <*> (@idmap V (a ~^_(V,C) b))) \; - (@comp_morphism V C a b b) ; - ecat_comp_right_unital : forall a b: C, - forall r: (a ~^_(V,C) b) * onec ~>_V (a ~^_(V,C) b), - r = ((@idmap V (a ~^_(V,C) b)) <*> (@id_element V C a)) \; - (@comp_morphism V C a a b) -}. -Unset Universe Checking. -#[verbose] -HB.structure Definition EnCat (V: Monoidal.type) : Set := { C of IsEnCat V C }. -Set Universe Checking. - - - -(*** DOUBLE CATEGORIES (REVISED) *) - -(* A quiver from which horizontal morphisms arise (just a copy of quiver) *) -HB.mixin Record IsHQuiver C := { - hhom : C -> C -> U - }. -Unset Universe Checking. -#[short(type="hquiver")] -HB.structure Definition HQuiver : Set := { C of IsHQuiver C }. -Set Universe Checking. - -(* domain-specific sigma-type to represent the set of morphims - (needed for 2-objects, i.e. horizontal morphisms) *) -Record Total2 T (h: T -> T -> U) : Type := HO { - source : T; - target : T; - this_morph : h source target }. - -(* the set of horizontal morphisms. - HB.tag needed to identify HHomSet as lifter *) -HB.tag Definition HHomSet (C: hquiver) := Total2 (@hhom C). - -(* source functor (for horizontal morphisms): D1 -> D0. - defined as object-level function, by functoriality lifted to a - (2-cell, vertical) morphism-level one *) -HB.tag Definition HSource C := fun (X: HHomSet C) => @source C (@hhom C) X. -(* target functor (for horizontal morphisms): D1 -> D0. *) -HB.tag Definition HTarget C := fun (X: HHomSet C) => @target C (@hhom C) X. - -(* D1 quiver requirement. *) -#[wrapper] -HB.mixin Record IsD1Quiver T of HQuiver T := { - d1_quiver : IsQuiver (@HHomSet T) }. -Unset Universe Checking. -#[short(type="d1quiver")] -HB.structure Definition D1Quiver : Set := { C of IsD1Quiver C }. -Set Universe Checking. - -(* all the quivers required by a double category *) -Unset Universe Checking. -#[short(type="dquiver")] -HB.structure Definition DQuiver : Set := - { C of Quiver C & HQuiver C & IsD1Quiver C }. -Set Universe Checking. - -(* used to define composable pairs of morphisms as a set *) -Record GenComp T (h: T -> T -> U) := GC { - c_one : T; - c_two : T ; - c_three : T; - c_first : h c_one c_two ; - c_second : h c_two c_three -}. - -(* composable pairs of horizontal morphisms as a set *) -HB.tag Definition HComp (C: hquiver) := GenComp (@hhom C). - -(* -(* pullback category condition (i.e. (HComp T) is a category). - requires T to be a category, and (HHomSet T) to be a quiver *) -#[wrapper] -HB.mixin Record IsHCompCat T of Cat T & DQuiver T := { - hcompcat : Cat (HComp T) }. -Unset Universe Checking. -#[short(type="hcompcat")] -HB.structure Definition HCompCat : Set := { C of IsHCompCat C }. -Set Universe Checking. -*) - -(* c2unit - horizontal unit functor. - - c2comp - horizontal composition functor. - - Both specified as object-level functions, to be lifted by - functoriality to morphism-level ones. - - At the object level, c2unit gives a horizontal identity morphism - for each D0 object. At the morphism level, it gives horizontal - 2-cell identity for each vertical morphism. - - In the case of HComp, relying on functoriality requires some care - in defining the pullback category, making sure that adjacency at - the object-level (between horizontal morphisms) is matched by - adjacency at the morphism-level (between 2-cells). *) -HB.mixin Record IsC2Quiver T of DQuiver T (* & HCompCat T *) := { - h2unit : forall a: T, @hhom T a a ; - h2comp : forall (a b c: T), - @hhom T a b -> @hhom T b c -> @hhom T a c; - - c2unit : T -> HHomSet T ; - c2comp : HComp T -> HHomSet T ; - - c2unit_eq : forall a: T, c2unit a = @HO T (@hhom T) a a (h2unit a) ; - c2comp_eq1 : forall (a b c: T) (h1: @hhom T a b) (h2: @hhom T b c), - c2comp (@GC T (@hhom T) a b c h1 h2) = - @HO T (@hhom T) a c (h2comp a b c h1 h2) -}. -Unset Universe Checking. -#[short(type="c2quiver")] -HB.structure Definition C2Quiver : Set := { C of IsC2Quiver C }. -Set Universe Checking. - -(* Precategory based on the DQuiver (i.e. precategory D1) - only, - instead of making it inherit from D1Quiver, we make it inherit from - DQuiver. DOES NOT WORK WITH C2Quiver. Gives: - vertical 2-cell identity morphism. - vertical 2-cell composition. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsC2PreCat T of C2Quiver T := { - c2precat : Quiver_IsPreCat (@HHomSet T) }. -#[short(type="c2precat")] -HB.structure Definition C2PreCat : Set := { C of IsC2PreCat C }. -Set Universe Checking. - -(* The category based on the DQuiver (i.e. category D1). *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsC2Cat T of C2PreCat T := { - c2cat : PreCat_IsCat (@HHomSet T) }. -#[short(type="h2cat")] -HB.structure Definition C2Cat : Set := { C of IsC2Cat C }. -Set Universe Checking. - -(* unit functor: D0 -> D1 *) -HB.tag Definition UnitF (C: c2quiver) := - fun (x: C2Quiver.sort C) => @c2unit C x. -(* composition functor: D1 * D1 -> D1 *) -HB.tag Definition CompF (C: c2quiver) := - fun (x: HComp C) => @c2comp C x. - -(* source prefunctor. - HHomSet T is the quiver of the 2-morphisms, thanks to H2Quiver. - T is the quiver of 1-morphisms. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsHSPreFunctor T of Cat T & C2Cat T (* & HCompCat T *) := { - h2s_prefunctor : IsPreFunctor (HHomSet T) T (@HSource T) }. -HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. -Set Universe Checking. - -(* target prefunctor. *) -Unset Universe Checking. -#[wrapper] - HB.mixin Record IsHTPreFunctor T of HSPreFunctor T := { - h2t_prefunctor : IsPreFunctor (HHomSet T) T (@HTarget T) }. -HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. -Set Universe Checking. - -(* source functor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record HSPreFunctor_IsFunctor T of HTPreFunctor T := { - h2s_functor : PreFunctor_IsFunctor (HHomSet T) T (@HSource T) }. -HB.structure Definition HSFunctor : Set := {C of HSPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* target functor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record HTPreFunctor_IsFunctor T of HSFunctor T := { - h2t_functor : PreFunctor_IsFunctor (HHomSet T) T (@HTarget T) }. -HB.structure Definition HTFunctor : Set := {C of HTPreFunctor_IsFunctor C}. -Set Universe Checking. - -(** HComp quiver *) -Definition HComp_hom (T: HTFunctor.type) := - (fun (A B: HComp T) => match (A, B) with - | (@GC _ _ a1 b1 c1 h1 k1, @GC _ _ a2 b2 c2 h2 k2) => - let h1' := @HO T (@hhom T) a1 b1 h1 - in let k1' := @HO T (@hhom T) b1 c1 k1 - in let h2' := @HO T (@hhom T) a2 b2 h2 - in let k2' := @HO T (@hhom T) b2 c2 k2 - in sigT (fun (hh: @hom (HHomSet T) h1' h2') => - (sigT (fun (kk: @hom (HHomSet T) k1' k2') => - @Fhom _ _ (@HTarget T) h1' h2' hh = - @Fhom _ _ (@HSource T) k1' k2' kk))) - end). - -HB.instance Definition HCompQuiver (T: HTFunctor.type) : IsQuiver (HComp T) := - IsQuiver.Build (HComp T) (fun A B => @HComp_hom T A B). - - -Program Definition HCompPreCat (T: HTFunctor.type) : - Quiver_IsPreCat (HComp T) := - Quiver_IsPreCat.Build (HComp T) - (fun x: HComp T => _) (fun a b c: HComp T => _). -Obligation 1. -Admitted. -Obligation 2. -Admitted. - - -Definition HCompId (T: HTFunctor.type) : forall A: HComp T, HComp_hom A A := - fun A => match A with - | @GC _ _ a b c h k => - let h' := @HO T (@hhom T) a b h - in let k' := @HO T (@hhom T) b c k - in existT (idmap (HHomSet T) h') - (existT (idmap (HHomSet T) k') ) - - - -(* unit prefunctor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsHUPreFunctor T of C2Quiver T & HTFunctor T := - { h2u_prefunctor : IsPreFunctor T (HHomSet T) (@UnitF T) }. -HB.structure Definition HUPreFunctor : Set := {C of IsHUPreFunctor C}. -Set Universe Checking. - -(* unit functor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record HUPreFunctor_IsFunctor T of HUPreFunctor T := { - h2u_functor : PreFunctor_IsFunctor T (HHomSet T) (@UnitF T) }. -HB.structure Definition HUFunctor : Set := {C of HUPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* composition prefunctor *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsHCPreFunctor T of HUFunctor T := - { h2c_prefunctor : IsPreFunctor (HComp T) (HHomSet T) (@CompF T) }. -HB.structure Definition HCPreFunctor : Set := {C of IsHCPreFunctor C}. -Set Universe Checking. - -(* composition functor *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record HCPreFunctor_IsFunctor T of HCPreFunctor T := { - h2c_functor : PreFunctor_IsFunctor (HComp T) (HHomSet T) (@CompF T) }. -HB.structure Definition HCFunctor : Set := {C of HCPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* 2-morphisms *) -Definition c2hom (D: C2Quiver.type) := @hom (@HHomSet D). - -(* The set of D1 morphisms *) -HB.tag Definition C2HomSet (C: C2Quiver.type) := Total2 (@c2hom C). - -(* horizontal 2-cell unit (maps vertical morphisms to horizontally - unitary 2-cells) *) -Definition HC2Unit (T: HUFunctor.type) (a b: T) (m: @hom T a b) : - c2hom (UnitF a) (UnitF b) := @Fhom _ _ (@UnitF T) a b m. - -(* horizontal 2-cell composition: maps two adjecent pairs of - horizontal morphisms (a and b) and a pullback-category morphism - between them (m, which basically gives two adjecent cells) to a - 2-cell morphism between the horizontal composition (CompF) of each - pair *) -Definition HC2Comp (T: HCFunctor.type) (a b: HComp T) - (m: @hom (HComp T) a b) : - c2hom (CompF a) (CompF b) := @Fhom _ _ (@CompF T) a b m. - -(* Double category complete with properties of horizontal 2-cell - identity and composition *) -Unset Universe Checking. -HB.mixin Record IsDCat T of HCFunctor T := { - left_unital : forall (a0 a1 b0 b1: T) - (r: @hhom T a0 a1) (s: @hhom T b0 b1), - let rr := @HO T (@hhom T) a0 a1 r in - let ss := @HO T (@hhom T) b0 b1 s in - let aa := @h2unit T a0 in - let bb := @h2unit T b0 in - @hom (HHomSet T) rr ss = - @hom (HHomSet T) (c2comp (@GC T _ a0 a0 a1 aa r)) - (c2comp (@GC T _ b0 b0 b1 bb s)) ; - - right_unital : forall (a0 a1 b0 b1: T) - (r: @hhom T a0 a1) (s: @hhom T b0 b1), - let rr := @HO T (@hhom T) a0 a1 r in - let ss := @HO T (@hhom T) b0 b1 s in - let aa := @h2unit T a1 in - let bb := @h2unit T b1 in - @hom (HHomSet T) rr ss = - @hom (HHomSet T) (c2comp (@GC T _ a0 a1 a1 r aa)) - (c2comp (@GC T _ b0 b1 b1 s bb)) ; - - associator : forall (a0 a1 a2 a3: T) - (h1: @hhom T a0 a1) (h2: @hhom T a1 a2) - (h3: @hhom T a2 a3) (x: HHomSet T), - let h23 := h2comp a1 a2 a3 h2 h3 in - let h12 := h2comp a0 a1 a2 h1 h2 in - let hh1 := h2comp a0 a1 a3 h1 h23 in - let hh2 := h2comp a0 a2 a3 h12 h3 in - @hom (HHomSet T) (@HO T (@hhom T) a0 a3 hh1) x = - @hom (HHomSet T) (@HO T (@hhom T) a0 a3 hh2) x -}. -#[short(type="dcat")] -HB.structure Definition DCat : Set := { C of IsDCat C }. -Set Universe Checking. - - - -(*********************************************************************) -(**** GARBAGE ****************************************************) - -(* Double category *) -Unset Universe Checking. -HB.mixin Record IsDCat T of HCFunctor T := { - left_unital : forall (a b: T) (r: @hhom T a b), - let rr := @HO T (@hhom T) a b r in - let aa := @h2unit T a in - @hom (HHomSet T) (c2comp (@GC T _ a a b aa r)) rr ; - - right_unital : forall (a b: T) (r: @hhom T a b), - let rr := @HO T (@hhom T) a b r in - let bb := @h2unit T b in - @hom (HHomSet T) (c2comp (@GC T _ a b b r bb)) rr ; -}. - -(* Double category *) -Unset Universe Checking. -HB.mixin Record IsDCat T of HCFunctor T := { - left_unital : forall (a b c d: T) (r: @hhom T a c) (s: @hhom T b d), - forall (ha: @hhom T a a) (hb: @hhom T b b), - @hom (HHomSet T) (@HO T (@hhom T) a c r) (@HO T (@hhom T) b d s) = - @hom (HHomSet T) (c2comp (@GC T _ a a c ha r)) - (c2comp (@GC T _ b b d hb s)) ; - - right_unital : forall (a b c d: T) (r: @hhom T a c) (s: @hhom T b d), - forall (ha: @hhom T c c) (hb: @hhom T d d), - @hom (HHomSet T) (@HO T (@hhom T) a c r) (@HO T (@hhom T) b d s) = - @hom (HHomSet T) (c2comp (@GC T _ a c c r ha)) - (c2comp (@GC T _ b d d s hb)) ; - - associator : forall (a0 a1 a2 a3: T) - (h1: @hhom T a0 a1) (h2: @hhom T a1 a2) - (h3: @hhom T a2 a3), - forall (h12: @hhom T a0 a2) (h23: @hhom T a1 a3) (x: HHomSet T), - @HO T (@hhom T) a1 a3 h23 = c2comp (@GC T _ a1 a2 a3 h2 h3) -> - @HO T (@hhom T) a0 a2 h12 = c2comp (@GC T _ a0 a1 a2 h1 h2) -> - let hh1 := c2comp (@GC T _ a0 a1 a3 h1 h23) in - let hh2 := c2comp (@GC T _ a0 a2 a3 h12 h3) in - @hom (HHomSet T) hh1 x = @hom (HHomSet T) hh2 x -}. -#[short(type="dcat")] -HB.structure Definition DCat : Set := { C of IsDCat C }. -Set Universe Checking. - - -(* a sequence of two adjacent morphisms (pullback object), - which we can use to represent composition *) -Record GenComp' T (h: T -> T -> U) := GCmp { - comp_first : @Total2 T h ; - comp_second : @Total2 T h ; - comp_adjacent : target comp_first = source comp_second -}. -(* horizontal morphism composition type. ultimately though, SHOULD - DEPEND ON D0 (hence on 'Quiver T' and 'Quiver (T * T)) *) -Definition HComp' (C: hquiver) := GenComp' (@hhom C). - - -(* source prefunctor. - HHomSet T is the quiver of the 2-morphisms, thanks to H2Quiver. - T is the quiver of 1-morphisms. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsHSPreFunctor T of Cat T & H2Cat T := { - h2s_prefunctor : IsPreFunctor (HHomSet T) T (@Source T) }. -HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. -Set Universe Checking. - -(* target prefunctor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsHTPreFunctor T of Cat T & H2Cat T := { - h2t_prefunctor : IsPreFunctor (HHomSet T) T (@Target T) }. -HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. -Set Universe Checking. - - - -HB.mixin Record IsC2Quiver T of Quiver T & PreC2Quiver T := { - c2left : C2HomSet T -> VHomSet T ; - c2right : C2HomSet T -> VHomSet T ; - - c2unit : forall x:T, HHomSet T ; - - c2left_eq1 : forall d: C2HomSet T, - source (source d) = source (c2left d) ; - c2left_eq2 : forall d: C2HomSet T, - source (target d) = target (c2left d) ; - c2right_eq1 : forall d: C2HomSet T, - target (source d) = source (c2right d) ; - c2right_eq2 : forall d: C2HomSet T, - target (target d) = target (c2right d) ; - - c2unit_eq : forall a: T, - let h := c2unit a in source h = target h ; - -}. -Unset Universe Checking. -#[short(type="c2quiver")] -HB.structure Definition C2Quiver : Set := { C of IsC2Quiver C }. -Set Universe Checking. - -(* left edge functor: D1 -> D0 *) -HB.tag Definition C2Left (C: C2Quiver.type) := - fun (X: C2HomSet C) => @c2left C X. -(* right edge functor: D1 -> D0 *) -HB.tag Definition C2Right (C: C2Quiver.type) := - fun (X: C2HomSet C) => @c2right C X. - - - -(* we need horizontal morphisms to form at least a precategory *) -HB.mixin Record HQuiver_IsHPreCat C of HQuiver C := { - hidmap : forall (a : C), hhom a a; - hcomp : forall d : D1_prod C, - hhom (source (d1_first d)) (target (d1_second d)); -}. -Unset Universe Checking. -#[short(type="hprecat")] -HB.structure Definition HPreCat : Set := { C of HQuiver_IsHPreCat C }. -Set Universe Checking. - - -HB.mixin Record IsH2Grid T of Quiver T & H2Quiver T := { - h2left_edge : H2HomSet T -> VHomSet T ; - h2right_edge : H2HomSet T -> VHomSet T -}. -Unset Universe Checking. -#[short(type="h2grid")] -HB.structure Definition H2Grid : Set := { C of IsH2Grid C }. -Set Universe Checking. - -(* adding the map to define (1) the unit functor D0 -> D1 - and (2) composition D1 *d0 D1 -> D1 *) -HB.mixin Record IsH2FQuiver T of H2Quiver T & H2Grid T & PreCat T := { - h2unit_map: forall x:T, HHomSet T ; - h2unit_map_eq: forall x:T, h2unit_map x = - @HO T (@hhom T) x x (hidmap x) ; - h2comp_map: D1_prod T -> HHomSet T ; - h2comp_map_eq: forall d: D1_prod T, h2comp_map d = - @HO T (@hhom T) (source (d1_first d)) (target (d1_second d)) (hcomp d) -}. -Unset Universe Checking. -#[short(type="h2fquiver")] -HB.structure Definition H2FQuiver : Set := { C of IsH2FQuiver C }. -Set Universe Checking. - -(* Precat based on the H2Quiver (D1). *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2PreCat T of H2FQuiver T := { - h2precat : Quiver_IsPreCat (@HHomSet T) }. -#[short(type="h2precat")] -HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. -Set Universe Checking. - -(* The category based on the H2Quiver (D1). *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2Cat T of H2PreCat T := { - h2cat : PreCat_IsCat (@HHomSet T) }. -#[short(type="h2cat")] -HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. -Set Universe Checking. - -(* -Unset Universe Checking. -#[short(type="predcat")] -HB.structure Definition PreDCat : Set := { D of H2Cat D & H2Grid D }. -Set Universe Checking. -*) - -Record D2_prod T := { - d2_first : @H2HomSet T ; - d2_second : @H2HomSet T ; - d2_adjacent : target d2_first = source d2_second -}. - -(* probably not needed *) -HB.mixin Record HQuiver_IsH2PreCat' C of H2Grid C := { - h2idmap : forall (a : C), hhom a a; - h2comp : forall d : D2_prod C, - h2hom (source (d2_first d)) (target (d2_second d)); -}. -Unset Universe Checking. -#[short(type="hprecat")] -HB.structure Definition H2PreCat' : Set := { C of HQuiver_IsH2PreCat' C }. -Set Universe Checking. - - - -(* -(* gives left and right edges of a 2-cell (i.e. the vertical - morphisms associated with the 2-morphism). - these should be functors - *) -HB.mixin Record IsH2Grid T of Quiver T & H2Quiver T := { - h2left_edge : forall a b c d: T, - forall (h1: hhom a b) (h2: hhom c d), - @hom (@HHomSet T) (@HO T (@hhom T) a b h1) - (@HO T (@hhom T) c d h2) -> @hom T a c ; - h2right_edge : forall a b c d: T, - forall (h1: hhom a b) (h2: hhom c d), - @hom (@HHomSet T) (@HO T (@hhom T) a b h1) - (@HO T (@hhom T) c d h2) -> @hom T b d -}. -Unset Universe Checking. -#[short(type="h2grid")] -HB.structure Definition H2Grid : Set := { C of IsH2Grid C }. -Set Universe Checking. - -(* -(* adding the map to define (1) the unit functor D0 -> D1 - and (2) composition D1 *d0 D1 -> D1 *) -HB.mixin Record IsH2FQuiver T of H2Quiver T := { - h2unit_map: forall x:T, HHomSet T ; - h2unit_map_eq: forall x:T, h2unit_map x = - @HO T (@hhom T) x x (hidmap x) ; - h2comp_map: HHomSet T * HHomSet T -> HHomSet T ; - h2comp_map_eq: forall (a b c: T) (h1: hhom a b) (h2: hhom b c), - let x := @HO T (@hhom T) a b h1 - in let y := @HO T (@hhom T) b c h2 - in let z := @HO T (@hhom T) a c (hcomp a b c h1 h2) - in h2comp_map (x, y) = z }. -Unset Universe Checking. -#[short(type="h2fquiver")] -HB.structure Definition H2FQuiver : Set := { C of IsH2FQuiver C }. -Set Universe Checking. -*) -(* -(* adding the map to define the unit functor D0 -> D1 *) -HB.mixin Record IsH2FQuiver T of H2Quiver T := { - h2unit_map: forall x:T, HHomSet T ; - h2unit_map_eq: forall x:T, let y := h2unit_map x in - source y = target y ; - h2comp_map: HHomSet T * HHomSet T -> HHomSet T ; - h2comp_map_eq: forall x y: HHomSet T, target x = source y -> - exists f: hhom (source x) (target y), - h2comp_map (x, y) = @HO T (@hhom T) (source x) (target y) f ; -(* square_comp : forall (a1 b1 c1 a2 b2 c2: T), - forall (ha1: hhom a1 b1) (hb1: hhom b1 c1) - (ha2: hhom a2 b2) (hb2: hhom b2 c2), *) - }. -Unset Universe Checking. -#[short(type="h2fquiver")] -HB.structure Definition H2FQuiver : Set := { C of IsH2FQuiver C }. -Set Universe Checking. -*) - -(* Precat based on the H2Quiver (D1). *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2PreCat T of H2FQuiver T := { - h2precat : Quiver_IsPreCat (@HHomSet T) }. -#[short(type="h2precat")] -HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. -Set Universe Checking. - -(* The category based on the H2Quiver (D1). *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2Cat T of H2PreCat T := { - h2cat : PreCat_IsCat (@HHomSet T) }. -#[short(type="h2cat")] -HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. -Set Universe Checking. - -(* Pre-double category, with horizontal 2-cell composition *) -Unset Universe Checking. -HB.mixin Record IsPreDCat T of Cat T & H2Cat T & H2Grid T := { - h2adjacent : forall (a b c d e f: T), - forall (h1: hhom a b) (h2: hhom b c) (h3: hhom d e) (h4: hhom e f), - forall (hh1: @hom (@HHomSet T) (@HO T (@hhom T) a b h1) - (@HO T (@hhom T) d e h3)) - (hh2: @hom (@HHomSet T) (@HO T (@hhom T) b c h2) - (@HO T (@hhom T) e f h4)), - h2right_edge a b d e h1 h3 hh1 = - h2left_edge b c e f h2 h4 hh2 ; - - h2comp : forall (h1 h2 h3 h4: HHomSet T), - forall (hh1: h1 ~> h2) (hh2: h3 ~> h4), - h2comp_map (h1,h3) ~> h2comp_map (h2,h4) ; - -(* - h2comp_eq : forall (a b c d e f: T), - forall (h1: hhom a b) (h2: hhom b c) (h3: hhom d e) (h4: hhom e f), - forall (hh1: @hom (@HHomSet T) (@HO T (@hhom T) a b h1) - (@HO T (@hhom T) d e h3)) - (hh2: @hom (@HHomSet T) (@HO T (@hhom T) b c h2) - (@HO T (@hhom T) e f h4)), - h2adjacent a b c d e f h1 h2 hh1 hh2 -> - let h1' := (@HO T (@hhom T) a b h1) - in let h2' := (@HO T (@hhom T) b c h2) - in let h3' := (@HO T (@hhom T) d e h3) - in let h4' := (@HO T (@hhom T) e f h4) - h2comp h1' h2' h3' h4' hh1 hh2 = -*) - }. -#[short(type="predcat")] -HB.structure Definition PreDCat : Set := { D of IsPreDCat D }. -Set Universe Checking. - - -*) - -(* source functor: D1 -> D0 *) -HB.tag Definition Source C := fun (X: HHomSet C) => @source C (@hhom C) X. -(* target functor: D1 -> D0 *) -HB.tag Definition Target C := fun (X: HHomSet C) => @target C (@hhom C) X. -(* unit functor: D0 -> D1 *) -HB.tag Definition UnitF (C: h2fquiver) := - fun (x:H2FQuiver.sort C) => @h2unit_map C x. - -(* source prefunctor. - HHomSet T is the quiver of the 2-morphisms, thanks to H2Quiver. - T is the quiver of 1-morphisms. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsHSPreFunctor T of Cat T & H2Cat T := { - h2s_prefunctor : IsPreFunctor (HHomSet T) T (@Source T) }. -HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. -Set Universe Checking. - -(* target prefunctor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsHTPreFunctor T of Cat T & H2Cat T := { - h2t_prefunctor : IsPreFunctor (HHomSet T) T (@Target T) }. -HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. -Set Universe Checking. - - - -HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. -Set Universe Checking. - -(* source functor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record HSPreFunctor_IsFunctor T of Cat T & HSPreFunctor T := { - h2s_functor : PreFunctor_IsFunctor (HHomSet T) T (@Source T) }. -HB.structure Definition HSFunctor : Set := {C of HSPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* target functor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record HTPreFunctor_IsFunctor T of Cat T & HTPreFunctor T := { - h2t_functor : PreFunctor_IsFunctor (HHomSet T) T (@Target T) }. -HB.structure Definition HTFunctor : Set := {C of HTPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* unit prefunctor. *) -Unset Universe Checking. - #[wrapper] -HB.mixin Record IsHUPreFunctor T of Cat T & PreDCat T := { - h2u_prefunctor : IsPreFunctor T (HHomSet T) (@UnitF T) }. -HB.structure Definition HUPreFunctor : Set := {C of IsHUPreFunctor C}. -Set Universe Checking. - - -Unset Universe Checking. - #[wrapper] -HB.mixin Record HUPreFunctor_IsFunctor T of Cat T & HUPreFunctor T := { - h2u_functor : PreFunctor_IsFunctor T (HHomSet T) (@UnitF T) }. - HB.structure Definition HUFunctor : Set := {T of - Cat T & HUPreFunctor T & - PreFunctor_IsFunctor T (HHomSet T) (@UnitF T) - }. -Set Universe Checking. - - -Unset Universe Checking. - #[wrapper] -HB.mixin Record HUPreFunctor_IsFunctor T of Cat T & HUPreFunctor T := { - h2u_functor : PreFunctor_IsFunctor T (HHomSet T) (@UnitF T) }. -HB.structure Definition HUFunctor : Set := {C of HUPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* double category *) -Unset Universe Checking. -HB.structure Definition DCat : Set := - {D of HSPreFunctor_IsFunctor D & HTPreFunctor_IsFunctor D & - HUPreFunctor_IsFunctor D}. -Set Universe Checking. - -(* 2-morphisms *) -Definition h2hom (D: DCat.type) := @hom (@HHomSet D). - -(* still don't understand - transposition whould swap vertical and horizontal morphisms, - i.e. hom and hhom *) -Definition transpose1 (D: DCat.type) : U := D. -(* however, given transpose1 this should hold *) -Lemma hom_transpose (D: DCat.type) : @hom (transpose1 D) = @hhom D. -Admitted. -(* and this too *) -Lemma hhom_transpose (D: DCat.type) : @hhom (transpose1 D) = @hom D. -Admitted. - -(* tranposition as a relation *) -Definition isTranspose C - (FQ: PreDCat C -> Quiver C) - (FHQ: PreDCat C -> HQuiver C) - (D1 D2: PreDCat C) : Type := - @hom (Quiver.Pack (FQ D2)) = @hhom (HQuiver.Pack (FHQ D1)) /\ - @hhom (HQuiver.Pack (FHQ D2)) = @hom (Quiver.Pack (FQ D1)). - -Definition transpose_isquiver C (X: IsQuiver C) : IsHQuiver C. - destruct X. - econstructor. - exact hom0. -Defined. - -Definition transpose_ishquiver C (X: IsHQuiver C) : IsQuiver C. - destruct X. - econstructor. - exact hhom0. -Defined. - -Definition transpose_quiver C (X: Quiver C) : HQuiver C. - destruct X. - econstructor. - eapply transpose_isquiver; eauto. -Defined. - -Definition transpose_hquiver C (X: HQuiver C) : Quiver C. - destruct X. - econstructor. - eapply transpose_ishquiver; eauto. -Defined. - -(* tranposition as a relation, using the transpose functions *) -Definition isTransposeF C - (FQ: PreDCat C -> Quiver C) - (FHQ: PreDCat C -> HQuiver C) - (D1 D2: PreDCat C) : Type := - Quiver.Pack (FQ D2) = Quiver.Pack (@transpose_hquiver C (FHQ D1)) /\ - HQuiver.Pack (FHQ D2) = HQuiver.Pack (@transpose_quiver C (FQ D1)). - - - -(*** DOUBLE CATEGORIES (PREVIOUS) *) - -(* A quiver from which horizontal morphisms arise. D1 is the type of - D1 objects (horizontal morphisms in C), with source and target - functors. *) -HB.mixin Record HasD1 C := { - D1 : U ; - s10 : D1 -> C ; - t10 : D1 -> C }. -Unset Universe Checking. -#[short(type="hquiver")] -HB.structure Definition D1type : Set := { C of HasD1 C }. -Set Universe Checking. - -(* A quiver from which 2-morphisms arise as arrows between 2-objects - (i.e. horizontal morphisms) *) -#[wrapper] -HB.mixin Record IsH2Quiver T of HasD1 T := { - h2quiver : IsQuiver (@D1 T) }. -Unset Universe Checking. -#[short(type="h2quiver")] -HB.structure Definition H2Quiver : Set := { C of IsH2Quiver C }. -Set Universe Checking. - -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2PreCat T of H2Quiver T := { - h2precat : Quiver_IsPreCat (@D1 T) }. -#[short(type="h2precat")] -HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. -Set Universe Checking. - -(* The category based on the H2Quiver (D1). *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2Cat T of H2PreCat T := { - h2cat : PreCat_IsCat (@D1 T) }. -#[short(type="h2cat")] -#[verbose] -HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. -Set Universe Checking. - -(* Pre-double category (no functors yet): this corresponds to the old -definition *) -Unset Universe Checking. -HB.structure Definition PreDCat : Set := { D of Cat D & H2Cat D }. -Set Universe Checking. - -(* source prefunctor. - D1 here is the quiver of the 2-morphisms, thanks to IsH2Quiver. - T is the quiver of 1-morphisms. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsHSPreFunctor T of Cat T & H2Cat T := { - h2s_prefunctor : IsPreFunctor D1 T s10 }. -HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. -Set Universe Checking. - -(* target prefunctor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsHTPreFunctor T of Cat T & H2Cat T := { - h2t_prefunctor : IsPreFunctor D1 T t10 }. -HB.structure Definition HTPreFunctor : Set := {C of IsHTPreFunctor C}. -Set Universe Checking. - -(* source functor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record HSPreFunctor_IsFunctor T of Cat T & HSPreFunctor T := { - h2s_prefunctor : PreFunctor_IsFunctor D1 T s10 }. -HB.structure Definition HSFunctor : Set := {C of HSPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* target functor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record HTPreFunctor_IsFunctor T of Cat T & HTPreFunctor T := { - h2t_prefunctor : PreFunctor_IsFunctor D1 T t10 }. -HB.structure Definition HTFunctor : Set := {C of HTPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* double category *) -Unset Universe Checking. -HB.structure Definition DCat : Set := - {D of HSPreFunctor_IsFunctor D & HTPreFunctor_IsFunctor D }. -Set Universe Checking. - -(* 2-morphisms *) -Definition hhom (D: DCat.type) := @hom (@D1 D). - -Definition transpose (D: DCat.type) : U := D. - -Fail Lemma hom_transpose (D: DCat.type) : @hom (transpose D) = @hhom D. - -Fail Lemma hhom_transpose (D: DCat.type) : @hhom (transpose D) = @hom D. - - - -(*** DOUBLE CATEGORIES (OLD) *) - -(* A quiver from which horizontal morphisms arise (just a copy of quiver) *) -HB.mixin Record IsHQuiver C := { hhom : C -> C -> U }. -Unset Universe Checking. -#[short(type="hquiver")] -HB.structure Definition HQuiver : Set := { C of IsHQuiver C }. -Set Universe Checking. - -(* domain-specific sigma-type to represent the 2-objects *) -Record Total2 T (h: T -> T -> U) : Type := HO { - source : T; - target : T; - this_hom : h source target }. - -(* needed to identify HHomSet as lifter *) -HB.tag Definition HHomSet (C: hquiver) := Total2 (@hhom C). - -(* A quiver from which 2-morphisms arise as arrows between 2-objects - (i.e. horizontal morphisms) *) -#[wrapper] -HB.mixin Record IsH2Quiver T of HQuiver T := { - h2quiver : Quiver (@HHomSet T) }. -Unset Universe Checking. -#[short(type="h2quiver")] -HB.structure Definition H2Quiver : Set := { C of IsH2Quiver C }. -Set Universe Checking. - -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2PreCat T of HQuiver T & H2Quiver T := { - h2precat : Quiver_IsPreCat (@HHomSet T) }. -#[short(type="h2precat")] -HB.structure Definition H2PreCat : Set := { C of IsH2PreCat C }. -Set Universe Checking. - -(* The category based on the H2Quiver (D1). *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsH2Cat T of H2PreCat T := { - h2cat : PreCat_IsCat (@HHomSet T) }. -#[short(type="h2cat")] -HB.structure Definition H2Cat : Set := { C of IsH2Cat C }. -Set Universe Checking. - -(* Double categories, from - https://ncatlab.org/nlab/show/double+category - - The definition we follow here however is a comparatively informal - one, which also mentions internal categories (not formalized yet). - - Double category (D0, D1). - - base obejcts (D0): C ; - - vertical morphisms (D0): @hom C ; - - horizontal morhisms (and 2-objects, D1): @HHomSet C ; - - 2-morphisms (D1): @hom (@HHomSet C) *) -Unset Universe Checking. -#[short(type="dcat")] -HB.structure Definition DCat : Set := { C of Cat C & H2Cat C }. -Set Universe Checking. - - - -(*******************************************************************) - -(*** Related to BICATEGORIES (just an experiment, - not the right formalization) *) - -(* We want to factor constants and operators out of the axioms. - Suggestion: introduce some notion of module to bind them - together. *) - -(* monoid axioms *) -HB.mixin Record isMonoid T (mu: T) (mc: T -> T -> T): Type := { - massoc : associative mc; - mlid : left_id mu mc ; - mrid : right_id mu mc ; -}. - -(* to be used as homset identity in bicategories *) -HB.mixin Record isHId T := { - hid : T; -}. -HB.structure Definition HId := { T of isHId T }. - -(* to be used as homset composition in bicategories *) -HB.mixin Record isHComp T := { - hcomp : T -> T -> T; -}. -HB.structure Definition HComp := { T of isHComp T }. - -#[wrapper] -HB.mixin Record Quiver_HasId T of Quiver T := - { Quiver_HasId_private : forall A B, isHId (@hom T A B) }. -HB.structure Definition HasId := - { Obj of Quiver Obj & Quiver_HasId Obj }. - -#[wrapper] -HB.mixin Record Quiver_HasComp T of Quiver T := - { Quiver_HasComp_private : forall A B, isHComp (@hom T A B) }. -HB.structure Definition HasComp := - { Obj of Quiver Obj & Quiver_HasComp Obj }. - -(* a bicategory, without axioms *) -HB.structure Definition BiCatQuiver := - {T of Quiver_HasId T & Quiver_HasComp T}. - -#[wrapper] -HB.mixin Record isHMonoid T of HId T & HComp T := - { isHMonoid_private: isMonoid T (hid: T) (@hcomp T) }. -#[verbose] -HB.structure Definition HMonoid := { T of isHMonoid T }. - -#[wrapper] -(* does not work (generic Elpi error): - HB.mixin Record isHCat T of precat_quiver T := *) -HB.mixin Record isPreBiCategory T of IsPreCat T := - { isPreBiCategory_private : forall A B: T, HMonoid (@hom T A B) }. -HB.structure Definition PreBiCategory := - { Obj of isPreBiCategory Obj }. - -(* to be used as object monoid unit *) -HB.mixin Record isMUnit T := { - munit : T; -}. -HB.structure Definition MUnit := { T of isMUnit T }. - -(* to be used as object monoid composition *) -HB.mixin Record isMComp T := { - mcomp : T -> T -> T; -}. -HB.structure Definition MComp := { T of isMComp T }. - -(* has object monoid operators *) -HB.structure Definition Premonoid := - {T of isMUnit T & isMComp T}. - -(* the precategory has monoidal operators *) -HB.structure Definition Precat_IsPremonoidal := - {T of PreCat T & Premonoid T}. - -(* object monoid *) -HB.mixin Record isOMonoid T of isMUnit T & isMComp T := - { isHMonoid_private: isMonoid T (munit: T) (mcomp: T -> T -> T) }. -#[verbose] -HB.structure Definition OMonoid := { T of isOMonoid T }. - -(* some sort of monoidal category *) -HB.structure Definition PreMonBiCategory := - { Obj of PreBiCategory Obj & OMonoid Obj }. - - -(*******************************************************************) - -Section th_of_pb. -Variables (Q : cat) (A B C D E F : Q). -Variables (f : A ~> D) (g : B ~> D) (h : C ~> A). -Variables (u : E ~> A) (v : E ~> B) (w : F ~> C) (z : F ~> E). -Variable (uvfg : pbsquare u v f g). - -Set Printing Width 50. -Theorem pbsquarec_compP : - pbsquare w z h u <=> pbsquare w (z \; v) (h \; f) g. -Proof. -split=> [] sq. - - have @sq_ispb : pullback (Cospan h u) := HB.pack (Span w z) sq. - have @uvfg_ispb : pullback (Cospan f g) := HB.pack (Span u v) uvfg. - have /=E2 := @is_square _ _ _ _ sq_ispb. - have /=E1 := @is_square _ _ _ _ uvfg_ispb. - - have p1 : @isPrePullback Q C B (Cospan (h \; f) g) (Span w (z \; v)). - by constructor; rewrite /= compoA E2 -compoA E1 compoA. - pose big_black_square : prepullback (Cospan (h \; f) g) := - HB.pack (Span w (z \; v)) p1. - - have @from : forall - (big_red_square : prepullback {| top := D; left2top := h \; f; right2top := g |}), - big_red_square ~> pb_terminal big_black_square. - - move=> big_red_square; unfold pb_terminal. - - have /= := @is_square _ _ _ _ big_red_square. - - pose F' := bot big_red_square. - set w' : F' ~> C := bot2left big_red_square. - set z' : F' ~> B := bot2right big_red_square. - move=> E3. - - have xxx : isPrePullback Q A B (Cospan f g) (Span (w' \; h) z'). - by constructor=> /=; rewrite -compoA E3. - pose red_black_square : prepullback (Cospan f g) := - HB.pack (Span (w' \; h) z') xxx. - have := @from_unique _ (pb_terminal uvfg_ispb) red_black_square. - set blue := @from _ (pb_terminal uvfg_ispb) red_black_square. - move=> blue_unique. - - have p3 : @isPrePullback Q C E (Cospan h u) (Span w' (bot_map blue)). - by constructor; rewrite /= (bot2left_map blue). (* buggy unifier without blue *) - pose blue_red_black_square : prepullback (Cospan h u) := - HB.pack (Span w' (bot_map blue)) p3. - - pose red := @from _ (pb_terminal sq_ispb) blue_red_black_square. - - admit. - - - - have p2 : prepullback_isTerminal.axioms_ Q C B (Cospan (h \; f) g) (Span w (z \; v)) p1. - constructor. econstructor=> /=. - admit. - - by HB.from p1 p2. - -Admitted. - -End th_of_pb. - - -Module test. - -Section test. -Variables (Q : precat) (A B : Q) (c : cospan A B). -Variable (p : pullback c). -Check pb_terminal p : terminal _. - -End test. -End test. - - - - diff --git a/theories/encatB.v b/theories/encatB.v deleted file mode 100644 index 6b1d40250..000000000 --- a/theories/encatB.v +++ /dev/null @@ -1,1952 +0,0 @@ -Require Import ssreflect ssrfun. -From HB Require Import structures. - -Set Implicit Arguments. -Unset Strict Implicit. -Unset Printing Implicit Defensive. -Add Search Blacklist "__canonical__". - -Declare Scope algebra_scope. -Delimit Scope algebra_scope with A. -Local Open Scope algebra_scope. - -Declare Scope cat_scope. -Delimit Scope cat_scope with cat. -Local Open Scope cat_scope. - -(* we assume a few axioms to make life easier *) -Axiom funext : forall {T : Type} {U : T -> Type} [f g : forall t, U t], - (forall t, f t = g t) -> f = g. -Axiom propext : forall P Q : Prop, P <-> Q -> P = Q. -Axiom Prop_irrelevance : forall (P : Prop) (x y : P), x = y. - -(* Shortcut *) -Notation U := Type. - -(* Base definition : raw categories = quivers *) -HB.mixin Record IsQuiver C := { hom : C -> C -> U }. -Unset Universe Checking. -#[short(type="quiver")] -HB.structure Definition Quiver : Set := { C of IsQuiver C }. -Set Universe Checking. - -Bind Scope cat_scope with quiver. -Bind Scope cat_scope with hom. -Arguments hom {C} : rename. -Notation homs T := (@hom T _ _). -Notation "a ~> b" := (hom a b) - (at level 99, b at level 200, format "a ~> b") : cat_scope. -Notation "a ~>_ C b" := (@hom C a b) - (at level 99, C at level 0, only parsing) : cat_scope. - -(* precategories are quivers + id and comp *) -HB.mixin Record Quiver_IsPreCat C of Quiver C := { - idmap : forall (a : C), a ~> a; - comp : forall (a b c : C), (a ~> b) -> (b ~> c) -> (a ~> c); -}. - -HB.factory Record IsPreCat C := { - hom : C -> C -> U; - idmap : forall (a : C), hom a a; - comp : forall (a b c : C), hom a b -> hom b c -> hom a c; -}. -HB.builders Context C of IsPreCat C. - HB.instance Definition _ := IsQuiver.Build C hom. - HB.instance Definition _ := Quiver_IsPreCat.Build C idmap comp. -HB.end. - -Unset Universe Checking. -#[short(type="precat")] -HB.structure Definition PreCat : Set := { C of IsPreCat C }. -Set Universe Checking. - -Bind Scope cat_scope with precat. -Arguments idmap {C} {a} : rename. -Arguments comp {C} {a b c} : rename. -Notation "f \o g" := (comp g f) : cat_scope. -Notation "f \; g :> T" := (@comp T _ _ _ f g) - (at level 60, g, T at level 60, format "f \; g :> T", only parsing) : cat_scope. -Notation "f \; g" := (comp f g) : cat_scope. -Notation "\idmap_ a" := (@idmap _ a) (only parsing, at level 0) : cat_scope. - -(* categories are precategories + laws *) -HB.mixin Record PreCat_IsCat C of PreCat C := { - comp1o : forall (a b : C) (f : a ~> b), idmap \; f = f; - compo1 : forall (a b : C) (f : a ~> b), f \; idmap = f; - compoA : forall (a b c d : C) (f : a ~> b) (g : b ~> c) (h : c ~> d), - f \; (g \; h) = (f \; g) \; h -}. -Unset Universe Checking. -#[short(type="cat")] -HB.structure Definition Cat : Set := { C of PreCat_IsCat C & IsPreCat C }. -Set Universe Checking. - -Bind Scope cat_scope with cat. -Arguments compo1 {C a b} : rename. -Arguments comp1o {C a b} : rename. -Arguments compoA {C a b c d} : rename. - -(* the discrete category on a type cannot be the default, we make an alias *) -Definition discrete (T : U) := T. -HB.instance Definition _ T := @IsPreCat.Build (discrete T) (fun x y => x = y) - (fun=> erefl) (@etrans _). -Lemma etransA T (a b c d : discrete T) (f : a ~> b) (g : b ~> c) (h : c ~> d) : - f \; (g \; h) = (f \; g) \; h. -Proof. by rewrite /idmap/comp/=; case: _ / h; case: _ / g. Qed. -HB.instance Definition _ T := PreCat_IsCat.Build (discrete T) (@etrans_id _) - (fun _ _ _ => erefl) (@etransA _). - -(* the category of the unit type is the discrete one *) -HB.instance Definition _ := Cat.copy unit (discrete unit). - -HB.instance Definition _ := @IsPreCat.Build U (fun A B => A -> B) - (fun a => idfun) (fun a b c (f : a -> b) (g : b -> c) => (g \o f)%FUN). -HB.instance Definition _ := PreCat_IsCat.Build U (fun _ _ _ => erefl) - (fun _ _ _ => erefl) (fun _ _ _ _ _ _ _ => erefl). - - -Lemma Ucomp (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) : f \; g = (g \o f)%FUN. -Proof. by []. Qed. -Lemma Ucompx (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) x : (f \; g) x = g (f x). -Proof. by []. Qed. -Lemma U1 (X : U) : \idmap_X = idfun. -Proof. by []. Qed. -Lemma U1x (X : U) x : \idmap_X x = x. -Proof. by []. Qed. - -(* a prefunctor is a functor without laws *) -HB.mixin Record IsPreFunctor (C D : quiver) (F : C -> D) := { - Fhom : forall (a b : C), (a ~> b) -> (F a ~> F b) -}. - -Unset Universe Checking. -HB.structure Definition PreFunctor (C D : quiver) : Set := - { F of IsPreFunctor C D F }. -Set Universe Checking. -HB.instance Definition _ := IsQuiver.Build quiver PreFunctor.type. - -Notation "F ^$" := (@Fhom _ _ F _ _) - (at level 1, format "F ^$") : cat_scope. -Notation "F <$> f" := (@Fhom _ _ F _ _ f) - (at level 58, format "F <$> f", right associativity) : cat_scope. - -(* prefunctors are equal if their object and hom part are respectively equal *) -Lemma prefunctorP (C D : quiver) (F G : C ~> D) (eqFG : F =1 G) : - let homF a b F := F a ~> F b in - (forall a b f, eq_rect _ (homF a b) (F <$> f) _ (funext eqFG) = G <$> f) -> - F = G. -Proof. -move: F G => [F [[/= Fhom]]] [G [[/= Ghom]]] in eqFG *. -case: _ / (funext eqFG) => /= in Ghom * => eqFGhom. -congr PreFunctor.Pack; congr PreFunctor.Class; congr IsPreFunctor.Axioms_. -by do 3!apply: funext=> ?. -Qed. - -(* a functor is a prefunctor + laws for id and comp *) -HB.mixin Record PreFunctor_IsFunctor (C D : precat) (F : C -> D) - of @PreFunctor C D F := { - F1 : forall (a : C), F <$> \idmap_a = idmap; - Fcomp : forall (a b c : C) (f : a ~> b) (g : b ~> c), - F <$> (f \; g) = F <$> f \; F <$> g; -}. -Unset Universe Checking. - -(* precat and cat have a quiver structure *) -HB.structure Definition Functor (C D : precat) : Set := - { F of IsPreFunctor C D F & PreFunctor_IsFunctor C D F }. -Set Universe Checking. -HB.instance Definition _ := IsQuiver.Build precat Functor.type. -HB.instance Definition _ := IsQuiver.Build cat Functor.type. - -(* functor equality is the same as prefunctor because of PI *) -Lemma functorP (C D : precat) (F G : C ~> D) (eqFG : F =1 G) : - let homF a b F := F a ~> F b in - (forall a b f, eq_rect _ (homF a b) (F^$ f) _ (funext eqFG) = G^$ f) -> - F = G. -Proof. -move=> /= /prefunctorP {eqFG}. -case: F G => [F [/= Fm Fm']] [G [/= Gm Gm']]//=. -move=> [_] /EqdepFacts.eq_sigT_iff_eq_dep eqFG. -case: _ / eqFG in Gm' *. -congr Functor.Pack; congr Functor.Class. -case: Fm' Gm' => [F1 Fc] [G1 Gc]. -by congr PreFunctor_IsFunctor.Axioms_; apply: Prop_irrelevance. -Qed. - -(* the identity function is a functor *) -HB.instance Definition _ (C : quiver) := - IsPreFunctor.Build C C idfun (fun a b => idfun). -HB.instance Definition _ (C : precat) := - PreFunctor_IsFunctor.Build C C idfun (fun=> erefl) (fun _ _ _ _ _ => erefl). - -(* the composition of prefunctors *) -Section comp_prefunctor. -Context {C D E : quiver} {F : C ~> D} {G : D ~> E}. - -HB.instance Definition _ := IsPreFunctor.Build C E (G \o F)%FUN - (fun a b f => G <$> F <$> f). -Lemma comp_Fun (a b : C) (f : a ~> b) : (G \o F)%FUN <$> f = G <$> (F <$> f). -Proof. by []. Qed. -End comp_prefunctor. - -Section comp_functor. -Context {C D E : precat} {F : C ~> D} {G : D ~> E}. -Lemma comp_F1 (a : C) : (G \o F)%FUN <$> \idmap_a = idmap. -Proof. by rewrite !comp_Fun !F1. Qed. -Lemma comp_Fcomp (a b c : C) (f : a ~> b) (g : b ~> c) : - (G \o F)%FUN <$> (f \; g) = (G \o F)%FUN <$> f \; (G \o F)%FUN <$> g. -Proof. by rewrite !comp_Fun !Fcomp. Qed. -HB.instance Definition _ := PreFunctor_IsFunctor.Build C E (G \o F)%FUN - comp_F1 comp_Fcomp. -End comp_functor. - -(* precat and cat have a precategory structure *) -HB.instance Definition _ := Quiver_IsPreCat.Build precat - (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). -HB.instance Definition _ := Quiver_IsPreCat.Build cat - (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). - -Lemma funext_frefl A B (f : A -> B) : funext (frefl f) = erefl. -Proof. exact: Prop_irrelevance. Qed. - -(* precategories and categories form a category *) -Definition precat_cat : PreCat_IsCat precat. -Proof. -by split=> [C D F|C D F|C D C' D' F G H]; - apply/functorP => a b f /=; rewrite funext_frefl. -Qed. -HB.instance Definition _ := precat_cat. -Definition cat_cat : PreCat_IsCat cat. -Proof. -by split=> [C D F|C D F|C D C' D' F G H]; - apply/functorP => a b f /=; rewrite funext_frefl. -Qed. -HB.instance Definition _ := cat_cat. - -Check (cat : cat). - -(* concrete categories *) -HB.mixin Record Quiver_IsPreConcrete T of Quiver T := { - concrete : T -> U; - concrete_fun : forall (a b : T), (a ~> b) -> concrete a -> concrete b; -}. -Unset Universe Checking. -#[short(type="preconcrete_quiver")] -HB.structure Definition PreConcreteQuiver : Set := - { C of Quiver_IsPreConcrete C & IsQuiver C }. -Set Universe Checking. -Coercion concrete : PreConcreteQuiver.sort >-> Sortclass. - -HB.mixin Record PreConcrete_IsConcrete T of PreConcreteQuiver T := { - concrete_fun_inj : forall (a b : T), injective (concrete_fun a b) -}. -Unset Universe Checking. -#[short(type="concrete_quiver")] -HB.structure Definition ConcreteQuiver : Set := - { C of PreConcreteQuiver C & PreConcrete_IsConcrete C }. -Set Universe Checking. - -HB.instance Definition _ (C : ConcreteQuiver.type) := - IsPreFunctor.Build _ _ (concrete : C -> U) concrete_fun. - -HB.mixin Record PreCat_IsConcrete T of ConcreteQuiver T & PreCat T := { - concrete1 : forall (a : T), concrete <$> \idmap_a = idfun; - concrete_comp : forall (a b c : T) (f : a ~> b) (g : b ~> c), - concrete <$> (f \; g) = ((concrete <$> g) \o (concrete <$> f))%FUN; -}. -Unset Universe Checking. -#[short(type="concrete_precat")] -HB.structure Definition ConcretePreCat : Set := - { C of PreCat C & ConcreteQuiver C & PreCat_IsConcrete C }. -#[short(type="concrete_cat")] -HB.structure Definition ConcreteCat : Set := - { C of Cat C & ConcreteQuiver C & PreCat_IsConcrete C }. -Set Universe Checking. - -HB.instance Definition _ (C : concrete_precat) := - PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). -HB.instance Definition _ (C : ConcreteCat.type) := - PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). - -HB.instance Definition _ := Quiver_IsPreConcrete.Build U (fun _ _ => id). -HB.instance Definition _ := PreConcrete_IsConcrete.Build U (fun _ _ _ _ => id). -HB.instance Definition _ := PreCat_IsConcrete.Build U - (fun=> erefl) (fun _ _ _ _ _ => erefl). - -Unset Universe Checking. -HB.instance Definition _ := Quiver_IsPreConcrete.Build quiver (fun _ _ => id). -HB.instance Definition _ := Quiver_IsPreConcrete.Build precat (fun _ _ => id). -HB.instance Definition _ := Quiver_IsPreConcrete.Build cat (fun _ _ => id). -Lemma quiver_concrete_subproof : PreConcrete_IsConcrete quiver. -Proof. -constructor=> C D F G FG; apply: prefunctorP. - by move=> x; congr (_ x); apply: FG. -by move=> *; apply: Prop_irrelevance. -Qed. -HB.instance Definition _ := quiver_concrete_subproof. - -Lemma precat_concrete_subproof : PreConcrete_IsConcrete precat. -Proof. -constructor=> C D F G FG; apply: functorP. - by move=> x; congr (_ x); apply: FG. -by move=> *; apply: Prop_irrelevance. -Qed. -HB.instance Definition _ := precat_concrete_subproof. - -Lemma cat_concrete_subproof : PreConcrete_IsConcrete cat. -Proof. -constructor=> C D F G FG; apply: functorP. - by move=> x; congr (_ x); apply: FG. -by move=> *; apply: Prop_irrelevance. -Qed. -HB.instance Definition _ := cat_concrete_subproof. -HB.instance Definition _ := PreCat_IsConcrete.Build precat - (fun=> erefl) (fun _ _ _ _ _ => erefl). -HB.instance Definition _ := PreCat_IsConcrete.Build cat - (fun=> erefl) (fun _ _ _ _ _ => erefl). -Set Universe Checking. - -(* constant functor *) -Definition cst (C D : quiver) (c : C) := fun of D => c. -Arguments cst {C} D c. -HB.instance Definition _ {C D : precat} (c : C) := - IsPreFunctor.Build D C (cst D c) (fun _ _ _ => idmap). -HB.instance Definition _ {C D : cat} (c : C) := - PreFunctor_IsFunctor.Build D C (cst D c) (fun=> erefl) - (fun _ _ _ _ _ => esym (compo1 idmap)). - -(* opposite category *) -Definition catop (C : U) : U := C. -Notation "C ^op" := (catop C) - (at level 2, format "C ^op") : cat_scope. -HB.instance Definition _ (C : quiver) := - IsQuiver.Build C^op (fun a b => hom b a). -HB.instance Definition _ (C : precat) := - Quiver_IsPreCat.Build (C^op) (fun=> idmap) (fun _ _ _ f g => g \; f). -HB.instance Definition _ (C : cat) := PreCat_IsCat.Build (C^op) - (fun _ _ _ => compo1 _) (fun _ _ _ => comp1o _) - (fun _ _ _ _ _ _ _ => esym (compoA _ _ _)). - -HB.instance Definition _ {C : precat} {c : C} := - IsPreFunctor.Build C _ (hom c) (fun a b f g => g \; f). -Lemma hom_Fhom_subproof (C : cat) (x : C) : - PreFunctor_IsFunctor _ _ (hom x). -Proof. by split=> *; apply/funext => h; [apply: compo1 | apply: compoA]. Qed. -HB.instance Definition _ {C : cat} {c : C} := hom_Fhom_subproof c. - -Check fun (C : cat) (x : C) => hom x : C ~>_cat U. - -Lemma hom_op {C : quiver} (c : C^op) : hom c = (@hom C)^~ c. -Proof. reflexivity. Qed. - -Lemma homFhomx {C : precat} (a b c : C) (f : a ~> b) (g : c ~> a) : - (hom c <$> f) g = g \; f. -Proof. reflexivity. Qed. - -(* nary product of categories *) -Definition dprod {I : U} (C : I -> U) := forall i, C i. - -Section hom_dprod. -Context {I : U} (C : I -> quiver). -Definition dprod_hom_subdef (a b : dprod C) := forall i, a i ~> b i. -HB.instance Definition _ := IsQuiver.Build (dprod C) dprod_hom_subdef. -End hom_dprod. -Arguments dprod_hom_subdef /. - -Section precat_dprod. -Context {I : U} (C : I -> precat). -Definition dprod_idmap_subdef (a : dprod C) : a ~> a := fun=> idmap. -Definition dprod_comp_subdef (a b c : dprod C) (f : a ~> b) (g : b ~> c) : a ~> c := - fun i => f i \; g i. -HB.instance Definition _ := IsPreCat.Build (dprod C) - dprod_idmap_subdef dprod_comp_subdef. -End precat_dprod. -Arguments dprod_idmap_subdef /. -Arguments dprod_comp_subdef /. - -Section cat_dprod. -Context {I : U} (C : I -> cat). -Local Notation type := (dprod C). -Lemma dprod_is_cat : PreCat_IsCat type. -Proof. -split=> [a b f|a b f|a b c d f g h]; apply/funext => i; -[exact: comp1o | exact: compo1 | exact: compoA]. -Qed. -HB.instance Definition _ := dprod_is_cat. -End cat_dprod. - -(* binary product *) -Section hom_prod. -Context {C D : quiver}. -Definition prod_hom_subdef (a b : C * D) := ((a.1 ~> b.1) * (a.2 ~> b.2))%type. -HB.instance Definition _ := IsQuiver.Build (C * D)%type prod_hom_subdef. -End hom_prod. - -Section precat_prod. -Context {C D : precat}. -HB.instance Definition _ := IsPreCat.Build (C * D)%type (fun=> (idmap, idmap)) - (fun a b c (f : a ~> b) (g : b ~> c) => (f.1 \; g.1, f.2 \; g.2)). -End precat_prod. - -Section cat_prod. -Context {C D : cat}. -Local Notation type := (C * D)%type. -Lemma prod_is_cat : PreCat_IsCat type. -Proof. -split=> [[a1 a2] [b1 b2] [f1 f2]|[a1 a2] [b1 b2] [f1 f2]| - [a1 a2] [b1 b2] [c1 c2] [d1 d2] [f1 f2] [g1 g2] [h1 h2]]; congr (_, _) => //=; -by [exact: comp1o | exact: compo1 | exact: compoA]. -Qed. -HB.instance Definition _ := prod_is_cat. -End cat_prod. - -(* naturality *) -HB.mixin Record IsNatural (C D : precat) (F G : C ~>_quiver D) - (n : forall c, F c ~> G c) := { - natural : forall (a b : C) (f : a ~> b), - F <$> f \; n b = n a \; G <$> f -}. -Unset Universe Checking. -HB.structure Definition Natural (C D : precat) - (F G : C ~>_quiver D) : Set := - { n of @IsNatural C D F G n }. -Set Universe Checking. -HB.instance Definition _ (C D : precat) := - IsQuiver.Build (PreFunctor.type C D) (@Natural.type C D). -HB.instance Definition _ (C D : cat) := - IsQuiver.Build (Functor.type C D) (@Natural.type C D). -Arguments natural {C D F G} n [a b] f : rename. - -Check fun (C D : cat) (F G : C ~> D) => F ~>_(C ~>_cat D) G. - -Lemma naturalx (C : precat) (D : concrete_precat) - (F G : C ~>_quiver D) (n : F ~> G) (a b : C) (f : a ~> b) g : - (concrete <$> n b) ((concrete <$> F <$> f) g) = - (concrete <$> G <$> f) ((concrete <$> n a) g). -Proof. -have /(congr1 (fun h => (concrete <$> h) g)) := natural n f. -by rewrite !Fcomp. -Qed. -Arguments naturalx {C D F G} n [a b] f. - -Lemma naturalU (C : precat) (F G : C ~>_quiver U) (n : F ~> G) - (a b : C) (f : a ~> b) g : n b (F^$ f g) = G^$ f (n a g). -Proof. exact: (naturalx n). Qed. - -Lemma natP (C D : precat) (F G : C ~>_quiver D) (n m : F ~> G) : - Natural.sort n = Natural.sort m -> n = m. -Proof. -case: n m => [/= n nP] [/= m mP] enm. -elim: _ / enm in mP *; congr Natural.Pack. -case: nP mP => [[?]] [[?]]; congr Natural.Class. -congr IsNatural.Axioms_. -exact: Prop_irrelevance. -Qed. - -Notation "F ~~> G" := (F ~>_(homs quiver) G) - (at level 99, G at level 200, format "F ~~> G"). -Notation "F ~~> G :> C ~> D" := (F ~> G :> (C ~>_quiver D)) - (at level 99, G at level 200, C, D at level 0, - format "F ~~> G :> C ~> D"). - -Definition natural_id {C D : precat} (F : C ~>_quiver D) (a : C) := \idmap_(F a). -Definition natural_id_natural (C D : cat) (F : C ~>_quiver D) : - IsNatural C D F F (natural_id F). -Proof. by constructor=> a b f; rewrite /natural_id/= compo1 comp1o. Qed. -HB.instance Definition _ C D F := @natural_id_natural C D F. - -Check fun {C D : cat} (F : C ~>_quiver D) => natural_id F : F ~> F. - -Definition natural_comp {C D : precat} (F G H : C ~>_quiver D) - (m : F ~> G) (n : G ~> H) (a : C) := m a \; n a. -Definition natural_comp_natural (C D : cat) (F G H : C ~>_quiver D) m n : - IsNatural C D F H (@natural_comp C D F G H m n). -Proof. -constructor=> a b f; rewrite /natural_comp/=. -by rewrite compoA natural -compoA natural compoA. -Qed. -HB.instance Definition _ C D F G H m n := @natural_comp_natural C D F G H m n. - -HB.instance Definition _ {C D : cat} := - Quiver_IsPreCat.Build (PreFunctor.type C D) natural_id natural_comp. -HB.instance Definition _ {C D : cat} := - Quiver_IsPreCat.Build (Functor.type C D) natural_id natural_comp. - -Lemma prefunctor_cat {C D : cat} : PreCat_IsCat (PreFunctor.type C D). -Proof. -constructor => [F G f|F G f|F G H J f g h]. -- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. -- by apply/natP/funext => a; rewrite /= /natural_comp compo1. -- by apply/natP/funext => a; rewrite /= /natural_comp compoA. -Qed. -HB.instance Definition _ C D := @prefunctor_cat C D. - -Lemma functor_cat {C D : cat} : PreCat_IsCat (Functor.type C D). -Proof. -constructor => [F G f|F G f|F G H J f g h]. -- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. -- by apply/natP/funext => a; rewrite /= /natural_comp compo1. -- by apply/natP/funext => a; rewrite /= /natural_comp compoA. -Qed. -HB.instance Definition _ C D := @functor_cat C D. - -Section nat_map_left. -Context {C D E : precat} {F G : C ~> D}. - -Definition nat_lmap (H : D ~>_quiver E) (n : forall c, F c ~> G c) : - forall c, (H \o F)%FUN c ~> (H \o G)%FUN c := fun c => H <$> n c. - -Fail Check fun (H : D ~> E) (n : F ~~> G) => nat_lmap H n : H \o F ~~> H \o G. - -Lemma nat_lmap_is_natural (H : D ~> E) (n : F ~~> G) : - IsNatural C E (H \o F) (H \o G) (nat_lmap H n). -Proof. by constructor=> a b f; rewrite /nat_lmap/= -!Fcomp natural. Qed. -HB.instance Definition _ H n := nat_lmap_is_natural H n. - -Check fun (H : D ~> E) (n : F ~~> G) => nat_lmap H n : H \o F ~~> H \o G. - -End nat_map_left. - -Notation "F n" := (nat_lmap F n) - (at level 58, format "F n", right associativity) : cat_scope. - -Section nat_map_right. -Context {C D E : precat} {F G : C ~> D}. - -Definition nat_rmap (H : E -> C) (n : forall c, F c ~> G c) : - forall c, (F \o H)%FUN c ~> (G \o H)%FUN c := fun c => n (H c). -Lemma nat_rmap_is_natural (H : E ~> C :> quiver) (n : F ~~> G) : - IsNatural E D (F \o H)%FUN (G \o H)%FUN (nat_rmap H n). -Proof. by constructor=> a b f; rewrite /nat_lmap/= natural. Qed. -HB.instance Definition _ H n := nat_rmap_is_natural H n. - -End nat_map_right. - -Notation "F <$o> n" := (nat_rmap F n) - (at level 58, format "F <$o> n", right associativity) : cat_scope. - -Definition delta (C D : cat) : C -> (D ~> C) := cst D. -Arguments delta C D : clear implicits. - -Definition map_delta {C D : cat} (a b : C) (f : a ~> b) : - delta C D a ~> delta C D b. -Proof. -apply: (@Natural.Pack _ _ (cst D a) (cst D b) (fun x => f)). -apply: Natural.Class; apply: (IsNatural.Build _ _ _ _ _). -by move=> a' b' ?; rewrite compo1 comp1o. -Defined. - -HB.instance Definition _ {C D : cat} := - IsPreFunctor.Build C (D ~> C) (delta C D) (@map_delta C D). - -Lemma delta_functor {C D : cat} : PreFunctor_IsFunctor _ _ (delta C D). -Proof. by constructor=> [a|a b c f g]; exact/natP. Qed. -HB.instance Definition _ C D := @delta_functor C D. - -HB.mixin Record IsMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { - unit : idfun ~~> M; - join : (M \o M)%FUN ~~> M; - bind : forall (a b : C), (a ~> M b) -> (M a ~> M b); - bindE : forall a b (f : a ~> M b), bind a b f = M <$> f \; join b; - unit_join : forall a, (M <$> unit a) \; join _ = idmap; - join_unit : forall a, join _ \; (M <$> unit a) = idmap; - join_square : forall a, M <$> join a \; join _ = join _ \; join _ -}. - -#[short(type="premonad")] -HB.structure Definition PreMonad (C : precat) := - {M of @PreFunctor C C M & IsMonad C M}. -#[short(type="monad")] -HB.structure Definition Monad (C : precat) := - {M of @Functor C C M & IsMonad C M}. - -HB.factory Record IsJoinMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { - unit : idfun ~~> M; - join : (M \o M)%FUN ~~> M; - unit_join : forall a, (M <$> unit a) \; join _ = idmap; - join_unit : forall a, join _ \; (M <$> unit a) = idmap; - join_square : forall a, M <$> join a \; join _ = join _ \; join _ -}. -HB.builders Context C M of IsJoinMonad C M. - HB.instance Definition _ := IsMonad.Build C M - (fun a b f => erefl) unit_join join_unit join_square. -HB.end. - -HB.mixin Record IsCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { - counit : M ~~> idfun; - cojoin : M ~~> (M \o M)%FUN; - cobind : forall (a b : C), (M a ~> b) -> (M a ~> M b); - cobindE : forall a b (f : M a ~> b), cobind a b f = cojoin _ \; M <$> f; - unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; - join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; - cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ -}. -#[short(type="precomonad")] -HB.structure Definition PreCoMonad (C : precat) := - {M of @PreFunctor C C M & IsCoMonad C M}. -#[short(type="comonad")] -HB.structure Definition CoMonad (C : precat) := - {M of @Functor C C M & IsCoMonad C M}. - -HB.factory Record IsJoinCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { - counit : M ~~> idfun; - cojoin : M ~~> (M \o M)%FUN; - unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; - join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; - cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ -}. -HB.builders Context C M of IsJoinCoMonad C M. - HB.instance Definition _ := IsCoMonad.Build C M - (fun a b f => erefl) unit_cojoin join_counit cojoin_square. -HB.end. - -Lemma idFmap (C : cat) (a b : C) (f : a ~> b) : idfun <$> f = f. -Proof. by []. Qed. - -Lemma compFmap (C D E : cat) (F : C ~> D) (G : D ~> E) (a b : C) (f : a ~> b) : - (G \o F) <$> f = G <$> F <$> f. -Proof. by []. Qed. - -(* yoneda *) -Section hom_repr. -Context {C : cat} (F : C ~>_cat U). - -Definition homF : C -> U := fun c => hom c ~~> F. - -Section nat. -Context (x y : C) (xy : x ~> y). - -(* Goal hom x ~~> F -> hom y ~~> F *) -Context (n : hom x ~~> F). -Definition homFhom c : hom y c ~> F c := fun g => n _ (xy \; g). - -Lemma homFhom_natural_subdef : IsNatural C U (hom y) F homFhom. -Proof. -by split=> a b f /=; apply/funext => g /=; - rewrite /homFhom !Ucompx/= !naturalU/= Fcomp. -Qed. -HB.instance Definition _ := homFhom_natural_subdef. -End nat. -Arguments homFhom / : clear implicits. - -HB.about IsPreFunctor.Build. -Check homFhom : forall x y : C, (x ~> y) -> (homF x -> homF y). -HB.instance Definition _ := IsPreFunctor.Build _ _ homF homFhom. -Lemma homF_functor_subproof : PreFunctor_IsFunctor _ _ homF. -Proof. -split=> [a|a b c f g]. - apply/funext => -[/= f natf]. - apply: natP => //=; apply: funext => b; apply: funext => g/=. - by rewrite comp1o. -apply/funext => -[/= h natf]. -apply: natP => //=; apply: funext => d; apply: funext => k/=. -by rewrite compoA. -Qed. -HB.instance Definition _ := homF_functor_subproof. - -Section pointed. -Context (c : C). -Definition hom_repr : homF c ~> F c := fun f => f _ idmap. -Arguments hom_repr /. - -Definition repr_hom (fc : F c) a : hom c a ~> F a := - fun f => F^$ f fc. -Arguments repr_hom / : clear implicits. -Lemma repr_hom_subdef (fc : F c) : IsNatural _ _ _ _ (repr_hom fc). -Proof. by split=> a b f /=; apply/funext=> x; rewrite !Ucompx/= Fcomp. Qed. -HB.instance Definition _ {fc : F c} := repr_hom_subdef fc. - -Definition repr_hom_nat : F c ~> homF c := repr_hom. - -Lemma hom_reprK : cancel hom_repr repr_hom_nat. -Proof. -move=> f; apply/natP; apply/funext => a; apply/funext => g /=. -by rewrite -naturalU/=; congr (f _ _); apply: comp1o. -Qed. -Lemma repr_homK : cancel (repr_hom : F c ~> homF c) hom_repr. -Proof. by move=> fc; rewrite /= F1. Qed. -End pointed. -Arguments hom_repr /. -Arguments repr_hom /. - -Lemma hom_repr_natural_subproof : IsNatural _ _ _ _ hom_repr. -Proof. -split=> a b f /=; apply/funext => n /=; rewrite !Ucompx/= compo1/=. -by rewrite -naturalU/=; congr (n _ _); apply/esym/comp1o. -Qed. -HB.instance Definition _ := hom_repr_natural_subproof. - -(* show this from the previous proof *) -Lemma hom_natural_repr_subproof : IsNatural _ _ _ _ repr_hom_nat. -Proof. -split=> a b f /=; apply: funext => fa /=; rewrite !Ucompx/=. -apply: natP; apply: funext => c /=; apply: funext => d /=. -by rewrite Fcomp Ucompx/=. -Qed. -HB.instance Definition _ := hom_natural_repr_subproof. - -Definition hom_repr_nat : homF ~~> F := hom_repr. -Definition repr_hom_nat_nat : F ~~> homF := repr_hom_nat. - -End hom_repr. - -(* comma categories *) -Module comma. -Section homcomma. -Context {C D E : precat} (F : C ~> E) (G : D ~> E). - -Definition type := { x : C * D & F x.1 ~> G x.2 }. -Definition hom_subdef (a b : type) := { - f : tag a ~> tag b & F <$> f.1 \; tagged b = tagged a \; G <$> f.2 - }. -HB.instance Definition _ := IsQuiver.Build type hom_subdef. -End homcomma. -Arguments hom_subdef /. -Section comma. -Context {C D E : cat} (F : C ~> E) (G : D ~> E). -Notation type := (type F G). - -Program Definition idmap_subdef (a : type) : a ~> a := @Tagged _ idmap _ _. -Next Obligation. by rewrite !F1 comp1o compo1. Qed. -Program Definition comp_subdef (a b c : type) - (f : a ~> b) (g : b ~> c) : a ~> c := - @Tagged _ (tag f \; tag g) _ _. -Next Obligation. by rewrite !Fcomp -compoA (tagged g) compoA (tagged f) compoA. Qed. -HB.instance Definition _ := IsPreCat.Build type idmap_subdef comp_subdef. -Arguments idmap_subdef /. -Arguments comp_subdef /. - -Lemma comma_homeqP (a b : type) (f g : a ~> b) : projT1 f = projT1 g -> f = g. -Proof. -case: f g => [f fP] [g +]/= eqfg; case: _ / eqfg => gP. -by congr existT; apply: Prop_irrelevance. -Qed. - -Lemma comma_is_cat : PreCat_IsCat type. -Proof. -by split=> [[a fa] [b fb] [*]|[a fa] [b fb] [*]|*]; - apply/comma_homeqP; rewrite /= ?(comp1o, compo1, compoA). -Qed. -HB.instance Definition _ := comma_is_cat. -End comma. -End comma. -Notation "F `/` G" := (@comma.type _ _ _ F G) - (at level 40, G at level 40, format "F `/` G") : cat_scope. -Notation "a /` G" := (cst unit a `/` G) - (at level 40, G at level 40, format "a /` G") : cat_scope. -Notation "F `/ b" := (F `/` cst unit b) - (at level 40, b at level 40, format "F `/ b") : cat_scope. -Notation "a / b" := (cst unit a `/ b) : cat_scope. - -Definition obj (C : quiver) : Type := C. -HB.mixin Record IsInitial {C : quiver} (i : obj C) := { - to : forall c, i ~> c; - to_unique : forall c (f : i ~> c), f = to c -}. -#[short(type="initial")] -HB.structure Definition Initial {C : quiver} := {i of IsInitial C i}. - -HB.mixin Record IsTerminal {C : quiver} (t : obj C) := { - from : forall c, c ~> t; - from_unique : forall c (f : c ~> t), f = from c -}. -#[short(type="terminal")] -HB.structure Definition Terminal {C : quiver} := {t of IsTerminal C t}. -#[short(type="universal")] -HB.structure Definition Universal {C : quiver} := - {u of Initial C u & Terminal C u}. - -(* Definition hom' {C : precat} (a b : C) := a ~> b. *) -(* (* Bug *) *) -(* Identity Coercion hom'_hom : hom' >-> hom. *) - -(* HB.mixin Record IsMono {C : precat} (b c : C) (f : hom b c) := { *) -(* monoP : forall (a : C) (g1 g2 : a ~> b), g1 \; f = g2 \; f -> g1 = g2 *) -(* }. *) -(* #[short(type="mono")] *) -(* HB.structure Definition Mono {C : precat} (a b : C) := {m of IsMono C a b m}. *) -(* Notation "a >~> b" := (mono a b) *) -(* (at level 99, b at level 200, format "a >~> b") : cat_scope. *) -(* Notation "C >~>_ T D" := (@mono T C D) *) -(* (at level 99, T at level 0, only parsing) : cat_scope. *) - -(* HB.mixin Record IsEpi {C : precat} (a b : C) (f : hom a b) := { *) -(* epiP : forall (c : C) (g1 g2 : b ~> c), g1 \o f = g2 \o f -> g1 = g2 *) -(* }. *) -(* #[short(type="epi")] *) -(* HB.structure Definition Epi {C : precat} (a b : C) := {e of IsEpi C a b e}. *) -(* Notation "a ~>> b" := (epi a b) *) -(* (at level 99, b at level 200, format "a ~>> b") : cat_scope. *) -(* Notation "C ~>>_ T D" := (@epi T C D) *) -(* (at level 99, T at level 0, only parsing) : cat_scope. *) - -(* #[short(type="iso")] *) -(* HB.structure Definition Iso {C : precat} (a b : C) := *) -(* {i of @Mono C a b i & @Epi C a b i}. *) -(* Notation "a <~> b" := (epi a b) *) -(* (at level 99, b at level 200, format "a <~> b") : cat_scope. *) -(* Notation "C <~>_ T D" := (@epi T C D) *) -(* (at level 99, T at level 0, only parsing) : cat_scope. *) - -HB.mixin Record IsRightAdjoint (D C : precat) (R : D -> C) - of @PreFunctor D C R := { - L_ : C ~> D; - phi : forall c d, (L_ c ~> d) -> (c ~> R d); - psy : forall c d, (c ~> R d) -> (L_ c ~> d); - phi_psy c d : (phi c d \o psy c d)%FUN = @id (c ~> R d); - psy_phi c d : (psy c d \o phi c d)%FUN = @id (L_ c ~> d) -}. -#[short(type="right_adjoint")] -HB.structure Definition RightAdjoint (D C : precat) := - { R of @Functor D C R & IsRightAdjoint D C R }. -Arguments L_ {_ _}. -Arguments phi {D C s} {c d}. -Arguments psy {D C s} {c d}. - - -HB.mixin Record PreCat_IsMonoidal C of PreCat C := { - onec : C; - (* prod1 : @hom precat (C * C)%type C ; *) - prod : (C * C)%type ~>_precat C; -}. -#[short(type="premonoidal")] -#[verbose] -HB.structure Definition PreMonoidal := { C of PreCat C & PreCat_IsMonoidal C }. -Notation premonoidal := premonoidal. -Arguments prod {C} : rename. -Notation "a * b" := (prod (a, b)) : cat_scope. -Reserved Notation "f <*> g" (at level 40, g at level 40, format "f <*> g"). -Notation "f <*> g" := (prod^$ (f, g)) (only printing) : cat_scope. -Notation "f <*> g" := (prod^$ ((f, g) : (_, _) ~> (_, _))) - (only parsing) : cat_scope. -Notation "1" := onec : cat_scope. - -Definition hom_cast {C : quiver} {a a' : C} (eqa : a = a') {b b' : C} (eqb : b = b') : - (a ~> b) -> (a' ~> b'). -Proof. now elim: _ / eqa; elim: _ / eqb. Defined. - -HB.mixin Record PreFunctor_IsMonoidal (C D : premonoidal) F of - @PreFunctor C D F := { - fun_one : F 1 = 1; - fun_prod : forall (x y : C), F (x * y) = F x * F y; -}. -#[short(type="monoidal_prefunctor")] -HB.structure Definition MonoidalPreFunctor C D := - { F of @PreFunctor_IsMonoidal C D F }. -Arguments fun_prod {C D F x y} : rename. -(* Arguments fun_prodF {C D F x x'} f {y y'} g : rename. *) -Unset Universe Checking. -HB.instance Definition _ := IsQuiver.Build premonoidal MonoidalPreFunctor.type. -Set Universe Checking. - -HB.instance Definition _ (C : quiver) := - IsPreFunctor.Build (C * C)%type C fst - (fun (a b : C * C) (f : a ~> b) => f.1). -HB.instance Definition _ (C : quiver) := - IsPreFunctor.Build (C * C)%type C snd - (fun (a b : C * C) (f : a ~> b) => f.2). - -Definition prod3l {C : premonoidal} (x : C * C * C) : C := - (x.1.1 * x.1.2) * x.2. -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build _ C prod3l - (fun a b (f : a ~> b) => (f.1.1 <*> f.1.2) <*> f.2). - -Definition prod3r {C : premonoidal} (x : C * C * C) : C := - x.1.1 * (x.1.2 * x.2). -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build _ C prod3r - (fun a b (f : a ~> b) => f.1.1 <*> (f.1.2 <*> f.2)). - -Definition prod1r {C : premonoidal} (x : C) : C := 1 * x. -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build C C prod1r - (fun (a b : C) (f : a ~> b) => \idmap_1 <*> f). - -Definition prod1l {C : premonoidal} (x : C) : C := x * 1. -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build C C prod1l - (fun (a b : C) (f : a ~> b) => f <*> \idmap_1). - -HB.mixin Record PreMonoidal_IsMonoidal C of PreMonoidal C := { - prodA : prod3l ~~> prod3r; - prod1c : prod1r ~~> idfun; - prodc1 : prod1l ~~> idfun; - prodc1c : forall (x y : C), - prodA (x, 1, y) \; \idmap_x <*> prod1c y = prodc1 x <*> \idmap_y; - prodA4 : forall (w x y z : C), - prodA (w * x, y, z) \; prodA (w, x, y * z) = - prodA (w, x, y) <*> \idmap_z \; prodA (w, x * y, z) \; \idmap_w <*> prodA (x, y, z); -}. - -Unset Universe Checking. -#[short(type="monoidal")] -#[verbose] -HB.structure Definition Monoidal : Set := - { C of PreMonoidal_IsMonoidal C & PreMonoidal C }. -Set Universe Checking. - -(******************************************************************) - - -Record cospan (Q : quiver) (A B : Q) := Cospan { - top : Q; - left2top : A ~> top; - right2top : B ~> top -}. - -Section cospans. -Variables (Q : precat) (A B : Q). -Record cospan_map (c c' : cospan A B) := CospanMap { - top_map : top c ~> top c'; - left2top_map : left2top c \; top_map = left2top c'; - right2top_map : right2top c \; top_map = right2top c'; -}. -HB.instance Definition _ := IsQuiver.Build (cospan A B) cospan_map. - -Lemma cospan_mapP (c c' : cospan A B) (f g : c ~> c') : - top_map f = top_map g <-> f = g. -Admitted. -End cospans. - -Section cospans_in_cat. -Variables (Q : cat) (A B : Q). -Definition cospan_idmap (c : cospan A B) := - @CospanMap Q A B c c idmap (compo1 _) (compo1 _). -Program Definition cospan_comp (c1 c2 c3 : cospan A B) - (f12 : c1 ~> c2) (f23 : c2 ~> c3) := - @CospanMap Q A B c1 c3 (top_map f12 \; top_map f23) _ _. -Next Obligation. by rewrite compoA !left2top_map. Qed. -Next Obligation. by rewrite compoA !right2top_map. Qed. -HB.instance Definition _ := IsPreCat.Build (cospan A B) cospan_idmap cospan_comp. - -Lemma cospan_are_cats : PreCat_IsCat (cospan A B). -Proof. -constructor=> [a b f|a b f|a b c d f g h]. -- by apply/cospan_mapP => /=; rewrite comp1o. -- by apply/cospan_mapP => /=; rewrite compo1. -- by apply/cospan_mapP => /=; rewrite compoA. -Qed. -HB.instance Definition _ := cospan_are_cats. -End cospans_in_cat. - -Section spans_and_co. -Variables (Q : quiver) (A B : Q). -Definition span := @cospan Q^op A B. -Definition bot (s : span) : Q := top s. -Definition bot2left (s : span) : bot s ~>_Q A := left2top s. -Definition bot2right (s : span) : bot s ~>_Q B := right2top s. -Definition Span (C : Q) (f : C ~> A) (g : C ~> B) : span := - @Cospan Q^op A B C f g. -End spans_and_co. - -HB.instance Definition _ (Q : precat) (A B : Q) := - Quiver.copy (span A B) (@cospan Q^op A B)^op. -HB.instance Definition _ (Q : cat) (A B : Q) := - Cat.copy (span A B) (@cospan Q^op A B)^op. - -Section bot_map. -Variables (C : cat) (A B : C) (s s' : span A B) (f : s ~> s'). -Definition bot_map : bot s ~> bot s' := top_map f. -Lemma bot2left_map : bot_map \; bot2left s' = bot2left s. -Proof. exact: left2top_map f. Qed. -Lemma bot2right_map : bot_map \; bot2right s' = bot2right s. -Proof. exact: right2top_map f. Qed. -End bot_map. - -HB.mixin Record isPrePullback (Q : precat) (A B : Q) - (c : cospan A B) (s : span A B) := { - is_square : bot2left s \; left2top c = bot2right s \; right2top c; -}. -#[short(type=prepullback)] -HB.structure Definition PrePullback Q A B (c : cospan A B) := - {s of isPrePullback Q A B c s}. -Arguments prepullback {Q A B} c. - -Section prepullback. -Variables (Q : precat) (A B : Q) (c : cospan A B). -HB.instance Definition _ := - IsQuiver.Build (prepullback c) - (fun a b => (a : span A B) ~>_(span A B) (b : span A B)). -Lemma eq_prepullbackP (p q : prepullback c) : - p = q :> span _ _ <-> p = q. -Admitted. -End prepullback. -Section prepullback. -Variables (Q : cat) (A B : Q) (csp : cospan A B). -(* TODO: why can't we do that? *) -(* HB.instance Definition _ := Cat.on (prepullback csp). *) -HB.instance Definition _ := - Quiver_IsPreCat.Build (prepullback csp) - (fun a => \idmap_(a : span A B)) - (* TODO: study how to make this coercion trigger - even when the target is not reduced to span *) - (fun a b c f g => f \; g). -Lemma prepullback_is_cat : PreCat_IsCat (prepullback csp). -Proof. (* should be copied from the cat on span *) -constructor=> [a b f|a b f|a b c d f g h]; - [exact: comp1o|exact: compo1|exact: compoA]. -Qed. -End prepullback. - -HB.tag Definition pb_terminal (Q : precat) - (A B : Q) (c : cospan A B) (s : prepullback c) : - obj (prepullback c) := s. - -#[wrapper] -HB.mixin Record prepullback_isTerminal (Q : precat) - (A B : Q) (c : cospan A B) - (s : span A B) of isPrePullback Q A B c s := { - prepullback_terminal : - IsTerminal (prepullback c) (pb_terminal s) -}. -#[short(type="pullback"), verbose] -HB.structure Definition Pullback (Q : precat) - (A B : Q) (c : cospan A B) := - {s of isPrePullback Q A B c s - & IsTerminal (prepullback c) (pb_terminal s) }. - -Notation pbsquare u v f g := - (Pullback _ (Cospan f g) (Span u v)). - -Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). - -(********************************************************************) -(********************************************************************) - -(*** ENRICHED CATEGORIES *) - -Declare Scope encat_scope. -Delimit Scope encat_scope with encat. -Local Open Scope encat_scope. - -(* Enrichment in a monoidal category, following - https://ncatlab.org/nlab/show/enriched+category -*) -HB.mixin Record IsEnQuiver (V: Type) C := { - hom_object : C -> C -> V - }. -Unset Universe Checking. -HB.structure Definition EnQuiver (V: Type) : Set := - { C of IsEnQuiver V C }. -Set Universe Checking. - -(* Monoidal precategory with the enrichment operators (no axioms) *) -HB.mixin Record IsEnPreCat (V: PreMonoidal.type) C of - EnQuiver (PreMonoidal.sort V) C := { - id_element : forall (a: C), - @hom V onec (hom_object a a) ; - comp_morphism : forall (a b c: C), - @hom V (@hom_object V C b c * @hom_object V C a b) - (@hom_object V C a c) -}. -Unset Universe Checking. -HB.structure Definition EnPreCat (V: PreMonoidal.type) : Set := - { C of IsEnPreCat V C }. -Set Universe Checking. - -Notation "a ~^ b" := (hom_object a b) - (at level 99, b at level 200, format "a ~^ b") : encat_scope. -Notation "a ~^_ ( V , C ) b" := (@hom_object V C a b) - (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. -Notation "~^IE a" := (id_element a) - (at level 99, format "~^IE a") : cat_scope. -Notation "~^IE_ ( V , C ) a" := (@id_element V C a) - (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. -(* not working *) -Notation "~^CM a b c" := (comp_morphism a b c) - (at level 99, - format "~^CM a b c") : cat_scope. -Notation "~^CM_ ( V , C ) a b c" := (@comp_morphism V C a b c) - (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. - -(* V-enriched category: - V is the monoidal category; - C is the base category that gets enriched -*) -HB.mixin Record IsEnCat (V: Monoidal.type) C of EnPreCat V C := { - ecat_comp_assoc : forall a b c d: C, - forall alpha: - (((c ~^_(V,C) d) * (b ~^_(V,C) c)) * (a ~^_(V,C) b)) ~>_V - ((c ~^_(V,C) d) * ((b ~^_(V,C) c) * (a ~^_(V,C) b))), - ((@comp_morphism V C b c d) <*> (@idmap V (a ~^_(V,C) b))) \; - (@comp_morphism V C a b d) - = - alpha \; - ((@idmap V (c ~^_(V,C) d)) <*> (@comp_morphism V C a b c)) \; - (@comp_morphism V C a c d) ; - - ecat_comp_left_unital : forall a b: C, - forall l: onec * (a ~^_(V,C) b) ~>_V (a ~^_(V,C) b), - l = ((@id_element V C b) <*> (@idmap V (a ~^_(V,C) b))) \; - (@comp_morphism V C a b b) ; - ecat_comp_right_unital : forall a b: C, - forall r: (a ~^_(V,C) b) * onec ~>_V (a ~^_(V,C) b), - r = ((@idmap V (a ~^_(V,C) b)) <*> (@id_element V C a)) \; - (@comp_morphism V C a a b) -}. -Unset Universe Checking. -#[verbose] -HB.structure Definition EnCat (V: Monoidal.type) : Set := - { C of IsEnCat V C }. -Set Universe Checking. - -(********************************************************************) - -(*** DOUBLE CATEGORIES (without internal categories) *) - -(* Strict double categories, from - https://ncatlab.org/nlab/show/double+category - (we don't use internal categories) - - base obejcts as 0-cells: C ; - - vertical 1-morphisms (category D0 on C): hom C ; - - horizontal 1-morphisms (category H on C): hom (transpose C) ; - - horizontal 1-morhisms as 1-cells for D1: D1obj C ; - - 2-morphisms (category D1 on C1obj): hom (D1obj C) ; - - horizontally composable pairs of 1-cells : DPobj C ; - - horizontally composable pairs of 2-morphisms - (product category DP, D1 *0 D1) : hom (DPobj C) ; - - The definition of Strict Double Category, SDouble = (D0, H, D1, Dp), - is given by: - - - base objects C - - - (level-1) category (D0) of vertical 1-morphism on C - - - (level-1) category (H) of horizontal 1-morphism (D1obj) on C - - - (level-2) category (D1) of vertical 2-morphism on D1obj - - - (derived) category (DP) of vertical 2-morphisms on - horizontally D0-composable D1 products - ($\mbox{D1} *_0 \mbox{D1}$) - - - Source functor: $\mbox{D1} \to \mbox{D0}$ - - - Target functor: $\mbox{D1} \to \mbox{D0}$ - - - Horizontal unit functor: $\mbox{D0} \to \mbox{D1}$ - - - Horizontal composition functor: $\mbox{DP} \to \mbox{D1}$ -*) - - -(** Quivers for double categories *) - -(* transpose for horizontal morphism quiver. - HB.tag needed to identify transpose as lifter *) -HB.tag Definition transpose (C : quiver) : U := C. -#[wrapper] HB.mixin Record _IsHQuiver C of IsQuiver C := { - is_hquiver : IsQuiver (transpose C) -}. -(* vertical and horizontal quivers, defining cells *) -Unset Universe Checking. -#[short(type="vhquiver")] -HB.structure Definition VHQuiver : Set := - { C of IsQuiver C & IsQuiver (transpose C) }. -Set Universe Checking. - -HB.tag Definition hhom (c : VHQuiver.type) : c -> c -> U := @hom (transpose c). -Notation "a +> b" := (hhom a b) - (at level 99, b at level 200, format "a +> b") : cat_scope. - -(* record to represent the set of morphims - (needed for 2-objects, i.e. horizontal morphisms) *) -Record Total2 T (h: T -> T -> U) : Type := TT2 { - source : T; - target : T; - this_morph : h source target }. - -(* the set of horizontal morphisms. *) -HB.tag Definition D1obj (C: vhquiver) := Total2 (@hhom C). - -(* D1 quiver requirement (includes D0 quiver and its transpose). *) -#[wrapper] -HB.mixin Record _IsDQuiver T of VHQuiver T := - { is_dquiver : Quiver (D1obj T) }. -Unset Universe Checking. -#[short(type="dquiver")] -HB.structure Definition DQuiver : Set := { C of Quiver (D1obj C) }. -Set Universe Checking. - - -(** Horizonal D0-level category (H-D0) *) - -(* Precategory based on the HQuiver (i.e. horizontal precategory on D0 - objects) *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record _IsHPreCat T of VHQuiver T := { - is_hprecat : Quiver_IsPreCat (transpose T) }. -#[short(type="hprecat")] -HB.structure Definition HPreCat : Set := - { C of Quiver_IsPreCat (transpose C) }. -Set Universe Checking. - -(* The category based on the HQuiver (i.e. horizontal category on D0 - objects) *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record _IsHCat T of HPreCat T := { - is_hcat : PreCat_IsCat (transpose T) }. -#[short(type="hcat")] -HB.structure Definition HCat : Set := - { C of PreCat_IsCat (transpose C) }. -Set Universe Checking. - - -(** Vertical 2-cell level category (D1 category) *) - -(* Precategory based on the DQuiver (i.e. precategory D1). Gives: - vertical 2-cell identity morphism. - vertical 2-cell composition. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record _IsD1PreCat T of DQuiver T := { - is_d1precat : Quiver_IsPreCat (@D1obj T) }. -#[short(type="d1precat")] -HB.structure Definition D1PreCat : Set := - { C of Quiver_IsPreCat (@D1obj C) }. -Set Universe Checking. - -(* The category based on the DQuiver (i.e. category D1). *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record _IsD1Cat T of D1PreCat T := { - is_d1cat : PreCat_IsCat (@D1obj T) }. -#[short(type="d1cat")] -HB.structure Definition D1Cat : Set := - { C of PreCat_IsCat (@D1obj C) }. -Set Universe Checking. - - -(** Naked double category *) - -(* Naked double category. Vertical (V-D0) and D1 categories. Double - category without horizontal operators and functors *) -Unset Universe Checking. -#[short(type="dcat")] -HB.structure Definition DCat : Set := - { C of Cat C & D1Cat C }. -Set Universe Checking. - -(* Naked strict double category. Vertical (V-D0), horizontal (H-D0) - and D1 categories. Strict double category without functors *) -Unset Universe Checking. -#[short(type="sd2cat")] -HB.structure Definition SDCat : Set := { C of Cat C & HCat C & D1Cat C }. -Set Universe Checking. - - -(** Auxiliary notions for Source, Target and - Horizontal Unit functors *) - - - -(* homsets of 2-cell (D1) morphisms *) -Definition d1hom (D: DQuiver.type) : D1obj D -> D1obj D -> U := - @hom (D1obj D). -(* type-level smart constructor for D1 homsets *) -Definition D1hom (D: DQuiver.type) (a b c d: D) (h0: hhom a b) - (h1: hhom c d) : U := d1hom (TT2 h0) (TT2 h1). - -(* smart projections for: - source functor (for horizontal morphisms): D1 -> D0. - defined as object-level function, by functoriality lifted to a - (2-cell, vertical) morphism-level one *) -HB.tag Definition HSource C := fun (X: D1obj C) => @source C (@hhom C) X. -(* target functor (for horizontal morphisms): D1 -> D0. *) -HB.tag Definition HTarget C := fun (X: D1obj C) => @target C (@hhom C) X. - -(* horizontal unit functor: D0 -> D1 *) -Definition hhunit (T: hprecat) (a: T) : D1obj T := - @TT2 T (@hhom T) a a (@idmap (transpose T) a). -HB.tag Definition H1Unit (C: hprecat) := - fun (x: HPreCat.sort C) => @hhunit C x. - - -(** Auxiliary notions for 2-cell Horizontal Composition functor *) - -(* composable pairs of morphisms as a set *) -Record GenComp T (h: T -> T -> U) := GC { - h_one : T; - h_two : T ; - h_three : T; - h_first : h h_one h_two ; - h_second : h h_two h_three }. - -(* composable pairs of horizontal morphisms as a set *) -HB.tag Definition DPobj (C: vhquiver) := GenComp (@hhom C). - -(* smart projections *) -Definition H2First (C: vhquiver) (X: @DPobj C) : D1obj C := - @TT2 C _ (h_one X) (h_two X) (h_first X). -Definition H2Second (C: vhquiver) (X: @DPobj C) : D1obj C := - @TT2 C _ (h_two X) (h_three X) (h_second X). - - -(* horizontal composition functor: D1 * D1 -> D1 *) -Definition hhcomp (T: hprecat) (x: DPobj T) : D1obj T := - match x with - @GC _ _ a b c h1 h2 => @TT2 T (@hhom T) a c (h1 \; h2) end. -HB.tag Definition H1Comp (C: hprecat) := - fun (x: DPobj C) => @hhcomp C x. - -(* hhunit - horizontal unit functor. - - hhcomp - horizontal composition functor (horizontal composition of - two horizontal morphisms from a cell product). - - Both specified as object-level functions (they actually come for - free from the H-D0 category, since we are in the strict case), to - be lifted by functoriality to morphism-level ones. - - At the object level, hhunit gives a horizontal identity morphism - for each D0 object. At the morphism level, it gives horizontal - 2-cell identity for each vertical morphism. - - In the case of hhcomp, relying on functoriality requires some care - in defining the product category, making sure that adjacency at the - object-level (between horizontal morphisms) is matched by adjacency - at the morphism-level (between 2-cells). *) - - -(** Source and target functors *) - -(* source prefunctor. - D1obj T is the quiver of the 2-morphisms, thanks to VHQuiver. - T is the quiver of 1-morphisms. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsSPreFunctor T of DCat T := { - is_sprefunctor : IsPreFunctor (D1obj T) T (@HSource T) }. -HB.structure Definition SPreFunctor : Set := {C of IsSPreFunctor C}. -Set Universe Checking. - -(* target prefunctor. *) -Unset Universe Checking. -#[wrapper] - HB.mixin Record IsTPreFunctor T of DCat T := { - is_tprefunctor : IsPreFunctor (D1obj T) T (@HTarget T) }. -HB.structure Definition TPreFunctor : Set := {C of IsTPreFunctor C}. -Set Universe Checking. - -(* source functor. *) -Unset Universe Checking. -#[wrapper] - HB.mixin Record SPreFunctor_IsFunctor T of SPreFunctor T := { - is_sfunctor : PreFunctor_IsFunctor (D1obj T) T (@HSource T) }. -HB.structure Definition SFunctor : Set := {C of SPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* target functor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record TPreFunctor_IsFunctor T of TPreFunctor T := { - is_tfunctor : PreFunctor_IsFunctor (D1obj T) T (@HTarget T) }. -HB.structure Definition TFunctor : Set := {C of TPreFunctor_IsFunctor C}. -Set Universe Checking. - - -(** Unit functor *) - -(* unit prefunctor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsUPreFunctor T of SDCat T := - { is_uprefunctor : IsPreFunctor T (D1obj T) (@H1Unit T) }. -HB.structure Definition UPreFunctor : Set := {C of IsUPreFunctor C}. -Set Universe Checking. - -(* unit functor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record UPreFunctor_IsFunctor T of UPreFunctor T := { - is_ufunctor : PreFunctor_IsFunctor T (D1obj T) (@H1Unit T) }. -HB.structure Definition UFunctor : Set := {C of UPreFunctor_IsFunctor C}. -Set Universe Checking. - -Unset Universe Checking. -HB.about Functor. -HB.structure Definition STUFunctor : Set := - {C of SFunctor C & TFunctor C & UFunctor C}. -Set Universe Checking. - - -(** Lifting of Source, Target and Unit functors to D1 morphisms *) - -(* 2-cell source *) -Definition H1Source (T: SFunctor.type) (a b: @D1obj T) - (m: @d1hom T a b) : - (HSource a) ~> (HSource b) := (@HSource T) <$> m. - -(* 2-cell target *) -Definition H1Target (T: TFunctor.type) (a b: @D1obj T) - (m: @d1hom T a b) : - (HTarget a) ~> (HTarget b) := (@HTarget T) <$> m. - -(* horizontal 2-cell unit (maps vertical morphisms to horizontally - unitary 2-cells) *) -Definition H2Unit (T: UFunctor.type) (a b: T) (m: @hom T a b) : - (H1Unit a) ~> (H1Unit b) := (@H1Unit T) <$> m. - - -(** Horizontal product category (D1 *d0 D1) *) -(* DPobj T is the pseudo-pullback category used to deal with - products of D1 (where the adjacency condition is expressed - w.r.t. D0 *) - -(* horizontal composition of two (naked) horizontal morphisms *) -Definition l_hcomp (T: SDCat.type) (a0 a1 a2: T) - (h0: hhom a0 a1) (h1: hhom a1 a2) : D1obj T := - @TT2 T _ a0 a2 (h0 \; h1). - -Notation "'sigma' x .. y , p" := - (sigT (fun x => .. (sigT (fun y => p)) ..)) - (at level 200, x binder, right associativity, - format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") - : type_scope. - -(** DPobj quiver *) -Definition DP_hom (T: STUFunctor.type) (x y: DPobj T) := - sigma (hh0: D1hom (h_first x) (h_first y)) - (hh1: D1hom (h_second x) (h_second y)), - H1Target hh0 = H1Source hh1. - -HB.instance Definition DPQuiver (T: STUFunctor.type) : - IsQuiver (DPobj T) := - IsQuiver.Build (DPobj T) (fun A B => @DP_hom T A B). - - -(** Product precategory *) - -Lemma DP_id_eq (T : STUFunctor.type) (a: DPobj T) : - H1Target (@idmap (@D1obj T) (H2First a)) = - H1Source (@idmap (@D1obj T) (H2Second a)). -unfold H1Target, HTarget. -unfold H1Source, HSource. -repeat rewrite F1; auto. -Defined. - -(* DPobj identity *) -Definition DP_id (T: STUFunctor.type) (A: DPobj T) : A ~> A := - let h0 := h_first A - in let h1 := h_second A - in let uu0 := @idmap (D1obj T) (TT2 h0) - in let uu1 := @idmap (D1obj T) (TT2 h1) - in @existT (D1hom h0 h0) - (fun hh0: (D1hom h0 h0) => - sigma (hh1 : D1hom h1 h1), H1Target hh0 = H1Source hh1) uu0 - (@existT (D1hom h1 h1) - (fun hh1: (D1hom h1 h1) => H1Target uu0 = H1Source hh1) uu1 - (@DP_id_eq T A)). - -Definition DP_comp_auxA (T : STUFunctor.type) - (A B C : DPobj T) - (hhA0 : D1hom (h_first A) (h_first B)) - (hhA1 : D1hom (h_second A) (h_second B)) - (ppA : H1Target hhA0 = H1Source hhA1) - (hhB0 : D1hom (h_first B) (h_first C)) - (hhB1 : D1hom (h_second B) (h_second C)) - (ppB : H1Target hhB0 = H1Source hhB1) : - (H1Target hhA0) \; (H1Target hhB0) = - (H1Source hhA1) \; (H1Source hhB1). - rewrite ppA. - rewrite ppB. - reflexivity. -Defined. - -Definition DP_comp_auxS (T : STUFunctor.type) - (A B C : DPobj T) - (hhA0 : D1hom (h_first A) (h_first B)) - (hhA1 : D1hom (h_second A) (h_second B)) - (ppA : H1Target hhA0 = H1Source hhA1) - (hhB0 : D1hom (h_first B) (h_first C)) - (hhB1 : D1hom (h_second B) (h_second C)) - (ppB : H1Target hhB0 = H1Source hhB1) : - H1Source (hhA1 \; hhB1) = (H1Source hhA1) \; (H1Source hhB1). - unfold H1Source, HSource. - repeat rewrite Fcomp. - reflexivity. -Defined. - -Definition DP_comp_auxT (T : STUFunctor.type) - (A B C : DPobj T) - (hhA0 : D1hom (h_first A) (h_first B)) - (hhA1 : D1hom (h_second A) (h_second B)) - (ppA : H1Target hhA0 = H1Source hhA1) - (hhB0 : D1hom (h_first B) (h_first C)) - (hhB1 : D1hom (h_second B) (h_second C)) - (ppB : H1Target hhB0 = H1Source hhB1) : - H1Target (hhA0 \; hhB0) = (H1Target hhA0) \; (H1Target hhB0). - unfold H1Target, HTarget. - repeat rewrite Fcomp. - reflexivity. -Defined. - -Definition DP_comp_auxI (T : STUFunctor.type) - (A B C : DPobj T) - (hhA0 : D1hom (h_first A) (h_first B)) - (hhA1 : D1hom (h_second A) (h_second B)) - (ppA : H1Target hhA0 = H1Source hhA1) - (hhB0 : D1hom (h_first B) (h_first C)) - (hhB1 : D1hom (h_second B) (h_second C)) - (ppB : H1Target hhB0 = H1Source hhB1) : - A ~> C. - econstructor 1 with (comp hhA0 hhB0). - econstructor 1 with (comp hhA1 hhB1). - setoid_rewrite DP_comp_auxS; eauto. - setoid_rewrite DP_comp_auxT; eauto. - eapply DP_comp_auxA; eauto. -Defined. - -(* DPobj composition, defined in proof mode *) -Definition DP_comp (T: STUFunctor.type) (A B C: DPobj T) : - (A ~> B) -> (B ~> C) -> A ~> C. - intros chA chB. - destruct chA as [hhA0 [hhA1 ppA]]. - destruct chB as [hhB0 [hhB1 ppB]]. - eapply DP_comp_auxI; eauto. -Defined. - -(* DPobj is a precategory *) -HB.instance Definition DPPreCat (T: STUFunctor.type) : - Quiver_IsPreCat (DPobj T) := - Quiver_IsPreCat.Build (DPobj T) (@DP_id T) (@DP_comp T). - -(* - have HcompP : - (a b : DPobj T) - (f g : a ~> b), - proj1T f = proj1t f -> - - -> - f = g. - - exists a b p, - fst f = a - f = (a,b,p) -*) - -(** Product category *) - -Lemma DP_LeftUnit_lemma (T : STUFunctor.type) : - forall (a b : DPobj T) (f : a ~> b), idmap \; f = f. - - move => a b [x [x0 e]] /=. - simpl in *. - unfold idmap; simpl. - unfold DP_id; simpl. - unfold comp; simpl. - unfold DP_comp_auxI; simpl. - - assert (idmap \; x = x) as A. - { rewrite comp1o; auto. } - - assert (idmap \; x0 = x0) as A0. - { rewrite comp1o; auto. } - - assert (H1Target (idmap \; x) = H1Source (idmap \; x0)) as B. - { rewrite A. - rewrite A0; auto. } - - destruct a eqn: aaa. - destruct b eqn: bbb. - simpl. - - assert (existT - (fun hh0 : D1hom h_first0 h_first1 => - sigma hh1 : D1hom h_second0 h_second1,H1Target hh0 = H1Source hh1) - (idmap \; x) - (existT - (fun hh1 : D1hom h_second0 h_second1 => - H1Target (idmap \; x) = H1Source hh1) - (idmap \; x0) - B) = - existT - (fun hh0 : D1hom h_first0 h_first1 => - sigma hh1 : D1hom h_second0 h_second1,H1Target hh0 = H1Source hh1) - x - (existT - (fun hh1 : D1hom h_second0 h_second1 => H1Target x = H1Source hh1) - x0 - e)) as C. - { revert B. - revert A. - revert A0. - generalize (idmap \; x) as v. - generalize (idmap \; x0) as v0. - intros v0 v A0. - rewrite A0. - intro A. - rewrite A. - intro B. - - assert (B = e) as BE. - { eapply Prop_irrelevance. } - - rewrite BE. - reflexivity. -} - - inversion aaa; subst. - rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] - (Prop_irrelevance _ B). - eapply C. -Qed. - -Lemma DP_RightUnit_lemma (T : STUFunctor.type) : - forall (a b : DPobj T) (f : a ~> b), f \; idmap = f. - - move => a b [x [x0 e]] /=. - simpl in *. - unfold idmap; simpl. - unfold DP_id; simpl. - unfold comp; simpl. - unfold DP_comp_auxI; simpl. - - assert (x \; idmap = x) as A. - { rewrite compo1; auto. } - - assert (x0 \; idmap = x0) as A0. - { rewrite compo1; auto. } - - assert (H1Target (x \; idmap) = H1Source (x0 \; idmap)) as B. - { rewrite A. - rewrite A0; auto. } - - destruct a eqn: aaa. - destruct b eqn: bbb. - simpl. - - assert (existT - (fun hh0 : D1hom h_first0 h_first1 => - sigma hh1 : D1hom h_second0 h_second1, - H1Target hh0 = H1Source hh1) - (x \; idmap) - (existT - (fun hh1 : D1hom h_second0 h_second1 => - H1Target (x \; idmap) = H1Source hh1) - (x0 \; idmap) - B) = - existT - (fun hh0 : D1hom h_first0 h_first1 => - sigma hh1 : D1hom h_second0 h_second1, - H1Target hh0 = H1Source hh1) - x - (existT - (fun hh1 : D1hom h_second0 h_second1 => - H1Target x = H1Source hh1) - x0 - e)) as C. - { revert B. - revert A. - revert A0. - generalize (x \; idmap) as v. - generalize (x0 \; idmap) as v0. - intros v0 v A0. - rewrite A0. - intro A. - rewrite A. - intro B. - - assert (B = e) as BE. - { eapply Prop_irrelevance. } - - rewrite BE. - reflexivity. - } - - inversion aaa; subst. - rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] - (Prop_irrelevance _ B). - eapply C. -Qed. - -Lemma DP_Assoc_lemma (T : STUFunctor.type) : - forall (a b c d : DPobj T) (f : a ~> b) (g : b ~> c) (h : c ~> d), - f \; g \; h = (f \; g) \; h. - intros. - remember f as f1. - remember g as g1. - remember h as h1. - destruct f as [x0 s0]. - destruct g as [x1 s1]. - destruct h as [x2 s2]. - destruct s0 as [y0 e0]. - destruct s1 as [y1 e1]. - destruct s2 as [y2 e2]. - simpl. - - set (x01 := comp x0 x1). - set (x12 := comp x1 x2). - set (x0_12 := comp x0 x12). - set (x01_2 := comp x01 x2). - set (y01 := comp y0 y1). - set (y12 := comp y1 y2). - set (y0_12 := comp y0 y12). - set (y01_2 := comp y01 y2). - - assert (x0_12 = x01_2) as X0. - { subst x0_12 x01_2. - rewrite compoA; eauto. } - assert (y0_12 = y01_2) as Y0. - { subst y0_12 y01_2. - rewrite compoA; eauto. } - - set (x01_t := comp (H1Target x0) (H1Target x1)). - set (x01_2_t := comp x01_t (H1Target x2)). - set (x12_t := comp (H1Target x1) (H1Target x2)). - set (x0_12_t := comp (H1Target x0) x12_t). - set (y01_s := comp (H1Source y0) (H1Source y1)). - set (y01_2_s := comp y01_s (H1Source y2)). - set (y12_s := comp (H1Source y1) (H1Source y2)). - set (y0_12_s := comp (H1Source y0) y12_s). - - assert (x01_t = y01_s) as E01. - { subst x01_t y01_s. - rewrite e0. - rewrite e1; auto. } - assert (x01_2_t = y01_2_s) as E01_2. - { subst x01_2_t y01_2_s. - rewrite E01. - rewrite e2; auto. } - assert (x12_t = y12_s) as E12. - { subst x12_t y12_s. - rewrite e1. - rewrite e2; auto. } - assert (x0_12_t = y0_12_s) as E0_12. - { subst x0_12_t y0_12_s. - rewrite E12. - rewrite e0; auto. } - - assert (x0_12_t = x01_2_t) as E02T. - { subst x0_12_t x01_2_t. - subst x12_t x01_t. - rewrite compoA; auto. } - assert (y0_12_s = y01_2_s) as E02S. - { subst y0_12_s y01_2_s. - subst y12_s y01_s. - rewrite compoA; auto. } - - unfold comp. - simpl. - unfold DP_comp. - simpl. - inversion Heqf1; subst. - clear H. - - unfold DP_comp_auxI; simpl. - - assert (H1Target (x0 \; x1 \; x2) = - H1Source (y0 \; y1 \; y2)) as KR. - { subst x0_12_t y0_12_s. - subst x12_t y12_s. - unfold H1Target. - repeat rewrite Fcomp; simpl. - unfold H1Target in E0_12. - rewrite E0_12. - unfold H1Source. - repeat rewrite Fcomp; simpl. - auto. - } - - assert (H1Target ((x0 \; x1) \; x2) = - H1Source ((y0 \; y1) \; y2)) as KL. - { subst x01_2_t y01_2_s. - subst x01_t y01_s. - unfold H1Target. - repeat rewrite Fcomp; simpl. - unfold H1Target in E01_2. - rewrite E01_2. - unfold H1Source. - repeat rewrite Fcomp; simpl. - auto. - } - - assert (existT - (fun hh0 : D1hom (h_first a) (h_first d) => - sigma hh1 : D1hom (h_second a) (h_second d), - H1Target hh0 = H1Source hh1) - (x0 \; x1 \; x2) - (existT - (fun hh1 : D1hom (h_second a) (h_second d) => - H1Target (x0 \; x1 \; x2) = H1Source hh1) - (y0 \; y1 \; y2) - KR) - = - existT - (fun hh0 : D1hom (h_first a) (h_first d) => - sigma hh1 : D1hom (h_second a) (h_second d), - H1Target hh0 = H1Source hh1) - ((x0 \; x1) \; x2) - (existT - (fun hh1 : D1hom (h_second a) (h_second d) => - H1Target ((x0 \; x1) \; x2) = H1Source hh1) - ((y0 \; y1) \; y2) - KL)) as KA. - { revert KL. - revert KR. - subst x0_12 x01_2 x12 x01. - subst y0_12 y01_2 y12 y01. - rewrite <- X0. - rewrite <- Y0. - intros KR KL. - - assert (KR = KL) as I1. - { eapply Prop_irrelevance. } - rewrite I1. - reflexivity. - } - - rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] - (Prop_irrelevance _ KR). - - rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] - (Prop_irrelevance _ KL). - eapply KA. -Qed. - -Program Definition DPCatP (T: STUFunctor.type) : - PreCat_IsCat (DPobj T). -econstructor. -eapply DP_LeftUnit_lemma; eauto. -eapply DP_RightUnit_lemma; eauto. -eapply DP_Assoc_lemma; eauto. -Qed. - -(* DPobj is a category *) -HB.instance Definition DPCat (T: STUFunctor.type) := DPCatP T. - - -(** Horizontal composition functor and strict double categories *) - -(* composition prefunctor *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsCPreFunctor T of STUFunctor T := - { is_cprefunctor : IsPreFunctor (DPobj T) (D1obj T) (@H1Comp T) }. -HB.structure Definition CPreFunctor : Set := {C of IsCPreFunctor C}. -Set Universe Checking. - -(* composition functor - gives the definition of Strict Double Category *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record CPreFunctor_IsFunctor T of CPreFunctor T := { - is_cfunctor : PreFunctor_IsFunctor (DPobj T) (D1obj T) (@H1Comp T) }. -#[short(type="sdoublecat")] -HB.structure Definition SDoubleCat : Set := {C of CPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* horizontal 2-cell composition: maps two adjecent pairs of - horizontal morphisms (a and b) and a pullback-category morphism - between them (m, which basically gives two adjecent cells) to a - 2-cell morphism between the horizontal composition (HComp) of each - pair *) -Definition HC2Comp (T: SDoubleCat.type) (a b: DPobj T) - (m: @hom (DPobj T) a b) : - d1hom (H1Comp a) (H1Comp b) := @Fhom _ _ (@H1Comp T) a b m. - -Program Definition HC2Comp_flat (T: SDoubleCat.type) (a0 a1 a2 b0 b1 b2: T) - (h0: hhom a0 a1) (h1: hhom a1 a2) - (k0: hhom b0 b1) (k1: hhom b1 b2) - (hh0: D1hom h0 k0) - (hh1: D1hom h1 k1) - (k: H1Target hh0 = H1Source hh1) - : (* D1hom (hcomp _ _ _ h0 h1) (hcomp _ _ _ k0 k1) *) - d1hom (l_hcomp h0 h1) (l_hcomp k0 k1) := - @Fhom _ _ (@H1Comp T) (GC h0 h1) (GC k0 k1) _. -Obligation 1. -refine (@existT (D1hom h0 k0) _ hh0 (@existT (D1hom h1 k1) _ hh1 k)). -Defined. - -(********************************************************************) -(********************************************************************) - - -Section th_of_pb. -Variables (Q : cat) (A B C D E F : Q). -Variables (f : A ~> D) (g : B ~> D) (h : C ~> A). -Variables (u : E ~> A) (v : E ~> B) (w : F ~> C) (z : F ~> E). -Variable (uvfg : pbsquare u v f g). - -Set Printing Width 50. -Theorem pbsquarec_compP : - pbsquare w z h u <=> pbsquare w (z \; v) (h \; f) g. -Proof. -split=> [] sq. - - have @sq_ispb : pullback (Cospan h u) := HB.pack (Span w z) sq. - have @uvfg_ispb : pullback (Cospan f g) := HB.pack (Span u v) uvfg. - have /=E2 := @is_square _ _ _ _ sq_ispb. - have /=E1 := @is_square _ _ _ _ uvfg_ispb. - - have p1 : @isPrePullback Q C B (Cospan (h \; f) g) (Span w (z \; v)). - by constructor; rewrite /= compoA E2 -compoA E1 compoA. - pose big_black_square : prepullback (Cospan (h \; f) g) := - HB.pack (Span w (z \; v)) p1. - - have @from : forall - (big_red_square : prepullback {| top := D; left2top := h \; f; right2top := g |}), - big_red_square ~> pb_terminal big_black_square. - - move=> big_red_square; unfold pb_terminal. - - have /= := @is_square _ _ _ _ big_red_square. - - pose F' := bot big_red_square. - set w' : F' ~> C := bot2left big_red_square. - set z' : F' ~> B := bot2right big_red_square. - move=> E3. - - have xxx : isPrePullback Q A B (Cospan f g) (Span (w' \; h) z'). - by constructor=> /=; rewrite -compoA E3. - pose red_black_square : prepullback (Cospan f g) := - HB.pack (Span (w' \; h) z') xxx. - have := @from_unique _ (pb_terminal uvfg_ispb) red_black_square. - set blue := @from _ (pb_terminal uvfg_ispb) red_black_square. - move=> blue_unique. - - have p3 : @isPrePullback Q C E (Cospan h u) (Span w' (bot_map blue)). - by constructor; rewrite /= (bot2left_map blue). (* buggy unifier without blue *) - pose blue_red_black_square : prepullback (Cospan h u) := - HB.pack (Span w' (bot_map blue)) p3. - - pose red := @from _ (pb_terminal sq_ispb) blue_red_black_square. - - admit. - - - - have p2 : prepullback_isTerminal.axioms_ Q C B (Cospan (h \; f) g) (Span w (z \; v)) p1. - constructor. econstructor=> /=. - admit. - - by HB.from p1 p2. - -Admitted. - -End th_of_pb. - - -Module test. - -Section test. -Variables (Q : precat) (A B : Q) (c : cospan A B). -Variable (p : pullback c). -Check pb_terminal p : terminal _. - -End test. -End test. - - - - diff --git a/theories/encatD1.v b/theories/encatD1.v deleted file mode 100644 index 7f957d9ab..000000000 --- a/theories/encatD1.v +++ /dev/null @@ -1,2587 +0,0 @@ -Require Import Coq.Program.Equality. -Require Import ssreflect ssrfun. -From HB Require Import structures. - -Set Implicit Arguments. -Unset Strict Implicit. -Unset Printing Implicit Defensive. -Add Search Blacklist "__canonical__". - -Declare Scope algebra_scope. -Delimit Scope algebra_scope with A. -Local Open Scope algebra_scope. - -Declare Scope cat_scope. -Delimit Scope cat_scope with cat. -Local Open Scope cat_scope. - -(* we assume a few axioms to make life easier *) -Axiom funext : forall {T : Type} {U : T -> Type} [f g : forall t, U t], - (forall t, f t = g t) -> f = g. -Axiom propext : forall P Q : Prop, P <-> Q -> P = Q. -Axiom Prop_irrelevance : forall (P : Prop) (x y : P), x = y. - -(* Shortcut *) -Notation U := Type. - -(* Base definition : raw categories = quivers *) -HB.mixin Record IsQuiver C := { hom : C -> C -> U }. -Unset Universe Checking. -#[short(type="quiver")] -HB.structure Definition Quiver : Set := { C of IsQuiver C }. -Set Universe Checking. - -Bind Scope cat_scope with quiver. -Bind Scope cat_scope with hom. -Arguments hom {C} : rename. -Notation homs T := (@hom T _ _). -Notation "a ~> b" := (hom a b) - (at level 99, b at level 200, format "a ~> b") : cat_scope. -Notation "a ~>_ C b" := (@hom C (a : C) (b : C)) - (at level 99, C at level 0, only parsing) : cat_scope. - -(* precategories are quivers + id and comp *) -HB.mixin Record Quiver_IsPreCat C of Quiver C := { - idmap : forall (a : C), a ~> a; - comp : forall (a b c : C), (a ~> b) -> (b ~> c) -> (a ~> c); -}. - -HB.factory Record IsPreCat C := { - hom : C -> C -> U; - idmap : forall (a : C), hom a a; - comp : forall (a b c : C), hom a b -> hom b c -> hom a c; -}. -HB.builders Context C of IsPreCat C. - HB.instance Definition _ := IsQuiver.Build C hom. - HB.instance Definition _ := Quiver_IsPreCat.Build C idmap comp. -HB.end. - -Unset Universe Checking. -#[short(type="precat")] -HB.structure Definition PreCat : Set := { C of IsPreCat C }. -Set Universe Checking. - -Bind Scope cat_scope with precat. -Arguments idmap {C} {a} : rename. -Arguments comp {C} {a b c} : rename. -Notation "f \o g" := (comp g f) : cat_scope. -Notation "f \; g :> T" := (@comp T _ _ _ f g) - (at level 60, g, T at level 60, format "f \; g :> T", only parsing) : cat_scope. -Notation "f \; g" := (comp f g) : cat_scope. -Notation "\idmap_ a" := (@idmap _ a) (only parsing, at level 0) : cat_scope. - -(* categories are precategories + laws *) -HB.mixin Record PreCat_IsCat C of PreCat C := { - comp1o : forall (a b : C) (f : a ~> b), idmap \; f = f; - compo1 : forall (a b : C) (f : a ~> b), f \; idmap = f; - compoA : forall (a b c d : C) (f : a ~> b) (g : b ~> c) (h : c ~> d), - f \; (g \; h) = (f \; g) \; h -}. -Unset Universe Checking. -#[short(type="cat")] -HB.structure Definition Cat : Set := { C of PreCat_IsCat C & IsPreCat C }. -Set Universe Checking. - -Bind Scope cat_scope with cat. -Arguments compo1 {C a b} : rename. -Arguments comp1o {C a b} : rename. -Arguments compoA {C a b c d} : rename. - -(* the discrete category on a type cannot be the default, we make an alias *) -Definition discrete (T : U) := T. -HB.instance Definition _ T := @IsPreCat.Build (discrete T) (fun x y => x = y) - (fun=> erefl) (@etrans _). -Lemma etransA T (a b c d : discrete T) (f : a ~> b) (g : b ~> c) (h : c ~> d) : - f \; (g \; h) = (f \; g) \; h. -Proof. by rewrite /idmap/comp/=; case: _ / h; case: _ / g. Qed. -HB.instance Definition _ T := PreCat_IsCat.Build (discrete T) (@etrans_id _) - (fun _ _ _ => erefl) (@etransA _). - -(* the category of the unit type is the discrete one *) -HB.instance Definition _ := Cat.copy unit (discrete unit). - -HB.instance Definition _ := @IsPreCat.Build U (fun A B => A -> B) - (fun a => idfun) (fun a b c (f : a -> b) (g : b -> c) => (g \o f)%FUN). -HB.instance Definition _ := PreCat_IsCat.Build U (fun _ _ _ => erefl) - (fun _ _ _ => erefl) (fun _ _ _ _ _ _ _ => erefl). - - -Lemma Ucomp (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) : f \; g = (g \o f)%FUN. -Proof. by []. Qed. -Lemma Ucompx (X Y Z : U) (f : X ~> Y) (g : Y ~> Z) x : (f \; g) x = g (f x). -Proof. by []. Qed. -Lemma U1 (X : U) : \idmap_X = idfun. -Proof. by []. Qed. -Lemma U1x (X : U) x : \idmap_X x = x. -Proof. by []. Qed. - -(* a prefunctor is a functor without laws *) -HB.mixin Record IsPreFunctor (C D : quiver) (F : C -> D) := { - Fhom : forall (a b : C), (a ~> b) -> (F a ~> F b) -}. - -Unset Universe Checking. -HB.structure Definition PreFunctor (C D : quiver) : Set := - { F of IsPreFunctor C D F }. -Set Universe Checking. -HB.instance Definition _ := IsQuiver.Build quiver PreFunctor.type. - -Notation "F ^$" := (@Fhom _ _ F _ _) - (at level 1, format "F ^$") : cat_scope. -Notation "F <$> f" := (@Fhom _ _ F _ _ f) - (at level 58, format "F <$> f", right associativity) : cat_scope. - -(* prefunctors are equal if their object and hom part are respectively equal *) -Lemma prefunctorP (C D : quiver) (F G : C ~> D) (eqFG : F =1 G) : - let homF a b F := F a ~> F b in - (forall a b f, eq_rect _ (homF a b) (F <$> f) _ (funext eqFG) = G <$> f) -> - F = G. -Proof. -move: F G => [F [[/= Fhom]]] [G [[/= Ghom]]] in eqFG *. -case: _ / (funext eqFG) => /= in Ghom * => eqFGhom. -congr PreFunctor.Pack; congr PreFunctor.Class; congr IsPreFunctor.Axioms_. -by do 3!apply: funext=> ?. -Qed. - -(* a functor is a prefunctor + laws for id and comp *) -HB.mixin Record PreFunctor_IsFunctor (C D : precat) (F : C -> D) - of @PreFunctor C D F := { - F1 : forall (a : C), F <$> \idmap_a = idmap; - Fcomp : forall (a b c : C) (f : a ~> b) (g : b ~> c), - F <$> (f \; g) = F <$> f \; F <$> g; -}. -Unset Universe Checking. - -(* precat and cat have a quiver structure *) -HB.structure Definition Functor (C D : precat) : Set := - { F of IsPreFunctor C D F & PreFunctor_IsFunctor C D F }. -Set Universe Checking. -HB.instance Definition _ := IsQuiver.Build precat Functor.type. -HB.instance Definition _ := IsQuiver.Build cat Functor.type. - -(* functor equality is the same as prefunctor because of PI *) -Lemma functorP (C D : precat) (F G : C ~> D) (eqFG : F =1 G) : - let homF a b F := F a ~> F b in - (forall a b f, eq_rect _ (homF a b) (F^$ f) _ (funext eqFG) = G^$ f) -> - F = G. -Proof. -move=> /= /prefunctorP {eqFG}. -case: F G => [F [/= Fm Fm']] [G [/= Gm Gm']]//=. -move=> [_] /EqdepFacts.eq_sigT_iff_eq_dep eqFG. -case: _ / eqFG in Gm' *. -congr Functor.Pack; congr Functor.Class. -case: Fm' Gm' => [F1 Fc] [G1 Gc]. -by congr PreFunctor_IsFunctor.Axioms_; apply: Prop_irrelevance. -Qed. - -(* the identity function is a functor *) -HB.instance Definition _ (C : quiver) := - IsPreFunctor.Build C C idfun (fun a b => idfun). -HB.instance Definition _ (C : precat) := - PreFunctor_IsFunctor.Build C C idfun (fun=> erefl) (fun _ _ _ _ _ => erefl). - -(* the composition of prefunctors *) -Section comp_prefunctor. -Context {C D E : quiver} {F : C ~> D} {G : D ~> E}. - -HB.instance Definition _ := IsPreFunctor.Build C E (G \o F)%FUN - (fun a b f => G <$> F <$> f). -Lemma comp_Fun (a b : C) (f : a ~> b) : (G \o F)%FUN <$> f = G <$> (F <$> f). -Proof. by []. Qed. -End comp_prefunctor. - -Section comp_functor. -Context {C D E : precat} {F : C ~> D} {G : D ~> E}. -Lemma comp_F1 (a : C) : (G \o F)%FUN <$> \idmap_a = idmap. -Proof. by rewrite !comp_Fun !F1. Qed. -Lemma comp_Fcomp (a b c : C) (f : a ~> b) (g : b ~> c) : - (G \o F)%FUN <$> (f \; g) = (G \o F)%FUN <$> f \; (G \o F)%FUN <$> g. -Proof. by rewrite !comp_Fun !Fcomp. Qed. -HB.instance Definition _ := PreFunctor_IsFunctor.Build C E (G \o F)%FUN - comp_F1 comp_Fcomp. -End comp_functor. - -(* precat and cat have a precategory structure *) -HB.instance Definition _ := Quiver_IsPreCat.Build precat - (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). -HB.instance Definition _ := Quiver_IsPreCat.Build cat - (fun=> idfun) (fun C D E (F : C ~> D) (G : D ~> E) => (G \o F)%FUN). - -Lemma funext_frefl A B (f : A -> B) : funext (frefl f) = erefl. -Proof. exact: Prop_irrelevance. Qed. - -(* precategories and categories form a category *) -Definition precat_cat : PreCat_IsCat precat. -Proof. -by split=> [C D F|C D F|C D C' D' F G H]; - apply/functorP => a b f /=; rewrite funext_frefl. -Qed. -HB.instance Definition _ := precat_cat. -Definition cat_cat : PreCat_IsCat cat. -Proof. -by split=> [C D F|C D F|C D C' D' F G H]; - apply/functorP => a b f /=; rewrite funext_frefl. -Qed. -HB.instance Definition _ := cat_cat. - -Check (cat : cat). - -(* concrete categories *) -HB.mixin Record Quiver_IsPreConcrete T of Quiver T := { - concrete : T -> U; - concrete_fun : forall (a b : T), (a ~> b) -> concrete a -> concrete b; -}. -Unset Universe Checking. -#[short(type="preconcrete_quiver")] -HB.structure Definition PreConcreteQuiver : Set := - { C of Quiver_IsPreConcrete C & IsQuiver C }. -Set Universe Checking. -Coercion concrete : PreConcreteQuiver.sort >-> Sortclass. - -HB.mixin Record PreConcrete_IsConcrete T of PreConcreteQuiver T := { - concrete_fun_inj : forall (a b : T), injective (concrete_fun a b) -}. -Unset Universe Checking. -#[short(type="concrete_quiver")] -HB.structure Definition ConcreteQuiver : Set := - { C of PreConcreteQuiver C & PreConcrete_IsConcrete C }. -Set Universe Checking. - -HB.instance Definition _ (C : ConcreteQuiver.type) := - IsPreFunctor.Build _ _ (concrete : C -> U) concrete_fun. - -HB.mixin Record PreCat_IsConcrete T of ConcreteQuiver T & PreCat T := { - concrete1 : forall (a : T), concrete <$> \idmap_a = idfun; - concrete_comp : forall (a b c : T) (f : a ~> b) (g : b ~> c), - concrete <$> (f \; g) = ((concrete <$> g) \o (concrete <$> f))%FUN; -}. -Unset Universe Checking. -#[short(type="concrete_precat")] -HB.structure Definition ConcretePreCat : Set := - { C of PreCat C & ConcreteQuiver C & PreCat_IsConcrete C }. -#[short(type="concrete_cat")] -HB.structure Definition ConcreteCat : Set := - { C of Cat C & ConcreteQuiver C & PreCat_IsConcrete C }. -Set Universe Checking. - -HB.instance Definition _ (C : concrete_precat) := - PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). -HB.instance Definition _ (C : ConcreteCat.type) := - PreFunctor_IsFunctor.Build C U concrete (@concrete1 _) (@concrete_comp _). - -HB.instance Definition _ := Quiver_IsPreConcrete.Build U (fun _ _ => id). -HB.instance Definition _ := PreConcrete_IsConcrete.Build U (fun _ _ _ _ => id). -HB.instance Definition _ := PreCat_IsConcrete.Build U - (fun=> erefl) (fun _ _ _ _ _ => erefl). - -Unset Universe Checking. -HB.instance Definition _ := Quiver_IsPreConcrete.Build quiver (fun _ _ => id). -HB.instance Definition _ := Quiver_IsPreConcrete.Build precat (fun _ _ => id). -HB.instance Definition _ := Quiver_IsPreConcrete.Build cat (fun _ _ => id). -Lemma quiver_concrete_subproof : PreConcrete_IsConcrete quiver. -Proof. -constructor=> C D F G FG; apply: prefunctorP. - by move=> x; congr (_ x); apply: FG. -by move=> *; apply: Prop_irrelevance. -Qed. -HB.instance Definition _ := quiver_concrete_subproof. - -Lemma precat_concrete_subproof : PreConcrete_IsConcrete precat. -Proof. -constructor=> C D F G FG; apply: functorP. - by move=> x; congr (_ x); apply: FG. -by move=> *; apply: Prop_irrelevance. -Qed. -HB.instance Definition _ := precat_concrete_subproof. - -Lemma cat_concrete_subproof : PreConcrete_IsConcrete cat. -Proof. -constructor=> C D F G FG; apply: functorP. - by move=> x; congr (_ x); apply: FG. -by move=> *; apply: Prop_irrelevance. -Qed. -HB.instance Definition _ := cat_concrete_subproof. -HB.instance Definition _ := PreCat_IsConcrete.Build precat - (fun=> erefl) (fun _ _ _ _ _ => erefl). -HB.instance Definition _ := PreCat_IsConcrete.Build cat - (fun=> erefl) (fun _ _ _ _ _ => erefl). -Set Universe Checking. - -(* constant functor *) -Definition cst (C D : quiver) (c : C) := fun of D => c. -Arguments cst {C} D c. -HB.instance Definition _ {C D : precat} (c : C) := - IsPreFunctor.Build D C (cst D c) (fun _ _ _ => idmap). -HB.instance Definition _ {C D : cat} (c : C) := - PreFunctor_IsFunctor.Build D C (cst D c) (fun=> erefl) - (fun _ _ _ _ _ => esym (compo1 idmap)). - -(* opposite category *) -Definition catop (C : U) : U := C. -Notation "C ^op" := (catop C) - (at level 2, format "C ^op") : cat_scope. -HB.instance Definition _ (C : quiver) := - IsQuiver.Build C^op (fun a b => hom b a). -HB.instance Definition _ (C : precat) := - Quiver_IsPreCat.Build (C^op) (fun=> idmap) (fun _ _ _ f g => g \; f). -HB.instance Definition _ (C : cat) := PreCat_IsCat.Build (C^op) - (fun _ _ _ => compo1 _) (fun _ _ _ => comp1o _) - (fun _ _ _ _ _ _ _ => esym (compoA _ _ _)). - -HB.instance Definition _ {C : precat} {c : C} := - IsPreFunctor.Build C _ (hom c) (fun a b f g => g \; f). -Lemma hom_Fhom_subproof (C : cat) (x : C) : - PreFunctor_IsFunctor _ _ (hom x). -Proof. by split=> *; apply/funext => h; [apply: compo1 | apply: compoA]. Qed. -HB.instance Definition _ {C : cat} {c : C} := hom_Fhom_subproof c. - -Check fun (C : cat) (x : C) => hom x : C ~>_cat U. - -Lemma hom_op {C : quiver} (c : C^op) : hom c = (@hom C)^~ c. -Proof. reflexivity. Qed. - -Lemma homFhomx {C : precat} (a b c : C) (f : a ~> b) (g : c ~> a) : - (hom c <$> f) g = g \; f. -Proof. reflexivity. Qed. - -(* nary product of categories *) -Definition dprod {I : U} (C : I -> U) := forall i, C i. - -Section hom_dprod. -Context {I : U} (C : I -> quiver). -Definition dprod_hom_subdef (a b : dprod C) := forall i, a i ~> b i. -HB.instance Definition _ := IsQuiver.Build (dprod C) dprod_hom_subdef. -End hom_dprod. -Arguments dprod_hom_subdef /. - -Section precat_dprod. -Context {I : U} (C : I -> precat). -Definition dprod_idmap_subdef (a : dprod C) : a ~> a := fun=> idmap. -Definition dprod_comp_subdef (a b c : dprod C) (f : a ~> b) (g : b ~> c) : a ~> c := - fun i => f i \; g i. -HB.instance Definition _ := IsPreCat.Build (dprod C) - dprod_idmap_subdef dprod_comp_subdef. -End precat_dprod. -Arguments dprod_idmap_subdef /. -Arguments dprod_comp_subdef /. - -Section cat_dprod. -Context {I : U} (C : I -> cat). -Local Notation type := (dprod C). -Lemma dprod_is_cat : PreCat_IsCat type. -Proof. -split=> [a b f|a b f|a b c d f g h]; apply/funext => i; -[exact: comp1o | exact: compo1 | exact: compoA]. -Qed. -HB.instance Definition _ := dprod_is_cat. -End cat_dprod. - -(* binary product *) -Section hom_prod. -Context {C D : quiver}. -Definition prod_hom_subdef (a b : C * D) := ((a.1 ~> b.1) * (a.2 ~> b.2))%type. -HB.instance Definition _ := IsQuiver.Build (C * D)%type prod_hom_subdef. -End hom_prod. - -Section precat_prod. -Context {C D : precat}. -HB.instance Definition _ := IsPreCat.Build (C * D)%type (fun=> (idmap, idmap)) - (fun a b c (f : a ~> b) (g : b ~> c) => (f.1 \; g.1, f.2 \; g.2)). -End precat_prod. - -Section cat_prod. -Context {C D : cat}. -Local Notation type := (C * D)%type. -Lemma prod_is_cat : PreCat_IsCat type. -Proof. -split=> [[a1 a2] [b1 b2] [f1 f2]|[a1 a2] [b1 b2] [f1 f2]| - [a1 a2] [b1 b2] [c1 c2] [d1 d2] [f1 f2] [g1 g2] [h1 h2]]; congr (_, _) => //=; -by [exact: comp1o | exact: compo1 | exact: compoA]. -Qed. -HB.instance Definition _ := prod_is_cat. -End cat_prod. - -(* naturality *) -HB.mixin Record IsNatural (C D : precat) (F G : C ~>_quiver D) - (n : forall c, F c ~> G c) := { - natural : forall (a b : C) (f : a ~> b), - F <$> f \; n b = n a \; G <$> f -}. -Unset Universe Checking. -HB.structure Definition Natural (C D : precat) - (F G : C ~>_quiver D) : Set := - { n of @IsNatural C D F G n }. -Set Universe Checking. -HB.instance Definition _ (C D : precat) := - IsQuiver.Build (PreFunctor.type C D) (@Natural.type C D). -HB.instance Definition _ (C D : cat) := - IsQuiver.Build (Functor.type C D) (@Natural.type C D). -Arguments natural {C D F G} n [a b] f : rename. - -Check fun (C D : cat) (F G : C ~> D) => F ~>_(C ~>_cat D) G. - -Lemma naturalx (C : precat) (D : concrete_precat) - (F G : C ~>_quiver D) (n : F ~> G) (a b : C) (f : a ~> b) g : - (concrete <$> n b) ((concrete <$> F <$> f) g) = - (concrete <$> G <$> f) ((concrete <$> n a) g). -Proof. -have /(congr1 (fun h => (concrete <$> h) g)) := natural n f. -by rewrite !Fcomp. -Qed. -Arguments naturalx {C D F G} n [a b] f. - -Lemma naturalU (C : precat) (F G : C ~>_quiver U) (n : F ~> G) - (a b : C) (f : a ~> b) g : n b (F^$ f g) = G^$ f (n a g). -Proof. exact: (naturalx n). Qed. - -Lemma natP (C D : precat) (F G : C ~>_quiver D) (n m : F ~> G) : - Natural.sort n = Natural.sort m -> n = m. -Proof. -case: n m => [/= n nP] [/= m mP] enm. -elim: _ / enm in mP *; congr Natural.Pack. -case: nP mP => [[?]] [[?]]; congr Natural.Class. -congr IsNatural.Axioms_. -exact: Prop_irrelevance. -Qed. - -Notation "F ~~> G" := (F ~>_(homs quiver) G) - (at level 99, G at level 200, format "F ~~> G"). -Notation "F ~~> G :> C ~> D" := (F ~> G :> (C ~>_quiver D)) - (at level 99, G at level 200, C, D at level 0, - format "F ~~> G :> C ~> D"). - -Definition natural_id {C D : precat} (F : C ~>_quiver D) (a : C) := \idmap_(F a). -Definition natural_id_natural (C D : cat) (F : C ~>_quiver D) : - IsNatural C D F F (natural_id F). -Proof. by constructor=> a b f; rewrite /natural_id/= compo1 comp1o. Qed. -HB.instance Definition _ C D F := @natural_id_natural C D F. - -Check fun {C D : cat} (F : C ~>_quiver D) => natural_id F : F ~> F. - -Definition natural_comp {C D : precat} (F G H : C ~>_quiver D) - (m : F ~> G) (n : G ~> H) (a : C) := m a \; n a. -Definition natural_comp_natural (C D : cat) (F G H : C ~>_quiver D) m n : - IsNatural C D F H (@natural_comp C D F G H m n). -Proof. -constructor=> a b f; rewrite /natural_comp/=. -by rewrite compoA natural -compoA natural compoA. -Qed. -HB.instance Definition _ C D F G H m n := @natural_comp_natural C D F G H m n. - -HB.instance Definition _ {C D : cat} := - Quiver_IsPreCat.Build (PreFunctor.type C D) natural_id natural_comp. -HB.instance Definition _ {C D : cat} := - Quiver_IsPreCat.Build (Functor.type C D) natural_id natural_comp. - -Lemma prefunctor_cat {C D : cat} : PreCat_IsCat (PreFunctor.type C D). -Proof. -constructor => [F G f|F G f|F G H J f g h]. -- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. -- by apply/natP/funext => a; rewrite /= /natural_comp compo1. -- by apply/natP/funext => a; rewrite /= /natural_comp compoA. -Qed. -HB.instance Definition _ C D := @prefunctor_cat C D. - -Lemma functor_cat {C D : cat} : PreCat_IsCat (Functor.type C D). -Proof. -constructor => [F G f|F G f|F G H J f g h]. -- by apply/natP/funext => a; rewrite /= /natural_comp comp1o. -- by apply/natP/funext => a; rewrite /= /natural_comp compo1. -- by apply/natP/funext => a; rewrite /= /natural_comp compoA. -Qed. -HB.instance Definition _ C D := @functor_cat C D. - -Section nat_map_left. -Context {C D E : precat} {F G : C ~> D}. - -Definition nat_lmap (H : D ~>_quiver E) (n : forall c, F c ~> G c) : - forall c, (H \o F)%FUN c ~> (H \o G)%FUN c := fun c => H <$> n c. - -Fail Check fun (H : D ~> E) (n : F ~~> G) => nat_lmap H n : H \o F ~~> H \o G. - -Lemma nat_lmap_is_natural (H : D ~> E) (n : F ~~> G) : - IsNatural C E (H \o F) (H \o G) (nat_lmap H n). -Proof. by constructor=> a b f; rewrite /nat_lmap/= -!Fcomp natural. Qed. -HB.instance Definition _ H n := nat_lmap_is_natural H n. - -Check fun (H : D ~> E) (n : F ~~> G) => nat_lmap H n : H \o F ~~> H \o G. - -End nat_map_left. - -Notation "F n" := (nat_lmap F n) - (at level 58, format "F n", right associativity) : cat_scope. - -Section nat_map_right. -Context {C D E : precat} {F G : C ~> D}. - -Definition nat_rmap (H : E -> C) (n : forall c, F c ~> G c) : - forall c, (F \o H)%FUN c ~> (G \o H)%FUN c := fun c => n (H c). -Lemma nat_rmap_is_natural (H : E ~> C :> quiver) (n : F ~~> G) : - IsNatural E D (F \o H)%FUN (G \o H)%FUN (nat_rmap H n). -Proof. by constructor=> a b f; rewrite /nat_lmap/= natural. Qed. -HB.instance Definition _ H n := nat_rmap_is_natural H n. - -End nat_map_right. - -Notation "F <$o> n" := (nat_rmap F n) - (at level 58, format "F <$o> n", right associativity) : cat_scope. - -Definition delta (C D : cat) : C -> (D ~> C) := cst D. -Arguments delta C D : clear implicits. - -Definition map_delta {C D : cat} (a b : C) (f : a ~> b) : - delta C D a ~> delta C D b. -Proof. -apply: (@Natural.Pack _ _ (cst D a) (cst D b) (fun x => f)). -apply: Natural.Class; apply: (IsNatural.Build _ _ _ _ _). -by move=> a' b' ?; rewrite compo1 comp1o. -Defined. - -HB.instance Definition _ {C D : cat} := - IsPreFunctor.Build C (D ~> C) (delta C D) (@map_delta C D). - -Lemma delta_functor {C D : cat} : PreFunctor_IsFunctor _ _ (delta C D). -Proof. by constructor=> [a|a b c f g]; exact/natP. Qed. -HB.instance Definition _ C D := @delta_functor C D. - -HB.mixin Record IsMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { - unit : idfun ~~> M; - join : (M \o M)%FUN ~~> M; - bind : forall (a b : C), (a ~> M b) -> (M a ~> M b); - bindE : forall a b (f : a ~> M b), bind a b f = M <$> f \; join b; - unit_join : forall a, (M <$> unit a) \; join _ = idmap; - join_unit : forall a, join _ \; (M <$> unit a) = idmap; - join_square : forall a, M <$> join a \; join _ = join _ \; join _ -}. - -#[short(type="premonad")] -HB.structure Definition PreMonad (C : precat) := - {M of @PreFunctor C C M & IsMonad C M}. -#[short(type="monad")] -HB.structure Definition Monad (C : precat) := - {M of @Functor C C M & IsMonad C M}. - -HB.factory Record IsJoinMonad (C : precat) (M : C -> C) of @PreFunctor C C M := { - unit : idfun ~~> M; - join : (M \o M)%FUN ~~> M; - unit_join : forall a, (M <$> unit a) \; join _ = idmap; - join_unit : forall a, join _ \; (M <$> unit a) = idmap; - join_square : forall a, M <$> join a \; join _ = join _ \; join _ -}. -HB.builders Context C M of IsJoinMonad C M. - HB.instance Definition _ := IsMonad.Build C M - (fun a b f => erefl) unit_join join_unit join_square. -HB.end. - -HB.mixin Record IsCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { - counit : M ~~> idfun; - cojoin : M ~~> (M \o M)%FUN; - cobind : forall (a b : C), (M a ~> b) -> (M a ~> M b); - cobindE : forall a b (f : M a ~> b), cobind a b f = cojoin _ \; M <$> f; - unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; - join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; - cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ -}. -#[short(type="precomonad")] -HB.structure Definition PreCoMonad (C : precat) := - {M of @PreFunctor C C M & IsCoMonad C M}. -#[short(type="comonad")] -HB.structure Definition CoMonad (C : precat) := - {M of @Functor C C M & IsCoMonad C M}. - -HB.factory Record IsJoinCoMonad (C : precat) (M : C -> C) of @IsPreFunctor C C M := { - counit : M ~~> idfun; - cojoin : M ~~> (M \o M)%FUN; - unit_cojoin : forall a, (M <$> counit a) \; cojoin _ = idmap; - join_counit : forall a, cojoin _ \; (M <$> counit a) = idmap; - cojoin_square : forall a, cojoin _ \; M <$> cojoin a = cojoin _ \; cojoin _ -}. -HB.builders Context C M of IsJoinCoMonad C M. - HB.instance Definition _ := IsCoMonad.Build C M - (fun a b f => erefl) unit_cojoin join_counit cojoin_square. -HB.end. - -Lemma idFmap (C : cat) (a b : C) (f : a ~> b) : idfun <$> f = f. -Proof. by []. Qed. - -Lemma compFmap (C D E : cat) (F : C ~> D) (G : D ~> E) (a b : C) (f : a ~> b) : - (G \o F) <$> f = G <$> F <$> f. -Proof. by []. Qed. - -(* yoneda *) -Section hom_repr. -Context {C : cat} (F : C ~>_cat U). - -Definition homF : C -> U := fun c => hom c ~~> F. - -Section nat. -Context (x y : C) (xy : x ~> y). - -(* Goal hom x ~~> F -> hom y ~~> F *) -Context (n : hom x ~~> F). -Definition homFhom c : hom y c ~> F c := fun g => n _ (xy \; g). - -Lemma homFhom_natural_subdef : IsNatural C U (hom y) F homFhom. -Proof. -by split=> a b f /=; apply/funext => g /=; - rewrite /homFhom !Ucompx/= !naturalU/= Fcomp. -Qed. -HB.instance Definition _ := homFhom_natural_subdef. -End nat. -Arguments homFhom / : clear implicits. - -HB.about IsPreFunctor.Build. -Check homFhom : forall x y : C, (x ~> y) -> (homF x -> homF y). -HB.instance Definition _ := IsPreFunctor.Build _ _ homF homFhom. -Lemma homF_functor_subproof : PreFunctor_IsFunctor _ _ homF. -Proof. -split=> [a|a b c f g]. - apply/funext => -[/= f natf]. - apply: natP => //=; apply: funext => b; apply: funext => g/=. - by rewrite comp1o. -apply/funext => -[/= h natf]. -apply: natP => //=; apply: funext => d; apply: funext => k/=. -by rewrite compoA. -Qed. -HB.instance Definition _ := homF_functor_subproof. - -Section pointed. -Context (c : C). -Definition hom_repr : homF c ~> F c := fun f => f _ idmap. -Arguments hom_repr /. - -Definition repr_hom (fc : F c) a : hom c a ~> F a := - fun f => F^$ f fc. -Arguments repr_hom / : clear implicits. -Lemma repr_hom_subdef (fc : F c) : IsNatural _ _ _ _ (repr_hom fc). -Proof. by split=> a b f /=; apply/funext=> x; rewrite !Ucompx/= Fcomp. Qed. -HB.instance Definition _ {fc : F c} := repr_hom_subdef fc. - -Definition repr_hom_nat : F c ~> homF c := repr_hom. - -Lemma hom_reprK : cancel hom_repr repr_hom_nat. -Proof. -move=> f; apply/natP; apply/funext => a; apply/funext => g /=. -by rewrite -naturalU/=; congr (f _ _); apply: comp1o. -Qed. -Lemma repr_homK : cancel (repr_hom : F c ~> homF c) hom_repr. -Proof. by move=> fc; rewrite /= F1. Qed. -End pointed. -Arguments hom_repr /. -Arguments repr_hom /. - -Lemma hom_repr_natural_subproof : IsNatural _ _ _ _ hom_repr. -Proof. -split=> a b f /=; apply/funext => n /=; rewrite !Ucompx/= compo1/=. -by rewrite -naturalU/=; congr (n _ _); apply/esym/comp1o. -Qed. -HB.instance Definition _ := hom_repr_natural_subproof. - -(* show this from the previous proof *) -Lemma hom_natural_repr_subproof : IsNatural _ _ _ _ repr_hom_nat. -Proof. -split=> a b f /=; apply: funext => fa /=; rewrite !Ucompx/=. -apply: natP; apply: funext => c /=; apply: funext => d /=. -by rewrite Fcomp Ucompx/=. -Qed. -HB.instance Definition _ := hom_natural_repr_subproof. - -Definition hom_repr_nat : homF ~~> F := hom_repr. -Definition repr_hom_nat_nat : F ~~> homF := repr_hom_nat. - -End hom_repr. - -(* comma categories *) -Module comma. -Section homcomma. -Context {C D E : precat} (F : C ~> E) (G : D ~> E). - -Definition type := { x : C * D & F x.1 ~> G x.2 }. -Definition hom_subdef (a b : type) := { - f : tag a ~> tag b & F <$> f.1 \; tagged b = tagged a \; G <$> f.2 - }. -HB.instance Definition _ := IsQuiver.Build type hom_subdef. -End homcomma. -Arguments hom_subdef /. -Section comma. -Context {C D E : cat} (F : C ~> E) (G : D ~> E). -Notation type := (type F G). - -Program Definition idmap_subdef (a : type) : a ~> a := @Tagged _ idmap _ _. -Next Obligation. by rewrite !F1 comp1o compo1. Qed. -Program Definition comp_subdef (a b c : type) - (f : a ~> b) (g : b ~> c) : a ~> c := - @Tagged _ (tag f \; tag g) _ _. -Next Obligation. by rewrite !Fcomp -compoA (tagged g) compoA (tagged f) compoA. Qed. -HB.instance Definition _ := IsPreCat.Build type idmap_subdef comp_subdef. -Arguments idmap_subdef /. -Arguments comp_subdef /. - -Lemma comma_homeqP (a b : type) (f g : a ~> b) : projT1 f = projT1 g -> f = g. -Proof. -case: f g => [f fP] [g +]/= eqfg; case: _ / eqfg => gP. -by congr existT; apply: Prop_irrelevance. -Qed. - -Lemma comma_is_cat : PreCat_IsCat type. -Proof. -by split=> [[a fa] [b fb] [*]|[a fa] [b fb] [*]|*]; - apply/comma_homeqP; rewrite /= ?(comp1o, compo1, compoA). -Qed. -HB.instance Definition _ := comma_is_cat. -End comma. -End comma. -Notation "F `/` G" := (@comma.type _ _ _ F G) - (at level 40, G at level 40, format "F `/` G") : cat_scope. -Notation "a /` G" := (cst unit a `/` G) - (at level 40, G at level 40, format "a /` G") : cat_scope. -Notation "F `/ b" := (F `/` cst unit b) - (at level 40, b at level 40, format "F `/ b") : cat_scope. -Notation "a / b" := (cst unit a `/ b) : cat_scope. - -Definition obj (C : U) : U := C. -HB.mixin Record IsInitial {C : quiver} (i : obj C) := { - to : forall c, i ~> c; - to_unique : forall c (f : i ~> c), f = to c -}. -#[short(type="initial")] -HB.structure Definition Initial {C : quiver} := {i of IsInitial C i}. - -HB.mixin Record IsTerminal {C : quiver} (t : obj C) := { - from : forall c, c ~> t; - from_unique : forall c (f : c ~> t), f = from c -}. -#[short(type="terminal")] -HB.structure Definition Terminal {C : quiver} := {t of IsTerminal C t}. -#[short(type="universal")] -HB.structure Definition Universal {C : quiver} := - {u of Initial C u & Terminal C u}. - -(* Definition hom' {C : precat} (a b : C) := a ~> b. *) -(* (* Bug *) *) -(* Identity Coercion hom'_hom : hom' >-> hom. *) - -(* HB.mixin Record IsMono {C : precat} (b c : C) (f : hom b c) := { *) -(* monoP : forall (a : C) (g1 g2 : a ~> b), g1 \; f = g2 \; f -> g1 = g2 *) -(* }. *) -(* #[short(type="mono")] *) -(* HB.structure Definition Mono {C : precat} (a b : C) := {m of IsMono C a b m}. *) -(* Notation "a >~> b" := (mono a b) *) -(* (at level 99, b at level 200, format "a >~> b") : cat_scope. *) -(* Notation "C >~>_ T D" := (@mono T C D) *) -(* (at level 99, T at level 0, only parsing) : cat_scope. *) - -(* HB.mixin Record IsEpi {C : precat} (a b : C) (f : hom a b) := { *) -(* epiP : forall (c : C) (g1 g2 : b ~> c), g1 \o f = g2 \o f -> g1 = g2 *) -(* }. *) -(* #[short(type="epi")] *) -(* HB.structure Definition Epi {C : precat} (a b : C) := {e of IsEpi C a b e}. *) -(* Notation "a ~>> b" := (epi a b) *) -(* (at level 99, b at level 200, format "a ~>> b") : cat_scope. *) -(* Notation "C ~>>_ T D" := (@epi T C D) *) -(* (at level 99, T at level 0, only parsing) : cat_scope. *) - -(* #[short(type="iso")] *) -(* HB.structure Definition Iso {C : precat} (a b : C) := *) -(* {i of @Mono C a b i & @Epi C a b i}. *) -(* Notation "a <~> b" := (epi a b) *) -(* (at level 99, b at level 200, format "a <~> b") : cat_scope. *) -(* Notation "C <~>_ T D" := (@epi T C D) *) -(* (at level 99, T at level 0, only parsing) : cat_scope. *) - -HB.mixin Record IsRightAdjoint (D C : precat) (R : D -> C) - of @PreFunctor D C R := { - L_ : C ~> D; - phi : forall c d, (L_ c ~> d) -> (c ~> R d); - psy : forall c d, (c ~> R d) -> (L_ c ~> d); - phi_psy c d : (phi c d \o psy c d)%FUN = @id (c ~> R d); - psy_phi c d : (psy c d \o phi c d)%FUN = @id (L_ c ~> d) -}. -#[short(type="right_adjoint")] -HB.structure Definition RightAdjoint (D C : precat) := - { R of @Functor D C R & IsRightAdjoint D C R }. -Arguments L_ {_ _}. -Arguments phi {D C s} {c d}. -Arguments psy {D C s} {c d}. - - -HB.mixin Record PreCat_IsMonoidal C of PreCat C := { - onec : C; - (* prod1 : @hom precat (C * C)%type C ; *) - prod : (C * C)%type ~>_precat C; -}. -#[short(type="premonoidal")] -#[verbose] -HB.structure Definition PreMonoidal := { C of PreCat C & PreCat_IsMonoidal C }. -Notation premonoidal := premonoidal. -Arguments prod {C} : rename. -Notation "a * b" := (prod (a, b)) : cat_scope. -Reserved Notation "f <*> g" (at level 40, g at level 40, format "f <*> g"). -Notation "f <*> g" := (prod^$ (f, g)) (only printing) : cat_scope. -Notation "f <*> g" := (prod^$ ((f, g) : (_, _) ~> (_, _))) - (only parsing) : cat_scope. -Notation "1" := onec : cat_scope. - -Definition hom_cast {C : quiver} {a a' : C} (eqa : a = a') {b b' : C} (eqb : b = b') : - (a ~> b) -> (a' ~> b'). -Proof. now elim: _ / eqa; elim: _ / eqb. Defined. - -HB.mixin Record PreFunctor_IsMonoidal (C D : premonoidal) F of - @PreFunctor C D F := { - fun_one : F 1 = 1; - fun_prod : forall (x y : C), F (x * y) = F x * F y; -}. -#[short(type="monoidal_prefunctor")] -HB.structure Definition MonoidalPreFunctor C D := - { F of @PreFunctor_IsMonoidal C D F }. -Arguments fun_prod {C D F x y} : rename. -(* Arguments fun_prodF {C D F x x'} f {y y'} g : rename. *) -Unset Universe Checking. -HB.instance Definition _ := IsQuiver.Build premonoidal MonoidalPreFunctor.type. -Set Universe Checking. - -HB.instance Definition _ (C : quiver) := - IsPreFunctor.Build (C * C)%type C fst - (fun (a b : C * C) (f : a ~> b) => f.1). -HB.instance Definition _ (C : quiver) := - IsPreFunctor.Build (C * C)%type C snd - (fun (a b : C * C) (f : a ~> b) => f.2). - -Definition prod3l {C : premonoidal} (x : C * C * C) : C := - (x.1.1 * x.1.2) * x.2. -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build _ C prod3l - (fun a b (f : a ~> b) => (f.1.1 <*> f.1.2) <*> f.2). - -Definition prod3r {C : premonoidal} (x : C * C * C) : C := - x.1.1 * (x.1.2 * x.2). -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build _ C prod3r - (fun a b (f : a ~> b) => f.1.1 <*> (f.1.2 <*> f.2)). - -Definition prod1r {C : premonoidal} (x : C) : C := 1 * x. -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build C C prod1r - (fun (a b : C) (f : a ~> b) => \idmap_1 <*> f). - -Definition prod1l {C : premonoidal} (x : C) : C := x * 1. -HB.instance Definition _ {C : premonoidal} := - IsPreFunctor.Build C C prod1l - (fun (a b : C) (f : a ~> b) => f <*> \idmap_1). - -HB.mixin Record PreMonoidal_IsMonoidal C of PreMonoidal C := { - prodA : prod3l ~~> prod3r; - prod1c : prod1r ~~> idfun; - prodc1 : prod1l ~~> idfun; - prodc1c : forall (x y : C), - prodA (x, 1, y) \; \idmap_x <*> prod1c y = prodc1 x <*> \idmap_y; - prodA4 : forall (w x y z : C), - prodA (w * x, y, z) \; prodA (w, x, y * z) = - prodA (w, x, y) <*> \idmap_z \; prodA (w, x * y, z) \; \idmap_w <*> prodA (x, y, z); -}. - -Unset Universe Checking. -#[short(type="monoidal")] -#[verbose] -HB.structure Definition Monoidal : Set := - { C of PreMonoidal_IsMonoidal C & PreMonoidal C }. -Set Universe Checking. - -(******************************************************************) - - -Record cospan (Q : quiver) (A B : Q) := Cospan { - top : Q; - left2top : A ~> top; - right2top : B ~> top -}. - -Section cospans. -Variables (Q : precat) (A B : Q). -Record cospan_map (c c' : cospan A B) := CospanMap { - top_map : top c ~> top c'; - left2top_map : left2top c \; top_map = left2top c'; - right2top_map : right2top c \; top_map = right2top c'; -}. -HB.instance Definition _ := IsQuiver.Build (cospan A B) cospan_map. - -Lemma cospan_mapP (c c' : cospan A B) (f g : c ~> c') : - top_map f = top_map g <-> f = g. -Admitted. -End cospans. - -Section cospans_in_cat. -Variables (Q : cat) (A B : Q). -Definition cospan_idmap (c : cospan A B) := - @CospanMap Q A B c c idmap (compo1 _) (compo1 _). -Program Definition cospan_comp (c1 c2 c3 : cospan A B) - (f12 : c1 ~> c2) (f23 : c2 ~> c3) := - @CospanMap Q A B c1 c3 (top_map f12 \; top_map f23) _ _. -Next Obligation. by rewrite compoA !left2top_map. Qed. -Next Obligation. by rewrite compoA !right2top_map. Qed. -HB.instance Definition _ := IsPreCat.Build (cospan A B) cospan_idmap cospan_comp. - -Lemma cospan_are_cats : PreCat_IsCat (cospan A B). -Proof. -constructor=> [a b f|a b f|a b c d f g h]. -- by apply/cospan_mapP => /=; rewrite comp1o. -- by apply/cospan_mapP => /=; rewrite compo1. -- by apply/cospan_mapP => /=; rewrite compoA. -Qed. -HB.instance Definition _ := cospan_are_cats. -End cospans_in_cat. - -Section spans_and_co. -Variables (Q : quiver) (A B : Q). -Definition span := @cospan Q^op A B. -Definition bot (s : span) : Q := top s. -Definition bot2left (s : span) : bot s ~>_Q A := left2top s. -Definition bot2right (s : span) : bot s ~>_Q B := right2top s. -Definition Span (C : Q) (f : C ~> A) (g : C ~> B) : span := - @Cospan Q^op A B C f g. -End spans_and_co. - -HB.instance Definition _ (Q : precat) (A B : Q) := - Quiver.copy (span A B) (@cospan Q^op A B)^op. -HB.instance Definition _ (Q : cat) (A B : Q) := - Cat.copy (span A B) (@cospan Q^op A B)^op. - -Section bot_map. -Variables (C : cat) (A B : C) (s s' : span A B) (f : s ~> s'). -Definition bot_map : bot s ~> bot s' := top_map f. -Lemma bot2left_map : bot_map \; bot2left s' = bot2left s. -Proof. exact: left2top_map f. Qed. -Lemma bot2right_map : bot_map \; bot2right s' = bot2right s. -Proof. exact: right2top_map f. Qed. -End bot_map. - -HB.mixin Record isPrePullback (Q : precat) (A B : Q) - (c : cospan A B) (s : span A B) := { - is_square : bot2left s \; left2top c = bot2right s \; right2top c; -}. -#[short(type=prepullback)] -HB.structure Definition PrePullback Q A B (c : cospan A B) := - {s of isPrePullback Q A B c s}. -Arguments prepullback {Q A B} c. - -Section prepullback. -Variables (Q : precat) (A B : Q) (c : cospan A B). -HB.instance Definition _ := - IsQuiver.Build (prepullback c) - (fun a b => (a : span A B) ~>_(span A B) (b : span A B)). -Lemma eq_prepullbackP (p q : prepullback c) : - p = q :> span _ _ <-> p = q. -Admitted. -End prepullback. -Section prepullback. -Variables (Q : cat) (A B : Q) (csp : cospan A B). -(* TODO: why can't we do that? *) -(* HB.instance Definition _ := Cat.on (prepullback csp). *) -HB.instance Definition _ := - Quiver_IsPreCat.Build (prepullback csp) - (fun a => \idmap_(a : span A B)) - (* TODO: study how to make this coercion trigger - even when the target is not reduced to span *) - (fun a b c f g => f \; g). -Lemma prepullback_is_cat : PreCat_IsCat (prepullback csp). -Proof. (* should be copied from the cat on span *) -constructor=> [a b f|a b f|a b c d f g h]; - [exact: comp1o|exact: compo1|exact: compoA]. -Qed. -End prepullback. - -HB.tag Definition pb_terminal (Q : precat) - (A B : Q) (c : cospan A B) (s : prepullback c) : - obj (prepullback c) := s. - -#[wrapper] -HB.mixin Record prepullback_isTerminal (Q : precat) - (A B : Q) (c : cospan A B) - (s : span A B) of isPrePullback Q A B c s := { - prepullback_terminal : - IsTerminal (prepullback c) (pb_terminal s) -}. -#[short(type="pullback"), verbose] -HB.structure Definition Pullback (Q : precat) - (A B : Q) (c : cospan A B) := - {s of isPrePullback Q A B c s - & IsTerminal (prepullback c) (pb_terminal s) }. - -Notation pbsquare u v f g := - (Pullback _ (Cospan f g) (Span u v)). - -Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). - -(********************************************************************) -(********************************************************************) - -(*** CATEGORIES WITH PULLBACKS *) - -(* category with all prepullbacks *) -(* Ideally span is in fact expanded and the final mixin has -a pb : forall A B, cospan A B -> C -but it is not clear how to do that yet -*) -HB.mixin Record HasPBop C of Cat C := { - pb : forall (A B: C), cospan A B -> span A B - }. -#[short(type="pbop")] -HB.structure Definition PBop := - {C of HasPBop C & PreCat C }. - -(* category with all pullbacks *) -(* Wrong: we don't wrap classes, only mixins *) -#[wrapper] -HB.mixin Record HasPreBCat C of PBop C : Type := { - is_pb : forall (a b : C) (c : cospan a b), isPrePullback C a b c (@pb C a b c) - }. -#[short(type="pbcat")] -HB.structure Definition PreBCat := - {C of HasPreBCat C}. - -#[wrapper] -HB.mixin Record HasPBCat C of PBop C & HasPreBCat C : Type := { - is_pb : forall (a b : C) (c : cospan a b), - prepullback_isTerminal C a b c (@pb C a b c) - }. -#[short(type="pbcat")] -HB.structure Definition PBCat := - {C of HasPBCat C}. - - -(********************************************************************) - -(*** INTERNAL CATEGORIES *) -(* based on the NLab definition at - https://ncatlab.org/nlab/show/internal+category -*) - -(* category extended with internal objects *) -HB.mixin Record HasIObjects C of Cat C := { - Obj : C ; - Mor : C -}. -HB.structure Definition IObjects := - { C of HasIObjects C }. - -(* operators (meant to abstract over pullbacks and pushouts*) -HB.mixin Record HasPOps C of IObjects C := { - prd : C -> C -> C ; - prj1 : forall c1 c2, prd c1 c2 ~> c1 ; - prj2 : forall c1 c2, prd c1 c2 ~> c2 ; - mprd : forall c1 c2 c3 c4, - (c1 ~> c3) -> (c2 ~> c4) -> prd c1 c2 ~> prd c3 c4 ; - mjn : forall c1 c2 c3, - (c1 ~> c2) -> (c1 ~> c3) -> c1 ~> prd c2 c3 -}. -HB.structure Definition POps := - { C of HasPOps C }. - -(* category extended with internal morphisms *) -HB.mixin Record IsIQuiver C of POps C := { - iid : Obj ~>_C Mor ; - isrc : Mor ~>_C Obj ; - itrg : Mor ~>_C Obj ; - icmp : @prd C Mor Mor ~> Mor -}. -HB.structure Definition IQuiver := - { C of IsIQuiver C }. - -Notation idO C := (@idmap C Obj). -Notation idM C := (@idmap C Mor). -Notation prdMM := (prd Mor Mor). -Notation prdPM := (prd (prd Mor Mor) Mor). -Notation prjMM1 := (prj1 Mor Mor). -Notation prjMM2 := (prj2 Mor Mor). -Notation prjOM1 := (prj1 Obj Mor). -Notation prjOM2 := (prj2 Obj Mor). -Notation prjMO1 := (prj1 Mor Obj). -Notation prjMO2 := (prj2 Mor Obj). -Notation prjPM1 := (prj1 (prd Mor Mor) Mor). -Notation prjPM2 := (prj2 (prd Mor Mor) Mor). -Notation prjPM1_ C := (@prj1 C (prd Mor Mor) Mor). -Notation prjPM2_ C := (@prj2 C (prd Mor Mor) Mor). -Notation prjMP1 := (prj1 Mor (prd Mor Mor)). -Notation prjMP2 := (prj2 Mor (prd Mor Mor)). -Notation mprdOMMM := (mprd Obj Mor Mor Mor). -Notation mprdMOMM := (mprd Mor Obj Mor Mor). -Notation mprdPMMM := (mprd (prd Mor Mor) Mor Mor Mor). -Notation mprdMPMM := (mprd Mor (prd Mor Mor) Mor Mor). - -(* internal quiver extended with the required pullback properties *) -HB.mixin Record IsIPreCat C of IQuiver C := { - pbkMM : prjMM2 \; @isrc C = prjMM1 \; itrg ; - pbkPMcmp : prjPM2 \; @isrc C = prjPM1 \; icmp \; itrg ; - pbkMPcmp : prjMP2 \; @icmp C \; isrc = prjMP1 \; itrg ; - pbkPM : prjPM2 \; @isrc C = prjPM1 \; prjMM2 \; itrg ; - pbkMP : prjMP2 \; prjMM1 \; @isrc C = prjMP1 \; itrg ; - pbkPM2MM1 : prjPM1_ C \; prjMM2 = - mjn prdPM Mor Mor (prjPM1 \; prjMM2) prjPM2 \; prjMM1 ; - pbkPM2MM2 : prjPM2_ C = - mjn prdPM Mor Mor (prjPM1 \; prjMM2) prjPM2 \; prjMM2 ; - pbkPM2MP1 : prjPM1_ C \; prjMM1 = - mjn prdPM Mor prdMM (prjPM1 \; prjMM1) - (mjn prdPM Mor Mor (prjPM1 \; prjMM2) prjPM2) \; prjMP1 ; - pbkPM2MP2 : mjn prdPM Mor Mor (prjPM1_ C \; prjMM2) prjPM2 = - mjn prdPM Mor prdMM (prjPM1 \; prjMM1) - (mjn prdPM Mor Mor (prjPM1 \; prjMM2) prjPM2) \; prjMP2 ; -}. -HB.structure Definition IPreCat := - { C of IsIPreCat C }. - -(* definition of internal category *) -HB.mixin Record IsICat C of IPreCat C := { - iid_s : iid \; isrc = idO C ; - iid_t : iid \; itrg = idO C ; - icmp_s : @icmp C \; isrc = prjMM1 \; isrc ; - icmp_t : @icmp C \; itrg = prjMM2 \; itrg ; - unit_l : mprdOMMM iid (idM C) \; icmp = prjOM2 ; - unit_r : mprdMOMM (idM C) iid \; icmp = prjMO1 ; - assoc : mprdPMMM icmp (idM C) \; icmp = - mjn prdPM Mor prdMM (prjPM1 \; prjMM1) - (mjn prdPM Mor Mor (prjPM1 \; prjMM2) prjPM2) \; - mprdMPMM (idM C) icmp \; icmp -}. -HB.structure Definition ICat := - { C of IsICat C }. -(* -HB.mixin Record IsICat C of IQuiver C := { - iid_s : iid \; isrc = @idmap C Obj ; - iid_t : iid \; itrg = @idmap C Obj ; - icmp_s : @icmp C \; isrc = prj1 Mor Mor \; isrc ; - icmp_t : @icmp C \; itrg = prj2 Mor Mor \; itrg ; - unit_l : mprd Obj Mor Mor Mor iid (@idmap C Mor) \; icmp = - prj2 Obj Mor ; - unit_r : mprd Mor Obj Mor Mor (@idmap C Mor) iid \; icmp = - prj1 Mor Obj ; - assoc : mprd (prd Mor Mor) Mor Mor Mor icmp (@idmap C Mor) - \; icmp = - (mjn (prd (prd Mor Mor) Mor) Mor (prd Mor Mor) - (prj1 (prd Mor Mor) Mor \; prj1 Mor Mor) - (mjn (prd (prd Mor Mor) Mor) Mor Mor - (prj1 (prd Mor Mor) Mor \; prj2 Mor Mor) - (prj2 (prd Mor Mor) Mor))) \; - (mprd Mor (prd Mor Mor) Mor Mor (@idmap C Mor) icmp) - \; icmp -}. -*) - -(********************************************************************) - -(*** GENERALISED ENRICHED CATEGORIES *) - -Declare Scope encat_scope. -Delimit Scope encat_scope with encat. -Local Open Scope encat_scope. - -(* Enrichment in a monoidal category, following - https://ncatlab.org/nlab/show/enriched+category -*) -HB.mixin Record IsEnQuiver (V: Type) C := { - hom_object : C -> C -> V - }. -Unset Universe Checking. -HB.structure Definition EnQuiver (V: Type) : Set := - { C of IsEnQuiver V C }. -Set Universe Checking. - -(* Monoidal precategory with the enrichment operators (no axioms) *) -HB.mixin Record IsEnPreCat (V: PreMonoidal.type) C of - EnQuiver (PreMonoidal.sort V) C := { - id_element : forall (a: C), - @hom V onec (hom_object a a) ; - comp_morphism : forall (a b c: C), - @hom V (@hom_object V C b c * @hom_object V C a b) - (@hom_object V C a c) -}. -Unset Universe Checking. -HB.structure Definition EnPreCat (V: PreMonoidal.type) : Set := - { C of IsEnPreCat V C }. -Set Universe Checking. - -Notation "a ~^ b" := (hom_object a b) - (at level 99, b at level 200, format "a ~^ b") : encat_scope. -Notation "a ~^_ ( V , C ) b" := (@hom_object V C a b) - (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. -Notation "~^IE a" := (id_element a) - (at level 99, format "~^IE a") : cat_scope. -Notation "~^IE_ ( V , C ) a" := (@id_element V C a) - (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. -(* not working *) -Notation "~^CM a b c" := (comp_morphism a b c) - (at level 99, - format "~^CM a b c") : cat_scope. -Notation "~^CM_ ( V , C ) a b c" := (@comp_morphism V C a b c) - (at level 99, V at level 0, C at level 0, only parsing) : cat_scope. - -(* V-enriched category: - V is the monoidal category; - C is the base category that gets enriched -*) -HB.mixin Record IsEnCat (V: Monoidal.type) C of EnPreCat V C := { - ecat_comp_assoc : forall a b c d: C, - forall alpha: - (((c ~^_(V,C) d) * (b ~^_(V,C) c)) * (a ~^_(V,C) b)) ~>_V - ((c ~^_(V,C) d) * ((b ~^_(V,C) c) * (a ~^_(V,C) b))), - ((@comp_morphism V C b c d) <*> (@idmap V (a ~^_(V,C) b))) \; - (@comp_morphism V C a b d) - = - alpha \; - ((@idmap V (c ~^_(V,C) d)) <*> (@comp_morphism V C a b c)) \; - (@comp_morphism V C a c d) ; - - ecat_comp_left_unital : forall a b: C, - forall l: onec * (a ~^_(V,C) b) ~>_V (a ~^_(V,C) b), - l = ((@id_element V C b) <*> (@idmap V (a ~^_(V,C) b))) \; - (@comp_morphism V C a b b) ; - ecat_comp_right_unital : forall a b: C, - forall r: (a ~^_(V,C) b) * onec ~>_V (a ~^_(V,C) b), - r = ((@idmap V (a ~^_(V,C) b)) <*> (@id_element V C a)) \; - (@comp_morphism V C a a b) -}. -Unset Universe Checking. -#[verbose] -HB.structure Definition EnCat (V: Monoidal.type) : Set := - { C of IsEnCat V C }. -Set Universe Checking. - -(********************************************************************) - -(*** DOUBLE CATEGORIES (without internal categories) *) - -(* Strict double categories, from - https://ncatlab.org/nlab/show/double+category - (we don't use internal categories) - - base obejcts as 0-cells: C ; - - vertical 1-morphisms (category D0 on C): hom C ; - - horizontal 1-morphisms (category H on C): hom (transpose C) ; - - horizontal 1-morhisms as 1-cells for D1: D1obj C ; - - 2-morphisms (category D1 on C1obj): hom (D1obj C) ; - - horizontally composable pairs of 1-cells : DPobj C ; - - horizontally composable pairs of 2-morphisms - (product category DP, D1 *0 D1) : hom (DPobj C) ; - - The definition of Strict Double Category, SDouble = (D0, H, D1, Dp), - is given by: - - - base objects C - - - (level-1) category (D0) of vertical 1-morphism on C - - - (level-1) category (H) of horizontal 1-morphism (D1obj) on C - - - (level-2) category (D1) of vertical 2-morphism on D1obj - - - (derived) category (DP) of vertical 2-morphisms on - horizontally D0-composable D1 products - ($\mbox{D1} *_0 \mbox{D1}$) - - - Source functor: $\mbox{D1} \to \mbox{D0}$ - - - Target functor: $\mbox{D1} \to \mbox{D0}$ - - - Horizontal unit functor: $\mbox{D0} \to \mbox{D1}$ - - - Horizontal composition functor: $\mbox{DP} \to \mbox{D1}$ -*) - - -(** Quivers for double categories *) - -(* transpose for horizontal morphism quiver. - HB.tag needed to identify transpose as lifter *) -HB.tag Definition transpose (C : quiver) : U := C. -#[wrapper] HB.mixin Record _IsHQuiver C of IsQuiver C := { - is_hquiver : IsQuiver (transpose C) -}. -(* vertical and horizontal quivers, defining cells *) -Unset Universe Checking. -#[short(type="vhquiver")] -HB.structure Definition VHQuiver : Set := - { C of IsQuiver C & IsQuiver (transpose C) }. -Set Universe Checking. - -HB.tag Definition hhom (c : VHQuiver.type) : c -> c -> U := @hom (transpose c). -Notation "a +> b" := (hhom a b) - (at level 99, b at level 200, format "a +> b") : cat_scope. - -(* record to represent the set of morphims - (needed for 2-objects, i.e. horizontal morphisms) *) -Record Total2 T (h: T -> T -> U) : Type := TT2 { - source : T; - target : T; - this_morph : h source target }. - -(* the set of horizontal morphisms. *) -HB.tag Definition D1obj (C: vhquiver) := Total2 (@hhom C). - -(* D1 quiver requirement (includes D0 quiver and its transpose). *) -#[wrapper] -HB.mixin Record _IsDQuiver T of VHQuiver T := - { is_dquiver : Quiver (D1obj T) }. -Unset Universe Checking. -#[short(type="dquiver")] -HB.structure Definition DQuiver : Set := { C of Quiver (D1obj C) }. -Set Universe Checking. - - -(** Horizonal D0-level category (H-D0) *) - -(* Precategory based on the HQuiver (i.e. horizontal precategory on D0 - objects) *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record _IsHPreCat T of VHQuiver T := { - is_hprecat : Quiver_IsPreCat (transpose T) }. -#[short(type="hprecat")] -HB.structure Definition HPreCat : Set := - { C of Quiver_IsPreCat (transpose C) }. -Set Universe Checking. - -(* The category based on the HQuiver (i.e. horizontal category on D0 - objects) *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record _IsHCat T of HPreCat T := { - is_hcat : PreCat_IsCat (transpose T) }. -#[short(type="hcat")] -HB.structure Definition HCat : Set := - { C of PreCat_IsCat (transpose C) }. -Set Universe Checking. - - -(** Vertical 2-cell level category (D1 category) *) - -(* Precategory based on the DQuiver (i.e. precategory D1). Gives: - vertical 2-cell identity morphism. - vertical 2-cell composition. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record _IsD1PreCat T of DQuiver T := { - is_d1precat : Quiver_IsPreCat (@D1obj T) }. -#[short(type="d1precat")] -HB.structure Definition D1PreCat : Set := - { C of Quiver_IsPreCat (@D1obj C) }. -Set Universe Checking. - -(* The category based on the DQuiver (i.e. category D1). *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record _IsD1Cat T of D1PreCat T := { - is_d1cat : PreCat_IsCat (@D1obj T) }. -#[short(type="d1cat")] -HB.structure Definition D1Cat : Set := - { C of PreCat_IsCat (@D1obj C) }. -Set Universe Checking. - - -(** Naked double category *) - -(* Naked double category. Vertical (V-D0) and D1 categories. Double - category without horizontal operators and functors *) -Unset Universe Checking. -#[short(type="dcat")] -HB.structure Definition DCat : Set := - { C of Cat C & D1Cat C }. -Set Universe Checking. - -(* Naked strict double category. Vertical (V-D0), horizontal (H-D0) - and D1 categories. Strict double category without functors *) -Unset Universe Checking. -#[short(type="sd2cat")] -HB.structure Definition SDCat : Set := { C of Cat C & HCat C & D1Cat C }. -Set Universe Checking. - - -(** Auxiliary notions for Source, Target and - Horizontal Unit functors *) - -(* homsets of 2-cell (D1) morphisms *) -Definition d1hom (D: DQuiver.type) : D1obj D -> D1obj D -> U := - @hom (D1obj D). -(* type-level smart constructor for D1 homsets *) -Definition D1hom (D: DQuiver.type) (a b c d: D) (h0: hhom a b) - (h1: hhom c d) : U := d1hom (TT2 h0) (TT2 h1). - -(* smart projections for: - source functor (for horizontal morphisms): D1 -> D0. - defined as object-level function, by functoriality lifted to a - (2-cell, vertical) morphism-level one *) -HB.tag Definition HSource C := fun (X: D1obj C) => @source C (@hhom C) X. -(* target functor (for horizontal morphisms): D1 -> D0. *) -HB.tag Definition HTarget C := fun (X: D1obj C) => @target C (@hhom C) X. - -(* horizontal unit functor: D0 -> D1 *) -Definition hhunit (T: hprecat) (a: T) : D1obj T := - @TT2 T (@hhom T) a a (@idmap (transpose T) a). -HB.tag Definition H1Unit (C: hprecat) := - fun (x: HPreCat.sort C) => @hhunit C x. - - -(** Auxiliary notions for 2-cell Horizontal Composition functor *) - -(* composable pairs of morphisms as a set *) -Record GenComp T (h: T -> T -> U) := GC { - h_one : T; - h_two : T ; - h_three : T; - h_first : h h_one h_two ; - h_second : h h_two h_three }. - -(* composable pairs of horizontal morphisms as a set *) -HB.tag Definition DPobj (C: vhquiver) := GenComp (@hhom C). - -(* smart projections *) -Definition H2First (C: vhquiver) (X: @DPobj C) : D1obj C := - @TT2 C _ (h_one X) (h_two X) (h_first X). -Definition H2Second (C: vhquiver) (X: @DPobj C) : D1obj C := - @TT2 C _ (h_two X) (h_three X) (h_second X). - - -(* horizontal composition functor: D1 * D1 -> D1 *) -Definition hhcomp (T: hprecat) (x: DPobj T) : D1obj T := - match x with - @GC _ _ a b c h1 h2 => @TT2 T (@hhom T) a c (h1 \; h2) end. -HB.tag Definition H1Comp (C: hprecat) := - fun (x: DPobj C) => @hhcomp C x. - -(* hhunit - horizontal unit functor. - - hhcomp - horizontal composition functor (horizontal composition of - two horizontal morphisms from a cell product). - - Both specified as object-level functions (they actually come for - free from the H-D0 category, since we are in the strict case), to - be lifted by functoriality to morphism-level ones. - - At the object level, hhunit gives a horizontal identity morphism - for each D0 object. At the morphism level, it gives horizontal - 2-cell identity for each vertical morphism. - - In the case of hhcomp, relying on functoriality requires some care - in defining the product category, making sure that adjacency at the - object-level (between horizontal morphisms) is matched by adjacency - at the morphism-level (between 2-cells). *) - - -(** Source and target functors *) - -(* source prefunctor. - D1obj T is the quiver of the 2-morphisms, thanks to VHQuiver. - T is the quiver of 1-morphisms. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsSPreFunctor T of DCat T := { - is_sprefunctor : IsPreFunctor (D1obj T) T (@HSource T) }. -HB.structure Definition SPreFunctor : Set := {C of IsSPreFunctor C}. -Set Universe Checking. - -(* target prefunctor. *) -Unset Universe Checking. -#[wrapper] - HB.mixin Record IsTPreFunctor T of DCat T := { - is_tprefunctor : IsPreFunctor (D1obj T) T (@HTarget T) }. -HB.structure Definition TPreFunctor : Set := {C of IsTPreFunctor C}. -Set Universe Checking. - -(* source functor. *) -Unset Universe Checking. -#[wrapper] - HB.mixin Record SPreFunctor_IsFunctor T of SPreFunctor T := { - is_sfunctor : PreFunctor_IsFunctor (D1obj T) T (@HSource T) }. -HB.structure Definition SFunctor : Set := {C of SPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* target functor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record TPreFunctor_IsFunctor T of TPreFunctor T := { - is_tfunctor : PreFunctor_IsFunctor (D1obj T) T (@HTarget T) }. -HB.structure Definition TFunctor : Set := {C of TPreFunctor_IsFunctor C}. -Set Universe Checking. - - -(** Unit functor *) - -(* unit prefunctor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsUPreFunctor T of SDCat T := - { is_uprefunctor : IsPreFunctor T (D1obj T) (@H1Unit T) }. -HB.structure Definition UPreFunctor : Set := {C of IsUPreFunctor C}. -Set Universe Checking. - -(* unit functor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record UPreFunctor_IsFunctor T of UPreFunctor T := { - is_ufunctor : PreFunctor_IsFunctor T (D1obj T) (@H1Unit T) }. -HB.structure Definition UFunctor : Set := {C of UPreFunctor_IsFunctor C}. -Set Universe Checking. - -Unset Universe Checking. -HB.about Functor. -HB.structure Definition STUFunctor : Set := - {C of SFunctor C & TFunctor C & UFunctor C}. -Set Universe Checking. - - -(** Lifting of Source, Target and Unit functors to D1 morphisms *) - -(* 2-cell source *) -Definition H1Source (T: SFunctor.type) (a b: @D1obj T) - (m: @d1hom T a b) : - (HSource a) ~> (HSource b) := (@HSource T) <$> m. - -(* 2-cell target *) -Definition H1Target (T: TFunctor.type) (a b: @D1obj T) - (m: @d1hom T a b) : - (HTarget a) ~> (HTarget b) := (@HTarget T) <$> m. - -(* horizontal 2-cell unit (maps vertical morphisms to horizontally - unitary 2-cells) *) -Definition H2Unit (T: UFunctor.type) (a b: T) (m: @hom T a b) : - (H1Unit a) ~> (H1Unit b) := (@H1Unit T) <$> m. - - -(** Horizontal product category (D1 *d0 D1) *) -(* DPobj T is the pseudo-pullback category used to deal with - products of D1 (where the adjacency condition is expressed - w.r.t. D0 *) - -(* horizontal composition of two (naked) horizontal morphisms *) -Definition l_hcomp (T: SDCat.type) (a0 a1 a2: T) - (h0: hhom a0 a1) (h1: hhom a1 a2) : D1obj T := - @TT2 T _ a0 a2 (h0 \; h1). - -Notation "'sigma' x .. y , p" := - (sigT (fun x => .. (sigT (fun y => p)) ..)) - (at level 200, x binder, right associativity, - format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") - : type_scope. - -(** DPobj quiver *) -Definition DP_hom (T: STUFunctor.type) (x y: DPobj T) := - sigma (hh0: D1hom (h_first x) (h_first y)) - (hh1: D1hom (h_second x) (h_second y)), - H1Target hh0 = H1Source hh1. - -HB.instance Definition DPQuiver (T: STUFunctor.type) : - IsQuiver (DPobj T) := - IsQuiver.Build (DPobj T) (fun A B => @DP_hom T A B). - - -(** Product precategory *) - -Lemma DP_id_eq (T : STUFunctor.type) (a: DPobj T) : - H1Target (@idmap (@D1obj T) (H2First a)) = - H1Source (@idmap (@D1obj T) (H2Second a)). -unfold H1Target, HTarget. -unfold H1Source, HSource. -repeat rewrite F1; auto. -Defined. - -(* DPobj identity *) -Definition DP_id (T: STUFunctor.type) (A: DPobj T) : A ~> A := - let h0 := h_first A - in let h1 := h_second A - in let uu0 := @idmap (D1obj T) (TT2 h0) - in let uu1 := @idmap (D1obj T) (TT2 h1) - in @existT (D1hom h0 h0) - (fun hh0: (D1hom h0 h0) => - sigma (hh1 : D1hom h1 h1), H1Target hh0 = H1Source hh1) uu0 - (@existT (D1hom h1 h1) - (fun hh1: (D1hom h1 h1) => H1Target uu0 = H1Source hh1) uu1 - (@DP_id_eq T A)). - -Definition DP_comp_auxA (T : STUFunctor.type) - (A B C : DPobj T) - (hhA0 : D1hom (h_first A) (h_first B)) - (hhA1 : D1hom (h_second A) (h_second B)) - (ppA : H1Target hhA0 = H1Source hhA1) - (hhB0 : D1hom (h_first B) (h_first C)) - (hhB1 : D1hom (h_second B) (h_second C)) - (ppB : H1Target hhB0 = H1Source hhB1) : - (H1Target hhA0) \; (H1Target hhB0) = - (H1Source hhA1) \; (H1Source hhB1). - rewrite ppA. - rewrite ppB. - reflexivity. -Defined. - -Definition DP_comp_auxS (T : STUFunctor.type) - (A B C : DPobj T) - (hhA0 : D1hom (h_first A) (h_first B)) - (hhA1 : D1hom (h_second A) (h_second B)) - (ppA : H1Target hhA0 = H1Source hhA1) - (hhB0 : D1hom (h_first B) (h_first C)) - (hhB1 : D1hom (h_second B) (h_second C)) - (ppB : H1Target hhB0 = H1Source hhB1) : - H1Source (hhA1 \; hhB1) = (H1Source hhA1) \; (H1Source hhB1). - unfold H1Source, HSource. - repeat rewrite Fcomp. - reflexivity. -Defined. - -Definition DP_comp_auxT (T : STUFunctor.type) - (A B C : DPobj T) - (hhA0 : D1hom (h_first A) (h_first B)) - (hhA1 : D1hom (h_second A) (h_second B)) - (ppA : H1Target hhA0 = H1Source hhA1) - (hhB0 : D1hom (h_first B) (h_first C)) - (hhB1 : D1hom (h_second B) (h_second C)) - (ppB : H1Target hhB0 = H1Source hhB1) : - H1Target (hhA0 \; hhB0) = (H1Target hhA0) \; (H1Target hhB0). - unfold H1Target, HTarget. - repeat rewrite Fcomp. - reflexivity. -Defined. - -Definition DP_comp_auxI (T : STUFunctor.type) - (A B C : DPobj T) - (hhA0 : D1hom (h_first A) (h_first B)) - (hhA1 : D1hom (h_second A) (h_second B)) - (ppA : H1Target hhA0 = H1Source hhA1) - (hhB0 : D1hom (h_first B) (h_first C)) - (hhB1 : D1hom (h_second B) (h_second C)) - (ppB : H1Target hhB0 = H1Source hhB1) : - A ~> C. - econstructor 1 with (comp hhA0 hhB0). - econstructor 1 with (comp hhA1 hhB1). - setoid_rewrite DP_comp_auxS; eauto. - setoid_rewrite DP_comp_auxT; eauto. - eapply DP_comp_auxA; eauto. -Defined. - -(* DPobj composition, defined in proof mode *) -Definition DP_comp (T: STUFunctor.type) (A B C: DPobj T) : - (A ~> B) -> (B ~> C) -> A ~> C. - intros chA chB. - destruct chA as [hhA0 [hhA1 ppA]]. - destruct chB as [hhB0 [hhB1 ppB]]. - eapply DP_comp_auxI; eauto. -Defined. - -(* DPobj is a precategory *) -HB.instance Definition DPPreCat (T: STUFunctor.type) : - Quiver_IsPreCat (DPobj T) := - Quiver_IsPreCat.Build (DPobj T) (@DP_id T) (@DP_comp T). - -(* - have HcompP : - (a b : DPobj T) - (f g : a ~> b), - proj1T f = proj1t f -> - - -> - f = g. - - exists a b p, - fst f = a - f = (a,b,p) -*) - -(** Product category *) - -Lemma DP_LeftUnit_lemma (T : STUFunctor.type) : - forall (a b : DPobj T) (f : a ~> b), idmap \; f = f. - - move => a b [x [x0 e]] /=. - simpl in *. - unfold idmap; simpl. - unfold DP_id; simpl. - unfold comp; simpl. - unfold DP_comp_auxI; simpl. - - assert (idmap \; x = x) as A. - { rewrite comp1o; auto. } - - assert (idmap \; x0 = x0) as A0. - { rewrite comp1o; auto. } - - assert (H1Target (idmap \; x) = H1Source (idmap \; x0)) as B. - { rewrite A. - rewrite A0; auto. } - - destruct a eqn: aaa. - destruct b eqn: bbb. - simpl. - - assert (existT - (fun hh0 : D1hom h_first0 h_first1 => - sigma hh1 : D1hom h_second0 h_second1,H1Target hh0 = H1Source hh1) - (idmap \; x) - (existT - (fun hh1 : D1hom h_second0 h_second1 => - H1Target (idmap \; x) = H1Source hh1) - (idmap \; x0) - B) = - existT - (fun hh0 : D1hom h_first0 h_first1 => - sigma hh1 : D1hom h_second0 h_second1,H1Target hh0 = H1Source hh1) - x - (existT - (fun hh1 : D1hom h_second0 h_second1 => H1Target x = H1Source hh1) - x0 - e)) as C. - { revert B. - revert A. - revert A0. - generalize (idmap \; x) as v. - generalize (idmap \; x0) as v0. - intros v0 v A0. - rewrite A0. - intro A. - rewrite A. - intro B. - - assert (B = e) as BE. - { eapply Prop_irrelevance. } - - rewrite BE. - reflexivity. -} - - inversion aaa; subst. - rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] - (Prop_irrelevance _ B). - eapply C. -Qed. - -Lemma DP_RightUnit_lemma (T : STUFunctor.type) : - forall (a b : DPobj T) (f : a ~> b), f \; idmap = f. - - move => a b [x [x0 e]] /=. - simpl in *. - unfold idmap; simpl. - unfold DP_id; simpl. - unfold comp; simpl. - unfold DP_comp_auxI; simpl. - - assert (x \; idmap = x) as A. - { rewrite compo1; auto. } - - assert (x0 \; idmap = x0) as A0. - { rewrite compo1; auto. } - - assert (H1Target (x \; idmap) = H1Source (x0 \; idmap)) as B. - { rewrite A. - rewrite A0; auto. } - - destruct a eqn: aaa. - destruct b eqn: bbb. - simpl. - - assert (existT - (fun hh0 : D1hom h_first0 h_first1 => - sigma hh1 : D1hom h_second0 h_second1, - H1Target hh0 = H1Source hh1) - (x \; idmap) - (existT - (fun hh1 : D1hom h_second0 h_second1 => - H1Target (x \; idmap) = H1Source hh1) - (x0 \; idmap) - B) = - existT - (fun hh0 : D1hom h_first0 h_first1 => - sigma hh1 : D1hom h_second0 h_second1, - H1Target hh0 = H1Source hh1) - x - (existT - (fun hh1 : D1hom h_second0 h_second1 => - H1Target x = H1Source hh1) - x0 - e)) as C. - { revert B. - revert A. - revert A0. - generalize (x \; idmap) as v. - generalize (x0 \; idmap) as v0. - intros v0 v A0. - rewrite A0. - intro A. - rewrite A. - intro B. - - assert (B = e) as BE. - { eapply Prop_irrelevance. } - - rewrite BE. - reflexivity. - } - - inversion aaa; subst. - rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] - (Prop_irrelevance _ B). - eapply C. -Qed. - -Lemma DP_Assoc_lemma (T : STUFunctor.type) : - forall (a b c d : DPobj T) (f : a ~> b) (g : b ~> c) (h : c ~> d), - f \; g \; h = (f \; g) \; h. - intros. - remember f as f1. - remember g as g1. - remember h as h1. - destruct f as [x0 s0]. - destruct g as [x1 s1]. - destruct h as [x2 s2]. - destruct s0 as [y0 e0]. - destruct s1 as [y1 e1]. - destruct s2 as [y2 e2]. - simpl. - - set (x01 := comp x0 x1). - set (x12 := comp x1 x2). - set (x0_12 := comp x0 x12). - set (x01_2 := comp x01 x2). - set (y01 := comp y0 y1). - set (y12 := comp y1 y2). - set (y0_12 := comp y0 y12). - set (y01_2 := comp y01 y2). - - assert (x0_12 = x01_2) as X0. - { subst x0_12 x01_2. - rewrite compoA; eauto. } - assert (y0_12 = y01_2) as Y0. - { subst y0_12 y01_2. - rewrite compoA; eauto. } - - set (x01_t := comp (H1Target x0) (H1Target x1)). - set (x01_2_t := comp x01_t (H1Target x2)). - set (x12_t := comp (H1Target x1) (H1Target x2)). - set (x0_12_t := comp (H1Target x0) x12_t). - set (y01_s := comp (H1Source y0) (H1Source y1)). - set (y01_2_s := comp y01_s (H1Source y2)). - set (y12_s := comp (H1Source y1) (H1Source y2)). - set (y0_12_s := comp (H1Source y0) y12_s). - - assert (x01_t = y01_s) as E01. - { subst x01_t y01_s. - rewrite e0. - rewrite e1; auto. } - assert (x01_2_t = y01_2_s) as E01_2. - { subst x01_2_t y01_2_s. - rewrite E01. - rewrite e2; auto. } - assert (x12_t = y12_s) as E12. - { subst x12_t y12_s. - rewrite e1. - rewrite e2; auto. } - assert (x0_12_t = y0_12_s) as E0_12. - { subst x0_12_t y0_12_s. - rewrite E12. - rewrite e0; auto. } - - assert (x0_12_t = x01_2_t) as E02T. - { subst x0_12_t x01_2_t. - subst x12_t x01_t. - rewrite compoA; auto. } - assert (y0_12_s = y01_2_s) as E02S. - { subst y0_12_s y01_2_s. - subst y12_s y01_s. - rewrite compoA; auto. } - - unfold comp. - simpl. - unfold DP_comp. - simpl. - inversion Heqf1; subst. - clear H. - - unfold DP_comp_auxI; simpl. - - assert (H1Target (x0 \; x1 \; x2) = - H1Source (y0 \; y1 \; y2)) as KR. - { subst x0_12_t y0_12_s. - subst x12_t y12_s. - unfold H1Target. - repeat rewrite Fcomp; simpl. - unfold H1Target in E0_12. - rewrite E0_12. - unfold H1Source. - repeat rewrite Fcomp; simpl. - auto. - } - - assert (H1Target ((x0 \; x1) \; x2) = - H1Source ((y0 \; y1) \; y2)) as KL. - { subst x01_2_t y01_2_s. - subst x01_t y01_s. - unfold H1Target. - repeat rewrite Fcomp; simpl. - unfold H1Target in E01_2. - rewrite E01_2. - unfold H1Source. - repeat rewrite Fcomp; simpl. - auto. - } - - assert (existT - (fun hh0 : D1hom (h_first a) (h_first d) => - sigma hh1 : D1hom (h_second a) (h_second d), - H1Target hh0 = H1Source hh1) - (x0 \; x1 \; x2) - (existT - (fun hh1 : D1hom (h_second a) (h_second d) => - H1Target (x0 \; x1 \; x2) = H1Source hh1) - (y0 \; y1 \; y2) - KR) - = - existT - (fun hh0 : D1hom (h_first a) (h_first d) => - sigma hh1 : D1hom (h_second a) (h_second d), - H1Target hh0 = H1Source hh1) - ((x0 \; x1) \; x2) - (existT - (fun hh1 : D1hom (h_second a) (h_second d) => - H1Target ((x0 \; x1) \; x2) = H1Source hh1) - ((y0 \; y1) \; y2) - KL)) as KA. - { revert KL. - revert KR. - subst x0_12 x01_2 x12 x01. - subst y0_12 y01_2 y12 y01. - rewrite <- X0. - rewrite <- Y0. - intros KR KL. - - assert (KR = KL) as I1. - { eapply Prop_irrelevance. } - rewrite I1. - reflexivity. - } - - rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] - (Prop_irrelevance _ KR). - - rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] - (Prop_irrelevance _ KL). - eapply KA. -Qed. - -Program Definition DPCatP (T: STUFunctor.type) : - PreCat_IsCat (DPobj T). -econstructor. -eapply DP_LeftUnit_lemma; eauto. -eapply DP_RightUnit_lemma; eauto. -eapply DP_Assoc_lemma; eauto. -Qed. - -(* DPobj is a category *) -HB.instance Definition DPCat (T: STUFunctor.type) := DPCatP T. - - -(** Horizontal composition functor and strict double categories *) - -(* composition prefunctor *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsCPreFunctor T of STUFunctor T := - { is_cprefunctor : IsPreFunctor (DPobj T) (D1obj T) (@H1Comp T) }. -HB.structure Definition CPreFunctor : Set := {C of IsCPreFunctor C}. -Set Universe Checking. - -(* composition functor - gives the definition of Strict Double Category *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record CPreFunctor_IsFunctor T of CPreFunctor T := { - is_cfunctor : PreFunctor_IsFunctor (DPobj T) (D1obj T) (@H1Comp T) }. -#[short(type="sdoublecat")] -HB.structure Definition SDoubleCat : Set := {C of CPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* horizontal 2-cell composition: maps two adjecent pairs of - horizontal morphisms (a and b) and a pullback-category morphism - between them (m, which basically gives two adjecent cells) to a - 2-cell morphism between the horizontal composition (HComp) of each - pair *) -Definition HC2Comp (T: SDoubleCat.type) (a b: DPobj T) - (m: @hom (DPobj T) a b) : - d1hom (H1Comp a) (H1Comp b) := @Fhom _ _ (@H1Comp T) a b m. - -Program Definition HC2Comp_flat (T: SDoubleCat.type) (a0 a1 a2 b0 b1 b2: T) - (h0: hhom a0 a1) (h1: hhom a1 a2) - (k0: hhom b0 b1) (k1: hhom b1 b2) - (hh0: D1hom h0 k0) - (hh1: D1hom h1 k1) - (k: H1Target hh0 = H1Source hh1) - : (* D1hom (hcomp _ _ _ h0 h1) (hcomp _ _ _ k0 k1) *) - d1hom (l_hcomp h0 h1) (l_hcomp k0 k1) := - @Fhom _ _ (@H1Comp T) (GC h0 h1) (GC k0 k1) _. -Obligation 1. -refine (@existT (D1hom h0 k0) _ hh0 (@existT (D1hom h1 k1) _ hh1 k)). -Defined. - -(********************************************************************) -(********************************************************************) - - -Section th_of_pb. -Variables (Q : cat) (A B C D E F : Q). -Variables (f : A ~> D) (g : B ~> D) (h : C ~> A). -Variables (u : E ~> A) (v : E ~> B) (w : F ~> C) (z : F ~> E). -Variable (uvfg : pbsquare u v f g). - -Set Printing Width 50. -Theorem pbsquarec_compP : - pbsquare w z h u <=> pbsquare w (z \; v) (h \; f) g. -Proof. -split=> [] sq. - - have @sq_ispb : pullback (Cospan h u) := HB.pack (Span w z) sq. - have @uvfg_ispb : pullback (Cospan f g) := HB.pack (Span u v) uvfg. - have /=E2 := @is_square _ _ _ _ sq_ispb. - have /=E1 := @is_square _ _ _ _ uvfg_ispb. - - have p1 : @isPrePullback Q C B (Cospan (h \; f) g) (Span w (z \; v)). - by constructor; rewrite /= compoA E2 -compoA E1 compoA. - pose big_black_square : prepullback (Cospan (h \; f) g) := - HB.pack (Span w (z \; v)) p1. - - have @from : forall - (big_red_square : prepullback {| top := D; left2top := h \; f; right2top := g |}), - big_red_square ~> pb_terminal big_black_square. - - move=> big_red_square; unfold pb_terminal. - - have /= := @is_square _ _ _ _ big_red_square. - - pose F' := bot big_red_square. - set w' : F' ~> C := bot2left big_red_square. - set z' : F' ~> B := bot2right big_red_square. - move=> E3. - - have xxx : isPrePullback Q A B (Cospan f g) (Span (w' \; h) z'). - by constructor=> /=; rewrite -compoA E3. - pose red_black_square : prepullback (Cospan f g) := - HB.pack (Span (w' \; h) z') xxx. - have := @from_unique _ (pb_terminal uvfg_ispb) red_black_square. - set blue := @from _ (pb_terminal uvfg_ispb) red_black_square. - move=> blue_unique. - - have p3 : @isPrePullback Q C E (Cospan h u) (Span w' (bot_map blue)). - by constructor; rewrite /= (bot2left_map blue). (* buggy unifier without blue *) - pose blue_red_black_square : prepullback (Cospan h u) := - HB.pack (Span w' (bot_map blue)) p3. - - pose red := @from _ (pb_terminal sq_ispb) blue_red_black_square. - - admit. - - - - have p2 : prepullback_isTerminal.axioms_ Q C B (Cospan (h \; f) g) (Span w (z \; v)) p1. - constructor. econstructor=> /=. - admit. - - by HB.from p1 p2. - -Admitted. - -End th_of_pb. - - -Module test. - -Section test. -Variables (Q : precat) (A B : Q) (c : cospan A B). -Variable (p : pullback c). -Check pb_terminal p : terminal _. - -End test. -End test. - - - -(************************************************************************) - -(**** INTERNAL CATEGORIES - NEW DEFINITION *) - -(* Defining internal hom objects. - C0 and C1 are objects of C. - C0 is the object of objects, - C1 is the object of morphims (and the subject). - this will allow to define a generic _ *_C0 _ notation - by recognizing the structure of hom objects on the LHS and RHS - Basically, w.r.t. double categories, C1 represents 'horizontal' - 1-morpshisms and the D1 category, whereas C0 represents the objects - of the base D0 category. *) -HB.mixin Record isInternalHom {C: quiver} (C0 : C) (C1 : obj C) := { - src : C1 ~> C0; tgt : C1 ~> C0 -}. -#[short(type="iHom")] -HB.structure Definition InternalHom {C: quiver} (C0 : C) := - { C1 of isInternalHom C C0 C1 }. - -Notation "X ':>' C" := (X : obj C) (at level 60, C at next level). - -(* HB.instance Definition _ (T : quiver) := Quiver.on (obj T). *) -(* HB.instance Definition _ (T : precat) := PreCat.on (obj T). *) -(* HB.instance Definition _ (T : cat) := Cat.on (obj T). *) -(* HB.instance Definition _ (T : pbcat) := PBCat.on (obj T). *) - -(* constructs the pullback from the cospan given by target and source. - Type-level construction: X and Y are two instances of the morphism - object, specified by (iHom C0), and are objects of (obj C). Here - 'iprod' is just an object of (obj C). The cospan is given by the - target of X and the source of Y. The pullback provides a commuting - square on the cospan, which basically ensures that the morphisms in - X and Y can be composed. *) -Definition iprod_pb {C: pbcat} {C0 : C} (X Y : iHom C0) : - span (X :> C) (Y :> C) := - pb _ _ (Cospan (tgt : (X :> C) ~> C0) (src : (Y :> C) ~> C0)). - -Definition iprod {C: pbcat} {C0 : obj C} (X Y : iHom C0) : obj C := - bot (@iprod_pb C C0 X Y). -Notation "X *_ C0 Y" := (@iprod _ C0 (X : iHom C0) (Y : iHom C0)) - (at level 99, C0 at level 0, only parsing) : cat_scope. -Notation "X *_ C0 Y" := (@iprod _ C0 X Y) - (at level 99, C0 at level 0) : cat_scope. - -(* -(1) Defines pullback square (iprod_pb) - - X --- tgt -----> C0 - ^ ^ - | | - bot2left src - | | - X*Y - bot2right -> Y - - -(2) Defines source and target of the product (iprod_iHom) - - X --- src -----> C0 - ^ ^ - | | - iprodl tgt - | | - X*Y -- iprodr ---> Y -*) - -(* left and right projection morphisms of the product *) -Definition iprodl {C: pbcat} {C0 : C} (X Y : iHom C0) : - X *_C0 Y ~> (X :> C) := bot2left (iprod_pb X Y). -Definition iprodr {C: pbcat} {C0 : C} (X Y : iHom C0) : - X *_C0 Y ~> (Y :> C) := bot2right (iprod_pb X Y). - -(* Given (iHom C0) instances X and Y, we want to say that (X *_C0 Y) -is also an instance of (iHom C0). X and Y represent composable -morphisms, as by pullback properties, the diagram (1) commutes. -source and target are obtained by composing with product projections -(2) *) -Definition iprod_iHom {C: pbcat} {C0: C} (X Y: @iHom C C0) : - @isInternalHom C C0 (X *_C0 Y) := - @isInternalHom.Build C C0 (X *_C0 Y) - ((iprodl X Y) \; src) - ((iprodr X Y) \; tgt). - -HB.instance Definition iprod_iHom' {C: pbcat} {C0: C} (X Y: @iHom C C0) : - @isInternalHom C C0 (X *_C0 Y) := iprod_iHom X Y. - -(* the product as (iHom C0) object *) -Definition pbC0 (C : pbcat) (C0 : C) (X Y : iHom C0) : iHom C0 := - (X *_C0 Y) : iHom C0. - -(* we also define the trivial internal hom type *) -HB.instance Definition trivial_iHom {C: pbcat} {C0: C} := - isInternalHom.Build C C0 C0 idmap idmap. - - - -(* we need internal hom morphisms: -the ones that preserve sources and targets. -basically, we recast morphisms in (obj C) into some in (@iHom C C0), -i.e. into morphism between copies of C1 *) -HB.mixin Record IsInternalHomHom {C: pbcat} (C0 : C) - (C1 C1' : @iHom C C0) (f : (C1 :> C) ~> (C1' :> C)) := { -(* hom_src : f \; src = src; - hom_tgt : f \; tgt = tgt; *) -}. -#[short(type="iHomHom")] -HB.structure Definition InternalHomHom {C: pbcat} - (C0 : C) (C1 C1' : @iHom C C0) := - { f of @IsInternalHomHom C C0 C1 C1' f }. - -(* internal homs form a category, - the morphisms are the one that preserve source and target *) -HB.instance Definition iHom_quiver {C: pbcat} (C0 : C) : - IsQuiver (@iHom C C0) := - IsQuiver.Build (@iHom C C0) (@iHomHom C C0). -Print iHom_quiver. - -Definition pre_iHom_id {C: pbcat} (C0 : C) (C1 : @iHom C C0) : - @IsInternalHomHom C C0 C1 C1 idmap := - @IsInternalHomHom.Build C C0 C1 C1 idmap. -(* -Obligation 1. -setoid_rewrite comp1o; reflexivity. -Defined. -Obligation 2. -setoid_rewrite comp1o; reflexivity. -Defined. -*) - -Program Definition iHom_id {C: pbcat} (C0 : C) (C1 : @iHom C C0) : - C1 ~>_(@iHom C C0) C1 := - @InternalHomHom.Pack C C0 C1 C1 idmap _. -(* -The term "pre_iHom_id C1" has type "IsInternalHomHom.phant_axioms idmap" -while it is expected to have type "InternalHomHom.axioms_ ?sort". -*) -Obligation 1. -econstructor. -eapply (@pre_iHom_id C C0 C1). -Defined. - -Definition pre_iHom_comp {C: pbcat} (C0 : C) (C1 C2 C3: @iHom C C0) - (f: C1 ~>_(@iHom C C0) C2) (g: C2 ~>_(@iHom C C0) C3) : - @IsInternalHomHom C C0 C1 C3 (f \; g) := - @IsInternalHomHom.Build C C0 C1 C3 (f \; g). -(* -Obligation 1. -setoid_rewrite <- compoA. -repeat (setoid_rewrite hom_src); auto. -Defined. -Obligation 2. -setoid_rewrite <- compoA. -repeat (setoid_rewrite hom_tgt); auto. -Defined. -*) - -Program Definition iHom_comp {C: pbcat} (C0 : C) (C1 C2 C3: @iHom C C0) - (f: C1 ~>_(@iHom C C0) C2) (g: C2 ~>_(@iHom C C0) C3) : - C1 ~>_(@iHom C C0) C3 := - @InternalHomHom.Pack C C0 C1 C3 (f \; g) _. -Obligation 1. -econstructor. -eapply (@pre_iHom_comp C C0 C1 C2 C3 f g). -Defined. - -Program Definition iHom_precat {C: pbcat} (C0 : C) : - Quiver_IsPreCat (@iHom C C0) := - Quiver_IsPreCat.Build (@iHom C C0) _ _. -Obligation 1. -eapply (@iHom_id C C0 a). -Defined. -Obligation 2. -eapply (@iHom_comp C C0 a b c0 X X0). -Defined. - -HB.instance Definition iHom_precat' {C: pbcat} (C0 : C) := iHom_precat C0. - -Lemma iHom_LeftUnit_lemma (C : pbcat) (C0 : C) - (a b : iHom C0) (f : a ~> b) : idmap \; f = f. -unfold idmap; simpl. -unfold iHom_precat_obligation_1. -unfold comp; simpl. -unfold iHom_precat_obligation_2. -unfold iHom_comp. -remember f as f1. -remember a as a1. -remember b as b1. -destruct f as [ff class]. -destruct a as [Ca class_a]. -destruct b as [Cb class_b]. -destruct class_a as [IMa]. -destruct class_b as [IMb]. -destruct class as [IM]. -destruct IMa. -destruct IMb. -destruct IM. -unfold obj in *. -simpl in *; simpl. - -eassert ( forall x, exists y, - {| - InternalHomHom.sort := idmap \; f1; - InternalHomHom.class := x - |} = - {| - InternalHomHom.sort := f1; - InternalHomHom.class := y - |} ) as A2. -{ rewrite Heqf1; simpl. - rewrite comp1o. - intros. - destruct x as [X]. - econstructor. - destruct X. - reflexivity. -}. - -setoid_rewrite Heqf1 at 3. -specialize (A2 (iHom_comp_obligation_1 (iHom_id a1) f1)). -destruct A2. -rewrite H. - -inversion Heqf1; subst. -simpl. -destruct x as [IM]. -destruct IM. -reflexivity. -Qed. - -Lemma iHom_RightUnit_lemma (C : pbcat) (C0 : C) - (a b : iHom C0) (f : a ~> b) : f \; idmap = f. -unfold idmap; simpl. -unfold iHom_precat_obligation_1. -unfold comp; simpl. -unfold iHom_precat_obligation_2. -unfold iHom_comp. -remember f as f1. -remember a as a1. -remember b as b1. -destruct f as [ff class]. -destruct a as [Ca class_a]. -destruct b as [Cb class_b]. -destruct class_a as [IMa]. -destruct class_b as [IMb]. -destruct class as [IM]. -destruct IMa. -destruct IMb. -destruct IM. -unfold obj in *. -simpl in *; simpl. - -eassert ( forall x, exists y, - {| - InternalHomHom.sort := f1 \; idmap; - InternalHomHom.class := x - |} = - {| - InternalHomHom.sort := f1; - InternalHomHom.class := y - |} ) as A2. -{ rewrite Heqf1; simpl. - rewrite compo1. - intros. - destruct x as [X]. - econstructor. - destruct X. - reflexivity. -}. - -setoid_rewrite Heqf1 at 3. -specialize (A2 (iHom_comp_obligation_1 f1 (iHom_id b1))). -destruct A2. -rewrite H. - -inversion Heqf1; subst. -simpl. -destruct x as [IM]. -destruct IM. -reflexivity. -Qed. - -Lemma iHom_Assoc_lemma {C : pbcat} (C0 : C) - (a b c d : iHom C0) (f : a ~> b) (g : b ~> c) (h : c ~> d) : - f \; g \; h = (f \; g) \; h. - unfold comp; simpl. - unfold iHom_precat_obligation_2; simpl. - unfold iHom_comp; simpl. - remember a as a1. - remember b as b1. - remember c as c1. - remember d as d1. - remember f as f1. - remember g as g1. - remember h as h1. - destruct a as [C_a class_a]. - destruct b as [C_b class_b]. - destruct c as [C_c class_c]. - destruct d as [C_d class_d]. - destruct f as [M_f class_f]. - destruct g as [M_g class_g]. - destruct h as [M_h class_h]. - destruct class_a as [IM_a]. - destruct class_b as [IM_b]. - destruct class_c as [IM_c]. - destruct class_d as [IM_d]. - destruct IM_a. - destruct IM_b. - destruct IM_c. - destruct IM_d. - destruct class_f as [IM_f]. - destruct class_g as [IM_g]. - destruct class_h as [IM_h]. - destruct IM_f. - destruct IM_g. - destruct IM_h. - unfold obj in *; simpl in *; simpl. - - eassert ( forall x y, - {| - InternalHomHom.sort := f1 \; g1 \; h1; - InternalHomHom.class := x - |} = - {| - InternalHomHom.sort := (f1 \; g1) \; h1; - InternalHomHom.class := y - |} ) as A2. - { rewrite Heqf1; simpl. - rewrite compoA. - intros. - destruct x as [X]. - destruct y as [Y]. - destruct X. - destruct Y. - reflexivity. - }. - - setoid_rewrite A2. - reflexivity. -Qed. - -Program Definition iHom_cat {C: pbcat} (C0 : C) : - PreCat_IsCat (@iHom C C0) := - PreCat_IsCat.Build (@iHom C C0) _ _ _. -Obligation 1. -eapply iHom_LeftUnit_lemma; eauto. -Qed. -Obligation 2. -eapply iHom_RightUnit_lemma; eauto. -Qed. -Obligation 3. -eapply iHom_Assoc_lemma; eauto. -Qed. - -HB.instance Definition iHom_cat' {C: pbcat} (C0 : C) := iHom_cat C0. - -Definition iprodlC0 {C: pbcat} {C0 : C} (X Y : iHom C0) : - pbC0 X Y ~>_(iHom C0) X. - econstructor. - instantiate (1:=(iprodl X Y)). - econstructor. - econstructor. -Defined. -Definition iprodrC0 {C: pbcat} {C0 : C} (X Y : iHom C0) : - pbC0 X Y ~>_(iHom C0) Y. - econstructor. - instantiate (1:=(iprodr X Y)). - econstructor. - econstructor. -Defined. - - -(* Now we define an internal quiver as an object C0, - which has a C1 : iHom C0 attached to it *) -HB.mixin Record IsPreInternalQuiver (C : quiver) (C0 : obj C) := - { C1 : obj C }. -HB.structure Definition PreInternalQuiver C := - { C0 of @IsPreInternalQuiver C C0 }. - -Arguments C1 {C s}. - -#[wrapper] HB.mixin Record IsInternalQuiver (C : quiver) (C0 : obj C) of - @PreInternalQuiver C C0 := { - priv: @InternalHom C C0 (@C1 _ C0) - }. -#[short(type="iquiver")] -HB.structure Definition InternalQuiver (C : quiver) := - { C0 of IsInternalQuiver C C0 }. - -Coercion iquiver_quiver (C : quiver) (C0 : iquiver C) : C := C0 :> C. -Coercion iquiver_precat (C : precat) (C0 : iquiver C) : C := C0 :> C. -Coercion iquiver_cat (C : cat) (C0 : iquiver C) : C := C0 :> C. - - -(* nested product *) -Program Definition iprodA {C : pbcat} {C0 : C} (C1 C2 C3 : iHom C0) : - ((C1 *_C0 C2 : iHom C0) *_C0 C3) ~>_(iHom C0) - (C1 *_C0 (C2 *_C0 C3 : iHom C0)). - (* := ... *) - (* OK define it with the universal arrow of the pullback *) -Admitted. - -(* product morphism. - PROBLEM: f and g do not generally preserve source and target, - therefore there is no guarantee that - iprodlC0 \; f \; tgt = iprodrC0 \; g \; src - missing which, we cannot derive the existence of the morphism - between the two products. -*) -Definition ipair {C : pbcat} {C0 : C} {a b c d : iHom C0} - (f : a ~> c) (g : b ~> d) : (a *_C0 b) ~> (c *_C0 d). -Admitted. -Notation "<( f , g )>" := (ipair f g). - - -(* An internal precategory is an internal category with two operators - that must be src and tgt preserving, i.e. iHom morphisms: identity - : C0 -> C1 (corresponding to horizontal 1-morphism identity in - double cat) and composition : C1 * C1 -> C1 (corresponding to - horizontal composition) *) -HB.mixin Record IsInternalPreCat (C : pbcat) (C0 : obj C) - of @InternalQuiver C C0 := { - iid : (C0 : iHom C0) ~>_(iHom C0) (@C1 C C0 : iHom C0); - icomp : let C1 := @C1 C C0 : iHom C0 in - let C2 := pbC0 C1 C1 : iHom C0 in - (C2 ~>_(iHom C0) C1) -}. -#[short(type="iprecat")] -HB.structure Definition InternalPreCat (C : pbcat) := - { C0 of @IsInternalPreCat C C0 }. - -(* Check (iquiver Type <~> quiver). *) -(* Check (iprecat Type <~> precat). *) - -(* An internal category moreover must satisfy additional properies on iid and icomp -(associativity and unit laws) *) -#[key="C0"] -HB.mixin Record IsInternalCat (C : pbcat) (C0 : obj C) of InternalPreCat C C0 := { - (* icompA : <(icomp, idmap)> \; icomp = (iprodA _ _ _) \; <(idmap, icomp)> \; icomp; *) - (* icomp1l : <(idmap, iid)> \; icomp = iprodlC0 C1 C1; *) - (* icomp1r : <(iid, idmap)> \; icomp = iprodrC0 C1 C1; *) -}. -#[short(type="icat")] -HB.structure Definition InternalCat (C : pbcat) := {C0 of @IsInternalCat C C0}. -(* Check (icat Type <~> cat). *) - - -(* A double category is an internal category in cat - - The objects are the objects of C0 - - The vertical maps are the maps of C0 - - The horizontal maps are the objects of C1 - - The 2-cells are the maps of C1 - - About identities: - - The identity vertical map on (x : C) is \idmap_x - - The identity horizontal map on (x : C) is iid x - - the identity 2-cell on (x : C) is iid (\idmap_x) = \idmap_(iid x) - - About compositions: - - The vertical composition of maps is the composition of C0 - - The vertical compositions of 2-cells is the composition of C1 - (and it agrees with the former because src and tgt are functors - and because iid is a iHom-map) - - The horizontal composition of maps is the object part of icomp - - The horizontal composition of 2-cells is the map part of icomp -*) -(* HB.structure' Definition DoubleCat := @InternalCat cat. *) -Axiom cat_pbop : HasPBop cat. -HB.instance Definition _ := cat_pbop. - -Axiom cat_preb : - forall (a b: cat) (c: cospan a b), isPrePullback cat a b c (@pb cat a b c). -HB.instance Definition _ (a b: cat) (c: cospan a b) := @cat_preb a b c. -Axiom cat_pb : - forall (a b: cat) (c: cospan a b), - prepullback_isTerminal cat a b c (@pb cat a b c). -HB.instance Definition _ (a b: cat) (c: cospan a b) := @cat_pb a b c. - -(* basically, the internal category adds the D1 category to the base -D0 category, which is C0 (an object of cat, which is shown to have -pullbacks) *) -Definition doublecat := icat cat. - -(* Check (doublecat <~> ???) *) - From e84c91f6556e93d3f61fcfe5cc019577e4d8dd60 Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Fri, 19 Jan 2024 14:06:27 +0100 Subject: [PATCH 133/147] updated encatI.v --- theories/encatI.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/theories/encatI.v b/theories/encatI.v index 706369800..f5e3c8731 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -1027,7 +1027,7 @@ destruct (X E33) as [mm R]. exact mm. Qed. -Print Assumptions iprodCAsc. +(* Print Assumptions iprodCAsc. *) (* An internal precategory is an internal category with two operators that must be src and tgt preserving, i.e. iHom morphisms: identity From 3564fd6e5a7a8c4877e809b0813761aadefa7da1 Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Fri, 19 Jan 2024 14:21:58 +0100 Subject: [PATCH 134/147] updated dependencies --- _CoqProject | 2 +- theories/encatD.v | 2 +- theories/encatI.v | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/_CoqProject b/_CoqProject index 9ea90d11e..577ff83da 100644 --- a/_CoqProject +++ b/_CoqProject @@ -1,6 +1,6 @@ structures.v theories/cat.v -theories/algebra.v +theories/encatD.v -arg -w -arg -elpi.accumulate-syntax -arg -w -arg +elpi.typecheck -Q . HB diff --git a/theories/encatD.v b/theories/encatD.v index de39bddde..bb297f625 100644 --- a/theories/encatD.v +++ b/theories/encatD.v @@ -498,7 +498,7 @@ HB.structure Definition UFunctor : Set := {C of UPreFunctor_IsFunctor C}. Set Universe Checking. Unset Universe Checking. -HB.about Functor. +(* HB.about Functor. *) HB.structure Definition STUFunctor : Set := {C of SFunctor C & TFunctor C & UFunctor C}. Set Universe Checking. diff --git a/theories/encatI.v b/theories/encatI.v index f5e3c8731..18bdc4634 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -1,6 +1,6 @@ Require Import ssreflect ssrfun. Unset Universe Checking. -From HB Require Import structures cat. +From HB Require Import structures cat encatD. Set Universe Checking. Require Import Coq.Program.Equality. From 1ce5b1169a5f791f91366b5695bf59c4d755f679 Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Fri, 19 Jan 2024 14:35:40 +0100 Subject: [PATCH 135/147] updated dependencies --- theories/cat.v | 5 +++++ theories/encat.v | 3 ++- theories/encatD.v | 3 ++- theories/encatI.v | 2 ++ theories/encatI0.v | 3 ++- 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/theories/cat.v b/theories/cat.v index 3f1235a26..81a248147 100644 --- a/theories/cat.v +++ b/theories/cat.v @@ -1199,6 +1199,11 @@ Notation pb s := (prepullback_isTerminal _ _ _ _ s). Notation "P <=> Q" := ((P -> Q) * (Q -> P))%type (at level 70). +Notation "'sigma' x .. y , p" := + (sigT (fun x => .. (sigT (fun y => p)) ..)) + (at level 200, x binder, right associativity, + format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") + : cat_scope. (**********************************************************************) diff --git a/theories/encat.v b/theories/encat.v index 8681f31cb..d8394cfbe 100644 --- a/theories/encat.v +++ b/theories/encat.v @@ -13,12 +13,13 @@ Local Open Scope algebra_scope. Local Open Scope cat_scope. +(* Notation "'sigma' x .. y , p" := (sigT (fun x => .. (sigT (fun y => p)) ..)) (at level 200, x binder, right associativity, format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") : type_scope. - +*) (*** DOUBLE CATEGORIES (REVISED) *) diff --git a/theories/encatD.v b/theories/encatD.v index bb297f625..e16a8041f 100644 --- a/theories/encatD.v +++ b/theories/encatD.v @@ -13,12 +13,13 @@ Local Open Scope algebra_scope. Local Open Scope cat_scope. +(* Notation "'sigma' x .. y , p" := (sigT (fun x => .. (sigT (fun y => p)) ..)) (at level 200, x binder, right associativity, format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") : type_scope. - +*) (********************************************************************) diff --git a/theories/encatI.v b/theories/encatI.v index 18bdc4634..308799040 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -13,11 +13,13 @@ Local Open Scope algebra_scope. Local Open Scope cat_scope. +(* Notation "'sigma' x .. y , p" := (sigT (fun x => .. (sigT (fun y => p)) ..)) (at level 200, x binder, right associativity, format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") : type_scope. +*) (*** GENERALISED ENRICHED CATEGORIES *) diff --git a/theories/encatI0.v b/theories/encatI0.v index f02dec3ac..8fbcc8fa9 100644 --- a/theories/encatI0.v +++ b/theories/encatI0.v @@ -13,12 +13,13 @@ Local Open Scope algebra_scope. Local Open Scope cat_scope. +(* Notation "'sigma' x .. y , p" := (sigT (fun x => .. (sigT (fun y => p)) ..)) (at level 200, x binder, right associativity, format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") : type_scope. - +*) (*** CATEGORIES WITH PULLBACKS *) From d94c19faa51f444ac767db965c7e37d12f0db4e5 Mon Sep 17 00:00:00 2001 From: Paolo Torrini Date: Fri, 19 Jan 2024 19:25:30 +0100 Subject: [PATCH 136/147] updated encatI.v --- _CoqProject | 1 + theories/encatI.v | 393 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 390 insertions(+), 4 deletions(-) diff --git a/_CoqProject b/_CoqProject index 577ff83da..1222fe98f 100644 --- a/_CoqProject +++ b/_CoqProject @@ -1,6 +1,7 @@ structures.v theories/cat.v theories/encatD.v +theories/encatI.v -arg -w -arg -elpi.accumulate-syntax -arg -w -arg +elpi.typecheck -Q . HB diff --git a/theories/encatI.v b/theories/encatI.v index 308799040..1e6a8ede9 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -21,6 +21,345 @@ Notation "'sigma' x .. y , p" := : type_scope. *) +(************************************************************************) + +Program Definition brel_fcast {X Y C : Type} {F: X -> C} {G: Y -> C} + {a1 b1: X} {a2 b2: Y} {R: C -> C -> Type} + (e1: F a1 = G a2) (e2: F b1 = G b2) : + R (G a2) (G b2) = R (F a1) (F b1). +rewrite e1. +rewrite e2. +auto. +Defined. + +Program Definition recast2 {X Y C : Type} {F: X -> C} {G: Y -> C} + {a1 b1: X} {a2 b2: Y} {R: C -> C -> Type} + (e1: F a1 = G a2) (e2: F b1 = G b2) + (x: R (G a2) (G b2)) : R (F a1) (F b1). +rewrite -(brel_fcast e1 e2). +exact x. +Defined. + +Program Definition brel_fcast_h {X Y C : Type} {F: X -> C} {G: Y -> C} + {a1 b1: X} {a2 b2: Y} {R: C -> C -> Type} + (e1: F a1 = G a2) (e2: F b1 = G b2) + (x: R (G a2) (G b2)) (P: forall T: Type, T -> Prop) : + P _ x = P _ (recast2 e1 e2 x). +unfold recast2. +unfold eq_rect. +unfold brel_fcast. +unfold eq_ind_r. +unfold eq_ind. +unfold eq_sym. +destruct e1. +destruct e2. +auto. +Defined. + +Program Definition brel_fcast_3h {X Y C : Type} {F: X -> C} {G: Y -> C} + {a1 b1 c1: X} {a2 b2 c2: Y} {R: C -> C -> Type} + (e1: F a1 = G a2) (e2: F b1 = G b2) (e3: F c1 = G c2) + (x: R (G a2) (G b2)) (y: R (G b2) (G c2)) (z: R (G a2) (G c2)) + (P: forall T1 T2 T3: Type, T1 -> T2 -> T3 -> Prop) : + P _ _ _ x y z = P _ _ _ (recast2 e1 e2 x) (recast2 e2 e3 y) (recast2 e1 e3 z). +unfold recast2. +unfold eq_rect. +unfold brel_fcast. +unfold eq_ind_r. +unfold eq_ind. +unfold eq_sym. +destruct e1. +destruct e2. +destruct e3. +auto. +Defined. + +Program Definition brel_fcast_3hh {X Y C : Type} {F: X -> C} {G: Y -> C} + {a1 b1 c1: X} {a2 b2 c2: Y} {R: C -> C -> Type} + (e1: F a1 = G a2) (e2: F b1 = G b2) (e3: F c1 = G c2) + (x: R (G a2) (G b2)) (y: R (G b2) (G c2)) (z: R (G a2) (G c2)) + (P: forall (d1 d2 d3: C), R d1 d2 -> R d2 d3 -> R d1 d3 -> Prop) : + P _ _ _ x y z = P _ _ _ (recast2 e1 e2 x) (recast2 e2 e3 y) (recast2 e1 e3 z). +unfold recast2. +unfold eq_rect. +unfold brel_fcast. +unfold eq_ind_r. +unfold eq_ind. +unfold eq_sym. +destruct e1. +destruct e2. +destruct e3. +auto. +Defined. + +Program Definition recast2_h {X Y C : Type} {F: X -> C} {G: Y -> C} + {a1 b1: X} {a2 b2: Y} {R: C -> C -> Type} + (e1: F a1 = G a2) (e2: F b1 = G b2) + (x: R (G a2) (G b2)) (P: forall T: Type, T -> Prop) + (p: P _ x) : P _ (recast2 e1 e2 x). +rewrite -(brel_fcast_h e1 e2). +exact p. +Defined. + +Program Definition recast2_3h {X Y C : Type} {F: X -> C} {G: Y -> C} + {a1 b1 c1: X} {a2 b2 c2: Y} {R: C -> C -> Type} + (e1: F a1 = G a2) (e2: F b1 = G b2) (e3: F c1 = G c2) + (x: R (G a2) (G b2)) (y: R (G b2) (G c2)) (z: R (G a2) (G c2)) + (P: forall T1 T2 T3: Type, T1 -> T2 -> T3 -> Prop) + (p: P _ _ _ x y z) : + P _ _ _ (recast2 e1 e2 x) (recast2 e2 e3 y) (recast2 e1 e3 z). +rewrite -(brel_fcast_3h e1 e2 e3). +exact p. +Defined. + +Program Definition recast2_3hh {X Y C : Type} {F: X -> C} {G: Y -> C} + {a1 b1 c1: X} {a2 b2 c2: Y} {R: C -> C -> Type} + (e1: F a1 = G a2) (e2: F b1 = G b2) (e3: F c1 = G c2) + (x: R (G a2) (G b2)) (y: R (G b2) (G c2)) (z: R (G a2) (G c2)) + (P: forall (d1 d2 d3: C), R d1 d2 -> R d2 d3 -> R d1 d3 -> Prop) + (p: P _ _ _ x y z) : + P _ _ _ (recast2 e1 e2 x) (recast2 e2 e3 y) (recast2 e1 e3 z). +rewrite -(brel_fcast_3hh e1 e2 e3). +exact p. +Defined. + +Program Definition recast_hom {X Y C : precat} {F: X -> C} {G: Y -> C} + {a1 b1: X} {a2 b2: Y} {R: C -> C -> Type} + (e1: F a1 = G a2) (e2: F b1 = G b2) + (x: (G a2) ~> (G b2)) : (F a1) ~> (F b1). +eapply recast2; eauto. +Defined. + +Definition recast21 {X Y C : Type} {F: X -> C} {G: Y -> C} + {R: C -> C -> Type} {a b: (X * Y)} + (e: (F (fst a), F (fst b)) = (G (snd a), G (snd b))) +(* + (e1: F (fst a) = G (snd a)) (e2: F (fst b) = G (snd b)) *) + (x: R (G (snd a)) (G (snd b))) : R (F (fst a)) (F (fst b)). + destruct a as [a1 a2]. + destruct b as [b1 b2]. + inversion e; subst. + rewrite H0. + rewrite H1. + auto. +Defined. + +Definition mk_pair_eq {X Y C: Type} {F: X -> C} {G: Y -> C} {a b: (X * Y)} + (e1: F (fst a) = G (snd a)) (e2: F (fst b) = G (snd b)) : + (F (fst a), F (fst b)) = (G (snd a), G (snd b)). + destruct a as [a1 a2]. + destruct b as [b1 b2]. + simpl in *; simpl. + rewrite e1. + rewrite e2. + auto. +Defined. + + +Module commaE. + +Section homcommaE. +Context {C D E : precat} (F : C ~> E) (G : D ~> E). + +Definition ptype := { x : C * D & F x.1 = G x.2 }. + +Definition hom_psubdef (a b : ptype) := { + f : tag a ~> tag b & + (F <$> f.1) = (recast2 (tagged a) (tagged b) (G <$> f.2)) }. +#[export] +HB.instance Definition _ := IsQuiver.Build ptype hom_psubdef. +End homcommaE. + +Arguments hom_psubdef /. + +Section commaS. +Context {C D E : cat} (F : C ~> E) (G : D ~> E). +Notation ptype := (ptype F G). + +Program Definition idmap_psubdef (a : ptype) : a ~> a := @Tagged _ idmap _ _. +Next Obligation. + unfold recast2. + unfold eq_rect. + unfold brel_fcast. + unfold eq_ind_r. + unfold eq_ind. + unfold eq_sym. + destruct a. + destruct x. + simpl in *; simpl. + rewrite F1. + rewrite F1. + unfold idmap. + simpl. + destruct e. + auto. +Defined. + +Program Definition comp_psubdef (a b c : ptype) + (f : a ~> b) (g : b ~> c) : a ~> c := + @Tagged _ (tag f \; tag g) _ _. +Next Obligation. + destruct f as [ff ef]. + destruct g as [gg eg]. + destruct a as [aa ea]. + destruct aa as [a1 a2]. + destruct b as [bb eb]. + destruct bb as [b1 b2]. + destruct c as [cc ec]. + destruct cc as [c1 c2]. + destruct ff as [f1 f2]. + destruct gg as [g1 g2]. + + simpl; simpl in *. + + rewrite Fcomp. + rewrite Fcomp. + + rewrite ef. + rewrite eg. + clear ef eg. + + eapply (@recast2_3hh _ _ _ _ _ _ _ _ _ _ _ _ + ea eb ec (G <$> f2) (G <$> g2) (G <$> f2 \; G <$> g2) + (fun (d1 d2 d3: E) (x: d1 ~> d2) (y: d2 ~> d3) + (z: d1 ~> d3) => x \; y = z) ); auto. +Defined. + (* by rewrite !Fcomp -compoA (tagged g) compoA (tagged f) compoA. Qed. *) + +#[export] +HB.instance Definition _ := IsPreCat.Build ptype idmap_psubdef comp_psubdef. +Arguments idmap_psubdef /. +Arguments comp_psubdef /. + +Lemma pcomma_homeqP (a b : ptype) (f g : a ~> b) : projT1 f = projT1 g -> f = g. +Proof. +case: f g => [f fP] [g +]/= eqfg; case: _ / eqfg => gP. +by congr existT; apply: Prop_irrelevance. +Qed. + +Lemma pcomma_is_cat : PreCat_IsCat ptype. +Proof. +by split=> [[a fa] [b fb] [*]|[a fa] [b fb] [*]|*]; + apply/pcomma_homeqP; rewrite /= ?(comp1o, compo1, compoA). +Qed. + +#[export] +HB.instance Definition _ := pcomma_is_cat. + +End commaS. + +Module Exports. + HB.reexport. +End Exports. + +End commaE. + +Import commaE.Exports. + +(* +Notation "F `/` G" := (@comma.type _ _ _ F G) + (at level 40, G at level 40, format "F `/` G") : cat_scope. +Notation "a /` G" := (cst unit a `/` G) + (at level 40, G at level 40, format "a /` G") : cat_scope. +Notation "F `/ b" := (F `/` cst unit b) + (at level 40, b at level 40, format "F `/ b") : cat_scope. +Notation "a / b" := (cst unit a `/ b) : cat_scope. +*) + + +Definition pcat_prj1 {C D E F G} (P: @commaE.ptype C D E F G) : C := + fst (tag P). + +Definition pcat_prj2 {C D E F G} (P: @commaE.ptype C D E F G) : D := + snd (tag P). + +Program Definition pcat_prj1_isPreFunctor {C D E F G} := + IsPreFunctor.Build _ _ (@pcat_prj1 C D E F G) _. +Obligation 1. +destruct X as [f Y]. +exact f.1. +Defined. + +Program Definition pcat_prj2_isPreFunctor {C D E F G} := + IsPreFunctor.Build _ _ (@pcat_prj2 C D E F G) _. +Obligation 1. +destruct X as [f Y]. +exact f.2. +Defined. + +HB.instance Definition _ {C D E F G} : IsPreFunctor _ _ pcat_prj1 := + @pcat_prj1_isPreFunctor C D E F G. + +HB.instance Definition _ {C D E F G} : IsPreFunctor _ _ pcat_prj2 := + @pcat_prj2_isPreFunctor C D E F G. + +Program Definition pcat_prj1_isFunctor {C D E: cat} {F G} := + PreFunctor_IsFunctor.Build _ _ (@pcat_prj1 C D E F G) _ _. +Obligation 2. +destruct a. +destruct b. +destruct c0. +destruct f. +destruct g. +simpl; simpl in *. +unfold Fhom. +simpl. auto. +Defined. + +Program Definition pcat_prj2_isFunctor {C D E: cat} {F G} := + PreFunctor_IsFunctor.Build _ _ (@pcat_prj2 C D E F G) _ _. +Obligation 2. +destruct a. +destruct b. +destruct c0. +destruct f. +destruct g. +simpl; simpl in *. +unfold Fhom. +simpl. auto. +Defined. + +HB.instance Definition _ {C D E F G} : PreFunctor_IsFunctor _ _ pcat_prj1 := + @pcat_prj1_isFunctor C D E F G. + +HB.instance Definition _ {C D E F G} : PreFunctor_IsFunctor _ _ pcat_prj2 := + @pcat_prj2_isFunctor C D E F G. + +(* +Definition pcat_prj1 {C D E F G} (P: @ptype C D E F G) : C := + fst (tag P). + +Definition pcat_prj2 {C D E F G} (P: @ptype C D E F G) : D := + snd (tag P). + +Program Definition pcat_prj1_isPreFunctor {C D E F G} := + IsPreFunctor.Build _ _ (@pcat_prj1 C D E F G) _. +Obligation 1. +destruct X as [f Y]. +exact f.1. +Defined. + +Program Definition pcat_prj2_isPreFunctor {C D E F G} := + IsPreFunctor.Build _ _ (@pcat_prj2 C D E F G) _. +Obligation 1. +destruct X as [f Y]. +exact f.2. +Defined. + +HB.instance Definition _ {C D E F G} : IsPreFunctor _ _ pcat_prj1 := + @pcat_prj1_isPreFunctor C D E F G. + +HB.instance Definition _ {C D E F G} : IsPreFunctor _ _ pcat_prj2 := + @pcat_prj2_isPreFunctor C D E F G. + +Program Definition pcat_prj1_isFunctor {C D E: cat} {F G} := + PreFunctor_IsFunctor.Build _ _ (@pcat_prj1 C D E F G) _ _. +*) + + + +(************************************************************************) + (*** GENERALISED ENRICHED CATEGORIES *) Declare Scope encat_scope. @@ -359,7 +698,7 @@ eassert ( forall x, exists y, econstructor. destruct X. reflexivity. -}. +} setoid_rewrite Heqf1 at 3. specialize (A2 (iHom_comp_obligation_1 (iHom_id a1) f1)). @@ -485,7 +824,7 @@ Lemma iHom_Assoc_lemma {C : pbcat} (C0 : C) rewrite D1. rewrite D2. reflexivity. - }. + } setoid_rewrite A2. reflexivity. @@ -967,7 +1306,13 @@ assert (forall (e2: ((c2 *_C0 c3) :> C) = Pb23), (* dependent destruction e2. *) rewrite compoA. rewrite m23_E. - unfold jmcomp. + unfold jmcomp. +(* clear -E23. + rewrite -compoA. + congr (_ \; _ \; _). + Set Printing All. + case: _ / E23. + do [destruct E23] in j23L m23 *. *) dependent destruction E23. rewrite compoA; auto. } @@ -1120,7 +1465,47 @@ HB.structure Definition InternalCat (C : pbcat) := - The horizontal composition of 2-cells is the map part of icomp *) (* HB.structure' Definition DoubleCat := @InternalCat cat. *) -Axiom cat_pbop : HasPBop cat. + +(* this proof, so painful, why? *) +Lemma cat_pbop : HasPBop cat. + econstructor; intros. + destruct H. + simpl in *. + unfold hom in *. + simpl in *. + + set (PB := (@commaE.ptype A B top left2top right2top : cat)). + + assert (PB ~> A) as L1. + { subst PB. + unfold hom. + simpl. + + set (ff := @pcat_prj1 A B top left2top right2top). + econstructor. + instantiate (1:=ff). + econstructor. + subst ff. + + eapply pcat_prj1_isFunctor. + } + + assert (PB ~> B) as R1. + { subst PB. + unfold hom. + simpl. + + set (ff := @pcat_prj2 A B top left2top right2top). + econstructor. + instantiate (1:=ff). + econstructor. + subst ff. + + eapply pcat_prj2_isFunctor. + } + + eexact (@Span cat A B PB L1 R1). +Qed. HB.instance Definition _ := cat_pbop. Axiom cat_preb : From d88dd204036aa7a0c43e9bcd9a6bfd6125804d8e Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Mon, 29 Jan 2024 14:04:20 +0100 Subject: [PATCH 137/147] wip --- HB/structure.elpi | 20 +- Makefile.coq.local | 2 +- Makefile.test-suite.coq.local | 2 +- _CoqProject | 3 +- _CoqProject.test-suite | 2 +- tests/hnf.v.out | 3 - theories/encatI.v | 1083 ++----------------------- structures.v => theories/structures.v | 4 + 8 files changed, 78 insertions(+), 1041 deletions(-) rename structures.v => theories/structures.v (99%) diff --git a/HB/structure.elpi b/HB/structure.elpi index fea5c9d00..e768ad202 100644 --- a/HB/structure.elpi +++ b/HB/structure.elpi @@ -180,10 +180,11 @@ declare Module BSkel Sort :- std.do! [ log.coq.env.end-module-name ElpiOperationModName ElpiOperations, export.module ElpiOperationModName ElpiOperations, - % we need to filter the wrappers out of ML - std.filter ML (x\ wrapper-mixin x _ _) WrapperML, % we need to assert locally the clauses in EX - EX => std.forall WrapperML private.reexport-wrapper-as-instance, + EX => std.forall ML private.reexport-wrapper-as-instance, + + %hack + hack, if-verbose (coq.say {header} "abbreviation factory-by-classname"), @@ -196,6 +197,11 @@ declare Module BSkel Sort :- std.do! [ % NewClauses => instance.saturate-instances, ]. +pred hack. +hack :- coq.next-synterp-action (begin-section X), coq.env.begin-section X, hack. +hack :- coq.next-synterp-action end-section, coq.env.end-section, hack. +hack. + /* ------------------------------------------------------------------------- */ /* ----------------------------- private code ------------------------------ */ /* ------------------------------------------------------------------------- */ @@ -703,7 +709,7 @@ lift-to-the-subject.aux [factory-on-subject-lifter Expr _ _|_] _ _ :- % instance.declare-const (notably used in the API, i.e. in structures.v, % HB.instance) pred reexport-wrapper-as-instance i:mixinname. -reexport-wrapper-as-instance M :- std.do! [ +reexport-wrapper-as-instance M :- wrapper-mixin M _ _, !, std.do! [ % need the body of the wrapper projection type exported-op M _ C, @@ -718,5 +724,11 @@ reexport-wrapper-as-instance M :- std.do! [ get-option "wrapper" ff => instance.declare-const Str B Arity _ ]. +reexport-wrapper-as-instance _ :- + std.assert! (coq.next-synterp-action (begin-section SectionName)) "synterp code did not open section", + coq.env.begin-section SectionName, + std.assert! (coq.next-synterp-action (end-section)) "synterp code did not close section", + coq.env.end-section. + }} diff --git a/Makefile.coq.local b/Makefile.coq.local index fdbf88499..574d21940 100644 --- a/Makefile.coq.local +++ b/Makefile.coq.local @@ -1,5 +1,5 @@ # Coq does not know about Elpi Accumulate File, so we declare the dependency here -structures.vo : $(wildcard HB/*.elpi HB/common/*.elpi) +theories/structures.vo : $(wildcard HB/*.elpi HB/common/*.elpi) clean:: $(SHOW)'CLEAN *.hb *.hb.old' diff --git a/Makefile.test-suite.coq.local b/Makefile.test-suite.coq.local index 2b1a6ac59..605b5634e 100644 --- a/Makefile.test-suite.coq.local +++ b/Makefile.test-suite.coq.local @@ -7,7 +7,7 @@ output_for=`\ fi` DIFF=\ - @if [ -z "$$COQ_ELPI_ATTRIBUTES" ]; then \ + if [ -z "$$COQ_ELPI_ATTRIBUTES" ]; then \ echo OUTPUT DIFF $(1);\ $(COQTOP) $(COQFLAGS) $(COQLIBS) -topfile $(1) \ < $(1) 2>/dev/null \ diff --git a/_CoqProject b/_CoqProject index 1222fe98f..227bfb087 100644 --- a/_CoqProject +++ b/_CoqProject @@ -1,10 +1,9 @@ -structures.v +theories/structures.v theories/cat.v theories/encatD.v theories/encatI.v -arg -w -arg -elpi.accumulate-syntax -arg -w -arg +elpi.typecheck --Q . HB -R tests HB.tests -R examples HB.examples diff --git a/_CoqProject.test-suite b/_CoqProject.test-suite index 5412b499b..9c7e78e57 100644 --- a/_CoqProject.test-suite +++ b/_CoqProject.test-suite @@ -100,4 +100,4 @@ tests/tag_wrap.v -R tests HB.tests -R examples HB.examples --Q . HB \ No newline at end of file +-R theories HB \ No newline at end of file diff --git a/tests/hnf.v.out b/tests/hnf.v.out index 7d6491aa9..f94f1ac4b 100644 --- a/tests/hnf.v.out +++ b/tests/hnf.v.out @@ -7,6 +7,3 @@ HB_unnamed_mixin_8 = Datatypes_bool__canonical__hnf_S = {| S.sort := bool; S.class := {| S.hnf_M_mixin := hnf_f__to__hnf_M__11 |} |} : S.type -HB_unnamed_mixin_12 = -Builders_1.HB_unnamed_factory_3 bool HB_unnamed_factory_9 - : M.axioms_ bool diff --git a/theories/encatI.v b/theories/encatI.v index 1e6a8ede9..228ace8fd 100644 --- a/theories/encatI.v +++ b/theories/encatI.v @@ -276,14 +276,16 @@ Definition pcat_prj2 {C D E F G} (P: @commaE.ptype C D E F G) : D := Program Definition pcat_prj1_isPreFunctor {C D E F G} := IsPreFunctor.Build _ _ (@pcat_prj1 C D E F G) _. Obligation 1. -destruct X as [f Y]. +About IsPreFunctor.phant_Build. +Show. +destruct H as [f Y]. exact f.1. Defined. Program Definition pcat_prj2_isPreFunctor {C D E F G} := IsPreFunctor.Build _ _ (@pcat_prj2 C D E F G) _. Obligation 1. -destruct X as [f Y]. +destruct H as [f Y]. exact f.2. Defined. @@ -298,7 +300,8 @@ Program Definition pcat_prj1_isFunctor {C D E: cat} {F G} := Obligation 2. destruct a. destruct b. -destruct c0. +Show. +destruct x. destruct f. destruct g. simpl; simpl in *. @@ -311,7 +314,7 @@ Program Definition pcat_prj2_isFunctor {C D E: cat} {F G} := Obligation 2. destruct a. destruct b. -destruct c0. +destruct x. destruct f. destruct g. simpl; simpl in *. @@ -655,7 +658,8 @@ Obligation 1. eapply (@iHom_id C C0 a). Defined. Obligation 2. -eapply (@iHom_comp C C0 a b c0 X X0). +Show. +eapply (@iHom_comp C C0 _ _ _ H H0). Defined. HB.instance Definition iHom_precat' {C: pbcat} (C0 : C) := iHom_precat C0. @@ -1374,24 +1378,64 @@ destruct (X E33) as [mm R]. exact mm. Qed. -(* Print Assumptions iprodCAsc. *) (* An internal precategory is an internal category with two operators that must be src and tgt preserving, i.e. iHom morphisms: identity : C0 -> C1 (corresponding to horizontal 1-morphism identity in double cat) and composition : C1 * C1 -> C1 (corresponding to horizontal composition) *) + +(*Set Printing All.*) (* bug in elpi 2.0.1 *) HB.mixin Record IsInternalPreCat (C : pbcat) (C0 : obj C) of @InternalQuiver C C0 := { iidI : (C0 : iHom C0) ~>_(iHom C0) (@C1 C C0 : iHom C0); - icompI : let C1 := @C1 C C0 : iHom C0 in - let C2 := pbC0 C1 C1 : iHom C0 in - (C2 ~>_(iHom C0) C1) + icompI : + + let C1 : iHom C0 := @C1 C C0 in + let C2 : iHom C0 := @pbC0 C C0 C1 C1 in + + (C2 ~>_(iHom C0) C1 ) }. +(* bad +-------> G: PBCat.type +-------> G: (obj C) +-------> G: (@InternalQuiver.axioms_ C C0) +-------> G: (IsPreInternalQuiver.axioms_ (encatI_PBCat__to__cat_Quiver C) C0) +-------> G: (IsInternalQuiver.axioms_ (encatI_PBCat__to__cat_Quiver C) C0 + local_mixin_encatI_IsPreInternalQuiver) +-------> G: Type +-------> G: (@hom (@InternalHom.type (elpi.hole elpi.hole) C0) + (C0 : @InternalHom.type (elpi.hole elpi.hole) C0) + (@C1 C C0 : @InternalHom.type (elpi.hole elpi.hole) C0)) +-------> G: (let C1 := @C1 C C0 in + let C2 := @pbC0 C C0 C1 C1 in +@hom (@InternalHom.type (elpi.hole C2 C1 elpi.hole) C0) C2 C1) + + + + +-------> G: PBCat.type +-------> G: (obj C) +-------> G: (@InternalQuiver.axioms_ C C0) +-------> G: (IsPreInternalQuiver.axioms_ (encatI_PBCat__to__cat_Quiver C) C0) +-------> G: (IsInternalQuiver.axioms_ (encatI_PBCat__to__cat_Quiver C) C0 + local_mixin_encatI_IsPreInternalQuiver) +-------> G: Type +-------> G: (@hom (@InternalHom.type (elpi.hole elpi.hole) C0) + (C0 : @InternalHom.type (elpi.hole elpi.hole) C0) + (@C1 C C0 : @InternalHom.type (elpi.hole elpi.hole) C0)) +-------> G: (let C1 : @InternalHom.type (elpi.hole elpi.hole) C0 := @C1 C C0 in + let C2 : @InternalHom.type (elpi.hole C1 elpi.hole) C0 := + @pbC0 C C0 C1 C1 in + @hom (@InternalHom.type (elpi.hole C2 C1 elpi.hole) C0) C2 C1) + *) + #[short(type="iprecat")] HB.structure Definition InternalPreCat (C : pbcat) := { C0 of @IsInternalPreCat C C0 }. +Unset Printing All. + Program Definition iidC' {C : pbcat} {C0 : iprecat C} : ((C0 : iHom C0) :> C) ~>_C ((@C1 C C0 : iHom C0) :> C). @@ -1468,7 +1512,7 @@ HB.structure Definition InternalCat (C : pbcat) := (* this proof, so painful, why? *) Lemma cat_pbop : HasPBop cat. - econstructor; intros. + econstructor; intros A B H. destruct H. simpl in *. unfold hom in *. @@ -1523,1025 +1567,6 @@ Definition doublecat := icat cat. (* Check (doublecat <~> ???) *) - -(************************************************************************) - -(*** STRICT DOUBLE CATEGORIES (without internal categories) *) - -(* Strict double categories, from - https://ncatlab.org/nlab/show/double+category - (we don't use internal categories) - - base obejcts as 0-cells: C ; - - vertical 1-morphisms (category D0 on C): hom C ; - - horizontal 1-morphisms (category H on C): hom (transpose C) ; - - horizontal 1-morhisms as 1-cells for D1: D1obj C ; - - 2-morphisms (category D1 on C1obj): hom (D1obj C) ; - - horizontally composable pairs of 1-cells : DPobj C ; - - horizontally composable pairs of 2-morphisms - (product category DP, D1 *0 D1) : hom (DPobj C) ; - - The definition of Strict Double Category, SDouble = (D0, H, D1, Dp), - is given by: - - - base objects C - - - (level-1) category (D0) of vertical 1-morphism on C - - - (level-1) category (H) of horizontal 1-morphism (D1obj) on C - - - (level-2) category (D1) of vertical 2-morphism on D1obj - - - (derived) category (DP) of vertical 2-morphisms on - horizontally D0-composable D1 products - ($\mbox{D1} *_0 \mbox{D1}$) - - - Source functor: $\mbox{D1} \to \mbox{D0}$ - - - Target functor: $\mbox{D1} \to \mbox{D0}$ - - - Horizontal unit functor: $\mbox{D0} \to \mbox{D1}$ - - - Horizontal composition functor: $\mbox{DP} \to \mbox{D1}$ -*) - - -(** Quivers for double categories *) - -(* transpose for horizontal morphism quiver. - HB.tag needed to identify transpose as lifter *) -HB.tag Definition transpose (C : quiver) : U := C. -#[wrapper] HB.mixin Record _IsHQuiver C of IsQuiver C := { - is_hquiver : IsQuiver (transpose C) -}. -(* vertical and horizontal quivers, defining cells *) -Unset Universe Checking. -#[short(type="vhquiver")] -HB.structure Definition VHQuiver : Set := - { C of IsQuiver C & IsQuiver (transpose C) }. -Set Universe Checking. - -HB.tag Definition hhom (c : VHQuiver.type) : c -> c -> U := @hom (transpose c). -Notation "a +> b" := (hhom a b) - (at level 99, b at level 200, format "a +> b") : cat_scope. - -(* record to represent the set of morphims - (needed for 2-objects, i.e. horizontal morphisms) *) -Record Total2 T (h: T -> T -> U) : Type := TT2 { - source : T; - target : T; - this_morph : h source target }. - -(* the set of horizontal morphisms. *) -HB.tag Definition D1obj (C: vhquiver) := Total2 (@hhom C). - -(* D1 quiver requirement (includes D0 quiver and its transpose). *) -#[wrapper] -HB.mixin Record _IsDQuiver T of VHQuiver T := - { is_dquiver : Quiver (D1obj T) }. -Unset Universe Checking. -#[short(type="dquiver")] -HB.structure Definition DQuiver : Set := { C of Quiver (D1obj C) }. -Set Universe Checking. - - -(** Horizonal D0-level category (H-D0) *) - -(* Precategory based on the HQuiver (i.e. horizontal precategory on D0 - objects) *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record _IsHPreCat T of VHQuiver T := { - is_hprecat : Quiver_IsPreCat (transpose T) }. -#[short(type="hprecat")] -HB.structure Definition HPreCat : Set := - { C of Quiver_IsPreCat (transpose C) }. -Set Universe Checking. - -(* The category based on the HQuiver (i.e. horizontal category on D0 - objects) *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record _IsHCat T of HPreCat T := { - is_hcat : PreCat_IsCat (transpose T) }. -#[short(type="hcat")] -HB.structure Definition HCat : Set := - { C of PreCat_IsCat (transpose C) }. -Set Universe Checking. - - -(** Vertical 2-cell level category (D1 category) *) - -(* Precategory based on the DQuiver (i.e. precategory D1). Gives: - vertical 2-cell identity morphism. - vertical 2-cell composition. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record _IsD1PreCat T of DQuiver T := { - is_d1precat : Quiver_IsPreCat (@D1obj T) }. -#[short(type="d1precat")] -HB.structure Definition D1PreCat : Set := - { C of Quiver_IsPreCat (@D1obj C) }. -Set Universe Checking. - -(* The category based on the DQuiver (i.e. category D1). *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record _IsD1Cat T of D1PreCat T := { - is_d1cat : PreCat_IsCat (@D1obj T) }. -#[short(type="d1cat")] -HB.structure Definition D1Cat : Set := - { C of PreCat_IsCat (@D1obj C) }. -Set Universe Checking. - - -(** Naked double category *) - -(* Naked double category. Vertical (V-D0) and D1 categories. Double - category without horizontal operators and functors *) -Unset Universe Checking. -#[short(type="dcat")] -HB.structure Definition DCat : Set := - { C of Cat C & D1Cat C }. -Set Universe Checking. - -(* Naked strict double category. Vertical (V-D0), horizontal (H-D0) - and D1 categories. Strict double category without functors *) -Unset Universe Checking. -#[short(type="sd2cat")] -HB.structure Definition SDCat : Set := { C of Cat C & HCat C & D1Cat C }. -Set Universe Checking. - - -(** Auxiliary notions for Source, Target and - Horizontal Unit functors *) - -(* homsets of 2-cell (D1) morphisms *) -Definition d1hom (D: DQuiver.type) : D1obj D -> D1obj D -> U := - @hom (D1obj D). -(* type-level smart constructor for D1 homsets *) -Definition D1hom (D: DQuiver.type) (a b c d: D) (h0: hhom a b) - (h1: hhom c d) : U := d1hom (TT2 h0) (TT2 h1). - -(* smart projections for: - source functor (for horizontal morphisms): D1 -> D0. - defined as object-level function, by functoriality lifted to a - (2-cell, vertical) morphism-level one *) -HB.tag Definition HSource C := fun (X: D1obj C) => @source C (@hhom C) X. -(* target functor (for horizontal morphisms): D1 -> D0. *) -HB.tag Definition HTarget C := fun (X: D1obj C) => @target C (@hhom C) X. - -(* horizontal unit functor: D0 -> D1 *) -Definition hhunit (T: hprecat) (a: T) : D1obj T := - @TT2 T (@hhom T) a a (@idmap (transpose T) a). -HB.tag Definition H1Unit (C: hprecat) := - fun (x: HPreCat.sort C) => @hhunit C x. - - -(** Auxiliary notions for 2-cell Horizontal Composition functor *) - -(* composable pairs of morphisms as a set *) -Record GenComp T (h: T -> T -> U) := GC { - h_one : T; - h_two : T ; - h_three : T; - h_first : h h_one h_two ; - h_second : h h_two h_three }. - -(* composable pairs of horizontal morphisms as a set *) -HB.tag Definition DPobj (C: vhquiver) := GenComp (@hhom C). - -(* smart projections *) -Definition H2First (C: vhquiver) (X: @DPobj C) : D1obj C := - @TT2 C _ (h_one X) (h_two X) (h_first X). -Definition H2Second (C: vhquiver) (X: @DPobj C) : D1obj C := - @TT2 C _ (h_two X) (h_three X) (h_second X). - - -(* horizontal composition functor: D1 * D1 -> D1 *) -Definition hhcomp (T: hprecat) (x: DPobj T) : D1obj T := - match x with - @GC _ _ a b c h1 h2 => @TT2 T (@hhom T) a c (h1 \; h2) end. -HB.tag Definition H1Comp (C: hprecat) := - fun (x: DPobj C) => @hhcomp C x. - -(* hhunit - horizontal unit functor. - - hhcomp - horizontal composition functor (horizontal composition of - two horizontal morphisms from a cell product). - - Both specified as object-level functions (they actually come for - free from the H-D0 category, since we are in the strict case), to - be lifted by functoriality to morphism-level ones. - - At the object level, hhunit gives a horizontal identity morphism - for each D0 object. At the morphism level, it gives horizontal - 2-cell identity for each vertical morphism. - - In the case of hhcomp, relying on functoriality requires some care - in defining the product category, making sure that adjacency at the - object-level (between horizontal morphisms) is matched by adjacency - at the morphism-level (between 2-cells). *) - - -(** Source and target functors *) - -(* source prefunctor. - D1obj T is the quiver of the 2-morphisms, thanks to VHQuiver. - T is the quiver of 1-morphisms. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsSPreFunctor T of DCat T := { - is_sprefunctor : IsPreFunctor (D1obj T) T (@HSource T) }. -HB.structure Definition SPreFunctor : Set := {C of IsSPreFunctor C}. -Set Universe Checking. - -(* target prefunctor. *) -Unset Universe Checking. -#[wrapper] - HB.mixin Record IsTPreFunctor T of DCat T := { - is_tprefunctor : IsPreFunctor (D1obj T) T (@HTarget T) }. -HB.structure Definition TPreFunctor : Set := {C of IsTPreFunctor C}. -Set Universe Checking. - -(* source functor. *) -Unset Universe Checking. -#[wrapper] - HB.mixin Record SPreFunctor_IsFunctor T of SPreFunctor T := { - is_sfunctor : PreFunctor_IsFunctor (D1obj T) T (@HSource T) }. -HB.structure Definition SFunctor : Set := {C of SPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* target functor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record TPreFunctor_IsFunctor T of TPreFunctor T := { - is_tfunctor : PreFunctor_IsFunctor (D1obj T) T (@HTarget T) }. -HB.structure Definition TFunctor : Set := {C of TPreFunctor_IsFunctor C}. -Set Universe Checking. - - -(** Unit functor *) - -(* unit prefunctor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsUPreFunctor T of SDCat T := - { is_uprefunctor : IsPreFunctor T (D1obj T) (@H1Unit T) }. -HB.structure Definition UPreFunctor : Set := {C of IsUPreFunctor C}. -Set Universe Checking. - -(* unit functor. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record UPreFunctor_IsFunctor T of UPreFunctor T := { - is_ufunctor : PreFunctor_IsFunctor T (D1obj T) (@H1Unit T) }. -HB.structure Definition UFunctor : Set := {C of UPreFunctor_IsFunctor C}. -Set Universe Checking. - -Unset Universe Checking. -HB.about Functor. -HB.structure Definition STUFunctor : Set := - {C of SFunctor C & TFunctor C & UFunctor C}. -Set Universe Checking. - - -(** Lifting of Source, Target and Unit functors to D1 morphisms *) - -(* 2-cell source *) -Definition H1Source (T: SFunctor.type) (a b: @D1obj T) - (m: @d1hom T a b) : - (HSource a) ~> (HSource b) := (@HSource T) <$> m. - -(* 2-cell target *) -Definition H1Target (T: TFunctor.type) (a b: @D1obj T) - (m: @d1hom T a b) : - (HTarget a) ~> (HTarget b) := (@HTarget T) <$> m. - -(* horizontal 2-cell unit (maps vertical morphisms to horizontally - unitary 2-cells) *) -Definition H2Unit (T: UFunctor.type) (a b: T) (m: @hom T a b) : - (H1Unit a) ~> (H1Unit b) := (@H1Unit T) <$> m. - - -(** Horizontal product category (D1 *d0 D1) *) -(* DPobj T is the pseudo-pullback category used to deal with - products of D1 (where the adjacency condition is expressed - w.r.t. D0 *) - -(* horizontal composition of two (naked) horizontal morphisms *) -Definition l_hcomp (T: SDCat.type) (a0 a1 a2: T) - (h0: hhom a0 a1) (h1: hhom a1 a2) : D1obj T := - @TT2 T _ a0 a2 (h0 \; h1). - - -(** DPobj quiver *) -Definition DP_hom (T: STUFunctor.type) (x y: DPobj T) := - sigma (hh0: D1hom (h_first x) (h_first y)) - (hh1: D1hom (h_second x) (h_second y)), - H1Target hh0 = H1Source hh1. - -HB.instance Definition DPQuiver (T: STUFunctor.type) : - IsQuiver (DPobj T) := - IsQuiver.Build (DPobj T) (fun A B => @DP_hom T A B). - - -(** Product precategory *) - -Lemma DP_id_eq (T : STUFunctor.type) (a: DPobj T) : - H1Target (@idmap (@D1obj T) (H2First a)) = - H1Source (@idmap (@D1obj T) (H2Second a)). -unfold H1Target, HTarget. -unfold H1Source, HSource. -repeat rewrite F1; auto. -Defined. - -(* DPobj identity *) -Definition DP_id (T: STUFunctor.type) (A: DPobj T) : A ~> A := - let h0 := h_first A - in let h1 := h_second A - in let uu0 := @idmap (D1obj T) (TT2 h0) - in let uu1 := @idmap (D1obj T) (TT2 h1) - in @existT (D1hom h0 h0) - (fun hh0: (D1hom h0 h0) => - sigma (hh1 : D1hom h1 h1), H1Target hh0 = H1Source hh1) uu0 - (@existT (D1hom h1 h1) - (fun hh1: (D1hom h1 h1) => H1Target uu0 = H1Source hh1) uu1 - (@DP_id_eq T A)). - -Definition DP_comp_auxA (T : STUFunctor.type) - (A B C : DPobj T) - (hhA0 : D1hom (h_first A) (h_first B)) - (hhA1 : D1hom (h_second A) (h_second B)) - (ppA : H1Target hhA0 = H1Source hhA1) - (hhB0 : D1hom (h_first B) (h_first C)) - (hhB1 : D1hom (h_second B) (h_second C)) - (ppB : H1Target hhB0 = H1Source hhB1) : - (H1Target hhA0) \; (H1Target hhB0) = - (H1Source hhA1) \; (H1Source hhB1). - rewrite ppA. - rewrite ppB. - reflexivity. -Defined. - -Definition DP_comp_auxS (T : STUFunctor.type) - (A B C : DPobj T) - (hhA0 : D1hom (h_first A) (h_first B)) - (hhA1 : D1hom (h_second A) (h_second B)) - (ppA : H1Target hhA0 = H1Source hhA1) - (hhB0 : D1hom (h_first B) (h_first C)) - (hhB1 : D1hom (h_second B) (h_second C)) - (ppB : H1Target hhB0 = H1Source hhB1) : - H1Source (hhA1 \; hhB1) = (H1Source hhA1) \; (H1Source hhB1). - unfold H1Source, HSource. - repeat rewrite Fcomp. - reflexivity. -Defined. - -Definition DP_comp_auxT (T : STUFunctor.type) - (A B C : DPobj T) - (hhA0 : D1hom (h_first A) (h_first B)) - (hhA1 : D1hom (h_second A) (h_second B)) - (ppA : H1Target hhA0 = H1Source hhA1) - (hhB0 : D1hom (h_first B) (h_first C)) - (hhB1 : D1hom (h_second B) (h_second C)) - (ppB : H1Target hhB0 = H1Source hhB1) : - H1Target (hhA0 \; hhB0) = (H1Target hhA0) \; (H1Target hhB0). - unfold H1Target, HTarget. - repeat rewrite Fcomp. - reflexivity. -Defined. - -Definition DP_comp_auxI (T : STUFunctor.type) - (A B C : DPobj T) - (hhA0 : D1hom (h_first A) (h_first B)) - (hhA1 : D1hom (h_second A) (h_second B)) - (ppA : H1Target hhA0 = H1Source hhA1) - (hhB0 : D1hom (h_first B) (h_first C)) - (hhB1 : D1hom (h_second B) (h_second C)) - (ppB : H1Target hhB0 = H1Source hhB1) : - A ~> C. - econstructor 1 with (comp hhA0 hhB0). - econstructor 1 with (comp hhA1 hhB1). - setoid_rewrite DP_comp_auxS; eauto. - setoid_rewrite DP_comp_auxT; eauto. - eapply DP_comp_auxA; eauto. -Defined. - -(* DPobj composition, defined in proof mode *) -Definition DP_comp (T: STUFunctor.type) (A B C: DPobj T) : - (A ~> B) -> (B ~> C) -> A ~> C. - intros chA chB. - destruct chA as [hhA0 [hhA1 ppA]]. - destruct chB as [hhB0 [hhB1 ppB]]. - eapply DP_comp_auxI; eauto. -Defined. - -(* DPobj is a precategory *) -HB.instance Definition DPPreCat (T: STUFunctor.type) : - Quiver_IsPreCat (DPobj T) := - Quiver_IsPreCat.Build (DPobj T) (@DP_id T) (@DP_comp T). - -(* - have HcompP : - (a b : DPobj T) - (f g : a ~> b), - proj1T f = proj1t f -> - - -> - f = g. - - exists a b p, - fst f = a - f = (a,b,p) -*) - -(** Product category *) - -Lemma DP_LeftUnit_lemma (T : STUFunctor.type) : - forall (a b : DPobj T) (f : a ~> b), idmap \; f = f. - - move => a b [x [x0 e]] /=. - simpl in *. - unfold idmap; simpl. - unfold DP_id; simpl. - unfold comp; simpl. - unfold DP_comp_auxI; simpl. - - assert (idmap \; x = x) as A. - { rewrite comp1o; auto. } - - assert (idmap \; x0 = x0) as A0. - { rewrite comp1o; auto. } - - assert (H1Target (idmap \; x) = H1Source (idmap \; x0)) as B. - { rewrite A. - rewrite A0; auto. } - - destruct a eqn: aaa. - destruct b eqn: bbb. - simpl. - - assert (existT - (fun hh0 : D1hom h_first0 h_first1 => - sigma hh1 : D1hom h_second0 h_second1,H1Target hh0 = H1Source hh1) - (idmap \; x) - (existT - (fun hh1 : D1hom h_second0 h_second1 => - H1Target (idmap \; x) = H1Source hh1) - (idmap \; x0) - B) = - existT - (fun hh0 : D1hom h_first0 h_first1 => - sigma hh1 : D1hom h_second0 h_second1,H1Target hh0 = H1Source hh1) - x - (existT - (fun hh1 : D1hom h_second0 h_second1 => H1Target x = H1Source hh1) - x0 - e)) as C. - { revert B. - revert A. - revert A0. - generalize (idmap \; x) as v. - generalize (idmap \; x0) as v0. - intros v0 v A0. - rewrite A0. - intro A. - rewrite A. - intro B. - - assert (B = e) as BE. - { eapply Prop_irrelevance. } - - rewrite BE. - reflexivity. -} - - inversion aaa; subst. - rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] - (Prop_irrelevance _ B). - eapply C. -Qed. - -Lemma DP_RightUnit_lemma (T : STUFunctor.type) : - forall (a b : DPobj T) (f : a ~> b), f \; idmap = f. - - move => a b [x [x0 e]] /=. - simpl in *. - unfold idmap; simpl. - unfold DP_id; simpl. - unfold comp; simpl. - unfold DP_comp_auxI; simpl. - - assert (x \; idmap = x) as A. - { rewrite compo1; auto. } - - assert (x0 \; idmap = x0) as A0. - { rewrite compo1; auto. } - - assert (H1Target (x \; idmap) = H1Source (x0 \; idmap)) as B. - { rewrite A. - rewrite A0; auto. } - - destruct a eqn: aaa. - destruct b eqn: bbb. - simpl. - - assert (existT - (fun hh0 : D1hom h_first0 h_first1 => - sigma hh1 : D1hom h_second0 h_second1, - H1Target hh0 = H1Source hh1) - (x \; idmap) - (existT - (fun hh1 : D1hom h_second0 h_second1 => - H1Target (x \; idmap) = H1Source hh1) - (x0 \; idmap) - B) = - existT - (fun hh0 : D1hom h_first0 h_first1 => - sigma hh1 : D1hom h_second0 h_second1, - H1Target hh0 = H1Source hh1) - x - (existT - (fun hh1 : D1hom h_second0 h_second1 => - H1Target x = H1Source hh1) - x0 - e)) as C. - { revert B. - revert A. - revert A0. - generalize (x \; idmap) as v. - generalize (x0 \; idmap) as v0. - intros v0 v A0. - rewrite A0. - intro A. - rewrite A. - intro B. - - assert (B = e) as BE. - { eapply Prop_irrelevance. } - - rewrite BE. - reflexivity. - } - - inversion aaa; subst. - rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] - (Prop_irrelevance _ B). - eapply C. -Qed. - -Lemma DP_Assoc_lemma (T : STUFunctor.type) : - forall (a b c d : DPobj T) (f : a ~> b) (g : b ~> c) (h : c ~> d), - f \; g \; h = (f \; g) \; h. - intros. - remember f as f1. - remember g as g1. - remember h as h1. - destruct f as [x0 s0]. - destruct g as [x1 s1]. - destruct h as [x2 s2]. - destruct s0 as [y0 e0]. - destruct s1 as [y1 e1]. - destruct s2 as [y2 e2]. - simpl. - - set (x01 := comp x0 x1). - set (x12 := comp x1 x2). - set (x0_12 := comp x0 x12). - set (x01_2 := comp x01 x2). - set (y01 := comp y0 y1). - set (y12 := comp y1 y2). - set (y0_12 := comp y0 y12). - set (y01_2 := comp y01 y2). - - assert (x0_12 = x01_2) as X0. - { subst x0_12 x01_2. - rewrite compoA; eauto. } - assert (y0_12 = y01_2) as Y0. - { subst y0_12 y01_2. - rewrite compoA; eauto. } - - set (x01_t := comp (H1Target x0) (H1Target x1)). - set (x01_2_t := comp x01_t (H1Target x2)). - set (x12_t := comp (H1Target x1) (H1Target x2)). - set (x0_12_t := comp (H1Target x0) x12_t). - set (y01_s := comp (H1Source y0) (H1Source y1)). - set (y01_2_s := comp y01_s (H1Source y2)). - set (y12_s := comp (H1Source y1) (H1Source y2)). - set (y0_12_s := comp (H1Source y0) y12_s). - - assert (x01_t = y01_s) as E01. - { subst x01_t y01_s. - rewrite e0. - rewrite e1; auto. } - assert (x01_2_t = y01_2_s) as E01_2. - { subst x01_2_t y01_2_s. - rewrite E01. - rewrite e2; auto. } - assert (x12_t = y12_s) as E12. - { subst x12_t y12_s. - rewrite e1. - rewrite e2; auto. } - assert (x0_12_t = y0_12_s) as E0_12. - { subst x0_12_t y0_12_s. - rewrite E12. - rewrite e0; auto. } - - assert (x0_12_t = x01_2_t) as E02T. - { subst x0_12_t x01_2_t. - subst x12_t x01_t. - rewrite compoA; auto. } - assert (y0_12_s = y01_2_s) as E02S. - { subst y0_12_s y01_2_s. - subst y12_s y01_s. - rewrite compoA; auto. } - - unfold comp. - simpl. - unfold DP_comp. - simpl. - inversion Heqf1; subst. - clear H. - - unfold DP_comp_auxI; simpl. - - assert (H1Target (x0 \; x1 \; x2) = - H1Source (y0 \; y1 \; y2)) as KR. - { subst x0_12_t y0_12_s. - subst x12_t y12_s. - unfold H1Target. - repeat rewrite Fcomp; simpl. - unfold H1Target in E0_12. - rewrite E0_12. - unfold H1Source. - repeat rewrite Fcomp; simpl. - auto. - } - - assert (H1Target ((x0 \; x1) \; x2) = - H1Source ((y0 \; y1) \; y2)) as KL. - { subst x01_2_t y01_2_s. - subst x01_t y01_s. - unfold H1Target. - repeat rewrite Fcomp; simpl. - unfold H1Target in E01_2. - rewrite E01_2. - unfold H1Source. - repeat rewrite Fcomp; simpl. - auto. - } - - assert (existT - (fun hh0 : D1hom (h_first a) (h_first d) => - sigma hh1 : D1hom (h_second a) (h_second d), - H1Target hh0 = H1Source hh1) - (x0 \; x1 \; x2) - (existT - (fun hh1 : D1hom (h_second a) (h_second d) => - H1Target (x0 \; x1 \; x2) = H1Source hh1) - (y0 \; y1 \; y2) - KR) - = - existT - (fun hh0 : D1hom (h_first a) (h_first d) => - sigma hh1 : D1hom (h_second a) (h_second d), - H1Target hh0 = H1Source hh1) - ((x0 \; x1) \; x2) - (existT - (fun hh1 : D1hom (h_second a) (h_second d) => - H1Target ((x0 \; x1) \; x2) = H1Source hh1) - ((y0 \; y1) \; y2) - KL)) as KA. - { revert KL. - revert KR. - subst x0_12 x01_2 x12 x01. - subst y0_12 y01_2 y12 y01. - rewrite <- X0. - rewrite <- Y0. - intros KR KL. - - assert (KR = KL) as I1. - { eapply Prop_irrelevance. } - rewrite I1. - reflexivity. - } - - rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] - (Prop_irrelevance _ KR). - - rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] - (Prop_irrelevance _ KL). - eapply KA. -Qed. - -Program Definition DPCatP (T: STUFunctor.type) : - PreCat_IsCat (DPobj T). -econstructor. -eapply DP_LeftUnit_lemma; eauto. -eapply DP_RightUnit_lemma; eauto. -eapply DP_Assoc_lemma; eauto. -Qed. - -(* DPobj is a category *) -HB.instance Definition DPCat (T: STUFunctor.type) := DPCatP T. - - -(** Horizontal composition functor and strict double categories *) - -(* composition prefunctor *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record IsCPreFunctor T of STUFunctor T := - { is_cprefunctor : IsPreFunctor (DPobj T) (D1obj T) (@H1Comp T) }. -HB.structure Definition CPreFunctor : Set := {C of IsCPreFunctor C}. -Set Universe Checking. - -(* composition functor - gives the definition of Strict Double Category *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record CPreFunctor_IsFunctor T of CPreFunctor T := { - is_cfunctor : PreFunctor_IsFunctor (DPobj T) (D1obj T) (@H1Comp T) }. -#[short(type="sdoublecat")] -HB.structure Definition SDoubleCat : Set := {C of CPreFunctor_IsFunctor C}. -Set Universe Checking. - -(* horizontal 2-cell composition: maps two adjecent pairs of - horizontal morphisms (a and b) and a pullback-category morphism - between them (m, which basically gives two adjecent cells) to a - 2-cell morphism between the horizontal composition (HComp) of each - pair *) -Definition HC2Comp (T: SDoubleCat.type) (a b: DPobj T) - (m: @hom (DPobj T) a b) : - d1hom (H1Comp a) (H1Comp b) := @Fhom _ _ (@H1Comp T) a b m. - -Program Definition HC2Comp_flat (T: SDoubleCat.type) (a0 a1 a2 b0 b1 b2: T) - (h0: hhom a0 a1) (h1: hhom a1 a2) - (k0: hhom b0 b1) (k1: hhom b1 b2) - (hh0: D1hom h0 k0) - (hh1: D1hom h1 k1) - (k: H1Target hh0 = H1Source hh1) - : (* D1hom (hcomp _ _ _ h0 h1) (hcomp _ _ _ k0 k1) *) - d1hom (l_hcomp h0 h1) (l_hcomp k0 k1) := - @Fhom _ _ (@H1Comp T) (GC h0 h1) (GC k0 k1) _. -Obligation 1. -refine (@existT (D1hom h0 k0) _ hh0 (@existT (D1hom h1 k1) _ hh1 k)). -Defined. - -(*HB.builders Context (T : obj cat) (f : IsInternalCat cat T).*) -(* Context (f : doublecat). *) - -(* hcomp (hm, hu) = prj1 (hm, hu) = hm - hcomp (hu, hm) = prj2 (hu, hm) = hm - (hm1 * hm2) * hm3 ~> hm1 * (hm2 * hm3) - -(* Double category with universal characterization of weak - horizontal associativity *) -HB.mixin Record IsDCat_UA T of CFunctor T := { - associator : forall (a0 a1 a2 a3: T) - (h1: @hhom T a0 a1) (h2: @hhom T a1 a2) - (h3: @hhom T a2 a3), - let h23 := hcomp a1 a2 a3 h2 h3 in - let h12 := hcomp a0 a1 a2 h1 h2 in - let hh1 := hcomp a0 a1 a3 h1 h23 in - let hh2 := hcomp a0 a2 a3 h12 h3 in - @hom (HHomSet T) (@HO T (@hhom T) a0 a3 hh2) - (@HO T (@hhom T) a0 a3 hh1) -}. -*) - -(*********************************************************************) - -Program Definition brel_fcast {X Y C : Type} {F: X -> C} {G: Y -> C} - {a1 b1: X} {a2 b2: Y} {R: C -> C -> Type} - (e1: F a1 = G a2) (e2: F b1 = G b2) : - R (G a2) (G b2) = R (F a1) (F b1). -rewrite e1. -rewrite e2. -auto. -Defined. - -Program Definition recast2 {X Y C : Type} {F: X -> C} {G: Y -> C} - {a1 b1: X} {a2 b2: Y} {R: C -> C -> Type} - (e1: F a1 = G a2) (e2: F b1 = G b2) - (x: R (G a2) (G b2)) : R (F a1) (F b1). -rewrite -(brel_fcast e1 e2). -exact x. -Defined. - -Program Definition brel_fcast_h {X Y C : Type} {F: X -> C} {G: Y -> C} - {a1 b1: X} {a2 b2: Y} {R: C -> C -> Type} - (e1: F a1 = G a2) (e2: F b1 = G b2) - (x: R (G a2) (G b2)) (P: forall T: Type, T -> Prop) : - P _ x = P _ (recast2 e1 e2 x). -unfold recast2. -unfold eq_rect. -unfold brel_fcast. -unfold eq_ind_r. -unfold eq_ind. -unfold eq_sym. -dependent destruction e1. -dependent destruction e2. -auto. -Defined. - -Program Definition brel_fcast_3h {X Y C : Type} {F: X -> C} {G: Y -> C} - {a1 b1 c1: X} {a2 b2 c2: Y} {R: C -> C -> Type} - (e1: F a1 = G a2) (e2: F b1 = G b2) (e3: F c1 = G c2) - (x: R (G a2) (G b2)) (y: R (G b2) (G c2)) (z: R (G a2) (G c2)) - (P: forall T1 T2 T3: Type, T1 -> T2 -> T3 -> Prop) : - P _ _ _ x y z = P _ _ _ (recast2 e1 e2 x) (recast2 e2 e3 y) (recast2 e1 e3 z). -unfold recast2. -unfold eq_rect. -unfold brel_fcast. -unfold eq_ind_r. -unfold eq_ind. -unfold eq_sym. -dependent destruction e1. -dependent destruction e2. -dependent destruction e3. -auto. -Defined. - -Program Definition brel_fcast_3hh {X Y C : Type} {F: X -> C} {G: Y -> C} - {a1 b1 c1: X} {a2 b2 c2: Y} {R: C -> C -> Type} - (e1: F a1 = G a2) (e2: F b1 = G b2) (e3: F c1 = G c2) - (x: R (G a2) (G b2)) (y: R (G b2) (G c2)) (z: R (G a2) (G c2)) - (P: forall (d1 d2 d3: C), R d1 d2 -> R d2 d3 -> R d1 d3 -> Prop) : - P _ _ _ x y z = P _ _ _ (recast2 e1 e2 x) (recast2 e2 e3 y) (recast2 e1 e3 z). -unfold recast2. -unfold eq_rect. -unfold brel_fcast. -unfold eq_ind_r. -unfold eq_ind. -unfold eq_sym. -dependent destruction e1. -dependent destruction e2. -dependent destruction e3. -auto. -Defined. - -Program Definition recast2_h {X Y C : Type} {F: X -> C} {G: Y -> C} - {a1 b1: X} {a2 b2: Y} {R: C -> C -> Type} - (e1: F a1 = G a2) (e2: F b1 = G b2) - (x: R (G a2) (G b2)) (P: forall T: Type, T -> Prop) - (p: P _ x) : P _ (recast2 e1 e2 x). -rewrite -(brel_fcast_h e1 e2). -exact p. -Defined. - -Program Definition recast2_3h {X Y C : Type} {F: X -> C} {G: Y -> C} - {a1 b1 c1: X} {a2 b2 c2: Y} {R: C -> C -> Type} - (e1: F a1 = G a2) (e2: F b1 = G b2) (e3: F c1 = G c2) - (x: R (G a2) (G b2)) (y: R (G b2) (G c2)) (z: R (G a2) (G c2)) - (P: forall T1 T2 T3: Type, T1 -> T2 -> T3 -> Prop) - (p: P _ _ _ x y z) : - P _ _ _ (recast2 e1 e2 x) (recast2 e2 e3 y) (recast2 e1 e3 z). -rewrite -(brel_fcast_3h e1 e2 e3). -exact p. -Defined. - -Program Definition recast2_3hh {X Y C : Type} {F: X -> C} {G: Y -> C} - {a1 b1 c1: X} {a2 b2 c2: Y} {R: C -> C -> Type} - (e1: F a1 = G a2) (e2: F b1 = G b2) (e3: F c1 = G c2) - (x: R (G a2) (G b2)) (y: R (G b2) (G c2)) (z: R (G a2) (G c2)) - (P: forall (d1 d2 d3: C), R d1 d2 -> R d2 d3 -> R d1 d3 -> Prop) - (p: P _ _ _ x y z) : - P _ _ _ (recast2 e1 e2 x) (recast2 e2 e3 y) (recast2 e1 e3 z). -rewrite -(brel_fcast_3hh e1 e2 e3). -exact p. -Defined. - -Program Definition recast_hom {X Y C : precat} {F: X -> C} {G: Y -> C} - {a1 b1: X} {a2 b2: Y} {R: C -> C -> Type} - (e1: F a1 = G a2) (e2: F b1 = G b2) - (x: (G a2) ~> (G b2)) : (F a1) ~> (F b1). -eapply recast2; eauto. -Defined. - -Definition recast21 {X Y C : Type} {F: X -> C} {G: Y -> C} - {R: C -> C -> Type} {a b: (X * Y)} - (e: (F (fst a), F (fst b)) = (G (snd a), G (snd b))) -(* - (e1: F (fst a) = G (snd a)) (e2: F (fst b) = G (snd b)) *) - (x: R (G (snd a)) (G (snd b))) : R (F (fst a)) (F (fst b)). - destruct a as [a1 a2]. - destruct b as [b1 b2]. - inversion e; subst. - rewrite H0. - rewrite H1. - auto. -Defined. - -Definition mk_pair_eq {X Y C: Type} {F: X -> C} {G: Y -> C} {a b: (X * Y)} - (e1: F (fst a) = G (snd a)) (e2: F (fst b) = G (snd b)) : - (F (fst a), F (fst b)) = (G (snd a), G (snd b)). - destruct a as [a1 a2]. - destruct b as [b1 b2]. - simpl in *; simpl. - rewrite e1. - rewrite e2. - auto. -Defined. - -Module commaE. -Section homcommaE. -Context {C D E : precat} (F : C ~> E) (G : D ~> E). - -Definition ptype := { x : C * D & F x.1 = G x.2 }. - -Definition hom_psubdef (a b : ptype) := { - f : tag a ~> tag b & - (F <$> f.1) = (recast2 (tagged a) (tagged b) (G <$> f.2)) }. -HB.instance Definition _ := IsQuiver.Build ptype hom_psubdef. -End homcommaE. -Arguments hom_psubdef /. -Section commaE. -Context {C D E : cat} (F : C ~> E) (G : D ~> E). -Notation ptype := (ptype F G). - -Program Definition idmap_psubdef (a : ptype) : a ~> a := @Tagged _ idmap _ _. -Next Obligation. - unfold recast2. - unfold eq_rect. - unfold brel_fcast. - unfold eq_ind_r. - unfold eq_ind. - unfold eq_sym. - destruct a. - destruct x. - simpl in *; simpl. - rewrite F1. - rewrite F1. - unfold idmap. - simpl. - dependent destruction e. - auto. -Defined. - -Program Definition comp_psubdef (a b c : ptype) - (f : a ~> b) (g : b ~> c) : a ~> c := - @Tagged _ (tag f \; tag g) _ _. -Next Obligation. - destruct f as [ff ef]. - destruct g as [gg eg]. - destruct a as [aa ea]. - destruct aa as [a1 a2]. - destruct b as [bb eb]. - destruct bb as [b1 b2]. - destruct c as [cc ec]. - destruct cc as [c1 c2]. - destruct ff as [f1 f2]. - destruct gg as [g1 g2]. - - simpl; simpl in *. - - rewrite Fcomp. - rewrite Fcomp. - - rewrite ef. - rewrite eg. - clear ef eg. - - eapply (@recast2_3hh _ _ _ _ _ _ _ _ _ _ _ _ - ea eb ec (G <$> f2) (G <$> g2) (G <$> f2 \; G <$> g2) - (fun (d1 d2 d3: E) (x: d1 ~> d2) (y: d2 ~> d3) - (z: d1 ~> d3) => x \; y = z) ); auto. -Defined. - (* by rewrite !Fcomp -compoA (tagged g) compoA (tagged f) compoA. Qed. *) -HB.instance Definition _ := IsPreCat.Build ptype idmap_psubdef comp_psubdef. -Arguments idmap_psubdef /. -Arguments comp_psubdef /. - -Lemma comma_homeqP (a b : ptype) (f g : a ~> b) : projT1 f = projT1 g -> f = g. -Proof. -case: f g => [f fP] [g +]/= eqfg; case: _ / eqfg => gP. -by congr existT; apply: Prop_irrelevance. -Qed. - -Lemma comma_is_cat : PreCat_IsCat ptype. -Proof. -by split=> [[a fa] [b fb] [*]|[a fa] [b fb] [*]|*]; - apply/comma_homeqP; rewrite /= ?(comp1o, compo1, compoA). -Qed. -HB.instance Definition _ := comma_is_cat. -End commaE. -End commaE. -(* -Notation "F `/` G" := (@comma.type _ _ _ F G) - (at level 40, G at level 40, format "F `/` G") : cat_scope. -Notation "a /` G" := (cst unit a `/` G) - (at level 40, G at level 40, format "a /` G") : cat_scope. -Notation "F `/ b" := (F `/` cst unit b) - (at level 40, b at level 40, format "F `/ b") : cat_scope. -Notation "a / b" := (cst unit a `/ b) : cat_scope. -*) (* Lemma cat_pbop : HasPBop cat. econstructor; intros. diff --git a/structures.v b/theories/structures.v similarity index 99% rename from structures.v rename to theories/structures.v index 9187b4727..dfccfc917 100644 --- a/structures.v +++ b/theories/structures.v @@ -701,6 +701,10 @@ actions N :- coq.env.current-library File, coq.elpi.accumulate current "export.db" (clause _ _ (module-to-export File E)), coq.elpi.accumulate current "export.db" (clause _ _ (module-to-export File O)), + + % hack + std.forall {std.iota 20} (x\begin-section "x",end-section), + if (get-option "mathcomp" tt ; get-option "mathcomp.axiom" _) (actions-compat N) true. pred actions-compat i:id. From b9cb11f4baab478b34a17f311213940fa4a152a9 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Mon, 29 Jan 2024 20:52:42 +0100 Subject: [PATCH 138/147] wip --- HB/structure.elpi | 64 ++++++++++++++++++++++++++++++++++++++++++++++- _CoqProject | 1 + theories/encatD.v | 8 ++++-- 3 files changed, 70 insertions(+), 3 deletions(-) diff --git a/HB/structure.elpi b/HB/structure.elpi index e768ad202..fa7b6b371 100644 --- a/HB/structure.elpi +++ b/HB/structure.elpi @@ -7,9 +7,14 @@ namespace structure { % cons p1\ cons p2\ nil t\ [triple f1 [p1] t,triple f2 [p1, {{p1 * p2}}] t] pred declare i:string, i:term, i:sort. pred declare i:string, i:term, i:universe. -declare Module BSkel Sort :- std.do! [ +declare Module BSkel Sort :- + private.declare-wrappers BSkel WrapperClauses, +coq.say "cccc" WrapperClauses, + WrapperClauses => std.do! [ + disable-id-phant BSkel BSkelNoId, failsafe-structure-inference BSkelNoId BSkelNoIdX, + coq.say {coq.term->string BSkelNoIdX} BSkelNoIdX, std.assert-ok! (coq.elaborate-skeleton BSkelNoIdX _ BNoId) "illtyped structure definition", re-enable-id-phant BNoId B, private.sigT->list-w-params B GRFSwP_or_ThingtoBeWrapped ClosureCheck, @@ -701,6 +706,63 @@ lift-to-the-subject.aux [factory-on-subject-lifter _ F OP|Rest] T [WF|Rest1] :- lift-to-the-subject.aux [factory-on-subject-lifter Expr _ _|_] _ _ :- coq.error "NYI: automatic wrapping for" {coq.term->string Expr}. +pred declare-wrappers i:term, o:list prop. +declare-wrappers B C :- std.do! [ + private.sigT->list-w-params B X _, + declare-wrappers.aux X Wrappers, + distribute-w-params Wrappers WrappersWP, + std.map WrappersWP declare-wrapper Clauses, + std.flatten Clauses C, +]. +declare-wrappers.aux (w-params.cons ID T F) (w-params.cons ID T F1) :- + @pi-parameter ID T x\ declare-wrappers.aux (F x) (F1 x). +declare-wrappers.aux (w-params.nil ID T F) (w-params.nil ID T F1) :- + @pi-parameter ID T x\ declare-wrappers.aux2 (F x) (F1 x). +declare-wrappers.aux2 [factory-on-the-type _|XS] R :- declare-wrappers.aux2 XS R. +declare-wrappers.aux2 [factory-on-subject-lifter _ F G|XS] R :- wrapper-mixin _ G F, !, declare-wrappers.aux2 XS R. +declare-wrappers.aux2 [factory-on-subject-lifter T F G|XS] [triple (triple T F G) _ _|R] :- coq.say "TODO wrapper" T F G, declare-wrappers.aux2 XS R. +declare-wrappers.aux2 [] []. + +pred declare-wrapper i:one-w-params (triple term gref gref), o:list prop. +declare-wrapper F C :- std.do! [ + missing-wrapper->record F RSkel OP M, + std.assert-ok! (coq.elaborate-indt-decl-skeleton RSkel R) "illtyped wrapper", + coq.say R, + expand-structures R W, + std.assert-ok! (coq.typecheck-indt-decl W) "illtyped wrapper record", + coq.say W, + std.spy(log.coq.env.add-indt W I), + C = [wrapper-mixin (indt I) OP M], +]. + +pred missing-wrapper->record i:one-w-params (triple term gref gref), o:indt-decl, o:gref, o:mixinname. +missing-wrapper->record (w-params.cons ID T F) (parameter ID explicit T F1) OP M:- + @pi-parameter ID T x\ missing-wrapper->record (F x) (F1 x) OP M. +missing-wrapper->record (w-params.nil ID T F) (parameter ID explicit T F1) OP M:- + @pi-parameter ID T x\ missing-wrapper->record.aux (F x) (F1 x) OP M. +missing-wrapper->record.aux (triple (triple T M OP) _ _) (record "www" _ "wwwk" (field [] "privaffte" T (x\end-record))) OP M. + +pred expand-structures i:indt-decl, o:indt-decl. +expand-structures (parameter ID I T ((s\record _ _ _ _) as R)) (parameter ID I _ R1) :- !, std.do! [ + coq.safe-dest-app T (global GR) Args, is-structure GR, class-def (class C GR ML), + get-constructor C K, + get-constructor GR SK, + coq.mk-app (global K) Args KArgs, + coq.mk-app (global SK) Args SKArgs, + (pi x\ + apply-w-params ML Args x (F x), + expand-structures.aux (F x) {coq.mk-app SKArgs [x]} {coq.mk-app KArgs [x]} R (R1 x)), +]. +expand-structures.aux [triple M PS X|MS] Pack Class R (parameter "m" explicit Ty R1) :- std.do! [ + synthesis.infer-all-gref-deps PS X M Ty, + (@pi-decl `m` Ty m\ + expand-structures.aux MS Pack {coq.mk-app Class [m]} R (R1 m)), +]. +expand-structures.aux [] Pack Class R R1 :- R1 = R {coq.mk-app Pack [Class]}. + + +expand-structures(parameter ID I T F) (parameter ID I T F1) :- + @pi-parameter ID T x\ expand-structures (F x) (F1 x). % M is the gref of the wrapper mixin. % C gets now instantiated to the projection, i.e. hom_isMon_private. diff --git a/_CoqProject b/_CoqProject index 227bfb087..5d369f041 100644 --- a/_CoqProject +++ b/_CoqProject @@ -4,6 +4,7 @@ theories/encatD.v theories/encatI.v -arg -w -arg -elpi.accumulate-syntax -arg -w -arg +elpi.typecheck +-arg -w -arg -redundant-canonical-projection -R tests HB.tests -R examples HB.examples diff --git a/theories/encatD.v b/theories/encatD.v index e16a8041f..4e26abda0 100644 --- a/theories/encatD.v +++ b/theories/encatD.v @@ -270,16 +270,20 @@ Set Universe Checking. (* transpose for horizontal morphism quiver. HB.tag needed to identify transpose as lifter *) HB.tag Definition transpose (C : quiver) : U := C. +(* #[wrapper] HB.mixin Record _IsHQuiver C of IsQuiver C := { is_hquiver : IsQuiver (transpose C) -}. +}. *) +Unset Implicit Arguments. (* vertical and horizontal quivers, defining cells *) Unset Universe Checking. -#[short(type="vhquiver")] +#[short(type="vhquiver"),verbose] HB.structure Definition VHQuiver : Set := { C of IsQuiver C & IsQuiver (transpose C) }. Set Universe Checking. +x + HB.tag Definition hhom (c : VHQuiver.type) : c -> c -> U := @hom (transpose c). Notation "a +> b" := (hhom a b) (at level 99, b at level 200, format "a +> b") : cat_scope. From f2590ab698b06101a187035330332e3721992892 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Wed, 31 Jan 2024 16:51:40 +0100 Subject: [PATCH 139/147] unsafe(univ) option --- HB/common/utils-synterp.elpi | 1 + HB/common/utils.elpi | 9 +++++++++ theories/structures.v | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/HB/common/utils-synterp.elpi b/HB/common/utils-synterp.elpi index 7ce05ed31..9a6900b3c 100644 --- a/HB/common/utils-synterp.elpi +++ b/HB/common/utils-synterp.elpi @@ -25,6 +25,7 @@ with-attributes P :- att "non_forgetful_inheritance" bool, att "hnf" bool, att "wrapper" bool, + att "unsafe.univ" bool, ] Opts, !, Opts => (save-docstring, P). diff --git a/HB/common/utils.elpi b/HB/common/utils.elpi index 00153f062..72b7e2094 100644 --- a/HB/common/utils.elpi +++ b/HB/common/utils.elpi @@ -356,3 +356,12 @@ saturate-type-constructor T ET :- coq.typecheck T TH ok, coq.count-prods TH N, coq.mk-app T {coq.mk-n-holes N} ET. + +pred with-unsafe-univ i:prop. +with-unsafe-univ P :- get-option "unsafe.univ" tt, !, + coq.option.get ["Universe","Checking"] Old, + coq.option.set ["Universe","Checking"] (coq.option.bool ff), + P, + coq.option.set ["Universe","Checking"] Old. +with-unsafe-univ P :- P. + \ No newline at end of file diff --git a/theories/structures.v b/theories/structures.v index dfccfc917..e31781e98 100644 --- a/theories/structures.v +++ b/theories/structures.v @@ -677,7 +677,7 @@ main [const-decl N (some B) Arity] :- std.do! [ % compute the universe for the structure (default ) prod-last {coq.arity->term Arity} Ty, if (ground_term Ty) (Sort = Ty) (Sort = {{Type}}), sort Univ = Sort, - with-attributes (with-logging (structure.declare N B Univ)), + with-attributes (with-logging (with-unsafe-univ (structure.declare N B Univ))), ]. }}. From e8a680cd305aedfb8ecd660a9e77ec057402583d Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Wed, 31 Jan 2024 16:51:59 +0100 Subject: [PATCH 140/147] wip --- HB/structure.elpi | 69 ++++++++++++++++++++++++++++++++++++----------- theories/encatD.v | 21 ++++++++------- 2 files changed, 65 insertions(+), 25 deletions(-) diff --git a/HB/structure.elpi b/HB/structure.elpi index fa7b6b371..4eccc0860 100644 --- a/HB/structure.elpi +++ b/HB/structure.elpi @@ -8,8 +8,8 @@ namespace structure { pred declare i:string, i:term, i:sort. pred declare i:string, i:term, i:universe. declare Module BSkel Sort :- - private.declare-wrappers BSkel WrapperClauses, -coq.say "cccc" WrapperClauses, + private.declare-wrappers BSkel WrapperClauses, % move to factory.elpi + WrapperClauses => std.do! [ disable-id-phant BSkel BSkelNoId, @@ -136,7 +136,8 @@ coq.say "cccc" WrapperClauses, std.flatten [ Factories, [ClassAlias], [is-structure Structure], NewJoins, [class-def CurrentClass], GRDepsClauses, - [gref-deps GRPack MLwP], MixinMems, [StructKeyClause] + [gref-deps GRPack MLwP], MixinMems, [StructKeyClause], + WrapperClauses ] NewClauses, acc-clauses current NewClauses, @@ -698,11 +699,12 @@ lift-to-the-subject.aux [] _ []. lift-to-the-subject.aux [factory-on-the-type F|Rest] T [F|Rest1] :- lift-to-the-subject.aux Rest T Rest1. lift-to-the-subject.aux [factory-on-subject-lifter _ F OP|Rest] T [WF|Rest1] :- - wrapper-mixin Wrapper OP F, !, + wrapper-mixin Wrapper OP F, !, std.spy-do! [ factory-nparams Wrapper NParams, coq.mk-app {coq.env.global Wrapper} {std.append {coq.mk-n-holes NParams} [T]} W, factory? W WF, - lift-to-the-subject.aux Rest T Rest1. + lift-to-the-subject.aux Rest T Rest1, +]. lift-to-the-subject.aux [factory-on-subject-lifter Expr _ _|_] _ _ :- coq.error "NYI: automatic wrapping for" {coq.term->string Expr}. @@ -726,13 +728,44 @@ declare-wrappers.aux2 [] []. pred declare-wrapper i:one-w-params (triple term gref gref), o:list prop. declare-wrapper F C :- std.do! [ missing-wrapper->record F RSkel OP M, - std.assert-ok! (coq.elaborate-indt-decl-skeleton RSkel R) "illtyped wrapper", - coq.say R, - expand-structures R W, + std.assert-ok! (coq.elaborate-indt-decl-skeleton RSkel RDecl) "illtyped wrapper", + coq.say RDecl, + expand-structures RDecl W MLwP, std.assert-ok! (coq.typecheck-indt-decl W) "illtyped wrapper record", coq.say W, - std.spy(log.coq.env.add-indt W I), - C = [wrapper-mixin (indt I) OP M], + std.spy(log.coq.env.add-indt W R), + coq.env.indt R tt _ _ _ [K] _, + GRK = indc K, + GR = indt R, + + coq.gref->id GR Name, + + w-params.nparams MLwP NParams, + factory.private.build-deps-for-projections R MLwP GRDepsClausesProjs, + GRDepsClauses = [ gref-deps GR MLwP, gref-deps (indc K) MLwP | GRDepsClausesProjs], + + GRDepsClauses => phant.of-gref ff GRK [] PhGRK, + GRDepsClauses => phant.add-abbreviation {calc (Name ^ "_Build")} PhGRK BuildConst BuildAbbrev, + GRDepsClauses => phant.of-gref ff GR [] PhTerm, + GRDepsClauses => phant.add-abbreviation {calc (Name ^ "_axiom")} PhTerm PhC Abbrv, + + FRClauses = [ + phant-abbrev GRK (const BuildConst) BuildAbbrev, + phant-abbrev GR (const PhC) Abbrv, + ], + + GRDepsClauses => FRClauses => factory.private.declare-id-builder GR IdBuilderClause, + + std.flatten [ + [ wrapper-mixin GR OP M, + factory-constructor GR GRK, + factory-nparams GR NParams, + IdBuilderClause], + FRClauses, + GRDepsClauses, + ] C, + %factory-builder-nparams BuildConst NParams, + ]. pred missing-wrapper->record i:one-w-params (triple term gref gref), o:indt-decl, o:gref, o:mixinname. @@ -740,10 +773,14 @@ missing-wrapper->record (w-params.cons ID T F) (parameter ID explicit T F1) OP M @pi-parameter ID T x\ missing-wrapper->record (F x) (F1 x) OP M. missing-wrapper->record (w-params.nil ID T F) (parameter ID explicit T F1) OP M:- @pi-parameter ID T x\ missing-wrapper->record.aux (F x) (F1 x) OP M. -missing-wrapper->record.aux (triple (triple T M OP) _ _) (record "www" _ "wwwk" (field [] "privaffte" T (x\end-record))) OP M. - -pred expand-structures i:indt-decl, o:indt-decl. -expand-structures (parameter ID I T ((s\record _ _ _ _) as R)) (parameter ID I _ R1) :- !, std.do! [ +missing-wrapper->record.aux (triple (triple T M OP) _ _) + (record Name _ Bname (field [] Fname T (x\end-record))) OP M :- + Name is "wrapper_" ^ {std.any->string {new_int}} ^ "_" ^ {coq.gref->id OP} ^ "_" ^ {nice-gref->string M}, + Fname is Name ^ "_private", + Bname is Name ^ "_build". + +pred expand-structures i:indt-decl, o:indt-decl, o:mixins. +expand-structures (parameter ID I T ((s\record _ _ _ _) as R)) (parameter ID I _ R1) ML :- !, std.do! [ coq.safe-dest-app T (global GR) Args, is-structure GR, class-def (class C GR ML), get-constructor C K, get-constructor GR SK, @@ -761,8 +798,8 @@ expand-structures.aux [triple M PS X|MS] Pack Class R (parameter "m" explicit Ty expand-structures.aux [] Pack Class R R1 :- R1 = R {coq.mk-app Pack [Class]}. -expand-structures(parameter ID I T F) (parameter ID I T F1) :- - @pi-parameter ID T x\ expand-structures (F x) (F1 x). +expand-structures(parameter ID I T F) (parameter ID I T F1) ML :- + @pi-parameter ID T x\ expand-structures (F x) (F1 x) ML. % M is the gref of the wrapper mixin. % C gets now instantiated to the projection, i.e. hom_isMon_private. diff --git a/theories/encatD.v b/theories/encatD.v index 4e26abda0..81e9cebdc 100644 --- a/theories/encatD.v +++ b/theories/encatD.v @@ -270,19 +270,22 @@ Set Universe Checking. (* transpose for horizontal morphism quiver. HB.tag needed to identify transpose as lifter *) HB.tag Definition transpose (C : quiver) : U := C. -(* -#[wrapper] HB.mixin Record _IsHQuiver C of IsQuiver C := { - is_hquiver : IsQuiver (transpose C) -}. *) -Unset Implicit Arguments. + (* vertical and horizontal quivers, defining cells *) -Unset Universe Checking. -#[short(type="vhquiver"),verbose] +#[short(type="vhquiver"),unsafe(univ)] HB.structure Definition VHQuiver : Set := { C of IsQuiver C & IsQuiver (transpose C) }. -Set Universe Checking. -x + +(* +Print VHQuiver.axioms_. +Print wrapper_4_transpose_cat_IsQuiver. +Record wrapper_4_transpose_cat_IsQuiver (C : U) (m : IsQuiver.axioms_ C) : U := + wrapper_4_transpose_cat_IsQuiver_build { + wrapper_4_transpose_cat_IsQuiver_private : + IsQuiver.phant_axioms (transpose {| Quiver.sort := C; + Quiver.class := {| Quiver.cat_IsQuiver_mixin := m |} |}) }. +*) HB.tag Definition hhom (c : VHQuiver.type) : c -> c -> U := @hom (transpose c). Notation "a +> b" := (hhom a b) From 18ca7ba02a6bf55fc81890f07c897ce9b9038bdd Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Fri, 2 Feb 2024 17:47:10 +0100 Subject: [PATCH 141/147] wip --- HB/common/utils.elpi | 15 ++- HB/structure.elpi | 32 ++++--- _CoqProject | 1 + theories/encatD.v | 211 +++++++++++++++++++++++++++++++++---------- 4 files changed, 199 insertions(+), 60 deletions(-) diff --git a/HB/common/utils.elpi b/HB/common/utils.elpi index 72b7e2094..02e8f7a33 100644 --- a/HB/common/utils.elpi +++ b/HB/common/utils.elpi @@ -76,7 +76,7 @@ gref->modname GR NComp Sep ModName :- std.length Path Len, if (Len >= NComp) true (coq.error "Not enough enclosing modules for" {coq.gref->string GR}), std.take NComp Mods L, - std.string.concat Sep {std.rev L} ModName. + std.string.concat Sep {std.rev [{std.any->string {new_int}}|L]} ModName. pred gref->modname-label i:gref, i:int, i:string, o:string. gref->modname-label GR NComp Sep ModName :- coq.gref->path GR Path, @@ -315,6 +315,19 @@ re-enable-id-phant T T1 :- (pi f1 f2 t v\ copy {{lib:@hb.ignore_disabled lp:t lp:f1 lp:v lp:f2}} {{lib:@hb.ignore lp:t lp:v}} :- !) => copy T T1. +pred disable-id-phant-indt-decl i:indt-decl, o:indt-decl. +disable-id-phant-indt-decl D D1 :- + (pi fresh fresh1 t v\ copy {{lib:@hb.id lp:t lp:v}} {{lib:@hb.id_disabled lp:t lp:fresh lp:v lp:fresh1}} :- !) => + (pi fresh fresh1 t v\ copy {{lib:@hb.ignore lp:t lp:v}} {{lib:@hb.ignore_disabled lp:t lp:fresh lp:v lp:fresh1}} :- !) => + copy-indt-decl D D1. + +pred re-enable-id-phant-indt-decl i:indt-decl, o:indt-decl. +re-enable-id-phant-indt-decl D D1 :- + (pi f1 f2 t v\ copy {{lib:@hb.id_disabled lp:t lp:f1 lp:v lp:f2}} {{lib:@hb.id lp:t lp:v}} :- !) => + (pi f1 f2 t v\ copy {{lib:@hb.ignore_disabled lp:t lp:f1 lp:v lp:f2}} {{lib:@hb.ignore lp:t lp:v}} :- !) => + copy-indt-decl D D1. + + pred failsafe-structure-inference i:term, o:term. failsafe-structure-inference T T1 :- (pi T T2 F_Params F_Params1 Args Args1 Subject Subject1 NP ArgsOp ArgsOp1 OP S\ diff --git a/HB/structure.elpi b/HB/structure.elpi index 4eccc0860..3bf9d6d99 100644 --- a/HB/structure.elpi +++ b/HB/structure.elpi @@ -14,7 +14,7 @@ declare Module BSkel Sort :- disable-id-phant BSkel BSkelNoId, failsafe-structure-inference BSkelNoId BSkelNoIdX, - coq.say {coq.term->string BSkelNoIdX} BSkelNoIdX, + %coq.say {coq.term->string BSkelNoIdX} BSkelNoIdX, std.assert-ok! (coq.elaborate-skeleton BSkelNoIdX _ BNoId) "illtyped structure definition", re-enable-id-phant BNoId B, private.sigT->list-w-params B GRFSwP_or_ThingtoBeWrapped ClosureCheck, @@ -699,7 +699,7 @@ lift-to-the-subject.aux [] _ []. lift-to-the-subject.aux [factory-on-the-type F|Rest] T [F|Rest1] :- lift-to-the-subject.aux Rest T Rest1. lift-to-the-subject.aux [factory-on-subject-lifter _ F OP|Rest] T [WF|Rest1] :- - wrapper-mixin Wrapper OP F, !, std.spy-do! [ + wrapper-mixin Wrapper OP F, !, std.do! [ factory-nparams Wrapper NParams, coq.mk-app {coq.env.global Wrapper} {std.append {coq.mk-n-holes NParams} [T]} W, factory? W WF, @@ -713,8 +713,7 @@ declare-wrappers B C :- std.do! [ private.sigT->list-w-params B X _, declare-wrappers.aux X Wrappers, distribute-w-params Wrappers WrappersWP, - std.map WrappersWP declare-wrapper Clauses, - std.flatten Clauses C, + std.fold WrappersWP [] declare-wrapper C, ]. declare-wrappers.aux (w-params.cons ID T F) (w-params.cons ID T F1) :- @pi-parameter ID T x\ declare-wrappers.aux (F x) (F1 x). @@ -725,13 +724,20 @@ declare-wrappers.aux2 [factory-on-subject-lifter _ F G|XS] R :- wrapper-mixin _ declare-wrappers.aux2 [factory-on-subject-lifter T F G|XS] [triple (triple T F G) _ _|R] :- coq.say "TODO wrapper" T F G, declare-wrappers.aux2 XS R. declare-wrappers.aux2 [] []. -pred declare-wrapper i:one-w-params (triple term gref gref), o:list prop. -declare-wrapper F C :- std.do! [ +pred declare-wrapper i:one-w-params (triple term gref gref), i:list prop, o:list prop. +declare-wrapper F C0 C :- C0 => std.do! [ + coq.say "Missing" F, missing-wrapper->record F RSkel OP M, - std.assert-ok! (coq.elaborate-indt-decl-skeleton RSkel RDecl) "illtyped wrapper", - coq.say RDecl, - expand-structures RDecl W MLwP, - std.assert-ok! (coq.typecheck-indt-decl W) "illtyped wrapper record", + %coq.say "Wrapper skel" RSkel, + disable-id-phant-indt-decl RSkel RSkelNoId, + std.assert-ok! (coq.elaborate-indt-decl-skeleton RSkelNoId RDeclNoId) "illtyped wrapper", + re-enable-id-phant-indt-decl RDeclNoId RDecl, + %coq.say "Record wrapper" RDecl, + expand-structures RDecl W' MLwP, + %coq.say "Expanded record wrapper" W', + %std.assert-ok! (coq.typecheck-indt-decl W) "illtyped wrapper record", + coq.say W', + std.assert-ok! (coq.elaborate-indt-decl-skeleton W' W) "illtyped wrapper record", coq.say W, std.spy(log.coq.env.add-indt W R), coq.env.indt R tt _ _ _ [K] _, @@ -756,7 +762,7 @@ declare-wrapper F C :- std.do! [ GRDepsClauses => FRClauses => factory.private.declare-id-builder GR IdBuilderClause, - std.flatten [ + std.flatten [ C0, [ wrapper-mixin GR OP M, factory-constructor GR GRK, factory-nparams GR NParams, @@ -786,13 +792,13 @@ expand-structures (parameter ID I T ((s\record _ _ _ _) as R)) (parameter ID I _ get-constructor GR SK, coq.mk-app (global K) Args KArgs, coq.mk-app (global SK) Args SKArgs, - (pi x\ + (@pi-decl `TheType` {{ Type }} x\ % TYPE is wrong apply-w-params ML Args x (F x), expand-structures.aux (F x) {coq.mk-app SKArgs [x]} {coq.mk-app KArgs [x]} R (R1 x)), ]. expand-structures.aux [triple M PS X|MS] Pack Class R (parameter "m" explicit Ty R1) :- std.do! [ synthesis.infer-all-gref-deps PS X M Ty, - (@pi-decl `m` Ty m\ + (@pi-decl `m` Ty m\ mixin-src X M m => expand-structures.aux MS Pack {coq.mk-app Class [m]} R (R1 m)), ]. expand-structures.aux [] Pack Class R R1 :- R1 = R {coq.mk-app Pack [Class]}. diff --git a/_CoqProject b/_CoqProject index 5d369f041..6fd1beebb 100644 --- a/_CoqProject +++ b/_CoqProject @@ -2,6 +2,7 @@ theories/structures.v theories/cat.v theories/encatD.v theories/encatI.v +theories/encatH.v -arg -w -arg -elpi.accumulate-syntax -arg -w -arg +elpi.typecheck -arg -w -arg -redundant-canonical-projection diff --git a/theories/encatD.v b/theories/encatD.v index 81e9cebdc..581371d92 100644 --- a/theories/encatD.v +++ b/theories/encatD.v @@ -219,7 +219,7 @@ Set Universe Checking. (********************************************************************) -(*** DOUBLE CATEGORIES (without internal categories) *) +(*** DOUBLE CATEGORIES (without internal categories, with H0) *) (* Strict double categories, from https://ncatlab.org/nlab/show/double+category @@ -233,7 +233,7 @@ Set Universe Checking. horizontal 1-morhisms as 1-cells for D1: D1obj C ; - 2-morphisms (category D1 on C1obj): hom (D1obj C) ; + 2-morphisms (category D1 on D1obj): hom (D1obj C) ; horizontally composable pairs of 1-cells : DPobj C ; @@ -255,13 +255,17 @@ Set Universe Checking. horizontally D0-composable D1 products ($\mbox{D1} *_0 \mbox{D1}$) - - Source functor: $\mbox{D1} \to \mbox{D0}$ + - Source functor: D1 -> D0 - - Target functor: $\mbox{D1} \to \mbox{D0}$ + - Target functor: D1 -> D0 - - Horizontal unit functor: $\mbox{D0} \to \mbox{D1}$ + - Horizontal unit functor: D0 -> D1 - - Horizontal composition functor: $\mbox{DP} \to \mbox{D1}$ + - Horizontal composition functor: DP -> D1 + + - First DP projection: DP -> D1 + + - Second DP projection: DP -> D1 *) @@ -276,17 +280,6 @@ HB.tag Definition transpose (C : quiver) : U := C. HB.structure Definition VHQuiver : Set := { C of IsQuiver C & IsQuiver (transpose C) }. - -(* -Print VHQuiver.axioms_. -Print wrapper_4_transpose_cat_IsQuiver. -Record wrapper_4_transpose_cat_IsQuiver (C : U) (m : IsQuiver.axioms_ C) : U := - wrapper_4_transpose_cat_IsQuiver_build { - wrapper_4_transpose_cat_IsQuiver_private : - IsQuiver.phant_axioms (transpose {| Quiver.sort := C; - Quiver.class := {| Quiver.cat_IsQuiver_mixin := m |} |}) }. -*) - HB.tag Definition hhom (c : VHQuiver.type) : c -> c -> U := @hom (transpose c). Notation "a +> b" := (hhom a b) (at level 99, b at level 200, format "a +> b") : cat_scope. @@ -302,39 +295,29 @@ Record Total2 T (h: T -> T -> U) : Type := TT2 { HB.tag Definition D1obj (C: vhquiver) := Total2 (@hhom C). (* D1 quiver requirement (includes D0 quiver and its transpose). *) -#[wrapper] -HB.mixin Record _IsDQuiver T of VHQuiver T := - { is_dquiver : Quiver (D1obj T) }. -Unset Universe Checking. -#[short(type="dquiver")] +#[short(type="dquiver"),unsafe(univ)] HB.structure Definition DQuiver : Set := { C of Quiver (D1obj C) }. -Set Universe Checking. - (** Horizonal D0-level category (H-D0) *) (* Precategory based on the HQuiver (i.e. horizontal precategory on D0 objects) *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record _IsHPreCat T of VHQuiver T := { - is_hprecat : Quiver_IsPreCat (transpose T) }. -#[short(type="hprecat")] +#[short(type="hprecat"),unsafe(univ)] HB.structure Definition HPreCat : Set := { C of Quiver_IsPreCat (transpose C) }. -Set Universe Checking. (* The category based on the HQuiver (i.e. horizontal category on D0 objects) *) -Unset Universe Checking. +(* Unset Universe Checking. #[wrapper] HB.mixin Record _IsHCat T of HPreCat T := { - is_hcat : PreCat_IsCat (transpose T) }. -#[short(type="hcat")] -HB.structure Definition HCat : Set := - { C of PreCat_IsCat (transpose C) }. -Set Universe Checking. + is_hcat : PreCat_IsCat (transpose T) }. *) +#[short(type="hcat"),unsafe(univ)] +HB.structure Definition HCat : Set := HERE: do not only read deps from transpose, but also from PreCat_IsCat... + { C of HPreCat C & PreCat_IsCat (transpose C) }. +(*Set Universe Checking.*) +x (** Vertical 2-cell level category (D1 category) *) @@ -529,6 +512,28 @@ Definition H1Target (T: TFunctor.type) (a b: @D1obj T) Definition H2Unit (T: UFunctor.type) (a b: T) (m: @hom T a b) : (H1Unit a) ~> (H1Unit b) := (@H1Unit T) <$> m. +(* DP objects source and target *) +Lemma DPsource (T: STUFunctor.type) (a: DPobj T) : + HSource (H1Comp a) = HSource (TT2 (h_first a)). + destruct a; simpl in *; simpl. + auto. +Defined. + +Lemma DPtarget (T: STUFunctor.type) (a: DPobj T) : + HTarget (H1Comp a) = HTarget (TT2 (h_second a)). + destruct a; simpl in *; simpl. + auto. +Defined. + +Lemma unit_source (T: STUFunctor.type) (a: T) : + HSource (H1Unit a) = a. + simpl in *; simpl; auto. +Defined. + +Lemma unit_target (T: STUFunctor.type) (a: T) : + HTarget (H1Unit a) = a. + simpl in *; simpl; auto. +Defined. (** Horizontal product category (D1 *d0 D1) *) (* DPobj T is the pseudo-pullback category used to deal with @@ -540,11 +545,13 @@ Definition l_hcomp (T: SDCat.type) (a0 a1 a2: T) (h0: hhom a0 a1) (h1: hhom a1 a2) : D1obj T := @TT2 T _ a0 a2 (h0 \; h1). +(* Notation "'sigma' x .. y , p" := (sigT (fun x => .. (sigT (fun y => p)) ..)) (at level 200, x binder, right associativity, format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") : type_scope. +*) (** DPobj quiver *) Definition DP_hom (T: STUFunctor.type) (x y: DPobj T) := @@ -960,6 +967,38 @@ HB.instance Definition DPCat (T: STUFunctor.type) := DPCatP T. (** Horizontal composition functor and strict double categories *) +(* fst horizontal projection prefunctor *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHFPreFunctor T of STUFunctor T := + { is_hfprefunctor : IsPreFunctor (DPobj T) (D1obj T) (@H2First T) }. +HB.structure Definition HFPreFunctor : Set := {C of IsHFPreFunctor C}. +Set Universe Checking. + +(* fst horizontal projection functor *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record HFPreFunctor_IsFunctor T of HFPreFunctor T := { + is_hffunctor : PreFunctor_IsFunctor (DPobj T) (D1obj T) (@H2First T) }. +HB.structure Definition HFFunctor : Set := {C of HFPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* snd horizontal projection prefunctor *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHSPreFunctor T of STUFunctor T := + { is_hsprefunctor : IsPreFunctor (DPobj T) (D1obj T) (@H2Second T) }. +HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. +Set Universe Checking. + +(* snd horizontal projection functor *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record HSPreFunctor_IsFunctor T of HSPreFunctor T := { + is_hsfunctor : PreFunctor_IsFunctor (DPobj T) (D1obj T) (@H2Second T) }. +HB.structure Definition HSFunctor : Set := {C of HSPreFunctor_IsFunctor C}. +Set Universe Checking. + (* composition prefunctor *) Unset Universe Checking. #[wrapper] @@ -968,37 +1007,117 @@ HB.mixin Record IsCPreFunctor T of STUFunctor T := HB.structure Definition CPreFunctor : Set := {C of IsCPreFunctor C}. Set Universe Checking. -(* composition functor - gives the definition of Strict Double Category *) +(* composition functor *) Unset Universe Checking. #[wrapper] HB.mixin Record CPreFunctor_IsFunctor T of CPreFunctor T := { is_cfunctor : PreFunctor_IsFunctor (DPobj T) (D1obj T) (@H1Comp T) }. -#[short(type="sdoublecat")] -HB.structure Definition SDoubleCat : Set := {C of CPreFunctor_IsFunctor C}. +HB.structure Definition CFunctor : Set := {C of CPreFunctor_IsFunctor C}. Set Universe Checking. +(* All functors together *) +Unset Universe Checking. +HB.structure Definition FCFunctor : Set := + {C of HFFunctor C & HSFunctor C & CFunctor C}. +Set Universe Checking. + + +(* first and second projection from pairs of cells *) +Definition HH2First (T: HFFunctor.type) (a b: DPobj T) + (m: DP_hom a b) : H2First a ~> H2First b := (@H2First T) <$> m. + +Definition HH2Second (T: HSFunctor.type) (a b: DPobj T) + (m: DP_hom a b) : H2Second a ~> H2Second b := (@H2Second T) <$> m. + +(* +Definition HH2First (T: HFFunctor.type) (a b: DPobj T) + (m: @hom (DPobj T) a b) : H2First a ~> H2First b := (@H2First T) <$> m. + +Definition HH2Second (T: HSFunctor.type) (a b: DPobj T) + (m: @hom (DPobj T) a b) : H2Second a ~> H2Second b := (@H2Second T) <$> m. +*) + (* horizontal 2-cell composition: maps two adjecent pairs of horizontal morphisms (a and b) and a pullback-category morphism between them (m, which basically gives two adjecent cells) to a 2-cell morphism between the horizontal composition (HComp) of each pair *) -Definition HC2Comp (T: SDoubleCat.type) (a b: DPobj T) +Definition HC2Comp (T: CFunctor.type) (a b: DPobj T) + (m: DP_hom a b) : + d1hom (H1Comp a) (H1Comp b) := @Fhom _ _ (@H1Comp T) a b m. + +(* +Definition HC2Comp (T: CFunctor.type) (a b: DPobj T) (m: @hom (DPobj T) a b) : d1hom (H1Comp a) (H1Comp b) := @Fhom _ _ (@H1Comp T) a b m. +*) -Program Definition HC2Comp_flat (T: SDoubleCat.type) (a0 a1 a2 b0 b1 b2: T) +Program Definition HC2Comp_flat (T: CFunctor.type) (a0 a1 a2 b0 b1 b2: T) (h0: hhom a0 a1) (h1: hhom a1 a2) (k0: hhom b0 b1) (k1: hhom b1 b2) (hh0: D1hom h0 k0) (hh1: D1hom h1 k1) - (k: H1Target hh0 = H1Source hh1) - : (* D1hom (hcomp _ _ _ h0 h1) (hcomp _ _ _ k0 k1) *) - d1hom (l_hcomp h0 h1) (l_hcomp k0 k1) := - @Fhom _ _ (@H1Comp T) (GC h0 h1) (GC k0 k1) _. + (K: H1Target hh0 = H1Source hh1) : D1hom (h0 \; h1) (k0 \; k1) := + @Fhom _ _ (@H1Comp T) (GC h0 h1) (GC k0 k1) _. Obligation 1. -refine (@existT (D1hom h0 k0) _ hh0 (@existT (D1hom h1 k1) _ hh1 k)). +refine (@existT (D1hom h0 k0) _ hh0 (@existT (D1hom h1 k1) _ hh1 K)). Defined. + +(* quasi-double category *) +Unset Universe Checking. +HB.mixin Record IsQDoubleCat T of FCFunctor T := { + unit_source : forall (a b: T) (m: hom a b), + H1Source (H2Unit m) = m ; + + unit_target : forall (a b: T) (m: hom a b), + H1Target (H2Unit m) = m ; +}. +#[short(type="qdoublecat")] +HB.structure Definition QDoubleCat : Set := + { C of IsQDoubleCat C }. +Set Universe Checking. + + +(* definition of strict double category *) +Unset Universe Checking. +HB.mixin Record IsSDoubleCat T of QDoubleCat T := { + source_comp_dist : forall (a b: DPobj T) (m: DP_hom a b), + TT2 (H1Source (HC2Comp m)) = TT2 (H1Source (HH2First m)) ; + + target_comp_dist : forall (a b: DPobj T) (m: DP_hom a b), + TT2 (H1Target (HC2Comp m)) = TT2 (H1Target (HH2Second m)) ; +}. +#[short(type="sdoublecat")] +HB.structure Definition SDoubleCat : Set := + { C of IsSDoubleCat C }. +Set Universe Checking. + +(* alternative definition of strict double category (display-style) *) +Unset Universe Checking. +HB.mixin Record IsSDoubleCat1 T of QDoubleCat T := { + source_comp_dist1 : forall (a0 a1 a2 b0 b1 b2: T) + (h0: hhom a0 a1) (h1: hhom a1 a2) + (k0: hhom b0 b1) (k1: hhom b1 b2) + (hh0: D1hom h0 k0) + (hh1: D1hom h1 k1) + (K: H1Target hh0 = H1Source hh1), + H1Source (HC2Comp_flat K) = H1Source hh0 ; + + target_comp_dist1 : forall (a0 a1 a2 b0 b1 b2: T) + (h0: hhom a0 a1) (h1: hhom a1 a2) + (k0: hhom b0 b1) (k1: hhom b1 b2) + (hh0: D1hom h0 k0) + (hh1: D1hom h1 k1) + (K: H1Target hh0 = H1Source hh1), + H1Target (HC2Comp_flat K) = H1Target hh1 ; +}. +#[short(type="sdoublecat1")] +HB.structure Definition SDoubleCat1 : Set := + { C of IsSDoubleCat1 C }. +Set Universe Checking. + + (* hcomp (hm, hu) = prj1 (hm, hu) = hm hcomp (hu, hm) = prj2 (hu, hm) = hm (hm1 * hm2) * hm3 ~> hm1 * (hm2 * hm3) From 59af016c51931ca2deb071436599e8634dd04e26 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Fri, 2 Feb 2024 17:47:26 +0100 Subject: [PATCH 142/147] wip --- theories/encatH.v | 1265 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1265 insertions(+) create mode 100644 theories/encatH.v diff --git a/theories/encatH.v b/theories/encatH.v new file mode 100644 index 000000000..e067152fe --- /dev/null +++ b/theories/encatH.v @@ -0,0 +1,1265 @@ +Require Import ssreflect ssrfun. +Unset Universe Checking. +From HB Require Import structures cat encatD. +Set Universe Checking. +Require Import Coq.Program.Equality. + +Set Implicit Arguments. +Unset Strict Implicit. +Unset Printing Implicit Defensive. +Add Search Blacklist "__canonical__". + +Local Open Scope algebra_scope. + +Local Open Scope cat_scope. + +(* +Notation "'sigma' x .. y , p" := + (sigT (fun x => .. (sigT (fun y => p)) ..)) + (at level 200, x binder, right associativity, + format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") + : type_scope. +*) + +(********************************************************************) + +(*** DOUBLE CATEGORIES (without internal categories, with H1) *) + +(* Strict double categories, from + https://ncatlab.org/nlab/show/double+category + (we don't use internal categories) + + base obejcts as 0-cells: C ; + + vertical 1-morphisms (category D0 on C): hom C ; + + horizontal 1-morphisms (category H on C): hom (transpose C) ; + + horizontal 1-morhisms as 1-cells for D1: D1obj C ; + + vertical 1-morhisms as 1-cells for H1: H1obj C ; + + 2-morphisms (category D1 on D1obj): hom (D1obj C) ; + + horizontally composable pairs of 1-cells : DPobj C ; + + horizontally composable pairs of 2-morphisms + (product category DP, D1 *0 D1) : hom (DPobj C) ; + + The definition of Strict Double Category, SDouble = (D0, D1, Dp, H1), + is given by: + + - base objects C + + - (level-1) category (D0) of vertical 1-morphism on C + + - (level-2) category (D1) of vertical 2-morphism on D1obj + + - (derived) category (DP) of vertical 2-morphisms on + horizontally D0-composable D1 products + ($\mbox{D1} *_0 \mbox{D1}$) + + - (level-2) category (H1) of horizontal 12morphism on H1obj + + - Source functor: D1 -> D0 + + - Target functor: D1 -> D0 + + - Horizontal unit functor: D0 -> D1 + + - Horizontal composition functor: DP -> D1 + + - First DP projection: DP -> D1 + + - Second DP projection: DP -> D1 +*) + + +(** Quivers for double categories *) + +(* transpose for horizontal morphism quiver. + HB.tag needed to identify transpose as lifter *) +HB.tag Definition transpose (C : quiver) : U := C. +#[wrapper] HB.mixin Record _IsHQuiver C of IsQuiver C := { + is_hquiver : IsQuiver (transpose C) +}. +(* vertical and horizontal quivers, defining cells *) +Unset Universe Checking. +#[short(type="vhquiver")] +HB.structure Definition VHQuiver : Set := + { C of IsQuiver C & IsQuiver (transpose C) }. +Set Universe Checking. + +HB.tag Definition hhom (c : VHQuiver.type) : c -> c -> U := @hom (transpose c). +Notation "a +> b" := (hhom a b) + (at level 99, b at level 200, format "a +> b") : cat_scope. + +(* record to represent the set of morphims + (needed for 2-objects, i.e. horizontal morphisms) *) +Record Total2 T (h: T -> T -> U) : Type := TT2 { + source : T; + target : T; + this_morph : h source target }. + +(* the set of horizontal morphisms. *) +HB.tag Definition D1obj (C: vhquiver) := Total2 (@hhom C). + +(* D1 quiver requirement (includes D0 quiver and its transpose). *) +#[wrapper] +HB.mixin Record _IsDQuiver T of VHQuiver T := + { is_dquiver : Quiver (D1obj T) }. +Unset Universe Checking. +#[short(type="dquiver")] +HB.structure Definition DQuiver : Set := { C of Quiver (D1obj C) }. +Set Universe Checking. + + +(** Horizonal D0-level category (H-D0) *) +(* +(* Precategory based on the HQuiver (i.e. horizontal precategory on D0 + objects) *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record _IsHPreCat T of VHQuiver T := { + is_hprecat : Quiver_IsPreCat (transpose T) }. +#[short(type="hprecat")] +HB.structure Definition HPreCat : Set := + { C of Quiver_IsPreCat (transpose C) }. +Set Universe Checking. + +(* The category based on the HQuiver (i.e. horizontal category on D0 + objects) *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record _IsHCat T of HPreCat T := { + is_hcat : PreCat_IsCat (transpose T) }. +#[short(type="hcat")] +HB.structure Definition HCat : Set := + { C of PreCat_IsCat (transpose C) }. +Set Universe Checking. +*) + +(** Vertical 2-cell level category (D1 category) *) + +(* Precategory based on the DQuiver (i.e. precategory D1). Gives: + vertical 2-cell identity morphism. + vertical 2-cell composition. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record _IsD1PreCat T of DQuiver T := { + is_d1precat : Quiver_IsPreCat (@D1obj T) }. +#[short(type="d1precat")] +HB.structure Definition D1PreCat : Set := + { C of Quiver_IsPreCat (@D1obj C) }. +Set Universe Checking. + +(* The category based on the DQuiver (i.e. category D1). *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record _IsD1Cat T of D1PreCat T := { + is_d1cat : PreCat_IsCat (@D1obj T) }. +#[short(type="d1cat")] +HB.structure Definition D1Cat : Set := + { C of PreCat_IsCat (@D1obj C) }. +Set Universe Checking. + + +(** Naked double category *) + +(* Naked double category. Vertical (V-D0) and D1 categories. Double + category without horizontal operators and functors *) +Unset Universe Checking. +#[short(type="dcat")] +HB.structure Definition DCat : Set := + { C of Cat C & D1Cat C }. +Set Universe Checking. + + +(* composable pairs of morphisms as a set *) +Record GenComp T (h: T -> T -> U) := GC { + h_one : T; + h_two : T ; + h_three : T; + h_first : h h_one h_two ; + h_second : h h_two h_three }. + +(* composable pairs of horizontal morphisms as a set *) +HB.tag Definition DPobj (C: vhquiver) := GenComp (@hhom C). + + +HB.mixin Record IsHDQuiver T of DQuiver T := { + hunit : forall a: T, @hhom T a a ; + hcomp : forall (a b c: T), @hhom T a b -> @hhom T b c -> @hhom T a c; +}. +Unset Universe Checking. +#[short(type="hdquiver")] +HB.structure Definition HDQuiver : Set := { C of IsHDQuiver C }. +Set Universe Checking. + +Definition hhunit (T: hdquiver) (a: T) : D1obj T := + @TT2 T (@hhom T) a a (hunit a). +HB.tag Definition H1Unit (C: hdquiver) := + fun (x: HDQuiver.sort C) => @hhunit C x. + +(* horizontal composition of two horizontal morphisms from a + cell product *) +Definition hhcomp (T: hdquiver) (x: DPobj T) : D1obj T := + match x with + @GC _ _ a b c h1 h2 => @TT2 T (@hhom T) a c (hcomp a b c h1 h2) end. +HB.tag Definition H1Comp (C: hdquiver) := + fun (x: DPobj C) => @hhcomp C x. + + +(* +(* Naked double category. Vertical V-D0 + and V-D1 categories. Strict double category without functors *) +Unset Universe Checking. +#[short(type="sd2cat")] +HB.structure Definition SDCat : Set := { C of Cat C (* & HCat C *) & D1Cat C }. +Set Universe Checking. +*) + +(** Auxiliary notions for Source, Target and + Horizontal Unit functors *) + +(* homsets of 2-cell (D1) morphisms *) +Definition d1hom (D: DQuiver.type) : D1obj D -> D1obj D -> U := + @hom (D1obj D). +(* type-level smart constructor for D1 homsets *) +Definition D1hom (D: DQuiver.type) (a b c d: D) (h0: hhom a b) + (h1: hhom c d) : U := d1hom (TT2 h0) (TT2 h1). + +(* smart projections for: + source functor (for horizontal morphisms): D1 -> D0. + defined as object-level function, by functoriality lifted to a + (2-cell, vertical) morphism-level one *) +HB.tag Definition HSource C := fun (X: D1obj C) => @source C (@hhom C) X. +(* target functor (for horizontal morphisms): D1 -> D0. *) +HB.tag Definition HTarget C := fun (X: D1obj C) => @target C (@hhom C) X. + +(* +(* horizontal unit functor: D0 -> D1 *) +Definition hhunit (T: hprecat) (a: T) : D1obj T := + @TT2 T (@hhom T) a a (@idmap (transpose T) a). +HB.tag Definition H1Unit (C: hprecat) := + fun (x: HPreCat.sort C) => @hhunit C x. +*) + +(** Auxiliary notions for 2-cell Horizontal Composition functor *) + +(* smart projections *) +Definition H2First (C: vhquiver) (X: @DPobj C) : D1obj C := + @TT2 C _ (h_one X) (h_two X) (h_first X). +Definition H2Second (C: vhquiver) (X: @DPobj C) : D1obj C := + @TT2 C _ (h_two X) (h_three X) (h_second X). + +(* +(* horizontal composition functor: D1 * D1 -> D1 *) +Definition hhcomp (T: hprecat) (x: DPobj T) : D1obj T := + match x with + @GC _ _ a b c h1 h2 => @TT2 T (@hhom T) a c (h1 \; h2) end. +HB.tag Definition H1Comp (C: hprecat) := + fun (x: DPobj C) => @hhcomp C x. +*) + +(* hhunit - horizontal unit functor. + + hhcomp - horizontal composition functor (horizontal composition of + two horizontal morphisms from a cell product). + + Both specified as object-level functions (they actually come for + free from the H-D0 category, since we are in the strict case), to + be lifted by functoriality to morphism-level ones. + + At the object level, hhunit gives a horizontal identity morphism + for each D0 object. At the morphism level, it gives horizontal + 2-cell identity for each vertical morphism. + + In the case of hhcomp, relying on functoriality requires some care + in defining the product category, making sure that adjacency at the + object-level (between horizontal morphisms) is matched by adjacency + at the morphism-level (between 2-cells). *) + + +(** Source and target functors *) + +(* source prefunctor. + D1obj T is the quiver of the 2-morphisms, thanks to VHQuiver. + T is the quiver of 1-morphisms. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsSPreFunctor T of DCat T := { + is_sprefunctor : IsPreFunctor (D1obj T) T (@HSource T) }. +HB.structure Definition SPreFunctor : Set := {C of IsSPreFunctor C}. +Set Universe Checking. + +(* target prefunctor. *) +Unset Universe Checking. +#[wrapper] + HB.mixin Record IsTPreFunctor T of DCat T := { + is_tprefunctor : IsPreFunctor (D1obj T) T (@HTarget T) }. +HB.structure Definition TPreFunctor : Set := {C of IsTPreFunctor C}. +Set Universe Checking. + +(* source functor. *) +Unset Universe Checking. +#[wrapper] + HB.mixin Record SPreFunctor_IsFunctor T of SPreFunctor T := { + is_sfunctor : PreFunctor_IsFunctor (D1obj T) T (@HSource T) }. +HB.structure Definition SFunctor : Set := {C of SPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* target functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record TPreFunctor_IsFunctor T of TPreFunctor T := { + is_tfunctor : PreFunctor_IsFunctor (D1obj T) T (@HTarget T) }. +HB.structure Definition TFunctor : Set := {C of TPreFunctor_IsFunctor C}. +Set Universe Checking. + + +(** Unit functor *) + +(* unit prefunctor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsUPreFunctor T of HDQuiver T & TFunctor T := + { is_uprefunctor : IsPreFunctor T (D1obj T) (@H1Unit T) }. +HB.structure Definition UPreFunctor : Set := {C of IsUPreFunctor C}. +Set Universe Checking. + +(* unit functor. *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record UPreFunctor_IsFunctor T of UPreFunctor T := { + is_ufunctor : PreFunctor_IsFunctor T (D1obj T) (@H1Unit T) }. +HB.structure Definition UFunctor : Set := {C of UPreFunctor_IsFunctor C}. +Set Universe Checking. + +Unset Universe Checking. +(* HB.about Functor. *) +HB.structure Definition STUFunctor : Set := + {C of SFunctor C & TFunctor C & UFunctor C}. +Set Universe Checking. + + +(** Lifting of Source, Target and Unit functors to D1 morphisms *) + +(* 2-cell source *) +Definition H1Source (T: SFunctor.type) (a b: @D1obj T) + (m: @d1hom T a b) : + (HSource a) ~> (HSource b) := (@HSource T) <$> m. + +(* 2-cell target *) +Definition H1Target (T: TFunctor.type) (a b: @D1obj T) + (m: @d1hom T a b) : + (HTarget a) ~> (HTarget b) := (@HTarget T) <$> m. + +(* horizontal 2-cell unit (maps vertical morphisms to horizontally + unitary 2-cells) *) +Definition H2Unit (T: UFunctor.type) (a b: T) (m: @hom T a b) : + (H1Unit a) ~> (H1Unit b) := (@H1Unit T) <$> m. + +(* DP objects source and target *) +Lemma DPsource (T: STUFunctor.type) (a: DPobj T) : + HSource (H1Comp a) = HSource (TT2 (h_first a)). + destruct a; simpl in *; simpl. + auto. +Defined. + +Lemma DPtarget (T: STUFunctor.type) (a: DPobj T) : + HTarget (H1Comp a) = HTarget (TT2 (h_second a)). + destruct a; simpl in *; simpl. + auto. +Defined. + + +(** Horizontal product category (D1 *d0 D1) *) +(* DPobj T is the pseudo-pullback category used to deal with + products of D1 (where the adjacency condition is expressed + w.r.t. D0 *) + +(* horizontal composition of two (naked) horizontal morphisms *) +Definition l_hcomp (T: UFunctor.type) (a0 a1 a2: T) + (h0: hhom a0 a1) (h1: hhom a1 a2) : D1obj T := + @TT2 T _ a0 a2 (hcomp a0 a1 a2 h0 h1). + +(* +Notation "'sigma' x .. y , p" := + (sigT (fun x => .. (sigT (fun y => p)) ..)) + (at level 200, x binder, right associativity, + format "'[' 'sigma' '/ ' x .. y , '/ ' p ']'") + : type_scope. +*) + +(** DPobj quiver *) +Definition DP_hom (T: STUFunctor.type) (x y: DPobj T) := + sigma (hh0: D1hom (h_first x) (h_first y)) + (hh1: D1hom (h_second x) (h_second y)), + H1Target hh0 = H1Source hh1. + +HB.instance Definition DPQuiver (T: STUFunctor.type) : + IsQuiver (DPobj T) := + IsQuiver.Build (DPobj T) (fun A B => @DP_hom T A B). + + +(** Product precategory *) + +Lemma DP_id_eq (T : STUFunctor.type) (a: DPobj T) : + H1Target (@idmap (@D1obj T) (H2First a)) = + H1Source (@idmap (@D1obj T) (H2Second a)). +unfold H1Target, HTarget. +unfold H1Source, HSource. +repeat rewrite F1; auto. +Defined. + +(* DPobj identity *) +Definition DP_id (T: STUFunctor.type) (A: DPobj T) : A ~> A := + let h0 := h_first A + in let h1 := h_second A + in let uu0 := @idmap (D1obj T) (TT2 h0) + in let uu1 := @idmap (D1obj T) (TT2 h1) + in @existT (D1hom h0 h0) + (fun hh0: (D1hom h0 h0) => + sigma (hh1 : D1hom h1 h1), H1Target hh0 = H1Source hh1) uu0 + (@existT (D1hom h1 h1) + (fun hh1: (D1hom h1 h1) => H1Target uu0 = H1Source hh1) uu1 + (@DP_id_eq T A)). + +Definition DP_comp_auxA (T : STUFunctor.type) + (A B C : DPobj T) + (hhA0 : D1hom (h_first A) (h_first B)) + (hhA1 : D1hom (h_second A) (h_second B)) + (ppA : H1Target hhA0 = H1Source hhA1) + (hhB0 : D1hom (h_first B) (h_first C)) + (hhB1 : D1hom (h_second B) (h_second C)) + (ppB : H1Target hhB0 = H1Source hhB1) : + (H1Target hhA0) \; (H1Target hhB0) = + (H1Source hhA1) \; (H1Source hhB1). + rewrite ppA. + rewrite ppB. + reflexivity. +Defined. + +Definition DP_comp_auxS (T : STUFunctor.type) + (A B C : DPobj T) + (hhA0 : D1hom (h_first A) (h_first B)) + (hhA1 : D1hom (h_second A) (h_second B)) + (ppA : H1Target hhA0 = H1Source hhA1) + (hhB0 : D1hom (h_first B) (h_first C)) + (hhB1 : D1hom (h_second B) (h_second C)) + (ppB : H1Target hhB0 = H1Source hhB1) : + H1Source (hhA1 \; hhB1) = (H1Source hhA1) \; (H1Source hhB1). + unfold H1Source, HSource. + repeat rewrite Fcomp. + reflexivity. +Defined. + +Definition DP_comp_auxT (T : STUFunctor.type) + (A B C : DPobj T) + (hhA0 : D1hom (h_first A) (h_first B)) + (hhA1 : D1hom (h_second A) (h_second B)) + (ppA : H1Target hhA0 = H1Source hhA1) + (hhB0 : D1hom (h_first B) (h_first C)) + (hhB1 : D1hom (h_second B) (h_second C)) + (ppB : H1Target hhB0 = H1Source hhB1) : + H1Target (hhA0 \; hhB0) = (H1Target hhA0) \; (H1Target hhB0). + unfold H1Target, HTarget. + repeat rewrite Fcomp. + reflexivity. +Defined. + +Definition DP_comp_auxI (T : STUFunctor.type) + (A B C : DPobj T) + (hhA0 : D1hom (h_first A) (h_first B)) + (hhA1 : D1hom (h_second A) (h_second B)) + (ppA : H1Target hhA0 = H1Source hhA1) + (hhB0 : D1hom (h_first B) (h_first C)) + (hhB1 : D1hom (h_second B) (h_second C)) + (ppB : H1Target hhB0 = H1Source hhB1) : + A ~> C. + econstructor 1 with (comp hhA0 hhB0). + econstructor 1 with (comp hhA1 hhB1). + setoid_rewrite DP_comp_auxS; eauto. + setoid_rewrite DP_comp_auxT; eauto. + eapply DP_comp_auxA; eauto. +Defined. + +(* DPobj composition, defined in proof mode *) +Definition DP_comp (T: STUFunctor.type) (A B C: DPobj T) : + (A ~> B) -> (B ~> C) -> A ~> C. + intros chA chB. + destruct chA as [hhA0 [hhA1 ppA]]. + destruct chB as [hhB0 [hhB1 ppB]]. + eapply DP_comp_auxI; eauto. +Defined. + +(* DPobj is a precategory *) +HB.instance Definition DPPreCat (T: STUFunctor.type) : + Quiver_IsPreCat (DPobj T) := + Quiver_IsPreCat.Build (DPobj T) (@DP_id T) (@DP_comp T). + +(* + have HcompP : + (a b : DPobj T) + (f g : a ~> b), + proj1T f = proj1t f -> + + -> + f = g. + + exists a b p, + fst f = a + f = (a,b,p) +*) + +(** Product category *) + +Lemma DP_LeftUnit_lemma (T : STUFunctor.type) : + forall (a b : DPobj T) (f : a ~> b), idmap \; f = f. + + move => a b [x [x0 e]] /=. + simpl in *. + unfold idmap; simpl. + unfold DP_id; simpl. + unfold comp; simpl. + unfold DP_comp_auxI; simpl. + + assert (idmap \; x = x) as A. + { rewrite comp1o; auto. } + + assert (idmap \; x0 = x0) as A0. + { rewrite comp1o; auto. } + + assert (H1Target (idmap \; x) = H1Source (idmap \; x0)) as B. + { rewrite A. + rewrite A0; auto. } + + destruct a eqn: aaa. + destruct b eqn: bbb. + simpl. + + assert (existT + (fun hh0 : D1hom h_first0 h_first1 => + sigma hh1 : D1hom h_second0 h_second1,H1Target hh0 = H1Source hh1) + (idmap \; x) + (existT + (fun hh1 : D1hom h_second0 h_second1 => + H1Target (idmap \; x) = H1Source hh1) + (idmap \; x0) + B) = + existT + (fun hh0 : D1hom h_first0 h_first1 => + sigma hh1 : D1hom h_second0 h_second1,H1Target hh0 = H1Source hh1) + x + (existT + (fun hh1 : D1hom h_second0 h_second1 => H1Target x = H1Source hh1) + x0 + e)) as C. + { revert B. + revert A. + revert A0. + generalize (idmap \; x) as v. + generalize (idmap \; x0) as v0. + intros v0 v A0. + rewrite A0. + intro A. + rewrite A. + intro B. + + assert (B = e) as BE. + { eapply Prop_irrelevance. } + + rewrite BE. + reflexivity. +} + + inversion aaa; subst. + rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] + (Prop_irrelevance _ B). + eapply C. +Qed. + +Lemma DP_RightUnit_lemma (T : STUFunctor.type) : + forall (a b : DPobj T) (f : a ~> b), f \; idmap = f. + + move => a b [x [x0 e]] /=. + simpl in *. + unfold idmap; simpl. + unfold DP_id; simpl. + unfold comp; simpl. + unfold DP_comp_auxI; simpl. + + assert (x \; idmap = x) as A. + { rewrite compo1; auto. } + + assert (x0 \; idmap = x0) as A0. + { rewrite compo1; auto. } + + assert (H1Target (x \; idmap) = H1Source (x0 \; idmap)) as B. + { rewrite A. + rewrite A0; auto. } + + destruct a eqn: aaa. + destruct b eqn: bbb. + simpl. + + assert (existT + (fun hh0 : D1hom h_first0 h_first1 => + sigma hh1 : D1hom h_second0 h_second1, + H1Target hh0 = H1Source hh1) + (x \; idmap) + (existT + (fun hh1 : D1hom h_second0 h_second1 => + H1Target (x \; idmap) = H1Source hh1) + (x0 \; idmap) + B) = + existT + (fun hh0 : D1hom h_first0 h_first1 => + sigma hh1 : D1hom h_second0 h_second1, + H1Target hh0 = H1Source hh1) + x + (existT + (fun hh1 : D1hom h_second0 h_second1 => + H1Target x = H1Source hh1) + x0 + e)) as C. + { revert B. + revert A. + revert A0. + generalize (x \; idmap) as v. + generalize (x0 \; idmap) as v0. + intros v0 v A0. + rewrite A0. + intro A. + rewrite A. + intro B. + + assert (B = e) as BE. + { eapply Prop_irrelevance. } + + rewrite BE. + reflexivity. + } + + inversion aaa; subst. + rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] + (Prop_irrelevance _ B). + eapply C. +Qed. + +Lemma DP_Assoc_lemma (T : STUFunctor.type) : + forall (a b c d : DPobj T) (f : a ~> b) (g : b ~> c) (h : c ~> d), + f \; g \; h = (f \; g) \; h. + intros. + remember f as f1. + remember g as g1. + remember h as h1. + destruct f as [x0 s0]. + destruct g as [x1 s1]. + destruct h as [x2 s2]. + destruct s0 as [y0 e0]. + destruct s1 as [y1 e1]. + destruct s2 as [y2 e2]. + simpl. + + set (x01 := comp x0 x1). + set (x12 := comp x1 x2). + set (x0_12 := comp x0 x12). + set (x01_2 := comp x01 x2). + set (y01 := comp y0 y1). + set (y12 := comp y1 y2). + set (y0_12 := comp y0 y12). + set (y01_2 := comp y01 y2). + + assert (x0_12 = x01_2) as X0. + { subst x0_12 x01_2. + rewrite compoA; eauto. } + assert (y0_12 = y01_2) as Y0. + { subst y0_12 y01_2. + rewrite compoA; eauto. } + + set (x01_t := comp (H1Target x0) (H1Target x1)). + set (x01_2_t := comp x01_t (H1Target x2)). + set (x12_t := comp (H1Target x1) (H1Target x2)). + set (x0_12_t := comp (H1Target x0) x12_t). + set (y01_s := comp (H1Source y0) (H1Source y1)). + set (y01_2_s := comp y01_s (H1Source y2)). + set (y12_s := comp (H1Source y1) (H1Source y2)). + set (y0_12_s := comp (H1Source y0) y12_s). + + assert (x01_t = y01_s) as E01. + { subst x01_t y01_s. + rewrite e0. + rewrite e1; auto. } + assert (x01_2_t = y01_2_s) as E01_2. + { subst x01_2_t y01_2_s. + rewrite E01. + rewrite e2; auto. } + assert (x12_t = y12_s) as E12. + { subst x12_t y12_s. + rewrite e1. + rewrite e2; auto. } + assert (x0_12_t = y0_12_s) as E0_12. + { subst x0_12_t y0_12_s. + rewrite E12. + rewrite e0; auto. } + + assert (x0_12_t = x01_2_t) as E02T. + { subst x0_12_t x01_2_t. + subst x12_t x01_t. + rewrite compoA; auto. } + assert (y0_12_s = y01_2_s) as E02S. + { subst y0_12_s y01_2_s. + subst y12_s y01_s. + rewrite compoA; auto. } + + unfold comp. + simpl. + unfold DP_comp. + simpl. + inversion Heqf1; subst. + clear H. + + unfold DP_comp_auxI; simpl. + + assert (H1Target (x0 \; x1 \; x2) = + H1Source (y0 \; y1 \; y2)) as KR. + { subst x0_12_t y0_12_s. + subst x12_t y12_s. + unfold H1Target. + repeat rewrite Fcomp; simpl. + unfold H1Target in E0_12. + rewrite E0_12. + unfold H1Source. + repeat rewrite Fcomp; simpl. + auto. + } + + assert (H1Target ((x0 \; x1) \; x2) = + H1Source ((y0 \; y1) \; y2)) as KL. + { subst x01_2_t y01_2_s. + subst x01_t y01_s. + unfold H1Target. + repeat rewrite Fcomp; simpl. + unfold H1Target in E01_2. + rewrite E01_2. + unfold H1Source. + repeat rewrite Fcomp; simpl. + auto. + } + + assert (existT + (fun hh0 : D1hom (h_first a) (h_first d) => + sigma hh1 : D1hom (h_second a) (h_second d), + H1Target hh0 = H1Source hh1) + (x0 \; x1 \; x2) + (existT + (fun hh1 : D1hom (h_second a) (h_second d) => + H1Target (x0 \; x1 \; x2) = H1Source hh1) + (y0 \; y1 \; y2) + KR) + = + existT + (fun hh0 : D1hom (h_first a) (h_first d) => + sigma hh1 : D1hom (h_second a) (h_second d), + H1Target hh0 = H1Source hh1) + ((x0 \; x1) \; x2) + (existT + (fun hh1 : D1hom (h_second a) (h_second d) => + H1Target ((x0 \; x1) \; x2) = H1Source hh1) + ((y0 \; y1) \; y2) + KL)) as KA. + { revert KL. + revert KR. + subst x0_12 x01_2 x12 x01. + subst y0_12 y01_2 y12 y01. + rewrite <- X0. + rewrite <- Y0. + intros KR KL. + + assert (KR = KL) as I1. + { eapply Prop_irrelevance. } + rewrite I1. + reflexivity. + } + + rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] + (Prop_irrelevance _ KR). + + rewrite [Morphisms.trans_sym_co_inv_impl_morphism _ _ _ _ _] + (Prop_irrelevance _ KL). + eapply KA. +Qed. + +Program Definition DPCatP (T: STUFunctor.type) : + PreCat_IsCat (DPobj T). +econstructor. +eapply DP_LeftUnit_lemma; eauto. +eapply DP_RightUnit_lemma; eauto. +eapply DP_Assoc_lemma; eauto. +Qed. + +(* DPobj is a category *) +HB.instance Definition DPCat (T: STUFunctor.type) := DPCatP T. + + +(** Horizontal composition functor and strict double categories *) + +(* fst horizontal projection prefunctor *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHFPreFunctor T of STUFunctor T := + { is_hfprefunctor : IsPreFunctor (DPobj T) (D1obj T) (@H2First T) }. +HB.structure Definition HFPreFunctor : Set := {C of IsHFPreFunctor C}. +Set Universe Checking. + +(* fst horizontal projection functor *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record HFPreFunctor_IsFunctor T of HFPreFunctor T := { + is_hffunctor : PreFunctor_IsFunctor (DPobj T) (D1obj T) (@H2First T) }. +HB.structure Definition HFFunctor : Set := {C of HFPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* snd horizontal projection prefunctor *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsHSPreFunctor T of STUFunctor T := + { is_hsprefunctor : IsPreFunctor (DPobj T) (D1obj T) (@H2Second T) }. +HB.structure Definition HSPreFunctor : Set := {C of IsHSPreFunctor C}. +Set Universe Checking. + +(* snd horizontal projection functor *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record HSPreFunctor_IsFunctor T of HSPreFunctor T := { + is_hsfunctor : PreFunctor_IsFunctor (DPobj T) (D1obj T) (@H2Second T) }. +HB.structure Definition HSFunctor : Set := {C of HSPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* composition prefunctor *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record IsCPreFunctor T of STUFunctor T := + { is_cprefunctor : IsPreFunctor (DPobj T) (D1obj T) (@H1Comp T) }. +HB.structure Definition CPreFunctor : Set := {C of IsCPreFunctor C}. +Set Universe Checking. + +(* composition functor - gives the definition of Strict Double Category *) +Unset Universe Checking. +#[wrapper] +HB.mixin Record CPreFunctor_IsFunctor T of CPreFunctor T := { + is_cfunctor : PreFunctor_IsFunctor (DPobj T) (D1obj T) (@H1Comp T) }. +(* #[short(type="sdoublecat")] *) +HB.structure Definition CFunctor : Set := {C of CPreFunctor_IsFunctor C}. +Set Universe Checking. + +(* All functors together *) +Unset Universe Checking. +HB.structure Definition FCFunctor : Set := + {C of HFFunctor C & HSFunctor C & CFunctor C}. +Set Universe Checking. + + +(* first and second projection from pairs of cells *) +Definition HH2First (T: HFFunctor.type) (a b: DPobj T) + (m: DP_hom a b) : H2First a ~> H2First b := (@H2First T) <$> m. + +Definition HH2Second (T: HSFunctor.type) (a b: DPobj T) + (m: DP_hom a b) : H2Second a ~> H2Second b := (@H2Second T) <$> m. + + +(* horizontal 2-cell composition: maps two adjecent pairs of + horizontal morphisms (a and b) and a pullback-category morphism + between them (m, which basically gives two adjecent cells) to a + 2-cell morphism between the horizontal composition (HComp) of each + pair *) +Definition HC2Comp (T: CFunctor.type) (a b: DPobj T) + (m: DP_hom a b) : + d1hom (H1Comp a) (H1Comp b) := @Fhom _ _ (@H1Comp T) a b m. + +(* +Definition HC2Comp (T: CFunctor.type) (a b: DPobj T) + (m: @hom (DPobj T) a b) : + d1hom (H1Comp a) (H1Comp b) := @Fhom _ _ (@H1Comp T) a b m. +*) + +Program Definition HC2Comp_flat (T: CFunctor.type) (a0 a1 a2 b0 b1 b2: T) + (h0: hhom a0 a1) (h1: hhom a1 a2) + (k0: hhom b0 b1) (k1: hhom b1 b2) + (hh0: D1hom h0 k0) + (hh1: D1hom h1 k1) + (k: H1Target hh0 = H1Source hh1) : + D1hom (hcomp _ _ _ h0 h1) (hcomp _ _ _ k0 k1) := + (* d1hom (l_hcomp h0 h1) (l_hcomp k0 k1) := *) + @Fhom _ _ (@H1Comp T) (GC h0 h1) (GC k0 k1) _. +Obligation 1. +refine (@existT (D1hom h0 k0) _ hh0 (@existT (D1hom h1 k1) _ hh1 k)). +Show Proof. + +Defined. + + +(* quasi-double category *) +Unset Universe Checking. +HB.mixin Record IsQDoubleCat T of FCFunctor T := { + unit_source : forall (a b: T) (m: hom a b), + H1Source (H2Unit m) = m ; + + unit_target : forall (a b: T) (m: hom a b), + H1Target (H2Unit m) = m ; +}. +#[short(type="qdoublecat")] +HB.structure Definition QDoubleCat : Set := + { C of IsQDoubleCat C }. +Set Universe Checking. + + +(* definition of strict double precategory *) +Unset Universe Checking. +HB.mixin Record IsPreSDoubleCat T of QDoubleCat T := { + source_comp_dist : forall (a b: DPobj T) (m: DP_hom a b), + TT2 (H1Source (HC2Comp m)) = TT2 (H1Source (HH2First m)) ; + + target_comp_dist : forall (a b: DPobj T) (m: DP_hom a b), + TT2 (H1Target (HC2Comp m)) = TT2 (H1Target (HH2Second m)) ; +}. +#[short(type="presdoublecat")] +HB.structure Definition PreSDoubleCat : Set := + { C of IsPreSDoubleCat C }. +Set Universe Checking. + + +(* alternative definition of strict double precategory *) +Unset Universe Checking. +HB.mixin Record IsPreSDoubleCat1 T of QDoubleCat T := { + source_comp_dist1 : forall (a0 a1 a2 b0 b1 b2: T) + (h0: hhom a0 a1) (h1: hhom a1 a2) + (k0: hhom b0 b1) (k1: hhom b1 b2) + (hh0: D1hom h0 k0) + (hh1: D1hom h1 k1) + (K: H1Target hh0 = H1Source hh1), + H1Source (HC2Comp_flat K) = H1Source hh0 ; + + target_comp_dist1 : forall (a0 a1 a2 b0 b1 b2: T) + (h0: hhom a0 a1) (h1: hhom a1 a2) + (k0: hhom b0 b1) (k1: hhom b1 b2) + (hh0: D1hom h0 k0) + (hh1: D1hom h1 k1) + (K: H1Target hh0 = H1Source hh1), + H1Target (HC2Comp_flat K) = H1Target hh1 ; +}. +#[short(type="presdoublecat1")] +HB.structure Definition PreSDoubleCat1 : Set := + { C of IsPreSDoubleCat1 C }. +Set Universe Checking. + + + +(** Horizontal 2-cell level category (H1 category) *) + +HB.tag Definition H1obj (C: VHQuiver.type) := Total2 (@hom C). + +(* a and b are vertical (D0) morphisms. Gives the condition for a +horizontal (H1) morphism between them. Given two horizontal (H0) +morphisms h1 and h2 between sources and targets of the vertical ones, +respectively, we expect that there is a vertical (D1) morphism between +them. *) +Definition H1hom (T: STUFunctor.type) (a b: H1obj T) := + sigma (h1: hhom (source a) (source b)) (h2: hhom (target a) (target b)) + (hh: D1hom h1 h2), + H1Source hh = this_morph a /\ H1Target hh = this_morph b. +(* +Definition H1hom (T: DQuiver.type) (a b: H1obj T) := + sigma (h1: hhom (source a) (source b)) (h2: hhom (target a) (target b)), + @hom (D1obj T) (TT2 h1) (TT2 h2). +*) + +HB.instance Definition H1Quiver (T: STUFunctor.type) : + IsQuiver (H1obj T) := + IsQuiver.Build (H1obj T) (@H1hom T). + + +Program Definition H1_id (T: QDoubleCat.type) (a: H1obj T) : a ~> a. +unfold hom. +simpl. +unfold H1hom. +destruct a. +simpl; simpl in *. +econstructor 1 with (x:= hunit source0). +econstructor 1 with (x:= hunit target0). +econstructor 1 with (x:= H2Unit this_morph0). +split. +eapply unit_source. +eapply unit_target. +Defined. + +Program Definition H1_comp (T: PreSDoubleCat1.type) (a b c: H1obj T) + (hh1: a ~> b) (hh2: b ~> c) : a ~> c. +destruct a. +destruct b. +destruct c. +unfold hom in *; simpl in *. +unfold H1hom in *; simpl in *. +destruct hh1 as [h1 [k1 [hk1 [hk1S hk1T]]]]. +destruct hh2 as [h2 [k2 [hk2 [hk2S hk2T]]]]. +econstructor 1 with (x:= hcomp _ _ _ h1 h2). +econstructor 1 with (x:= hcomp _ _ _ k1 k2). +assert (@H1Target T (TT2 h1) (TT2 k1) hk1 = + @H1Source T (TT2 h2) (TT2 k2) hk2) as K. +{ + rewrite hk1T. + rewrite hk2S; auto. +} + +econstructor 1 with (x := HC2Comp_flat K). + +split. +rewrite source_comp_dist1; auto. +rewrite target_comp_dist1; auto. +Defined. + +HB.instance Definition H1PreCat (T: PreSDoubleCat1.type) : + IsPreCat (H1obj T) := + IsPreCat.Build (H1obj T) (@H1_id T) (@H1_comp T). + +Unset Universe Checking. +#[wrapper] +(* Fail HB.mixin Record IsSDoubleCat T of PreSDoubleCat1 T := { + Fail HB.mixin Record IsSDoubleCat T of IsPreSDoubleCat1 T := { *) +HB.mixin Record IsSDoubleCat (T: PreSDoubleCat1.type) := { + is_sdcat : PreCat_IsCat (H1obj T) }. +#[short(type="sdcat")] +HB.structure Definition SDoubleCat : Set := + { C of IsSDoubleCat C }. +Set Universe Checking. + + + +(* +Program Definition H2hom (T: DQuiver.type) (a b: H1obj T) := + match (a, b) with + | (@TT2 _ _ sa ta ma, @TT2 _ _ sb tb mb) => + sigma (h1: hhom sa sb) (h2: hhom ta tb), (@TT2 T _ h1) ~> (TT2 h2) end. + +(* Precategory based on the DQuiver (i.e. precategory D1). Gives: + vertical 2-cell identity morphism. + vertical 2-cell composition. *) +HB.instance Definition H2Quiver (T: DQuiver.type) : + IsQuiver (transpose (D1obj T)) := + IsQuiver.Build (transpose (D1obj T)) + + + +Unset Universe Checking. +#[wrapper] +HB.mixin Record _IsD1PreCat T of DQuiver T := { + is_d1precat : Quiver_IsPreCat (@D1obj T) }. +#[short(type="d1precat")] +HB.structure Definition D1PreCat : Set := + { C of Quiver_IsPreCat (@D1obj C) }. +Set Universe Checking. + + +(* Like requiring HCat T *) +HB.mixin Record IsDCat T of CFunctor T := { + h1_left_unital : forall (a0 a1: T) (h : hhom a0 a1), + @hcomp T a0 a0 a1 (hunit a0) h = h ; + + h1_right_unital : forall (a0 a1: T) (h : hhom a0 a1), + @hcomp T a0 a1 a1 h (hunit a1) = h ; + + h1_assoc : forall (a0 a1 a2 a3: T) + (h1 : hhom a0 a1) + (h2: hhom a1 a2) (h3: hhom a2 a3), + @hcomp T a0 a2 a3 (@hcomp T a0 a1 a2 h1 h2) h3 = + @hcomp T a0 a1 a3 h1 (@hcomp T a1 a2 a3 h2 h3) +}. +Unset Universe Checking. +#[short(type="sdoublecat")] +HB.structure Definition SDoubleCat : Set := { C of IsDCat C }. +Set Universe Checking. + +Lemma DP1source (T: CFunctor.type) (a b: DPobj T) + (m: DP_hom a b) : + H1Source (HC2Comp m) = H1Source (HC2Comp m) /\ + H1Source (projT1 m) = H1Source (projT1 m). + remember m as m1. + destruct m1. + simpl. + destruct s. + unfold HC2Comp. + unfold H1Comp. + unfold hhcomp. + + unfold Fhom. + simpl. + unfold H1Source. + unfold HSource. + unfold hhom. + simpl. + destruct a. + destruct b. + unfold hhom in *. + simpl; simpl in *. + unfold DP_hom in m. + simpl in *. + +Lemma DP1source (T: CFunctor.type) (a b: DPobj T) + (m: @hom (DPobj T) a b) : + H1Source (HC2Comp m) = + H1Source (TT2 (h_first m)). + destruct a; simpl in *; simpl. + auto. +Defined. + + +Lemma Adj12_3 (T: CFunctor.type) (a b: DPobj T) + (m: @hom (DPobj T) a b) : + H1Source (HC2Comp m) = H1Source (projT1 a). + + + + T: CFunctor.type} {a0 a1 a2 a3 b0 b1 b2 b3: T} + {h1: hhom a0 a1} {h2: hhom a1 a2} {h3: hhom a2 a3} + {k1: hhom b0 b1} {k2: hhom b1 b2} {k3: hhom b2 b3} + (hh1: D1hom h1 k1) (hh2: D1hom h2 k2) (hh3: D1hom h3 k3) + (A1: H1Target hh1 = H1Source hh2) + (A2: H1Target hh2 = H1Source hh3) : + let hh12 := @HC2Comp_flat T a0 a1 a2 b0 b1 b2 h1 h2 k1 k2 hh1 hh2 A1 + in H1Target hh12 = H1Source hh3. + + + + +Lemma Adj12_3 {T: CFunctor.type} {a0 a1 a2 a3 b0 b1 b2 b3: T} + {h1: hhom a0 a1} {h2: hhom a1 a2} {h3: hhom a2 a3} + {k1: hhom b0 b1} {k2: hhom b1 b2} {k3: hhom b2 b3} + (hh1: D1hom h1 k1) (hh2: D1hom h2 k2) (hh3: D1hom h3 k3) + (A1: H1Target hh1 = H1Source hh2) + (A2: H1Target hh2 = H1Source hh3) : + let hh12 := @HC2Comp_flat T a0 a1 a2 b0 b1 b2 h1 h2 k1 k2 hh1 hh2 A1 + in H1Target hh12 = H1Source hh3. + simpl. + rewrite - A2. + clear A2 hh3. + clear h3 k3. + unfold HC2Comp_flat. + unfold H1Comp. + + unfold H1Target, H1Source in *. + unfold HTarget, HSource in *. + unfold target. + unfold HC2Comp_flat_obligation_1; simpl. + unfold H1Comp; simpl. + unfold hhcomp; simpl. + + unfold Fhom in * ; simpl. + unfold IsPreFunctor.Fhom in *. + simpl; simpl in *. + unfold D1hom in *. + unfold d1hom in *; simpl in *. + unfold hhom in *. + unfold hom in *. + simpl in *. + + unfold l_hcomp. + unfold hcomp. + simpl. + + + unfold D1hom in *. + simpl. + unfold H1Target, H1Source in A1. + unfold HTarget, HSource in A1. + simpl in *. + unfold Fhom in A1. + + assert (forall U, U <$> + (IsPreFunctor.Fhom (Op_isMx__306__ELIM T) + (existT + (fun hh0 : D1hom h1 k1 => + sigma hh3 : D1hom h2 k2, H1Target hh0 = H1Source hh3) hh1 + (existT (fun hh0 : D1hom h2 k2 => H1Target hh1 = H1Source hh0) hh2 + A1))) = + U <$> hh2). + + rewrite - A2. + unfold H1Target, H1Source. + unfold HTarget, HSource. + unfold D1hom in *. + unfold d1hom in *. + unfold hom. + simpl. + unfold Fhom. + simpl. +Admitted. + +Lemma Adj1_23 {T: CFunctor.type} {a0 a1 a2 a3 b0 b1 b2 b3: T} + {h1: hhom a0 a1} {h2: hhom a1 a2} {h3: hhom a2 a3} + {k1: hhom b0 b1} {k2: hhom b1 b2} {k3: hhom b2 b3} + (hh1: D1hom h1 k1) (hh2: D1hom h2 k2) (hh3: D1hom h3 k3) + (A1: H1Target hh1 = H1Source hh2) + (A2: H1Target hh2 = H1Source hh3) : + let hh23 := @HC2Comp_flat T a1 a2 a3 b1 b2 b3 h2 h3 k2 k3 hh2 hh3 A2 + in H1Target hh1 = H1Source hh23. +Admitted. + +HB.mixin Record IsDCat2 T of CFunctor T := { + h2_left_unital : forall (a0 a1 b0 b1: T) (m: @hom T a0 b0) + (h1: hhom a0 a1) (k1: hhom b0 b1) + (hh1: D1hom h1 k1) + (A: H1Target (@H2Unit T a0 b0 m) = H1Source hh1), + TT2 (@HC2Comp_flat T a0 a0 a1 b0 b0 b1 (hunit a0) h1 (hunit b0) k1 + (@H2Unit T a0 b0 m) hh1 A) = TT2 hh1 ; + + h2_right_unital : forall (a0 a1 b0 b1: T) (m: @hom T a1 b1) + (h1: hhom a0 a1) (k1: hhom b0 b1) + (hh1: D1hom h1 k1) + (A: H1Target hh1 = H1Source (@H2Unit T a1 b1 m)), + TT2 (@HC2Comp_flat T a0 a1 a1 b0 b1 b1 h1 (hunit a1) k1 (hunit b1) + hh1 (@H2Unit T a1 b1 m) A) = TT2 hh1 ; + + h2_assoc : forall (a0 a1 a2 a3 b0 b1 b2 b3: T) + (h1: hhom a0 a1) (h2: hhom a1 a2) (h3: hhom a2 a3) + (k1: hhom b0 b1) (k2: hhom b1 b2) (k3: hhom b2 b3) + (hh1: D1hom h1 k1) (hh2: D1hom h2 k2) (hh3: D1hom h3 k3) + (A1: H1Target hh1 = H1Source hh2) + (A2: H1Target hh2 = H1Source hh3), + let hh12 := + @HC2Comp_flat T a0 a1 a2 b0 b1 b2 h1 h2 k1 k2 hh1 hh2 A1 + in let hh23 := + @HC2Comp_flat T a1 a2 a3 b1 b2 b3 h2 h3 k2 k3 hh2 hh3 A2 + in TT2 (HC2Comp_flat (Adj12_3 A1 A2)) = + TT2 (HC2Comp_flat (Adj1_23 A1 A2)) ; +}. +Unset Universe Checking. +#[short(type="sdoublecat2")] +HB.structure Definition SDoubleCat2 : Set := { C of IsDCat2 C }. +Set Universe Checking. + + +(* hcomp (hm, hu) = prj1 (hm, hu) = hm + hcomp (hu, hm) = prj2 (hu, hm) = hm + (hm1 * hm2) * hm3 ~> hm1 * (hm2 * hm3) + +(* Double category with universal characterization of weak + horizontal associativity *) +HB.mixin Record IsDCat_UA T of CFunctor T := { + associator : forall (a0 a1 a2 a3: T) + (h1: @hhom T a0 a1) (h2: @hhom T a1 a2) + (h3: @hhom T a2 a3), + let h23 := hcomp a1 a2 a3 h2 h3 in + let h12 := hcomp a0 a1 a2 h1 h2 in + let hh1 := hcomp a0 a1 a3 h1 h23 in + let hh2 := hcomp a0 a2 a3 h12 h3 in + @hom (HHomSet T) (@HO T (@hhom T) a0 a3 hh2) + (@HO T (@hhom T) a0 a3 hh1) +}. +*) + +Definition l_hcomp (T: SDCat.type) (a0 a1 a2: T) + (h0: hhom a0 a1) (h1: hhom a1 a2) : D1obj T := + @TT2 T _ a0 a2 (h0 \; h1). +*) From e19ed85fc10ec89926900f01302db0aaea24cabd Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Mon, 4 Mar 2024 15:21:21 +0100 Subject: [PATCH 143/147] wip --- HB/status.elpi | 11 ++++ HB/structure.elpi | 134 +++++++++++++++++++++++++++++++++++----------- theories/encatD.v | 21 ++------ 3 files changed, 120 insertions(+), 46 deletions(-) diff --git a/HB/status.elpi b/HB/status.elpi index e6bf3684e..ab857a82f 100644 --- a/HB/status.elpi +++ b/HB/status.elpi @@ -28,6 +28,13 @@ print-hierarchy :- std.do! [ std.forall BDL private.pp-builder-decl ), + std.findall (wrapper-mixin _ _ _) WL, + if (WL = []) true ( + coq.say "", + coq.say "--------------------- Wrappers ----------------------", + std.forall WL private.pp-wrapper + ), + std.findall (current-mode BF_) BFL, if (BFL = []) true ( coq.say "", @@ -76,6 +83,10 @@ pp-builder-decl (builder-decl (builder N F M GR)) :- coq.say "builder" GR "with serial number" N "will build mixin" M "from factory" F. +pred pp-wrapper i:prop. +pp-wrapper (wrapper-mixin W O M) :- + coq.say "wrapper" W "for mixin" M "for lifter" O. + pred pp-current-mode i:prop. pp-current-mode (current-mode (builder-from TheType TheFactory GRF Mod)) :- coq.say "The current key is" TheType "with factory" TheFactory diff --git a/HB/structure.elpi b/HB/structure.elpi index 3bf9d6d99..ff2a762dc 100644 --- a/HB/structure.elpi +++ b/HB/structure.elpi @@ -711,41 +711,68 @@ lift-to-the-subject.aux [factory-on-subject-lifter Expr _ _|_] _ _ :- pred declare-wrappers i:term, o:list prop. declare-wrappers B C :- std.do! [ private.sigT->list-w-params B X _, - declare-wrappers.aux X Wrappers, - distribute-w-params Wrappers WrappersWP, - std.fold WrappersWP [] declare-wrapper C, + declare-wrappers.filter-lifted X FWrappers, + distribute-w-params FWrappers FWrappersWP, + factories-provide FWrappersWP WrappersWP, + declare-wrappers.filter-new WrappersWP NewWrappersWP, + std.fold NewWrappersWP [] declare-wrapper C, ]. -declare-wrappers.aux (w-params.cons ID T F) (w-params.cons ID T F1) :- - @pi-parameter ID T x\ declare-wrappers.aux (F x) (F1 x). -declare-wrappers.aux (w-params.nil ID T F) (w-params.nil ID T F1) :- - @pi-parameter ID T x\ declare-wrappers.aux2 (F x) (F1 x). -declare-wrappers.aux2 [factory-on-the-type _|XS] R :- declare-wrappers.aux2 XS R. -declare-wrappers.aux2 [factory-on-subject-lifter _ F G|XS] R :- wrapper-mixin _ G F, !, declare-wrappers.aux2 XS R. -declare-wrappers.aux2 [factory-on-subject-lifter T F G|XS] [triple (triple T F G) _ _|R] :- coq.say "TODO wrapper" T F G, declare-wrappers.aux2 XS R. -declare-wrappers.aux2 [] []. +declare-wrappers.filter-lifted (w-params.cons ID T F) (w-params.cons ID T F1) :- + @pi-parameter ID T x\ declare-wrappers.filter-lifted (F x) (F1 x). +declare-wrappers.filter-lifted (w-params.nil ID T F) (w-params.nil ID T F1) :- + @pi-parameter ID T x\ declare-wrappers.filter-lifted.aux (F x) (F1 x). +declare-wrappers.filter-lifted.aux [factory-on-the-type _|XS] R :- declare-wrappers.filter-lifted.aux XS R. +declare-wrappers.filter-lifted.aux [factory-on-subject-lifter T F G|XS] [triple T F G|R] :- declare-wrappers.filter-lifted.aux XS R. +declare-wrappers.filter-lifted.aux [] []. + +declare-wrappers.filter-new (w-params.cons ID T F) (w-params.cons ID T F1) :- + @pi-parameter ID T x\ declare-wrappers.filter-new (F x) (F1 x). +declare-wrappers.filter-new (w-params.nil ID T F) (w-params.nil ID T F1) :- + @pi-parameter ID T x\ declare-wrappers.filter-new.aux (F x) (F1 x). +declare-wrappers.filter-new.aux [factory-on-the-type _|XS] R :- declare-wrappers.filter-new.aux XS R. +declare-wrappers.filter-new.aux [factory-on-subject-lifter _ F G|XS] R :- wrapper-mixin _ G F, !, declare-wrappers.filter-new.aux XS R. +declare-wrappers.filter-new.aux [factory-on-subject-lifter T F G|XS] [triple T F G|R] :- declare-wrappers.filter-new.aux XS R. +declare-wrappers.filter-new.aux [] []. + +pred wrap-deps i:gref, i:mixins, o:mixins. +wrap-deps OP (w-params.cons ID T F) (w-params.cons ID T F1) :- + @pi-parameter ID T x\ wrap-deps OP (F x) (F1 x). +wrap-deps OP (w-params.nil ID T F) (w-params.nil ID T F1) :- + @pi-parameter ID T x\ wrap-deps.mixins OP (F x) (F1 x). + +pred wrap-deps.mixins i:gref, i:list (w-args mixinname), o:list (w-args mixinname). +wrap-deps.mixins _ [] []. +wrap-deps.mixins OP [triple M P X|ML] [triple WM P X|ML1] :- + std.assert! (wrapper-mixin WM OP M) "no wrapper for the lifter on a dep", + wrap-deps.mixins OP ML ML1. pred declare-wrapper i:one-w-params (triple term gref gref), i:list prop, o:list prop. declare-wrapper F C0 C :- C0 => std.do! [ - coq.say "Missing" F, + %coq.say "Missing" F, missing-wrapper->record F RSkel OP M, %coq.say "Wrapper skel" RSkel, disable-id-phant-indt-decl RSkel RSkelNoId, std.assert-ok! (coq.elaborate-indt-decl-skeleton RSkelNoId RDeclNoId) "illtyped wrapper", re-enable-id-phant-indt-decl RDeclNoId RDecl, %coq.say "Record wrapper" RDecl, - expand-structures RDecl W' MLwP, + gref-deps M MDeps, + wrap-deps OP MDeps WrappedDeps, + expand-structures RDecl WrappedDeps W', %coq.say "Expanded record wrapper" W', %std.assert-ok! (coq.typecheck-indt-decl W) "illtyped wrapper record", - coq.say W', + coq.say "Wrapper:" W', std.assert-ok! (coq.elaborate-indt-decl-skeleton W' W) "illtyped wrapper record", - coq.say W, - std.spy(log.coq.env.add-indt W R), + %coq.say W, + log.coq.env.add-indt W R, coq.env.indt R tt _ _ _ [K] _, GRK = indc K, GR = indt R, coq.gref->id GR Name, + wrapper-deps F W MLwP, + %coq.say "W deps" MLwP, + w-params.nparams MLwP NParams, factory.private.build-deps-for-projections R MLwP GRDepsClausesProjs, GRDepsClauses = [ gref-deps GR MLwP, gref-deps (indc K) MLwP | GRDepsClausesProjs], @@ -778,34 +805,81 @@ pred missing-wrapper->record i:one-w-params (triple term gref gref), o:indt-decl missing-wrapper->record (w-params.cons ID T F) (parameter ID explicit T F1) OP M:- @pi-parameter ID T x\ missing-wrapper->record (F x) (F1 x) OP M. missing-wrapper->record (w-params.nil ID T F) (parameter ID explicit T F1) OP M:- - @pi-parameter ID T x\ missing-wrapper->record.aux (F x) (F1 x) OP M. -missing-wrapper->record.aux (triple (triple T M OP) _ _) - (record Name _ Bname (field [] Fname T (x\end-record))) OP M :- + @pi-parameter ID T x\ missing-wrapper->record.body (F x) (F1 x) OP M. + +pred unfold-phant i:term, o:term. +unfold-phant (app [global (const C)|A]) R :- + coq.env.const C (some B) _, + unwind {hd-beta B A} R. + +pred missing-wrapper->record.body i:w-args (triple term gref gref), o:indt-decl, o:gref, o:mixinname. +missing-wrapper->record.body (triple (triple T M OP) _ _) + (record Name _ Bname (field [] Fname T1 (x\end-record))) OP M :- std.do! [ + coq.safe-dest-app T (global PM) _, + if (not(PM = M)) % the term uses a _phant alias + (unfold-phant T T1) + (T1 = T), + Name is "wrapper_" ^ {std.any->string {new_int}} ^ "_" ^ {coq.gref->id OP} ^ "_" ^ {nice-gref->string M}, Fname is Name ^ "_private", - Bname is Name ^ "_build". + Bname is Name ^ "_build", +]. -pred expand-structures i:indt-decl, o:indt-decl, o:mixins. -expand-structures (parameter ID I T ((s\record _ _ _ _) as R)) (parameter ID I _ R1) ML :- !, std.do! [ +pred wrapper-deps i:one-w-params (triple term gref gref), i:indt-decl, o:mixins. +wrapper-deps (w-params.cons _ _ F) (parameter ID explicit T F1) (w-params.cons ID T ML) :- + @pi-parameter ID T x\ wrapper-deps (F x) (F1 x) (ML x). +wrapper-deps (w-params.nil _ _ _) (parameter ID explicit T F1) (w-params.nil ID T ML) :- + @pi-parameter ID T x\ wrapper-deps.aux (F1 x) x (ML x). +wrapper-deps.aux (parameter ID explicit T F1) X [triple M Params X|ML] :- + coq.safe-dest-app T Mixin ParamsXStuff, + coq.env.global M Mixin, + std.appendR Params [X|_] ParamsXStuff, + @pi-parameter ID T x\ wrapper-deps.aux (F1 x) X ML. +wrapper-deps.aux (record _ _ _ _) _ []. + +pred expand-structures i:indt-decl, i:mixins, o:indt-decl. +expand-structures(parameter ID I T F) Deps (parameter ID I T F1) :- + @pi-parameter ID T x\ expand-structures (F x) Deps (F1 x). +expand-structures (parameter ID I T ((s\record _ _ _ _) as R)) Deps (parameter ID I _ R1) :- !, std.do! [ coq.safe-dest-app T (global GR) Args, is-structure GR, class-def (class C GR ML), + coq.mk-n-holes {w-params.nparams Deps} Holes, get-constructor C K, get-constructor GR SK, - coq.mk-app (global K) Args KArgs, coq.mk-app (global SK) Args SKArgs, (@pi-decl `TheType` {{ Type }} x\ % TYPE is wrong apply-w-params ML Args x (F x), - expand-structures.aux (F x) {coq.mk-app SKArgs [x]} {coq.mk-app KArgs [x]} R (R1 x)), + apply-w-params Deps Holes x (DepsX x), + %toposort-mixins {std.append (F x) (DepsX x)} (MoreParams x), + expand-structures.aux (F x) (DepsX x) [] {coq.mk-app SKArgs [x]} K Args x R (R1 x)), ]. -expand-structures.aux [triple M PS X|MS] Pack Class R (parameter "m" explicit Ty R1) :- std.do! [ +expand-structures.aux [triple M PS X|MS] D ACC Pack K KA Subj R (parameter "m" explicit Ty R1) :- std.do! [ synthesis.infer-all-gref-deps PS X M Ty, (@pi-decl `m` Ty m\ mixin-src X M m => - expand-structures.aux MS Pack {coq.mk-app Class [m]} R (R1 m)), + expand-structures.aux MS D ACC Pack K KA Subj R (R1 m)), +]. +expand-structures.aux [] [triple M PS X|D] ACC Pack K KA Subj R (parameter "m" explicit Ty R1) :- std.do! [ + synthesis.infer-all-gref-deps PS X M Ty, + coq.safe-dest-app Ty _ Args, + M = indt I, + std.assert! (coq.env.projections I [some Priv]) "wrapper with no projection", + (@pi-decl `m` Ty m\ sigma PM\ + coq.mk-app (app [{coq.env.global (const Priv)}|Args]) [m] PM, + mixin-src X M m => unwrap-dep m PM => + expand-structures.aux [] D [m|ACC] Pack K KA Subj R (R1 m)), +]. +expand-structures.aux [] [] WrappedDepsRev Pack K KA Subj R R2 :- std.spy-do! [ + synthesis.infer-all-gref-deps KA Subj K Class, + R1 = R {coq.mk-app Pack [Class]}, + R1 = record N S NK (field FA FN T _\end-record), + R2 = record N S NK (field FA FN T1 _\end-record), + factory?-split T _ FParams LiftedSubject Deps, + std.assert! (std.forall Deps var) "wrapper: deps should be inferred, not given", + std.rev WrappedDepsRev WrappedDeps, + std.map WrappedDeps unwrap-dep ProjWrappedDeps, + coq.mk-app (app FParams) [LiftedSubject|ProjWrappedDeps] T1, ]. -expand-structures.aux [] Pack Class R R1 :- R1 = R {coq.mk-app Pack [Class]}. - -expand-structures(parameter ID I T F) (parameter ID I T F1) ML :- - @pi-parameter ID T x\ expand-structures (F x) (F1 x) ML. +pred unwrap-dep i:term, o:term. % M is the gref of the wrapper mixin. % C gets now instantiated to the projection, i.e. hom_isMon_private. diff --git a/theories/encatD.v b/theories/encatD.v index 581371d92..3527cb124 100644 --- a/theories/encatD.v +++ b/theories/encatD.v @@ -308,30 +308,19 @@ HB.structure Definition HPreCat : Set := (* The category based on the HQuiver (i.e. horizontal category on D0 objects) *) -(* Unset Universe Checking. -#[wrapper] -HB.mixin Record _IsHCat T of HPreCat T := { - is_hcat : PreCat_IsCat (transpose T) }. *) #[short(type="hcat"),unsafe(univ)] -HB.structure Definition HCat : Set := HERE: do not only read deps from transpose, but also from PreCat_IsCat... +HB.structure Definition HCat : Set := { C of HPreCat C & PreCat_IsCat (transpose C) }. -(*Set Universe Checking.*) - -x - + (** Vertical 2-cell level category (D1 category) *) (* Precategory based on the DQuiver (i.e. precategory D1). Gives: vertical 2-cell identity morphism. vertical 2-cell composition. *) -Unset Universe Checking. -#[wrapper] -HB.mixin Record _IsD1PreCat T of DQuiver T := { - is_d1precat : Quiver_IsPreCat (@D1obj T) }. -#[short(type="d1precat")] + HB.status. +#[short(type="d1precat"),unsafe(univ)] HB.structure Definition D1PreCat : Set := - { C of Quiver_IsPreCat (@D1obj C) }. -Set Universe Checking. + { C of Quiver_IsPreCat (D1obj C) }. (* The category based on the DQuiver (i.e. category D1). *) Unset Universe Checking. From 10b3fb0fe04272723fcbe3bb6a8dbebfa04da457 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Mon, 4 Mar 2024 15:23:08 +0100 Subject: [PATCH 144/147] wip --- HB/structure.elpi | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/HB/structure.elpi b/HB/structure.elpi index ff2a762dc..b658c9e76 100644 --- a/HB/structure.elpi +++ b/HB/structure.elpi @@ -711,28 +711,18 @@ lift-to-the-subject.aux [factory-on-subject-lifter Expr _ _|_] _ _ :- pred declare-wrappers i:term, o:list prop. declare-wrappers B C :- std.do! [ private.sigT->list-w-params B X _, - declare-wrappers.filter-lifted X FWrappers, - distribute-w-params FWrappers FWrappersWP, - factories-provide FWrappersWP WrappersWP, - declare-wrappers.filter-new WrappersWP NewWrappersWP, - std.fold NewWrappersWP [] declare-wrapper C, + declare-wrappers.aux X Wrappers, + distribute-w-params Wrappers WrappersWP, + std.fold WrappersWP [] declare-wrapper C, ]. -declare-wrappers.filter-lifted (w-params.cons ID T F) (w-params.cons ID T F1) :- - @pi-parameter ID T x\ declare-wrappers.filter-lifted (F x) (F1 x). -declare-wrappers.filter-lifted (w-params.nil ID T F) (w-params.nil ID T F1) :- - @pi-parameter ID T x\ declare-wrappers.filter-lifted.aux (F x) (F1 x). -declare-wrappers.filter-lifted.aux [factory-on-the-type _|XS] R :- declare-wrappers.filter-lifted.aux XS R. -declare-wrappers.filter-lifted.aux [factory-on-subject-lifter T F G|XS] [triple T F G|R] :- declare-wrappers.filter-lifted.aux XS R. -declare-wrappers.filter-lifted.aux [] []. - -declare-wrappers.filter-new (w-params.cons ID T F) (w-params.cons ID T F1) :- - @pi-parameter ID T x\ declare-wrappers.filter-new (F x) (F1 x). -declare-wrappers.filter-new (w-params.nil ID T F) (w-params.nil ID T F1) :- - @pi-parameter ID T x\ declare-wrappers.filter-new.aux (F x) (F1 x). -declare-wrappers.filter-new.aux [factory-on-the-type _|XS] R :- declare-wrappers.filter-new.aux XS R. -declare-wrappers.filter-new.aux [factory-on-subject-lifter _ F G|XS] R :- wrapper-mixin _ G F, !, declare-wrappers.filter-new.aux XS R. -declare-wrappers.filter-new.aux [factory-on-subject-lifter T F G|XS] [triple T F G|R] :- declare-wrappers.filter-new.aux XS R. -declare-wrappers.filter-new.aux [] []. +declare-wrappers.aux (w-params.cons ID T F) (w-params.cons ID T F1) :- + @pi-parameter ID T x\ declare-wrappers.aux (F x) (F1 x). +declare-wrappers.aux (w-params.nil ID T F) (w-params.nil ID T F1) :- + @pi-parameter ID T x\ declare-wrappers.aux2 (F x) (F1 x). +declare-wrappers.aux2 [factory-on-the-type _|XS] R :- declare-wrappers.aux2 XS R. +declare-wrappers.aux2 [factory-on-subject-lifter _ F G|XS] R :- wrapper-mixin _ G F, !, declare-wrappers.aux2 XS R. +declare-wrappers.aux2 [factory-on-subject-lifter T F G|XS] [triple (triple T F G) _ _|R] :-coq.say "TODO wrapper" T F G, declare-wrappers.aux2 XS R. +declare-wrappers.aux2 [] []. pred wrap-deps i:gref, i:mixins, o:mixins. wrap-deps OP (w-params.cons ID T F) (w-params.cons ID T F1) :- From af2989f09f12297d6de6371b0caae1051942a759 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Mon, 4 Mar 2024 17:48:40 +0100 Subject: [PATCH 145/147] wip --- HB/common/phant-abbreviation.elpi | 8 ++++- HB/common/synthesis.elpi | 1 + HB/common/utils.elpi | 2 +- HB/structure.elpi | 60 +++++++++++++++++-------------- theories/encatD.v | 4 +-- 5 files changed, 45 insertions(+), 30 deletions(-) diff --git a/HB/common/phant-abbreviation.elpi b/HB/common/phant-abbreviation.elpi index 943c30c74..63ef25731 100644 --- a/HB/common/phant-abbreviation.elpi +++ b/HB/common/phant-abbreviation.elpi @@ -20,13 +20,19 @@ namespace phant { % term T and an abbreviation Name as per Ph. % Use the API below to build a PhT as you like. pred add-abbreviation i:string, i:phant-term, o:constant, o:abbreviation. -add-abbreviation N (private.phant-term AL T1) C Abbrev :- std.do! [ +add-abbreviation N (private.phant-term AL T1) C Abbrev :- std.spy-do! [ NC is "phant_" ^ N, std.assert-ok! (coq.elaborate-skeleton T1 TTy T) "add-abbreviation: T illtyped", log.coq.env.add-const-noimplicits NC T TTy @transparent! C, private.build-abbreviation 0 (global (const C)) AL NParams AbbrevT, @global! => log.coq.notation.add-abbreviation N NParams AbbrevT tt Abbrev, ]. +pred add-abbreviation2 i:gref, i:string, i:phant-term, o:constant, o:abbreviation. +add-abbreviation2 GR N (private.phant-term _ _) C Abbrev :- std.do! [ + NC is "phant_" ^ N, + log.coq.env.add-const-noimplicits NC (global GR) _ @transparent! C, + @global! => log.coq.notation.add-abbreviation N 0 (global (const C)) tt Abbrev, +]. % [of-gref WithCopy GR RealMixinArgs PT] % builds a phant-term taking all parameters, diff --git a/HB/common/synthesis.elpi b/HB/common/synthesis.elpi index 055a4fc1c..cced84833 100644 --- a/HB/common/synthesis.elpi +++ b/HB/common/synthesis.elpi @@ -260,6 +260,7 @@ instantiate-all-these-mixin-args (fun _ Tm F) T ML R :- coq.safe-dest-app Tm (global TmGR) _, factory-alias->gref TmGR M, std.mem! ML M, + factory? Tm (triple _ _ Subj), Subj = T, % check the subject is T (do not pass T to factory?) !, mixin-for T M X, !, instantiate-all-these-mixin-args (F X) T ML R. diff --git a/HB/common/utils.elpi b/HB/common/utils.elpi index 02e8f7a33..de4cad12f 100644 --- a/HB/common/utils.elpi +++ b/HB/common/utils.elpi @@ -293,7 +293,7 @@ pack? (indc K) C :- coq.env.indc K _ _ _ KTy, prod-last-gref KTy (indt I), % TODO: use new API class-def (class C (indt I) _). -pred distribute-w-params i:list-w-params A, o:list (one-w-params A). +pred distribute-w-params i:w-params (list A), o:list (w-params A). distribute-w-params (w-params.cons N T F) L :- pi x\ distribute-w-params (F x) (L1 x), std.map (L1 x) (bind-cons N T x) L. distribute-w-params (w-params.nil N T F) L :- diff --git a/HB/structure.elpi b/HB/structure.elpi index b658c9e76..d135ede49 100644 --- a/HB/structure.elpi +++ b/HB/structure.elpi @@ -688,6 +688,7 @@ sigT->list-w-params {{ lib:@hb.sigT _ lp:{{ fun N Ty B }} }} L C :- @pi-decl N Ty t\ product->triples (B t) t (Rest t) C. +%TODO expand factories in lift pred lift-to-the-subject i:w-params (list factory-on-subject), o:list-w-params factoryname. lift-to-the-subject (w-params.cons ID T Rest) (w-params.cons ID T Rest1) :- @pi-parameter ID T x\ @@ -711,18 +712,27 @@ lift-to-the-subject.aux [factory-on-subject-lifter Expr _ _|_] _ _ :- pred declare-wrappers i:term, o:list prop. declare-wrappers B C :- std.do! [ private.sigT->list-w-params B X _, - declare-wrappers.aux X Wrappers, - distribute-w-params Wrappers WrappersWP, + declare-wrappers.filter-lifted X Wrappers, + w-params.map Wrappers (_\_\std.flatten) Wrappers1, + distribute-w-params Wrappers1 WrappersWP, std.fold WrappersWP [] declare-wrapper C, ]. -declare-wrappers.aux (w-params.cons ID T F) (w-params.cons ID T F1) :- - @pi-parameter ID T x\ declare-wrappers.aux (F x) (F1 x). -declare-wrappers.aux (w-params.nil ID T F) (w-params.nil ID T F1) :- - @pi-parameter ID T x\ declare-wrappers.aux2 (F x) (F1 x). -declare-wrappers.aux2 [factory-on-the-type _|XS] R :- declare-wrappers.aux2 XS R. -declare-wrappers.aux2 [factory-on-subject-lifter _ F G|XS] R :- wrapper-mixin _ G F, !, declare-wrappers.aux2 XS R. -declare-wrappers.aux2 [factory-on-subject-lifter T F G|XS] [triple (triple T F G) _ _|R] :-coq.say "TODO wrapper" T F G, declare-wrappers.aux2 XS R. -declare-wrappers.aux2 [] []. +pred declare-wrappers.filter-lifted i:w-params (list factory-on-subject), o:w-params (list (list (pair gref (w-args mixinname)))). +declare-wrappers.filter-lifted (w-params.cons ID T F) (w-params.cons ID T F1) :- + @pi-parameter ID T x\ declare-wrappers.filter-lifted (F x) (F1 x). +declare-wrappers.filter-lifted (w-params.nil ID T F) (w-params.nil ID T F1) :- + @pi-parameter ID T x\ declare-wrappers.filter-lifted.aux (F x) (F1 x). +declare-wrappers.filter-lifted.aux [factory-on-the-type _|XS] R :- declare-wrappers.filter-lifted.aux XS R. +declare-wrappers.filter-lifted.aux [factory-on-subject-lifter T F G|XS] [WL|R] :- + factory? T (triple _ Params S), + factory-provides F MLwP, + apply-w-params MLwP Params S Triples, + std.map-filter Triples (declare-wrappers.filter-new G) WL, + declare-wrappers.filter-lifted.aux XS R. +declare-wrappers.filter-lifted.aux [] []. + +pred declare-wrappers.filter-new i:gref, i:w-args mixinname, o:pair gref (w-args mixinname). +declare-wrappers.filter-new G (triple F _ _ as T) (pr G T) :- not (wrapper-mixin _ G F). pred wrap-deps i:gref, i:mixins, o:mixins. wrap-deps OP (w-params.cons ID T F) (w-params.cons ID T F1) :- @@ -736,11 +746,11 @@ wrap-deps.mixins OP [triple M P X|ML] [triple WM P X|ML1] :- std.assert! (wrapper-mixin WM OP M) "no wrapper for the lifter on a dep", wrap-deps.mixins OP ML ML1. -pred declare-wrapper i:one-w-params (triple term gref gref), i:list prop, o:list prop. +pred declare-wrapper i:w-params (pair gref (w-args mixinname)), i:list prop, o:list prop. declare-wrapper F C0 C :- C0 => std.do! [ %coq.say "Missing" F, missing-wrapper->record F RSkel OP M, - %coq.say "Wrapper skel" RSkel, + coq.say "Wrapper skel" RSkel, disable-id-phant-indt-decl RSkel RSkelNoId, std.assert-ok! (coq.elaborate-indt-decl-skeleton RSkelNoId RDeclNoId) "illtyped wrapper", re-enable-id-phant-indt-decl RDeclNoId RDecl, @@ -761,7 +771,7 @@ declare-wrapper F C0 C :- C0 => std.do! [ coq.gref->id GR Name, wrapper-deps F W MLwP, - %coq.say "W deps" MLwP, + coq.say "W deps" MLwP, w-params.nparams MLwP NParams, factory.private.build-deps-for-projections R MLwP GRDepsClausesProjs, @@ -788,10 +798,10 @@ declare-wrapper F C0 C :- C0 => std.do! [ GRDepsClauses, ] C, %factory-builder-nparams BuildConst NParams, - + coq.say "Wrapper DONE", ]. -pred missing-wrapper->record i:one-w-params (triple term gref gref), o:indt-decl, o:gref, o:mixinname. +pred missing-wrapper->record i:w-params (pair gref (w-args mixinname)), o:indt-decl, o:gref, o:mixinname. missing-wrapper->record (w-params.cons ID T F) (parameter ID explicit T F1) OP M:- @pi-parameter ID T x\ missing-wrapper->record (F x) (F1 x) OP M. missing-wrapper->record (w-params.nil ID T F) (parameter ID explicit T F1) OP M:- @@ -802,20 +812,17 @@ unfold-phant (app [global (const C)|A]) R :- coq.env.const C (some B) _, unwind {hd-beta B A} R. -pred missing-wrapper->record.body i:w-args (triple term gref gref), o:indt-decl, o:gref, o:mixinname. -missing-wrapper->record.body (triple (triple T M OP) _ _) - (record Name _ Bname (field [] Fname T1 (x\end-record))) OP M :- std.do! [ - coq.safe-dest-app T (global PM) _, - if (not(PM = M)) % the term uses a _phant alias - (unfold-phant T T1) - (T1 = T), +pred missing-wrapper->record.body i:pair gref (w-args mixinname), o:indt-decl, o:gref, o:mixinname. +missing-wrapper->record.body (pr OP (triple M Params Subject)) + (record Name _ Bname (field [] Fname T (x\end-record))) OP M :- std.do! [ + coq.mk-app {coq.env.global M} {std.append Params [Subject]} T, Name is "wrapper_" ^ {std.any->string {new_int}} ^ "_" ^ {coq.gref->id OP} ^ "_" ^ {nice-gref->string M}, Fname is Name ^ "_private", Bname is Name ^ "_build", ]. -pred wrapper-deps i:one-w-params (triple term gref gref), i:indt-decl, o:mixins. +pred wrapper-deps i:w-params (pair gref (w-args gref)), i:indt-decl, o:mixins. wrapper-deps (w-params.cons _ _ F) (parameter ID explicit T F1) (w-params.cons ID T ML) :- @pi-parameter ID T x\ wrapper-deps (F x) (F1 x) (ML x). wrapper-deps (w-params.nil _ _ _) (parameter ID explicit T F1) (w-params.nil ID T ML) :- @@ -857,13 +864,14 @@ expand-structures.aux [] [triple M PS X|D] ACC Pack K KA Subj R (parameter "m" mixin-src X M m => unwrap-dep m PM => expand-structures.aux [] D [m|ACC] Pack K KA Subj R (R1 m)), ]. -expand-structures.aux [] [] WrappedDepsRev Pack K KA Subj R R2 :- std.spy-do! [ +expand-structures.aux [] [] WrappedDepsRev Pack K KA Subj R R2 :- std.do! [ synthesis.infer-all-gref-deps KA Subj K Class, R1 = R {coq.mk-app Pack [Class]}, R1 = record N S NK (field FA FN T _\end-record), R2 = record N S NK (field FA FN T1 _\end-record), - factory?-split T _ FParams LiftedSubject Deps, - std.assert! (std.forall Deps var) "wrapper: deps should be inferred, not given", + factory?-split T _ FParams LiftedSubject _Deps, + %std.assert! (std.forall Deps var) "wrapper: deps should be inferred, not given", + %CONVOLUTED std.rev WrappedDepsRev WrappedDeps, std.map WrappedDeps unwrap-dep ProjWrappedDeps, coq.mk-app (app FParams) [LiftedSubject|ProjWrappedDeps] T1, diff --git a/theories/encatD.v b/theories/encatD.v index 3527cb124..dd5c2d7eb 100644 --- a/theories/encatD.v +++ b/theories/encatD.v @@ -296,7 +296,7 @@ HB.tag Definition D1obj (C: vhquiver) := Total2 (@hhom C). (* D1 quiver requirement (includes D0 quiver and its transpose). *) #[short(type="dquiver"),unsafe(univ)] -HB.structure Definition DQuiver : Set := { C of Quiver (D1obj C) }. +HB.structure Definition DQuiver : Set := { C of IsQuiver (D1obj C) }. (** Horizonal D0-level category (H-D0) *) @@ -304,7 +304,7 @@ HB.structure Definition DQuiver : Set := { C of Quiver (D1obj C) }. objects) *) #[short(type="hprecat"),unsafe(univ)] HB.structure Definition HPreCat : Set := - { C of Quiver_IsPreCat (transpose C) }. + { C of Quiver_IsPreCat (transpose C) }. MISSING DEPS (* The category based on the HQuiver (i.e. horizontal category on D0 objects) *) From 0cf1c4c8fc90c52085563773b111e862a6215d77 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Mon, 4 Mar 2024 21:06:34 +0100 Subject: [PATCH 146/147] wip --- HB/structure.elpi | 11 ++++------- theories/encatD.v | 2 +- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/HB/structure.elpi b/HB/structure.elpi index d135ede49..fe1cbb088 100644 --- a/HB/structure.elpi +++ b/HB/structure.elpi @@ -861,24 +861,21 @@ expand-structures.aux [] [triple M PS X|D] ACC Pack K KA Subj R (parameter "m" std.assert! (coq.env.projections I [some Priv]) "wrapper with no projection", (@pi-decl `m` Ty m\ sigma PM\ coq.mk-app (app [{coq.env.global (const Priv)}|Args]) [m] PM, - mixin-src X M m => unwrap-dep m PM => - expand-structures.aux [] D [m|ACC] Pack K KA Subj R (R1 m)), + mixin-src X M m => + expand-structures.aux [] D [PM|ACC] Pack K KA Subj R (R1 m)), ]. expand-structures.aux [] [] WrappedDepsRev Pack K KA Subj R R2 :- std.do! [ synthesis.infer-all-gref-deps KA Subj K Class, R1 = R {coq.mk-app Pack [Class]}, R1 = record N S NK (field FA FN T _\end-record), R2 = record N S NK (field FA FN T1 _\end-record), - factory?-split T _ FParams LiftedSubject _Deps, + factory? T (triple F Params LiftedSubject), %std.assert! (std.forall Deps var) "wrapper: deps should be inferred, not given", %CONVOLUTED std.rev WrappedDepsRev WrappedDeps, - std.map WrappedDeps unwrap-dep ProjWrappedDeps, - coq.mk-app (app FParams) [LiftedSubject|ProjWrappedDeps] T1, + coq.mk-app (app [global F|Params]) [LiftedSubject|WrappedDeps] T1, ]. -pred unwrap-dep i:term, o:term. - % M is the gref of the wrapper mixin. % C gets now instantiated to the projection, i.e. hom_isMon_private. % we need to count the parameters, we can get that from the type. diff --git a/theories/encatD.v b/theories/encatD.v index dd5c2d7eb..248db9882 100644 --- a/theories/encatD.v +++ b/theories/encatD.v @@ -304,7 +304,7 @@ HB.structure Definition DQuiver : Set := { C of IsQuiver (D1obj C) }. objects) *) #[short(type="hprecat"),unsafe(univ)] HB.structure Definition HPreCat : Set := - { C of Quiver_IsPreCat (transpose C) }. MISSING DEPS + { C of Quiver_IsPreCat (transpose C) }. MISSING DEPS, wrapper drops phants (* The category based on the HQuiver (i.e. horizontal category on D0 objects) *) From e85441c77497dcd7310a6f6048db0b22049cb8d7 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Mon, 4 Mar 2024 22:26:17 +0100 Subject: [PATCH 147/147] wip --- HB/common/phant-abbreviation.elpi | 2 +- HB/structure.elpi | 25 +++++++++++++------------ theories/encatD.v | 3 ++- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/HB/common/phant-abbreviation.elpi b/HB/common/phant-abbreviation.elpi index 63ef25731..e2451a6d8 100644 --- a/HB/common/phant-abbreviation.elpi +++ b/HB/common/phant-abbreviation.elpi @@ -20,7 +20,7 @@ namespace phant { % term T and an abbreviation Name as per Ph. % Use the API below to build a PhT as you like. pred add-abbreviation i:string, i:phant-term, o:constant, o:abbreviation. -add-abbreviation N (private.phant-term AL T1) C Abbrev :- std.spy-do! [ +add-abbreviation N (private.phant-term AL T1) C Abbrev :- std.do! [ NC is "phant_" ^ N, std.assert-ok! (coq.elaborate-skeleton T1 TTy T) "add-abbreviation: T illtyped", log.coq.env.add-const-noimplicits NC T TTy @transparent! C, diff --git a/HB/structure.elpi b/HB/structure.elpi index fe1cbb088..98733af3e 100644 --- a/HB/structure.elpi +++ b/HB/structure.elpi @@ -670,7 +670,7 @@ product->triples {{ lib:hb.prod lp:A lp:B }} T L ClosureCheck :- !, std.append GRA GRB L. product->triples {{ True }} _ [] tt :- !. product->triples {{ False }} _ [] ff :- !. -product->triples A T [factory-on-the-type F] tt :- factory? A F, F = triple _ _ T, !. +product->triples A T [factory-on-the-type F] tt :- (factory? A F), (F = triple _ _ T), !. product->triples A _ [factory-on-subject-lifter A F OP] tt :- factory-on-some-structure-op? A [] F OP, !. product->triples A T _ _ :- coq.error "HB: expecting a factory on" {coq.term->string T} @@ -750,17 +750,17 @@ pred declare-wrapper i:w-params (pair gref (w-args mixinname)), i:list prop, o:l declare-wrapper F C0 C :- C0 => std.do! [ %coq.say "Missing" F, missing-wrapper->record F RSkel OP M, - coq.say "Wrapper skel" RSkel, - disable-id-phant-indt-decl RSkel RSkelNoId, - std.assert-ok! (coq.elaborate-indt-decl-skeleton RSkelNoId RDeclNoId) "illtyped wrapper", - re-enable-id-phant-indt-decl RDeclNoId RDecl, + %coq.say "Wrapper skel" F "=" RSkel, + %disable-id-phant-indt-decl RSkel RSkelNoId, + %std.assert-ok! (coq.elaborate-indt-decl-skeleton RSkelNoId RDeclNoId) "illtyped wrapper", + %re-enable-id-phant-indt-decl RDeclNoId RDecl, %coq.say "Record wrapper" RDecl, gref-deps M MDeps, wrap-deps OP MDeps WrappedDeps, - expand-structures RDecl WrappedDeps W', + ((pi X Y L\ copy X Y :- var X _ L, prune Y L) => copy-indt-decl RSkel RSkel'), std.spy(expand-structures RSkel' WrappedDeps W'), %coq.say "Expanded record wrapper" W', %std.assert-ok! (coq.typecheck-indt-decl W) "illtyped wrapper record", - coq.say "Wrapper:" W', + coq.say "Wrapper for" OP "and" M "is" W', std.assert-ok! (coq.elaborate-indt-decl-skeleton W' W) "illtyped wrapper record", %coq.say W, log.coq.env.add-indt W R, @@ -771,7 +771,7 @@ declare-wrapper F C0 C :- C0 => std.do! [ coq.gref->id GR Name, wrapper-deps F W MLwP, - coq.say "W deps" MLwP, + %coq.say "W deps" F "=" MLwP, w-params.nparams MLwP NParams, factory.private.build-deps-for-projections R MLwP GRDepsClausesProjs, @@ -798,7 +798,7 @@ declare-wrapper F C0 C :- C0 => std.do! [ GRDepsClauses, ] C, %factory-builder-nparams BuildConst NParams, - coq.say "Wrapper DONE", + coq.say "Wrapper DONE" F, ]. pred missing-wrapper->record i:w-params (pair gref (w-args mixinname)), o:indt-decl, o:gref, o:mixinname. @@ -835,9 +835,8 @@ wrapper-deps.aux (parameter ID explicit T F1) X [triple M Params X|ML] :- wrapper-deps.aux (record _ _ _ _) _ []. pred expand-structures i:indt-decl, i:mixins, o:indt-decl. -expand-structures(parameter ID I T F) Deps (parameter ID I T F1) :- - @pi-parameter ID T x\ expand-structures (F x) Deps (F1 x). -expand-structures (parameter ID I T ((s\record _ _ _ _) as R)) Deps (parameter ID I _ R1) :- !, std.do! [ +expand-structures (parameter ID I T ((s\record _ _ _ (field _ _ (X s) _\end-record)) as R)) Deps (parameter ID I _ R1) :- !, std.spy-do! [ + (@pi-decl `TheType` T x\ std.assert-ok! (coq.typecheck (X x) (Ty_ x)) "illtyped subject"), coq.safe-dest-app T (global GR) Args, is-structure GR, class-def (class C GR ML), coq.mk-n-holes {w-params.nparams Deps} Holes, get-constructor C K, @@ -849,6 +848,8 @@ expand-structures (parameter ID I T ((s\record _ _ _ _) as R)) Deps (parameter I %toposort-mixins {std.append (F x) (DepsX x)} (MoreParams x), expand-structures.aux (F x) (DepsX x) [] {coq.mk-app SKArgs [x]} K Args x R (R1 x)), ]. +expand-structures(parameter ID I T F) Deps (parameter ID I T F1) :- + @pi-parameter ID T x\ expand-structures (F x) Deps (F1 x). expand-structures.aux [triple M PS X|MS] D ACC Pack K KA Subj R (parameter "m" explicit Ty R1) :- std.do! [ synthesis.infer-all-gref-deps PS X M Ty, (@pi-decl `m` Ty m\ mixin-src X M m => diff --git a/theories/encatD.v b/theories/encatD.v index 248db9882..2ad0c7d4b 100644 --- a/theories/encatD.v +++ b/theories/encatD.v @@ -304,7 +304,7 @@ HB.structure Definition DQuiver : Set := { C of IsQuiver (D1obj C) }. objects) *) #[short(type="hprecat"),unsafe(univ)] HB.structure Definition HPreCat : Set := - { C of Quiver_IsPreCat (transpose C) }. MISSING DEPS, wrapper drops phants + { C of Quiver_IsPreCat (transpose C) }. (* The category based on the HQuiver (i.e. horizontal category on D0 objects) *) @@ -322,6 +322,7 @@ HB.structure Definition HCat : Set := HB.structure Definition D1PreCat : Set := { C of Quiver_IsPreCat (D1obj C) }. +x (* The category based on the DQuiver (i.e. category D1). *) Unset Universe Checking. #[wrapper]