author | nipkow |
Mon, 26 Mar 2001 19:37:31 +0200 | |
changeset 11225 | 01181fdbc9f0 |
parent 11085 | b830bf10bf71 |
child 11549 | e7265e70fd7c |
permissions | -rw-r--r-- |
10496 | 1 |
(* Title: HOL/BCV/Err.thy |
2 |
ID: $Id$ |
|
3 |
Author: Tobias Nipkow |
|
4 |
Copyright 2000 TUM |
|
5 |
||
6 |
The error type |
|
7 |
*) |
|
8 |
||
9 |
header "The Error Type" |
|
10 |
||
11 |
theory Err = Semilat: |
|
12 |
||
13 |
datatype 'a err = Err | OK 'a |
|
14 |
||
15 |
types 'a ebinop = "'a => 'a => 'a err" |
|
16 |
'a esl = "'a set * 'a ord * 'a ebinop" |
|
17 |
||
18 |
consts |
|
19 |
ok_val :: "'a err => 'a" |
|
20 |
primrec |
|
21 |
"ok_val (OK x) = x" |
|
22 |
||
23 |
constdefs |
|
24 |
lift :: "('a => 'b err) => ('a err => 'b err)" |
|
25 |
"lift f e == case e of Err => Err | OK x => f x" |
|
26 |
||
27 |
lift2 :: "('a => 'b => 'c err) => 'a err => 'b err => 'c err" |
|
28 |
"lift2 f e1 e2 == |
|
29 |
case e1 of Err => Err |
|
30 |
| OK x => (case e2 of Err => Err | OK y => f x y)" |
|
31 |
||
32 |
le :: "'a ord => 'a err ord" |
|
33 |
"le r e1 e2 == |
|
34 |
case e2 of Err => True | |
|
35 |
OK y => (case e1 of Err => False | OK x => x <=_r y)" |
|
36 |
||
37 |
sup :: "('a => 'b => 'c) => ('a err => 'b err => 'c err)" |
|
38 |
"sup f == lift2(%x y. OK(x +_f y))" |
|
39 |
||
40 |
err :: "'a set => 'a err set" |
|
41 |
"err A == insert Err {x . ? y:A. x = OK y}" |
|
42 |
||
43 |
esl :: "'a sl => 'a esl" |
|
44 |
"esl == %(A,r,f). (A,r, %x y. OK(f x y))" |
|
45 |
||
46 |
sl :: "'a esl => 'a err sl" |
|
47 |
"sl == %(A,r,f). (err A, le r, lift2 f)" |
|
48 |
||
49 |
syntax |
|
50 |
err_semilat :: "'a esl => bool" |
|
51 |
translations |
|
52 |
"err_semilat L" == "semilat(Err.sl L)" |
|
53 |
||
54 |
||
10812
ead84e90bfeb
merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents:
10496
diff
changeset
|
55 |
consts |
ead84e90bfeb
merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents:
10496
diff
changeset
|
56 |
strict :: "('a => 'b err) => ('a err => 'b err)" |
ead84e90bfeb
merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents:
10496
diff
changeset
|
57 |
primrec |
ead84e90bfeb
merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents:
10496
diff
changeset
|
58 |
"strict f Err = Err" |
ead84e90bfeb
merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents:
10496
diff
changeset
|
59 |
"strict f (OK x) = f x" |
ead84e90bfeb
merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents:
10496
diff
changeset
|
60 |
|
11085 | 61 |
lemma strict_Some [simp]: |
62 |
"(strict f x = OK y) = (\<exists> z. x = OK z \<and> f z = OK y)" |
|
63 |
by (cases x, auto) |
|
10812
ead84e90bfeb
merged semilattice orders with <=' from Convert.thy (now defined in JVMType.thy)
kleing
parents:
10496
diff
changeset
|
64 |
|
10496 | 65 |
lemma not_Err_eq: |
66 |
"(x \<noteq> Err) = (\<exists>a. x = OK a)" |
|
67 |
by (cases x) auto |
|
68 |
||
69 |
lemma not_OK_eq: |
|
70 |
"(\<forall>y. x \<noteq> OK y) = (x = Err)" |
|
71 |
by (cases x) auto |
|
72 |
||
73 |
lemma unfold_lesub_err: |
|
74 |
"e1 <=_(le r) e2 == le r e1 e2" |
|
75 |
by (simp add: lesub_def) |
|
76 |
||
77 |
lemma le_err_refl: |
|
78 |
"!x. x <=_r x ==> e <=_(Err.le r) e" |
|
79 |
apply (unfold lesub_def Err.le_def) |
|
80 |
apply (simp split: err.split) |
|
81 |
done |
|
82 |
||
83 |
lemma le_err_trans [rule_format]: |
|
84 |
"order r ==> e1 <=_(le r) e2 --> e2 <=_(le r) e3 --> e1 <=_(le r) e3" |
|
85 |
apply (unfold unfold_lesub_err le_def) |
|
86 |
apply (simp split: err.split) |
|
87 |
apply (blast intro: order_trans) |
|
88 |
done |
|
89 |
||
90 |
lemma le_err_antisym [rule_format]: |
|
91 |
"order r ==> e1 <=_(le r) e2 --> e2 <=_(le r) e1 --> e1=e2" |
|
92 |
apply (unfold unfold_lesub_err le_def) |
|
93 |
apply (simp split: err.split) |
|
94 |
apply (blast intro: order_antisym) |
|
95 |
done |
|
96 |
||
97 |
lemma OK_le_err_OK: |
|
98 |
"(OK x <=_(le r) OK y) = (x <=_r y)" |
|
99 |
by (simp add: unfold_lesub_err le_def) |
|
100 |
||
101 |
lemma order_le_err [iff]: |
|
102 |
"order(le r) = order r" |
|
103 |
apply (rule iffI) |
|
104 |
apply (subst order_def) |
|
105 |
apply (blast dest: order_antisym OK_le_err_OK [THEN iffD2] |
|
106 |
intro: order_trans OK_le_err_OK [THEN iffD1]) |
|
107 |
apply (subst order_def) |
|
108 |
apply (blast intro: le_err_refl le_err_trans le_err_antisym |
|
109 |
dest: order_refl) |
|
110 |
done |
|
111 |
||
112 |
lemma le_Err [iff]: "e <=_(le r) Err" |
|
113 |
by (simp add: unfold_lesub_err le_def) |
|
114 |
||
115 |
lemma Err_le_conv [iff]: |
|
116 |
"Err <=_(le r) e = (e = Err)" |
|
117 |
by (simp add: unfold_lesub_err le_def split: err.split) |
|
118 |
||
119 |
lemma le_OK_conv [iff]: |
|
120 |
"e <=_(le r) OK x = (? y. e = OK y & y <=_r x)" |
|
121 |
by (simp add: unfold_lesub_err le_def split: err.split) |
|
122 |
||
123 |
lemma OK_le_conv: |
|
124 |
"OK x <=_(le r) e = (e = Err | (? y. e = OK y & x <=_r y))" |
|
125 |
by (simp add: unfold_lesub_err le_def split: err.split) |
|
126 |
||
127 |
lemma top_Err [iff]: "top (le r) Err"; |
|
128 |
by (simp add: top_def) |
|
129 |
||
130 |
lemma OK_less_conv [rule_format, iff]: |
|
131 |
"OK x <_(le r) e = (e=Err | (? y. e = OK y & x <_r y))" |
|
132 |
by (simp add: lesssub_def lesub_def le_def split: err.split) |
|
133 |
||
134 |
lemma not_Err_less [rule_format, iff]: |
|
135 |
"~(Err <_(le r) x)" |
|
136 |
by (simp add: lesssub_def lesub_def le_def split: err.split) |
|
137 |
||
138 |
lemma semilat_errI: |
|
139 |
"semilat(A,r,f) ==> semilat(err A, Err.le r, lift2(%x y. OK(f x y)))" |
|
140 |
apply (unfold semilat_Def closed_def plussub_def lesub_def lift2_def Err.le_def err_def) |
|
141 |
apply (simp split: err.split) |
|
142 |
done |
|
143 |
||
144 |
lemma err_semilat_eslI: |
|
145 |
"!!L. semilat L ==> err_semilat(esl L)" |
|
146 |
apply (unfold sl_def esl_def) |
|
147 |
apply (simp (no_asm_simp) only: split_tupled_all) |
|
148 |
apply (simp add: semilat_errI) |
|
149 |
done |
|
150 |
||
151 |
lemma acc_err [simp, intro!]: "acc r ==> acc(le r)" |
|
152 |
apply (unfold acc_def lesub_def le_def lesssub_def) |
|
153 |
apply (simp add: wf_eq_minimal split: err.split) |
|
154 |
apply clarify |
|
155 |
apply (case_tac "Err : Q") |
|
156 |
apply blast |
|
157 |
apply (erule_tac x = "{a . OK a : Q}" in allE) |
|
158 |
apply (case_tac "x") |
|
159 |
apply fast |
|
160 |
apply blast |
|
161 |
done |
|
162 |
||
163 |
lemma Err_in_err [iff]: "Err : err A" |
|
164 |
by (simp add: err_def) |
|
165 |
||
166 |
lemma Ok_in_err [iff]: "(OK x : err A) = (x:A)" |
|
167 |
by (auto simp add: err_def) |
|
168 |
||
11085 | 169 |
section {* lift *} |
10496 | 170 |
|
171 |
lemma lift_in_errI: |
|
172 |
"[| e : err S; !x:S. e = OK x --> f x : err S |] ==> lift f e : err S" |
|
173 |
apply (unfold lift_def) |
|
174 |
apply (simp split: err.split) |
|
175 |
apply blast |
|
176 |
done |
|
177 |
||
178 |
lemma Err_lift2 [simp]: |
|
179 |
"Err +_(lift2 f) x = Err" |
|
180 |
by (simp add: lift2_def plussub_def) |
|
181 |
||
182 |
lemma lift2_Err [simp]: |
|
183 |
"x +_(lift2 f) Err = Err" |
|
184 |
by (simp add: lift2_def plussub_def split: err.split) |
|
185 |
||
186 |
lemma OK_lift2_OK [simp]: |
|
187 |
"OK x +_(lift2 f) OK y = x +_f y" |
|
188 |
by (simp add: lift2_def plussub_def split: err.split) |
|
189 |
||
11085 | 190 |
|
191 |
section {* sup *} |
|
10496 | 192 |
|
193 |
lemma Err_sup_Err [simp]: |
|
194 |
"Err +_(Err.sup f) x = Err" |
|
195 |
by (simp add: plussub_def Err.sup_def Err.lift2_def) |
|
196 |
||
197 |
lemma Err_sup_Err2 [simp]: |
|
198 |
"x +_(Err.sup f) Err = Err" |
|
199 |
by (simp add: plussub_def Err.sup_def Err.lift2_def split: err.split) |
|
200 |
||
201 |
lemma Err_sup_OK [simp]: |
|
202 |
"OK x +_(Err.sup f) OK y = OK(x +_f y)" |
|
203 |
by (simp add: plussub_def Err.sup_def Err.lift2_def) |
|
204 |
||
205 |
lemma Err_sup_eq_OK_conv [iff]: |
|
206 |
"(Err.sup f ex ey = OK z) = (? x y. ex = OK x & ey = OK y & f x y = z)" |
|
207 |
apply (unfold Err.sup_def lift2_def plussub_def) |
|
208 |
apply (rule iffI) |
|
209 |
apply (simp split: err.split_asm) |
|
210 |
apply clarify |
|
211 |
apply simp |
|
212 |
done |
|
213 |
||
214 |
lemma Err_sup_eq_Err [iff]: |
|
215 |
"(Err.sup f ex ey = Err) = (ex=Err | ey=Err)" |
|
216 |
apply (unfold Err.sup_def lift2_def plussub_def) |
|
217 |
apply (simp split: err.split) |
|
218 |
done |
|
219 |
||
11085 | 220 |
section {* semilat (err A) (le r) f *} |
10496 | 221 |
|
222 |
lemma semilat_le_err_Err_plus [simp]: |
|
223 |
"[| x: err A; semilat(err A, le r, f) |] ==> Err +_f x = Err" |
|
224 |
by (blast intro: le_iff_plus_unchanged [THEN iffD1] le_iff_plus_unchanged2 [THEN iffD1]) |
|
225 |
||
226 |
lemma semilat_le_err_plus_Err [simp]: |
|
227 |
"[| x: err A; semilat(err A, le r, f) |] ==> x +_f Err = Err" |
|
228 |
by (blast intro: le_iff_plus_unchanged [THEN iffD1] le_iff_plus_unchanged2 [THEN iffD1]) |
|
229 |
||
230 |
lemma semilat_le_err_OK1: |
|
231 |
"[| x:A; y:A; semilat(err A, le r, f); OK x +_f OK y = OK z |] |
|
232 |
==> x <=_r z"; |
|
233 |
apply (rule OK_le_err_OK [THEN iffD1]) |
|
234 |
apply (erule subst) |
|
235 |
apply simp |
|
236 |
done |
|
237 |
||
238 |
lemma semilat_le_err_OK2: |
|
239 |
"[| x:A; y:A; semilat(err A, le r, f); OK x +_f OK y = OK z |] |
|
240 |
==> y <=_r z" |
|
241 |
apply (rule OK_le_err_OK [THEN iffD1]) |
|
242 |
apply (erule subst) |
|
243 |
apply simp |
|
244 |
done |
|
245 |
||
246 |
lemma eq_order_le: |
|
247 |
"[| x=y; order r |] ==> x <=_r y" |
|
248 |
apply (unfold order_def) |
|
249 |
apply blast |
|
250 |
done |
|
251 |
||
252 |
lemma OK_plus_OK_eq_Err_conv [simp]: |
|
253 |
"[| x:A; y:A; semilat(err A, le r, fe) |] ==> |
|
254 |
((OK x) +_fe (OK y) = Err) = (~(? z:A. x <=_r z & y <=_r z))" |
|
255 |
proof - |
|
256 |
have plus_le_conv3: "!!A x y z f r. |
|
257 |
[| semilat (A,r,f); x +_f y <=_r z; x:A; y:A; z:A |] |
|
258 |
==> x <=_r z \<and> y <=_r z" |
|
259 |
by (rule plus_le_conv [THEN iffD1]) |
|
260 |
case antecedent |
|
261 |
thus ?thesis |
|
262 |
apply (rule_tac iffI) |
|
263 |
apply clarify |
|
264 |
apply (drule OK_le_err_OK [THEN iffD2]) |
|
265 |
apply (drule OK_le_err_OK [THEN iffD2]) |
|
266 |
apply (drule semilat_lub) |
|
267 |
apply assumption |
|
268 |
apply assumption |
|
269 |
apply simp |
|
270 |
apply simp |
|
271 |
apply simp |
|
272 |
apply simp |
|
273 |
apply (case_tac "(OK x) +_fe (OK y)") |
|
274 |
apply assumption |
|
275 |
apply (rename_tac z) |
|
276 |
apply (subgoal_tac "OK z: err A") |
|
277 |
apply (drule eq_order_le) |
|
278 |
apply blast |
|
279 |
apply (blast dest: plus_le_conv3) |
|
280 |
apply (erule subst) |
|
281 |
apply (blast intro: closedD) |
|
282 |
done |
|
283 |
qed |
|
284 |
||
11085 | 285 |
section {* semilat (err(Union AS)) *} |
10496 | 286 |
|
287 |
(* FIXME? *) |
|
288 |
lemma all_bex_swap_lemma [iff]: |
|
289 |
"(!x. (? y:A. x = f y) --> P x) = (!y:A. P(f y))" |
|
290 |
by blast |
|
291 |
||
292 |
lemma closed_err_Union_lift2I: |
|
293 |
"[| !A:AS. closed (err A) (lift2 f); AS ~= {}; |
|
294 |
!A:AS.!B:AS. A~=B --> (!a:A.!b:B. a +_f b = Err) |] |
|
295 |
==> closed (err(Union AS)) (lift2 f)" |
|
296 |
apply (unfold closed_def err_def) |
|
297 |
apply simp |
|
298 |
apply clarify |
|
299 |
apply simp |
|
300 |
apply fast |
|
301 |
done |
|
302 |
||
11085 | 303 |
text {* |
304 |
If @{term "AS = {}"} the thm collapses to |
|
305 |
@{prop "order r & closed {Err} f & Err +_f Err = Err"} |
|
306 |
which may not hold |
|
307 |
*} |
|
10496 | 308 |
lemma err_semilat_UnionI: |
309 |
"[| !A:AS. err_semilat(A, r, f); AS ~= {}; |
|
310 |
!A:AS.!B:AS. A~=B --> (!a:A.!b:B. ~ a <=_r b & a +_f b = Err) |] |
|
311 |
==> err_semilat(Union AS, r, f)" |
|
312 |
apply (unfold semilat_def sl_def) |
|
313 |
apply (simp add: closed_err_Union_lift2I) |
|
314 |
apply (rule conjI) |
|
315 |
apply blast |
|
316 |
apply (simp add: err_def) |
|
317 |
apply (rule conjI) |
|
318 |
apply clarify |
|
319 |
apply (rename_tac A a u B b) |
|
320 |
apply (case_tac "A = B") |
|
321 |
apply simp |
|
322 |
apply simp |
|
323 |
apply (rule conjI) |
|
324 |
apply clarify |
|
325 |
apply (rename_tac A a u B b) |
|
326 |
apply (case_tac "A = B") |
|
327 |
apply simp |
|
328 |
apply simp |
|
329 |
apply clarify |
|
330 |
apply (rename_tac A ya yb B yd z C c a b) |
|
331 |
apply (case_tac "A = B") |
|
332 |
apply (case_tac "A = C") |
|
333 |
apply simp |
|
334 |
apply (rotate_tac -1) |
|
335 |
apply simp |
|
336 |
apply (rotate_tac -1) |
|
337 |
apply (case_tac "B = C") |
|
338 |
apply simp |
|
339 |
apply (rotate_tac -1) |
|
340 |
apply simp |
|
341 |
done |
|
342 |
||
343 |
end |