author | kleing |
Sun, 24 Mar 2002 14:05:53 +0100 | |
changeset 13065 | d6585b32412b |
parent 13062 | 4b1edf2f6bd2 |
child 13066 | b57d926d1de2 |
permissions | -rw-r--r-- |
12516 | 1 |
(* Title: HOL/MicroJava/BV/Kildall.thy |
10496 | 2 |
ID: $Id$ |
12516 | 3 |
Author: Tobias Nipkow, Gerwin Klein |
10496 | 4 |
Copyright 2000 TUM |
5 |
||
6 |
Kildall's algorithm |
|
7 |
*) |
|
8 |
||
12911 | 9 |
header {* \isaheader{Kildall's Algorithm}\label{sec:Kildall} *} |
10496 | 10 |
|
13062 | 11 |
theory Kildall = SemilatAlg + While_Combinator: |
12516 | 12 |
|
10496 | 13 |
|
14 |
consts |
|
12516 | 15 |
iter :: "'s binop \<Rightarrow> 's step_type \<Rightarrow> |
11298 | 16 |
's list \<Rightarrow> nat set \<Rightarrow> 's list \<times> nat set" |
13006 | 17 |
propa :: "'s binop \<Rightarrow> (nat \<times> 's) list \<Rightarrow> 's list \<Rightarrow> nat set \<Rightarrow> 's list * nat set" |
10496 | 18 |
|
19 |
primrec |
|
12516 | 20 |
"propa f [] ss w = (ss,w)" |
21 |
"propa f (q'#qs) ss w = (let (q,t) = q'; |
|
22 |
u = t +_f ss!q; |
|
23 |
w' = (if u = ss!q then w else insert q w) |
|
24 |
in propa f qs (ss[q := u]) w')" |
|
10496 | 25 |
|
11175
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
26 |
defs iter_def: |
12516 | 27 |
"iter f step ss w == |
11298 | 28 |
while (%(ss,w). w \<noteq> {}) |
12516 | 29 |
(%(ss,w). let p = SOME p. p \<in> w |
30 |
in propa f (step p (ss!p)) ss (w-{p})) |
|
11298 | 31 |
(ss,w)" |
10496 | 32 |
|
33 |
constdefs |
|
13006 | 34 |
unstables :: "'s ord \<Rightarrow> 's step_type \<Rightarrow> 's list \<Rightarrow> nat set" |
12516 | 35 |
"unstables r step ss == {p. p < size ss \<and> \<not>stable r step ss p}" |
10496 | 36 |
|
13006 | 37 |
kildall :: "'s ord \<Rightarrow> 's binop \<Rightarrow> 's step_type \<Rightarrow> 's list \<Rightarrow> 's list" |
12516 | 38 |
"kildall r f step ss == fst(iter f step ss (unstables r step ss))" |
10496 | 39 |
|
13006 | 40 |
consts merges :: "'s binop \<Rightarrow> (nat \<times> 's) list \<Rightarrow> 's list \<Rightarrow> 's list" |
10496 | 41 |
primrec |
12516 | 42 |
"merges f [] ss = ss" |
43 |
"merges f (p'#ps) ss = (let (p,s) = p' in merges f ps (ss[p := s +_f ss!p]))" |
|
10496 | 44 |
|
45 |
||
10774 | 46 |
lemmas [simp] = Let_def le_iff_plus_unchanged [symmetric] |
10496 | 47 |
|
48 |
||
12516 | 49 |
lemma nth_merges: |
13006 | 50 |
"\<And>ss. \<lbrakk> semilat (A, r, f); p < length ss; ss \<in> list n A; |
51 |
\<forall>(p,t)\<in>set ps. p<n \<and> t\<in>A \<rbrakk> \<Longrightarrow> |
|
12516 | 52 |
(merges f ps ss)!p = map snd [(p',t') \<in> ps. p'=p] ++_f ss!p" |
13006 | 53 |
(is "\<And>ss. _ \<Longrightarrow> _ \<Longrightarrow> _ \<Longrightarrow> ?steptype ps \<Longrightarrow> ?P ss ps") |
12516 | 54 |
proof (induct ps) |
55 |
show "\<And>ss. ?P ss []" by simp |
|
56 |
||
57 |
fix ss p' ps' |
|
58 |
assume sl: "semilat (A, r, f)" |
|
59 |
assume ss: "ss \<in> list n A" |
|
60 |
assume l: "p < length ss" |
|
61 |
assume "?steptype (p'#ps')" |
|
62 |
then obtain a b where |
|
63 |
p': "p'=(a,b)" and ab: "a<n" "b\<in>A" and "?steptype ps'" |
|
64 |
by (cases p', auto) |
|
65 |
assume "\<And>ss. semilat (A,r,f) \<Longrightarrow> p < length ss \<Longrightarrow> ss \<in> list n A \<Longrightarrow> ?steptype ps' \<Longrightarrow> ?P ss ps'" |
|
66 |
hence IH: "\<And>ss. ss \<in> list n A \<Longrightarrow> p < length ss \<Longrightarrow> ?P ss ps'" . |
|
67 |
||
68 |
from sl ss ab |
|
69 |
have "ss[a := b +_f ss!a] \<in> list n A" by (simp add: closedD) |
|
70 |
moreover |
|
71 |
from calculation |
|
72 |
have "p < length (ss[a := b +_f ss!a])" by simp |
|
73 |
ultimately |
|
74 |
have "?P (ss[a := b +_f ss!a]) ps'" by (rule IH) |
|
75 |
with p' l |
|
76 |
show "?P ss (p'#ps')" by simp |
|
77 |
qed |
|
78 |
||
79 |
||
10496 | 80 |
(** merges **) |
81 |
||
82 |
lemma length_merges [rule_format, simp]: |
|
12516 | 83 |
"\<forall>ss. size(merges f ps ss) = size ss" |
10496 | 84 |
by (induct_tac ps, auto) |
85 |
||
12516 | 86 |
|
87 |
lemma merges_preserves_type_lemma: |
|
13006 | 88 |
"semilat(A,r,f) \<Longrightarrow> |
89 |
\<forall>xs. xs \<in> list n A \<longrightarrow> (\<forall>(p,x) \<in> set ps. p<n \<and> x\<in>A) |
|
90 |
\<longrightarrow> merges f ps xs \<in> list n A" |
|
12516 | 91 |
apply (frule semilatDclosedI) |
92 |
apply (unfold closed_def) |
|
10496 | 93 |
apply (induct_tac ps) |
12516 | 94 |
apply simp |
95 |
apply clarsimp |
|
10496 | 96 |
done |
97 |
||
12516 | 98 |
lemma merges_preserves_type [simp]: |
13006 | 99 |
"\<lbrakk> semilat(A,r,f); xs \<in> list n A; \<forall>(p,x) \<in> set ps. p<n \<and> x\<in>A \<rbrakk> |
100 |
\<Longrightarrow> merges f ps xs \<in> list n A" |
|
12516 | 101 |
by (simp add: merges_preserves_type_lemma) |
102 |
||
103 |
lemma merges_incr_lemma: |
|
13006 | 104 |
"semilat(A,r,f) \<Longrightarrow> |
105 |
\<forall>xs. xs \<in> list n A \<longrightarrow> (\<forall>(p,x)\<in>set ps. p<size xs \<and> x \<in> A) \<longrightarrow> xs <=[r] merges f ps xs" |
|
10496 | 106 |
apply (induct_tac ps) |
107 |
apply simp |
|
108 |
apply simp |
|
109 |
apply clarify |
|
110 |
apply (rule order_trans) |
|
111 |
apply simp |
|
112 |
apply (erule list_update_incr) |
|
113 |
apply assumption |
|
114 |
apply simp |
|
115 |
apply simp |
|
116 |
apply (blast intro!: listE_set intro: closedD listE_length [THEN nth_in]) |
|
117 |
done |
|
118 |
||
12516 | 119 |
lemma merges_incr: |
13006 | 120 |
"\<lbrakk> semilat(A,r,f); xs \<in> list n A; \<forall>(p,x)\<in>set ps. p<size xs \<and> x \<in> A \<rbrakk> |
121 |
\<Longrightarrow> xs <=[r] merges f ps xs" |
|
12516 | 122 |
by (simp add: merges_incr_lemma) |
123 |
||
124 |
||
10496 | 125 |
lemma merges_same_conv [rule_format]: |
13006 | 126 |
"semilat(A,r,f) \<Longrightarrow> |
127 |
(\<forall>xs. xs \<in> list n A \<longrightarrow> (\<forall>(p,x)\<in>set ps. p<size xs \<and> x\<in>A) \<longrightarrow> |
|
12516 | 128 |
(merges f ps xs = xs) = (\<forall>(p,x)\<in>set ps. x <=_r xs!p))" |
10496 | 129 |
apply (induct_tac ps) |
130 |
apply simp |
|
131 |
apply clarsimp |
|
12516 | 132 |
apply (rename_tac p x ps xs) |
10496 | 133 |
apply (rule iffI) |
134 |
apply (rule context_conjI) |
|
135 |
apply (subgoal_tac "xs[p := x +_f xs!p] <=[r] xs") |
|
136 |
apply (force dest!: le_listD simp add: nth_list_update) |
|
137 |
apply (erule subst, rule merges_incr) |
|
138 |
apply assumption |
|
139 |
apply (blast intro!: listE_set intro: closedD listE_length [THEN nth_in]) |
|
12516 | 140 |
apply clarify |
141 |
apply (rule conjI) |
|
142 |
apply simp |
|
143 |
apply (blast dest: boundedD) |
|
144 |
apply blast |
|
10496 | 145 |
apply clarify |
146 |
apply (rotate_tac -2) |
|
147 |
apply (erule allE) |
|
148 |
apply (erule impE) |
|
149 |
apply assumption |
|
150 |
apply (erule impE) |
|
151 |
apply assumption |
|
152 |
apply (drule bspec) |
|
153 |
apply assumption |
|
154 |
apply (simp add: le_iff_plus_unchanged [THEN iffD1] list_update_same_conv [THEN iffD2]) |
|
12516 | 155 |
apply blast |
10496 | 156 |
apply clarify |
157 |
apply (simp add: le_iff_plus_unchanged [THEN iffD1] list_update_same_conv [THEN iffD2]) |
|
158 |
done |
|
159 |
||
160 |
||
161 |
lemma list_update_le_listI [rule_format]: |
|
13006 | 162 |
"set xs <= A \<longrightarrow> set ys <= A \<longrightarrow> xs <=[r] ys \<longrightarrow> p < size xs \<longrightarrow> |
163 |
x <=_r ys!p \<longrightarrow> semilat(A,r,f) \<longrightarrow> x\<in>A \<longrightarrow> |
|
10496 | 164 |
xs[p := x +_f xs!p] <=[r] ys" |
165 |
apply (unfold Listn.le_def lesub_def semilat_def) |
|
166 |
apply (simp add: list_all2_conv_all_nth nth_list_update) |
|
167 |
done |
|
168 |
||
169 |
lemma merges_pres_le_ub: |
|
13006 | 170 |
"\<lbrakk> semilat(A,r,f); set ts <= A; set ss <= A; |
12516 | 171 |
\<forall>(p,t)\<in>set ps. t <=_r ts!p \<and> t \<in> A \<and> p < size ts; |
13006 | 172 |
ss <=[r] ts \<rbrakk> |
173 |
\<Longrightarrow> merges f ps ss <=[r] ts" |
|
10496 | 174 |
proof - |
175 |
{ fix A r f t ts ps |
|
176 |
have |
|
13006 | 177 |
"\<And>qs. \<lbrakk> semilat(A,r,f); set ts <= A; |
178 |
\<forall>(p,t)\<in>set ps. t <=_r ts!p \<and> t \<in> A \<and> p < size ts \<rbrakk> \<Longrightarrow> |
|
179 |
set qs <= set ps \<longrightarrow> |
|
180 |
(\<forall>ss. set ss <= A \<longrightarrow> ss <=[r] ts \<longrightarrow> merges f qs ss <=[r] ts)" |
|
10496 | 181 |
apply (induct_tac qs) |
182 |
apply simp |
|
183 |
apply (simp (no_asm_simp)) |
|
184 |
apply clarify |
|
185 |
apply (rotate_tac -2) |
|
186 |
apply simp |
|
187 |
apply (erule allE, erule impE, erule_tac [2] mp) |
|
12516 | 188 |
apply (drule bspec, assumption) |
189 |
apply (simp add: closedD) |
|
190 |
apply (drule bspec, assumption) |
|
10496 | 191 |
apply (simp add: list_update_le_listI) |
12516 | 192 |
done |
10496 | 193 |
} note this [dest] |
194 |
||
11549 | 195 |
case rule_context |
10496 | 196 |
thus ?thesis by blast |
197 |
qed |
|
198 |
||
199 |
||
12516 | 200 |
(** propa **) |
10496 | 201 |
|
202 |
||
12516 | 203 |
lemma decomp_propa: |
13006 | 204 |
"\<And>ss w. (\<forall>(q,t)\<in>set qs. q < size ss) \<Longrightarrow> |
12516 | 205 |
propa f qs ss w = |
206 |
(merges f qs ss, {q. \<exists>t. (q,t)\<in>set qs \<and> t +_f ss!q \<noteq> ss!q} Un w)" |
|
207 |
apply (induct qs) |
|
208 |
apply simp |
|
10496 | 209 |
apply (simp (no_asm)) |
12516 | 210 |
apply clarify |
211 |
apply simp |
|
212 |
apply (rule conjI) |
|
10496 | 213 |
apply (simp add: nth_list_update) |
214 |
apply blast |
|
215 |
apply (simp add: nth_list_update) |
|
216 |
apply blast |
|
217 |
done |
|
218 |
||
219 |
(** iter **) |
|
220 |
||
221 |
lemma stable_pres_lemma: |
|
13006 | 222 |
"\<lbrakk> semilat (A,r,f); pres_type step n A; bounded step n; |
12516 | 223 |
ss \<in> list n A; p \<in> w; \<forall>q\<in>w. q < n; |
224 |
\<forall>q. q < n \<longrightarrow> q \<notin> w \<longrightarrow> stable r step ss q; q < n; |
|
225 |
\<forall>s'. (q,s') \<in> set (step p (ss ! p)) \<longrightarrow> s' +_f ss ! q = ss ! q; |
|
13006 | 226 |
q \<notin> w \<or> q = p \<rbrakk> |
227 |
\<Longrightarrow> stable r step (merges f (step p (ss!p)) ss) q" |
|
10496 | 228 |
apply (unfold stable_def) |
12516 | 229 |
apply (subgoal_tac "\<forall>s'. (q,s') \<in> set (step p (ss!p)) \<longrightarrow> s' : A") |
230 |
prefer 2 |
|
231 |
apply clarify |
|
232 |
apply (erule pres_typeD) |
|
233 |
prefer 3 apply assumption |
|
234 |
apply (rule listE_nth_in) |
|
235 |
apply assumption |
|
236 |
apply simp |
|
237 |
apply simp |
|
10496 | 238 |
apply simp |
239 |
apply clarify |
|
12516 | 240 |
apply (subst nth_merges) |
241 |
apply assumption |
|
242 |
apply simp |
|
243 |
apply (blast dest: boundedD) |
|
10496 | 244 |
apply assumption |
12516 | 245 |
apply clarify |
246 |
apply (rule conjI) |
|
247 |
apply (blast dest: boundedD) |
|
248 |
apply (erule pres_typeD) |
|
249 |
prefer 3 apply assumption |
|
250 |
apply simp |
|
251 |
apply simp |
|
252 |
apply (frule nth_merges [of _ _ _ q _ _ "step p (ss!p)"]) (* fixme: why does method subst not work?? *) |
|
253 |
prefer 2 apply assumption |
|
254 |
apply simp |
|
255 |
apply clarify |
|
10496 | 256 |
apply (rule conjI) |
12516 | 257 |
apply (blast dest: boundedD) |
258 |
apply (erule pres_typeD) |
|
259 |
prefer 3 apply assumption |
|
260 |
apply simp |
|
261 |
apply simp |
|
262 |
apply (drule_tac P = "\<lambda>x. (a, b) \<in> set (step q x)" in subst) |
|
263 |
apply assumption |
|
264 |
||
265 |
apply (simp add: plusplus_empty) |
|
266 |
apply (cases "q \<in> w") |
|
267 |
apply simp |
|
268 |
apply (rule ub1') |
|
269 |
apply assumption |
|
270 |
apply clarify |
|
271 |
apply (rule pres_typeD) |
|
272 |
apply assumption |
|
273 |
prefer 3 apply assumption |
|
274 |
apply (blast intro: listE_nth_in dest: boundedD) |
|
275 |
apply (blast intro: pres_typeD dest: boundedD) |
|
276 |
apply (blast intro: listE_nth_in dest: boundedD) |
|
277 |
apply assumption |
|
10496 | 278 |
|
12516 | 279 |
apply simp |
280 |
apply (erule allE, erule impE, assumption, erule impE, assumption) |
|
281 |
apply (rule order_trans) |
|
282 |
apply simp |
|
283 |
defer |
|
284 |
apply (rule ub2) |
|
285 |
apply assumption |
|
286 |
apply simp |
|
287 |
apply clarify |
|
288 |
apply simp |
|
289 |
apply (rule pres_typeD) |
|
290 |
apply assumption |
|
291 |
prefer 3 apply assumption |
|
292 |
apply (blast intro: listE_nth_in dest: boundedD) |
|
293 |
apply (blast intro: pres_typeD dest: boundedD) |
|
294 |
apply (blast intro: listE_nth_in dest: boundedD) |
|
295 |
apply blast |
|
296 |
done |
|
297 |
||
298 |
||
299 |
lemma merges_bounded_lemma: |
|
13006 | 300 |
"\<lbrakk> semilat (A,r,f); mono r step n A; bounded step n; |
12516 | 301 |
\<forall>(p',s') \<in> set (step p (ss!p)). s' \<in> A; ss \<in> list n A; ts \<in> list n A; p < n; |
13006 | 302 |
ss <=[r] ts; ! p. p < n \<longrightarrow> stable r step ts p \<rbrakk> |
303 |
\<Longrightarrow> merges f (step p (ss!p)) ss <=[r] ts" |
|
10496 | 304 |
apply (unfold stable_def) |
12516 | 305 |
apply (rule merges_pres_le_ub) |
306 |
apply assumption |
|
307 |
apply simp |
|
308 |
apply simp |
|
309 |
prefer 2 apply assumption |
|
310 |
||
311 |
apply clarsimp |
|
312 |
apply (drule boundedD, assumption+) |
|
313 |
apply (erule allE, erule impE, assumption) |
|
314 |
apply (drule bspec, assumption) |
|
315 |
apply simp |
|
316 |
||
317 |
apply (drule monoD [of _ _ _ _ p "ss!p" "ts!p"]) |
|
318 |
apply assumption |
|
319 |
apply simp |
|
320 |
apply (simp add: le_listD) |
|
321 |
||
322 |
apply (drule lesub_step_type, assumption) |
|
323 |
apply clarify |
|
324 |
apply (drule bspec, assumption) |
|
325 |
apply simp |
|
326 |
apply (blast intro: order_trans) |
|
10496 | 327 |
done |
328 |
||
11175
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
329 |
lemma termination_lemma: |
13006 | 330 |
"\<lbrakk> semilat(A,r,f); ss \<in> list n A; \<forall>(q,t)\<in>set qs. q<n \<and> t\<in>A; p\<in>w \<rbrakk> \<Longrightarrow> |
12516 | 331 |
ss <[r] merges f qs ss \<or> |
332 |
merges f qs ss = ss \<and> {q. \<exists>t. (q,t)\<in>set qs \<and> t +_f ss!q \<noteq> ss!q} Un (w-{p}) < w" |
|
11175
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
333 |
apply (unfold lesssub_def) |
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
334 |
apply (simp (no_asm_simp) add: merges_incr) |
10496 | 335 |
apply (rule impI) |
11175
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
336 |
apply (rule merges_same_conv [THEN iffD1, elim_format]) |
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
337 |
apply assumption+ |
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
338 |
defer |
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
339 |
apply (rule sym, assumption) |
12516 | 340 |
defer apply simp |
341 |
apply (subgoal_tac "\<forall>q t. \<not>((q, t) \<in> set qs \<and> t +_f ss ! q \<noteq> ss ! q)") |
|
11175
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
342 |
apply (blast intro!: psubsetI elim: equalityE) |
12516 | 343 |
apply clarsimp |
344 |
apply (drule bspec, assumption) |
|
345 |
apply (drule bspec, assumption) |
|
346 |
apply clarsimp |
|
347 |
done |
|
10496 | 348 |
|
11298 | 349 |
lemma iter_properties[rule_format]: |
11175
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
350 |
"\<lbrakk> semilat(A,r,f); acc r ; pres_type step n A; mono r step n A; |
12516 | 351 |
bounded step n; \<forall>p\<in>w0. p < n; ss0 \<in> list n A; |
352 |
\<forall>p<n. p \<notin> w0 \<longrightarrow> stable r step ss0 p \<rbrakk> \<Longrightarrow> |
|
353 |
iter f step ss0 w0 = (ss',w') |
|
11175
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
354 |
\<longrightarrow> |
12516 | 355 |
ss' \<in> list n A \<and> stables r step ss' \<and> ss0 <=[r] ss' \<and> |
356 |
(\<forall>ts\<in>list n A. ss0 <=[r] ts \<and> stables r step ts \<longrightarrow> ss' <=[r] ts)" |
|
11298 | 357 |
apply (unfold iter_def stables_def) |
11175
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
358 |
apply (rule_tac P = "%(ss,w). |
12516 | 359 |
ss \<in> list n A \<and> (\<forall>p<n. p \<notin> w \<longrightarrow> stable r step ss p) \<and> ss0 <=[r] ss \<and> |
360 |
(\<forall>ts\<in>list n A. ss0 <=[r] ts \<and> stables r step ts \<longrightarrow> ss <=[r] ts) \<and> |
|
11175
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
361 |
(\<forall>p\<in>w. p < n)" and |
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
362 |
r = "{(ss',ss) . ss <[r] ss'} <*lex*> finite_psubset" |
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
363 |
in while_rule) |
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
364 |
|
12516 | 365 |
-- "Invariant holds initially:" |
366 |
apply (simp add:stables_def) |
|
367 |
||
368 |
-- "Invariant is preserved:" |
|
11175
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
369 |
apply(simp add: stables_def split_paired_all) |
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
370 |
apply(rename_tac ss w) |
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
371 |
apply(subgoal_tac "(SOME p. p \<in> w) \<in> w") |
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
372 |
prefer 2; apply (fast intro: someI) |
12516 | 373 |
apply(subgoal_tac "\<forall>(q,t) \<in> set (step (SOME p. p \<in> w) (ss ! (SOME p. p \<in> w))). q < length ss \<and> t \<in> A") |
374 |
prefer 2 |
|
375 |
apply clarify |
|
376 |
apply (rule conjI) |
|
377 |
apply(clarsimp, blast dest!: boundedD) |
|
378 |
apply (erule pres_typeD) |
|
379 |
prefer 3 |
|
380 |
apply assumption |
|
381 |
apply (erule listE_nth_in) |
|
382 |
apply blast |
|
383 |
apply blast |
|
11175
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
384 |
apply (subst decomp_propa) |
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
385 |
apply blast |
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
386 |
apply simp |
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
387 |
apply (rule conjI) |
12516 | 388 |
apply (erule merges_preserves_type) |
389 |
apply blast |
|
390 |
apply clarify |
|
391 |
apply (rule conjI) |
|
392 |
apply(clarsimp, blast dest!: boundedD) |
|
393 |
apply (erule pres_typeD) |
|
394 |
prefer 3 |
|
395 |
apply assumption |
|
396 |
apply (erule listE_nth_in) |
|
397 |
apply blast |
|
398 |
apply blast |
|
399 |
apply (rule conjI) |
|
400 |
apply clarify |
|
11175
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
401 |
apply (blast intro!: stable_pres_lemma) |
12516 | 402 |
apply (rule conjI) |
11175
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
403 |
apply (blast intro!: merges_incr intro: le_list_trans) |
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
404 |
apply (rule conjI) |
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
405 |
apply clarsimp |
12516 | 406 |
apply (blast intro!: merges_bounded_lemma) |
11175
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
407 |
apply (blast dest!: boundedD) |
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
408 |
|
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
409 |
|
12516 | 410 |
-- "Postcondition holds upon termination:" |
411 |
apply(clarsimp simp add: stables_def split_paired_all) |
|
412 |
||
413 |
-- "Well-foundedness of the termination relation:" |
|
11175
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
414 |
apply (rule wf_lex_prod) |
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
415 |
apply (drule (1) semilatDorderI [THEN acc_le_listI]) |
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
416 |
apply (simp only: acc_def lesssub_def) |
12516 | 417 |
apply (rule wf_finite_psubset) |
11175
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
418 |
|
12516 | 419 |
-- "Loop decreases along termination relation:" |
11175
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
420 |
apply(simp add: stables_def split_paired_all) |
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
421 |
apply(rename_tac ss w) |
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
422 |
apply(subgoal_tac "(SOME p. p \<in> w) \<in> w") |
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
423 |
prefer 2; apply (fast intro: someI) |
12516 | 424 |
apply(subgoal_tac "\<forall>(q,t) \<in> set (step (SOME p. p \<in> w) (ss ! (SOME p. p \<in> w))). q < length ss \<and> t \<in> A") |
425 |
prefer 2 |
|
426 |
apply clarify |
|
427 |
apply (rule conjI) |
|
428 |
apply(clarsimp, blast dest!: boundedD) |
|
429 |
apply (erule pres_typeD) |
|
430 |
prefer 3 |
|
431 |
apply assumption |
|
432 |
apply (erule listE_nth_in) |
|
433 |
apply blast |
|
434 |
apply blast |
|
11175
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
435 |
apply (subst decomp_propa) |
12516 | 436 |
apply blast |
437 |
apply clarify |
|
11175
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
438 |
apply (simp del: listE_length |
12516 | 439 |
add: lex_prod_def finite_psubset_def |
11175
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
440 |
bounded_nat_set_is_finite) |
12516 | 441 |
apply (rule termination_lemma) |
442 |
apply assumption+ |
|
443 |
defer |
|
444 |
apply assumption |
|
445 |
apply clarsimp |
|
446 |
apply (blast dest!: boundedD) |
|
447 |
done |
|
448 |
||
11175
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
10774
diff
changeset
|
449 |
|
11229 | 450 |
lemma kildall_properties: |
451 |
"\<lbrakk> semilat(A,r,f); acc r; pres_type step n A; mono r step n A; |
|
12516 | 452 |
bounded step n; ss0 \<in> list n A \<rbrakk> \<Longrightarrow> |
453 |
kildall r f step ss0 \<in> list n A \<and> |
|
454 |
stables r step (kildall r f step ss0) \<and> |
|
455 |
ss0 <=[r] kildall r f step ss0 \<and> |
|
456 |
(\<forall>ts\<in>list n A. ss0 <=[r] ts \<and> stables r step ts \<longrightarrow> |
|
457 |
kildall r f step ss0 <=[r] ts)" |
|
11229 | 458 |
apply (unfold kildall_def) |
12516 | 459 |
apply(case_tac "iter f step ss0 (unstables r step ss0)") |
11298 | 460 |
apply(simp) |
11229 | 461 |
apply (rule iter_properties) |
462 |
apply (simp_all add: unstables_def stable_def) |
|
463 |
done |
|
10496 | 464 |
|
465 |
lemma is_bcv_kildall: |
|
13006 | 466 |
"\<lbrakk> semilat(A,r,f); acc r; top r T; |
12516 | 467 |
pres_type step n A; bounded step n; |
13006 | 468 |
mono r step n A \<rbrakk> |
469 |
\<Longrightarrow> is_bcv r T step n A (kildall r f step)" |
|
11299 | 470 |
apply(unfold is_bcv_def wt_step_def) |
11229 | 471 |
apply(insert kildall_properties[of A]) |
472 |
apply(simp add:stables_def) |
|
473 |
apply clarify |
|
12516 | 474 |
apply(subgoal_tac "kildall r f step ss \<in> list n A") |
11229 | 475 |
prefer 2 apply (simp(no_asm_simp)) |
476 |
apply (rule iffI) |
|
12516 | 477 |
apply (rule_tac x = "kildall r f step ss" in bexI) |
11229 | 478 |
apply (rule conjI) |
479 |
apply blast |
|
480 |
apply (simp (no_asm_simp)) |
|
481 |
apply assumption |
|
482 |
apply clarify |
|
12516 | 483 |
apply(subgoal_tac "kildall r f step ss!p <=_r ts!p") |
11229 | 484 |
apply simp |
485 |
apply (blast intro!: le_listD less_lengthI) |
|
486 |
done |
|
10496 | 487 |
|
12516 | 488 |
end |