11229
|
1 |
(* Title: HOL/MicroJava/BV/Typing_Framework_err.thy
|
|
2 |
ID: $Id$
|
|
3 |
Author: Gerwin Klein
|
|
4 |
Copyright 2000 TUM
|
|
5 |
|
|
6 |
*)
|
|
7 |
|
12911
|
8 |
header {* \isaheader{Static and Dynamic Welltyping} *}
|
11229
|
9 |
|
13062
|
10 |
theory Typing_Framework_err = Typing_Framework + SemilatAlg:
|
11229
|
11 |
|
|
12 |
constdefs
|
|
13 |
|
13066
|
14 |
wt_err_step :: "'s ord \<Rightarrow> 's err step_type \<Rightarrow> 's err list \<Rightarrow> bool"
|
|
15 |
"wt_err_step r step ts \<equiv> wt_step (Err.le r) Err step ts"
|
12516
|
16 |
|
13066
|
17 |
wt_app_eff :: "'s ord \<Rightarrow> (nat \<Rightarrow> 's \<Rightarrow> bool) \<Rightarrow> 's step_type \<Rightarrow> 's list \<Rightarrow> bool"
|
|
18 |
"wt_app_eff r app step ts \<equiv>
|
12516
|
19 |
\<forall>p < size ts. app p (ts!p) \<and> (\<forall>(q,t) \<in> set (step p (ts!p)). t <=_r ts!q)"
|
|
20 |
|
13067
|
21 |
|
12516
|
22 |
map_snd :: "('b \<Rightarrow> 'c) \<Rightarrow> ('a \<times> 'b) list \<Rightarrow> ('a \<times> 'c) list"
|
13066
|
23 |
"map_snd f \<equiv> map (\<lambda>(x,y). (x, f y))"
|
|
24 |
|
|
25 |
error :: "nat \<Rightarrow> (nat \<times> 'a err) list"
|
|
26 |
"error n \<equiv> map (\<lambda>x. (x,Err)) [0..n(]"
|
11229
|
27 |
|
13067
|
28 |
|
13066
|
29 |
err_step :: "nat \<Rightarrow> (nat \<Rightarrow> 's \<Rightarrow> bool) \<Rightarrow> 's step_type \<Rightarrow> 's err step_type"
|
|
30 |
"err_step n app step p t \<equiv>
|
|
31 |
case t of
|
|
32 |
Err \<Rightarrow> error n
|
|
33 |
| OK t' \<Rightarrow> if app p t' then map_snd OK (step p t') else error n"
|
11229
|
34 |
|
13066
|
35 |
lemmas err_step_defs = err_step_def map_snd_def error_def
|
12516
|
36 |
|
13067
|
37 |
lemma bounded_err_stepD:
|
|
38 |
"bounded (err_step n app step) n \<Longrightarrow>
|
|
39 |
p < n \<Longrightarrow> app p a \<Longrightarrow> (q,b) \<in> set (step p a) \<Longrightarrow>
|
|
40 |
q < n"
|
|
41 |
apply (simp add: bounded_def err_step_def)
|
|
42 |
apply (erule allE, erule impE, assumption)
|
|
43 |
apply (erule_tac x = "OK a" in allE, drule bspec)
|
|
44 |
apply (simp add: map_snd_def)
|
|
45 |
apply fast
|
|
46 |
apply simp
|
|
47 |
done
|
|
48 |
|
|
49 |
|
|
50 |
lemma in_map_sndD: "(a,b) \<in> set (map_snd f xs) \<Longrightarrow> \<exists>b'. (a,b') \<in> set xs"
|
|
51 |
apply (induct xs)
|
|
52 |
apply (auto simp add: map_snd_def)
|
|
53 |
done
|
11229
|
54 |
|
12516
|
55 |
|
13067
|
56 |
lemma bounded_err_stepI:
|
|
57 |
"\<forall>p. p < n \<longrightarrow> (\<forall>s. ap p s \<longrightarrow> (\<forall>(q,s') \<in> set (step p s). q < n))
|
|
58 |
\<Longrightarrow> bounded (err_step n ap step) n"
|
|
59 |
apply (unfold bounded_def)
|
|
60 |
apply clarify
|
|
61 |
apply (simp add: err_step_def split: err.splits)
|
|
62 |
apply (simp add: error_def)
|
|
63 |
apply blast
|
|
64 |
apply (simp split: split_if_asm)
|
|
65 |
apply (blast dest: in_map_sndD)
|
|
66 |
apply (simp add: error_def)
|
|
67 |
apply blast
|
|
68 |
done
|
|
69 |
|
|
70 |
|
|
71 |
text {*
|
|
72 |
There used to be a condition here that each instruction must have a
|
|
73 |
successor. This is not needed any more, because the definition of
|
|
74 |
@{term error} trivially ensures that there is a successor for
|
|
75 |
the critical case where @{term app} does not hold.
|
|
76 |
*}
|
13066
|
77 |
lemma wt_err_imp_wt_app_eff:
|
|
78 |
assumes wt: "wt_err_step r (err_step (size ts) app step) ts"
|
13067
|
79 |
assumes b: "bounded (err_step (size ts) app step) (size ts)"
|
13066
|
80 |
shows "wt_app_eff r app step (map ok_val ts)"
|
|
81 |
proof (unfold wt_app_eff_def, intro strip, rule conjI)
|
|
82 |
fix p assume "p < size (map ok_val ts)"
|
|
83 |
hence lp: "p < size ts" by simp
|
13067
|
84 |
hence ts: "0 < size ts" by (cases p) auto
|
|
85 |
hence err: "(0,Err) \<in> set (error (size ts))" by (simp add: error_def)
|
11229
|
86 |
|
|
87 |
from wt lp
|
13066
|
88 |
have [intro?]: "\<And>p. p < size ts \<Longrightarrow> ts ! p \<noteq> Err"
|
|
89 |
by (unfold wt_err_step_def wt_step_def) simp
|
11229
|
90 |
|
|
91 |
show app: "app p (map ok_val ts ! p)"
|
13067
|
92 |
proof (rule ccontr)
|
|
93 |
from wt lp obtain s where
|
12516
|
94 |
OKp: "ts ! p = OK s" and
|
13066
|
95 |
less: "\<forall>(q,t) \<in> set (err_step (size ts) app step p (ts!p)). t <=_(Err.le r) ts!q"
|
|
96 |
by (unfold wt_err_step_def wt_step_def stable_def)
|
12516
|
97 |
(auto iff: not_Err_eq)
|
13067
|
98 |
assume "\<not> app p (map ok_val ts ! p)"
|
|
99 |
with OKp lp have "\<not> app p s" by simp
|
|
100 |
with OKp have "err_step (size ts) app step p (ts!p) = error (size ts)"
|
|
101 |
by (simp add: err_step_def)
|
|
102 |
with err ts obtain q where
|
|
103 |
"(q,Err) \<in> set (err_step (size ts) app step p (ts!p))" and
|
|
104 |
q: "q < size ts" by auto
|
|
105 |
with less have "ts!q = Err" by auto
|
|
106 |
moreover from q have "ts!q \<noteq> Err" ..
|
|
107 |
ultimately show False by blast
|
12516
|
108 |
qed
|
|
109 |
|
|
110 |
show "\<forall>(q,t)\<in>set(step p (map ok_val ts ! p)). t <=_r map ok_val ts ! q"
|
|
111 |
proof clarify
|
|
112 |
fix q t assume q: "(q,t) \<in> set (step p (map ok_val ts ! p))"
|
11229
|
113 |
|
|
114 |
from wt lp q
|
|
115 |
obtain s where
|
|
116 |
OKp: "ts ! p = OK s" and
|
13066
|
117 |
less: "\<forall>(q,t) \<in> set (err_step (size ts) app step p (ts!p)). t <=_(Err.le r) ts!q"
|
|
118 |
by (unfold wt_err_step_def wt_step_def stable_def)
|
11229
|
119 |
(auto iff: not_Err_eq)
|
|
120 |
|
13067
|
121 |
from b lp app q have lq: "q < size ts" by (rule bounded_err_stepD)
|
12516
|
122 |
hence "ts!q \<noteq> Err" ..
|
|
123 |
then obtain s' where OKq: "ts ! q = OK s'" by (auto iff: not_Err_eq)
|
11229
|
124 |
|
12516
|
125 |
from lp lq OKp OKq app less q
|
|
126 |
show "t <=_r map ok_val ts ! q"
|
|
127 |
by (auto simp add: err_step_def map_snd_def)
|
11229
|
128 |
qed
|
|
129 |
qed
|
|
130 |
|
|
131 |
|
13066
|
132 |
lemma wt_app_eff_imp_wt_err:
|
|
133 |
assumes app_eff: "wt_app_eff r app step ts"
|
|
134 |
assumes bounded: "bounded (err_step (size ts) app step) (size ts)"
|
|
135 |
shows "wt_err_step r (err_step (size ts) app step) (map OK ts)"
|
|
136 |
proof (unfold wt_err_step_def wt_step_def, intro strip, rule conjI)
|
|
137 |
fix p assume "p < size (map OK ts)"
|
|
138 |
hence p: "p < size ts" by simp
|
11229
|
139 |
thus "map OK ts ! p \<noteq> Err" by simp
|
12516
|
140 |
{ fix q t
|
13066
|
141 |
assume q: "(q,t) \<in> set (err_step (size ts) app step p (map OK ts ! p))"
|
|
142 |
with p app_eff obtain
|
12516
|
143 |
"app p (ts ! p)" "\<forall>(q,t) \<in> set (step p (ts!p)). t <=_r ts!q"
|
13066
|
144 |
by (unfold wt_app_eff_def) blast
|
11229
|
145 |
moreover
|
13066
|
146 |
from q p bounded have "q < size ts"
|
|
147 |
by - (rule boundedD)
|
11229
|
148 |
hence "map OK ts ! q = OK (ts!q)" by simp
|
|
149 |
moreover
|
|
150 |
have "p < size ts" by (rule p)
|
12516
|
151 |
moreover note q
|
11229
|
152 |
ultimately
|
12516
|
153 |
have "t <=_(Err.le r) map OK ts ! q"
|
|
154 |
by (auto simp add: err_step_def map_snd_def)
|
11229
|
155 |
}
|
13066
|
156 |
thus "stable (Err.le r) (err_step (size ts) app step) (map OK ts) p"
|
11229
|
157 |
by (unfold stable_def) blast
|
|
158 |
qed
|
|
159 |
|
|
160 |
end
|