MGS.More-Exercise-Solutions
This is ported from the Midlands Graduate School 2019 lecture notes
https://www.cs.bham.ac.uk/~mhe/HoTT-UF.in-Agda-Lecture-Notes/HoTT-UF-Agda.html
https://github.com/martinescardo/HoTT-UF.Agda-Lecture-Notes
{-# OPTIONS --safe --without-K #-}
module MGS.More-Exercise-Solutions where
open import MGS.Classifiers public
open import MGS.Subsingleton-Truncation public
module โ-order-exercise-solution where
_โค'_ : โ โ โ โ ๐คโ ฬ
_โค'_ = โ-iteration (โ โ ๐คโ ฬ ) (ฮป y โ ๐)
(ฮป f โ โ-recursion (๐คโ ฬ ) ๐ (ฮป y P โ f y))
open โ-order
โค-and-โค'-coincide : (x y : โ) โ (x โค y) ๏ผ (x โค' y)
โค-and-โค'-coincide 0 y = refl _
โค-and-โค'-coincide (succ x) 0 = refl _
โค-and-โค'-coincide (succ x) (succ y) = โค-and-โค'-coincide x y
module โ-more where
open Arithmetic renaming (_+_ to _โ_)
open basic-arithmetic-and-order
โค-prop-valued : (x y : โ) โ is-subsingleton (x โค y)
โค-prop-valued 0 y = ๐-is-subsingleton
โค-prop-valued (succ x) zero = ๐-is-subsingleton
โค-prop-valued (succ x) (succ y) = โค-prop-valued x y
โผ-prop-valued : (x y : โ) โ is-subsingleton (x โผ y)
โผ-prop-valued x y (z , p) (z' , p') = ฮณ
where
q : z ๏ผ z'
q = +-lc x z z' (x โ z ๏ผโจ p โฉ
y ๏ผโจ p' โปยน โฉ
x โ z' โ)
ฮณ : z , p ๏ผ z' , p'
ฮณ = to-subtype-๏ผ (ฮป z โ โ-is-set (x โ z) y) q
โค-charac : propext ๐คโ โ (x y : โ) โ (x โค y) ๏ผ (x โผ y)
โค-charac pe x y = pe (โค-prop-valued x y) (โผ-prop-valued x y)
(โค-gives-โผ x y) (โผ-gives-โค x y)
the-subsingletons-are-the-subtypes-of-a-singleton : (X : ๐ค ฬ )
โ is-subsingleton X โ (X โช ๐)
the-subsingletons-are-the-subtypes-of-a-singleton X = ฯ , ฯ
where
i : is-subsingleton X โ is-embedding (!๐' X)
i s โ (x , refl โ) (y , refl โ) = ap (ฮป - โ - , refl โ) (s x y)
ฯ : is-subsingleton X โ X โช ๐
ฯ s = !๐ , i s
ฯ : X โช ๐ โ is-subsingleton X
ฯ (f , e) x y = d
where
a : x ๏ผ y โ f x ๏ผ f y
a = ap f {x} {y}
b : is-equiv a
b = embedding-gives-ap-is-equiv f e x y
c : f x ๏ผ f y
c = ๐-is-subsingleton (f x) (f y)
d : x ๏ผ y
d = inverse a b c
the-subsingletons-are-the-subtypes-of-a-singleton' : propext ๐ค โ global-dfunext
โ (X : ๐ค ฬ )
โ is-subsingleton X ๏ผ (X โช ๐)
the-subsingletons-are-the-subtypes-of-a-singleton' pe fe X = ฮณ
where
a : is-subsingleton X โ (X โช ๐)
a = the-subsingletons-are-the-subtypes-of-a-singleton X
b : is-subsingleton (X โช ๐)
b (f , e) (f' , e') = to-subtype-๏ผ
(being-embedding-is-subsingleton fe)
(fe (ฮป x โ ๐-is-subsingleton (f x) (f' x)))
ฮณ : is-subsingleton X ๏ผ (X โช ๐)
ฮณ = pe (being-subsingleton-is-subsingleton fe) b (prโ a) (prโ a)
Gโ-โ-equation : (ua : is-univalent (๐ค โ ๐ฅ))
โ (X : ๐ค ฬ )
โ (A : (ฮฃ Y ๊ ๐ค โ ๐ฅ ฬ , X โ Y) โ ๐ฆ ฬ )
โ (a : A (Lift ๐ฅ X , โ-Lift X))
โ Gโ-โ ua X A a (Lift ๐ฅ X) (โ-Lift X) ๏ผ a
Gโ-โ-equation {๐ค} {๐ฅ} {๐ฆ} ua X A a =
Gโ-โ ua X A a (Lift ๐ฅ X) (โ-Lift X) ๏ผโจ refl (transport A p a) โฉ
transport A p a ๏ผโจ ap (ฮป - โ transport A - a) q โฉ
transport A (refl t) a ๏ผโจ refl a โฉ
a โ
where
t : (ฮฃ Y ๊ ๐ค โ ๐ฅ ฬ , X โ Y)
t = (Lift ๐ฅ X , โ-Lift X)
p : t ๏ผ t
p = univalenceโ'' {๐ค} {๐ค โ ๐ฅ} ua X t t
q : p ๏ผ refl t
q = subsingletons-are-sets (ฮฃ Y ๊ ๐ค โ ๐ฅ ฬ , X โ Y)
(univalenceโ'' {๐ค} {๐ค โ ๐ฅ} ua X) t t p (refl t)
Hโ-โ-equation : (ua : is-univalent (๐ค โ ๐ฅ))
โ (X : ๐ค ฬ )
โ (A : (Y : ๐ค โ ๐ฅ ฬ ) โ X โ Y โ ๐ฆ ฬ )
โ (a : A (Lift ๐ฅ X) (โ-Lift X))
โ Hโ-โ ua X A a (Lift ๐ฅ X) (โ-Lift X) ๏ผ a
Hโ-โ-equation ua X A = Gโ-โ-equation ua X (ฮฃ-induction A)
has-section-charac : {X : ๐ค ฬ } {Y : ๐ฅ ฬ } (f : X โ Y)
โ ((y : Y) โ ฮฃ x ๊ X , f x ๏ผ y) โ has-section f
has-section-charac f = ฮ ฮฃ-distr-โ
retractions-into : ๐ค ฬ โ ๐ค โบ ฬ
retractions-into {๐ค} Y = ฮฃ X ๊ ๐ค ฬ , Y โ X
pointed-types : (๐ค : Universe) โ ๐ค โบ ฬ
pointed-types ๐ค = ฮฃ X ๊ ๐ค ฬ , X
retraction-classifier : Univalence
โ (Y : ๐ค ฬ ) โ retractions-into Y โ (Y โ pointed-types ๐ค)
retraction-classifier {๐ค} ua Y =
retractions-into Y โโจ i โฉ
(ฮฃ X ๊ ๐ค ฬ , ฮฃ f ๊ (X โ Y) , ((y : Y) โ ฮฃ x ๊ X , f x ๏ผ y)) โโจ id-โ _ โฉ
((๐ค /[ id ] Y)) โโจ ii โฉ
(Y โ pointed-types ๐ค) โ
where
i = โ-sym (ฮฃ-cong (ฮป X โ ฮฃ-cong (ฮป f โ ฮ ฮฃ-distr-โ)))
ii = special-map-classifier (ua ๐ค)
(univalence-gives-dfunext' (ua ๐ค) (ua (๐ค โบ)))
id Y
module surjection-classifier
(pt : subsingleton-truncations-exist)
(ua : Univalence)
where
hfe : global-hfunext
hfe = univalence-gives-global-hfunext ua
open basic-truncation-development pt hfe public
_โ _ : ๐ค ฬ โ ๐ฅ ฬ โ ๐ค โ ๐ฅ ฬ
X โ Y = ฮฃ f ๊ (X โ Y), is-surjection f
surjections-into : ๐ค ฬ โ ๐ค โบ ฬ
surjections-into {๐ค} Y = ฮฃ X ๊ ๐ค ฬ , X โ Y
inhabited-types : (๐ค : Universe) โ ๐ค โบ ฬ
inhabited-types ๐ค = ฮฃ X ๊ ๐ค ฬ , โฅ X โฅ
surjection-classifier : Univalence
โ (Y : ๐ค ฬ )
โ surjections-into Y โ (Y โ inhabited-types ๐ค)
surjection-classifier {๐ค} ua = special-map-classifier (ua ๐ค)
(univalence-gives-dfunext' (ua ๐ค) (ua (๐ค โบ)))
โฅ_โฅ
positive-cantors-diagonal : (e : โ โ (โ โ โ)) โ ฮฃ ฮฑ ๊ (โ โ โ), ((n : โ) โ ฮฑ โ e n)
cantors-diagonal : ยฌ (ฮฃ e ๊ (โ โ (โ โ โ)) , ((ฮฑ : โ โ โ) โ ฮฃ n ๊ โ , ฮฑ ๏ผ e n))
๐-has-๐-automorphisms : dfunext ๐คโ ๐คโ โ (๐ โ ๐) โ ๐
lifttwo : is-univalent ๐คโ โ is-univalent ๐คโ โ (๐ ๏ผ ๐) ๏ผ Lift ๐คโ ๐
DNE : โ ๐ค โ ๐ค โบ ฬ
DNE ๐ค = (P : ๐ค ฬ ) โ is-subsingleton P โ ยฌยฌ P โ P
ne : (X : ๐ค ฬ ) โ ยฌยฌ (X + ยฌ X)
DNE-gives-EM : dfunext ๐ค ๐คโ โ DNE ๐ค โ EM ๐ค
EM-gives-DNE : EM ๐ค โ DNE ๐ค
SN : โ ๐ค โ ๐ค โบ ฬ
SN ๐ค = (P : ๐ค ฬ ) โ is-subsingleton P โ ฮฃ X ๊ ๐ค ฬ , P โ ยฌ X
SN-gives-DNE : SN ๐ค โ DNE ๐ค
DNE-gives-SN : DNE ๐ค โ SN ๐ค
succ-no-fixed-point : (n : โ) โ succ n โ n
succ-no-fixed-point 0 = positive-not-zero 0
succ-no-fixed-point (succ n) = ฮณ
where
IH : succ n โ n
IH = succ-no-fixed-point n
ฮณ : succ (succ n) โ succ n
ฮณ p = IH (succ-lc p)
positive-cantors-diagonal = sol
where
sol : (e : โ โ (โ โ โ)) โ ฮฃ ฮฑ ๊ (โ โ โ), ((n : โ) โ ฮฑ โ e n)
sol e = (ฮฑ , ฯ)
where
ฮฑ : โ โ โ
ฮฑ n = succ (e n n)
ฯ : (n : โ) โ ฮฑ โ e n
ฯ n p = succ-no-fixed-point (e n n) q
where
q = succ (e n n) ๏ผโจ refl (ฮฑ n) โฉ
ฮฑ n ๏ผโจ ap (ฮป - โ - n) p โฉ
e n n โ
cantors-diagonal = sol
where
sol : ยฌ (ฮฃ e ๊ (โ โ (โ โ โ)) , ((ฮฑ : โ โ โ) โ ฮฃ n ๊ โ , ฮฑ ๏ผ e n))
sol (e , ฮณ) = c
where
ฮฑ : โ โ โ
ฮฑ = prโ (positive-cantors-diagonal e)
ฯ : (n : โ) โ ฮฑ โ e n
ฯ = prโ (positive-cantors-diagonal e)
b : ฮฃ n ๊ โ , ฮฑ ๏ผ e n
b = ฮณ ฮฑ
c : ๐
c = ฯ (prโ b) (prโ b)
๐-has-๐-automorphisms = sol
where
sol : dfunext ๐คโ ๐คโ โ (๐ โ ๐) โ ๐
sol fe = invertibility-gives-โ f (g , ฮท , ฮต)
where
f : (๐ โ ๐) โ ๐
f (h , e) = h โ
g : ๐ โ (๐ โ ๐)
g โ = id , id-is-equiv ๐
g โ = swapโ , swapโ-is-equiv
ฮท : (e : ๐ โ ๐) โ g (f e) ๏ผ e
ฮท (h , e) = ฮณ (h โ) (h โ) (refl (h โ)) (refl (h โ))
where
ฮณ : (m n : ๐) โ h โ ๏ผ m โ h โ ๏ผ n โ g (h โ) ๏ผ (h , e)
ฮณ โ โ p q = !๐ (g (h โ) ๏ผ (h , e))
(โ-is-not-โ (equivs-are-lc h e (h โ ๏ผโจ q โฉ
โ ๏ผโจ p โปยน โฉ
h โ โ)))
ฮณ โ โ p q = to-subtype-๏ผ
(being-equiv-is-subsingleton fe fe)
(fe (๐-induction (ฮป n โ prโ (g (h โ)) n ๏ผ h n)
(prโ (g (h โ)) โ ๏ผโจ ap (ฮป - โ prโ (g -) โ) p โฉ
prโ (g โ) โ ๏ผโจ refl โ โฉ
โ ๏ผโจ p โปยน โฉ
h โ โ)
(prโ (g (h โ)) โ ๏ผโจ ap (ฮป - โ prโ (g -) โ) p โฉ
prโ (g โ) โ ๏ผโจ refl โ โฉ
โ ๏ผโจ q โปยน โฉ
h โ โ)))
ฮณ โ โ p q = to-subtype-๏ผ
(being-equiv-is-subsingleton fe fe)
(fe (๐-induction (ฮป n โ prโ (g (h โ)) n ๏ผ h n)
(prโ (g (h โ)) โ ๏ผโจ ap (ฮป - โ prโ (g -) โ) p โฉ
prโ (g โ) โ ๏ผโจ refl โ โฉ
โ ๏ผโจ p โปยน โฉ
h โ โ)
(prโ (g (h โ)) โ ๏ผโจ ap (ฮป - โ prโ (g -) โ) p โฉ
prโ (g โ) โ ๏ผโจ refl โ โฉ
โ ๏ผโจ q โปยน โฉ
h โ โ)))
ฮณ โ โ p q = !๐ (g (h โ) ๏ผ (h , e))
(โ-is-not-โ (equivs-are-lc h e (h โ ๏ผโจ q โฉ
โ ๏ผโจ p โปยน โฉ
h โ โ)))
ฮต : (n : ๐) โ f (g n) ๏ผ n
ฮต โ = refl โ
ฮต โ = refl โ
lifttwo = sol
where
sol : is-univalent ๐คโ โ is-univalent ๐คโ โ (๐ ๏ผ ๐) ๏ผ Lift ๐คโ ๐
sol uaโ uaโ = EqโId uaโ (๐ ๏ผ ๐) (Lift ๐คโ ๐) e
where
e = (๐ ๏ผ ๐) โโจ IdโEq ๐ ๐ , uaโ ๐ ๐ โฉ
(๐ โ ๐) โโจ ๐-has-๐-automorphisms (univalence-gives-dfunext uaโ) โฉ
๐ โโจ โ-sym (Lift-โ ๐) โฉ
Lift ๐คโ ๐ โ
hde-is-subsingleton : dfunext ๐ค ๐คโ
โ dfunext ๐ค ๐ค
โ (X : ๐ค ฬ )
โ is-subsingleton (has-decidable-equality X)
hde-is-subsingleton feโ fe X h h' = c h h'
where
a : (x y : X) โ is-subsingleton (decidable (x ๏ผ y))
a x y = +-is-subsingleton' feโ b
where
b : is-subsingleton (x ๏ผ y)
b = hedberg h x y
c : is-subsingleton (has-decidable-equality X)
c = ฮ -is-subsingleton fe (ฮป x โ ฮ -is-subsingleton fe (a x))
ne = sol
where
sol : (X : ๐ค ฬ ) โ ยฌยฌ (X + ยฌ X)
sol X = ฮป (f : ยฌ (X + ยฌ X)) โ f (inr (ฮป (x : X) โ f (inl x)))
DNE-gives-EM = sol
where
sol : dfunext ๐ค ๐คโ โ DNE ๐ค โ EM ๐ค
sol fe dne P i = dne (P + ยฌ P) (+-is-subsingleton' fe i) (ne P)
EM-gives-DNE = sol
where
sol : EM ๐ค โ DNE ๐ค
sol em P i = ฮณ (em P i)
where
ฮณ : P + ยฌ P โ ยฌยฌ P โ P
ฮณ (inl p) ฯ = p
ฮณ (inr n) ฯ = !๐ P (ฯ n)
SN-gives-DNE = sol
where
sol : SN ๐ค โ DNE ๐ค
sol {๐ค} sn P i = h
where
X : ๐ค ฬ
X = prโ (sn P i)
f : P โ ยฌ X
f = prโ (prโ (sn P i))
g : ยฌ X โ P
g = prโ (prโ (sn P i))
f' : ยฌยฌ P โ ยฌ (ยฌยฌ X)
f' = contrapositive (contrapositive f)
h : ยฌยฌ P โ P
h = g โ tno X โ f'
h' : ยฌยฌ P โ P
h' ฯ = g (ฮป (x : X) โ ฯ (ฮป (p : P) โ f p x))
DNE-gives-SN = sol
where
sol : DNE ๐ค โ SN ๐ค
sol dne P i = ยฌ P , dni P , dne P i