| author | blanchet |
| Wed, 14 Dec 2011 23:08:03 +0100 | |
| changeset 45882 | 5d8a7fe36ce5 |
| parent 45623 | f682f3f7b726 |
| child 46039 | 698de142f6f9 |
| permissions | -rw-r--r-- |
| 45111 | 1 |
(* Author: Tobias Nipkow *) |
2 |
||
3 |
theory Abs_State |
|
4 |
imports Abs_Int0_fun |
|
5 |
"~~/src/HOL/Library/Char_ord" "~~/src/HOL/Library/List_lexord" |
|
6 |
(* Library import merely to allow string lists to be sorted for output *) |
|
7 |
begin |
|
8 |
||
9 |
subsection "Abstract State with Computable Ordering" |
|
10 |
||
11 |
text{* A concrete type of state with computable @{text"\<sqsubseteq>"}: *}
|
|
12 |
||
| 45212 | 13 |
datatype 'a st = FunDom "vname \<Rightarrow> 'a" "vname list" |
| 45111 | 14 |
|
15 |
fun "fun" where "fun (FunDom f _) = f" |
|
16 |
fun dom where "dom (FunDom _ A) = A" |
|
17 |
||
18 |
definition [simp]: "inter_list xs ys = [x\<leftarrow>xs. x \<in> set ys]" |
|
19 |
||
20 |
definition "show_st S = [(x,fun S x). x \<leftarrow> sort(dom S)]" |
|
21 |
||
|
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
22 |
definition "show_acom = map_acom (Option.map show_st)" |
|
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
23 |
definition "show_acom_opt = Option.map show_acom" |
| 45111 | 24 |
|
25 |
definition "lookup F x = (if x : set(dom F) then fun F x else \<top>)" |
|
26 |
||
27 |
definition "update F x y = |
|
28 |
FunDom ((fun F)(x:=y)) (if x \<in> set(dom F) then dom F else x # dom F)" |
|
29 |
||
30 |
lemma lookup_update: "lookup (update S x y) = (lookup S)(x:=y)" |
|
31 |
by(rule ext)(auto simp: lookup_def update_def) |
|
32 |
||
33 |
definition "rep_st rep F = {f. \<forall>x. f x \<in> rep(lookup F x)}"
|
|
34 |
||
35 |
instantiation st :: (SL_top) SL_top |
|
36 |
begin |
|
37 |
||
38 |
definition "le_st F G = (ALL x : set(dom G). lookup F x \<sqsubseteq> fun G x)" |
|
39 |
||
40 |
definition |
|
41 |
"join_st F G = |
|
42 |
FunDom (\<lambda>x. fun F x \<squnion> fun G x) (inter_list (dom F) (dom G))" |
|
43 |
||
44 |
definition "\<top> = FunDom (\<lambda>x. \<top>) []" |
|
45 |
||
46 |
instance |
|
47 |
proof |
|
48 |
case goal2 thus ?case |
|
49 |
apply(auto simp: le_st_def) |
|
50 |
by (metis lookup_def preord_class.le_trans top) |
|
51 |
qed (auto simp: le_st_def lookup_def join_st_def Top_st_def) |
|
52 |
||
53 |
end |
|
54 |
||
55 |
lemma mono_lookup: "F \<sqsubseteq> F' \<Longrightarrow> lookup F x \<sqsubseteq> lookup F' x" |
|
56 |
by(auto simp add: lookup_def le_st_def) |
|
57 |
||
58 |
lemma mono_update: "a \<sqsubseteq> a' \<Longrightarrow> S \<sqsubseteq> S' \<Longrightarrow> update S x a \<sqsubseteq> update S' x a'" |
|
59 |
by(auto simp add: le_st_def lookup_def update_def) |
|
60 |
||
|
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
61 |
context Val_abs |
| 45111 | 62 |
begin |
63 |
||
|
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
64 |
abbreviation rep_f :: "'a st \<Rightarrow> state set" ("\<gamma>\<^isub>f")
|
|
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
65 |
where "\<gamma>\<^isub>f == rep_st rep" |
| 45111 | 66 |
|
|
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
67 |
abbreviation rep_u :: "'a st option \<Rightarrow> state set" ("\<gamma>\<^isub>u")
|
|
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
68 |
where "\<gamma>\<^isub>u == rep_option \<gamma>\<^isub>f" |
| 45111 | 69 |
|
|
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
70 |
abbreviation rep_c :: "'a st option acom \<Rightarrow> state set acom" ("\<gamma>\<^isub>c")
|
|
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
71 |
where "\<gamma>\<^isub>c == map_acom \<gamma>\<^isub>u" |
| 45111 | 72 |
|
|
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
73 |
lemma rep_f_Top[simp]: "rep_f Top = UNIV" |
|
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
74 |
by(auto simp: Top_st_def rep_st_def lookup_def) |
|
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
75 |
|
|
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
76 |
lemma rep_u_Top[simp]: "rep_u Top = UNIV" |
|
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
77 |
by (simp add: Top_option_def) |
| 45111 | 78 |
|
|
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
79 |
(* FIXME (maybe also le \<rightarrow> sqle?) *) |
|
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
80 |
|
|
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
81 |
lemma mono_rep_f: "f \<sqsubseteq> g \<Longrightarrow> \<gamma>\<^isub>f f \<subseteq> \<gamma>\<^isub>f g" |
|
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
82 |
apply(simp add:rep_st_def subset_iff lookup_def le_st_def split: if_splits) |
|
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
83 |
by (metis UNIV_I mono_rep rep_Top subsetD) |
| 45111 | 84 |
|
|
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
85 |
lemma mono_rep_u: |
|
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
86 |
"sa \<sqsubseteq> sa' \<Longrightarrow> \<gamma>\<^isub>u sa \<subseteq> \<gamma>\<^isub>u sa'" |
|
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
87 |
by(induction sa sa' rule: le_option.induct)(simp_all add: mono_rep_f) |
| 45111 | 88 |
|
|
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
89 |
lemma mono_rep_c: "ca \<sqsubseteq> ca' \<Longrightarrow> \<gamma>\<^isub>c ca \<le> \<gamma>\<^isub>c ca'" |
|
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
90 |
by (induction ca ca' rule: le_acom.induct) (simp_all add:mono_rep_u) |
|
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
91 |
|
|
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45212
diff
changeset
|
92 |
lemma in_rep_up_iff: "x : rep_option r u \<longleftrightarrow> (\<exists>u'. u = Some u' \<and> x : r u')" |
| 45111 | 93 |
by (cases u) auto |
94 |
||
95 |
end |
|
96 |
||
97 |
end |