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 |
|
|
10 |
theory Typing_Framework_err = Typing_Framework:
|
|
11 |
|
|
12 |
constdefs
|
|
13 |
|
13006
|
14 |
dynamic_wt :: "'s ord \<Rightarrow> 's err step_type \<Rightarrow> 's err list \<Rightarrow> bool"
|
12516
|
15 |
"dynamic_wt r step ts == wt_step (Err.le r) Err step ts"
|
|
16 |
|
13006
|
17 |
static_wt :: "'s ord \<Rightarrow> (nat \<Rightarrow> 's \<Rightarrow> bool) \<Rightarrow> 's step_type \<Rightarrow> 's list \<Rightarrow> bool"
|
12516
|
18 |
"static_wt r app step ts ==
|
|
19 |
\<forall>p < size ts. app p (ts!p) \<and> (\<forall>(q,t) \<in> set (step p (ts!p)). t <=_r ts!q)"
|
|
20 |
|
|
21 |
map_snd :: "('b \<Rightarrow> 'c) \<Rightarrow> ('a \<times> 'b) list \<Rightarrow> ('a \<times> 'c) list"
|
|
22 |
"map_snd f == map (\<lambda>(x,y). (x, f y))"
|
11229
|
23 |
|
12516
|
24 |
map_err :: "('a \<times> 'b) list \<Rightarrow> ('a \<times> 'b err) list"
|
|
25 |
"map_err == map_snd (\<lambda>y. Err)"
|
11229
|
26 |
|
12516
|
27 |
err_step :: "(nat \<Rightarrow> 's \<Rightarrow> bool) \<Rightarrow> 's step_type \<Rightarrow> 's err step_type"
|
|
28 |
"err_step app step p t == case t of Err \<Rightarrow> map_err (step p arbitrary) | OK t' \<Rightarrow>
|
|
29 |
if app p t' then map_snd OK (step p t') else map_err (step p t')"
|
11229
|
30 |
|
13006
|
31 |
non_empty :: "'s step_type \<Rightarrow> bool"
|
12516
|
32 |
"non_empty step == \<forall>p t. step p t \<noteq> []"
|
11229
|
33 |
|
|
34 |
|
12516
|
35 |
lemmas err_step_defs = err_step_def map_snd_def map_err_def
|
|
36 |
|
11229
|
37 |
lemma non_emptyD:
|
13006
|
38 |
"non_empty step \<Longrightarrow> \<exists>q t'. (q,t') \<in> set(step p t)"
|
11229
|
39 |
proof (unfold non_empty_def)
|
12516
|
40 |
assume "\<forall>p t. step p t \<noteq> []"
|
|
41 |
hence "step p t \<noteq> []" by blast
|
|
42 |
then obtain x xs where "step p t = x#xs"
|
11229
|
43 |
by (auto simp add: neq_Nil_conv)
|
12516
|
44 |
hence "x \<in> set(step p t)" by simp
|
|
45 |
thus ?thesis by (cases x) blast
|
11229
|
46 |
qed
|
|
47 |
|
12516
|
48 |
|
11229
|
49 |
lemma dynamic_imp_static:
|
13006
|
50 |
"\<lbrakk> bounded step (size ts); non_empty step;
|
|
51 |
dynamic_wt r (err_step app step) ts \<rbrakk>
|
|
52 |
\<Longrightarrow> static_wt r app step (map ok_val ts)"
|
11229
|
53 |
proof (unfold static_wt_def, intro strip, rule conjI)
|
|
54 |
|
12516
|
55 |
assume b: "bounded step (size ts)"
|
|
56 |
assume n: "non_empty step"
|
|
57 |
assume wt: "dynamic_wt r (err_step app step) ts"
|
11229
|
58 |
|
|
59 |
fix p
|
|
60 |
assume "p < length (map ok_val ts)"
|
|
61 |
hence lp: "p < length ts" by simp
|
|
62 |
|
|
63 |
from wt lp
|
12516
|
64 |
have [intro?]: "\<And>p. p < length ts \<Longrightarrow> ts ! p \<noteq> Err"
|
11299
|
65 |
by (unfold dynamic_wt_def wt_step_def) simp
|
11229
|
66 |
|
|
67 |
show app: "app p (map ok_val ts ! p)"
|
|
68 |
proof -
|
12516
|
69 |
from wt lp
|
|
70 |
obtain s where
|
|
71 |
OKp: "ts ! p = OK s" and
|
|
72 |
less: "\<forall>(q,t) \<in> set (err_step app step p (ts!p)). t <=_(Err.le r) ts!q"
|
|
73 |
by (unfold dynamic_wt_def wt_step_def stable_def)
|
|
74 |
(auto iff: not_Err_eq)
|
|
75 |
|
11229
|
76 |
from n
|
12516
|
77 |
obtain q t where q: "(q,t) \<in> set(step p s)"
|
|
78 |
by (blast dest: non_emptyD)
|
|
79 |
|
|
80 |
from lp b q
|
|
81 |
have lq: "q < length ts" by (unfold bounded_def) blast
|
|
82 |
hence "ts!q \<noteq> Err" ..
|
|
83 |
then obtain s' where OKq: "ts ! q = OK s'" by (auto iff: not_Err_eq)
|
|
84 |
|
|
85 |
with OKp less q have "app p s"
|
|
86 |
by (auto simp add: err_step_defs split: err.split_asm split_if_asm)
|
|
87 |
|
|
88 |
with lp OKp show ?thesis by simp
|
|
89 |
qed
|
|
90 |
|
|
91 |
show "\<forall>(q,t)\<in>set(step p (map ok_val ts ! p)). t <=_r map ok_val ts ! q"
|
|
92 |
proof clarify
|
|
93 |
fix q t assume q: "(q,t) \<in> set (step p (map ok_val ts ! p))"
|
11229
|
94 |
|
|
95 |
from wt lp q
|
|
96 |
obtain s where
|
|
97 |
OKp: "ts ! p = OK s" and
|
12516
|
98 |
less: "\<forall>(q,t) \<in> set (err_step app step p (ts!p)). t <=_(Err.le r) ts!q"
|
11299
|
99 |
by (unfold dynamic_wt_def wt_step_def stable_def)
|
11229
|
100 |
(auto iff: not_Err_eq)
|
|
101 |
|
|
102 |
from lp b q
|
12516
|
103 |
have lq: "q < length ts" by (unfold bounded_def) blast
|
|
104 |
hence "ts!q \<noteq> Err" ..
|
|
105 |
then obtain s' where OKq: "ts ! q = OK s'" by (auto iff: not_Err_eq)
|
11229
|
106 |
|
12516
|
107 |
from lp lq OKp OKq app less q
|
|
108 |
show "t <=_r map ok_val ts ! q"
|
|
109 |
by (auto simp add: err_step_def map_snd_def)
|
11229
|
110 |
qed
|
|
111 |
qed
|
|
112 |
|
|
113 |
|
|
114 |
lemma static_imp_dynamic:
|
13006
|
115 |
"\<lbrakk> static_wt r app step ts; bounded step (size ts) \<rbrakk>
|
|
116 |
\<Longrightarrow> dynamic_wt r (err_step app step) (map OK ts)"
|
11299
|
117 |
proof (unfold dynamic_wt_def wt_step_def, intro strip, rule conjI)
|
12516
|
118 |
assume bounded: "bounded step (size ts)"
|
|
119 |
assume static: "static_wt r app step ts"
|
11229
|
120 |
fix p assume "p < length (map OK ts)"
|
|
121 |
hence p: "p < length ts" by simp
|
|
122 |
thus "map OK ts ! p \<noteq> Err" by simp
|
12516
|
123 |
{ fix q t
|
|
124 |
assume q: "(q,t) \<in> set (err_step app step p (map OK ts ! p))"
|
11229
|
125 |
with p static obtain
|
12516
|
126 |
"app p (ts ! p)" "\<forall>(q,t) \<in> set (step p (ts!p)). t <=_r ts!q"
|
11229
|
127 |
by (unfold static_wt_def) blast
|
|
128 |
moreover
|
12516
|
129 |
from q p bounded have "q < size ts"
|
|
130 |
by (clarsimp simp add: bounded_def err_step_defs
|
|
131 |
split: err.splits split_if_asm) blast+
|
11229
|
132 |
hence "map OK ts ! q = OK (ts!q)" by simp
|
|
133 |
moreover
|
|
134 |
have "p < size ts" by (rule p)
|
12516
|
135 |
moreover note q
|
11229
|
136 |
ultimately
|
12516
|
137 |
have "t <=_(Err.le r) map OK ts ! q"
|
|
138 |
by (auto simp add: err_step_def map_snd_def)
|
11229
|
139 |
}
|
12516
|
140 |
thus "stable (Err.le r) (err_step app step) (map OK ts) p"
|
11229
|
141 |
by (unfold stable_def) blast
|
|
142 |
qed
|
|
143 |
|
|
144 |
end
|