Martin Escardo, 20th August 2018 We consider type and subtype classifiers, and discuss an obvious generalization. * (Ξ£ X κ π€ Μ , X β Y) β (Y β π€ Μ ) * (Ξ£ X κ π€ Μ , X βͺ Y) β (Y β Ξ© π€) \begin{code} {-# OPTIONS --safe --without-K #-} module UF.Classifiers-Old where open import MLTT.Spartan open import UF.Subsingletons open import UF.Equiv open import UF.EquivalenceExamples open import UF.Equiv-FunExt open import UF.Base open import UF.Univalence open import UF.UA-FunExt open import UF.FunExt open import UF.Embeddings open import UF.SubtypeClassifier module type-classifier {π€ : Universe} (fe' : funext π€ (π€ βΊ)) (ua : is-univalent π€) (Y : π€ Μ ) where Ο : (Ξ£ X κ π€ Μ , (X β Y)) β (Y β π€ Μ ) Ο (X , f) = fiber f T : (Y β π€ Μ ) β Ξ£ X κ π€ Μ , (X β Y) T A = Ξ£ A , prβ ΟT : (A : Y β π€ Μ ) β Ο (T A) οΌ A ΟT A = dfunext fe' Ξ³ where f : β y β (Ξ£ Ο κ Ξ£ A , prβ Ο οΌ y) β A y f y ((.y , a) , refl) = a g : β y β A y β Ξ£ Ο κ Ξ£ A , prβ Ο οΌ y g y a = (y , a) , refl fg : β y a β f y (g y a) οΌ a fg y a = refl gf : β y Ο β g y (f y Ο) οΌ Ο gf y ((.y , a) , refl) = refl Ξ³ : β y β (Ξ£ Ο κ Ξ£ A , prβ Ο οΌ y) οΌ A y Ξ³ y = eqtoid ua _ _ (f y , ((g y , fg y) , (g y , gf y))) transport-map : {X X' Y : π€ Μ } (e : X β X') (g : X β Y) β transport (Ξ» - β - β Y) (eqtoid ua X X' e) g οΌ g β eqtofun (β-sym e) transport-map {X} {X'} {Y} e g = Ο (eqtoid ua X X' e) refl where Ο : (p : X οΌ X') β p οΌ eqtoid ua X X' e β transport (Ξ» - β - β Y) p g οΌ g β eqtofun (β-sym e) Ο refl q = ap (Ξ» h β g β h) s where r : idtoeq X X refl οΌ e r = idtoeq X X refl οΌβ¨ ap (idtoeq X X) q β© idtoeq X X (eqtoid ua X X e) οΌβ¨ idtoeq-eqtoid ua X X e β© e β s : id οΌ eqtofun (β-sym e) s = ap (Ξ» - β eqtofun (β-sym -)) r TΟ : (Ο : Ξ£ X κ π€ Μ , (X β Y)) β T (Ο Ο) οΌ Ο TΟ (X , f) = to-Ξ£-οΌ (eqtoid ua _ _ (total-fiber-is-domain f) , transport-map (total-fiber-is-domain f) prβ) Ο-is-equivalence : is-equiv Ο Ο-is-equivalence = (T , ΟT) , (T , TΟ) classification-equivalence : (Ξ£ X κ π€ Μ , (X β Y)) β (Y β π€ Μ ) classification-equivalence = Ο , Ο-is-equivalence module subtype-classifier {π€ : Universe} (fe' : funext π€ (π€ βΊ)) (ua : is-univalent π€) (Y : π€ Μ ) where fe : funext π€ π€ fe = univalence-gives-funext ua Ο : (Ξ£ X κ π€ Μ , X βͺ Y) β (Y β Ξ© π€) Ο (X , f , i) y = fiber f y , i y T : (Y β Ξ© π€) β Ξ£ X κ π€ Μ , X βͺ Y T P = (Ξ£ y κ Y , P y holds) , prβ , prβ-is-embedding (Ξ» y β holds-is-prop (P y)) ΟT : (P : Y β Ξ© π€) β Ο (T P) οΌ P ΟT P = dfunext fe' Ξ³ where f : β y β Ο (T P) y holds β P y holds f y ((.y , h) , refl) = h g : β y β P y holds β Ο (T P) y holds g y h = (y , h) , refl Ξ³ : (y : Y) β Ο (T P) y οΌ P y Ξ³ y = Ξ©-ext-from-univalence ua (f y) (g y) transport-embedding : {X X' Y : π€ Μ } (e : X β X') (g : X β Y) (i : is-embedding g) β transport (Ξ» - β - βͺ Y) (eqtoid ua X X' e) (g , i) οΌ g β eqtofun (β-sym e) , β-is-embedding (equivs-are-embeddings (eqtofun (β-sym e)) (eqtofun- (β-sym e))) i transport-embedding {X} {X'} {Y} e g i = Ο (eqtoid ua X X' e) refl where Ο : (p : X οΌ X') β p οΌ eqtoid ua X X' e β transport (Ξ» - β - βͺ Y) p (g , i) οΌ g β eqtofun (β-sym e) , β-is-embedding (equivs-are-embeddings (eqtofun (β-sym e)) (eqtofun- (β-sym e))) i Ο refl q = to-Ξ£-οΌ (ap (Ξ» h β g β h) s , being-embedding-is-prop fe (g β eqtofun (β-sym e)) _ _) where r : idtoeq X X refl οΌ e r = ap (idtoeq X X) q β idtoeq-eqtoid ua X X e s : id οΌ eqtofun (β-sym e) s = ap (Ξ» - β eqtofun (β-sym -)) r TΟ : (Ο : Ξ£ X κ π€ Μ , X βͺ Y) β T (Ο Ο) οΌ Ο TΟ (X , f , i) = to-Ξ£-οΌ (eqtoid ua _ _ (total-fiber-is-domain f) , (transport-embedding (total-fiber-is-domain f) prβ (prβ-is-embedding i) β to-Ξ£-οΌ' (being-embedding-is-prop fe f _ _))) Ο-is-equivalence : is-equiv Ο Ο-is-equivalence = (T , ΟT) , (T , TΟ) classification-equivalence : (Ξ£ X κ π€ Μ , X βͺ Y) β (Y β Ξ© π€) classification-equivalence = Ο , Ο-is-equivalence \end{code} TODO. Consider a property "green" of types, and call a map green if its fibers are all green. Then the maps of Y into green types should correspond to the green maps X β Y. This generalizes the above situation. In particular, the case green = contractible is of interest and describes a previously known situation. Another example is that surjections X β Y are in bijection with families Y β Ξ£ (Z : π€ Μ ) β β₯ Z β₯), that is, families of inhabited types. It is not necessary that "green" is proposition valued. It can be universe valued in general. And then of course retractions X β Y are in bijections with families of pointed types. Tom de Jong, September 2019. I implement the above TODO. (There is an alternative solution at https://www.cs.bham.ac.uk/~mhe/HoTT-UF.in-Agda-Lecture-Notes/) Fix type universes π€ and π₯ and a type Y : π€ Μ. Consider a property green : π€ β π₯. If X : π€ Μ and f : X β Y, then we say that f is a green map if all of its fibers are green. The general theorem says that type of green maps to Y is equivalent to the type of green types: Green-map β (Y β Green). The examples are obtained by specialising to a specific property green: * Every type and map is green. (Ξ£ X κ π€ Μ , X β Y) β (Y β π€ Μ ) * A type is green exactly if it is a subsingleton. Then a map is green exactly if it is an embedding. (Ξ£ X κ π€ Μ , X βͺ Y) β (Y β Ξ© π€) * A type is green exactly if it is inhabited. Then a map is green exactly if it is a surjection. (Ξ£ X κ π€ Μ , (Ξ£ f κ X β Y , is-surjection f )) β (Y β (Ξ£ X κ π€ Μ , β₯ X β₯)) * A type is green exactly if it is pointed. Then a map is green exactly if it is a retraction. (Ξ£ X κ π€ Μ , Y β X) β (Y β (Ξ£ X κ π€ Μ , X)) \begin{code} eqtoid-comp : (ua : is-univalent π€) {X Y Z : π€ Μ } (f : X β Y) (g : Y β Z) β (eqtoid ua X Y f) β (eqtoid ua Y Z g) οΌ eqtoid ua X Z (f β g) eqtoid-comp {π€} ua {X} {Y} {Z} f = JEq ua Y (Ξ» Z g β eqtoid ua X Y f β eqtoid ua Y Z g οΌ eqtoid ua X Z (f β g)) Ξ³ Z where fe : funext π€ π€ fe = univalence-gives-funext ua h : f οΌ f β β-refl Y h = (β-refl-right' fe fe fe f)β»ΒΉ Ξ³ = eqtoid ua X Y f β eqtoid ua Y Y (β-refl Y) οΌβ¨ ap (Ξ» - β eqtoid ua X Y f β -) (eqtoid-refl ua Y) β© eqtoid ua X Y f οΌβ¨ ap (Ξ» - β eqtoid ua X Y -) h β© eqtoid ua X Y (f β β-refl Y) β module general-classifier {π€ π₯ : Universe} (fe : funext π€ π₯) (fe' : funext π€ (π€ βΊ β π₯)) (ua : is-univalent π€) (Y : π€ Μ ) (green : π€ Μ β π₯ Μ ) where green-map : {X : π€ Μ } β (X β Y) β π€ β π₯ Μ green-map f = (y : Y) β green (fiber f y) Green : π€ βΊ β π₯ Μ Green = Ξ£ X κ π€ Μ , green X Green-map : π€ βΊ β π₯ Μ Green-map = Ξ£ X κ π€ Μ , Ξ£ f κ (X β Y) , green-map f Ο : Green-map β (Y β Green) Ο (X , f , g) y = (fiber f y) , (g y) fiber-equiv-οΌ : (A : Y β Green) (y : Y) β prβ (A y) οΌ fiber prβ y fiber-equiv-οΌ A y = (eqtoid ua (fiber prβ y) (prβ (A y)) (prβ-fiber-equiv {π€} {π€} {Y} {prβ β A} y)) β»ΒΉ T : (Y β Green) β Green-map T A = Ξ£ (prβ β A) , prβ , g where g : green-map prβ g y = transport green (fiber-equiv-οΌ A y) (prβ (A y)) ΟT : (A : Y β Green) β Ο (T A) οΌ A ΟT A = dfunext fe' Ξ³ where Ξ³ : (y : Y) β Ο (T A) y οΌ A y Ξ³ y = to-Ξ£-οΌ ((a β»ΒΉ) , b) where a : prβ (A y) οΌ prβ (Ο (T A) y) a = fiber-equiv-οΌ A y b = transport green (a β»ΒΉ) (prβ (Ο (T A) y)) οΌβ¨ refl β© transport green (a β»ΒΉ) (transport green a (prβ (A y))) οΌβ¨ i β© transport green (a β a β»ΒΉ) (prβ (A y)) οΌβ¨ ii β© transport green refl (prβ (A y)) οΌβ¨ refl β© prβ (A y) β where i = (transport-β green a (a β»ΒΉ)) β»ΒΉ ii = ap (Ξ» - β transport green - (prβ (A y))) (trans-sym' a) green-maps-are-closed-under-precomp-with-equivs : {X X' : π€ Μ } (e : X' β X) {f : X β Y} β green-map f β green-map (f β eqtofun e) green-maps-are-closed-under-precomp-with-equivs e {f} g y = transport green p (g y) where p : fiber f y οΌ fiber (f β eqtofun e) y p = (eqtoid ua _ _ (precomposition-with-equiv-does-not-change-fibers e f y)) β»ΒΉ precomp-with-β-refl-green-map : {X : π€ Μ } (f : X β Y) (g : green-map f) β green-maps-are-closed-under-precomp-with-equivs (β-refl X) g οΌ g precomp-with-β-refl-green-map {X} f g = dfunext fe Ξ³ where Ξ³ : (y : Y) β green-maps-are-closed-under-precomp-with-equivs (β-refl X) g y οΌ g y Ξ³ y = green-maps-are-closed-under-precomp-with-equivs (β-refl X) g y οΌβ¨ refl β© transport green ((eqtoid ua _ _ (β-refl (fiber f y))) β»ΒΉ) (g y) οΌβ¨ i β© g y β where i = ap (Ξ» - β transport green (- β»ΒΉ) (g y)) (eqtoid-refl ua (fiber f y)) transport-green-map-eqtoid : {X X' : π€ Μ } (e : X' β X) (f : X β Y) (g : green-map f) β transport (Ξ» - β Ξ£ h κ (- β Y) , green-map h) ((eqtoid ua X' X e) β»ΒΉ) (f , g) οΌ f β (eqtofun e) , green-maps-are-closed-under-precomp-with-equivs e g transport-green-map-eqtoid {X} {X'} = JEq ua X' E Ξ³ X where B : π€ Μ β π€ β π₯ Μ B Z = Ξ£ h κ (Z β Y) , green-map h E : (Z : π€ Μ ) β X' β Z β π€ β π₯ Μ E Z e = (f : Z β Y) β (g : green-map f) β transport B ((eqtoid ua X' Z e) β»ΒΉ) (f , g) οΌ f β (eqtofun e) , green-maps-are-closed-under-precomp-with-equivs e g Ξ³ : E X' (β-refl X') Ξ³ f g = transport B ((eqtoid ua X' X' (β-refl X')) β»ΒΉ) (f , g) οΌβ¨ i β© f , g οΌβ¨ ii β© f , green-maps-are-closed-under-precomp-with-equivs (β-refl X') g β where i = ap (Ξ» - β transport B (- β»ΒΉ) (f , g)) (eqtoid-refl ua X') ii = to-Ξ£-οΌ (refl , ((precomp-with-β-refl-green-map f g) β»ΒΉ)) TΟ : (f : Green-map) β T (Ο f) οΌ f TΟ (X , f , g) = to-Ξ£-οΌ (a , (to-Ξ£-οΌ (b , c))) where X' : π€ Μ X' = prβ (T (Ο (X , f , g))) f' : X' β Y f' = prβ (prβ (T (Ο (X , f , g)))) g' : green-map f' g' = prβ (prβ (T (Ο (X , f , g)))) e : X β X' e = domain-is-total-fiber f a : X' οΌ X a = (eqtoid ua X X' e) β»ΒΉ B : π€ Μ β π€ β π₯ Μ B Z = Ξ£ h κ (Z β Y), green-map h t : transport B a (f' , g') οΌ (f' β eqtofun e) , (green-maps-are-closed-under-precomp-with-equivs e g') t = transport-green-map-eqtoid e f' g' tβ : prβ (transport B a (f' , g')) οΌ f' β eqtofun e tβ = prβ (from-Ξ£-οΌ t) tβ : transport green-map tβ (prβ (transport B a (f' , g'))) οΌ green-maps-are-closed-under-precomp-with-equivs e g' tβ = prβ (from-Ξ£-οΌ t) b : prβ (transport B a (f' , g')) οΌ f b = prβ (transport B a (f' , g')) οΌβ¨ tβ β© f' β eqtofun e οΌβ¨ refl β© f β c : transport green-map b (prβ (transport B a (f' , g'))) οΌ g c = transport green-map b (prβ (transport B a (f' , g'))) οΌβ¨ refl β© transport green-map tβ (prβ (transport B a (f' , g'))) οΌβ¨ tβ β© green-maps-are-closed-under-precomp-with-equivs e g' οΌβ¨ dfunext fe u β© g β where u : (y : Y) β green-maps-are-closed-under-precomp-with-equivs e g' y οΌ g y u y = green-maps-are-closed-under-precomp-with-equivs e g' y οΌβ¨ refl β© transport green (p β»ΒΉ) (g' y) οΌβ¨ refl β© transport green (p β»ΒΉ) (transport green (q β»ΒΉ) (g y)) οΌβ¨ i β© transport green (q β»ΒΉ β p β»ΒΉ) (g y) οΌβ¨ ii β© g y β where p : fiber (f' β eqtofun e) y οΌ fiber f' y p = eqtoid ua _ _ (precomposition-with-equiv-does-not-change-fibers e f' y) q : fiber f' y οΌ fiber f y q = eqtoid ua (fiber f' y) (fiber f y) (prβ-fiber-equiv y) i = (transport-β green (q β»ΒΉ) (p β»ΒΉ)) β»ΒΉ ii = ap (Ξ» - β transport green - (g y)) v where v = q β»ΒΉ β p β»ΒΉ οΌβ¨ β»ΒΉ-contravariant p q β© (p β q) β»ΒΉ οΌβ¨ ap (_β»ΒΉ) w β© refl β where w : p β q οΌ refl w = eqtoid ua _ _ Ο β eqtoid ua _ _ Ο οΌβ¨ eqtoid-comp ua _ _ β© eqtoid ua _ _ (Ο β Ο) οΌβ¨ ap (eqtoid ua _ _) ΟΟ β© eqtoid ua _ _ (β-refl _) οΌβ¨ eqtoid-refl ua _ β© refl β where Ο : fiber (f' β eqtofun e) y β fiber f' y Ο = precomposition-with-equiv-does-not-change-fibers e f' y Ο : fiber prβ y β prβ (Ο (X , f , g) y) Ο = prβ-fiber-equiv y ΟΟ : Ο β Ο οΌ β-refl (fiber (f' β eqtofun e) y) ΟΟ = to-Ξ£-οΌ (dfunext fe'' ΟΟ' , being-equiv-is-prop'' fe'' id _ (id-is-equiv _)) where ΟΟ' : (z : fiber (f' β eqtofun e) y) β eqtofun (Ο β Ο) z οΌ z ΟΟ' (x , refl) = refl fe'' : funext π€ π€ fe'' = univalence-gives-funext ua Ο-is-equivalence : is-equiv Ο Ο-is-equivalence = (T , ΟT) , (T , TΟ) classification-equivalence : Green-map β (Y β Green) classification-equivalence = Ο , Ο-is-equivalence \end{code} We now can get type-classifier above as a special case of this more general situation: \begin{code} module type-classifier-bis {π€ : Universe} (fe' : funext π€ (π€ βΊ)) (ua : is-univalent π€) (Y : π€ Μ ) where open general-classifier (univalence-gives-funext ua) fe' ua Y (Ξ» (X : π€ Μ ) β π) type-classification-equivalence : (Ξ£ X κ π€ Μ , (X β Y)) β (Y β π€ Μ ) type-classification-equivalence = (Ξ£ X κ π€ Μ , (X β Y)) ββ¨ Ο β© Green-map ββ¨ classification-equivalence β© (Y β Green) ββ¨ Ο β© (Y β π€ Μ ) β where Ο : (Ξ£ X κ π€ Μ , (X β Y)) β Green-map Ο = qinveq Ξ± (Ξ² , a , b) where Ξ± : (Ξ£ X κ π€ Μ , (X β Y)) β Green-map Ξ± (X , f) = X , (f , (Ξ» y β β)) Ξ² : Green-map β (Ξ£ X κ π€ Μ , (X β Y)) Ξ² (X , f , g) = X , f a : (p : Ξ£ (Ξ» X β X β Y)) β Ξ² (Ξ± p) οΌ p a (X , f) = refl b : (q : Green-map) β Ξ± (Ξ² q) οΌ q b (X , f , g) = to-Ξ£-οΌ (refl , to-Ξ£-οΌ (refl , dfunext (univalence-gives-funext ua) (Ξ» y β π-is-prop β (g y)))) Ο : (Y β Green) β (Y β π€ Μ ) Ο = βcong fe' fe' (β-refl Y) Ξ³ where Ξ³ : Green β π€ Μ Ξ³ = qinveq prβ ((Ξ» X β (X , β )) , c , Ξ» x β refl) where c : (p : Ξ£ (Ξ» X β π)) β prβ p , β οΌ p c (x , β) = refl \end{code} And we also get the other examples in the TODO: \begin{code} module subsingleton-classifier {π€ : Universe} (fe' : funext π€ (π€ βΊ)) (ua : is-univalent π€) (Y : π€ Μ ) where open general-classifier (univalence-gives-funext ua) fe' ua Y (Ξ» (X : π€ Μ ) β is-prop X) subsingleton-classification-equivalence : (Ξ£ X κ π€ Μ , X βͺ Y) β (Y β Ξ© π€ ) subsingleton-classification-equivalence = classification-equivalence module singleton-classifier {π€ : Universe} (fe' : funext π€ (π€ βΊ)) (ua : is-univalent π€) (Y : π€ Μ ) where open import UF.Subsingletons-FunExt open general-classifier (univalence-gives-funext ua) fe' ua Y (Ξ» (X : π€ Μ ) β is-singleton X) singleton-classification-equivalence : (Ξ£ X κ π€ Μ , X β Y) β π {π€} singleton-classification-equivalence = (Ξ£ X κ π€ Μ , X β Y) ββ¨ i β© (Ξ£ X κ π€ Μ , (Ξ£ f κ (X β Y), is-vv-equiv f)) ββ¨ ii β© (Y β (Ξ£ X κ π€ Μ , is-singleton X)) ββ¨ iii β© (Y β π) ββ¨ βπ fe β© π β where fe : funext π€ π€ fe = univalence-gives-funext ua i = Ξ£-cong (Ξ» (X : π€ Μ ) β Ξ£-cong (Ξ» (f : X β Y) β logically-equivalent-props-are-equivalent (being-equiv-is-prop'' fe f) (Ξ -is-prop fe (Ξ» y β being-singleton-is-prop fe)) (equivs-are-vv-equivs f) (vv-equivs-are-equivs f))) ii = classification-equivalence iii = βcong fe fe' (β-refl Y) Ο where Ο : Ξ£ (Ξ» X β is-singleton X) β π Ο = qinveq unique-to-π ((Ξ» _ β π , π-is-singleton) , (a , π-is-prop β)) where a : (p : Ξ£ (Ξ» v β is-singleton v)) β π , π-is-singleton οΌ p a (X , s) = to-Ξ£-οΌ (eqtoid ua π X (singleton-β-π' s) , being-singleton-is-prop fe _ s) open import UF.PropTrunc module inhabited-classifier {π€ : Universe} (fe' : funext π€ (π€ βΊ)) (ua : is-univalent π€) (Y : π€ Μ ) (pt : propositional-truncations-exist) where open import UF.ImageAndSurjection pt open PropositionalTruncation pt open general-classifier (univalence-gives-funext ua) fe' ua Y (Ξ» (X : π€ Μ ) β β₯ X β₯) inhabited-classification-equivalence : (Ξ£ X κ π€ Μ , (Ξ£ f κ (X β Y), is-surjection f )) β (Y β (Ξ£ X κ π€ Μ , β₯ X β₯)) inhabited-classification-equivalence = classification-equivalence module pointed-classifier {π€ : Universe} (fe' : funext π€ (π€ βΊ)) (ua : is-univalent π€) (Y : π€ Μ ) where open import UF.Retracts open general-classifier (univalence-gives-funext ua) fe' ua Y (Ξ» (X : π€ Μ ) β X) pointed-classification-equivalence : (Ξ£ X κ π€ Μ , Y β X) β (Y β (Ξ£ X κ π€ Μ , X)) pointed-classification-equivalence = (Ξ£ X κ π€ Μ , Y β X) ββ¨ i β© (Ξ£ X κ π€ Μ , (Ξ£ f κ (X β Y) , ((y : Y) β fiber f y))) ββ¨ ii β© (Y β (Ξ£ X κ π€ Μ , X)) β where i = Ξ£-cong (Ξ» (X : π€ Μ ) β Ξ£-cong (Ξ» (f : X β Y) β retract-pointed-fibers)) ii = classification-equivalence \end{code}