{-# OPTIONS --cubical --safe #-} module Cardinality.Finite.ManifestBishop.Isomorphism where open import Prelude open import Data.Fin open import Data.Fin.Properties open import Container.List.Isomorphism import Cardinality.Finite.ManifestBishop.Inductive as π import Cardinality.Finite.ManifestBishop.Container as β open import Cardinality.Finite.SplitEnumerable.Isomorphism open import Data.Nat.Properties β!βββ!π : β (x : A) l (xs : Fin l β A) β x β.β! (l , xs) β x π.β! ββπ (l , xs) β!βββ!π x (suc l) xs ((f0 , p) , u) = (f0 , p) , lemma where lemma : (y : x π.β ββπ (suc l , xs)) β (f0 , p) β‘ y lemma (f0 , q) = cong (ββββπ x (suc l , xs)) (u (f0 , q)) lemma (fs m , q) = let o , r = subst (x β.β_) (ββπββ l (xs β fs)) (m , q) in β₯-elim (znots (cong (FinToβ β fst) (u (fs o , r)))) β!βββ!π x (suc l) xs ((fs n , p) , u) = π.push! xs0β’x (β!βββ!π x l (xs β fs) ((n , p) , uxss)) where xs0β’x : xs f0 β’ x xs0β’x xs0β‘x = snotz (cong (FinToβ β fst) (u (f0 , xs0β‘x))) uxss : (y : x β.β (l , xs β fs)) β (n , p) β‘ y uxss (m , q) = cong (Ξ» { (f0 , q) β β₯-elim (xs0β’x q) ; (fs m , q) β m , q}) (u (fs m , q)) πβββ¨β¬β© : π.β¬ A β β.β¬ A πβββ¨β¬β© .fun (sup , cov) = πββ sup , cov πβββ¨β¬β© .inv ((l , xs) , cov) = ββπ (l , xs) , Ξ» x β β!βββ!π x l xs (cov x) πβββ¨β¬β© .rightInv (sup , cov) i .fst = πββ .rightInv sup i πβββ¨β¬β© .rightInv ((l , xs) , cov) i .snd x = J (Ξ» ys ysβ‘ β (zs : x β.β! ys) β PathP (Ξ» i β x β.β! sym ysβ‘ i) zs (cov x)) (Ξ» _ β isPropIsContr _ _) (sym (ββπββ l xs)) (β!βββ!π x l xs (cov x)) i πβββ¨β¬β© .leftInv (sup , cov) i .fst = πββ .leftInv sup i πβββ¨β¬β© .leftInv (sup , cov) i .snd x = J (Ξ» ys ysβ‘ β (zs : x π.β! ys) β PathP (Ξ» i β x π.β! sym ysβ‘ i) zs (cov x)) (Ξ» zs β isPropIsContr _ _) (sym (πβββπ sup)) (β!βββ!π x (π.length sup) (sup π.!_) (cov x)) i