MartΓn EscardΓ³ 1st May 2020.
This is ported from the Midlands Graduate School 2019 lecture notes, which are available online from the following links.
{-# OPTIONS --without-K --exact-split --safe #-} module MGS-Subsingleton-Truncation where open import MGS-Powerset public open import MGS-Embeddings public is-inhabited : π€ Μ β π€ βΊ Μ is-inhabited {π€} X = (P : π€ Μ ) β is-subsingleton P β (X β P) β P inhabitation-is-subsingleton : global-dfunext β (X : π€ Μ ) β is-subsingleton (is-inhabited X) inhabitation-is-subsingleton fe X = Ξ -is-subsingleton fe (Ξ» P β Ξ -is-subsingleton fe (Ξ» (s : is-subsingleton P) β Ξ -is-subsingleton fe (Ξ» (f : X β P) β s))) inhabited-intro : {X : π€ Μ } β X β is-inhabited X inhabited-intro x = Ξ» P s f β f x inhabited-recursion : {X P : π€ Μ } β is-subsingleton P β (X β P) β is-inhabited X β P inhabited-recursion s f Ο = Ο (codomain f) s f inhabited-recursion-computation : {X P : π€ Μ } (i : is-subsingleton P) (f : X β P) (x : X) β inhabited-recursion i f (inhabited-intro x) β‘ f x inhabited-recursion-computation i f x = refl (f x) inhabited-induction : global-dfunext β {X : π€ Μ } {P : is-inhabited X β π€ Μ } (i : (s : is-inhabited X) β is-subsingleton (P s)) (f : (x : X) β P (inhabited-intro x)) β (s : is-inhabited X) β P s inhabited-induction fe {X} {P} i f s = Ο' s where Ο : X β P s Ο x = transport P (inhabitation-is-subsingleton fe X (inhabited-intro x) s) (f x) Ο' : is-inhabited X β P s Ο' = inhabited-recursion (i s) Ο inhabited-computation : (fe : global-dfunext) {X : π€ Μ } {P : is-inhabited X β π€ Μ } (i : (s : is-inhabited X) β is-subsingleton (P s)) (f : (x : X) β P (inhabited-intro x)) (x : X) β inhabited-induction fe i f (inhabited-intro x) β‘ f x inhabited-computation fe i f x = i (inhabited-intro x) (inhabited-induction fe i f (inhabited-intro x)) (f x) inhabited-subsingletons-are-pointed : (P : π€ Μ ) β is-subsingleton P β is-inhabited P β P inhabited-subsingletons-are-pointed P s = inhabited-recursion s (ππ P) inhabited-functorial : global-dfunext β (X : π€ βΊ Μ ) (Y : π€ Μ ) β (X β Y) β is-inhabited X β is-inhabited Y inhabited-functorial fe X Y f = inhabited-recursion (inhabitation-is-subsingleton fe Y) (inhabited-intro β f) image' : {X : π€ Μ } {Y : π₯ Μ } β (X β Y) β (π€ β π₯)βΊ Μ image' f = Ξ£ y κ codomain f , is-inhabited (Ξ£ x κ domain f , f x β‘ y) restriction' : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y) β image' f β Y restriction' f (y , _) = y corestriction' : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y) β X β image' f corestriction' f x = f x , inhabited-intro (x , refl (f x)) is-surjection' : {X : π€ Μ } {Y : π₯ Μ } β (X β Y) β (π€ β π₯)βΊ Μ is-surjection' f = (y : codomain f) β is-inhabited (Ξ£ x κ domain f , f x β‘ y) record subsingleton-truncations-exist : π€Ο where field β₯_β₯ : {π€ : Universe} β π€ Μ β π€ Μ β₯β₯-is-subsingleton : {π€ : Universe} {X : π€ Μ } β is-subsingleton β₯ X β₯ β£_β£ : {π€ : Universe} {X : π€ Μ } β X β β₯ X β₯ β₯β₯-recursion : {π€ π₯ : Universe} {X : π€ Μ } {P : π₯ Μ } β is-subsingleton P β (X β P) β β₯ X β₯ β P infix 0 β₯_β₯ module basic-truncation-development (pt : subsingleton-truncations-exist) (hfe : global-hfunext) where open subsingleton-truncations-exist pt public hunapply : {X : π€ Μ } {A : X β π₯ Μ } {f g : Ξ A} β f βΌ g β f β‘ g hunapply = hfunext-gives-dfunext hfe β₯β₯-recursion-computation : {X : π€ Μ } {P : π₯ Μ } β (i : is-subsingleton P) β (f : X β P) β (x : X) β β₯β₯-recursion i f β£ x β£ β‘ f x β₯β₯-recursion-computation i f x = i (β₯β₯-recursion i f β£ x β£) (f x) β₯β₯-induction : {X : π€ Μ } {P : β₯ X β₯ β π₯ Μ } β ((s : β₯ X β₯) β is-subsingleton (P s)) β ((x : X) β P β£ x β£) β (s : β₯ X β₯) β P s β₯β₯-induction {π€} {π₯} {X} {P} i f s = Ο' s where Ο : X β P s Ο x = transport P (β₯β₯-is-subsingleton β£ x β£ s) (f x) Ο' : β₯ X β₯ β P s Ο' = β₯β₯-recursion (i s) Ο β₯β₯-computation : {X : π€ Μ } {P : β₯ X β₯ β π₯ Μ } β (i : (s : β₯ X β₯) β is-subsingleton (P s)) β (f : (x : X) β P β£ x β£) β (x : X) β β₯β₯-induction i f β£ x β£ β‘ f x β₯β₯-computation i f x = i β£ x β£ (β₯β₯-induction i f β£ x β£) (f x) β₯β₯-functor : {X : π€ Μ } {Y : π₯ Μ } β (X β Y) β β₯ X β₯ β β₯ Y β₯ β₯β₯-functor f = β₯β₯-recursion β₯β₯-is-subsingleton (Ξ» x β β£ f x β£) β₯β₯-agrees-with-inhabitation : (X : π€ Μ ) β β₯ X β₯ β is-inhabited X β₯β₯-agrees-with-inhabitation X = a , b where a : β₯ X β₯ β is-inhabited X a = β₯β₯-recursion (inhabitation-is-subsingleton hunapply X) inhabited-intro b : is-inhabited X β β₯ X β₯ b = inhabited-recursion β₯β₯-is-subsingleton β£_β£ _β¨_ : π€ Μ β π₯ Μ β π€ β π₯ Μ A β¨ B = β₯ A + B β₯ infixl 20 _β¨_ β : {X : π€ Μ } β (X β π₯ Μ ) β π€ β π₯ Μ β A = (β₯ Ξ£ A β₯) -β : {π€ π₯ : Universe} (X : π€ Μ ) (Y : X β π₯ Μ ) β π€ β π₯ Μ -β X Y = β Y syntax -β A (Ξ» x β b) = β x κ A , b infixr -1 -β β¨-is-subsingleton : {A : π€ Μ } {B : π₯ Μ } β is-subsingleton (A β¨ B) β¨-is-subsingleton = β₯β₯-is-subsingleton β-is-subsingleton : {X : π€ Μ } {A : X β π₯ Μ } β is-subsingleton (β A) β-is-subsingleton = β₯β₯-is-subsingleton image : {X : π€ Μ } {Y : π₯ Μ } β (X β Y) β π€ β π₯ Μ image f = Ξ£ y κ codomain f , β x κ domain f , f x β‘ y -- inv : {X : π€ Μ }{Y : π₯ Μ }(f : X β Y) β image f β {!!} -- inv f imgf = prβ imgf restriction : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y) β image f β Y restriction f (y , _) = y corestriction : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y) β X β image f corestriction f x = f x , β£ (x , refl (f x)) β£ is-surjection : {X : π€ Μ } {Y : π₯ Μ } β (X β Y) β π€ β π₯ Μ is-surjection f = (y : codomain f) β β x κ domain f , f x β‘ y being-surjection-is-subsingleton : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y) β is-subsingleton (is-surjection f) being-surjection-is-subsingleton f = Ξ -is-subsingleton hunapply (Ξ» y β β-is-subsingleton) corestriction-surjection : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y) β is-surjection (corestriction f) corestriction-surjection f (y , s) = β₯β₯-functor g s where g : (Ξ£ x κ domain f , f x β‘ y) β Ξ£ x κ domain f , corestriction f x β‘ (y , s) g (x , p) = x , to-subtype-β‘ (Ξ» _ β β-is-subsingleton) p surjection-induction : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y) β is-surjection f β (P : Y β π¦ Μ ) β ((y : Y) β is-subsingleton (P y)) β ((x : X) β P (f x)) β (y : Y) β P y surjection-induction f i P j Ξ± y = β₯β₯-recursion (j y) Ο (i y) where Ο : fiber f y β P y Ο (x , r) = transport P r (Ξ± x) β£β£-is-surjection : (X : π€ Μ ) β is-surjection (Ξ» (x : X) β β£ x β£) β£β£-is-surjection X s = Ξ³ where f : X β β x κ X , β£ x β£ β‘ s f x = β£ (x , β₯β₯-is-subsingleton β£ x β£ s) β£ Ξ³ : β x κ X , β£ x β£ β‘ s Ξ³ = β₯β₯-recursion β₯β₯-is-subsingleton f s singletons-are-inhabited : (X : π€ Μ ) β is-singleton X β β₯ X β₯ singletons-are-inhabited X s = β£ center X s β£ inhabited-subsingletons-are-singletons : (X : π€ Μ ) β β₯ X β₯ β is-subsingleton X β is-singleton X inhabited-subsingletons-are-singletons X t i = c , Ο where c : X c = β₯β₯-recursion i (ππ X) t Ο : (x : X) β c β‘ x Ο = i c singleton-iff-inhabited-subsingleton : (X : π€ Μ ) β is-singleton X β (β₯ X β₯ Γ is-subsingleton X) singleton-iff-inhabited-subsingleton X = (Ξ» (s : is-singleton X) β singletons-are-inhabited X s , singletons-are-subsingletons X s) , Ξ£-induction (inhabited-subsingletons-are-singletons X) equiv-iff-embedding-and-surjection : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y) β is-equiv f β (is-embedding f Γ is-surjection f) equiv-iff-embedding-and-surjection f = (a , b) where a : is-equiv f β is-embedding f Γ is-surjection f a e = (Ξ» y β singletons-are-subsingletons (fiber f y) (e y)) , (Ξ» y β singletons-are-inhabited (fiber f y) (e y)) b : is-embedding f Γ is-surjection f β is-equiv f b (e , s) y = inhabited-subsingletons-are-singletons (fiber f y) (s y) (e y) equiv-β‘-embedding-and-surjection : {X : π€ Μ } {Y : π₯ Μ } (f : X β Y) β propext (π€ β π₯) β is-equiv f β‘ (is-embedding f Γ is-surjection f) equiv-β‘-embedding-and-surjection f pe = pe (being-equiv-is-subsingleton hunapply hunapply f) (Γ-is-subsingleton (being-embedding-is-subsingleton hunapply f) (being-surjection-is-subsingleton f)) (lr-implication (equiv-iff-embedding-and-surjection f)) (rl-implication (equiv-iff-embedding-and-surjection f)) fix : {X : π€ Μ } β (X β X) β π€ Μ fix f = Ξ£ x κ domain f , f x β‘ x from-fix : {X : π€ Μ } (f : X β X) β fix f β X from-fix f = prβ to-fix : {X : π€ Μ } (f : X β X) β wconstant f β X β fix f to-fix f ΞΊ x = f x , ΞΊ (f x) x fix-is-subsingleton : {X : π€ Μ } (f : X β X) β wconstant f β is-subsingleton (fix f) fix-is-subsingleton {π€} {X} f ΞΊ = Ξ³ where a : (y x : X) β (f x β‘ x) β (f y β‘ x) a y x = transport (_β‘ x) (ΞΊ x y) , transport-is-equiv (_β‘ x) (ΞΊ x y) b : (y : X) β fix f β singleton-type' (f y) b y = Ξ£-cong (a y) c : X β is-singleton (fix f) c y = equiv-to-singleton (b y) (singleton-types'-are-singletons X (f y)) d : fix f β is-singleton (fix f) d = c β from-fix f Ξ³ : is-subsingleton (fix f) Ξ³ = subsingleton-criterion d choice-function : π€ Μ β π€ βΊ Μ choice-function X = is-inhabited X β X wconstant-endomap-gives-choice-function : {X : π€ Μ } β wconstant-endomap X β choice-function X wconstant-endomap-gives-choice-function {π€} {X} (f , ΞΊ) = from-fix f β Ξ³ where Ξ³ : is-inhabited X β fix f Ξ³ = inhabited-recursion (fix-is-subsingleton f ΞΊ) (to-fix f ΞΊ) choice-function-gives-wconstant-endomap : global-dfunext β {X : π€ Μ } β choice-function X β wconstant-endomap X choice-function-gives-wconstant-endomap fe {X} c = f , ΞΊ where f : X β X f = c β inhabited-intro ΞΊ : wconstant f ΞΊ x y = ap c (inhabitation-is-subsingleton fe X (inhabited-intro x) (inhabited-intro y)) module find-hidden-root where open basic-arithmetic-and-order public ΞΌΟ : (f : β β β) β root f β root f ΞΌΟ f r = minimal-root-is-root f (root-gives-minimal-root f r) ΞΌΟ-root : (f : β β β) β root f β β ΞΌΟ-root f r = prβ (ΞΌΟ f r) ΞΌΟ-root-is-root : (f : β β β) (r : root f) β f (ΞΌΟ-root f r) β‘ 0 ΞΌΟ-root-is-root f r = prβ (ΞΌΟ f r) ΞΌΟ-root-minimal : (f : β β β) (m : β) (p : f m β‘ 0) β (n : β) β f n β‘ 0 β ΞΌΟ-root f (m , p) β€ n ΞΌΟ-root-minimal f m p n q = not-<-gives-β₯ (ΞΌΟ-root f (m , p)) n Ξ³ where Ο : Β¬(f n β’ 0) β Β¬(n < ΞΌΟ-root f (m , p)) Ο = contrapositive (prβ(prβ (root-gives-minimal-root f (m , p))) n) Ξ³ : Β¬ (n < ΞΌΟ-root f (m , p)) Ξ³ = Ο (dni (f n β‘ 0) q) ΞΌΟ-wconstant : (f : β β β) β wconstant (ΞΌΟ f) ΞΌΟ-wconstant f (n , p) (n' , p') = r where m m' : β m = ΞΌΟ-root f (n , p) m' = ΞΌΟ-root f (n' , p') l : m β€ m' l = ΞΌΟ-root-minimal f n p m' (ΞΌΟ-root-is-root f (n' , p')) l' : m' β€ m l' = ΞΌΟ-root-minimal f n' p' m (ΞΌΟ-root-is-root f (n , p)) q : m β‘ m' q = β€-anti _ _ l l' r : ΞΌΟ f (n , p) β‘ ΞΌΟ f (n' , p') r = to-subtype-β‘ (Ξ» _ β β-is-set (f _) 0) q find-existing-root : (f : β β β) β is-inhabited (root f) β root f find-existing-root f = h β g where Ξ³ : root f β fix (ΞΌΟ f) Ξ³ = to-fix (ΞΌΟ f) (ΞΌΟ-wconstant f) g : is-inhabited (root f) β fix (ΞΌΟ f) g = inhabited-recursion (fix-is-subsingleton (ΞΌΟ f) (ΞΌΟ-wconstant f)) Ξ³ h : fix (ΞΌΟ f) β root f h = from-fix (ΞΌΟ f) module find-existing-root-example where f : β β β f 0 = 1 f 1 = 1 f 2 = 0 f 3 = 1 f 4 = 0 f 5 = 1 f 6 = 1 f 7 = 0 f (succ (succ (succ (succ (succ (succ (succ (succ x)))))))) = x root-existence : is-inhabited (root f) root-existence = inhabited-intro (8 , refl 0) r : root f r = find-existing-root f root-existence x : β x = prβ r x-is-root : f x β‘ 0 x-is-root = prβ r p : x β‘ 2 p = refl _ module exit-β₯β₯ (pt : subsingleton-truncations-exist) (hfe : global-hfunext) where open basic-truncation-development pt hfe open find-hidden-root find-β₯β₯-existing-root : (f : β β β) β (β n κ β , f n β‘ 0) β Ξ£ n κ β , f n β‘ 0 find-β₯β₯-existing-root f = k where Ξ³ : root f β fix (ΞΌΟ f) Ξ³ = to-fix (ΞΌΟ f) (ΞΌΟ-wconstant f) g : β₯ root f β₯ β fix (ΞΌΟ f) g = β₯β₯-recursion (fix-is-subsingleton (ΞΌΟ f) (ΞΌΟ-wconstant f)) Ξ³ h : fix (ΞΌΟ f) β root f h = from-fix (ΞΌΟ f) k : β₯ root f β₯ β root f k = h β g module find-β₯β₯-existing-root-example where f : β β β f 0 = 1 f 1 = 1 f 2 = 0 f 3 = 1 f 4 = 0 f 5 = 1 f 6 = 1 f 7 = 0 f (succ (succ (succ (succ (succ (succ (succ (succ x)))))))) = x root-β₯β₯-existence : β₯ root f β₯ root-β₯β₯-existence = β£ 8 , refl 0 β£ r : root f r = find-β₯β₯-existing-root f root-β₯β₯-existence x : β x = prβ r x-is-root : f x β‘ 0 x-is-root = prβ r NB : find-β₯β₯-existing-root f β‘ from-fix (ΞΌΟ f) β β₯β₯-recursion (fix-is-subsingleton (ΞΌΟ f) (ΞΌΟ-wconstant f)) (to-fix (ΞΌΟ f) (ΞΌΟ-wconstant f)) NB = refl _ p : x β‘ 2 p = ap (prβ β from-fix (ΞΌΟ f)) (β₯β₯-recursion-computation (fix-is-subsingleton (ΞΌΟ f) (ΞΌΟ-wconstant f)) (to-fix (ΞΌΟ f) (ΞΌΟ-wconstant f)) (8 , refl _)) wconstant-endomap-gives-β₯β₯-choice-function : {X : π€ Μ } β wconstant-endomap X β (β₯ X β₯ β X) wconstant-endomap-gives-β₯β₯-choice-function {π€} {X} (f , ΞΊ) = from-fix f β Ξ³ where Ξ³ : β₯ X β₯ β fix f Ξ³ = β₯β₯-recursion (fix-is-subsingleton f ΞΊ) (to-fix f ΞΊ) β₯β₯-choice-function-gives-wconstant-endomap : {X : π€ Μ } β (β₯ X β₯ β X) β wconstant-endomap X β₯β₯-choice-function-gives-wconstant-endomap {π€} {X} c = f , ΞΊ where f : X β X f = c β β£_β£ ΞΊ : wconstant f ΞΊ x y = ap c (β₯β₯-is-subsingleton β£ x β£ β£ y β£) β₯β₯-recursion-set : (X : π€ Μ ) (Y : π₯ Μ ) β is-set Y β (f : X β Y) β wconstant f β β₯ X β₯ β Y β₯β₯-recursion-set {π€} {π₯} X Y s f ΞΊ = f' where Ο : (y y' : Y) β (Ξ£ x κ X , f x β‘ y) β (Ξ£ x' κ X , f x' β‘ y') β y β‘ y' Ο y y' (x , r) (x' , r') = y β‘β¨ r β»ΒΉ β© f x β‘β¨ ΞΊ x x' β© f x' β‘β¨ r' β© y' β Ο : (y y' : Y) β (β x κ X , f x β‘ y) β (β x' κ X , f x' β‘ y') β y β‘ y' Ο y y' u u' = β₯β₯-recursion (s y y') (Ξ» - β β₯β₯-recursion (s y y') (Ο y y' -) u') u P : π€ β π₯ Μ P = image f i : is-subsingleton P i (y , u) (y' , u') = to-subtype-β‘ (Ξ» _ β β-is-subsingleton) (Ο y y' u u') g : β₯ X β₯ β P g = β₯β₯-recursion i (corestriction f) h : P β Y h = restriction f f' : β₯ X β₯ β Y f' = h β g