Martin Escardo, 9th April 2018

We first give Voevodsky's original proof that univalence implies
non-dependent, naive function extensionality, as presented by Gambino,
Kapulkin and Lumsdaine in
http://www.math.uwo.ca/faculty/kapulkin/notes/ua_implies_fe.pdf.

We then deduce dependent function extensionality applying a second
argument by Voevodsky, developed in another module, which doesn't
depend on univalence.

\begin{code}

{-# OPTIONS --safe --without-K #-}

module UF.UA-FunExt where

open import MLTT.Spartan
open import UF.Equiv
open import UF.FunExt
open import UF.FunExt-Properties
open import UF.LeftCancellable
open import UF.SubtypeClassifier
open import UF.Univalence

naive-univalence-gives-funext : is-univalent 𝓀 β†’ βˆ€ {π“₯} β†’ naive-funext π“₯ 𝓀
naive-univalence-gives-funext {𝓀} ua {π“₯} {X} {Y} {fβ‚€} {f₁} h = Ξ³
 where
  Ξ” = Ξ£ yβ‚€ κž‰ Y , Ξ£ y₁ κž‰ Y , yβ‚€ = y₁

  Ξ΄ : Y β†’ Ξ”
  Ξ΄ y = (y , y , refl)

  Ο€β‚€ π₁ : Ξ” β†’ Y
  Ο€β‚€ (yβ‚€ , y₁ , p) = yβ‚€
  π₁ (yβ‚€ , y₁ , p) = y₁

  Ξ΄-is-equiv : is-equiv Ξ΄
  Ξ΄-is-equiv = (Ο€β‚€ , Ξ·) , (Ο€β‚€ , Ξ΅)
   where
    Ξ· : (d : Ξ”) β†’ Ξ΄ (Ο€β‚€ d) = d
    Ξ· (yβ‚€ , y₁ , refl) = refl
    Ξ΅ : (y : Y) β†’ Ο€β‚€ (Ξ΄ y) = y
    Ξ΅ y = refl

  πδ : Ο€β‚€ ∘ Ξ΄ = π₁ ∘ Ξ΄
  πδ = refl

  Ο† : (Ξ” β†’ Y) β†’ (Y β†’ Y)
  Ο† Ο€ = Ο€ ∘ Ξ΄

  Ο†-is-equiv : is-equiv Ο†
  Ο†-is-equiv = pre-comp-is-equiv ua Ξ΄ Ξ΄-is-equiv

  Ο€β‚€-equals-π₁ : Ο€β‚€ = π₁
  Ο€β‚€-equals-π₁ = is-equiv-lc Ο† Ο†-is-equiv πδ

  Ξ³ : fβ‚€ = f₁
  Ξ³ = fβ‚€                              =⟨refl⟩
      (Ξ» x β†’ fβ‚€ x)                    =⟨refl⟩
      (Ξ» x β†’ Ο€β‚€ (fβ‚€ x , f₁ x , h x))  =⟨ I ⟩
      (Ξ» x β†’ π₁ (fβ‚€ x , f₁ x , h x))  =⟨refl⟩
      (Ξ» x β†’ f₁ x)                    =⟨refl⟩
      f₁                              ∎
       where
        I = ap (Ξ» Ο€ x β†’ Ο€ (fβ‚€ x , f₁ x , h x)) Ο€β‚€-equals-π₁

\end{code}

Added 19th May 2018:

\begin{code}

univalence-gives-funext : is-univalent 𝓀 β†’ funext 𝓀 𝓀
univalence-gives-funext ua = naive-funext-gives-funext
                              (naive-univalence-gives-funext ua)

\end{code}

Added 27 Jun 2018:

\begin{code}

univalence-gives-funext' : βˆ€ 𝓀 π“₯
                         β†’ is-univalent 𝓀
                         β†’ is-univalent (𝓀 βŠ” π“₯)
                         β†’ funext 𝓀 π“₯
univalence-gives-funext' 𝓀 π“₯ ua ua' = naive-funext-gives-funext'
                                       (naive-univalence-gives-funext ua')
                                       (naive-univalence-gives-funext ua)

Univalence-gives-FunExt : Univalence β†’ FunExt
Univalence-gives-FunExt ua 𝓀 π“₯ = univalence-gives-funext' 𝓀 π“₯
                                  (ua 𝓀)
                                  (ua (𝓀 βŠ” π“₯))

Univalence-gives-Fun-Ext : Univalence β†’ Fun-Ext
Univalence-gives-Fun-Ext ua {𝓀} {π“₯} = Univalence-gives-FunExt ua 𝓀 π“₯

funext-from-successive-univalence : βˆ€ 𝓀
                                  β†’ is-univalent 𝓀
                                  β†’ is-univalent (𝓀 ⁺)
                                  β†’ funext 𝓀 (𝓀 ⁺)
funext-from-successive-univalence 𝓀 = univalence-gives-funext' 𝓀 (𝓀 ⁺)

open import UF.Subsingletons

Ξ©-ext-from-univalence : is-univalent 𝓀
                      β†’ {p q : Ξ© 𝓀}
                      β†’ (p holds β†’ q holds)
                      β†’ (q holds β†’ p holds)
                      β†’ p = q
Ξ©-ext-from-univalence {𝓀} ua {p} {q} = Ξ©-extensionality
                                        (univalence-gives-propext ua)
                                        (univalence-gives-funext ua)
\end{code}

April 2020. How much function extensionality do we get from
propositional univalence?

\begin{code}

naive-prop-valued-funext : (𝓀 π“₯ : Universe) β†’ (𝓀 βŠ” π“₯)⁺ Μ‡
naive-prop-valued-funext 𝓀 π“₯ = (X : 𝓀 Μ‡ ) (Y : π“₯ Μ‡ )
                              β†’ is-prop Y
                              β†’ is-prop (X β†’ Y)

propositional-univalence : (𝓀 : Universe) β†’ 𝓀 ⁺ Μ‡
propositional-univalence 𝓀 = (P : 𝓀 Μ‡ )
                           β†’ is-prop P
                           β†’ (Y : 𝓀 Μ‡ ) β†’ is-equiv (idtoeq P Y)

prop-eqtoid : propositional-univalence 𝓀
            β†’ (P : 𝓀 Μ‡ )
            β†’ is-prop P
            β†’ (Y : 𝓀 Μ‡ )
            β†’ P ≃ Y β†’ P = Y
prop-eqtoid pu P i Y = inverse (idtoeq P Y) (pu P i Y)


propositional-≃-induction : (𝓀 π“₯ : Universe) β†’ (𝓀 βŠ” π“₯)⁺ Μ‡
propositional-≃-induction 𝓀 π“₯ = (P : 𝓀 Μ‡ )
                              β†’ is-prop P
                              β†’ (A : (Y : 𝓀 Μ‡ ) β†’ P ≃ Y β†’ π“₯ Μ‡ )
                              β†’ A P (≃-refl P) β†’ (Y : 𝓀 Μ‡ ) (e : P ≃ Y) β†’ A Y e

propositional-JEq : propositional-univalence 𝓀
                  β†’ (π“₯ : Universe)
                  β†’ propositional-≃-induction 𝓀 π“₯
propositional-JEq {𝓀} pu π“₯ P i A b Y e = Ξ³
 where
  A' : (Y : 𝓀 Μ‡ ) β†’ P = Y β†’ π“₯ Μ‡
  A' Y q = A Y (idtoeq P Y q)

  b' : A' P refl
  b' = b

  f' : (Y : 𝓀 Μ‡ ) (q : P = Y) β†’ A' Y q
  f' = Jbased P A' b'

  g : A Y (idtoeq P Y (prop-eqtoid pu P i Y e))
  g = f' Y (prop-eqtoid pu P i Y e)

  Ξ³ : A Y (id e)
  Ξ³ = transport (A Y) (inverses-are-sections (idtoeq P Y) (pu P i Y) e) g

prop-precomp-is-equiv : propositional-univalence 𝓀
                      β†’ (X Y Z : 𝓀 Μ‡ )
                      β†’ is-prop X
                      β†’ (f : X β†’ Y)
                      β†’ is-equiv f
                      β†’ is-equiv (Ξ» (g : Y β†’ Z) β†’ g ∘ f)
prop-precomp-is-equiv {𝓀} pu X Y Z i f ise =
 propositional-JEq pu 𝓀 X i (Ξ» W e β†’ is-equiv (Ξ» g β†’ g ∘ ⌜ e ⌝))
   (id-is-equiv (X β†’ Z)) Y (f , ise)

prop-precomp-is-equiv' : propositional-univalence 𝓀
                       β†’ (X Y Z : 𝓀 Μ‡ )
                       β†’ is-prop Y
                       β†’ (f : X β†’ Y)
                       β†’ is-equiv f
                       β†’ is-equiv (Ξ» (g : Y β†’ Z) β†’ g ∘ f)
prop-precomp-is-equiv' {𝓀} pu X Y Z i f ise =
 prop-precomp-is-equiv pu X Y Z j f ise
  where
   j : is-prop X
   j = equiv-to-prop (f , ise) i

propositional-univalence-gives-naive-prop-valued-funext
 : propositional-univalence 𝓀
 β†’ naive-prop-valued-funext π“₯ 𝓀
propositional-univalence-gives-naive-prop-valued-funext
 {𝓀} {π“₯} pu X Y Y-is-prop fβ‚€ f₁ = Ξ³
 where
  Ξ” : 𝓀 Μ‡
  Ξ” = Ξ£ yβ‚€ κž‰ Y , Ξ£ y₁ κž‰ Y , yβ‚€ = y₁

  Ξ΄ : Y β†’ Ξ”
  Ξ΄ y = (y , y , refl)

  Ο€β‚€ π₁ : Ξ” β†’ Y
  Ο€β‚€ (yβ‚€ , y₁ , p) = yβ‚€
  π₁ (yβ‚€ , y₁ , p) = y₁

  Ξ΄-is-equiv : is-equiv Ξ΄
  Ξ΄-is-equiv = (Ο€β‚€ , Ξ·) , (Ο€β‚€ , Ξ΅)
   where
    Ξ· : (d : Ξ”) β†’ Ξ΄ (Ο€β‚€ d) = d
    Ξ· (yβ‚€ , y₁ , refl) = refl

    Ξ΅ : (y : Y) β†’ Ο€β‚€ (Ξ΄ y) = y
    Ξ΅ y = refl

  πδ : Ο€β‚€ ∘ Ξ΄ = π₁ ∘ Ξ΄
  πδ = refl

  Ο† : (Ξ” β†’ Y) β†’ (Y β†’ Y)
  Ο† Ο€ = Ο€ ∘ Ξ΄

  Ο†-is-equiv : is-equiv Ο†
  Ο†-is-equiv = prop-precomp-is-equiv pu Y Ξ” Y Y-is-prop Ξ΄ Ξ΄-is-equiv

  Ο€β‚€-equals-π₁ : Ο€β‚€ = π₁
  Ο€β‚€-equals-π₁ = equivs-are-lc Ο† Ο†-is-equiv πδ

  Ξ³ : fβ‚€ = f₁
  Ξ³ = fβ‚€                              =⟨refl⟩
      (Ξ» x β†’ fβ‚€ x)                    =⟨refl⟩
      (Ξ» x β†’ Ο€β‚€ (fβ‚€ x , f₁ x , h x))  =⟨ I ⟩
      (Ξ» x β†’ π₁ (fβ‚€ x , f₁ x , h x))  =⟨refl⟩
      (Ξ» x β†’ f₁ x)                    =⟨refl⟩
      f₁                              ∎
   where
    h : (x : X) β†’ fβ‚€ x = f₁ x
    h x = Y-is-prop (fβ‚€ x) (f₁ x)

    I = ap (Ξ» Ο€ x β†’ Ο€ (fβ‚€ x , f₁ x , h x)) Ο€β‚€-equals-π₁

\end{code}