92 |
92 |
93 |
93 |
94 subsection{* Verification infrastructure *} |
94 subsection{* Verification infrastructure *} |
95 |
95 |
96 lemma exec_trans: "P \<turnstile> c \<rightarrow>* c' \<Longrightarrow> P \<turnstile> c' \<rightarrow>* c'' \<Longrightarrow> P \<turnstile> c \<rightarrow>* c''" |
96 lemma exec_trans: "P \<turnstile> c \<rightarrow>* c' \<Longrightarrow> P \<turnstile> c' \<rightarrow>* c'' \<Longrightarrow> P \<turnstile> c \<rightarrow>* c''" |
97 by (induct rule: exec.induct) fastsimp+ |
97 by (induct rule: exec.induct) fastforce+ |
98 |
98 |
99 inductive_cases iexec1_cases [elim!]: |
99 inductive_cases iexec1_cases [elim!]: |
100 "LOADI n \<turnstile>i c \<rightarrow> c'" |
100 "LOADI n \<turnstile>i c \<rightarrow> c'" |
101 "LOAD x \<turnstile>i c \<rightarrow> c'" |
101 "LOAD x \<turnstile>i c \<rightarrow> c'" |
102 "ADD \<turnstile>i c \<rightarrow> c'" |
102 "ADD \<turnstile>i c \<rightarrow> c'" |
129 |
129 |
130 lemma exec1_appendR: "P \<turnstile> c \<rightarrow> c' \<Longrightarrow> P@P' \<turnstile> c \<rightarrow> c'" |
130 lemma exec1_appendR: "P \<turnstile> c \<rightarrow> c' \<Longrightarrow> P@P' \<turnstile> c \<rightarrow> c'" |
131 by auto |
131 by auto |
132 |
132 |
133 lemma exec_appendR: "P \<turnstile> c \<rightarrow>* c' \<Longrightarrow> P@P' \<turnstile> c \<rightarrow>* c'" |
133 lemma exec_appendR: "P \<turnstile> c \<rightarrow>* c' \<Longrightarrow> P@P' \<turnstile> c \<rightarrow>* c'" |
134 by (induct rule: exec.induct) (fastsimp intro: exec1_appendR)+ |
134 by (induct rule: exec.induct) (fastforce intro: exec1_appendR)+ |
135 |
135 |
136 lemma iexec1_shiftI: |
136 lemma iexec1_shiftI: |
137 assumes "X \<turnstile>i (i,s,stk) \<rightarrow> (i',s',stk')" |
137 assumes "X \<turnstile>i (i,s,stk) \<rightarrow> (i',s',stk')" |
138 shows "X \<turnstile>i (n+i,s,stk) \<rightarrow> (n+i',s',stk')" |
138 shows "X \<turnstile>i (n+i,s,stk) \<rightarrow> (n+i',s',stk')" |
139 using assms by cases auto |
139 using assms by cases auto |
199 "acomp (V x) = [LOAD x]" | |
199 "acomp (V x) = [LOAD x]" | |
200 "acomp (Plus a1 a2) = acomp a1 @ acomp a2 @ [ADD]" |
200 "acomp (Plus a1 a2) = acomp a1 @ acomp a2 @ [ADD]" |
201 |
201 |
202 lemma acomp_correct[intro]: |
202 lemma acomp_correct[intro]: |
203 "acomp a \<turnstile> (0,s,stk) \<rightarrow>* (isize(acomp a),s,aval a s#stk)" |
203 "acomp a \<turnstile> (0,s,stk) \<rightarrow>* (isize(acomp a),s,aval a s#stk)" |
204 by (induct a arbitrary: stk) fastsimp+ |
204 by (induct a arbitrary: stk) fastforce+ |
205 |
205 |
206 fun bcomp :: "bexp \<Rightarrow> bool \<Rightarrow> int \<Rightarrow> instr list" where |
206 fun bcomp :: "bexp \<Rightarrow> bool \<Rightarrow> int \<Rightarrow> instr list" where |
207 "bcomp (B bv) c n = (if bv=c then [JMP n] else [])" | |
207 "bcomp (B bv) c n = (if bv=c then [JMP n] else [])" | |
208 "bcomp (Not b) c n = bcomp b (\<not>c) n" | |
208 "bcomp (Not b) c n = bcomp b (\<not>c) n" | |
209 "bcomp (And b1 b2) c n = |
209 "bcomp (And b1 b2) c n = |
222 "0 \<le> n \<Longrightarrow> |
222 "0 \<le> n \<Longrightarrow> |
223 bcomp b c n \<turnstile> |
223 bcomp b c n \<turnstile> |
224 (0,s,stk) \<rightarrow>* (isize(bcomp b c n) + (if c = bval b s then n else 0),s,stk)" |
224 (0,s,stk) \<rightarrow>* (isize(bcomp b c n) + (if c = bval b s then n else 0),s,stk)" |
225 proof(induct b arbitrary: c n m) |
225 proof(induct b arbitrary: c n m) |
226 case Not |
226 case Not |
227 from Not(1)[where c="~c"] Not(2) show ?case by fastsimp |
227 from Not(1)[where c="~c"] Not(2) show ?case by fastforce |
228 next |
228 next |
229 case (And b1 b2) |
229 case (And b1 b2) |
230 from And(1)[of "if c then isize (bcomp b2 c n) else isize (bcomp b2 c n) + n" |
230 from And(1)[of "if c then isize (bcomp b2 c n) else isize (bcomp b2 c n) + n" |
231 "False"] |
231 "False"] |
232 And(2)[of n "c"] And(3) |
232 And(2)[of n "c"] And(3) |
233 show ?case by fastsimp |
233 show ?case by fastforce |
234 qed fastsimp+ |
234 qed fastforce+ |
235 |
235 |
236 fun ccomp :: "com \<Rightarrow> instr list" where |
236 fun ccomp :: "com \<Rightarrow> instr list" where |
237 "ccomp SKIP = []" | |
237 "ccomp SKIP = []" | |
238 "ccomp (x ::= a) = acomp a @ [STORE x]" | |
238 "ccomp (x ::= a) = acomp a @ [STORE x]" | |
239 "ccomp (c\<^isub>1;c\<^isub>2) = ccomp c\<^isub>1 @ ccomp c\<^isub>2" | |
239 "ccomp (c\<^isub>1;c\<^isub>2) = ccomp c\<^isub>1 @ ccomp c\<^isub>2" | |
256 |
256 |
257 lemma ccomp_bigstep: |
257 lemma ccomp_bigstep: |
258 "(c,s) \<Rightarrow> t \<Longrightarrow> ccomp c \<turnstile> (0,s,stk) \<rightarrow>* (isize(ccomp c),t,stk)" |
258 "(c,s) \<Rightarrow> t \<Longrightarrow> ccomp c \<turnstile> (0,s,stk) \<rightarrow>* (isize(ccomp c),t,stk)" |
259 proof(induct arbitrary: stk rule: big_step_induct) |
259 proof(induct arbitrary: stk rule: big_step_induct) |
260 case (Assign x a s) |
260 case (Assign x a s) |
261 show ?case by (fastsimp simp:fun_upd_def cong: if_cong) |
261 show ?case by (fastforce simp:fun_upd_def cong: if_cong) |
262 next |
262 next |
263 case (Semi c1 s1 s2 c2 s3) |
263 case (Semi c1 s1 s2 c2 s3) |
264 let ?cc1 = "ccomp c1" let ?cc2 = "ccomp c2" |
264 let ?cc1 = "ccomp c1" let ?cc2 = "ccomp c2" |
265 have "?cc1 @ ?cc2 \<turnstile> (0,s1,stk) \<rightarrow>* (isize ?cc1,s2,stk)" |
265 have "?cc1 @ ?cc2 \<turnstile> (0,s1,stk) \<rightarrow>* (isize ?cc1,s2,stk)" |
266 using Semi.hyps(2) by fastsimp |
266 using Semi.hyps(2) by fastforce |
267 moreover |
267 moreover |
268 have "?cc1 @ ?cc2 \<turnstile> (isize ?cc1,s2,stk) \<rightarrow>* (isize(?cc1 @ ?cc2),s3,stk)" |
268 have "?cc1 @ ?cc2 \<turnstile> (isize ?cc1,s2,stk) \<rightarrow>* (isize(?cc1 @ ?cc2),s3,stk)" |
269 using Semi.hyps(4) by fastsimp |
269 using Semi.hyps(4) by fastforce |
270 ultimately show ?case by simp (blast intro: exec_trans) |
270 ultimately show ?case by simp (blast intro: exec_trans) |
271 next |
271 next |
272 case (WhileTrue b s1 c s2 s3) |
272 case (WhileTrue b s1 c s2 s3) |
273 let ?cc = "ccomp c" |
273 let ?cc = "ccomp c" |
274 let ?cb = "bcomp b False (isize ?cc + 1)" |
274 let ?cb = "bcomp b False (isize ?cc + 1)" |
275 let ?cw = "ccomp(WHILE b DO c)" |
275 let ?cw = "ccomp(WHILE b DO c)" |
276 have "?cw \<turnstile> (0,s1,stk) \<rightarrow>* (isize ?cb + isize ?cc,s2,stk)" |
276 have "?cw \<turnstile> (0,s1,stk) \<rightarrow>* (isize ?cb + isize ?cc,s2,stk)" |
277 using WhileTrue(1,3) by fastsimp |
277 using WhileTrue(1,3) by fastforce |
278 moreover |
278 moreover |
279 have "?cw \<turnstile> (isize ?cb + isize ?cc,s2,stk) \<rightarrow>* (0,s2,stk)" |
279 have "?cw \<turnstile> (isize ?cb + isize ?cc,s2,stk) \<rightarrow>* (0,s2,stk)" |
280 by fastsimp |
280 by fastforce |
281 moreover |
281 moreover |
282 have "?cw \<turnstile> (0,s2,stk) \<rightarrow>* (isize ?cw,s3,stk)" by(rule WhileTrue(5)) |
282 have "?cw \<turnstile> (0,s2,stk) \<rightarrow>* (isize ?cw,s3,stk)" by(rule WhileTrue(5)) |
283 ultimately show ?case by(blast intro: exec_trans) |
283 ultimately show ?case by(blast intro: exec_trans) |
284 qed fastsimp+ |
284 qed fastforce+ |
285 |
285 |
286 end |
286 end |