author | nipkow |
Thu, 19 Jan 2012 09:51:42 +0100 | |
changeset 46251 | 8fbcbcf4380e |
parent 46246 | e69684c1c142 |
child 46346 | 10c18630612a |
permissions | -rw-r--r-- |
45111 | 1 |
(* Author: Tobias Nipkow *) |
2 |
||
3 |
theory Abs_Int1 |
|
46246 | 4 |
imports Abs_Int0 Vars |
45111 | 5 |
begin |
6 |
||
7 |
instantiation prod :: (preord,preord) preord |
|
8 |
begin |
|
9 |
||
10 |
definition "le_prod p1 p2 = (fst p1 \<sqsubseteq> fst p2 \<and> snd p1 \<sqsubseteq> snd p2)" |
|
11 |
||
12 |
instance |
|
13 |
proof |
|
14 |
case goal1 show ?case by(simp add: le_prod_def) |
|
15 |
next |
|
16 |
case goal2 thus ?case unfolding le_prod_def by(metis le_trans) |
|
17 |
qed |
|
18 |
||
19 |
end |
|
20 |
||
46246 | 21 |
instantiation com :: vars |
22 |
begin |
|
23 |
||
24 |
fun vars_com :: "com \<Rightarrow> vname set" where |
|
25 |
"vars com.SKIP = {}" | |
|
26 |
"vars (x::=e) = {x} \<union> vars e" | |
|
27 |
"vars (c1;c2) = vars c1 \<union> vars c2" | |
|
28 |
"vars (IF b THEN c1 ELSE c2) = vars b \<union> vars c1 \<union> vars c2" | |
|
29 |
"vars (WHILE b DO c) = vars b \<union> vars c" |
|
30 |
||
31 |
instance .. |
|
32 |
||
33 |
end |
|
34 |
||
35 |
lemma finite_avars: "finite(vars(a::aexp))" |
|
36 |
by(induction a) simp_all |
|
37 |
||
38 |
lemma finite_bvars: "finite(vars(b::bexp))" |
|
39 |
by(induction b) (simp_all add: finite_avars) |
|
40 |
||
41 |
lemma finite_cvars: "finite(vars(c::com))" |
|
42 |
by(induction c) (simp_all add: finite_avars finite_bvars) |
|
43 |
||
45111 | 44 |
|
45 |
subsection "Backward Analysis of Expressions" |
|
46 |
||
47 |
hide_const bot |
|
48 |
||
49 |
class L_top_bot = SL_top + |
|
50 |
fixes meet :: "'a \<Rightarrow> 'a \<Rightarrow> 'a" (infixl "\<sqinter>" 65) |
|
51 |
and bot :: "'a" ("\<bottom>") |
|
52 |
assumes meet_le1 [simp]: "x \<sqinter> y \<sqsubseteq> x" |
|
53 |
and meet_le2 [simp]: "x \<sqinter> y \<sqsubseteq> y" |
|
54 |
and meet_greatest: "x \<sqsubseteq> y \<Longrightarrow> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<sqinter> z" |
|
55 |
assumes bot[simp]: "\<bottom> \<sqsubseteq> x" |
|
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
56 |
begin |
45111 | 57 |
|
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
58 |
lemma mono_meet: "x \<sqsubseteq> x' \<Longrightarrow> y \<sqsubseteq> y' \<Longrightarrow> x \<sqinter> y \<sqsubseteq> x' \<sqinter> y'" |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
59 |
by (metis meet_greatest meet_le1 meet_le2 le_trans) |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
60 |
|
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
61 |
end |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
62 |
|
46039 | 63 |
locale Val_abs1_gamma = |
46063 | 64 |
Val_abs where \<gamma> = \<gamma> for \<gamma> :: "'av::L_top_bot \<Rightarrow> val set" + |
46039 | 65 |
assumes inter_gamma_subset_gamma_meet: |
66 |
"\<gamma> a1 \<inter> \<gamma> a2 \<subseteq> \<gamma>(a1 \<sqinter> a2)" |
|
67 |
and gamma_Bot[simp]: "\<gamma> \<bottom> = {}" |
|
45111 | 68 |
begin |
69 |
||
46039 | 70 |
lemma in_gamma_meet: "x : \<gamma> a1 \<Longrightarrow> x : \<gamma> a2 \<Longrightarrow> x : \<gamma>(a1 \<sqinter> a2)" |
71 |
by (metis IntI inter_gamma_subset_gamma_meet set_mp) |
|
45111 | 72 |
|
46039 | 73 |
lemma gamma_meet[simp]: "\<gamma>(a1 \<sqinter> a2) = \<gamma> a1 \<inter> \<gamma> a2" |
74 |
by (metis equalityI inter_gamma_subset_gamma_meet le_inf_iff mono_gamma meet_le1 meet_le2) |
|
45111 | 75 |
|
76 |
end |
|
77 |
||
78 |
||
46063 | 79 |
locale Val_abs1 = |
80 |
Val_abs1_gamma where \<gamma> = \<gamma> |
|
81 |
for \<gamma> :: "'av::L_top_bot \<Rightarrow> val set" + |
|
82 |
fixes filter_plus' :: "'av \<Rightarrow> 'av \<Rightarrow> 'av \<Rightarrow> 'av * 'av" |
|
83 |
and filter_less' :: "bool \<Rightarrow> 'av \<Rightarrow> 'av \<Rightarrow> 'av * 'av" |
|
45111 | 84 |
assumes filter_plus': "filter_plus' a a1 a2 = (a1',a2') \<Longrightarrow> |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
85 |
n1 : \<gamma> a1 \<Longrightarrow> n2 : \<gamma> a2 \<Longrightarrow> n1+n2 : \<gamma> a \<Longrightarrow> n1 : \<gamma> a1' \<and> n2 : \<gamma> a2'" |
45111 | 86 |
and filter_less': "filter_less' (n1<n2) a1 a2 = (a1',a2') \<Longrightarrow> |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
87 |
n1 : \<gamma> a1 \<Longrightarrow> n2 : \<gamma> a2 \<Longrightarrow> n1 : \<gamma> a1' \<and> n2 : \<gamma> a2'" |
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
88 |
|
45111 | 89 |
|
46063 | 90 |
locale Abs_Int1 = |
91 |
Val_abs1 where \<gamma> = \<gamma> for \<gamma> :: "'av::L_top_bot \<Rightarrow> val set" |
|
45111 | 92 |
begin |
93 |
||
46039 | 94 |
lemma in_gamma_join_UpI: "s : \<gamma>\<^isub>o S1 \<or> s : \<gamma>\<^isub>o S2 \<Longrightarrow> s : \<gamma>\<^isub>o(S1 \<squnion> S2)" |
95 |
by (metis (no_types) join_ge1 join_ge2 mono_gamma_o set_rev_mp) |
|
45111 | 96 |
|
46063 | 97 |
fun aval'' :: "aexp \<Rightarrow> 'av st option \<Rightarrow> 'av" where |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
98 |
"aval'' e None = \<bottom>" | |
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
99 |
"aval'' e (Some sa) = aval' e sa" |
45111 | 100 |
|
46039 | 101 |
lemma aval''_sound: "s : \<gamma>\<^isub>o S \<Longrightarrow> aval a s : \<gamma>(aval'' a S)" |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
102 |
by(cases S)(simp add: aval'_sound)+ |
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
103 |
|
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
104 |
subsubsection "Backward analysis" |
45111 | 105 |
|
46063 | 106 |
fun afilter :: "aexp \<Rightarrow> 'av \<Rightarrow> 'av st option \<Rightarrow> 'av st option" where |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
107 |
"afilter (N n) a S = (if n : \<gamma> a then S else None)" | |
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
108 |
"afilter (V x) a S = (case S of None \<Rightarrow> None | Some S \<Rightarrow> |
45111 | 109 |
let a' = lookup S x \<sqinter> a in |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
110 |
if a' \<sqsubseteq> \<bottom> then None else Some(update S x a'))" | |
45111 | 111 |
"afilter (Plus e1 e2) a S = |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
112 |
(let (a1,a2) = filter_plus' a (aval'' e1 S) (aval'' e2 S) |
45111 | 113 |
in afilter e1 a1 (afilter e2 a2 S))" |
114 |
||
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
115 |
text{* The test for @{const bot} in the @{const V}-case is important: @{const |
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
116 |
bot} indicates that a variable has no possible values, i.e.\ that the current |
45111 | 117 |
program point is unreachable. But then the abstract state should collapse to |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
118 |
@{const None}. Put differently, we maintain the invariant that in an abstract |
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
119 |
state of the form @{term"Some s"}, all variables are mapped to non-@{const |
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
120 |
bot} values. Otherwise the (pointwise) join of two abstract states, one of |
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
121 |
which contains @{const bot} values, may produce too large a result, thus |
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
122 |
making the analysis less precise. *} |
45111 | 123 |
|
124 |
||
46063 | 125 |
fun bfilter :: "bexp \<Rightarrow> bool \<Rightarrow> 'av st option \<Rightarrow> 'av st option" where |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
126 |
"bfilter (Bc v) res S = (if v=res then S else None)" | |
45111 | 127 |
"bfilter (Not b) res S = bfilter b (\<not> res) S" | |
128 |
"bfilter (And b1 b2) res S = |
|
129 |
(if res then bfilter b1 True (bfilter b2 True S) |
|
130 |
else bfilter b1 False S \<squnion> bfilter b2 False S)" | |
|
131 |
"bfilter (Less e1 e2) res S = |
|
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
132 |
(let (res1,res2) = filter_less' res (aval'' e1 S) (aval'' e2 S) |
45111 | 133 |
in afilter e1 res1 (afilter e2 res2 S))" |
134 |
||
46039 | 135 |
lemma afilter_sound: "s : \<gamma>\<^isub>o S \<Longrightarrow> aval e s : \<gamma> a \<Longrightarrow> s : \<gamma>\<^isub>o (afilter e a S)" |
45111 | 136 |
proof(induction e arbitrary: a S) |
137 |
case N thus ?case by simp |
|
138 |
next |
|
139 |
case (V x) |
|
46039 | 140 |
obtain S' where "S = Some S'" and "s : \<gamma>\<^isub>f S'" using `s : \<gamma>\<^isub>o S` |
141 |
by(auto simp: in_gamma_option_iff) |
|
142 |
moreover hence "s x : \<gamma> (lookup S' x)" by(simp add: \<gamma>_st_def) |
|
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
143 |
moreover have "s x : \<gamma> a" using V by simp |
45111 | 144 |
ultimately show ?case using V(1) |
46039 | 145 |
by(simp add: lookup_update Let_def \<gamma>_st_def) |
146 |
(metis mono_gamma emptyE in_gamma_meet gamma_Bot subset_empty) |
|
45111 | 147 |
next |
148 |
case (Plus e1 e2) thus ?case |
|
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
149 |
using filter_plus'[OF _ aval''_sound[OF Plus(3)] aval''_sound[OF Plus(3)]] |
45111 | 150 |
by (auto split: prod.split) |
151 |
qed |
|
152 |
||
46039 | 153 |
lemma bfilter_sound: "s : \<gamma>\<^isub>o S \<Longrightarrow> bv = bval b s \<Longrightarrow> s : \<gamma>\<^isub>o(bfilter b bv S)" |
45111 | 154 |
proof(induction b arbitrary: S bv) |
45200 | 155 |
case Bc thus ?case by simp |
45111 | 156 |
next |
157 |
case (Not b) thus ?case by simp |
|
158 |
next |
|
46039 | 159 |
case (And b1 b2) thus ?case by(fastforce simp: in_gamma_join_UpI) |
45111 | 160 |
next |
161 |
case (Less e1 e2) thus ?case |
|
162 |
by (auto split: prod.split) |
|
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
163 |
(metis afilter_sound filter_less' aval''_sound Less) |
45111 | 164 |
qed |
165 |
||
166 |
||
46063 | 167 |
fun step' :: "'av st option \<Rightarrow> 'av st option acom \<Rightarrow> 'av st option acom" |
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
168 |
where |
45655
a49f9428aba4
simplified Collecting1 and renamed: step -> step', step_cs -> step
nipkow
parents:
45623
diff
changeset
|
169 |
"step' S (SKIP {P}) = (SKIP {S})" | |
a49f9428aba4
simplified Collecting1 and renamed: step -> step', step_cs -> step
nipkow
parents:
45623
diff
changeset
|
170 |
"step' S (x ::= e {P}) = |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
171 |
x ::= e {case S of None \<Rightarrow> None | Some S \<Rightarrow> Some(update S x (aval' e S))}" | |
45655
a49f9428aba4
simplified Collecting1 and renamed: step -> step', step_cs -> step
nipkow
parents:
45623
diff
changeset
|
172 |
"step' S (c1; c2) = step' S c1; step' (post c1) c2" | |
a49f9428aba4
simplified Collecting1 and renamed: step -> step', step_cs -> step
nipkow
parents:
45623
diff
changeset
|
173 |
"step' S (IF b THEN c1 ELSE c2 {P}) = |
a49f9428aba4
simplified Collecting1 and renamed: step -> step', step_cs -> step
nipkow
parents:
45623
diff
changeset
|
174 |
(let c1' = step' (bfilter b True S) c1; c2' = step' (bfilter b False S) c2 |
45111 | 175 |
in IF b THEN c1' ELSE c2' {post c1 \<squnion> post c2})" | |
45655
a49f9428aba4
simplified Collecting1 and renamed: step -> step', step_cs -> step
nipkow
parents:
45623
diff
changeset
|
176 |
"step' S ({Inv} WHILE b DO c {P}) = |
45111 | 177 |
{S \<squnion> post c} |
45655
a49f9428aba4
simplified Collecting1 and renamed: step -> step', step_cs -> step
nipkow
parents:
45623
diff
changeset
|
178 |
WHILE b DO step' (bfilter b True Inv) c |
45111 | 179 |
{bfilter b False Inv}" |
180 |
||
46063 | 181 |
definition AI :: "com \<Rightarrow> 'av st option acom option" where |
45655
a49f9428aba4
simplified Collecting1 and renamed: step -> step', step_cs -> step
nipkow
parents:
45623
diff
changeset
|
182 |
"AI = lpfp\<^isub>c (step' \<top>)" |
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
183 |
|
45655
a49f9428aba4
simplified Collecting1 and renamed: step -> step', step_cs -> step
nipkow
parents:
45623
diff
changeset
|
184 |
lemma strip_step'[simp]: "strip(step' S c) = strip c" |
45111 | 185 |
by(induct c arbitrary: S) (simp_all add: Let_def) |
186 |
||
187 |
||
188 |
subsubsection "Soundness" |
|
189 |
||
46039 | 190 |
lemma in_gamma_update: |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
191 |
"\<lbrakk> s : \<gamma>\<^isub>f S; i : \<gamma> a \<rbrakk> \<Longrightarrow> s(x := i) : \<gamma>\<^isub>f(update S x a)" |
46039 | 192 |
by(simp add: \<gamma>_st_def lookup_update) |
45111 | 193 |
|
46068 | 194 |
lemma step_preserves_le: |
195 |
"\<lbrakk> S \<subseteq> \<gamma>\<^isub>o S'; cs \<le> \<gamma>\<^isub>c ca \<rbrakk> \<Longrightarrow> step S cs \<le> \<gamma>\<^isub>c (step' S' ca)" |
|
196 |
proof(induction cs arbitrary: ca S S') |
|
197 |
case SKIP thus ?case by(auto simp:SKIP_le map_acom_SKIP) |
|
45111 | 198 |
next |
199 |
case Assign thus ?case |
|
46068 | 200 |
by (fastforce simp: Assign_le map_acom_Assign intro: aval'_sound in_gamma_update |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
201 |
split: option.splits del:subsetD) |
45111 | 202 |
next |
46068 | 203 |
case Semi thus ?case apply (auto simp: Semi_le map_acom_Semi) |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
204 |
by (metis le_post post_map_acom) |
45111 | 205 |
next |
46068 | 206 |
case (If b cs1 cs2 P) |
207 |
then obtain ca1 ca2 Pa where |
|
208 |
"ca= IF b THEN ca1 ELSE ca2 {Pa}" |
|
46039 | 209 |
"P \<subseteq> \<gamma>\<^isub>o Pa" "cs1 \<le> \<gamma>\<^isub>c ca1" "cs2 \<le> \<gamma>\<^isub>c ca2" |
46068 | 210 |
by (fastforce simp: If_le map_acom_If) |
46039 | 211 |
moreover have "post cs1 \<subseteq> \<gamma>\<^isub>o(post ca1 \<squnion> post ca2)" |
212 |
by (metis (no_types) `cs1 \<le> \<gamma>\<^isub>c ca1` join_ge1 le_post mono_gamma_o order_trans post_map_acom) |
|
213 |
moreover have "post cs2 \<subseteq> \<gamma>\<^isub>o(post ca1 \<squnion> post ca2)" |
|
214 |
by (metis (no_types) `cs2 \<le> \<gamma>\<^isub>c ca2` join_ge2 le_post mono_gamma_o order_trans post_map_acom) |
|
46067 | 215 |
ultimately show ?case using `S \<subseteq> \<gamma>\<^isub>o S'` |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
216 |
by (simp add: If.IH subset_iff bfilter_sound) |
45111 | 217 |
next |
46068 | 218 |
case (While I b cs1 P) |
219 |
then obtain ca1 Ia Pa where |
|
220 |
"ca = {Ia} WHILE b DO ca1 {Pa}" |
|
46039 | 221 |
"I \<subseteq> \<gamma>\<^isub>o Ia" "P \<subseteq> \<gamma>\<^isub>o Pa" "cs1 \<le> \<gamma>\<^isub>c ca1" |
46068 | 222 |
by (fastforce simp: map_acom_While While_le) |
46067 | 223 |
moreover have "S \<union> post cs1 \<subseteq> \<gamma>\<^isub>o (S' \<squnion> post ca1)" |
224 |
using `S \<subseteq> \<gamma>\<^isub>o S'` le_post[OF `cs1 \<le> \<gamma>\<^isub>c ca1`, simplified] |
|
46039 | 225 |
by (metis (no_types) join_ge1 join_ge2 le_sup_iff mono_gamma_o order_trans) |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
226 |
ultimately show ?case by (simp add: While.IH subset_iff bfilter_sound) |
45111 | 227 |
qed |
228 |
||
46070 | 229 |
lemma AI_sound: "AI c = Some c' \<Longrightarrow> CS c \<le> \<gamma>\<^isub>c c'" |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
230 |
proof(simp add: CS_def AI_def) |
45655
a49f9428aba4
simplified Collecting1 and renamed: step -> step', step_cs -> step
nipkow
parents:
45623
diff
changeset
|
231 |
assume 1: "lpfp\<^isub>c (step' \<top>) c = Some c'" |
a49f9428aba4
simplified Collecting1 and renamed: step -> step', step_cs -> step
nipkow
parents:
45623
diff
changeset
|
232 |
have 2: "step' \<top> c' \<sqsubseteq> c'" by(rule lpfpc_pfp[OF 1]) |
a49f9428aba4
simplified Collecting1 and renamed: step -> step', step_cs -> step
nipkow
parents:
45623
diff
changeset
|
233 |
have 3: "strip (\<gamma>\<^isub>c (step' \<top> c')) = c" |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
234 |
by(simp add: strip_lpfpc[OF _ 1]) |
46066 | 235 |
have "lfp (step UNIV) c \<le> \<gamma>\<^isub>c (step' \<top> c')" |
45903 | 236 |
proof(rule lfp_lowerbound[simplified,OF 3]) |
45655
a49f9428aba4
simplified Collecting1 and renamed: step -> step', step_cs -> step
nipkow
parents:
45623
diff
changeset
|
237 |
show "step UNIV (\<gamma>\<^isub>c (step' \<top> c')) \<le> \<gamma>\<^isub>c (step' \<top> c')" |
46068 | 238 |
proof(rule step_preserves_le[OF _ _]) |
46039 | 239 |
show "UNIV \<subseteq> \<gamma>\<^isub>o \<top>" by simp |
240 |
show "\<gamma>\<^isub>c (step' \<top> c') \<le> \<gamma>\<^isub>c c'" by(rule mono_gamma_c[OF 2]) |
|
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
241 |
qed |
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
242 |
qed |
46066 | 243 |
from this 2 show "lfp (step UNIV) c \<le> \<gamma>\<^isub>c c'" |
46039 | 244 |
by (blast intro: mono_gamma_c order_trans) |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
245 |
qed |
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
246 |
|
46246 | 247 |
|
248 |
subsubsection "Commands over a set of variables" |
|
249 |
||
250 |
text{* Key invariant: the domains of all abstract states are subsets of the |
|
251 |
set of variables of the program. *} |
|
252 |
||
253 |
definition "domo S = (case S of None \<Rightarrow> {} | Some S' \<Rightarrow> set(dom S'))" |
|
254 |
||
255 |
definition Com :: "vname set \<Rightarrow> 'a st option acom set" where |
|
256 |
"Com X = {c. \<forall>S \<in> set(annos c). domo S \<subseteq> X}" |
|
257 |
||
258 |
lemma domo_Top[simp]: "domo \<top> = {}" |
|
259 |
by(simp add: domo_def Top_st_def Top_option_def) |
|
260 |
||
46251 | 261 |
lemma bot_acom_Com[simp]: "\<bottom>\<^sub>c c \<in> Com X" |
46246 | 262 |
by(simp add: bot_acom_def Com_def domo_def set_annos_anno) |
263 |
||
264 |
lemma post_in_annos: "post c : set(annos c)" |
|
265 |
by(induction c) simp_all |
|
266 |
||
267 |
lemma domo_join: "domo (S \<squnion> T) \<subseteq> domo S \<union> domo T" |
|
268 |
by(auto simp: domo_def join_st_def split: option.split) |
|
269 |
||
270 |
lemma domo_afilter: "vars a \<subseteq> X \<Longrightarrow> domo S \<subseteq> X \<Longrightarrow> domo(afilter a i S) \<subseteq> X" |
|
271 |
apply(induction a arbitrary: i S) |
|
272 |
apply(simp add: domo_def) |
|
273 |
apply(simp add: domo_def Let_def update_def lookup_def split: option.splits) |
|
274 |
apply blast |
|
275 |
apply(simp split: prod.split) |
|
276 |
done |
|
277 |
||
278 |
lemma domo_bfilter: "vars b \<subseteq> X \<Longrightarrow> domo S \<subseteq> X \<Longrightarrow> domo(bfilter b bv S) \<subseteq> X" |
|
279 |
apply(induction b arbitrary: bv S) |
|
280 |
apply(simp add: domo_def) |
|
281 |
apply(simp) |
|
282 |
apply(simp) |
|
283 |
apply rule |
|
284 |
apply (metis le_sup_iff subset_trans[OF domo_join]) |
|
285 |
apply(simp split: prod.split) |
|
286 |
by (metis domo_afilter) |
|
287 |
||
288 |
lemma step'_Com: |
|
289 |
"domo S \<subseteq> X \<Longrightarrow> vars(strip c) \<subseteq> X \<Longrightarrow> c : Com X \<Longrightarrow> step' S c : Com X" |
|
290 |
apply(induction c arbitrary: S) |
|
291 |
apply(simp add: Com_def) |
|
292 |
apply(simp add: Com_def domo_def update_def split: option.splits) |
|
293 |
apply(simp (no_asm_use) add: Com_def ball_Un) |
|
294 |
apply (metis post_in_annos) |
|
295 |
apply(simp (no_asm_use) add: Com_def ball_Un) |
|
296 |
apply rule |
|
297 |
apply (metis Un_assoc domo_join order_trans post_in_annos subset_Un_eq) |
|
298 |
apply (metis domo_bfilter) |
|
299 |
apply(simp (no_asm_use) add: Com_def) |
|
300 |
apply rule |
|
301 |
apply (metis domo_join le_sup_iff post_in_annos subset_trans) |
|
302 |
apply rule |
|
303 |
apply (metis domo_bfilter) |
|
304 |
by (metis domo_bfilter) |
|
305 |
||
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
306 |
end |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
307 |
|
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
308 |
|
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
309 |
subsubsection "Monotonicity" |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
310 |
|
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
311 |
locale Abs_Int1_mono = Abs_Int1 + |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
312 |
assumes mono_plus': "a1 \<sqsubseteq> b1 \<Longrightarrow> a2 \<sqsubseteq> b2 \<Longrightarrow> plus' a1 a2 \<sqsubseteq> plus' b1 b2" |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
313 |
and mono_filter_plus': "a1 \<sqsubseteq> b1 \<Longrightarrow> a2 \<sqsubseteq> b2 \<Longrightarrow> r \<sqsubseteq> r' \<Longrightarrow> |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
314 |
filter_plus' r a1 a2 \<sqsubseteq> filter_plus' r' b1 b2" |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
315 |
and mono_filter_less': "a1 \<sqsubseteq> b1 \<Longrightarrow> a2 \<sqsubseteq> b2 \<Longrightarrow> |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
316 |
filter_less' bv a1 a2 \<sqsubseteq> filter_less' bv b1 b2" |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
317 |
begin |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
318 |
|
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
319 |
lemma mono_aval': "S \<sqsubseteq> S' \<Longrightarrow> aval' e S \<sqsubseteq> aval' e S'" |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
320 |
by(induction e) (auto simp: le_st_def lookup_def mono_plus') |
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
321 |
|
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
322 |
lemma mono_aval'': "S \<sqsubseteq> S' \<Longrightarrow> aval'' e S \<sqsubseteq> aval'' e S'" |
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
323 |
apply(cases S) |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
324 |
apply simp |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
325 |
apply(cases S') |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
326 |
apply simp |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
327 |
by (simp add: mono_aval') |
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
328 |
|
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
329 |
lemma mono_afilter: "r \<sqsubseteq> r' \<Longrightarrow> S \<sqsubseteq> S' \<Longrightarrow> afilter e r S \<sqsubseteq> afilter e r' S'" |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
330 |
apply(induction e arbitrary: r r' S S') |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
331 |
apply(auto simp: Let_def split: option.splits prod.splits) |
46039 | 332 |
apply (metis mono_gamma subsetD) |
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
333 |
apply(drule_tac x = "list" in mono_lookup) |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
334 |
apply (metis mono_meet le_trans) |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
335 |
apply (metis mono_meet mono_lookup mono_update) |
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
336 |
apply(metis mono_aval'' mono_filter_plus'[simplified le_prod_def] fst_conv snd_conv) |
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
337 |
done |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
338 |
|
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
339 |
lemma mono_bfilter: "S \<sqsubseteq> S' \<Longrightarrow> bfilter b r S \<sqsubseteq> bfilter b r S'" |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
340 |
apply(induction b arbitrary: r S S') |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
341 |
apply(auto simp: le_trans[OF _ join_ge1] le_trans[OF _ join_ge2] split: prod.splits) |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
342 |
apply(metis mono_aval'' mono_afilter mono_filter_less'[simplified le_prod_def] fst_conv snd_conv) |
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
343 |
done |
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
344 |
|
46153 | 345 |
lemma mono_step': "S \<sqsubseteq> S' \<Longrightarrow> c \<sqsubseteq> c' \<Longrightarrow> step' S c \<sqsubseteq> step' S' c'" |
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
346 |
apply(induction c c' arbitrary: S S' rule: le_acom.induct) |
46153 | 347 |
apply (auto simp: mono_post mono_bfilter mono_update mono_aval' Let_def le_join_disj |
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
348 |
split: option.split) |
45127
d2eb07a1e01b
separated monotonicity reasoning and defined narrowing with while_option
nipkow
parents:
45111
diff
changeset
|
349 |
done |
45111 | 350 |
|
46153 | 351 |
lemma mono_step'2: "mono (step' S)" |
352 |
by(simp add: mono_def mono_step'[OF le_refl]) |
|
45623
f682f3f7b726
Abstract interpretation is now based uniformly on annotated programs,
nipkow
parents:
45200
diff
changeset
|
353 |
|
45111 | 354 |
end |
355 |
||
356 |
end |