author | haftmann |
Wed, 30 Jan 2008 10:57:44 +0100 | |
changeset 26013 | 8764a1f1253b |
parent 24470 | 41c81e23c08d |
child 27244 | af0a44372d1f |
permissions | -rw-r--r-- |
13857 | 1 |
(* Title: HOL/Hoare/HoareAbort.thy |
2 |
ID: $Id$ |
|
3 |
Author: Leonor Prensa Nieto & Tobias Nipkow |
|
4 |
Copyright 2003 TUM |
|
5 |
||
6 |
Like Hoare.thy, but with an Abort statement for modelling run time errors. |
|
7 |
*) |
|
8 |
||
16417 | 9 |
theory HoareAbort imports Main |
24470
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
10 |
begin |
13857 | 11 |
|
12 |
types |
|
13 |
'a bexp = "'a set" |
|
14 |
'a assn = "'a set" |
|
15 |
||
16 |
datatype |
|
17 |
'a com = Basic "'a \<Rightarrow> 'a" |
|
18 |
| Abort |
|
19 |
| Seq "'a com" "'a com" ("(_;/ _)" [61,60] 60) |
|
20 |
| Cond "'a bexp" "'a com" "'a com" ("(1IF _/ THEN _ / ELSE _/ FI)" [0,0,0] 61) |
|
21 |
| While "'a bexp" "'a assn" "'a com" ("(1WHILE _/ INV {_} //DO _ /OD)" [0,0,0] 61) |
|
22 |
||
23 |
syntax |
|
24 |
"@assign" :: "id => 'b => 'a com" ("(2_ :=/ _)" [70,65] 61) |
|
25 |
"@annskip" :: "'a com" ("SKIP") |
|
26 |
||
27 |
translations |
|
28 |
"SKIP" == "Basic id" |
|
29 |
||
30 |
types 'a sem = "'a option => 'a option => bool" |
|
31 |
||
32 |
consts iter :: "nat => 'a bexp => 'a sem => 'a sem" |
|
33 |
primrec |
|
13875 | 34 |
"iter 0 b S = (\<lambda>s s'. s \<notin> Some ` b \<and> s=s')" |
35 |
"iter (Suc n) b S = |
|
36 |
(\<lambda>s s'. s \<in> Some ` b \<and> (\<exists>s''. S s s'' \<and> iter n b S s'' s'))" |
|
13857 | 37 |
|
38 |
consts Sem :: "'a com => 'a sem" |
|
39 |
primrec |
|
40 |
"Sem(Basic f) s s' = (case s of None \<Rightarrow> s' = None | Some t \<Rightarrow> s' = Some(f t))" |
|
41 |
"Sem Abort s s' = (s' = None)" |
|
13875 | 42 |
"Sem(c1;c2) s s' = (\<exists>s''. Sem c1 s s'' \<and> Sem c2 s'' s')" |
13857 | 43 |
"Sem(IF b THEN c1 ELSE c2 FI) s s' = |
44 |
(case s of None \<Rightarrow> s' = None |
|
13875 | 45 |
| Some t \<Rightarrow> ((t \<in> b \<longrightarrow> Sem c1 s s') \<and> (t \<notin> b \<longrightarrow> Sem c2 s s')))" |
13857 | 46 |
"Sem(While b x c) s s' = |
13875 | 47 |
(if s = None then s' = None else \<exists>n. iter n b (Sem c) s s')" |
13857 | 48 |
|
49 |
constdefs Valid :: "'a bexp \<Rightarrow> 'a com \<Rightarrow> 'a bexp \<Rightarrow> bool" |
|
50 |
"Valid p c q == \<forall>s s'. Sem c s s' \<longrightarrow> s : Some ` p \<longrightarrow> s' : Some ` q" |
|
51 |
||
52 |
||
53 |
syntax |
|
54 |
"@hoare_vars" :: "[idts, 'a assn,'a com,'a assn] => bool" |
|
55 |
("VARS _// {_} // _ // {_}" [0,0,55,0] 50) |
|
56 |
syntax ("" output) |
|
57 |
"@hoare" :: "['a assn,'a com,'a assn] => bool" |
|
58 |
("{_} // _ // {_}" [0,55,0] 50) |
|
59 |
||
60 |
(** parse translations **) |
|
61 |
||
62 |
ML{* |
|
63 |
||
64 |
local |
|
65 |
fun free a = Free(a,dummyT) |
|
66 |
fun abs((a,T),body) = |
|
67 |
let val a = absfree(a, dummyT, body) |
|
68 |
in if T = Bound 0 then a else Const(Syntax.constrainAbsC,dummyT) $ a $ T end |
|
69 |
in |
|
70 |
||
71 |
fun mk_abstuple [x] body = abs (x, body) |
|
72 |
| mk_abstuple (x::xs) body = |
|
73 |
Syntax.const "split" $ abs (x, mk_abstuple xs body); |
|
74 |
||
75 |
fun mk_fbody a e [x as (b,_)] = if a=b then e else free b |
|
76 |
| mk_fbody a e ((b,_)::xs) = |
|
77 |
Syntax.const "Pair" $ (if a=b then e else free b) $ mk_fbody a e xs; |
|
78 |
||
79 |
fun mk_fexp a e xs = mk_abstuple xs (mk_fbody a e xs) |
|
80 |
end |
|
81 |
*} |
|
82 |
||
83 |
(* bexp_tr & assn_tr *) |
|
84 |
(*all meta-variables for bexp except for TRUE are translated as if they |
|
85 |
were boolean expressions*) |
|
86 |
ML{* |
|
87 |
fun bexp_tr (Const ("TRUE", _)) xs = Syntax.const "TRUE" |
|
88 |
| bexp_tr b xs = Syntax.const "Collect" $ mk_abstuple xs b; |
|
89 |
||
90 |
fun assn_tr r xs = Syntax.const "Collect" $ mk_abstuple xs r; |
|
91 |
*} |
|
92 |
(* com_tr *) |
|
93 |
ML{* |
|
94 |
fun com_tr (Const("@assign",_) $ Free (a,_) $ e) xs = |
|
95 |
Syntax.const "Basic" $ mk_fexp a e xs |
|
96 |
| com_tr (Const ("Basic",_) $ f) xs = Syntax.const "Basic" $ f |
|
97 |
| com_tr (Const ("Seq",_) $ c1 $ c2) xs = |
|
98 |
Syntax.const "Seq" $ com_tr c1 xs $ com_tr c2 xs |
|
99 |
| com_tr (Const ("Cond",_) $ b $ c1 $ c2) xs = |
|
100 |
Syntax.const "Cond" $ bexp_tr b xs $ com_tr c1 xs $ com_tr c2 xs |
|
101 |
| com_tr (Const ("While",_) $ b $ I $ c) xs = |
|
102 |
Syntax.const "While" $ bexp_tr b xs $ assn_tr I xs $ com_tr c xs |
|
103 |
| com_tr t _ = t (* if t is just a Free/Var *) |
|
104 |
*} |
|
105 |
||
17781 | 106 |
(* triple_tr *) (* FIXME does not handle "_idtdummy" *) |
13857 | 107 |
ML{* |
108 |
local |
|
109 |
||
110 |
fun var_tr(Free(a,_)) = (a,Bound 0) (* Bound 0 = dummy term *) |
|
111 |
| var_tr(Const ("_constrain", _) $ (Free (a,_)) $ T) = (a,T); |
|
112 |
||
113 |
fun vars_tr (Const ("_idts", _) $ idt $ vars) = var_tr idt :: vars_tr vars |
|
114 |
| vars_tr t = [var_tr t] |
|
115 |
||
116 |
in |
|
117 |
fun hoare_vars_tr [vars, pre, prg, post] = |
|
118 |
let val xs = vars_tr vars |
|
119 |
in Syntax.const "Valid" $ |
|
120 |
assn_tr pre xs $ com_tr prg xs $ assn_tr post xs |
|
121 |
end |
|
122 |
| hoare_vars_tr ts = raise TERM ("hoare_vars_tr", ts); |
|
123 |
end |
|
124 |
*} |
|
125 |
||
126 |
parse_translation {* [("@hoare_vars", hoare_vars_tr)] *} |
|
127 |
||
128 |
||
129 |
(*****************************************************************************) |
|
130 |
||
131 |
(*** print translations ***) |
|
132 |
ML{* |
|
133 |
fun dest_abstuple (Const ("split",_) $ (Abs(v,_, body))) = |
|
134 |
subst_bound (Syntax.free v, dest_abstuple body) |
|
135 |
| dest_abstuple (Abs(v,_, body)) = subst_bound (Syntax.free v, body) |
|
136 |
| dest_abstuple trm = trm; |
|
137 |
||
138 |
fun abs2list (Const ("split",_) $ (Abs(x,T,t))) = Free (x, T)::abs2list t |
|
139 |
| abs2list (Abs(x,T,t)) = [Free (x, T)] |
|
140 |
| abs2list _ = []; |
|
141 |
||
142 |
fun mk_ts (Const ("split",_) $ (Abs(x,_,t))) = mk_ts t |
|
143 |
| mk_ts (Abs(x,_,t)) = mk_ts t |
|
144 |
| mk_ts (Const ("Pair",_) $ a $ b) = a::(mk_ts b) |
|
145 |
| mk_ts t = [t]; |
|
146 |
||
147 |
fun mk_vts (Const ("split",_) $ (Abs(x,_,t))) = |
|
148 |
((Syntax.free x)::(abs2list t), mk_ts t) |
|
149 |
| mk_vts (Abs(x,_,t)) = ([Syntax.free x], [t]) |
|
150 |
| mk_vts t = raise Match; |
|
151 |
||
152 |
fun find_ch [] i xs = (false, (Syntax.free "not_ch",Syntax.free "not_ch" )) |
|
153 |
| find_ch ((v,t)::vts) i xs = if t=(Bound i) then find_ch vts (i-1) xs |
|
154 |
else (true, (v, subst_bounds (xs,t))); |
|
155 |
||
156 |
fun is_f (Const ("split",_) $ (Abs(x,_,t))) = true |
|
157 |
| is_f (Abs(x,_,t)) = true |
|
158 |
| is_f t = false; |
|
159 |
*} |
|
160 |
||
161 |
(* assn_tr' & bexp_tr'*) |
|
162 |
ML{* |
|
163 |
fun assn_tr' (Const ("Collect",_) $ T) = dest_abstuple T |
|
164 |
| assn_tr' (Const ("op Int",_) $ (Const ("Collect",_) $ T1) $ |
|
165 |
(Const ("Collect",_) $ T2)) = |
|
166 |
Syntax.const "op Int" $ dest_abstuple T1 $ dest_abstuple T2 |
|
167 |
| assn_tr' t = t; |
|
168 |
||
169 |
fun bexp_tr' (Const ("Collect",_) $ T) = dest_abstuple T |
|
170 |
| bexp_tr' t = t; |
|
171 |
*} |
|
172 |
||
173 |
(*com_tr' *) |
|
174 |
ML{* |
|
175 |
fun mk_assign f = |
|
176 |
let val (vs, ts) = mk_vts f; |
|
177 |
val (ch, which) = find_ch (vs~~ts) ((length vs)-1) (rev vs) |
|
178 |
in if ch then Syntax.const "@assign" $ fst(which) $ snd(which) |
|
179 |
else Syntax.const "@skip" end; |
|
180 |
||
181 |
fun com_tr' (Const ("Basic",_) $ f) = if is_f f then mk_assign f |
|
182 |
else Syntax.const "Basic" $ f |
|
183 |
| com_tr' (Const ("Seq",_) $ c1 $ c2) = Syntax.const "Seq" $ |
|
184 |
com_tr' c1 $ com_tr' c2 |
|
185 |
| com_tr' (Const ("Cond",_) $ b $ c1 $ c2) = Syntax.const "Cond" $ |
|
186 |
bexp_tr' b $ com_tr' c1 $ com_tr' c2 |
|
187 |
| com_tr' (Const ("While",_) $ b $ I $ c) = Syntax.const "While" $ |
|
188 |
bexp_tr' b $ assn_tr' I $ com_tr' c |
|
189 |
| com_tr' t = t; |
|
190 |
||
191 |
||
192 |
fun spec_tr' [p, c, q] = |
|
193 |
Syntax.const "@hoare" $ assn_tr' p $ com_tr' c $ assn_tr' q |
|
194 |
*} |
|
195 |
||
196 |
print_translation {* [("Valid", spec_tr')] *} |
|
197 |
||
198 |
(*** The proof rules ***) |
|
199 |
||
200 |
lemma SkipRule: "p \<subseteq> q \<Longrightarrow> Valid p (Basic id) q" |
|
201 |
by (auto simp:Valid_def) |
|
202 |
||
203 |
lemma BasicRule: "p \<subseteq> {s. f s \<in> q} \<Longrightarrow> Valid p (Basic f) q" |
|
204 |
by (auto simp:Valid_def) |
|
205 |
||
206 |
lemma SeqRule: "Valid P c1 Q \<Longrightarrow> Valid Q c2 R \<Longrightarrow> Valid P (c1;c2) R" |
|
207 |
by (auto simp:Valid_def) |
|
208 |
||
209 |
lemma CondRule: |
|
210 |
"p \<subseteq> {s. (s \<in> b \<longrightarrow> s \<in> w) \<and> (s \<notin> b \<longrightarrow> s \<in> w')} |
|
211 |
\<Longrightarrow> Valid w c1 q \<Longrightarrow> Valid w' c2 q \<Longrightarrow> Valid p (Cond b c1 c2) q" |
|
212 |
by (fastsimp simp:Valid_def image_def) |
|
213 |
||
13875 | 214 |
lemma iter_aux: |
215 |
"! s s'. Sem c s s' \<longrightarrow> s \<in> Some ` (I \<inter> b) \<longrightarrow> s' \<in> Some ` I \<Longrightarrow> |
|
216 |
(\<And>s s'. s \<in> Some ` I \<Longrightarrow> iter n b (Sem c) s s' \<Longrightarrow> s' \<in> Some ` (I \<inter> -b))"; |
|
13857 | 217 |
apply(unfold image_def) |
218 |
apply(induct n) |
|
219 |
apply clarsimp |
|
220 |
apply(simp (no_asm_use)) |
|
221 |
apply blast |
|
222 |
done |
|
223 |
||
224 |
lemma WhileRule: |
|
225 |
"p \<subseteq> i \<Longrightarrow> Valid (i \<inter> b) c i \<Longrightarrow> i \<inter> (-b) \<subseteq> q \<Longrightarrow> Valid p (While b i c) q" |
|
226 |
apply(simp add:Valid_def) |
|
227 |
apply(simp (no_asm) add:image_def) |
|
228 |
apply clarify |
|
229 |
apply(drule iter_aux) |
|
230 |
prefer 2 apply assumption |
|
231 |
apply blast |
|
232 |
apply blast |
|
233 |
done |
|
234 |
||
235 |
lemma AbortRule: "p \<subseteq> {s. False} \<Longrightarrow> Valid p Abort q" |
|
236 |
by(auto simp:Valid_def) |
|
237 |
||
24470
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
238 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
239 |
subsection {* Derivation of the proof rules and, most importantly, the VCG tactic *} |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
240 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
241 |
ML {* |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
242 |
(*** The tactics ***) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
243 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
244 |
(*****************************************************************************) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
245 |
(** The function Mset makes the theorem **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
246 |
(** "?Mset <= {(x1,...,xn). ?P (x1,...,xn)} ==> ?Mset <= {s. ?P s}", **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
247 |
(** where (x1,...,xn) are the variables of the particular program we are **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
248 |
(** working on at the moment of the call **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
249 |
(*****************************************************************************) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
250 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
251 |
local open HOLogic in |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
252 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
253 |
(** maps (%x1 ... xn. t) to [x1,...,xn] **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
254 |
fun abs2list (Const ("split",_) $ (Abs(x,T,t))) = Free (x, T)::abs2list t |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
255 |
| abs2list (Abs(x,T,t)) = [Free (x, T)] |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
256 |
| abs2list _ = []; |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
257 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
258 |
(** maps {(x1,...,xn). t} to [x1,...,xn] **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
259 |
fun mk_vars (Const ("Collect",_) $ T) = abs2list T |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
260 |
| mk_vars _ = []; |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
261 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
262 |
(** abstraction of body over a tuple formed from a list of free variables. |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
263 |
Types are also built **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
264 |
fun mk_abstupleC [] body = absfree ("x", unitT, body) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
265 |
| mk_abstupleC (v::w) body = let val (n,T) = dest_Free v |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
266 |
in if w=[] then absfree (n, T, body) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
267 |
else let val z = mk_abstupleC w body; |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
268 |
val T2 = case z of Abs(_,T,_) => T |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
269 |
| Const (_, Type (_,[_, Type (_,[T,_])])) $ _ => T; |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
270 |
in Const ("split", (T --> T2 --> boolT) --> mk_prodT (T,T2) --> boolT) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
271 |
$ absfree (n, T, z) end end; |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
272 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
273 |
(** maps [x1,...,xn] to (x1,...,xn) and types**) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
274 |
fun mk_bodyC [] = HOLogic.unit |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
275 |
| mk_bodyC (x::xs) = if xs=[] then x |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
276 |
else let val (n, T) = dest_Free x ; |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
277 |
val z = mk_bodyC xs; |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
278 |
val T2 = case z of Free(_, T) => T |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
279 |
| Const ("Pair", Type ("fun", [_, Type |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
280 |
("fun", [_, T])])) $ _ $ _ => T; |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
281 |
in Const ("Pair", [T, T2] ---> mk_prodT (T, T2)) $ x $ z end; |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
282 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
283 |
(** maps a goal of the form: |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
284 |
1. [| P |] ==> VARS x1 ... xn {._.} _ {._.} or to [x1,...,xn]**) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
285 |
fun get_vars thm = let val c = Logic.unprotect (concl_of (thm)); |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
286 |
val d = Logic.strip_assums_concl c; |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
287 |
val Const _ $ pre $ _ $ _ = dest_Trueprop d; |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
288 |
in mk_vars pre end; |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
289 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
290 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
291 |
(** Makes Collect with type **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
292 |
fun mk_CollectC trm = let val T as Type ("fun",[t,_]) = fastype_of trm |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
293 |
in Collect_const t $ trm end; |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
294 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
295 |
fun inclt ty = Const (@{const_name HOL.less_eq}, [ty,ty] ---> boolT); |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
296 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
297 |
(** Makes "Mset <= t" **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
298 |
fun Mset_incl t = let val MsetT = fastype_of t |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
299 |
in mk_Trueprop ((inclt MsetT) $ Free ("Mset", MsetT) $ t) end; |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
300 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
301 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
302 |
fun Mset thm = let val vars = get_vars(thm); |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
303 |
val varsT = fastype_of (mk_bodyC vars); |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
304 |
val big_Collect = mk_CollectC (mk_abstupleC vars |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
305 |
(Free ("P",varsT --> boolT) $ mk_bodyC vars)); |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
306 |
val small_Collect = mk_CollectC (Abs("x",varsT, |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
307 |
Free ("P",varsT --> boolT) $ Bound 0)); |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
308 |
val impl = implies $ (Mset_incl big_Collect) $ |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
309 |
(Mset_incl small_Collect); |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
310 |
in Goal.prove (ProofContext.init (Thm.theory_of_thm thm)) ["Mset", "P"] [] impl (K (CLASET' blast_tac 1)) end; |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
311 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
312 |
end; |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
313 |
*} |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
314 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
315 |
(*****************************************************************************) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
316 |
(** Simplifying: **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
317 |
(** Some useful lemmata, lists and simplification tactics to control which **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
318 |
(** theorems are used to simplify at each moment, so that the original **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
319 |
(** input does not suffer any unexpected transformation **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
320 |
(*****************************************************************************) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
321 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
322 |
lemma Compl_Collect: "-(Collect b) = {x. ~(b x)}" |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
323 |
by blast |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
324 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
325 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
326 |
ML {* |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
327 |
(**Simp_tacs**) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
328 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
329 |
val before_set2pred_simp_tac = |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
330 |
(simp_tac (HOL_basic_ss addsimps [@{thm Collect_conj_eq} RS sym, @{thm Compl_Collect}])); |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
331 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
332 |
val split_simp_tac = (simp_tac (HOL_basic_ss addsimps [split_conv])); |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
333 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
334 |
(*****************************************************************************) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
335 |
(** set2pred transforms sets inclusion into predicates implication, **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
336 |
(** maintaining the original variable names. **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
337 |
(** Ex. "{x. x=0} <= {x. x <= 1}" -set2pred-> "x=0 --> x <= 1" **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
338 |
(** Subgoals containing intersections (A Int B) or complement sets (-A) **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
339 |
(** are first simplified by "before_set2pred_simp_tac", that returns only **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
340 |
(** subgoals of the form "{x. P x} <= {x. Q x}", which are easily **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
341 |
(** transformed. **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
342 |
(** This transformation may solve very easy subgoals due to a ligth **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
343 |
(** simplification done by (split_all_tac) **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
344 |
(*****************************************************************************) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
345 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
346 |
fun set2pred i thm = |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
347 |
let val var_names = map (fst o dest_Free) (get_vars thm) in |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
348 |
((before_set2pred_simp_tac i) THEN_MAYBE |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
349 |
(EVERY [rtac subsetI i, |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
350 |
rtac CollectI i, |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
351 |
dtac CollectD i, |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
352 |
(TRY(split_all_tac i)) THEN_MAYBE |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
353 |
((rename_params_tac var_names i) THEN |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
354 |
(full_simp_tac (HOL_basic_ss addsimps [split_conv]) i)) ])) thm |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
355 |
end; |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
356 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
357 |
(*****************************************************************************) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
358 |
(** BasicSimpTac is called to simplify all verification conditions. It does **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
359 |
(** a light simplification by applying "mem_Collect_eq", then it calls **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
360 |
(** MaxSimpTac, which solves subgoals of the form "A <= A", **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
361 |
(** and transforms any other into predicates, applying then **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
362 |
(** the tactic chosen by the user, which may solve the subgoal completely. **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
363 |
(*****************************************************************************) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
364 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
365 |
fun MaxSimpTac tac = FIRST'[rtac subset_refl, set2pred THEN_MAYBE' tac]; |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
366 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
367 |
fun BasicSimpTac tac = |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
368 |
simp_tac |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
369 |
(HOL_basic_ss addsimps [mem_Collect_eq,split_conv] addsimprocs [record_simproc]) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
370 |
THEN_MAYBE' MaxSimpTac tac; |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
371 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
372 |
(** HoareRuleTac **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
373 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
374 |
fun WlpTac Mlem tac i = |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
375 |
rtac @{thm SeqRule} i THEN HoareRuleTac Mlem tac false (i+1) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
376 |
and HoareRuleTac Mlem tac pre_cond i st = st |> |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
377 |
(*abstraction over st prevents looping*) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
378 |
( (WlpTac Mlem tac i THEN HoareRuleTac Mlem tac pre_cond i) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
379 |
ORELSE |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
380 |
(FIRST[rtac @{thm SkipRule} i, |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
381 |
rtac @{thm AbortRule} i, |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
382 |
EVERY[rtac @{thm BasicRule} i, |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
383 |
rtac Mlem i, |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
384 |
split_simp_tac i], |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
385 |
EVERY[rtac @{thm CondRule} i, |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
386 |
HoareRuleTac Mlem tac false (i+2), |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
387 |
HoareRuleTac Mlem tac false (i+1)], |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
388 |
EVERY[rtac @{thm WhileRule} i, |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
389 |
BasicSimpTac tac (i+2), |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
390 |
HoareRuleTac Mlem tac true (i+1)] ] |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
391 |
THEN (if pre_cond then (BasicSimpTac tac i) else rtac subset_refl i) )); |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
392 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
393 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
394 |
(** tac:(int -> tactic) is the tactic the user chooses to solve or simplify **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
395 |
(** the final verification conditions **) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
396 |
|
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
397 |
fun hoare_tac tac i thm = |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
398 |
let val Mlem = Mset(thm) |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
399 |
in SELECT_GOAL(EVERY[HoareRuleTac Mlem tac true 1]) i thm end; |
41c81e23c08d
removed Hoare/hoare.ML, Hoare/hoareAbort.ML, ex/svc_oracle.ML (which can be mistaken as attached ML script on case-insensitive file-system);
wenzelm
parents:
21588
diff
changeset
|
400 |
*} |
13857 | 401 |
|
402 |
method_setup vcg = {* |
|
21588 | 403 |
Method.no_args (Method.SIMPLE_METHOD' (hoare_tac (K all_tac))) *} |
13857 | 404 |
"verification condition generator" |
405 |
||
406 |
method_setup vcg_simp = {* |
|
407 |
Method.ctxt_args (fn ctxt => |
|
21588 | 408 |
Method.SIMPLE_METHOD' (hoare_tac (asm_full_simp_tac (local_simpset_of ctxt)))) *} |
13857 | 409 |
"verification condition generator plus simplification" |
410 |
||
13875 | 411 |
(* Special syntax for guarded statements and guarded array updates: *) |
412 |
||
413 |
syntax |
|
414 |
guarded_com :: "bool \<Rightarrow> 'a com \<Rightarrow> 'a com" ("(2_ \<rightarrow>/ _)" 71) |
|
415 |
array_update :: "'a list \<Rightarrow> nat \<Rightarrow> 'a \<Rightarrow> 'a com" ("(2_[_] :=/ _)" [70,65] 61) |
|
416 |
translations |
|
417 |
"P \<rightarrow> c" == "IF P THEN c ELSE Abort FI" |
|
20770 | 418 |
"a[i] := v" => "(i < CONST length a) \<rightarrow> (a := list_update a i v)" |
13875 | 419 |
(* reverse translation not possible because of duplicate "a" *) |
420 |
||
421 |
text{* Note: there is no special syntax for guarded array access. Thus |
|
422 |
you must write @{text"j < length a \<rightarrow> a[i] := a!j"}. *} |
|
423 |
||
13857 | 424 |
end |