Theory Expressions
section ‹Expressions›
theory Expressions
imports Contracts StateMonad
begin
subsection ‹Semantics of Expressions›
definition lift ::
"(e ⇒ environment ⇒ calldataT ⇒ state ⇒ (stackvalue * type, ex, gas) state_monad)
⇒ (types ⇒ types ⇒ valuetype ⇒ valuetype ⇒ (valuetype * types) option)
⇒ e ⇒ e ⇒ environment ⇒ calldataT ⇒ state ⇒ (stackvalue * type, ex, gas) state_monad"
where
"lift expr f e1 e2 e cd st ≡
(do {
kv1 ← expr e1 e cd st;
(v1, t1) ← case kv1 of (KValue v1, Value t1) ⇒ return (v1, t1) | _ ⇒ (throw Err::(valuetype * types, ex, gas) state_monad);
kv2 ← expr e2 e cd st;
(v2, t2) ← case kv2 of (KValue v2, Value t2) ⇒ return (v2, t2) | _ ⇒ (throw Err::(valuetype * types, ex, gas) state_monad);
(v, t) ← (option Err (λ_::gas. f t1 t2 v1 v2))::(valuetype * types, ex, gas) state_monad;
return (KValue v, Value t)::(stackvalue * type, ex, gas) state_monad
})"
declare lift_def[simp]
lemma lift_cong [fundef_cong]:
assumes "expr e1 e cd st g = expr' e1 e cd st g"
and "⋀v g'. expr' e1 e cd st g = Normal (v,g') ⟹ expr e2 e cd st g' = expr' e2 e cd st g'"
shows "lift expr f e1 e2 e cd st g = lift expr' f e1 e2 e cd st g"
unfolding lift_def using assms by (auto split: prod.split_asm result.split option.split_asm option.split stackvalue.split type.split)