src/HOL/IMP/Comp_Rev.thy
author hoelzl
Tue, 26 Mar 2013 12:20:59 +0100
changeset 51528 66c3a7589de7
parent 51259 1491459df114
child 51705 3d213f39d83c
permissions -rw-r--r--
Series.thy is based on Limits.thy and not Deriv.thy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
     1
(* Author: Gerwin Klein *)
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
     2
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
     3
theory Comp_Rev
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
     4
imports Compiler
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
     5
begin
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
     6
50061
7110422d4cb3 tuned text
nipkow
parents: 50060
diff changeset
     7
section {* Compiler Correctness, Reverse Direction *}
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
     8
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
     9
subsection {* Definitions *}
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    10
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    11
text {* Execution in @{term n} steps for simpler induction *}
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    12
primrec 
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    13
  exec_n :: "instr list \<Rightarrow> config \<Rightarrow> nat \<Rightarrow> config \<Rightarrow> bool" 
44000
ab4d8499815c resolved code_pred FIXME in IMP; clearer notation for exec_n
kleing
parents: 43438
diff changeset
    14
  ("_/ \<turnstile> (_ \<rightarrow>^_/ _)" [65,0,1000,55] 55)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    15
where 
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    16
  "P \<turnstile> c \<rightarrow>^0 c' = (c'=c)" |
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    17
  "P \<turnstile> c \<rightarrow>^(Suc n) c'' = (\<exists>c'. (P \<turnstile> c \<rightarrow> c') \<and> P \<turnstile> c' \<rightarrow>^n c'')"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    18
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
    19
text {* The possible successor PCs of an instruction at position @{term n} *}
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    20
definition
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    21
  "isuccs i n \<equiv> case i of 
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    22
     JMP j \<Rightarrow> {n + 1 + j}
45322
654cc47f6115 JMPF(LESS|GE) -> JMP(LESS|GE) because jumps are int now.
kleing
parents: 45218
diff changeset
    23
   | JMPLESS j \<Rightarrow> {n + 1 + j, n + 1}
654cc47f6115 JMPF(LESS|GE) -> JMP(LESS|GE) because jumps are int now.
kleing
parents: 45218
diff changeset
    24
   | JMPGE j \<Rightarrow> {n + 1 + j, n + 1}
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    25
   | _ \<Rightarrow> {n +1}"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    26
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
    27
text {* The possible successors PCs of an instruction list *}
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    28
definition
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
    29
  succs :: "instr list \<Rightarrow> int \<Rightarrow> int set" where
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
    30
  "succs P n = {s. \<exists>i::int. 0 \<le> i \<and> i < size P \<and> s \<in> isuccs (P!!i) (n+i)}" 
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    31
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
    32
text {* Possible exit PCs of a program *}
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    33
definition
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
    34
  "exits P = succs P 0 - {0..< size P}"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    35
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    36
  
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    37
subsection {* Basic properties of @{term exec_n} *}
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    38
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    39
lemma exec_n_exec:
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    40
  "P \<turnstile> c \<rightarrow>^n c' \<Longrightarrow> P \<turnstile> c \<rightarrow>* c'"
50060
43753eca324a replaced relation by function - simplifies development
nipkow
parents: 47818
diff changeset
    41
  by (induct n arbitrary: c) (auto simp del: exec1_def)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    42
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    43
lemma exec_0 [intro!]: "P \<turnstile> c \<rightarrow>^0 c" by simp
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    44
45218
f115540543d8 removed [trans] concept from basic material
kleing
parents: 45200
diff changeset
    45
lemma exec_Suc:
44000
ab4d8499815c resolved code_pred FIXME in IMP; clearer notation for exec_n
kleing
parents: 43438
diff changeset
    46
  "\<lbrakk> P \<turnstile> c \<rightarrow> c'; P \<turnstile> c' \<rightarrow>^n c'' \<rbrakk> \<Longrightarrow> P \<turnstile> c \<rightarrow>^(Suc n) c''" 
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44070
diff changeset
    47
  by (fastforce simp del: split_paired_Ex)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    48
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    49
lemma exec_exec_n:
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    50
  "P \<turnstile> c \<rightarrow>* c' \<Longrightarrow> \<exists>n. P \<turnstile> c \<rightarrow>^n c'"
50060
43753eca324a replaced relation by function - simplifies development
nipkow
parents: 47818
diff changeset
    51
  by (induct rule: exec.induct) (auto simp del: exec1_def intro: exec_Suc)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    52
    
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    53
lemma exec_eq_exec_n:
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    54
  "(P \<turnstile> c \<rightarrow>* c') = (\<exists>n. P \<turnstile> c \<rightarrow>^n c')"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    55
  by (blast intro: exec_exec_n exec_n_exec)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    56
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    57
lemma exec_n_Nil [simp]:
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    58
  "[] \<turnstile> c \<rightarrow>^k c' = (c' = c \<and> k = 0)"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    59
  by (induct k) auto
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    60
44004
a9fcbafdf208 compiler proof cleanup
kleing
parents: 44000
diff changeset
    61
lemma exec1_exec_n [intro!]:
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    62
  "P \<turnstile> c \<rightarrow> c' \<Longrightarrow> P \<turnstile> c \<rightarrow>^1 c'"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    63
  by (cases c') simp
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    64
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    65
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    66
subsection {* Concrete symbolic execution steps *}
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    67
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    68
lemma exec_n_step:
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    69
  "n \<noteq> n' \<Longrightarrow> 
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    70
  P \<turnstile> (n,stk,s) \<rightarrow>^k (n',stk',s') = 
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    71
  (\<exists>c. P \<turnstile> (n,stk,s) \<rightarrow> c \<and> P \<turnstile> c \<rightarrow>^(k - 1) (n',stk',s') \<and> 0 < k)"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    72
  by (cases k) auto
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    73
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    74
lemma exec1_end:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
    75
  "size P <= fst c \<Longrightarrow> \<not> P \<turnstile> c \<rightarrow> c'"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    76
  by auto
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    77
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    78
lemma exec_n_end:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
    79
  "size P <= (n::int) \<Longrightarrow> 
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    80
  P \<turnstile> (n,s,stk) \<rightarrow>^k (n',s',stk') = (n' = n \<and> stk'=stk \<and> s'=s \<and> k =0)"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    81
  by (cases k) (auto simp: exec1_end)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    82
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    83
lemmas exec_n_simps = exec_n_step exec_n_end
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    84
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    85
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    86
subsection {* Basic properties of @{term succs} *}
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    87
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    88
lemma succs_simps [simp]: 
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    89
  "succs [ADD] n = {n + 1}"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    90
  "succs [LOADI v] n = {n + 1}"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    91
  "succs [LOAD x] n = {n + 1}"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    92
  "succs [STORE x] n = {n + 1}"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    93
  "succs [JMP i] n = {n + 1 + i}"
45322
654cc47f6115 JMPF(LESS|GE) -> JMP(LESS|GE) because jumps are int now.
kleing
parents: 45218
diff changeset
    94
  "succs [JMPGE i] n = {n + 1 + i, n + 1}"
654cc47f6115 JMPF(LESS|GE) -> JMP(LESS|GE) because jumps are int now.
kleing
parents: 45218
diff changeset
    95
  "succs [JMPLESS i] n = {n + 1 + i, n + 1}"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    96
  by (auto simp: succs_def isuccs_def)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    97
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    98
lemma succs_empty [iff]: "succs [] n = {}"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
    99
  by (simp add: succs_def)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   100
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   101
lemma succs_Cons:
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   102
  "succs (x#xs) n = isuccs x n \<union> succs xs (1+n)" (is "_ = ?x \<union> ?xs")
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   103
proof 
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   104
  let ?isuccs = "\<lambda>p P n i::int. 0 \<le> i \<and> i < size P \<and> p \<in> isuccs (P!!i) (n+i)"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   105
  { fix p assume "p \<in> succs (x#xs) n"
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   106
    then obtain i::int where isuccs: "?isuccs p (x#xs) n i"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   107
      unfolding succs_def by auto     
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   108
    have "p \<in> ?x \<union> ?xs" 
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   109
    proof cases
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   110
      assume "i = 0" with isuccs show ?thesis by simp
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   111
    next
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   112
      assume "i \<noteq> 0" 
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   113
      with isuccs 
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   114
      have "?isuccs p xs (1+n) (i - 1)" by auto
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   115
      hence "p \<in> ?xs" unfolding succs_def by blast
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   116
      thus ?thesis .. 
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   117
    qed
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   118
  } 
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   119
  thus "succs (x#xs) n \<subseteq> ?x \<union> ?xs" ..
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   120
  
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   121
  { fix p assume "p \<in> ?x \<or> p \<in> ?xs"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   122
    hence "p \<in> succs (x#xs) n"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   123
    proof
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44070
diff changeset
   124
      assume "p \<in> ?x" thus ?thesis by (fastforce simp: succs_def)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   125
    next
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   126
      assume "p \<in> ?xs"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   127
      then obtain i where "?isuccs p xs (1+n) i"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   128
        unfolding succs_def by auto
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   129
      hence "?isuccs p (x#xs) n (1+i)"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   130
        by (simp add: algebra_simps)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   131
      thus ?thesis unfolding succs_def by blast
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   132
    qed
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   133
  }  
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   134
  thus "?x \<union> ?xs \<subseteq> succs (x#xs) n" by blast
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   135
qed
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   136
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   137
lemma succs_iexec1:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   138
  assumes "c' = iexec (P!!i) (i,s,stk)" "0 \<le> i" "i < size P"
44004
a9fcbafdf208 compiler proof cleanup
kleing
parents: 44000
diff changeset
   139
  shows "fst c' \<in> succs P 0"
50060
43753eca324a replaced relation by function - simplifies development
nipkow
parents: 47818
diff changeset
   140
  using assms by (auto simp: succs_def isuccs_def split: instr.split)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   141
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   142
lemma succs_shift:
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   143
  "(p - n \<in> succs P 0) = (p \<in> succs P n)" 
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44070
diff changeset
   144
  by (fastforce simp: succs_def isuccs_def split: instr.split)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   145
  
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   146
lemma inj_op_plus [simp]:
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   147
  "inj (op + (i::int))"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   148
  by (metis add_minus_cancel inj_on_inverseI)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   149
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   150
lemma succs_set_shift [simp]:
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   151
  "op + i ` succs xs 0 = succs xs i"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   152
  by (force simp: succs_shift [where n=i, symmetric] intro: set_eqI)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   153
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   154
lemma succs_append [simp]:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   155
  "succs (xs @ ys) n = succs xs n \<union> succs ys (n + size xs)"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   156
  by (induct xs arbitrary: n) (auto simp: succs_Cons algebra_simps)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   157
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   158
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   159
lemma exits_append [simp]:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   160
  "exits (xs @ ys) = exits xs \<union> (op + (size xs)) ` exits ys - 
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   161
                     {0..<size xs + size ys}" 
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   162
  by (auto simp: exits_def image_set_diff)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   163
  
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   164
lemma exits_single:
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   165
  "exits [x] = isuccs x 0 - {0}"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   166
  by (auto simp: exits_def succs_def)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   167
  
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   168
lemma exits_Cons:
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   169
  "exits (x # xs) = (isuccs x 0 - {0}) \<union> (op + 1) ` exits xs - 
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   170
                     {0..<1 + size xs}" 
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   171
  using exits_append [of "[x]" xs]
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   172
  by (simp add: exits_single)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   173
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   174
lemma exits_empty [iff]: "exits [] = {}" by (simp add: exits_def)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   175
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   176
lemma exits_simps [simp]:
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   177
  "exits [ADD] = {1}"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   178
  "exits [LOADI v] = {1}"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   179
  "exits [LOAD x] = {1}"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   180
  "exits [STORE x] = {1}"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   181
  "i \<noteq> -1 \<Longrightarrow> exits [JMP i] = {1 + i}"
45322
654cc47f6115 JMPF(LESS|GE) -> JMP(LESS|GE) because jumps are int now.
kleing
parents: 45218
diff changeset
   182
  "i \<noteq> -1 \<Longrightarrow> exits [JMPGE i] = {1 + i, 1}"
654cc47f6115 JMPF(LESS|GE) -> JMP(LESS|GE) because jumps are int now.
kleing
parents: 45218
diff changeset
   183
  "i \<noteq> -1 \<Longrightarrow> exits [JMPLESS i] = {1 + i, 1}"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   184
  by (auto simp: exits_def)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   185
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   186
lemma acomp_succs [simp]:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   187
  "succs (acomp a) n = {n + 1 .. n + size (acomp a)}"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   188
  by (induct a arbitrary: n) auto
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   189
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   190
lemma acomp_size:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   191
  "(1::int) \<le> size (acomp a)"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   192
  by (induct a) auto
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   193
44010
823549d46960 more consistent naming in IMP/Comp_Rev
kleing
parents: 44004
diff changeset
   194
lemma acomp_exits [simp]:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   195
  "exits (acomp a) = {size (acomp a)}"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   196
  by (auto simp: exits_def acomp_size)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   197
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   198
lemma bcomp_succs:
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   199
  "0 \<le> i \<Longrightarrow>
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   200
  succs (bcomp b c i) n \<subseteq> {n .. n + size (bcomp b c i)}
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   201
                           \<union> {n + i + size (bcomp b c i)}" 
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44890
diff changeset
   202
proof (induction b arbitrary: c i n)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   203
  case (And b1 b2)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   204
  from And.prems
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   205
  show ?case 
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   206
    by (cases c)
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44890
diff changeset
   207
       (auto dest: And.IH(1) [THEN subsetD, rotated] 
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44890
diff changeset
   208
                   And.IH(2) [THEN subsetD, rotated])
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   209
qed auto
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   210
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   211
lemmas bcomp_succsD [dest!] = bcomp_succs [THEN subsetD, rotated]
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   212
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   213
lemma bcomp_exits:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   214
  fixes i :: int
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   215
  shows
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   216
  "0 \<le> i \<Longrightarrow>
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   217
  exits (bcomp b c i) \<subseteq> {size (bcomp b c i), i + size (bcomp b c i)}" 
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   218
  by (auto simp: exits_def)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   219
  
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   220
lemma bcomp_exitsD [dest!]:
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   221
  "p \<in> exits (bcomp b c i) \<Longrightarrow> 0 \<le> i \<Longrightarrow> 
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   222
  p = size (bcomp b c i) \<or> p = i + size (bcomp b c i)"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   223
  using bcomp_exits by auto
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   224
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   225
lemma ccomp_succs:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   226
  "succs (ccomp c) n \<subseteq> {n..n + size (ccomp c)}"
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44890
diff changeset
   227
proof (induction c arbitrary: n)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   228
  case SKIP thus ?case by simp
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   229
next
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   230
  case Assign thus ?case by simp
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   231
next
47818
151d137f1095 renamed Semi to Seq
nipkow
parents: 45605
diff changeset
   232
  case (Seq c1 c2)
151d137f1095 renamed Semi to Seq
nipkow
parents: 45605
diff changeset
   233
  from Seq.prems
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   234
  show ?case 
47818
151d137f1095 renamed Semi to Seq
nipkow
parents: 45605
diff changeset
   235
    by (fastforce dest: Seq.IH [THEN subsetD])
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   236
next
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   237
  case (If b c1 c2)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   238
  from If.prems
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   239
  show ?case
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44890
diff changeset
   240
    by (auto dest!: If.IH [THEN subsetD] simp: isuccs_def succs_Cons)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   241
next
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   242
  case (While b c)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   243
  from While.prems
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44890
diff changeset
   244
  show ?case by (auto dest!: While.IH [THEN subsetD])
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   245
qed
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   246
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   247
lemma ccomp_exits:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   248
  "exits (ccomp c) \<subseteq> {size (ccomp c)}"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   249
  using ccomp_succs [of c 0] by (auto simp: exits_def)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   250
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   251
lemma ccomp_exitsD [dest!]:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   252
  "p \<in> exits (ccomp c) \<Longrightarrow> p = size (ccomp c)"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   253
  using ccomp_exits by auto
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   254
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   255
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   256
subsection {* Splitting up machine executions *}
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   257
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   258
lemma exec1_split:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   259
  fixes i j :: int
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   260
  shows
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   261
  "P @ c @ P' \<turnstile> (size P + i, s) \<rightarrow> (j,s') \<Longrightarrow> 0 \<le> i \<Longrightarrow> i < size c \<Longrightarrow> 
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   262
  c \<turnstile> (i,s) \<rightarrow> (j - size P, s')"
50060
43753eca324a replaced relation by function - simplifies development
nipkow
parents: 47818
diff changeset
   263
  by (auto split: instr.splits)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   264
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   265
lemma exec_n_split:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   266
  fixes i j :: int
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   267
  assumes "P @ c @ P' \<turnstile> (size P + i, s) \<rightarrow>^n (j, s')"
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   268
          "0 \<le> i" "i < size c" 
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   269
          "j \<notin> {size P ..< size P + size c}"
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   270
  shows "\<exists>s'' (i'::int) k m. 
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   271
                   c \<turnstile> (i, s) \<rightarrow>^k (i', s'') \<and>
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   272
                   i' \<in> exits c \<and> 
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   273
                   P @ c @ P' \<turnstile> (size P + i', s'') \<rightarrow>^m (j, s') \<and>
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   274
                   n = k + m" 
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44890
diff changeset
   275
using assms proof (induction n arbitrary: i j s)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   276
  case 0
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   277
  thus ?case by simp
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   278
next
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   279
  case (Suc n)
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   280
  have i: "0 \<le> i" "i < size c" by fact+
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   281
  from Suc.prems
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   282
  have j: "\<not> (size P \<le> j \<and> j < size P + size c)" by simp
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   283
  from Suc.prems 
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   284
  obtain i0 s0 where
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   285
    step: "P @ c @ P' \<turnstile> (size P + i, s) \<rightarrow> (i0,s0)" and
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   286
    rest: "P @ c @ P' \<turnstile> (i0,s0) \<rightarrow>^n (j, s')"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   287
    by clarsimp
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   288
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   289
  from step i
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   290
  have c: "c \<turnstile> (i,s) \<rightarrow> (i0 - size P, s0)" by (rule exec1_split)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   291
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   292
  have "i0 = size P + (i0 - size P) " by simp
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   293
  then obtain j0::int where j0: "i0 = size P + j0"  ..
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   294
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   295
  note split_paired_Ex [simp del]
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   296
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   297
  { assume "j0 \<in> {0 ..< size c}"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   298
    with j0 j rest c
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   299
    have ?case
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44890
diff changeset
   300
      by (fastforce dest!: Suc.IH intro!: exec_Suc)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   301
  } moreover {
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   302
    assume "j0 \<notin> {0 ..< size c}"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   303
    moreover
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   304
    from c j0 have "j0 \<in> succs c 0"
50060
43753eca324a replaced relation by function - simplifies development
nipkow
parents: 47818
diff changeset
   305
      by (auto dest: succs_iexec1 simp del: iexec.simps)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   306
    ultimately
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   307
    have "j0 \<in> exits c" by (simp add: exits_def)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   308
    with c j0 rest
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44070
diff changeset
   309
    have ?case by fastforce
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   310
  }
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   311
  ultimately
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   312
  show ?case by cases
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   313
qed
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   314
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   315
lemma exec_n_drop_right:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   316
  fixes j :: int
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   317
  assumes "c @ P' \<turnstile> (0, s) \<rightarrow>^n (j, s')" "j \<notin> {0..<size c}"
44004
a9fcbafdf208 compiler proof cleanup
kleing
parents: 44000
diff changeset
   318
  shows "\<exists>s'' i' k m. 
a9fcbafdf208 compiler proof cleanup
kleing
parents: 44000
diff changeset
   319
          (if c = [] then s'' = s \<and> i' = 0 \<and> k = 0
a9fcbafdf208 compiler proof cleanup
kleing
parents: 44000
diff changeset
   320
           else c \<turnstile> (0, s) \<rightarrow>^k (i', s'') \<and>
a9fcbafdf208 compiler proof cleanup
kleing
parents: 44000
diff changeset
   321
           i' \<in> exits c) \<and> 
a9fcbafdf208 compiler proof cleanup
kleing
parents: 44000
diff changeset
   322
           c @ P' \<turnstile> (i', s'') \<rightarrow>^m (j, s') \<and>
a9fcbafdf208 compiler proof cleanup
kleing
parents: 44000
diff changeset
   323
           n = k + m"
a9fcbafdf208 compiler proof cleanup
kleing
parents: 44000
diff changeset
   324
  using assms
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   325
  by (cases "c = []")
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   326
     (auto dest: exec_n_split [where P="[]", simplified])
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   327
  
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   328
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   329
text {*
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   330
  Dropping the left context of a potentially incomplete execution of @{term c}.
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   331
*}
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   332
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   333
lemma exec1_drop_left:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   334
  fixes i n :: int
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   335
  assumes "P1 @ P2 \<turnstile> (i, s, stk) \<rightarrow> (n, s', stk')" and "size P1 \<le> i"
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   336
  shows "P2 \<turnstile> (i - size P1, s, stk) \<rightarrow> (n - size P1, s', stk')"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   337
proof -
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   338
  have "i = size P1 + (i - size P1)" by simp 
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   339
  then obtain i' :: int where "i = size P1 + i'" ..
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   340
  moreover
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   341
  have "n = size P1 + (n - size P1)" by simp 
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   342
  then obtain n' :: int where "n = size P1 + n'" ..
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   343
  ultimately 
50060
43753eca324a replaced relation by function - simplifies development
nipkow
parents: 47818
diff changeset
   344
  show ?thesis using assms by (clarsimp simp del: iexec.simps)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   345
qed
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   346
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   347
lemma exec_n_drop_left:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   348
  fixes i n :: int
44004
a9fcbafdf208 compiler proof cleanup
kleing
parents: 44000
diff changeset
   349
  assumes "P @ P' \<turnstile> (i, s, stk) \<rightarrow>^k (n, s', stk')"
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   350
          "size P \<le> i" "exits P' \<subseteq> {0..}"
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   351
  shows "P' \<turnstile> (i - size P, s, stk) \<rightarrow>^k (n - size P, s', stk')"
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44890
diff changeset
   352
using assms proof (induction k arbitrary: i s stk)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   353
  case 0 thus ?case by simp
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   354
next
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   355
  case (Suc k)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   356
  from Suc.prems
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   357
  obtain i' s'' stk'' where
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   358
    step: "P @ P' \<turnstile> (i, s, stk) \<rightarrow> (i', s'', stk'')" and
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   359
    rest: "P @ P' \<turnstile> (i', s'', stk'') \<rightarrow>^k (n, s', stk')"
50060
43753eca324a replaced relation by function - simplifies development
nipkow
parents: 47818
diff changeset
   360
    by (auto simp del: exec1_def)
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   361
  from step `size P \<le> i`
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   362
  have "P' \<turnstile> (i - size P, s, stk) \<rightarrow> (i' - size P, s'', stk'')" 
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   363
    by (rule exec1_drop_left)
45218
f115540543d8 removed [trans] concept from basic material
kleing
parents: 45200
diff changeset
   364
  moreover
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   365
  then have "i' - size P \<in> succs P' 0"
50060
43753eca324a replaced relation by function - simplifies development
nipkow
parents: 47818
diff changeset
   366
    by (fastforce dest!: succs_iexec1 simp del: iexec.simps)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   367
  with `exits P' \<subseteq> {0..}`
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   368
  have "size P \<le> i'" by (auto simp: exits_def)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   369
  from rest this `exits P' \<subseteq> {0..}`     
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   370
  have "P' \<turnstile> (i' - size P, s'', stk'') \<rightarrow>^k (n - size P, s', stk')"
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44890
diff changeset
   371
    by (rule Suc.IH)
45218
f115540543d8 removed [trans] concept from basic material
kleing
parents: 45200
diff changeset
   372
  ultimately
f115540543d8 removed [trans] concept from basic material
kleing
parents: 45200
diff changeset
   373
  show ?case by auto
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   374
qed
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   375
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   376
lemmas exec_n_drop_Cons = 
45605
a89b4bc311a5 eliminated obsolete "standard";
wenzelm
parents: 45322
diff changeset
   377
  exec_n_drop_left [where P="[instr]", simplified] for instr
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   378
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   379
definition
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   380
  "closed P \<longleftrightarrow> exits P \<subseteq> {size P}" 
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   381
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   382
lemma ccomp_closed [simp, intro!]: "closed (ccomp c)"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   383
  using ccomp_exits by (auto simp: closed_def)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   384
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   385
lemma acomp_closed [simp, intro!]: "closed (acomp c)"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   386
  by (simp add: closed_def)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   387
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   388
lemma exec_n_split_full:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   389
  fixes j :: int
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   390
  assumes exec: "P @ P' \<turnstile> (0,s,stk) \<rightarrow>^k (j, s', stk')"
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   391
  assumes P: "size P \<le> j" 
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   392
  assumes closed: "closed P"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   393
  assumes exits: "exits P' \<subseteq> {0..}"
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   394
  shows "\<exists>k1 k2 s'' stk''. P \<turnstile> (0,s,stk) \<rightarrow>^k1 (size P, s'', stk'') \<and> 
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   395
                           P' \<turnstile> (0,s'',stk'') \<rightarrow>^k2 (j - size P, s', stk')"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   396
proof (cases "P")
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   397
  case Nil with exec
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44070
diff changeset
   398
  show ?thesis by fastforce
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   399
next
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   400
  case Cons
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   401
  hence "0 < size P" by simp
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   402
  with exec P closed
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   403
  obtain k1 k2 s'' stk'' where
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   404
    1: "P \<turnstile> (0,s,stk) \<rightarrow>^k1 (size P, s'', stk'')" and
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   405
    2: "P @ P' \<turnstile> (size P,s'',stk'') \<rightarrow>^k2 (j, s', stk')"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   406
    by (auto dest!: exec_n_split [where P="[]" and i=0, simplified] 
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   407
             simp: closed_def)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   408
  moreover
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   409
  have "j = size P + (j - size P)" by simp
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   410
  then obtain j0 :: int where "j = size P + j0" ..
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   411
  ultimately
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   412
  show ?thesis using exits
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44070
diff changeset
   413
    by (fastforce dest: exec_n_drop_left)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   414
qed
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   415
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   416
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   417
subsection {* Correctness theorem *}
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   418
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   419
lemma acomp_neq_Nil [simp]:
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   420
  "acomp a \<noteq> []"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   421
  by (induct a) auto
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   422
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   423
lemma acomp_exec_n [dest!]:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   424
  "acomp a \<turnstile> (0,s,stk) \<rightarrow>^n (size (acomp a),s',stk') \<Longrightarrow> 
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   425
  s' = s \<and> stk' = aval a s#stk"
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44890
diff changeset
   426
proof (induction a arbitrary: n s' stk stk')
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   427
  case (Plus a1 a2)
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   428
  let ?sz = "size (acomp a1) + (size (acomp a2) + 1)"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   429
  from Plus.prems
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   430
  have "acomp a1 @ acomp a2 @ [ADD] \<turnstile> (0,s,stk) \<rightarrow>^n (?sz, s', stk')" 
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   431
    by (simp add: algebra_simps)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   432
      
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   433
  then obtain n1 s1 stk1 n2 s2 stk2 n3 where 
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   434
    "acomp a1 \<turnstile> (0,s,stk) \<rightarrow>^n1 (size (acomp a1), s1, stk1)"
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   435
    "acomp a2 \<turnstile> (0,s1,stk1) \<rightarrow>^n2 (size (acomp a2), s2, stk2)" 
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   436
       "[ADD] \<turnstile> (0,s2,stk2) \<rightarrow>^n3 (1, s', stk')"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   437
    by (auto dest!: exec_n_split_full)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   438
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44890
diff changeset
   439
  thus ?case by (fastforce dest: Plus.IH simp: exec_n_simps)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   440
qed (auto simp: exec_n_simps)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   441
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   442
lemma bcomp_split:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   443
  fixes i j :: int
44004
a9fcbafdf208 compiler proof cleanup
kleing
parents: 44000
diff changeset
   444
  assumes "bcomp b c i @ P' \<turnstile> (0, s, stk) \<rightarrow>^n (j, s', stk')" 
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   445
          "j \<notin> {0..<size (bcomp b c i)}" "0 \<le> i"
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   446
  shows "\<exists>s'' stk'' (i'::int) k m. 
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   447
           bcomp b c i \<turnstile> (0, s, stk) \<rightarrow>^k (i', s'', stk'') \<and>
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   448
           (i' = size (bcomp b c i) \<or> i' = i + size (bcomp b c i)) \<and>
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   449
           bcomp b c i @ P' \<turnstile> (i', s'', stk'') \<rightarrow>^m (j, s', stk') \<and>
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   450
           n = k + m"
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44070
diff changeset
   451
  using assms by (cases "bcomp b c i = []") (fastforce dest!: exec_n_drop_right)+
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   452
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   453
lemma bcomp_exec_n [dest]:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   454
  fixes i j :: int
44004
a9fcbafdf208 compiler proof cleanup
kleing
parents: 44000
diff changeset
   455
  assumes "bcomp b c j \<turnstile> (0, s, stk) \<rightarrow>^n (i, s', stk')"
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   456
          "size (bcomp b c j) \<le> i" "0 \<le> j"
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   457
  shows "i = size(bcomp b c j) + (if c = bval b s then j else 0) \<and>
44004
a9fcbafdf208 compiler proof cleanup
kleing
parents: 44000
diff changeset
   458
         s' = s \<and> stk' = stk"
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44890
diff changeset
   459
using assms proof (induction b arbitrary: c j i n s' stk')
45200
1f1897ac7877 renamed B to Bc
nipkow
parents: 45015
diff changeset
   460
  case Bc thus ?case 
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   461
    by (simp split: split_if_asm add: exec_n_simps)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   462
next
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   463
  case (Not b) 
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   464
  from Not.prems show ?case
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44890
diff changeset
   465
    by (fastforce dest!: Not.IH) 
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   466
next
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   467
  case (And b1 b2)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   468
  
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   469
  let ?b2 = "bcomp b2 c j" 
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   470
  let ?m  = "if c then size ?b2 else size ?b2 + j"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   471
  let ?b1 = "bcomp b1 False ?m" 
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   472
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   473
  have j: "size (bcomp (And b1 b2) c j) \<le> i" "0 \<le> j" by fact+
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   474
  
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   475
  from And.prems
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   476
  obtain s'' stk'' and i'::int and k m where 
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   477
    b1: "?b1 \<turnstile> (0, s, stk) \<rightarrow>^k (i', s'', stk'')"
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   478
        "i' = size ?b1 \<or> i' = ?m + size ?b1" and
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   479
    b2: "?b2 \<turnstile> (i' - size ?b1, s'', stk'') \<rightarrow>^m (i - size ?b1, s', stk')"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   480
    by (auto dest!: bcomp_split dest: exec_n_drop_left)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   481
  from b1 j
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   482
  have "i' = size ?b1 + (if \<not>bval b1 s then ?m else 0) \<and> s'' = s \<and> stk'' = stk"
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44890
diff changeset
   483
    by (auto dest!: And.IH)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   484
  with b2 j
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   485
  show ?case 
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44890
diff changeset
   486
    by (fastforce dest!: And.IH simp: exec_n_end split: split_if_asm)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   487
next
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   488
  case Less
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   489
  thus ?case by (auto dest!: exec_n_split_full simp: exec_n_simps) (* takes time *) 
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   490
qed
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   491
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   492
lemma ccomp_empty [elim!]:
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   493
  "ccomp c = [] \<Longrightarrow> (c,s) \<Rightarrow> s"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   494
  by (induct c) auto
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   495
44070
cebb7abb54b1 import constant folding theory into IMP
kleing
parents: 44010
diff changeset
   496
declare assign_simp [simp]
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   497
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   498
lemma ccomp_exec_n:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   499
  "ccomp c \<turnstile> (0,s,stk) \<rightarrow>^n (size(ccomp c),t,stk')
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   500
  \<Longrightarrow> (c,s) \<Rightarrow> t \<and> stk'=stk"
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44890
diff changeset
   501
proof (induction c arbitrary: s t stk stk' n)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   502
  case SKIP
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   503
  thus ?case by auto
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   504
next
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   505
  case (Assign x a)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   506
  thus ?case
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44070
diff changeset
   507
    by simp (fastforce dest!: exec_n_split_full simp: exec_n_simps)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   508
next
47818
151d137f1095 renamed Semi to Seq
nipkow
parents: 45605
diff changeset
   509
  case (Seq c1 c2)
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44070
diff changeset
   510
  thus ?case by (fastforce dest!: exec_n_split_full)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   511
next
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   512
  case (If b c1 c2)
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44890
diff changeset
   513
  note If.IH [dest!]
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   514
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   515
  let ?if = "IF b THEN c1 ELSE c2"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   516
  let ?cs = "ccomp ?if"
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   517
  let ?bcomp = "bcomp b False (size (ccomp c1) + 1)"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   518
  
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   519
  from `?cs \<turnstile> (0,s,stk) \<rightarrow>^n (size ?cs,t,stk')`
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   520
  obtain i' :: int and k m s'' stk'' where
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   521
    cs: "?cs \<turnstile> (i',s'',stk'') \<rightarrow>^m (size ?cs,t,stk')" and
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   522
        "?bcomp \<turnstile> (0,s,stk) \<rightarrow>^k (i', s'', stk'')" 
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   523
        "i' = size ?bcomp \<or> i' = size ?bcomp + size (ccomp c1) + 1"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   524
    by (auto dest!: bcomp_split)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   525
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   526
  hence i':
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   527
    "s''=s" "stk'' = stk" 
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   528
    "i' = (if bval b s then size ?bcomp else size ?bcomp+size(ccomp c1)+1)"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   529
    by auto
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   530
  
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   531
  with cs have cs':
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   532
    "ccomp c1@JMP (size (ccomp c2))#ccomp c2 \<turnstile> 
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   533
       (if bval b s then 0 else size (ccomp c1)+1, s, stk) \<rightarrow>^m
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   534
       (1 + size (ccomp c1) + size (ccomp c2), t, stk')"
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44070
diff changeset
   535
    by (fastforce dest: exec_n_drop_left simp: exits_Cons isuccs_def algebra_simps)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   536
     
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   537
  show ?case
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   538
  proof (cases "bval b s")
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   539
    case True with cs'
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   540
    show ?thesis
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   541
      by simp
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44070
diff changeset
   542
         (fastforce dest: exec_n_drop_right 
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   543
                   split: split_if_asm simp: exec_n_simps)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   544
  next
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   545
    case False with cs'
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   546
    show ?thesis
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   547
      by (auto dest!: exec_n_drop_Cons exec_n_drop_left 
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   548
               simp: exits_Cons isuccs_def)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   549
  qed
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   550
next
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   551
  case (While b c)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   552
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   553
  from While.prems
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   554
  show ?case
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44890
diff changeset
   555
  proof (induction n arbitrary: s rule: nat_less_induct)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   556
    case (1 n)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   557
    
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   558
    { assume "\<not> bval b s"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   559
      with "1.prems"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   560
      have ?case
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   561
        by simp
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44070
diff changeset
   562
           (fastforce dest!: bcomp_exec_n bcomp_split 
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   563
                     simp: exec_n_simps)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   564
    } moreover {
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   565
      assume b: "bval b s"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   566
      let ?c0 = "WHILE b DO c"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   567
      let ?cs = "ccomp ?c0"
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   568
      let ?bs = "bcomp b False (size (ccomp c) + 1)"
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   569
      let ?jmp = "[JMP (-((size ?bs + size (ccomp c) + 1)))]"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   570
      
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   571
      from "1.prems" b
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   572
      obtain k where
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   573
        cs: "?cs \<turnstile> (size ?bs, s, stk) \<rightarrow>^k (size ?cs, t, stk')" and
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   574
        k:  "k \<le> n"
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44070
diff changeset
   575
        by (fastforce dest!: bcomp_split)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   576
      
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   577
      have ?case
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   578
      proof cases
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   579
        assume "ccomp c = []"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   580
        with cs k
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   581
        obtain m where
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   582
          "?cs \<turnstile> (0,s,stk) \<rightarrow>^m (size (ccomp ?c0), t, stk')"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   583
          "m < n"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   584
          by (auto simp: exec_n_step [where k=k])
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44890
diff changeset
   585
        with "1.IH"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   586
        show ?case by blast
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   587
      next
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   588
        assume "ccomp c \<noteq> []"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   589
        with cs
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   590
        obtain m m' s'' stk'' where
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   591
          c: "ccomp c \<turnstile> (0, s, stk) \<rightarrow>^m' (size (ccomp c), s'', stk'')" and 
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   592
          rest: "?cs \<turnstile> (size ?bs + size (ccomp c), s'', stk'') \<rightarrow>^m 
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   593
                       (size ?cs, t, stk')" and
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   594
          m: "k = m + m'"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   595
          by (auto dest: exec_n_split [where i=0, simplified])
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   596
        from c
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   597
        have "(c,s) \<Rightarrow> s''" and stk: "stk'' = stk"
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44890
diff changeset
   598
          by (auto dest!: While.IH)
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   599
        moreover
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   600
        from rest m k stk
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   601
        obtain k' where
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   602
          "?cs \<turnstile> (0, s'', stk) \<rightarrow>^k' (size ?cs, t, stk')"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   603
          "k' < n"
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   604
          by (auto simp: exec_n_step [where k=m])
45015
fdac1e9880eb Updated IMP to use new induction method
nipkow
parents: 44890
diff changeset
   605
        with "1.IH"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   606
        have "(?c0, s'') \<Rightarrow> t \<and> stk' = stk" by blast
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   607
        ultimately
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   608
        show ?case using b by blast
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   609
      qed
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   610
    }
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   611
    ultimately show ?case by cases
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   612
  qed
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   613
qed
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   614
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   615
theorem ccomp_exec:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   616
  "ccomp c \<turnstile> (0,s,stk) \<rightarrow>* (size(ccomp c),t,stk') \<Longrightarrow> (c,s) \<Rightarrow> t"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   617
  by (auto dest: exec_exec_n ccomp_exec_n)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   618
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   619
corollary ccomp_sound:
51259
1491459df114 eliminated isize in favour of size + type coercion
kleing
parents: 50061
diff changeset
   620
  "ccomp c \<turnstile> (0,s,stk) \<rightarrow>* (size(ccomp c),t,stk)  \<longleftrightarrow>  (c,s) \<Rightarrow> t"
43438
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   621
  by (blast intro!: ccomp_exec ccomp_bigstep)
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   622
a666b8d11252 IMP compiler with int, added reverse soundness direction
kleing
parents:
diff changeset
   623
end