author | nipkow |
Tue, 18 Sep 2012 03:24:51 +0200 | |
changeset 49432 | 3f4104ccca77 |
parent 49431 | bf491a1c15c2 |
child 49464 | 4e4bdd12280f |
permissions | -rw-r--r-- |
47613 | 1 |
(* Author: Tobias Nipkow *) |
2 |
||
3 |
theory Abs_Int1 |
|
4 |
imports Abs_State |
|
5 |
begin |
|
6 |
||
7 |
lemma le_iff_le_annos_zip: "C1 \<sqsubseteq> C2 \<longleftrightarrow> |
|
8 |
(\<forall> (a1,a2) \<in> set(zip (annos C1) (annos C2)). a1 \<sqsubseteq> a2) \<and> strip C1 = strip C2" |
|
9 |
by(induct C1 C2 rule: le_acom.induct) (auto simp: size_annos_same2) |
|
10 |
||
11 |
lemma le_iff_le_annos: "C1 \<sqsubseteq> C2 \<longleftrightarrow> |
|
12 |
strip C1 = strip C2 \<and> (\<forall> i<size(annos C1). annos C1 ! i \<sqsubseteq> annos C2 ! i)" |
|
13 |
by(auto simp add: le_iff_le_annos_zip set_zip) (metis size_annos_same2) |
|
14 |
||
15 |
||
49396 | 16 |
lemma mono_fun_L[simp]: "F \<in> L X \<Longrightarrow> F \<sqsubseteq> G \<Longrightarrow> x : X \<Longrightarrow> fun F x \<sqsubseteq> fun G x" |
17 |
by(simp add: mono_fun L_st_def) |
|
47613 | 18 |
|
49396 | 19 |
lemma bot_in_L[simp]: "bot c \<in> L(vars c)" |
20 |
by(simp add: L_acom_def bot_def) |
|
47613 | 21 |
|
49396 | 22 |
lemma L_acom_simps[simp]: "SKIP {P} \<in> L X \<longleftrightarrow> P \<in> L X" |
23 |
"(x ::= e {P}) \<in> L X \<longleftrightarrow> x : X \<and> vars e \<subseteq> X \<and> P \<in> L X" |
|
24 |
"(C1;C2) \<in> L X \<longleftrightarrow> C1 \<in> L X \<and> C2 \<in> L X" |
|
25 |
"(IF b THEN {P1} C1 ELSE {P2} C2 {Q}) \<in> L X \<longleftrightarrow> |
|
26 |
vars b \<subseteq> X \<and> C1 \<in> L X \<and> C2 \<in> L X \<and> P1 \<in> L X \<and> P2 \<in> L X \<and> Q \<in> L X" |
|
27 |
"({I} WHILE b DO {P} C {Q}) \<in> L X \<longleftrightarrow> |
|
28 |
I \<in> L X \<and> vars b \<subseteq> X \<and> P \<in> L X \<and> C \<in> L X \<and> Q \<in> L X" |
|
29 |
by(auto simp add: L_acom_def) |
|
47613 | 30 |
|
49353 | 31 |
lemma post_in_annos: "post C : set(annos C)" |
32 |
by(induction C) auto |
|
33 |
||
49396 | 34 |
lemma post_in_L[simp]: "C \<in> L X \<Longrightarrow> post C \<in> L X" |
35 |
by(simp add: L_acom_def post_in_annos) |
|
47613 | 36 |
|
37 |
lemma lpfp_inv: |
|
38 |
assumes "lpfp f x0 = Some x" and "\<And>x. P x \<Longrightarrow> P(f x)" and "P(bot x0)" |
|
39 |
shows "P x" |
|
40 |
using assms unfolding lpfp_def pfp_def |
|
41 |
by (metis (lifting) while_option_rule) |
|
42 |
||
43 |
||
44 |
subsection "Computable Abstract Interpretation" |
|
45 |
||
46 |
text{* Abstract interpretation over type @{text st} instead of |
|
47 |
functions. *} |
|
48 |
||
49 |
context Gamma |
|
50 |
begin |
|
51 |
||
52 |
fun aval' :: "aexp \<Rightarrow> 'av st \<Rightarrow> 'av" where |
|
53 |
"aval' (N n) S = num' n" | |
|
54 |
"aval' (V x) S = fun S x" | |
|
55 |
"aval' (Plus a1 a2) S = plus' (aval' a1 S) (aval' a2 S)" |
|
56 |
||
57 |
lemma aval'_sound: "s : \<gamma>\<^isub>f S \<Longrightarrow> vars a \<subseteq> dom S \<Longrightarrow> aval a s : \<gamma>(aval' a S)" |
|
58 |
by (induction a) (auto simp: gamma_num' gamma_plus' \<gamma>_st_def) |
|
59 |
||
60 |
end |
|
61 |
||
62 |
text{* The for-clause (here and elsewhere) only serves the purpose of fixing |
|
63 |
the name of the type parameter @{typ 'av} which would otherwise be renamed to |
|
64 |
@{typ 'a}. *} |
|
65 |
||
49396 | 66 |
locale Abs_Int = Gamma where \<gamma>=\<gamma> for \<gamma> :: "'av::semilattice \<Rightarrow> val set" |
47613 | 67 |
begin |
68 |
||
69 |
fun step' :: "'av st option \<Rightarrow> 'av st option acom \<Rightarrow> 'av st option acom" where |
|
70 |
"step' S (SKIP {P}) = (SKIP {S})" | |
|
71 |
"step' S (x ::= e {P}) = |
|
72 |
x ::= e {case S of None \<Rightarrow> None | Some S \<Rightarrow> Some(update S x (aval' e S))}" | |
|
73 |
"step' S (C1; C2) = step' S C1; step' (post C1) C2" | |
|
49344 | 74 |
"step' S (IF b THEN {P1} C1 ELSE {P2} C2 {Q}) = |
75 |
(IF b THEN {S} step' P1 C1 ELSE {S} step' P2 C2 {post C1 \<squnion> post C2})" | |
|
76 |
"step' S ({I} WHILE b DO {P} C {Q}) = |
|
77 |
{S \<squnion> post C} WHILE b DO {I} step' P C {I}" |
|
47613 | 78 |
|
79 |
definition AI :: "com \<Rightarrow> 'av st option acom option" where |
|
80 |
"AI c = lpfp (step' (top c)) c" |
|
81 |
||
82 |
||
83 |
lemma strip_step'[simp]: "strip(step' S C) = strip C" |
|
84 |
by(induct C arbitrary: S) (simp_all add: Let_def) |
|
85 |
||
86 |
||
87 |
text{* Soundness: *} |
|
88 |
||
89 |
lemma in_gamma_update: |
|
90 |
"\<lbrakk> s : \<gamma>\<^isub>f S; i : \<gamma> a \<rbrakk> \<Longrightarrow> s(x := i) : \<gamma>\<^isub>f(update S x a)" |
|
91 |
by(simp add: \<gamma>_st_def) |
|
92 |
||
93 |
theorem step_preserves_le: |
|
49396 | 94 |
"\<lbrakk> S \<subseteq> \<gamma>\<^isub>o S'; C \<le> \<gamma>\<^isub>c C'; C' \<in> L X; S' \<in> L X \<rbrakk> \<Longrightarrow> step S C \<le> \<gamma>\<^isub>c (step' S' C')" |
47613 | 95 |
proof(induction C arbitrary: C' S S') |
96 |
case SKIP thus ?case by(auto simp:SKIP_le map_acom_SKIP) |
|
97 |
next |
|
98 |
case Assign thus ?case |
|
49396 | 99 |
by(fastforce simp: Assign_le map_acom_Assign L_st_def |
47613 | 100 |
intro: aval'_sound in_gamma_update split: option.splits) |
101 |
next |
|
47818 | 102 |
case Seq thus ?case apply (auto simp: Seq_le map_acom_Seq) |
49396 | 103 |
by (metis le_post post_map_acom post_in_L) |
47613 | 104 |
next |
49344 | 105 |
case (If b P1 C1 P2 C2 Q) |
106 |
then obtain P1' P2' C1' C2' Q' where |
|
107 |
"C' = IF b THEN {P1'} C1' ELSE {P2'} C2' {Q'}" |
|
108 |
"P1 \<subseteq> \<gamma>\<^isub>o P1'" "P2 \<subseteq> \<gamma>\<^isub>o P2'" "Q \<subseteq> \<gamma>\<^isub>o Q'" "C1 \<le> \<gamma>\<^isub>c C1'" "C2 \<le> \<gamma>\<^isub>c C2'" |
|
47613 | 109 |
by (fastforce simp: If_le map_acom_If) |
49396 | 110 |
moreover from this(1) `C' \<in> L X` |
111 |
have L: "C1' \<in> L X" "C2' \<in> L X" "P1' \<in> L X" "P2' \<in> L X" by simp_all |
|
47613 | 112 |
moreover have "post C1 \<subseteq> \<gamma>\<^isub>o(post C1' \<squnion> post C2')" |
49396 | 113 |
by (metis (no_types) `C1 \<le> \<gamma>\<^isub>c C1'` join_ge1 le_post mono_gamma_o order_trans post_map_acom L post_in_L) |
47613 | 114 |
moreover have "post C2 \<subseteq> \<gamma>\<^isub>o(post C1' \<squnion> post C2')" |
49396 | 115 |
by (metis (no_types) `C2 \<le> \<gamma>\<^isub>c C2'` join_ge2 le_post mono_gamma_o order_trans post_map_acom L post_in_L) |
116 |
ultimately show ?case using `S \<subseteq> \<gamma>\<^isub>o S'` `S' \<in> L X` |
|
47613 | 117 |
by (simp add: If.IH subset_iff) |
118 |
next |
|
49344 | 119 |
case (While I b P1 C1 Q) |
120 |
then obtain C1' I' P1' Q' where |
|
121 |
"C' = {I'} WHILE b DO {P1'} C1' {Q'}" |
|
122 |
"I \<subseteq> \<gamma>\<^isub>o I'" "P1 \<subseteq> \<gamma>\<^isub>o P1'" "C1 \<le> \<gamma>\<^isub>c C1'" "Q \<subseteq> \<gamma>\<^isub>o Q'" |
|
47613 | 123 |
by (fastforce simp: map_acom_While While_le) |
49396 | 124 |
moreover from this(1) `C' \<in> L X` |
125 |
have L: "C1' \<in> L X" "I' \<in> L X" "P1' \<in> L X" by simp_all |
|
126 |
moreover note compat = `S' \<in> L X` post_in_L[OF L(1)] |
|
47613 | 127 |
moreover have "S \<union> post C1 \<subseteq> \<gamma>\<^isub>o (S' \<squnion> post C1')" |
128 |
using `S \<subseteq> \<gamma>\<^isub>o S'` le_post[OF `C1 \<le> \<gamma>\<^isub>c C1'`, simplified] |
|
129 |
by (metis (no_types) join_ge1[OF compat] join_ge2[OF compat] le_sup_iff mono_gamma_o order_trans) |
|
130 |
ultimately show ?case by (simp add: While.IH subset_iff) |
|
131 |
qed |
|
132 |
||
49396 | 133 |
lemma step'_in_L[simp]: |
134 |
"\<lbrakk> C \<in> L X; S \<in> L X \<rbrakk> \<Longrightarrow> (step' S C) \<in> L X" |
|
47613 | 135 |
proof(induction C arbitrary: S) |
136 |
case Assign thus ?case |
|
49396 | 137 |
by(auto simp: L_st_def update_def split: option.splits) |
47613 | 138 |
qed auto |
139 |
||
140 |
theorem AI_sound: "AI c = Some C \<Longrightarrow> CS c \<le> \<gamma>\<^isub>c C" |
|
141 |
proof(simp add: CS_def AI_def) |
|
142 |
assume 1: "lpfp (step' (top c)) c = Some C" |
|
49396 | 143 |
have "C \<in> L(vars c)" |
144 |
by(rule lpfp_inv[where P = "%C. C \<in> L(vars c)", OF 1 _ bot_in_L]) |
|
145 |
(erule step'_in_L[OF _ top_in_L]) |
|
47613 | 146 |
have 2: "step' (top c) C \<sqsubseteq> C" by(rule lpfpc_pfp[OF 1]) |
147 |
have 3: "strip (\<gamma>\<^isub>c (step' (top c) C)) = c" |
|
148 |
by(simp add: strip_lpfp[OF _ 1]) |
|
48759
ff570720ba1c
Improved complete lattice formalisation - no more index set.
nipkow
parents:
47818
diff
changeset
|
149 |
have "lfp c (step UNIV) \<le> \<gamma>\<^isub>c (step' (top c) C)" |
47613 | 150 |
proof(rule lfp_lowerbound[simplified,OF 3]) |
151 |
show "step UNIV (\<gamma>\<^isub>c (step' (top c) C)) \<le> \<gamma>\<^isub>c (step' (top c) C)" |
|
49396 | 152 |
proof(rule step_preserves_le[OF _ _ `C \<in> L(vars c)` top_in_L]) |
47613 | 153 |
show "UNIV \<subseteq> \<gamma>\<^isub>o (top c)" by simp |
154 |
show "\<gamma>\<^isub>c (step' (top c) C) \<le> \<gamma>\<^isub>c C" by(rule mono_gamma_c[OF 2]) |
|
155 |
qed |
|
156 |
qed |
|
48759
ff570720ba1c
Improved complete lattice formalisation - no more index set.
nipkow
parents:
47818
diff
changeset
|
157 |
from this 2 show "lfp c (step UNIV) \<le> \<gamma>\<^isub>c C" |
47613 | 158 |
by (blast intro: mono_gamma_c order_trans) |
159 |
qed |
|
160 |
||
161 |
end |
|
162 |
||
163 |
||
164 |
subsubsection "Monotonicity" |
|
165 |
||
49396 | 166 |
lemma le_join_disj: "y \<in> L X \<Longrightarrow> (z::_::semilatticeL) \<in> L X \<Longrightarrow> |
167 |
x \<sqsubseteq> y \<or> x \<sqsubseteq> z \<Longrightarrow> x \<sqsubseteq> y \<squnion> z" |
|
47613 | 168 |
by (metis join_ge1 join_ge2 preord_class.le_trans) |
169 |
||
170 |
locale Abs_Int_mono = Abs_Int + |
|
171 |
assumes mono_plus': "a1 \<sqsubseteq> b1 \<Longrightarrow> a2 \<sqsubseteq> b2 \<Longrightarrow> plus' a1 a2 \<sqsubseteq> plus' b1 b2" |
|
172 |
begin |
|
173 |
||
49396 | 174 |
lemma mono_aval': |
49402 | 175 |
"S1 \<sqsubseteq> S2 \<Longrightarrow> S1 \<in> L X \<Longrightarrow> S2 \<in> L X \<Longrightarrow> vars e \<subseteq> X \<Longrightarrow> aval' e S1 \<sqsubseteq> aval' e S2" |
49396 | 176 |
by(induction e) (auto simp: le_st_def mono_plus' L_st_def) |
47613 | 177 |
|
49396 | 178 |
theorem mono_step': "S1 \<in> L X \<Longrightarrow> S2 \<in> L X \<Longrightarrow> C1 \<in> L X \<Longrightarrow> C2 \<in> L X \<Longrightarrow> |
47613 | 179 |
S1 \<sqsubseteq> S2 \<Longrightarrow> C1 \<sqsubseteq> C2 \<Longrightarrow> step' S1 C1 \<sqsubseteq> step' S2 C2" |
180 |
apply(induction C1 C2 arbitrary: S1 S2 rule: le_acom.induct) |
|
181 |
apply (auto simp: Let_def mono_aval' mono_post |
|
49396 | 182 |
le_join_disj le_join_disj[OF post_in_L post_in_L] |
47613 | 183 |
split: option.split) |
184 |
done |
|
185 |
||
49396 | 186 |
lemma mono_step'_top: "C \<in> L(vars c) \<Longrightarrow> C' \<in> L(vars c) \<Longrightarrow> |
187 |
C \<sqsubseteq> C' \<Longrightarrow> step' (top c) C \<sqsubseteq> step' (top c) C'" |
|
188 |
by (metis top_in_L mono_step' preord_class.le_refl) |
|
47613 | 189 |
|
190 |
end |
|
191 |
||
192 |
||
193 |
subsubsection "Termination" |
|
194 |
||
195 |
abbreviation sqless (infix "\<sqsubset>" 50) where |
|
196 |
"x \<sqsubset> y == x \<sqsubseteq> y \<and> \<not> y \<sqsubseteq> x" |
|
197 |
||
198 |
lemma pfp_termination: |
|
199 |
fixes x0 :: "'a::preord" and m :: "'a \<Rightarrow> nat" |
|
200 |
assumes mono: "\<And>x y. I x \<Longrightarrow> I y \<Longrightarrow> x \<sqsubseteq> y \<Longrightarrow> f x \<sqsubseteq> f y" |
|
201 |
and m: "\<And>x y. I x \<Longrightarrow> I y \<Longrightarrow> x \<sqsubset> y \<Longrightarrow> m x > m y" |
|
202 |
and I: "\<And>x y. I x \<Longrightarrow> I(f x)" and "I x0" and "x0 \<sqsubseteq> f x0" |
|
203 |
shows "EX x. pfp f x0 = Some x" |
|
204 |
proof(simp add: pfp_def, rule wf_while_option_Some[where P = "%x. I x & x \<sqsubseteq> f x"]) |
|
205 |
show "wf {(y,x). ((I x \<and> x \<sqsubseteq> f x) \<and> \<not> f x \<sqsubseteq> x) \<and> y = f x}" |
|
206 |
by(rule wf_subset[OF wf_measure[of m]]) (auto simp: m I) |
|
207 |
next |
|
208 |
show "I x0 \<and> x0 \<sqsubseteq> f x0" using `I x0` `x0 \<sqsubseteq> f x0` by blast |
|
209 |
next |
|
210 |
fix x assume "I x \<and> x \<sqsubseteq> f x" thus "I(f x) \<and> f x \<sqsubseteq> f(f x)" |
|
211 |
by (blast intro: I mono) |
|
212 |
qed |
|
213 |
||
214 |
lemma lpfp_termination: |
|
215 |
fixes f :: "'a::preord option acom \<Rightarrow> 'a option acom" |
|
216 |
and m :: "'a option acom \<Rightarrow> nat" and I :: "'a option acom \<Rightarrow> bool" |
|
217 |
assumes "\<And>x y. I x \<Longrightarrow> I y \<Longrightarrow> x \<sqsubset> y \<Longrightarrow> m x > m y" |
|
218 |
and "\<And>x y. I x \<Longrightarrow> I y \<Longrightarrow> x \<sqsubseteq> y \<Longrightarrow> f x \<sqsubseteq> f y" |
|
219 |
and "\<And>x y. I x \<Longrightarrow> I(f x)" and "I(bot c)" |
|
220 |
and "\<And>C. strip (f C) = strip C" |
|
221 |
shows "\<exists>c'. lpfp f c = Some c'" |
|
222 |
unfolding lpfp_def |
|
223 |
by(fastforce intro: pfp_termination[where I=I and m=m] assms bot_least |
|
224 |
simp: assms(5)) |
|
225 |
||
226 |
||
227 |
locale Abs_Int_measure = |
|
49396 | 228 |
Abs_Int_mono where \<gamma>=\<gamma> for \<gamma> :: "'av::semilattice \<Rightarrow> val set" + |
47613 | 229 |
fixes m :: "'av \<Rightarrow> nat" |
230 |
fixes h :: "nat" |
|
231 |
assumes m1: "x \<sqsubseteq> y \<Longrightarrow> m x \<ge> m y" |
|
232 |
assumes m2: "x \<sqsubset> y \<Longrightarrow> m x > m y" |
|
233 |
assumes h: "m x \<le> h" |
|
234 |
begin |
|
235 |
||
49432 | 236 |
definition m_st :: "'av st \<Rightarrow> nat" ("m\<^isub>s\<^isub>t") where |
237 |
"m_st S = (\<Sum> x \<in> dom S. m(fun S x))" |
|
47613 | 238 |
|
49431 | 239 |
lemma m_st_h: "x \<in> L X \<Longrightarrow> finite X \<Longrightarrow> m_st x \<le> h * card X" |
240 |
by(simp add: L_st_def m_st_def) |
|
241 |
(metis nat_mult_commute of_nat_id setsum_bounded[OF h]) |
|
242 |
||
47613 | 243 |
lemma m_st1: "S1 \<sqsubseteq> S2 \<Longrightarrow> m_st S1 \<ge> m_st S2" |
244 |
proof(auto simp add: le_st_def m_st_def) |
|
245 |
assume "\<forall>x\<in>dom S2. fun S1 x \<sqsubseteq> fun S2 x" |
|
246 |
hence "\<forall>x\<in>dom S2. m(fun S1 x) \<ge> m(fun S2 x)" by (metis m1) |
|
247 |
thus "(\<Sum>x\<in>dom S2. m (fun S2 x)) \<le> (\<Sum>x\<in>dom S2. m (fun S1 x))" |
|
248 |
by (metis setsum_mono) |
|
249 |
qed |
|
250 |
||
251 |
lemma m_st2: "finite(dom S1) \<Longrightarrow> S1 \<sqsubset> S2 \<Longrightarrow> m_st S1 > m_st S2" |
|
252 |
proof(auto simp add: le_st_def m_st_def) |
|
253 |
assume "finite(dom S2)" and 0: "\<forall>x\<in>dom S2. fun S1 x \<sqsubseteq> fun S2 x" |
|
254 |
hence 1: "\<forall>x\<in>dom S2. m(fun S1 x) \<ge> m(fun S2 x)" by (metis m1) |
|
255 |
fix x assume "x \<in> dom S2" "\<not> fun S2 x \<sqsubseteq> fun S1 x" |
|
256 |
hence 2: "\<exists>x\<in>dom S2. m(fun S1 x) > m(fun S2 x)" using 0 m2 by blast |
|
257 |
from setsum_strict_mono_ex1[OF `finite(dom S2)` 1 2] |
|
258 |
show "(\<Sum>x\<in>dom S2. m (fun S2 x)) < (\<Sum>x\<in>dom S2. m (fun S1 x))" . |
|
259 |
qed |
|
260 |
||
261 |
||
49432 | 262 |
definition m_o :: "nat \<Rightarrow> 'av st option \<Rightarrow> nat" ("m\<^isub>o") where |
47613 | 263 |
"m_o d opt = (case opt of None \<Rightarrow> h*d+1 | Some S \<Rightarrow> m_st S)" |
264 |
||
49431 | 265 |
lemma m_o_h: "ost \<in> L X \<Longrightarrow> finite X \<Longrightarrow> m_o (card X) ost \<le> (h*card X + 1)" |
266 |
by(auto simp add: m_o_def m_st_h split: option.split dest!:m_st_h) |
|
47613 | 267 |
|
49396 | 268 |
lemma m_o1: "finite X \<Longrightarrow> o1 \<in> L X \<Longrightarrow> o2 \<in> L X \<Longrightarrow> |
47613 | 269 |
o1 \<sqsubseteq> o2 \<Longrightarrow> m_o (card X) o1 \<ge> m_o (card X) o2" |
270 |
proof(induction o1 o2 rule: le_option.induct) |
|
271 |
case 1 thus ?case by (simp add: m_o_def)(metis m_st1) |
|
272 |
next |
|
273 |
case 2 thus ?case |
|
49396 | 274 |
by(simp add: L_option_def m_o_def le_SucI m_st_h split: option.splits) |
47613 | 275 |
next |
276 |
case 3 thus ?case by simp |
|
277 |
qed |
|
278 |
||
49396 | 279 |
lemma m_o2: "finite X \<Longrightarrow> o1 \<in> L X \<Longrightarrow> o2 \<in> L X \<Longrightarrow> |
47613 | 280 |
o1 \<sqsubset> o2 \<Longrightarrow> m_o (card X) o1 > m_o (card X) o2" |
281 |
proof(induction o1 o2 rule: le_option.induct) |
|
49396 | 282 |
case 1 thus ?case by (simp add: m_o_def L_st_def m_st2) |
47613 | 283 |
next |
284 |
case 2 thus ?case |
|
285 |
by(auto simp add: m_o_def le_imp_less_Suc m_st_h) |
|
286 |
next |
|
287 |
case 3 thus ?case by simp |
|
288 |
qed |
|
289 |
||
49431 | 290 |
|
49432 | 291 |
definition m_c :: "'av st option acom \<Rightarrow> nat" ("m\<^isub>c") where |
49431 | 292 |
"m_c C = (\<Sum>i<size(annos C). m_o (card(vars(strip C))) (annos C ! i))" |
293 |
||
294 |
lemma m_c_h: assumes "C \<in> L(vars(strip C))" |
|
295 |
shows "m_c C \<le> size(annos C) * (h * card(vars(strip C)) + 1)" |
|
296 |
proof- |
|
297 |
let ?X = "vars(strip C)" let ?n = "card ?X" let ?a = "size(annos C)" |
|
298 |
{ fix i assume "i < ?a" |
|
299 |
hence "annos C ! i \<in> L ?X" using assms by(simp add: L_acom_def) |
|
300 |
note m_o_h[OF this finite_cvars] |
|
301 |
} note 1 = this |
|
302 |
have "m_c C = (\<Sum>i<?a. m_o ?n (annos C ! i))" by(simp add: m_c_def) |
|
303 |
also have "\<dots> \<le> (\<Sum>i<?a. h * ?n + 1)" |
|
304 |
apply(rule setsum_mono) using 1 by simp |
|
305 |
also have "\<dots> = ?a * (h * ?n + 1)" by simp |
|
306 |
finally show ?thesis . |
|
307 |
qed |
|
308 |
||
49396 | 309 |
lemma m_c2: "C1 \<in> L(vars(strip C1)) \<Longrightarrow> C2 \<in> L(vars(strip C2)) \<Longrightarrow> |
310 |
C1 \<sqsubset> C2 \<Longrightarrow> m_c C1 > m_c C2" |
|
311 |
proof(auto simp add: le_iff_le_annos m_c_def size_annos_same[of C1 C2] L_acom_def) |
|
312 |
let ?X = "vars(strip C2)" |
|
47613 | 313 |
let ?n = "card ?X" |
49396 | 314 |
assume V1: "\<forall>a\<in>set(annos C1). a \<in> L ?X" |
315 |
and V2: "\<forall>a\<in>set(annos C2). a \<in> L ?X" |
|
316 |
and strip_eq: "strip C1 = strip C2" |
|
317 |
and 0: "\<forall>i<size(annos C2). annos C1 ! i \<sqsubseteq> annos C2 ! i" |
|
318 |
hence 1: "\<forall>i<size(annos C2). m_o ?n (annos C1 ! i) \<ge> m_o ?n (annos C2 ! i)" |
|
47613 | 319 |
by (auto simp: all_set_conv_all_nth) |
320 |
(metis finite_cvars m_o1 size_annos_same2) |
|
49396 | 321 |
fix i assume "i < size(annos C2)" "\<not> annos C2 ! i \<sqsubseteq> annos C1 ! i" |
322 |
hence "m_o ?n (annos C1 ! i) > m_o ?n (annos C2 ! i)" (is "?P i") |
|
323 |
by(metis m_o2[OF finite_cvars] V1 V2 nth_mem size_annos_same[OF strip_eq] 0) |
|
324 |
hence 2: "\<exists>i < size(annos C2). ?P i" using `i < size(annos C2)` by blast |
|
325 |
show "(\<Sum>i<size(annos C2). m_o ?n (annos C2 ! i)) |
|
326 |
< (\<Sum>i<size(annos C2). m_o ?n (annos C1 ! i))" |
|
47613 | 327 |
apply(rule setsum_strict_mono_ex1) using 1 2 by (auto) |
328 |
qed |
|
329 |
||
330 |
lemma AI_Some_measure: "\<exists>C. AI c = Some C" |
|
331 |
unfolding AI_def |
|
49396 | 332 |
apply(rule lpfp_termination[where I = "%C. strip C = c \<and> C \<in> L(vars c)" |
47613 | 333 |
and m="m_c"]) |
334 |
apply(simp_all add: m_c2 mono_step'_top) |
|
335 |
done |
|
336 |
||
337 |
end |
|
338 |
||
339 |
end |