header "Denotational Semantics of Commands"
theory Denotation imports Natural begin
types com_den = "(state×state)set"
definition
Gamma :: "[bexp,com_den] => (com_den => com_den)" where
"Gamma b cd = (λphi. {(s,t). (s,t) ∈ (cd O phi) ∧ b s} ∪
{(s,t). s=t ∧ ¬b s})"
primrec C :: "com => com_den"
where
C_skip: "C \<SKIP> = Id"
| C_assign: "C (x :== a) = {(s,t). t = s[x\<mapsto>a(s)]}"
| C_comp: "C (c0;c1) = C(c0) O C(c1)"
| C_if: "C (\<IF> b \<THEN> c1 \<ELSE> c2) = {(s,t). (s,t) ∈ C c1 ∧ b s} ∪
{(s,t). (s,t) ∈ C c2 ∧ ¬b s}"
| C_while: "C(\<WHILE> b \<DO> c) = lfp (Gamma b (C c))"
lemma Gamma_mono: "mono (Gamma b c)"
by (unfold Gamma_def mono_def) fast
lemma C_While_If: "C(\<WHILE> b \<DO> c) = C(\<IF> b \<THEN> c;\<WHILE> b \<DO> c \<ELSE> \<SKIP>)"
apply simp
apply (subst lfp_unfold [OF Gamma_mono]) --{*lhs only*}
apply (simp add: Gamma_def)
done
lemma com1: "〈c,s〉 -->\<^sub>c t ==> (s,t) ∈ C(c)"
apply (induct set: evalc)
apply auto
apply (unfold Gamma_def)
apply (subst lfp_unfold[OF Gamma_mono, simplified Gamma_def])
apply fast
apply (subst lfp_unfold[OF Gamma_mono, simplified Gamma_def])
apply auto
done
lemma com2: "(s,t) ∈ C(c) ==> 〈c,s〉 -->\<^sub>c t"
apply (induct c arbitrary: s t)
apply auto
apply blast
apply (erule lfp_induct2 [OF _ Gamma_mono])
apply (unfold Gamma_def)
apply auto
done
lemma denotational_is_natural: "(s,t) ∈ C(c) = (〈c,s〉 -->\<^sub>c t)"
by (fast elim: com2 dest: com1)
end