src/HOL/IMP/Compiler0.thy
author krauss
Wed, 02 Feb 2011 08:47:45 +0100
changeset 41686 d8efc2490b8e
parent 39246 9e58f0499f57
child 41959 b460124855b8
permissions -rw-r--r--
made SML/NJ happy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13095
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
     1
(*  Title:      HOL/IMP/Compiler.thy
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
     2
    Author:     Tobias Nipkow, TUM
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
     3
    Copyright   1996 TUM
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
     4
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
     5
This is an early version of the compiler, where the abstract machine
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
     6
has an explicit pc. This turned out to be awkward, and a second
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
     7
development was started. See Machines.thy and Compiler.thy.
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
     8
*)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
     9
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    10
header "A Simple Compiler"
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    11
16417
9bc16273c2d4 migrated theory headers to new format
haftmann
parents: 14565
diff changeset
    12
theory Compiler0 imports Natural begin
13095
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    13
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    14
subsection "An abstract, simplistic machine"
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    15
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    16
text {* There are only three instructions: *}
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    17
datatype instr = ASIN loc aexp | JMPF bexp nat | JMPB nat
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    18
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    19
text {* We describe execution of programs in the machine by
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    20
  an operational (small step) semantics:
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    21
*}
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    22
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 18372
diff changeset
    23
inductive_set
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 18372
diff changeset
    24
  stepa1 :: "instr list \<Rightarrow> ((state\<times>nat) \<times> (state\<times>nat))set"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 18372
diff changeset
    25
  and stepa1' :: "[instr list,state,nat,state,nat] \<Rightarrow> bool"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 18372
diff changeset
    26
    ("_ \<turnstile> (3\<langle>_,_\<rangle>/ -1\<rightarrow> \<langle>_,_\<rangle>)" [50,0,0,0,0] 50)
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 18372
diff changeset
    27
  for P :: "instr list"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 18372
diff changeset
    28
where
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 18372
diff changeset
    29
  "P \<turnstile> \<langle>s,m\<rangle> -1\<rightarrow> \<langle>t,n\<rangle> == ((s,m),t,n) : stepa1 P"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 18372
diff changeset
    30
| ASIN[simp]:
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 18372
diff changeset
    31
  "\<lbrakk> n<size P; P!n = ASIN x a \<rbrakk> \<Longrightarrow> P \<turnstile> \<langle>s,n\<rangle> -1\<rightarrow> \<langle>s[x\<mapsto> a s],Suc n\<rangle>"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 18372
diff changeset
    32
| JMPFT[simp,intro]:
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 18372
diff changeset
    33
  "\<lbrakk> n<size P; P!n = JMPF b i;  b s \<rbrakk> \<Longrightarrow> P \<turnstile> \<langle>s,n\<rangle> -1\<rightarrow> \<langle>s,Suc n\<rangle>"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 18372
diff changeset
    34
| JMPFF[simp,intro]:
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 18372
diff changeset
    35
  "\<lbrakk> n<size P; P!n = JMPF b i; ~b s; m=n+i \<rbrakk> \<Longrightarrow> P \<turnstile> \<langle>s,n\<rangle> -1\<rightarrow> \<langle>s,m\<rangle>"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 18372
diff changeset
    36
| JMPB[simp]:
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 18372
diff changeset
    37
  "\<lbrakk> n<size P; P!n = JMPB i; i <= n; j = n-i \<rbrakk> \<Longrightarrow> P \<turnstile> \<langle>s,n\<rangle> -1\<rightarrow> \<langle>s,j\<rangle>"
14565
c6dc17aab88a use more symbols in HTML output
kleing
parents: 13130
diff changeset
    38
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 18372
diff changeset
    39
abbreviation
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 18372
diff changeset
    40
  stepa :: "[instr list,state,nat,state,nat] \<Rightarrow> bool"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 18372
diff changeset
    41
    ("_ \<turnstile>/ (3\<langle>_,_\<rangle>/ -*\<rightarrow> \<langle>_,_\<rangle>)" [50,0,0,0,0] 50)  where
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 18372
diff changeset
    42
  "P \<turnstile> \<langle>s,m\<rangle> -*\<rightarrow> \<langle>t,n\<rangle> == ((s,m),t,n) : ((stepa1 P)^*)"
13095
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    43
23746
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 18372
diff changeset
    44
abbreviation
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 18372
diff changeset
    45
  stepan :: "[instr list,state,nat,nat,state,nat] \<Rightarrow> bool"
a455e69c31cc Adapted to new inductive definition package.
berghofe
parents: 18372
diff changeset
    46
    ("_ \<turnstile>/ (3\<langle>_,_\<rangle>/ -(_)\<rightarrow> \<langle>_,_\<rangle>)" [50,0,0,0,0,0] 50)  where
30952
7ab2716dd93b power operation on functions with syntax o^; power operation on relations with syntax ^^
haftmann
parents: 27363
diff changeset
    47
  "P \<turnstile> \<langle>s,m\<rangle> -(i)\<rightarrow> \<langle>t,n\<rangle> == ((s,m),t,n) : (stepa1 P ^^ i)"
13095
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    48
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    49
subsection "The compiler"
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    50
39246
9e58f0499f57 modernized primrec
haftmann
parents: 30952
diff changeset
    51
primrec compile :: "com \<Rightarrow> instr list" where
9e58f0499f57 modernized primrec
haftmann
parents: 30952
diff changeset
    52
"compile \<SKIP> = []" |
9e58f0499f57 modernized primrec
haftmann
parents: 30952
diff changeset
    53
"compile (x:==a) = [ASIN x a]" |
9e58f0499f57 modernized primrec
haftmann
parents: 30952
diff changeset
    54
"compile (c1;c2) = compile c1 @ compile c2" |
13095
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    55
"compile (\<IF> b \<THEN> c1 \<ELSE> c2) =
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    56
 [JMPF b (length(compile c1) + 2)] @ compile c1 @
39246
9e58f0499f57 modernized primrec
haftmann
parents: 30952
diff changeset
    57
 [JMPF (%x. False) (length(compile c2)+1)] @ compile c2" |
13095
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    58
"compile (\<WHILE> b \<DO> c) = [JMPF b (length(compile c) + 2)] @ compile c @
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    59
 [JMPB (length(compile c)+1)]"
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    60
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    61
declare nth_append[simp]
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    62
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    63
subsection "Context lifting lemmas"
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    64
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
    65
text {*
13095
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    66
  Some lemmas for lifting an execution into a prefix and suffix
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    67
  of instructions; only needed for the first proof.
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    68
*}
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    69
lemma app_right_1:
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
    70
  assumes "is1 \<turnstile> \<langle>s1,i1\<rangle> -1\<rightarrow> \<langle>s2,i2\<rangle>"
13095
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    71
  shows "is1 @ is2 \<turnstile> \<langle>s1,i1\<rangle> -1\<rightarrow> \<langle>s2,i2\<rangle>"
27363
6d93bbe5633e tuned proofs;
wenzelm
parents: 23746
diff changeset
    72
  using assms
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
    73
  by induct auto
13095
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    74
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    75
lemma app_left_1:
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
    76
  assumes "is2 \<turnstile> \<langle>s1,i1\<rangle> -1\<rightarrow> \<langle>s2,i2\<rangle>"
13095
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    77
  shows "is1 @ is2 \<turnstile> \<langle>s1,size is1+i1\<rangle> -1\<rightarrow> \<langle>s2,size is1+i2\<rangle>"
27363
6d93bbe5633e tuned proofs;
wenzelm
parents: 23746
diff changeset
    78
  using assms
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
    79
  by induct auto
13095
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    80
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    81
declare rtrancl_induct2 [induct set: rtrancl]
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    82
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    83
lemma app_right:
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
    84
  assumes "is1 \<turnstile> \<langle>s1,i1\<rangle> -*\<rightarrow> \<langle>s2,i2\<rangle>"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
    85
  shows "is1 @ is2 \<turnstile> \<langle>s1,i1\<rangle> -*\<rightarrow> \<langle>s2,i2\<rangle>"
27363
6d93bbe5633e tuned proofs;
wenzelm
parents: 23746
diff changeset
    86
  using assms
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
    87
proof induct
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
    88
  show "is1 @ is2 \<turnstile> \<langle>s1,i1\<rangle> -*\<rightarrow> \<langle>s1,i1\<rangle>" by simp
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
    89
next
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
    90
  fix s1' i1' s2 i2
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
    91
  assume "is1 @ is2 \<turnstile> \<langle>s1,i1\<rangle> -*\<rightarrow> \<langle>s1',i1'\<rangle>"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
    92
    and "is1 \<turnstile> \<langle>s1',i1'\<rangle> -1\<rightarrow> \<langle>s2,i2\<rangle>"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
    93
  thus "is1 @ is2 \<turnstile> \<langle>s1,i1\<rangle> -*\<rightarrow> \<langle>s2,i2\<rangle>"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
    94
    by (blast intro: app_right_1 rtrancl_trans)
13095
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    95
qed
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    96
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
    97
lemma app_left:
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
    98
  assumes "is2 \<turnstile> \<langle>s1,i1\<rangle> -*\<rightarrow> \<langle>s2,i2\<rangle>"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
    99
  shows "is1 @ is2 \<turnstile> \<langle>s1,size is1+i1\<rangle> -*\<rightarrow> \<langle>s2,size is1+i2\<rangle>"
27363
6d93bbe5633e tuned proofs;
wenzelm
parents: 23746
diff changeset
   100
using assms
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   101
proof induct
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   102
  show "is1 @ is2 \<turnstile> \<langle>s1,length is1 + i1\<rangle> -*\<rightarrow> \<langle>s1,length is1 + i1\<rangle>" by simp
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   103
next
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   104
  fix s1' i1' s2 i2
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   105
  assume "is1 @ is2 \<turnstile> \<langle>s1,length is1 + i1\<rangle> -*\<rightarrow> \<langle>s1',length is1 + i1'\<rangle>"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   106
    and "is2 \<turnstile> \<langle>s1',i1'\<rangle> -1\<rightarrow> \<langle>s2,i2\<rangle>"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   107
  thus "is1 @ is2 \<turnstile> \<langle>s1,length is1 + i1\<rangle> -*\<rightarrow> \<langle>s2,length is1 + i2\<rangle>"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   108
    by (blast intro: app_left_1 rtrancl_trans)
13095
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   109
qed
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   110
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   111
lemma app_left2:
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   112
  "\<lbrakk> is2 \<turnstile> \<langle>s1,i1\<rangle> -*\<rightarrow> \<langle>s2,i2\<rangle>; j1 = size is1+i1; j2 = size is1+i2 \<rbrakk> \<Longrightarrow>
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   113
    is1 @ is2 \<turnstile> \<langle>s1,j1\<rangle> -*\<rightarrow> \<langle>s2,j2\<rangle>"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   114
  by (simp add: app_left)
13095
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   115
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   116
lemma app1_left:
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   117
  assumes "is \<turnstile> \<langle>s1,i1\<rangle> -*\<rightarrow> \<langle>s2,i2\<rangle>"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   118
  shows "instr # is \<turnstile> \<langle>s1,Suc i1\<rangle> -*\<rightarrow> \<langle>s2,Suc i2\<rangle>"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   119
proof -
27363
6d93bbe5633e tuned proofs;
wenzelm
parents: 23746
diff changeset
   120
  from app_left [OF assms, of "[instr]"]
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   121
  show ?thesis by simp
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   122
qed
13095
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   123
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   124
subsection "Compiler correctness"
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   125
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   126
declare rtrancl_into_rtrancl[trans]
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   127
        converse_rtrancl_into_rtrancl[trans]
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   128
        rtrancl_trans[trans]
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   129
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   130
text {*
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   131
  The first proof; The statement is very intuitive,
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   132
  but application of induction hypothesis requires the above lifting lemmas
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   133
*}
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   134
theorem
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   135
  assumes "\<langle>c,s\<rangle> \<longrightarrow>\<^sub>c t"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   136
  shows "compile c \<turnstile> \<langle>s,0\<rangle> -*\<rightarrow> \<langle>t,length(compile c)\<rangle>" (is "?P c s t")
27363
6d93bbe5633e tuned proofs;
wenzelm
parents: 23746
diff changeset
   137
  using assms
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   138
proof induct
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   139
  show "\<And>s. ?P \<SKIP> s s" by simp
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   140
next
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   141
  show "\<And>a s x. ?P (x :== a) s (s[x\<mapsto> a s])" by force
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   142
next
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   143
  fix c0 c1 s0 s1 s2
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   144
  assume "?P c0 s0 s1"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   145
  hence "compile c0 @ compile c1 \<turnstile> \<langle>s0,0\<rangle> -*\<rightarrow> \<langle>s1,length(compile c0)\<rangle>"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   146
    by (rule app_right)
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   147
  moreover assume "?P c1 s1 s2"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   148
  hence "compile c0 @ compile c1 \<turnstile> \<langle>s1,length(compile c0)\<rangle> -*\<rightarrow>
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   149
    \<langle>s2,length(compile c0)+length(compile c1)\<rangle>"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   150
  proof -
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   151
    show "\<And>is1 is2 s1 s2 i2.
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   152
      is2 \<turnstile> \<langle>s1,0\<rangle> -*\<rightarrow> \<langle>s2,i2\<rangle> \<Longrightarrow>
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   153
      is1 @ is2 \<turnstile> \<langle>s1,size is1\<rangle> -*\<rightarrow> \<langle>s2,size is1+i2\<rangle>"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   154
      using app_left[of _ 0] by simp
13095
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   155
  qed
18372
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   156
  ultimately have "compile c0 @ compile c1 \<turnstile> \<langle>s0,0\<rangle> -*\<rightarrow>
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   157
      \<langle>s2,length(compile c0)+length(compile c1)\<rangle>"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   158
    by (rule rtrancl_trans)
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   159
  thus "?P (c0; c1) s0 s2" by simp
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   160
next
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   161
  fix b c0 c1 s0 s1
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   162
  let ?comp = "compile(\<IF> b \<THEN> c0 \<ELSE> c1)"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   163
  assume "b s0" and IH: "?P c0 s0 s1"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   164
  hence "?comp \<turnstile> \<langle>s0,0\<rangle> -1\<rightarrow> \<langle>s0,1\<rangle>" by auto
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   165
  also from IH
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   166
  have "?comp \<turnstile> \<langle>s0,1\<rangle> -*\<rightarrow> \<langle>s1,length(compile c0)+1\<rangle>"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   167
    by(auto intro:app1_left app_right)
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   168
  also have "?comp \<turnstile> \<langle>s1,length(compile c0)+1\<rangle> -1\<rightarrow> \<langle>s1,length ?comp\<rangle>"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   169
    by(auto)
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   170
  finally show "?P (\<IF> b \<THEN> c0 \<ELSE> c1) s0 s1" .
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   171
next
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   172
  fix b c0 c1 s0 s1
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   173
  let ?comp = "compile(\<IF> b \<THEN> c0 \<ELSE> c1)"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   174
  assume "\<not>b s0" and IH: "?P c1 s0 s1"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   175
  hence "?comp \<turnstile> \<langle>s0,0\<rangle> -1\<rightarrow> \<langle>s0,length(compile c0) + 2\<rangle>" by auto
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   176
  also from IH
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   177
  have "?comp \<turnstile> \<langle>s0,length(compile c0)+2\<rangle> -*\<rightarrow> \<langle>s1,length ?comp\<rangle>"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   178
    by (force intro!: app_left2 app1_left)
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   179
  finally show "?P (\<IF> b \<THEN> c0 \<ELSE> c1) s0 s1" .
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   180
next
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   181
  fix b c and s::state
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   182
  assume "\<not>b s"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   183
  thus "?P (\<WHILE> b \<DO> c) s s" by force
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   184
next
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   185
  fix b c and s0::state and s1 s2
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   186
  let ?comp = "compile(\<WHILE> b \<DO> c)"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   187
  assume "b s0" and
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   188
    IHc: "?P c s0 s1" and IHw: "?P (\<WHILE> b \<DO> c) s1 s2"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   189
  hence "?comp \<turnstile> \<langle>s0,0\<rangle> -1\<rightarrow> \<langle>s0,1\<rangle>" by auto
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   190
  also from IHc
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   191
  have "?comp \<turnstile> \<langle>s0,1\<rangle> -*\<rightarrow> \<langle>s1,length(compile c)+1\<rangle>"
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   192
    by (auto intro: app1_left app_right)
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   193
  also have "?comp \<turnstile> \<langle>s1,length(compile c)+1\<rangle> -1\<rightarrow> \<langle>s1,0\<rangle>" by simp
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   194
  also note IHw
2bffdf62fe7f tuned proofs;
wenzelm
parents: 16417
diff changeset
   195
  finally show "?P (\<WHILE> b \<DO> c) s0 s2".
13095
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   196
qed
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   197
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   198
text {*
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   199
  Second proof; statement is generalized to cater for prefixes and suffixes;
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   200
  needs none of the lifting lemmas, but instantiations of pre/suffix.
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   201
  *}
13130
423ce375bf65 commented out half converted proof
nipkow
parents: 13112
diff changeset
   202
(*
13112
7275750553b7 a bit of conversion to structured proofs
nipkow
parents: 13095
diff changeset
   203
theorem assumes A: "\<langle>c,s\<rangle> \<longrightarrow>\<^sub>c t"
7275750553b7 a bit of conversion to structured proofs
nipkow
parents: 13095
diff changeset
   204
shows "\<And>a z. a@compile c@z \<turnstile> \<langle>s,size a\<rangle> -*\<rightarrow> \<langle>t,size a + size(compile c)\<rangle>"
7275750553b7 a bit of conversion to structured proofs
nipkow
parents: 13095
diff changeset
   205
      (is "\<And>a z. ?P c s t a z")
7275750553b7 a bit of conversion to structured proofs
nipkow
parents: 13095
diff changeset
   206
proof -
7275750553b7 a bit of conversion to structured proofs
nipkow
parents: 13095
diff changeset
   207
  from A show "\<And>a z. ?thesis a z"
7275750553b7 a bit of conversion to structured proofs
nipkow
parents: 13095
diff changeset
   208
  proof induct
7275750553b7 a bit of conversion to structured proofs
nipkow
parents: 13095
diff changeset
   209
    case Skip thus ?case by simp
7275750553b7 a bit of conversion to structured proofs
nipkow
parents: 13095
diff changeset
   210
  next
7275750553b7 a bit of conversion to structured proofs
nipkow
parents: 13095
diff changeset
   211
    case Assign thus ?case by (force intro!: ASIN)
7275750553b7 a bit of conversion to structured proofs
nipkow
parents: 13095
diff changeset
   212
  next
7275750553b7 a bit of conversion to structured proofs
nipkow
parents: 13095
diff changeset
   213
    fix c1 c2 s s' s'' a z
7275750553b7 a bit of conversion to structured proofs
nipkow
parents: 13095
diff changeset
   214
    assume IH1: "\<And>a z. ?P c1 s s' a z" and IH2: "\<And>a z. ?P c2 s' s'' a z"
7275750553b7 a bit of conversion to structured proofs
nipkow
parents: 13095
diff changeset
   215
    from IH1 IH2[of "a@compile c1"]
7275750553b7 a bit of conversion to structured proofs
nipkow
parents: 13095
diff changeset
   216
    show "?P (c1;c2) s s'' a z"
7275750553b7 a bit of conversion to structured proofs
nipkow
parents: 13095
diff changeset
   217
      by(simp add:add_assoc[THEN sym])(blast intro:rtrancl_trans)
7275750553b7 a bit of conversion to structured proofs
nipkow
parents: 13095
diff changeset
   218
  next
7275750553b7 a bit of conversion to structured proofs
nipkow
parents: 13095
diff changeset
   219
(* at this point I gave up converting to structured proofs *)
13095
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   220
(* \<IF> b \<THEN> c0 \<ELSE> c1; case b is true *)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   221
   apply(intro strip)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   222
   (* instantiate assumption sufficiently for later: *)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   223
   apply(erule_tac x = "a@[?I]" in allE)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   224
   apply(simp)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   225
   (* execute JMPF: *)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   226
   apply(rule converse_rtrancl_into_rtrancl)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   227
    apply(force intro!: JMPFT)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   228
   (* execute compile c0: *)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   229
   apply(rule rtrancl_trans)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   230
    apply(erule allE)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   231
    apply assumption
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   232
   (* execute JMPF: *)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   233
   apply(rule r_into_rtrancl)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   234
   apply(force intro!: JMPFF)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   235
(* end of case b is true *)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   236
  apply(intro strip)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   237
  apply(erule_tac x = "a@[?I]@compile c0@[?J]" in allE)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   238
  apply(simp add:add_assoc)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   239
  apply(rule converse_rtrancl_into_rtrancl)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   240
   apply(force intro!: JMPFF)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   241
  apply(blast)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   242
 apply(force intro: JMPFF)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   243
apply(intro strip)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   244
apply(erule_tac x = "a@[?I]" in allE)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   245
apply(erule_tac x = a in allE)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   246
apply(simp)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   247
apply(rule converse_rtrancl_into_rtrancl)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   248
 apply(force intro!: JMPFT)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   249
apply(rule rtrancl_trans)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   250
 apply(erule allE)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   251
 apply assumption
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   252
apply(rule converse_rtrancl_into_rtrancl)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   253
 apply(force intro!: JMPB)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   254
apply(simp)
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   255
done
13130
423ce375bf65 commented out half converted proof
nipkow
parents: 13112
diff changeset
   256
*)
13095
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   257
text {* Missing: the other direction! I did much of it, and although
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   258
the main lemma is very similar to the one in the new development, the
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   259
lemmas surrounding it seemed much more complicated. In the end I gave
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   260
up. *}
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   261
8ed413a57bdc New machine architecture and other direction of compiler proof.
nipkow
parents:
diff changeset
   262
end