module CoercionExpr.SyntacComp 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.Nullary.Negation using (contradiction)
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
_β¨_ : β {gβ gβ gβ} (cΜ
β : CExpr gβ β gβ) (cΜ
β : CExpr gβ β gβ) β CExpr gβ β gβ
cΜ
β β¨ β₯ gβ gβ p = β₯ _ gβ p
cΜ
β β¨ id g = cΜ
β β¨Ύ id g
cΜ
β β¨ (cΜ
β β¨Ύ c) = (cΜ
β β¨ cΜ
β) β¨Ύ c
comp-pres-β : β {gβ gββ² gβ gββ² gβ gββ²}
{cΜ
β : CExpr gβ β gβ} {cΜ
β : CExpr gβ β gβ}
{cΜ
ββ² : CExpr gββ² β gββ²} {cΜ
ββ² : CExpr gββ² β gββ²}
β β’ cΜ
β β cΜ
ββ²
β β’ cΜ
β β cΜ
ββ²
β β’ cΜ
β β¨ cΜ
β β cΜ
ββ² β¨ cΜ
ββ²
comp-pres-β cΜ
ββcΜ
ββ² (β-β₯ x gββgββ²) =
let β¨ gββgββ² , _ β© = precββ _ _ cΜ
ββcΜ
ββ² in
β-β₯ gββgββ² gββgββ²
comp-pres-β cΜ
ββcΜ
ββ² (β-id gβgβ²) = β-cast cΜ
ββcΜ
ββ² gβgβ² gβgβ²
comp-pres-β cΜ
ββcΜ
ββ² (β-cast cΜ
ββcΜ
ββ² gβgβ gβ²βgββ²) =
β-cast (comp-pres-β cΜ
ββcΜ
ββ² cΜ
ββcΜ
ββ²) gβgβ gβ²βgββ²
comp-pres-β cΜ
ββcΜ
ββ² (β-castl cΜ
ββcΜ
ββ² gβgββ² gββgββ²) =
β-castl (comp-pres-β cΜ
ββcΜ
ββ² cΜ
ββcΜ
ββ²) gβgββ² gββgββ²
comp-pres-β cΜ
ββcΜ
ββ² (β-castr cΜ
ββcΜ
ββ² gββgβ² gββgββ²) =
β-castr (comp-pres-β cΜ
ββcΜ
ββ² cΜ
ββcΜ
ββ²) gββgβ² gββgββ²
comp-pres-β-ll : β {gβ gβ gβ gβ²}
{cΜ
β : CExpr gβ β gβ} {cΜ
β : CExpr gβ β gβ}
β β’l cΜ
β β gβ²
β β’l cΜ
β β gβ²
β β’l cΜ
β β¨ cΜ
β β gβ²
comp-pres-β-ll cΜ
ββcΜ
ββ² (β-id gβgβ²) = β-cast cΜ
ββcΜ
ββ² gβgβ² gβgβ²
comp-pres-β-ll cΜ
ββcΜ
ββ² (β-cast cΜ
ββcΜ
ββ² gβgββ² gββgββ²) =
β-cast (comp-pres-β-ll cΜ
ββcΜ
ββ² cΜ
ββcΜ
ββ²) gβgββ² gββgββ²
comp-pres-β-rr : β {g gββ² gββ² gββ²}
{cΜ
ββ² : CExpr gββ² β gββ²} {cΜ
ββ² : CExpr gββ² β gββ²}
β β’r g β cΜ
ββ²
β β’r g β cΜ
ββ²
β β’r g β cΜ
ββ² β¨ cΜ
ββ²
comp-pres-β-rr gβcΜ
ββ² (β-id gβgβ²) = β-cast gβcΜ
ββ² gβgβ² gβgβ²
comp-pres-β-rr gβcΜ
ββ² (β-cast gβcΜ
β² x y) = β-cast (comp-pres-β-rr gβcΜ
ββ² gβcΜ
β²) x y
comp-pres-β-rr gβcΜ
ββ² (β-β₯ _ x) = β-β₯ (projβ (prec-rightββ _ gβcΜ
ββ²)) x
comp-pres-β-lr : β {gβ gββ² gβ gββ²}
{cΜ
: CExpr gβ β gβ} {cΜ
β² : CExpr gββ² β gββ²}
β β’l cΜ
β gββ²
β β’r gβ β cΜ
β²
β β’ cΜ
β cΜ
β²
comp-pres-β-lr cΜ
βgββ² (β-id gβgβ²) = β-left-expand cΜ
βgββ²
comp-pres-β-lr cΜ
βgββ² (β-cast gββcΜ
β² x y) = β-castr (comp-pres-β-lr cΜ
βgββ² gββcΜ
β²) x y
comp-pres-β-lr cΜ
βgββ² (β-β₯ x y) = β-β₯ (projβ (prec-leftββ _ cΜ
βgββ²)) y
comp-pres-β-rl : β {gβ gββ² gβ gββ²}
{cΜ
: CExpr gβ β gβ} {cΜ
β² : CExpr gββ² β gββ²}
β β’r gβ β cΜ
β²
β β’l cΜ
β gββ²
β β’ cΜ
β cΜ
β²
comp-pres-β-rl gββcΜ
β² (β-id gβgβ²) = β-right-expand gββcΜ
β²
comp-pres-β-rl gββcΜ
β² (β-cast cΜ
βgββ² gββgββ² gββgββ²) = β-castl (comp-pres-β-rl gββcΜ
β² cΜ
βgββ²) gββgββ² gββgββ²
comp-pres-β-lb : β {gβ gββ² gβ gββ² gβ}
{cΜ
β : CExpr gβ β gβ} {cΜ
β : CExpr gβ β gβ}
{cΜ
β² : CExpr gββ² β gββ²}
β β’l cΜ
β β gββ²
β β’ cΜ
β β cΜ
β²
β β’ cΜ
β β¨ cΜ
β β cΜ
β²
comp-pres-β-lb cΜ
ββgβ (β-id gβgβ²) = β-castl (β-left-expand cΜ
ββgβ) gβgβ² gβgβ²
comp-pres-β-lb cΜ
ββgβ (β-cast cΜ
βcΜ
β² gββgββ² gββgββ²) = β-cast (comp-pres-β-lb cΜ
ββgβ cΜ
βcΜ
β²) gββgββ² gββgββ²
comp-pres-β-lb cΜ
ββgβ (β-castl cΜ
βcΜ
β² gββgβ² gββgβ²) = β-castl (comp-pres-β-lb cΜ
ββgβ cΜ
βcΜ
β²) gββgβ² gββgβ²
comp-pres-β-lb cΜ
ββgβ (β-castr cΜ
βcΜ
β² gβgββ² gβgββ²) = β-castr (comp-pres-β-lb cΜ
ββgβ cΜ
βcΜ
β²) gβgββ² gβgββ²
comp-pres-β-lb cΜ
ββgβ (β-β₯ gββgββ² gββgββ²) = β-β₯ (projβ (prec-leftββ _ cΜ
ββgβ)) gββgββ²
comp-pres-β-rb : β {gβ gββ² gβ gββ² gββ²}
{cΜ
: CExpr gβ β gβ}
{cΜ
ββ² : CExpr gββ² β gββ²} {cΜ
ββ² : CExpr gββ² β gββ²}
β β’r gβ β cΜ
ββ²
β β’ cΜ
β cΜ
ββ²
β β’ cΜ
β cΜ
ββ² β¨ cΜ
ββ²
comp-pres-β-rb gββcΜ
ββ² (β-id gβgβ²) = β-castr (β-right-expand gββcΜ
ββ²) gβgβ² gβgβ²
comp-pres-β-rb gββcΜ
ββ² (β-cast cΜ
βcΜ
ββ² x y) = β-cast (comp-pres-β-rb gββcΜ
ββ² cΜ
βcΜ
ββ²) x y
comp-pres-β-rb gββcΜ
ββ² (β-castl cΜ
βcΜ
ββ² x y) = β-castl (comp-pres-β-rb gββcΜ
ββ² cΜ
βcΜ
ββ²) x y
comp-pres-β-rb gββcΜ
ββ² (β-castr cΜ
βcΜ
ββ² x y) = β-castr (comp-pres-β-rb gββcΜ
ββ² cΜ
βcΜ
ββ²) x y
comp-pres-β-rb gββcΜ
ββ² (β-β₯ x y) = β-β₯ (projβ (prec-rightββ _ gββcΜ
ββ²)) y
comp-pres-β-bl : β {gβ gββ² gβ gββ² gβ}
{cΜ
β : CExpr gβ β gβ} {cΜ
β : CExpr gβ β gβ}
{cΜ
β² : CExpr gββ² β gββ²}
β β’ cΜ
β β cΜ
β²
β β’l cΜ
β β gββ²
β β’ cΜ
β β¨ cΜ
β β cΜ
β²
comp-pres-β-bl cΜ
ββcΜ
β² (β-id gβgβ²) = β-castl cΜ
ββcΜ
β² gβgβ² gβgβ²
comp-pres-β-bl cΜ
ββcΜ
β² (β-cast cΜ
ββgββ² gββgββ² gββgββ²) =
β-castl (comp-pres-β-bl cΜ
ββcΜ
β² cΜ
ββgββ²) gββgββ² gββgββ²
comp-pres-β-br : β {gβ gββ² gβ gββ² gββ²}
{cΜ
: CExpr gβ β gβ}
{cΜ
ββ² : CExpr gββ² β gββ²} {cΜ
ββ² : CExpr gββ² β gββ²}
β β’ cΜ
β cΜ
ββ²
β β’r gβ β cΜ
ββ²
β β’ cΜ
β cΜ
ββ² β¨ cΜ
ββ²
comp-pres-β-br cΜ
βcΜ
ββ² (β-id gβgβ²) = β-castr cΜ
βcΜ
ββ² gβgβ² gβgβ²
comp-pres-β-br cΜ
βcΜ
ββ² (β-cast x y z) = β-castr (comp-pres-β-br cΜ
βcΜ
ββ² x) y z
comp-pres-β-br cΜ
βcΜ
ββ² (β-β₯ _ x) = β-β₯ (projβ (precββ _ _ cΜ
βcΜ
ββ²)) x
comp-not-val : β {β gβ gβ}
β (cΜ
: CExpr l β β gβ)
β (dΜ
: CExpr gβ β gβ)
β Β¬ (CVal (cΜ
β¨ dΜ
))
comp-not-val c (id _) = Ξ» ()
comp-not-val c (d β¨Ύ _ !) (inj v) = contradiction v (comp-not-val c d)
comp-not-val c (d β¨Ύ β) (up v) = contradiction v (comp-not-val c d)
comp-not-val c (β₯ _ _ p) = Ξ» ()
comp-ββΊ : β {β gβ gβ} {cΜ
β : CExpr l β β gβ} {cΜ
β : CExpr gβ β gβ} {dΜ
}
β (cΜ
β β¨ cΜ
β) ββ dΜ
β CVal dΜ
β (cΜ
β β¨ cΜ
β) βββΊ dΜ
comp-ββΊ {cΜ
β = cΜ
β¨Ύ _ !} (_ β) (inj π) = contradiction π (comp-not-val _ cΜ
)
comp-ββΊ {cΜ
β = cΜ
β¨Ύ β} (_ β) (up π) = contradiction π (comp-not-val _ cΜ
)
comp-ββΊ (_ βββ¨ x β© r) _ = _ βββ¨ x β© r