\import Equiv
\import Category
\import Category.SubcatPred
\import Equiv.Sigma
\import Homotopy.Fibration
\import Function.Meta
\import Homotopy.Truncation
\import InfCat.Arrows
\import InfCat.Basics
\import InfCat.CatPushout
\import InfCat.Functor.Equiv
\import InfCat.Functor.Embedding
\import InfCat.Functor.FullyFaithful
\import InfCat.HoCat
\import InfCat.Interval
\import InfCat.Nerve.Nerve
\import InfCat.Nerve.NerveAdjunction
\import InfCat.Nerve.NerveEmbedding
\import InfCat.OFS.CatAccessibleOFS
\import InfCat.OFS.CatOFS
\import InfCat.Square
\import Logic
\import Logic.Meta
\import Logic.Unique
\import Paths
\import Paths.Meta
\type IsCompClosed {C : \Cat} (P : (DI ->⁺ C) -> \Prop) : \Prop
=> \Sigma (Pid : \Pi {h : DI ->⁺ C} -> P h -> \Sigma (P (idd {C} {h dleft})) (P (idd {C} {h dright})))
(Pc : \Pi {x y z : C} {f : x ~> y} {g : y ~> z} -> P f -> P g -> P (comp f g))
\func IsWideSubset {C : \Cat} (P : (DI ->⁺ C) -> \Prop) : \Prop
=> \Sigma (\Pi (x : C) -> P (idd {C} {x}))
(\Pi {x y z : C} {f : x ~> y} {g : y ~> z} -> P f -> P g -> P (comp f g))
\where
\lemma isCompClosed (w : IsWideSubset P) : IsCompClosed P
=> (\lam {h : DI ->⁺ C} _ => (w.1 (h dleft), w.1 (h dright)), w.2)
-- | The subcategory of {C} generated by the arrows satisfying {P}.
\type SubCat {C : \Cat} (P : (DI ->⁺ C) -> \Prop) : \Cat
=> CatFactor {_} {Arrows P} {C} evalArr
\where {
\protected \instance family : CatFactor.Family
| J => \Sigma
| X _ => CatPushout {Empty} {DI} {DI} absurd+ absurd+
| Y _ => DI
| F _ => codiag absurd+
\protected \lemma family-emb {C D : \Cat} {f : C ->⁺ D} : family.IsRight f <-> IsEmbedding f
=> (\lam r => embedding-orthogonal.2 (r ()), \lam fe () => embedding-orthogonal.1 fe)
\where {
-- | A functor is an embedding if and only if it is right orthogonal to the fold map `DI ⊔ DI -> DI`.
\lemma embedding-orthogonal {C D : \Cat} {f : C ->⁺ D} : IsEmbedding f <-> IsOrthogonal (codiag {Empty} {DI} absurd+) f
=> IsEmbedding.diag-equiv `<->trans` post-DI-equiv `<->trans` <->sym IsOrthogonal-fold
-- | {f} is right orthogonal to the fold map `X ⊔ X -> X` if and only if postcomposition with its diagonal is an equivalence on functors from {X}.
\lemma IsOrthogonal-fold {X C D : \Cat} {f : C ->⁺ D}
: IsOrthogonal (codiag {Empty} {X} absurd+) f <-> IsEquiv {X ->⁺ C} {X ->⁺ \Sigma⁺ (x y : C) (f x = f y)} (\lam h x => IsEmbedding.diag f (h x))
=> \have p => IsEquiv.parallelEquiv (inP idEquiv)
(IsEquiv.trans (inP IsOrthogonal-sections.squares-equiv) $
IsEquiv.trans (inP (sigma-right \lam (v : X ->⁺ D) => empty-pushout-equiv {X} {X} {\lam z =>⁺ \Sigma⁺ (c : C) (f c = v (codiag absurd+ z))}))
(lifts-equiv f))
(\lam h => idp)
\in (\lam o => p.1 o, \lam e => p.2 e)
\where {
-- | Two lifts of the same functor to {D} give a functor to the domain of the diagonal of {f}.
\func lifts-map {X C D : \Cat} (f : C ->⁺ D)
(s : \Sigma (v : X ->⁺ D) (\Sigma (\Pi (x :⁺ X) -> \Sigma⁺ (c : C) (f c = v x)) (\Pi (x :⁺ X) -> \Sigma⁺ (c : C) (f c = v x))))
: X ->⁺ \Sigma⁺ (x y : C) (f x = f y)
=> \lam x => ((s.2.1 x).1, (s.2.2 x).1, (s.2.1 x).2 *> inv (s.2.2 x).2)
\func lifts-ret {X C D : \Cat} (f : C ->⁺ D) (k : X ->⁺ \Sigma⁺ (x y : C) (f x = f y))
: \Sigma (v : X ->⁺ D) (\Sigma (\Pi (x :⁺ X) -> \Sigma⁺ (c : C) (f c = v x)) (\Pi (x :⁺ X) -> \Sigma⁺ (c : C) (f c = v x)))
=> (\lam x => f (k x).1, (\lam x => ((k x).1, idp), \lam x => ((k x).2, inv (k x).3)))
\lemma lifts-equiv {X C D : \Cat} (f : C ->⁺ D) : IsEquiv (lifts-map {X} f)
=> inP \new QEquiv {
| ret => lifts-ret f
| ret_f s => contract f (\lam x => (s.2.1 x).1) (path \lam i x => (s.2.1 x).2 i) s.2.2
| f_sec k => path \lam j x => ((k x).1, (k x).2, (idp_*> *> inv_inv {_} {_} {_} {(k x).3}) j)
}
\func contract {X C D : \Cat} (f : C ->⁺ D) (a : X ->⁺ C) {v : X ->⁺ D} (q : (\lam x =>⁺ f (a x)) = v)
(b : \Pi (x :⁺ X) -> \Sigma⁺ (c : C) (f c = v x))
: lifts-ret f (lifts-map f (v, (\lam x => (a x, path \lam i => q i x), b))) = (v, (\lam x => (a x, path \lam i => q i x), b)) \elim q
| idp => path \lam j => (\lam x => f (a x), (\lam x => (a x, idp), \lam x => ((b x).1, inv-cancel (b x).2 j)))
\private \func inv-cancel {A :⁺ \Cat} {a a' :⁺ A} (p :⁺ a = a') : inv (idp *> inv p) = p \elim p
| idp => idp
}
}
-- | Arrows of {C} satisfying {P}, freely as a category.
\data Arrows {C : \Cat} (P : (DI ->⁺ C) -> \Prop)
| arr (h : DI ->⁺ C) (Ph : P h) (i :⁺ DI)
\func evalArr {C : \Cat} {P : (DI ->⁺ C) -> \Prop} (a :⁺ Arrows P) : C \elim a
| arr h _ i => h i
\func inc (d :⁺ SubCat P) : C
=> catFactorRight d
\lemma inc-con.{u} {C : \Cat u} {P : (DI ->⁺ C) -> \Prop} (Pc : IsCompClosed P)
{d : DI ->⁺ SubCat P} : P (\lam i => inc {C} {P} (d i))
=> HoCat-left (\lam ge => IsOrthogonal_o-left (catFactorLeft.isLeft (family-emb.2 ge)) $
IsOrthogonal_IsHEquiv-left $ inP \new HQEquiv {CatFactor evalArr} {SubCat P} {
| f d => d
| finv d => d
| finv_f d => idp
| f_finv d => idp
})
(SubcatPred.pullback (HoCat-map \lam x => inc {C} {P} x) (PSub Pc))
(\lam {a} {a'} h => \case \elim a, \elim a', \elim h \with {
| in1 a, in1 a', HoCat.mkHom k => evalArr-con Pc.1 {\lam i => k i}
})
{in1 (d dleft)} {in1 (d dright)} (HoCat.mkHom (dpath \lam i => d i))
\where \private {
-- | Arrows of the homotopy category of {C} which are classes of arrows satisfying {P}.
\func PH.{v} {C : \Cat v} {P : (DI ->⁺ C) -> \Prop} {X Y : Trunc1 C} (h : HoCat.Hom X Y) : \Prop \elim X, Y, h
| in1 x, in1 y, HoCat.mkHom f => P f
-- | The subcategory of the homotopy category of {C} spanned by the arrows satisfying {P}.
\func PSub.{v} {C : \Cat v} {P : (DI ->⁺ C) -> \Prop} (Pc : IsCompClosed P)
: SubcatPred (HoCat C) \cowith
| ob X => PH {C} {P} (id {HoCat C} {X})
| hom h => PH {C} {P} h
| hom-dom {X} {Y} {h} => \case \elim X, \elim Y, \elim h \with {
| in1 x, in1 y, HoCat.mkHom f => \lam p => (Pc.1 p).1
}
| hom-cod {X} {Y} {h} => \case \elim X, \elim Y, \elim h \with {
| in1 x, in1 y, HoCat.mkHom f => \lam p => (Pc.1 p).2
}
| ob-id o => o
| hom-o {X} {Y} {Z} {g} {f} => \case \elim X, \elim Y, \elim Z, \elim g, \elim f \with {
| in1 x, in1 y, in1 z, HoCat.mkHom g, HoCat.mkHom f => \lam pg pf => Pc.2 pf pg
}
-- | Arrows of {Arrows} are mapped to arrows satisfying {P}.
\lemma evalArr-con.{v} {C : \Cat v} {P : (DI ->⁺ C) -> \Prop}
(Pid : \Pi {h : DI ->⁺ C} -> P h -> \Sigma (P (idd {C} {h dleft})) (P (idd {C} {h dright})))
{k : DI ->⁺ Arrows P} : P (\lam i => evalArr (k i))
=> \let | d0 => arrData (k dleft)
| e : (\lam i => evalArr (k i)) = {DI ->⁺ C} (\lam i => d0.1 (arrPos (k i)))
=> ext (\lam i => evalArr-split (k i)) *> pmap (\lam (G : DI ->⁺ \Sigma (h : DI ->⁺ C) (P h)) (i :⁺ DI) => (G i).1 (arrPos (k i))) (DI-const (dmap arrData (dpath \lam i => k i)))
\in transportInv P e (restrict-con Pid d0.2 (dpath \lam i => arrPos (k i)))
\func arrData.{v} {C : \Cat v} {P : (DI ->⁺ C) -> \Prop} (a :⁺ Arrows P) : \Sigma (h : DI ->⁺ C) (P h) \elim a
| arr h Ph _ => (h, Ph)
\func arrPos.{v} {C : \Cat v} {P : (DI ->⁺ C) -> \Prop} (a :⁺ Arrows P) : DI \elim a
| arr _ _ i => i
\func evalArr-split.{v} {C : \Cat v} {P : (DI ->⁺ C) -> \Prop} (a :⁺ Arrows P) : evalArr a = (arrData a).1 (arrPos a) \elim a
| arr h Ph i => idp
-- | Maps from {DI} to a type are constant.
\func DI-const {A :⁺ \Type} {a b :⁺ A} (p :⁺ a ~> b) : (\lam i => p i) = {DI ->⁺ A} (\lam _ => a) \elim p
| idd => idp
-- | Restrictions of arrows satisfying {P} along maps `DI -> DI` satisfy {P}.
\lemma restrict-con.{v} {C : \Cat v} {P : (DI ->⁺ C) -> \Prop}
(Pid : \Pi {h : DI ->⁺ C} -> P h -> \Sigma (P (idd {C} {h dleft})) (P (idd {C} {h dright})))
{h : DI ->⁺ C} (Ph : P h) {x y : DI} (p : x ~> y) : P (\lam i => h (p i)) \elim x
| dleft => \case \elim y, \elim p \with {
| dleft, p => transport (\lam (q : dleft ~> dleft) => P (\lam i => h (q i))) (DI-hom-prop idd p) (Pid Ph).1
| dright, p => transport (\lam (q : dleft ~> dright) => P (\lam i => h (q i))) (DI-hom-prop (dpath \lam i => i) p) Ph
}
| dright => \case \elim y, \elim p \with {
| dleft, p => absurd (DI-hom-rl-empty p)
| dright, p => transport (\lam (q : dright ~> dright) => P (\lam i => h (q i))) (DI-hom-prop idd p) (Pid Ph).2
}
{- | {HoCat} preserves left maps: it sends maps left orthogonal to embeddings to left maps of the factorization system
- on 1-categories whose right maps are faithful functors which are embeddings on objects.
-
- Given a subcategory `S` of `HoCat B` containing the image of `HoCat A`, the nerve of its inclusion is an embedding,
- so the unit `B -> Nerve (HoCat B)` lifts to the nerve of `S`; such a lift maps arrows of {B} to arrows of `S`.
-}
\lemma HoCat-left.{u} {A B : \Cat u} {f : A ->⁺ B} (fl : \Pi {E E' : \Cat u} {g : E ->⁺ E'} -> IsEmbedding g -> IsOrthogonal f g)
: IsGeneratingFunctor (HoCat-map f)
=> \lam S hyp {X} {Y} g =>
\have | Je => nerveMap-emb S.incl (Embedding.projection S.ob)
| la => embedding-lift Je (\lam a => unit (f a)) \lam k => inP (\lam i => arrow {A} {B} {f} S hyp k i,
\lam i => inv (square-homotopy (unit-hom (dmap f (dpath \lam i => k i))) i))
| c => Contr.center {IsOrthogonal-char.1 (fl Je) (\lam a => la.1 a) (\lam b => unit b) (\lam a => inv (la.2 a))}
\in extract S c.1 c.3 g
\where {
\open NerveUnit
-- | The arrow of the nerve of {S} given by the image of {k}.
\func arrow.{u} {A B : \Cat u} {f : A ->⁺ B} (S : SubcatPred (HoCat B))
(hyp : \Pi {a a' : Trunc1 A} (h : Hom {HoCat A} a a') -> S.hom ((HoCat-map f).Func h)) (k : DI ->⁺ A)
=> \let | hk => hyp {in1 (k dleft)} {in1 (k dright)} (HoCat.mkHom (dpath \lam i => k i))
| s0 : \Sigma (X : Trunc1 B) (S.ob X) => (in1 (f (k dleft)), S.hom-dom hk)
| s1 : \Sigma (X : Trunc1 B) (S.ob X) => (in1 (f (k dright)), S.hom-cod hk)
\in nerveHom {S.toPrecat} {s0} {s1} (HoCat.mkHom (dmap f (dpath \lam i => k i)), hk)
-- | A lift of the unit along the nerve of the inclusion of {S} maps arrows of {B} to arrows of {S}.
\lemma extract.{u} {B : \Cat u} (S : SubcatPred (HoCat B))
(h : B ->⁺ Nerve S.toPrecat) (H : \Pi (b :⁺ B) -> nerveMap S.incl (h b) = unit b) {X Y : Trunc1 B} (g : Hom {HoCat B} X Y) : S.hom g
=> \case \elim X, \elim Y, \elim g \with {
| in1 x, in1 y, HoCat.mkHom k =>
\have sq => inv (pmap (comp _) =_~>_comp)
*> square-paste (~>-natural {B} {_} {\lam b => nerveMap S.incl (h b)} {\lam b => unit b} (\lam b => =_~> (H b)) {x} {y} {k}) (unit-hom k)
*> pmap (comp __ _) =_~>_comp
\in \case nerve-image S.incl (dmap h k) (H x *> unit-ob x) (H y *> unit-ob y) (HoCat.mkHom k) sq \with {
| inP (s, t, psi, e1, e2, e) => transport S.hom e (S.hom-transport e1 e2 psi.2)
}
}
-- | A commutative square whose horizontal sides are paths gives a pointwise path between the vertical arrows.
\func square-homotopy {C : \Cat} {a b a' b' : C} {al : a ~> b} {be : a' ~> b'} {p : a = a'} {q : b = b'}
(sq : comp al (=_~> q) = comp (=_~> p) be) (i :⁺ DI) : al i = be i \elim p, q
| idp, idp => path \lam j => (inv comp_idd-right *> sq *> comp_idd-left) j i
}
}
\func make (h : DI ->⁺ C) (Ph : P h) (i :⁺ DI) : SubCat P
=> catFactorLeft {_} {Arrows P} (arr h Ph i)
\lemma inc-sat {h : DI ->⁺ C} (Ph : P h) : ∃ (k : DI ->⁺ SubCat P) (\Pi (i :⁺ DI) -> inc (k i) = h i)
=> inP (make h Ph, \lam i => idp)
\lemma inc-emb : IsEmbedding inc
=> family-emb.1 \lam p => IsOrthogonal_o-right (IsOrthogonal_IsHEquiv-right $
inP \new HQEquiv {SubCat P} {CatFactor evalArr} {
| f d => d
| finv d => d
| finv_f d => idp
| f_finv d => idp
}) (catFactorRight.isRight p)
-- | If {P} contains identities, then the subcategory is wide.
\lemma inc-surj (Pid : \Pi (x : C) -> P (idd {C} {x})) : IsSurjMap inc
=> \lam y => inP (make (\lam _ => y) (Pid y) dleft, idp)
-- | The subcategory is contained in every subcategory containing the arrows satisfying {P}.
\sfunc isMin {E : \Cat} {f : E ->⁺ C} (fe : IsEmbedding f)
(fs : \Pi {h : DI ->⁺ C} -> P h -> ∃ (k : DI ->⁺ E) (\Pi (i :⁺ DI) -> f (k i) = h i))
: \Sigma (g : SubCat P ->⁺ E) (\Pi (x :⁺ SubCat P) -> f (g x) = inc x)
=> \have l => catFactorRight.lift (arrLift fe fs) (family-emb.2 fe) (arrLift-eq fe fs)
\in (\lam d =>⁺ (l d).1, \lam d => (l d).2)
\where {
\lemma lift {E : \Cat} {f : E ->⁺ C} (fe : IsEmbedding f)
(fs : \Pi {h : DI ->⁺ C} -> P h -> ∃ (k : DI ->⁺ E) (\Pi (i :⁺ DI) -> f (k i) = h i))
{h : DI ->⁺ C} (Ph : P h) : \Sigma (k : DI ->⁺ E) (\Pi (i :⁺ DI) -> f (k i) = h i)
=> TruncP.remove (IsEmbedding.lift-isProp fe h) (fs Ph)
\func arrLift {E : \Cat} {f : E ->⁺ C} (fe : IsEmbedding f)
(fs : \Pi {h : DI ->⁺ C} -> P h -> ∃ (k : DI ->⁺ E) (\Pi (i :⁺ DI) -> f (k i) = h i))
(a :⁺ Arrows P) : E \elim a
| arr h Ph i => (lift fe fs Ph).1 i
\func arrLift-eq {E : \Cat} {f : E ->⁺ C} (fe : IsEmbedding f)
(fs : \Pi {h : DI ->⁺ C} -> P h -> ∃ (k : DI ->⁺ E) (\Pi (i :⁺ DI) -> f (k i) = h i))
(a :⁺ Arrows P) : f (arrLift fe fs a) = evalArr a \elim a
| arr h Ph i => (lift fe fs Ph).2 i
}
-- | A functor whose arrows satisfy {P} factors through the subcategory.
\sfunc isMax {E : \Cat} {g : E ->⁺ C} (gP : \Pi (k : DI ->⁺ E) -> P (\lam i => g (k i)))
: \Sigma (h : E ->⁺ SubCat P) (\Pi (y :⁺ E) -> inc (h y) = g y)
=> embedding-lift inc-emb g \lam k => inc-sat (gP k)
}
-- | If {P} is closed under composition, then arrows of the subcategory are arrows of {C} satisfying {P}.
\lemma subCat-arr-equiv.{u} {C : \Cat u} {P : (DI ->⁺ C) -> \Prop} (Pc : IsCompClosed P)
: IsEquiv {DI ->⁺ SubCat P} {\Sigma (h : DI ->⁺ C) (P h)}
(\lam d => (\lam i => SubCat.inc (d i), SubCat.inc-con {C} {P} Pc))
=> IsEquiv.fromEmbSurj
(leftEmbedding (Embedding.sigma-prop-embedding \lam h => prop-isProp) (IsEmbedding.post SubCat.inc-emb DI))
(\lam s => TruncP.map (SubCat.inc-sat s.2) \lam t => (t.1, sigma-prop-ext (\lam h => prop-isProp) (path \lam j i => t.2 i j)))
-- | Functors into the subcategory are functors to {C} whose arrows satisfy {P}.
\lemma subCat-fun-equiv.{u} {C : \Cat u} {P : (DI ->⁺ C) -> \Prop} (Pc : IsCompClosed P) {T : \Cat}
: IsEquiv {T ->⁺ SubCat P} {\Sigma (g : T ->⁺ C) (\Pi (k : DI ->⁺ T) -> P (\lam i => g (k i)))}
(\lam h => (\lam t => SubCat.inc (h t), \lam k => SubCat.inc-con {C} {P} Pc))
=> IsEquiv.fromEmbSurj (leftEmbedding (Embedding.projection \lam (g : T ->⁺ C) => \Pi (k : DI ->⁺ T) -> P (\lam i => g (k i)))
(IsEmbedding.post SubCat.inc-emb T))
\lam s => \have l => SubCat.isMax {C} {P} {T} {s.1} s.2
\in inP (l.1, ext (ext l.2))
-- | If {P} is a wide subset, then arrows into {x} in the subcategory are arrows into `inc x` satisfying {P}.
\lemma subCat-into-equiv.{u} {C : \Cat u} {P : (DI ->⁺ C) -> \Prop} (Pc : IsWideSubset P) (x : SubCat P)
: IsEquiv {\Sigma (y : SubCat P) (y ~> x)} {\Sigma (s : \Sigma (u : C) (u ~> SubCat.inc x)) (P s.2)}
(\lam w => ((SubCat.inc w.1, dpath \lam i => SubCat.inc (w.2 i)), SubCat.inc-con (IsWideSubset.isCompClosed Pc)))
=> inP $ into-fib x `transQEquiv`
fib-parallel-equiv (subCat-arr-equiv (IsWideSubset.isCompClosed Pc))
(IsEquiv.fromEmbSurj (IsEmbedding.char.1 SubCat.inc-emb).1 (SubCat.inc-surj Pc.1)) (\lam d => idp) x `transQEquiv`
fib-into (SubCat.inc x)
\where \private {
-- | Arrows into {x} are functors from {DI} ending at {x}.
\func into-fib {E : \Cat} (x : E) : QEquiv {\Sigma (y : E) (y ~> x)} {Fib {DI ->⁺ E} (\lam d => d dright) x} \cowith
| f w => (\lam i => w.2 i, idp)
| ret s => (s.1 dleft, transport (s.1 dleft ~> __) s.2 (dpath s.1))
| ret_f w => idp
| f_sec s => aux s.2
\where
\private \sfunc aux {E : \Cat} {d : DI ->⁺ E} {x : E} (e : d dright = x)
: ((\lam i => transport (d dleft ~> __) e (dpath d) i, idp) : Fib {DI ->⁺ E} (\lam d => d dright) x) = (d, e) \elim e
| idp => idp
-- | Functors from {DI} satisfying {P} and ending at {z} are arrows into {z} satisfying {P}.
\func fib-into {C : \Cat} {P : (DI ->⁺ C) -> \Prop} (z : C)
: QEquiv {Fib {\Sigma (h : DI ->⁺ C) (P h)} (\lam s => s.1 dright) z} {\Sigma (s : \Sigma (u : C) (u ~> z)) (P s.2)} \cowith
| f s => aux s.1.1 s.1.2 s.2
| ret s => ((\lam i => s.1.2 i, s.2), idp)
| ret_f s => aux-ret s.1.2 s.2
| f_sec s => idp
\where \private {
\func aux {z : C} (h : DI ->⁺ C) (Ph : P h) (e : h dright = z) : \Sigma (s : \Sigma (u : C) (u ~> z)) (P s.2) \elim e
| idp => ((h dleft, dpath h), Ph)
\sfunc aux-ret {z : C} {h : DI ->⁺ C} (Ph : P h) (e : h dright = z)
: ((\lam i => (aux h Ph e).1.2 i, (aux h Ph e).2), idp) = {Fib {\Sigma (h : DI ->⁺ C) (P h)} (\lam s => s.1 dright) z} ((h, Ph), e) \elim e
| idp => idp
}
}