module CoercionExpr.SimBack 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.SimBackLemmas
sim-back : β {β ββ² g gβ²} {cΜ
β cΜ
β : CExpr (l β) β g} {cΜ
ββ² : CExpr (l ββ²) β gβ²}
β β’ cΜ
β β cΜ
ββ²
β cΜ
β ββ cΜ
β
β β[ cΜ
ββ² ] (cΜ
ββ² ββ cΜ
ββ²) Γ (β’ cΜ
β β cΜ
ββ²)
sim-back-castl : β {β ββ² gβ gβ gβ²} {cΜ
: CExpr (l β) β gβ} {c : β’ gβ β gβ} {cΜ
β} {cΜ
ββ² : CExpr (l ββ²) β gβ²}
β β’ cΜ
β cΜ
ββ²
β gβ ββ gβ² β gβ ββ gβ²
β cΜ
β¨Ύ c ββ cΜ
β
β β[ cΜ
ββ² ] (cΜ
ββ² ββ cΜ
ββ²) Γ (β’ cΜ
β β cΜ
ββ²)
sim-back-castl cΜ
βcΜ
ββ² gββgβ² gββgβ² (ΞΎ cΜ
βcΜ
β)
with sim-back cΜ
βcΜ
ββ² cΜ
βcΜ
β
... | β¨ cΜ
ββ² , cΜ
ββ²β cΜ
ββ² , cΜ
ββcΜ
ββ² β© =
β¨ cΜ
ββ² , cΜ
ββ²β cΜ
ββ² , β-castl cΜ
ββcΜ
ββ² gββgβ² gββgβ² β©
sim-back-castl β₯βcΜ
ββ² gββgβ² gββgβ² ΞΎ-β₯
with sim-back-blame β₯βcΜ
ββ² | precββ _ _ β₯βcΜ
ββ²
... | β¨ q , cΜ
ββ²β β₯ , β₯ββ₯ β© | β¨ ββββ² , _ β© =
β¨ β₯ _ _ q , cΜ
ββ²β β₯ , β-β₯ ββββ² gββgβ² β©
sim-back-castl cΜ
βcΜ
ββ² gββgβ² gββgβ² (id v) = β¨ _ , _ β , cΜ
βcΜ
ββ² β©
sim-back-castl cΜ
β¨Ύ!βcΜ
ββ² ββ lβl (?-id v)
with catchup-back _ _ (inj v) cΜ
β¨Ύ!βcΜ
ββ²
... | β¨ id (l ββ²) , cΜ
ββ²β cΜ
ββ² , v-v id (β-castl cΜ
ββid lβl ββ) β© =
β¨ id (l ββ²) , cΜ
ββ²β cΜ
ββ² , cΜ
ββid β©
... | β¨ id (l low) β¨Ύ β , cΜ
ββ²β cΜ
ββ² , v-v (up id) (β-castl cΜ
ββidβ¨Ύβ lβl ββ) β© =
β¨ id (l low) β¨Ύ β , cΜ
ββ²β cΜ
ββ² , cΜ
ββidβ¨Ύβ β©
... | β¨ id (l low) β¨Ύ β , cΜ
ββ²β cΜ
ββ² , v-v (up id) (β-castr (β-castl _ () _) _ _) β©
... | β¨ β₯ _ _ p , cΜ
ββ²β β₯ , v-β₯ x β© =
let β¨ ββββ² , _ β© = precββ _ _ cΜ
β¨Ύ!βcΜ
ββ² in
β¨ β₯ _ _ p , cΜ
ββ²β β₯ , β-β₯ ββββ² lβl β©
sim-back-castl cΜ
β¨Ύ!βcΜ
ββ² ββ lβl (?-β v)
with catchup-back _ _ (inj v) cΜ
β¨Ύ!βcΜ
ββ²
... | β¨ id (l high) , cΜ
ββ²β cΜ
ββ² , v-v id (β-castl _ () _) β©
... | β¨ id (l low) β¨Ύ β , cΜ
ββ²β cΜ
ββ² , v-v (up id) (β-cast x lβl ββ) β© =
β¨ id (l low) β¨Ύ β , cΜ
ββ²β cΜ
ββ² , β-cast x lβl lβl β©
... | β¨ id (l low) β¨Ύ β , cΜ
ββ²β cΜ
ββ² , v-v (up id) (β-castr (β-castl x lβl ββ) ββ ββ) β© =
β¨ id (l low) β¨Ύ β , cΜ
ββ²β cΜ
ββ² , β-cast x lβl lβl β©
... | β¨ β₯ _ _ p , cΜ
ββ²β β₯ , v-β₯ x β© =
let β¨ ββββ² , _ β© = precββ _ _ cΜ
β¨Ύ!βcΜ
ββ² in
β¨ β₯ _ _ p , cΜ
ββ²β β₯ , β-β₯ ββββ² lβl β©
sim-back-castl cΜ
β¨Ύ!βcΜ
ββ² ββ lβl (?-β₯ v)
with catchup-back _ _ (inj v) cΜ
β¨Ύ!βcΜ
ββ²
... | β¨ id (l low) , cΜ
ββ²β cΜ
ββ² , v-v id (β-castl _ () _) β©
... | β¨ β₯ _ _ p , cΜ
ββ²β β₯ , v-β₯ _ β© =
let β¨ ββββ² , _ β© = precββ _ _ cΜ
β¨Ύ!βcΜ
ββ² in
β¨ β₯ _ _ p , cΜ
ββ²β β₯ , β-β₯ ββββ² lβl β©
sim-back-cast : β {β ββ² gβ gββ² gβ gββ²} {cΜ
β : CExpr (l β) β gβ} {cΜ
β}
{cΜ
ββ² : CExpr (l ββ²) β gββ²} {c : β’ gβ β gβ} {cβ² : β’ gββ² β gββ²}
β β’ cΜ
β β cΜ
ββ²
β gβ ββ gββ² β gβ ββ gββ²
β cΜ
β β¨Ύ c ββ cΜ
β
β β[ cΜ
ββ² ] (cΜ
ββ² β¨Ύ cβ² ββ cΜ
ββ²) Γ (β’ cΜ
β β cΜ
ββ²)
sim-back-cast {c = c} {cβ²} cΜ
ββcΜ
ββ² gββgββ² gββgββ² (ΞΎ cΜ
ββcΜ
β)
with sim-back cΜ
ββcΜ
ββ² cΜ
ββcΜ
β
... | β¨ cΜ
ββ² , cΜ
ββ²β cΜ
ββ² , cΜ
ββcΜ
ββ² β© =
β¨ cΜ
ββ² β¨Ύ cβ² , plug-cong cΜ
ββ²β cΜ
ββ² , β-cast cΜ
ββcΜ
ββ² gββgββ² gββgββ² β©
sim-back-cast {c = c} {cβ²} β₯βcΜ
ββ² gββgββ² gββgββ² ΞΎ-β₯
with sim-back-blame β₯βcΜ
ββ² | precββ _ _ β₯βcΜ
ββ²
... | β¨ q , cΜ
ββ²β β₯ , β₯ββ₯ β© | β¨ ββββ² , _ β© =
β¨ β₯ _ _ q , β -trans (plug-cong cΜ
ββ²β β₯) (β₯ _ _ q β¨Ύ cβ² βββ¨ ΞΎ-β₯ β© β₯ _ _ q β) ,
β-β₯ ββββ² gββgββ² β©
sim-back-cast {cβ² = cβ²} cΜ
ββcΜ
ββ² gββgββ² gββgββ² (id v)
with catchup-back _ _ v (β-castr {cβ² = cβ²} cΜ
ββcΜ
ββ² gββgββ² gββgββ²)
... | β¨ cΜ
ββ² , cΜ
ββ²β¨Ύcβ²β cΜ
ββ² , v-v vβ² x β© = β¨ cΜ
ββ² , cΜ
ββ²β¨Ύcβ²β cΜ
ββ² , x β©
... | β¨ cΜ
ββ² , cΜ
ββ²β¨Ύcβ²β cΜ
ββ² , v-β₯ x β© = β¨ cΜ
ββ² , cΜ
ββ²β¨Ύcβ²β cΜ
ββ² , x β©
sim-back-cast cΜ
ββ¨Ύ!βcΜ
ββ² ββ lβl (?-id v) = sim-back-cast-id? cΜ
ββ¨Ύ!βcΜ
ββ² v
sim-back-cast cΜ
ββ¨Ύ!βcΜ
ββ² ββ lβl (?-β v) = sim-back-cast-β cΜ
ββ¨Ύ!βcΜ
ββ² v
sim-back-cast {c = c} {cβ²} cΜ
β¨Ύ!βcΜ
ββ² ββ lβl (?-β₯ v)
with catchup-back _ _ (inj v) cΜ
β¨Ύ!βcΜ
ββ² | cβ²
... | β¨ id (l low) , cΜ
β¨Ύ!β cΜ
ββ² , v-v id (β-castl _ () _) β© | _
... | β¨ id (l low) β¨Ύ β , cΜ
β¨Ύ!β cΜ
ββ² , v-v (up id) (β-castr (β-castl _ () _) _ _) β© | _
... | β¨ id (l low) β¨Ύ low ! , cΜ
β¨Ύ!β cΜ
ββ² , v-v (inj id) (β-castr (β-castl _ () _) _ _) β© | _
... | β¨ id (l high) β¨Ύ high ! , cΜ
β¨Ύ!β cΜ
ββ² , v-v (inj id) x β© | low ?? q =
let β¨ ββββ² , _ β© = precββ _ _ cΜ
β¨Ύ!βcΜ
ββ² in
β¨ β₯ _ _ q , β -trans (plug-cong cΜ
β¨Ύ!β cΜ
ββ²) (id (l high) β¨Ύ (high !) β¨Ύ (low ?? q) βββ¨ ?-β₯ id β©
β₯ (l high) (l low) q β) , β-β₯ ββββ² lβl β©
... | β¨ id (l low) β¨Ύ β β¨Ύ high ! , cΜ
β¨Ύ!β cΜ
ββ² , v-v (inj (up id)) x β© | low ?? q =
let β¨ ββββ² , _ β© = precββ _ _ cΜ
β¨Ύ!βcΜ
ββ² in
β¨ β₯ _ _ q , β -trans (plug-cong cΜ
β¨Ύ!β cΜ
ββ²) (id (l low) β¨Ύ β β¨Ύ (high !) β¨Ύ (low ?? q) βββ¨ ?-β₯ (up id) β©
β₯ (l low) (l low) q β) , β-β₯ ββββ² lβl β©
... | β¨ β₯ _ _ p , cΜ
β¨Ύ!β β₯ , v-β₯ x β© | cβ² =
let β¨ ββββ² , _ β© = precββ _ _ cΜ
β¨Ύ!βcΜ
ββ² in
β¨ β₯ _ _ p , β -trans (plug-cong cΜ
β¨Ύ!β β₯) (β₯ _ _ p β¨Ύ cβ² βββ¨ ΞΎ-β₯ β© β₯ _ _ p β) ,
β-β₯ ββββ² lβl β©
sim-back (β-cast cΜ
βcΜ
β² gββgββ² gβgβ²) cΜ
β¨ΎcβcΜ
β = sim-back-cast cΜ
βcΜ
β² gββgββ² gβgβ² cΜ
β¨ΎcβcΜ
β
sim-back (β-castl cΜ
βcΜ
ββ² gββgβ² gβgβ²) cΜ
β¨ΎcβcΜ
β = sim-back-castl cΜ
βcΜ
ββ² gββgβ² gβgβ² cΜ
β¨ΎcβcΜ
β
sim-back (β-castr {cβ² = cβ²} cΜ
ββcΜ
β² gβgββ² gβgβ²) cΜ
ββcΜ
β
with sim-back cΜ
ββcΜ
β² cΜ
ββcΜ
β
... | β¨ cΜ
ββ² , cΜ
ββ²β cΜ
ββ² , cΜ
ββcΜ
ββ² β© =
β¨ cΜ
ββ² β¨Ύ cβ² , plug-cong cΜ
ββ²β cΜ
ββ² , β-castr cΜ
ββcΜ
ββ² gβgββ² gβgβ² β©
sim-back (β-β₯ lβl gβgβ²) cΜ
ββcΜ
β = β¨ _ , _ β , β-β₯ lβl gβgβ² β©