48 "\<lbrakk> P \<turnstile> c \<rightarrow> c'; P \<turnstile> c' \<rightarrow>^n c'' \<rbrakk> \<Longrightarrow> P \<turnstile> c \<rightarrow>^(Suc n) c''" |
48 "\<lbrakk> P \<turnstile> c \<rightarrow> c'; P \<turnstile> c' \<rightarrow>^n c'' \<rbrakk> \<Longrightarrow> P \<turnstile> c \<rightarrow>^(Suc n) c''" |
49 by (fastforce simp del: split_paired_Ex) |
49 by (fastforce simp del: split_paired_Ex) |
50 |
50 |
51 lemma exec_exec_n: |
51 lemma exec_exec_n: |
52 "P \<turnstile> c \<rightarrow>* c' \<Longrightarrow> \<exists>n. P \<turnstile> c \<rightarrow>^n c'" |
52 "P \<turnstile> c \<rightarrow>* c' \<Longrightarrow> \<exists>n. P \<turnstile> c \<rightarrow>^n c'" |
53 by (induct rule: exec.induct) (auto simp del: exec1_def intro: exec_Suc) |
53 by (induct rule: star.induct) (auto intro: exec_Suc) |
54 |
54 |
55 lemma exec_eq_exec_n: |
55 lemma exec_eq_exec_n: |
56 "(P \<turnstile> c \<rightarrow>* c') = (\<exists>n. P \<turnstile> c \<rightarrow>^n c')" |
56 "(P \<turnstile> c \<rightarrow>* c') = (\<exists>n. P \<turnstile> c \<rightarrow>^n c')" |
57 by (blast intro: exec_exec_n exec_n_exec) |
57 by (blast intro: exec_exec_n exec_n_exec) |
58 |
58 |
59 lemma exec_n_Nil [simp]: |
59 lemma exec_n_Nil [simp]: |
60 "[] \<turnstile> c \<rightarrow>^k c' = (c' = c \<and> k = 0)" |
60 "[] \<turnstile> c \<rightarrow>^k c' = (c' = c \<and> k = 0)" |
61 by (induct k) auto |
61 by (induct k) (auto simp: exec1_def) |
62 |
62 |
63 lemma exec1_exec_n [intro!]: |
63 lemma exec1_exec_n [intro!]: |
64 "P \<turnstile> c \<rightarrow> c' \<Longrightarrow> P \<turnstile> c \<rightarrow>^1 c'" |
64 "P \<turnstile> c \<rightarrow> c' \<Longrightarrow> P \<turnstile> c \<rightarrow>^1 c'" |
65 by (cases c') simp |
65 by (cases c') simp |
66 |
66 |
73 (\<exists>c. P \<turnstile> (n,stk,s) \<rightarrow> c \<and> P \<turnstile> c \<rightarrow>^(k - 1) (n',stk',s') \<and> 0 < k)" |
73 (\<exists>c. P \<turnstile> (n,stk,s) \<rightarrow> c \<and> P \<turnstile> c \<rightarrow>^(k - 1) (n',stk',s') \<and> 0 < k)" |
74 by (cases k) auto |
74 by (cases k) auto |
75 |
75 |
76 lemma exec1_end: |
76 lemma exec1_end: |
77 "size P <= fst c \<Longrightarrow> \<not> P \<turnstile> c \<rightarrow> c'" |
77 "size P <= fst c \<Longrightarrow> \<not> P \<turnstile> c \<rightarrow> c'" |
78 by auto |
78 by (auto simp: exec1_def) |
79 |
79 |
80 lemma exec_n_end: |
80 lemma exec_n_end: |
81 "size P <= (n::int) \<Longrightarrow> |
81 "size P <= (n::int) \<Longrightarrow> |
82 P \<turnstile> (n,s,stk) \<rightarrow>^k (n',s',stk') = (n' = n \<and> stk'=stk \<and> s'=s \<and> k =0)" |
82 P \<turnstile> (n,s,stk) \<rightarrow>^k (n',s',stk') = (n' = n \<and> stk'=stk \<and> s'=s \<and> k =0)" |
83 by (cases k) (auto simp: exec1_end) |
83 by (cases k) (auto simp: exec1_end) |
260 lemma exec1_split: |
260 lemma exec1_split: |
261 fixes i j :: int |
261 fixes i j :: int |
262 shows |
262 shows |
263 "P @ c @ P' \<turnstile> (size P + i, s) \<rightarrow> (j,s') \<Longrightarrow> 0 \<le> i \<Longrightarrow> i < size c \<Longrightarrow> |
263 "P @ c @ P' \<turnstile> (size P + i, s) \<rightarrow> (j,s') \<Longrightarrow> 0 \<le> i \<Longrightarrow> i < size c \<Longrightarrow> |
264 c \<turnstile> (i,s) \<rightarrow> (j - size P, s')" |
264 c \<turnstile> (i,s) \<rightarrow> (j - size P, s')" |
265 by (auto split: instr.splits) |
265 by (auto split: instr.splits simp: exec1_def) |
266 |
266 |
267 lemma exec_n_split: |
267 lemma exec_n_split: |
268 fixes i j :: int |
268 fixes i j :: int |
269 assumes "P @ c @ P' \<turnstile> (size P + i, s) \<rightarrow>^n (j, s')" |
269 assumes "P @ c @ P' \<turnstile> (size P + i, s) \<rightarrow>^n (j, s')" |
270 "0 \<le> i" "i < size c" |
270 "0 \<le> i" "i < size c" |
302 by (fastforce dest!: Suc.IH intro!: exec_Suc) |
302 by (fastforce dest!: Suc.IH intro!: exec_Suc) |
303 } moreover { |
303 } moreover { |
304 assume "j0 \<notin> {0 ..< size c}" |
304 assume "j0 \<notin> {0 ..< size c}" |
305 moreover |
305 moreover |
306 from c j0 have "j0 \<in> succs c 0" |
306 from c j0 have "j0 \<in> succs c 0" |
307 by (auto dest: succs_iexec1 simp del: iexec.simps) |
307 by (auto dest: succs_iexec1 simp: exec1_def simp del: iexec.simps) |
308 ultimately |
308 ultimately |
309 have "j0 \<in> exits c" by (simp add: exits_def) |
309 have "j0 \<in> exits c" by (simp add: exits_def) |
310 with c j0 rest |
310 with c j0 rest |
311 have ?case by fastforce |
311 have ?case by fastforce |
312 } |
312 } |
341 then obtain i' :: int where "i = size P1 + i'" .. |
341 then obtain i' :: int where "i = size P1 + i'" .. |
342 moreover |
342 moreover |
343 have "n = size P1 + (n - size P1)" by simp |
343 have "n = size P1 + (n - size P1)" by simp |
344 then obtain n' :: int where "n = size P1 + n'" .. |
344 then obtain n' :: int where "n = size P1 + n'" .. |
345 ultimately |
345 ultimately |
346 show ?thesis using assms by (clarsimp simp del: iexec.simps) |
346 show ?thesis using assms |
|
347 by (clarsimp simp: exec1_def simp del: iexec.simps) |
347 qed |
348 qed |
348 |
349 |
349 lemma exec_n_drop_left: |
350 lemma exec_n_drop_left: |
350 fixes i n :: int |
351 fixes i n :: int |
351 assumes "P @ P' \<turnstile> (i, s, stk) \<rightarrow>^k (n, s', stk')" |
352 assumes "P @ P' \<turnstile> (i, s, stk) \<rightarrow>^k (n, s', stk')" |
363 from step `size P \<le> i` |
364 from step `size P \<le> i` |
364 have "P' \<turnstile> (i - size P, s, stk) \<rightarrow> (i' - size P, s'', stk'')" |
365 have "P' \<turnstile> (i - size P, s, stk) \<rightarrow> (i' - size P, s'', stk'')" |
365 by (rule exec1_drop_left) |
366 by (rule exec1_drop_left) |
366 moreover |
367 moreover |
367 then have "i' - size P \<in> succs P' 0" |
368 then have "i' - size P \<in> succs P' 0" |
368 by (fastforce dest!: succs_iexec1 simp del: iexec.simps) |
369 by (fastforce dest!: succs_iexec1 simp: exec1_def simp del: iexec.simps) |
369 with `exits P' \<subseteq> {0..}` |
370 with `exits P' \<subseteq> {0..}` |
370 have "size P \<le> i'" by (auto simp: exits_def) |
371 have "size P \<le> i'" by (auto simp: exits_def) |
371 from rest this `exits P' \<subseteq> {0..}` |
372 from rest this `exits P' \<subseteq> {0..}` |
372 have "P' \<turnstile> (i' - size P, s'', stk'') \<rightarrow>^k (n - size P, s', stk')" |
373 have "P' \<turnstile> (i' - size P, s'', stk'') \<rightarrow>^k (n - size P, s', stk')" |
373 by (rule Suc.IH) |
374 by (rule Suc.IH) |
436 "acomp a1 \<turnstile> (0,s,stk) \<rightarrow>^n1 (size (acomp a1), s1, stk1)" |
437 "acomp a1 \<turnstile> (0,s,stk) \<rightarrow>^n1 (size (acomp a1), s1, stk1)" |
437 "acomp a2 \<turnstile> (0,s1,stk1) \<rightarrow>^n2 (size (acomp a2), s2, stk2)" |
438 "acomp a2 \<turnstile> (0,s1,stk1) \<rightarrow>^n2 (size (acomp a2), s2, stk2)" |
438 "[ADD] \<turnstile> (0,s2,stk2) \<rightarrow>^n3 (1, s', stk')" |
439 "[ADD] \<turnstile> (0,s2,stk2) \<rightarrow>^n3 (1, s', stk')" |
439 by (auto dest!: exec_n_split_full) |
440 by (auto dest!: exec_n_split_full) |
440 |
441 |
441 thus ?case by (fastforce dest: Plus.IH simp: exec_n_simps) |
442 thus ?case by (fastforce dest: Plus.IH simp: exec_n_simps exec1_def) |
442 qed (auto simp: exec_n_simps) |
443 qed (auto simp: exec_n_simps exec1_def) |
443 |
444 |
444 lemma bcomp_split: |
445 lemma bcomp_split: |
445 fixes i j :: int |
446 fixes i j :: int |
446 assumes "bcomp b c i @ P' \<turnstile> (0, s, stk) \<rightarrow>^n (j, s', stk')" |
447 assumes "bcomp b c i @ P' \<turnstile> (0, s, stk) \<rightarrow>^n (j, s', stk')" |
447 "j \<notin> {0..<size (bcomp b c i)}" "0 \<le> i" |
448 "j \<notin> {0..<size (bcomp b c i)}" "0 \<le> i" |
458 "size (bcomp b c j) \<le> i" "0 \<le> j" |
459 "size (bcomp b c j) \<le> i" "0 \<le> j" |
459 shows "i = size(bcomp b c j) + (if c = bval b s then j else 0) \<and> |
460 shows "i = size(bcomp b c j) + (if c = bval b s then j else 0) \<and> |
460 s' = s \<and> stk' = stk" |
461 s' = s \<and> stk' = stk" |
461 using assms proof (induction b arbitrary: c j i n s' stk') |
462 using assms proof (induction b arbitrary: c j i n s' stk') |
462 case Bc thus ?case |
463 case Bc thus ?case |
463 by (simp split: split_if_asm add: exec_n_simps) |
464 by (simp split: split_if_asm add: exec_n_simps exec1_def) |
464 next |
465 next |
465 case (Not b) |
466 case (Not b) |
466 from Not.prems show ?case |
467 from Not.prems show ?case |
467 by (fastforce dest!: Not.IH) |
468 by (fastforce dest!: Not.IH) |
468 next |
469 next |
486 with b2 j |
487 with b2 j |
487 show ?case |
488 show ?case |
488 by (fastforce dest!: And.IH simp: exec_n_end split: split_if_asm) |
489 by (fastforce dest!: And.IH simp: exec_n_end split: split_if_asm) |
489 next |
490 next |
490 case Less |
491 case Less |
491 thus ?case by (auto dest!: exec_n_split_full simp: exec_n_simps) (* takes time *) |
492 thus ?case by (auto dest!: exec_n_split_full simp: exec_n_simps exec1_def) (* takes time *) |
492 qed |
493 qed |
493 |
494 |
494 lemma ccomp_empty [elim!]: |
495 lemma ccomp_empty [elim!]: |
495 "ccomp c = [] \<Longrightarrow> (c,s) \<Rightarrow> s" |
496 "ccomp c = [] \<Longrightarrow> (c,s) \<Rightarrow> s" |
496 by (induct c) auto |
497 by (induct c) auto |
540 proof (cases "bval b s") |
541 proof (cases "bval b s") |
541 case True with cs' |
542 case True with cs' |
542 show ?thesis |
543 show ?thesis |
543 by simp |
544 by simp |
544 (fastforce dest: exec_n_drop_right |
545 (fastforce dest: exec_n_drop_right |
545 split: split_if_asm simp: exec_n_simps) |
546 split: split_if_asm |
|
547 simp: exec_n_simps exec1_def) |
546 next |
548 next |
547 case False with cs' |
549 case False with cs' |
548 show ?thesis |
550 show ?thesis |
549 by (auto dest!: exec_n_drop_Cons exec_n_drop_left |
551 by (auto dest!: exec_n_drop_Cons exec_n_drop_left |
550 simp: exits_Cons isuccs_def) |
552 simp: exits_Cons isuccs_def) |
581 assume "ccomp c = []" |
583 assume "ccomp c = []" |
582 with cs k |
584 with cs k |
583 obtain m where |
585 obtain m where |
584 "?cs \<turnstile> (0,s,stk) \<rightarrow>^m (size (ccomp ?c0), t, stk')" |
586 "?cs \<turnstile> (0,s,stk) \<rightarrow>^m (size (ccomp ?c0), t, stk')" |
585 "m < n" |
587 "m < n" |
586 by (auto simp: exec_n_step [where k=k]) |
588 by (auto simp: exec_n_step [where k=k] exec1_def) |
587 with "1.IH" |
589 with "1.IH" |
588 show ?case by blast |
590 show ?case by blast |
589 next |
591 next |
590 assume "ccomp c \<noteq> []" |
592 assume "ccomp c \<noteq> []" |
591 with cs |
593 with cs |
601 moreover |
603 moreover |
602 from rest m k stk |
604 from rest m k stk |
603 obtain k' where |
605 obtain k' where |
604 "?cs \<turnstile> (0, s'', stk) \<rightarrow>^k' (size ?cs, t, stk')" |
606 "?cs \<turnstile> (0, s'', stk) \<rightarrow>^k' (size ?cs, t, stk')" |
605 "k' < n" |
607 "k' < n" |
606 by (auto simp: exec_n_step [where k=m]) |
608 by (auto simp: exec_n_step [where k=m] exec1_def) |
607 with "1.IH" |
609 with "1.IH" |
608 have "(?c0, s'') \<Rightarrow> t \<and> stk' = stk" by blast |
610 have "(?c0, s'') \<Rightarrow> t \<and> stk' = stk" by blast |
609 ultimately |
611 ultimately |
610 show ?case using b by blast |
612 show ?case using b by blast |
611 qed |
613 qed |