module Generic.Simulation where open import Size open import Data.List hiding ([_] ; lookup ; zip) open import Function open import Relation.Binary.PropositionalEquality hiding ([_]) open import indexed open import var hiding (_<$>_) open import varlike open import rel open import environment open import Generic.Syntax open import Generic.Semantics open import Generic.Zip module _ {I : Set} {π₯β π₯β πβ πβ : I β List I β Set} (π‘^π₯ : Rel π₯β π₯β) (π‘^π : Rel πβ πβ) where reify^R : {vlβ : VarLike π₯β} {vlβ : VarLike π₯β} (vl^R : VarLike^R π‘^π₯ vlβ vlβ) β {Ξ : List I} β β Ξ Ο β {kβ : Kripke π₯β πβ Ξ Ο Ξ} {kβ : Kripke π₯β πβ Ξ Ο Ξ} β Kripke^R π‘^π₯ π‘^π Ξ Ο kβ kβ β rel π‘^π (reify vlβ Ξ Ο kβ) (reify vlβ Ξ Ο kβ) reify^R vl^R [] Ο k^R = k^R reify^R vl^R Ξ@(_ β· _) Ο k^R = k^R (freshΚ³ vl^Var Ξ) (VarLike^R.freshΛ‘^R vl^R _) record Sim (d : Desc I) (π’β : Sem d π₯β πβ) (π’β : Sem d π₯β πβ) : Set where field th^R : {Ξ Ξ : List I} {i : I} {vβ : π₯β i Ξ} {vβ : π₯β i Ξ} β (Ο : Thinning Ξ Ξ) β rel π‘^π₯ vβ vβ β rel π‘^π₯ (Sem.th^π₯ π’β vβ Ο) (Sem.th^π₯ π’β vβ Ο) var^R : {Ξ : List I} {i : I} {vβ : π₯β i Ξ} {vβ : π₯β i Ξ} β rel π‘^π₯ vβ vβ β rel π‘^π (Sem.var π’β vβ) (Sem.var π’β vβ) alg^R : {Ξ Ξ : List I} {i : I} {s : Size} β (b : β¦ d β§ (Scope (Tm d s)) i Ξ) β {Οβ : (Ξ βEnv) π₯β Ξ} {Οβ : (Ξ βEnv) π₯β Ξ} β β[ π‘^π₯ ] Οβ Οβ β let vβ = fmap d (Sem.body π’β Οβ) b vβ = fmap d (Sem.body π’β Οβ) b in Zip d (Kripke^R π‘^π₯ π‘^π) vβ vβ β rel π‘^π (Sem.alg π’β vβ) (Sem.alg π’β vβ) sim : {Ξ Ξ : List I} {Οβ : (Ξ βEnv) π₯β Ξ} {Οβ : (Ξ βEnv) π₯β Ξ} {i : I} {s : Size} β β[ π‘^π₯ ] Οβ Οβ β (t : Tm d s i Ξ) β rel π‘^π (Sem.sem π’β Οβ t) (Sem.sem π’β Οβ t) body : {Ξ Ξ : List I} {Οβ : (Ξ βEnv) π₯β Ξ} {Οβ : (Ξ βEnv) π₯β Ξ} {s : Size} β β[ π‘^π₯ ] Οβ Οβ β β Ξ j β (t : Scope (Tm d s) Ξ j Ξ) β Kripke^R π‘^π₯ π‘^π Ξ j (Sem.body π’β Οβ Ξ j t) (Sem.body π’β Οβ Ξ j t) sim Ο (`var k) = var^R (lookup^R Ο k) sim Ο (`con t) = alg^R t Ο (zip d (body Ο) t) body Ο [] i t = sim Ο t body Ο (Ο β· Ξ) i t = Ξ» Ο Οβ² β sim (Οβ² >>^R (th^R Ο <$>^R Ο)) t module _ {I : Set} {d : Desc I} where RenExt : Sim Eq^R Eq^R d Renaming Renaming Sim.th^R RenExt = Ξ» Ο β cong (lookup Ο) Sim.var^R RenExt = cong `var Sim.alg^R RenExt = Ξ» _ _ β cong `con β zip^reify Eq^R (reify^R Eq^R Eq^R (vl^Refl vl^Var)) d SubExt : Sim Eq^R Eq^R d Substitution Substitution Sim.th^R SubExt = Ξ» Ο β cong (ren Ο) Sim.var^R SubExt = id Sim.alg^R SubExt = Ξ» _ _ β cong `con β zip^reify Eq^R (reify^R Eq^R Eq^R (vl^Refl vl^Tm)) d module _ {I : Set} {d : Desc I} where vl^VarTm : VarLike^R VarTm^R vl^Var (vl^Tm {d = d}) VarLike^R.new^R vl^VarTm = refl VarLike^R.th^R vl^VarTm = Ξ» Ο β cong (ren Ο) RenSub : Sim VarTm^R Eq^R d Renaming Substitution Sim.var^R RenSub = id Sim.th^R RenSub = Ξ» { _ refl β refl } Sim.alg^R RenSub = Ξ» _ _ β cong `con β zip^reify (mkRel (_β‘_ β `var)) (reify^R VarTm^R Eq^R vl^VarTm) d rensub : {Ξ Ξ : List I} (Ο : Thinning Ξ Ξ) {i : I} (t : Tm d β i Ξ) β ren Ο t β‘ sub (`var <$> Ο) t rensub Ο = Sim.sim RenSub (pack^R (Ξ» _ β refl))