open import 1Lab.HLevel
open import 1Lab.Equiv
open import 1Lab.Path
open import 1Lab.Type

module 1Lab.Equiv.FromPath {β„“} (P : (i : I) β†’ Type β„“) where

Equivs from PathsπŸ”—

In Cubical Type Theory: a constructive interpretation of the univalence axiom, Cohen et. al. give a direct cubical construction of an equivalence A ≃ B from a path A ≑ B. This is in contrast with the indirect definition, transporting the identity equivalence along the path:

private
  badPathToEquiv : P i0 ≃ P i1
  badPathToEquiv = transport (Ξ» i β†’ P i0 ≃ P i) (id , id-equiv)

While is-equiv is a proposition – and thus the particular proof does not matter propositionally – Agda is still a programming language, so we still need to evaluate the proof. Cohen et. al.’s construction gives a much shorter normal form for lineβ†’equiv.

private
  ~P : (i : I) β†’ Type β„“
  ~P = Ξ» i β†’ P (~ i)

  A B : Type β„“
  A = P i0
  B = P i1

The construction begins by giving the endpoints of P – and the inverse of P – better names. We do the same for transports along P and ~P:

  f : A β†’ B
  f x = coe0β†’1 P x

  g : B β†’ A
  g y = coe1β†’0 P y

Since f and g are defined by coercion along a path, we can define fillers u and v connecting f (resp g) to the identity function, over P:

  u : PathP (Ξ» i β†’ A β†’ P i) id f
  u i x = coe0β†’i P i x

  v : PathP (Ξ» i β†’ B β†’ P i) g id
  v i y = coe1β†’i P i y

To prove that f is an equivalence, by definition, it must have contractible fibres. It suffices to show that the fibre over y is inhabited, and that the fibre over y is a proposition.

To prove that the fibre over y is inhabited, we take g y to be the preimage, and prove that there is a path f (g y) ≑ y, as we are required to do. For this, we use the β€œlid” (the dotted face) of the square below (this is the comp term):

  hasFib : (y : B) β†’ fibre f y
  hasFib y .fst = g y
  hasFib y .snd i = comp P (Ξ» j β†’ Ξ» { (i = i1) β†’ v j y
                                    ; (i = i0) β†’ u j (g y) })
                           (g y)

To prove that the fibre over y is propositional, there is significantly more work involved. Especially since all of the paths involved are dependent, and thus none of the path operations (especially sym!) apply. We begin by stating the types of what we’re going to construct:

  fibProp : (y : B) β†’ is-prop (fibre f y)
  fibProp y (xβ‚€ , Ξ²β‚€) (x₁ , β₁) k = Ο‰ k , Ξ» j β†’ Ξ΄ k (~ j) where
    Ο‰ : xβ‚€ ≑ x₁
    Ξ΄ : Square refl (sym Ξ²β‚€) (sym β₁) (ap f Ο‰)

While Ο‰ is a line, Ξ΄ is a square. Namely, by looking at its type, we see that its boundary is the square below. Observe that it is essentially a path Ξ²β‚€ ≑ β₁, lying over Ο‰, which is exactly what we need to equate the fibres:

As an intermediate step in the construction of Ξ΄, we construct ΞΈ. However, that is also hard to do directly, so we have four (really, two) more intermediate steps: Ο‰β‚€/ΞΈβ‚€ and ω₁/θ₁.

The line Ο‰β‚€ is the dashed line in the composition below, and ΞΈβ‚€ is the square itself. The type of ΞΈβ‚€ is hard to look at, so focus on the diagram: It connects Ξ²β‚€ and Ο‰β‚€, in the vertical direction.

    square : A β†’ βˆ€ j i β†’ PartialP (~ j ∨ j) (Ξ» _ β†’ P (~ i))
    square x j i (j = i0) = v (~ i) y
    square x j i (j = i1) = u (~ i) x

    Ο‰β‚€ : g y ≑ xβ‚€
    Ο‰β‚€ j = comp ~P (square xβ‚€ j) (Ξ²β‚€ (~ j))

    ΞΈβ‚€ : SquareP (Ξ» i j β†’ P (~ j)) (sym Ξ²β‚€) (Ξ» i β†’ v (~ i) y) (Ξ» i β†’ u (~ i) xβ‚€) Ο‰β‚€
    ΞΈβ‚€ j i = fill ~P (square xβ‚€ j) (inS (Ξ²β‚€ (~ j))) i

Analogously, we have ω₁ and θ₁ connecting β₁ and that, as the dashed line and filler of the square below:

    ω₁ : g y ≑ x₁
    ω₁ j = comp ~P (square x₁ j) (β₁ (~ j))

    θ₁ : SquareP (Ξ» i j β†’ P (~ j)) (sym β₁) (Ξ» i β†’ v (~ i) y) (Ξ» i β†’ u (~ i) x₁) ω₁
    θ₁ j i = fill ~P (square x₁ j) (inS (β₁ (~ j))) i

Now, we are almost done. Like a magic trick, the paths Ο‰β‚€ and ω₁ we constructed above to aid in proving Ξ΄ assemble to give a complete proof of Ο‰, as the dashed line in the square below:

    sys : (k j : I) β†’ _
    sys k j (k = i0) = Ο‰β‚€ j
    sys k j (k = i1) = ω₁ j

    Ο‰ k = hcomp (sys k) (g y)
    ΞΈ : Square refl Ο‰β‚€ ω₁ Ο‰
    ΞΈ k = hfill (sys k) (inS (g y))

We also have ΞΈ, which is the filler of the above square - i.e., it is a path connecting Ο‰β‚€ and ω₁. Now we can finally assemble Ξ΄. Since we are constructing a square, we are filling a cube, i.e.Β a path of paths of paths! The β€œfull” face of this cube is given by ΞΈ, which indicates the boundaries of the other faces. The full cube is right after the definition:

    Ξ΄ k j =
      comp P
        (Ξ» i β†’ Ξ» { (j = i0) β†’ v i y
                 ; (k = i0) β†’ ΞΈβ‚€ j (~ i)
                 ; (j = i1) β†’ u i (Ο‰ k)
                 ; (k = i1) β†’ θ₁ j (~ i) })
        (ΞΈ k j)

The idea behind the diagram is to piece together the three squares we have constructed, ΞΈ, ΞΈβ‚€ and θ₁, with the intent of getting a composite Ξ²β‚€ ≑ β₁. The purpleish square behind is ΞΈ; The brownish square in front is Ξ΄. Finally, putting together the proof of inhabitation and the proof of propositionality, we get the desired: f is an equivalence.

line→is-equiv : is-equiv f
line→is-equiv .is-eqv y .centre = hasFib y
line→is-equiv .is-eqv y .paths = fibProp y _

lineβ†’equiv : A ≃ B
line→equiv .fst = f
line→equiv .snd = line→is-equiv