Theory ExCF
section "Exact nonstandard semantics"
theory ExCF
imports HOLCF HOLCFUtils CPSScheme Utils
begin
text ‹
We now alter the standard semantics given in the previous section to calculate a control flow graph instead of the return value. At this point, we still ``run'' the program in full, so this is not yet the static analysis that we aim for. Instead, this is the reference for the correctness proof of the static analysis: If an edge is recorded here, we expect it to be found by the static analysis as well.
›
text ‹
In preparation of the correctness proof we change the type of the contour counters. Instead of plain natural numbers as in the previous sections we use lists of labels, remembering at each step which part of the program was just evaluated.
Note that for the exact semantics, this is information is not used in any way and it would have been possible to just use natural numbers again. This is reflected by the preorder instance for the contours which only look at the length of the list, but not the entries.
›
definition "contour = (UNIV::label list set)"
typedef contour = contour
unfolding contour_def by auto
definition initial_contour ("\<binit>")
where "\<binit> = Abs_contour []"
definition nb
where "nb b c = Abs_contour (c # Rep_contour b)"
instantiation contour :: preorder
begin
definition le_contour_def: "b ≤ b' ⟷ length (Rep_contour b) ≤ length (Rep_contour b')"
definition less_contour_def: "b < b' ⟷ length (Rep_contour b) < length (Rep_contour b')"
instance proof
qed(auto simp add:le_contour_def less_contour_def Rep_contour_inverse Abs_contour_inverse contour_def)
end
text ‹
Three simple lemmas helping Isabelle to automatically prove statements about contour numbers.
›
lemma nb_le_less[iff]: "nb b c ≤ b' ⟷ b < b'"
unfolding nb_def
by (auto simp add:le_contour_def less_contour_def Rep_contour_inverse Abs_contour_inverse contour_def)
lemma nb_less[iff]: "b' < nb b c ⟷ b' ≤ b"
unfolding nb_def
by (auto simp add:le_contour_def less_contour_def Rep_contour_inverse Abs_contour_inverse contour_def)
declare less_imp_le[where 'a = contour, intro]
text ‹
The other types used in our semantics functions have not changed.
›
type_synonym benv = "label ⇀ contour"
type_synonym closure = "lambda × benv"