author | kleing |
Fri, 14 Jun 2002 23:25:36 +0200 | |
changeset 13214 | 2aa33ed5f526 |
parent 13077 | c2e4d9990162 |
child 13365 | a2c4faad4d35 |
permissions | -rw-r--r-- |
12516 | 1 |
(* Title: HOL/MicroJava/BV/Semilat.thy |
10496 | 2 |
ID: $Id$ |
3 |
Author: Tobias Nipkow |
|
4 |
Copyright 2000 TUM |
|
5 |
||
6 |
Semilattices |
|
7 |
*) |
|
8 |
||
12911 | 9 |
header {* |
10 |
\chapter{Bytecode Verifier}\label{cha:bv} |
|
11 |
\isaheader{Semilattices} |
|
12 |
*} |
|
10496 | 13 |
|
12542 | 14 |
theory Semilat = While_Combinator: |
10496 | 15 |
|
13006 | 16 |
types 'a ord = "'a \<Rightarrow> 'a \<Rightarrow> bool" |
17 |
'a binop = "'a \<Rightarrow> 'a \<Rightarrow> 'a" |
|
10496 | 18 |
'a sl = "'a set * 'a ord * 'a binop" |
19 |
||
20 |
consts |
|
13006 | 21 |
"@lesub" :: "'a \<Rightarrow> 'a ord \<Rightarrow> 'a \<Rightarrow> bool" ("(_ /<='__ _)" [50, 1000, 51] 50) |
22 |
"@lesssub" :: "'a \<Rightarrow> 'a ord \<Rightarrow> 'a \<Rightarrow> bool" ("(_ /<'__ _)" [50, 1000, 51] 50) |
|
10496 | 23 |
defs |
24 |
lesub_def: "x <=_r y == r x y" |
|
25 |
lesssub_def: "x <_r y == x <=_r y & x ~= y" |
|
26 |
||
27 |
consts |
|
13006 | 28 |
"@plussub" :: "'a \<Rightarrow> ('a \<Rightarrow> 'b \<Rightarrow> 'c) \<Rightarrow> 'b \<Rightarrow> 'c" ("(_ /+'__ _)" [65, 1000, 66] 65) |
10496 | 29 |
defs |
30 |
plussub_def: "x +_f y == f x y" |
|
31 |
||
32 |
||
33 |
constdefs |
|
13006 | 34 |
ord :: "('a*'a)set \<Rightarrow> 'a ord" |
10496 | 35 |
"ord r == %x y. (x,y):r" |
36 |
||
13006 | 37 |
order :: "'a ord \<Rightarrow> bool" |
10496 | 38 |
"order r == (!x. x <=_r x) & |
13006 | 39 |
(!x y. x <=_r y & y <=_r x \<longrightarrow> x=y) & |
40 |
(!x y z. x <=_r y & y <=_r z \<longrightarrow> x <=_r z)" |
|
10496 | 41 |
|
13006 | 42 |
acc :: "'a ord \<Rightarrow> bool" |
10496 | 43 |
"acc r == wf{(y,x) . x <_r y}" |
44 |
||
13006 | 45 |
top :: "'a ord \<Rightarrow> 'a \<Rightarrow> bool" |
10496 | 46 |
"top r T == !x. x <=_r T" |
47 |
||
13006 | 48 |
closed :: "'a set \<Rightarrow> 'a binop \<Rightarrow> bool" |
10496 | 49 |
"closed A f == !x:A. !y:A. x +_f y : A" |
50 |
||
13006 | 51 |
semilat :: "'a sl \<Rightarrow> bool" |
10496 | 52 |
"semilat == %(A,r,f). order r & closed A f & |
53 |
(!x:A. !y:A. x <=_r x +_f y) & |
|
54 |
(!x:A. !y:A. y <=_r x +_f y) & |
|
13006 | 55 |
(!x:A. !y:A. !z:A. x <=_r z & y <=_r z \<longrightarrow> x +_f y <=_r z)" |
10496 | 56 |
|
13006 | 57 |
is_ub :: "('a*'a)set \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool" |
10496 | 58 |
"is_ub r x y u == (x,u):r & (y,u):r" |
59 |
||
13006 | 60 |
is_lub :: "('a*'a)set \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> bool" |
61 |
"is_lub r x y u == is_ub r x y u & (!z. is_ub r x y z \<longrightarrow> (u,z):r)" |
|
10496 | 62 |
|
13006 | 63 |
some_lub :: "('a*'a)set \<Rightarrow> 'a \<Rightarrow> 'a \<Rightarrow> 'a" |
13074 | 64 |
"some_lub r x y == SOME z. is_lub r x y z"; |
10496 | 65 |
|
13074 | 66 |
locale semilat = |
67 |
fixes A :: "'a set" |
|
68 |
and r :: "'a ord" |
|
69 |
and f :: "'a binop" |
|
70 |
assumes semilat: "semilat(A,r,f)" |
|
10496 | 71 |
|
72 |
lemma order_refl [simp, intro]: |
|
13006 | 73 |
"order r \<Longrightarrow> x <=_r x"; |
10496 | 74 |
by (simp add: order_def) |
75 |
||
76 |
lemma order_antisym: |
|
13006 | 77 |
"\<lbrakk> order r; x <=_r y; y <=_r x \<rbrakk> \<Longrightarrow> x = y" |
10496 | 78 |
apply (unfold order_def) |
13074 | 79 |
apply (simp (no_asm_simp)) |
10496 | 80 |
done |
81 |
||
82 |
lemma order_trans: |
|
13006 | 83 |
"\<lbrakk> order r; x <=_r y; y <=_r z \<rbrakk> \<Longrightarrow> x <=_r z" |
10496 | 84 |
apply (unfold order_def) |
85 |
apply blast |
|
86 |
done |
|
87 |
||
88 |
lemma order_less_irrefl [intro, simp]: |
|
13006 | 89 |
"order r \<Longrightarrow> ~ x <_r x" |
10496 | 90 |
apply (unfold order_def lesssub_def) |
91 |
apply blast |
|
92 |
done |
|
93 |
||
94 |
lemma order_less_trans: |
|
13006 | 95 |
"\<lbrakk> order r; x <_r y; y <_r z \<rbrakk> \<Longrightarrow> x <_r z" |
10496 | 96 |
apply (unfold order_def lesssub_def) |
97 |
apply blast |
|
98 |
done |
|
99 |
||
100 |
lemma topD [simp, intro]: |
|
13006 | 101 |
"top r T \<Longrightarrow> x <=_r T" |
10496 | 102 |
by (simp add: top_def) |
103 |
||
104 |
lemma top_le_conv [simp]: |
|
13006 | 105 |
"\<lbrakk> order r; top r T \<rbrakk> \<Longrightarrow> (T <=_r x) = (x = T)" |
10496 | 106 |
by (blast intro: order_antisym) |
107 |
||
108 |
lemma semilat_Def: |
|
109 |
"semilat(A,r,f) == order r & closed A f & |
|
110 |
(!x:A. !y:A. x <=_r x +_f y) & |
|
111 |
(!x:A. !y:A. y <=_r x +_f y) & |
|
13006 | 112 |
(!x:A. !y:A. !z:A. x <=_r z & y <=_r z \<longrightarrow> x +_f y <=_r z)" |
10918 | 113 |
apply (unfold semilat_def split_conv [THEN eq_reflection]) |
10496 | 114 |
apply (rule refl [THEN eq_reflection]) |
115 |
done |
|
116 |
||
13074 | 117 |
lemma (in semilat) orderI [simp, intro]: |
118 |
"order r" |
|
119 |
by (insert semilat) (simp add: semilat_Def) |
|
120 |
||
121 |
lemma (in semilat) closedI [simp, intro]: |
|
122 |
"closed A f" |
|
123 |
by (insert semilat) (simp add: semilat_Def) |
|
124 |
||
13077 | 125 |
lemma closedD: |
126 |
"\<lbrakk> closed A f; x:A; y:A \<rbrakk> \<Longrightarrow> x +_f y : A" |
|
127 |
by (unfold closed_def) blast |
|
128 |
||
129 |
lemma closed_UNIV [simp]: "closed UNIV f" |
|
130 |
by (simp add: closed_def) |
|
131 |
||
132 |
||
133 |
lemma (in semilat) closed_f [simp, intro]: |
|
134 |
"\<lbrakk>x:A; y:A\<rbrakk> \<Longrightarrow> x +_f y : A" |
|
135 |
by (simp add: closedD [OF closedI]) |
|
136 |
||
137 |
lemma (in semilat) refl_r [intro, simp]: |
|
138 |
"x <=_r x" |
|
139 |
by simp |
|
140 |
||
141 |
lemma (in semilat) antisym_r [intro?]: |
|
142 |
"\<lbrakk> x <=_r y; y <=_r x \<rbrakk> \<Longrightarrow> x = y" |
|
143 |
by (rule order_antisym) auto |
|
144 |
||
145 |
lemma (in semilat) trans_r [trans, intro?]: |
|
146 |
"\<lbrakk>x <=_r y; y <=_r z\<rbrakk> \<Longrightarrow> x <=_r z" |
|
147 |
by (auto intro: order_trans) |
|
148 |
||
149 |
||
150 |
lemma (in semilat) ub1 [simp, intro?]: |
|
13074 | 151 |
"\<lbrakk> x:A; y:A \<rbrakk> \<Longrightarrow> x <=_r x +_f y" |
152 |
by (insert semilat) (unfold semilat_Def, simp) |
|
153 |
||
13077 | 154 |
lemma (in semilat) ub2 [simp, intro?]: |
13074 | 155 |
"\<lbrakk> x:A; y:A \<rbrakk> \<Longrightarrow> y <=_r x +_f y" |
156 |
by (insert semilat) (unfold semilat_Def, simp) |
|
10496 | 157 |
|
13077 | 158 |
lemma (in semilat) lub [simp, intro?]: |
13074 | 159 |
"\<lbrakk> x <=_r z; y <=_r z; x:A; y:A; z:A \<rbrakk> \<Longrightarrow> x +_f y <=_r z"; |
160 |
by (insert semilat) (unfold semilat_Def, simp) |
|
161 |
||
162 |
||
163 |
lemma (in semilat) plus_le_conv [simp]: |
|
164 |
"\<lbrakk> x:A; y:A; z:A \<rbrakk> \<Longrightarrow> (x +_f y <=_r z) = (x <=_r z & y <=_r z)" |
|
13077 | 165 |
by (blast intro: ub1 ub2 lub order_trans) |
13074 | 166 |
|
167 |
lemma (in semilat) le_iff_plus_unchanged: |
|
168 |
"\<lbrakk> x:A; y:A \<rbrakk> \<Longrightarrow> (x <=_r y) = (x +_f y = y)" |
|
169 |
apply (rule iffI) |
|
13077 | 170 |
apply (blast intro: antisym_r refl_r lub ub2) |
13074 | 171 |
apply (erule subst) |
10496 | 172 |
apply simp |
173 |
done |
|
174 |
||
13074 | 175 |
lemma (in semilat) le_iff_plus_unchanged2: |
176 |
"\<lbrakk> x:A; y:A \<rbrakk> \<Longrightarrow> (x <=_r y) = (y +_f x = y)" |
|
10496 | 177 |
apply (rule iffI) |
13074 | 178 |
apply (blast intro: order_antisym lub order_refl ub1) |
10496 | 179 |
apply (erule subst) |
180 |
apply simp |
|
181 |
done |
|
182 |
||
183 |
||
13074 | 184 |
lemma (in semilat) plus_assoc [simp]: |
13068 | 185 |
assumes a: "a \<in> A" and b: "b \<in> A" and c: "c \<in> A" |
186 |
shows "a +_f (b +_f c) = a +_f b +_f c" |
|
187 |
proof - |
|
188 |
from a b have ab: "a +_f b \<in> A" .. |
|
189 |
from this c have abc: "(a +_f b) +_f c \<in> A" .. |
|
190 |
from b c have bc: "b +_f c \<in> A" .. |
|
191 |
from a this have abc': "a +_f (b +_f c) \<in> A" .. |
|
192 |
||
13077 | 193 |
show ?thesis |
194 |
proof |
|
13068 | 195 |
show "a +_f (b +_f c) <=_r (a +_f b) +_f c" |
13074 | 196 |
proof - |
13068 | 197 |
from a b have "a <=_r a +_f b" .. |
198 |
also from ab c have "\<dots> <=_r \<dots> +_f c" .. |
|
199 |
finally have "a<": "a <=_r (a +_f b) +_f c" . |
|
200 |
from a b have "b <=_r a +_f b" .. |
|
201 |
also from ab c have "\<dots> <=_r \<dots> +_f c" .. |
|
202 |
finally have "b<": "b <=_r (a +_f b) +_f c" . |
|
203 |
from ab c have "c<": "c <=_r (a +_f b) +_f c" .. |
|
204 |
from "b<" "c<" b c abc have "b +_f c <=_r (a +_f b) +_f c" .. |
|
205 |
from "a<" this a bc abc show ?thesis .. |
|
206 |
qed |
|
207 |
show "(a +_f b) +_f c <=_r a +_f (b +_f c)" |
|
208 |
proof - |
|
209 |
from b c have "b <=_r b +_f c" .. |
|
210 |
also from a bc have "\<dots> <=_r a +_f \<dots>" .. |
|
211 |
finally have "b<": "b <=_r a +_f (b +_f c)" . |
|
212 |
from b c have "c <=_r b +_f c" .. |
|
213 |
also from a bc have "\<dots> <=_r a +_f \<dots>" .. |
|
214 |
finally have "c<": "c <=_r a +_f (b +_f c)" . |
|
215 |
from a bc have "a<": "a <=_r a +_f (b +_f c)" .. |
|
216 |
from "a<" "b<" a b abc' have "a +_f b <=_r a +_f (b +_f c)" .. |
|
217 |
from this "c<" ab c abc' show ?thesis .. |
|
218 |
qed |
|
219 |
qed |
|
220 |
qed |
|
221 |
||
13074 | 222 |
lemma (in semilat) plus_com_lemma: |
223 |
"\<lbrakk>a \<in> A; b \<in> A\<rbrakk> \<Longrightarrow> a +_f b <=_r b +_f a" |
|
13068 | 224 |
proof - |
13074 | 225 |
assume a: "a \<in> A" and b: "b \<in> A" |
13077 | 226 |
from b a have "a <=_r b +_f a" .. |
227 |
moreover from b a have "b <=_r b +_f a" .. |
|
228 |
moreover note a b |
|
229 |
moreover from b a have "b +_f a \<in> A" .. |
|
230 |
ultimately show ?thesis .. |
|
13068 | 231 |
qed |
232 |
||
13074 | 233 |
lemma (in semilat) plus_commutative: |
234 |
"\<lbrakk>a \<in> A; b \<in> A\<rbrakk> \<Longrightarrow> a +_f b = b +_f a" |
|
235 |
by(blast intro: order_antisym plus_com_lemma) |
|
13068 | 236 |
|
10496 | 237 |
lemma is_lubD: |
13006 | 238 |
"is_lub r x y u \<Longrightarrow> is_ub r x y u & (!z. is_ub r x y z \<longrightarrow> (u,z):r)" |
10496 | 239 |
by (simp add: is_lub_def) |
240 |
||
241 |
lemma is_ubI: |
|
13006 | 242 |
"\<lbrakk> (x,u) : r; (y,u) : r \<rbrakk> \<Longrightarrow> is_ub r x y u" |
10496 | 243 |
by (simp add: is_ub_def) |
244 |
||
245 |
lemma is_ubD: |
|
13006 | 246 |
"is_ub r x y u \<Longrightarrow> (x,u) : r & (y,u) : r" |
10496 | 247 |
by (simp add: is_ub_def) |
248 |
||
249 |
||
250 |
lemma is_lub_bigger1 [iff]: |
|
251 |
"is_lub (r^* ) x y y = ((x,y):r^* )" |
|
252 |
apply (unfold is_lub_def is_ub_def) |
|
253 |
apply blast |
|
254 |
done |
|
255 |
||
256 |
lemma is_lub_bigger2 [iff]: |
|
257 |
"is_lub (r^* ) x y x = ((y,x):r^* )" |
|
258 |
apply (unfold is_lub_def is_ub_def) |
|
259 |
apply blast |
|
12542 | 260 |
done |
10496 | 261 |
|
262 |
lemma extend_lub: |
|
13006 | 263 |
"\<lbrakk> single_valued r; is_lub (r^* ) x y u; (x',x) : r \<rbrakk> |
264 |
\<Longrightarrow> EX v. is_lub (r^* ) x' y v" |
|
10496 | 265 |
apply (unfold is_lub_def is_ub_def) |
266 |
apply (case_tac "(y,x) : r^*") |
|
267 |
apply (case_tac "(y,x') : r^*") |
|
268 |
apply blast |
|
11175
56ab6a5ba351
recoded function iter with the help of the while-combinator.
nipkow
parents:
11085
diff
changeset
|
269 |
apply (blast elim: converse_rtranclE dest: single_valuedD) |
10496 | 270 |
apply (rule exI) |
271 |
apply (rule conjI) |
|
12566
fe20540bcf93
renamed rtrancl_into_rtrancl2 to converse_rtrancl_into_rtrancl
nipkow
parents:
12542
diff
changeset
|
272 |
apply (blast intro: converse_rtrancl_into_rtrancl dest: single_valuedD) |
fe20540bcf93
renamed rtrancl_into_rtrancl2 to converse_rtrancl_into_rtrancl
nipkow
parents:
12542
diff
changeset
|
273 |
apply (blast intro: rtrancl_into_rtrancl converse_rtrancl_into_rtrancl |
10797 | 274 |
elim: converse_rtranclE dest: single_valuedD) |
12542 | 275 |
done |
10496 | 276 |
|
10797 | 277 |
lemma single_valued_has_lubs [rule_format]: |
13006 | 278 |
"\<lbrakk> single_valued r; (x,u) : r^* \<rbrakk> \<Longrightarrow> (!y. (y,u) : r^* \<longrightarrow> |
10496 | 279 |
(EX z. is_lub (r^* ) x y z))" |
280 |
apply (erule converse_rtrancl_induct) |
|
281 |
apply clarify |
|
282 |
apply (erule converse_rtrancl_induct) |
|
283 |
apply blast |
|
12566
fe20540bcf93
renamed rtrancl_into_rtrancl2 to converse_rtrancl_into_rtrancl
nipkow
parents:
12542
diff
changeset
|
284 |
apply (blast intro: converse_rtrancl_into_rtrancl) |
10496 | 285 |
apply (blast intro: extend_lub) |
286 |
done |
|
287 |
||
288 |
lemma some_lub_conv: |
|
13006 | 289 |
"\<lbrakk> acyclic r; is_lub (r^* ) x y u \<rbrakk> \<Longrightarrow> some_lub (r^* ) x y = u" |
10496 | 290 |
apply (unfold some_lub_def is_lub_def) |
291 |
apply (rule someI2) |
|
292 |
apply assumption |
|
293 |
apply (blast intro: antisymD dest!: acyclic_impl_antisym_rtrancl) |
|
12542 | 294 |
done |
10496 | 295 |
|
296 |
lemma is_lub_some_lub: |
|
13006 | 297 |
"\<lbrakk> single_valued r; acyclic r; (x,u):r^*; (y,u):r^* \<rbrakk> |
298 |
\<Longrightarrow> is_lub (r^* ) x y (some_lub (r^* ) x y)"; |
|
10797 | 299 |
by (fastsimp dest: single_valued_has_lubs simp add: some_lub_conv) |
10496 | 300 |
|
12542 | 301 |
subsection{*An executable lub-finder*} |
302 |
||
303 |
constdefs |
|
304 |
exec_lub :: "('a * 'a) set \<Rightarrow> ('a \<Rightarrow> 'a) \<Rightarrow> 'a binop" |
|
305 |
"exec_lub r f x y == while (\<lambda>z. (x,z) \<notin> r\<^sup>*) f y" |
|
306 |
||
307 |
||
308 |
lemma acyclic_single_valued_finite: |
|
309 |
"\<lbrakk>acyclic r; single_valued r; (x,y) \<in> r\<^sup>*\<rbrakk> |
|
310 |
\<Longrightarrow> finite (r \<inter> {a. (x, a) \<in> r\<^sup>*} \<times> {b. (b, y) \<in> r\<^sup>*})" |
|
311 |
apply(erule converse_rtrancl_induct) |
|
312 |
apply(rule_tac B = "{}" in finite_subset) |
|
313 |
apply(simp only:acyclic_def) |
|
314 |
apply(blast intro:rtrancl_into_trancl2 rtrancl_trancl_trancl) |
|
315 |
apply simp |
|
316 |
apply(rename_tac x x') |
|
317 |
apply(subgoal_tac "r \<inter> {a. (x,a) \<in> r\<^sup>*} \<times> {b. (b,y) \<in> r\<^sup>*} = |
|
318 |
insert (x,x') (r \<inter> {a. (x', a) \<in> r\<^sup>*} \<times> {b. (b, y) \<in> r\<^sup>*})") |
|
319 |
apply simp |
|
12566
fe20540bcf93
renamed rtrancl_into_rtrancl2 to converse_rtrancl_into_rtrancl
nipkow
parents:
12542
diff
changeset
|
320 |
apply(blast intro:converse_rtrancl_into_rtrancl |
12542 | 321 |
elim:converse_rtranclE dest:single_valuedD) |
322 |
done |
|
323 |
||
324 |
||
12773 | 325 |
lemma exec_lub_conv: |
326 |
"\<lbrakk> acyclic r; !x y. (x,y) \<in> r \<longrightarrow> f x = y; is_lub (r\<^sup>*) x y u \<rbrakk> \<Longrightarrow> |
|
327 |
exec_lub r f x y = u"; |
|
12542 | 328 |
apply(unfold exec_lub_def) |
329 |
apply(rule_tac P = "\<lambda>z. (y,z) \<in> r\<^sup>* \<and> (z,u) \<in> r\<^sup>*" and |
|
330 |
r = "(r \<inter> {(a,b). (y,a) \<in> r\<^sup>* \<and> (b,u) \<in> r\<^sup>*})^-1" in while_rule) |
|
331 |
apply(blast dest: is_lubD is_ubD) |
|
332 |
apply(erule conjE) |
|
333 |
apply(erule_tac z = u in converse_rtranclE) |
|
334 |
apply(blast dest: is_lubD is_ubD) |
|
335 |
apply(blast dest:rtrancl_into_rtrancl) |
|
336 |
apply(rename_tac s) |
|
337 |
apply(subgoal_tac "is_ub (r\<^sup>*) x y s") |
|
338 |
prefer 2; apply(simp add:is_ub_def) |
|
339 |
apply(subgoal_tac "(u, s) \<in> r\<^sup>*") |
|
340 |
prefer 2; apply(blast dest:is_lubD) |
|
341 |
apply(erule converse_rtranclE) |
|
342 |
apply blast |
|
343 |
apply(simp only:acyclic_def) |
|
344 |
apply(blast intro:rtrancl_into_trancl2 rtrancl_trancl_trancl) |
|
345 |
apply(rule finite_acyclic_wf) |
|
346 |
apply simp |
|
347 |
apply(erule acyclic_single_valued_finite) |
|
348 |
apply(blast intro:single_valuedI) |
|
349 |
apply(simp add:is_lub_def is_ub_def) |
|
350 |
apply simp |
|
351 |
apply(erule acyclic_subset) |
|
352 |
apply blast |
|
353 |
apply simp |
|
354 |
apply(erule conjE) |
|
355 |
apply(erule_tac z = u in converse_rtranclE) |
|
356 |
apply(blast dest: is_lubD is_ubD) |
|
357 |
apply(blast dest:rtrancl_into_rtrancl) |
|
358 |
done |
|
359 |
||
12773 | 360 |
lemma is_lub_exec_lub: |
361 |
"\<lbrakk> single_valued r; acyclic r; (x,u):r^*; (y,u):r^*; !x y. (x,y) \<in> r \<longrightarrow> f x = y \<rbrakk> |
|
362 |
\<Longrightarrow> is_lub (r^* ) x y (exec_lub r f x y)" |
|
363 |
by (fastsimp dest: single_valued_has_lubs simp add: exec_lub_conv) |
|
364 |
||
10496 | 365 |
end |