module CoercionExpr.Simulation where
open import Data.Nat
open import Data.Unit using (β€; tt)
open import Data.Bool using (true; false) renaming (Bool to πΉ)
open import Data.List hiding ([_])
open import Data.Product renaming (_,_ to β¨_,_β©)
open import Data.Sum using (_β_)
open import Data.Maybe
open import Relation.Nullary using (Β¬_; Dec; yes; no)
open import Relation.Binary.PropositionalEquality using (_β‘_; refl)
open import Function using (case_of_)
open import Common.Utils
open import Common.SecurityLabels
open import Common.BlameLabels
open import CoercionExpr.CoercionExpr
open import CoercionExpr.Precision
open import CoercionExpr.SimLemmas
sim : β {gβ gββ² gβ gββ²} {cΜ
β : CExpr gβ β gβ} {cΜ
ββ² cΜ
ββ² : CExpr gββ² β gββ²}
β β’ cΜ
β β cΜ
ββ²
β cΜ
ββ² ββ cΜ
ββ²
β β[ cΜ
β ] (cΜ
β ββ cΜ
β) Γ (β’ cΜ
β β cΜ
ββ²)
sim-cast : β {gβ gββ² gβ gββ² gβ gββ²}
{cΜ
β : CExpr gβ β gβ} {cΜ
ββ² : CExpr gββ² β gββ²}
{cΜ
ββ² : CExpr gββ² β gββ²}
{c : β’ gβ β gβ} {cβ² : β’ gββ² β gββ²}
β β’ cΜ
β β cΜ
ββ²
β gβ ββ gββ² β gβ ββ gββ²
β cΜ
ββ² β¨Ύ cβ² ββ cΜ
ββ²
β β[ cΜ
β ] (cΜ
β β¨Ύ c ββ cΜ
β) Γ (β’ cΜ
β β cΜ
ββ²)
sim-cast {c = c} {cβ²} cΜ
ββcΜ
ββ² gββgββ² gββgββ² (ΞΎ cΜ
ββ²βcΜ
β²)
with sim cΜ
ββcΜ
ββ² cΜ
ββ²βcΜ
β²
... | β¨ cΜ
, cΜ
ββ cΜ
, cΜ
βcΜ
β² β© = β¨ cΜ
β¨Ύ c , plug-cong cΜ
ββ cΜ
, β-cast cΜ
βcΜ
β² gββgββ² gββgββ² β©
sim-cast {cΜ
β = cΜ
β} {c = c} {cβ²} cΜ
βββ₯ gββgββ² gββgββ² ΞΎ-β₯ =
let β¨ gββgββ² , _ β© = precββ cΜ
β _ cΜ
βββ₯ in
β¨ cΜ
β β¨Ύ c , _ β , β-β₯ gββgββ² gββgββ² β©
sim-cast cΜ
ββcΜ
ββ² gββgββ² gββgββ² (id vβ²) = sim-cast-id cΜ
ββcΜ
ββ² gββgββ² gββgββ² vβ²
sim-cast cΜ
ββcΜ
ββ² gββgββ² gββgββ² (?-id vβ²) = sim-cast-id? cΜ
ββcΜ
ββ² gββgββ² gββgββ² vβ²
sim-cast cΜ
ββcΜ
ββ² gββgββ² gββgββ² (?-β vβ²) = sim-cast-β cΜ
ββcΜ
ββ² gββgββ² gββgββ² vβ²
sim-cast cΜ
ββcΜ
ββ² gββgββ² gββgββ² (?-β₯ vβ²) =
let β¨ gββgββ² , _ β© = precββ _ _ cΜ
ββcΜ
ββ² in
β¨ _ , _ β , β-β₯ gββgββ² gββgββ² β©
sim-castr : β {gβ gββ² gβ gββ² gββ²}
{cΜ
β : CExpr gβ β gβ} {cΜ
ββ² : CExpr gββ² β gββ²}
{cΜ
ββ² : CExpr gββ² β gββ²}
{cβ² : β’ gββ² β gββ²}
β β’ cΜ
β β cΜ
ββ²
β gβ ββ gββ² β gβ ββ gββ²
β cΜ
ββ² β¨Ύ cβ² ββ cΜ
ββ²
β β[ cΜ
β ] (cΜ
β ββ cΜ
β) Γ (β’ cΜ
β β cΜ
ββ²)
sim-castr {cβ² = cβ²} cΜ
ββcΜ
ββ² gββgββ² gββgββ² (ΞΎ cΜ
ββ²βcΜ
β²)
with sim cΜ
ββcΜ
ββ² cΜ
ββ²βcΜ
β²
... | β¨ cΜ
, cΜ
ββ cΜ
, cΜ
βcΜ
β² β© = β¨ cΜ
, cΜ
ββ cΜ
, β-castr cΜ
βcΜ
β² gββgββ² gββgββ² β©
sim-castr {cΜ
β = cΜ
β} {cβ² = cβ²} cΜ
βββ₯ gββgββ² gββgββ² ΞΎ-β₯ =
let β¨ gββgββ² , _ β© = precββ cΜ
β _ cΜ
βββ₯ in
β¨ cΜ
β , _ β , β-β₯ gββgββ² gββgββ² β©
sim-castr cΜ
ββcΜ
ββ² gββgββ² gββgββ² (id vβ²) = β¨ _ , _ β , cΜ
ββcΜ
ββ² β©
sim-castr cΜ
ββcΜ
ββ² ββ ββ (?-id vβ²)
with catchup _ _ (inj vβ²) cΜ
ββcΜ
ββ²
... | β¨ cΜ
β , v , cΜ
ββ cΜ
β , cΜ
ββcΜ
ββ² β© = β¨ cΜ
β , cΜ
ββ cΜ
β , prec-inj-left _ _ v vβ² cΜ
ββcΜ
ββ² β©
sim-castr cΜ
ββcΜ
ββ² ββ ββ (?-β vβ²)
with catchup _ _ (inj vβ²) cΜ
ββcΜ
ββ²
... | β¨ cΜ
β , v , cΜ
ββ cΜ
β , cΜ
ββcΜ
ββ² β© = β¨ cΜ
β , cΜ
ββ cΜ
β , β-castr (prec-inj-left _ _ v vβ² cΜ
ββcΜ
ββ²) ββ ββ β©
sim-castr cΜ
ββcΜ
ββ² gββgββ² gββgββ² (?-β₯ vβ²) =
let β¨ gββgββ² , _ β© = precββ _ _ cΜ
ββcΜ
ββ² in
β¨ _ , _ β , β-β₯ gββgββ² gββgββ² β©
sim (β-cast cΜ
ββcΜ
ββ² gββgββ² gββgββ²) cΜ
ββ²βcΜ
ββ² = sim-cast cΜ
ββcΜ
ββ² gββgββ² gββgββ² cΜ
ββ²βcΜ
ββ²
sim (β-castl {c = c} cΜ
ββcΜ
ββ² gββgββ² gββgββ²) cΜ
ββ²βcΜ
ββ²
with sim cΜ
ββcΜ
ββ² cΜ
ββ²βcΜ
ββ²
... | β¨ cΜ
, cΜ
ββ cΜ
, cΜ
βcΜ
β² β© = β¨ cΜ
β¨Ύ c , plug-cong cΜ
ββ cΜ
, β-castl cΜ
βcΜ
β² gββgββ² gββgββ² β©
sim (β-castr cΜ
ββcΜ
ββ² gββgββ² gββgββ²) cΜ
ββ²βcΜ
ββ² = sim-castr cΜ
ββcΜ
ββ² gββgββ² gββgββ² cΜ
ββ²βcΜ
ββ²