author | schirmer |
Fri, 22 Feb 2002 11:26:44 +0100 | |
changeset 12925 | 99131847fb93 |
parent 12859 | f63315dfffd4 |
child 13688 | a0b16d42d489 |
permissions | -rw-r--r-- |
12857 | 1 |
(* Title: HOL/Bali/AxExample.thy |
12854 | 2 |
ID: $Id$ |
3 |
Author: David von Oheimb |
|
12859 | 4 |
License: GPL (GNU GENERAL PUBLIC LICENSE) |
12854 | 5 |
*) |
12925
99131847fb93
Added check for field/method access to operational semantics and proved the acesses valid.
schirmer
parents:
12859
diff
changeset
|
6 |
|
12854 | 7 |
header {* Example of a proof based on the Bali axiomatic semantics *} |
8 |
||
9 |
theory AxExample = AxSem + Example: |
|
10 |
||
11 |
constdefs |
|
12 |
arr_inv :: "st \<Rightarrow> bool" |
|
13 |
"arr_inv \<equiv> \<lambda>s. \<exists>obj a T el. globs s (Stat Base) = Some obj \<and> |
|
14 |
values obj (Inl (arr, Base)) = Some (Addr a) \<and> |
|
15 |
heap s a = Some \<lparr>tag=Arr T 2,values=el\<rparr>" |
|
16 |
||
17 |
lemma arr_inv_new_obj: |
|
18 |
"\<And>a. \<lbrakk>arr_inv s; new_Addr (heap s)=Some a\<rbrakk> \<Longrightarrow> arr_inv (gupd(Inl a\<mapsto>x) s)" |
|
19 |
apply (unfold arr_inv_def) |
|
20 |
apply (force dest!: new_AddrD2) |
|
21 |
done |
|
22 |
||
23 |
lemma arr_inv_set_locals [simp]: "arr_inv (set_locals l s) = arr_inv s" |
|
24 |
apply (unfold arr_inv_def) |
|
25 |
apply (simp (no_asm)) |
|
26 |
done |
|
27 |
||
28 |
lemma arr_inv_gupd_Stat [simp]: |
|
29 |
"Base \<noteq> C \<Longrightarrow> arr_inv (gupd(Stat C\<mapsto>obj) s) = arr_inv s" |
|
30 |
apply (unfold arr_inv_def) |
|
31 |
apply (simp (no_asm_simp)) |
|
32 |
done |
|
33 |
||
34 |
lemma ax_inv_lupd [simp]: "arr_inv (lupd(x\<mapsto>y) s) = arr_inv s" |
|
35 |
apply (unfold arr_inv_def) |
|
36 |
apply (simp (no_asm)) |
|
37 |
done |
|
38 |
||
39 |
||
40 |
declare split_if_asm [split del] |
|
41 |
declare lvar_def [simp] |
|
42 |
||
43 |
ML {* |
|
44 |
fun inst1_tac s t = instantiate_tac [(s,t)]; |
|
45 |
val ax_tac = REPEAT o rtac allI THEN' |
|
46 |
resolve_tac(thm "ax_Skip"::thm "ax_StatRef"::thm "ax_MethdN":: |
|
47 |
thm "ax_Alloc"::thm "ax_Alloc_Arr":: |
|
48 |
thm "ax_SXAlloc_Normal":: |
|
49 |
funpow 7 tl (thms "ax_derivs.intros")) |
|
50 |
*} |
|
51 |
||
52 |
||
53 |
theorem ax_test: "tprg,({}::'a triple set)\<turnstile> |
|
54 |
{Normal (\<lambda>Y s Z::'a. heap_free four s \<and> \<not>initd Base s \<and> \<not> initd Ext s)} |
|
55 |
.test [Class Base]. {\<lambda>Y s Z. abrupt s = Some (Xcpt (Std IndOutBound))}" |
|
56 |
apply (unfold test_def arr_viewed_from_def) |
|
57 |
apply (tactic "ax_tac 1" (*;;*)) |
|
58 |
defer |
|
59 |
apply (tactic "ax_tac 1" (* Try *)) |
|
60 |
defer |
|
61 |
apply (tactic {* inst1_tac "Q1" |
|
62 |
"\<lambda>Y s Z. arr_inv (snd s) \<and> tprg,s\<turnstile>catch SXcpt NullPointer" *}) |
|
63 |
prefer 2 |
|
64 |
apply simp |
|
65 |
apply (rule_tac P' = "Normal (\<lambda>Y s Z. arr_inv (snd s))" in conseq1) |
|
66 |
prefer 2 |
|
67 |
apply clarsimp |
|
68 |
apply (rule_tac Q' = "(\<lambda>Y s Z. ?Q Y s Z)\<leftarrow>=False\<down>=\<diamondsuit>" in conseq2) |
|
69 |
prefer 2 |
|
70 |
apply simp |
|
71 |
apply (tactic "ax_tac 1" (* While *)) |
|
72 |
prefer 2 |
|
73 |
apply (rule ax_impossible [THEN conseq1], clarsimp) |
|
74 |
apply (rule_tac P' = "Normal ?P" in conseq1) |
|
75 |
prefer 2 |
|
76 |
apply clarsimp |
|
77 |
apply (tactic "ax_tac 1") |
|
78 |
apply (tactic "ax_tac 1" (* AVar *)) |
|
79 |
prefer 2 |
|
80 |
apply (rule ax_subst_Val_allI) |
|
81 |
apply (tactic {* inst1_tac "P'21" "\<lambda>u a. Normal (?PP a\<leftarrow>?x) u" *}) |
|
82 |
apply (simp del: avar_def2 peek_and_def2) |
|
83 |
apply (tactic "ax_tac 1") |
|
84 |
apply (tactic "ax_tac 1") |
|
85 |
(* just for clarification: *) |
|
86 |
apply (rule_tac Q' = "Normal (\<lambda>Var:(v, f) u ua. fst (snd (avar tprg (Intg 2) v u)) = Some (Xcpt (Std IndOutBound)))" in conseq2) |
|
87 |
prefer 2 |
|
88 |
apply (clarsimp simp add: split_beta) |
|
89 |
apply (tactic "ax_tac 1" (* FVar *)) |
|
90 |
apply (tactic "ax_tac 2" (* StatRef *)) |
|
91 |
apply (rule ax_derivs.Done [THEN conseq1]) |
|
92 |
apply (clarsimp simp add: arr_inv_def inited_def in_bounds_def) |
|
93 |
defer |
|
94 |
apply (rule ax_SXAlloc_catch_SXcpt) |
|
95 |
apply (rule_tac Q' = "(\<lambda>Y (x, s) Z. x = Some (Xcpt (Std NullPointer)) \<and> arr_inv s) \<and>. heap_free two" in conseq2) |
|
96 |
prefer 2 |
|
97 |
apply (simp add: arr_inv_new_obj) |
|
98 |
apply (tactic "ax_tac 1") |
|
99 |
apply (rule_tac C = "Ext" in ax_Call_known_DynT) |
|
100 |
apply (unfold DynT_prop_def) |
|
101 |
apply (simp (no_asm)) |
|
102 |
apply (intro strip) |
|
103 |
apply (rule_tac P' = "Normal ?P" in conseq1) |
|
104 |
apply (tactic "ax_tac 1" (* Methd *)) |
|
105 |
apply (rule ax_thin [OF _ empty_subsetI]) |
|
106 |
apply (simp (no_asm) add: body_def2) |
|
107 |
apply (tactic "ax_tac 1" (* Body *)) |
|
108 |
(* apply (rule_tac [2] ax_derivs.Abrupt) *) |
|
109 |
defer |
|
110 |
apply (simp (no_asm)) |
|
111 |
apply (tactic "ax_tac 1") |
|
112 |
apply (tactic "ax_tac 1") (* Ass *) |
|
113 |
prefer 2 |
|
114 |
apply (rule ax_subst_Var_allI) |
|
115 |
apply (tactic {* inst1_tac "P'27" "\<lambda>a vs l vf. ?PP a vs l vf\<leftarrow>?x \<and>. ?p" *}) |
|
116 |
apply (rule allI) |
|
117 |
apply (tactic {* simp_tac (simpset() delloop "split_all_tac" delsimps [thm "peek_and_def2"]) 1 *}) |
|
118 |
apply (rule ax_derivs.Abrupt) |
|
119 |
apply (simp (no_asm)) |
|
120 |
apply (tactic "ax_tac 1" (* FVar *)) |
|
121 |
apply (tactic "ax_tac 2", tactic "ax_tac 2", tactic "ax_tac 2") |
|
122 |
apply (tactic "ax_tac 1") |
|
123 |
apply clarsimp |
|
124 |
apply (tactic {* inst1_tac "R14" "\<lambda>a'. Normal ((\<lambda>Vals:vs (x, s) Z. arr_inv s \<and> inited Ext (globs s) \<and> a' \<noteq> Null \<and> hd vs = Null) \<and>. heap_free two)" *}) |
|
125 |
prefer 5 |
|
126 |
apply (rule ax_derivs.Done [THEN conseq1], force) |
|
127 |
apply force |
|
128 |
apply (rule ax_subst_Val_allI) |
|
129 |
apply (tactic {* inst1_tac "P'33" "\<lambda>u a. Normal (?PP a\<leftarrow>?x) u" *}) |
|
130 |
apply (simp (no_asm) del: peek_and_def2) |
|
131 |
apply (tactic "ax_tac 1") |
|
132 |
prefer 2 |
|
133 |
apply (rule ax_subst_Val_allI) |
|
134 |
apply (tactic {* inst1_tac "P'4" "\<lambda>aa v. Normal (?QQ aa v\<leftarrow>?y)" *}) |
|
135 |
apply (simp del: peek_and_def2) |
|
136 |
apply (tactic "ax_tac 1") |
|
137 |
apply (tactic "ax_tac 1") |
|
138 |
apply (tactic "ax_tac 1") |
|
139 |
apply (tactic "ax_tac 1") |
|
140 |
(* end method call *) |
|
141 |
apply (simp (no_asm)) |
|
142 |
(* just for clarification: *) |
|
143 |
apply (rule_tac Q' = "Normal ((\<lambda>Y (x, s) Z. arr_inv s \<and> (\<exists>a. the (locals s (VName e)) = Addr a \<and> obj_class (the (globs s (Inl a))) = Ext \<and> |
|
144 |
invocation_declclass tprg IntVir s (the (locals s (VName e))) (ClassT Base) |
|
145 |
\<lparr>name = foo, parTs = [Class Base]\<rparr> = Ext)) \<and>. initd Ext \<and>. heap_free two)" |
|
146 |
in conseq2) |
|
147 |
prefer 2 |
|
148 |
apply clarsimp |
|
149 |
apply (tactic "ax_tac 1") |
|
150 |
apply (tactic "ax_tac 1") |
|
151 |
defer |
|
152 |
apply (rule ax_subst_Var_allI) |
|
153 |
apply (tactic {* inst1_tac "P'14" "\<lambda>u vf. Normal (?PP vf \<and>. ?p) u" *}) |
|
154 |
apply (simp (no_asm) del: split_paired_All peek_and_def2) |
|
155 |
apply (tactic "ax_tac 1" (* NewC *)) |
|
156 |
apply (tactic "ax_tac 1" (* ax_Alloc *)) |
|
157 |
(* just for clarification: *) |
|
158 |
apply (rule_tac Q' = "Normal ((\<lambda>Y s Z. arr_inv (store s) \<and> vf=lvar (VName e) (store s)) \<and>. heap_free tree \<and>. initd Ext)" in conseq2) |
|
159 |
prefer 2 |
|
160 |
apply (simp add: invocation_declclass_def dynmethd_def) |
|
161 |
apply (unfold dynlookup_def) |
|
162 |
apply (simp add: dynmethd_Ext_foo) |
|
163 |
apply (force elim!: arr_inv_new_obj atleast_free_SucD atleast_free_weaken) |
|
164 |
(* begin init *) |
|
165 |
apply (rule ax_InitS) |
|
166 |
apply force |
|
167 |
apply (simp (no_asm)) |
|
168 |
apply (tactic {* simp_tac (simpset() delloop "split_all_tac") 1 *}) |
|
169 |
apply (rule ax_Init_Skip_lemma) |
|
170 |
apply (tactic {* simp_tac (simpset() delloop "split_all_tac") 1 *}) |
|
171 |
apply (rule ax_InitS [THEN conseq1] (* init Base *)) |
|
172 |
apply force |
|
173 |
apply (simp (no_asm)) |
|
174 |
apply (unfold arr_viewed_from_def) |
|
175 |
apply (rule allI) |
|
176 |
apply (rule_tac P' = "Normal ?P" in conseq1) |
|
177 |
apply (tactic {* simp_tac (simpset() delloop "split_all_tac") 1 *}) |
|
178 |
apply (tactic "ax_tac 1") |
|
179 |
apply (tactic "ax_tac 1") |
|
180 |
apply (rule_tac [2] ax_subst_Var_allI) |
|
181 |
apply (tactic {* inst1_tac "P'29" "\<lambda>vf l vfa. Normal (?P vf l vfa)" *}) |
|
182 |
apply (tactic {* simp_tac (simpset() delloop "split_all_tac" delsimps [split_paired_All, thm "peek_and_def2"]) 2 *}) |
|
183 |
apply (tactic "ax_tac 2" (* NewA *)) |
|
184 |
apply (tactic "ax_tac 3" (* ax_Alloc_Arr *)) |
|
185 |
apply (tactic "ax_tac 3") |
|
186 |
apply (tactic {* inst1_tac "P" "\<lambda>vf l vfa. Normal (?P vf l vfa\<leftarrow>\<diamondsuit>)" *}) |
|
187 |
apply (tactic {* simp_tac (simpset() delloop "split_all_tac") 2 *}) |
|
188 |
apply (tactic "ax_tac 2") |
|
189 |
apply (tactic "ax_tac 1" (* FVar *)) |
|
190 |
apply (tactic "ax_tac 2" (* StatRef *)) |
|
191 |
apply (rule ax_derivs.Done [THEN conseq1]) |
|
192 |
apply (tactic {* inst1_tac "Q22" "\<lambda>vf. Normal ((\<lambda>Y s Z. vf=lvar (VName e) (snd s)) \<and>. heap_free four \<and>. initd Base \<and>. initd Ext)" *}) |
|
193 |
apply (clarsimp split del: split_if) |
|
194 |
apply (frule atleast_free_weaken [THEN atleast_free_weaken]) |
|
195 |
apply (drule initedD) |
|
196 |
apply (clarsimp elim!: atleast_free_SucD simp add: arr_inv_def) |
|
197 |
apply force |
|
198 |
apply (tactic {* simp_tac (simpset() delloop "split_all_tac") 1 *}) |
|
199 |
apply (rule ax_triv_Init_Object [THEN peek_and_forget2, THEN conseq1]) |
|
200 |
apply (rule wf_tprg) |
|
201 |
apply clarsimp |
|
202 |
apply (tactic {* inst1_tac "P22" "\<lambda>vf. Normal ((\<lambda>Y s Z. vf = lvar (VName e) (snd s)) \<and>. heap_free four \<and>. initd Ext)" *}) |
|
203 |
apply clarsimp |
|
204 |
apply (tactic {* inst1_tac "PP" "\<lambda>vf. Normal ((\<lambda>Y s Z. vf = lvar (VName e) (snd s)) \<and>. heap_free four \<and>. Not \<circ> initd Base)" *}) |
|
205 |
apply clarsimp |
|
206 |
(* end init *) |
|
207 |
apply (rule conseq1) |
|
208 |
apply (tactic "ax_tac 1") |
|
209 |
apply clarsimp |
|
210 |
done |
|
211 |
||
212 |
(* |
|
213 |
while (true) { |
|
214 |
if (i) {throw xcpt;} |
|
215 |
else i=j |
|
216 |
} |
|
217 |
*) |
|
218 |
lemma Loop_Xcpt_benchmark: |
|
219 |
"Q = (\<lambda>Y (x,s) Z. x \<noteq> None \<longrightarrow> the_Bool (the (locals s i))) \<Longrightarrow> |
|
220 |
G,({}::'a triple set)\<turnstile>{Normal (\<lambda>Y s Z::'a. True)} |
|
221 |
.lab1\<bullet> While(Lit (Bool True)) (If(Acc (LVar i)) (Throw (Acc (LVar xcpt))) Else |
|
222 |
(Expr (Ass (LVar i) (Acc (LVar j))))). {Q}" |
|
223 |
apply (rule_tac P' = "Q" and Q' = "Q\<leftarrow>=False\<down>=\<diamondsuit>" in conseq12) |
|
224 |
apply safe |
|
225 |
apply (tactic "ax_tac 1" (* Loop *)) |
|
226 |
apply (rule ax_Normal_cases) |
|
227 |
prefer 2 |
|
228 |
apply (rule ax_derivs.Abrupt [THEN conseq1], clarsimp simp add: Let_def) |
|
229 |
apply (rule conseq1) |
|
230 |
apply (tactic "ax_tac 1") |
|
231 |
apply clarsimp |
|
232 |
prefer 2 |
|
233 |
apply clarsimp |
|
234 |
apply (tactic "ax_tac 1" (* If *)) |
|
235 |
apply (tactic |
|
236 |
{* inst1_tac "P'21" "Normal (\<lambda>s.. (\<lambda>Y s Z. True)\<down>=Val (the (locals s i)))" *}) |
|
237 |
apply (tactic "ax_tac 1") |
|
238 |
apply (rule conseq1) |
|
239 |
apply (tactic "ax_tac 1") |
|
240 |
apply clarsimp |
|
241 |
apply (rule allI) |
|
242 |
apply (rule ax_escape) |
|
243 |
apply auto |
|
244 |
apply (rule conseq1) |
|
245 |
apply (tactic "ax_tac 1" (* Throw *)) |
|
246 |
apply (tactic "ax_tac 1") |
|
247 |
apply (tactic "ax_tac 1") |
|
248 |
apply clarsimp |
|
249 |
apply (rule_tac Q' = "Normal (\<lambda>Y s Z. True)" in conseq2) |
|
250 |
prefer 2 |
|
251 |
apply clarsimp |
|
252 |
apply (rule conseq1) |
|
253 |
apply (tactic "ax_tac 1") |
|
254 |
apply (tactic "ax_tac 1") |
|
255 |
prefer 2 |
|
256 |
apply (rule ax_subst_Var_allI) |
|
257 |
apply (tactic {* inst1_tac "P'29" "\<lambda>b Y ba Z vf. \<lambda>Y (x,s) Z. x=None \<and> snd vf = snd (lvar i s)" *}) |
|
258 |
apply (rule allI) |
|
259 |
apply (rule_tac P' = "Normal ?P" in conseq1) |
|
260 |
prefer 2 |
|
261 |
apply clarsimp |
|
262 |
apply (tactic "ax_tac 1") |
|
263 |
apply (rule conseq1) |
|
264 |
apply (tactic "ax_tac 1") |
|
265 |
apply clarsimp |
|
266 |
apply (tactic "ax_tac 1") |
|
267 |
apply clarsimp |
|
268 |
done |
|
269 |
||
270 |
end |
|
271 |