Created
March 28, 2022 03:58
-
-
Save FrozenWinters/933a8a8ee42903a07262eca7be16cc3c to your computer and use it in GitHub Desktop.
Fragment of the proof that normal forms form a set in which I prove that type erasure is injective using a bidirectional approach to sectioning it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Normal (π : Contextual β β) β¦ πCCC : CCC π β¦ | |
| {X : Type β} (base : X β Contextual.ty π) where | |
| open Contextual π | |
| open CCC πCCC | |
| data Ne : (Ξ : ctx) (A : ty) β Type β | |
| data Nf : (Ξ : ctx) (A : ty) β Type β | |
| data Ne where | |
| VN : {Ξ : ctx} {A : ty} β IntVar Ξ A β Ne Ξ A | |
| APP : {Ξ : ctx} {A B : ty} β Ne Ξ (A β B) β Nf Ξ A β Ne Ξ B | |
| data Nf where | |
| NEU : {Ξ : ctx} {x : X} β Ne Ξ (base x) β Nf Ξ (base x) | |
| LAM : {Ξ : ctx} {A B : ty} β Nf (Ξ βΉ A) B β Nf Ξ (A β B) | |
| -- ... skipping stuff | |
| module PathNormal (isDiscTy : Discrete ty) where | |
| isSetTy = DiscreteβisSet isDiscTy | |
| open πππPath ty isSetTy | |
| data UNe : (n : β) β Type β | |
| data UNf : (n : β) β Type β | |
| data UNe where | |
| VN : {n : β} β Fin n β UNe n | |
| APP : {n : β} β UNe n β UNf n β UNe n | |
| data UNf where | |
| NEU : {n : β} β X β UNe n β UNf n | |
| LAM : {n : β} β ty β UNf (S n) β UNf n | |
| eraseNe : {Ξ : ctx} {A : ty} β Ne Ξ A β UNe (len Ξ) | |
| eraseNf : {Ξ : ctx} {A : ty} β Nf Ξ A β UNf (len Ξ) | |
| eraseNe (VN v) = VN (numify v) | |
| eraseNe (APP M N) = APP (eraseNe M) (eraseNf N) | |
| eraseNf (NEU {x = x} M) = NEU x (eraseNe M) | |
| eraseNf (LAM {A = A} N) = LAM A (eraseNf N) | |
| indTy : (Ξ : ctx) (n : Fin (len Ξ)) β ty | |
| indTy (Ξ βΉ A) π = A | |
| indTy (Ξ βΉ A) (π n) = indTy Ξ n | |
| indVar : (Ξ : ctx) (n : Fin (len Ξ)) β IntVar Ξ (indTy Ξ n) | |
| indVar (Ξ βΉ A) π = π§π£ | |
| indVar (Ξ βΉ A) (π n) = π π£ (indVar Ξ n) | |
| compareTy : (A : ty) β (B : ty) β Maybe (A β‘ B) | |
| compareTy A B with isDiscTy A B | |
| ... | yes p = just p | |
| ... | no Β¬p = nothing | |
| checkNe : (Ξ : ctx) (A : ty) β UNe (len Ξ) β Maybe (Ne Ξ A) | |
| synthNf : (Ξ : ctx) β UNf (len Ξ) β Maybe (Ξ£ ty (Ξ» A β Nf Ξ A)) | |
| checkNe Ξ A (VN n) = do | |
| p β compareTy (indTy Ξ n) A | |
| just (subst (Ne Ξ) p (VN (indVar Ξ n))) | |
| checkNe Ξ A (APP M N) = do | |
| (B , N') β synthNf Ξ N | |
| M' β checkNe Ξ (B β A) M | |
| just (APP M' N') | |
| synthNf Ξ (NEU x M) = do | |
| M' β checkNe Ξ (base x) M | |
| just (base x , NEU M') | |
| synthNf Ξ (LAM A N) = do | |
| (B , N') β synthNf (Ξ βΉ A) N | |
| just (A β B , LAM N') | |
| indTyLem : {Ξ : ctx} {A : ty} (v : IntVar Ξ A) β indTy Ξ (numify v) β‘ A | |
| indTyLem π§π£ = refl | |
| indTyLem (π π£ v) = indTyLem v | |
| compareLem : {Ξ : ctx} {A : ty} (v : IntVar Ξ A) β | |
| compareTy (indTy Ξ (numify v)) A β‘ just (indTyLem v) | |
| compareLem {Ξ} {A} v with isDiscTy (indTy Ξ (numify v)) A | |
| ... | yes p = Ξ» i β just (DiscreteβisSet isDiscTy (indTy Ξ (numify v)) A p (indTyLem v) i) | |
| ... | no Β¬p = absurd (Β¬p (indTyLem v)) | |
| insertπΆπ‘π₯ : ctx β ty β β β ctx | |
| insertπΆπ‘π₯ Ξ A Z = Ξ βΉ A | |
| insertπΆπ‘π₯ β A (S n) = β βΉ A | |
| insertπΆπ‘π₯ (Ξ βΉ B) A (S n) = insertπΆπ‘π₯ Ξ A n βΉ B | |
| shiftVar : {Ξ : ctx} (A : ty) {B : ty} β IntVar Ξ B β (n : β) β IntVar (insertπΆπ‘π₯ Ξ A n) B | |
| shiftNe : {Ξ : ctx} (A : ty) {B : ty} β Ne Ξ B β (n : β) β Ne (insertπΆπ‘π₯ Ξ A n) B | |
| shiftNf : {Ξ : ctx} (A : ty) {B : ty} β Nf Ξ B β (n : β) β Nf (insertπΆπ‘π₯ Ξ A n) B | |
| shiftVar A v Z = π π£ v | |
| shiftVar A π§π£ (S n) = π§π£ | |
| shiftVar A (π π£ v) (S n) = π π£ (shiftVar A v n) | |
| shiftNe A (VN v) n = VN (shiftVar A v n) | |
| shiftNe A (APP M N) n = APP (shiftNe A M n) (shiftNf A N n) | |
| shiftNf A (NEU M) n = NEU (shiftNe A M n) | |
| shiftNf A (LAM N) n = LAM (shiftNf A N (S n)) | |
| WβNe : {Ξ : ctx} (A : ty) {B : ty} β Ne Ξ B β Ne (Ξ βΉ A) B | |
| WβNe A M = shiftNe A M Z | |
| transpWβNe : {Ξ : ctx} {A Bβ Bβ : ty} (M : Ne Ξ Bβ) (p : Bβ β‘ Bβ) β | |
| subst (Ne (Ξ βΉ A)) p (WβNe A M) β‘ WβNe A (subst (Ne Ξ) p M) | |
| transpWβNe {Ξ} {A} M p = | |
| J (Ξ» B p β subst (Ne (Ξ βΉ A)) p (WβNe A M) β‘ WβNe A (subst (Ne Ξ) p M)) | |
| (transportRefl (WβNe A M) β ap (WβNe A) (transportRefl M β»ΒΉ)) p | |
| varSection : {Ξ : ctx} {A : ty} (v : IntVar Ξ A) β checkNe Ξ A (VN (numify v)) β‘ just (VN v) | |
| checkSection : {Ξ : ctx} {A : ty} (M : Ne Ξ A) β checkNe Ξ A (eraseNe M) β‘ just M | |
| synthSection : {Ξ : ctx} {A : ty} (N : Nf Ξ A) β synthNf Ξ (eraseNf N) β‘ just (A , N) | |
| varSection {Ξ βΉ A} π§π£ = | |
| (compareTy A A >>= (Ξ» p β just (subst (Ne (Ξ βΉ A)) p (VN π§π£)))) | |
| β‘β¨ (Ξ» i β compareLem {Ξ βΉ A} π§π£ i >>= (Ξ» p β just (subst (Ne (Ξ βΉ A)) p (VN π§π£)))) β© | |
| just (transport refl (VN π§π£)) | |
| β‘β¨ ap just (transportRefl (VN π§π£)) β© | |
| just (VN π§π£) | |
| β | |
| varSection {Ξ βΉ A} {B} (π π£ v) = | |
| (compareTy (indTy Ξ (numify v)) B >>= | |
| (Ξ» p β just (subst (Ne (Ξ βΉ A)) p (VN (π π£ (indVar Ξ (numify v))))))) | |
| β‘β¨ (Ξ» i β compareLem v i >>= | |
| (Ξ» p β just (subst (Ne (Ξ βΉ A)) p (VN (π π£ (indVar Ξ (numify v))))))) β© | |
| just (subst (Ne (Ξ βΉ A)) (indTyLem v) (WβNe A (VN (indVar Ξ (numify v))))) | |
| β‘β¨ ap just (transpWβNe (VN (indVar Ξ (numify v))) (indTyLem v)) β© | |
| (just (subst (Ne Ξ) (indTyLem v) (VN (indVar Ξ (numify v)))) >>= (Ξ» M β just (WβNe A M))) | |
| β‘β¨ (Ξ» i β compareLem v (~ i) >>= | |
| (Ξ» p β just (subst (Ne Ξ) p (VN (indVar Ξ (numify v))))) >>= (Ξ» M β just (WβNe A M))) β© | |
| (compareTy (indTy Ξ (numify v)) B >>= | |
| (Ξ» p β just (subst (Ne Ξ) p (VN (indVar Ξ (numify v))))) >>= (Ξ» M β just (WβNe A M))) | |
| β‘β¨ (Ξ» i β varSection v i >>= (Ξ» M β just (WβNe A M))) β© | |
| just (VN (π π£ v)) | |
| β | |
| checkSection (VN v) = varSection v | |
| checkSection (APP {Ξ} {A} {B} M N) = | |
| (synthNf Ξ (eraseNf N) >>= | |
| (Ξ» { (A , N') β checkNe Ξ (A β B) (eraseNe M) >>= (Ξ» M' β just (Ne.APP M' N'))})) | |
| β‘β¨ (Ξ» i β synthSection N i >>= | |
| (Ξ» { (A , N') β checkNe Ξ (A β B) (eraseNe M) >>= (Ξ» M' β just (APP M' N'))})) β© | |
| (checkNe Ξ (A β B) (eraseNe M) >>= (Ξ» M' β just (APP M' N))) | |
| β‘β¨ (Ξ» i β checkSection M i >>= (Ξ» M' β just (APP M' N))) β© | |
| just (APP M N) | |
| β | |
| synthSection (NEU {x = x} M) = | |
| ap (_>>= (Ξ» M' β just (base x , NEU M'))) (checkSection M) | |
| synthSection (LAM {Ξ} {A} {B} N) = | |
| ap (_>>= (Ξ» { (B , N') β just ((A β B) , LAM N') })) (synthSection N) | |
| just-invert : {A : Type ββ} β A β Maybe A β A | |
| just-invert a (just b) = b | |
| just-invert a nothing = a | |
| straightenNf : {Ξ : ctx} {A : ty} {Nβ Nβ : Nf Ξ A} {p : A β‘ A} β | |
| PathP (Ξ» i β Nf Ξ (p i)) Nβ Nβ β Nβ β‘ Nβ | |
| straightenNf {Ξ} {A} {Nβ} {Nβ} {p} q = | |
| transport (Ξ» i β PathP (Ξ» j β Nf Ξ (isSetTy A A p refl i j)) Nβ Nβ) q | |
| eraseNfInj : {Ξ : ctx} {A : ty} (Nβ Nβ : Nf Ξ A) β eraseNf Nβ β‘ eraseNf Nβ β Nβ β‘ Nβ | |
| eraseNfInj {Ξ} {A} Nβ Nβ p = | |
| straightenNf | |
| (ap (Ξ» x β snd (just-invert (A , Nβ) x)) | |
| (synthSection Nβ β»ΒΉ β ap (synthNf Ξ) p β synthSection Nβ)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment