{-# OPTIONS --cubical --no-import-sorts --safe #-}
module Cubical.HITs.PropositionalTruncation.MagicTrick where
open import Cubical.Foundations.Prelude
open import Cubical.Foundations.Function
open import Cubical.Foundations.Path
open import Cubical.Foundations.Pointed
open import Cubical.Foundations.Pointed.Homogeneous
open import Cubical.HITs.PropositionalTruncation.Base
open import Cubical.HITs.PropositionalTruncation.Properties
module Recover {ℓ} (A∙ : Pointed ℓ) (h : isHomogeneous A∙) where
private
A = typ A∙
a = pt A∙
toEquivPtd : ∥ A ∥ → Σ[ B∙ ∈ Pointed ℓ ] (A , a) ≡ B∙
toEquivPtd = rec isPropSingl (λ x → (A , x) , h x)
private
B∙ : ∥ A ∥ → Pointed ℓ
B∙ tx = fst (toEquivPtd tx)
private
obvs : ∀ x → B∙ ∣ x ∣ ≡ (A , x)
obvs x = refl
recover : ∀ (tx : ∥ A ∥) → typ (B∙ tx)
recover tx = pt (B∙ tx)
recover∣∣ : ∀ (x : A) → recover ∣ x ∣ ≡ x
recover∣∣ x = refl
private
obvs2 : A → A
obvs2 = recover ∘ ∣_∣
recover-squash : ∀ x y →
PathP (λ i → typ (B∙ (squash ∣ x ∣ ∣ y ∣ i))) x y
recover-squash x y = cong recover (squash ∣ x ∣ ∣ y ∣)
private
open import Cubical.Data.Nat
open Recover (ℕ , zero) (isHomogeneousDiscrete discreteℕ)
module _ where
private
hidden : ℕ
hidden = 17
∣hidden∣ : ∥ ℕ ∥
∣hidden∣ = ∣ hidden ∣
test : recover ∣hidden∣ ≡ 17
test = refl