module LabelExpr.CatchUp 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 LabelExpr.LabelExpr
open import CoercionExpr.CoercionExpr renaming (_βββ¨_β©_ to _ββββ¨_β©_ ; _β to _ββ)
open import CoercionExpr.Precision renaming (precββ to precβββ)
open import CoercionExpr.SyntacComp
open import CoercionExpr.CatchUp renaming (catchup to catchupβ)
catchup : β {g gβ²} {M Vβ²}
β LVal Vβ²
β β’ M β Vβ² β g β gβ²
β β[ V ] (LVal V) Γ (M ββ β V) Γ (β’ V β Vβ² β g β gβ²)
catchup v-l β-l = β¨ _ , v-l , _ β , β-l β©
catchup v-l (β-castl {gβ} {gβ} {gβ²} {M} {Mβ²} {cΜ
} Mββ cΜ
ββ)
with catchup v-l Mββ
... | β¨ l β , v-l , Mβ V , β-l β© =
case catchupβ cΜ
(id gβ²) id (β-left-expand cΜ
ββ) of Ξ» where
β¨ id _ , id , _ ββ , cΜ
ββid β© β
let β£ = β β-trans (plug-congβ Mβ V)
(l β βͺ id (l β) β« βββ¨ Ξ²-id β©
l β β) in
β¨ l β , v-l , β£ , β-l β©
β¨ id _ , id , _ ββββ¨ r β© r* , cΜ
ββid β© β
let β£ = β β-trans (plug-congβ Mβ V)
(l β βͺ cΜ
β« βββ¨ cast (_ ββββ¨ r β© r*) id β©
l β βͺ id (l β) β« βββ¨ Ξ²-id β©
l β β) in
β¨ l β , v-l , β£ , β-l β©
β¨ cΜ
β , inj π , _ ββ , cΜ
ββid β© β
β¨ l β βͺ cΜ
β β« , v-cast (ir (inj π) (Ξ» ())) , plug-congβ Mβ V ,
β-castl β-l (β-left-contract cΜ
ββid) β©
β¨ cΜ
β , inj π , _ ββββ¨ r β© r* , cΜ
ββid β© β
let β₯ = β β-trans (plug-congβ Mβ V)
(l β βͺ cΜ
β« βββ¨ cast (_ ββββ¨ r β© r*) (inj π) β©
l β βͺ cΜ
β β« β) in
β¨ l β βͺ cΜ
β β« , v-cast (ir (inj π) (Ξ» ())) , β₯ ,
β-castl β-l (β-left-contract cΜ
ββid) β©
β¨ cΜ
β , up π , cΜ
β cΜ
β , β-castl _ lβl () β©
... | β¨ l β βͺ cΜ
β β« , v-cast i , Mβ V , β-castl β-l cΜ
βββ β© =
case catchupβ (cΜ
β β¨ cΜ
) (id gβ²) id (β-left-expand (comp-pres-β-ll cΜ
βββ cΜ
ββ)) of Ξ» where
β¨ id _ , id , cΜ
ββ¨cΜ
β cΜ
β , cΜ
ββid β© β
let β£ = β β-trans (plug-congβ Mβ V)
(l β βͺ cΜ
β β« βͺ cΜ
β« βββ¨ comp i β©
l β βͺ cΜ
β β¨ cΜ
β« βββ¨ cast (comp-ββΊ cΜ
ββ¨cΜ
β cΜ
β id) id β©
l β βͺ id (l β) β« βββ¨ Ξ²-id β©
l β β) in
β¨ l β , v-l , β£ , β-l β©
β¨ cΜ
β , inj π , cΜ
ββ¨cΜ
β cΜ
β , cΜ
ββid β© β
let β₯ = β β-trans (plug-congβ Mβ V)
(l β βͺ cΜ
β β« βͺ cΜ
β« βββ¨ comp i β©
l β βͺ cΜ
β β¨ cΜ
β« βββ¨ cast (comp-ββΊ cΜ
ββ¨cΜ
β cΜ
β (inj π)) (inj π) β©
l β βͺ cΜ
β β« β) in
β¨ l β βͺ cΜ
β β« , v-cast (ir (inj π) (Ξ» ())) , β₯ ,
β-castl β-l (β-left-contract cΜ
ββid) β©
β¨ cΜ
β , up π , cΜ
ββ¨cΜ
β cΜ
β , β-castl _ lβl () β©
catchup (v-cast (ir πβ² x )) (β-cast {gβ} {gββ²} {gβ} {gββ²} {M} {Mβ²} {cΜ
} {cΜ
β²} MβVβ² cΜ
βcΜ
β²)
with catchup v-l MβVβ²
... | β¨ l β , v-l , Mβ V , β-l β© =
case catchupβ cΜ
cΜ
β² πβ² cΜ
βcΜ
β² of Ξ» where
β¨ id _ , id , _ ββ , cΜ
ββcΜ
β² β© β
let β£ = β β-trans (plug-congβ Mβ V)
(l β βͺ id (l β) β« βββ¨ Ξ²-id β©
l β β) in
β¨ l β , v-l , β£ , β-castr β-l (β-right-contract cΜ
ββcΜ
β²) β©
β¨ id _ , id , _ ββββ¨ r β© r* , cΜ
ββcΜ
β² β© β
let β£ = β β-trans (plug-congβ Mβ V)
(l β βͺ cΜ
β« βββ¨ cast (_ ββββ¨ r β© r*) id β©
l β βͺ id (l β) β« βββ¨ Ξ²-id β©
l β β) in
β¨ l β , v-l , β£ , β-castr β-l (β-right-contract cΜ
ββcΜ
β²) β©
β¨ cΜ
β , inj π , _ ββ , cΜ
ββcΜ
β² β© β
β¨ l β βͺ cΜ
β β« , v-cast (ir (inj π) (Ξ» ())) , plug-congβ Mβ V , β-cast β-l cΜ
ββcΜ
β² β©
β¨ cΜ
β , inj π , _ ββββ¨ r β© r* , cΜ
ββcΜ
β² β© β
let β₯ = β β-trans (plug-congβ Mβ V)
(l β βͺ cΜ
β« βββ¨ cast (_ ββββ¨ r β© r*) (inj π) β©
l β βͺ cΜ
β β« β) in
β¨ l β βͺ cΜ
β β« , v-cast (ir (inj π) (Ξ» ())) , β₯ , β-cast β-l cΜ
ββcΜ
β² β©
β¨ cΜ
β , up id , _ ββ , cΜ
ββcΜ
β² β© β
case (precβββ _ _ cΜ
ββcΜ
β²) of Ξ» where
β¨ _ , lβl β© β β¨ l β βͺ cΜ
β β« , v-cast (ir (up id) x ) , plug-congβ Mβ V , β-cast β-l cΜ
ββcΜ
β² β©
β¨ cΜ
β , up id , _ ββββ¨ r β© r* , cΜ
ββcΜ
β² β© β
let β₯ = β β-trans (plug-congβ Mβ V)
(l β βͺ cΜ
β« βββ¨ cast (_ ββββ¨ r β© r*) (up id) β©
l β βͺ cΜ
β β« β) in
case (precβββ _ _ cΜ
ββcΜ
β²) of Ξ» where
β¨ _ , lβl β© β β¨ l β βͺ cΜ
β β« , v-cast (ir (up id) x ) , β₯ , β-cast β-l cΜ
ββcΜ
β² β©
... | β¨ l β βͺ cΜ
β β« , v-cast i , Mβ V , β-castl β-l cΜ
βββ β© =
case catchupβ (cΜ
β β¨ cΜ
) cΜ
β² πβ² (comp-pres-β-lb cΜ
βββ cΜ
βcΜ
β²) of Ξ» where
β¨ id _ , id , cΜ
ββ¨cΜ
β cΜ
β , cΜ
ββcΜ
β² β© β
let β£ = β β-trans (plug-congβ Mβ V)
(l β βͺ cΜ
β β« βͺ cΜ
β« βββ¨ comp i β©
l β βͺ cΜ
β β¨ cΜ
β« βββ¨ cast (comp-ββΊ cΜ
ββ¨cΜ
β cΜ
β id) id β©
l β βͺ id (l β) β« βββ¨ Ξ²-id β©
l β β) in
β¨ l β , v-l , β£ , β-castr β-l (β-right-contract cΜ
ββcΜ
β²) β©
β¨ cΜ
β , inj π , cΜ
ββ¨cΜ
β cΜ
β , cΜ
ββcΜ
β² β© β
let β₯ = β β-trans (plug-congβ Mβ V)
(l β βͺ cΜ
β β« βͺ cΜ
β« βββ¨ comp i β©
l β βͺ cΜ
β β¨ cΜ
β« βββ¨ cast (comp-ββΊ cΜ
ββ¨cΜ
β cΜ
β (inj π)) (inj π) β©
l β βͺ cΜ
β β« β) in
β¨ l β βͺ cΜ
β β« , v-cast (ir (inj π) (Ξ» ())) , β₯ ,
β-cast β-l cΜ
ββcΜ
β² β©
β¨ cΜ
β , up id , cΜ
ββ¨cΜ
β cΜ
β , cΜ
ββcΜ
β² β© β
case (precβββ _ _ cΜ
ββcΜ
β²) of Ξ» where
β¨ _ , lβl β© β
let β₯ = β β-trans (plug-congβ Mβ V)
(l β βͺ cΜ
β β« βͺ cΜ
β« βββ¨ comp i β©
l β βͺ cΜ
β β¨ cΜ
β« βββ¨ cast (comp-ββΊ cΜ
ββ¨cΜ
β cΜ
β (up id)) (up id) β©
l β βͺ cΜ
β β« β) in
β¨ l β βͺ cΜ
β β« , v-cast (ir (up id) x) , β₯ ,
β-cast β-l cΜ
ββcΜ
β² β©
catchup (v-cast (ir πβ² x )) (β-castl {gβ} {gβ} {gβ²} {M} {Mβ²} {cΜ
} MβVβ² cΜ
βgβ²)
with catchup (v-cast (ir πβ² x)) MβVβ²
... | β¨ l β , v-l , Mβ V , β-castr β-l ββcΜ
β² β© =
case catchupβ cΜ
(id gβ²) id (β-left-expand cΜ
βgβ²) of Ξ» where
β¨ id _ , id , _ ββ , cΜ
ββid β© β
let β£ = β β-trans (plug-congβ Mβ V)
(l β βͺ id (l β) β« βββ¨ Ξ²-id β©
l β β) in
β¨ l β , v-l , β£ , β-castr β-l ββcΜ
β² β©
β¨ id _ , id , _ ββββ¨ r β© r* , cΜ
ββid β© β
let β£ = β β-trans (plug-congβ Mβ V)
(l β βͺ cΜ
β« βββ¨ cast (_ ββββ¨ r β© r*) id β©
l β βͺ id (l β) β« βββ¨ Ξ²-id β©
l β β) in
β¨ l β , v-l , β£ , β-castr β-l ββcΜ
β² β©
β¨ cΜ
β , inj π , _ ββ , cΜ
ββid β© β
β¨ l β βͺ cΜ
β β« , v-cast (ir (inj π) (Ξ» ())) , plug-congβ Mβ V ,
β-castl (β-castr β-l ββcΜ
β²) (β-left-contract cΜ
ββid) β©
β¨ cΜ
β , inj π , _ ββββ¨ r β© r* , cΜ
ββid β© β
let β₯ = β β-trans (plug-congβ Mβ V)
(l β βͺ cΜ
β« βββ¨ cast (_ ββββ¨ r β© r*) (inj π) β©
l β βͺ cΜ
β β« β) in
β¨ l β βͺ cΜ
β β« , v-cast (ir (inj π) (Ξ» ())) , β₯ ,
β-castl (β-castr β-l ββcΜ
β²) (β-left-contract cΜ
ββid) β©
β¨ cΜ
β , up π , _ ββ , cΜ
ββid β© β
case (precβββ _ _ cΜ
ββid) of Ξ» where
β¨ _ , lβl β© β
β¨ l β βͺ cΜ
β β« , v-cast (ir (up π) x) , plug-congβ Mβ V ,
β-castl (β-castr β-l ββcΜ
β²) (β-left-contract cΜ
ββid) β©
β¨ cΜ
β , up π , _ ββββ¨ r β© r* , cΜ
ββid β© β
let β₯ = β β-trans (plug-congβ Mβ V)
(l β βͺ cΜ
β« βββ¨ cast (_ ββββ¨ r β© r*) (up π) β©
l β βͺ cΜ
β β« β) in
case (precβββ _ _ cΜ
ββid) of Ξ» where
β¨ _ , lβl β© β
β¨ l β βͺ cΜ
β β« , v-cast (ir (up π) x) , β₯ ,
β-castl (β-castr β-l ββcΜ
β²) (β-left-contract cΜ
ββid) β©
... | β¨ l β βͺ cΜ
β β« , v-cast i , Mβ V , β-cast β-l cΜ
ββcΜ
β² β© =
case catchupβ (cΜ
β β¨ cΜ
) _ πβ² (comp-pres-β-bl cΜ
ββcΜ
β² cΜ
βgβ²) of Ξ» where
β¨ id _ , id , cΜ
ββ¨cΜ
β cΜ
β , cΜ
ββcΜ
β² β© β
let β£ = β β-trans (plug-congβ Mβ V)
(l β βͺ cΜ
β β« βͺ cΜ
β« βββ¨ comp i β©
l β βͺ cΜ
β β¨ cΜ
β« βββ¨ cast (comp-ββΊ cΜ
ββ¨cΜ
β cΜ
β id) id β©
l β βͺ id (l β) β« βββ¨ Ξ²-id β©
l β β) in
β¨ l β , v-l , β£ , β-castr β-l (β-right-contract cΜ
ββcΜ
β²) β©
β¨ cΜ
β , inj π , cΜ
ββ¨cΜ
β cΜ
β , cΜ
ββcΜ
β² β© β
let β₯ = β β-trans (plug-congβ Mβ V)
(l β βͺ cΜ
β β« βͺ cΜ
β« βββ¨ comp i β©
l β βͺ cΜ
β β¨ cΜ
β« βββ¨ cast (comp-ββΊ cΜ
ββ¨cΜ
β cΜ
β (inj π)) (inj π) β©
l β βͺ cΜ
β β« β) in
β¨ l β βͺ cΜ
β β« , v-cast (ir (inj π) (Ξ» ())) , β₯ ,
β-cast β-l cΜ
ββcΜ
β² β©
β¨ cΜ
β , up π , cΜ
ββ¨cΜ
β cΜ
β , cΜ
ββcΜ
β² β© β
case (precβββ _ _ cΜ
ββcΜ
β²) of Ξ» where
β¨ _ , lβl β© β
let β₯ = β β-trans (plug-congβ Mβ V)
(l β βͺ cΜ
β β« βͺ cΜ
β« βββ¨ comp i β©
l β βͺ cΜ
β β¨ cΜ
β« βββ¨ cast (comp-ββΊ cΜ
ββ¨cΜ
β cΜ
β (up π)) (up π) β©
l β βͺ cΜ
β β« β) in
β¨ l β βͺ cΜ
β β« , v-cast (ir (up π) x) , β₯ ,
β-cast β-l cΜ
ββcΜ
β² β©
... | β¨ l β βͺ cΜ
β β« , v-cast i , Mβ V , β-castl (β-castr β-l ββcΜ
β²) cΜ
ββgβ² β© =
case catchupβ (cΜ
β β¨ cΜ
) (id gβ²) id (β-left-expand (comp-pres-β-ll cΜ
ββgβ² cΜ
βgβ²)) of Ξ» where
β¨ id _ , id , cΜ
ββ¨cΜ
β cΜ
β , cΜ
ββcΜ
β² β© β
let β£ = β β-trans (plug-congβ Mβ V)
(l β βͺ cΜ
β β« βͺ cΜ
β« βββ¨ comp i β©
l β βͺ cΜ
β β¨ cΜ
β« βββ¨ cast (comp-ββΊ cΜ
ββ¨cΜ
β cΜ
β id) id β©
l β βͺ id (l β) β« βββ¨ Ξ²-id β©
l β β) in
β¨ l β , v-l , β£ , β-castr β-l ββcΜ
β² β©
β¨ cΜ
β , inj π , cΜ
ββ¨cΜ
β cΜ
β , cΜ
ββcΜ
β² β© β
let β₯ = β β-trans (plug-congβ Mβ V)
(l β βͺ cΜ
β β« βͺ cΜ
β« βββ¨ comp i β©
l β βͺ cΜ
β β¨ cΜ
β« βββ¨ cast (comp-ββΊ cΜ
ββ¨cΜ
β cΜ
β (inj π)) (inj π) β©
l β βͺ cΜ
β β« β) in
β¨ l β βͺ cΜ
β β« , v-cast (ir (inj π) (Ξ» ())) , β₯ ,
β-castl (β-castr β-l ββcΜ
β²) (β-left-contract cΜ
ββcΜ
β²) β©
β¨ cΜ
β , up π , cΜ
ββ¨cΜ
β cΜ
β , cΜ
ββcΜ
β² β© β
case (precβββ _ _ cΜ
ββcΜ
β²) of Ξ» where
β¨ _ , lβl β© β
let β₯ = β β-trans (plug-congβ Mβ V)
(l β βͺ cΜ
β β« βͺ cΜ
β« βββ¨ comp i β©
l β βͺ cΜ
β β¨ cΜ
β« βββ¨ cast (comp-ββΊ cΜ
ββ¨cΜ
β cΜ
β (up π)) (up π) β©
l β βͺ cΜ
β β« β) in
β¨ l β βͺ cΜ
β β« , v-cast (ir (up π) x) , β₯ ,
β-castl (β-castr β-l ββcΜ
β²) (β-left-contract cΜ
ββcΜ
β²) β©
... | β¨ l β βͺ cΜ
β β« , v-cast i , Mβ V , β-castr (β-castl β-l cΜ
βββ) gββcΜ
β² β© =
case catchupβ (cΜ
β β¨ cΜ
) _ πβ² (comp-pres-β-bl (comp-pres-β-lr cΜ
βββ gββcΜ
β²) cΜ
βgβ²) of Ξ» where
β¨ id _ , id , cΜ
ββ¨cΜ
β cΜ
β , cΜ
ββcΜ
β² β© β
let β£ = β β-trans (plug-congβ Mβ V)
(l β βͺ cΜ
β β« βͺ cΜ
β« βββ¨ comp i β©
l β βͺ cΜ
β β¨ cΜ
β« βββ¨ cast (comp-ββΊ cΜ
ββ¨cΜ
β cΜ
β id) id β©
l β βͺ id (l β) β« βββ¨ Ξ²-id β©
l β β) in
β¨ l β , v-l , β£ , β-castr β-l (β-right-contract cΜ
ββcΜ
β²) β©
β¨ cΜ
β , inj π , cΜ
ββ¨cΜ
β cΜ
β , cΜ
ββcΜ
β² β© β
let β₯ = β β-trans (plug-congβ Mβ V)
(l β βͺ cΜ
β β« βͺ cΜ
β« βββ¨ comp i β©
l β βͺ cΜ
β β¨ cΜ
β« βββ¨ cast (comp-ββΊ cΜ
ββ¨cΜ
β cΜ
β (inj π)) (inj π) β©
l β βͺ cΜ
β β« β) in
β¨ l β βͺ cΜ
β β« , v-cast (ir (inj π) (Ξ» ())) , β₯ ,
β-cast β-l cΜ
ββcΜ
β² β©
β¨ cΜ
β , up π , cΜ
ββ¨cΜ
β cΜ
β , cΜ
ββcΜ
β² β© β
case (precβββ _ _ cΜ
ββcΜ
β²) of Ξ» where
β¨ _ , lβl β© β
let β₯ = β β-trans (plug-congβ Mβ V)
(l β βͺ cΜ
β β« βͺ cΜ
β« βββ¨ comp i β©
l β βͺ cΜ
β β¨ cΜ
β« βββ¨ cast (comp-ββΊ cΜ
ββ¨cΜ
β cΜ
β (up π)) (up π) β©
l β βͺ cΜ
β β« β) in
β¨ l β βͺ cΜ
β β« , v-cast (ir (up π) x) , β₯ ,
β-cast β-l cΜ
ββcΜ
β² β©
catchup (v-cast (ir πβ² x)) (β-castr {g} {gββ²} {gββ²} {M} {Mβ²} {cΜ
β²} MβVβ² gβcΜ
)
with catchup v-l MβVβ²
... | β¨ l β , v-l , Mβ V , β-l β© =
β¨ l β , v-l , Mβ V , β-castr β-l gβcΜ
β©
... | β¨ l β βͺ cΜ
β β« , v-cast i , Mβ V , β-castl β-l cΜ
βββ β© =
β¨ l β βͺ cΜ
β β« , v-cast i , Mβ V ,
β-castr (β-castl β-l cΜ
βββ) gβcΜ
β©