{-# OPTIONS --safe #-}
module Cubical.Foundations.Equiv.Base where
open import Cubical.Foundations.Function
open import Cubical.Foundations.Prelude
open import Cubical.Core.Glue public
using ( isEquiv ; equiv-proof ; _≃_ ; equivFun ; equivProof )
fiber : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} (f : A → B) (y : B) → Type (ℓ-max ℓ ℓ')
fiber {A = A} f y = Σ[ x ∈ A ] f x ≡ y
strictContrFibers : ∀ {ℓ ℓ'} {A : Type ℓ} {B : Type ℓ'} {f : A → B} (g : B → A) (b : B)
→ Σ[ t ∈ fiber f (f (g b)) ]
((t' : fiber f b) → Path (fiber f (f (g b))) t (g (f (t' .fst)) , cong (f ∘ g) (t' .snd)))
strictContrFibers {f = f} g b .fst = (g b , refl)
strictContrFibers {f = f} g b .snd (a , p) i = (g (p (~ i)) , λ j → f (g (p (~ i ∨ j))))
idIsEquiv : ∀ {ℓ} (A : Type ℓ) → isEquiv (idfun A)
idIsEquiv A .equiv-proof = strictContrFibers (idfun A)
idEquiv : ∀ {ℓ} (A : Type ℓ) → A ≃ A
idEquiv A .fst = idfun A
idEquiv A .snd = idIsEquiv A
isEquiv' : ∀ {ℓ}{ℓ'}{A : Type ℓ}{B : Type ℓ'} → (A → B) → Type (ℓ-max ℓ ℓ')
isEquiv' {B = B} f = (y : B) → isContr (fiber f y)
isEquivTransp : ∀ {ℓ : I → Level} (A : (i : I) → Type (ℓ i)) → ∀ (φ : I) → isEquiv (transp (λ j → A (φ ∨ j)) φ)
isEquivTransp A φ = u₁ where
coei→1 : A φ → A i1
coei→1 = transp (λ j → A (φ ∨ j)) φ
γ : (k : I) → Type _
γ k = isEquiv (transp (λ j → A (φ ∨ (j ∧ k))) (φ ∨ ~ k))
_ : γ i0 ≡ isEquiv (idfun (A φ))
_ = refl
_ : γ i1 ≡ isEquiv coei→1
_ = refl
u₀ : γ i0
u₀ = idIsEquiv (A φ)
u₁ : γ i1
u₁ = transp γ φ u₀
transpEquiv : ∀ {ℓ : I → Level} (A : (i : I) → Type (ℓ i)) → ∀ φ → A φ ≃ A i1
transpEquiv A φ .fst = transp (λ j → A (φ ∨ j)) φ
transpEquiv A φ .snd = isEquivTransp A φ