7 subsection "Orderings" |
7 subsection "Orderings" |
8 |
8 |
9 declare order_trans[trans] |
9 declare order_trans[trans] |
10 |
10 |
11 class semilattice = semilattice_sup + top |
11 class semilattice = semilattice_sup + top |
12 (* + |
|
13 assumes join_ge1 [simp]: "x \<le> x \<squnion> y" |
|
14 and join_ge2 [simp]: "y \<le> x \<squnion> y" |
|
15 and join_least: "x \<le> z \<Longrightarrow> y \<le> z \<Longrightarrow> x \<squnion> y \<le> z" |
|
16 begin |
|
17 |
|
18 lemma join_le_iff[simp]: "x \<squnion> y \<le> z \<longleftrightarrow> x \<le> z \<and> y \<le> z" |
|
19 by (metis join_ge1 join_ge2 join_least order_trans) |
|
20 *) |
|
21 |
|
22 lemma le_join_disj: "x \<le> y \<or> x \<le> z \<Longrightarrow> x \<le> y \<squnion> (z::'a::semilattice_sup)" |
|
23 by (metis sup_ge1 sup_ge2 order_trans) |
|
24 |
12 |
25 |
13 |
26 instance "fun" :: (type, semilattice) semilattice .. |
14 instance "fun" :: (type, semilattice) semilattice .. |
27 (* |
|
28 definition top_fun where "top_fun = (\<lambda>x. \<top>)" |
|
29 |
|
30 lemma join_apply[simp]: "(f \<squnion> g) x = f x \<squnion> g x" |
|
31 by (simp add: join_fun_def) |
|
32 |
|
33 instance |
|
34 proof |
|
35 qed (simp_all add: le_fun_def) |
|
36 |
|
37 end |
|
38 *) |
|
39 |
15 |
40 instantiation option :: (order)order |
16 instantiation option :: (order)order |
41 begin |
17 begin |
42 |
18 |
43 fun less_eq_option where |
19 fun less_eq_option where |
94 next |
70 next |
95 case goal3 thus ?case by(cases z, simp, cases y, simp, cases x, simp_all) |
71 case goal3 thus ?case by(cases z, simp, cases y, simp, cases x, simp_all) |
96 qed |
72 qed |
97 |
73 |
98 end |
74 end |
|
75 |
|
76 lemma [simp]: "(Some x < Some y) = (x < y)" |
|
77 by(auto simp: less_le) |
99 |
78 |
100 instantiation option :: (order)bot |
79 instantiation option :: (order)bot |
101 begin |
80 begin |
102 |
81 |
103 definition bot_option :: "'a option" where |
82 definition bot_option :: "'a option" where |
176 fun aval' :: "aexp \<Rightarrow> 'av st \<Rightarrow> 'av" where |
155 fun aval' :: "aexp \<Rightarrow> 'av st \<Rightarrow> 'av" where |
177 "aval' (N i) S = num' i" | |
156 "aval' (N i) S = num' i" | |
178 "aval' (V x) S = S x" | |
157 "aval' (V x) S = S x" | |
179 "aval' (Plus a1 a2) S = plus' (aval' a1 S) (aval' a2 S)" |
158 "aval' (Plus a1 a2) S = plus' (aval' a1 S) (aval' a2 S)" |
180 |
159 |
181 (* Interpretation would be nicer but is impossible *) |
160 definition "step' = Step |
182 definition "step' = Step.Step |
|
183 (\<lambda>x e S. case S of None \<Rightarrow> None | Some S \<Rightarrow> Some(S(x := aval' e S))) |
161 (\<lambda>x e S. case S of None \<Rightarrow> None | Some S \<Rightarrow> Some(S(x := aval' e S))) |
184 (\<lambda>b S. S)" |
162 (\<lambda>b S. S)" |
185 |
163 |
186 lemma [simp]: "step' S (SKIP {P}) = (SKIP {S})" |
|
187 by(simp add: step'_def Step.Step.simps) |
|
188 lemma [simp]: "step' S (x ::= e {P}) = |
|
189 x ::= e {case S of None \<Rightarrow> None | Some S \<Rightarrow> Some(S(x := aval' e S))}" |
|
190 by(simp add: step'_def Step.Step.simps) |
|
191 lemma [simp]: "step' S (C1; C2) = step' S C1; step' (post C1) C2" |
|
192 by(simp add: step'_def Step.Step.simps) |
|
193 lemma [simp]: "step' S (IF b THEN {P1} C1 ELSE {P2} C2 {Q}) = |
|
194 IF b THEN {S} step' P1 C1 ELSE {S} step' P2 C2 |
|
195 {post C1 \<squnion> post C2}" |
|
196 by(simp add: step'_def Step.Step.simps) |
|
197 lemma [simp]: "step' S ({I} WHILE b DO {P} C {Q}) = |
|
198 {S \<squnion> post C} WHILE b DO {I} step' P C {I}" |
|
199 by(simp add: step'_def Step.Step.simps) |
|
200 |
|
201 definition AI :: "com \<Rightarrow> 'av st option acom option" where |
164 definition AI :: "com \<Rightarrow> 'av st option acom option" where |
202 "AI c = pfp (step' \<top>) (bot c)" |
165 "AI c = pfp (step' \<top>) (bot c)" |
203 |
|
204 |
|
205 lemma strip_step'[simp]: "strip(step' S C) = strip C" |
|
206 by(induct C arbitrary: S) (simp_all add: Let_def) |
|
207 |
166 |
208 |
167 |
209 abbreviation \<gamma>\<^isub>s :: "'av st \<Rightarrow> state set" |
168 abbreviation \<gamma>\<^isub>s :: "'av st \<Rightarrow> state set" |
210 where "\<gamma>\<^isub>s == \<gamma>_fun \<gamma>" |
169 where "\<gamma>\<^isub>s == \<gamma>_fun \<gamma>" |
211 |
170 |
234 text{* Soundness: *} |
193 text{* Soundness: *} |
235 |
194 |
236 lemma aval'_sound: "s : \<gamma>\<^isub>s S \<Longrightarrow> aval a s : \<gamma>(aval' a S)" |
195 lemma aval'_sound: "s : \<gamma>\<^isub>s S \<Longrightarrow> aval a s : \<gamma>(aval' a S)" |
237 by (induct a) (auto simp: gamma_num' gamma_plus' \<gamma>_fun_def) |
196 by (induct a) (auto simp: gamma_num' gamma_plus' \<gamma>_fun_def) |
238 |
197 |
239 lemma in_gamma_update: |
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))" |
240 "\<lbrakk> s : \<gamma>\<^isub>s S; i : \<gamma> a \<rbrakk> \<Longrightarrow> s(x := i) : \<gamma>\<^isub>s(S(x := a))" |
|
241 by(simp add: \<gamma>_fun_def) |
199 by(simp add: \<gamma>_fun_def) |
242 |
200 |
|
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 |
243 lemma step_step': "step (\<gamma>\<^isub>o S) (\<gamma>\<^isub>c C) \<le> \<gamma>\<^isub>c (step' S C)" |
207 lemma step_step': "step (\<gamma>\<^isub>o S) (\<gamma>\<^isub>c C) \<le> \<gamma>\<^isub>c (step' S C)" |
244 proof(induction C arbitrary: S) |
208 unfolding step_def step'_def |
245 case SKIP thus ?case by auto |
209 by(rule gamma_Step_subcomm) (auto simp: aval'_sound in_gamma_update split: option.splits) |
246 next |
|
247 case Assign thus ?case |
|
248 by (fastforce intro: aval'_sound in_gamma_update split: option.splits) |
|
249 next |
|
250 case Seq thus ?case by auto |
|
251 next |
|
252 case If thus ?case by (auto simp: mono_gamma_o) |
|
253 next |
|
254 case While thus ?case by (auto simp: mono_gamma_o) |
|
255 qed |
|
256 |
210 |
257 lemma AI_sound: "AI c = Some C \<Longrightarrow> CS c \<le> \<gamma>\<^isub>c C" |
211 lemma AI_sound: "AI c = Some C \<Longrightarrow> CS c \<le> \<gamma>\<^isub>c C" |
258 proof(simp add: CS_def AI_def) |
212 proof(simp add: CS_def AI_def) |
259 assume 1: "pfp (step' \<top>) (bot c) = Some C" |
213 assume 1: "pfp (step' \<top>) (bot c) = Some C" |
260 have pfp': "step' \<top> C \<le> C" by(rule pfp_pfp[OF 1]) |
214 have pfp': "step' \<top> C \<le> C" by(rule pfp_pfp[OF 1]) |
261 have 2: "step (\<gamma>\<^isub>o \<top>) (\<gamma>\<^isub>c C) \<le> \<gamma>\<^isub>c C" --"transfer the pfp'" |
215 have 2: "step (\<gamma>\<^isub>o \<top>) (\<gamma>\<^isub>c C) \<le> \<gamma>\<^isub>c C" --"transfer the pfp'" |
262 proof(rule order_trans) |
216 proof(rule order_trans) |
263 show "step (\<gamma>\<^isub>o \<top>) (\<gamma>\<^isub>c C) \<le> \<gamma>\<^isub>c (step' \<top> C)" by(rule step_step') |
217 show "step (\<gamma>\<^isub>o \<top>) (\<gamma>\<^isub>c C) \<le> \<gamma>\<^isub>c (step' \<top> C)" by(rule step_step') |
264 show "... \<le> \<gamma>\<^isub>c C" by (metis mono_gamma_c[OF pfp']) |
218 show "... \<le> \<gamma>\<^isub>c C" by (metis mono_gamma_c[OF pfp']) |
265 qed |
219 qed |
266 have 3: "strip (\<gamma>\<^isub>c C) = c" by(simp add: strip_pfp[OF _ 1]) |
220 have 3: "strip (\<gamma>\<^isub>c C) = c" by(simp add: strip_pfp[OF _ 1] step'_def) |
267 have "lfp c (step (\<gamma>\<^isub>o \<top>)) \<le> \<gamma>\<^isub>c C" |
221 have "lfp c (step (\<gamma>\<^isub>o \<top>)) \<le> \<gamma>\<^isub>c C" |
268 by(rule lfp_lowerbound[simplified,where f="step (\<gamma>\<^isub>o \<top>)", OF 3 2]) |
222 by(rule lfp_lowerbound[simplified,where f="step (\<gamma>\<^isub>o \<top>)", OF 3 2]) |
269 thus "lfp c (step UNIV) \<le> \<gamma>\<^isub>c C" by simp |
223 thus "lfp c (step UNIV) \<le> \<gamma>\<^isub>c C" by simp |
270 qed |
224 qed |
271 |
225 |
286 |
240 |
287 lemma mono_update: "a \<le> a' \<Longrightarrow> S \<le> S' \<Longrightarrow> S(x := a) \<le> S'(x := a')" |
241 lemma mono_update: "a \<le> a' \<Longrightarrow> S \<le> S' \<Longrightarrow> S(x := a) \<le> S'(x := a')" |
288 by(simp add: le_fun_def) |
242 by(simp add: le_fun_def) |
289 |
243 |
290 lemma mono_step': "S1 \<le> S2 \<Longrightarrow> C1 \<le> C2 \<Longrightarrow> step' S1 C1 \<le> step' S2 C2" |
244 lemma mono_step': "S1 \<le> S2 \<Longrightarrow> C1 \<le> C2 \<Longrightarrow> step' S1 C1 \<le> step' S2 C2" |
291 apply(induction C1 C2 arbitrary: S1 S2 rule: less_eq_acom.induct) |
245 unfolding step'_def |
292 apply (auto simp: Let_def mono_update mono_aval' mono_post le_join_disj |
246 by(rule mono2_Step) (auto simp: mono_update mono_aval' split: option.split) |
293 split: option.split) |
|
294 done |
|
295 |
247 |
296 end |
248 end |
297 |
249 |
298 text{* Problem: not executable because of the comparison of abstract states, |
250 text{* Problem: not executable because of the comparison of abstract states, |
299 i.e. functions, in the post-fixedpoint computation. *} |
251 i.e. functions, in the post-fixedpoint computation. *} |