open import Cat.Instances.Assemblies
open import Cat.Instances.Sets
open import Cat.Functor.Base
open import Cat.Prelude

open import Data.Partial.Total
open import Data.Partial.Base
open import Data.Bool.Base

open import Realisability.PCA.Trivial
open import Realisability.PCA

import Cat.Reasoning

import Realisability.Data.Bool
import Realisability.PCA.Sugar
import Realisability.Base
module Cat.Instances.Assemblies.Univalence {β„“A} (𝔸 : PCA β„“A) where
open Realisability.Data.Bool 𝔸
open Realisability.PCA.Sugar 𝔸

Failure of univalence in categories of assembliesπŸ”—

While the category of assemblies over a partial combinatory algebra may look like an ordinary category of structured sets, the computable maps are not the maps which preserve the realisability relation. This means that the category of assemblies fails to be univalent, unless is trivial (so that We show this by formalising the β€œflipped” assembly of booleans, 𝟚' below, and showing that no identifications between 𝟚 and 𝟚' extend the identity map.

𝟚' : Assembly 𝔸 lzero
𝟚' .Ob = Bool
𝟚' .has-is-set  = hlevel 2
𝟚' .realisers true  = singleton⁺ `false
𝟚' .realisers false = singleton⁺ `true
𝟚' .realised  true  = inc (`false .fst , inc refl)
𝟚' .realised  false = inc (`true .fst , inc refl)

This theorem turns out to be pretty basic path algebra: if we are given an identification between 𝟚 and 𝟚', we have, in particular, an identification between their realisability relations over the identification between their underlying sets. And if we assume that the identification between the underlying sets is refl, we’re left with an ordinary identification between the realisability relations; but the realisability relation of 𝟚' was chosen explicitly so it differs from πŸšβ€™s.

no-path-extends-identity
  : (p : 𝟚 𝔸 ≑ 𝟚') β†’ ap Ob p ≑ refl β†’ `true .fst ≑ `false .fst
no-path-extends-identity p q =
  let
    p' : (e : β†― ⌞ 𝔸 ⌟) (x : Bool) β†’ [ 𝟚 𝔸 ] e ⊩ x ≑ [ 𝟚' ] e ⊩ x
    p' e x =
      [ 𝟚 𝔸 ] e ⊩ transport refl x                     β‰‘βŸ¨ sym (apβ‚‚ (Ξ» e x β†’ [ 𝟚 𝔸 ] e ⊩ x) (transport-refl e) (ap (Ξ» e β†’ transport (sym e) x) q)) ⟩
      [ 𝟚 𝔸 ] (transport refl e) ⊩ subst Ob (sym p) x  β‰‘βŸ¨ ap (Ξ» r β†’ e ∈ r x) (from-pathp (ap realisers p)) ⟩
      [ 𝟚' ] e ⊩ x                                     ∎
  in sym (β–‘-out! (transport (p' (`true .fst) true) (inc refl)))

As we argued above, the identity map is a computable function from 𝟚 to 𝟚' with computable inverse; so if were univalent, we could extend it to a path satisfying the conditions of the theorem above.

πŸšβ‰…πŸš' : 𝟚 𝔸 Asm.β‰… 𝟚'
πŸšβ‰…πŸš' = Asm.make-iso to from (ext Ξ» _ β†’ refl) (ext Ξ» _ β†’ refl) where
  to = to-assembly-hom record where
    map      = Ξ» x β†’ x
    realiser = `not
    tracks   = Ξ» where
      true  _ p β†’ inc (sym (ap (`not ⋆_) (sym (β–‘-out! p)) βˆ™ `not-Ξ²t))
      false _ p β†’ inc (sym (ap (`not ⋆_) (sym (β–‘-out! p)) βˆ™ `not-Ξ²f))

  from = to-assembly-hom record where
    map      = Ξ» x β†’ x
    realiser = `not
    tracks   = Ξ» where
      true  _ p β†’ inc (sym (ap (`not ⋆_) (sym (β–‘-out! p)) βˆ™ `not-Ξ²f))
      false _ p β†’ inc (sym (ap (`not ⋆_) (sym (β–‘-out! p)) βˆ™ `not-Ξ²t))

Assemblies-not-univalent
  : is-category (Assemblies 𝔸 lzero) β†’ is-trivial-pca 𝔸
Assemblies-not-univalent cat =
  let
    p : 𝟚 𝔸 ≑ 𝟚'
    p = cat .to-path πŸšβ‰…πŸš'

    Ξ“ = Forget 𝔸
    module Sets = Cat.Reasoning (Sets lzero)

    Ξ³ : Path (Set lzero) (Ξ“ Β· 𝟚 𝔸) (Ξ“ Β· 𝟚') β†’ Bool ≑ Bool
    γ = ap ∣_∣

    q : ap Ob p ≑ refl
    q =
      ap Ob p                                          β‰‘βŸ¨βŸ©
      Ξ³ (ap (apply Ξ“) p)                               β‰‘βŸ¨ ap Ξ³ (F-map-path (Forget 𝔸) cat Sets-is-category πŸšβ‰…πŸš') ⟩
      Ξ³ (Sets-is-category .to-path (F-map-iso Ξ“ πŸšβ‰…πŸš')) β‰‘βŸ¨ ap Ξ³ (ap (Sets-is-category .to-path) (Sets.β‰…-pathp refl refl refl)) ⟩
      Ξ³ (Sets-is-category .to-path Sets.id-iso)        β‰‘βŸ¨ ap Ξ³ (to-path-refl Sets-is-category) ⟩
      Ξ³ refl                                           β‰‘βŸ¨βŸ©
      refl                                             ∎
  in no-path-extends-identity p q