author | nipkow |
Mon, 11 Mar 2013 12:27:31 +0100 | |
changeset 51390 | 1dff81cf425b |
parent 51389 | 8a9f0503b1c0 |
child 51625 | bd3358aac5d2 |
permissions | -rw-r--r-- |
47613 | 1 |
(* Author: Tobias Nipkow *) |
2 |
||
3 |
theory Abs_Int0 |
|
4 |
imports Abs_Int_init |
|
5 |
begin |
|
6 |
||
7 |
subsection "Orderings" |
|
8 |
||
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
9 |
declare order_trans[trans] |
47613 | 10 |
|
51389 | 11 |
class semilattice = semilattice_sup + top |
47613 | 12 |
|
13 |
||
51389 | 14 |
instance "fun" :: (type, semilattice) semilattice .. |
47613 | 15 |
|
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
16 |
instantiation option :: (order)order |
47613 | 17 |
begin |
18 |
||
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
19 |
fun less_eq_option where |
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
20 |
"Some x \<le> Some y = (x \<le> y)" | |
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
21 |
"None \<le> y = True" | |
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
22 |
"Some _ \<le> None = False" |
47613 | 23 |
|
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
24 |
definition less_option where "x < (y::'a option) = (x \<le> y \<and> \<not> y \<le> x)" |
47613 | 25 |
|
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
26 |
lemma [simp]: "(x \<le> None) = (x = None)" |
47613 | 27 |
by (cases x) simp_all |
28 |
||
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
29 |
lemma [simp]: "(Some x \<le> u) = (\<exists>y. u = Some y \<and> x \<le> y)" |
47613 | 30 |
by (cases u) auto |
31 |
||
32 |
instance proof |
|
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
33 |
case goal1 show ?case by(rule less_option_def) |
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
34 |
next |
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
35 |
case goal2 show ?case by(cases x, simp_all) |
47613 | 36 |
next |
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
37 |
case goal3 thus ?case by(cases z, simp, cases y, simp, cases x, auto) |
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
38 |
next |
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
39 |
case goal4 thus ?case by(cases y, simp, cases x, auto) |
47613 | 40 |
qed |
41 |
||
42 |
end |
|
43 |
||
51389 | 44 |
instantiation option :: (sup)sup |
47613 | 45 |
begin |
46 |
||
51389 | 47 |
fun sup_option where |
47613 | 48 |
"Some x \<squnion> Some y = Some(x \<squnion> y)" | |
49 |
"None \<squnion> y = y" | |
|
50 |
"x \<squnion> None = x" |
|
51 |
||
51389 | 52 |
lemma sup_None2[simp]: "x \<squnion> None = x" |
47613 | 53 |
by (cases x) simp_all |
54 |
||
55 |
instance .. |
|
56 |
||
57 |
end |
|
58 |
||
49396 | 59 |
instantiation option :: (semilattice)semilattice |
47613 | 60 |
begin |
61 |
||
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
62 |
definition top_option where "\<top> = Some \<top>" |
47613 | 63 |
|
64 |
instance proof |
|
51389 | 65 |
case goal4 show ?case by(cases a, simp_all add: top_option_def) |
47613 | 66 |
next |
51389 | 67 |
case goal1 thus ?case by(cases x, simp, cases y, simp_all) |
47613 | 68 |
next |
51389 | 69 |
case goal2 thus ?case by(cases y, simp, cases x, simp_all) |
47613 | 70 |
next |
51389 | 71 |
case goal3 thus ?case by(cases z, simp, cases y, simp, cases x, simp_all) |
47613 | 72 |
qed |
73 |
||
74 |
end |
|
75 |
||
51390 | 76 |
lemma [simp]: "(Some x < Some y) = (x < y)" |
77 |
by(auto simp: less_le) |
|
78 |
||
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
79 |
instantiation option :: (order)bot |
47613 | 80 |
begin |
81 |
||
49396 | 82 |
definition bot_option :: "'a option" where |
47613 | 83 |
"\<bottom> = None" |
84 |
||
85 |
instance |
|
86 |
proof |
|
49396 | 87 |
case goal1 thus ?case by(auto simp: bot_option_def) |
47613 | 88 |
qed |
89 |
||
90 |
end |
|
91 |
||
92 |
||
93 |
definition bot :: "com \<Rightarrow> 'a option acom" where |
|
94 |
"bot c = anno None c" |
|
95 |
||
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
96 |
lemma bot_least: "strip C = c \<Longrightarrow> bot c \<le> C" |
47613 | 97 |
by(induct C arbitrary: c)(auto simp: bot_def) |
98 |
||
99 |
lemma strip_bot[simp]: "strip(bot c) = c" |
|
100 |
by(simp add: bot_def) |
|
101 |
||
102 |
||
103 |
subsubsection "Post-fixed point iteration" |
|
104 |
||
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
105 |
definition pfp :: "(('a::order) \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'a option" where |
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
106 |
"pfp f = while_option (\<lambda>x. \<not> f x \<le> x) f" |
47613 | 107 |
|
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
108 |
lemma pfp_pfp: assumes "pfp f x0 = Some x" shows "f x \<le> x" |
47613 | 109 |
using while_option_stop[OF assms[simplified pfp_def]] by simp |
110 |
||
49464 | 111 |
lemma while_least: |
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
112 |
fixes q :: "'a::order" |
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
113 |
assumes "\<forall>x\<in>L.\<forall>y\<in>L. x \<le> y \<longrightarrow> f x \<le> f y" and "\<forall>x. x \<in> L \<longrightarrow> f x \<in> L" |
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
114 |
and "\<forall>x \<in> L. b \<le> x" and "b \<in> L" and "f q \<le> q" and "q \<in> L" |
49464 | 115 |
and "while_option P f b = Some p" |
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
116 |
shows "p \<le> q" |
49464 | 117 |
using while_option_rule[OF _ assms(7)[unfolded pfp_def], |
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
118 |
where P = "%x. x \<in> L \<and> x \<le> q"] |
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
119 |
by (metis assms(1-6) order_trans) |
47613 | 120 |
|
49464 | 121 |
lemma pfp_inv: |
122 |
"pfp f x = Some y \<Longrightarrow> (\<And>x. P x \<Longrightarrow> P(f x)) \<Longrightarrow> P x \<Longrightarrow> P y" |
|
123 |
unfolding pfp_def by (metis (lifting) while_option_rule) |
|
47613 | 124 |
|
125 |
lemma strip_pfp: |
|
126 |
assumes "\<And>x. g(f x) = g x" and "pfp f x0 = Some x" shows "g x = g x0" |
|
49464 | 127 |
using pfp_inv[OF assms(2), where P = "%x. g x = g x0"] assms(1) by simp |
47613 | 128 |
|
129 |
||
130 |
subsection "Abstract Interpretation" |
|
131 |
||
132 |
definition \<gamma>_fun :: "('a \<Rightarrow> 'b set) \<Rightarrow> ('c \<Rightarrow> 'a) \<Rightarrow> ('c \<Rightarrow> 'b)set" where |
|
133 |
"\<gamma>_fun \<gamma> F = {f. \<forall>x. f x \<in> \<gamma>(F x)}" |
|
134 |
||
135 |
fun \<gamma>_option :: "('a \<Rightarrow> 'b set) \<Rightarrow> 'a option \<Rightarrow> 'b set" where |
|
136 |
"\<gamma>_option \<gamma> None = {}" | |
|
137 |
"\<gamma>_option \<gamma> (Some a) = \<gamma> a" |
|
138 |
||
139 |
text{* The interface for abstract values: *} |
|
140 |
||
141 |
locale Val_abs = |
|
49396 | 142 |
fixes \<gamma> :: "'av::semilattice \<Rightarrow> val set" |
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
143 |
assumes mono_gamma: "a \<le> b \<Longrightarrow> \<gamma> a \<le> \<gamma> b" |
47613 | 144 |
and gamma_Top[simp]: "\<gamma> \<top> = UNIV" |
145 |
fixes num' :: "val \<Rightarrow> 'av" |
|
146 |
and plus' :: "'av \<Rightarrow> 'av \<Rightarrow> 'av" |
|
51036 | 147 |
assumes gamma_num': "i \<in> \<gamma>(num' i)" |
148 |
and gamma_plus': "i1 \<in> \<gamma> a1 \<Longrightarrow> i2 \<in> \<gamma> a2 \<Longrightarrow> i1+i2 \<in> \<gamma>(plus' a1 a2)" |
|
47613 | 149 |
|
150 |
type_synonym 'av st = "(vname \<Rightarrow> 'av)" |
|
151 |
||
49396 | 152 |
locale Abs_Int_Fun = Val_abs \<gamma> for \<gamma> :: "'av::semilattice \<Rightarrow> val set" |
47613 | 153 |
begin |
154 |
||
155 |
fun aval' :: "aexp \<Rightarrow> 'av st \<Rightarrow> 'av" where |
|
50896 | 156 |
"aval' (N i) S = num' i" | |
47613 | 157 |
"aval' (V x) S = S x" | |
158 |
"aval' (Plus a1 a2) S = plus' (aval' a1 S) (aval' a2 S)" |
|
159 |
||
51390 | 160 |
definition "step' = Step |
51389 | 161 |
(\<lambda>x e S. case S of None \<Rightarrow> None | Some S \<Rightarrow> Some(S(x := aval' e S))) |
162 |
(\<lambda>b S. S)" |
|
163 |
||
47613 | 164 |
definition AI :: "com \<Rightarrow> 'av st option acom option" where |
49464 | 165 |
"AI c = pfp (step' \<top>) (bot c)" |
47613 | 166 |
|
167 |
||
49497 | 168 |
abbreviation \<gamma>\<^isub>s :: "'av st \<Rightarrow> state set" |
169 |
where "\<gamma>\<^isub>s == \<gamma>_fun \<gamma>" |
|
47613 | 170 |
|
171 |
abbreviation \<gamma>\<^isub>o :: "'av st option \<Rightarrow> state set" |
|
49497 | 172 |
where "\<gamma>\<^isub>o == \<gamma>_option \<gamma>\<^isub>s" |
47613 | 173 |
|
174 |
abbreviation \<gamma>\<^isub>c :: "'av st option acom \<Rightarrow> state set acom" |
|
175 |
where "\<gamma>\<^isub>c == map_acom \<gamma>\<^isub>o" |
|
176 |
||
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
177 |
lemma gamma_s_Top[simp]: "\<gamma>\<^isub>s \<top> = UNIV" |
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
178 |
by(simp add: top_fun_def \<gamma>_fun_def) |
47613 | 179 |
|
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
180 |
lemma gamma_o_Top[simp]: "\<gamma>\<^isub>o \<top> = UNIV" |
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
181 |
by (simp add: top_option_def) |
47613 | 182 |
|
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
183 |
lemma mono_gamma_s: "f1 \<le> f2 \<Longrightarrow> \<gamma>\<^isub>s f1 \<subseteq> \<gamma>\<^isub>s f2" |
47613 | 184 |
by(auto simp: le_fun_def \<gamma>_fun_def dest: mono_gamma) |
185 |
||
186 |
lemma mono_gamma_o: |
|
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
187 |
"S1 \<le> S2 \<Longrightarrow> \<gamma>\<^isub>o S1 \<subseteq> \<gamma>\<^isub>o S2" |
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
188 |
by(induction S1 S2 rule: less_eq_option.induct)(simp_all add: mono_gamma_s) |
47613 | 189 |
|
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
190 |
lemma mono_gamma_c: "C1 \<le> C2 \<Longrightarrow> \<gamma>\<^isub>c C1 \<le> \<gamma>\<^isub>c C2" |
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
191 |
by (induction C1 C2 rule: less_eq_acom.induct) (simp_all add:mono_gamma_o) |
47613 | 192 |
|
193 |
text{* Soundness: *} |
|
194 |
||
49497 | 195 |
lemma aval'_sound: "s : \<gamma>\<^isub>s S \<Longrightarrow> aval a s : \<gamma>(aval' a S)" |
47613 | 196 |
by (induct a) (auto simp: gamma_num' gamma_plus' \<gamma>_fun_def) |
197 |
||
51390 | 198 |
lemma in_gamma_update: "\<lbrakk> s : \<gamma>\<^isub>s S; i : \<gamma> a \<rbrakk> \<Longrightarrow> s(x := i) : \<gamma>\<^isub>s(S(x := a))" |
47613 | 199 |
by(simp add: \<gamma>_fun_def) |
200 |
||
51390 | 201 |
lemma gamma_Step_subcomm: |
202 |
assumes "!!x e S. f1 x e (\<gamma>\<^isub>o S) \<subseteq> \<gamma>\<^isub>o (f2 x e S)" "!!b S. g1 b (\<gamma>\<^isub>o S) \<subseteq> \<gamma>\<^isub>o (g2 b S)" |
|
203 |
shows "Step f1 g1 (\<gamma>\<^isub>o S) (\<gamma>\<^isub>c C) \<le> \<gamma>\<^isub>c (Step f2 g2 S C)" |
|
204 |
proof(induction C arbitrary: S) |
|
205 |
qed (auto simp: mono_gamma_o assms) |
|
206 |
||
50986 | 207 |
lemma step_step': "step (\<gamma>\<^isub>o S) (\<gamma>\<^isub>c C) \<le> \<gamma>\<^isub>c (step' S C)" |
51390 | 208 |
unfolding step_def step'_def |
209 |
by(rule gamma_Step_subcomm) (auto simp: aval'_sound in_gamma_update split: option.splits) |
|
47613 | 210 |
|
211 |
lemma AI_sound: "AI c = Some C \<Longrightarrow> CS c \<le> \<gamma>\<^isub>c C" |
|
212 |
proof(simp add: CS_def AI_def) |
|
49464 | 213 |
assume 1: "pfp (step' \<top>) (bot c) = Some C" |
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
214 |
have pfp': "step' \<top> C \<le> C" by(rule pfp_pfp[OF 1]) |
50986 | 215 |
have 2: "step (\<gamma>\<^isub>o \<top>) (\<gamma>\<^isub>c C) \<le> \<gamma>\<^isub>c C" --"transfer the pfp'" |
216 |
proof(rule order_trans) |
|
217 |
show "step (\<gamma>\<^isub>o \<top>) (\<gamma>\<^isub>c C) \<le> \<gamma>\<^isub>c (step' \<top> C)" by(rule step_step') |
|
218 |
show "... \<le> \<gamma>\<^isub>c C" by (metis mono_gamma_c[OF pfp']) |
|
47613 | 219 |
qed |
51390 | 220 |
have 3: "strip (\<gamma>\<^isub>c C) = c" by(simp add: strip_pfp[OF _ 1] step'_def) |
50986 | 221 |
have "lfp c (step (\<gamma>\<^isub>o \<top>)) \<le> \<gamma>\<^isub>c C" |
222 |
by(rule lfp_lowerbound[simplified,where f="step (\<gamma>\<^isub>o \<top>)", OF 3 2]) |
|
223 |
thus "lfp c (step UNIV) \<le> \<gamma>\<^isub>c C" by simp |
|
47613 | 224 |
qed |
225 |
||
226 |
end |
|
227 |
||
228 |
||
229 |
subsubsection "Monotonicity" |
|
230 |
||
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
231 |
lemma mono_post: "C1 \<le> C2 \<Longrightarrow> post C1 \<le> post C2" |
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
232 |
by(induction C1 C2 rule: less_eq_acom.induct) (auto) |
47613 | 233 |
|
234 |
locale Abs_Int_Fun_mono = Abs_Int_Fun + |
|
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
235 |
assumes mono_plus': "a1 \<le> b1 \<Longrightarrow> a2 \<le> b2 \<Longrightarrow> plus' a1 a2 \<le> plus' b1 b2" |
47613 | 236 |
begin |
237 |
||
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
238 |
lemma mono_aval': "S \<le> S' \<Longrightarrow> aval' e S \<le> aval' e S'" |
47613 | 239 |
by(induction e)(auto simp: le_fun_def mono_plus') |
240 |
||
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
241 |
lemma mono_update: "a \<le> a' \<Longrightarrow> S \<le> S' \<Longrightarrow> S(x := a) \<le> S'(x := a')" |
47613 | 242 |
by(simp add: le_fun_def) |
243 |
||
51359
00b45c7e831f
major redesign: order instead of preorder, new definition of intervals as quotients
nipkow
parents:
51036
diff
changeset
|
244 |
lemma mono_step': "S1 \<le> S2 \<Longrightarrow> C1 \<le> C2 \<Longrightarrow> step' S1 C1 \<le> step' S2 C2" |
51390 | 245 |
unfolding step'_def |
246 |
by(rule mono2_Step) (auto simp: mono_update mono_aval' split: option.split) |
|
47613 | 247 |
|
248 |
end |
|
249 |
||
250 |
text{* Problem: not executable because of the comparison of abstract states, |
|
251 |
i.e. functions, in the post-fixedpoint computation. *} |
|
252 |
||
253 |
end |