\begin{code}
{-# OPTIONS --without-K #-}
module hsetfunext where
open import tiny-library
open import hprop-truncation
module extensionality-discussion where
truncation-rec-rec : {X Y P : Type} → hprop P → (X → Y → P) → ∥ X ∥ → ∥ Y ∥ → P
truncation-rec-rec {X} {Y} {P} h f u v = truncation-rec h (λ x → truncation-rec h (f x) v) u
hset-truncation-rec : {X Y : Type} → hset Y → (f : X → Y) → constant f → ∥ X ∥ → Y
hset-truncation-rec {X} {Y} hs f c u = π₀(F u)
where
ψ : (y y' : Y) → (Σ \x → f x ≡ y) → (Σ \x' → f x' ≡ y') → y ≡ y'
ψ y y' (x , r) (x' , r') = r ⁻¹ • c x x' • r'
P : Type
P = Σ \(y : Y) → ∥ (Σ \x → f x ≡ y) ∥
P-hprop : hprop P
P-hprop (y , u) (y' , u') = Σ-≡ {Y} {λ y → ∥ (Σ \x → f x ≡ y) ∥} y y' u u' p (truncation-path (transport p u) u')
where
p : y ≡ y'
p = truncation-rec-rec (hs y y') (ψ y y') u u'
F : ∥ X ∥ → P
F = truncation-rec P-hprop (λ x → f x , ∣ (x , refl) ∣)
extension-property : {X Y : Type} (hs : hset Y) (f : X → Y) (c : constant f) (x : X)
→ hset-truncation-rec hs f c ∣ x ∣ ≡ f x
extension-property hs f c x = refl
hset-funext : {X : Type} {Y : X → Type} → ((x : X) → hset(Y x)) → {f g : (x : X) → Y x}
→ ((x : X) → f x ≡ g x) → f ≡ g
hset-funext {X} {Y} hs {f} {g} φ = ap H' (truncation-path ∣ ₀ ∣ ∣ ₁ ∣)
where
h : (x : X) → ₂ → Y x
h x ₀ = f x
h x ₁ = g x
hx-constant : (x : X) → constant(h x)
hx-constant x ₀ ₀ = refl
hx-constant x ₀ ₁ = φ x
hx-constant x ₁ ₀ = (φ x)⁻¹
hx-constant x ₁ ₁ = refl
H : (x : X) → ∥ ₂ ∥ → Y x
H x = hset-truncation-rec (hs x) (h x) (hx-constant x)
H' : ∥ ₂ ∥ → (x : X) → Y x
H' n x = H x n
\end{code}
\begin{code}
hprop-funext : {X : Type} {P : X → Type} → ((x : X) → hprop(P x)) → {f g : (x : X) → P x}
→ ((x : X) → f x ≡ g x) → f ≡ g
hprop-funext {X} {P} hp {f} {g} φ = ap H' (truncation-path ∣ ₀ ∣ ∣ ₁ ∣)
where
h : (x : X) → ₂ → P x
h x ₀ = f x
h x ₁ = g x
H : (x : X) → ∥ ₂ ∥ → P x
H x = truncation-rec (hp x) (h x)
H' : ∥ ₂ ∥ → (x : X) → P x
H' n x = H x n
\end{code}
\begin{code}
contractible-closed-under-Π : {X : Type} {P : X → Type} → ((x : X) → contractible(P x)) → contractible((x : X) → P x)
contractible-closed-under-Π {X} {P} φ =
ψ , (λ ψ' → hprop-funext (λ x p p' → (c x p)⁻¹ • (c x p')) {ψ} {ψ'} (λ x → c x (ψ' x)))
where
ψ : (x : X) → P x
ψ x = π₀(φ x)
c : (x : X) → (p : P x) → ψ x ≡ p
c x = π₁(φ x)
\end{code}
\begin{code}
funext : {X : Type} {Y : X → Type} → {f g : (x : X) → Y x}
→ ((x : X) → f x ≡ g x) → f ≡ g
funext {X} {Y} {f} {g} φ = ap (λ H x → π₀(H x)) e
where
P : X → Type
P x = Σ \(y : Y x) → f x ≡ y
u : (x : X) (p : P x) → (f x , refl) ≡ p
u _ (_ , r) = path-from-trivial-loop r
c : ((x : X) → contractible(P x))
c x = (f x , refl) , u x
d : contractible((x : X) → P x)
d = contractible-closed-under-Π c
F : (x : X) → P x
F = π₀ d
G : (x : X) → P x
G x = g x , φ x
e : F ≡ G
e = π₁ d G
\end{code}
\begin{code}
hprop-hprop : {X : Type} → hprop(hprop X)
hprop-hprop {X} f g = funext q
where
h : hset X
h = hprop-is-hset f
p : (x y : X) → f x y ≡ g x y
p x y = h x y (f x y) (g x y)
q : (x : X) → f x ≡ g x
q x = funext (p x)
\end{code}
\begin{code}
module interval where
I : Type
I = ∥ ₂ ∥
seg : ∣ ₀ ∣ ≡ ∣ ₁ ∣
seg = truncation-path ∣ ₀ ∣ ∣ ₁ ∣
I-hset : hset I
I-hset = hprop-is-hset truncation-path
\end{code}
\begin{code}
I-rec' : {X : Type} {x₀ x₁ : X} → x₀ ≡ x₁ → I → paths-from x₀
I-rec' {X} {x₀} {x₁} p = truncation-rec (paths-from-is-hprop x₀) f
where
f : ₂ → paths-from x₀
f ₀ = trivial-loop x₀
f ₁ = x₁ , p
I-rec : {X : Type} {x₀ x₁ : X} → x₀ ≡ x₁ → I → X
I-rec p i = end-point(I-rec' p i)
\end{code}
\begin{code}
I-rec-equation₀ : {X : Type} {x₀ x₁ : X} (p : x₀ ≡ x₁) → I-rec p ∣ ₀ ∣ ≡ x₀
I-rec-equation₀ p = refl
I-rec-equation₁ : {X : Type} {x₀ x₁ : X} (p : x₀ ≡ x₁) → I-rec p ∣ ₁ ∣ ≡ x₁
I-rec-equation₁ p = refl
\end{code}
\begin{code}
I-rec-seg-equation-base : {X : Type} {x : X} → ap (I-rec refl) seg ≡ refl
I-rec-seg-equation-base {X} {x} = r ⁻¹ • q
where
p : ap (I-rec' refl) seg ≡ refl {paths-from x} {trivial-loop x}
p = paths-from-is-hset x (I-rec' refl ∣ ₀ ∣) (trivial-loop x) (ap (I-rec' refl) seg) refl
q : ap end-point (ap (I-rec' refl) seg) ≡ refl
q = ap (ap end-point) p
r : ap end-point (ap (I-rec' refl) seg) ≡ ap (I-rec refl) seg
r = ap-functorial (I-rec' refl) end-point seg
I-rec-seg-equation : {X : Type} {x₀ x₁ : X} (p : x₀ ≡ x₁) → ap (I-rec p) seg ≡ p
I-rec-seg-equation refl = I-rec-seg-equation-base
\end{code}
\begin{code}
funext-from-interval : {X Y : Type} {f g : X → Y} → ((x : X) -> f x ≡ g x) → f ≡ g
funext-from-interval {X} {Y} h = ap I-X-family seg
where
X-I-family : X → I → Y
X-I-family x = I-rec (h x)
I-X-family : I → X → Y
I-X-family i x = X-I-family x i
\end{code}
\begin{code}
module I-induction (A : I → Type) where
T : {i j : I} → i ≡ j → A i → A j
T = transport {I} {A}
I-ind' : {a₀ : A ∣ ₀ ∣} {a₁ : A ∣ ₁ ∣} → T seg a₀ ≡ a₁ → I → Σ \(i : I) → A i
I-ind' {a₀} {a₁} r = I-rec p
where
x₀ x₁ : Σ \(i : I) → A i
x₀ = ∣ ₀ ∣ , a₀
x₁ = ∣ ₁ ∣ , a₁
p : x₀ ≡ x₁
p = Σ-≡ ∣ ₀ ∣ ∣ ₁ ∣ a₀ a₁ seg r
I-ind-path : {a₀ : A ∣ ₀ ∣} {a₁ : A ∣ ₁ ∣} → (p : T seg a₀ ≡ a₁) → (i : I) → π₀(I-ind' p i) ≡ i
I-ind-path p = truncation-ind h g
where
h : (i : I) → hprop(π₀(I-ind' p i) ≡ i)
h i = I-hset (π₀(I-ind' p i)) i
g : (n : ₂) → π₀(I-ind' p ∣ n ∣) ≡ ∣ n ∣
g ₀ = refl
g ₁ = refl
I-ind : {a₀ : A ∣ ₀ ∣} {a₁ : A ∣ ₁ ∣} → T seg a₀ ≡ a₁ → (i : I) → A i
I-ind p i = T (I-ind-path p i) (π₁(I-ind' p i))
I-ind-equation₀ : {a₀ : A ∣ ₀ ∣} {a₁ : A ∣ ₁ ∣} (p : T seg a₀ ≡ a₁) → I-ind p ∣ ₀ ∣ ≡ a₀
I-ind-equation₀ p = refl
I-ind-equation₁ : {a₀ : A ∣ ₀ ∣} {a₁ : A ∣ ₁ ∣} (p : T seg a₀ ≡ a₁) → I-ind p ∣ ₁ ∣ ≡ a₁
I-ind-equation₁ p = refl
\end{code}
\begin{code}
trivial-Loop : {X : Type} (x : X) → I → X
trivial-Loop x i = x
I-rec-refl-is-trivial-Loop : {X : Type} {x : X} → I-rec refl ≡ trivial-Loop x
I-rec-refl-is-trivial-Loop {X} {x} = funext g
where
open extensionality-discussion
P : I → Type
P i = I-rec' refl i ≡ trivial-loop x
H : (i : I) → hprop(P i)
H i = paths-from-is-hset x (I-rec' refl i) (trivial-loop x)
f : (n : ₂) → I-rec' refl ∣ n ∣ ≡ trivial-loop x
f ₀ = refl
f ₁ = refl
f' : (i : I) → I-rec' refl i ≡ trivial-loop x
f' = truncation-ind H f
g : (i : I) → I-rec refl i ≡ x
g i = ap end-point (f' i)
\end{code}
\begin{code}
module factor-constant where
\end{code}
\begin{code}
propositional-factorization : {X Y : Type} (x₀ : X) (f : X → Y) → constant f → ∥ X ∥ → Y
propositional-factorization x₀ f _ _ = f x₀
\end{code}
\begin{code}
propositional-factorization-equation : {X Y : Type} (x₀ : X) (f : X → Y) (c : constant f) (x : X)
→ propositional-factorization x₀ f c (∣ x ∣) ≡ f x
propositional-factorization-equation x₀ f c x = c x₀ x
\end{code}
\begin{code}
judgemental-factorization : {X Y : Type} (x₀ : X) (f : X → Y) → constant f → ∥ X ∥ → Y
judgemental-factorization {X} {Y} x₀ f c s = end-point(g' s)
where
g : X → paths-from(f x₀)
g x = f x , c x₀ x
g' : ∥ X ∥ → paths-from(f x₀)
g' = truncation-rec (paths-from-is-hprop (f x₀)) g
judgemental-factorization-equation : {X Y : Type} (x₀ : X) (f : X → Y) (c : constant f)
→ (judgemental-factorization x₀ f c) ∘ ∣_∣ ≡ f
judgemental-factorization-equation x₀ f c = refl
\end{code}
\begin{code}
factorizable : {X Y : Type} (f : X → Y) → Type
factorizable {X} {Y} f = Σ \( f' : ∥ X ∥ → Y) → (x : X) → f' ∣ x ∣ ≡ f x
observation : {X Y : Type} (f : X → Y) → (∥ X ∥ → factorizable f) → factorizable f
observation {X} {Y} f F = f' , e
where
f' : ∥ X ∥ → Y
f' s = π₀ (F s) s
e : (x : X) → f' ∣ x ∣ ≡ f x
e x = π₁ (F ∣ x ∣) x
factors-through : {X X' Y : Type} → (X → X') → (X → Y) → Type
factors-through {X} {X'} {Y} g f = Σ \( f' : X' → Y) → (x : X) → f'(g x) ≡ f x
observation-bis : {X X' Y : Type} (g : X → X') (f : X → Y) → (X' → factors-through g f) → factors-through g f
observation-bis {X} {X'} {Y} g f F = f' , e
where
f' : X' → Y
f' s = π₀ (F s) s
e : (x : X) → f'(g x) ≡ f x
e x = π₁ (F(g x)) x
\end{code}
\begin{code}
constant-valued : {X Y : Type} → (f : X → Y) → Type
constant-valued {X} {Y} f = Σ \(y : Y) → (x : X) → y ≡ f x
observation' : {X Y : Type} (f : X → Y) → factorizable f → ∥ X ∥ → constant-valued f
observation' f (f' , e) s = f' s , (λ x → ap f' (truncation-path s ∣ x ∣) • e x)
constant-valued-factorization : {X Y : Type} (f : X → Y) → constant-valued f → ∥ X ∥ → Y
constant-valued-factorization {X} {Y} f (y , φ) s = end-point(g' s)
where
g : X → paths-from y
g x = f x , φ x
g' : ∥ X ∥ → paths-from y
g' = truncation-rec (paths-from-is-hprop y) g
constant-valued-factorization-equation : {X Y : Type} (f : X → Y) (c : constant-valued f)
→ (constant-valued-factorization f c) ∘ ∣_∣ ≡ f
constant-valued-factorization-equation f c = refl
\end{code}
\begin{code}
hstable : Type → Type
hstable X = ∥ X ∥ → X
hstable-factorization : {X Y : Type} → hstable X → (f : X → Y) → constant f → ∥ X ∥ → Y
hstable-factorization h f c s = judgemental-factorization (h s) f c s
hstable-factorization-equation : {X Y : Type} (h : hstable X) (f : X → Y) (c : constant f)
→ (hstable-factorization h f c) ∘ ∣_∣ ≡ f
hstable-factorization-equation h f c = refl
\end{code}
\begin{code}
judgementalize : {X Y : Type} → (f : X → Y) → factorizable f → ∥ X ∥ → Y
judgementalize f fa s = constant-valued-factorization f (observation' f fa s) s
judgementalize-equation : {X Y : Type} (f : X → Y) (fa : factorizable f)
→ (judgementalize f fa) ∘ ∣_∣ ≡ f
judgementalize-equation f fa = refl
judgementalization : {X Y : Type} → (f : X → Y) → factorizable f → factorizable f
judgementalization f fa = judgementalize f fa , λ x → refl
\end{code}
\begin{code}
judgementalize-bis' : {X Y : Type} (f : X → Y) (f' : ∥ X ∥ → Y) (e : (x : X) → f' ∣ x ∣ ≡ f x)
→ (s : ∥ X ∥) → paths-from(f' s)
judgementalize-bis' {X} {Y} f f' e s = g' s
where
φ : (x : X) → f' s ≡ f x
φ x = ap f' (truncation-path s ∣ x ∣) • e x
g : X → paths-from(f' s)
g x = f x , φ x
g' : ∥ X ∥ → paths-from(f' s)
g' = truncation-rec (paths-from-is-hprop(f' s)) g
judgementalize-bis : {X Y : Type} → (f : X → Y) → factorizable f → ∥ X ∥ → Y
judgementalize-bis {X} {Y} f (f' , e) s = π₀(judgementalize-bis' f f' e s)
judgementalize-same-as-judgementalize-bis : {X Y : Type} → judgementalize {X} {Y} ≡ judgementalize-bis {X} {Y}
judgementalize-same-as-judgementalize-bis = refl
\end{code}
\begin{code}
Constant : {X Y : Type} (f : X → Y) → Type
Constant {X} f = ∥ X ∥ → constant-valued f
fact-charac₀ : {X Y : Type} (f : X → Y) → factorizable f → Constant f
fact-charac₀ f (f' , φ) s = (f' s) , (λ x → ap f' (truncation-path s ∣ x ∣) • φ x)
fact-charac₁ : {X Y : Type} (f : X → Y) → Constant f → factorizable f
fact-charac₁ f C = (λ s → π₀ (C s)) , (λ x → π₁ (C ∣ x ∣) x)
\end{code}